linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@elte.hu, laijs@cn.fujitsu.com, dipankar@in.ibm.com,
	akpm@linux-foundation.org, mathieu.desnoyers@polymtl.ca,
	josh@joshtriplett.org, niv@us.ibm.com, tglx@linutronix.de,
	peterz@infradead.org, rostedt@goodmis.org,
	Valdis.Kletnieks@vt.edu, dhowells@redhat.com,
	eric.dumazet@gmail.com, darren@dvhart.com, fweisbec@gmail.com,
	patches@linaro.org, "Paul E. McKenney" <paul.mckenney@linaro.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCH tip/core/rcu 36/47] rcu: Move synchronize_sched_expedited() to rcutree.c
Date: Fri,  3 Feb 2012 17:45:11 -0800	[thread overview]
Message-ID: <1328319922-30828-36-git-send-email-paulmck@linux.vnet.ibm.com> (raw)
In-Reply-To: <1328319922-30828-1-git-send-email-paulmck@linux.vnet.ibm.com>

From: "Paul E. McKenney" <paul.mckenney@linaro.org>

Now that TREE_RCU and TREE_PREEMPT_RCU no longer do anything different
for the single-CPU case, there is no need for multiple definitions of
synchronize_sched_expedited().  It is no longer in any sense a plug-in,
so move it from kernel/rcutree_plugin.h to kernel/rcutree.c.

Signed-off-by: Paul E. McKenney <paul.mckenney@linaro.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcutree.c        |  117 +++++++++++++++++++++++++++++++++++++++++++++++
 kernel/rcutree_plugin.h |  116 ----------------------------------------------
 2 files changed, 117 insertions(+), 116 deletions(-)

diff --git a/kernel/rcutree.c b/kernel/rcutree.c
index bcf7db2..05470d4 100644
--- a/kernel/rcutree.c
+++ b/kernel/rcutree.c
@@ -50,6 +50,8 @@
 #include <linux/wait.h>
 #include <linux/kthread.h>
 #include <linux/prefetch.h>
+#include <linux/delay.h>
+#include <linux/stop_machine.h>
 
 #include "rcutree.h"
 #include <trace/events/rcu.h>
@@ -1918,6 +1920,121 @@ void synchronize_rcu_bh(void)
 }
 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
 
