mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@kernel.org, jiangshanlai@gmail.com, dipankar@in.ibm.com,
	akpm@linux-foundation.org, mathieu.desnoyers@efficios.com,
	josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org,
	rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com,
	fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCH tip/core/rcu 36/40] rcutorture: Correctly handle grace-period sequence wrap
Date: Mon, 25 Jun 2018 17:08:55 -0700	[thread overview]
Message-ID: <20180626000859.23572-36-paulmck@linux.vnet.ibm.com> (raw)
In-Reply-To: <20180626000841.GA15696@linux.vnet.ibm.com>

The new ->gq_seq grace-period sequence numbers must be shifted down,
which give artifacts when these numbers wrap.  This commit therefore
enables rcutorture and rcuperf to handle grace-period sequence numbers
even if they do wrap.  It does this by allowing a special subtraction
function to be specified, and this function subtracts before shifting.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 kernel/rcu/rcu.h        |  9 +++++++++
 kernel/rcu/rcuperf.c    | 18 ++++++++++++++++--
 kernel/rcu/rcutorture.c | 19 +++++++++++++------
 kernel/rcu/tree.c       |  6 +++---
 4 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h
index 1c5cbd9d7c97..aa215d6355f8 100644
--- a/kernel/rcu/rcu.h
+++ b/kernel/rcu/rcu.h
@@ -142,6 +142,15 @@ static inline bool rcu_seq_new_gp(unsigned long old, unsigned long new)
 			    new);
 }
 
+/*
+ * Roughly how many full grace periods have elapsed between the collection
+ * of the two specified grace periods?
+ */
+static inline unsigned long rcu_seq_diff(unsigned long new, unsigned long old)
+{
+	return (new - old) >> RCU_SEQ_CTR_SHIFT;
+}
+
 /*
  * debug_rcu_head_queue()/debug_rcu_head_unqueue() are used internally
  * by call_rcu() and rcu callback execution, and are therefore not part of the
diff --git a/kernel/rcu/rcuperf.c b/kernel/rcu/rcuperf.c
index 2b5a613afcf3..b080bc4a4f45 100644
--- a/kernel/rcu/rcuperf.c
+++ b/kernel/rcu/rcuperf.c
@@ -139,6 +139,7 @@ struct rcu_perf_ops {
 	int (*readlock)(void);
 	void (*readunlock)(int idx);
 	unsigned long (*get_gp_seq)(void);
+	unsigned long (*gp_diff)(unsigned long new, unsigned long old);
 	unsigned long (*exp_completed)(void);
 	void (*async)(struct rcu_head *head, rcu_callback_t func);
 	void (*gp_barrier)(void);
@@ -179,6 +180,7 @@ static struct rcu_perf_ops rcu_ops = {
 	.readlock	= rcu_perf_read_lock,
 	.readunlock	= rcu_perf_read_unlock,
 	.get_gp_seq	= rcu_get_gp_seq,
+	.gp_diff	= rcu_seq_diff,
 	.exp_completed	= rcu_exp_batches_completed,
 	.async		= call_rcu,
 	.gp_barrier	= rcu_barrier,
@@ -208,6 +210,7 @@ static struct rcu_perf_ops rcu_bh_ops = {
 	.readlock	= rcu_bh_perf_read_lock,
 	.readunlock	= rcu_bh_perf_read_unlock,
 	.get_gp_seq	= rcu_bh_get_gp_seq,
+	.gp_diff	= rcu_seq_diff,
 	.exp_completed	= rcu_exp_batches_completed_sched,
 	.async		= call_rcu_bh,
 	.gp_barrier	= rcu_barrier_bh,
@@ -264,6 +267,7 @@ static struct rcu_perf_ops srcu_ops = {
 	.readlock	= srcu_perf_read_lock,
 	.readunlock	= srcu_perf_read_unlock,
 	.get_gp_seq	= srcu_perf_completed,
+	.gp_diff	= rcu_seq_diff,
 	.exp_completed	= srcu_perf_completed,
 	.async		= srcu_call_rcu,
 	.gp_barrier	= srcu_rcu_barrier,
@@ -292,6 +296,7 @@ static struct rcu_perf_ops srcud_ops = {
 	.readlock	= srcu_perf_read_lock,
 	.readunlock	= srcu_perf_read_unlock,
 	.get_gp_seq	= srcu_perf_completed,
+	.gp_diff	= rcu_seq_diff,
 	.exp_completed	= srcu_perf_completed,
 	.async		= srcu_call_rcu,
 	.gp_barrier	= srcu_rcu_barrier,
@@ -321,6 +326,7 @@ static struct rcu_perf_ops sched_ops = {
 	.readlock	= sched_perf_read_lock,
 	.readunlock	= sched_perf_read_unlock,
 	.get_gp_seq	= rcu_sched_get_gp_seq,
+	.gp_diff	= rcu_seq_diff,
 	.exp_completed	= rcu_exp_batches_completed_sched,
 	.async		= call_rcu_sched,
 	.gp_barrier	= rcu_barrier_sched,
@@ -348,6 +354,7 @@ static struct rcu_perf_ops tasks_ops = {
 	.readlock	= tasks_perf_read_lock,
 	.readunlock	= tasks_perf_read_unlock,
 	.get_gp_seq	= rcu_no_completed,
+	.gp_diff	= rcu_seq_diff,
 	.async		= call_rcu_tasks,
 	.gp_barrier	= rcu_barrier_tasks,
 	.sync		= synchronize_rcu_tasks,
@@ -355,6 +362,13 @@ static struct rcu_perf_ops tasks_ops = {
 	.name		= "tasks"
 };
 
+static unsigned long rcuperf_seq_diff(unsigned long new, unsigned long old)
+{
+	if (!cur_ops->gp_diff)
+		return new - old;
+	return cur_ops->gp_diff(new, old);
+}
+
 static bool __maybe_unused torturing_tasks(void)
 {
 	return cur_ops == &tasks_ops;
@@ -577,8 +591,8 @@ rcu_perf_cleanup(void)
 			 t_rcu_perf_writer_finished -
 			 t_rcu_perf_writer_started,
 			 ngps,
-			 b_rcu_perf_writer_finished -
-			 b_rcu_perf_writer_started);
+			 rcuperf_seq_diff(b_rcu_perf_writer_finished,
+					  b_rcu_perf_writer_started));
 		for (i = 0; i < nrealwriters; i++) {
 			if (!writer_durations)
 				break;
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 81fb43530d64..0481c7286875 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -265,6 +265,7 @@ struct rcu_torture_ops {
 	void (*read_delay)(struct torture_random_state *rrsp);
 	void (*readunlock)(int idx);
 	unsigned long (*get_gp_seq)(void);
+	unsigned long (*gp_diff)(unsigned long new, unsigned long old);
 	void (*deferred_free)(struct rcu_torture *p);
 	void (*sync)(void);
 	void (*exp_sync)(void);
@@ -400,6 +401,7 @@ static struct rcu_torture_ops rcu_ops = {
 	.read_delay	= rcu_read_delay,
 	.readunlock	= rcu_torture_read_unlock,
 	.get_gp_seq	= rcu_get_gp_seq,
+	.gp_diff	= rcu_seq_diff,
 	.deferred_free	= rcu_torture_deferred_free,
 	.sync		= synchronize_rcu,
 	.exp_sync	= synchronize_rcu_expedited,
@@ -441,6 +443,7 @@ static struct rcu_torture_ops rcu_bh_ops = {
 	.read_delay	= rcu_read_delay,  /* just reuse rcu's version. */
 	.readunlock	= rcu_bh_torture_read_unlock,
 	.get_gp_seq	= rcu_bh_get_gp_seq,
