sched_ext: improve WAKE_SYNC behavior for default idle CPU selection
PATCH v2 1/1 sched_ext: improve WAKE_SYNC behavior for default idle CPU selection
In the sched_ext built-in idle CPU selection logic, when handling a WF_SYNC wakeup, we always attempt to migrate the task to the waker's CPU, as the waker is expected to yield the CPU after waking the task.
However, it may be preferable to keep the task on its previous CPU if the waker's CPU is cache-affine.
The same approach is also used by the fair class and in other scx schedulers, like scx_rusty and scx_bpfland.
Therefore, apply the same logic to the built-in idle CPU selection policy as well.
--- kernel/sched/ext.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-)
ChangeLog v1 -> v2:
- correctly return prev_cpu in the cache affine case
kernel/sched/ext.c +33 -13
@@ -3087,20 +3087,40 @@ static s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu, *found = false;/* -* If WAKE_SYNC, the waker's local DSQ is empty, and the system is -* under utilized, wake up @p to the local DSQ of the waker. Checking -* only for an empty local DSQ is insufficient as it could give the -* wakee an unfair advantage when the system is oversaturated. -* Checking only for the presence of idle CPUs is also insufficient as -* the local DSQ of the waker could have tasks piled up on it even if -* there is an idle core elsewhere on the system. -*/ - cpu =smp_processor_id (); -if ((wake_flags &SCX_WAKE_SYNC ) && - !cpumask_empty (idle_masks.cpu) && !(current->flags &PF_EXITING ) && -cpu_rq (cpu)->scx.local_dsq.nr ==0 ) { -if (cpumask_test_cpu (cpu, p->cpus_ptr)) +* If WAKE_SYNC, try to migrate the wakee to the waker's CPU. +*/ +if (wake_flags &SCX_WAKE_SYNC ) { + cpu =smp_processor_id (); + +/* +* If the waker's CPU is cache affine and prev_cpu is idle, +* then avoid a migration. +*/ +if (cpus_share_cache (cpu, prev_cpu) && +test_and_clear_cpu_idle (prev_cpu)) { + cpu = prev_cpu; goto cpu_found; + } + +/* +* If the waker's local DSQ is empty, and the system is under +* utilized, try to wake up @p to the local DSQ of the waker. +* +* Checking only for an empty local DSQ is insufficient as it +* could give the wakee an unfair advantage when the system is +* oversaturated. +* +* Checking only for the presence of idle CPUs is also +* insufficient as the local DSQ of the waker could have tasks +* piled up on it even if there is an idle core elsewhere on +* the system. +*/ +if (!cpumask_empty (idle_masks.cpu) && + !(current->flags &PF_EXITING ) && +cpu_rq (cpu)->scx.local_dsq.nr ==0 ) { +if (cpumask_test_cpu (cpu, p->cpus_ptr)) + goto cpu_found; + } }/*
Signature · 1 line
2.47.0
Tejun Heo
AppliedQuoted 7 lines · Andrea Righi
In the
sched_extbuilt-in idle CPU selection logic, when handling aWF_SYNCwakeup, we always attempt to migrate the task to the waker's CPU, as the waker is expected to yield the CPU after waking the task.However, it may be preferable to keep the task on its previous CPU if the waker's CPU is cache-affine.
Quoted 7 lines
The same approach is also used by the fair class and in other scx schedulers, like
scx_rustyandscx_bpfland.Therefore, apply the same logic to the built-in idle CPU selection policy as well.
Signed-off-by Andrea Righi <[email protected]>
Applied to sched_ext/for-6.13.
Thanks.
Signature · 1 line
tejun