* [PATCH sched_ext/for-7.4] tools/sched_ext: Skip scx_lib_init_probe() without CONFIG_FUNCTION_TRACER
@ 2026-08-24 15:50 Cheng-Yang Chou
2026-08-24 16:02 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Cheng-Yang Chou @ 2026-08-24 15:50 UTC (permalink / raw)
To: sched-ext, Tejun Heo, David Vernet, Andrea Righi, Changwoo Min
Cc: Ching-Chun Huang, Chia-Ping Tsai, chengyang.chou, Cheng-Yang Chou
scx_lib_init_probe() is a fentry probe auto-attached by every scheduler
via SCX_OPS_LOAD()/SCX_OPS_ATTACH(). Without CONFIG_FUNCTION_TRACER it
can't attach, and skel__attach()'s all-or-nothing semantics takes the
whole scheduler down.
Skip its autoload when /proc/sys/kernel/ftrace_enabled is absent, and
skip disabled programs in the post-load struct_ops association loop so
it doesn't try to associate a program with no FD. Reproduced and fixed
in vng with a CONFIG_FUNCTION_TRACER=n kernel.
Syncs the fix from https://github.com/sched-ext/scx/pull/3758. As
discussed in GitHub, once we stop supporting pre-6.18 kernels, this
workaround can be removed.
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
tools/sched_ext/include/scx/compat.h | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/tools/sched_ext/include/scx/compat.h b/tools/sched_ext/include/scx/compat.h
index 7c12df45fdba..faf608cbed55 100644
--- a/tools/sched_ext/include/scx/compat.h
+++ b/tools/sched_ext/include/scx/compat.h
@@ -361,13 +361,27 @@ static inline void __scx_ops_assoc_prog(struct bpf_program *prog,
}
#endif
+/*
+ * Whether the kernel supports function tracing (CONFIG_FUNCTION_TRACER),
+ * needed for fentry/fexit BPF programs to load or attach.
+ * /proc/sys/kernel/ftrace_enabled only exists when it's compiled in, so its
+ * presence is a cheap proxy.
+ */
+static inline bool __COMPAT_function_tracer_available(void)
+{
+ return access("/proc/sys/kernel/ftrace_enabled", F_OK) == 0;
+}
+
/* See SCX_OPS_OPEN() above for backward-compatibility handling. */
#define SCX_OPS_LOAD(__skel, __ops_name, __scx_name, __uei_name) ({ \
struct bpf_program *__prog; \
UEI_SET_SIZE(__skel, __ops_name, __uei_name); \
+ if (!__COMPAT_function_tracer_available()) \
+ bpf_program__set_autoload((__skel)->progs.scx_lib_init_probe, false); \
SCX_BUG_ON(__scx_name##__load((__skel)), "Failed to load skel"); \
bpf_object__for_each_program(__prog, (__skel)->obj) { \
- if (bpf_program__type(__prog) == BPF_PROG_TYPE_STRUCT_OPS) \
+ if (bpf_program__type(__prog) == BPF_PROG_TYPE_STRUCT_OPS || \
+ !bpf_program__autoload(__prog)) \
continue; \
__scx_ops_assoc_prog(__prog, (__skel)->maps.__ops_name, \
#__ops_name); \
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH sched_ext/for-7.4] tools/sched_ext: Skip scx_lib_init_probe() without CONFIG_FUNCTION_TRACER
2026-08-24 15:50 [PATCH sched_ext/for-7.4] tools/sched_ext: Skip scx_lib_init_probe() without CONFIG_FUNCTION_TRACER Cheng-Yang Chou
@ 2026-08-24 16:02 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-08-24 16:02 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: sched-ext
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The SCX_OPS_LOAD macro introduces a hard compile-time dependency on `scx_lib_init_probe` existing in the user's BPF skeleton, which will cause a C compiler error for schedulers that do not define this probe.
--
--- Patch [1]: [PATCH sched_ext/for-7.4] tools/sched_ext: Skip scx_lib_init_probe() without CONFIG_FUNCTION_TRACER ---
commit fc2df7f154a3b0d6909630ef49d7036552669ee3
Author: Cheng-Yang Chou <yphbchou0911@gmail.com>
tools/sched_ext: Skip scx_lib_init_probe() without CONFIG_FUNCTION_TRACER
This commit updates the SCX_OPS_LOAD macro to conditionally disable
autoload for the scx_lib_init_probe program if function tracing is
unavailable. It also modifies the post-load loop to skip programs that
have autoload disabled.
> diff --git a/tools/sched_ext/include/scx/compat.h b/tools/sched_ext/include/scx/compat.h
> --- a/tools/sched_ext/include/scx/compat.h
> +++ b/tools/sched_ext/include/scx/compat.h
[ ... ]
> /* See SCX_OPS_OPEN() above for backward-compatibility handling. */
> #define SCX_OPS_LOAD(__skel, __ops_name, __scx_name, __uei_name) ({ \
> struct bpf_program *__prog; \
> UEI_SET_SIZE(__skel, __ops_name, __uei_name); \
> + if (!__COMPAT_function_tracer_available()) \
> + bpf_program__set_autoload((__skel)->progs.scx_lib_init_probe, false); \
[Severity: Medium]
Will this cause a compile-time failure for out-of-tree schedulers that do
not include a scx_lib_init_probe program?
Skeletons generated by bpftool only contain fields for BPF programs that
are actually present in the BPF object. If a user's scheduler skeleton
lacks this specific probe, (__skel)->progs.scx_lib_init_probe won't exist
in the generated struct and will trigger a C compiler error when invoking
this macro.
Could this look up the program dynamically using
bpf_object__find_program_by_name() at runtime instead, to avoid breaking
compilation for schedulers without this probe?
> SCX_BUG_ON(__scx_name##__load((__skel)), "Failed to load skel"); \
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260824155051.20841-1-yphbchou0911@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-24 16:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-24 15:50 [PATCH sched_ext/for-7.4] tools/sched_ext: Skip scx_lib_init_probe() without CONFIG_FUNCTION_TRACER Cheng-Yang Chou
2026-08-24 16:02 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox