From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj2-f3.google.com (mail-pj2-f3.google.com [74.125.227.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66326415F32 for ; Tue, 21 Jul 2026 17:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784656131; cv=none; b=rpBR3s4letWe5NZJOlbUNyjCtp9VDG+/PVBgDzJLsZXT8n059KPlj8/SNpOPI5QSou/Z6v9IGfAQNwOgWpIWU/35yAmwwXyAub3HXClHAI47dPpWUOPKmmXb7nuL3U6I7c3KbYJumEijAk5oY/t8gJTGv/GvmnbX59NAgluQIW4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784656131; c=relaxed/simple; bh=+fRWz032Ue1fMDnjt8nBJt0lr8qqkpM0+XI+1mNdwjA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LyS1ypUVLbX+Rc9tYFw+nOfVItkpj4aQ53/hhOeW6oNB8dWi1VlCwKXYoWPKW/tN5vKRUdekS4pYjeVdZdjPa6tCxB/DYxrWz/UHf6T16uFkzTL7ASM2dhuakeuoeKAFCYdVxZU4ZMzR50sIDaj/1NqUBUimtdIl7E6UrXXeEjc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nJ2OqJln; arc=none smtp.client-ip=74.125.227.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nJ2OqJln" Received: by mail-pj2-f3.google.com with SMTP id 98e67ed59e1d1-38dadcaf0f0so2528204a91.1 for ; Tue, 21 Jul 2026 10:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784656126; x=1785260926; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=V1HVbnWwjz/zPGwxKegdY4p1KeImHVO8vqQ7kQJ99fQ=; b=nJ2OqJlnR05TlUwDW37eUv3kZb69nltnK2CXWUrV3Rhx+PzAqOQhiuBayNxjj56G2P 31FW+VRsJSTsvoxBhEO3mYDTZZcbNsq/reNj3OYaukN1hkCqIK2H3UIrsUhSM1mN0vGG 2uFeV7VmGNROOfqbV6HXLo0JCzS1bqPbnIiZXss3sgAgAsZNVCL9SGN2REZjlZjqXSHx D89uz2F+OS3Sw5xEkkpMy8hSAcm2P//09sagAcoqNaeNW+7Nmmlkj/E9yq1xSe17LX/N bN5C5fm7NcM19qEn1Zlb+WkJTv4jDrgUkPuab600Plsab+Crd/lq+9ou+0K7JOfE2nQA 8Fwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784656126; x=1785260926; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=V1HVbnWwjz/zPGwxKegdY4p1KeImHVO8vqQ7kQJ99fQ=; b=b6Y70TmyYOWe7S4RYACO71zj0XlCNtahJZGlts4KmRtRWxRM3O7GxxZyaExAiJw8Yv p9tZEcD+ggH8FQJZHO+lcfDivuGZGRc9k/44R8RiRxiyxbq6QKheGm2Pch0Za5HCGIP2 /e+pa8h7L8Q9fis2I6zSXfMjDlx2+XlWS3B99LCOXAvqvBokKtuUKQVN6wY12cqsbWBF QAoiOx0IvRdSkMfOKk4HjA7QS8tBpfQBMpttXsAoHtwRbvQdYo5QQUibtUC+pJ8GVs1Z /KhihW5bCv7asLkD5HO9GhW392VKrkgB1H9UebAiemPIyEXiRawNN2uog5vBHsMcbUpm aHGA== X-Forwarded-Encrypted: i=1; AHgh+RqPGxG8n+O8N2KKlOqVip2im/5BG2NVuucsZ/cOEHqcCiRvIK2/Q1HIQp0uSYdXMUIoNl4N1iIgg44Miw==@vger.kernel.org X-Gm-Message-State: AOJu0Yx6tKLA7Ne0SfzWqe8OCqtw4F+VIREzkXNxAVaEjrrDIi7OkGRo mucycKBY/4EhNNoRyyS47S8jb7LkSEPPmbwoFzODmj08pQVoGPTrDTZJ X-Gm-Gg: AR+sD127voEI2Fq7tLbLlIAlwTppWmbEOzO4V/5o365yzB9/tqtw3bHniseMoYe6eN2 4OxtyiNmb91ET7u1oW6b0D9sNQ4iiHXHaH4fFXQfzgUnZNd+NjXdwBstcjqK6SKZ3dWs99s4rVL kPoNkkHVfyMzJcUYWxCxVlRPesYMtKm+vcSiXq3X3cTwuddNeqUqe6fEa/nco/ZMSCPTFg4t0fC J5on/fntw5S1FOiqODOKC3HqgkPrtoAXGpffRrXDW7AD+Wu9il/b7SM8FpQmNU0JkGcNX4fgo5n PkpBOL7QgS7gTzNN19OENzlzQBl4goiyiD5tGO3vEpV8MK18nGgju8GXy0EL6jGp24eCOa6qM2H IMLsCYO/I/txwHelIJhShkAoYluHHU1DkFatcmOkkPRuITMx387bGc4rP7qwqcZk2eGgGryCk7o WJNZjPIz4= X-Received: by 2002:a05:6a21:114c:b0:3bf:a489:1483 with SMTP id adf61e73a8af0-3c3ad80c23dmr20107991637.33.1784656125438; Tue, 21 Jul 2026 10:48:45 -0700 (PDT) Received: from localhost ([2a03:2880:9ff:65::]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147e1b6a45sm872370eec.28.2026.07.21.10.48.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2026 10:48:44 -0700 (PDT) From: Ziyang Men To: Shuah Khan , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Jiri Kosina , Benjamin Tissoires , David Vernet , Eduard Zingerman Cc: Andrea Righi , Changwoo Min , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , JP Kobryn , Mykola Lysenko , Nathan Chancellor , linux-kselftest@vger.kernel.org, cgroups@vger.kernel.org, linux-input@vger.kernel.org, sched-ext@lists.linux.dev, linux-mm@kvack.org, kernel-team@meta.com, bpf@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Ziyang Men Subject: [PATCH v2 4/4] selftests/sched_ext: build BPF schedulers via the shared lib.bpf.mk Date: Tue, 21 Jul 2026 10:48:33 -0700 Message-ID: <20260721174833.1232771-5-ziyang.meme@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260721174833.1232771-1-ziyang.meme@gmail.com> References: <20260721174833.1232771-1-ziyang.meme@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. sched_ext emits a skeleton and a subskeleton per scheduler with a .bpf.skel.h suffix, so it sets BPF_SKEL_EXT := .bpf.skel.h and BPF_GEN_SUBSKEL := 1. Its BPF programs need scheduler-specific include paths and are not -Werror clean, so it overrides BPF_CFLAGS wholesale after the include; the userspace runner/testcase rules are kept and repointed at the fragment's flat $(OUTPUT) skeletons. No functional change: all 28 skeletons and 28 subskeletons keep a byte-identical public API before and after, the runner builds and links the same way, and the folder builds cleanly under both plain make and LLVM=1. Suggested-by: Shakeel Butt Suggested-by: Eduard Zingerman Suggested-by: Mykola Lysenko Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ziyang Men --- tools/testing/selftests/sched_ext/Makefile | 153 +++++---------------- 1 file changed, 35 insertions(+), 118 deletions(-) diff --git a/tools/testing/selftests/sched_ext/Makefile b/tools/testing/selftests/sched_ext/Makefile index 5d2dffca0e91..67ff96bf34e8 100644 --- a/tools/testing/selftests/sched_ext/Makefile +++ b/tools/testing/selftests/sched_ext/Makefile @@ -14,48 +14,36 @@ 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 - -BPFTOOL ?= $(DEFAULT_BPFTOOL) +# The BPF schedulers are compiled into skeletons + subskeletons by the shared +# lib.bpf.mk fragment. They use the modern *.bpf.c layout with a .bpf.skel.h +# suffix and need subskeletons. +BPF_SRCS := $(wildcard *.bpf.c) +BPF_SKEL_EXT := .bpf.skel.h +BPF_GEN_SUBSKEL := 1 +BPF_EXTRA_HDRS = $(wildcard $(CURDIR)/include/scx/*.h) \ + $(wildcard $(CURDIR)/include/*.h) +# Keep generated files under build/ as before (skeletons in build/include, +# objects in build/obj) rather than flat in the source dir. lib.bpf.mk creates +# these dirs; 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) + +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 +52,29 @@ 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 + -fms-extensions -$(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 +110,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 +120,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