Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66a565c2 authored by Ingo Molnar's avatar Ingo Molnar
Browse files

Merge tag 'perf-ebpf-for-mingo' of...

Merge tag 'perf-ebpf-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux

 into perf/core

Pull basic perf/ebpf integration:

 "Please see the changeset comments, but this is the very basic integration of
  perf with libbpf that, given a .o file built for the 'bpf' target with clang,
  will get it validated and loaded into the kernel via the sys_bpf syscall, which
  can be seen using 'perf trace' to trace the whole thing looking just for the
  bpf and perf_event_open syscalls:

    # perf trace -e bpf,perf_event_open perf record -g --event /tmp/foo.o -a
     362.779 ( 0.129 ms): perf/22408 bpf(cmd: 5, uattr: 0x7ffd4edb6db0, size: 48                           ) = 3
     384.192 ( 0.016 ms): perf/22408 perf_event_open(attr_uptr: 0x7ffd4edbace0, pid: -1, cpu: 3, group_fd: -1, flags: FD_CLOEXEC) = 5
     384.247 ( 0.038 ms): perf/22408 perf_event_open(attr_uptr: 0x37aedd8, pid: -1, group_fd: -1, flags: FD_CLOEXEC) = 5
     384.261 ( 0.007 ms): perf/22408 perf_event_open(attr_uptr: 0x37aedd8, pid: -1, group_fd: -1, flags: FD_CLOEXEC) = 5
     387.680 ( 3.413 ms): perf/22408 perf_event_open(attr_uptr: 0x3222f08, pid: -1, group_fd: -1, flags: FD_CLOEXEC) = 5
     387.688 ( 0.005 ms): perf/22408 perf_event_open(attr_uptr: 0x3222f08, pid: -1, cpu: 1, group_fd: -1, flags: FD_CLOEXEC) = 6
     387.693 ( 0.004 ms): perf/22408 perf_event_open(attr_uptr: 0x3222f08, pid: -1, cpu: 2, group_fd: -1, flags: FD_CLOEXEC) = 7
     387.698 ( 0.003 ms): perf/22408 perf_event_open(attr_uptr: 0x3222f08, pid: -1, cpu: 3, group_fd: -1, flags: FD_CLOEXEC) = 8
    ^C[ perf record: Woken up 1 times to write data ]
      [ perf record: Captured and wrote 0.221 MB perf.data (2 samples) ]
    # perf script
    bash 18389 [002] 83446.412607: perf_bpf_probe:fork: (ffffffff8109be30)
                    29be31 _do_fork (/lib/modules/4.3.0-rc6+/build/vmlinux)
                    96d662 tracesys_phase2 (/lib/modules/4.3.0-rc6+/build/vmlinux)
                     bd56c __libc_fork (/usr/lib64/libc-2.17.so)
                     413b2 make_child (/usr/bin/bash)

    bash 18389 [002] 83447.227255: perf_bpf_probe:fork: (ffffffff8109be30)
                    29be31 _do_fork (/lib/modules/4.3.0-rc6+/build/vmlinux)
                    96d662 tracesys_phase2 (/lib/modules/4.3.0-rc6+/build/vmlinux)
                     bd56c __libc_fork (/usr/lib64/libc-2.17.so)
                     413b2 make_child (/usr/bin/bash)

    # perf evlist -v
    perf_bpf_probe:fork: type: 2, size: 112, config: 0x6cf, { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD|RAW, disabled: 1, inherit: 1, mmap: 1, comm: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1
    #

  More work is about to be reviewed, tested and merged that will allow the whole
  process of going from a .c file to an .o file via clang, etc to be done
  automagically. (Wang Nan)"

Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parents 6fc774ef 4edf30e3
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -53,7 +53,8 @@ FEATURE_TESTS ?= \
	libdw-dwarf-unwind		\
	zlib				\
	lzma				\
	get_cpuid
	get_cpuid			\
	bpf

FEATURE_DISPLAY ?=			\
	dwarf				\
@@ -71,7 +72,8 @@ FEATURE_DISPLAY ?= \
	libdw-dwarf-unwind		\
	zlib				\
	lzma				\
	get_cpuid
	get_cpuid			\
	bpf

# 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
+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ tools/build
tools/arch/x86/include/asm/atomic.h
tools/arch/x86/include/asm/rmwcc.h
tools/lib/traceevent
tools/lib/bpf
tools/lib/api
tools/lib/bpf
tools/lib/hweight.c
@@ -69,6 +70,8 @@ arch/*/lib/memset*.S
include/linux/poison.h
include/linux/hw_breakpoint.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/swab.h
include/uapi/linux/hw_breakpoint.h
+19 −2
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ include config/utilities.mak
# 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_LIBBPF if you do not want BPF support

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

LIB_DIR          = $(srctree)/tools/lib/api/
TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
BPF_DIR = $(srctree)/tools/lib/bpf/

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

ifneq ($(OUTPUT),)
  TE_PATH=$(OUTPUT)
  BPF_PATH=$(OUTPUT)
ifneq ($(subdir),)
  LIB_PATH=$(OUTPUT)/../lib/api/
else
@@ -188,6 +192,7 @@ endif
else
  TE_PATH=$(TRACE_EVENT_DIR)
  LIB_PATH=$(LIB_DIR)
  BPF_PATH=$(BPF_DIR)
endif

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

LIBBPF = $(BPF_PATH)libbpf.a

# python extension build directories
PYTHON_EXTBUILD     := $(OUTPUT)python_ext_build/
PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
@@ -251,6 +258,9 @@ export PERL_PATH
LIB_FILE=$(OUTPUT)libperf.a

PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT)
ifndef NO_LIBBPF
  PERFLIBS += $(LIBBPF)
endif

# We choose to avoid "if .. else if .. else .. endif endif"
# because maintaining the nesting to match is a pain.  If
@@ -420,6 +430,13 @@ $(LIBAPI)-clean:
	$(call QUIET_CLEAN, libapi)
	$(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:
	@echo 'Perf make targets:'
	@echo '  doc		- make *all* documentation (see below)'
@@ -459,7 +476,7 @@ INSTALL_DOC_TARGETS += quick-install-doc quick-install-man quick-install-html
$(DOC_TARGETS):
	$(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

TAGS:
@@ -567,7 +584,7 @@ config-clean:
	$(call QUIET_CLEAN, config)
	$(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)
	$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
	$(Q)$(RM) $(OUTPUT).config-detected
+18 −1
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ ifdef LIBBABELTRACE
  FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
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 $(src-perf)/arch/$(ARCH)/Makefile

@@ -237,6 +238,7 @@ ifdef NO_LIBELF
  NO_DEMANGLE := 1
  NO_LIBUNWIND := 1
  NO_LIBDW_DWARF_UNWIND := 1
  NO_LIBBPF := 1
else
  ifeq ($(feature-libelf), 0)
    ifeq ($(feature-glibc), 1)
@@ -246,13 +248,14 @@ else
      LIBC_SUPPORT := 1
    endif
    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_DWARF := 1
      NO_DEMANGLE := 1
      NO_LIBUNWIND := 1
      NO_LIBDW_DWARF_UNWIND := 1
      NO_LIBBPF := 1
    else
      ifneq ($(filter s% -static%,$(LDFLAGS),),)
        msg := $(error No static glibc found, please install glibc-static);
@@ -309,6 +312,13 @@ ifndef NO_LIBELF
      $(call detected,CONFIG_DWARF)
    endif # PERF_HAVE_DWARF_REGS
  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

ifeq ($(ARCH),powerpc)
@@ -324,6 +334,13 @@ ifndef NO_LIBUNWIND
  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-text := BUG

+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include "util/run-command.h"
#include "util/parse-events.h"
#include "util/parse-options.h"
#include "util/bpf-loader.h"
#include "util/debug.h"
#include <api/fs/tracing_path.h>
#include <pthread.h>
@@ -385,6 +386,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
	status = p->fn(argc, argv, prefix);
	exit_browser(status);
	perf_env__exit(&perf_env);
	bpf__clear();

	if (status)
		return status & 0xff;
Loading