scx_lavd: support large x86_64 systems (raise LAVD_CPU_ID_MAX to 8192)#3634
Open
jkkm wants to merge 2 commits into
Open
scx_lavd: support large x86_64 systems (raise LAVD_CPU_ID_MAX to 8192)#3634jkkm wants to merge 2 commits into
jkkm wants to merge 2 commits into
Conversation
added 2 commits
June 8, 2026 12:58
The per-compute-domain bitmap scan loops in collect_sys_stat(), plan_x_cpdom_migration()'s helper, and the init path iterate the full LAVD_CPU_ID_MAX/64 longs of cpdom_ctx.__cpumask regardless of how many CPUs the system actually has. On a machine with few CPUs (or a large LAVD_CPU_ID_MAX), the upper longs are always zero, so the inner bit-scan breaks immediately, but the outer loop still visits every long. Break out of the outer loop once the long index is past nr_cpu_ids: __cpumask bits are only ever set for CPU ids < nr_cpu_ids, so the remaining longs are guaranteed zero. The loop keeps its compile-time LAVD_CPU_ID_MAX/64 bound, so the __cpumask[i] access is still provably in range for the verifier; the added test is just an early exit. This makes the scan cost scale with the actual CPU count (ceil(nr_cpu_ids/64) iterations) instead of LAVD_CPU_ID_MAX, with no change in verifier complexity (the loops are open-coded iterators). No functional change. Signed-off-by: Kyle McMartin <jkkm@meta.com>
scx_lavd refuses to start (panic in Scheduler::init) when the system has more possible CPUs than LAVD_CPU_ID_MAX, which was 512. Machines with more than 512 CPUs therefore cannot run scx_lavd at all. Raise the cap to 8192, matching x86_64's MAXSMP NR_CPUS, so scx_lavd runs on any x86_64 configuration. The constant sizes CPU-id-indexed rodata arrays (cpu_capacity, cpu_sibling, cpu_big, cpu_turbo, pco_table) and the per-cpdom __cpumask bitmap, so this adds ~345 KB of static data per scheduler instance. With the preceding change bounding the cpumask scan loops by nr_cpu_ids, there is no runtime cost: the loops still iterate only ceil(nr_cpu_ids/64) times, and verifier complexity is unchanged. Note: 8192 is the x86_64 maximum; architectures with a larger NR_CPUS may need a higher value. Signed-off-by: Kyle McMartin <jkkm@meta.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two commits:
scx_lavd: bound per-cpdom cpumask scan loops by nr_cpu_idsscx_lavd: raise LAVD_CPU_ID_MAX to 8192 to support large x86_64 systemsProblem
scx_lavdpanics inScheduler::init("Num possible CPU IDs (N) exceedsmaximum of (512)") on any machine with more than 512 possible CPUs, so it
cannot run there at all.
LAVD_CPU_ID_MAXsizes the CPU-id-indexed rodataarrays (
cpu_capacity,cpu_sibling,cpu_big,cpu_turbo,pco_table) andthe per-cpdom
__cpumaskbitmap.Separately, the per-cpdom bitmap scan loops iterate the full
LAVD_CPU_ID_MAX/64longs regardless of the actual CPU count, so raising thecap would add wasted iterations on every system.
Fix
Commit 1 breaks out of each scan loop (
collect_sys_stat,plan_x_cpdom_migrationhelper, init path) once the long index is pastnr_cpu_ids.__cpumaskbits are only set for CPU ids <nr_cpu_ids, so theremaining longs are always zero. The loop keeps its compile-time
LAVD_CPU_ID_MAX/64bound, so the__cpumask[i]access stays provably in rangefor the verifier — the test is just an early exit. The scan now costs
ceil(nr_cpu_ids/64)iterations regardless ofLAVD_CPU_ID_MAX.Commit 2 raises
LAVD_CPU_ID_MAXfrom 512 to 8192 (x86_64MAXSMP).Testing (NR_CPUS=1024 kernel, veristat)
scan loops are open-coded iterators, verified once regardless of bound).
nr_cpu_ids, so on a 316-CPU host the scan runs 5 iterations whether the capis 512 or 8192 (vs 128 for an un-bounded 8192 loop).
for the CPU-id-indexed arrays + ~120 KB for the per-cpdom
__cpumask).Note
8192 is the x86_64 maximum; architectures with a larger
NR_CPUSmay need ahigher value (or sizing the cap from the arch maximum).