+static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
+static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
+
+static int synchronize_sched_expedited_cpu_stop(void *data)
+{
+	/*
+	 * There must be a full memory barrier on each affected CPU
+	 * between the time that try_stop_cpus() is called and the
+	 * time that it returns.
+	 *
+	 * In the current initial implementation of cpu_stop, the
+	 * above condition is already met when the control reaches
+	 * this point and the following smp_mb() is not strictly
+	 * necessary.  Do smp_mb() anyway for documentation and
+	 * robustness against future implementation changes.
+	 */
+	smp_mb(); /* See above comment block. */
+	return 0;
+}
+
+/*
+ * Wait for an rcu-sched grace period to elapse, but use "big hammer"
+ * approach to force grace period to end quickly.  This consumes
+ * significant time on all CPUs, and is thus not recommended for
+ * any sort of common-case code.
+ *
+ * Note that it is illegal to call this function while holding any
+ * lock that is acquired by a CPU-hotplug notifier.  Failing to
+ * observe this restriction will result in deadlock.
+ *
+ * This implementation can be thought of as an application of ticket
+ * locking to RCU, with sync_sched_expedited_started and
+ * sync_sched_expedited_done taking on the roles of the halves
+ * of the ticket-lock word.  Each task atomically increments
+ * sync_sched_expedited_started upon entry, snapshotting the old value,
+ * then attempts to stop all the CPUs.  If this succeeds, then each
+ * CPU will have executed a context switch, resulting in an RCU-sched
+ * grace period.  We are then done, so we use atomic_cmpxchg() to
+ * update sync_sched_expedited_done to match our snapshot -- but
+ * only if someone else has not already advanced past our snapshot.
+ *
+ * On the other hand, if try_stop_cpus() fails, we check the value
+ * of sync_sched_expedited_done.  If it has advanced past our
+ * initial snapshot, then someone else must have forced a grace period
+ * some time after we took our snapshot.  In this case, our work is
+ * done for us, and we can simply return.  Otherwise, we try again,
+ * but keep our initial snapshot for purposes of checking for someone
+ * doing our work for us.
+ *
+ * If we fail too many times in a row, we fall back to synchronize_sched().
+ */
+void synchronize_sched_expedited(void)
+{
+	int firstsnap, s, snap, trycount = 0;
+
+	/* Note that atomic_inc_return() implies full memory barrier. */
+	firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
+	get_online_cpus();
+	WARN_ON_ONCE(cpu_is_offline(smp_processor_id()));
+
+	/*
+	 * Each pass through the following loop attempts to force a
+	 * context switch on each CPU.
+	 */
+	while (try_stop_cpus(cpu_online_mask,
+			     synchronize_sched_expedited_cpu_stop,
+			     NULL) == -EAGAIN) {
+		put_online_cpus();
+
+		/* No joy, try again later.  Or just synchronize_sched(). */
+		if (trycount++ < 10)
+			udelay(trycount * num_online_cpus());
+		else {
+			synchronize_sched();
+			return;
+		}
+
+		/* Check to see if someone else did our work for us. */
+		s = atomic_read(&sync_sched_expedited_done);
+		if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
+			smp_mb(); /* ensure test happens before caller kfree */
+			return;
+		}
+
+		/*
+		 * Refetching sync_sched_expedited_started allows later
+		 * callers to piggyback on our grace period.  We subtract
+		 * 1 to get the same token that the last incrementer got.
+		 * We retry after they started, so our grace period works
+		 * for them, and they started after our first try, so their
+		 * grace period works for us.
+		 */
+		get_online_cpus();
+		snap = atomic_read(&sync_sched_expedited_started);
+		smp_mb(); /* ensure read is before try_stop_cpus(). */
+	}
+
+	/*
+	 * Everyone up to our most recent fetch is covered by our grace
+	 * period.  Update the counter, but only if our work is still
+	 * relevant -- which it won't be if someone who started later
+	 * than we did beat us to the punch.
+	 */
+	do {
+		s = atomic_read(&sync_sched_expedited_done);
+		if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
+			smp_mb(); /* ensure test happens before caller kfree */
+			break;
+		}
+	} while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
+
+	put_online_cpus();
+}
+EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
+
 /*
  * Check to see if there is any immediate RCU-related work to be done
  * by the current CPU, for the specified type of RCU, returning 1 if so.
diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
index 7addcdf..30eaf14 100644
--- a/kernel/rcutree_plugin.h
+++ b/kernel/rcutree_plugin.h
@@ -25,7 +25,6 @@
  */
 
 #include <linux/delay.h>
-#include <linux/stop_machine.h>
 
 #define RCU_KTHREAD_PRIO 1
 
@@ -1888,121 +1887,6 @@ static void __cpuinit rcu_prepare_kthreads(int cpu)
 
 #endif /* #else #ifdef CONFIG_RCU_BOOST */
 
