Re: [PATCH 2/5] sched: add WF_CURRENT_CPU and externise ttwu

From: Chen Yu
Date: Thu Jan 12 2023 - 02:36:13 EST


On 2023-01-10 at 13:30:07 -0800, Andrei Vagin wrote:
> From: Peter Oskolkov <posk@xxxxxxxxxx>
>
> Add WF_CURRENT_CPU wake flag that advices the scheduler to
> move the wakee to the current CPU. This is useful for fast on-CPU
> context switching use cases.
>
> In addition, make ttwu external rather than static so that
> the flag could be passed to it from outside of sched/core.c.
>
> Signed-off-by: Peter Oskolkov <posk@xxxxxxxxxx>
> Signed-off-by: Andrei Vagin <avagin@xxxxxxxxx>
> @@ -7380,6 +7380,10 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags)
> if (wake_flags & WF_TTWU) {
> record_wakee(p);
>
> + if ((wake_flags & WF_CURRENT_CPU) &&
> + cpumask_test_cpu(cpu, p->cpus_ptr))
> + return cpu;
I agree that cross-CPU wake up brings pain to fast context switching
use cases, especially on high core count system. We suffered from this
issue as well, so previously we presented this issue as well. The difference
is that we used some dynamic "WF_CURRENT_CPU" mechanism[1] to deal with it.
That is, if the waker/wakee are both short duration tasks, let the waker wakes up
the wakee on current CPU. So not only seccomp but also other components/workloads
could benefit from this without having to set the WF_CURRENT_CPU flag.

Link [1]:
https://lore.kernel.org/lkml/cover.1671158588.git.yu.c.chen@xxxxxxxxx/

thanks,
Chenyu