Skip to content

Commit

Permalink
scx_bpfland: Allow tasks to overflow primary domain more aggressively
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
arighi committed Jan 18, 2025
1 parent 60d5bf2 commit a0b613b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions scheds/rust/scx_bpfland/src/bpf/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;

/*
Expand All @@ -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)
Expand Down

0 comments on commit a0b613b

Please sign in to comment.