From 4432e64d85a9de26b871686d2b2166d51878ad74 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Mon, 14 Oct 2024 10:08:44 +0200 Subject: [PATCH] scx_rustland_core: allow user-space scheduler to run indefinitely Assign an infinite time slice to the user-space scheduler itself, so that it can completely drain all the pending tasks and voluntarily release the CPU when it's done. This allows to achieve more consistent performance and we can also remove the speculative user-space scheduler wakeup from ops.stopping(). Signed-off-by: Andrea Righi --- rust/scx_rustland_core/assets/bpf/main.bpf.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/rust/scx_rustland_core/assets/bpf/main.bpf.c b/rust/scx_rustland_core/assets/bpf/main.bpf.c index 82de537..9f01148 100644 --- a/rust/scx_rustland_core/assets/bpf/main.bpf.c +++ b/rust/scx_rustland_core/assets/bpf/main.bpf.c @@ -913,8 +913,14 @@ static bool dispatch_user_scheduler(void) /* * Use the highest vtime possible to give the scheduler itself the * lowest priority possible. + * + * At the same time make sure to assign an infinite time slice, so that + * it can completely drain all the pending tasks. + * + * The user-space scheduler will voluntarily yield the CPU upon + * completion through BpfScheduler->notify_complete(). */ - scx_bpf_dispatch_vtime(p, SHARED_DSQ, SCX_SLICE_DFL, -1ULL, 0); + scx_bpf_dispatch_vtime(p, SHARED_DSQ, SCX_SLICE_INF, -1ULL, 0); cpu = pick_idle_cpu(p, scx_bpf_task_cpu(p), 0); if (cpu >= 0) @@ -1062,15 +1068,8 @@ void BPF_STRUCT_OPS(rustland_stopping, struct task_struct *p, bool runnable) /* * Mark the CPU as idle by setting the owner to 0. */ - if (!is_usersched_task(p)) { + if (!is_usersched_task(p)) __sync_fetch_and_sub(&nr_running, 1); - /* - * Kick the user-space scheduler immediately when a task - * releases a CPU and speculate on the fact that most of the - * time there is another task ready to run. - */ - set_usersched_needed(); - } } /*