Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scx_rustland_core: re-introduce ops.update_idle() #1274

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion rust/scx_rustland_core/assets/bpf/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,42 @@ void BPF_STRUCT_OPS(rustland_stopping, struct task_struct *p, bool runnable)
__sync_fetch_and_sub(&nr_running, 1);
}

/*
* A CPU is about to change its idle state.
*/
void BPF_STRUCT_OPS(rustland_update_idle, s32 cpu, bool idle)
{
/*
* Don't do anything if we exit from and idle state, a CPU owner will
* be assigned in .running().
*/
if (!idle)
return;

/*
* A CPU is now available, notify the user-space scheduler that tasks
* can be dispatched.
*/
if (usersched_has_pending_tasks()) {
set_usersched_needed();
/*
* Wake up the idle CPU and trigger a resched, so that it can
* immediately accept dispatched tasks.
*/
scx_bpf_kick_cpu(cpu, 0);
return;
}

/*
* Kick the CPU if there are still tasks dispatched to the
* corresponding per-CPU DSQ.
*/
if (scx_bpf_dsq_nr_queued(cpu_to_dsq(cpu)) > 0) {
scx_bpf_kick_cpu(cpu, 0);
return;
}
}

/*
* Task @p changes cpumask: update its local cpumask generation counter.
*/
Expand Down Expand Up @@ -1238,12 +1274,13 @@ SCX_OPS_DEFINE(rustland,
.dispatch = (void *)rustland_dispatch,
.running = (void *)rustland_running,
.stopping = (void *)rustland_stopping,
.update_idle = (void *)rustland_update_idle,
.set_cpumask = (void *)rustland_set_cpumask,
.cpu_release = (void *)rustland_cpu_release,
.init_task = (void *)rustland_init_task,
.init = (void *)rustland_init,
.exit = (void *)rustland_exit,
.flags = SCX_OPS_ENQ_LAST,
.flags = SCX_OPS_ENQ_LAST | SCX_OPS_KEEP_BUILTIN_IDLE,
.timeout_ms = 5000,
.dispatch_max_batch = MAX_DISPATCH_SLOT,
.name = "rustland");