perf build: Make BUILD_BPF_SKEL default, rename to NO_BPF_SKEL
authorIan Rogers <irogers@google.com>
Sat, 11 Mar 2023 06:57:42 +0000 (22:57 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 14 Mar 2023 11:29:46 +0000 (08:29 -0300)
BPF skeleton support is now key to a number of perf features. Rather
than making it so that BPF support must be enabled for the build, make
this the default and error if the build lacks a clang and libbpf that
are sufficient. To avoid the error and build without BPF skeletons the
NO_BPF_SKEL=1 flag can be used. Add a build-options flag to 'perf
version' to enable detection of the BPF skeleton support and use this
in the offcpu shell test.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Martin Liška <mliska@suse.cz>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Pavithra Gurushankar <gpavithrasha@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Monnet <quentin@isovalent.com>
Cc: Roberto Sassu <roberto.sassu@huawei.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Tom Rix <trix@redhat.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: llvm@lists.linux.dev
Link: https://lore.kernel.org/r/20230311065753.3012826-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Makefile.config
tools/perf/Makefile.perf
tools/perf/builtin-lock.c
tools/perf/builtin-record.c
tools/perf/builtin-version.c
tools/perf/tests/shell/record_offcpu.sh

index 51a4e26bd0303cbf35f4b279a25dfecd09a058ce..318af7657225981e7711b1988edb9ee6260a8981 100644 (file)
@@ -415,6 +415,7 @@ ifdef NO_LIBELF
   NO_LIBUNWIND := 1
   NO_LIBDW_DWARF_UNWIND := 1
   NO_LIBBPF := 1
+  NO_BPF_SKEL := 1
   NO_JVMTI := 1
 else
   ifeq ($(feature-libelf), 0)
@@ -662,18 +663,22 @@ ifndef NO_LIBBPF
     msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
     NO_LIBBPF := 1
   endif
+else
+  NO_BPF_SKEL := 1
 endif
 
-ifdef BUILD_BPF_SKEL
+ifndef NO_BPF_SKEL
   $(call feature_check,clang-bpf-co-re)
   ifeq ($(feature-clang-bpf-co-re), 0)
-    dummy := $(error Error: clang too old/not installed. Please install recent clang to build with BUILD_BPF_SKEL)
-  endif
-  ifeq ($(filter -DHAVE_LIBBPF_SUPPORT, $(CFLAGS)),)
-    dummy := $(error Error: BPF skeleton support requires libbpf)
+    dummy := $(error: ERROR: BPF skeletons unsupported. clang too old/not installed or build with NO_BPF_SKEL=1.)
+  else
+    ifeq ($(filter -DHAVE_LIBBPF_SUPPORT, $(CFLAGS)),)
+      dummy := $(error: ERROR: BPF skeletons unsupported. BPF skeleton support requires libbpf or build with NO_BPF_SKEL=1.)
+    else
+      $(call detected,CONFIG_PERF_BPF_SKEL)
+      CFLAGS += -DHAVE_BPF_SKEL
+    endif
   endif
-  $(call detected,CONFIG_PERF_BPF_SKEL)
-  CFLAGS += -DHAVE_BPF_SKEL
 endif
 
 dwarf-post-unwind := 1
index 2fcee585b225d64bec4fd33953b4b0ccb9bc3da4..283ee4f56234a5593d1aed048c3c36866d2e4f9c 100644 (file)
@@ -126,7 +126,7 @@ include ../scripts/utilities.mak
 #
 # Define NO_LIBDEBUGINFOD if you do not want support debuginfod
 #
-# Define BUILD_BPF_SKEL to enable BPF skeletons
+# Define NO_BPF_SKEL to disable BPF skeletons
 #
 
 # As per kernel Makefile, avoid funny character set dependencies
@@ -1055,7 +1055,7 @@ SKELETONS += $(SKEL_OUT)/kwork_trace.skel.h
 $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT):
        $(Q)$(MKDIR) -p $@
 
-ifdef BUILD_BPF_SKEL
+ifndef NO_BPF_SKEL
 BPFTOOL := $(SKEL_TMP_OUT)/bootstrap/bpftool
 BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE)
 
@@ -1088,11 +1088,11 @@ bpf-skel: $(SKELETONS)
 
 .PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o
 
-else # BUILD_BPF_SKEL
+else # NO_BPF_SKEL
 
 bpf-skel:
 
-endif # BUILD_BPF_SKEL
+endif # NO_BPF_SKEL
 
 bpf-skel-clean:
        $(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS)
index 054997edd98bc526cca13e680b829f3cef117548..240d49a85524d72a78b82b588b54232ec6cdd667 100644 (file)
@@ -2371,7 +2371,7 @@ int cmd_lock(int argc, const char **argv)
 
 #ifndef HAVE_BPF_SKEL
                set_option_nobuild(contention_options, 'b', "use-bpf",
-                                  "no BUILD_BPF_SKEL=1", false);
+                                  "NO_BPF_SKEL=1", false);
 #endif
                if (argc) {
                        argc = parse_options(argc, argv, contention_options,
index 74388164a5713817e6d55efbd21fdaf389d48300..33ebe42b025e88ad4b696cf27099e9f28b57b193 100644 (file)
@@ -3971,7 +3971,7 @@ int cmd_record(int argc, const char **argv)
 
 #ifndef HAVE_BPF_SKEL
 # define set_nobuild(s, l, m, c) set_option_nobuild(record_options, s, l, m, c)
-       set_nobuild('\0', "off-cpu", "no BUILD_BPF_SKEL=1", true);
+       set_nobuild('\0', "off-cpu", "NO_BPF_SKEL=1", true);
 # undef set_nobuild
 #endif
 
index a886929ec6e5f5d2e05f69aa5bf0461f9b9e90e7..0d9cda238c07d154c63d493d46a0e38c61238b3c 100644 (file)
@@ -83,6 +83,7 @@ static void library_status(void)
        STATUS(HAVE_ZSTD_SUPPORT, zstd);
        STATUS(HAVE_LIBPFM, libpfm4);
        STATUS(HAVE_LIBTRACEEVENT, libtraceevent);
+       STATUS(HAVE_BPF_SKEL, BPF skeletons);
 }
 
 int cmd_version(int argc, const char **argv)
index e01973d4e0fbab6ed46cd727f7d8a3a08ad691c1..24f81ff85793f2bedf8ef70c0622273b1252b0a8 100755 (executable)
@@ -28,7 +28,7 @@ test_offcpu_priv() {
     err=2
     return
   fi
-  if perf record --off-cpu -o /dev/null --quiet true 2>&1 | grep BUILD_BPF_SKEL
+  if perf version --build-options 2>&1 | grep HAVE_BPF_SKEL | grep -q OFF
   then
     echo "off-cpu test [Skipped missing BPF support]"
     err=2