The following commit has been merged into the core/rcu branch of tip:

Commit-ID:     19012b786ecccb29a9fa20c4ec0a67e2cdfbc010
Gitweb:        
https://git.kernel.org/tip/19012b786ecccb29a9fa20c4ec0a67e2cdfbc010
Author:        Paul E. McKenney <paul...@kernel.org>
AuthorDate:    Tue, 01 Sep 2020 16:58:41 -07:00
Committer:     Paul E. McKenney <paul...@kernel.org>
CommitterDate: Fri, 06 Nov 2020 17:13:48 -08:00

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.  This commit also uses hrtimers to provide
very short sleeps to avoid degrading the sudden-on testing that stutter
is supposed to provide.

Reviewed-by: Davidlohr Bueso <dbu...@suse.de>
Signed-off-by: Paul E. McKenney <paul...@kernel.org>
---
 kernel/torture.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/kernel/torture.c b/kernel/torture.c
index 1061492..be09377 100644
--- a/kernel/torture.c
+++ b/kernel/torture.c
@@ -602,8 +602,11 @@ static int stutter_gap;
  */
 bool stutter_wait(const char *title)
 {
-       int spt;
+       ktime_t delay;
+       unsigned int i = 0;
+       int oldnice;
        bool ret = false;
+       int spt;
 
        cond_resched_tasks_rcu_qs();
        spt = READ_ONCE(stutter_pause_test);
@@ -612,8 +615,17 @@ bool stutter_wait(const char *title)
                if (spt == 1) {
                        schedule_timeout_interruptible(1);
                } else if (spt == 2) {
-                       while (READ_ONCE(stutter_pause_test))
+                       oldnice = task_nice(current);
+                       set_user_nice(current, MAX_NICE);
+                       while (READ_ONCE(stutter_pause_test)) {
+                               if (!(i++ & 0xffff)) {
+                                       set_current_state(TASK_INTERRUPTIBLE);
+                                       delay = 10 * NSEC_PER_USEC;
+                                       schedule_hrtimeout(&delay, 
HRTIMER_MODE_REL);
+                               }
                                cond_resched();
+                       }
+                       set_user_nice(current, oldnice);
                } else {
                        
schedule_timeout_interruptible(round_jiffies_relative(HZ));
                }

Reply via email to