scx_bpfland: always refill task timeslice in ops.dispatch()

When a task exhausts its timeslice and no other tasks are ready to run,
we automatically refill its timeslice, but only if the current CPU is a
fully idle SMT core.

If we don’t handle the refill, the sched_ext core will default to
refilling using SCX_SLICE_DFL, which may not be optimal.

To ensure better control over the task’s timeslice, always refill it
when no other tasks are available to run.

Fixes: 6e24fcc ("scx_bpfland: keep tasks running on full-idle SMT cores")
Signed-off-by: Andrea Righi <andrea.righi@linux.dev>
This commit is contained in:
Andrea Righi 2024-10-09 11:42:52 +02:00
parent 54d704ceda
commit ceb4f1755f

View File

@ -1059,29 +1059,12 @@ void BPF_STRUCT_OPS(bpfland_dispatch, s32 cpu, struct task_struct *prev)
return;
/*
* If the current task expired its time slice, its CPU is still a
* full-idle SMT core and no other task wants to run, simply replenish
* its time slice and let it run for another round on the same CPU.
*
* Note that bpfland_stopping() won't be called if we replenish the
* time slice here. As a result, the nvcsw statistics won't be updated,
* but this isn't an issue, because these statistics are only relevant
* when the system is overloaded, which isn't the case when there are
* no other tasks to run.
* If the current task expired its time slice and no other task wants
* to run, simply replenish its time slice and let it run for another
* round on the same CPU.
*/
if (prev && (prev->scx.flags & SCX_TASK_QUEUED)) {
const struct cpumask *idle_smtmask;
if (!smt_enabled) {
if (prev && (prev->scx.flags & SCX_TASK_QUEUED))
task_refill_slice(prev);
return;
}
idle_smtmask = scx_bpf_get_idle_smtmask();
if (bpf_cpumask_test_cpu(cpu, idle_smtmask))
task_refill_slice(prev);
scx_bpf_put_idle_cpumask(idle_smtmask);
}
}
/*