From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751888AbdFPAp5 (ORCPT ); Thu, 15 Jun 2017 20:45:57 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:36863 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751578AbdFPAp4 (ORCPT ); Thu, 15 Jun 2017 20:45:56 -0400 Date: Fri, 16 Jun 2017 08:47:32 +0800 From: Boqun Feng To: "Luis R. Rodriguez" Cc: peterz@infradead.org, paulmck@linux.vnet.ibm.com, oleg@redhat.com, josh@joshtriplett.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, paul.gortmaker@windriver.com, ebiederm@xmission.com, dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org Subject: Re: [RFC v2 1/2] swait: add idle variants which don't contribute to load average Message-ID: <20170616004732.oo2dfpri6p6qjq4s@tardis> References: <87zid92ns2.fsf@xmission.com> <20170615184820.22994-1-mcgrof@kernel.org> <20170615184820.22994-2-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="kunn7dzjcptzv2k2" Content-Disposition: inline In-Reply-To: <20170615184820.22994-2-mcgrof@kernel.org> User-Agent: NeoMutt/20170225 (1.8.0) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --kunn7dzjcptzv2k2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 15, 2017 at 11:48:19AM -0700, Luis R. Rodriguez wrote: > There are cases where folks are using an interruptible swait when > using kthreads. This is rather confusing given you'd expect > interruptible waits to be -- interruptible, but kthreads are not > interruptible ! The reason for such practice though is to avoid > having these kthreads contribute to the system load average. >=20 > When systems are idle some kthreads may spend a lot of time blocking if > using swait_event_timeout(). This would contribute to the system load > average. On systems without preemption this would mean the load average > of an idle system is bumped to 2 instead of 0. On systems with PREEMPT=3Dy > this would mean the load average of an idle system is bumped to 3 > instead of 0. >=20 > This adds proper API using TASK_IDLE to make such goals explicit and > avoid confusion. >=20 > Suggested-by: "Eric W. Biederman" > Signed-off-by: Luis R. Rodriguez > --- > include/linux/swait.h | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) >=20 > diff --git a/include/linux/swait.h b/include/linux/swait.h > index 2c700694d50a..105c70e23286 100644 > --- a/include/linux/swait.h > +++ b/include/linux/swait.h > @@ -194,4 +194,29 @@ do { \ > __ret; \ > }) > =20 > +#define __swait_event_idle(wq, condition) \ > + ___swait_event(wq, condition, TASK_IDLE, 0, schedule()) > + > +#define swait_event_idle(wq, condition) \ Better to have some comments before to describe the purpose of this API? Something like: /** * swait_event_idle - wait uninterruptibly without system load contribution * @wq: the waitqueue to wait on * @condition: a C expression for the event to wait for * * The process is put to sleep (TASK_IDLE) until the * @condition evaluates to true or a signal is received. * The @condition is checked each time the waitqueue @wq is woken up. * * This function is mostly used when a kthread waits some condition and * doesn't want to contribute to system load */ so is for swait_event_idle_timeout(). Thoughts? Regards, Boqun > +({ \ > + int __ret =3D 0; \ > + if (!(condition)) \ > + __ret =3D __swait_event_idle(wq, condition); \ > + __ret; \ > +}) > + > +#define __swait_event_idle_timeout(wq, condition, timeout) \ > + ___swait_event(wq, ___wait_cond_timeout(condition), \ > + TASK_IDLE, timeout, \ > + __ret =3D schedule_timeout(__ret)) > + > +#define swait_event_idle_timeout(wq, condition, timeout) \ > +({ \ > + long __ret =3D timeout; \ > + if (!___wait_cond_timeout(condition)) \ > + __ret =3D __swait_event_idle_timeout(wq, \ > + condition, timeout); \ > + __ret; \ > +}) > + > #endif /* _LINUX_SWAIT_H */ > --=20 > 2.11.0 >=20 --kunn7dzjcptzv2k2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAllDKqAACgkQSXnow7UH +ril6AgAl+EHwp8FtmfUNwBYdU9UP1mHF36TZQWEDhqhmeMWUAbmwhtD1NUpyPtk dkpqHAwSGe8P0GZc/8wQjMFyJTZ7/i6BwGi5RBfmmnAtyzQHbIT1OPUDNQYIsQh+ K5OmS/vzNFMmGU8RIsVN3FIpTugz3HayuQ32c8iiav4YnfUrsyj5fJIcrGXrlY55 zGsrpNvUNgVRxsoUb8bc7HAoxnWwjwjQmBNQOydbNnUn5nINYxCfyVKywU17Cgr9 tlENw33ok4qywo+l3WLzWNIhqParChURwW2q5B3dlID3Q5rGSIp0eRd6rh7dXE9s Asn6lZv+uGyUuz62io8H1Evksbe/xA== =Dzep -----END PGP SIGNATURE----- --kunn7dzjcptzv2k2--