Patchwork [v3,1/2] sched: Add cond_resched_rcu_lock() helper

mail settings
Submitter Simon Horman
Date May 1, 2013, 8:57 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/240743/
State Not Applicable
Headers show


Simon Horman - May 1, 2013, 8:57 a.m.
This is intended for use in loops which read data protected by RCU and may
have a large number of iterations.  Such an example is dumping the list of
connections known to IPVS: ip_vs_conn_array() and ip_vs_conn_seq_next().

The call to cond_resched() is guarded by #ifndef CONFIG_PREEMPT_RCU as in
the case of CONFIG_PREEMPT_RCU _rcu_read_unlock() will check to see if the
RCU core needs to be informed, so there is no need to invoke cond_resched()
in that case. Thanks to Paul E. McKenney for explaining this.

cond_resched_rcu_lock() suggested by Eric Dumazet.
ifndef guard suggested by Paul E. McKenney and Julian Anastasov.

Cc: Eric Dumazet <>
Cc: Paul E. McKenney <>
Cc: Julian Anastasov <>
Acked-by: Ingo Molnar <>
Signed-off-by: Simon Horman <>


* Remove if (need_resched()), it is no longer needed with
  the guard added in v2.

* Guard the call to cond_resched() with #ifndef CONFIG_PREEMPT_RCU
 include/linux/sched.h | 9 +++++++++
 1 file changed, 9 insertions(+)


diff --git a/include/linux/sched.h b/include/linux/sched.h
index e692a02..79cfe6d 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2787,3 +2787,12 @@  static inline unsigned long rlimit_max(unsigned int limit)
+static void inline cond_resched_rcu_lock(void)
+	rcu_read_unlock();
+	cond_resched();
+	rcu_read_lock();