[PATCHSET sched_ext/for-7.4] sched_ext: Add scx_bpf_cgroup_nr_cpus()

From: Andrea Righi

Date: Tue Sep 29 2026 - 04:48:52 EST


Hierarchical BPF schedulers need to know how many CPUs a cgroup can run on when
distributing group-wide weights. For example, fair's group share calculation
scales a group's weight by the smaller of its estimated runnable task count and
the number of CPUs in its effective cpuset (tg_cpus() -> cpuset_num_cpus()).
Without that count, a BPF scheduler can only use the machine-wide CPU count and
may give a group confined to a few CPUs excessive shares.

This patchset adds scx_bpf_cgroup_nr_cpus(), a kfunc that returns the same count
fair uses. This allows scx_eevdf to implement proper group scheduling, computing
per-cgroup shares the same way fair does, including for groups confined to a
subset of CPUs through cpuset.

Andrea Righi (3):
cgroup/cpuset: Protect is_in_v2_mode() in cpuset_num_cpus()
sched_ext: Introduce scx_bpf_cgroup_nr_cpus()
selftests/sched_ext: Test scx_bpf_cgroup_nr_cpus()

kernel/cgroup/cpuset.c | 6 +-
kernel/sched/ext/ext.c | 22 ++
tools/sched_ext/include/scx/common.bpf.h | 1 +
tools/sched_ext/include/scx/compat.bpf.h | 7 +
tools/testing/selftests/sched_ext/Makefile | 6 +-
.../selftests/sched_ext/cgroup_nr_cpus.bpf.c | 60 +++
tools/testing/selftests/sched_ext/cgroup_nr_cpus.c | 419 +++++++++++++++++++++
tools/testing/selftests/sched_ext/config | 1 +
8 files changed, 519 insertions(+), 3 deletions(-)
create mode 100644 tools/testing/selftests/sched_ext/cgroup_nr_cpus.bpf.c
create mode 100644 tools/testing/selftests/sched_ext/cgroup_nr_cpus.c