Skip to contentSkip to conversation

RCU torture for v6.13

PATCH In review Frederic Weisbecker 3 participants 11 messages Nov 6, 2024 – Nov 11, 2024

Subsystems (4)
lore
Share & tools
lore

Frederic Weisbecker

author maintainer
#0 lore raw

cover RCU torture for v6.13

Hello,

Please find below the RCU NOCB patches targeted for the upcoming merge window.

Paul E. McKenney (4):
torture: Add --no-affinity parameter to kvm.sh
refscale: Correct affinity check
rcuscale: Add guest_os_delay module parameter
rcutorture: Avoid printing cpu=-1 for no-fault RCU boost failure

Uladzislau Rezki (Sony) (2):
rcuscale: Do a proper cleanup if kfree_scale_init() fails
rcuscale: Remove redundant WARN_ON_ONCE() splat

 kernel/rcu/rcuscale.c                         |  6 +--
 kernel/rcu/rcutorture.c                       |  9 +++-
 kernel/rcu/refscale.c                         | 19 +++++++-
 .../rcutorture/bin/kvm-test-1-run-batch.sh    | 43 ++++++++++---------
 tools/testing/selftests/rcutorture/bin/kvm.sh |  6 +++
 5 files changed, 56 insertions(+), 27 deletions(-)

Thanks.

Signature · 1 line
2.46.0
author maintainer
#1 lore raw

PATCH 1/6 torture: Add --no-affinity parameter to kvm.sh

From: "Paul E. McKenney" <[email protected]>

In performance tests, it can be counter-productive to spread torture-test guest OSes across sockets. Plus the experimenter might have ideas about what CPUs individual guest OSes are to run on. This commit therefore adds a --no-affinity parameter to kvm.sh to prevent it from running taskset on its guest OSes.

---
 .../rcutorture/bin/kvm-test-1-run-batch.sh    | 43 ++++++++++---------
 tools/testing/selftests/rcutorture/bin/kvm.sh |  6 +++
 2 files changed, 29 insertions(+), 20 deletions(-)
tools/testing/selftests/rcutorture/bin/kvm-test-1-run-batch.sh +23 -20
index c3808c490d92..f87046b702d8 100755
@@ -56,27 +56,30 @@ do
 	echo > $i/kvm-test-1-run-qemu.sh.out
 	export TORTURE_AFFINITY=
 	kvm-get-cpus-script.sh $T/cpuarray.awk $T/cpubatches.awk $T/cpustate
