public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: "Joel Fernandes (Google)" <joel@joelfernandes.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Neeraj Upadhyay <neeraj.upadhyay@amd.com>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Uladzislau Rezki <urezki@gmail.com>, rcu <rcu@vger.kernel.org>,
	stable@vger.kernel.org, Frederic Weisbecker <frederic@kernel.org>
Subject: [PATCH 08/23] rcutorture: Fix stuttering races and other issues
Date: Tue, 10 Oct 2023 13:59:06 +0200	[thread overview]
Message-ID: <20231010115921.988766-9-frederic@kernel.org> (raw)
In-Reply-To: <20231010115921.988766-1-frederic@kernel.org>

From: "Joel Fernandes (Google)" <joel@joelfernandes.org>

The stuttering code isn't functioning as expected. Ideally, it should
pause the torture threads for a designated period before resuming. Yet,
it fails to halt the test for the correct duration. Additionally, a race
condition exists, potentially causing the stuttering code to pause for
an extended period if the 'spt' variable is non-zero due to the stutter
orchestration thread's inadequate CPU time.

Moreover, over-stuttering can hinder RCU's progress on TREE07 kernels.
This happens as the stuttering code may run within a softirq due to RCU
callbacks. Consequently, ksoftirqd keeps a CPU busy for several seconds,
thus obstructing RCU's progress. This situation triggers a warning
message in the logs:

[ 2169.481783] rcu_torture_writer: rtort_pipe_count: 9

This warning suggests that an RCU torture object, although invisible to
RCU readers, couldn't make it past the pipe array and be freed -- a
strong indication that there weren't enough grace periods during the
stutter interval.

To address these issues, this patch sets the "stutter end" time to an
absolute point in the future set by the main stutter thread. This is
then used for waiting in stutter_wait(). While the stutter thread still
defines this absolute time, the waiters' waiting logic doesn't rely on
the stutter thread receiving sufficient CPU time to halt the stuttering
as the halting is now self-controlled.

Cc: stable@vger.kernel.org
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
---
 kernel/torture.c | 45 ++++++++++++---------------------------------
 1 file changed, 12 insertions(+), 33 deletions(-)

diff --git a/kernel/torture.c b/kernel/torture.c
index 6ba62e5993e7..fd353f98162f 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -720,7 +720,7 @@ static void torture_shutdown_cleanup(void)
  * suddenly applied to or removed from the system.
  */
 static struct task_struct *stutter_task;
-static int stutter_pause_test;
+static ktime_t stutter_till_abs_time;
 static int stutter;
 static int stutter_gap;
 
