Skip to content

Commit 21b8964

Browse files
arighihtejun
authored andcommitted
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. Signed-off-by: Andrea Righi <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent ba1c9d3 commit 21b8964

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

kernel/sched/ext.c

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,20 +3132,40 @@ static s32 scx_select_cpu_dfl(struct task_struct *p, s32 prev_cpu,
31323132
}
31333133

31343134
/*
3135-
* If WAKE_SYNC, the waker's local DSQ is empty, and the system is
3136-
* under utilized, wake up @p to the local DSQ of the waker. Checking
3137-
* only for an empty local DSQ is insufficient as it could give the
3138-
* wakee an unfair advantage when the system is oversaturated.
3139-
* Checking only for the presence of idle CPUs is also insufficient as
3140-
* the local DSQ of the waker could have tasks piled up on it even if
3141-
* there is an idle core elsewhere on the system.
3142-
*/
3143-
cpu = smp_processor_id();
3144-
if ((wake_flags & SCX_WAKE_SYNC) &&
3145-
!cpumask_empty(idle_masks.cpu) && !(current->flags & PF_EXITING) &&
3146-
cpu_rq(cpu)->scx.local_dsq.nr == 0) {
3147-
if (cpumask_test_cpu(cpu, p->cpus_ptr))
3135+
* If WAKE_SYNC, try to migrate the wakee to the waker's CPU.
3136+
*/
3137+
if (wake_flags & SCX_WAKE_SYNC) {
3138+
cpu = smp_processor_id();
3139+
3140+
/*
3141+
* If the waker's CPU is cache affine and prev_cpu is idle,
3142+
* then avoid a migration.
3143+
*/
3144+
if (cpus_share_cache(cpu, prev_cpu) &&
3145+
test_and_clear_cpu_idle(prev_cpu)) {
3146+
cpu = prev_cpu;
31483147
goto cpu_found;
3148+
}
3149+
3150+
/*
3151+
* If the waker's local DSQ is empty, and the system is under
3152+
* utilized, try to wake up @p to the local DSQ of the waker.
3153+
*
3154+
* Checking only for an empty local DSQ is insufficient as it
3155+
* could give the wakee an unfair advantage when the system is
3156+
* oversaturated.
3157+
*
3158+
* Checking only for the presence of idle CPUs is also
3159+
* insufficient as the local DSQ of the waker could have tasks
3160+
* piled up on it even if there is an idle core elsewhere on
3161+
* the system.
3162+
*/
3163+
if (!cpumask_empty(idle_masks.cpu) &&
3164+
!(current->flags & PF_EXITING) &&
3165+
cpu_rq(cpu)->scx.local_dsq.nr == 0) {
3166+
if (cpumask_test_cpu(cpu, p->cpus_ptr))
3167+
goto cpu_found;
3168+
}
31493169
}
31503170

31513171
/*

0 commit comments

Comments
 (0)