summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>2016-11-29 13:13:47 -0800
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2016-12-05 09:24:46 -0800
commit15705d6709cb6ba6183dec6497856c7a78401c63 (patch)
treeb1ee4277604ff000b17928118212ffc7f23e83dc /kernel
parent49f462e13f9aaa4692471a6bbf7a9d38919ac304 (diff)
rcu: Add functions to test for trivial grace periods
Under some circumstances, RCU grace periods are zero cost. For RCU-preempt, this is the case during boot, and for RCU-bh and RCU-sched, this is the case if there is only one CPU. This means that RCU users might wish to dispense with grace-period-avoidance strategies when grace periods are zero cost, so this commit adds rcu_trivial_gp(), rcu_bh_trivial_gp(), and rcu_sched_trivial_gp() to test for these conditions. Because the conditions leading to zero-cost grace periods can change at any time (for example, when a second CPU is onlined), these functions should be used as performance hints, and must not be relied on for correctness. For example, even if rcu_trivial_gp() returns true, you are required to invoke synchronize_rcu(). Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/rcu/tree.c24
-rw-r--r--kernel/rcu/tree_plugin.h11
2 files changed, 35 insertions, 0 deletions
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 991c62f2f1ca..50cb208c64fe 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -3418,6 +3418,18 @@ void synchronize_sched(void)
EXPORT_SYMBOL_GPL(synchronize_sched);
/**
+ * rcu_sched_trivial_gp - Are RCU-sched grace periods trivially zero cost?
+ *
+ * Returns true if RCU-sched grace periods are currently zero cost, which
+ * they are if there is only one CPU. Note that unless you take steps to
+ * prevent it, the number of CPUs might change at any time.
+ */
+bool rcu_sched_trivial_gp(void)
+{
+ return rcu_blocking_is_gp();
+}
+
+/**
* synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed.
*
* Control will return to the caller some time after a full rcu_bh grace
@@ -3445,6 +3457,18 @@ void synchronize_rcu_bh(void)
EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
/**
+ * rcu_bh_trivial_gp - Are RCU-bh grace periods trivially zero cost?
+ *
+ * Returns true if RCU-bh grace periods are currently zero cost, which
+ * they are if there is only one CPU. Note that unless you take steps to
+ * prevent it, the number of CPUs might change at any time.
+ */
+bool rcu_bh_trivial_gp(void)
+{
+ return rcu_blocking_is_gp();
+}
+
+/**
* get_state_synchronize_rcu - Snapshot current RCU state
*
* Returns a cookie that is used by a later call to cond_synchronize_rcu()
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index 98cd997b078e..69c6eb27c37f 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -680,6 +680,17 @@ void synchronize_rcu(void)
EXPORT_SYMBOL_GPL(synchronize_rcu);
/**
+ * rcu_trivial_gp - Are RCU grace periods trivially zero cost?
+ *
+ * Returns true if RCU grace periods are currently zero cost, which
+ * they are during boot.
+ */
+bool rcu_trivial_gp(void)
+{
+ return !rcu_scheduler_active;
+}
+
+/**
* rcu_barrier - Wait until all in-flight call_rcu() callbacks complete.
*
* Note that this primitive does not necessarily wait for an RCU grace period