mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-31 06:14:39 +01:00
perf build: Move BPF skeleton generation out of Makefile.perf
Currently, the top-level Makefile.perf defines a massive global bpf-skel umbrella target that pre-compiles all 12+ BPF skeletons (%.skel.h) upfront before launching sub-makes. This forces unrelated sub-makes to serialize behind bpftool and clang BPF target evaluations, causing parallel build bottlenecks. Furthermore, bench_uprobe.bpf.c lived inside util/bpf_skel/, breaking conceptual directory encapsulation since it is consumed purely by bench/uprobe.c. Refactor the BPF skeletons to better achieve directory isolation: 1. Move tools/perf/util/bpf_skel/bench_uprobe.bpf.c directly into tools/perf/bench/bpf_skel/. 2. Extract the skeleton generation infrastructure out of Makefile.perf into a shared inclusion file tools/perf/bpf_skel.mak. 3. Include bpf_skel.mak locally inside tools/perf/util/Build and tools/perf/bench/Build and bind precise local prerequisites. 4. Safely synchronize the shared bpftool bootstrap and vmlinux.h targets via the conditional prepare: umbrella to avoid parallel sub-make races, while evaluating the actual skeletons completely locally on demand. A later patch will move these targets into bpf_skel.mak. 5. Export CLANG from the global Makefile to ensure accurate tool propagation. 6. Clean up Makefile.perf by stripping the global bpf-skel umbrella target and its SKELETONS list. While removing code from Makefile.perf generally helps build performance, the impact here is minimal. The main motivation for the change is to better encapsulate things in the build and simplify Makefile.perf that has around 50 lines removed. Reviewed-by: Namhyung Kim <[email protected]> Assisted-by: Gemini:gemini-3.1-pro-preview Signed-off-by: Ian Rogers <[email protected]> Tested-by: James Clark <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Albert Ou <[email protected]> Cc: Alexandre Chartre <[email protected]> Cc: Alexandre Ghiti <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Ankur Arora <[email protected]> Cc: Collin Funk <[email protected]> Cc: Costa Shulyupin <[email protected]> Cc: Daniel Borkmann <[email protected]> Cc: Dapeng Mi <[email protected]> Cc: David Sterba <[email protected]> Cc: Dmitrii Dolgov <[email protected]> Cc: Eduard Zingerman <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kumar Kartikeya Dwivedi <[email protected]> Cc: Leo Yan <[email protected]> Cc: Markus Mayer <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nick Terrell <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Quentin Monnet <[email protected]> Cc: Ricky Ringler <[email protected]> Cc: Song Liu <[email protected]> Cc: Swapnil Sapkal <[email protected]> Cc: Thomas Falcon <[email protected]> Cc: Tomas Glozar <[email protected]> Cc: Yonghong Song <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
This commit is contained in:
1 parent
5af31e1573
commit
713eeb2279
6 files changed
+78
-56
No files matched your search
@@ -274,7 +274,7 @@ ifeq ($(PYLINT),1)
|
||||
PYLINT := $(shell which pylint 2> /dev/null)
|
||||
endif
|
||||
|
||||
export srctree OUTPUT RM CC CXX RUSTC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK
|
||||
export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF
|
||||
export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT
|
||||
|
||||
include $(srctree)/tools/build/Makefile.include
|
||||
@@ -632,8 +632,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE \
|
||||
$(LIBAPI) \
|
||||
$(LIBPERF) \
|
||||
$(LIBSUBCMD) \
|
||||
$(LIBSYMBOL) \
|
||||
bpf-skel
|
||||
$(LIBSYMBOL)
|
||||
|
||||
ifdef LIBBPF_STATIC
|
||||
prepare: $(LIBBPF)
|
||||
@@ -914,44 +913,13 @@ python-clean:
|
||||
|
||||
SKEL_OUT := $(abspath $(OUTPUT)util/bpf_skel)
|
||||
SKEL_TMP_OUT := $(abspath $(SKEL_OUT)/.tmp)
|
||||
SKELETONS := $(SKEL_OUT)/bpf_prog_profiler.skel.h
|
||||
SKELETONS += $(SKEL_OUT)/bperf_leader.skel.h $(SKEL_OUT)/bperf_follower.skel.h
|
||||
SKELETONS += $(SKEL_OUT)/bperf_cgroup.skel.h $(SKEL_OUT)/func_latency.skel.h
|
||||
SKELETONS += $(SKEL_OUT)/off_cpu.skel.h $(SKEL_OUT)/lock_contention.skel.h
|
||||
SKELETONS += $(SKEL_OUT)/kwork_trace.skel.h $(SKEL_OUT)/sample_filter.skel.h
|
||||
SKELETONS += $(SKEL_OUT)/kwork_top.skel.h $(SKEL_OUT)/syscall_summary.skel.h
|
||||
SKELETONS += $(SKEL_OUT)/bench_uprobe.skel.h
|
||||
SKELETONS += $(SKEL_OUT)/augmented_raw_syscalls.skel.h
|
||||
|
||||
$(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT):
|
||||
$(Q)$(MKDIR) -p $@
|
||||
|
||||
ifeq ($(CONFIG_PERF_BPF_SKEL),y)
|
||||
prepare: $(BPFTOOL) $(SKEL_OUT)/vmlinux.h
|
||||
BPFTOOL := $(SKEL_TMP_OUT)/bootstrap/bpftool
|
||||
# Get Clang's default includes on this system, as opposed to those seen by
|
||||
# '--target=bpf'. This fixes "missing" files on some architectures/distros,
|
||||
# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
|
||||
#
|
||||
# Use '-idirafter': Don't interfere with include mechanics except where the
|
||||
# build would have failed anyways.
|
||||
define get_sys_includes
|
||||
$(shell $(1) $(2) -v -E - </dev/null 2>&1 \
|
||||
| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
|
||||
$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}')
|
||||
endef
|
||||
|
||||
ifneq ($(CROSS_COMPILE),)
|
||||
CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%))
|
||||
endif
|
||||
|
||||
CLANG_OPTIONS = -Wall
|
||||
CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
|
||||
BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES)
|
||||
TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi
|
||||
|
||||
ifneq ($(WERROR),0)
|
||||
CLANG_OPTIONS += -Werror
|
||||
endif
|
||||
|
||||
$(BPFTOOL): | $(SKEL_TMP_OUT)
|
||||
$(Q)CFLAGS= $(MAKE) -C ../bpf/bpftool \
|
||||
@@ -993,29 +961,10 @@ else
|
||||
$(Q)cp "$(VMLINUX_H)" $@
|
||||
endif
|
||||
|
||||
$(SKEL_TMP_OUT)/%.bpf.o: $(OUTPUT)PERF-VERSION-FILE util/bpf_skel/perf_version.h | $(SKEL_TMP_OUT)
|
||||
$(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(LIBBPF) $(SKEL_OUT)/vmlinux.h
|
||||
$(QUIET_CLANG)$(CLANG) -g -O2 -fno-stack-protector --target=bpf \
|
||||
$(CLANG_OPTIONS) $(EXTRA_BPF_FLAGS) $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \
|
||||
-include $(OUTPUT)PERF-VERSION-FILE -include util/bpf_skel/perf_version.h \
|
||||
-fms-extensions -Wno-microsoft-anon-tag \
|
||||
-c $(filter util/bpf_skel/%.bpf.c,$^) -o $@
|
||||
|
||||
$(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o | $(BPFTOOL)
|
||||
$(QUIET_GENSKEL)$(BPFTOOL) gen skeleton $< > $@
|
||||
|
||||
bpf-skel: $(SKELETONS)
|
||||
|
||||
.PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o
|
||||
|
||||
else # CONFIG_PERF_BPF_SKEL
|
||||
|
||||
bpf-skel:
|
||||
|
||||
endif # CONFIG_PERF_BPF_SKEL
|
||||
|
||||
bpf-skel-clean:
|
||||
$(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS) $(SKEL_OUT)/vmlinux.h
|
||||
$(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKEL_OUT)/*.skel.h $(SKEL_OUT)/vmlinux.h $(OUTPUT)bench/bpf_skel/*.skel.h $(OUTPUT)bench/bpf_skel/.tmp
|
||||
|
||||
pmu-events-clean:
|
||||
ifeq ($(OUTPUT),)
|
||||
|
||||
@@ -24,3 +24,9 @@ perf-bench-$(CONFIG_X86_64) += mem-memcpy-x86-64-asm.o
|
||||
perf-bench-$(CONFIG_X86_64) += mem-memset-x86-64-asm.o
|
||||
|
||||
perf-bench-$(CONFIG_NUMA) += numa.o
|
||||
|
||||
ifeq ($(CONFIG_PERF_BPF_SKEL),y)
|
||||
include $(srctree)/tools/perf/bpf_skel.mak
|
||||
|
||||
$(OUTPUT)bench/uprobe.o: $(SKEL_OUT)/bench_uprobe.skel.h
|
||||
endif
|
||||
File renamed without changes.
@@ -44,7 +44,7 @@ static const char * const bench_uprobe_usage[] = {
|
||||
};
|
||||
|
||||
#ifdef HAVE_BPF_SKEL
|
||||
#include "bpf_skel/bench_uprobe.skel.h"
|
||||
#include "bench/bpf_skel/bench_uprobe.skel.h"
|
||||
|
||||
#define bench_uprobe__attach_uprobe(prog) \
|
||||
skel->links.prog = bpf_program__attach_uprobe_opts(/*prog=*/skel->progs.prog, \
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
# Shared BPF Skeleton Generator Rules
|
||||
|
||||
include $(srctree)/tools/scripts/Makefile.include
|
||||
|
||||
# Shared foundational tooling always lives in util/bpf_skel
|
||||
SKEL_TOOL_OUT := $(abspath $(OUTPUT)util/bpf_skel)
|
||||
SKEL_TOOL_TMP_OUT := $(abspath $(SKEL_TOOL_OUT)/.tmp)
|
||||
|
||||
# Component specific output lives in $(dir)/bpf_skel
|
||||
SKEL_OUT := $(abspath $(OUTPUT)$(dir)/bpf_skel)
|
||||
SKEL_TMP_OUT := $(abspath $(SKEL_OUT)/.tmp)
|
||||
|
||||
ifeq ($(CONFIG_PERF_BPF_SKEL),y)
|
||||
BPFTOOL := $(SKEL_TOOL_TMP_OUT)/bootstrap/bpftool
|
||||
VMLINUX_H := $(SKEL_TOOL_OUT)/vmlinux.h
|
||||
|
||||
define get_sys_includes
|
||||
$(shell $(1) $(2) -v -E - </dev/null 2>&1 \
|
||||
| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
|
||||
$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}')
|
||||
endef
|
||||
|
||||
ifneq ($(CROSS_COMPILE),)
|
||||
CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%))
|
||||
endif
|
||||
|
||||
CLANG_OPTIONS = -Wall
|
||||
CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
|
||||
LIBBPF_INCLUDE := $(abspath $(or $(OUTPUT),.))/libbpf/include
|
||||
BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(SKEL_TOOL_OUT) -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES)
|
||||
TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi
|
||||
|
||||
ifneq ($(WERROR),0)
|
||||
CLANG_OPTIONS += -Werror
|
||||
endif
|
||||
|
||||
# Consolidated Pattern rule for $(dir)/bpf_skel/
|
||||
$(SKEL_TMP_OUT)/%.bpf.o: $(srctree)/tools/perf/$(dir)/bpf_skel/%.bpf.c $(LIBBPF) $(VMLINUX_H) $(OUTPUT)PERF-VERSION-FILE util/bpf_skel/perf_version.h
|
||||
$(call rule_mkdir)
|
||||
$(QUIET_CLANG)
|
||||
$(Q)$(CLANG) -g -O2 -fno-stack-protector --target=bpf \
|
||||
$(CLANG_OPTIONS) $(EXTRA_BPF_FLAGS) $(BPF_INCLUDE) $(TOOLS_UAPI_INCLUDE) \
|
||||
-include $(OUTPUT)PERF-VERSION-FILE -include util/bpf_skel/perf_version.h \
|
||||
-fms-extensions -Wno-microsoft-anon-tag \
|
||||
-c $< -o $@
|
||||
|
||||
$(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o $(BPFTOOL)
|
||||
$(call rule_mkdir)
|
||||
$(QUIET_GENSKEL)
|
||||
$(Q)$(BPFTOOL) gen skeleton $< > $@
|
||||
|
||||
.PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o
|
||||
endif # CONFIG_PERF_BPF_SKEL
|
||||
@@ -441,4 +441,17 @@ $(OUTPUT)%.pylint_log: %
|
||||
|
||||
perf-util-y += $(PYLINT_TEST_LOGS)
|
||||
|
||||
ifeq ($(CONFIG_PERF_BPF_SKEL),y)
|
||||
include $(srctree)/tools/perf/bpf_skel.mak
|
||||
|
||||
$(OUTPUT)util/bpf_ftrace.o: $(SKEL_OUT)/func_latency.skel.h
|
||||
$(OUTPUT)util/bpf-filter.o: $(SKEL_OUT)/sample_filter.skel.h
|
||||
$(OUTPUT)util/bpf_kwork_top.o: $(SKEL_OUT)/kwork_top.skel.h
|
||||
$(OUTPUT)util/bpf_off_cpu.o: $(SKEL_OUT)/off_cpu.skel.h
|
||||
$(OUTPUT)util/bpf-trace-summary.o: $(SKEL_OUT)/syscall_summary.skel.h
|
||||
$(OUTPUT)util/bpf_counter_cgroup.o: $(SKEL_OUT)/bperf_cgroup.skel.h
|
||||
$(OUTPUT)util/bpf_trace_augment.o: $(SKEL_OUT)/augmented_raw_syscalls.skel.h
|
||||
$(OUTPUT)util/bpf_counter.o: $(SKEL_OUT)/bpf_prog_profiler.skel.h $(SKEL_OUT)/bperf_leader.skel.h $(SKEL_OUT)/bperf_follower.skel.h
|
||||
$(OUTPUT)util/bpf_lock_contention.o: $(SKEL_OUT)/lock_contention.skel.h
|
||||
$(OUTPUT)util/bpf_kwork.o: $(SKEL_OUT)/kwork_trace.skel.h
|
||||
endif
|
||||
Reference in new issue
Block a user