-	cat << '	___EOF___' >> $T/cpubatches.awk
-	END {
-		affinitylist = "";
-		if (!gotcpus()) {
-			print "echo No CPU-affinity information, so no taskset command.";
-		} else if (cpu_count !~ /^[0-9][0-9]*$/) {
-			print "echo " scenario ": Bogus number of CPUs (old qemu-cmd?), so no taskset command.";
-		} else {
-			affinitylist = nextcpus(cpu_count);
-			if (!(affinitylist ~ /^[0-9,-][0-9,-]*$/))
-				print "echo " scenario ": Bogus CPU-affinity information, so no taskset command.";
-			else if (!dumpcpustate())
-				print "echo " scenario ": Could not dump state, so no taskset command.";
-			else
-				print "export TORTURE_AFFINITY=" affinitylist;
+	if test -z "${TORTURE_NO_AFFINITY}"
+	then
+		cat << '		___EOF___' >> $T/cpubatches.awk
+		END {
+			affinitylist = "";
+			if (!gotcpus()) {
+				print "echo No CPU-affinity information, so no taskset command.";
+			} else if (cpu_count !~ /^[0-9][0-9]*$/) {
+				print "echo " scenario ": Bogus number of CPUs (old qemu-cmd?), so no taskset command.";
+			} else {
+				affinitylist = nextcpus(cpu_count);
+				if (!(affinitylist ~ /^[0-9,-][0-9,-]*$/))
+					print "echo " scenario ": Bogus CPU-affinity information, so no taskset command.";
+				else if (!dumpcpustate())
+					print "echo " scenario ": Could not dump state, so no taskset command.";
+				else
+					print "export TORTURE_AFFINITY=" affinitylist;
+			}
 		}
-	}
-	___EOF___
-	cpu_count="`grep '# TORTURE_CPU_COUNT=' $i/qemu-cmd | sed -e 's/^.*=//'`"
-	affinity_export="`awk -f $T/cpubatches.awk -v cpu_count="$cpu_count" -v scenario=$i < /dev/null`"
-	$affinity_export
+		___EOF___
+		cpu_count="`grep '# TORTURE_CPU_COUNT=' $i/qemu-cmd | sed -e 's/^.*=//'`"
+		affinity_export="`awk -f $T/cpubatches.awk -v cpu_count="$cpu_count" -v scenario=$i < /dev/null`"
+		$affinity_export
+	fi
 	kvm-test-1-run-qemu.sh $i >> $i/kvm-test-1-run-qemu.sh.out 2>&1 &
 done
 for i in $runfiles
tools/testing/selftests/rcutorture/bin/kvm.sh +6 -0
index 7af73ddc148d..42e5e8597a1a 100755
@@ -42,6 +42,7 @@ TORTURE_JITTER_STOP=""
 TORTURE_KCONFIG_KASAN_ARG=""
 TORTURE_KCONFIG_KCSAN_ARG=""
 TORTURE_KMAKE_ARG=""
+TORTURE_NO_AFFINITY=""
 TORTURE_QEMU_MEM=512
 torture_qemu_mem_default=1
 TORTURE_REMOTE=
@@ -82,6 +83,7 @@ usage () {
 	echo "       --kmake-arg kernel-make-arguments"
 	echo "       --mac nn:nn:nn:nn:nn:nn"
 	echo "       --memory megabytes|nnnG"
+	echo "       --no-affinity"
 	echo "       --no-initrd"
 	echo "       --qemu-args qemu-arguments"
 	echo "       --qemu-cmd qemu-system-..."
@@ -220,6 +222,9 @@ do
 		torture_qemu_mem_default=
 		shift
 		;;
+	--no-affinity)
+		TORTURE_NO_AFFINITY="no-affinity"
+		;;
 	--no-initrd)
 		TORTURE_INITRD=""; export TORTURE_INITRD
 		;;
@@ -417,6 +422,7 @@ TORTURE_KCONFIG_KASAN_ARG="$TORTURE_KCONFIG_KASAN_ARG"; export TORTURE_KCONFIG_K
 TORTURE_KCONFIG_KCSAN_ARG="$TORTURE_KCONFIG_KCSAN_ARG"; export TORTURE_KCONFIG_KCSAN_ARG
 TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
 TORTURE_MOD="$TORTURE_MOD"; export TORTURE_MOD
+TORTURE_NO_AFFINITY="$TORTURE_NO_AFFINITY"; export TORTURE_NO_AFFINITY
 TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
 TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
 TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
Signature · 1 line
2.46.0
author maintainer
#2 lore raw

PATCH 2/6 refscale: Correct affinity check

In reply to Frederic Weisbecker

From: "Paul E. McKenney" <[email protected]>

The current affinity check works fine until there are more reader processes than CPUs, at which point the affinity check is looking for non-existent CPUs. This commit therefore applies the same modulus to the check as is present in the set_cpus_allowed_ptr() call.

---
 kernel/rcu/refscale.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/refscale.c +1 -1
index 0db9db73f57f..25910ebe95c0 100644
@@ -829,7 +829,7 @@ ref_scale_reader(void *arg)
 		goto end;
 
 	// Make sure that the CPU is affinitized appropriately during testing.
-	WARN_ON_ONCE(raw_smp_processor_id() != me);
+	WARN_ON_ONCE(raw_smp_processor_id() != me % nr_cpu_ids);
 
 	WRITE_ONCE(rt->start_reader, 0);
 	if (!atomic_dec_return(&n_started))