-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
-
-static int synchronize_sched_expedited_cpu_stop(void *data)
-{
-	/*
-	 * There must be a full memory barrier on each affected CPU
-	 * between the time that try_stop_cpus() is called and the
-	 * time that it returns.
-	 *
-	 * In the current initial implementation of cpu_stop, the
-	 * above condition is already met when the control reaches
-	 * this point and the following smp_mb() is not strictly
-	 * necessary.  Do smp_mb() anyway for documentation and
-	 * robustness against future implementation changes.
-	 */
-	smp_mb(); /* See above comment block. */
-	return 0;
-}
-
-/*
- * Wait for an rcu-sched grace period to elapse, but use "big hammer"
- * approach to force grace period to end quickly.  This consumes
- * significant time on all CPUs, and is thus not recommended for
- * any sort of common-case code.
- *
- * Note that it is illegal to call this function while holding any
- * lock that is acquired by a CPU-hotplug notifier.  Failing to
- * observe this restriction will result in deadlock.
- *
- * This implementation can be thought of as an application of ticket
- * locking to RCU, with sync_sched_expedited_started and
- * sync_sched_expedited_done taking on the roles of the halves
- * of the ticket-lock word.  Each task atomically increments
- * sync_sched_expedited_started upon entry, snapshotting the old value,
- * then attempts to stop all the CPUs.  If this succeeds, then each
- * CPU will have executed a context switch, resulting in an RCU-sched
- * grace period.  We are then done, so we use atomic_cmpxchg() to
- * update sync_sched_expedited_done to match our snapshot -- but
- * only if someone else has not already advanced past our snapshot.
- *
- * On the other hand, if try_stop_cpus() fails, we check the value
- * of sync_sched_expedited_done.  If it has advanced past our
- * initial snapshot, then someone else must have forced a grace period
- * some time after we took our snapshot.  In this case, our work is
- * done for us, and we can simply return.  Otherwise, we try again,
- * but keep our initial snapshot for purposes of checking for someone
- * doing our work for us.
- *
- * If we fail too many times in a row, we fall back to synchronize_sched().
- */
-void synchronize_sched_expedited(void)
-{
-	int firstsnap, s, snap, trycount = 0;
-
-	/* Note that atomic_inc_return() implies full memory barrier. */
-	firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
-	get_online_cpus();
-	WARN_ON_ONCE(cpu_is_offline(smp_processor_id()));
-
-	/*
-	 * Each pass through the following loop attempts to force a
-	 * context switch on each CPU.
-	 */
-	while (try_stop_cpus(cpu_online_mask,
-			     synchronize_sched_expedited_cpu_stop,
-			     NULL) == -EAGAIN) {
-		put_online_cpus();
-
-		/* No joy, try again later.  Or just synchronize_sched(). */
-		if (trycount++ < 10)
-			udelay(trycount * num_online_cpus());
-		else {
-			synchronize_sched();
-			return;
-		}
-
-		/* Check to see if someone else did our work for us. */
-		s = atomic_read(&sync_sched_expedited_done);
-		if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
-			smp_mb(); /* ensure test happens before caller kfree */
-			return;
-		}
-
-		/*
-		 * Refetching sync_sched_expedited_started allows later
-		 * callers to piggyback on our grace period.  We subtract
-		 * 1 to get the same token that the last incrementer got.
-		 * We retry after they started, so our grace period works
-		 * for them, and they started after our first try, so their
-		 * grace period works for us.
-		 */
-		get_online_cpus();
-		snap = atomic_read(&sync_sched_expedited_started);
-		smp_mb(); /* ensure read is before try_stop_cpus(). */
-	}
-
-	/*
-	 * Everyone up to our most recent fetch is covered by our grace
-	 * period.  Update the counter, but only if our work is still
-	 * relevant -- which it won't be if someone who started later
-	 * than we did beat us to the punch.
-	 */
-	do {
-		s = atomic_read(&sync_sched_expedited_done);
-		if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
-			smp_mb(); /* ensure test happens before caller kfree */
-			break;
-		}
-	} while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
-
-	put_online_cpus();
-}
-EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
-
 #if !defined(CONFIG_RCU_FAST_NO_HZ)
 
 /*
-- 
1.7.8


  parent reply	other threads:[~2012-02-04  1:54 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-04  1:44 [PATCH tip/core/rcu 0/N] v2 RCU commits for 3.4 Paul E. McKenney
2012-02-04  1:44 ` [PATCH tip/core/rcu 01/47] rcu: Bring RTFP.txt up to date Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 02/47] rcu: Improve synchronize_rcu() diagnostics Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 03/47] rcu: Add lockdep-RCU checks for simple self-deadlock Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 04/47] rcu: Add diagnostic for misaligned rcu_head structures Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 05/47] rcu: Avoid waking up CPUs having only kfree_rcu() callbacks Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 06/47] rcu: Move RCU_TRACE to lib/Kconfig.debug Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 07/47] s390: Convert call_rcu() to kfree_rcu(), drop ext_int_hash_update() Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 08/47] tcm_fc: Convert call_rcu() to kfree_rcu(), drop ft_tport_rcu_free() Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 09/47] ipv4: Convert call_rcu() to kfree_rcu(), drop opt_kfree_rcu() Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 10/47] ipv4: Convert call_rcu() to kfree_rcu(), drop opt_kfree_rcu Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 11/47] mac80211: Convert call_rcu() to kfree_rcu(), drop mesh_gate_node_reclaim() Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 12/47] rcu: Simplify offline processing Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 13/47] rcu: Make rcutorture flag online/offline failures Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 14/47] rcu: Limit lazy-callback duration Paul E. McKenney
2012-02-04 13:54     ` Frederic Weisbecker
2012-02-04 14:30       ` Paul E. McKenney
2012-02-04 14:32         ` Frederic Weisbecker
2012-02-04  1:44   ` [PATCH tip/core/rcu 15/47] rcu: Check for callback invocation from offline CPUs Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 16/47] rcu: Don't make callbacks go through second full grace period Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 17/47] rcu: Remove single-rcu_node optimization in rcu_start_gp() Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 18/47] rcu: Protect __rcu_read_unlock() against scheduler-using irq handlers Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 19/47] rcu: Streamline code produced by __rcu_read_unlock() Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 20/47] rcu: Prevent RCU callbacks from executing before scheduler initialized Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 21/47] rcu: Inform RCU of irq_exit() activity Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 22/47] rcu: Simplify unboosting checks Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 23/47] rcu: Clean up straggling rcu_preempt_needs_cpu() name Paul E. McKenney
2012-02-04  1:44   ` [PATCH tip/core/rcu 24/47] rcu: Check for idle-loop entry while in RCU read-side critical section Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 25/47] rcu: Make rcu_sleep_check() also check rcu_lock_map Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 26/47] rcu: Note that rcu_access_pointer() can be used for teardown Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 27/47] rcu: Remove #ifdef CONFIG_SMP from TREE_RCU Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 28/47] rcu: Set RCU CPU stall times via sysfs Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 29/47] rcu: Print scheduling-clock information on RCU CPU stall-warning messages Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 30/47] rcutorture: Permit holding off CPU-hotplug operations during boot Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 31/47] rcu: Make documentation give more realistic rcutorture duration Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 32/47] rcu: Add CPU-stall capability to rcutorture Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 33/47] rcu: Update stall-warning documentation Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 34/47] rcu: Make boolean rcutorture parameters be of type "bool" Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 35/47] rcu: Check for illegal use of RCU from offlined CPUs Paul E. McKenney
2012-02-04  1:45   ` Paul E. McKenney [this message]
2012-02-04  1:45   ` [PATCH tip/core/rcu 37/47] rcu: No interrupt disabling for rcu_prepare_for_idle() Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 38/47] lockdep: Add CPU-idle/offline warning to lockdep-RCU splat Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 39/47] rcu: Rework detection of use of RCU by offline CPUs Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 40/47] rcu: Call out dangers of expedited RCU primitives Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 41/47] rcu: Trace only after NULL-pointer check Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 42/47] rcu: Convert WARN_ON_ONCE() in rcu_lock_acquire() to lockdep Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 43/47] PTR_ERR should be called before its argument is cleared Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 44/47] rcu: Remove redundant check for rcu_head misalignment Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 45/47] rcu: Allow nesting of rcu_idle_enter() and rcu_idle_exit() Paul E. McKenney
2012-02-09  4:07     ` Frederic Weisbecker
2012-02-09 15:26       ` Paul E. McKenney
2012-02-09 15:33         ` Frederic Weisbecker
2012-02-04  1:45   ` [PATCH tip/core/rcu 46/47] rcu: Add RCU_NONIDLE() for idle-loop RCU read-side critical sections Paul E. McKenney
2012-02-04  1:45   ` [PATCH tip/core/rcu 47/47] cpuidle: Inform RCU of " Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1328319922-30828-36-git-send-email-paulmck@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=akpm@linux-foundation.org \
    --cc=darren@dvhart.com \
    --cc=dhowells@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=eric.dumazet@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@polymtl.ca \
    --cc=mingo@elte.hu \
    --cc=niv@us.ibm.com \
    --cc=patches@linaro.org \
    --cc=paul.mckenney@linaro.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).