scx_rustland_core: simplify CPU selection logic

Simplify the CPU idle selection logic relying on the built-in logic.

If something can be improved in this logic it should be done in the
backend, changing the default idle selection logic, rustland doesn't
need to do anything special here for now.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
This commit is contained in:
Andrea Righi 2024-05-12 09:05:13 +02:00
parent 0d75c80587
commit 912bde6a52

View File

@ -433,14 +433,6 @@ static void dispatch_user_scheduler(void)
bpf_task_release(p);
}
/*
* Return true if we are waking up from a wait event, false otherwise.
*/
static bool is_waking_up(u64 wake_flags)
{
return !!(wake_flags & SCX_WAKE_TTWU);
}
/*
* Select the target CPU where a task can be executed.
*
@ -460,38 +452,17 @@ s32 BPF_STRUCT_OPS(rustland_select_cpu, struct task_struct *p, s32 prev_cpu,
s32 cpu;
/*
* In full-user mode simply assign the previously used CPU and let the
* user-space scheduler decide where it should be dispatched.
* When full_user is enabled, the user-space scheduler is responsible
* for selecting a target CPU based on its scheduling logic and
* possibly its own idle tracking mechanism.
*/
if (full_user)
return prev_cpu;
/*
* Always try to stick on the same CPU if it's available, to better
* exploit the cached working set.
*/
if (scx_bpf_test_and_clear_cpu_idle(prev_cpu)) {
/*
* Using SCX_DSQ_LOCAL ensures that the task will be executed
* directly on the CPU returned by this function.
*/
dispatch_task(p, SCX_DSQ_LOCAL, 0, 0, 0);
__sync_fetch_and_add(&nr_kernel_dispatches, 1);
return prev_cpu;
}
/*
* If the previously used CPU is not available, check whether the task
* is coming from a wait state. If not, enqueue it on the same CPU
* regardless, without directly dispatching it.
*/
if (!is_waking_up(wake_flags))
return prev_cpu;
/*
* If we are coming from a wait state, try to find the best CPU relying
* on the built-in idle selection logic (eventually migrating the
* task).
* Try to find the best CPU relying on the built-in idle selection
* logic, eventually migrating the task and dispatching directly from
* here if a CPU is available.
*/
cpu = scx_bpf_select_cpu_dfl(p, prev_cpu, wake_flags, &is_idle);
if (is_idle) {