Skip to contentSkip to conversation

rcutorture: Perform more frequent testing of ->gpwrap

PATCH In review Joel Fernandes 3 participants 6 messages Apr 21, 2025 – May 12, 2025

Subsystems (3)
lore
Share & tools
lore

Joel Fernandes

author maintainer
#0 lore raw

PATCH v5 1/1 rcutorture: Perform more frequent testing of ->gpwrap

Currently, the ->gpwrap is not tested (at all per my testing) due to the requirement of a large delta between a CPU's rdp->gp_seq and its node's rnp->gpseq.

This results in no testing of ->gpwrap being set. This patch by default adds 5 minutes of testing with ->gpwrap forced by lowering the delta between rdp->gp_seq and rnp->gp_seq to just 8 GPs. All of this is configurable, including the active time for the setting and a full testing cycle.

By default, the first 25 minutes of a test will have the _default_ behavior there is right now (ULONG_MAX / 4) delta. Then for 5 minutes, we switch to a smaller delta causing 1-2 wraps in 5 minutes. I believe this is reasonable since we at least add a little bit of testing for usecases where ->gpwrap is set.

---
v4->v5
- Added gpwrap_lag torture param to turn off entire test.
- replaced references to 'ovf' with 'gpwrap lag'.

Will move this to my rcu/torture-for-6.16 and update my rcu/for-next branches.

 .../admin-guide/kernel-parameters.txt         |  5 ++
 kernel/rcu/rcu.h                              |  4 ++
 kernel/rcu/rcutorture.c                       | 72 ++++++++++++++++++-
 kernel/rcu/tree.c                             | 34 ++++++++-
 kernel/rcu/tree.h                             |  1 +
 5 files changed, 113 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +5 -0
index 76e538c77e31..e1d11b6595fd 100644
@@ -5657,6 +5657,11 @@
 			are zero, rcutorture acts as if is interpreted
 			they are all non-zero.
 
+	rcutorture.gpwrap_lag= [KNL]
+			Enable grace-period wrap lag testing. Setting
+			to false prevents the gpwrap lag test from
+			running.
+
 	rcutorture.irqreader= [KNL]
 			Run RCU readers from irq handlers, or, more
 			accurately, from a timer handler.  Not all RCU
kernel/rcu/rcu.h +4 -0
index eed2951a4962..516b26024a37 100644
@@ -572,6 +572,8 @@ void do_trace_rcu_torture_read(const char *rcutorturename,
 			       unsigned long c_old,
 			       unsigned long c);
 void rcu_gp_set_torture_wait(int duration);