Signature · 1 line
2.46.0
author maintainer
#3 lore raw

PATCH 3/6 rcuscale: Add guest_os_delay module parameter

In reply to Frederic Weisbecker

From: "Paul E. McKenney" <[email protected]>

This commit adds a guest_os_delay module parameter that extends warm-up and cool-down the specified number of seconds before and after the series of test runs. This allows the data-collection intervals from any given rcuscale guest OSes to line up with active periods in the other rcuscale guest OSes, and also allows the thermal warm-up period required to obtain consistent results from one test to the next.

---
 kernel/rcu/refscale.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
kernel/rcu/refscale.c +17 -0
index 25910ebe95c0..c8374760e003 100644
@@ -75,6 +75,9 @@ MODULE_PARM_DESC(scale_type, "Type of test (rcu, srcu, refcnt, rwsem, rwlock.");
 torture_param(int, verbose, 0, "Enable verbose debugging printk()s");
 torture_param(int, verbose_batched, 0, "Batch verbose debugging printk()s");
 
+// Number of seconds to extend warm-up and cool-down for multiple guest OSes
+torture_param(long, guest_os_delay, 0,
+	      "Number of seconds to extend warm-up/cool-down for multiple guest OSes.");
 // Wait until there are multiple CPUs before starting test.
 torture_param(int, holdoff, IS_BUILTIN(CONFIG_RCU_REF_SCALE_TEST) ? 10 : 0,
 	      "Holdoff time before test start (s)");
@@ -801,6 +804,18 @@ static void rcu_scale_one_reader(void)
 		cur_ops->delaysection(loops, readdelay / 1000, readdelay % 1000);
 }
 
+// Warm up cache, or, if needed run a series of rcu_scale_one_reader()
+// to allow multiple rcuscale guest OSes to collect mutually valid data.
+static void rcu_scale_warm_cool(void)
+{
+	unsigned long jdone = jiffies + (guest_os_delay > 0 ? guest_os_delay * HZ : -1);
+
+	do {
+		rcu_scale_one_reader();
+		cond_resched();
+	} while (time_before(jiffies, jdone));
+}
+
 // Reader kthread.  Repeatedly does empty RCU read-side
 // critical section, minimizing update-side interference.
 static int
@@ -957,6 +972,7 @@ static int main_func(void *arg)
 		schedule_timeout_uninterruptible(1);
 
 	// Start exp readers up per experiment
+	rcu_scale_warm_cool();
 	for (exp = 0; exp < nruns && !torture_must_stop(); exp++) {
 		if (torture_must_stop())
 			goto end;
@@ -987,6 +1003,7 @@ static int main_func(void *arg)
 
 		result_avg[exp] = div_u64(1000 * process_durations(nreaders), nreaders * loops);
 	}
+	rcu_scale_warm_cool();
 
 	// Print the average of all experiments
 	SCALEOUT("END OF TEST. Calculating average duration per loop (nanoseconds)...\n");
Signature · 1 line
2.46.0
author maintainer
#4 lore raw

PATCH 4/6 rcutorture: Avoid printing cpu=-1 for no-fault RCU boost failure

In reply to Frederic Weisbecker

From: "Paul E. McKenney" <[email protected]>

If a CPU runs throughout the stalled grace period without passing through a quiescent state, RCU priority boosting cannot help. The rcu_torture_boost_failed() function therefore prints a message flagging the first such CPU. However, if the stall was instead due to (for example) RCU's grace-period kthread being starved of CPU, there will be no such CPU, causing rcu_check_boost_fail() to instead pass back -1 through its cpup CPU-pointer parameter.

Therefore, the current message complains about a mythical CPU -1.

This commit therefore checks for this situation, and notes that all CPUs have passed through a quiescent state.

---
 kernel/rcu/rcutorture.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
