Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools/sched_ext/include: Add libbpf version guard for assoc_struct_ops

Extract the inline bpf_program__assoc_struct_ops() call in SCX_OPS_LOAD()
into a __scx_ops_assoc_prog() helper and wrap it with a libbpf >= 1.7
version guard. bpf_program__assoc_struct_ops() was added in libbpf 1.7;
the guard provides a no-op fallback for older versions. Add the
<bpf/libbpf.h> include needed by the helper, and fix "assumming" typo in
a nearby comment.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Andrea Righi <arighi@nvidia.com>

Tejun Heo 93ac9b15 c9c8546c

+29 -6
+29 -6
tools/sched_ext/include/scx/compat.h
··· 8 8 #define __SCX_COMPAT_H 9 9 10 10 #include <bpf/btf.h> 11 + #include <bpf/libbpf.h> 11 12 #include <fcntl.h> 12 13 #include <stdlib.h> 13 14 #include <unistd.h> ··· 183 182 __skel; \ 184 183 }) 185 184 185 + /* 186 + * Associate non-struct_ops BPF programs with the scheduler's struct_ops map so 187 + * that scx_prog_sched() can determine which scheduler a BPF program belongs 188 + * to. Requires libbpf >= 1.7. 189 + */ 190 + #if LIBBPF_MAJOR_VERSION > 1 || \ 191 + (LIBBPF_MAJOR_VERSION == 1 && LIBBPF_MINOR_VERSION >= 7) 192 + static inline void __scx_ops_assoc_prog(struct bpf_program *prog, 193 + struct bpf_map *map, 194 + const char *ops_name) 195 + { 196 + s32 err = bpf_program__assoc_struct_ops(prog, map, NULL); 197 + if (err) 198 + fprintf(stderr, 199 + "ERROR: Failed to associate %s with %s: %d\n", 200 + bpf_program__name(prog), ops_name, err); 201 + } 202 + #else 203 + static inline void __scx_ops_assoc_prog(struct bpf_program *prog, 204 + struct bpf_map *map, 205 + const char *ops_name) 206 + { 207 + } 208 + #endif 209 + 186 210 #define SCX_OPS_LOAD(__skel, __ops_name, __scx_name, __uei_name) ({ \ 187 211 struct bpf_program *__prog; \ 188 212 UEI_SET_SIZE(__skel, __ops_name, __uei_name); \ ··· 215 189 bpf_object__for_each_program(__prog, (__skel)->obj) { \ 216 190 if (bpf_program__type(__prog) == BPF_PROG_TYPE_STRUCT_OPS) \ 217 191 continue; \ 218 - s32 err = bpf_program__assoc_struct_ops(__prog, \ 219 - (__skel)->maps.__ops_name, NULL); \ 220 - if (err) \ 221 - fprintf(stderr, "ERROR: Failed to associate %s with %s: %d\n", \ 222 - bpf_program__name(__prog), #__ops_name, err); \ 192 + __scx_ops_assoc_prog(__prog, (__skel)->maps.__ops_name, \ 193 + #__ops_name); \ 223 194 } \ 224 195 }) 225 196 226 197 /* 227 198 * New versions of bpftool now emit additional link placeholders for BPF maps, 228 199 * and set up BPF skeleton in such a way that libbpf will auto-attach BPF maps 229 - * automatically, assumming libbpf is recent enough (v1.5+). Old libbpf will do 200 + * automatically, assuming libbpf is recent enough (v1.5+). Old libbpf will do 230 201 * nothing with those links and won't attempt to auto-attach maps. 231 202 * 232 203 * To maintain compatibility with older libbpf while avoiding trying to attach