+void rcu_set_gpwrap_lag(unsigned long lag);
+int rcu_get_gpwrap_count(int cpu);
 #else
 static inline void rcutorture_get_gp_data(int *flags, unsigned long *gp_seq)
 {
@@ -589,6 +591,8 @@ void do_trace_rcu_torture_read(const char *rcutorturename,
 	do { } while (0)
 #endif
 static inline void rcu_gp_set_torture_wait(int duration) { }
+static inline void rcu_set_gpwrap_lag(unsigned long lag) { }
+static inline int rcu_get_gpwrap_count(int cpu) { return 0; }
 #endif
 unsigned long long rcutorture_gather_gp_seqs(void);
 void rcutorture_format_gp_seqs(unsigned long long seqs, char *cp, size_t len);
kernel/rcu/rcutorture.c +71 -1

127 lines not on this page · raw message

kernel/rcu/tree.c +32 -2
index 659f83e71048..6ec30d07759d 100644
@@ -80,6 +80,15 @@ static void rcu_sr_normal_gp_cleanup_work(struct work_struct *);
 static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, rcu_data) = {
 	.gpwrap = true,
 };
+
+int rcu_get_gpwrap_count(int cpu)
+{
+	struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
+
+	return READ_ONCE(rdp->gpwrap_count);
+}
+EXPORT_SYMBOL_GPL(rcu_get_gpwrap_count);
+
 static struct rcu_state rcu_state = {
 	.level = { &rcu_state.node[0] },
 	.gp_state = RCU_GP_IDLE,
@@ -757,6 +766,25 @@ void rcu_request_urgent_qs_task(struct task_struct *t)
 	smp_store_release(per_cpu_ptr(&rcu_data.rcu_urgent_qs, cpu), true);
 }
 
+/**
+ * rcu_set_gpwrap_lag - Set RCU GP sequence overflow lag value.
+ * @lag_gps: Set overflow lag to this many grace period worth of counters
+ * which is used by rcutorture to quickly force a gpwrap situation.
+ * @lag_gps = 0 means we reset it back to the boot-time value.
+ */
+static unsigned long seq_gpwrap_lag = ULONG_MAX / 4;
+
+void rcu_set_gpwrap_lag(unsigned long lag_gps)
+{
+	unsigned long lag_seq_count;
+
+	lag_seq_count = (lag_gps == 0)
+			? ULONG_MAX / 4
+			: lag_gps << RCU_SEQ_CTR_SHIFT;
+	WRITE_ONCE(seq_gpwrap_lag, lag_seq_count);
+}
+EXPORT_SYMBOL_GPL(rcu_set_gpwrap_lag);
+
 /*
  * When trying to report a quiescent state on behalf of some other CPU,
  * it is our responsibility to check for and handle potential overflow
@@ -767,9 +795,11 @@ void rcu_request_urgent_qs_task(struct task_struct *t)
 static void rcu_gpnum_ovf(struct rcu_node *rnp, struct rcu_data *rdp)
 {
 	raw_lockdep_assert_held_rcu_node(rnp);
-	if (ULONG_CMP_LT(rcu_seq_current(&rdp->gp_seq) + ULONG_MAX / 4,
-			 rnp->gp_seq))
+	if (ULONG_CMP_LT(rcu_seq_current(&rdp->gp_seq) + seq_gpwrap_lag,
+			 rnp->gp_seq)) {
 		WRITE_ONCE(rdp->gpwrap, true);
+		WRITE_ONCE(rdp->gpwrap_count, READ_ONCE(rdp->gpwrap_count) + 1);
+	}
 	if (ULONG_CMP_LT(rdp->rcu_iw_gp_seq + ULONG_MAX / 4, rnp->gp_seq))
 		rdp->rcu_iw_gp_seq = rnp->gp_seq + ULONG_MAX / 4;
 }
kernel/rcu/tree.h +1 -0
index a9a811d9d7a3..63bea388c243 100644
@@ -183,6 +183,7 @@ struct rcu_data {
 	bool		core_needs_qs;	/* Core waits for quiescent state. */
 	bool		beenonline;	/* CPU online at least once. */
 	bool		gpwrap;		/* Possible ->gp_seq wrap. */
+	unsigned int	gpwrap_count;	/* Count of GP sequence wrap. */
 	bool		cpu_started;	/* RCU watching this onlining CPU. */
 	struct rcu_node *mynode;	/* This CPU's leaf of hierarchy */
 	unsigned long grpmask;		/* Mask to apply to leaf qsmask. */
Signature · 1 line
2.43.0
author maintainer
#1 lore raw
Quoted 37 lines · Joel Fernandes

Currently, the ->gpwrap is not tested (at all per my testing) due to the requirement of a large delta between a CPU's rdp->gp_seq and its node's rnp->gpseq.

This results in no testing of ->gpwrap being set. This patch by default adds 5 minutes of testing with ->gpwrap forced by lowering the delta between rdp->gp_seq and rnp->gp_seq to just 8 GPs. All of this is configurable, including the active time for the setting and a full testing cycle.

By default, the first 25 minutes of a test will have the _default_ behavior there is right now (ULONG_MAX / 4) delta. Then for 5 minutes, we switch to a smaller delta causing 1-2 wraps in 5 minutes. I believe this is reasonable since we at least add a little bit of testing for usecases where ->gpwrap is set.

---
v4->v5
- Added gpwrap_lag torture param to turn off entire test.
- replaced references to 'ovf' with 'gpwrap lag'.

Will move this to my rcu/torture-for-6.16 and update my rcu/for-next branches.

 .../admin-guide/kernel-parameters.txt         |  5 ++
 kernel/rcu/rcu.h                              |  4 ++
 kernel/rcu/rcutorture.c                       | 72 ++++++++++++++++++-
 kernel/rcu/tree.c                             | 34 ++++++++-
 kernel/rcu/tree.h                             |  1 +
 5 files changed, 113 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -0
index 76e538c77e31..e1d11b6595fd 100644

Documentation/admin-guide/kernel-parameters.txt line 5664

Quoted 8 lines
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -5657,6 +5657,11 @@
 			are zero, rcutorture acts as if is interpreted
 			they are all non-zero.
 
+	rcutorture.gpwrap_lag= [KNL]
+			Enable grace-period wrap lag testing. Setting
+			to false prevents the gpwrap lag test from
+			running.
+

FYI, I added docs for the additional params here as well:

+ rcutorture.gpwrap_lag= [KNL]

+                       Enable grace-period wrap lag testing. Setting
+                       to false prevents the gpwrap lag test from
+                       running.
+
+       rcutorture.gpwrap_lag_gps= [KNL]
+                       Set the value for grace-period wrap lag during
+                       active lag testing periods. This controls how many
+                       grace periods differences we tolerate between
+                       rdp and rnp's gp_seq before setting overflow flag.
+
+       rcutorture.gpwrap_lag_cycle_mins= [KNL]
+                       Set the total cycle duration for gpwrap lag
+                       testing in minutes. This is the total time for
+                       one complete cycle of active and inactive
+                       testing periods. Default is 30 minutes.
+
+       rcutorture.gpwrap_lag_active_mins= [KNL]
+                       Set the duration for which gpwrap lag is active
+                       within each cycle, in minutes. During this time,
+                       the grace-period wrap lag will be set to the
+                       value specified by gpwrap_lag_gps. Default is
+                       5 minutes.

+

Will push this to my rcu/torture-for-6.16 and also update my rcu/for-next branch.

- Joel

maintainer
#2 lore raw
Quoted 41 lines · Joel Fernandes
Quoted 40 lines · Joel Fernandes

Currently, the ->gpwrap is not tested (at all per my testing) due to the requirement of a large delta between a CPU's rdp->gp_seq and its node's rnp->gpseq.

This results in no testing of ->gpwrap being set. This patch by default adds 5 minutes of testing with ->gpwrap forced by lowering the delta between rdp->gp_seq and rnp->gp_seq to just 8 GPs. All of this is configurable, including the active time for the setting and a full testing cycle.

By default, the first 25 minutes of a test will have the _default_ behavior there is right now (ULONG_MAX / 4) delta. Then for 5 minutes, we switch to a smaller delta causing 1-2 wraps in 5 minutes. I believe this is reasonable since we at least add a little bit of testing for usecases where ->gpwrap is set.

---
v4->v5
- Added gpwrap_lag torture param to turn off entire test.
- replaced references to 'ovf' with 'gpwrap lag'.

Will move this to my rcu/torture-for-6.16 and update my rcu/for-next branches.

 .../admin-guide/kernel-parameters.txt         |  5 ++
 kernel/rcu/rcu.h                              |  4 ++
 kernel/rcu/rcutorture.c                       | 72 ++++++++++++++++++-
 kernel/rcu/tree.c                             | 34 ++++++++-
 kernel/rcu/tree.h                             |  1 +
 5 files changed, 113 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -0
index 76e538c77e31..e1d11b6595fd 100644
@@ -5657,6 +5657,11 @@
 			are zero, rcutorture acts as if is interpreted
 			they are all non-zero.
 
Quoted 6 lines

Documentation/admin-guide/kernel-parameters.txt line 5664

Quoted 5 lines
Documentation/admin-guide/kernel-parameters.txt +5 -0
+	rcutorture.gpwrap_lag= [KNL]
+			Enable grace-period wrap lag testing. Setting
+			to false prevents the gpwrap lag test from
+			running.
+

FYI, I added docs for the additional params here as well:

Even better, thank you!

Documentation/admin-guide/kernel-parameters.txt

Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +10 -0
+       rcutorture.gpwrap_lag= [KNL]
+                       Enable grace-period wrap lag testing. Setting
+                       to false prevents the gpwrap lag test from
+                       running.
+
+       rcutorture.gpwrap_lag_gps= [KNL]
+                       Set the value for grace-period wrap lag during
+                       active lag testing periods. This controls how many
+                       grace periods differences we tolerate between
+                       rdp and rnp's gp_seq before setting overflow flag.

I suggest adding the default, as well as the default when no testing is taking place.

Thanx, Paul

Quoted 20 lines
(quoted diff) +13 -0
+       rcutorture.gpwrap_lag_cycle_mins= [KNL]
+                       Set the total cycle duration for gpwrap lag
+                       testing in minutes. This is the total time for
+                       one complete cycle of active and inactive
+                       testing periods. Default is 30 minutes.
+
+       rcutorture.gpwrap_lag_active_mins= [KNL]
+                       Set the duration for which gpwrap lag is active
+                       within each cycle, in minutes. During this time,
+                       the grace-period wrap lag will be set to the
+                       value specified by gpwrap_lag_gps. Default is
+                       5 minutes.
+

Will push this to my rcu/torture-for-6.16 and also update my rcu/for-next branch.

- Joel

author maintainer
#3 lore raw
Quoted 62 lines · Paul E. McKenney
Quoted 41 lines · Joel Fernandes
Quoted 40 lines · Joel Fernandes

Currently, the ->gpwrap is not tested (at all per my testing) due to the requirement of a large delta between a CPU's rdp->gp_seq and its node's rnp->gpseq.

This results in no testing of ->gpwrap being set. This patch by default adds 5 minutes of testing with ->gpwrap forced by lowering the delta between rdp->gp_seq and rnp->gp_seq to just 8 GPs. All of this is configurable, including the active time for the setting and a full testing cycle.

By default, the first 25 minutes of a test will have the _default_ behavior there is right now (ULONG_MAX / 4) delta. Then for 5 minutes, we switch to a smaller delta causing 1-2 wraps in 5 minutes. I believe this is reasonable since we at least add a little bit of testing for usecases where ->gpwrap is set.

---
v4->v5
- Added gpwrap_lag torture param to turn off entire test.
- replaced references to 'ovf' with 'gpwrap lag'.

Will move this to my rcu/torture-for-6.16 and update my rcu/for-next branches.

 .../admin-guide/kernel-parameters.txt         |  5 ++
 kernel/rcu/rcu.h                              |  4 ++
 kernel/rcu/rcutorture.c                       | 72 ++++++++++++++++++-
 kernel/rcu/tree.c                             | 34 ++++++++-
 kernel/rcu/tree.h                             |  1 +
 5 files changed, 113 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -0
index 76e538c77e31..e1d11b6595fd 100644
@@ -5657,6 +5657,11 @@
 			are zero, rcutorture acts as if is interpreted
 			they are all non-zero.
 
Quoted 6 lines

Documentation/admin-guide/kernel-parameters.txt line 5664

Quoted 5 lines
Documentation/admin-guide/kernel-parameters.txt +5 -0
+	rcutorture.gpwrap_lag= [KNL]
+			Enable grace-period wrap lag testing. Setting
+			to false prevents the gpwrap lag test from
+			running.
+

FYI, I added docs for the additional params here as well:

Even better, thank you!

Documentation/admin-guide/kernel-parameters.txt

Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +10 -0
+       rcutorture.gpwrap_lag= [KNL]
+                       Enable grace-period wrap lag testing. Setting
+                       to false prevents the gpwrap lag test from
+                       running.
+
+       rcutorture.gpwrap_lag_gps= [KNL]
+                       Set the value for grace-period wrap lag during
+                       active lag testing periods. This controls how many
+                       grace periods differences we tolerate between
+                       rdp and rnp's gp_seq before setting overflow flag.
Quoted 2 lines

I suggest adding the default, as well as the default when no testing is taking place.

Will do, thanks.

- Joel

#4 lore raw
In reply to Joel Fernandes

[Trimmed most CCs]

Hi Joel,

I've got a warning from "make htmldocs" on top of rcu/next:

[...]/kernel/rcu/tree.c:775: warning: cannot understand function prototype: 'unsigned long seq_gpwrap_lag = ULONG_MAX / 4; '

On Mon, 21 Apr 2025 13:47:15 -0400, Joel Fernandes wrote:
[...]

Quoted 4 lines
kernel/rcu/tree.c +0 -0
index 659f83e71048..6ec30d07759d 100644

[...]

kernel/rcu/tree.c void rcu_request_urgent_qs_task(struct task_struct *t) · line 774

Quoted 10 lines
kernel/rcu/tree.c +6 -0
@@ -757,6 +766,25 @@ void rcu_request_urgent_qs_task(struct task_struct *t)
 	smp_store_release(per_cpu_ptr(&rcu_data.rcu_urgent_qs, cpu), true);
 }
 
