[PATCH] [RFC] rt: kernel/sched/core: fix kthread_park() pending too long when CPU un-plugged
From: Ran Wang
Date: Thu Jan 07 2021 - 04:10:57 EST
When doing CPU un-plug stress test, function smpboot_park_threads() would
get call to park kernel threads (which including ksoftirqd) on that
CPU core, and function wait_task_inactive() would yield for those queued
task(s) by calling schedule_hrtimerout() with mode of HRTIMER_MODE_REL.
stack trace:
...
smpboot_thread_fn
cpuhp_thread_fun
cpuhp_invoke_callback
smpboot_park_threads
smpboot_park_thread: ksoftirqd/1
kthread_park
wait_task_inactive
schedule_hrtimerout
However, when PREEMPT_RT is set, this would cause a pending issue since
schedule_hrtimerout() depend on thread ksoftirqd to complete related
work if it using HRTIMER_MODE_SOFT. So force using HRTIMER_MODE_HARD
in such case.
Suggested-by: Jiafei Pan <jiafei.pan@xxxxxxx>
Signed-off-by: Ran Wang <ran.wang_1@xxxxxxx>
---
kernel/sched/core.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 792da55..4cc742a 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2054,10 +2054,15 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state)
ktime_t to = NSEC_PER_SEC / HZ;
set_current_state(TASK_UNINTERRUPTIBLE);
- schedule_hrtimeout(&to, HRTIMER_MODE_REL);
+
+ if (IS_ENABLED(CONFIG_PREEMPT_RT) &&
+ !strncmp(p->comm, "ksoftirqd/", 10))
+ schedule_hrtimeout(&to,
+ HRTIMER_MODE_REL | HRTIMER_MODE_HARD);
+ else
+ schedule_hrtimeout(&to, HRTIMER_MODE_REL);
continue;
}
-
/*
* Ahh, all good. It wasn't running, and it wasn't
* runnable, which means that it will never become
--
2.7.4