kernel/rcu/rcutorture.c +7 -2
index bb75dbf5c800..e92fa97fc76f 100644
@@ -1059,8 +1059,13 @@ static bool rcu_torture_boost_failed(unsigned long gp_state, unsigned long *star
 			// At most one persisted message per boost test.
 			j = jiffies;
 			lp = READ_ONCE(last_persist);
-			if (time_after(j, lp + mininterval) && cmpxchg(&last_persist, lp, j) == lp)
-				pr_info("Boost inversion persisted: No QS from CPU %d\n", cpu);
+			if (time_after(j, lp + mininterval) &&
+			    cmpxchg(&last_persist, lp, j) == lp) {
+				if (cpu < 0)
+					pr_info("Boost inversion persisted: QS from all CPUs\n");
+				else
+					pr_info("Boost inversion persisted: No QS from CPU %d\n", cpu);
+			}
 			return false; // passed on a technicality
 		}
 		VERBOSE_TOROUT_STRING("rcu_torture_boost boosting failed");
Signature · 1 line
2.46.0
author maintainer
#5 lore raw

PATCH 5/6 rcuscale: Do a proper cleanup if kfree_scale_init() fails

In reply to Frederic Weisbecker

From: "Uladzislau Rezki (Sony)" <[email protected]>

A static analyzer for C, Smatch, reports and triggers below warnings:

kernel/rcu/rcuscale.c:1215 rcu_scale_init()
warn: inconsistent returns 'global &fullstop_mutex'.

The checker complains about, we do not unlock the "fullstop_mutex" mutex, in case of hitting below error path:

<snip>
...

    if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
        pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
        WARN_ON_ONCE(1);
        return -1;
        ^^^^^^^^^^

...
<snip>

it happens because "-1" is returned right away instead of doing a proper unwinding.

Fix it by jumping to "unwind" label instead of returning -1.

---
 kernel/rcu/rcuscale.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/rcu/rcuscale.c +2 -2
index 6d37596deb1f..de7d511e6be4 100644
@@ -890,13 +890,13 @@ kfree_scale_init(void)
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
 			WARN_ON_ONCE(1);
-			return -1;
+			goto unwind;
 		}
 
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
 			WARN_ON_ONCE(1);
-			return -1;
+			goto unwind;
 		}
 	}
 
Signature · 1 line
2.46.0
#6 lore raw

Re: [PATCH 5/6] rcuscale: Do a proper cleanup if kfree_scale_init() fails

kernel/rcu/rcuscale.c kfree_scale_init(void) · line 893

Quoted 11 lines
kernel/rcu/rcuscale.c +1 -1
index 6d37596deb1f..de7d511e6be4 100644
@@ -890,13 +890,13 @@ kfree_scale_init(void)
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
 			WARN_ON_ONCE(1);
-			return -1;
+			goto unwind;

Do we need to set firsterr = -1 here before "goto unwind"? Otherwise, 0 is returned from kfree_scale_init().

kernel/rcu/rcuscale.c kfree_scale_init(void) · line 899

Quoted 7 lines
kernel/rcu/rcuscale.c +1 -1
 		}
 
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
 			WARN_ON_ONCE(1);
-			return -1;
+			goto unwind;

Ditto

- Neeraj

Quoted 3 lines
kernel/rcu/rcuscale.c +0 -0
 		}
 	}
 
maintainer
#7 lore raw

Re: [PATCH 5/6] rcuscale: Do a proper cleanup if kfree_scale_init() fails

Quoted 17 lines · Neeraj Upadhyay

kernel/rcu/rcuscale.c kfree_scale_init(void) · line 893

Quoted 11 lines
kernel/rcu/rcuscale.c +1 -1
index 6d37596deb1f..de7d511e6be4 100644
@@ -890,13 +890,13 @@ kfree_scale_init(void)
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
 			WARN_ON_ONCE(1);
-			return -1;
+			goto unwind;

