Skip to content

Commit ed63f34

Browse files
WangNan0acmel
authored andcommitted
perf tools: Make perf depend on libbpf
By adding libbpf into perf's Makefile, this patch enables perf to build libbpf if libelf is found and neither NO_LIBELF nor NO_LIBBPF is set. The newly introduced code is similar to how libapi and libtraceevent are wired into Makefile.perf. MANIFEST is also updated for 'make perf-*-src-pkg'. Append make_no_libbpf to tools/perf/tests/make. The 'bpf' feature check is appended into default FEATURE_TESTS and FEATURE_DISPLAY, so perf will check the API version of bpf in /path/to/kernel/include/uapi/linux/bpf.h. Which should not fail except when we are trying to port this code to an old kernel. Error messages are also updated to notify users about the lack of BPF support in 'perf record' if libelf is missing or the BPF API check failed. tools/lib/bpf is added to TAG_FOLDERS to allow us to navigate libbpf files when working on perf using tools/perf/tags. Signed-off-by: Wang Nan <wangnan0@huawei.com> Acked-by: Alexei Starovoitov <ast@plumgrid.com> Cc: Brendan Gregg <brendan.d.gregg@gmail.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: David Ahern <dsahern@gmail.com> Cc: He Kuang <hekuang@huawei.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kaixu Xia <xiakaixu@huawei.com> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1444826502-49291-2-git-send-email-wangnan0@huawei.com [ Document NO_LIBBPF in Makefile.perf, noted by Jiri Olsa ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 443f8c7 commit ed63f34

5 files changed

Lines changed: 47 additions & 6 deletions

File tree

‎tools/build/Makefile.feature‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ FEATURE_TESTS ?= \
5353
libdw-dwarf-unwind \
5454
zlib \
5555
lzma \
56-
get_cpuid
56+
get_cpuid \
57+
bpf
5758

5859
FEATURE_DISPLAY ?= \
5960
dwarf \
@@ -71,7 +72,8 @@ FEATURE_DISPLAY ?= \
7172
libdw-dwarf-unwind \
7273
zlib \
7374
lzma \
74-
get_cpuid
75+
get_cpuid \
76+
bpf
7577

7678
# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
7779
# If in the future we need per-feature checks/flags for features not

