perf tools: filtering events using eBPF programs
Subsystems (3)
(I forget to CC mailing list when sending previous pull req. Sorry for the noisy.)
Hi Arnaldo,
I rebased my code on your perf/core and send a new pull request. You
can find main changes in the tag message. The most biggest changes are the resesigning of dummy placeholder and the new testcase for BPF prologue. They are patch 10, patch 11, patch 26 and patch 27. Please have a look at them.
The following changes since commit 0959e527b1593e662cb99639a587eac39ea1232d:
perf stat: Move sw clock metrics printout to stat-shadow (2015-09-04 20:30:01 -0300)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pi3orama/linux tags/perf-ebpf-for-acme
for you to fetch changes up to 3af1c7f44478d1545f202bd0054e767d3f0f8130:
perf test: Test BPF prologue (2015-09-06 06:10:12 +0000)
----------------------------------------------------------------
BPF related bugfix and improve
1. Enforce the assumption that event parser never return empty list.
2. Reuse code and API from kernel's regs_query_register_offset().
3. Totally redesign dummy placeholder. Reuse existing dummy event instead of creating a new one.
4. Introduce new testcases, test LLVM kbuild searching and BPF prologue.
5. Adding a missing '!' in add_perf_probe_events.
6. Use new API ({convert,apply,cleanup}_perf_probe_events) to probe events. (while fix a bug that non-root user can't trace non-BPF events, like cycles)
----------------------------------------------------------------
He Kuang (2):
perf tools: Add prologue for BPF programs for fetching arguments perf record: Support custom vmlinux path
Wang Nan (25):
perf tools: Don't write to evsel if parser doesn't collect evsel perf tools: Make perf depend on libbpf
perf ebpf: Add the libbpf glue
perf tools: Enable passing bpf object file to --event perf record, bpf: Parse and create probe points for BPF programs perf bpf: Collect 'struct perf_probe_event' for bpf_program perf record: Load all eBPF object into kernel
perf tools: Add bpf_fd field to evsel and config it perf tools: Attach eBPF program to perf event
perf tools: Allow BPF placeholder dummy events to collect --filter
options
perf tools: Sync setting of real bpf events with placeholder perf record: Add clang options for compiling BPF scripts perf tools: Compile scriptlets to BPF objects when passing '.c' to
--event
perf test: Enforce LLVM test for BPF test
perf test: Add 'perf test BPF'
bpf tools: Load a program with different instances using preprocessor perf probe: Reset args and nargs for probe_trace_event when failure perf tools: Add BPF_PROLOGUE config options for further patches perf tools: Introduce regs_query_register_offset() for x86 perf tools: Generate prologue for BPF programs
perf tools: Use same BPF program if arguments are identical perf probe: Init symbol as kprobe
perf tools: Allow BPF program attach to uprobe events
perf test: Enforce LLVM test, add kbuild test
perf test: Test BPF prologue
tools/build/Makefile.feature | 6 +- tools/lib/bpf/libbpf.c | 143 +++++- tools/lib/bpf/libbpf.h | 22 + tools/perf/MANIFEST | 3 + tools/perf/Makefile.perf | 19 +- tools/perf/arch/x86/Makefile | 1 + tools/perf/arch/x86/util/Build | 1 + tools/perf/arch/x86/util/dwarf-regs.c | 122 +++-- tools/perf/builtin-record.c | 58 ++- tools/perf/builtin-stat.c | 8 +- tools/perf/builtin-top.c | 10 +- tools/perf/builtin-trace.c | 6 +- tools/perf/config/Makefile | 36 +- tools/perf/tests/Build | 24 +- tools/perf/tests/bpf-script-example.c | 48 ++ tools/perf/tests/bpf-script-test-kbuild.c | 21 + tools/perf/tests/bpf-script-test-prologue.c | 35 ++ tools/perf/tests/bpf.c | 229 +++++++++ tools/perf/tests/builtin-test.c | 12 + tools/perf/tests/llvm.c | 210 +++++++- tools/perf/tests/llvm.h | 29 ++ tools/perf/tests/make | 4 +- tools/perf/tests/tests.h | 3 + tools/perf/util/Build | 2 + tools/perf/util/bpf-loader.c | 756 ++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 94 ++++ tools/perf/util/bpf-prologue.c | 443 ++++++++++++++++ tools/perf/util/bpf-prologue.h | 34 ++ tools/perf/util/evlist.c | 115 +++++ tools/perf/util/evlist.h | 1 + tools/perf/util/evsel.c | 49 ++ tools/perf/util/evsel.h | 24 + tools/perf/util/include/dwarf-regs.h | 8 + tools/perf/util/parse-events.c | 82 ++- tools/perf/util/parse-events.h | 4 + tools/perf/util/parse-events.l | 6 + tools/perf/util/parse-events.y | 29 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/probe-finder.c | 4 + 39 files changed, 2618 insertions(+), 85 deletions(-) create mode 100644 tools/perf/tests/bpf-script-example.c create mode 100644 tools/perf/tests/bpf-script-test-kbuild.c create mode 100644 tools/perf/tests/bpf-script-test-prologue.c create mode 100644 tools/perf/tests/bpf.c create mode 100644 tools/perf/tests/llvm.h create mode 100644 tools/perf/util/bpf-loader.c create mode 100644 tools/perf/util/bpf-loader.h create mode 100644 tools/perf/util/bpf-prologue.c create mode 100644 tools/perf/util/bpf-prologue.h
Signature · 1 line
2.1.0
PATCH 1/27 perf tools: Don't write to evsel if parser doesn't collect evsel
If parse_events__scanner() collects no entry, perf_evlist__last(evlist) is invalid.
Although it shouldn't happen at this point, before calling perf_evlist__last(), we should ensure the list is not empty for safety reason.
There are 3 places need this checking:
1. Before setting cmdline_group_boundary;
2. Before __perf_evlist__set_leader();
3. In foreach_evsel_in_last_glob.
--- tools/perf/util/parse-events.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
tools/perf/util/parse-events.c +20 -3
@@ -793,6 +793,11 @@ void parse_events__set_leader(char *name, struct list_head *list) {struct perf_evsel *leader; +if (list_empty (list)) { +WARN_ONCE (true,"WARNING: failed to set leader: empty list" ); +return ; + } +__perf_evlist__set_leader (list); leader = list_entry(list->next, struct perf_evsel, node); leader->group_name = name ?strdup (name) :NULL ;
@@ -1143,10 +1148,16 @@ int parse_events(struct perf_evlist *evlist, const char *str,int entries = data.idx - evlist->nr_entries;struct perf_evsel *last; +if (list_empty (&data.list)) { +WARN_ONCE (true,"WARNING: event parser found nothing" ); +return -1 ; + } + + last = list_entry(data.list.prev, struct perf_evsel, node); + last->cmdline_group_boundary = true; +perf_evlist__splice_list_tail (evlist, &data.list, entries); evlist->nr_groups += data.nr_groups; - last =perf_evlist__last (evlist); - last->cmdline_group_boundary = true;return 0 ; }
@@ -1252,7 +1263,13 @@ foreach_evsel_in_last_glob(struct perf_evlist *evlist,struct perf_evsel *last =NULL ;int err; -if (evlist->nr_entries >0 ) +/* +* Don't return when list_empty, give func a chance to report +* error when it found last == NULL. +* +* So no need to WARN here, let *func do this. +*/ +if (!list_empty (&evlist->entries)) last =perf_evlist__last (evlist); do {
Signature · 1 line
2.1.0
tip-bot for Wang Nan
merge bot[tip:perf/core] perf tools: Don' t assume that the parser returns non empty evsel list
perf tools: Don't assume that the parser returns non empty evsel list
Commit-ID: 854f736364c659046f066a98fed2fdb10a39577a Gitweb: http://git.kernel.org/tip/854f736364c659046f066a98fed2fdb10a39577a Author: Wang Nan <[email protected]> AuthorDate: Sun, 6 Sep 2015 07:13:17 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 21 Sep 2015 18:01:17 -0300
perf tools: Don't assume that the parser returns non empty evsel list
Don't blindly retrieve and use a last element in the lists returned by parse_events__scanner(), as it may have collected no entries, i.e. return an empty list.
--- tools/perf/util/parse-events.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tools/perf/util/parse-events.c +16 -0
@@ -827,6 +827,11 @@ void parse_events__set_leader(char *name, struct list_head *list) {struct perf_evsel *leader; +if (list_empty (list)) { +WARN_ONCE (true,"WARNING: failed to set leader: empty list" ); +return ; + } +__perf_evlist__set_leader (list); leader = list_entry(list->next, struct perf_evsel, node); leader->group_name = name ?strdup (name) :NULL ;
@@ -1176,6 +1181,11 @@ int parse_events(struct perf_evlist *evlist, const char *str,if (!ret) {struct perf_evsel *last; +if (list_empty (&data.list)) { +WARN_ONCE (true,"WARNING: event parser found nothing" ); +return -1 ; + } +perf_evlist__splice_list_tail (evlist, &data.list); evlist->nr_groups += data.nr_groups; last =perf_evlist__last (evlist);
@@ -1285,6 +1295,12 @@ foreach_evsel_in_last_glob(struct perf_evlist *evlist,struct perf_evsel *last =NULL ;int err; +/* +* Don't return when list_empty, give func a chance to report +* error when it found last == NULL. +* +* So no need to WARN here, let *func do this. +*/ if (evlist->nr_entries >0 ) last =perf_evlist__last (evlist);
PATCH 2/27 perf tools: Make perf depend on libbpf
In reply to Wang NanBy adding libbpf into perf's Makefile, this patch enables perf to build libbpf during building if libelf is found and neither NO_LIBELF nor NO_LIBBPF is set. The newly introduced code is similar to libapi and libtraceevent building in Makefile.perf.
MANIFEST is also updated for 'make perf-*-src-pkg'.
Append make_no_libbpf to tools/perf/tests/make.
'bpf' feature check is appended into default FEATURE_TESTS and FEATURE_DISPLAY, so perf will check 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 disable of BPF support of 'perf record' if libelf is missed or BPF API check failed.
tools/lib/bpf is added into TAG_FOLDERS to allow us to navigate on libbpf files when working on perf using tools/perf/tags.
--- tools/build/Makefile.feature | 6 ++++-- tools/perf/MANIFEST | 3 +++ tools/perf/Makefile.perf | 19 +++++++++++++++++-- tools/perf/config/Makefile | 19 ++++++++++++++++++- tools/perf/tests/make | 4 +++- 5 files changed, 45 insertions(+), 6 deletions(-)
tools/build/Makefile.feature +4 -2
@@ -51,7 +51,8 @@ FEATURE_TESTS ?= \ timerfd \ libdw-dwarf-unwind \ zlib \ - lzma + lzma \ + bpf FEATURE_DISPLAY ?= \ dwarf \
@@ -67,7 +68,8 @@ FEATURE_DISPLAY ?= \ libunwind \ libdw-dwarf-unwind \ zlib \ - lzma + lzma \ + 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
tools/perf/MANIFEST +3 -0
@@ -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
@@ -68,6 +69,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
tools/perf/Makefile.perf +17 -2
@@ -145,6 +145,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 +181,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 +190,7 @@ endif else TE_PATH=$(TRACE_EVENT_DIR) LIB_PATH=$(LIB_DIR) + BPF_PATH=$(BPF_DIR) endif LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
@@ -199,6 +202,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 +256,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 +428,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 +474,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 +TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol ../lib/bpf TAG_FILES= ../../include/uapi/linux/perf_event.h TAGS:
@@ -567,7 +582,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
tools/perf/config/Makefile +18 -1
@@ -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
@@ -233,6 +234,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)
@@ -242,13 +244,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);
@@ -305,6 +308,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)
@@ -320,6 +330,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
tools/perf/tests/make +3 -1
@@ -44,6 +44,7 @@ make_no_libnuma := NO_LIBNUMA=1 make_no_libaudit := NO_LIBAUDIT=1 make_no_libbionic := NO_LIBBIONIC=1 make_no_auxtrace := NO_AUXTRACE=1 +make_no_libbpf := NO_LIBBPF=1 make_tags := tags make_cscope := cscope make_help := help
@@ -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_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_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 := make_pure
@@ -94,6 +95,7 @@ run += make_no_libnuma run += make_no_libaudit run += make_no_libbionic run += make_no_auxtrace +run += make_no_libbpf run += make_help run += make_doc run += make_perf_o
Signature · 1 line
2.1.0
PATCH 3/27 perf ebpf: Add the libbpf glue
In reply to Wang NanThe 'bpf-loader.[ch]' files are introduced in this patch. Which will be the interface between perf and libbpf. bpf__prepare_load() resides in bpf-loader.c. Dummy functions should be used because bpf-loader.c is available only when CONFIG_LIBBPF is on.
Functions in bpf-loader.c should not report error explicitly. Instead, strerror style error reporting should be used.
--- tools/perf/util/bpf-loader.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 47 ++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 tools/perf/util/bpf-loader.c create mode 100644 tools/perf/util/bpf-loader.h
tools/perf/util/bpf-loader.c new file +92 -0
@@ -0,0 +1,92 @@ +/* +* bpf-loader.c +* +* Copyright (C) 2015 Wang Nan <[email protected]> +* Copyright (C) 2015 Huawei Inc. +*/ + +#include <bpf/libbpf.h> +#include "perf.h" +#include "debug.h" +#include "bpf-loader.h" + +#define DEFINE_PRINT_FN (name, level) \ +static int libbpf_##name(const char *fmt, ...) \ +{ \ + va_list args; \ + int ret; \ + \ + va_start(args, fmt); \ + ret = veprintf(level, verbose, pr_fmt(fmt), args);\ + va_end(args); \ + return ret; \ +} + +DEFINE_PRINT_FN(warning, 0) +DEFINE_PRINT_FN(info, 0) +DEFINE_PRINT_FN(debug, 1) + +static bool libbpf_initialized; + +int bpf__prepare_load (const char *filename) +{ +struct bpf_object *obj; + +if (!libbpf_initialized) +libbpf_set_print (libbpf_warning, + libbpf_info, + libbpf_debug); + + obj =bpf_object__open (filename); +if (!obj) { +pr_debug ("bpf: failed to load %s\n" , filename); +return -EINVAL ; + } + +/* +* Throw object pointer away: it will be retrived using +* bpf_objects iterater. +*/ + +return 0 ; +} + +void bpf__clear (void ) +{ +struct bpf_object *obj, *tmp; + +bpf_object__for_each_safe (obj, tmp) +bpf_object__close (obj); +} + +#define bpf__strerror_head (err, buf, size) \ + char sbuf[STRERR_BUFSIZE], *emsg;\ + if (!size)\ + return 0;\ + if (err < 0)\ + err = -err;\ + emsg = strerror_r(err, sbuf, sizeof(sbuf));\ + switch (err) {\ + default:\ + scnprintf(buf, size, "%s", emsg);\ + break; + +#define bpf__strerror_entry(val, fmt...)\ + case val: {\ + scnprintf(buf, size, fmt);\ + break;\ + } + +#define bpf__strerror_end (buf, size)\ + }\ + buf[size - 1] = '\0'; + +int bpf__strerror_prepare_load (const char *filename,int err, +char *buf,size_t size) +{ +bpf__strerror_head (err, buf, size); +bpf__strerror_entry (EINVAL ,"%s: BPF object file '%s' is invalid" , + emsg, filename) +bpf__strerror_end (buf, size); +return 0 ; +}
tools/perf/util/bpf-loader.h new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 4/27 perf tools: Enable passing bpf object file to --event
In reply to Wang NanBy introducing new rules in tools/perf/util/parse-events.[ly], this patch enables 'perf record --event bpf_file.o' to select events by an eBPF object file. It calls parse_events_load_bpf() to load that file, which uses bpf__prepare_load() and finally calls bpf_object__open() for the object files.
Instead of introducing evsel to evlist during parsing, events selected by eBPF object files are appended separately. The reason is:
1. During parsing, the probing points have not been initialized.
2. Currently we are unable to call add_perf_probe_events() twice, therefore we have to wait until all such events are collected, then probe all points by one call.
The real probing and selecting is reside in following patches.
To make it compatible with other events, we insert a dummy event onto evlist. Its name field can be used to connect path of the object file.
Since bpf__prepare_load() is possible to be called during cmdline parsing, all builtin commands which are possible to call parse_events_option() should release bpf resources during cleanup. Add bpf__clear() to stat, record, top and trace commands, although currently we are going to support 'perf record' only.
Commiter note:
Testing if the event parsing changes indeed call the BPF loading routines:
[root@felicio ~]# ls -la foo.o
ls: cannot access foo.o: No such file or directory [root@felicio ~]# perf record --event foo.o sleep
libbpf: failed to open foo.o: No such file or directory
bpf: failed to load foo.o
invalid or unsupported event: 'foo.o'
Run 'perf list' for a list of valid events
usage: perf record [<options>] [<command>]
or: perf record [<options>] -- <command> [<options>]
-e, --event <event> event selector. use 'perf list' to list available events
[root@felicio ~]#
Yes, it does this time around.
[ The veprintf() and bpf loader parts were split from this one;
Add bpf__clear() into stat, record, top and trace commands. Add dummy evsel as place holder of BPF objects.
]
--- tools/perf/builtin-record.c | 7 ++++-- tools/perf/builtin-stat.c | 8 ++++-- tools/perf/builtin-top.c | 10 +++++--- tools/perf/builtin-trace.c | 6 ++++- tools/perf/util/Build | 1 + tools/perf/util/parse-events.c | 55 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/parse-events.h | 3 +++ tools/perf/util/parse-events.l | 3 +++ tools/perf/util/parse-events.y | 18 +++++++++++++- 9 files changed, 102 insertions(+), 9 deletions(-)
tools/perf/builtin-record.c +5 -2
@@ -31,6 +31,7 @@#include "util/auxtrace.h" #include "util/parse-branch-options.h" #include "util/parse-regs-options.h" +#include "util/bpf-loader.h" #include <unistd.h> #include <sched.h>
@@ -1132,13 +1133,13 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)if (!rec->itr) { rec->itr =auxtrace_record__init (rec->evlist, &err);if (err) -return err; + goto out_bpf_clear; } err =auxtrace_parse_snapshot_options (rec->itr, &rec->opts, rec->opts.auxtrace_snapshot_opts);if (err) -return err; + goto out_bpf_clear; err = -ENOMEM ;
@@ -1201,6 +1202,8 @@ out_symbol_exit:perf_evlist__delete (rec->evlist);symbol__exit ();auxtrace_record__free (rec->itr); +out_bpf_clear: +bpf__clear ();return err; }
tools/perf/builtin-stat.c +6 -2
@@ -59,6 +59,7 @@#include "util/thread.h" #include "util/thread_map.h" #include "util/counts.h" +#include "util/bpf-loader.h" #include <stdlib.h> #include <sys/prctl.h>
@@ -1224,7 +1225,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) output =fopen (output_name, mode);if (!output) {perror ("failed to create output file" ); -return -1 ; + status =-1 ; + goto out; }clock_gettime (CLOCK_REALTIME , &tm);fprintf (output,"# started on %s\n" ,ctime (&tm.tv_sec));
@@ -1233,7 +1235,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) output =fdopen (output_fd, mode);if (!output) {perror ("Failed opening logfd" ); -return -errno; + status = -errno; + goto out; } }
@@ -1366,5 +1369,6 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)perf_evlist__free_stats (evsel_list); out:perf_evlist__delete (evsel_list); +bpf__clear ();return status; }
tools/perf/builtin-top.c +7 -3
@@ -41,6 +41,7 @@#include "util/sort.h" #include "util/intlist.h" #include "util/parse-branch-options.h" +#include "util/bpf-loader.h" #include "arch/common.h" #include "util/debug.h"
@@ -1270,8 +1271,10 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) symbol_conf.priv_size =sizeof (struct annotation ); symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name ==NULL ); -if (symbol__init (NULL ) <0 ) -return -1 ; +if (symbol__init (NULL ) <0 ) { + status =-1 ; + goto out_bpf_clear; + }sort__setup_elide (stdout);
@@ -1289,6 +1292,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) out_delete_evlist:perf_evlist__delete (top.evlist); - +out_bpf_clear: +bpf__clear ();return status; }
tools/perf/builtin-trace.c +5 -1
@@ -31,6 +31,7 @@#include "util/intlist.h" #include "util/thread_map.h" #include "util/stat.h" +#include "util/bpf-loader.h" #include "trace-event.h" #include "util/parse-events.h"
@@ -3109,6 +3110,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)if (trace.evlist->nr_entries >0 )evlist__set_evsel_handler (trace.evlist, trace__event_handler); +/* trace__record calls cmd_record, which calls bpf__clear() */ if ((argc >=1 ) && (strcmp (argv[0 ],"record" ) ==0 ))return trace__record (&trace, argc-1 , &argv[1 ]);
@@ -3119,7 +3121,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)if (!trace.trace_syscalls && !trace.trace_pgfaults && trace.evlist->nr_entries ==0 /* Was --events used? */ ) {pr_err ("Please specify something to trace.\n" ); -return -1 ; + err =-1 ; + goto out; }if (output_name !=NULL ) {
@@ -3178,5 +3181,6 @@ out_close:if (output_name !=NULL )fclose (trace.output); out: +bpf__clear ();return err; }
tools/perf/util/Build +1 -0
@@ -85,6 +85,7 @@ libperf-$(CONFIG_AUXTRACE) += intel-bts.o libperf-y += parse-branch-options.o libperf-y += parse-regs-options.o +libperf-$(CONFIG_LIBBPF) += bpf-loader.o libperf-$(CONFIG_LIBELF) += symbol-elf.o libperf-$(CONFIG_LIBELF) += probe-file.o libperf-$(CONFIG_LIBELF) += probe-event.o
tools/perf/util/parse-events.c +55 -0
67 lines not on this page · raw message
tools/perf/util/parse-events.h +3 -0
@@ -119,6 +119,9 @@ int parse_events__modifier_group(struct list_head *list, char *event_mod);int parse_events_name (struct list_head *list,char *name);int parse_events_add_tracepoint (struct list_head *list,int *idx,char *sys,char *event); +int parse_events_load_bpf (struct parse_events_evlist *data, +struct list_head *list, +char *bpf_file_name); int parse_events_add_numeric(struct parse_events_evlist *data, struct list_head *list, u32 type, u64 config,
tools/perf/util/parse-events.l +3 -0
@@ -115,6 +115,7 @@ do { \ group [^,{}/]*[{][^}]*[}][^,{}/]* event_pmu [^,{}/]+[/][^/]*[/][^,{}/]* event [^,{}/]+ +bpf_object .*\.(o|bpf) num_dec [0-9]+ num_hex 0x[a-fA-F0-9]+
@@ -159,6 +160,7 @@ modifier_bp [rwx]{1,3} } {event_pmu} | +{bpf_object} | {event} { BEGIN(INITIAL); REWIND(1);
@@ -264,6 +266,7 @@ r{num_raw_hex} { return raw(yyscanner); } {num_hex} { return value(yyscanner, 16); } {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } +{bpf_object} { return str(yyscanner, PE_BPF_OBJECT); } {name} { return pmu_str_check(yyscanner); } "/" { BEGIN(config); return '/'; } - { return '-'; }
tools/perf/util/parse-events.y +17 -1
@@ -42,6 +42,7 @@ static inc_group_count(struct list_head *list, %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM %token PE_EVENT_NAME %token PE_NAME +%token PE_BPF_OBJECT %token PE_MODIFIER_EVENT PE_MODIFIER_BP %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
@@ -53,6 +54,7 @@ static inc_group_count(struct list_head *list, %type <num> PE_RAW %type <num> PE_TERM %type <str> PE_NAME +%type <str> PE_BPF_OBJECT %type <str> PE_NAME_CACHE_TYPE %type <str> PE_NAME_CACHE_OP_RESULT %type <str> PE_MODIFIER_EVENT
@@ -69,6 +71,7 @@ static inc_group_count(struct list_head *list, %type <head> event_legacy_tracepoint %type <head> event_legacy_numeric %type <head> event_legacy_raw +%type <head> event_bpf_file %type <head> event_def %type <head> event_mod %type <head> event_name
@@ -198,7 +201,8 @@ event_def: event_pmu | event_legacy_mem | event_legacy_tracepoint sep_dc | event_legacy_numeric sep_dc | - event_legacy_raw sep_dc + event_legacy_raw sep_dc | + event_bpf_file event_pmu: PE_NAME '/' event_config '/'
@@ -420,6 +424,18 @@ PE_RAW $$ = list; } +event_bpf_file: +PE_BPF_OBJECT +{ + struct parse_events_evlist *data = _data; + struct list_head *list; + + ALLOC_LIST(list); + ABORT_ON(parse_events_load_bpf(data, list, $1)); + $$ = list; +} + + start_terms: event_config { struct parse_events_terms *data = _data;
Signature · 1 line
2.1.0
PATCH 5/27 perf record, bpf: Parse and create probe points for BPF programs
In reply to Wang NanThis patch introduces bpf__{un,}probe() functions to enable callers to create kprobe points based on section names of BPF programs. It parses the section names of each eBPF program and creates corresponding 'struct perf_probe_event' structures. The parse_perf_probe_command() function is used to do the main parsing work.
Parsing result is stored into an array to satisify {convert,apply}_perf_probe_events(). It accepts an array of 'struct perf_probe_event' and do all the work in one call.
Define PERF_BPF_PROBE_GROUP as "perf_bpf_probe", which will be used as the group name of all eBPF probing points.
probe_conf.max_probes is set to MAX_PROBES to support glob matching.
Before ending of bpf__probe(), data in each 'struct perf_probe_event' is cleaned. Things will be changed by following patches because they need 'struct probe_trace_event' in them,
[Merged by two patches
wangnan: Utilize new perf probe API {convert,apply,cleanup}_perf_probe_events()
]
--- tools/perf/builtin-record.c | 19 +++++- tools/perf/util/bpf-loader.c | 149 +++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 13 ++++ 3 files changed, 180 insertions(+), 1 deletion(-)
tools/perf/builtin-record.c +18 -1
@@ -1141,7 +1141,23 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)if (err) goto out_bpf_clear; - err = -ENOMEM ; +/* +* bpf__probe must be called before symbol__init() because we +* need init_symbol_maps. If called after symbol__init, +* symbol_conf.sort_by_name won't take effect. +* +* bpf__unprobe() is safe even if bpf__probe() failed, and it +* also calls symbol__init. Therefore, goto out_symbol_exit +* is safe when probe failed. +*/ + err =bpf__probe (); +if (err) { +bpf__strerror_probe (err, errbuf,sizeof (errbuf)); + +pr_err ("Probing at events in BPF object failed.\n" ); +pr_err ("\t%s\n" , errbuf); + goto out_symbol_exit; + }symbol__init (NULL );
@@ -1202,6 +1218,7 @@ out_symbol_exit:perf_evlist__delete (rec->evlist);symbol__exit ();auxtrace_record__free (rec->itr); +bpf__unprobe (); out_bpf_clear:bpf__clear ();return err;
tools/perf/util/bpf-loader.c +149 -0
170 lines not on this page · raw message
tools/perf/util/bpf-loader.h +13 -0
@@ -9,10 +9,15 @@#include <string.h> #include "debug.h" +#define PERF_BPF_PROBE_GROUP "perf_bpf_probe" +#ifdef HAVE_LIBBPF_SUPPORT int bpf__prepare_load (const char *filename);int bpf__strerror_prepare_load (const char *filename,int err,char *buf,size_t size); +int bpf__probe (void ); +int bpf__unprobe (void ); +int bpf__strerror_probe (int err,char *buf,size_t size);void bpf__clear (void );#else
@@ -22,6 +27,8 @@ static inline int bpf__prepare_load(const char *filename __maybe_unused)return -1 ; } +static inline int bpf__probe (void ) {return 0 ; } +static inline int bpf__unprobe (void ) {return 0 ; }static inline void bpf__clear (void ) { } static inline int
@@ -43,5 +50,11 @@ bpf__strerror_prepare_load(const char *filename __maybe_unused, {return __bpf_strerror (buf, size); } + +static inline int bpf__strerror_probe (int err__maybe_unused , +char *buf,size_t size) +{ +return __bpf_strerror (buf, size); +}#endif #endif
Signature · 1 line
2.1.0
Re: [PATCH 05/27] perf record, bpf: Parse and create probe points for BPF programs
Em Sun, Sep 06, 2015 at 07:13:21AM +0000, Wang Nan escreveu:
Quoted 2 lines
This patch introduces bpf__{un,}probe() functions to enable callers to create kprobe points based on section names of BPF programs. It parses
Ok, so now I see that when we do:
perf record --event bpf_prog.o usleep 1
We are potentially inserting multiple events, one for each eBPF section found in bpf_prog.o, right?
I.e. multiple evsels, so, when parsing, we should create the kprobes and from there then create evsels and insert in the normal list that would eventually get spliced to the evlist being processed, I think.
So, and reading that comment on 4/27, we need to allow that to happen at parse_events() time, i.e. avoid adding a dummy evsel that would then, later, be "expanded" into potentially multiple non-dummy evsels.
I put the first 3 patches, with some adjustments, in my perf/ebpf branch, will try to do the above, i.e. do away with that dummy, allow parsing the bpf_prog.o sections at parse_events() time.
- Arnaldo
Quoted 307 lines
the section names of each eBPF program and creates corresponding 'struct
perf_probe_event' structures. Theparse_perf_probe_command()function is used to do the main parsing work.Parsing result is stored into an array to satisify {convert,apply}_perf_probe_events(). It accepts an array of 'struct
perf_probe_event' and do all the work in one call.Define
PERF_BPF_PROBE_GROUPas "perf_bpf_probe", which will be used as the group name of all eBPF probing points.probe_conf.max_probes is set to
MAX_PROBESto support glob matching.Before ending of
bpf__probe(), data in each 'structperf_probe_event' is cleaned. Things will be changed by following patches because they need 'structprobe_trace_event' in them,Signed-off-by Wang Nan <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Brendan Gregg <[email protected]>Cc Daniel Borkmann <[email protected]>Cc David Ahern <[email protected]>Cc He Kuang <[email protected]>Cc Jiri Olsa <[email protected]>Cc Kaixu Xia <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Zefan Li <[email protected]>[Merged by two patches
wangnan: Utilize new perf probe API {convert,apply,cleanup}_perf_probe_events()
]Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/builtin-record.c | 19 +++++- tools/perf/util/bpf-loader.c | 149 +++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 13 ++++ 3 files changed, 180 insertions(+), 1 deletion(-)tools/perf/builtin-record.c +18
-1@@ -1141,7 +1141,23 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)if (err) goto out_bpf_clear; - err = -ENOMEM ; +/* +* bpf__probe must be called before symbol__init() because we +* need init_symbol_maps. If called after symbol__init, +* symbol_conf.sort_by_name won't take effect. +* +* bpf__unprobe() is safe even if bpf__probe() failed, and it +* also calls symbol__init. Therefore, goto out_symbol_exit +* is safe when probe failed. +*/ + err =bpf__probe (); +if (err) { +bpf__strerror_probe (err, errbuf,sizeof (errbuf)); + +pr_err ("Probing at events in BPF object failed.\n" ); +pr_err ("\t%s\n" , errbuf); + goto out_symbol_exit; + }symbol__init (NULL );@@ -1202,6 +1218,7 @@ out_symbol_exit:perf_evlist__delete (rec->evlist);symbol__exit ();auxtrace_record__free (rec->itr); +bpf__unprobe (); out_bpf_clear:bpf__clear ();return err;tools/perf/util/bpf-loader.c +149
-0@@ -9,6 +9,8 @@#include "perf.h" #include "debug.h" #include "bpf-loader.h" +#include "probe-event.h" +#include "probe-finder.h" #define DEFINE_PRINT_FN (name, level) \ static int libbpf_##name(const char *fmt, ...) \@@ -28,6 +30,58 @@ DEFINE_PRINT_FN(debug, 1)static bool libbpf_initialized; +static int +config_bpf_program (struct bpf_program *prog,struct perf_probe_event *pev) +{ +const char *config_str; +int err; + + config_str =bpf_program__title (prog, false); +if (!config_str) { +pr_debug ("bpf: unable to get title for program\n" ); +return -EINVAL ; + } + +pr_debug ("bpf: config program '%s'\n" , config_str); + err =parse_perf_probe_command (config_str, pev); +if (err <0 ) { +pr_debug ("bpf: '%s' is not a valid config string\n" , + config_str); +/* parse failed, don't need clear pev. */ +return -EINVAL ; + } + +if (pev->group &&strcmp (pev->group,PERF_BPF_PROBE_GROUP )) { +pr_debug ("bpf: '%s': group for event is set and not '%s'.\n" , + config_str,PERF_BPF_PROBE_GROUP ); + err = -EINVAL ; + goto errout; + }else if (!pev->group) + pev->group =strdup (PERF_BPF_PROBE_GROUP ); + +if (!pev->group) { +pr_debug ("bpf: strdup failed\n" ); + err = -ENOMEM ; + goto errout; + } + +if (!pev->event) { +pr_debug ("bpf: '%s': event name is missing\n" , + config_str); + err = -EINVAL ; + goto errout; + } + +pr_debug ("bpf: config '%s' is ok\n" , config_str); + +return 0 ; + +errout: +if (pev) +clear_perf_probe_event (pev); +return err; +} +int bpf__prepare_load (const char *filename) {struct bpf_object *obj;@@ -59,6 +113,90 @@ void bpf__clear(void)bpf_object__close (obj); } +static bool is_probed; + +int bpf__unprobe (void ) +{ +struct strfilter *delfilter; +int ret; + +if (!is_probed) +return 0 ; + + delfilter =strfilter__new (PERF_BPF_PROBE_GROUP ":*" ,NULL ); +if (!delfilter) { +pr_debug ("Failed to create delfilter when unprobing\n" ); +return -ENOMEM ; + } + + ret =del_perf_probe_events (delfilter); +strfilter__delete (delfilter); +if (ret <0 && is_probed) +pr_debug ("Error: failed to delete events: %s\n" , +strerror (-ret)); +else + is_probed = false; +return ret <0 ? ret :0 ; +} + +int bpf__probe (void ) +{ +int err, nr_events =0 ; +struct bpf_object *obj, *tmp; +struct bpf_program *prog; +struct perf_probe_event *pevs; + + pevs =calloc (MAX_PROBES ,sizeof (pevs[0 ])); +if (!pevs) +return -ENOMEM ; + +bpf_object__for_each_safe (obj, tmp) { +bpf_object__for_each_program (prog, obj) { + err =config_bpf_program (prog, &pevs[nr_events++]); +if (err <0 ) + goto out; + +if (nr_events >=MAX_PROBES ) { +pr_debug ("Too many (more than %d) events\n" , +MAX_PROBES ); + err = -ERANGE ; + goto out; + }; + } + } + +if (!nr_events) { +/* +* Don't call following code to prevent perf report failure +* init_symbol_maps can fail when perf is started by non-root +* user, which prevent non-root user track normal events even +* without using BPF, because bpf__probe() is called by +* 'perf record' unconditionally. +*/ + err =0 ; + goto out; + } + + probe_conf.max_probes =MAX_PROBES ; +/* Let convert_perf_probe_events generates probe_trace_event (tevs) */ + err =convert_perf_probe_events (pevs, nr_events); +if (err <0 ) { +pr_debug ("bpf_probe: failed to convert perf probe events" ); + goto out; + } + + err =apply_perf_probe_events (pevs, nr_events); +if (err <0 ) +pr_debug ("bpf probe: failed to probe events\n" ); +else + is_probed = true; +out_cleanup: +cleanup_perf_probe_events (pevs, nr_events); +out: +free (pevs); +return err <0 ? err :0 ; +} +#define bpf__strerror_head (err, buf, size) \ char sbuf[STRERR_BUFSIZE], *emsg;\ if (!size)\@@ -90,3 +228,14 @@ int bpf__strerror_prepare_load(const char *filename, int err,bpf__strerror_end (buf, size);return 0 ; } + +int bpf__strerror_probe (int err,char *buf,size_t size) +{ +bpf__strerror_head (err, buf, size); +bpf__strerror_entry (ERANGE ,"Too many (more than %d) events" , +MAX_PROBES ); +bpf__strerror_entry (ENOENT ,"Selected kprobe point doesn't exist." ); +bpf__strerror_entry (EEXIST ,"Selected kprobe point already exist, try perf probe -d '*'." ); +bpf__strerror_end (buf, size); +return 0 ; +}tools/perf/util/bpf-loader.h +13
-0@@ -9,10 +9,15 @@#include <string.h> #include "debug.h" +#define PERF_BPF_PROBE_GROUP "perf_bpf_probe" +#ifdef HAVE_LIBBPF_SUPPORT int bpf__prepare_load (const char *filename);int bpf__strerror_prepare_load (const char *filename,int err,char *buf,size_t size); +int bpf__probe (void ); +int bpf__unprobe (void ); +int bpf__strerror_probe (int err,char *buf,size_t size);void bpf__clear (void );#else @@ -22,6 +27,8 @@ static inline int bpf__prepare_load(const char *filename __maybe_unused)return -1 ; } +static inline int bpf__probe (void ) {return 0 ; } +static inline int bpf__unprobe (void ) {return 0 ; }static inline void bpf__clear (void ) { } static inline int@@ -43,5 +50,11 @@ bpf__strerror_prepare_load(const char *filename __maybe_unused, {return __bpf_strerror (buf, size); } + +static inline int bpf__strerror_probe (int err__maybe_unused , +char *buf,size_t size) +{ +return __bpf_strerror (buf, size); +}#endif #endif Signature · 7 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 05/27] perf record, bpf: Parse and create probe points for BPF programs
Quoted 9 lines · Arnaldo Carvalho de Melo
Em Sun, Sep 06, 2015 at 07:13:21AM +0000, Wang Nan escreveu:
Quoted 2 lines
This patch introduces bpf__{un,}probe() functions to enable callers to create kprobe points based on section names of BPF programs. It parses
Ok, so now I see that when we do:
perf record --event bpf_prog.o usleep 1We are potentially inserting multiple events, one for each eBPF section found in bpf_prog.o, right?
Yes.
Quoted 11 lines
I.e. multiple evsels, so, when parsing, we should create the kprobes and from there then create evsels and insert in the normal list that would eventually get spliced to the evlist being processed, I think.
So, and reading that comment on 4/27, we need to allow that to happen at
parse_events()time, i.e. avoid adding a dummy evsel that would then, later, be "expanded" into potentially multiple non-dummy evsels.I put the first 3 patches, with some adjustments, in my perf/ebpf branch, will try to do the above, i.e. do away with that dummy, allow parsing the bpf_prog.o sections at
parse_events()time.
Then I suggest a small interface modification in libbpf to return 'struct bpf_object *', then after loading we can iterator on each program in that object, creat kprobe points then made evsels. We need to call convert_perf_probe_events() multiple times for each object. Since Namhyung updates the probing interface, I think it becomes possible.
I'm glad to see you will working on this problem. If you have other ugrent business to do, I think I can also start this work from Sept. 21 and will have 3 days before my vacation.
Thank you.
Quoted 309 lines
- Arnaldo
Quoted 307 lines
the section names of each eBPF program and creates corresponding 'struct
perf_probe_event' structures. Theparse_perf_probe_command()function is used to do the main parsing work.Parsing result is stored into an array to satisify {convert,apply}_perf_probe_events(). It accepts an array of 'struct
perf_probe_event' and do all the work in one call.Define
PERF_BPF_PROBE_GROUPas "perf_bpf_probe", which will be used as the group name of all eBPF probing points.probe_conf.max_probes is set to
MAX_PROBESto support glob matching.Before ending of
bpf__probe(), data in each 'structperf_probe_event' is cleaned. Things will be changed by following patches because they need 'structprobe_trace_event' in them,Signed-off-by Wang Nan <[email protected]>Cc Alexei Starovoitov <[email protected]>Cc Brendan Gregg <[email protected]>Cc Daniel Borkmann <[email protected]>Cc David Ahern <[email protected]>Cc He Kuang <[email protected]>Cc Jiri Olsa <[email protected]>Cc Kaixu Xia <[email protected]>Cc Masami Hiramatsu <[email protected]>Cc Namhyung Kim <[email protected]>Cc Paul Mackerras <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Zefan Li <[email protected]>[Merged by two patches
wangnan: Utilize new perf probe API {convert,apply,cleanup}_perf_probe_events()
]Signed-off-by Arnaldo Carvalho de Melo <[email protected]>--- tools/perf/builtin-record.c | 19 +++++- tools/perf/util/bpf-loader.c | 149 +++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 13 ++++ 3 files changed, 180 insertions(+), 1 deletion(-)tools/perf/builtin-record.c +18
-1@@ -1141,7 +1141,23 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)if (err) goto out_bpf_clear; - err = -ENOMEM ; +/* +* bpf__probe must be called before symbol__init() because we +* need init_symbol_maps. If called after symbol__init, +* symbol_conf.sort_by_name won't take effect. +* +* bpf__unprobe() is safe even if bpf__probe() failed, and it +* also calls symbol__init. Therefore, goto out_symbol_exit +* is safe when probe failed. +*/ + err =bpf__probe (); +if (err) { +bpf__strerror_probe (err, errbuf,sizeof (errbuf)); + +pr_err ("Probing at events in BPF object failed.\n" ); +pr_err ("\t%s\n" , errbuf); + goto out_symbol_exit; + }symbol__init (NULL );@@ -1202,6 +1218,7 @@ out_symbol_exit:perf_evlist__delete (rec->evlist);symbol__exit ();auxtrace_record__free (rec->itr); +bpf__unprobe (); out_bpf_clear:bpf__clear ();return err;tools/perf/util/bpf-loader.c +149
-0@@ -9,6 +9,8 @@#include "perf.h" #include "debug.h" #include "bpf-loader.h" +#include "probe-event.h" +#include "probe-finder.h" #define DEFINE_PRINT_FN (name, level) \ static int libbpf_##name(const char *fmt, ...) \@@ -28,6 +30,58 @@ DEFINE_PRINT_FN(debug, 1)static bool libbpf_initialized; +static int +config_bpf_program (struct bpf_program *prog,struct perf_probe_event *pev) +{ +const char *config_str; +int err; + + config_str =bpf_program__title (prog, false); +if (!config_str) { +pr_debug ("bpf: unable to get title for program\n" ); +return -EINVAL ; + } + +pr_debug ("bpf: config program '%s'\n" , config_str); + err =parse_perf_probe_command (config_str, pev); +if (err <0 ) { +pr_debug ("bpf: '%s' is not a valid config string\n" , + config_str); +/* parse failed, don't need clear pev. */ +return -EINVAL ; + } + +if (pev->group &&strcmp (pev->group,PERF_BPF_PROBE_GROUP )) { +pr_debug ("bpf: '%s': group for event is set and not '%s'.\n" , + config_str,PERF_BPF_PROBE_GROUP ); + err = -EINVAL ; + goto errout; + }else if (!pev->group) + pev->group =strdup (PERF_BPF_PROBE_GROUP ); + +if (!pev->group) { +pr_debug ("bpf: strdup failed\n" ); + err = -ENOMEM ; + goto errout; + } + +if (!pev->event) { +pr_debug ("bpf: '%s': event name is missing\n" , + config_str); + err = -EINVAL ; + goto errout; + } + +pr_debug ("bpf: config '%s' is ok\n" , config_str); + +return 0 ; + +errout: +if (pev) +clear_perf_probe_event (pev); +return err; +} +int bpf__prepare_load (const char *filename) {struct bpf_object *obj;@@ -59,6 +113,90 @@ void bpf__clear(void)bpf_object__close (obj); } +static bool is_probed; + +int bpf__unprobe (void ) +{ +struct strfilter *delfilter; +int ret; + +if (!is_probed) +return 0 ; + + delfilter =strfilter__new (PERF_BPF_PROBE_GROUP ":*" ,NULL ); +if (!delfilter) { +pr_debug ("Failed to create delfilter when unprobing\n" ); +return -ENOMEM ; + } + + ret =del_perf_probe_events (delfilter); +strfilter__delete (delfilter); +if (ret <0 && is_probed) +pr_debug ("Error: failed to delete events: %s\n" , +strerror (-ret)); +else + is_probed = false; +return ret <0 ? ret :0 ; +} + +int bpf__probe (void ) +{ +int err, nr_events =0 ; +struct bpf_object *obj, *tmp; +struct bpf_program *prog; +struct perf_probe_event *pevs; + + pevs =calloc (MAX_PROBES ,sizeof (pevs[0 ])); +if (!pevs) +return -ENOMEM ; + +bpf_object__for_each_safe (obj, tmp) { +bpf_object__for_each_program (prog, obj) { + err =config_bpf_program (prog, &pevs[nr_events++]); +if (err <0 ) + goto out; + +if (nr_events >=MAX_PROBES ) { +pr_debug ("Too many (more than %d) events\n" , +MAX_PROBES ); + err = -ERANGE ; + goto out; + }; + } + } + +if (!nr_events) { +/* +* Don't call following code to prevent perf report failure +* init_symbol_maps can fail when perf is started by non-root +* user, which prevent non-root user track normal events even +* without using BPF, because bpf__probe() is called by +* 'perf record' unconditionally. +*/ + err =0 ; + goto out; + } + + probe_conf.max_probes =MAX_PROBES ; +/* Let convert_perf_probe_events generates probe_trace_event (tevs) */ + err =convert_perf_probe_events (pevs, nr_events); +if (err <0 ) { +pr_debug ("bpf_probe: failed to convert perf probe events" ); + goto out; + } + + err =apply_perf_probe_events (pevs, nr_events); +if (err <0 ) +pr_debug ("bpf probe: failed to probe events\n" ); +else + is_probed = true; +out_cleanup: +cleanup_perf_probe_events (pevs, nr_events); +out: +free (pevs); +return err <0 ? err :0 ; +} +#define bpf__strerror_head (err, buf, size) \ char sbuf[STRERR_BUFSIZE], *emsg;\ if (!size)\@@ -90,3 +228,14 @@ int bpf__strerror_prepare_load(const char *filename, int err,bpf__strerror_end (buf, size);return 0 ; } + +int bpf__strerror_probe (int err,char *buf,size_t size) +{ +bpf__strerror_head (err, buf, size); +bpf__strerror_entry (ERANGE ,"Too many (more than %d) events" , +MAX_PROBES ); +bpf__strerror_entry (ENOENT ,"Selected kprobe point doesn't exist." ); +bpf__strerror_entry (EEXIST ,"Selected kprobe point already exist, try perf probe -d '*'." ); +bpf__strerror_end (buf, size); +return 0 ; +}tools/perf/util/bpf-loader.h +13
-0@@ -9,10 +9,15 @@#include <string.h> #include "debug.h" +#define PERF_BPF_PROBE_GROUP "perf_bpf_probe" +#ifdef HAVE_LIBBPF_SUPPORT int bpf__prepare_load (const char *filename);int bpf__strerror_prepare_load (const char *filename,int err,char *buf,size_t size); +int bpf__probe (void ); +int bpf__unprobe (void ); +int bpf__strerror_probe (int err,char *buf,size_t size);void bpf__clear (void );#else @@ -22,6 +27,8 @@ static inline int bpf__prepare_load(const char *filename __maybe_unused)return -1 ; } +static inline int bpf__probe (void ) {return 0 ; } +static inline int bpf__unprobe (void ) {return 0 ; }static inline void bpf__clear (void ) { } static inline int@@ -43,5 +50,11 @@ bpf__strerror_prepare_load(const char *filename __maybe_unused, {return __bpf_strerror (buf, size); } + +static inline int bpf__strerror_probe (int err__maybe_unused , +char *buf,size_t size) +{ +return __bpf_strerror (buf, size); +}#endif #endif Signature · 7 lines
2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
PATCH 6/27 perf bpf: Collect 'struct perf_probe_event' for bpf_program
In reply to Wang NanThis patch utilizes bpf_program__set_private(), binding perf_probe_event with bpf program by private field.
Saving those information so 'perf record' knows which kprobe point a program should be attached.
Since data in 'struct perf_probe_event' is build by 2 stages, pev_ready is used to mark whether the information (especially tevs) in 'struct perf_probe_event' is valid or not. It is false at first, and set to true by sync_bpf_program_pev(), which copies all pointers in original pev into a program specific memory region. sync_bpf_program_pev() is called after apply_perf_probe_events() to make sure ready of data.
Remove code which cleans 'struct perf_probe_event' after bpf__probe() because pointers in pevs are copied to program's private field, calling cleanup_perf_probe_events() becomes unsafe.
[Splitted from a larger patch
wangnan: Utilize new perf probe API {convert,apply,cleanup}_perf_probe_events()
]
--- tools/perf/util/bpf-loader.c | 110 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 4 deletions(-)
tools/perf/util/bpf-loader.c +106 -4
@@ -30,9 +30,47 @@ DEFINE_PRINT_FN(debug, 1)static bool libbpf_initialized; +struct bpf_prog_priv { +/* +* If pev_ready is false, ppev pointes to a local memory which +* is only valid inside bpf__probe(). +* pev is valid only when pev_ready. +*/ +bool pev_ready; +union { +struct perf_probe_event *ppev; +struct perf_probe_event pev; + }; +}; + +static void +bpf_prog_priv__clear (struct bpf_program *prog__maybe_unused , +void *_priv) +{ +struct bpf_prog_priv *priv = _priv; + +/* check if pev is initialized */ +if (priv && priv->pev_ready) { +int i; + +/* +* Similar code with cleanup_perf_probe_events, but without +* exit_symbol_maps(). +*/ +for (i =0 ; i < priv->pev.ntevs; i++) +clear_probe_trace_event (&priv->pev.tevs[i]); +zfree (&priv->pev.tevs); + priv->pev.ntevs =0 ; + +clear_perf_probe_event (&priv->pev); + } +free (priv); +} +static int config_bpf_program (struct bpf_program *prog,struct perf_probe_event *pev) { +struct bpf_prog_priv *priv =NULL ;const char *config_str;int err;
@@ -74,14 +112,58 @@ config_bpf_program(struct bpf_program *prog, struct perf_probe_event *pev)pr_debug ("bpf: config '%s' is ok\n" , config_str); + priv =calloc (1 ,sizeof (*priv)); +if (!priv) { +pr_debug ("bpf: failed to alloc memory\n" ); + err = -ENOMEM ; + goto errout; + } + +/* +* At this very early stage, tevs inside pev are not ready. +* It becomes usable after add_perf_probe_events() is called. +* set pev_ready to false so further access read priv->ppev +* only. +*/ + priv->pev_ready = false; + priv->ppev = pev; + + err =bpf_program__set_private (prog, priv, + bpf_prog_priv__clear); +if (err) { +pr_debug ("bpf: set program private failed\n" ); + err = -ENOMEM ; + goto errout; + }return 0 ; errout:if (pev)clear_perf_probe_event (pev); +if (priv) +free (priv);return err; } +static int +sync_bpf_program_pev (struct bpf_program *prog) +{ +int err; +struct bpf_prog_priv *priv; +struct perf_probe_event *ppev; + + err =bpf_program__get_private (prog, (void **)&priv); +if (err || !priv || priv->pev_ready) { +pr_debug ("Internal error: sync_bpf_program_pev\n" ); +return -EINVAL ; + } + + ppev = priv->ppev; +memcpy (&priv->pev, ppev,sizeof (*ppev)); + priv->pev_ready = true; +return 0 ; +} +int bpf__prepare_load (const char *filename) {struct bpf_object *obj;
@@ -186,15 +268,35 @@ int bpf__probe(void) } err =apply_perf_probe_events (pevs, nr_events); -if (err <0 ) +if (err <0 ) {pr_debug ("bpf probe: failed to probe events\n" ); -else + goto out_cleanup; + }else is_probed = true; -out_cleanup: -cleanup_perf_probe_events (pevs, nr_events); + +/* +* After add_perf_probe_events, 'struct perf_probe_event' is ready. +* Until now copying program's priv->pev field and freeing +* the big array allocated before become safe. +*/ +bpf_object__for_each_safe (obj, tmp) { +bpf_object__for_each_program (prog, obj) { + err =sync_bpf_program_pev (prog); +if (err) + goto out; + } + } out: +/* +* Don't call cleanup_perf_probe_events() for entries of pevs: +* they are used by prog's private field. +*/ free (pevs);return err <0 ? err :0 ; + +out_cleanup: +cleanup_perf_probe_events (pevs, nr_events); + goto out; }#define bpf__strerror_head (err, buf, size) \
Signature · 1 line
2.1.0
PATCH 7/27 perf record: Load all eBPF object into kernel
In reply to Wang NanThis patch utilizes bpf_object__load() provided by libbpf to load all objects into kernel.
--- tools/perf/builtin-record.c | 15 +++++++++++++++ tools/perf/util/bpf-loader.c | 28 ++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 10 ++++++++++ 3 files changed, 53 insertions(+)
tools/perf/builtin-record.c +15 -0
@@ -1159,6 +1159,21 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) goto out_symbol_exit; } +/* +* bpf__probe() also calls symbol__init() if there are probe +* events in bpf objects, so calling symbol_exit when failure +* is safe. If there is no probe event, bpf__load() always +* success. +*/ + err =bpf__load (); +if (err) { +pr_err ("Loading BPF programs failed:\n" ); + +bpf__strerror_load (err, errbuf,sizeof (errbuf)); +pr_err ("\t%s\n" , errbuf); + goto out_symbol_exit; + } +symbol__init (NULL );if (symbol_conf.kptr_restrict)
tools/perf/util/bpf-loader.c +28 -0
@@ -299,6 +299,25 @@ out_cleanup: goto out; } +int bpf__load (void ) +{ +struct bpf_object *obj, *tmp; +int err =0 ; + +bpf_object__for_each_safe (obj, tmp) { + err =bpf_object__load (obj); +if (err) { +pr_debug ("bpf: load objects failed\n" ); + goto errout; + } + } +return 0 ; +errout: +bpf_object__for_each_safe (obj, tmp) +bpf_object__unload (obj); +return err; +} +#define bpf__strerror_head (err, buf, size) \ char sbuf[STRERR_BUFSIZE], *emsg;\ if (!size)\
@@ -341,3 +360,12 @@ int bpf__strerror_probe(int err, char *buf, size_t size)bpf__strerror_end (buf, size);return 0 ; } + +int bpf__strerror_load (int err,char *buf,size_t size) +{ +bpf__strerror_head (err, buf, size); +bpf__strerror_entry (EINVAL ,"%s: add -v to see detail. Run a CONFIG_BPF_SYSCALL kernel?" , + emsg) +bpf__strerror_end (buf, size); +return 0 ; +}
tools/perf/util/bpf-loader.h +10 -0
@@ -19,6 +19,9 @@ int bpf__probe(void);int bpf__unprobe (void );int bpf__strerror_probe (int err,char *buf,size_t size); +int bpf__load (void ); +int bpf__strerror_load (int err,char *buf,size_t size); +void bpf__clear (void );#else static inline int bpf__prepare_load (const char *filename__maybe_unused )
@@ -29,6 +32,7 @@ static inline int bpf__prepare_load(const char *filename __maybe_unused)static inline int bpf__probe (void ) {return 0 ; }static inline int bpf__unprobe (void ) {return 0 ; } +static inline int bpf__load (void ) {return 0 ; }static inline void bpf__clear (void ) { } static inline int
@@ -56,5 +60,11 @@ static inline int bpf__strerror_probe(int err __maybe_unused, {return __bpf_strerror (buf, size); } + +static inline int bpf__strerror_load (int err__maybe_unused , +char *buf,size_t size) +{ +return __bpf_strerror (buf, size); +}#endif #endif
Signature · 1 line
2.1.0
PATCH 8/27 perf tools: Add bpf_fd field to evsel and config it
In reply to Wang NanThis patch adds a bpf_fd field to 'struct evsel' then introduces method to config it. In bpf-loader, a bpf__foreach_tev() function is added, which calls the callback function for each 'struct probe_trace_event' events for each bpf program with their file descriptors. In evlist.c, perf_evlist__add_bpf() is introduced to add all bpf events into evlist. The event names are found from probe_trace_event structure. 'perf record' calls perf_evlist__add_bpf().
Since bpf-loader.c will not be built if libbpf is turned off, an empty bpf__foreach_tev() is defined in bpf-loader.h to avoid compiling error.
This patch iterates over 'struct probe_trace_event' instead of 'struct probe_trace_event' during the loop for further patches, which will generate multiple instances form one BPF program and install then onto different 'struct probe_trace_event'.
--- tools/perf/builtin-record.c | 6 ++++++ tools/perf/util/bpf-loader.c | 41 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 13 +++++++++++++ tools/perf/util/evlist.c | 41 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/evlist.h | 1 + tools/perf/util/evsel.c | 1 + tools/perf/util/evsel.h | 1 + 7 files changed, 104 insertions(+)
tools/perf/builtin-record.c +6 -0
@@ -1174,6 +1174,12 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) goto out_symbol_exit; } + err =perf_evlist__add_bpf (rec->evlist); +if (err <0 ) { +pr_err ("Failed to add events from BPF object(s)\n" ); + goto out_symbol_exit; + } +symbol__init (NULL );if (symbol_conf.kptr_restrict)
tools/perf/util/bpf-loader.c +41 -0
47 lines not on this page · raw message
tools/perf/util/bpf-loader.h +13 -0
@@ -7,10 +7,14 @@#include <linux/compiler.h> #include <string.h> +#include "probe-event.h" #include "debug.h" #define PERF_BPF_PROBE_GROUP "perf_bpf_probe" +typedef int (*bpf_prog_iter_callback_t )(struct probe_trace_event *tev, +int fd,void *arg); +#ifdef HAVE_LIBBPF_SUPPORT int bpf__prepare_load (const char *filename); int bpf__strerror_prepare_load(const char *filename, int err,
@@ -23,6 +27,8 @@ int bpf__load(void);int bpf__strerror_load (int err,char *buf,size_t size);void bpf__clear (void ); + +int bpf__foreach_tev (bpf_prog_iter_callback_t func,void *arg);#else static inline int bpf__prepare_load (const char *filename__maybe_unused ) {
@@ -36,6 +42,13 @@ static inline int bpf__load(void) { return 0; }static inline void bpf__clear (void ) { }static inline int +bpf__foreach_tev (bpf_prog_iter_callback_t func__maybe_unused , +void *arg__maybe_unused ) +{ +return 0 ; +} + +static inline int __bpf_strerror (char *buf,size_t size) {if (!size)
tools/perf/util/evlist.c +41 -0
53 lines not on this page · raw message
tools/perf/util/evlist.h +1 -0
@@ -73,6 +73,7 @@ void perf_evlist__delete(struct perf_evlist *evlist);void perf_evlist__add (struct perf_evlist *evlist,struct perf_evsel *entry);int perf_evlist__add_default (struct perf_evlist *evlist); +int perf_evlist__add_bpf (struct perf_evlist *evlist);int __perf_evlist__add_default_attrs (struct perf_evlist *evlist,struct perf_event_attr *attrs,size_t nr_attrs);
tools/perf/util/evsel.c +1 -0
@@ -207,6 +207,7 @@ void perf_evsel__init(struct perf_evsel *evsel, evsel->unit ="" ; evsel->scale =1.0 ; evsel->evlist =NULL ; + evsel->bpf_fd =-1 ;INIT_LIST_HEAD (&evsel->node);INIT_LIST_HEAD (&evsel->config_terms); perf_evsel__object.init (evsel);
tools/perf/util/evsel.h +1 -0
@@ -119,6 +119,7 @@ struct perf_evsel {char *group_name;bool cmdline_group_boundary;struct list_head config_terms; +int bpf_fd; };union u64_swap {
Signature · 1 line
2.1.0
PATCH 9/27 perf tools: Attach eBPF program to perf event
In reply to Wang NanThis is the final patch which makes basic BPF filter work. After applying this patch, users are allowed to use BPF filter like:
# perf record --event ./hello_world.o ls
In this patch PERF_EVENT_IOC_SET_BPF ioctl is used to attach eBPF program to a newly created perf event. The file descriptor of the eBPF program is passed to perf record using previous patches, and stored into evsel->bpf_fd.
It is possible that different perf event are created for one kprobe events for different CPUs. In this case, when trying to call the ioctl, EEXIST will be return. This patch doesn't treat it as an error.
--- tools/perf/util/evsel.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tools/perf/util/evsel.c +16 -0
@@ -1333,6 +1333,22 @@ retry_open: err); goto try_fallback; } + +if (evsel->bpf_fd >=0 ) { +int evt_fd =FD (evsel, cpu, thread); +int bpf_fd = evsel->bpf_fd; + + err =ioctl (evt_fd, +PERF_EVENT_IOC_SET_BPF , + bpf_fd); +if (err && errno !=EEXIST ) { +pr_err ("failed to attach bpf fd %d: %s\n" , + bpf_fd,strerror (errno)); + err = -EINVAL ; + goto out_close; + } + } + set_rlimit =NO_CHANGE ;/*
Signature · 1 line
2.1.0
PATCH 10/27 perf tools: Allow BPF placeholder dummy events to collect --filter options
In reply to Wang NanThis patch improves collection and setting of filters, allows --filter be set to BPF placeholder events (which is a software dummy event).
perf_evsel__is_dummy(), perf_evsel__is_bpf_placeholder() and perf_evsel__can_filter() are introduced for this.
Test result:
# perf record --event dummy --exclude-perf --exclude-perf option should follow a -e tracepoint option
# perf record --event dummy:u --exclude-perf ls --exclude-perf option should follow a -e tracepoint option
# perf record --event test.o --exclude-perf ls Added new event: perf_bpf_probe:func_vfs_write (on vfs_write) ...
# perf record --event dummy.o --exclude-perf ls Added new event: perf_bpf_probe:func_write (on sys_write) ...
--- tools/perf/util/evlist.c | 7 +++++++ tools/perf/util/evsel.c | 32 ++++++++++++++++++++++++++++++++ tools/perf/util/evsel.h | 23 +++++++++++++++++++++++ tools/perf/util/parse-events.c | 4 ++-- 4 files changed, 64 insertions(+), 2 deletions(-)
tools/perf/util/evlist.c +7 -0
@@ -1223,6 +1223,13 @@ int perf_evlist__apply_filters(struct perf_evlist *evlist, struct perf_evsel **econtinue ;/* +* Filters are allowed to be set to dummy event for BPF object +* placeholder. Don't really apply them. +*/ +if (perf_evsel__is_dummy (evsel)) +continue ; + +/* * filters only work for tracepoint event, which doesn't have cpu limit. * So evlist and evsel should always be same. */
tools/perf/util/evsel.c +32 -0
@@ -2344,3 +2344,35 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, err,strerror_r (err, sbuf,sizeof (sbuf)), perf_evsel__name(evsel)); } + +bool perf_evsel__is_bpf_placeholder (struct perf_evsel *evsel) +{ +if (!perf_evsel__is_dummy (evsel)) +return false; +if (!evsel->name) +return false; +/* +* If evsel->name doesn't starts with 'dummy', it must be a BPF +* place holder. +*/ +if (strncmp (evsel->name, perf_evsel__sw_names[PERF_COUNT_SW_DUMMY ], +strlen (perf_evsel__sw_names[PERF_COUNT_SW_DUMMY ]))) +return true; +/* +* Very rare case: evsel->name is 'dummy_crazy.bpf'. +* +* Let's check name suffix. A bpf file should ends with one of: +* '.o', '.c' or '.bpf'. +*/ +#define SUFFIX_CMP (s)\ + strcmp(evsel->name + strlen(evsel->name) - (sizeof(s) - 1), s) + +if (SUFFIX_CMP (".o" ) ==0 ) +return true; +if (SUFFIX_CMP (".c" ) ==0 ) +return true; +if (SUFFIX_CMP (".bpf" ) ==0 ) +return true; +return false; +#undef SUFFIX_CMP +}
tools/perf/util/evsel.h +23 -0
@@ -372,11 +372,34 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err,int perf_evsel__open_strerror (struct perf_evsel *evsel,struct target *target,int err,char *msg,size_t size); +bool perf_evsel__is_bpf_placeholder (struct perf_evsel *evsel); +static inline int perf_evsel__group_idx (struct perf_evsel *evsel) {return evsel->idx - evsel->leader->idx; } +static inline bool perf_evsel__is_dummy (struct perf_evsel *evsel) +{ +if (!evsel) +return false; +if (evsel->attr.type !=PERF_TYPE_SOFTWARE ) +return false; +if (evsel->attr.config !=PERF_COUNT_SW_DUMMY ) +return false; +return true; +} + +static inline int perf_evsel__can_filter (struct perf_evsel *evsel) +{ +if (!evsel) +return false; +if (evsel->attr.type ==PERF_TYPE_TRACEPOINT ) +return true; + +return perf_evsel__is_bpf_placeholder (evsel); +} +#define for_each_group_member (_evsel, _leader) \ for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); \ (_evsel) && (_evsel)->leader == (_leader); \
tools/perf/util/parse-events.c +2 -2
@@ -1346,7 +1346,7 @@ static int set_filter(struct perf_evsel *evsel, const void *arg) {const char *str = arg; -if (evsel ==NULL || evsel->attr.type !=PERF_TYPE_TRACEPOINT ) { +if (!perf_evsel__can_filter (evsel)) {fprintf (stderr,"--filter option should follow a -e tracepoint option\n" );return -1 ;
@@ -1375,7 +1375,7 @@ static int add_exclude_perf_filter(struct perf_evsel *evsel, {char new_filter[64 ]; -if (evsel ==NULL || evsel->attr.type !=PERF_TYPE_TRACEPOINT ) { +if (!perf_evsel__can_filter (evsel)) {fprintf (stderr,"--exclude-perf option should follow a -e tracepoint option\n" );return -1 ;
Signature · 1 line
2.1.0
PATCH 11/27 perf tools: Sync setting of real bpf events with placeholder
In reply to Wang NanIn this patch, when adding real events described in BPF objects, sync filter and tracking settings with previous dummy placeholder. After this patch, command like:
# perf record --test-filter.o --exclude-perf ls
work as we expect.
After all settings are synced, we remove those placeholder from evlist so they won't appear in the final perf.data.
--- tools/perf/util/bpf-loader.c | 8 ++++- tools/perf/util/bpf-loader.h | 1 + tools/perf/util/evlist.c | 75 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 79 insertions(+), 5 deletions(-)
tools/perf/util/bpf-loader.c +7 -1
@@ -325,6 +325,12 @@ int bpf__foreach_tev(bpf_prog_iter_callback_t func, void *arg)int err;bpf_object__for_each_safe (obj, tmp) { +const char *obj_name; + + obj_name =bpf_object__get_name (obj); +if (!obj_name) + obj_name ="[unknown].o" ; +bpf_object__for_each_program (prog, obj) {struct probe_trace_event *tev;struct perf_probe_event *pev;
@@ -348,7 +354,7 @@ int bpf__foreach_tev(bpf_prog_iter_callback_t func, void *arg)return fd; } - err = (*func)(tev, fd, arg); + err = (*func)(tev, obj_name, fd, arg);if (err) {pr_debug ("bpf: call back failed, stop iterate\n" );return err;
tools/perf/util/bpf-loader.h +1 -0
@@ -13,6 +13,7 @@#define PERF_BPF_PROBE_GROUP "perf_bpf_probe"typedef int (*bpf_prog_iter_callback_t )(struct probe_trace_event *tev, +const char *obj_name,int fd,void *arg);#ifdef HAVE_LIBBPF_SUPPORT
tools/perf/util/evlist.c +71 -4
99 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH 12/27 perf record: Add clang options for compiling BPF scripts
In reply to Wang NanAlthough previous patch allows setting BPF compiler related options in perfconfig, on some ad-hoc situation it still requires passing options through cmdline. This patch introduces 2 options to 'perf record' for this propose: --clang-path and --clang-opt.
--- tools/perf/builtin-record.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/perf/builtin-record.c +7 -0
@@ -32,6 +32,7 @@#include "util/parse-branch-options.h" #include "util/parse-regs-options.h" #include "util/bpf-loader.h" +#include "util/llvm-utils.h" #include <unistd.h> #include <sched.h>
@@ -1097,6 +1098,12 @@ struct option __record_options[] = { "per thread proc mmap processing timeout in ms"),OPT_BOOLEAN (0 ,"switch-events" , &record.opts.record_switch_events,"Record context switch events" ), +#ifdef HAVE_LIBBPF_SUPPORT +OPT_STRING (0 ,"clang-path" , &llvm_param.clang_path,"clang path" , +"clang binary to use for compiling BPF scriptlets" ), +OPT_STRING (0 ,"clang-opt" , &llvm_param.clang_opt,"clang options" , +"options passed to clang when compiling BPF scriptlets" ), +#endif OPT_END() };
Signature · 1 line
2.1.0
PATCH 13/27 perf tools: Compile scriptlets to BPF objects when passing '.c' to --event
In reply to Wang NanThis patch provides infrastructure for passing source files to --event directly using:
# perf record --event bpf-file.c command
This patch does following works:
1) Allow passing '.c' file to '--event'. parse_events_load_bpf() is expanded to allow caller tell it whether the passed file is source file or object.
2) llvm__compile_bpf() is called to compile the '.c' file, the result is saved into memory. Use bpf_object__open_buffer() to load the in-memory object.
Introduces a bpf-script-example.c so we can manually test it:
# perf record --clang-opt "-DLINUX_VERSION_CODE=0x40200" --event ./bpf-script-example.c sleep 1
Note that '--clang-opt' must put before '--event'.
Futher patches will merge it into a testcase so can be tested automatically.
--- tools/perf/tests/bpf-script-example.c | 44 +++++++++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.c | 25 +++++++++++++++----- tools/perf/util/bpf-loader.h | 10 ++++---- tools/perf/util/parse-events.c | 6 ++--- tools/perf/util/parse-events.h | 3 ++- tools/perf/util/parse-events.l | 3 +++ tools/perf/util/parse-events.y | 15 ++++++++++-- 7 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 tools/perf/tests/bpf-script-example.c
tools/perf/tests/bpf-script-example.c new file +44 -0
@@ -0,0 +1,44 @@ +#ifndef LINUX_VERSION_CODE +# error Need LINUX_VERSION_CODE +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' +#endif +#define BPF_ANY 0 +#define BPF_MAP_TYPE_ARRAY 2 +#define BPF_FUNC_map_lookup_elem 1 +#define BPF_FUNC_map_update_elem 2 + +static void *(*bpf_map_lookup_elem)(void *map,void *key) = + (void *) BPF_FUNC_map_lookup_elem; +static void *(*bpf_map_update_elem)(void *map,void *key,void *value,int flags) = + (void *) BPF_FUNC_map_update_elem; + +struct bpf_map_def { +unsigned int type; +unsigned int key_size; +unsigned int value_size; +unsigned int max_entries; +}; + +#define SEC (NAME ) __attribute__((section(NAME), used)) +struct bpf_map_def SEC("maps") flip_table = { + .type = BPF_MAP_TYPE_ARRAY, + .key_size = sizeof(int), + .value_size = sizeof(int), + .max_entries = 1, +}; + +SEC("func=sys_epoll_pwait") +int bpf_func__sys_epoll_pwait (void *ctx) +{ +int ind =0 ; +int *flag =bpf_map_lookup_elem (&flip_table, &ind); +int new_flag; +if (!flag) +return 0 ; +/* flip flag and store back */ + new_flag = !*flag; +bpf_map_update_elem (&flip_table, &ind, &new_flag,BPF_ANY ); +return new_flag; +} +char _license[] SEC("license") = "GPL"; +int _version SEC("version") = LINUX_VERSION_CODE;
tools/perf/util/bpf-loader.c +19 -6
@@ -11,6 +11,7 @@#include "bpf-loader.h" #include "probe-event.h" #include "probe-finder.h" +#include "llvm-utils.h" #define DEFINE_PRINT_FN (name, level) \ static int libbpf_##name(const char *fmt, ...) \
@@ -164,16 +165,28 @@ sync_bpf_program_pev(struct bpf_program *prog)return 0 ; } -int bpf__prepare_load (const char *filename) +int bpf__prepare_load (const char *filename,bool source) {struct bpf_object *obj; +int err;if (!libbpf_initialized)libbpf_set_print (libbpf_warning, libbpf_info, libbpf_debug); - obj =bpf_object__open (filename); +if (source) { +void *obj_buf; +size_t obj_buf_sz; + + err =llvm__compile_bpf (filename, &obj_buf, &obj_buf_sz); +if (err) +return err; + obj =bpf_object__open_buffer (obj_buf, obj_buf_sz, filename); +free (obj_buf); + }else + obj =bpf_object__open (filename); +if (!obj) {pr_debug ("bpf: failed to load %s\n" , filename);return -EINVAL ;
@@ -387,12 +400,12 @@ int bpf__foreach_tev(bpf_prog_iter_callback_t func, void *arg) }\ buf[size -1 ] ='\0' ; -int bpf__strerror_prepare_load (const char *filename,int err, -char *buf,size_t size) +int bpf__strerror_prepare_load (const char *filename,bool source, +int err,char *buf,size_t size) {bpf__strerror_head (err, buf, size); -bpf__strerror_entry (EINVAL ,"%s: BPF object file '%s' is invalid" , - emsg, filename) +bpf__strerror_entry (EINVAL ,"%s: BPF %s file '%s' is invalid" , + emsg, source ?"source" :"object" , filename);bpf__strerror_end (buf, size);return 0 ; }
tools/perf/util/bpf-loader.h +6 -4
@@ -17,9 +17,9 @@ typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev, int fd, void *arg);#ifdef HAVE_LIBBPF_SUPPORT -int bpf__prepare_load (const char *filename); -int bpf__strerror_prepare_load (const char *filename,int err, -char *buf,size_t size); +int bpf__prepare_load (const char *filename,bool source); +int bpf__strerror_prepare_load (const char *filename,bool source, +int err,char *buf,size_t size);int bpf__probe (void );int bpf__unprobe (void );int bpf__strerror_probe (int err,char *buf,size_t size);
@@ -31,7 +31,8 @@ void bpf__clear(void);int bpf__foreach_tev (bpf_prog_iter_callback_t func,void *arg);#else -static inline int bpf__prepare_load (const char *filename__maybe_unused ) +static inline int bpf__prepare_load (const char *filename__maybe_unused , +bool source__maybe_unused ) {pr_debug ("ERROR: eBPF object loading is disabled during compiling.\n" );return -1 ;
@@ -63,6 +64,7 @@ __bpf_strerror(char *buf, size_t size)static inline int bpf__strerror_prepare_load (const char *filename__maybe_unused , +bool source__maybe_unused ,int err__maybe_unused ,char *buf,size_t size) {
tools/perf/util/parse-events.c +3 -3
@@ -484,7 +484,7 @@ int parse_events_add_tracepoint(struct list_head *list, int *idx,int parse_events_load_bpf (struct parse_events_evlist *data,struct list_head *list, -char *bpf_file_name) +char *bpf_file_name,bool source) {int err;char errbuf[BUFSIZ ];
@@ -522,9 +522,9 @@ int parse_events_load_bpf(struct parse_events_evlist *data,zfree (&dummy_evsel->name); dummy_evsel->name =strdup (bpf_file_name); - err =bpf__prepare_load (bpf_file_name); + err =bpf__prepare_load (bpf_file_name, source);if (err) { -bpf__strerror_prepare_load (bpf_file_name, err, +bpf__strerror_prepare_load (bpf_file_name, source, err, errbuf,sizeof (errbuf));list_del_init (&dummy_evsel->node);perf_evsel__delete (dummy_evsel);
tools/perf/util/parse-events.h +2 -1
@@ -121,7 +121,8 @@ int parse_events_add_tracepoint(struct list_head *list, int *idx, char *sys, char *event);int parse_events_load_bpf (struct parse_events_evlist *data,struct list_head *list, -char *bpf_file_name); +char *bpf_file_name, +bool source); int parse_events_add_numeric(struct parse_events_evlist *data, struct list_head *list, u32 type, u64 config,
tools/perf/util/parse-events.l +3 -0
@@ -116,6 +116,7 @@ group [^,{}/]*[{][^}]*[}][^,{}/]* event_pmu [^,{}/]+[/][^/]*[/][^,{}/]* event [^,{}/]+ bpf_object .*\.(o|bpf) +bpf_source .*\.c num_dec [0-9]+ num_hex 0x[a-fA-F0-9]+
@@ -161,6 +162,7 @@ modifier_bp [rwx]{1,3} {event_pmu} | {bpf_object} | +{bpf_source} | {event} { BEGIN(INITIAL); REWIND(1);
@@ -267,6 +269,7 @@ r{num_raw_hex} { return raw(yyscanner); } {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } {bpf_object} { return str(yyscanner, PE_BPF_OBJECT); } +{bpf_source} { return str(yyscanner, PE_BPF_SOURCE); } {name} { return pmu_str_check(yyscanner); } "/" { BEGIN(config); return '/'; } - { return '-'; }
tools/perf/util/parse-events.y +13 -2
@@ -42,7 +42,7 @@ static inc_group_count(struct list_head *list, %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM %token PE_EVENT_NAME %token PE_NAME -%token PE_BPF_OBJECT +%token PE_BPF_OBJECT PE_BPF_SOURCE %token PE_MODIFIER_EVENT PE_MODIFIER_BP %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
@@ -55,6 +55,7 @@ static inc_group_count(struct list_head *list, %type <num> PE_TERM %type <str> PE_NAME %type <str> PE_BPF_OBJECT +%type <str> PE_BPF_SOURCE %type <str> PE_NAME_CACHE_TYPE %type <str> PE_NAME_CACHE_OP_RESULT %type <str> PE_MODIFIER_EVENT
@@ -431,7 +432,17 @@ PE_BPF_OBJECT struct list_head *list; ALLOC_LIST(list); - ABORT_ON(parse_events_load_bpf(data, list, $1)); + ABORT_ON(parse_events_load_bpf(data, list, $1, false)); + $$ = list; +} +| +PE_BPF_SOURCE +{ + struct parse_events_evlist *data = _data; + struct list_head *list; + + ALLOC_LIST(list); + ABORT_ON(parse_events_load_bpf(data, list, $1, true)); $$ = list; }
Signature · 1 line
2.1.0
PATCH 14/27 perf test: Enforce LLVM test for BPF test
In reply to Wang NanThis patch replaces the original toy BPF program with previous introduced bpf-script-example.c. Dynamically embedded it into 'llvm-src.c'.
The newly introduced BPF program attaches a BPF program at 'sys_epoll_pwait()', and collect half samples from it. perf itself never use that syscall, so further test can verify their result with it.
Since BPF program require LINUX_VERSION_CODE of runtime kernel, this patch computes that code from uname.
Since the resuling BPF object is useful for further testcases, this patch introduces 'prepare' and 'cleanup' method to tests, and makes test__llvm() create a MAP_SHARED memory array to hold the resulting object.
[wangnan:
- Fix random building error by add $(call rule_mkdir) for tests/llvm-src.c.
]
--- tools/perf/tests/Build | 9 +++- tools/perf/tests/builtin-test.c | 8 ++++ tools/perf/tests/llvm.c | 104 +++++++++++++++++++++++++++++++++++----- tools/perf/tests/llvm.h | 14 ++++++ tools/perf/tests/tests.h | 2 + 5 files changed, 123 insertions(+), 14 deletions(-) create mode 100644 tools/perf/tests/llvm.h
tools/perf/tests/Build +8 -1
@@ -32,9 +32,16 @@ perf-y += sample-parsing.o perf-y += parse-no-sample-id-all.o perf-y += kmod-path.o perf-y += thread-map.o -perf-y += llvm.o +perf-y += llvm.o llvm-src.o perf-y += topology.o +$(OUTPUT)tests/llvm-src.c: tests/bpf-script-example.c + $(call rule_mkdir) + $(Q)echo '#include <tests/llvm.h>' > $@ + $(Q)echo 'const char test_llvm__bpf_prog[] =' >> $@ + $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ + $(Q)echo ';' >> $@ + perf-$(CONFIG_X86) += perf-time-to-tsc.o ifdef CONFIG_AUXTRACE perf-$(CONFIG_X86) += insn-x86.o
tools/perf/tests/builtin-test.c +8 -0
@@ -17,6 +17,8 @@static struct test {const char *desc;int (*func)(void ); +void (*prepare)(void ); +void (*cleanup)(void ); } tests[] = { { .desc ="vmlinux symtab matches kallsyms" ,
@@ -177,6 +179,8 @@ static struct test { { .desc = "Test LLVM searching and compiling", .func = test__llvm, + .prepare = test__llvm_prepare, + .cleanup = test__llvm_cleanup, },#ifdef HAVE_AUXTRACE_SUPPORT #if defined(__x86_64__) || defined(__i386__)
@@ -277,7 +281,11 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) }pr_debug ("\n--- start ---\n" ); +if (tests[curr].prepare) + tests[curr].prepare (); err =run_test (&tests[curr]); +if (tests[curr].cleanup) + tests[curr].cleanup ();pr_debug ("---- end ----\n%s:" , tests[curr].desc);switch (err) {
tools/perf/tests/llvm.c +91 -13
144 lines not on this page · raw message
tools/perf/tests/llvm.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef PERF_TEST_LLVM_H +#define PERF_TEST_LLVM_H + +#include <stddef.h> /* for size_t */ + +struct test_llvm__bpf_result { +size_t size; +char object[]; +}; + +extern struct test_llvm__bpf_result *p_test_llvm__bpf_result; +extern const char test_llvm__bpf_prog[]; + +#endif
tools/perf/tests/tests.h +2 -0
@@ -63,6 +63,8 @@ int test__fdarray__add(void);int test__kmod_path__parse (void );int test__thread_map (void );int test__llvm (void ); +void test__llvm_prepare (void ); +void test__llvm_cleanup (void );int test__insn_x86 (void );int test_session_topology (void );
Signature · 1 line
2.1.0
PATCH 15/27 perf test: Add 'perf test BPF'
In reply to Wang NanThis patch adds BPF testcase for testing BPF event filtering.
By utilizing the result of 'perf test LLVM', this patch compiles the eBPF sample program then test it ability. The BPF script in 'perf test LLVM' collects half of execution of epoll_pwait(). This patch runs 111 times of it, so the resule should contains 56 samples.
--- tools/perf/tests/Build | 1 + tools/perf/tests/bpf.c | 173 ++++++++++++++++++++++++++++++++++++++++ tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/llvm.c | 19 +++++ tools/perf/tests/llvm.h | 1 + tools/perf/tests/tests.h | 1 + tools/perf/util/bpf-loader.c | 14 ++++ tools/perf/util/bpf-loader.h | 8 ++ 8 files changed, 221 insertions(+) create mode 100644 tools/perf/tests/bpf.c
tools/perf/tests/Build +1 -0
@@ -33,6 +33,7 @@ perf-y += parse-no-sample-id-all.o perf-y += kmod-path.o perf-y += thread-map.o perf-y += llvm.o llvm-src.o +perf-y += bpf.o perf-y += topology.o $(OUTPUT)tests/llvm-src.c: tests/bpf-script-example.c
tools/perf/tests/bpf.c new file +173 -0
173 lines not on this page · raw message
tools/perf/tests/builtin-test.c +4 -0
@@ -195,6 +195,10 @@ static struct test { .func = test_session_topology, }, { + .desc = "Test BPF filter", + .func = test__bpf, + }, + { .func = NULL, }, };
tools/perf/tests/llvm.c +19 -0
@@ -174,3 +174,22 @@ void test__llvm_cleanup(void) (~((unsigned long )page_size -1 ));munmap ((void *)boundary, buf_end - boundary); } + +void +test_llvm__fetch_bpf_obj (void **p_obj_buf,size_t *p_obj_buf_sz) +{ + *p_obj_buf =NULL ; + *p_obj_buf_sz =0 ; + +if (!p_test_llvm__bpf_result) { +test__llvm_prepare (); +test__llvm (); +test__llvm_cleanup (); + } + +if (!p_test_llvm__bpf_result) +return ; + + *p_obj_buf = p_test_llvm__bpf_result->object; + *p_obj_buf_sz = p_test_llvm__bpf_result->size; +}
tools/perf/tests/llvm.h +1 -0
@@ -10,5 +10,6 @@ struct test_llvm__bpf_result {extern struct test_llvm__bpf_result *p_test_llvm__bpf_result;extern const char test_llvm__bpf_prog[]; +void test_llvm__fetch_bpf_obj (void **p_obj_buf,size_t *p_obj_buf_sz);#endif
tools/perf/tests/tests.h +1 -0
@@ -65,6 +65,7 @@ int test__thread_map(void);int test__llvm (void );void test__llvm_prepare (void );void test__llvm_cleanup (void ); +int test__bpf (void );int test__insn_x86 (void );int test_session_topology (void );
tools/perf/util/bpf-loader.c +14 -0
@@ -165,6 +165,20 @@ sync_bpf_program_pev(struct bpf_program *prog)return 0 ; } +int bpf__prepare_load_buffer (void *obj_buf,size_t obj_buf_sz, +const char *name) +{ +struct bpf_object *obj; + + obj =bpf_object__open_buffer (obj_buf, obj_buf_sz, name); +if (!obj) { +pr_debug ("bpf: failed to load buffer\n" ); +return -EINVAL ; + } + +return 0 ; +} +int bpf__prepare_load (const char *filename,bool source) {struct bpf_object *obj;
tools/perf/util/bpf-loader.h +8 -0
@@ -18,6 +18,8 @@ typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev,#ifdef HAVE_LIBBPF_SUPPORT int bpf__prepare_load (const char *filename,bool source); +int bpf__prepare_load_buffer (void *obj_buf,size_t obj_buf_sz, +const char *name);int bpf__strerror_prepare_load (const char *filename,bool source,int err,char *buf,size_t size);int bpf__probe (void );
@@ -38,6 +40,12 @@ static inline int bpf__prepare_load(const char *filename __maybe_unused,return -1 ; } +static inline int bpf__prepare_load_buffer (void *obj_buf__maybe_unused , +size_t obj_buf_sz__maybe_unused ) +{ +return bpf__prepare_load (NULL , false); +} +static inline int bpf__probe (void ) {return 0 ; }static inline int bpf__unprobe (void ) {return 0 ; }static inline int bpf__load (void ) {return 0 ; }
Signature · 1 line
2.1.0
PATCH 16/27 bpf tools: Load a program with different instances using preprocessor
In reply to Wang NanIn this patch, caller of libbpf is able to control the loaded programs by installing a preprocessor callback for a BPF program. With preprocessor, different instances can be created from one BPF program.
This patch will be used by perf to generate different prologue for different 'struct probe_trace_event' instances matched by one 'struct perf_probe_event'.
bpf_program__set_prep() is added to support this feature. Caller should pass libbpf the number of instances should be created and a preprocessor function which will be called when doing real loading. The callback should return instructions arrays for each instances.
fd field in bpf_programs is replaced by instance, which has an nr field and fds array. bpf_program__nth_fd() is introduced for read fd of instances. Old interface bpf_program__fd() is reimplemented by returning the first fd.
[wangnan: Add missing '!',
allows bpf_program__unload() when prog->instance.nr == -1 ] --- tools/lib/bpf/libbpf.c | 143 +++++++++++++++++++++++++++++++++++++++++++++---- tools/lib/bpf/libbpf.h | 22 ++++++++ 2 files changed, 156 insertions(+), 9 deletions(-)
tools/lib/bpf/libbpf.c +134 -9
@@ -98,7 +98,11 @@ struct bpf_program { } *reloc_desc;int nr_reloc; -int fd; +struct { +int nr; +int *fds; + } instance; +bpf_program_prep_t preprocessor;struct bpf_object *obj;void *priv;
@@ -152,10 +156,24 @@ struct bpf_object {static void bpf_program__unload (struct bpf_program *prog) { +int i; +if (!prog)return ; -zclose (prog->fd); +/* +* If the object is opened but the program is never loaded, +* it is possible that prog->instance.nr == -1. +*/ +if (prog->instance.nr >0 ) { +for (i =0 ; i < prog->instance.nr; i++) +zclose (prog->instance.fds[i]); + }else if (prog->instance.nr !=-1 ) +pr_warning ("Internal error: instance.nr is %d\n" , + prog->instance.nr); + + prog->instance.nr =-1 ; +zfree (&prog->instance.fds); }static void bpf_program__exit (struct bpf_program *prog)
@@ -206,7 +224,8 @@ bpf_program__init(void *data, size_t size, char *name, int idx,memcpy (prog->insns, data, prog->insns_cnt *sizeof (struct bpf_insn )); prog->idx = idx; - prog->fd =-1 ; + prog->instance.fds =NULL ; + prog->instance.nr =-1 ;return 0 ; errout:
@@ -795,13 +814,71 @@ static int bpf_program__load(struct bpf_program *prog, char *license, u32 kern_version) { - int err, fd; + int err = 0, fd, i; + +if (prog->instance.nr <0 || !prog->instance.fds) { +if (prog->preprocessor) { +pr_warning ("Internal error: can't load program '%s'\n" , + prog->section_name); +return -EINVAL ; + } + + prog->instance.fds =malloc (sizeof (int )); +if (!prog->instance.fds) { +pr_warning ("No enough memory for fds\n" ); +return -ENOMEM ; + } + prog->instance.nr =1 ; + prog->instance.fds[0 ] =-1 ; + } + +if (!prog->preprocessor) { +if (prog->instance.nr !=1 ) +pr_warning ("Program '%s' inconsistent: nr(%d) not 1\n" , + prog->section_name, prog->instance.nr); - err =load_program (prog->insns, prog->insns_cnt, - license, kern_version, &fd); -if (!err) - prog->fd = fd; + err =load_program (prog->insns, prog->insns_cnt, + license, kern_version, &fd); +if (!err) + prog->instance.fds[0 ] = fd; + goto out; + } + +for (i =0 ; i < prog->instance.nr; i++) { +struct bpf_prog_prep_result result; +bpf_program_prep_t preprocessor = prog->preprocessor; + +bzero (&result,sizeof (result)); + err =preprocessor (prog, i, prog->insns, + prog->insns_cnt, &result); +if (err) { +pr_warning ("Preprocessing %dth instance of program '%s' failed\n" , + i, prog->section_name); + goto out; + } + +if (!result.new_insn_ptr || !result.new_insn_cnt) { +pr_debug ("Skip loading %dth instance of program '%s'\n" , + i, prog->section_name); + prog->instance.fds[i] =-1 ; +continue ; + } + + err =load_program (result.new_insn_ptr, + result.new_insn_cnt, + license, kern_version, &fd); + +if (err) { +pr_warning ("Loading %dth instance of program '%s' failed\n" , + i, prog->section_name); + goto out; + } +if (result.pfd) + *result.pfd = fd; + prog->instance.fds[i] = fd; + } +out:if (err)pr_warning ("failed to load program '%s'\n" , prog->section_name);
@@ -1052,5 +1129,53 @@ const char *bpf_program__title(struct bpf_program *prog, bool dup)int bpf_program__fd (struct bpf_program *prog) { -return prog->fd; +return bpf_program__nth_fd (prog,0 ); +} + +int bpf_program__set_prep (struct bpf_program *prog,int nr_instance, +bpf_program_prep_t prep) +{ +int *instance_fds; + +if (nr_instance <=0 || !prep) +return -EINVAL ; + +if (prog->instance.nr >0 || prog->instance.fds) { +pr_warning ("Can't set pre-processor after loading\n" ); +return -EINVAL ; + } + + instance_fds =malloc (sizeof (int ) * nr_instance); +if (!instance_fds) { +pr_warning ("alloc memory failed for instance of fds\n" ); +return -ENOMEM ; + } + +/* fill all fd with -1 */ +memset (instance_fds,0xff ,sizeof (int ) * nr_instance); + + prog->instance.nr = nr_instance; + prog->instance.fds = instance_fds; + prog->preprocessor = prep; +return 0 ; +} + +int bpf_program__nth_fd (struct bpf_program *prog,int n) +{ +int fd; + +if (n >= prog->instance.nr || n <0 ) { +pr_warning ("Can't get the %dth fd from program %s: only %d instances\n" , + n, prog->section_name, prog->instance.nr); +return -EINVAL ; + } + + fd = prog->instance.fds[n]; +if (fd <0 ) { +pr_warning ("%dth instance of program '%s' is invalid\n" , + n, prog->section_name); +return -ENOENT ; + } + +return fd; }
tools/lib/bpf/libbpf.h +22 -0
@@ -67,6 +67,28 @@ const char *bpf_program__title(struct bpf_program *prog, bool dup);int bpf_program__fd (struct bpf_program *prog); +struct bpf_insn ; +struct bpf_prog_prep_result { +/* +* If not NULL, load new instruction array. +* If set to NULL, don't load this instance. +*/ +struct bpf_insn *new_insn_ptr; +int new_insn_cnt; + +/* If not NULL, result fd is set to it */ +int *pfd; +}; + +typedef int (*bpf_program_prep_t )(struct bpf_program *,int n, +struct bpf_insn *,int insn_cnt, +struct bpf_prog_prep_result *res); + +int bpf_program__set_prep (struct bpf_program *prog,int nr_instance, +bpf_program_prep_t prep); + +int bpf_program__nth_fd (struct bpf_program *prog,int n); +/* * We don't need __attribute__((packed)) now since it is * unnecessary for 'bpf_map_def' because they are all aligned.
Signature · 1 line
2.1.0
PATCH 17/27 perf probe: Reset args and nargs for probe_trace_event when failure
In reply to Wang NanWhen failure occures in add_probe_trace_event(), args in probe_trace_event is incomplete. Since information in it may be used in further, this patch frees the allocated memory and set it to NULL to avoid dangling pointer.
--- tools/perf/util/probe-finder.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/util/probe-finder.c +4 -0
@@ -1228,6 +1228,10 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, struct probe_finder *pf) end:free (args); +if (ret) { + tev->nargs =0 ; +zfree (&tev->args); + }return ret; }
Signature · 1 line
2.1.0
PATCH 18/27 perf tools: Add BPF_PROLOGUE config options for further patches
In reply to Wang NanIf both LIBBPF and DWARF are detected, it is possible to create prologue for eBPF programs to help them accessing kernel data. HAVE_BPF_PROLOGUE and CONFIG_BPF_PROLOGUE is added as flags for this feature.
PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET indicates an architecture supports converting name of a register to its offset in 'struct pt_regs'. Without this support, BPF_PROLOGUE should be turned off.
HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET is introduced as the corresponding CFLAGS of PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET.
[wangnan:
- Simplify Makefile based on Namhyung Kim's suggestion.
]
--- tools/perf/config/Makefile | 17 +++++++++++++++++ tools/perf/util/include/dwarf-regs.h | 8 ++++++++ 2 files changed, 25 insertions(+)
tools/perf/config/Makefile +17 -0
@@ -110,6 +110,11 @@ FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(AR # include ARCH specific config -include $(src-perf)/arch/$(ARCH)/Makefile +ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET + CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET +endif + + include $(src-perf)/config/utilities.mak ifeq ($(call get-executable,$(FLEX)),)
@@ -314,6 +319,18 @@ ifndef NO_LIBELF CFLAGS += -DHAVE_LIBBPF_SUPPORT $(call detected,CONFIG_LIBBPF) endif + + ifndef NO_DWARF + ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET + CFLAGS += -DHAVE_BPF_PROLOGUE + $(call detected,CONFIG_BPF_PROLOGUE) + else + msg := $(warning BPF prologue is not supported by architecture $(ARCH), missing regs_query_register_offset()); + endif + else + msg := $(warning DWARF support is off, BPF prologue is disabled); + endif + endif # NO_LIBBPF endif # NO_LIBELF
tools/perf/util/include/dwarf-regs.h +8 -0
@@ -5,4 +5,12 @@const char *get_arch_regstr (unsigned int n);#endif +#ifdef HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET +/* +* Arch should support fetching the offset of a register in pt_regs +* by its name. See kernel's regs_query_register_offset in +* arch/xxx/kernel/ptrace.c. +*/ +int regs_query_register_offset (const char *name); +#endif #endif
Signature · 1 line
2.1.0
tip-bot for Wang Nan
merge bot[tip:perf/core] perf tools: regs_query_register_offset() infrastructure
perf tools: regs_query_register_offset() infrastructure
Commit-ID: 63ab024a5b6f295ca17a293ad81b7c728f49a89a Gitweb: http://git.kernel.org/tip/63ab024a5b6f295ca17a293ad81b7c728f49a89a Author: Wang Nan <[email protected]> AuthorDate: Mon, 14 Sep 2015 23:02:49 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 15 Sep 2015 09:48:33 -0300
perf tools: regs_query_register_offset() infrastructure
regs_query_register_offset() is a helper function which converts register name like "%rax" to offset of a register in 'struct pt_regs', which is required by BPF prologue generator.
PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET indicates an architecture supports converting name of a register to its offset in 'struct pt_regs'.
HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET is introduced as the corresponding CFLAGS of PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET.
--- tools/perf/config/Makefile | 4 ++++ tools/perf/util/include/dwarf-regs.h | 8 ++++++++ 2 files changed, 12 insertions(+)
tools/perf/config/Makefile +4 -0
@@ -109,6 +109,10 @@ endif # include ARCH specific config -include $(src-perf)/arch/$(ARCH)/Makefile +ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET + CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET +endif + include $(src-perf)/config/utilities.mak ifeq ($(call get-executable,$(FLEX)),)
tools/perf/util/include/dwarf-regs.h +8 -0
@@ -5,4 +5,12 @@const char *get_arch_regstr (unsigned int n);#endif +#ifdef HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET +/* +* Arch should support fetching the offset of a register in pt_regs +* by its name. See kernel's regs_query_register_offset in +* arch/xxx/kernel/ptrace.c. +*/ +int regs_query_register_offset (const char *name); +#endif #endif
PATCH 19/27 perf tools: Introduce regs_query_register_offset() for x86
In reply to Wang Nanregs_query_register_offset() is a helper function which converts register name like "%rax" to offset of a register in 'struct pt_regs', which is required by BPF prologue generator. Since the function is identical, try to reuse the code in arch/x86/kernel/ptrace.c.
Comment inside dwarf-regs.c list the differences between this implementation and kernel code.
get_arch_regstr() switches to regoffset_table and the old string table is dropped.
--- tools/perf/arch/x86/Makefile | 1 + tools/perf/arch/x86/util/Build | 1 + tools/perf/arch/x86/util/dwarf-regs.c | 122 ++++++++++++++++++++++++---------- 3 files changed, 90 insertions(+), 34 deletions(-)
tools/perf/arch/x86/Makefile +1 -0
@@ -2,3 +2,4 @@ ifndef NO_DWARF PERF_HAVE_DWARF_REGS := 1 endif HAVE_KVM_STAT_SUPPORT := 1 +PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
tools/perf/arch/x86/util/Build +1 -0
@@ -5,6 +5,7 @@ libperf-y += kvm-stat.o libperf-y += perf_regs.o libperf-$(CONFIG_DWARF) += dwarf-regs.o +libperf-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
tools/perf/arch/x86/util/dwarf-regs.c +88 -34
143 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [PATCH 19/27] perf tools: Introduce regs_query_register_offset() for x86
Em Sun, Sep 06, 2015 at 07:13:35AM +0000, Wang Nan escreveu:
Quoted 10 lines
regs_query_register_offset()is a helper function which converts register name like "%rax" to offset of a register in 'structpt_regs', which is required by BPF prologue generator. Since the function is identical, try to reuse the code inarch/x86/kernel/ptrace.c.Comment inside
dwarf-regs.clist the differences between this implementation and kernel code.
get_arch_regstr()switches toregoffset_tableand the old string table is dropped.
Trying to cherry pick this one, but found this problem, trying to fix by adding the prototype somewhere...
[acme@zoo linux]$ m
make: Entering directory '/home/git/linux/tools/perf'
BUILD: Doing 'make -j4' parallel build
CC /tmp/build/perf/arch/x86/util/dwarf-regs.o
CC /tmp/build/perf/arch/x86/util/intel-pt.o
arch/x86/util/dwarf-regs.c:122:5: error: no previous prototype for
‘regs_query_register_offset’ [-Werror=missing-prototypes]
int regs_query_register_offset(const char *name)
^cc1: all warnings being treated as errors /home/git/linux/tools/build/Makefile.build:70: recipe for target '/tmp/build/perf/arch/x86/util/dwarf-regs.o' failed make[5]: *** [/tmp/build/perf/arch/x86/util/dwarf-regs.o] Error 1
Re: [PATCH 19/27] perf tools: Introduce regs_query_register_offset() for x86
Quoted 24 lines · Arnaldo Carvalho de Melo
Em Sun, Sep 06, 2015 at 07:13:35AM +0000, Wang Nan escreveu:
Quoted 10 lines
regs_query_register_offset()is a helper function which converts register name like "%rax" to offset of a register in 'structpt_regs', which is required by BPF prologue generator. Since the function is identical, try to reuse the code inarch/x86/kernel/ptrace.c.Comment inside
dwarf-regs.clist the differences between this implementation and kernel code.
get_arch_regstr()switches toregoffset_tableand the old string table is dropped.Trying to cherry pick this one, but found this problem, trying to fix by adding the prototype somewhere...
[acme@zoo linux]$ m
make: Entering directory '/home/git/linux/tools/perf'BUILD: Doing 'make -j4' parallel build CC /tmp/build/perf/arch/x86/util/dwarf-regs.o CC /tmp/build/perf/arch/x86/util/intel-pt.o arch/x86/util/dwarf-regs.c:122:5: error: no previous prototype for ‘regs_query_register_offset’ [-Werror=missing-prototypes] int regs_query_register_offset(const char *name) ^
Quoted 4 lines
cc1: all warnings being treated as errors
/home/git/linux/tools/build/Makefile.build:70: recipe for target '/tmp/build/perf/arch/x86/util/dwarf-regs.o' failed make[5]: *** [/tmp/build/perf/arch/x86/util/dwarf-regs.o] Error 1
This patch depends on patch 18/27: "perf tools: Add BPF_PROLOGUE config options for further patches" because I wanted to first create the infrastructure then add regs_qurey_register_offset() arch by arch.
I think split 18/27 into two patch should be better. First one adds HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET, let the second one consider bpf prologue.
Thanks.
tip-bot for Wang Nan
merge bot[tip:perf/core] perf tools: Introduce regs_query_register_offset( ) for x86
In reply to Wang Nanperf tools: Introduce regs_query_register_offset() for x86
Commit-ID: bbbe6bf6037d77816c4a19aaf35f4cecf662b49a Gitweb: http://git.kernel.org/tip/bbbe6bf6037d77816c4a19aaf35f4cecf662b49a Author: Wang Nan <[email protected]> AuthorDate: Sun, 6 Sep 2015 07:13:35 +0000 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 15 Sep 2015 09:48:33 -0300
perf tools: Introduce regs_query_register_offset() for x86
regs_query_register_offset() is a helper function which converts register name like "%rax" to offset of a register in 'struct pt_regs', which is required by BPF prologue generator. Since the function is identical, try to reuse the code in arch/x86/kernel/ptrace.c.
Comment inside dwarf-regs.c list the differences between this implementation and kernel code.
get_arch_regstr() switches to regoffset_table and the old string table is dropped.
--- tools/perf/arch/x86/Makefile | 1 + tools/perf/arch/x86/util/dwarf-regs.c | 122 ++++++++++++++++++++++++---------- 2 files changed, 89 insertions(+), 34 deletions(-)
tools/perf/arch/x86/Makefile +1 -0
@@ -2,3 +2,4 @@ ifndef NO_DWARF PERF_HAVE_DWARF_REGS := 1 endif HAVE_KVM_STAT_SUPPORT := 1 +PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
tools/perf/arch/x86/util/dwarf-regs.c +88 -34
143 lines not on this page · raw message
PATCH 20/27 perf tools: Add prologue for BPF programs for fetching arguments
In reply to Wang NanFrom: He Kuang <[email protected]>
This patch generates prologue for a BPF program which fetch arguments for it. With this patch, the program can have arguments as follow:
SEC("lock_page=__lock_page page->flags")
int lock_page(struct pt_regs *ctx, int err, unsigned long flags)
{
return 1;}
This patch passes at most 3 arguments from r3, r4 and r5. r1 is still the ctx pointer. r2 is used to indicate the successfulness of dereferencing.
This patch uses r6 to hold ctx (struct pt_regs) and r7 to hold stack pointer for result. Result of each arguments first store on stack:
low address
BPF_REG_FP - 24 ARG3 BPF_REG_FP - 16 ARG2 BPF_REG_FP - 8 ARG1
BPF_REG_FP
high address
Then loaded into r3, r4 and r5.
The output prologue for offn(...off2(off1(reg)))) should be:
r6 <- r1 // save ctx into a callee saved register
r7 <- fp
r7 <- r7 - stack_offset // pointer to result slot
/* load r3 with the offset in pt_regs of 'reg' */
(r7) <- r3 // make slot valid
r3 <- r3 + off1 // prepare to read unsafe pointer
r2 <- 8
r1 <- r7 // result put onto stack
call probe_read // read unsafe pointer
jnei r0, 0, err // error checking
r3 <- (r7) // read result
r3 <- r3 + off2 // prepare to read unsafe pointer
r2 <- 8
r1 <- r7
call probe_read
jnei r0, 0, err
...
/* load r2, r3, r4 from stack */
goto success
err:
r2 <- 1
/* load r3, r4, r5 with 0 */
goto usercode
success:
r2 <- 0
usercode:
r1 <- r6 // restore ctx
// original user codeIf all of arguments reside in register (dereferencing is not required), gen_prologue_fastpath() will be used to create fast prologue:
r3 <- (r1 + offset of reg1)
r4 <- (r1 + offset of reg2)
r5 <- (r1 + offset of reg3)
r2 <- 0P.S.
eBPF calling convention is defined as:
* r0 - return value from in-kernel function, and exit value
for eBPF program
* r1 - r5 - arguments from eBPF program to in-kernel function
* r6 - r9 - callee saved registers that in-kernel function will
preserve
* r10 - read-only frame pointer to access stack
--- tools/perf/util/Build | 1 + tools/perf/util/bpf-prologue.c | 443 +++++++++++++++++++++++++++++++++++++++++ tools/perf/util/bpf-prologue.h | 34 ++++ 3 files changed, 478 insertions(+) create mode 100644 tools/perf/util/bpf-prologue.c create mode 100644 tools/perf/util/bpf-prologue.h
tools/perf/util/Build +1 -0
@@ -86,6 +86,7 @@ libperf-y += parse-branch-options.o libperf-y += parse-regs-options.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o +libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o libperf-$(CONFIG_LIBELF) += symbol-elf.o libperf-$(CONFIG_LIBELF) += probe-file.o libperf-$(CONFIG_LIBELF) += probe-event.o
tools/perf/util/bpf-prologue.c new file +443 -0
443 lines not on this page · raw message
tools/perf/util/bpf-prologue.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Copyright (C) 2015, He Kuang <[email protected]> +* Copyright (C) 2015, Huawei Inc. +*/ +#ifndef __BPF_PROLOGUE_H +#define __BPF_PROLOGUE_H + +#include <linux/compiler.h> +#include <linux/filter.h> +#include "probe-event.h" + +#define BPF_PROLOGUE_MAX_ARGS 3 +#define BPF_PROLOGUE_START_ARG_REG BPF_REG_3 +#define BPF_PROLOGUE_FETCH_RESULT_REG BPF_REG_2 + +#ifdef HAVE_BPF_PROLOGUE +int bpf__gen_prologue (struct probe_trace_arg *args,int nargs, +struct bpf_insn *new_prog,size_t *new_cnt, +size_t cnt_space); +#else +static inline int +bpf__gen_prologue (struct probe_trace_arg *args__maybe_unused , +int nargs__maybe_unused , +struct bpf_insn *new_prog__maybe_unused , +size_t *new_cnt, +size_t cnt_space__maybe_unused ) +{ +if (!new_cnt) +return -EINVAL ; + *new_cnt =0 ; +return 0 ; +} +#endif +#endif /* __BPF_PROLOGUE_H */
Signature · 1 line
2.1.0
PATCH 21/27 perf tools: Generate prologue for BPF programs
In reply to Wang NanThis patch generates prologue for each 'struct probe_trace_event' for fetching arguments for BPF programs.
After bpf__probe(), iterate over each programs to check whether prologue is required. If none of 'struct perf_probe_event' a program will attach to has at least one argument, simply skip preprocessor hooking. For those who prologue is required, calls bpf__gen_prologue() and paste original instruction after prologue.
--- tools/perf/util/bpf-loader.c | 120 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-)
tools/perf/util/bpf-loader.c +119 -1
@@ -5,10 +5,13 @@* Copyright (C) 2015 Huawei Inc. */ +#include <linux/bpf.h> #include <bpf/libbpf.h> #include "perf.h" #include "debug.h" #include "bpf-loader.h" +#include "bpf-prologue.h" +#include "llvm-utils.h" #include "probe-event.h" #include "probe-finder.h" #include "llvm-utils.h"
@@ -42,6 +45,8 @@ struct bpf_prog_priv {struct perf_probe_event *ppev;struct perf_probe_event pev; }; +bool need_prologue; +struct bpf_insn *insns_buf; }; static void
@@ -65,6 +70,7 @@ bpf_prog_priv__clear(struct bpf_program *prog __maybe_unused,clear_perf_probe_event (&priv->pev); } +zfree (&priv->insns_buf);free (priv); }
@@ -248,6 +254,103 @@ int bpf__unprobe(void)return ret <0 ? ret :0 ; } +static int +preproc_gen_prologue (struct bpf_program *prog,int n, +struct bpf_insn *orig_insns,int orig_insns_cnt, +struct bpf_prog_prep_result *res) +{ +struct probe_trace_event *tev; +struct perf_probe_event *pev; +struct bpf_prog_priv *priv; +struct bpf_insn *buf; +size_t prologue_cnt =0 ; +int err; + + err =bpf_program__get_private (prog, (void **)&priv); +if (err || !priv || !priv->pev_ready) + goto errout; + + pev = &priv->pev; + +if (n <0 || n >= pev->ntevs) + goto errout; + + tev = &pev->tevs[n]; + + buf = priv->insns_buf; + err =bpf__gen_prologue (tev->args, tev->nargs, + buf, &prologue_cnt, +BPF_MAXINSNS - orig_insns_cnt); +if (err) { +const char *title; + + title =bpf_program__title (prog, false); +if (!title) + title ="??" ; + +pr_debug ("Failed to generate prologue for program %s\n" , + title); +return err; + } + +memcpy (&buf[prologue_cnt], orig_insns, +sizeof (struct bpf_insn ) * orig_insns_cnt); + + res->new_insn_ptr = buf; + res->new_insn_cnt = prologue_cnt + orig_insns_cnt; + res->pfd =NULL ; +return 0 ; + +errout: +pr_debug ("Internal error in preproc_gen_prologue\n" ); +return -EINVAL ; +} + +static int hook_load_preprocessor (struct bpf_program *prog) +{ +struct perf_probe_event *pev; +struct bpf_prog_priv *priv; +bool need_prologue = false; +int err, i; + + err =bpf_program__get_private (prog, (void **)&priv); +if (err || !priv) { +pr_debug ("Internal error when hook preprocessor\n" ); +return -EINVAL ; + } + + pev = &priv->pev; +for (i =0 ; i < pev->ntevs; i++) { +struct probe_trace_event *tev = &pev->tevs[i]; + +if (tev->nargs >0 ) { + need_prologue = true; +break ; + } + } + +/* +* Since all tev doesn't have argument, we don't need generate +* prologue. +*/ +if (!need_prologue) { + priv->need_prologue = false; +return 0 ; + } + + priv->need_prologue = true; + priv->insns_buf =malloc (sizeof (struct bpf_insn ) * +BPF_MAXINSNS ); +if (!priv->insns_buf) { +pr_debug ("No enough memory: alloc insns_buf failed\n" ); +return -ENOMEM ; + } + + err =bpf_program__set_prep (prog, pev->ntevs, + preproc_gen_prologue); +return err; +} +int bpf__probe (void ) {int err, nr_events =0 ;
@@ -311,6 +414,17 @@ int bpf__probe(void) err =sync_bpf_program_pev (prog);if (err) goto out; +/* +* After probing, let's consider prologue, which +* adds program fetcher to BPF programs. +* +* hook_load_preprocessorr() hooks pre-processor +* to bpf_program, let it generate prologue +* dynamically during loading. +*/ + err =hook_load_preprocessor (prog); +if (err) + goto out; } } out:
@@ -375,7 +489,11 @@ int bpf__foreach_tev(bpf_prog_iter_callback_t func, void *arg)for (i =0 ; i < pev->ntevs; i++) { tev = &pev->tevs[i]; - fd =bpf_program__fd (prog); +if (priv->need_prologue) + fd =bpf_program__nth_fd (prog, i); +else + fd =bpf_program__fd (prog); +if (fd <0 ) {pr_debug ("bpf: failed to get file descriptor\n" );return fd;
Signature · 1 line
2.1.0
PATCH 22/27 perf tools: Use same BPF program if arguments are identical
In reply to Wang NanThis patch allows creating only one BPF program for different 'probe_trace_event'(tev) generated by one 'perf_probe_event'(pev), if their prologues are identical.
This is done by comparing argument list of different tev, and maps type of prologue and tev using a mapping array. This patch utilizes qsort to sort tevs. After sorting, tevs with identical argument list will group together.
--- tools/perf/util/bpf-loader.c | 133 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 126 insertions(+), 7 deletions(-)
tools/perf/util/bpf-loader.c +126 -7
@@ -47,6 +47,8 @@ struct bpf_prog_priv { };bool need_prologue;struct bpf_insn *insns_buf; +int nr_types; +int *type_mapping; }; static void
@@ -71,6 +73,7 @@ bpf_prog_priv__clear(struct bpf_program *prog __maybe_unused,clear_perf_probe_event (&priv->pev); }zfree (&priv->insns_buf); +zfree (&priv->type_mapping);free (priv); }
@@ -264,7 +267,7 @@ preproc_gen_prologue(struct bpf_program *prog, int n,struct bpf_prog_priv *priv;struct bpf_insn *buf;size_t prologue_cnt =0 ; -int err; +int i, err; err =bpf_program__get_private (prog, (void **)&priv);if (err || !priv || !priv->pev_ready)
@@ -272,10 +275,20 @@ preproc_gen_prologue(struct bpf_program *prog, int n, pev = &priv->pev; -if (n <0 || n >= pev->ntevs) +if (n <0 || n >= priv->nr_types) goto errout; - tev = &pev->tevs[n]; +/* Find a tev belongs to that type */ +for (i =0 ; i < pev->ntevs; i++) +if (priv->type_mapping[i] == n) +break ; + +if (i >= pev->ntevs) { +pr_debug ("Internal error: prologue type %d not found\n" , n); +return -ENOENT ; + } + + tev = &pev->tevs[i]; buf = priv->insns_buf; err = bpf__gen_prologue(tev->args, tev->nargs,
@@ -306,6 +319,98 @@ errout:return -EINVAL ; } +/* +* compare_tev_args is reflexive, transitive and antisymmetric. +* I can show that but this margin is too narrow to contain. +*/ +static int compare_tev_args (const void *ptev1,const void *ptev2) +{ +int i, ret; +const struct probe_trace_event *tev1 = + *(const struct probe_trace_event **)ptev1; +const struct probe_trace_event *tev2 = + *(const struct probe_trace_event **)ptev2; + + ret = tev2->nargs - tev1->nargs; +if (ret) +return ret; + +for (i =0 ; i < tev1->nargs; i++) { +struct probe_trace_arg *arg1, *arg2; +struct probe_trace_arg_ref *ref1, *ref2; + + arg1 = &tev1->args[i]; + arg2 = &tev2->args[i]; + + ret =strcmp (arg1->value, arg2->value); +if (ret) +return ret; + + ref1 = arg1->ref; + ref2 = arg2->ref; + +while (ref1 && ref2) { + ret = ref2->offset - ref1->offset; +if (ret) +return ret; + + ref1 = ref1->next; + ref2 = ref2->next; + } + +if (ref1 || ref2) +return ref2 ?1 :-1 ; + } + +return 0 ; +} + +static int map_prologue (struct perf_probe_event *pev,int *mapping, +int *nr_types) +{ +int i, type =0 ; +struct { +struct probe_trace_event *tev; +int idx; + } *stevs; +size_t array_sz =sizeof (*stevs) * pev->ntevs; + + stevs =malloc (array_sz); +if (!stevs) { +pr_debug ("No ehough memory: alloc stevs failed\n" ); +return -ENOMEM ; + } + +pr_debug ("In map_prologue, ntevs=%d\n" , pev->ntevs); +for (i =0 ; i < pev->ntevs; i++) { + stevs[i].tev = &pev->tevs[i]; + stevs[i].idx = i; + } +qsort (stevs, pev->ntevs,sizeof (*stevs), + compare_tev_args); + +for (i =0 ; i < pev->ntevs; i++) { +if (i ==0 ) { + mapping[stevs[i].idx] = type; +pr_debug ("mapping[%d]=%d\n" , stevs[i].idx, + type); +continue ; + } + +if (compare_tev_args (stevs + i, stevs + i -1 ) ==0 ) + mapping[stevs[i].idx] = type; +else + mapping[stevs[i].idx] = ++type; + +pr_debug ("mapping[%d]=%d\n" , stevs[i].idx, + mapping[stevs[i].idx]); + } +free (stevs); + *nr_types = type +1 ; + +return 0 ; +} +static int hook_load_preprocessor (struct bpf_program *prog) {struct perf_probe_event *pev;
@@ -346,7 +451,19 @@ static int hook_load_preprocessor(struct bpf_program *prog)return -ENOMEM ; } - err =bpf_program__set_prep (prog, pev->ntevs, + priv->type_mapping =malloc (sizeof (int ) * pev->ntevs); +if (!priv->type_mapping) { +pr_debug ("No enough memory: alloc type_mapping failed\n" ); +return -ENOMEM ; + } +memset (priv->type_mapping,0xff , +sizeof (int ) * pev->ntevs); + + err =map_prologue (pev, priv->type_mapping, &priv->nr_types); +if (err) +return err; + + err =bpf_program__set_prep (prog, priv->nr_types, preproc_gen_prologue);return err; }
@@ -489,9 +606,11 @@ int bpf__foreach_tev(bpf_prog_iter_callback_t func, void *arg)for (i =0 ; i < pev->ntevs; i++) { tev = &pev->tevs[i]; -if (priv->need_prologue) - fd =bpf_program__nth_fd (prog, i); -else +if (priv->need_prologue) { +int type = priv->type_mapping[i]; + + fd =bpf_program__nth_fd (prog, type); + }else fd =bpf_program__fd (prog);if (fd <0 ) {
Signature · 1 line
2.1.0
PATCH 23/27 perf record: Support custom vmlinux path
In reply to Wang NanFrom: He Kuang <[email protected]>
Make perf-record command support --vmlinux option if BPF_PROLOGUE is on.
'perf record' needs vmlinux as the source of DWARF info to generate prologue for BPF programs, so path of vmlinux should be specified.
Short name 'k' has been taken by 'clockid'. This patch skips the short option name and use '--vmlinux' for vmlinux path.
--- tools/perf/builtin-record.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/perf/builtin-record.c +4 -0
@@ -1103,6 +1103,10 @@ struct option __record_options[] = { "clang binary to use for compiling BPF scriptlets"),OPT_STRING (0 ,"clang-opt" , &llvm_param.clang_opt,"clang options" ,"options passed to clang when compiling BPF scriptlets" ), +#ifdef HAVE_BPF_PROLOGUE +OPT_STRING (0 ,"vmlinux" , &symbol_conf.vmlinux_name, +"file" ,"vmlinux pathname" ), +#endif #endifOPT_END () };
Signature · 1 line
2.1.0
PATCH 24/27 perf probe: Init symbol as kprobe
In reply to Wang NanBefore this patch, add_perf_probe_events() init symbol maps only for uprobe if the first 'struct perf_probe_event' passed to it is a uprobe event. This is a trick because 'perf probe''s command line syntax constrains the first elements of the probe_event arrays must be kprobes if there is one kprobe there.
However, with the incoming BPF uprobe support, that constrain is not hold since 'perf record' will also probe on k/u probes through BPF object, and is possible to pass an array with kprobe but the first element is uprobe.
This patch init symbol maps for kprobes even if all of events are uprobes, because the extra cost should be small enough.
--- tools/perf/util/probe-event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
@@ -2746,7 +2746,7 @@ int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs) {int i, ret; - ret =init_symbol_maps (pevs->uprobes); + ret =init_symbol_maps (false);if (ret <0 )return ret;
Signature · 1 line
2.1.0
PATCH 25/27 perf tools: Allow BPF program attach to uprobe events
In reply to Wang NanThis patch appends new syntax to BPF object section name to support probing at uprobe event. Now we can use BPF program like this:
SEC(
"target=/lib64/libc.so.6\n"
"libcwrite=__write"
)
int libcwrite(void *ctx)
{
return 1;}
Where, in section name of a program, before the main config string, we can use 'key=value' style options. Now the only option key "target" is for uprobe probing.
--- tools/perf/util/bpf-loader.c | 88 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 7 deletions(-)
tools/perf/util/bpf-loader.c +81 -7
@@ -78,6 +78,84 @@ bpf_prog_priv__clear(struct bpf_program *prog __maybe_unused, }static int +do_config (const char *key,const char *value, +struct perf_probe_event *pev) +{ +pr_debug ("config bpf program: %s=%s\n" , key, value); +if (strcmp (key,"target" ) ==0 ) { + pev->uprobes = true; + pev->target =strdup (value); +return 0 ; + } + +pr_warning ("BPF: WARNING: invalid config option in object: %s=%s\n" , + key, value); +pr_warning ("\tHint: Currently only valid option is 'target=<file>'\n" ); +return 0 ; +} + +static const char * +parse_config_kvpair (const char *config_str,struct perf_probe_event *pev) +{ +char *text =strdup (config_str); +char *sep, *line; +const char *main_str =NULL ; +int err =0 ; + +if (!text) { +pr_debug ("No enough memory: dup config_str failed\n" ); +return NULL ; + } + + line = text; +while ((sep =strchr (line,'\n' ))) { +char *equ; + + *sep ='\0' ; + equ =strchr (line,'=' ); +if (!equ) { +pr_warning ("WARNING: invalid config in BPF object: %s\n" , + line); +pr_warning ("\tShould be 'key=value'.\n" ); + goto nextline; + } + *equ ='\0' ; + + err =do_config (line, equ +1 , pev); +if (err) +break ; +nextline: + line = sep +1 ; + } + +if (!err) + main_str = config_str + (line - text); +free (text); + +return main_str; +} + +static int +parse_config (const char *config_str,struct perf_probe_event *pev) +{ +const char *main_str; +int err; + + main_str =parse_config_kvpair (config_str, pev); +if (!main_str) +return -EINVAL ; + + err =parse_perf_probe_command (main_str, pev); +if (err <0 ) { +pr_debug ("bpf: '%s' is not a valid config string\n" , + config_str); +/* parse failed, don't need clear pev. */ +return -EINVAL ; + } +return 0 ; +} + +static int config_bpf_program (struct bpf_program *prog,struct perf_probe_event *pev) {struct bpf_prog_priv *priv =NULL ;
@@ -91,13 +169,9 @@ config_bpf_program(struct bpf_program *prog, struct perf_probe_event *pev) }pr_debug ("bpf: config program '%s'\n" , config_str); - err =parse_perf_probe_command (config_str, pev); -if (err <0 ) { -pr_debug ("bpf: '%s' is not a valid config string\n" , - config_str); -/* parse failed, don't need clear pev. */ -return -EINVAL ; - } + err =parse_config (config_str, pev); +if (err) +return err;if (pev->group &&strcmp (pev->group,PERF_BPF_PROBE_GROUP )) { pr_debug("bpf: '%s': group for event is set and not '%s'.\n",
Signature · 1 line
2.1.0
PATCH 26/27 perf test: Enforce LLVM test, add kbuild test
In reply to Wang NanThis patch enforces existing LLVM test, makes it compile more than one BPF source file. The compiled results are stored, can be used for other testcases. Except the first testcase (named LLVM_TESTCASE_BASE), failures of other test cases are not considered as failure of the whole test.
Adds a kbuild testcase to check whether kernel headers can be correctly found.
For example:
# perf test LLVM
38: Test LLVM searching and compiling : (llvm.kbuild-dir can be fixed) Ok
--- tools/perf/tests/Build | 11 ++- tools/perf/tests/bpf-script-example.c | 4 + tools/perf/tests/bpf-script-test-kbuild.c | 21 ++++ tools/perf/tests/bpf.c | 3 +- tools/perf/tests/llvm.c | 154 ++++++++++++++++++++++-------- tools/perf/tests/llvm.h | 10 +- 6 files changed, 156 insertions(+), 47 deletions(-) create mode 100644 tools/perf/tests/bpf-script-test-kbuild.c
tools/perf/tests/Build +9 -2
@@ -32,17 +32,24 @@ perf-y += sample-parsing.o perf-y += parse-no-sample-id-all.o perf-y += kmod-path.o perf-y += thread-map.o -perf-y += llvm.o llvm-src.o +perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o perf-y += bpf.o perf-y += topology.o -$(OUTPUT)tests/llvm-src.c: tests/bpf-script-example.c +$(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c $(call rule_mkdir) $(Q)echo '#include <tests/llvm.h>' > $@ $(Q)echo 'const char test_llvm__bpf_prog[] =' >> $@ $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ $(Q)echo ';' >> $@ +$(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c + $(call rule_mkdir) + $(Q)echo '#include <tests/llvm.h>' > $@ + $(Q)echo 'const char test_llvm__bpf_test_kbuild_prog[] =' >> $@ + $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ + $(Q)echo ';' >> $@ + perf-$(CONFIG_X86) += perf-time-to-tsc.o ifdef CONFIG_AUXTRACE perf-$(CONFIG_X86) += insn-x86.o
tools/perf/tests/bpf-script-example.c +4 -0
@@ -1,3 +1,7 @@ +/* +* bpf-script-example.c +* Test basic LLVM building +*/ #ifndef LINUX_VERSION_CODE # error Need LINUX_VERSION_CODE# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
tools/perf/tests/bpf-script-test-kbuild.c new file +21 -0
@@ -0,0 +1,21 @@ +/* +* bpf-script-test-kbuild.c +* Test include from kernel header +*/ +#ifndef LINUX_VERSION_CODE +# error Need LINUX_VERSION_CODE +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' +#endif +#define SEC (NAME ) __attribute__((section(NAME), used)) + +#include <uapi/linux/fs.h> +#include <uapi/asm/ptrace.h> + +SEC("func=vfs_llseek") +int bpf_func__vfs_llseek (struct pt_regs *ctx) +{ +return 0 ; +} + +char _license[] SEC("license") = "GPL"; +int _version SEC("version") = LINUX_VERSION_CODE;
tools/perf/tests/bpf.c +2 -1
@@ -143,7 +143,8 @@ int test__bpf(void)return TEST_SKIP ; } -test_llvm__fetch_bpf_obj (&obj_buf, &obj_buf_sz); +test_llvm__fetch_bpf_obj (&obj_buf, &obj_buf_sz,LLVM_TESTCASE_BASE ); +if (!obj_buf || !obj_buf_sz) {if (verbose ==0 )fprintf (stderr," (fix 'perf test LLVM' first)" );
tools/perf/tests/llvm.c +112 -42
238 lines not on this page · raw message
tools/perf/tests/llvm.h +8 -2
@@ -8,8 +8,14 @@ struct test_llvm__bpf_result { char object[]; }; -extern struct test_llvm__bpf_result *p_test_llvm__bpf_result;extern const char test_llvm__bpf_prog[]; -void test_llvm__fetch_bpf_obj (void **p_obj_buf,size_t *p_obj_buf_sz); +extern const char test_llvm__bpf_test_kbuild_prog[]; + +enum test_llvm__testcase { +LLVM_TESTCASE_BASE , +LLVM_TESTCASE_KBUILD , +NR_LLVM_TESTCASES , +}; +void test_llvm__fetch_bpf_obj (void **p_obj_buf,size_t *p_obj_buf_sz,int index);#endif
Signature · 1 line
2.1.0
PATCH 27/27 perf test: Test BPF prologue
In reply to Wang NanThis patch introduces a new BPF script to test BPF prologue. The new script probes at null_lseek, which is the function pointer when we try to lseek on '/dev/null'.
null_lseek is chosen because it is a function pointer, so we don't need to consider inlining and LTP.
By extracting file->f_mode, bpf-script-test-prologue.c should know whether the file is writable or readonly. According to llseek_loop() and bpf-script-test-prologue.c, one forth of total lseeks should be collected.
This patch improve test__bpf so it can run multiple BPF programs on different test functions.
--- tools/perf/tests/Build | 9 ++- tools/perf/tests/bpf-script-test-prologue.c | 35 +++++++++++ tools/perf/tests/bpf.c | 93 +++++++++++++++++++++++------ tools/perf/tests/llvm.c | 5 ++ tools/perf/tests/llvm.h | 8 +++ 5 files changed, 130 insertions(+), 20 deletions(-) create mode 100644 tools/perf/tests/bpf-script-test-prologue.c
tools/perf/tests/Build +8 -1
@@ -32,7 +32,7 @@ perf-y += sample-parsing.o perf-y += parse-no-sample-id-all.o perf-y += kmod-path.o perf-y += thread-map.o -perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o +perf-y += llvm.o llvm-src-base.o llvm-src-kbuild.o llvm-src-prologue.o perf-y += bpf.o perf-y += topology.o
@@ -50,6 +50,13 @@ $(OUTPUT)tests/llvm-src-kbuild.c: tests/bpf-script-test-kbuild.c $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ $(Q)echo ';' >> $@ +$(OUTPUT)tests/llvm-src-prologue.c: tests/bpf-script-test-prologue.c + $(call rule_mkdir) + $(Q)echo '#include <tests/llvm.h>' > $@ + $(Q)echo 'const char test_llvm__bpf_test_prologue_prog[] =' >> $@ + $(Q)sed -e 's/"/\\"/g' -e 's/\(.*\)/"\1\\n"/g' $< >> $@ + $(Q)echo ';' >> $@ + perf-$(CONFIG_X86) += perf-time-to-tsc.o ifdef CONFIG_AUXTRACE perf-$(CONFIG_X86) += insn-x86.o
tools/perf/tests/bpf-script-test-prologue.c new file +35 -0
@@ -0,0 +1,35 @@ +/* +* bpf-script-test-prologue.c +* Test BPF prologue +*/ +#ifndef LINUX_VERSION_CODE +# error Need LINUX_VERSION_CODE +# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig' +#endif +#define SEC (NAME ) __attribute__((section(NAME), used)) + +#include <uapi/linux/fs.h> + +#define FMODE_READ 0x1 +#define FMODE_WRITE 0x2 + +static void (*bpf_trace_printk)(const char *fmt,int fmt_size, ...) = + (void *)6 ; + +SEC("func=null_lseek file->f_mode offset orig") +int bpf_func__null_lseek (void *ctx,int err,unsigned long f_mode, +unsigned long offset,unsigned long orig) +{ +if (err) +return 0 ; +if (f_mode &FMODE_WRITE ) +return 0 ; +if (offset &1 ) +return 0 ; +if (orig ==SEEK_CUR ) +return 0 ; +return 1 ; +} + +char _license[] SEC("license") = "GPL"; +int _version SEC("version") = LINUX_VERSION_CODE;
tools/perf/tests/bpf.c +74 -19
146 lines not on this page · raw message
tools/perf/tests/llvm.c +5 -0
@@ -22,6 +22,11 @@ struct llvm_testcase { [LLVM_TESTCASE_KBUILD ] = {.source = test_llvm__bpf_test_kbuild_prog, .errmsg ="llvm.kbuild-dir can be fixed" , .tried = false}, + /* Don't output if this one fail. */ + [LLVM_TESTCASE_BPF_PROLOGUE ] = { + .source = test_llvm__bpf_test_prologue_prog, + .errmsg ="failed for unknown reason" , + .tried = false}, {.source = NULL} };
tools/perf/tests/llvm.h +8 -0
@@ -10,10 +10,18 @@ struct test_llvm__bpf_result {extern const char test_llvm__bpf_prog[];extern const char test_llvm__bpf_test_kbuild_prog[]; +extern const char test_llvm__bpf_test_prologue_prog[];enum test_llvm__testcase {LLVM_TESTCASE_BASE ,LLVM_TESTCASE_KBUILD , +/* +* We must put LLVM_TESTCASE_BPF_PROLOGUE after +* LLVM_TESTCASE_KBUILD, so if kbuild test failed, +* don't need to try this one, because it depend on +* kernel header. +*/ +LLVM_TESTCASE_BPF_PROLOGUE ,NR_LLVM_TESTCASES , };void test_llvm__fetch_bpf_obj (void **p_obj_buf,size_t *p_obj_buf_sz,int index);
Signature · 1 line
2.1.0