scx_lavd: direct dispatch when there is an idle CPU

When there is an idle CPU, direct dispatch is performed to reduce
scheduling latency. This didn't work well before, but it seems
to work well now with other tunings.

Signed-off-by: Changwoo Min <changwoo@igalia.com>
This commit is contained in:
Changwoo Min 2024-10-20 15:42:27 +09:00
parent 420de70159
commit 5a852dc3d9

View File

@ -911,6 +911,15 @@ out:
return cpu_id; return cpu_id;
} }
static void update_task_log_clk(struct task_ctx *taskc)
{
/*
* Update the logical clock of the virtual deadline.
*/
u64 vlc = READ_ONCE(cur_logical_clk) + taskc->vdeadline_delta_ns;
WRITE_ONCE(taskc->vdeadline_log_clk, vlc);
}
s32 BPF_STRUCT_OPS(lavd_select_cpu, struct task_struct *p, s32 prev_cpu, s32 BPF_STRUCT_OPS(lavd_select_cpu, struct task_struct *p, s32 prev_cpu,
u64 wake_flags) u64 wake_flags)
{ {
@ -923,31 +932,30 @@ s32 BPF_STRUCT_OPS(lavd_select_cpu, struct task_struct *p, s32 prev_cpu,
return prev_cpu; return prev_cpu;
cpu_id = pick_idle_cpu(p, taskc, prev_cpu, wake_flags, &found_idle); cpu_id = pick_idle_cpu(p, taskc, prev_cpu, wake_flags, &found_idle);
if (found_idle) if (found_idle) {
taskc->vdeadline_delta_ns = 0;
update_task_log_clk(taskc);
p->scx.slice = calc_time_slice(p, taskc);
scx_bpf_dispatch(p, SCX_DSQ_LOCAL, p->scx.slice, 0);
return cpu_id; return cpu_id;
}
taskc->wakeup_ft += !!(wake_flags & SCX_WAKE_SYNC); taskc->wakeup_ft += !!(wake_flags & SCX_WAKE_SYNC);
return (cpu_id >= 0) ? cpu_id : prev_cpu; return prev_cpu;
} }
static void calc_when_to_run(struct task_struct *p, struct task_ctx *taskc, static void calc_when_to_run(struct task_struct *p, struct task_ctx *taskc,
struct cpu_ctx *cpuc_cur, u64 enq_flags) struct cpu_ctx *cpuc_cur, u64 enq_flags)
{ {
u64 vlc;
/* /*
* Before enqueueing a task to a run queue, we should decide when a * Before enqueueing a task to a run queue, we should decide when a
* task should be scheduled. * task should be scheduled.
*/ */
calc_virtual_deadline_delta(p, taskc, cpuc_cur, enq_flags); calc_virtual_deadline_delta(p, taskc, cpuc_cur, enq_flags);
/* update_task_log_clk(taskc);
* Update the logical clock of the virtual deadline.
*/
vlc = READ_ONCE(cur_logical_clk) + taskc->vdeadline_delta_ns;
WRITE_ONCE(taskc->vdeadline_log_clk, vlc);
} }
static u64 find_proper_dsq(struct task_ctx *taskc, struct cpu_ctx *cpuc) static u64 find_proper_dsq(struct task_ctx *taskc, struct cpu_ctx *cpuc)