‎tools/perf/MANIFEST‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tools/build
1717
tools/arch/x86/include/asm/atomic.h
1818
tools/arch/x86/include/asm/rmwcc.h
1919
tools/lib/traceevent
20+
tools/lib/bpf
2021
tools/lib/api
2122
tools/lib/bpf
2223
tools/lib/hweight.c
@@ -69,6 +70,8 @@ arch/*/lib/memset*.S
6970
include/linux/poison.h
7071
include/linux/hw_breakpoint.h
7172
include/uapi/linux/perf_event.h
73+
include/uapi/linux/bpf.h
74+
include/uapi/linux/bpf_common.h
7275
include/uapi/linux/const.h
7376
include/uapi/linux/swab.h
7477
include/uapi/linux/hw_breakpoint.h

‎tools/perf/Makefile.perf‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ include config/utilities.mak
7575
# Define NO_LZMA if you do not want to support compressed (xz) kernel modules
7676
#
7777
# Define NO_AUXTRACE if you do not want AUX area tracing support
78+
#
79+
# Define NO_LIBBPF if you do not want BPF support
7880

7981
# As per kernel Makefile, avoid funny character set dependencies
8082
unexport LC_ALL
@@ -145,6 +147,7 @@ AWK = awk
145147

146148
LIB_DIR = $(srctree)/tools/lib/api/
147149
TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
150+
BPF_DIR = $(srctree)/tools/lib/bpf/
148151

149152
# include config/Makefile by default and rule out
150153
# non-config cases
@@ -180,6 +183,7 @@ strip-libs = $(filter-out -l%,$(1))
180183

181184
ifneq ($(OUTPUT),)
182185
TE_PATH=$(OUTPUT)
186+
BPF_PATH=$(OUTPUT)
183187
ifneq ($(subdir),)
184188
LIB_PATH=$(OUTPUT)/../lib/api/
185189
else
@@ -188,6 +192,7 @@ endif
188192
else
189193
TE_PATH=$(TRACE_EVENT_DIR)
190194
LIB_PATH=$(LIB_DIR)
195+
BPF_PATH=$(BPF_DIR)
191196
endif
192197

193198
LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
@@ -199,6 +204,8 @@ LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYN
199204
LIBAPI = $(LIB_PATH)libapi.a
200205
export LIBAPI
201206

207+
LIBBPF = $(BPF_PATH)libbpf.a
208+
202209
# python extension build directories
203210
PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/
204211
PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
@@ -251,6 +258,9 @@ export PERL_PATH
251258
LIB_FILE=$(OUTPUT)libperf.a
252259

253260
PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT)
261+
ifndef NO_LIBBPF
262+
PERFLIBS += $(LIBBPF)
263+
endif
254264

255265
# We choose to avoid "if .. else if .. else .. endif endif"
256266
# because maintaining the nesting to match is a pain. If
@@ -420,6 +430,13 @@ $(LIBAPI)-clean:
420430
$(call QUIET_CLEAN, libapi)
421431
$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
422432

433+
$(LIBBPF): FORCE
434+
$(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) $(OUTPUT)libbpf.a
435+
436+
$(LIBBPF)-clean:
437+
$(call QUIET_CLEAN, libbpf)
438+
$(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null
439+
423440
help:
424441
@echo 'Perf make targets:'
425442
@echo ' doc - make *all* documentation (see below)'
@@ -459,7 +476,7 @@ INSTALL_DOC_TARGETS += quick-install-doc quick-install-man quick-install-html
459476
$(DOC_TARGETS):
460477
$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all)
461478

462-
TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol ../include
479+
TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol ../include ../lib/bpf
463480
TAG_FILES= ../../include/uapi/linux/perf_event.h
464481

465482
TAGS:
@@ -567,7 +584,7 @@ config-clean:
567584
$(call QUIET_CLEAN, config)
568585
$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
569586

570-
clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean config-clean
587+
clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean
571588
$(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
572589
$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
573590
$(Q)$(RM) $(OUTPUT).config-detected

‎tools/perf/config/Makefile‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ ifdef LIBBABELTRACE
106106
FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
107107
endif
108108

109+
FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi
109110
# include ARCH specific config
110111
-include $(src-perf)/arch/$(ARCH)/Makefile
111112

@@ -237,6 +238,7 @@ ifdef NO_LIBELF
237238
NO_DEMANGLE := 1
238239
NO_LIBUNWIND := 1
239240
NO_LIBDW_DWARF_UNWIND := 1
241+
NO_LIBBPF := 1
240242
else
241243
ifeq ($(feature-libelf), 0)
242244
ifeq ($(feature-glibc), 1)
@@ -246,13 +248,14 @@ else
246248
LIBC_SUPPORT := 1
247249
endif
248250
ifeq ($(LIBC_SUPPORT),1)
249-
msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
251+
msg := $(warning No libelf found, disables 'probe' tool and BPF support in 'perf record', please install elfutils-libelf-devel/libelf-dev);
250252

251253
NO_LIBELF := 1
252254
NO_DWARF := 1
253255
NO_DEMANGLE := 1
254256
NO_LIBUNWIND := 1
255257
NO_LIBDW_DWARF_UNWIND := 1
258+
NO_LIBBPF := 1
256259
else
257260
ifneq ($(filter s% -static%,$(LDFLAGS),),)
258261
msg := $(error No static glibc found, please install glibc-static);
@@ -309,6 +312,13 @@ ifndef NO_LIBELF
309312
$(call detected,CONFIG_DWARF)
310313
endif # PERF_HAVE_DWARF_REGS
311314
endif # NO_DWARF
315+
316+
ifndef NO_LIBBPF
317+
ifeq ($(feature-bpf), 1)
318+
CFLAGS += -DHAVE_LIBBPF_SUPPORT
319+
$(call detected,CONFIG_LIBBPF)
320+
endif
321+
endif # NO_LIBBPF
312322
endif # NO_LIBELF
313323

314324
ifeq ($(ARCH),powerpc)
@@ -324,6 +334,13 @@ ifndef NO_LIBUNWIND
324334
endif
325335
endif
326336

337+
ifndef NO_LIBBPF
338+
ifneq ($(feature-bpf), 1)
339+
msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
340+
NO_LIBBPF := 1
341+
endif
342+
endif
343+
327344
dwarf-post-unwind := 1
328345
dwarf-post-unwind-text := BUG
329346

‎tools/perf/tests/make‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ make_no_libnuma := NO_LIBNUMA=1
4444
make_no_libaudit := NO_LIBAUDIT=1
4545
make_no_libbionic := NO_LIBBIONIC=1
4646
make_no_auxtrace := NO_AUXTRACE=1
47+
make_no_libbpf := NO_LIBBPF=1
4748
make_tags := tags
4849
make_cscope := cscope
4950
make_help := help
@@ -66,7 +67,7 @@ make_static := LDFLAGS=-static
6667
make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1
6768
make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1
6869
make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1
69-
make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1
70+
make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1
7071

7172
# $(run) contains all available tests
7273
run := make_pure
@@ -94,6 +95,7 @@ run += make_no_libnuma
9495
run += make_no_libaudit
9596
run += make_no_libbionic
9697
run += make_no_auxtrace
98+
run += make_no_libbpf
9799
run += make_help
98100
run += make_doc
99101
run += make_perf_o

0 commit comments

Comments
 (0)