summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSimon Horman <horms@verge.net.au>2013-05-22 14:50:31 +0900
committerMaciej Wereski <m.wereski@partner.samsung.com>2014-12-29 09:31:34 +0100
commitd71cd852d88a36a25b0e8ad05a5f72f540bdd085 (patch)
tree33e8a3a158c92fcb6375b8f36fe359c902c33f19 /include
parent960e9f6d75ac7720fc7af5770369d67af6adb575 (diff)
downloadlinux-3.10-d71cd852d88a36a25b0e8ad05a5f72f540bdd085.tar.gz
linux-3.10-d71cd852d88a36a25b0e8ad05a5f72f540bdd085.tar.bz2
linux-3.10-d71cd852d88a36a25b0e8ad05a5f72f540bdd085.zip
sched: add cond_resched_rcu() helper
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 benefits are for CONFIG_PREEMPT_RCU=y where we save CPU cycles by moving rcu_read_lock and rcu_read_unlock out of large loops but still allowing the current task to be preempted after every loop iteration for the CONFIG_PREEMPT_RCU=n case. The call to cond_resched() is not needed when CONFIG_PREEMPT_RCU=y. Thanks to Paul E. McKenney for explaining this and for the final version that checks the context with CONFIG_DEBUG_ATOMIC_SLEEP=y for all possible configurations. The function can be empty in the CONFIG_PREEMPT_RCU case, rcu_read_lock and rcu_read_unlock are not needed in this case because the task can be preempted on indication from scheduler. Thanks to Peter Zijlstra for catching this and for his help in trying a solution that changes __might_sleep. Initial cond_resched_rcu_lock() function suggested by Eric Dumazet. Tested-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Simon Horman <horms@verge.net.au> Acked-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Change-Id: I5f36f86484198f9064725d424c3d91d5fac8e1d4 Origin: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=f6f3c437d09e2f62533034e67bfb4385191e992c Backported-by: Maciej Wereski <m.wereski@partner.samsung.com> Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com>
Diffstat (limited to 'include')
-rw-r--r--include/linux/sched.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index f87e9a8d364..e12df9e68e3 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2462,6 +2462,15 @@ extern int __cond_resched_softirq(void);
__cond_resched_softirq(); \
})
+static inline void cond_resched_rcu(void)
+{
+#if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
+ rcu_read_unlock();
+ cond_resched();
+ rcu_read_lock();
+#endif
+}
+
/*
* Does a critical section need to be broken due to another
* task waiting?: (technically does not depend on CONFIG_PREEMPT,