Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1695143

[PATCH tip/core/rcu 08/15] swait: add idle variants which don't contribute to load average

From "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Newsgroups linux.kernel
Subject [PATCH tip/core/rcu 08/15] swait: add idle variants which don't contribute to load average
Date 2017-07-24 23:50 +0200
Message-ID <u6ToK-2fn-29@gated-at.bofh.it> (permalink)
References <u6ToJ-2fn-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: "Luis R. Rodriguez" <mcgrof@kernel.org>

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.

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=y
this would mean the load average of an idle system is bumped to 3
instead of 0.

This adds proper API using TASK_IDLE to make such goals explicit and
avoid confusion.

Suggested-by: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Tested-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 include/linux/swait.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/include/linux/swait.h b/include/linux/swait.h
index c1f9c62a8a50..4a4e180d0a35 100644
--- a/include/linux/swait.h
+++ b/include/linux/swait.h
@@ -169,4 +169,59 @@ do {									\
 	__ret;								\
 })
 
+#define __swait_event_idle(wq, condition)				\
+	(void)___swait_event(wq, condition, TASK_IDLE, 0, schedule())
+
+/**
+ * swait_event_idle - wait 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. The @condition is checked each time the waitqueue @wq is woken up.
+ *
+ * This function is mostly used when a kthread or workqueue waits for some
+ * condition and doesn't want to contribute to system load. Signals are
+ * ignored.
+ */
+#define swait_event_idle(wq, condition)					\
+do {									\
+	if (condition)							\
+		break;							\
+	__swait_event_idle(wq, condition);				\
+} while (0)
+
+#define __swait_event_idle_timeout(wq, condition, timeout)		\
+	___swait_event(wq, ___wait_cond_timeout(condition),		\
+		       TASK_IDLE, timeout,				\
+		       __ret = schedule_timeout(__ret))
+
+/**
+ * swait_event_idle_timeout - wait up to timeout without load contribution
+ * @wq: the waitqueue to wait on
+ * @condition: a C expression for the event to wait for
+ * @timeout: timeout at which we'll give up 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 is woken up.
+ *
+ * This function is mostly used when a kthread or workqueue waits for some
+ * condition and doesn't want to contribute to system load. Signals are
+ * ignored.
+ *
+ * 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 swait_event_idle_timeout(wq, condition, timeout)		\
+({									\
+	long __ret = timeout;						\
+	if (!___wait_cond_timeout(condition))				\
+		__ret = __swait_event_idle_timeout(wq,			\
+						   condition, timeout);	\
+	__ret;								\
+})
+
 #endif /* _LINUX_SWAIT_H */
-- 
2.5.2

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH tip/core/rcu 0/15] General fixes "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
  [PATCH tip/core/rcu 04/15] rcu: Create reasonable API for do_exit() TASKS_RCU processing "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
  [PATCH tip/core/rcu 09/15] rcu: use idle versions of swait to make idle-hack clear "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
  [PATCH tip/core/rcu 02/15] rcu: Use timer as backstop for NOCB deferred wakeups "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
    Re: [PATCH tip/core/rcu 02/15] rcu: Use timer as backstop for NOCB  deferred wakeups Steven Rostedt <rostedt@goodmis.org> - 2017-07-25 20:20 +0200
      Re: [PATCH tip/core/rcu 02/15] rcu: Use timer as backstop for NOCB  deferred wakeups "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-25 21:20 +0200
        Re: [PATCH tip/core/rcu 02/15] rcu: Use timer as backstop for NOCB  deferred wakeups Steven Rostedt <rostedt@goodmis.org> - 2017-07-26 00:20 +0200
          Re: [PATCH tip/core/rcu 02/15] rcu: Use timer as backstop for NOCB  deferred wakeups "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-26 02:10 +0200
            Re: [PATCH tip/core/rcu 02/15] rcu: Use timer as backstop for NOCB  deferred wakeups Steven Rostedt <rostedt@goodmis.org> - 2017-07-26 23:20 +0200
              Re: [PATCH tip/core/rcu 02/15] rcu: Use timer as backstop for NOCB  deferred wakeups "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-26 23:50 +0200
                Re: [PATCH tip/core/rcu 02/15] rcu: Use timer as backstop for NOCB  deferred wakeups Steven Rostedt <rostedt@goodmis.org> - 2017-07-27 01:10 +0200
                Re: [PATCH tip/core/rcu 02/15] rcu: Use timer as backstop for NOCB  deferred wakeups "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-27 19:40 +0200
  [PATCH tip/core/rcu 10/15] rcu: Add TPS() protection for _rcu_barrier_trace strings "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
    Re: [PATCH tip/core/rcu 10/15] rcu: Add TPS() protection for  _rcu_barrier_trace strings Steven Rostedt <rostedt@goodmis.org> - 2017-07-28 03:50 +0200
  [PATCH tip/core/rcu 14/15] rcu: Add warning to rcu_idle_enter() for irqs enabled "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
  [PATCH tip/core/rcu 01/15] sched,rcu: Make cond_resched() provide RCU quiescent state "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
  [PATCH tip/core/rcu 08/15] swait: add idle variants which don't contribute to load average "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
  [PATCH tip/core/rcu 15/15] rcu: Remove exports from rcu_idle_exit() and rcu_idle_enter() "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
  [PATCH tip/core/rcu 03/15] rcu: Drive TASKS_RCU directly off of PREEMPT "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
    Re: [PATCH tip/core/rcu 03/15] rcu: Drive TASKS_RCU directly off of  PREEMPT Steven Rostedt <rostedt@goodmis.org> - 2017-07-25 20:20 +0200
      Re: [PATCH tip/core/rcu 03/15] rcu: Drive TASKS_RCU directly off of  PREEMPT "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-25 21:20 +0200
  [PATCH tip/core/rcu 12/15] rcu: Add assertions verifying blocked-tasks list "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
  [PATCH tip/core/rcu 05/15] rcu: Add TPS() to event-traced strings "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200
    Re: [PATCH tip/core/rcu 05/15] rcu: Add TPS() to event-traced  strings Steven Rostedt <rostedt@goodmis.org> - 2017-07-28 03:40 +0200
  [PATCH tip/core/rcu 06/15] rcu: Move rcu.h to new trivial-function style "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-07-24 23:50 +0200

csiph-web