sched_ext carried its own ~130 lines of libbpf + bpftool + vmlinux.h + BPF-object + skeleton build machinery. Replace it with an include of the shared tools/testing/selftests/lib.bpf.mk, making sched_ext the third in-tree consumer of that fragment, after selftests/cgroup and selftests/hid. All 28 skeletons and 28 subskeletons keep a same public API before and after, the runner builds and links the same way. Suggested-by: Eduard Zingerman Suggested-by: Mykola Lysenko Assisted-by: Claude:claude-opus-5 Signed-off-by: Ziyang Men --- tools/testing/selftests/sched_ext/Makefile | 146 +++++---------------- 1 file changed, 30 insertions(+), 116 deletions(-) diff --git a/tools/testing/selftests/sched_ext/Makefile b/tools/testing/selftests/sched_ext/Makefile index 5d2dffca0e91..620e8cb31e6f 100644 --- a/tools/testing/selftests/sched_ext/Makefile +++ b/tools/testing/selftests/sched_ext/Makefile @@ -14,48 +14,32 @@ CURDIR := $(abspath .) REPOROOT := $(abspath ../../../..) TOOLSDIR := $(REPOROOT)/tools LIBDIR := $(TOOLSDIR)/lib -BPFDIR := $(LIBDIR)/bpf TOOLSINCDIR := $(TOOLSDIR)/include -BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool APIDIR := $(TOOLSINCDIR)/uapi GENDIR := $(REPOROOT)/include/generated GENHDR := $(GENDIR)/autoconf.h -SCXTOOLSDIR := $(TOOLSDIR)/sched_ext SCXTOOLSINCDIR := $(TOOLSDIR)/sched_ext/include -OUTPUT_DIR := $(OUTPUT)/build -OBJ_DIR := $(OUTPUT_DIR)/obj -INCLUDE_DIR := $(OUTPUT_DIR)/include -BPFOBJ_DIR := $(OBJ_DIR)/libbpf -SCXOBJ_DIR := $(OBJ_DIR)/sched_ext -BPFOBJ := $(BPFOBJ_DIR)/libbpf.a -LIBBPF_OUTPUT := $(OBJ_DIR)/libbpf/libbpf.a - -DEFAULT_BPFTOOL := $(OUTPUT_DIR)/host/sbin/bpftool -HOST_OBJ_DIR := $(OBJ_DIR)/host/bpftool -HOST_LIBBPF_OUTPUT := $(OBJ_DIR)/host/libbpf/ -HOST_LIBBPF_DESTDIR := $(OUTPUT_DIR)/host/ -HOST_DESTDIR := $(OUTPUT_DIR)/host/ - -VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ - $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ - ../../../../vmlinux \ - /sys/kernel/btf/vmlinux \ - /boot/vmlinux-$(shell uname -r) -VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) -ifeq ($(VMLINUX_BTF),) -$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)") -endif +# The schedulers are built by ../lib.bpf.mk: modern *.bpf.c layout, a +# .bpf.skel.h suffix, and subskeletons. +BPF_SRCS := $(wildcard *.bpf.c) +BPF_SKEL_EXT := .bpf.skel.h +BPF_GEN_SUBSKEL := 1 +# Keep the generated files under build/ as before. SCXOBJ_DIR (userspace +# objects) reuses the BPF object dir. +BPF_OBJ_DIR := $(OUTPUT)/build/obj/sched_ext +BPF_SKEL_DIR := $(OUTPUT)/build/include +SCXOBJ_DIR := $(BPF_OBJ_DIR) -BPFTOOL ?= $(DEFAULT_BPFTOOL) +include ../lib.bpf.mk ifneq ($(wildcard $(GENHDR)),) GENFLAGS := -DHAVE_GENHDR endif CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS) \ - -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ - -I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include -I$(SCXTOOLSINCDIR) + -I$(GENDIR) -I$(LIBDIR) -I$(TOOLSINCDIR) -I$(APIDIR) \ + -I$(CURDIR)/include -I$(SCXTOOLSINCDIR) # Silence some warnings when compiled with clang ifneq ($(LLVM),) @@ -64,102 +48,30 @@ endif LDFLAGS = -lelf -lz -lpthread -lzstd -IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - &1 \ - | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ -$(shell $(1) $(2) -dM -E - $@ -else - $(call msg,CP,,$@) - $(Q)cp "$(VMLINUX_H)" $@ -endif + $(BPF_EXTRA_CFLAGS) -$(SCXOBJ_DIR)/%.bpf.o: %.bpf.c $(INCLUDE_DIR)/vmlinux.h | $(BPFOBJ) $(SCXOBJ_DIR) - $(call msg,CLNG-BPF,,$(notdir $@)) - $(Q)$(CLANG) $(BPF_CFLAGS) -target bpf -c $< -o $@ - -$(INCLUDE_DIR)/%.bpf.skel.h: $(SCXOBJ_DIR)/%.bpf.o $(INCLUDE_DIR)/vmlinux.h $(BPFTOOL) | $(INCLUDE_DIR) - $(eval sched=$(notdir $@)) - $(call msg,GEN-SKEL,,$(sched)) - $(Q)$(BPFTOOL) gen object $(<:.o=.linked1.o) $< - $(Q)$(BPFTOOL) gen object $(<:.o=.linked2.o) $(<:.o=.linked1.o) - $(Q)$(BPFTOOL) gen object $(<:.o=.linked3.o) $(<:.o=.linked2.o) - $(Q)diff $(<:.o=.linked2.o) $(<:.o=.linked3.o) - $(Q)$(BPFTOOL) gen skeleton $(<:.o=.linked3.o) name $(subst .bpf.skel.h,,$(sched)) > $@ - $(Q)$(BPFTOOL) gen subskeleton $(<:.o=.linked3.o) name $(subst .bpf.skel.h,,$(sched)) > $(@:.skel.h=.subskel.h) +EXTRA_CLEAN += $(OUTPUT)/build ################ # C schedulers # ################ -override define CLEAN - rm -rf $(OUTPUT_DIR) - rm -f $(TEST_GEN_PROGS) -endef - -# Every testcase takes all of the BPF progs are dependencies by default. This +# Every testcase takes all of the BPF progs as dependencies by default. This # allows testcases to load any BPF scheduler, which is useful for testcases # that don't need their own prog to run their test. -all_test_bpfprogs := $(foreach prog,$(wildcard *.bpf.c),$(INCLUDE_DIR)/$(patsubst %.c,%.skel.h,$(prog))) +all_test_bpfprogs := $(BPF_SKELS) auto-test-targets := \ create_dsq \ @@ -195,7 +107,8 @@ auto-test-targets := \ testcase-targets := $(addsuffix .o,$(addprefix $(SCXOBJ_DIR)/,$(auto-test-targets))) $(SCXOBJ_DIR)/runner.o: runner.c | $(SCXOBJ_DIR) $(BPFOBJ) - $(CC) $(CFLAGS) -c $< -o $@ + $(call msg,CC,,$@) + $(Q)$(CC) $(CFLAGS) -c $< -o $@ # Create all of the test targets object files, whose testcase objects will be # registered into the runner in ELF constructors. @@ -204,15 +117,16 @@ $(SCXOBJ_DIR)/runner.o: runner.c | $(SCXOBJ_DIR) $(BPFOBJ) # compiling BPF object files only if one is present, as the wildcard Make # function doesn't support using implicit rules otherwise. $(testcase-targets): $(SCXOBJ_DIR)/%.o: %.c $(SCXOBJ_DIR)/runner.o $(all_test_bpfprogs) | $(SCXOBJ_DIR) - $(eval test=$(patsubst %.o,%.c,$(notdir $@))) - $(CC) $(CFLAGS) -c $< -o $@ + $(call msg,CC,,$@) + $(Q)$(CC) $(CFLAGS) -c $< -o $@ $(SCXOBJ_DIR)/util.o: util.c | $(SCXOBJ_DIR) - $(CC) $(CFLAGS) -c $< -o $@ + $(call msg,CC,,$@) + $(Q)$(CC) $(CFLAGS) -c $< -o $@ $(OUTPUT)/runner: $(SCXOBJ_DIR)/runner.o $(SCXOBJ_DIR)/util.o $(BPFOBJ) $(testcase-targets) - @echo "$(testcase-targets)" - $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) + $(call msg,BINARY,,$@) + $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) .DEFAULT_GOAL := all -- 2.53.0-Meta