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.
Showing the changes to kernel (1 of 1 file). Show all
Unified · Split
| @@ -602,8 +602,11 @@ static int stutter_gap; · 601 unmodified lines | ||
| 602 | 602 | */ |
| 603 | 603 | bool stutter_wait(const char *title) |
| 604 | 604 | { |
| 605 | − int spt; | |
| 605 | + ktime_t delay; | |
| 606 | + unsigned int i = 0; | |
| 607 | + int oldnice; | |
| 606 | 608 | bool ret = false; |
| 609 | + int spt; | |
| 607 | 610 | |
| 608 | 611 | cond_resched_tasks_rcu_qs(); |
| 609 | 612 | spt = READ_ONCE(stutter_pause_test); |
| @@ -612,8 +615,17 @@ bool stutter_wait(const char *title) · 2 unmodified lines | ||
| 612 | 615 | if (spt == 1) { |
| 613 | 616 | schedule_timeout_interruptible(1); |
| 614 | 617 | } else if (spt == 2) { |
| 615 | − while (READ_ONCE(stutter_pause_test)) | |
| 618 | + oldnice = task_nice(current); | |
| 619 | + set_user_nice(current, MAX_NICE); | |
| 620 | + while (READ_ONCE(stutter_pause_test)) { | |
| 621 | + if (!(i++ & 0xffff)) { | |
| 622 | + set_current_state(TASK_INTERRUPTIBLE); | |
| 623 | + delay = 10 * NSEC_PER_USEC; | |
| 624 | + schedule_hrtimeout(&delay, HRTIMER_MODE_REL); | |
| 625 | + } | |
| 616 | 626 | cond_resched(); |
| 627 | + } | |
| 628 | + set_user_nice(current, oldnice); | |
| 617 | 629 | } else { |
| 618 | 630 | schedule_timeout_interruptible(round_jiffies_relative(HZ)); |
| 619 | 631 | } |