perf build: Support building BPF skeletons with bpf-gcc
Subsystems (2)
Ian Rogers
reviewercover perf build: Support building BPF skeletons with bpf-gcc
Currently the perf build requires clang (>= 12.0.1) to compile BPF skeleton programs (.bpf.c -> .bpf.o). bpf-gcc (>= 14.0.0) also supports BPF CO-RE and BTF generation and is already supported in tools/testing/selftests/bpf/Makefile.
This series updates the perf build to support both clang and bpf-gcc:
- Patch 1 updates Makefile.config, Makefile.perf, and bpf_skel.mak to prefer bpf-gcc when building perf with GCC (CC_NO_CLANG=1) and clang when building with Clang/LLVM (CC_NO_CLANG=0), while respecting explicit BPF_GCC=... or CLANG=... command-line overrides and falling back to whichever compiler is available.
- Patch 2 adds make_bpf_skel_clang and make_bpf_skel_bpf_gcc build-test targets to tools/perf/tests/make and verifies with
'perf check -q feature bpf_skeletons' that BPF skeleton support is enabled (or disabled for make_no_bpf_skel) as expected.
Ian Rogers (2):
perf build: Support building BPF skeletons with bpf-gcc perf test make: Add BPF skeleton build tests for clang and bpf-gcc
tools/perf/Makefile.config | 81 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 36 ++++++++++----- tools/perf/tests/make | 29 ++++++++++++ tools/scripts/Makefile.include | 1 + 5 files changed, 126 insertions(+), 29 deletions(-)
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
Ian Rogers
reviewerPATCH 1/2 perf build: Support building BPF skeletons with bpf-gcc
Support building perf BPF skeletons with bpf-gcc (>= 14.0.0) in addition to clang (>= 12.0.1), similar to tools/testing/selftests/bpf/Makefile.
When building perf with GCC (CC_NO_CLANG=1), prefer bpf-gcc and fall back to clang if bpf-gcc is unavailable or too old. When building with Clang/LLVM (CC_NO_CLANG=0), prefer clang and fall back to bpf-gcc. Explicit command-line overrides via BPF_GCC=... or CLANG=... are respected, and setting BPF_GCC= or CLANG= to empty disables that compiler.
In bpf_skel.mak, pass the bpf-gcc flags (-mcpu=v3, -fno-ident, -DBPF_NO_PRESERVE_ACCESS_INDEX, -Wno-attributes, -D__TARGET_ARCH_$(SRCARCH), and target endianness) and query system include paths from $(CC).
--- tools/perf/Makefile.config | 81 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 36 ++++++++++----- tools/scripts/Makefile.include | 1 + 4 files changed, 97 insertions(+), 29 deletions(-)
tools/perf/Makefile.config +65 -16
@@ -662,27 +662,76 @@ ifeq ($(BUILD_BPF_SKEL),1) else ifeq ($(filter -DHAVE_LIBOPENSSL_SUPPORT, $(CFLAGS)),) $(warning Warning: Disabled BPF skeletons as libopenssl is required) BUILD_BPF_SKEL := 0 - else ifeq ($(call get-executable,$(CLANG)),) - $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing) - BUILD_BPF_SKEL := 0 - else - CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') - ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) - $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) - BUILD_BPF_SKEL := 0 - endif endif ifeq ($(BUILD_BPF_SKEL),1) - $(call feature_check,clang-bpf-co-re) - ifeq ($(feature-clang-bpf-co-re), 0) - $(warning Warning: Disabled BPF skeletons as clang is too old) + # Prefer bpf-gcc when building with gcc (CC_NO_CLANG=1) and clang when + # building with clang, unless CLANG or BPF_GCC was explicitly specified on + # the command line. Fall back to whichever compiler is available. + prefer_bpf_gcc := $(CC_NO_CLANG) + ifeq ($(origin BPF_GCC),command line) + ifneq ($(BPF_GCC),) + prefer_bpf_gcc := 1 + endif + else ifeq ($(origin CLANG),command line) + ifneq ($(CLANG),) + prefer_bpf_gcc := 0 + endif + endif + + have_bpf_gcc := 0 + have_clang_bpf := 0 + + define check_bpf_gcc + ifneq ($$(call get-executable,$$(BPF_GCC)),) + BPF_GCC_VERSION := $$(shell $$(BPF_GCC) -dumpfullversion -dumpversion 2>/dev/null) + ifneq ($$(call version-lt3,$$(BPF_GCC_VERSION),14.0.0),1) + have_bpf_gcc := 1 + endif + endif + endef + + ifeq ($(prefer_bpf_gcc),1) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),0) + ifneq ($(call get-executable,$(CLANG)),) + CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') + ifneq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(call feature_check,clang-bpf-co-re) + ifeq ($(feature-clang-bpf-co-re), 1) + have_clang_bpf := 1 + endif + endif + endif + endif + + ifeq ($(prefer_bpf_gcc)$(have_clang_bpf),00) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),1) + $(call detected,CONFIG_PERF_BPF_SKEL_BPF_GCC) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else ifeq ($(have_clang_bpf),1) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else + ifeq ($(call get-executable,$(CLANG))$(call get-executable,$(BPF_GCC)),) + $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) and bpf-gcc ($(BPF_GCC)) are missing) + else ifneq ($(call get-executable,$(CLANG)),) + ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) + else + $(warning Warning: Disabled BPF skeletons as clang is too old) + endif + else + $(warning Warning: Disabled BPF skeletons as bpf-gcc ($(BPF_GCC)) needs at least version 14.0.0) + endif BUILD_BPF_SKEL := 0 endif endif - ifeq ($(BUILD_BPF_SKEL),1) - $(call detected,CONFIG_PERF_BPF_SKEL) - CFLAGS += -DHAVE_BPF_SKEL - endif endif ifndef GEN_VMLINUX_H
tools/perf/Makefile.perf +6 -2
@@ -37,6 +37,9 @@ include ../scripts/utilities.mak # Define EXTRA_BPF_FLAGS="--sysroot=<path>" or other custom include paths for # cross-compiling BPF skeletons # +# Define BPF_GCC to point to the bpf-gcc binary if the default `bpf-gcc' is not +# correct, or set BPF_GCC= to disable using bpf-gcc for BPF skeletons. +# # Define EXCLUDE_EXTLIBS=-lmylib to exclude libmylib from the auto-generated # EXTLIBS. #
@@ -208,6 +211,7 @@ FIND = find INSTALL = install FLEX ?= flex BISON ?= bison +BPF_GCC ?= bpf-gcc AWK = awk # include Makefile.config by default and rule out
@@ -321,8 +325,8 @@ ifneq ($(force_fixdep),1) endif endif -export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF -export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL +export srctree OUTPUT RM CC CXX RUSTC CLANG BPF_GCC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF +export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL CONFIG_PERF_BPF_SKEL_BPF_GCC include $(srctree)/tools/build/Makefile.include
tools/perf/bpf_skel.mak +25 -11
@@ -22,21 +22,35 @@ bpf-skel-prepare: $(BPFTOOL) $(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)}') +$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') \ +$(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf("-D__BITS_PER_LONG=%d", $$3)}') \ +$(shell $(1) $(2) -dM -E - </dev/null | grep -E 'MIPS(EL|EB)|_MIPS_SZ(PTR|LONG) |_MIPS_SIM |_ABI(O32|N32|64) ' | awk '{printf("-D%s=%s ", $$2, $$3)}') endef -ifneq ($(CROSS_COMPILE),) -CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) +ifeq ($(CONFIG_PERF_BPF_SKEL_BPF_GCC),y) + BPF_CC := $(BPF_GCC) + QUIET_BPF_CC = $(QUIET_BPF_GCC) + IS_LITTLE_ENDIAN := $(shell $(CC) -dM -E - </dev/null | \ + grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__') + BPF_OPTIONS = -Wall -mcpu=v3 -fno-ident -DBPF_NO_PRESERVE_ACCESS_INDEX -Wno-attributes \ + -D__TARGET_ARCH_$(SRCARCH) $(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) + BPF_SYS_INCLUDES = $(call get_sys_includes,$(CC),) +else + BPF_CC := $(CLANG) + QUIET_BPF_CC = $(QUIET_CLANG) + ifneq ($(CROSS_COMPILE),) + CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) + endif + BPF_OPTIONS = -Wall -mcpu=v3 -fno-stack-protector --target=bpf -Wno-microsoft-anon-tag + BPF_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) endif -CLANG_OPTIONS = -Wall -mcpu=v3 -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) +BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(SKEL_TOOL_OUT) -I$(LIBBPF_INCLUDE) $(BPF_SYS_INCLUDES) TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi ifneq ($(WERROR),0) - CLANG_OPTIONS += -Werror + BPF_OPTIONS += -Werror endif $(BPFTOOL):
@@ -83,11 +97,11 @@ 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) \ + $(QUIET_BPF_CC) + $(Q)$(BPF_CC) -g -O2 \ + $(BPF_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 \ + -fms-extensions \ -c $< -o $@ $(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o $(BPFTOOL)
tools/scripts/Makefile.include +1 -0
@@ -217,6 +217,7 @@ ifneq ($(silent),1) QUIET_CC = @echo ' CC '$@; QUIET_CC_FPIC = @echo ' CC FPIC '$@; QUIET_CLANG = @echo ' CLANG '$@; + QUIET_BPF_GCC = @echo ' BPF_GCC '$@; QUIET_AR = @echo ' AR '$@; QUIET_LINK = @echo ' LINK '$@; QUIET_MKDIR = @echo ' MKDIR '$@;
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf build: bpf-gcc version check bypassed due to mutually exclusive GCC arguments --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf build: bpf-gcc version check bypassed due to mutually exclusive GCC arguments --
commit b2c0a31ec137ebce8b46644a6edfe507e7c3b298
Author: Ian Rogers <[email protected]>
perf build: Support building BPF skeletons with bpf-gcc
This commit supports building perf BPF skeletons with bpf-gcc (>= 14.0.0) in addition to clang. It updates the build system to prefer bpf-gcc when building with GCC, and falls back to Clang if bpf-gcc is unavailable or too old.
Quoted 3 lines
tools/perf/Makefile.config +0
-0
[ ... ]
tools/perf/Makefile.config ifeq ($(BUILD_BPF_SKEL),1) · line 686
Quoted 3 lines
tools/perf/Makefile.config +3
-0+ define check_bpf_gcc + ifneq ($$(call get-executable,$$(BPF_GCC)),) + BPF_GCC_VERSION := $$(shell $$(BPF_GCC) -dumpfullversion -dumpversion 2>/dev/null)
[Severity: Medium]
Does passing both -dumpfullversion and -dumpversion simultaneously cause GCC to fail with a fatal error?
If GCC rejects these mutually exclusive arguments, the error output is suppressed by 2>/dev/null, resulting in BPF_GCC_VERSION evaluating to an empty string.
tools/perf/Makefile.config ifeq ($(BUILD_BPF_SKEL),1) · line 689
Quoted 3 lines
tools/perf/Makefile.config +3
-0+ ifneq ($$(call version-lt3,$$(BPF_GCC_VERSION),14.0.0),1) + have_bpf_gcc := 1 + endif
When version-lt3 is called with an empty string against 14.0.0, the underlying awk expression evaluates this as false (0). The outer check ifneq (0,1) then evaluates to true, unconditionally setting have_bpf_gcc := 1.
Can this regression result in the version check being completely bypassed, allowing older, unsupported versions of bpf-gcc to be incorrectly permitted to build BPF skeletons instead of properly falling back to Clang?
Quoted 2 lines
tools/perf/Makefile.config +2
-0+ endif + endef
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Ian Rogers
reviewerPATCH 2/2 perf test make: Add BPF skeleton build tests for clang and bpf-gcc
In reply to Ian RogersAdd make_bpf_skel_clang (CLANG=clang BPF_GCC=) and make_bpf_skel_bpf_gcc (BPF_GCC=bpf-gcc CLANG=) targets to tools/perf/tests/make when the corresponding compiler and BPF skeleton dependencies are available on the host. Verify with 'perf check -q feature bpf_skeletons' that BPF skeleton support is enabled for both targets and disabled for make_no_bpf_skel.
--- tools/perf/tests/make | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
tools/perf/tests/make +29 -0
@@ -78,6 +78,8 @@ make_extra_tests := EXTRA_TESTS=1 make_no_jevents := NO_JEVENTS=1 make_jevents_all := JEVENTS_ARCH=all make_no_bpf_skel := BUILD_BPF_SKEL=0 +make_bpf_skel_clang := CLANG=clang BPF_GCC= +make_bpf_skel_bpf_gcc := BPF_GCC=bpf-gcc CLANG= make_gen_vmlinux_h := GEN_VMLINUX_H=1 make_no_python_module := NO_PYTHON_MODULE=1 make_no_scripts := NO_PYTHON_MODULE=1
@@ -142,6 +144,20 @@ have_libllvm := $(shell printf '#include <llvm/Support/ManagedStatic.h>\n#includ $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null) >/dev/null 2>&1 && echo y) endif +have_bpf_skel_deps := $(shell printf '#include <libelf.h>\n#include <zlib.h>\n#include <linux/bpf.h>\n#include <openssl/opensslv.h>\nint main(){return 0;}\n' | \ + $(CC) -x c -I$(srctree)/tools/include/uapi - -o /dev/null -lelf -lz -lcrypto >/dev/null 2>&1 && echo y) + +ifneq ($(have_bpf_skel_deps),) +ifneq ($(call has,clang),) +have_clang_bpf := $(shell printf '#if (__clang_major__ < 12) || (__clang_major__ == 12 && __clang_minor__ == 0 && __clang_patchlevel__ < 1)\n#error "old"\n#endif\n' | \ + clang -S -g --target=bpf -x c - -o /dev/null >/dev/null 2>&1 && echo y) +endif +ifneq ($(call has,bpf-gcc),) +have_bpf_gcc := $(shell printf '#if __GNUC__ < 14\n#error "old"\n#endif\n' | \ + bpf-gcc -E -x c - >/dev/null 2>&1 && echo y) +endif +endif + # $(run) contains all available tests run := make_pure # Targets 'clean all' can be run together only through top level
@@ -173,6 +189,12 @@ run += make_extra_tests run += make_no_jevents run += make_jevents_all run += make_no_bpf_skel +ifneq ($(have_clang_bpf),) +run += make_bpf_skel_clang +endif +ifneq ($(have_bpf_gcc),) +run += make_bpf_skel_bpf_gcc +endif run += make_gen_vmlinux_h run += make_no_python_module run += make_no_scripts
@@ -313,6 +335,13 @@ test_make_clang_nondistro := $(test_make_clang) test_make_clang_nondistro_O := $(test_make_clang_O) endif +test_make_no_bpf_skel := test -x $(PERF_O)/perf && ! $(PERF_O)/perf check -q feature bpf_skeletons +test_make_no_bpf_skel_O := test -x $$TMP_O/perf && ! $$TMP_O/perf check -q feature bpf_skeletons +test_make_bpf_skel_clang := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature bpf_skeletons +test_make_bpf_skel_clang_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature bpf_skeletons +test_make_bpf_skel_bpf_gcc := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature bpf_skeletons +test_make_bpf_skel_bpf_gcc_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature bpf_skeletons + test_make_python_perf_so_O := test -f $$TMP_O/python/perf.so test_make_perf_o_O := test -f $$TMP_O/perf.o test_make_util_map_o_O := test -f $$TMP_O/util/map.o
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
[email protected]
AI reviewRe: [PATCH v1 2/2] perf test make: Add BPF skeleton build tests for clang and bpf-gcc
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
Add
make_bpf_skel_clang(CLANG=clang BPF_GCC=) andmake_bpf_skel_bpf_gcc(BPF_GCC=bpf-gcc CLANG=) targets totools/perf/tests/makewhen the corresponding compiler and BPF skeleton dependencies are available on the host. Verify with 'perf check -q featurebpf_skeletons' that BPF skeleton support is enabled for both targets and disabled formake_no_bpf_skel.Assisted-by Antigravity:gemini-3.1-proSigned-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Ian Rogers
reviewerv2 cover perf build: Support building BPF skeletons with bpf-gcc
In reply to Ian RogersCurrently the perf build requires clang (>= 12.0.1) to compile BPF skeleton programs (.bpf.c -> .bpf.o). bpf-gcc (>= 14.0.0) also supports BPF CO-RE and BTF generation and is already supported in tools/testing/selftests/bpf/Makefile.
This series updates the perf build to support both clang and bpf-gcc:
- Patch 1 updates Makefile.config, Makefile.perf, and bpf_skel.mak to prefer bpf-gcc when building perf with GCC (CC_NO_CLANG=1) and clang when building with Clang/LLVM (CC_NO_CLANG=0), while respecting explicit BPF_GCC=... or CLANG=... command-line overrides and falling back to whichever compiler is available.
- Patch 2 adds make_bpf_skel_clang and make_bpf_skel_bpf_gcc build-test targets to tools/perf/tests/make and verifies with
'perf check -q feature bpf_skeletons' that BPF skeleton support is enabled (or disabled for make_no_bpf_skel) as expected.
v2: Pass only -dumpfullversion when querying BPF_GCC_VERSION, guard
against an empty version string, and fix version-ge3 / version-lt3 in tools/scripts/utilities.mak so empty or <3-component version strings do not shift awk fields and evaluate as false in version-lt3.
Ian Rogers (2):
perf build: Support building BPF skeletons with bpf-gcc perf test make: Add BPF skeleton build tests for clang and bpf-gcc
tools/perf/Makefile.config | 83 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 36 ++++++++++----- tools/perf/tests/make | 29 ++++++++++++ tools/scripts/Makefile.include | 1 + tools/scripts/utilities.mak | 4 +- 6 files changed, 130 insertions(+), 31 deletions(-)
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
Ian Rogers
reviewerPATCH v2 1/2 perf build: Support building BPF skeletons with bpf-gcc
Support building perf BPF skeletons with bpf-gcc (>= 14.0.0) in addition to clang (>= 12.0.1), similar to tools/testing/selftests/bpf/Makefile.
When building perf with GCC (CC_NO_CLANG=1), prefer bpf-gcc and fall back to clang if bpf-gcc is unavailable or too old. When building with Clang/LLVM (CC_NO_CLANG=0), prefer clang and fall back to bpf-gcc. Explicit command-line overrides via BPF_GCC=... or CLANG=... are respected, and setting BPF_GCC= or CLANG= to empty disables that compiler.
In bpf_skel.mak, pass the bpf-gcc flags (-mcpu=v3, -fno-ident, -DBPF_NO_PRESERVE_ACCESS_INDEX, -Wno-attributes, -D__TARGET_ARCH_$(SRCARCH), and target endianness) and query system include paths from $(CC).
Also update version-ge3 and version-lt3 in tools/scripts/utilities.mak to split the two version arguments separately in awk so empty or fewer-than-3-component version strings do not shift fields across arguments.
--- tools/perf/Makefile.config | 83 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 36 ++++++++++----- tools/scripts/Makefile.include | 1 + tools/scripts/utilities.mak | 4 +- 5 files changed, 101 insertions(+), 31 deletions(-)
tools/perf/Makefile.config +67 -16
@@ -662,27 +662,78 @@ ifeq ($(BUILD_BPF_SKEL),1) else ifeq ($(filter -DHAVE_LIBOPENSSL_SUPPORT, $(CFLAGS)),) $(warning Warning: Disabled BPF skeletons as libopenssl is required) BUILD_BPF_SKEL := 0 - else ifeq ($(call get-executable,$(CLANG)),) - $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing) - BUILD_BPF_SKEL := 0 - else - CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') - ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) - $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) - BUILD_BPF_SKEL := 0 - endif endif ifeq ($(BUILD_BPF_SKEL),1) - $(call feature_check,clang-bpf-co-re) - ifeq ($(feature-clang-bpf-co-re), 0) - $(warning Warning: Disabled BPF skeletons as clang is too old) + # Prefer bpf-gcc when building with gcc (CC_NO_CLANG=1) and clang when + # building with clang, unless CLANG or BPF_GCC was explicitly specified on + # the command line. Fall back to whichever compiler is available. + prefer_bpf_gcc := $(CC_NO_CLANG) + ifeq ($(origin BPF_GCC),command line) + ifneq ($(BPF_GCC),) + prefer_bpf_gcc := 1 + endif + else ifeq ($(origin CLANG),command line) + ifneq ($(CLANG),) + prefer_bpf_gcc := 0 + endif + endif + + have_bpf_gcc := 0 + have_clang_bpf := 0 + + define check_bpf_gcc + ifneq ($$(call get-executable,$$(BPF_GCC)),) + BPF_GCC_VERSION := $$(shell $$(BPF_GCC) -dumpfullversion 2>/dev/null) + ifneq ($$(BPF_GCC_VERSION),) + ifneq ($$(call version-lt3,$$(BPF_GCC_VERSION),14.0.0),1) + have_bpf_gcc := 1 + endif + endif + endif + endef + + ifeq ($(prefer_bpf_gcc),1) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),0) + ifneq ($(call get-executable,$(CLANG)),) + CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') + ifneq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(call feature_check,clang-bpf-co-re) + ifeq ($(feature-clang-bpf-co-re), 1) + have_clang_bpf := 1 + endif + endif + endif + endif + + ifeq ($(prefer_bpf_gcc)$(have_clang_bpf),00) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),1) + $(call detected,CONFIG_PERF_BPF_SKEL_BPF_GCC) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else ifeq ($(have_clang_bpf),1) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else + ifeq ($(call get-executable,$(CLANG))$(call get-executable,$(BPF_GCC)),) + $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) and bpf-gcc ($(BPF_GCC)) are missing) + else ifneq ($(call get-executable,$(CLANG)),) + ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) + else + $(warning Warning: Disabled BPF skeletons as clang is too old) + endif + else + $(warning Warning: Disabled BPF skeletons as bpf-gcc ($(BPF_GCC)) needs at least version 14.0.0) + endif BUILD_BPF_SKEL := 0 endif endif - ifeq ($(BUILD_BPF_SKEL),1) - $(call detected,CONFIG_PERF_BPF_SKEL) - CFLAGS += -DHAVE_BPF_SKEL - endif endif ifndef GEN_VMLINUX_H
tools/perf/Makefile.perf +6 -2
@@ -37,6 +37,9 @@ include ../scripts/utilities.mak # Define EXTRA_BPF_FLAGS="--sysroot=<path>" or other custom include paths for # cross-compiling BPF skeletons # +# Define BPF_GCC to point to the bpf-gcc binary if the default `bpf-gcc' is not +# correct, or set BPF_GCC= to disable using bpf-gcc for BPF skeletons. +# # Define EXCLUDE_EXTLIBS=-lmylib to exclude libmylib from the auto-generated # EXTLIBS. #
@@ -208,6 +211,7 @@ FIND = find INSTALL = install FLEX ?= flex BISON ?= bison +BPF_GCC ?= bpf-gcc AWK = awk # include Makefile.config by default and rule out
@@ -321,8 +325,8 @@ ifneq ($(force_fixdep),1) endif endif -export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF -export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL +export srctree OUTPUT RM CC CXX RUSTC CLANG BPF_GCC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF +export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL CONFIG_PERF_BPF_SKEL_BPF_GCC include $(srctree)/tools/build/Makefile.include
tools/perf/bpf_skel.mak +25 -11
@@ -22,21 +22,35 @@ bpf-skel-prepare: $(BPFTOOL) $(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)}') +$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') \ +$(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf("-D__BITS_PER_LONG=%d", $$3)}') \ +$(shell $(1) $(2) -dM -E - </dev/null | grep -E 'MIPS(EL|EB)|_MIPS_SZ(PTR|LONG) |_MIPS_SIM |_ABI(O32|N32|64) ' | awk '{printf("-D%s=%s ", $$2, $$3)}') endef -ifneq ($(CROSS_COMPILE),) -CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) +ifeq ($(CONFIG_PERF_BPF_SKEL_BPF_GCC),y) + BPF_CC := $(BPF_GCC) + QUIET_BPF_CC = $(QUIET_BPF_GCC) + IS_LITTLE_ENDIAN := $(shell $(CC) -dM -E - </dev/null | \ + grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__') + BPF_OPTIONS = -Wall -mcpu=v3 -fno-ident -DBPF_NO_PRESERVE_ACCESS_INDEX -Wno-attributes \ + -D__TARGET_ARCH_$(SRCARCH) $(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) + BPF_SYS_INCLUDES = $(call get_sys_includes,$(CC),) +else + BPF_CC := $(CLANG) + QUIET_BPF_CC = $(QUIET_CLANG) + ifneq ($(CROSS_COMPILE),) + CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) + endif + BPF_OPTIONS = -Wall -mcpu=v3 -fno-stack-protector --target=bpf -Wno-microsoft-anon-tag + BPF_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) endif -CLANG_OPTIONS = -Wall -mcpu=v3 -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) +BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(SKEL_TOOL_OUT) -I$(LIBBPF_INCLUDE) $(BPF_SYS_INCLUDES) TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi ifneq ($(WERROR),0) - CLANG_OPTIONS += -Werror + BPF_OPTIONS += -Werror endif $(BPFTOOL):
@@ -83,11 +97,11 @@ 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) \ + $(QUIET_BPF_CC) + $(Q)$(BPF_CC) -g -O2 \ + $(BPF_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 \ + -fms-extensions \ -c $< -o $@ $(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o $(BPFTOOL)
tools/scripts/Makefile.include +1 -0
@@ -217,6 +217,7 @@ ifneq ($(silent),1) QUIET_CC = @echo ' CC '$@; QUIET_CC_FPIC = @echo ' CC FPIC '$@; QUIET_CLANG = @echo ' CLANG '$@; + QUIET_BPF_GCC = @echo ' BPF_GCC '$@; QUIET_AR = @echo ' AR '$@; QUIET_LINK = @echo ' LINK '$@; QUIET_MKDIR = @echo ' MKDIR '$@;
tools/scripts/utilities.mak +2 -2
@@ -186,7 +186,7 @@ _gea_err = $(if $(1),$(error Please set '$(1)' appropriately)) # was to check the flex version to see if we can use compiler warnings as # errors for one of the cases flex generates code C compilers complains about. -version-ge3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * $$1 + 10000 * $$2 + $$3) >= (10000000 * $$4 + 10000 * $$5 + $$6)) }') +version-ge3 = $(shell awk -v v1="$(1)" -v v2="$(2)" 'BEGIN { split(v1, a, "."); split(v2, b, "."); printf("%d\n", (10000000 * a[1] + 10000 * a[2] + a[3]) >= (10000000 * b[1] + 10000 * b[2] + b[3])) }') # version-lt3 #
@@ -196,4 +196,4 @@ version-ge3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * # check the flex version to see if we can use compiler warnings as errors for # one of the cases flex generates code C compilers complains about. -version-lt3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * $$1 + 10000 * $$2 + $$3) < (10000000 * $$4 + 10000 * $$5 + $$6)) }') +version-lt3 = $(shell awk -v v1="$(1)" -v v2="$(2)" 'BEGIN { split(v1, a, "."); split(v2, b, "."); printf("%d\n", (10000000 * a[1] + 10000 * a[2] + a[3]) < (10000000 * b[1] + 10000 * b[2] + b[3])) }')
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
Support building perf BPF skeletons with bpf-gcc (>= 14.0.0) in addition to clang (>= 12.0.1), similar to
tools/testing/selftests/bpf/Makefile.When building perf with GCC (CC_NO_CLANG=1), prefer bpf-gcc and fall back to clang if bpf-gcc is unavailable or too old. When building with Clang/LLVM (CC_NO_CLANG=0), prefer clang and fall back to bpf-gcc. Explicit command-line overrides via BPF_GCC=... or CLANG=... are respected, and setting BPF_GCC= or CLANG= to empty disables that compiler.
In bpf_skel.mak, pass the bpf-gcc flags (-mcpu=v3, -fno-ident,
(quoted diff) +0
-2-DBPF_NO_PRESERVE_ACCESS_INDEX, -Wno-attributes, -D__TARGET_ARCH_$(SRCARCH), and target endianness) and query systeminclude paths from $(CC).
Quoted 7 lines
Also update version-ge3 and version-lt3 in
tools/scripts/utilities.makto split the two version arguments separately in awk so empty or fewer-than-3-component version strings do not shift fields across arguments.Assisted-by Antigravity:gemini-3.1-proSigned-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Ian Rogers
reviewerPATCH v2 2/2 perf test make: Add BPF skeleton build tests for clang and bpf-gcc
In reply to Ian RogersAdd make_bpf_skel_clang (CLANG=clang BPF_GCC=) and make_bpf_skel_bpf_gcc (BPF_GCC=bpf-gcc CLANG=) targets to tools/perf/tests/make when the corresponding compiler and BPF skeleton dependencies are available on the host. Verify with 'perf check -q feature bpf_skeletons' that BPF skeleton support is enabled for both targets and disabled for make_no_bpf_skel.
--- tools/perf/tests/make | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
tools/perf/tests/make +29 -0
@@ -78,6 +78,8 @@ make_extra_tests := EXTRA_TESTS=1 make_no_jevents := NO_JEVENTS=1 make_jevents_all := JEVENTS_ARCH=all make_no_bpf_skel := BUILD_BPF_SKEL=0 +make_bpf_skel_clang := CLANG=clang BPF_GCC= +make_bpf_skel_bpf_gcc := BPF_GCC=bpf-gcc CLANG= make_gen_vmlinux_h := GEN_VMLINUX_H=1 make_no_python_module := NO_PYTHON_MODULE=1 make_no_scripts := NO_PYTHON_MODULE=1
@@ -142,6 +144,20 @@ have_libllvm := $(shell printf '#include <llvm/Support/ManagedStatic.h>\n#includ $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null) >/dev/null 2>&1 && echo y) endif +have_bpf_skel_deps := $(shell printf '#include <libelf.h>\n#include <zlib.h>\n#include <linux/bpf.h>\n#include <openssl/opensslv.h>\nint main(){return 0;}\n' | \ + $(CC) -x c -I$(srctree)/tools/include/uapi - -o /dev/null -lelf -lz -lcrypto >/dev/null 2>&1 && echo y) + +ifneq ($(have_bpf_skel_deps),) +ifneq ($(call has,clang),) +have_clang_bpf := $(shell printf '#if (__clang_major__ < 12) || (__clang_major__ == 12 && __clang_minor__ == 0 && __clang_patchlevel__ < 1)\n#error "old"\n#endif\n' | \ + clang -S -g --target=bpf -x c - -o /dev/null >/dev/null 2>&1 && echo y) +endif +ifneq ($(call has,bpf-gcc),) +have_bpf_gcc := $(shell printf '#if __GNUC__ < 14\n#error "old"\n#endif\n' | \ + bpf-gcc -E -x c - >/dev/null 2>&1 && echo y) +endif +endif + # $(run) contains all available tests run := make_pure # Targets 'clean all' can be run together only through top level
@@ -173,6 +189,12 @@ run += make_extra_tests run += make_no_jevents run += make_jevents_all run += make_no_bpf_skel +ifneq ($(have_clang_bpf),) +run += make_bpf_skel_clang +endif +ifneq ($(have_bpf_gcc),) +run += make_bpf_skel_bpf_gcc +endif run += make_gen_vmlinux_h run += make_no_python_module run += make_no_scripts
@@ -313,6 +335,13 @@ test_make_clang_nondistro := $(test_make_clang) test_make_clang_nondistro_O := $(test_make_clang_O) endif +test_make_no_bpf_skel := test -x $(PERF_O)/perf && ! $(PERF_O)/perf check -q feature bpf_skeletons +test_make_no_bpf_skel_O := test -x $$TMP_O/perf && ! $$TMP_O/perf check -q feature bpf_skeletons +test_make_bpf_skel_clang := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature bpf_skeletons +test_make_bpf_skel_clang_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature bpf_skeletons +test_make_bpf_skel_bpf_gcc := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature bpf_skeletons +test_make_bpf_skel_bpf_gcc_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature bpf_skeletons + test_make_python_perf_so_O := test -f $$TMP_O/python/perf.so test_make_perf_o_O := test -f $$TMP_O/perf.o test_make_util_map_o_O := test -f $$TMP_O/util/map.o
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
[email protected]
AI reviewRe: [PATCH v2 2/2] perf test make: Add BPF skeleton build tests for clang and bpf-gcc
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] perf: bpf_skel test skipped due to missing pkg-config for OpenSSL - [Low] perf/tests: bash negation…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] perf: bpf_skel test skipped due to missing pkg-config for OpenSSL
- [Low] perf/tests: bash negation operator ! masks test framework crashes --
commit b1fbd7e0bcb15ba961fd484277db525d4021ba13
Author: Ian Rogers <[email protected]>
perf test make: Add BPF skeleton build tests for clang and bpf-gcc
Add make_bpf_skel_clang (CLANG=clang BPF_GCC=) and make_bpf_skel_bpf_gcc (BPF_GCC=bpf-gcc CLANG=) targets to tools/perf/tests/make when the corresponding compiler and BPF skeleton dependencies are available on the host.
Quoted 4 lines
tools/perf/tests/make +0
-0
[ ... ]
tools/perf/tests/make have_libllvm := $(shell printf '#include <llvm/Support/ManagedStatic.h>\n#includ · line 148
Quoted 6 lines
tools/perf/tests/make +2
-0@@ -142,6 +144,20 @@ have_libllvm := $(shell printf '#include <llvm/Support/ManagedStatic.h>\n#includ $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null) >/dev/null 2>&1 && echo y) endif +have_bpf_skel_deps := $(shell printf '#include <libelf.h>\n#include <zlib.h>\n#include <linux/bpf.h>\n#include <openssl/opensslv.h>\nint main(){return 0;}\n' | \ + $(CC) -x c -I$(srctree)/tools/include/uapi - -o /dev/null -lelf -lz -lcrypto >/dev/null 2>&1 && echo y)
[Severity: Low]
Does this hardcoded check fail to find OpenSSL on systems that require explicit paths via pkg-config?
Unlike tools/build/feature/Makefile which correctly utilizes pkg-config, it looks like missing pkg-config usage here could lead to silent test evasion on environments where OpenSSL is not in the default compiler search path.
Quoted 2 lines
tools/perf/tests/make +2
-0+ +ifneq ($(have_bpf_skel_deps),)
[ ... ]
tools/perf/tests/make test_make_clang_nondistro := $(test_make_clang) · line 339
Quoted 6 lines
tools/perf/tests/make +2
-0@@ -313,6 +335,13 @@ test_make_clang_nondistro := $(test_make_clang) test_make_clang_nondistro_O := $(test_make_clang_O) endif +test_make_no_bpf_skel := test -x $(PERF_O)/perf && ! $(PERF_O)/perf check -q feature bpf_skeletons +test_make_no_bpf_skel_O := test -x $$TMP_O/perf && ! $$TMP_O/perf check -q feature bpf_skeletons
[Severity: Low]
By using the shell negation operator !, does this prevent the framework from distinguishing between a graceful exit 1 (feature correctly absent) and a catastrophic crash (exit code >128)?
Would using an explicit exit code validation (e.g., ; test $? -eq 1) avoid masking crashes in the built perf check utility?
Quoted 5 lines
tools/perf/tests/make +5
-0+test_make_bpf_skel_clang := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature bpf_skeletons +test_make_bpf_skel_clang_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature bpf_skeletons +test_make_bpf_skel_bpf_gcc := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature bpf_skeletons +test_make_bpf_skel_bpf_gcc_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature bpf_skeletons +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Ian Rogers
reviewerv3 cover perf build: Support building BPF skeletons with bpf-gcc
In reply to Ian RogersCurrently the perf build requires clang (>= 12.0.1) to compile BPF skeleton programs (.bpf.c -> .bpf.o). bpf-gcc (>= 14.0.0) also supports BPF CO-RE and BTF generation and is already supported in tools/testing/selftests/bpf/Makefile.
This series updates the perf build to support both clang and bpf-gcc:
- Patch 1 updates Makefile.config, Makefile.perf, and bpf_skel.mak to prefer bpf-gcc when building perf with GCC (CC_NO_CLANG=1) and clang when building with Clang/LLVM (CC_NO_CLANG=0), while respecting explicit BPF_GCC=... or CLANG=... command-line overrides and falling back to whichever compiler is available.
- Patch 2 adds make_bpf_skel_clang and make_bpf_skel_bpf_gcc build-test targets to tools/perf/tests/make, reuses tools/build/Makefile.feature for feature detection, and verifies with
'perf check -q feature bpf_skeletons' that BPF skeleton support is enabled (or disabled for make_no_bpf_skel) as expected.
v3: Reuse tools/build/Makefile.feature and tools/scripts/utilities.mak
in tools/perf/tests/make rather than open-coding compiler feature probes, and explicitly check for exit code 1 from 'perf check' in make_no_bpf_skel so crashes are not masked by shell negation.
v2: Pass only -dumpfullversion when querying BPF_GCC_VERSION, guard
against an empty version string, and fix version-ge3 / version-lt3 in tools/scripts/utilities.mak so empty or <3-component version strings do not shift awk fields and evaluate as false in version-lt3.
Ian Rogers (2):
perf build: Support building BPF skeletons with bpf-gcc perf test make: Add BPF skeleton build tests for clang and bpf-gcc
tools/perf/Makefile.config | 83 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 36 ++++++++++----- tools/perf/tests/make | 71 ++++++++++++++++++++++------ tools/scripts/Makefile.include | 1 + tools/scripts/utilities.mak | 4 +- 6 files changed, 159 insertions(+), 44 deletions(-)
Signature · 1 line
2.56.0.307.g5fe7bd680c-goog
Ian Rogers
reviewerPATCH v3 1/2 perf build: Support building BPF skeletons with bpf-gcc
Support building perf BPF skeletons with bpf-gcc (>= 14.0.0) in addition to clang (>= 12.0.1), similar to tools/testing/selftests/bpf/Makefile.
When building perf with GCC (CC_NO_CLANG=1), prefer bpf-gcc and fall back to clang if bpf-gcc is unavailable or too old. When building with Clang/LLVM (CC_NO_CLANG=0), prefer clang and fall back to bpf-gcc. Explicit command-line overrides via BPF_GCC=... or CLANG=... are respected, and setting BPF_GCC= or CLANG= to empty disables that compiler.
In bpf_skel.mak, pass the bpf-gcc flags (-mcpu=v3, -fno-ident, -DBPF_NO_PRESERVE_ACCESS_INDEX, -Wno-attributes, -D__TARGET_ARCH_$(SRCARCH), and target endianness) and query system include paths from $(CC).
Also update version-ge3 and version-lt3 in tools/scripts/utilities.mak to split the two version arguments separately in awk so empty or fewer-than-3-component version strings do not shift fields across arguments.
--- tools/perf/Makefile.config | 83 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 36 ++++++++++----- tools/scripts/Makefile.include | 1 + tools/scripts/utilities.mak | 4 +- 5 files changed, 101 insertions(+), 31 deletions(-)
tools/perf/Makefile.config +67 -16
@@ -662,27 +662,78 @@ ifeq ($(BUILD_BPF_SKEL),1) else ifeq ($(filter -DHAVE_LIBOPENSSL_SUPPORT, $(CFLAGS)),) $(warning Warning: Disabled BPF skeletons as libopenssl is required) BUILD_BPF_SKEL := 0 - else ifeq ($(call get-executable,$(CLANG)),) - $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing) - BUILD_BPF_SKEL := 0 - else - CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') - ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) - $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) - BUILD_BPF_SKEL := 0 - endif endif ifeq ($(BUILD_BPF_SKEL),1) - $(call feature_check,clang-bpf-co-re) - ifeq ($(feature-clang-bpf-co-re), 0) - $(warning Warning: Disabled BPF skeletons as clang is too old) + # Prefer bpf-gcc when building with gcc (CC_NO_CLANG=1) and clang when + # building with clang, unless CLANG or BPF_GCC was explicitly specified on + # the command line. Fall back to whichever compiler is available. + prefer_bpf_gcc := $(CC_NO_CLANG) + ifeq ($(origin BPF_GCC),command line) + ifneq ($(BPF_GCC),) + prefer_bpf_gcc := 1 + endif + else ifeq ($(origin CLANG),command line) + ifneq ($(CLANG),) + prefer_bpf_gcc := 0 + endif + endif + + have_bpf_gcc := 0 + have_clang_bpf := 0 + + define check_bpf_gcc + ifneq ($$(call get-executable,$$(BPF_GCC)),) + BPF_GCC_VERSION := $$(shell $$(BPF_GCC) -dumpfullversion 2>/dev/null) + ifneq ($$(BPF_GCC_VERSION),) + ifneq ($$(call version-lt3,$$(BPF_GCC_VERSION),14.0.0),1) + have_bpf_gcc := 1 + endif + endif + endif + endef + + ifeq ($(prefer_bpf_gcc),1) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),0) + ifneq ($(call get-executable,$(CLANG)),) + CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') + ifneq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(call feature_check,clang-bpf-co-re) + ifneq ($(feature-clang-bpf-co-re), 0) + have_clang_bpf := 1 + endif + endif + endif + endif + + ifeq ($(prefer_bpf_gcc)$(have_clang_bpf),00) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),1) + $(call detected,CONFIG_PERF_BPF_SKEL_BPF_GCC) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else ifeq ($(have_clang_bpf),1) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else + ifeq ($(call get-executable,$(CLANG))$(call get-executable,$(BPF_GCC)),) + $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) and bpf-gcc ($(BPF_GCC)) are missing) + else ifneq ($(call get-executable,$(CLANG)),) + ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) + else + $(warning Warning: Disabled BPF skeletons as clang is too old) + endif + else + $(warning Warning: Disabled BPF skeletons as bpf-gcc ($(BPF_GCC)) needs at least version 14.0.0) + endif BUILD_BPF_SKEL := 0 endif endif - ifeq ($(BUILD_BPF_SKEL),1) - $(call detected,CONFIG_PERF_BPF_SKEL) - CFLAGS += -DHAVE_BPF_SKEL - endif endif ifndef GEN_VMLINUX_H
tools/perf/Makefile.perf +6 -2
@@ -37,6 +37,9 @@ include ../scripts/utilities.mak # Define EXTRA_BPF_FLAGS="--sysroot=<path>" or other custom include paths for # cross-compiling BPF skeletons # +# Define BPF_GCC to point to the bpf-gcc binary if the default `bpf-gcc' is not +# correct, or set BPF_GCC= to disable using bpf-gcc for BPF skeletons. +# # Define EXCLUDE_EXTLIBS=-lmylib to exclude libmylib from the auto-generated # EXTLIBS. #
@@ -208,6 +211,7 @@ FIND = find INSTALL = install FLEX ?= flex BISON ?= bison +BPF_GCC ?= bpf-gcc AWK = awk # include Makefile.config by default and rule out
@@ -321,8 +325,8 @@ ifneq ($(force_fixdep),1) endif endif -export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF -export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL +export srctree OUTPUT RM CC CXX RUSTC CLANG BPF_GCC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF +export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL CONFIG_PERF_BPF_SKEL_BPF_GCC include $(srctree)/tools/build/Makefile.include
tools/perf/bpf_skel.mak +25 -11
@@ -22,21 +22,35 @@ bpf-skel-prepare: $(BPFTOOL) $(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)}') +$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') \ +$(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf("-D__BITS_PER_LONG=%d", $$3)}') \ +$(shell $(1) $(2) -dM -E - </dev/null | grep -E 'MIPS(EL|EB)|_MIPS_SZ(PTR|LONG) |_MIPS_SIM |_ABI(O32|N32|64) ' | awk '{printf("-D%s=%s ", $$2, $$3)}') endef -ifneq ($(CROSS_COMPILE),) -CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) +ifeq ($(CONFIG_PERF_BPF_SKEL_BPF_GCC),y) + BPF_CC := $(BPF_GCC) + QUIET_BPF_CC = $(QUIET_BPF_GCC) + IS_LITTLE_ENDIAN := $(shell $(CC) -dM -E - </dev/null | \ + grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__') + BPF_OPTIONS = -Wall -mcpu=v3 -fno-ident -DBPF_NO_PRESERVE_ACCESS_INDEX -Wno-attributes \ + -D__TARGET_ARCH_$(SRCARCH) $(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) + BPF_SYS_INCLUDES = $(call get_sys_includes,$(CC),) +else + BPF_CC := $(CLANG) + QUIET_BPF_CC = $(QUIET_CLANG) + ifneq ($(CROSS_COMPILE),) + CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) + endif + BPF_OPTIONS = -Wall -mcpu=v3 -fno-stack-protector --target=bpf -Wno-microsoft-anon-tag + BPF_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) endif -CLANG_OPTIONS = -Wall -mcpu=v3 -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) +BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(SKEL_TOOL_OUT) -I$(LIBBPF_INCLUDE) $(BPF_SYS_INCLUDES) TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi ifneq ($(WERROR),0) - CLANG_OPTIONS += -Werror + BPF_OPTIONS += -Werror endif $(BPFTOOL):
@@ -83,11 +97,11 @@ 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) \ + $(QUIET_BPF_CC) + $(Q)$(BPF_CC) -g -O2 \ + $(BPF_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 \ + -fms-extensions \ -c $< -o $@ $(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o $(BPFTOOL)
tools/scripts/Makefile.include +1 -0
@@ -217,6 +217,7 @@ ifneq ($(silent),1) QUIET_CC = @echo ' CC '$@; QUIET_CC_FPIC = @echo ' CC FPIC '$@; QUIET_CLANG = @echo ' CLANG '$@; + QUIET_BPF_GCC = @echo ' BPF_GCC '$@; QUIET_AR = @echo ' AR '$@; QUIET_LINK = @echo ' LINK '$@; QUIET_MKDIR = @echo ' MKDIR '$@;
tools/scripts/utilities.mak +2 -2
@@ -186,7 +186,7 @@ _gea_err = $(if $(1),$(error Please set '$(1)' appropriately)) # was to check the flex version to see if we can use compiler warnings as # errors for one of the cases flex generates code C compilers complains about. -version-ge3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * $$1 + 10000 * $$2 + $$3) >= (10000000 * $$4 + 10000 * $$5 + $$6)) }') +version-ge3 = $(shell awk -v v1="$(1)" -v v2="$(2)" 'BEGIN { split(v1, a, "."); split(v2, b, "."); printf("%d\n", (10000000 * a[1] + 10000 * a[2] + a[3]) >= (10000000 * b[1] + 10000 * b[2] + b[3])) }') # version-lt3 #
@@ -196,4 +196,4 @@ version-ge3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * # check the flex version to see if we can use compiler warnings as errors for # one of the cases flex generates code C compilers complains about. -version-lt3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * $$1 + 10000 * $$2 + $$3) < (10000000 * $$4 + 10000 * $$5 + $$6)) }') +version-lt3 = $(shell awk -v v1="$(1)" -v v2="$(2)" 'BEGIN { split(v1, a, "."); split(v2, b, "."); printf("%d\n", (10000000 * a[1] + 10000 * a[2] + a[3]) < (10000000 * b[1] + 10000 * b[2] + b[3])) }')
Signature · 1 line
2.56.0.307.g5fe7bd680c-goog
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 15 lines
Support building perf BPF skeletons with bpf-gcc (>= 14.0.0) in addition to clang (>= 12.0.1), similar to
tools/testing/selftests/bpf/Makefile.When building perf with GCC (CC_NO_CLANG=1), prefer bpf-gcc and fall back to clang if bpf-gcc is unavailable or too old. When building with Clang/LLVM (CC_NO_CLANG=0), prefer clang and fall back to bpf-gcc. Explicit command-line overrides via BPF_GCC=... or CLANG=... are respected, and setting BPF_GCC= or CLANG= to empty disables that compiler.
In bpf_skel.mak, pass the bpf-gcc flags (-mcpu=v3, -fno-ident,
(quoted diff) +0
-2-DBPF_NO_PRESERVE_ACCESS_INDEX, -Wno-attributes, -D__TARGET_ARCH_$(SRCARCH), and target endianness) and query systeminclude paths from $(CC).
Quoted 7 lines
Also update version-ge3 and version-lt3 in
tools/scripts/utilities.makto split the two version arguments separately in awk so empty or fewer-than-3-component version strings do not shift fields across arguments.Assisted-by Antigravity:gemini-3.1-proSigned-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Namhyung Kim
maintainerQuoted 15 lines · Ian Rogers
Support building perf BPF skeletons with bpf-gcc (>= 14.0.0) in addition to clang (>= 12.0.1), similar to
tools/testing/selftests/bpf/Makefile.When building perf with GCC (CC_NO_CLANG=1), prefer bpf-gcc and fall back to clang if bpf-gcc is unavailable or too old. When building with Clang/LLVM (CC_NO_CLANG=0), prefer clang and fall back to bpf-gcc. Explicit command-line overrides via BPF_GCC=... or CLANG=... are respected, and setting BPF_GCC= or CLANG= to empty disables that compiler.
In bpf_skel.mak, pass the bpf-gcc flags (-mcpu=v3, -fno-ident,
(quoted diff) +0
-2-DBPF_NO_PRESERVE_ACCESS_INDEX, -Wno-attributes, -D__TARGET_ARCH_$(SRCARCH), and target endianness) and query systeminclude paths from $(CC).
Quoted 4 lines
Also update version-ge3 and version-lt3 in
tools/scripts/utilities.makto split the two version arguments separately in awk so empty or fewer-than-3-component version strings do not shift fields across arguments.
Sorry for the delay. But can you please split this part from the bpf-gcc changes?
Thanks,
Namhyung
Quoted 240 lines
Assisted-by Antigravity:gemini-3.1-proSigned-off-by Ian Rogers <[email protected]>--- tools/perf/Makefile.config | 83 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 36 ++++++++++----- tools/scripts/Makefile.include | 1 + tools/scripts/utilities.mak | 4 +- 5 files changed, 101 insertions(+), 31 deletions(-)tools/perf/Makefile.config +67
-16@@ -662,27 +662,78 @@ ifeq ($(BUILD_BPF_SKEL),1) else ifeq ($(filter -DHAVE_LIBOPENSSL_SUPPORT, $(CFLAGS)),) $(warning Warning: Disabled BPF skeletons as libopenssl is required) BUILD_BPF_SKEL := 0 - else ifeq ($(call get-executable,$(CLANG)),) - $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing) - BUILD_BPF_SKEL := 0 - else - CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') - ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) - $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) - BUILD_BPF_SKEL := 0 - endif endif ifeq ($(BUILD_BPF_SKEL),1) - $(call feature_check,clang-bpf-co-re) - ifeq ($(feature-clang-bpf-co-re), 0) - $(warning Warning: Disabled BPF skeletons as clang is too old) + # Prefer bpf-gcc when building with gcc (CC_NO_CLANG=1) and clang when + # building with clang, unless CLANG or BPF_GCC was explicitly specified on + # the command line. Fall back to whichever compiler is available. + prefer_bpf_gcc := $(CC_NO_CLANG) + ifeq ($(origin BPF_GCC),command line) + ifneq ($(BPF_GCC),) + prefer_bpf_gcc := 1 + endif + else ifeq ($(origin CLANG),command line) + ifneq ($(CLANG),) + prefer_bpf_gcc := 0 + endif + endif + + have_bpf_gcc := 0 + have_clang_bpf := 0 + + define check_bpf_gcc + ifneq ($$(call get-executable,$$(BPF_GCC)),) + BPF_GCC_VERSION := $$(shell $$(BPF_GCC) -dumpfullversion 2>/dev/null) + ifneq ($$(BPF_GCC_VERSION),) + ifneq ($$(call version-lt3,$$(BPF_GCC_VERSION),14.0.0),1) + have_bpf_gcc := 1 + endif + endif + endif + endef + + ifeq ($(prefer_bpf_gcc),1) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),0) + ifneq ($(call get-executable,$(CLANG)),) + CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') + ifneq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(call feature_check,clang-bpf-co-re) + ifneq ($(feature-clang-bpf-co-re), 0) + have_clang_bpf := 1 + endif + endif + endif + endif + + ifeq ($(prefer_bpf_gcc)$(have_clang_bpf),00) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),1) + $(call detected,CONFIG_PERF_BPF_SKEL_BPF_GCC) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else ifeq ($(have_clang_bpf),1) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else + ifeq ($(call get-executable,$(CLANG))$(call get-executable,$(BPF_GCC)),) + $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) and bpf-gcc ($(BPF_GCC)) are missing) + else ifneq ($(call get-executable,$(CLANG)),) + ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) + else + $(warning Warning: Disabled BPF skeletons as clang is too old) + endif + else + $(warning Warning: Disabled BPF skeletons as bpf-gcc ($(BPF_GCC)) needs at least version 14.0.0) + endif BUILD_BPF_SKEL := 0 endif endif - ifeq ($(BUILD_BPF_SKEL),1) - $(call detected,CONFIG_PERF_BPF_SKEL) - CFLAGS += -DHAVE_BPF_SKEL - endif endif ifndef GEN_VMLINUX_Htools/perf/Makefile.perf +6
-2@@ -37,6 +37,9 @@ include ../scripts/utilities.mak # Define EXTRA_BPF_FLAGS="--sysroot=<path>" or other custom include paths for # cross-compiling BPF skeletons # +# Define BPF_GCC to point to the bpf-gcc binary if the default `bpf-gcc' is not +# correct, or set BPF_GCC= to disable using bpf-gcc for BPF skeletons. +# # Define EXCLUDE_EXTLIBS=-lmylib to exclude libmylib from the auto-generated # EXTLIBS. #@@ -208,6 +211,7 @@ FIND = find INSTALL = install FLEX ?= flex BISON ?= bison +BPF_GCC ?= bpf-gcc AWK = awk # include Makefile.config by default and rule out@@ -321,8 +325,8 @@ ifneq ($(force_fixdep),1) endif endif -export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF -export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL +export srctree OUTPUT RM CC CXX RUSTC CLANG BPF_GCC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF +export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL CONFIG_PERF_BPF_SKEL_BPF_GCC include $(srctree)/tools/build/Makefile.includetools/perf/bpf_skel.mak +25
-11@@ -22,21 +22,35 @@ bpf-skel-prepare: $(BPFTOOL) $(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)}') +$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') \ +$(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf("-D__BITS_PER_LONG=%d", $$3)}') \ +$(shell $(1) $(2) -dM -E - </dev/null | grep -E 'MIPS(EL|EB)|_MIPS_SZ(PTR|LONG) |_MIPS_SIM |_ABI(O32|N32|64) ' | awk '{printf("-D%s=%s ", $$2, $$3)}') endef -ifneq ($(CROSS_COMPILE),) -CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) +ifeq ($(CONFIG_PERF_BPF_SKEL_BPF_GCC),y) + BPF_CC := $(BPF_GCC) + QUIET_BPF_CC = $(QUIET_BPF_GCC) + IS_LITTLE_ENDIAN := $(shell $(CC) -dM -E - </dev/null | \ + grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__') + BPF_OPTIONS = -Wall -mcpu=v3 -fno-ident -DBPF_NO_PRESERVE_ACCESS_INDEX -Wno-attributes \ + -D__TARGET_ARCH_$(SRCARCH) $(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) + BPF_SYS_INCLUDES = $(call get_sys_includes,$(CC),) +else + BPF_CC := $(CLANG) + QUIET_BPF_CC = $(QUIET_CLANG) + ifneq ($(CROSS_COMPILE),) + CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) + endif + BPF_OPTIONS = -Wall -mcpu=v3 -fno-stack-protector --target=bpf -Wno-microsoft-anon-tag + BPF_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) endif -CLANG_OPTIONS = -Wall -mcpu=v3 -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) +BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(SKEL_TOOL_OUT) -I$(LIBBPF_INCLUDE) $(BPF_SYS_INCLUDES) TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi ifneq ($(WERROR),0) - CLANG_OPTIONS += -Werror + BPF_OPTIONS += -Werror endif $(BPFTOOL):@@ -83,11 +97,11 @@ 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) \ + $(QUIET_BPF_CC) + $(Q)$(BPF_CC) -g -O2 \ + $(BPF_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 \ + -fms-extensions \ -c $< -o $@ $(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o $(BPFTOOL)tools/scripts/Makefile.include +1
-0@@ -217,6 +217,7 @@ ifneq ($(silent),1) QUIET_CC = @echo ' CC '$@; QUIET_CC_FPIC = @echo ' CC FPIC '$@; QUIET_CLANG = @echo ' CLANG '$@; + QUIET_BPF_GCC = @echo ' BPF_GCC '$@; QUIET_AR = @echo ' AR '$@; QUIET_LINK = @echo ' LINK '$@; QUIET_MKDIR = @echo ' MKDIR '$@;tools/scripts/utilities.mak +2
-2@@ -186,7 +186,7 @@ _gea_err = $(if $(1),$(error Please set '$(1)' appropriately)) # was to check the flex version to see if we can use compiler warnings as # errors for one of the cases flex generates code C compilers complains about. -version-ge3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * $$1 + 10000 * $$2 + $$3) >= (10000000 * $$4 + 10000 * $$5 + $$6)) }') +version-ge3 = $(shell awk -v v1="$(1)" -v v2="$(2)" 'BEGIN { split(v1, a, "."); split(v2, b, "."); printf("%d\n", (10000000 * a[1] + 10000 * a[2] + a[3]) >= (10000000 * b[1] + 10000 * b[2] + b[3])) }') # version-lt3 #@@ -196,4 +196,4 @@ version-ge3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * # check the flex version to see if we can use compiler warnings as errors for # one of the cases flex generates code C compilers complains about. -version-lt3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * $$1 + 10000 * $$2 + $$3) < (10000000 * $$4 + 10000 * $$5 + $$6)) }') +version-lt3 = $(shell awk -v v1="$(1)" -v v2="$(2)" 'BEGIN { split(v1, a, "."); split(v2, b, "."); printf("%d\n", (10000000 * a[1] + 10000 * a[2] + a[3]) < (10000000 * b[1] + 10000 * b[2] + b[3])) }')Signature · 1 line
2.56.0.307.g5fe7bd680c-goog
Ian Rogers
reviewerPATCH v3 2/2 perf test make: Add BPF skeleton build tests for clang and bpf-gcc
In reply to Ian RogersAdd make_bpf_skel_clang (CLANG=clang BPF_GCC=) and make_bpf_skel_bpf_gcc (BPF_GCC=bpf-gcc CLANG=) targets to tools/perf/tests/make when the corresponding compiler and BPF skeleton dependencies are available on the host.
Include tools/build/Makefile.feature and tools/scripts/utilities.mak in tools/perf/tests/make to reuse the existing feature checks (libelf, zlib, bpf, libopenssl, clang-bpf-co-re, libbfd-threadsafe, and llvm-perf) instead of open-coding compiler invocations.
Verify with 'perf check -q feature bpf_skeletons' that BPF skeleton support is enabled for both targets and disabled (exit code 1) for make_no_bpf_skel.
--- tools/perf/tests/make | 71 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 13 deletions(-)
tools/perf/tests/make +58 -13
@@ -54,6 +54,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree))) endif include $(srctree)/tools/scripts/Makefile.arch +include $(srctree)/tools/scripts/utilities.mak # FIXME looks like x86 is the only arch running tests ;-) # we need some IS_(32/64) flag to make this generic
@@ -65,6 +66,7 @@ endif has = $(shell which $1 2>/dev/null) python_perf_so := $(shell $(MAKE) python_perf_target|grep "Target is:"|awk '{print $$3}') +BPF_GCC ?= bpf-gcc # standard single make variable specified make_clean_all := clean all
@@ -78,6 +80,8 @@ make_extra_tests := EXTRA_TESTS=1 make_no_jevents := NO_JEVENTS=1 make_jevents_all := JEVENTS_ARCH=all make_no_bpf_skel := BUILD_BPF_SKEL=0 +make_bpf_skel_clang := CLANG=$(CLANG) BPF_GCC= +make_bpf_skel_bpf_gcc := BPF_GCC=$(BPF_GCC) CLANG= make_gen_vmlinux_h := GEN_VMLINUX_H=1 make_no_python_module := NO_PYTHON_MODULE=1 make_no_scripts := NO_PYTHON_MODULE=1
@@ -127,21 +131,49 @@ make_minimal += NO_LIBBPF=1 make_minimal += NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1 make_minimal += NO_CAPSTONE=1 +override FEATURE_OUTPUT := $(shell mktemp -d) +ifeq ($(FEATURE_OUTPUT),) +$(error Failed to create temporary directory for feature checks) +endif +saved_OUTPUT := $(OUTPUT) +override OUTPUT := $(FEATURE_OUTPUT)/ +FEATURE_DISPLAY_DEFERRED := 1 +FEATURE_TESTS := libelf zlib bpf libopenssl +FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi +include $(srctree)/tools/build/Makefile.feature + # binutils 2_42 and newer have bfd_thread_init() -new_libbfd := $(shell echo '#include <bfd.h>' | $(CC) -E -x c - | grep bfd_thread_init) +$(call feature_check,libbfd-threadsafe) # Whether libLLVM can be built, which needs the llvm-devel/llvm-dev headers and -# libraries of version 13 or newer, not just llvm-config. This mirrors the -# llvm-perf feature test in tools/build/feature/test-llvm-perf.cpp so that -# libLLVM is only asserted below when the default compiler can really build it. +# libraries of version 13 or newer, not just llvm-config. ifneq ($(call has,$(LLVM_CONFIG)),) -have_libllvm := $(shell printf '#include <llvm/Support/ManagedStatic.h>\n#include <llvm/Support/raw_ostream.h>\n#if LLVM_VERSION_MAJOR < 13\n#error "llvm-devel/llvm-dev version 13 or greater is required"\n#endif\nint main(){llvm::errs()<<"";llvm::llvm_shutdown();return 0;}\n' | \ - $(CXX) -x c++ -std=gnu++17 -I$(shell $(LLVM_CONFIG) --includedir 2>/dev/null) - -o /dev/null \ - -L$(shell $(LLVM_CONFIG) --libdir 2>/dev/null) \ - $(shell $(LLVM_CONFIG) --libs Core BPF 2>/dev/null) \ - $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null) >/dev/null 2>&1 && echo y) + $(call feature_check,llvm-perf) +endif + +ifeq ($(feature-libelf)$(feature-zlib)$(feature-bpf)$(feature-libopenssl),1111) + ifneq ($(call get-executable,$(CLANG)),) + CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') + ifneq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(call feature_check,clang-bpf-co-re) + ifeq ($(feature-clang-bpf-co-re),1) + have_clang_bpf := 1 + endif + endif + endif + ifneq ($(call get-executable,$(BPF_GCC)),) + BPF_GCC_VERSION := $(shell $(BPF_GCC) -dumpfullversion 2>/dev/null) + ifneq ($(BPF_GCC_VERSION),) + ifneq ($(call version-lt3,$(BPF_GCC_VERSION),14.0.0),1) + have_bpf_gcc := 1 + endif + endif + endif endif +$(shell rm -rf -- "$(FEATURE_OUTPUT)") +override OUTPUT := $(saved_OUTPUT) + # $(run) contains all available tests run := make_pure # Targets 'clean all' can be run together only through top level
@@ -155,7 +187,7 @@ MAKE_F := $(MAKE) -f $(MK) endif run += make_python_perf_so run += make_debug -ifneq ($(new_libbfd),) +ifeq ($(feature-libbfd-threadsafe),1) run += make_nondistro # Demangling with libbfd is only built when the C++ ABI's __cxa_demangle # isn't available, so it needs a build of its own to be compiled at all.
@@ -165,7 +197,7 @@ endif # a C compiler and a C++ compiler that don't match. ifneq ($(call has,clang),) run += make_clang -ifneq ($(new_libbfd),) +ifeq ($(feature-libbfd-threadsafe),1) run += make_clang_nondistro endif endif
@@ -173,6 +205,12 @@ run += make_extra_tests run += make_no_jevents run += make_jevents_all run += make_no_bpf_skel +ifeq ($(have_clang_bpf),1) +run += make_bpf_skel_clang +endif +ifeq ($(have_bpf_gcc),1) +run += make_bpf_skel_bpf_gcc +endif run += make_gen_vmlinux_h run += make_no_python_module run += make_no_scripts
@@ -306,13 +344,20 @@ test_make_libbpf_dynamic_O := ldd $$TMP_O/perf | grep -q libbpf # doesn't fail the build, it just quietly turns off everything that needs a # C++ compiler. Check a feature that does, otherwise these tests would pass # while producing a perf with less in it than the default build has. -ifneq ($(have_libllvm),) +ifeq ($(feature-llvm-perf),1) test_make_clang := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature libLLVM test_make_clang_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature libLLVM test_make_clang_nondistro := $(test_make_clang) test_make_clang_nondistro_O := $(test_make_clang_O) endif +test_make_no_bpf_skel := test -x $(PERF_O)/perf && ($(PERF_O)/perf check -q feature bpf_skeletons; test $$? -eq 1) +test_make_no_bpf_skel_O := test -x $$TMP_O/perf && ($$TMP_O/perf check -q feature bpf_skeletons; test $$? -eq 1) +test_make_bpf_skel_clang := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature bpf_skeletons +test_make_bpf_skel_clang_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature bpf_skeletons +test_make_bpf_skel_bpf_gcc := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature bpf_skeletons +test_make_bpf_skel_bpf_gcc_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature bpf_skeletons + test_make_python_perf_so_O := test -f $$TMP_O/python/perf.so test_make_perf_o_O := test -f $$TMP_O/perf.o test_make_util_map_o_O := test -f $$TMP_O/util/map.o
@@ -445,7 +490,7 @@ $(FEATURES_DUMP_FILE_STATIC): # The clang tests exist to run feature detection with a compiler other than # the default one, so they have to do their own and are left out of both the # dependency and the 'FEATURES_DUMP=' append below. -no_features_dump := make_clang make_clang_nondistro +no_features_dump := make_clang make_clang_nondistro make_bpf_skel_clang make_bpf_skel_bpf_gcc no_features_dump += $(addsuffix _O,$(no_features_dump)) # Add feature dump dependency for run/run_O targets
Signature · 1 line
2.56.0.307.g5fe7bd680c-goog
[email protected]
AI reviewRe: [PATCH v3 2/2] perf test make: Add BPF skeleton build tests for clang and bpf-gcc
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
Add
make_bpf_skel_clang(CLANG=clang BPF_GCC=) andmake_bpf_skel_bpf_gcc(BPF_GCC=bpf-gcc CLANG=) targets totools/perf/tests/makewhen the corresponding compiler and BPF skeleton dependencies are available on the host.Include
tools/build/Makefile.featureandtools/scripts/utilities.makintools/perf/tests/maketo reuse the existing feature checks (libelf, zlib, bpf, libopenssl, clang-bpf-co-re, libbfd-threadsafe, and llvm-perf) instead of open-coding compiler invocations.
Quoted 6 lines
Verify with 'perf check -q feature
bpf_skeletons' that BPF skeleton support is enabled for both targets and disabled (exit code 1) formake_no_bpf_skel.Assisted-by Antigravity:gemini-3.1-proSigned-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Ian Rogers
reviewerQuoted 27 lines · Ian Rogers
Currently the perf build requires clang (>= 12.0.1) to compile BPF skeleton programs (
.bpf.c-> .bpf.o). bpf-gcc (>= 14.0.0) also supports BPF CO-RE and BTF generation and is already supported intools/testing/selftests/bpf/Makefile.This series updates the perf build to support both clang and bpf-gcc:
- Patch 1 updates Makefile.config, Makefile.perf, and bpf_skel.mak to prefer bpf-gcc when building perf with GCC (CC_NO_CLANG=1) and clang when building with Clang/LLVM (CC_NO_CLANG=0), while respecting explicit BPF_GCC=... or CLANG=... command-line overrides and falling back to whichever compiler is available.
- Patch 2 addsmake_bpf_skel_clangandmake_bpf_skel_bpf_gccbuild-test targets totools/perf/tests/make, reusestools/build/Makefile.featurefor feature detection, and verifies with
'perf check -q featurebpf_skeletons' that BPF skeleton support is enabled (or disabled formake_no_bpf_skel) as expected.v3: Reuse
tools/build/Makefile.featureandtools/scripts/utilities.mak
intools/perf/tests/makerather than open-coding compiler feature probes, and explicitly check for exit code 1 from 'perf check' inmake_no_bpf_skelso crashes are not masked by shell negation.
v2: Pass only -dumpfullversion when queryingBPF_GCC_VERSION, guard
against an empty version string, and fix version-ge3 / version-lt3 intools/scripts/utilities.makso empty or <3-component version strings do not shift awk fields and evaluate as false in version-lt3.
Quoted 3 lines
Ian Rogers (2):
perf build: Support building BPF skeletons with bpf-gcc perf test make: Add BPF skeleton build tests for clang and bpf-gcc
Ping. Just to note that the 2 patches are clean with Sashiko:
https://sashiko.dev/#/patchset/20261022204627.1813821-1-irogers%40google.com
Thanks,
Ian
Quoted 11 lines
tools/perf/Makefile.config | 83 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 36 ++++++++++----- tools/perf/tests/make | 71 ++++++++++++++++++++++------ tools/scripts/Makefile.include | 1 + tools/scripts/utilities.mak | 4 +- 6 files changed, 159 insertions(+), 44 deletions(-)--
2.56.0.307.g5fe7bd680c-goog
Ian Rogers
reviewerQuoted 29 lines · Ian Rogers
Quoted 27 lines · Ian Rogers
Currently the perf build requires clang (>= 12.0.1) to compile BPF skeleton programs (
.bpf.c-> .bpf.o). bpf-gcc (>= 14.0.0) also supports BPF CO-RE and BTF generation and is already supported intools/testing/selftests/bpf/Makefile.This series updates the perf build to support both clang and bpf-gcc:
- Patch 1 updates Makefile.config, Makefile.perf, and bpf_skel.mak to prefer bpf-gcc when building perf with GCC (CC_NO_CLANG=1) and clang when building with Clang/LLVM (CC_NO_CLANG=0), while respecting explicit BPF_GCC=... or CLANG=... command-line overrides and falling back to whichever compiler is available.
- Patch 2 addsmake_bpf_skel_clangandmake_bpf_skel_bpf_gccbuild-test targets totools/perf/tests/make, reusestools/build/Makefile.featurefor feature detection, and verifies with
'perf check -q featurebpf_skeletons' that BPF skeleton support is enabled (or disabled formake_no_bpf_skel) as expected.v3: Reuse
tools/build/Makefile.featureandtools/scripts/utilities.mak
intools/perf/tests/makerather than open-coding compiler feature probes, and explicitly check for exit code 1 from 'perf check' inmake_no_bpf_skelso crashes are not masked by shell negation.
v2: Pass only -dumpfullversion when queryingBPF_GCC_VERSION, guard
against an empty version string, and fix version-ge3 / version-lt3 intools/scripts/utilities.makso empty or <3-component version strings do not shift awk fields and evaluate as false in version-lt3.
Quoted 6 lines
Quoted 3 lines
Ian Rogers (2):
perf build: Support building BPF skeletons with bpf-gcc perf test make: Add BPF skeleton build tests for clang and bpf-gccPing. Just to note that the 2 patches are clean with Sashiko:
https://sashiko.dev/#/patchset/20261022204627.1813821-1-irogers%40google.com
Ping.
Thanks,
Ian
Quoted 11 lines
Quoted 11 lines
tools/perf/Makefile.config | 83 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 36 ++++++++++----- tools/perf/tests/make | 71 ++++++++++++++++++++++------ tools/scripts/Makefile.include | 1 + tools/scripts/utilities.mak | 4 +- 6 files changed, 159 insertions(+), 44 deletions(-)--
2.56.0.307.g5fe7bd680c-goog
Ian Rogers
reviewerv4 cover perf build: Support building BPF skeletons with bpf-gcc
In reply to Ian RogersCurrently the perf build requires clang (>= 12.0.1) to compile BPF skeleton programs (.bpf.c -> .bpf.o). bpf-gcc (>= 14.0.0) also supports BPF CO-RE and BTF generation and is already supported in tools/testing/selftests/bpf/Makefile.
This series updates the perf build to support both clang and bpf-gcc, broken into small bisectable commits:
- Patch 1 fixes version-ge3 and version-lt3 in tools/scripts/utilities.mak so empty or fewer-than-3-component version strings do not shift awk fields across arguments.
- Patch 2 syncs bpf_skel.mak's get_sys_includes with tools/testing/selftests/bpf/Makefile for LoongArch and MIPS.
- Patch 3 updates Makefile.config, Makefile.perf, and bpf_skel.mak to prefer bpf-gcc when building perf with GCC (CC_NO_CLANG=1) and clang when building with Clang/LLVM (CC_NO_CLANG=0), while respecting explicit BPF_GCC=... or CLANG=... command-line overrides and falling back to whichever compiler is available.
- Patch 4 introduces tools/build/Makefile.feature in tools/perf/tests/make and switches the existing libbfd and llvm probes to reuse libbfd-threadsafe and llvm-perf.
- Patch 5 adds make_bpf_skel_clang and make_bpf_skel_bpf_gcc build-test targets to tools/perf/tests/make and verifies with
'perf check -q feature bpf_skeletons' that BPF skeleton support is enabled (or disabled with exit code 1 for make_no_bpf_skel) as expected.
This series was developed and reviewed with assistance from an AI coding agent (Gemini 3.1 Pro) and reviewed with Sashiko.
v4:
- Rebase onto perf-tools-next and drop Assisted-by tags per commit
1e035297ffda ("docs: remove Assisted-by references"). - Split the series into 5 smaller patches for bisection, separating the utilities.mak version-ge3/version-lt3 fix (requested by Namhyung Kim), the get_sys_includes sync, and the Makefile.feature refactoring in tools/perf/tests/make.
v3:
- Reuse tools/build/Makefile.feature and tools/scripts/utilities.mak in tools/perf/tests/make rather than open-coding compiler feature probes, and explicitly check for exit code 1 from 'perf check' in make_no_bpf_skel so crashes are not masked by shell negation.
v2:
- Pass only -dumpfullversion when querying BPF_GCC_VERSION, guard against an empty version string, and fix version-ge3 / version-lt3 in tools/scripts/utilities.mak so empty or <3-component version strings do not shift awk fields and evaluate as false in version-lt3.
Ian Rogers (5):
tools build: Fix version-ge3 and version-lt3 for <3-part versions perf build: Sync bpf_skel.mak get_sys_includes with selftests/bpf perf build: Support building BPF skeletons with bpf-gcc perf test make: Reuse Makefile.feature for libbfd and llvm probes perf test make: Add BPF skeleton build tests for clang and bpf-gcc
tools/perf/Makefile.config | 83 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 36 ++++++++++----- tools/perf/tests/make | 76 +++++++++++++++++++++++++------ tools/scripts/Makefile.include | 1 + tools/scripts/utilities.mak | 4 +- 6 files changed, 164 insertions(+), 44 deletions(-)
Signature · 1 line
2.56.0.567.gdb80ae8cd5-goog
Ian Rogers
reviewerPATCH v4 1/5 tools build: Fix version-ge3 and version-lt3 for <3-part versions
version-ge3 and version-lt3 concatenate their two arguments as "$(1).$(2)" and parse fields $1..$6 with awk -F'.'. When $(1) is empty or has fewer than three dot-separated components (for example GCC's 1- or 2-part -dumpversion output), fields $4..$6 shift across the boundary between $(1) and $(2). In particular, calling version-lt3 with an empty $(1) against "14.0.0" evaluates 0 < 0 and returns 0 (false).
Pass $(1) and $(2) as separate awk variables and split each into its own array so missing components default to 0 without shifting fields across arguments.
--- tools/scripts/utilities.mak | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/scripts/utilities.mak +2 -2
@@ -186,7 +186,7 @@ _gea_err = $(if $(1),$(error Please set '$(1)' appropriately)) # was to check the flex version to see if we can use compiler warnings as # errors for one of the cases flex generates code C compilers complains about. -version-ge3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * $$1 + 10000 * $$2 + $$3) >= (10000000 * $$4 + 10000 * $$5 + $$6)) }') +version-ge3 = $(shell awk -v v1="$(1)" -v v2="$(2)" 'BEGIN { split(v1, a, "."); split(v2, b, "."); printf("%d\n", (10000000 * a[1] + 10000 * a[2] + a[3]) >= (10000000 * b[1] + 10000 * b[2] + b[3])) }') # version-lt3 #
@@ -196,4 +196,4 @@ version-ge3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * # check the flex version to see if we can use compiler warnings as errors for # one of the cases flex generates code C compilers complains about. -version-lt3 = $(shell echo "$(1).$(2)" | awk -F'.' '{ printf("%d\n", (10000000 * $$1 + 10000 * $$2 + $$3) < (10000000 * $$4 + 10000 * $$5 + $$6)) }') +version-lt3 = $(shell awk -v v1="$(1)" -v v2="$(2)" 'BEGIN { split(v1, a, "."); split(v2, b, "."); printf("%d\n", (10000000 * a[1] + 10000 * a[2] + a[3]) < (10000000 * b[1] + 10000 * b[2] + b[3])) }')
Signature · 1 line
2.56.0.567.gdb80ae8cd5-goog
[email protected]
AI reviewRe: [PATCH v4 1/5] tools build: Fix version-ge3 and version-lt3 for <3-part versions
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
version-ge3 and version-lt3 concatenate their two arguments as "$(1).$(2)" and parse fields $1..$6 with awk -F'.'. When $(1) is empty or has fewer than three dot-separated components (for example GCC's 1- or 2-part -dumpversion output), fields $4..$6 shift across the boundary between $(1) and $(2). In particular, calling version-lt3 with an empty $(1) against "14.0.0" evaluates 0 < 0 and returns 0 (false).
Quoted 6 lines
Pass $(1) and $(2) as separate awk variables and split each into its own array so missing components default to 0 without shifting fields across arguments.
Fixes a9b451509565 ("tools build: Add 3-component logical version comparators")Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Ian Rogers
reviewerPATCH v4 2/5 perf build: Sync bpf_skel.mak get_sys_includes with selftests/bpf
In reply to Ian RogersForward __loongarch_grlen as -D__BITS_PER_LONG and the MIPS ABI, size, and endianness macros in bpf_skel.mak's get_sys_includes, matching tools/testing/selftests/bpf/Makefile so system headers receive the expected architecture macros when compiling BPF skeletons.
--- tools/perf/bpf_skel.mak | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/bpf_skel.mak +3 -1
@@ -22,7 +22,9 @@ bpf-skel-prepare: $(BPFTOOL) $(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)}') +$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') \ +$(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf("-D__BITS_PER_LONG=%d", $$3)}') \ +$(shell $(1) $(2) -dM -E - </dev/null | grep -E 'MIPS(EL|EB)|_MIPS_SZ(PTR|LONG) |_MIPS_SIM |_ABI(O32|N32|64) ' | awk '{printf("-D%s=%s ", $$2, $$3)}') endef ifneq ($(CROSS_COMPILE),)
Signature · 1 line
2.56.0.567.gdb80ae8cd5-goog
[email protected]
AI reviewRe: [PATCH v4 2/5] perf build: Sync bpf_skel.mak get_sys_includes with selftests/bpf
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Forward
__loongarch_grlenas -D__BITS_PER_LONG and the MIPS ABI, size, and endianness macros in bpf_skel.mak'sget_sys_includes, matchingtools/testing/selftests/bpf/Makefileso system headers receive the expected architecture macros when compiling BPF skeletons.Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Ian Rogers
reviewerPATCH v4 3/5 perf build: Support building BPF skeletons with bpf-gcc
In reply to Ian RogersSupport building perf BPF skeletons with bpf-gcc (>= 14.0.0) in addition to clang (>= 12.0.1), similar to tools/testing/selftests/bpf/Makefile.
When building perf with GCC (CC_NO_CLANG=1), prefer bpf-gcc and fall back to clang if bpf-gcc is unavailable or too old. When building with Clang/LLVM (CC_NO_CLANG=0), prefer clang and fall back to bpf-gcc. Explicit command-line overrides via BPF_GCC=... or CLANG=... are respected, and setting BPF_GCC= or CLANG= to empty disables that compiler.
In bpf_skel.mak, pass the bpf-gcc flags (-mcpu=v3, -fno-ident, -DBPF_NO_PRESERVE_ACCESS_INDEX, -Wno-attributes, -D__TARGET_ARCH_$(SRCARCH), and target endianness) and query system include paths from $(CC).
--- tools/perf/Makefile.config | 83 +++++++++++++++++++++++++++------- tools/perf/Makefile.perf | 8 +++- tools/perf/bpf_skel.mak | 32 +++++++++---- tools/scripts/Makefile.include | 1 + 4 files changed, 96 insertions(+), 28 deletions(-)
tools/perf/Makefile.config +67 -16
@@ -666,27 +666,78 @@ ifeq ($(BUILD_BPF_SKEL),1) else ifeq ($(filter -DHAVE_LIBOPENSSL_SUPPORT, $(CFLAGS)),) $(warning Warning: Disabled BPF skeletons as libopenssl is required) BUILD_BPF_SKEL := 0 - else ifeq ($(call get-executable,$(CLANG)),) - $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing) - BUILD_BPF_SKEL := 0 - else - CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') - ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) - $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) - BUILD_BPF_SKEL := 0 - endif endif ifeq ($(BUILD_BPF_SKEL),1) - $(call feature_check,clang-bpf-co-re) - ifeq ($(feature-clang-bpf-co-re), 0) - $(warning Warning: Disabled BPF skeletons as clang is too old) + # Prefer bpf-gcc when building with gcc (CC_NO_CLANG=1) and clang when + # building with clang, unless CLANG or BPF_GCC was explicitly specified on + # the command line. Fall back to whichever compiler is available. + prefer_bpf_gcc := $(CC_NO_CLANG) + ifeq ($(origin BPF_GCC),command line) + ifneq ($(BPF_GCC),) + prefer_bpf_gcc := 1 + endif + else ifeq ($(origin CLANG),command line) + ifneq ($(CLANG),) + prefer_bpf_gcc := 0 + endif + endif + + have_bpf_gcc := 0 + have_clang_bpf := 0 + + define check_bpf_gcc + ifneq ($$(call get-executable,$$(BPF_GCC)),) + BPF_GCC_VERSION := $$(shell $$(BPF_GCC) -dumpfullversion 2>/dev/null) + ifneq ($$(BPF_GCC_VERSION),) + ifneq ($$(call version-lt3,$$(BPF_GCC_VERSION),14.0.0),1) + have_bpf_gcc := 1 + endif + endif + endif + endef + + ifeq ($(prefer_bpf_gcc),1) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),0) + ifneq ($(call get-executable,$(CLANG)),) + CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') + ifneq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(call feature_check,clang-bpf-co-re) + ifneq ($(feature-clang-bpf-co-re), 0) + have_clang_bpf := 1 + endif + endif + endif + endif + + ifeq ($(prefer_bpf_gcc)$(have_clang_bpf),00) + $(eval $(check_bpf_gcc)) + endif + + ifeq ($(have_bpf_gcc),1) + $(call detected,CONFIG_PERF_BPF_SKEL_BPF_GCC) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else ifeq ($(have_clang_bpf),1) + $(call detected,CONFIG_PERF_BPF_SKEL) + CFLAGS += -DHAVE_BPF_SKEL + else + ifeq ($(call get-executable,$(CLANG))$(call get-executable,$(BPF_GCC)),) + $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) and bpf-gcc ($(BPF_GCC)) are missing) + else ifneq ($(call get-executable,$(CLANG)),) + ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1) + else + $(warning Warning: Disabled BPF skeletons as clang is too old) + endif + else + $(warning Warning: Disabled BPF skeletons as bpf-gcc ($(BPF_GCC)) needs at least version 14.0.0) + endif BUILD_BPF_SKEL := 0 endif endif - ifeq ($(BUILD_BPF_SKEL),1) - $(call detected,CONFIG_PERF_BPF_SKEL) - CFLAGS += -DHAVE_BPF_SKEL - endif endif ifndef GEN_VMLINUX_H
tools/perf/Makefile.perf +6 -2
@@ -37,6 +37,9 @@ include ../scripts/utilities.mak # Define EXTRA_BPF_FLAGS="--sysroot=<path>" or other custom include paths for # cross-compiling BPF skeletons # +# Define BPF_GCC to point to the bpf-gcc binary if the default `bpf-gcc' is not +# correct, or set BPF_GCC= to disable using bpf-gcc for BPF skeletons. +# # Define EXCLUDE_EXTLIBS=-lmylib to exclude libmylib from the auto-generated # EXTLIBS. #
@@ -208,6 +211,7 @@ FIND = find INSTALL = install FLEX ?= flex BISON ?= bison +BPF_GCC ?= bpf-gcc AWK = awk # include Makefile.config by default and rule out
@@ -321,8 +325,8 @@ ifneq ($(force_fixdep),1) endif endif -export srctree OUTPUT RM CC CXX RUSTC CLANG LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF -export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL +export srctree OUTPUT RM CC CXX RUSTC CLANG BPF_GCC LD AR CFLAGS CXXFLAGS RUST_FLAGS V BISON FLEX AWK LIBBPF READELF +export HOSTCC HOSTLD HOSTAR HOSTCFLAGS SHELLCHECK MYPY PYLINT CONFIG_PERF_BPF_SKEL CONFIG_PERF_BPF_SKEL_BPF_GCC include $(srctree)/tools/build/Makefile.include
tools/perf/bpf_skel.mak +22 -10
@@ -27,18 +27,30 @@ $(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf $(shell $(1) $(2) -dM -E - </dev/null | grep -E 'MIPS(EL|EB)|_MIPS_SZ(PTR|LONG) |_MIPS_SIM |_ABI(O32|N32|64) ' | awk '{printf("-D%s=%s ", $$2, $$3)}') endef -ifneq ($(CROSS_COMPILE),) -CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) +ifeq ($(CONFIG_PERF_BPF_SKEL_BPF_GCC),y) + BPF_CC := $(BPF_GCC) + QUIET_BPF_CC = $(QUIET_BPF_GCC) + IS_LITTLE_ENDIAN := $(shell $(CC) -dM -E - </dev/null | \ + grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__') + BPF_OPTIONS = -Wall -mcpu=v3 -fno-ident -DBPF_NO_PRESERVE_ACCESS_INDEX -Wno-attributes \ + -D__TARGET_ARCH_$(SRCARCH) $(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) + BPF_SYS_INCLUDES = $(call get_sys_includes,$(CC),) +else + BPF_CC := $(CLANG) + QUIET_BPF_CC = $(QUIET_CLANG) + ifneq ($(CROSS_COMPILE),) + CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) + endif + BPF_OPTIONS = -Wall -mcpu=v3 -fno-stack-protector --target=bpf -Wno-microsoft-anon-tag + BPF_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) endif -CLANG_OPTIONS = -Wall -mcpu=v3 -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) +BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(SKEL_TOOL_OUT) -I$(LIBBPF_INCLUDE) $(BPF_SYS_INCLUDES) TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi ifneq ($(WERROR),0) - CLANG_OPTIONS += -Werror + BPF_OPTIONS += -Werror endif $(BPFTOOL):
@@ -85,11 +97,11 @@ 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) \ + $(QUIET_BPF_CC) + $(Q)$(BPF_CC) -g -O2 \ + $(BPF_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 \ + -fms-extensions \ -c $< -o $@ $(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o $(BPFTOOL)
tools/scripts/Makefile.include +1 -0
@@ -217,6 +217,7 @@ ifneq ($(silent),1) QUIET_CC = @echo ' CC '$@; QUIET_CC_FPIC = @echo ' CC FPIC '$@; QUIET_CLANG = @echo ' CLANG '$@; + QUIET_BPF_GCC = @echo ' BPF_GCC '$@; QUIET_AR = @echo ' AR '$@; QUIET_LINK = @echo ' LINK '$@; QUIET_MKDIR = @echo ' MKDIR '$@;
Signature · 1 line
2.56.0.567.gdb80ae8cd5-goog
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 15 lines
Support building perf BPF skeletons with bpf-gcc (>= 14.0.0) in addition to clang (>= 12.0.1), similar to
tools/testing/selftests/bpf/Makefile.When building perf with GCC (CC_NO_CLANG=1), prefer bpf-gcc and fall back to clang if bpf-gcc is unavailable or too old. When building with Clang/LLVM (CC_NO_CLANG=0), prefer clang and fall back to bpf-gcc. Explicit command-line overrides via BPF_GCC=... or CLANG=... are respected, and setting BPF_GCC= or CLANG= to empty disables that compiler.
In bpf_skel.mak, pass the bpf-gcc flags (-mcpu=v3, -fno-ident,
(quoted diff) +0
-2-DBPF_NO_PRESERVE_ACCESS_INDEX, -Wno-attributes, -D__TARGET_ARCH_$(SRCARCH), and target endianness) and query systeminclude paths from $(CC).
Quoted 1 line
Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Ian Rogers
reviewerPATCH v4 4/5 perf test make: Reuse Makefile.feature for libbfd and llvm probes
In reply to Ian RogersInclude tools/build/Makefile.feature in tools/perf/tests/make (using a temporary OUTPUT directory that is removed immediately after probing) and replace the open-coded new_libbfd and have_libllvm compiler invocations with the existing libbfd-threadsafe and llvm-perf feature checks.
--- tools/perf/tests/make | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
tools/perf/tests/make +24 -12
@@ -127,19 +127,31 @@ make_minimal += NO_LIBBPF=1 make_minimal += NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1 make_minimal += NO_CAPSTONE=1 +override FEATURE_OUTPUT := $(shell mktemp -d) +ifeq ($(FEATURE_OUTPUT),) +$(error Failed to create temporary directory for feature checks) +endif +saved_OUTPUT_origin := $(origin OUTPUT) +saved_OUTPUT := $(OUTPUT) +override OUTPUT := $(FEATURE_OUTPUT)/ +FEATURE_DISPLAY_DEFERRED := 1 +FEATURE_TESTS := +include $(srctree)/tools/build/Makefile.feature + # binutils 2_42 and newer have bfd_thread_init() -new_libbfd := $(shell echo '#include <bfd.h>' | $(CC) -E -x c - | grep bfd_thread_init) +$(call feature_check,libbfd-threadsafe) # Whether libLLVM can be built, which needs the llvm-devel/llvm-dev headers and -# libraries of version 13 or newer, not just llvm-config. This mirrors the -# llvm-perf feature test in tools/build/feature/test-llvm-perf.cpp so that -# libLLVM is only asserted below when the default compiler can really build it. +# libraries of version 13 or newer, not just llvm-config. ifneq ($(call has,$(LLVM_CONFIG)),) -have_libllvm := $(shell printf '#include <llvm/Support/ManagedStatic.h>\n#include <llvm/Support/raw_ostream.h>\n#if LLVM_VERSION_MAJOR < 13\n#error "llvm-devel/llvm-dev version 13 or greater is required"\n#endif\nint main(){llvm::errs()<<"";llvm::llvm_shutdown();return 0;}\n' | \ - $(CXX) -x c++ -std=gnu++17 -I$(shell $(LLVM_CONFIG) --includedir 2>/dev/null) - -o /dev/null \ - -L$(shell $(LLVM_CONFIG) --libdir 2>/dev/null) \ - $(shell $(LLVM_CONFIG) --libs Core BPF 2>/dev/null) \ - $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null) >/dev/null 2>&1 && echo y) + $(call feature_check,llvm-perf) +endif + +$(shell rm -rf -- "$(FEATURE_OUTPUT)") +ifeq ($(saved_OUTPUT_origin),undefined) +override undefine OUTPUT +else +override OUTPUT := $(saved_OUTPUT) endif # $(run) contains all available tests
@@ -155,7 +167,7 @@ MAKE_F := $(MAKE) -f $(MK) endif run += make_python_perf_so run += make_debug -ifneq ($(new_libbfd),) +ifeq ($(feature-libbfd-threadsafe),1) run += make_nondistro # Demangling with libbfd is only built when the C++ ABI's __cxa_demangle # isn't available, so it needs a build of its own to be compiled at all.
@@ -165,7 +177,7 @@ endif # a C compiler and a C++ compiler that don't match. ifneq ($(call has,clang),) run += make_clang -ifneq ($(new_libbfd),) +ifeq ($(feature-libbfd-threadsafe),1) run += make_clang_nondistro endif endif
@@ -306,7 +318,7 @@ test_make_libbpf_dynamic_O := ldd $$TMP_O/perf | grep -q libbpf # doesn't fail the build, it just quietly turns off everything that needs a # C++ compiler. Check a feature that does, otherwise these tests would pass # while producing a perf with less in it than the default build has. -ifneq ($(have_libllvm),) +ifeq ($(feature-llvm-perf),1) test_make_clang := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature libLLVM test_make_clang_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature libLLVM test_make_clang_nondistro := $(test_make_clang)
Signature · 1 line
2.56.0.567.gdb80ae8cd5-goog
[email protected]
AI reviewRe: [PATCH v4 4/5] perf test make: Reuse Makefile.feature for libbfd and llvm probes
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
Include
tools/build/Makefile.featureintools/perf/tests/make(using a temporary OUTPUT directory that is removed immediately after probing) and replace the open-codednew_libbfdandhave_libllvmcompiler invocations with the existing libbfd-threadsafe and llvm-perf feature checks.Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Ian Rogers
reviewerPATCH v4 5/5 perf test make: Add BPF skeleton build tests for clang and bpf-gcc
In reply to Ian RogersAdd make_bpf_skel_clang (CLANG=$(CLANG) BPF_GCC=) and make_bpf_skel_bpf_gcc (BPF_GCC=$(BPF_GCC) CLANG=) targets to tools/perf/tests/make when the corresponding compiler and BPF skeleton dependencies (libelf, zlib, bpf, and libopenssl via Makefile.feature) are available on the host.
Verify with 'perf check -q feature bpf_skeletons' that BPF skeleton support is enabled for both targets and disabled (exit code 1) for make_no_bpf_skel.
--- tools/perf/tests/make | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-)
tools/perf/tests/make +40 -2
@@ -54,6 +54,7 @@ srctree := $(patsubst %/,%,$(dir $(srctree))) endif include $(srctree)/tools/scripts/Makefile.arch +include $(srctree)/tools/scripts/utilities.mak # FIXME looks like x86 is the only arch running tests ;-) # we need some IS_(32/64) flag to make this generic
@@ -65,6 +66,7 @@ endif has = $(shell which $1 2>/dev/null) python_perf_so := $(shell $(MAKE) python_perf_target|grep "Target is:"|awk '{print $$3}') +BPF_GCC ?= bpf-gcc # standard single make variable specified make_clean_all := clean all
@@ -78,6 +80,8 @@ make_extra_tests := EXTRA_TESTS=1 make_no_jevents := NO_JEVENTS=1 make_jevents_all := JEVENTS_ARCH=all make_no_bpf_skel := BUILD_BPF_SKEL=0 +make_bpf_skel_clang := CLANG=$(CLANG) BPF_GCC= +make_bpf_skel_bpf_gcc := BPF_GCC=$(BPF_GCC) CLANG= make_gen_vmlinux_h := GEN_VMLINUX_H=1 make_no_python_module := NO_PYTHON_MODULE=1 make_no_scripts := NO_PYTHON_MODULE=1
@@ -135,7 +139,8 @@ saved_OUTPUT_origin := $(origin OUTPUT) saved_OUTPUT := $(OUTPUT) override OUTPUT := $(FEATURE_OUTPUT)/ FEATURE_DISPLAY_DEFERRED := 1 -FEATURE_TESTS := +FEATURE_TESTS := libelf zlib bpf libopenssl +FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi include $(srctree)/tools/build/Makefile.feature # binutils 2_42 and newer have bfd_thread_init()
@@ -147,6 +152,26 @@ ifneq ($(call has,$(LLVM_CONFIG)),) $(call feature_check,llvm-perf) endif +ifeq ($(feature-libelf)$(feature-zlib)$(feature-bpf)$(feature-libopenssl),1111) + ifneq ($(call get-executable,$(CLANG)),) + CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g') + ifneq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1) + $(call feature_check,clang-bpf-co-re) + ifeq ($(feature-clang-bpf-co-re),1) + have_clang_bpf := 1 + endif + endif + endif + ifneq ($(call get-executable,$(BPF_GCC)),) + BPF_GCC_VERSION := $(shell $(BPF_GCC) -dumpfullversion 2>/dev/null) + ifneq ($(BPF_GCC_VERSION),) + ifneq ($(call version-lt3,$(BPF_GCC_VERSION),14.0.0),1) + have_bpf_gcc := 1 + endif + endif + endif +endif + $(shell rm -rf -- "$(FEATURE_OUTPUT)") ifeq ($(saved_OUTPUT_origin),undefined) override undefine OUTPUT
@@ -185,6 +210,12 @@ run += make_extra_tests run += make_no_jevents run += make_jevents_all run += make_no_bpf_skel +ifeq ($(have_clang_bpf),1) +run += make_bpf_skel_clang +endif +ifeq ($(have_bpf_gcc),1) +run += make_bpf_skel_bpf_gcc +endif run += make_gen_vmlinux_h run += make_no_python_module run += make_no_scripts
@@ -325,6 +356,13 @@ test_make_clang_nondistro := $(test_make_clang) test_make_clang_nondistro_O := $(test_make_clang_O) endif +test_make_no_bpf_skel := test -x $(PERF_O)/perf && ($(PERF_O)/perf check -q feature bpf_skeletons; test $$? -eq 1) +test_make_no_bpf_skel_O := test -x $$TMP_O/perf && ($$TMP_O/perf check -q feature bpf_skeletons; test $$? -eq 1) +test_make_bpf_skel_clang := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature bpf_skeletons +test_make_bpf_skel_clang_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature bpf_skeletons +test_make_bpf_skel_bpf_gcc := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature bpf_skeletons +test_make_bpf_skel_bpf_gcc_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature bpf_skeletons + test_make_python_perf_so_O := test -f $$TMP_O/python/perf.so test_make_perf_o_O := test -f $$TMP_O/perf.o test_make_util_map_o_O := test -f $$TMP_O/util/map.o
@@ -457,7 +495,7 @@ $(FEATURES_DUMP_FILE_STATIC): # The clang tests exist to run feature detection with a compiler other than # the default one, so they have to do their own and are left out of both the # dependency and the 'FEATURES_DUMP=' append below. -no_features_dump := make_clang make_clang_nondistro +no_features_dump := make_clang make_clang_nondistro make_bpf_skel_clang make_bpf_skel_bpf_gcc no_features_dump += $(addsuffix _O,$(no_features_dump)) # Add feature dump dependency for run/run_O targets
Signature · 1 line
2.56.0.567.gdb80ae8cd5-goog
[email protected]
AI reviewRe: [PATCH v4 5/5] perf test make: Add BPF skeleton build tests for clang and bpf-gcc
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
Add
make_bpf_skel_clang(CLANG=$(CLANG) BPF_GCC=) andmake_bpf_skel_bpf_gcc(BPF_GCC=$(BPF_GCC) CLANG=) targets totools/perf/tests/makewhen the corresponding compiler and BPF skeleton dependencies (libelf, zlib, bpf, and libopenssl via Makefile.feature) are available on the host.Verify with 'perf check -q feature
bpf_skeletons' that BPF skeleton support is enabled for both targets and disabled (exit code 1) formake_no_bpf_skel.Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Quoted 26 lines · Ian Rogers
Currently the perf build requires clang (>= 12.0.1) to compile BPF skeleton programs (
.bpf.c-> .bpf.o). bpf-gcc (>= 14.0.0) also supports BPF CO-RE and BTF generation and is already supported intools/testing/selftests/bpf/Makefile.This series updates the perf build to support both clang and bpf-gcc, broken into small bisectable commits:
- Patch 1 fixes version-ge3 and version-lt3 intools/scripts/utilities.makso empty or fewer-than-3-component version strings do not shift awk fields across arguments.
- Patch 2 syncs bpf_skel.mak'sget_sys_includeswithtools/testing/selftests/bpf/Makefilefor LoongArch and MIPS.
- Patch 3 updates Makefile.config, Makefile.perf, and bpf_skel.mak to prefer bpf-gcc when building perf with GCC (CC_NO_CLANG=1) and clang when building with Clang/LLVM (CC_NO_CLANG=0), while respecting explicit BPF_GCC=... or CLANG=... command-line overrides and falling back to whichever compiler is available.
- Patch 4 introducestools/build/Makefile.featureintools/perf/tests/makeand switches the existing libbfd and llvm probes to reuse libbfd-threadsafe and llvm-perf.
- Patch 5 addsmake_bpf_skel_clangandmake_bpf_skel_bpf_gccbuild-test targets totools/perf/tests/makeand verifies with
'perf check -q featurebpf_skeletons' that BPF skeleton support is enabled (or disabled with exit code 1 formake_no_bpf_skel) as expected.
Quoted 1 line
[...]
Applied to perf-tools-next, thanks!
Best regards
Namhyung