From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759354AbdADKH3 (ORCPT ); Wed, 4 Jan 2017 05:07:29 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33714 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759310AbdADKHZ (ORCPT ); Wed, 4 Jan 2017 05:07:25 -0500 Date: Wed, 4 Jan 2017 18:07:20 +0800 From: Boqun Feng To: Waiman Long Cc: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 6/7] locking/rtqspinlock: Voluntarily yield CPU when need_sched() Message-ID: <20170104100720.GA4985@tardis.cn.ibm.com> References: <1483466430-8028-1-git-send-email-longman@redhat.com> <1483466430-8028-7-git-send-email-longman@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pf9I7BMVVzbSWLtt" Content-Disposition: inline In-Reply-To: <1483466430-8028-7-git-send-email-longman@redhat.com> User-Agent: Mutt/1.7.2 (2016-11-26) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --pf9I7BMVVzbSWLtt Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jan 03, 2017 at 01:00:29PM -0500, Waiman Long wrote: > Ideally we want the CPU to be preemptible even when inside or waiting > for a lock. We cannot make it preemptible when inside a lock critical > section, but we can try to make the task voluntarily yield the CPU > when waiting for a lock. >=20 > This patch checks the need_sched() flag and yields the CPU when the > preemption count is 1. IOW, the spin_lock() call isn't done in a > region that doesn't allow preemption. Otherwise, it will just perform > RT spinning with a minimum priority of 1. >=20 > Signed-off-by: Waiman Long > --- > kernel/locking/qspinlock_rt.h | 68 +++++++++++++++++++++++++++++++++++++= ++++-- > 1 file changed, 65 insertions(+), 3 deletions(-) >=20 > diff --git a/kernel/locking/qspinlock_rt.h b/kernel/locking/qspinlock_rt.h > index 0c4d051..18ec1f8 100644 > --- a/kernel/locking/qspinlock_rt.h > +++ b/kernel/locking/qspinlock_rt.h > @@ -43,6 +43,16 @@ > * it will have to break out of the MCS wait queue just like what is done > * in the OSQ lock. Then it has to retry RT spinning if it has been boos= ted > * to RT priority. > + * > + * Another RT requirement is that the CPU need to be preemptible even wh= en > + * waiting for a spinlock. If the task has already acquired the lock, we > + * will let it run to completion to release the lock and reenable preemp= tion. > + * For non-nested spinlock, a spinlock waiter will periodically check > + * need_resched flag to see if it should break out of the waiting loop a= nd > + * yield the CPU as long as the preemption count indicates just one > + * preempt_disabled(). For nested spinlock with outer lock acquired, it = will > + * boost its priority to the highest RT priority level to try to acquire= the > + * inner lock, finish up its work, release the locks and reenable preemp= tion. > */ > #include > =20 > @@ -51,6 +61,15 @@ > #endif > =20 > /* > + * Rescheduling is only needed when it is in the task context, the > + * PREEMPT_NEED_RESCHED flag is set and the preemption count is one. > + * If only the TIF_NEED_RESCHED flag is set, it will be moved to RT > + * spinning with a minimum priority of 1. > + */ > +#define rt_should_resched() (preempt_count() =3D=3D \ > + (PREEMPT_OFFSET | PREEMPT_NEED_RESCHED)) > + Maybe I am missing something... but On x86, PREEMPT_NEED_RESCHED is used in an inverting style, i.e. 0 indicates "need to reschedule" and preempt_count() masks away this very bit, which makes rt_should_resched() always false. So... Regards, Boqun --pf9I7BMVVzbSWLtt Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlhsyVUACgkQSXnow7UH +riTOQf/c/CgYom5pAgPnbfFe3HizFU4zBsCf/5D+qQf7uVWcbIEAfySJzhrk6dI 8UE3JsNl85f4X8bukIJCmKndd+En9v9VerKC0iRucNnNRIe6JD3NYNHMK02m3d97 6HSUxazX3pgiEleOsh7h/dugPqk/lu2l4NWSqj/UX1OLVAXinfbPgPCy9JvvsZ6e 8Tsch2OuAtdc6Kz+bFImJwbTRjPCRdtbZ0HYoOfjD2YTjCGzCBG1Grmpa7vDY6oD 0qS9/Ft45NGbdi+81Fws3JET1sxNkcRseehYc8cFnoWEA3Mi0IlZ4YtCemBK9JhN yTi0hOFtgB8DQorSV4w+di3F9kuH5w== =Wt52 -----END PGP SIGNATURE----- --pf9I7BMVVzbSWLtt--