Skip to content

Commit fbcdaa1

Browse files
liu-song-6acmel
authored andcommitted
perf build: Support build BPF skeletons with perf
BPF programs are useful in perf to profile BPF programs. BPF skeleton is by far the easiest way to write BPF tools. Enable building BPF skeletons in util/bpf_skel. A dummy bpf skeleton is added. More bpf skeletons will be added for different use cases. Signed-off-by: Song Liu <songliubraving@fb.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Acked-by: Jiri Olsa <jolsa@redhat.com> Acked-by: Namhyung Kim <namhyung@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: kernel-team@fb.com Link: http://lore.kernel.org/lkml/20201229214214.3413833-3-songliubraving@fb.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent d2032d4 commit fbcdaa1

5 files changed

Lines changed: 63 additions & 3 deletions

File tree

‎tools/build/Makefile.feature‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ FEATURE_TESTS_EXTRA := \
9999
clang \
100100
libbpf \
101101
libpfm4 \
102-
libdebuginfod
102+
libdebuginfod \
103+
clang-bpf-co-re
104+
103105

104106
FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
105107

‎tools/perf/Makefile.config‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,15 @@ ifndef NO_LIBBPF
621621
endif
622622
endif
623623

624+
ifdef BUILD_BPF_SKEL
625+
$(call feature_check,clang-bpf-co-re)
626+
ifeq ($(feature-clang-bpf-co-re), 0)
627+
dummy := $(error Error: clang too old. Please install recent clang)
628+
endif
629+
$(call detected,CONFIG_PERF_BPF_SKEL)
630+
CFLAGS += -DHAVE_BPF_SKEL
631+
endif
632+
624633
dwarf-post-unwind := 1
625634
dwarf-post-unwind-text := BUG
626635

‎tools/perf/Makefile.perf‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ include ../scripts/utilities.mak
126126
#
127127
# Define NO_LIBDEBUGINFOD if you do not want support debuginfod
128128
#
129+
# Define BUILD_BPF_SKEL to enable BPF skeletons
130+
#
129131

130132
# As per kernel Makefile, avoid funny character set dependencies
131133
unexport LC_ALL
@@ -175,6 +177,12 @@ endef
175177

176178
LD += $(EXTRA_LDFLAGS)
177179

180+
HOSTCC ?= gcc
181+
HOSTLD ?= ld
182+
HOSTAR ?= ar
183+
CLANG ?= clang
184+
LLVM_STRIP ?= llvm-strip
185+
178186
PKG_CONFIG = $(CROSS_COMPILE)pkg-config
179187
LLVM_CONFIG ?= llvm-config
180188

@@ -731,7 +739,8 @@ prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioc
731739
$(x86_arch_prctl_code_array) \
732740
$(rename_flags_array) \
733741
$(arch_errno_name_array) \
734-
$(sync_file_range_arrays)
742+
$(sync_file_range_arrays) \
743+
bpf-skel
735744

736745
$(OUTPUT)%.o: %.c prepare FORCE
737746
$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
@@ -1004,7 +1013,43 @@ config-clean:
10041013
python-clean:
10051014
$(python-clean)
10061015

1007-
clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBPERF)-clean config-clean fixdep-clean python-clean
1016+
SKEL_OUT := $(abspath $(OUTPUT)util/bpf_skel)
1017+
SKEL_TMP_OUT := $(abspath $(SKEL_OUT)/.tmp)
1018+
SKELETONS :=
1019+
1020+
ifdef BUILD_BPF_SKEL
1021+
BPFTOOL := $(SKEL_TMP_OUT)/bootstrap/bpftool
1022+
LIBBPF_SRC := $(abspath ../lib/bpf)
1023+
BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(BPF_PATH) -I$(LIBBPF_SRC)/..
1024+
1025+
$(SKEL_TMP_OUT):
1026+
$(Q)$(MKDIR) -p $@
1027+
1028+
$(BPFTOOL): | $(SKEL_TMP_OUT)
1029+
CFLAGS= $(MAKE) -C ../bpf/bpftool \
1030+
OUTPUT=$(SKEL_TMP_OUT)/ bootstrap
1031+
1032+
$(SKEL_TMP_OUT)/%.bpf.o: util/bpf_skel/%.bpf.c $(LIBBPF) | $(SKEL_TMP_OUT)
1033+
$(QUIET_CLANG)$(CLANG) -g -O2 -target bpf $(BPF_INCLUDE) \
1034+
-c $(filter util/bpf_skel/%.bpf.c,$^) -o $@ && $(LLVM_STRIP) -g $@
1035+
1036+
$(SKEL_OUT)/%.skel.h: $(SKEL_TMP_OUT)/%.bpf.o | $(BPFTOOL)
1037+
$(QUIET_GENSKEL)$(BPFTOOL) gen skeleton $< > $@
1038+
1039+
bpf-skel: $(SKELETONS)
1040+
1041+
.PRECIOUS: $(SKEL_TMP_OUT)/%.bpf.o
1042+
1043+
else # BUILD_BPF_SKEL
1044+
1045+
bpf-skel:
1046+
1047+
endif # BUILD_BPF_SKEL
1048+
1049+
bpf-skel-clean:
1050+
$(call QUIET_CLEAN, bpf-skel) $(RM) -r $(SKEL_TMP_OUT) $(SKELETONS)
1051+
1052+
clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBPERF)-clean config-clean fixdep-clean python-clean bpf-skel-clean
10081053
$(call QUIET_CLEAN, core-objs) $(RM) $(LIBPERF_A) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
10091054
$(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
10101055
$(Q)$(RM) $(OUTPUT).config-detected
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
.tmp
3+
*.skel.h

‎tools/scripts/Makefile.include‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ ifneq ($(silent),1)
127127
$(MAKE) $(PRINT_DIR) -C $$subdir
128128
QUIET_FLEX = @echo ' FLEX '$@;
129129
QUIET_BISON = @echo ' BISON '$@;
130+
QUIET_GENSKEL = @echo ' GEN-SKEL '$@;
130131

131132
descend = \
132133
+@echo ' DESCEND '$(1); \

0 commit comments

Comments
 (0)