From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756692AbdLVW7a (ORCPT ); Fri, 22 Dec 2017 17:59:30 -0500 Received: from mx2.suse.de ([195.135.220.15]:37390 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756065AbdLVW72 (ORCPT ); Fri, 22 Dec 2017 17:59:28 -0500 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "Cc" From: NeilBrown To: Peter Zijlstra Date: Sat, 23 Dec 2017 09:59:19 +1100 Cc: Ingo Molnar , linux-kernel@vger.kernel.org Cc: Oleg Drokin , Andreas Dilger , James Simmons , Patrick Farrell Subject: Re: [PATCH 1/2] sched/wait: add wait_event_idle() functions. In-Reply-To: <20171222080656.5p54fdhxqqxdtvyo@hirez.programming.kicks-ass.net> References: <151391203805.23157.8332034037737592042.stgit@noble> <151391226402.23157.5260361528373791240.stgit@noble> <20171222080656.5p54fdhxqqxdtvyo@hirez.programming.kicks-ass.net> Message-ID: <87608y8j3s.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable [removing close lustre-devel list as requested, adding assorted Lustre indi= viduals] On Fri, Dec 22 2017, Peter Zijlstra wrote: > On Fri, Dec 22, 2017 at 02:11:04PM +1100, NeilBrown wrote: >> The new TASK_IDLE state (TASK_UNINTERRUPTIBLE | __TASK_NOLOAD) >> is not much used. One way to make it easier to use is to >> add wait_event*() family functions that make use of it. >> This patch adds: >> wait_event_idle() >> wait_event_idle_timeout() >> wait_event_idle_exclusive() >>=20 >> This set were chosen because lustre needs them before >> it can discard its own l_wait_event() macro. > > Seems sane enough; please take through the tree that introduces the > first users of this. Will do. > > Acked-by: Peter Zijlstra (Intel) Thanks, NeilBrown > >> Signed-off-by: NeilBrown >> --- >> include/linux/wait.h | 77 +++++++++++++++++++++++++++++++++++++++++++= +++++++ >> 1 file changed, 77 insertions(+) >>=20 >> diff --git a/include/linux/wait.h b/include/linux/wait.h >> index 158715445ffb..3aea0780c9d0 100644 >> --- a/include/linux/wait.h >> +++ b/include/linux/wait.h >> @@ -597,6 +597,83 @@ do { \ >> __ret; \ >> }) >>=20=20 >> +/** >> + * wait_event_idle - wait for a condition with contributing to system l= oad >> + * @wq_head: 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. >> + * The @condition is checked each time the waitqueue @wq_head is woken = up. >> + * >> + * wake_up() has to be called after changing any variable that could >> + * change the result of the wait condition. >> + * >> + */ >> +#define wait_event_idle(wq_head, condition) \ >> +do { \ >> + might_sleep(); \ >> + if (!(condition)) \ >> + ___wait_event(wq_head, condition, TASK_IDLE, 0, 0, schedule()); \ >> +} while (0) >> + >> +/** >> + * wait_event_idle_exclusive - wait for a condition with contributing t= o system load >> + * @wq_head: 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. >> + * The @condition is checked each time the waitqueue @wq_head is woken = up. >> + * >> + * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag >> + * set thus when other process waits process on the list if this >> + * process is awaken further processes are not considered. >> + * >> + * wake_up() has to be called after changing any variable that could >> + * change the result of the wait condition. >> + * >> + */ >> +#define wait_event_idle_exclusive(wq_head, condition) \ >> +do { \ >> + might_sleep(); \ >> + if (!(condition)) \ >> + ___wait_event(wq_head, condition, TASK_IDLE, 1, 0, schedule()); \ >> +} while (0) >> + >> +#define __wait_event_idle_timeout(wq_head, condition, timeout) \ >> + ___wait_event(wq_head, ___wait_cond_timeout(condition), \ >> + TASK_IDLE, 0, timeout, \ >> + __ret =3D schedule_timeout(__ret)) >> + >> +/** >> + * wait_event_idle_timeout - sleep without load until a condition gets = true or a timeout elapses >> + * @wq_head: the waitqueue to wait on >> + * @condition: a C expression for the event to wait for >> + * @timeout: timeout, in jiffies >> + * >> + * The process is put to sleep (TASK_IDLE) until the >> + * @condition evaluates to true. The @condition is checked each time >> + * the waitqueue @wq_head is woken up. >> + * >> + * wake_up() has to be called after changing any variable that could >> + * change the result of the wait condition. >> + * >> + * Returns: >> + * 0 if the @condition evaluated to %false after the @timeout elapsed, >> + * 1 if the @condition evaluated to %true after the @timeout elapsed, >> + * or the remaining jiffies (at least 1) if the @condition evaluated >> + * to %true before the @timeout elapsed. >> + */ >> +#define wait_event_idle_timeout(wq_head, condition, timeout) \ >> +({ \ >> + long __ret =3D timeout; \ >> + might_sleep(); \ >> + if (!___wait_cond_timeout(condition)) \ >> + __ret =3D __wait_event_timeout(wq_head, condition, timeout); \ >> + __ret; \ >> +}) >> + >> extern int do_wait_intr(wait_queue_head_t *, wait_queue_entry_t *); >> extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *); >>=20=20 >>=20 >>=20 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlo9jkcACgkQOeye3VZi gbmVFg//bdE7nxajHz9gV5SHvKsGc9DX3dzF2xmukKQxnEe53jKjluS34d/SIASq 1Pfpa9b59oVGc2rl2jI99XWwefbPSXKxSEJrIhh/EsanhMwvbS7Rr+tBKw+X1eio Vd2pEPFllm7NWI+nV7rYjIf1E+1OlDc89o+55C6zJIovOJqvnxMc7xVrpC5EB9Nl 5lrGLNT3OMSB/27IP6eqPg9We6FbVTzqI+Nebb7J8GkPfj1y8jJ5IzQRmutWlk2+ 2sqTRZQXxOTSLFBYCkpMSEiHK08jnVdoZOxEE2lTlWeT1VoElruD7lWng8jNrGk/ iebivbhRhFfD4s5dcRrldWxJOoeH8+NXRWxBeEpCIY/2/SueEGHYaYb0PO2m3DrT 7851wxeGF89BxEX6PVyMKygekW1/5lDL9OsevzLz5TyjnoasVgka11LMGmef3zHy tPmtrNBNAraKJ0asmH3iN4+C+huzdfIxLLOQJpG/NesUZ7NoHA6C5LN2/okch92r KVv73uSvjQJOUOkAjl7ZzN2vQNnPYQJRACmvPTg+bDNWDqGdg8pAhL9Jch7RJ9M8 bsGs5PhFv7mdUkervTrxxeG8n6SEg0JVTRs8bb5X8kXkEUWDePtqBPObVmid0Cea EIXQV/6OdFsgqDn3SEnjSrBl3L5EFX99V3FI4bdkNu1kLzI7k9s= =eVAN -----END PGP SIGNATURE----- --=-=-=--