// SPDX-License-Identifier: GPL-2.0 /* * A scheduler that validates the behavior of scx_bpf_select_cpu_and() by * selecting idle CPUs strictly within a subset of allowed CPUs. * * Copyright (c) 2025 Andrea Righi <arighi@nvidia.com>
*/
staticvoid
validate_idle_cpu(conststruct task_struct *p, conststruct cpumask *allowed, s32 cpu)
{ if (scx_bpf_test_and_clear_cpu_idle(cpu))
scx_bpf_error("CPU %d should be marked as busy", cpu);
if (bpf_cpumask_subset(allowed, p->cpus_ptr) &&
!bpf_cpumask_test_cpu(cpu, allowed))
scx_bpf_error("CPU %d not in the allowed domain for %d (%s)",
cpu, p->pid, p->comm);
}
allowed = cast_mask(allowed_cpumask); if (!allowed) {
scx_bpf_error("allowed domain not initialized"); return;
}
/* * Use scx_bpf_select_cpu_and() to proactively kick an idle CPU * within @allowed_cpumask, usable by @p.
*/
cpu = scx_bpf_select_cpu_and(p, prev_cpu, 0, allowed, 0); if (cpu >= 0) {
validate_idle_cpu(p, allowed, cpu);
scx_bpf_kick_cpu(cpu, SCX_KICK_IDLE);
}
}
mask = bpf_cpumask_create(); if (!mask) return -ENOMEM;
mask = bpf_kptr_xchg(&allowed_cpumask, mask); if (mask)
bpf_cpumask_release(mask);
bpf_rcu_read_lock();
/* * Assign the first online CPU to the allowed domain.
*/
mask = allowed_cpumask; if (mask) { conststruct cpumask *online = scx_bpf_get_online_cpumask();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.