+/**
+ * rcu_set_gpwrap_lag - Set RCU GP sequence overflow lag value.
+ * @lag_gps: Set overflow lag to this many grace period worth of counters
+ * which is used by rcutorture to quickly force a gpwrap situation.
+ * @lag_gps = 0 means we reset it back to the boot-time value.
+ */

This kernel-doc comment should be in front of its corresponding function prototype so that it is recognized as such.

kernel/rcu/tree.c void rcu_request_urgent_qs_task(struct task_struct *t) · line 776

Quoted 2 lines
kernel/rcu/tree.c +2 -0
+static unsigned long seq_gpwrap_lag = ULONG_MAX / 4;
+

, so this static variable needs to go above the kernel-doc comment.

kernel/rcu/tree.c void rcu_request_urgent_qs_task(struct task_struct *t) · line 787

Quoted 11 lines
kernel/rcu/tree.c +11 -0
+void rcu_set_gpwrap_lag(unsigned long lag_gps)
+{
+	unsigned long lag_seq_count;
+
+	lag_seq_count = (lag_gps == 0)
+			? ULONG_MAX / 4
+			: lag_gps << RCU_SEQ_CTR_SHIFT;
+	WRITE_ONCE(seq_gpwrap_lag, lag_seq_count);
+}
+EXPORT_SYMBOL_GPL(rcu_set_gpwrap_lag);
+

