Commit ed63f34c authored by Wang Nan's avatar Wang Nan Committed by Arnaldo Carvalho de Melo

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: default avatarWang Nan <wangnan0@huawei.com>
Acked-by: default avatarAlexei 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 443f8c75
...@@ -53,7 +53,8 @@ FEATURE_TESTS ?= \ ...@@ -53,7 +53,8 @@ FEATURE_TESTS ?= \
libdw-dwarf-unwind \ libdw-dwarf-unwind \
zlib \ zlib \
lzma \ lzma \
get_cpuid get_cpuid \
bpf
FEATURE_DISPLAY ?= \ FEATURE_DISPLAY ?= \
dwarf \ dwarf \
...@@ -71,7 +72,8 @@ FEATURE_DISPLAY ?= \ ...@@ -71,7 +72,8 @@ FEATURE_DISPLAY ?= \
libdw-dwarf-unwind \ libdw-dwarf-unwind \
zlib \ zlib \
lzma \ lzma \
get_cpuid get_cpuid \
bpf
# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features. # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
# If in the future we need per-feature checks/flags for features not # If in the future we need per-feature checks/flags for features not
......
...@@ -17,6 +17,7 @@ tools/build ...@@ -17,6 +17,7 @@ tools/build
tools/arch/x86/include/asm/atomic.h tools/arch/x86/include/asm/atomic.h
tools/arch/x86/include/asm/rmwcc.h tools/arch/x86/include/asm/rmwcc.h
tools/lib/traceevent tools/lib/traceevent
tools/lib/bpf
tools/lib/api tools/lib/api
tools/lib/bpf tools/lib/bpf
tools/lib/hweight.c tools/lib/hweight.c
...@@ -69,6 +70,8 @@ arch/*/lib/memset*.S ...@@ -69,6 +70,8 @@ arch/*/lib/memset*.S
include/linux/poison.h include/linux/poison.h
include/linux/hw_breakpoint.h include/linux/hw_breakpoint.h
include/uapi/linux/perf_event.h include/uapi/linux/perf_event.h
include/uapi/linux/bpf.h
include/uapi/linux/bpf_common.h
include/uapi/linux/const.h include/uapi/linux/const.h
include/uapi/linux/swab.h include/uapi/linux/swab.h
include/uapi/linux/hw_breakpoint.h include/uapi/linux/hw_breakpoint.h
......
...@@ -75,6 +75,8 @@ include config/utilities.mak ...@@ -75,6 +75,8 @@ include config/utilities.mak
# Define NO_LZMA if you do not want to support compressed (xz) kernel modules # Define NO_LZMA if you do not want to support compressed (xz) kernel modules
# #
# Define NO_AUXTRACE if you do not want AUX area tracing support # Define NO_AUXTRACE if you do not want AUX area tracing support
#
# Define NO_LIBBPF if you do not want BPF support
# As per kernel Makefile, avoid funny character set dependencies # As per kernel Makefile, avoid funny character set dependencies
unexport LC_ALL unexport LC_ALL
...@@ -145,6 +147,7 @@ AWK = awk ...@@ -145,6 +147,7 @@ AWK = awk
LIB_DIR = $(srctree)/tools/lib/api/ LIB_DIR = $(srctree)/tools/lib/api/
TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/ TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
BPF_DIR = $(srctree)/tools/lib/bpf/
# include config/Makefile by default and rule out # include config/Makefile by default and rule out
# non-config cases # non-config cases
...@@ -180,6 +183,7 @@ strip-libs = $(filter-out -l%,$(1)) ...@@ -180,6 +183,7 @@ strip-libs = $(filter-out -l%,$(1))
ifneq ($(OUTPUT),) ifneq ($(OUTPUT),)
TE_PATH=$(OUTPUT) TE_PATH=$(OUTPUT)
BPF_PATH=$(OUTPUT)
ifneq ($(subdir),) ifneq ($(subdir),)
LIB_PATH=$(OUTPUT)/../lib/api/ LIB_PATH=$(OUTPUT)/../lib/api/
else else
...@@ -188,6 +192,7 @@ endif ...@@ -188,6 +192,7 @@ endif
else else
TE_PATH=$(TRACE_EVENT_DIR) TE_PATH=$(TRACE_EVENT_DIR)
LIB_PATH=$(LIB_DIR) LIB_PATH=$(LIB_DIR)
BPF_PATH=$(BPF_DIR)
endif endif
LIBTRACEEVENT = $(TE_PATH)libtraceevent.a LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
...@@ -199,6 +204,8 @@ LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYN ...@@ -199,6 +204,8 @@ LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYN
LIBAPI = $(LIB_PATH)libapi.a LIBAPI = $(LIB_PATH)libapi.a
export LIBAPI export LIBAPI
LIBBPF = $(BPF_PATH)libbpf.a
# python extension build directories # python extension build directories
PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/ PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/
PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/ PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
...@@ -251,6 +258,9 @@ export PERL_PATH ...@@ -251,6 +258,9 @@ export PERL_PATH
LIB_FILE=$(OUTPUT)libperf.a LIB_FILE=$(OUTPUT)libperf.a
PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT) PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT)
ifndef NO_LIBBPF
PERFLIBS += $(LIBBPF)
endif
# We choose to avoid "if .. else if .. else .. endif endif" # We choose to avoid "if .. else if .. else .. endif endif"
# because maintaining the nesting to match is a pain. If # because maintaining the nesting to match is a pain. If
...@@ -420,6 +430,13 @@ $(LIBAPI)-clean: ...@@ -420,6 +430,13 @@ $(LIBAPI)-clean:
$(call QUIET_CLEAN, libapi) $(call QUIET_CLEAN, libapi)
$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
$(LIBBPF): FORCE
$(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) $(OUTPUT)libbpf.a
$(LIBBPF)-clean:
$(call QUIET_CLEAN, libbpf)
$(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null
help: help:
@echo 'Perf make targets:' @echo 'Perf make targets:'
@echo ' doc - make *all* documentation (see below)' @echo ' doc - make *all* documentation (see below)'
...@@ -459,7 +476,7 @@ INSTALL_DOC_TARGETS += quick-install-doc quick-install-man quick-install-html ...@@ -459,7 +476,7 @@ INSTALL_DOC_TARGETS += quick-install-doc quick-install-man quick-install-html
$(DOC_TARGETS): $(DOC_TARGETS):
$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all) $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all)
TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol ../include TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol ../include ../lib/bpf
TAG_FILES= ../../include/uapi/linux/perf_event.h TAG_FILES= ../../include/uapi/linux/perf_event.h
TAGS: TAGS:
...@@ -567,7 +584,7 @@ config-clean: ...@@ -567,7 +584,7 @@ config-clean:
$(call QUIET_CLEAN, config) $(call QUIET_CLEAN, config)
$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean config-clean clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean
$(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS) $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
$(Q)$(RM) $(OUTPUT).config-detected $(Q)$(RM) $(OUTPUT).config-detected
......
...@@ -106,6 +106,7 @@ ifdef LIBBABELTRACE ...@@ -106,6 +106,7 @@ ifdef LIBBABELTRACE
FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
endif endif
FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi
# include ARCH specific config # include ARCH specific config
-include $(src-perf)/arch/$(ARCH)/Makefile -include $(src-perf)/arch/$(ARCH)/Makefile
...@@ -237,6 +238,7 @@ ifdef NO_LIBELF ...@@ -237,6 +238,7 @@ ifdef NO_LIBELF
NO_DEMANGLE := 1 NO_DEMANGLE := 1
NO_LIBUNWIND := 1 NO_LIBUNWIND := 1
NO_LIBDW_DWARF_UNWIND := 1 NO_LIBDW_DWARF_UNWIND := 1
NO_LIBBPF := 1
else else
ifeq ($(feature-libelf), 0) ifeq ($(feature-libelf), 0)
ifeq ($(feature-glibc), 1) ifeq ($(feature-glibc), 1)
...@@ -246,13 +248,14 @@ else ...@@ -246,13 +248,14 @@ else
LIBC_SUPPORT := 1 LIBC_SUPPORT := 1
endif endif
ifeq ($(LIBC_SUPPORT),1) ifeq ($(LIBC_SUPPORT),1)
msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev); msg := $(warning No libelf found, disables 'probe' tool and BPF support in 'perf record', please install elfutils-libelf-devel/libelf-dev);
NO_LIBELF := 1 NO_LIBELF := 1
NO_DWARF := 1 NO_DWARF := 1
NO_DEMANGLE := 1 NO_DEMANGLE := 1
NO_LIBUNWIND := 1 NO_LIBUNWIND := 1
NO_LIBDW_DWARF_UNWIND := 1 NO_LIBDW_DWARF_UNWIND := 1
NO_LIBBPF := 1
else else
ifneq ($(filter s% -static%,$(LDFLAGS),),) ifneq ($(filter s% -static%,$(LDFLAGS),),)
msg := $(error No static glibc found, please install glibc-static); msg := $(error No static glibc found, please install glibc-static);
...@@ -309,6 +312,13 @@ ifndef NO_LIBELF ...@@ -309,6 +312,13 @@ ifndef NO_LIBELF
$(call detected,CONFIG_DWARF) $(call detected,CONFIG_DWARF)
endif # PERF_HAVE_DWARF_REGS endif # PERF_HAVE_DWARF_REGS
endif # NO_DWARF endif # NO_DWARF
ifndef NO_LIBBPF
ifeq ($(feature-bpf), 1)
CFLAGS += -DHAVE_LIBBPF_SUPPORT
$(call detected,CONFIG_LIBBPF)
endif
endif # NO_LIBBPF
endif # NO_LIBELF endif # NO_LIBELF
ifeq ($(ARCH),powerpc) ifeq ($(ARCH),powerpc)
...@@ -324,6 +334,13 @@ ifndef NO_LIBUNWIND ...@@ -324,6 +334,13 @@ ifndef NO_LIBUNWIND
endif endif
endif endif
ifndef NO_LIBBPF
ifneq ($(feature-bpf), 1)
msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
NO_LIBBPF := 1
endif
endif
dwarf-post-unwind := 1 dwarf-post-unwind := 1
dwarf-post-unwind-text := BUG dwarf-post-unwind-text := BUG
......
...@@ -44,6 +44,7 @@ make_no_libnuma := NO_LIBNUMA=1 ...@@ -44,6 +44,7 @@ make_no_libnuma := NO_LIBNUMA=1
make_no_libaudit := NO_LIBAUDIT=1 make_no_libaudit := NO_LIBAUDIT=1
make_no_libbionic := NO_LIBBIONIC=1 make_no_libbionic := NO_LIBBIONIC=1
make_no_auxtrace := NO_AUXTRACE=1 make_no_auxtrace := NO_AUXTRACE=1
make_no_libbpf := NO_LIBBPF=1
make_tags := tags make_tags := tags
make_cscope := cscope make_cscope := cscope
make_help := help make_help := help
...@@ -66,7 +67,7 @@ make_static := LDFLAGS=-static ...@@ -66,7 +67,7 @@ make_static := LDFLAGS=-static
make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1
make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1
make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1
make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1
# $(run) contains all available tests # $(run) contains all available tests
run := make_pure run := make_pure
...@@ -94,6 +95,7 @@ run += make_no_libnuma ...@@ -94,6 +95,7 @@ run += make_no_libnuma
run += make_no_libaudit run += make_no_libaudit
run += make_no_libbionic run += make_no_libbionic
run += make_no_auxtrace run += make_no_auxtrace
run += make_no_libbpf
run += make_help run += make_help
run += make_doc run += make_doc
run += make_perf_o run += make_perf_o
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment