]> Git Repo - linux.git/commit
kthread: Do not preempt current task if it is going to call schedule()
authorLiang Chen <[email protected]>
Fri, 6 Mar 2020 07:01:33 +0000 (15:01 +0800)
committerPeter Zijlstra <[email protected]>
Fri, 20 Mar 2020 12:06:20 +0000 (13:06 +0100)
commit26c7295be0c5e6da3fa45970e9748be983175b1b
treef8343709aea173894a49fd741a90819c5e2c09b8
parentc32b4308295aaaaedd5beae56cb42e205ae63e58
kthread: Do not preempt current task if it is going to call schedule()

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 <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Steven Rostedt (VMware) <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
kernel/kthread.c
This page took 0.057757 seconds and 4 git commands to generate.