You can test it by saying:

./scripts/kernel-doc -none kernel/rcu/tree.c

Thanks,
Akira

author maintainer
#5 lore raw
Quoted 14 lines · Akira Yokosawa

kernel/rcu/tree.c void rcu_request_urgent_qs_task(struct task_struct *t) · line 774

Quoted 11 lines
kernel/rcu/tree.c +6 -0
@@ -757,6 +766,25 @@ void rcu_request_urgent_qs_task(struct task_struct *t)
 	smp_store_release(per_cpu_ptr(&rcu_data.rcu_urgent_qs, cpu), true);
 }
 
+/**
+ * rcu_set_gpwrap_lag - Set RCU GP sequence overflow lag value.
+ * @lag_gps: Set overflow lag to this many grace period worth of counters
+ * which is used by rcutorture to quickly force a gpwrap situation.
+ * @lag_gps = 0 means we reset it back to the boot-time value.
+ */

This kernel-doc comment should be in front of its corresponding function prototype so that it is recognized as such.

Quoted 3 lines

Review void rcu_request_urgent_qs_task(struct task_struct *t) · line 776

Quoted 2 lines
(quoted diff) +2 -0
+static unsigned long seq_gpwrap_lag = ULONG_MAX / 4;
+

, so this static variable needs to go above the kernel-doc comment.

Thanks a lot Akira, I will fix this now.

- Joel