Merge pull request #189 from sched-ext/rustland-offline-cpus

scx_rustland: mitigate sub-optimal performance with offline CPUs
This commit is contained in:
David Vernet 2024-03-14 11:00:28 -05:00 committed by GitHub
commit 0ecac96467
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View File

@ -441,7 +441,7 @@ s32 BPF_STRUCT_OPS(rustland_select_cpu, struct task_struct *p, s32 prev_cpu,
s32 cpu;
cpu = scx_bpf_select_cpu_dfl(p, prev_cpu, wake_flags, &is_idle);
if (is_idle && !full_user) {
if (is_idle && cpu < num_possible_cpus && !full_user) {
/*
* Using SCX_DSQ_LOCAL ensures that the task will be executed
* directly on the CPU returned by this function.

View File

@ -264,14 +264,15 @@ impl<'a> Scheduler<'a> {
let init_page_faults: u64 = 0;
// Low-level BPF connector.
let nr_online_cpus = topo.span().weight() + 1;
let bpf = BpfScheduler::init(
opts.slice_us,
topo.nr_cpus() as i32,
nr_online_cpus as i32,
opts.partial,
opts.full_user,
opts.debug,
)?;
info!("{} scheduler attached", SCHEDULER_NAME);
info!("{} scheduler attached - {} online CPUs", SCHEDULER_NAME, nr_online_cpus);
// Return scheduler object.
Ok(Self {
@ -298,8 +299,8 @@ impl<'a> Scheduler<'a> {
// Count the number of cores where all the CPUs are idle.
for core in self.topo.cores().iter() {
let mut all_idle = true;
for (cpu_id, _) in core.cpus().iter() {
if self.bpf.get_cpu_pid(*cpu_id as i32) != 0 {
for cpu_id in core.span().into_iter() {
if self.bpf.get_cpu_pid(cpu_id as i32) != 0 {
all_idle = false;
break;
}