sched_ext: Make scx_bpf_events() read the calling scheduler's counters

scx_bpf_events() always reads the root scheduler's event counters, so a
sub-scheduler program querying its own events silently gets the root's
instead and has no BPF-visible way to read its own (the per-scheduler sysfs
"events" file is the only interface). Resolve the scheduler from the calling
program with scx_prog_sched(). Unassociated programs follow the usual
scx_prog_sched() resolution: the root scheduler under a pre-sub-attach
compat root and zeroed counters otherwise.

Also fix up the malformed comment into proper kerneldoc.

Signed-off-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
Tejun Heo 2026-08-14 18:26:37 -10:00
parent d440933231
commit b27dfc7d8d

View File

@ -10604,19 +10604,23 @@ static void scx_read_events(struct scx_sched *sch, struct scx_event_stats *event
}
}
/*
* scx_bpf_events - Get a system-wide event counter to
/**
* scx_bpf_events - Read the event counters of the calling scheduler
* @events: output buffer from a BPF program
* @events__sz: @events len, must end in '__sz'' for the verifier
* @events__sz: @events len, must end in '__sz' for the verifier
* @aux: implicit BPF argument to access bpf_prog_aux hidden from BPF progs
*
* Read the event counters of the scheduler associated with the calling program.
* @events is zeroed when no scheduler can be resolved.
*/
__bpf_kfunc void scx_bpf_events(struct scx_event_stats *events,
size_t events__sz)
__bpf_kfunc void scx_bpf_events(struct scx_event_stats *events, size_t events__sz,
const struct bpf_prog_aux *aux)
{
struct scx_sched *sch;
struct scx_event_stats e_sys;
rcu_read_lock();
sch = rcu_dereference(scx_root);
sch = scx_prog_sched(aux);
if (sch)
scx_read_events(sch, &e_sys);
else
@ -10739,7 +10743,7 @@ BTF_ID_FLAGS(func, scx_bpf_cpu_curr, KF_IMPLICIT_ARGS | KF_RET_NULL | KF_RCU_PRO
BTF_ID_FLAGS(func, scx_bpf_cid_curr, KF_IMPLICIT_ARGS | KF_RET_NULL | KF_RCU_PROTECTED)
BTF_ID_FLAGS(func, scx_bpf_tid_to_task, KF_RET_NULL | KF_RCU_PROTECTED)
BTF_ID_FLAGS(func, scx_bpf_now)
BTF_ID_FLAGS(func, scx_bpf_events)
BTF_ID_FLAGS(func, scx_bpf_events, KF_IMPLICIT_ARGS)
#ifdef CONFIG_CGROUP_SCHED
BTF_ID_FLAGS(func, scx_bpf_task_cgroup, KF_IMPLICIT_ARGS | KF_RCU | KF_ACQUIRE)
#endif