[PATCH v2 11/11] sched_ext: Print core event count in scx_central scheduler

Changwoo Min
2025-01-26T10:17:08Z

Modify the scx_central scheduler to print the core event counter
every second.

Signed-off-by: Changwoo Min <changwoo@igalia.com>
---
tools/sched_ext/scx_central.bpf.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)

diff --git a/tools/sched_ext/scx_central.bpf.c b/tools/sched_ext/scx_central.bpf.c
index 50bc1737c167..96b3c08132ea 100644
--- a/tools/sched_ext/scx_central.bpf.c
+++ b/tools/sched_ext/scx_central.bpf.c
@@ -256,6 +256,7 @@ static int central_timerfn(void *map, int *key, struct bpf_timer *timer)
u64 now = scx_bpf_now();
u64 nr_to_kick = nr_queued;
s32 i, curr_cpu;
+ struct scx_event_stats events;

curr_cpu = bpf_get_smp_processor_id();
if (timer_pinned && (curr_cpu != central_cpu)) {
@@ -291,6 +292,26 @@ static int central_timerfn(void *map, int *key, struct bpf_timer *timer)

bpf_timer_start(timer, TIMER_INTERVAL_NS, BPF_F_TIMER_CPU_PIN);
__sync_fetch_and_add(&nr_timers, 1);
+
+ /* print event counters every second */
+ if (nr_timers % 1000 == 0) {
+ scx_bpf_event_stats(&events, sizeof(events));
+
+ bpf_printk("%30s: %llu\n", "SELECT_CPU_FALLBACK",
+ scx_read_event(&events, SELECT_CPU_FALLBACK));
+ bpf_printk("%30s: %llu\n", "DISPATCH_LOCAL_DSQ_OFFLINE",
+ scx_read_event(&events, DISPATCH_LOCAL_DSQ_OFFLINE));
+ bpf_printk("%30s: %llu\n", "DISPATCH_KEEP_LAST",
+ scx_read_event(&events, DISPATCH_KEEP_LAST));
+ bpf_printk("%30s: %llu\n", "ENQ_SKIP_EXITING",
+ scx_read_event(&events, ENQ_SKIP_EXITING));
+ bpf_printk("%30s: %llu\n", "BYPASS_DURATION",
+ scx_read_event(&events, BYPASS_DURATION));
+ bpf_printk("%30s: %llu\n", "BYPASS_DISPATCH",
+ scx_read_event(&events, BYPASS_DISPATCH));
+ bpf_printk("%30s: %llu\n", "BYPASS_ACTIVATE",
+ scx_read_event(&events, BYPASS_ACTIVATE));
+ }
return 0;
}

--
2.48.1