+	.gp_diff	= rcu_seq_diff,
 	.deferred_free	= rcu_bh_torture_deferred_free,
 	.sync		= synchronize_rcu_bh,
 	.exp_sync	= synchronize_rcu_bh_expedited,
@@ -646,6 +649,7 @@ static struct rcu_torture_ops sched_ops = {
 	.read_delay	= rcu_read_delay,  /* just reuse rcu's version. */
 	.readunlock	= sched_torture_read_unlock,
 	.get_gp_seq	= rcu_sched_get_gp_seq,
+	.gp_diff	= rcu_seq_diff,
 	.deferred_free	= rcu_sched_torture_deferred_free,
 	.sync		= synchronize_sched,
 	.exp_sync	= synchronize_sched_expedited,
@@ -695,6 +699,13 @@ static struct rcu_torture_ops tasks_ops = {
 	.name		= "tasks"
 };
 
+static unsigned long rcutorture_seq_diff(unsigned long new, unsigned long old)
+{
+	if (!cur_ops->gp_diff)
+		return new - old;
+	return cur_ops->gp_diff(new, old);
+}
+
 static bool __maybe_unused torturing_tasks(void)
 {
 	return cur_ops == &tasks_ops;
@@ -1127,9 +1138,7 @@ static void rcu_torture_timer(struct timer_list *unused)
 		rcu_ftrace_dump(DUMP_ALL);
 	}
 	__this_cpu_inc(rcu_torture_count[pipe_count]);
-	completed = completed - started;
-	if (completed > ULONG_MAX >> 1)
-		completed = 0; /* Not all gp_seq have full range. */
+	completed = rcutorture_seq_diff(completed, started);
 	if (completed > RCU_TORTURE_PIPE_LEN) {
 		/* Should not happen, but... */
 		completed = RCU_TORTURE_PIPE_LEN;
@@ -1205,9 +1214,7 @@ rcu_torture_reader(void *arg)
 			rcu_ftrace_dump(DUMP_ALL);
 		}
 		__this_cpu_inc(rcu_torture_count[pipe_count]);
-		completed = completed - started;
-		if (completed > ULONG_MAX >> 1)
-			completed = 0; /* Not all gp_seq have full range. */
+		completed = rcutorture_seq_diff(completed, started);
 		if (completed > RCU_TORTURE_PIPE_LEN) {
 			/* Should not happen, but... */
 			completed = RCU_TORTURE_PIPE_LEN;
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 446163b6feba..fa82f0413d2c 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -532,7 +532,7 @@ static int rcu_pending(void);
  */
 unsigned long rcu_get_gp_seq(void)
 {
-	return rcu_seq_ctr(READ_ONCE(rcu_state_p->gp_seq));
+	return READ_ONCE(rcu_state_p->gp_seq);
 }
 EXPORT_SYMBOL_GPL(rcu_get_gp_seq);
 
@@ -541,7 +541,7 @@ EXPORT_SYMBOL_GPL(rcu_get_gp_seq);
  */
 unsigned long rcu_sched_get_gp_seq(void)
 {
-	return rcu_seq_ctr(READ_ONCE(rcu_sched_state.gp_seq));
+	return READ_ONCE(rcu_sched_state.gp_seq);
 }
 EXPORT_SYMBOL_GPL(rcu_sched_get_gp_seq);
 
@@ -550,7 +550,7 @@ EXPORT_SYMBOL_GPL(rcu_sched_get_gp_seq);
  */
 unsigned long rcu_bh_get_gp_seq(void)
 {
-	return rcu_seq_ctr(READ_ONCE(rcu_bh_state.gp_seq));
+	return READ_ONCE(rcu_bh_state.gp_seq);
 }
 EXPORT_SYMBOL_GPL(rcu_bh_get_gp_seq);
 
-- 
2.17.1


  parent reply	other threads:[~2018-06-26  0:10 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-26  0:08 [PATCH tip/core/rcu 0/40] RCU ->gp_seq conversion for v4.19 Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 01/40] rcu: Introduce grace-period sequence numbers Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 02/40] rcu: Move rcu_gp_slow() to ->gp_seq Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 03/40] rcu: Make rcutorture's batches-completed API use ->gp_seq Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 04/40] rcu: Convert rcu_check_gp_kthread_starvation() to GP sequence number Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 05/40] rcu: Make quiescent-state reporting use ->gp_seq Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 06/40] rcu: Convert conditional grace-period primitives to ->gp_seq Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 07/40] rcu: Move RCU's grace-period-change code " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 08/40] rcu: Convert rcu_gpnum_ovf() " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 09/40] rcu: Move rcu_implicit_dynticks_qs() " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 10/40] rcu: Move rcu_try_advance_all_cbs() " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 11/40] rcu: Move rcu_nocb_gp_get() " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 12/40] rcu: Move rcu_gp_in_progress() " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 13/40] rcu: Convert ->rcu_iw_gpnum " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 14/40] rcu: Convert ->completedqs " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 15/40] rcu: Convert grace-period requests " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 16/40] rcu: Make RCU CPU stall warnings use ->gp_seq Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 17/40] rcutorture: Convert rcutorture_get_gp_data() to ->gp_seq Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 18/40] rcu: Move from ->need_future_gp[] to ->gp_seq_needed Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 19/40] rcu: Make rcu_nocb_wait_gp() check if GP already requested Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 20/40] rcu: Convert rcu_grace_period tracepoint to gp_seq Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 21/40] rcu: Convert rcu_future_grace_period " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 22/40] rcu: Convert rcu_grace_period_init " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 23/40] rcu: Convert rcu_preempt_task tracepoint to ->gp_seq Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 24/40] rcu: Convert rcu_unlock_preempted_task " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 25/40] rcu: Convert rcu_quiescent_state_report " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 26/40] rcu: Convert rcu_fqs " Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 27/40] rcu: Remove ->gpnum and ->completed Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 28/40] rcu: Make simple callback acceleration refer to rdp->gp_seq_needed Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 29/40] doc: Update data-structure documentation for ->gp_seq Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 30/40] doc: Update memory-ordering documentation for ->gp-seq Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 31/40] doc: Update RCU CPU stall-warning documentation Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 32/40] rcu: Don't funnel-lock above leaf node if GP in progress Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 33/40] rcu: Produce last "CleanupMore" trace only if late-breaking request Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 34/40] rcu: Fix cpustart tracepoint gp_seq number Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 35/40] rcu: Make rcu_start_this_gp() check for grace period already started Paul E. McKenney
2018-06-26  0:08 ` Paul E. McKenney [this message]
2018-06-26  0:08 ` [PATCH tip/core/rcu 37/40] rcu: Regularize resetting of rcu_data wrap indicator Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 38/40] rcu: Rename the grace-period-request variables and parameters Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 39/40] rcu: Use better variable names in funnel locking loop Paul E. McKenney
2018-06-26  0:08 ` [PATCH tip/core/rcu 40/40] rcu: Identify grace period is in progress as we advance up the tree 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=20180626000859.23572-36-paulmck@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=edumazet@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jiangshanlai@gmail.com \
    --cc=joel@joelfernandes.org \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --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

all inboxes | Powered by JetHome®