From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: ACJfBos5JAk9tGrLJV6T9NREbON2QFxydJtGUxSRCXD8rGmitoiQP5bTu1JGg7X1hgXJqeHG3t59 ARC-Seal: i=1; a=rsa-sha256; t=1516202779; cv=none; d=google.com; s=arc-20160816; b=OOALxmo4Hie1Utpy6kkyfRMt0d0tx4D+fw9mDlB5LYnodSxYzN+kngzbxzu/sM9Z9A e/Pk2f9wGIi4kjY/84j+gTH8NZsbVorDT3Ywv2ntPJSRCQOcdLdGrGeRApwUSW9qT4Q5 pPhV/IFsZNSwsfmRVvHgdkfZExKffpQRfNSF4YC5QtyTRBzd1zniZSfYe0Na0YD4Sk/w +5UldKPJwJ5M6RRdag4cRgM/7pyqpVvrFd8mFSltNEHVTEC9tTRiIEf8AGZ1V3BQcrQv 00v0laI1VXoEIaQ4fB+Zlx+HdEz3s/R+Ksdw5kh7N6tVAuEp7zLGU7LuoulPXVHlCGxI 1f+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:dkim-signature:arc-authentication-results; bh=6ZkmmlhRqk1mnAqVuk7nTxQIHQbFlpwJy3tygZbJ8D0=; b=1DmaJdkYQS8ks+422FwU/kC5FCj72HOd7AzI4+BwenromYWRzTIn3X9kmyStVvb/H6 LfoFrvn9ftWVAwG1hsDaYK3nDuOsR26e9/jGbo2C0uUyfS/RcCryE7VpB4kevUSryvqA SIsLvZAUDYDSBt3Lc/JULrnUQ+bO05g9Ps6kRUWs94oKEev75p9hmSolyu+ypOBArbEm EMIUtVhWReplgmH1jF7cQaoz6i96/lNdl7mCs+NPCWsbXME/wrU3o6kl7NUV9lxHLfRB 3YOIt8ChgN28ixUnIFzeESLzbUH1bQxQWHkjjogpGcqGhq99EKuJSkoaI0jO0HQKoFJP FRnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=cQ1fkPWp; spf=pass (google.com: best guess record for domain of jsimmons@infradead.org designates 2001:8b0:10b:1236::1 as permitted sender) smtp.mailfrom=jsimmons@infradead.org Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=cQ1fkPWp; spf=pass (google.com: best guess record for domain of jsimmons@infradead.org designates 2001:8b0:10b:1236::1 as permitted sender) smtp.mailfrom=jsimmons@infradead.org Date: Wed, 17 Jan 2018 15:26:15 +0000 (GMT) From: James Simmons To: NeilBrown cc: Oleg Drokin , Andreas Dilger , Greg Kroah-Hartman , lkml , lustre Subject: Re: [PATCH 01/19] sched/wait: add wait_event_idle() functions. In-Reply-To: <151538209329.23920.16297706354917686170.stgit@noble> Message-ID: References: <151538168618.23920.8261096424342988792.stgit@noble> <151538209329.23920.16297706354917686170.stgit@noble> User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180117_152615_283160_1A13B3F9 X-CRM114-Status: GOOD ( 21.42 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 NO_RELAYS Informational: message was not relayed via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1588993353800344325?= X-GMAIL-MSGID: =?utf-8?q?1589853846066710218?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: > 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() > wait_event_idle_exclusive_timeout() > > This set was chosen because lustre needs them before > it can discard its own l_wait_event() macro. Reviewed-by: James Simmons > Acked-by: Peter Zijlstra (Intel) > Signed-off-by: NeilBrown > --- > include/linux/wait.h | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 114 insertions(+) > > diff --git a/include/linux/wait.h b/include/linux/wait.h > index 158715445ffb..ec7e7c65cee6 100644 > --- a/include/linux/wait.h > +++ b/include/linux/wait.h > @@ -597,6 +597,120 @@ do { \ > __ret; \ > }) > > +/** > + * wait_event_idle - wait for a condition without contributing to 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. > + * > + * 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 to 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 if other processes wait on the same list, when this > + * process is woken 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 = schedule_timeout(__ret)) > + > +/** > + * wait_event_idle_timeout - sleep without load until a condition becomes 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 = timeout; \ > + might_sleep(); \ > + if (!___wait_cond_timeout(condition)) \ > + __ret = __wait_event_idle_timeout(wq_head, condition, timeout); \ > + __ret; \ > +}) > + > +#define __wait_event_idle_exclusive_timeout(wq_head, condition, timeout) \ > + ___wait_event(wq_head, ___wait_cond_timeout(condition), \ > + TASK_IDLE, 1, timeout, \ > + __ret = schedule_timeout(__ret)) > + > +/** > + * wait_event_idle_exclusive_timeout - sleep without load until a condition becomes 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. > + * > + * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag > + * set thus if other processes wait on the same list, when this > + * process is woken further processes are not considered. > + * > + * 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_exclusive_timeout(wq_head, condition, timeout) \ > +({ \ > + long __ret = timeout; \ > + might_sleep(); \ > + if (!___wait_cond_timeout(condition)) \ > + __ret = __wait_event_idle_exclusive_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 *); > > > >