[PATCH v2 00/11] sched_ext: Implement core event counters

From: Changwoo Min
Date: Sun Jan 26 2025 - 05:16:44 EST


The sched_ext core often has to override the BPF scheduler decisions,
and some events could be interesting but not easily visible.

This patchset aims to address such a problem in the following manner:
- Introduce an infrastructure to collect such events in a scalable and
extensible way and to expose the collected events to the BPF scheduler
in a compatible way.
- Define seven events to be collected.
- Modify an scx scheduler to demonstrate the usage of the new BPF APIs.

ChangeLog: v1 -> v2
- Rename scx_event_stat and scx_bpf_event_stat() to scx_event_stats and
scx_bpf_event_stats().
- Rename event names following the convention of $COMPONENT_$EVENT.
- Rename event_stats to event_stats_cpu.
- Drop the enum scx_event_kind and related macros.
- Revise scx_add_event() to use this_cpu_add().
- Add __scx_add_event() to use __this_cpu_add().
- Move the event counter resetting code to the loading of a BPF scheduler.
- The bypass-related event is further categorized into three events:
BYPASS_ACTIVATE, BYPASS_DISPATCH, and BYPASS_DURATION.
- Revise SELECT_CPU_FALLBACK to capture the case of the chosen CPU is not
allowed.
- Move is_cpu_allowed() from core.c to sched.h to use in the
SELECT_CPU_FALLBACK code.

Changwoo Min (11):
sched_ext: Implement event counter infrastructure
sched: Move is_cpu_allowed() to the header
sched_ext: Add an event, SELECT_CPU_FALLBACK
sched_ext: Add an event, DISPATCH_LOCAL_DSQ_OFFLINE
sched_ext: Add an event, DISPATCH_KEEP_LAST
sched_ext: Add an event, ENQ_SKIP_EXITING
sched_ext: Add an event, BYPASS_ACTIVATE
sched_ext: Add an event, BYPASS_DISPATCH
sched_ext: Add an event, BYPASS_DURATION
sched_ext: Add scx_bpf_event_stats() and scx_read_event() for BPF
schedulers
sched_ext: Print core event count in scx_central scheduler

kernel/sched/core.c | 30 ----
kernel/sched/ext.c | 177 ++++++++++++++++++++++-
kernel/sched/sched.h | 30 ++++
tools/sched_ext/include/scx/common.bpf.h | 4 +
tools/sched_ext/scx_central.bpf.c | 21 +++
5 files changed, 231 insertions(+), 31 deletions(-)

--
2.48.1