From 0359842e78d74a09a49cad6af270b2c18a564422 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Sat, 18 Jan 2025 15:29:09 +0100 Subject: [PATCH] scx_bpfland: Allow tasks to overflow primary domain more aggressively Make it easier for tasks to overflow beyond the primary domain in a more aggressive way, using all available idle CPUs as a last resort while still prioritizing idle CPUs within the primary domain. This should address issue #1145. Signed-off-by: Andrea Righi --- scheds/rust/scx_bpfland/src/bpf/main.bpf.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scheds/rust/scx_bpfland/src/bpf/main.bpf.c b/scheds/rust/scx_bpfland/src/bpf/main.bpf.c index e5cfbd509..ba86dbb98 100644 --- a/scheds/rust/scx_bpfland/src/bpf/main.bpf.c +++ b/scheds/rust/scx_bpfland/src/bpf/main.bpf.c @@ -627,6 +627,15 @@ static s32 pick_idle_cpu(struct task_struct *p, s32 prev_cpu, u64 wake_flags, bo goto out_put_cpumask; } + /* + * Search for any idle CPU usable by the task. + */ + cpu = scx_bpf_pick_idle_cpu(p->cpus_ptr, 0); + if (cpu >= 0) { + *is_idle = true; + goto out_put_cpumask; + } + /* * We couldn't find any idle CPU, return the previous CPU if it is in * the task's L3 domain. @@ -684,7 +693,7 @@ s32 BPF_STRUCT_OPS(bpfland_select_cpu, struct task_struct *p, */ static void kick_idle_cpu(const struct task_struct *p, const struct task_ctx *tctx) { - const struct cpumask *idle_cpumask, *l3_mask; + const struct cpumask *idle_cpumask; s32 cpu; /* @@ -695,20 +704,14 @@ static void kick_idle_cpu(const struct task_struct *p, const struct task_ctx *tc return; /* - * Look for an idle CPU in the same L3 domain that can immediately + * Look for any idle CPU usable by the task that can immediately * execute the task. * * Note that we do not want to mark the CPU as busy, since we don't * know at this stage if we will actually dispatch any task on it. */ - l3_mask = cast_mask(tctx->l3_cpumask); - if (!l3_mask) { - scx_bpf_error("l3 cpumask not initialized"); - return; - } - idle_cpumask = scx_bpf_get_idle_cpumask(); - cpu = bpf_cpumask_any_and_distribute(l3_mask, idle_cpumask); + cpu = bpf_cpumask_any_and_distribute(p->cpus_ptr, idle_cpumask); scx_bpf_put_cpumask(idle_cpumask); if (cpu < nr_cpu_ids)