Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Wang Nan and committed by
Arnaldo Carvalho de Melo
ed63f34c 443f8c75

+47 -6
+4 -2
tools/build/Makefile.feature
··· 53 53 libdw-dwarf-unwind \ 54 54 zlib \ 55 55 lzma \ 56 - get_cpuid 56 + get_cpuid \ 57 + bpf 57 58 58 59 FEATURE_DISPLAY ?= \ 59 60 dwarf \ ··· 72 71 libdw-dwarf-unwind \ 73 72 zlib \ 74 73 lzma \ 75 - get_cpuid 74 + get_cpuid \ 75 + bpf 76 76 77 77 # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features. 78 78 # If in the future we need per-feature checks/flags for features not
+3
tools/perf/MANIFEST
··· 17 17 tools/arch/x86/include/asm/atomic.h 18 18 tools/arch/x86/include/asm/rmwcc.h 19 19 tools/lib/traceevent 20 + tools/lib/bpf 20 21 tools/lib/api 21 22 tools/lib/bpf 22 23 tools/lib/hweight.c ··· 70 69 include/linux/poison.h 71 70 include/linux/hw_breakpoint.h 72 71 include/uapi/linux/perf_event.h 72 + include/uapi/linux/bpf.h 73 + include/uapi/linux/bpf_common.h 73 74 include/uapi/linux/const.h 74 75 include/uapi/linux/swab.h 75 76 include/uapi/linux/hw_breakpoint.h
+19 -2
tools/perf/Makefile.perf
··· 75 75 # Define NO_LZMA if you do not want to support compressed (xz) kernel modules 76 76 # 77 77 # Define NO_AUXTRACE if you do not want AUX area tracing support 78 + # 79 + # Define NO_LIBBPF if you do not want BPF support 78 80 79 81 # As per kernel Makefile, avoid funny character set dependencies 80 82 unexport LC_ALL ··· 147 145 148 146 LIB_DIR = $(srctree)/tools/lib/api/ 149 147 TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/ 148 + BPF_DIR = $(srctree)/tools/lib/bpf/ 150 149 151 150 # include config/Makefile by default and rule out 152 151 # non-config cases ··· 183 180 184 181 ifneq ($(OUTPUT),) 185 182 TE_PATH=$(OUTPUT) 183 + BPF_PATH=$(OUTPUT) 186 184 ifneq ($(subdir),) 187 185 LIB_PATH=$(OUTPUT)/../lib/api/ 188 186 else ··· 192 188 else 193 189 TE_PATH=$(TRACE_EVENT_DIR) 194 190 LIB_PATH=$(LIB_DIR) 191 + BPF_PATH=$(BPF_DIR) 195 192 endif 196 193 197 194 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a ··· 203 198 204 199 LIBAPI = $(LIB_PATH)libapi.a 205 200 export LIBAPI 201 + 202 + LIBBPF = $(BPF_PATH)libbpf.a 206 203 207 204 # python extension build directories 208 205 PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/ ··· 258 251 LIB_FILE=$(OUTPUT)libperf.a 259 252 260 253 PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT) 254 + ifndef NO_LIBBPF 255 + PERFLIBS += $(LIBBPF) 256 + endif 261 257 262 258 # We choose to avoid "if .. else if .. else .. endif endif" 263 259 # because maintaining the nesting to match is a pain. If ··· 430 420 $(call QUIET_CLEAN, libapi) 431 421 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null 432 422 423 + $(LIBBPF): FORCE 424 + $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) $(OUTPUT)libbpf.a 425 + 426 + $(LIBBPF)-clean: 427 + $(call QUIET_CLEAN, libbpf) 428 + $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null 429 + 433 430 help: 434 431 @echo 'Perf make targets:' 435 432 @echo ' doc - make *all* documentation (see below)' ··· 476 459 $(DOC_TARGETS): 477 460 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all) 478 461 479 - TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol ../include 462 + TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol ../include ../lib/bpf 480 463 TAG_FILES= ../../include/uapi/linux/perf_event.h 481 464 482 465 TAGS: ··· 584 567 $(call QUIET_CLEAN, config) 585 568 $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null 586 569 587 - clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean config-clean 570 + clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean 588 571 $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS) 589 572 $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete 590 573 $(Q)$(RM) $(OUTPUT).config-detected
+18 -1
tools/perf/config/Makefile
··· 106 106 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf 107 107 endif 108 108 109 + FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi 109 110 # include ARCH specific config 110 111 -include $(src-perf)/arch/$(ARCH)/Makefile 111 112 ··· 238 237 NO_DEMANGLE := 1 239 238 NO_LIBUNWIND := 1 240 239 NO_LIBDW_DWARF_UNWIND := 1 240 + NO_LIBBPF := 1 241 241 else 242 242 ifeq ($(feature-libelf), 0) 243 243 ifeq ($(feature-glibc), 1) ··· 248 246 LIBC_SUPPORT := 1 249 247 endif 250 248 ifeq ($(LIBC_SUPPORT),1) 251 - msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev); 249 + msg := $(warning No libelf found, disables 'probe' tool and BPF support in 'perf record', please install elfutils-libelf-devel/libelf-dev); 252 250 253 251 NO_LIBELF := 1 254 252 NO_DWARF := 1 255 253 NO_DEMANGLE := 1 256 254 NO_LIBUNWIND := 1 257 255 NO_LIBDW_DWARF_UNWIND := 1 256 + NO_LIBBPF := 1 258 257 else 259 258 ifneq ($(filter s% -static%,$(LDFLAGS),),) 260 259 msg := $(error No static glibc found, please install glibc-static); ··· 312 309 $(call detected,CONFIG_DWARF) 313 310 endif # PERF_HAVE_DWARF_REGS 314 311 endif # NO_DWARF 312 + 313 + ifndef NO_LIBBPF 314 + ifeq ($(feature-bpf), 1) 315 + CFLAGS += -DHAVE_LIBBPF_SUPPORT 316 + $(call detected,CONFIG_LIBBPF) 317 + endif 318 + endif # NO_LIBBPF 315 319 endif # NO_LIBELF 316 320 317 321 ifeq ($(ARCH),powerpc) ··· 331 321 ifneq ($(feature-libunwind), 1) 332 322 msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR); 333 323 NO_LIBUNWIND := 1 324 + endif 325 + endif 326 + 327 + ifndef NO_LIBBPF 328 + ifneq ($(feature-bpf), 1) 329 + msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.) 330 + NO_LIBBPF := 1 334 331 endif 335 332 endif 336 333
+3 -1
tools/perf/tests/make
··· 44 44 make_no_libaudit := NO_LIBAUDIT=1 45 45 make_no_libbionic := NO_LIBBIONIC=1 46 46 make_no_auxtrace := NO_AUXTRACE=1 47 + make_no_libbpf := NO_LIBBPF=1 47 48 make_tags := tags 48 49 make_cscope := cscope 49 50 make_help := help ··· 67 66 make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 68 67 make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 69 68 make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 70 - make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 69 + make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 71 70 72 71 # $(run) contains all available tests 73 72 run := make_pure ··· 95 94 run += make_no_libaudit 96 95 run += make_no_libbionic 97 96 run += make_no_auxtrace 97 + run += make_no_libbpf 98 98 run += make_help 99 99 run += make_doc 100 100 run += make_perf_o