tools/sched_ext: Provide a compatible helper for scx_bpf_events()
authorAndrea Righi <arighi@nvidia.com>
Thu, 27 Feb 2025 09:11:38 +0000 (10:11 +0100)
committerTejun Heo <tj@kernel.org>
Thu, 27 Feb 2025 16:26:58 +0000 (06:26 -1000)
Introduce __COMPAT_scx_bpf_events() to use scx_bpf_events() in a
compatible way also with kernels that don't provide this kfunc.

This also fixes the following error with scx_qmap when running on a
kernel that does not provide scx_bpf_events():

 ; scx_bpf_events(&events, sizeof(events)); @ scx_qmap.bpf.c:777
 318: (b7) r2 = 72                     ; R2_w=72 async_cb
 319: <invalid kfunc call>
 kfunc 'scx_bpf_events' is referenced but wasn't resolved

Fixes: 9865f31d852a4 ("sched_ext: Add scx_bpf_events() and scx_read_event() for BPF schedulers")
Signed-off-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
tools/sched_ext/include/scx/compat.bpf.h
tools/sched_ext/scx_qmap.bpf.c

index 266f94fe479b7f6140231c6e90bd799abe41f446..9252e1a00556f555db5359efb5a10fe9f47b625a 100644 (file)
@@ -183,7 +183,15 @@ static inline bool __COMPAT_is_enq_cpu_selected(u64 enq_flags)
         bpf_ktime_get_ns())
 
 /*
+ * v6.15: Introduce event counters.
  *
+ * Preserve the following macro until v6.17.
+ */
+#define __COMPAT_scx_bpf_events(events, size)                                  \
+       (bpf_ksym_exists(scx_bpf_events) ?                                      \
+        scx_bpf_events(events, size) : ({}))
+
+/*
  * v6.15: Introduce NUMA-aware kfuncs to operate with per-node idle
  * cpumasks.
  *
index a6c6be308315aff8cfd75bfb73c56f34eec08e62..45fd643d2ca0dee03d37313c8f227c29763a0099 100644 (file)
@@ -774,7 +774,7 @@ static int monitor_timerfn(void *map, int *key, struct bpf_timer *timer)
        if (print_shared_dsq)
                dump_shared_dsq();
 
-       scx_bpf_events(&events, sizeof(events));
+       __COMPAT_scx_bpf_events(&events, sizeof(events));
 
        bpf_printk("%35s: %llu", "SCX_EV_SELECT_CPU_FALLBACK",
                   scx_read_event(&events, SCX_EV_SELECT_CPU_FALLBACK));