torture: Periodically pause in stutter_wait() Running locktorture scenario LOCK05 results in hangs: tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --torture lock --duration 3 --configs LOCK05 The lock_torture_writer() kthreads set themselves to MAX_NICE while running SCHED_OTHER. Other locktorture kthreads run at default niceness, also SCHED_OTHER. This results in these other locktorture kthreads indefinitely preempting the lock_torture_writer() kthreads. Note that the cond_resched() in the stutter_wait() function's loop is ineffective because this scenario is built with CONFIG_PREEMPT=y. It is not clear that such indefinite preemption is supposed to happen, but in the meantime this commit prevents kthreads running in stutter_wait() from being completely CPU-bound, thus allowing the other threads to get some CPU in a timely fashion. Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
diff --git a/kernel/torture.c b/kernel/torture.c index 1061492..9310c1d 100644 --- a/kernel/torture.c +++ b/kernel/torture.c
@@ -602,6 +602,7 @@ static int stutter_gap; */ bool stutter_wait(const char *title) { + unsigned i = 0; int spt; bool ret = false; @@ -612,8 +613,13 @@ bool stutter_wait(const char *title) if (spt == 1) { schedule_timeout_interruptible(1); } else if (spt == 2) { - while (READ_ONCE(stutter_pause_test)) + while (READ_ONCE(stutter_pause_test)) { + if (!(++i & 0xffff)) + schedule_timeout_interruptible(1); + else if (!(i & 0xfff)) + udelay(1); cond_resched(); + } } else { schedule_timeout_interruptible(round_jiffies_relative(HZ)); }