diff options
| author | Ingo Molnar <mingo@kernel.org> | 2015-08-08 04:05:17 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2015-08-08 04:05:17 -0400 |
| commit | f1d800bf615b84ca253af372d2dac8cdef743a20 (patch) | |
| tree | 0ba71f573541cf42609230d8d96bc5e4c295536c | |
| parent | 1354ac6ad84395660f551d0614a6ca39e5bfe8e3 (diff) | |
| parent | 9bc898c7019383b6aa2ae6cb2928c4ca926449f0 (diff) | |
Merge tag 'perf-ebpf-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/ebpf library + llvm/clang infrastructure changes from Arnaldo Carvalho de Melo:
Infrastructure changes:
- Add library for interfacing with the kernel eBPF infrastructure, with
tools/perf/ targeted as a first user. (Wang Nan)
- Add llvm/clang infrastructure for building BPF object files from C source
code. (Wang Nan)
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
| -rw-r--r-- | tools/build/feature/Makefile | 6 | ||||
| -rw-r--r-- | tools/build/feature/test-bpf.c | 18 | ||||
| -rw-r--r-- | tools/lib/bpf/.gitignore | 2 | ||||
| -rw-r--r-- | tools/lib/bpf/Build | 1 | ||||
| -rw-r--r-- | tools/lib/bpf/Makefile | 195 | ||||
| -rw-r--r-- | tools/lib/bpf/bpf.c | 85 | ||||
| -rw-r--r-- | tools/lib/bpf/bpf.h | 23 | ||||
| -rw-r--r-- | tools/lib/bpf/libbpf.c | 1037 | ||||
| -rw-r--r-- | tools/lib/bpf/libbpf.h | 81 | ||||
| -rw-r--r-- | tools/perf/MANIFEST | 1 | ||||
| -rw-r--r-- | tools/perf/tests/Build | 1 | ||||
| -rw-r--r-- | tools/perf/tests/builtin-test.c | 4 | ||||
| -rw-r--r-- | tools/perf/tests/llvm.c | 98 | ||||
| -rw-r--r-- | tools/perf/tests/tests.h | 1 | ||||
| -rw-r--r-- | tools/perf/util/Build | 1 | ||||
| -rw-r--r-- | tools/perf/util/config.c | 4 | ||||
| -rw-r--r-- | tools/perf/util/llvm-utils.c | 408 | ||||
| -rw-r--r-- | tools/perf/util/llvm-utils.h | 49 |
18 files changed, 2014 insertions, 1 deletions
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index 463ed8f2a267..1c0d69f44552 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile | |||
| @@ -33,7 +33,8 @@ FILES= \ | |||
| 33 | test-compile-32.bin \ | 33 | test-compile-32.bin \ |
| 34 | test-compile-x32.bin \ | 34 | test-compile-x32.bin \ |
| 35 | test-zlib.bin \ | 35 | test-zlib.bin \ |
| 36 | test-lzma.bin | 36 | test-lzma.bin \ |
| 37 | test-bpf.bin | ||
| 37 | 38 | ||
| 38 | CC := $(CROSS_COMPILE)gcc -MD | 39 | CC := $(CROSS_COMPILE)gcc -MD |
| 39 | PKG_CONFIG := $(CROSS_COMPILE)pkg-config | 40 | PKG_CONFIG := $(CROSS_COMPILE)pkg-config |
| @@ -156,6 +157,9 @@ test-zlib.bin: | |||
| 156 | test-lzma.bin: | 157 | test-lzma.bin: |
| 157 | $(BUILD) -llzma | 158 | $(BUILD) -llzma |
| 158 | 159 | ||
| 160 | test-bpf.bin: | ||
| 161 | $(BUILD) | ||
| 162 | |||
| 159 | -include *.d | 163 | -include *.d |
| 160 | 164 | ||
| 161 | ############################### | 165 | ############################### |
diff --git a/tools/build/feature/test-bpf.c b/tools/build/feature/test-bpf.c new file mode 100644 index 000000000000..062bac811af9 --- /dev/null +++ b/tools/build/feature/test-bpf.c | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | #include <linux/bpf.h> | ||
| 2 | |||
| 3 | int main(void) | ||
| 4 | { | ||
| 5 | union bpf_attr attr; | ||
| 6 | |||
| 7 | attr.prog_type = BPF_PROG_TYPE_KPROBE; | ||
| 8 | attr.insn_cnt = 0; | ||
| 9 | attr.insns = 0; | ||
| 10 | attr.license = 0; | ||
| 11 | attr.log_buf = 0; | ||
| 12 | attr.log_size = 0; | ||
| 13 | attr.log_level = 0; | ||
| 14 | attr.kern_version = 0; | ||
| 15 | |||
| 16 | attr = attr; | ||
| 17 | return 0; | ||
| 18 | } | ||
diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore new file mode 100644 index 000000000000..812aeedaea38 --- /dev/null +++ b/tools/lib/bpf/.gitignore | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | libbpf_version.h | ||
| 2 | FEATURE-DUMP | ||
diff --git a/tools/lib/bpf/Build b/tools/lib/bpf/Build new file mode 100644 index 000000000000..d8749756352d --- /dev/null +++ b/tools/lib/bpf/Build | |||
| @@ -0,0 +1 @@ | |||
| libbpf-y := libbpf.o bpf.o | |||
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile new file mode 100644 index 000000000000..f68d23a0b487 --- /dev/null +++ b/tools/lib/bpf/Makefile | |||
| @@ -0,0 +1,195 @@ | |||
| 1 | # Most of this file is copied from tools/lib/traceevent/Makefile | ||
| 2 | |||
| 3 | BPF_VERSION = 0 | ||
| 4 | BPF_PATCHLEVEL = 0 | ||
| 5 | BPF_EXTRAVERSION = 1 | ||
| 6 | |||
| 7 | MAKEFLAGS += --no-print-directory | ||
| 8 | |||
| 9 | |||
| 10 | # Makefiles suck: This macro sets a default value of $(2) for the | ||
| 11 | # variable named by $(1), unless the variable has been set by | ||
| 12 | # environment or command line. This is necessary for CC and AR | ||
| 13 | # because make sets default values, so the simpler ?= approach | ||
| 14 | # won't work as expected. | ||
| 15 | define allow-override | ||
| 16 | $(if $(or $(findstring environment,$(origin $(1))),\ | ||
| 17 | $(findstring command line,$(origin $(1)))),,\ | ||
| 18 | $(eval $(1) = $(2))) | ||
| 19 | endef | ||
| 20 | |||
| 21 | # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. | ||
| 22 | $(call allow-override,CC,$(CROSS_COMPILE)gcc) | ||
| 23 | $(call allow-override,AR,$(CROSS_COMPILE)ar) | ||
| 24 | |||
| 25 | INSTALL = install | ||
| 26 | |||
| 27 | # Use DESTDIR for installing into a different root directory. | ||
| 28 | # This is useful for building a package. The program will be | ||
| 29 | # installed in this directory as if it was the root directory. | ||
| 30 | # Then the build tool can move it later. | ||
| 31 | DESTDIR ?= | ||
| 32 | DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' | ||
| 33 | |||
| 34 | LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) | ||
| 35 | ifeq ($(LP64), 1) | ||
| 36 | libdir_relative = lib64 | ||
| 37 | else | ||
| 38 | libdir_relative = lib | ||
| 39 | endif | ||
| 40 | |||
| 41 | prefix ?= /usr/local | ||
| 42 | libdir = $(prefix)/$(libdir_relative) | ||
| 43 | man_dir = $(prefix)/share/man | ||
| 44 | man_dir_SQ = '$(subst ','\'',$(man_dir))' | ||
| 45 | |||
| 46 | export man_dir man_dir_SQ INSTALL | ||
| 47 | export DESTDIR DESTDIR_SQ | ||
| 48 | |||
| 49 | include ../../scripts/Makefile.include | ||
| 50 | |||
| 51 | # copy a bit from Linux kbuild | ||
| 52 | |||
| 53 | ifeq ("$(origin V)", "command line") | ||
| 54 | VERBOSE = $(V) | ||
| 55 | endif | ||
| 56 | ifndef VERBOSE | ||
| 57 | VERBOSE = 0 | ||
| 58 | endif | ||
| 59 | |||
| 60 | ifeq ($(srctree),) | ||
| 61 | srctree := $(patsubst %/,%,$(dir $(shell pwd))) | ||
| 62 | srctree := $(patsubst %/,%,$(dir $(srctree))) | ||
| 63 | srctree := $(patsubst %/,%,$(dir $(srctree))) | ||
| 64 | #$(info Determined 'srctree' to be $(srctree)) | ||
| 65 | endif | ||
| 66 | |||
| 67 | FEATURE_DISPLAY = libelf libelf-getphdrnum libelf-mmap bpf | ||
| 68 | FEATURE_TESTS = libelf bpf | ||
| 69 | |||
| 70 | INCLUDES = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi | ||
| 71 | FEATURE_CHECK_CFLAGS-bpf = $(INCLUDES) | ||
| 72 | |||
| 73 | include $(srctree)/tools/build/Makefile.feature | ||
| 74 | |||
| 75 | export prefix libdir src obj | ||
| 76 | |||
| 77 | # Shell quotes | ||
| 78 | libdir_SQ = $(subst ','\'',$(libdir)) | ||
| 79 | libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) | ||
| 80 | plugin_dir_SQ = $(subst ','\'',$(plugin_dir)) | ||
| 81 | |||
| 82 | LIB_FILE = libbpf.a libbpf.so | ||
| 83 | |||
| 84 | VERSION = $(BPF_VERSION) | ||
| 85 | PATCHLEVEL = $(BPF_PATCHLEVEL) | ||
| 86 | EXTRAVERSION = $(BPF_EXTRAVERSION) | ||
| 87 | |||
| 88 | OBJ = $@ | ||
| 89 | N = | ||
| 90 | |||
| 91 | LIBBPF_VERSION = $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION) | ||
| 92 | |||
| 93 | # Set compile option CFLAGS | ||
| 94 | ifdef EXTRA_CFLAGS | ||
| 95 | CFLAGS := $(EXTRA_CFLAGS) | ||
| 96 | else | ||
| 97 | CFLAGS := -g -Wall | ||
| 98 | endif | ||
| 99 | |||
| 100 | ifeq ($(feature-libelf-mmap), 1) | ||
| 101 | override CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT | ||
| 102 | endif | ||
| 103 | |||
| 104 | ifeq ($(feature-libelf-getphdrnum), 1) | ||
| 105 | override CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT | ||
| 106 | endif | ||
| 107 | |||
| 108 | # Append required CFLAGS | ||
| 109 | override CFLAGS += $(EXTRA_WARNINGS) | ||
| 110 | override CFLAGS += -Werror -Wall | ||
| 111 | override CFLAGS += -fPIC | ||
| 112 | override CFLAGS += $(INCLUDES) | ||
| 113 | |||
| 114 | ifeq ($(VERBOSE),1) | ||
| 115 | Q = | ||
| 116 | else | ||
| 117 | Q = @ | ||
| 118 | endif | ||
| 119 | |||
| 120 | # Disable command line variables (CFLAGS) overide from top | ||
| 121 | # level Makefile (perf), otherwise build Makefile will get | ||
| 122 | # the same command line setup. | ||
| 123 | MAKEOVERRIDES= | ||
| 124 | |||
| 125 | export srctree OUTPUT CC LD CFLAGS V | ||
| 126 | build := -f $(srctree)/tools/build/Makefile.build dir=. obj | ||
| 127 | |||
| 128 | BPF_IN := $(OUTPUT)libbpf-in.o | ||
| 129 | LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE)) | ||
| 130 | |||
| 131 | CMD_TARGETS = $(LIB_FILE) | ||
| 132 | |||
| 133 | TARGETS = $(CMD_TARGETS) | ||
| 134 | |||
| 135 | all: $(VERSION_FILES) all_cmd | ||
| 136 | |||
| 137 | all_cmd: $(CMD_TARGETS) | ||
| 138 | |||
