From: Greg Kroah-Hartman Date: Mon, 24 Aug 2020 07:23:15 +0000 (+0200) Subject: 5.4-stable patches X-Git-Tag: v4.4.234~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=894f5c5d232d153f37e374ccab6d331ea703f7fe;p=thirdparty%2Fkernel%2Fstable-queue.git 5.4-stable patches added patches: kthread-do-not-preempt-current-task-if-it-is-going-to-call-schedule.patch --- diff --git a/queue-5.4/kthread-do-not-preempt-current-task-if-it-is-going-to-call-schedule.patch b/queue-5.4/kthread-do-not-preempt-current-task-if-it-is-going-to-call-schedule.patch new file mode 100644 index 00000000000..a643f23137a --- /dev/null +++ b/queue-5.4/kthread-do-not-preempt-current-task-if-it-is-going-to-call-schedule.patch @@ -0,0 +1,76 @@ +From 26c7295be0c5e6da3fa45970e9748be983175b1b Mon Sep 17 00:00:00 2001 +From: Liang Chen +Date: Fri, 6 Mar 2020 15:01:33 +0800 +Subject: kthread: Do not preempt current task if it is going to call schedule() + +From: Liang Chen + +commit 26c7295be0c5e6da3fa45970e9748be983175b1b upstream. + +when we create a kthread with ktrhead_create_on_cpu(),the child thread +entry is ktread.c:ktrhead() which will be preempted by the parent after +call complete(done) while schedule() is not called yet,then the parent +will call wait_task_inactive(child) but the child is still on the runqueue, +so the parent will schedule_hrtimeout() for 1 jiffy,it will waste a lot of +time,especially on startup. + + parent child +ktrhead_create_on_cpu() + wait_fo_completion(&done) -----> ktread.c:ktrhead() + |----- complete(done);--wakeup and preempted by parent + kthread_bind() <------------| |-> schedule();--dequeue here + wait_task_inactive(child) | + schedule_hrtimeout(1 jiffy) -| + +So we hope the child just wakeup parent but not preempted by parent, and the +child is going to call schedule() soon,then the parent will not call +schedule_hrtimeout(1 jiffy) as the child is already dequeue. + +The same issue for ktrhead_park()&&kthread_parkme(). +This patch can save 120ms on rk312x startup with CONFIG_HZ=300. + +Signed-off-by: Liang Chen +Signed-off-by: Peter Zijlstra (Intel) +Reviewed-by: Steven Rostedt (VMware) +Link: https://lkml.kernel.org/r/20200306070133.18335-2-cl@rock-chips.com +Signed-off-by: Chanho Park +Signed-off-by: Greg Kroah-Hartman +--- + kernel/kthread.c | 17 +++++++++++++++-- + 1 file changed, 15 insertions(+), 2 deletions(-) + +--- a/kernel/kthread.c ++++ b/kernel/kthread.c +@@ -199,8 +199,15 @@ static void __kthread_parkme(struct kthr + if (!test_bit(KTHREAD_SHOULD_PARK, &self->flags)) + break; + ++ /* ++ * Thread is going to call schedule(), do not preempt it, ++ * or the caller of kthread_park() may spend more time in ++ * wait_task_inactive(). ++ */ ++ preempt_disable(); + complete(&self->parked); +- schedule(); ++ schedule_preempt_disabled(); ++ preempt_enable(); + } + __set_current_state(TASK_RUNNING); + } +@@ -245,8 +252,14 @@ static int kthread(void *_create) + /* OK, tell user we're spawned, wait for stop or wakeup */ + __set_current_state(TASK_UNINTERRUPTIBLE); + create->result = current; ++ /* ++ * Thread is going to call schedule(), do not preempt it, ++ * or the creator may spend more time in wait_task_inactive(). ++ */ ++ preempt_disable(); + complete(done); +- schedule(); ++ schedule_preempt_disabled(); ++ preempt_enable(); + + ret = -EINTR; + if (!test_bit(KTHREAD_SHOULD_STOP, &self->flags)) { diff --git a/queue-5.4/series b/queue-5.4/series index d23e5c3f18d..9e39a6dc010 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -36,6 +36,7 @@ mm-memory.c-skip-spurious-tlb-flush-for-retried-page-fault.patch drm-amdgpu-display-use-gfp_atomic-in-dcn20_validate_bandwidth_internal.patch drm-amd-display-fix-edid-parsing-after-resume-from-suspend.patch drm-amd-display-fix-pow-crashing-when-given-base-0.patch +kthread-do-not-preempt-current-task-if-it-is-going-to-call-schedule.patch opp-enable-resources-again-if-they-were-disabled-ear.patch scsi-ufs-add-delay_before_lpm-quirk-for-micron-devic.patch scsi-target-tcmu-fix-crash-in-tcmu_flush_dcache_rang.patch