@@ -730,30 +730,16 @@ static int stutter_gap;
  */
 bool stutter_wait(const char *title)
 {
-	unsigned int i = 0;
 	bool ret = false;
-	int spt;
+	ktime_t till_ns;
 
 	cond_resched_tasks_rcu_qs();
-	spt = READ_ONCE(stutter_pause_test);
-	for (; spt; spt = READ_ONCE(stutter_pause_test)) {
-		if (!ret && !rt_task(current)) {
-			sched_set_normal(current, MAX_NICE);
-			ret = true;
-		}
-		if (spt == 1) {
-			torture_hrtimeout_jiffies(1, NULL);
-		} else if (spt == 2) {
-			while (READ_ONCE(stutter_pause_test)) {
-				if (!(i++ & 0xffff))
-					torture_hrtimeout_us(10, 0, NULL);
-				cond_resched();
-			}
-		} else {
-			torture_hrtimeout_jiffies(round_jiffies_relative(HZ), NULL);
-		}
-		torture_shutdown_absorb(title);
+	till_ns = READ_ONCE(stutter_till_abs_time);
+	if (till_ns && ktime_before(ktime_get(), till_ns)) {
+		torture_hrtimeout_ns(till_ns, 0, HRTIMER_MODE_ABS, NULL);
+		ret = true;
 	}
+	torture_shutdown_absorb(title);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(stutter_wait);
@@ -764,23 +750,16 @@ EXPORT_SYMBOL_GPL(stutter_wait);
  */
 static int torture_stutter(void *arg)
 {
-	DEFINE_TORTURE_RANDOM(rand);
-	int wtime;
+	ktime_t till_ns;
 
 	VERBOSE_TOROUT_STRING("torture_stutter task started");
 	do {
 		if (!torture_must_stop() && stutter > 1) {
-			wtime = stutter;
-			if (stutter > 2) {
-				WRITE_ONCE(stutter_pause_test, 1);
-				wtime = stutter - 3;
-				torture_hrtimeout_jiffies(wtime, &rand);
-				wtime = 2;
-			}
-			WRITE_ONCE(stutter_pause_test, 2);
-			torture_hrtimeout_jiffies(wtime, NULL);
+			till_ns = ktime_add_ns(ktime_get(),
+					       jiffies_to_nsecs(stutter));
+			WRITE_ONCE(stutter_till_abs_time, till_ns);
+			torture_hrtimeout_jiffies(stutter - 1, NULL);
 		}
-		WRITE_ONCE(stutter_pause_test, 0);
 		if (!torture_must_stop())
 			torture_hrtimeout_jiffies(stutter_gap, NULL);
 		torture_shutdown_absorb("torture_stutter");
-- 
2.34.1


  parent reply	other threads:[~2023-10-10 12:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-10 11:58 [PATCH 00/23] RCU/lock torture updates for v6.7 Frederic Weisbecker
2023-10-10 11:58 ` [PATCH 01/23] torture: Share torture_random_state with torture_shuffle_tasks() Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 02/23] torture: Make kvm-recheck.sh use mktemp Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 03/23] torture: Make torture_hrtimeout_ns() take an hrtimer mode parameter Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 04/23] rcu: Include torture_sched_setaffinity() declaration Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 05/23] torture: Move rcutorture_sched_setaffinity() out of rcutorture Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 06/23] locktorture: Add readers_bind and writers_bind module parameters Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 07/23] rcutorture: Add CONFIG_DEBUG_OBJECTS to RCU Tasks testing Frederic Weisbecker
2023-10-10 11:59 ` Frederic Weisbecker [this message]
2023-10-10 11:59 ` [PATCH 09/23] locktorture: Alphabetize torture_param() entries Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 10/23] locktorture: Consolidate "if" statements in lock_torture_writer() Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 11/23] locktorture: Add acq_writer_lim to complain about long acquistion times Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 12/23] rcutorture: Copy out ftrace into its own console file Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 13/23] torture: Print out torture module parameters Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 14/23] torture: Make torture.sh refscale testing qualify verbose_batched Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 15/23] locktorture: Add new module parameters to lock_torture_print_module_parms() Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 16/23] locktorture: Add call_rcu_chains module parameter Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 17/23] doc: Catch-up update for locktorture module parameters Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 18/23] locktorture: Rename readers_bind/writers_bind to bind_readers/bind_writers Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 19/23] torture: Add kvm.sh --debug-info argument Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 20/23] rcutorture: Replace schedule_timeout*() 1-jiffy waits with HZ/20 Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 21/23] rcutorture: Traverse possible cpu to set maxcpu in rcu_nocb_toggle() Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 22/23] torture: Convert parse-console.sh to mktemp Frederic Weisbecker
2023-10-10 11:59 ` [PATCH 23/23] locktorture: Check the correct variable for allocation failure Frederic Weisbecker
2023-10-10 13:55   ` Paul E. McKenney
2023-10-10 14:07     ` Dan Carpenter
2023-10-10 15:53       ` Paul E. McKenney
2023-10-11  6:46         ` Dan Carpenter

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=20231010115921.988766-9-frederic@kernel.org \
    --to=frederic@kernel.org \
    --cc=boqun.feng@gmail.com \
    --cc=joel@joelfernandes.org \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=neeraj.upadhyay@amd.com \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    --cc=urezki@gmail.com \
    /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