Do we need to set firsterr = -1 here before "goto unwind"? Otherwise, 0 is returned from kfree_scale_init().

Quoted 2 lines
kernel/rcu/rcuscale.c +0 -0
 		}
 
Quoted 8 lines

kernel/rcu/rcuscale.c kfree_scale_init(void) · line 899

Quoted 5 lines
kernel/rcu/rcuscale.c +1 -1
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
 			WARN_ON_ONCE(1);
-			return -1;
+			goto unwind;

Ditto

Let me check it!

--
Uladzislau Rezki

maintainer
#8 lore raw

Re: [PATCH 5/6] rcuscale: Do a proper cleanup if kfree_scale_init() fails

Quoted 26 lines · Uladzislau Rezki
Quoted 17 lines · Neeraj Upadhyay

kernel/rcu/rcuscale.c kfree_scale_init(void) · line 893

Quoted 11 lines
kernel/rcu/rcuscale.c +1 -1
index 6d37596deb1f..de7d511e6be4 100644
@@ -890,13 +890,13 @@ kfree_scale_init(void)
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
 			WARN_ON_ONCE(1);
-			return -1;
+			goto unwind;

Do we need to set firsterr = -1 here before "goto unwind"? Otherwise, 0 is returned from kfree_scale_init().

Quoted 2 lines
kernel/rcu/rcuscale.c +0 -0
 		}
 
Quoted 8 lines

kernel/rcu/rcuscale.c kfree_scale_init(void) · line 899

Quoted 5 lines
kernel/rcu/rcuscale.c +1 -1
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
 			WARN_ON_ONCE(1);
-			return -1;
+			goto unwind;

Ditto

Quoted 2 lines

Let me check it!

Right you are. I will repost the patch to be align with a previous behaviour.

Thanks!

--
Uladzislau Rezki

author maintainer
#9 lore raw

PATCH 6/6 rcuscale: Remove redundant WARN_ON_ONCE() splat

In reply to Frederic Weisbecker

From: "Uladzislau Rezki (Sony)" <[email protected]>

There are two places where WARN_ON_ONCE() is called two times in the error paths. One which is encapsulated into if() condition and another one, which is unnecessary, is placed in the brackets.

Remove an extra WARN_ON_ONCE() splat which is in brackets.

---
 kernel/rcu/rcuscale.c | 2 --
 1 file changed, 2 deletions(-)
kernel/rcu/rcuscale.c +0 -2
index de7d511e6be4..1d8bb603c289 100644
@@ -889,13 +889,11 @@ kfree_scale_init(void)
 
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
-			WARN_ON_ONCE(1);
 			goto unwind;
 		}
 
 		if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
 			pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
-			WARN_ON_ONCE(1);
 			goto unwind;
 		}
 	}
Signature · 1 line
2.46.0
Reviewed-by on the v1 series
#10 lore raw
In reply to Frederic Weisbecker
Quoted 15 lines · Frederic Weisbecker

Hello,

Please find below the RCU NOCB patches targeted for the upcoming merge window.

Paul E. McKenney (4):
torture: Add --no-affinity parameter to kvm.sh
refscale: Correct affinity check
rcuscale: Add guest_os_delay module parameter
rcutorture: Avoid printing cpu=-1 for no-fault RCU boost failure

Uladzislau Rezki (Sony) (2):
rcuscale: Do a proper cleanup if kfree_scale_init() fails
rcuscale: Remove redundant WARN_ON_ONCE() splat

Quoted 8 lines
 kernel/rcu/rcuscale.c                         |  6 +--
 kernel/rcu/rcutorture.c                       |  9 +++-
 kernel/rcu/refscale.c                         | 19 +++++++-
 .../rcutorture/bin/kvm-test-1-run-batch.sh    | 43 ++++++++++---------
 tools/testing/selftests/rcutorture/bin/kvm.sh |  6 +++
 5 files changed, 56 insertions(+), 27 deletions(-)

Thanks.

- Neeraj