Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched/core: Micro-optimize ttwu_runnable()

ttwu_runnable() is used as a fast wakeup path when the wakee task
is running on CPU or runnable on RQ, in both cases we can just
set its state to TASK_RUNNING to prevent a sleep.

If the wakee task is on_cpu running, we don't need to update_rq_clock()
or check_preempt_curr().

But if the wakee task is on_rq && !on_cpu (e.g. an IRQ hit before
the task got to schedule() and the task been preempted), we should
check_preempt_curr() to see if it can preempt the current running.

This also removes the class->task_woken() callback from ttwu_runnable(),
which wasn't required per the RT/DL implementations: any required push
operation would have been queued during class->set_next_task() when p
got preempted.

ttwu_runnable() also loses the update to rq->idle_stamp, as by definition
the rq cannot be idle in this scenario.

Suggested-by: Valentin Schneider <vschneid@redhat.com>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Valentin Schneider <vschneid@redhat.com>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Link: https://lore.kernel.org/r/20221223103257.4962-1-zhouchengming@bytedance.com

authored by

Chengming Zhou and committed by
Ingo Molnar
efe09385 acbee592

+10 -3
+10 -3
kernel/sched/core.c
··· 3720 3720 3721 3721 rq = __task_rq_lock(p, &rf); 3722 3722 if (task_on_rq_queued(p)) { 3723 - /* check_preempt_curr() may use rq clock */ 3724 - update_rq_clock(rq); 3725 - ttwu_do_wakeup(rq, p, wake_flags, &rf); 3723 + if (!task_on_cpu(rq, p)) { 3724 + /* 3725 + * When on_rq && !on_cpu the task is preempted, see if 3726 + * it should preempt the task that is current now. 3727 + */ 3728 + update_rq_clock(rq); 3729 + check_preempt_curr(rq, p, wake_flags); 3730 + } 3731 + WRITE_ONCE(p->__state, TASK_RUNNING); 3732 + trace_sched_wakeup(p); 3726 3733 ret = 1; 3727 3734 } 3728 3735 __task_rq_unlock(rq, &rf);