Skip to content

Commit 3d6dfae

Browse files
captain5050acmel
authored andcommitted
perf parse-events: Remove BPF event support
New features like the BPF --filter support in perf record have made the BPF event functionality somewhat redundant. As shown by commit fcb027c1a4f6 ("perf tools: Revert enable indices setting syntax for BPF map") and commit 14e4b9f ("perf trace: Raw augmented syscalls fix libbpf 1.0+ compatibility") the BPF event support hasn't been well maintained and it adds considerable complexity in areas like event parsing, not least as '/' is a separator for event modifiers as well as in paths. This patch removes support in the event parser for BPF events and then the associated functions are removed. This leads to the removal of whole source files like bpf-loader.c. Removing support means that augmented syscalls in perf trace is broken, this will be fixed in a later commit adding support using BPF skeletons. The removal of BPF events causes an unused label warning from flex generated code, so update build to ignore it: ``` util/parse-events-flex.c:2704:1: error: label ‘find_rule’ defined but not used [-Werror=unused-label] 2704 | find_rule: /* we branch to this label when backing up */ ``` Committer notes: Extracted from a larger patch that was also removing the support for linking with libllvm and libclang, that were an alternative to using an external clang execution to compile the .c event source code into BPF bytecode. Testing it: # perf trace -e /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.c event syntax error: '/home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.c' \___ Bad event or PMU Unabled to find PMU or event on a PMU of 'home' Initial error: event syntax error: '/home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.c' \___ Cannot find PMU `home'. Missing kernel support? Run 'perf list' for a list of valid events Usage: perf trace [<options>] [<command>] or: perf trace [<options>] -- <command> [<options>] or: perf trace record [<options>] [<command>] or: perf trace record [<options>] -- <command> [<options>] -e, --event <event> event/syscall selector. use 'perf list' to list available events # Signed-off-by: Ian Rogers <[email protected]> Acked-by: Jiri Olsa <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Anshuman Khandual <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Brendan Gregg <[email protected]> Cc: Carsten Haitzler <[email protected]> Cc: Eduard Zingerman <[email protected]> Cc: Fangrui Song <[email protected]> Cc: He Kuang <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Kan Liang <[email protected]> Cc: Leo Yan <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Naveen N. Rao <[email protected]> Cc: Nick Desaulniers <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Rob Herring <[email protected]> Cc: Tiezhu Yang <[email protected]> Cc: Tom Rix <[email protected]> Cc: Wang Nan <[email protected]> Cc: Wang ShaoBo <[email protected]> Cc: Yang Jihong <[email protected]> Cc: Yonghong Song <[email protected]> Cc: YueHaibing <[email protected]> Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 56b11a2 commit 3d6dfae

27 files changed

+3
-4381
lines changed

tools/perf/Documentation/perf-config.txt

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ Given a $HOME/.perfconfig like this:
125125
group = true
126126
skip-empty = true
127127

128-
[llvm]
129-
dump-obj = true
130-
clang-opt = -g
131128

132129
You can hide source code of annotate feature setting the config to false with
133130

@@ -657,36 +654,6 @@ ftrace.*::
657654
-F option is not specified. Possible values are 'function' and
658655
'function_graph'.
659656

660-
llvm.*::
661-
llvm.clang-path::
662-
Path to clang. If omit, search it from $PATH.
663-
664-
llvm.clang-bpf-cmd-template::
665-
Cmdline template. Below lines show its default value. Environment
666-
variable is used to pass options.
667-
"$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
668-
"-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \
669-
"$CLANG_OPTIONS $PERF_BPF_INC_OPTIONS $KERNEL_INC_OPTIONS " \
670-
"-Wno-unused-value -Wno-pointer-sign " \
671-
"-working-directory $WORKING_DIR " \
672-
"-c \"$CLANG_SOURCE\" --target=bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE"
673-
674-
llvm.clang-opt::
675-
Options passed to clang.
676-
677-
llvm.kbuild-dir::
678-
kbuild directory. If not set, use /lib/modules/`uname -r`/build.
679-
If set to "" deliberately, skip kernel header auto-detector.
680-
681-
llvm.kbuild-opts::
682-
Options passed to 'make' when detecting kernel header options.
683-
684-
llvm.dump-obj::
685-
Enable perf dump BPF object files compiled by LLVM.
686-
687-
llvm.opts::
688-
Options passed to llc.
689-
690657
samples.*::
691658

692659
samples.context::

tools/perf/Documentation/perf-record.txt

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,6 @@ OPTIONS
9999
If you want to profile write accesses in [0x1000~1008), just set
100100
'mem:0x1000/8:w'.
101101

102-
- a BPF source file (ending in .c) or a precompiled object file (ending
103-
in .o) selects one or more BPF events.
104-
The BPF program can attach to various perf events based on the ELF section
105-
names.
106-
107-
When processing a '.c' file, perf searches an installed LLVM to compile it
108-
into an object file first. Optional clang options can be passed via the
109-
'--clang-opt' command line option, e.g.:
110-
111-
perf record --clang-opt "-DLINUX_VERSION_CODE=0x50000" \
112-
-e tests/bpf-script-example.c
113-
114-
Note: '--clang-opt' must be placed before '--event/-e'.
115-
116102
- a group of events surrounded by a pair of brace ("{event1,event2,...}").
117103
Each event is separated by commas and the group should be quoted to
118104
prevent the shell interpretation. You also need to use --group on
@@ -547,14 +533,6 @@ PERF_RECORD_SWITCH_CPU_WIDE. In some cases (e.g. Intel PT, CoreSight or Arm SPE)
547533
switch events will be enabled automatically, which can be suppressed by
548534
by the option --no-switch-events.
549535

550-
--clang-path=PATH::
551-
Path to clang binary to use for compiling BPF scriptlets.
552-
(enabled when BPF support is on)
553-
554-
--clang-opt=OPTIONS::
555-
Options passed to clang when compiling BPF scriptlets.
556-
(enabled when BPF support is on)
557-
558536
--vmlinux=PATH::
559537
Specify vmlinux path which has debuginfo.
560538
(enabled when BPF prologue is on)

tools/perf/Makefile.config

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -589,18 +589,6 @@ ifndef NO_LIBELF
589589
LIBBPF_STATIC := 1
590590
endif
591591
endif
592-
593-
ifndef NO_DWARF
594-
ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
595-
CFLAGS += -DHAVE_BPF_PROLOGUE
596-
$(call detected,CONFIG_BPF_PROLOGUE)
597-
else
598-
msg := $(warning BPF prologue is not supported by architecture $(SRCARCH), missing regs_query_register_offset());
599-
endif
600-
else
601-
msg := $(warning DWARF support is off, BPF prologue is disabled);
602-
endif
603-
604592
endif # NO_LIBBPF
605593
endif # NO_LIBELF
606594

tools/perf/builtin-record.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#include "util/parse-branch-options.h"
3838
#include "util/parse-regs-options.h"
3939
#include "util/perf_api_probe.h"
40-
#include "util/llvm-utils.h"
41-
#include "util/bpf-loader.h"
4240
#include "util/trigger.h"
4341
#include "util/perf-hooks.h"
4442
#include "util/cpu-set-sched.h"
@@ -2465,16 +2463,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
24652463
}
24662464
}
24672465

2468-
err = bpf__apply_obj_config();
2469-
if (err) {
2470-
char errbuf[BUFSIZ];
2471-
2472-
bpf__strerror_apply_obj_config(err, errbuf, sizeof(errbuf));
2473-
pr_err("ERROR: Apply config to BPF failed: %s\n",
2474-
errbuf);
2475-
goto out_free_threads;
2476-
}
2477-
24782466
/*
24792467
* Normally perf_session__new would do this, but it doesn't have the
24802468
* evlist.
@@ -3486,10 +3474,6 @@ static struct option __record_options[] = {
34863474
"collect kernel callchains"),
34873475
OPT_BOOLEAN(0, "user-callchains", &record.opts.user_callchains,
34883476
"collect user callchains"),
3489-
OPT_STRING(0, "clang-path", &llvm_param.clang_path, "clang path",
3490-
"clang binary to use for compiling BPF scriptlets"),
3491-
OPT_STRING(0, "clang-opt", &llvm_param.clang_opt, "clang options",
3492-
"options passed to clang when compiling BPF scriptlets"),
34933477
OPT_STRING(0, "vmlinux", &symbol_conf.vmlinux_name,
34943478
"file", "vmlinux pathname"),
34953479
OPT_BOOLEAN(0, "buildid-all", &record.buildid_all,
@@ -3967,27 +3951,6 @@ int cmd_record(int argc, const char **argv)
39673951

39683952
setlocale(LC_ALL, "");
39693953

3970-
#ifndef HAVE_LIBBPF_SUPPORT
3971-
# define set_nobuild(s, l, c) set_option_nobuild(record_options, s, l, "NO_LIBBPF=1", c)
3972-
set_nobuild('\0', "clang-path", true);
3973-
set_nobuild('\0', "clang-opt", true);
3974-
# undef set_nobuild
3975-
#endif
3976-
3977-
#ifndef HAVE_BPF_PROLOGUE
3978-
# if !defined (HAVE_DWARF_SUPPORT)
3979-
# define REASON "NO_DWARF=1"
3980-
# elif !defined (HAVE_LIBBPF_SUPPORT)
3981-
# define REASON "NO_LIBBPF=1"
3982-
# else
3983-
# define REASON "this architecture doesn't support BPF prologue"
3984-
# endif
3985-
# define set_nobuild(s, l, c) set_option_nobuild(record_options, s, l, REASON, c)
3986-
set_nobuild('\0', "vmlinux", true);
3987-
# undef set_nobuild
3988-
# undef REASON
3989-
#endif
3990-
39913954
#ifndef HAVE_BPF_SKEL
39923955
# define set_nobuild(s, l, m, c) set_option_nobuild(record_options, s, l, m, c)
39933956
set_nobuild('\0', "off-cpu", "no BUILD_BPF_SKEL=1", true);
@@ -4116,14 +4079,6 @@ int cmd_record(int argc, const char **argv)
41164079
if (dry_run)
41174080
goto out;
41184081

4119-
err = bpf__setup_stdout(rec->evlist);
4120-
if (err) {
4121-
bpf__strerror_setup_stdout(rec->evlist, err, errbuf, sizeof(errbuf));
4122-
pr_err("ERROR: Setup BPF stdout failed: %s\n",
4123-
errbuf);
4124-
goto out;
4125-
}
4126-
41274082
err = -ENOMEM;
41284083

41294084
if (rec->no_buildid_cache || rec->no_buildid) {

tools/perf/builtin-trace.c

Lines changed: 1 addition & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <api/fs/tracing_path.h>
1919
#ifdef HAVE_LIBBPF_SUPPORT
2020
#include <bpf/bpf.h>
21+
#include <bpf/libbpf.h>
2122
#endif
2223
#include "util/bpf_map.h"
2324
#include "util/rlimit.h"
@@ -53,7 +54,6 @@
5354
#include "trace/beauty/beauty.h"
5455
#include "trace-event.h"
5556
#include "util/parse-events.h"
56-
#include "util/bpf-loader.h"
5757
#include "util/tracepoint.h"
5858
#include "callchain.h"
5959
#include "print_binary.h"
@@ -3287,17 +3287,6 @@ static struct bpf_map *trace__find_bpf_map_by_name(struct trace *trace, const ch
32873287
return bpf_object__find_map_by_name(trace->bpf_obj, name);
32883288
}
32893289

3290-
static void trace__set_bpf_map_filtered_pids(struct trace *trace)
3291-
{
3292-
trace->filter_pids.map = trace__find_bpf_map_by_name(trace, "pids_filtered");
3293-
}
3294-
3295-
static void trace__set_bpf_map_syscalls(struct trace *trace)
3296-
{
3297-
trace->syscalls.prog_array.sys_enter = trace__find_bpf_map_by_name(trace, "syscalls_sys_enter");
3298-
trace->syscalls.prog_array.sys_exit = trace__find_bpf_map_by_name(trace, "syscalls_sys_exit");
3299-
}
3300-
33013290
static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace, const char *name)
33023291
{
33033292
struct bpf_program *pos, *prog = NULL;
@@ -3553,71 +3542,19 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
35533542
return err;
35543543
}
35553544

3556-
static void trace__delete_augmented_syscalls(struct trace *trace)
3557-
{
3558-
struct evsel *evsel, *tmp;
3559-
3560-
evlist__remove(trace->evlist, trace->syscalls.events.augmented);
3561-
evsel__delete(trace->syscalls.events.augmented);
3562-
trace->syscalls.events.augmented = NULL;
3563-
3564-
evlist__for_each_entry_safe(trace->evlist, tmp, evsel) {
3565-
if (evsel->bpf_obj == trace->bpf_obj) {
3566-
evlist__remove(trace->evlist, evsel);
3567-
evsel__delete(evsel);
3568-
}
3569-
3570-
}
3571-
3572-
bpf_object__close(trace->bpf_obj);
3573-
trace->bpf_obj = NULL;
3574-
}
35753545
#else // HAVE_LIBBPF_SUPPORT
35763546
static struct bpf_map *trace__find_bpf_map_by_name(struct trace *trace __maybe_unused,
35773547
const char *name __maybe_unused)
35783548
{
35793549
return NULL;
35803550
}
35813551

3582-
static void trace__set_bpf_map_filtered_pids(struct trace *trace __maybe_unused)
3583-
{
3584-
}
3585-
3586-
static void trace__set_bpf_map_syscalls(struct trace *trace __maybe_unused)
3587-
{
3588-
}
3589-
3590-
static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace __maybe_unused,
3591-
const char *name __maybe_unused)
3592-
{
3593-
return NULL;
3594-
}
3595-
35963552
static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace __maybe_unused)
35973553
{
35983554
return 0;
35993555
}
3600-
3601-
static void trace__delete_augmented_syscalls(struct trace *trace __maybe_unused)
3602-
{
3603-
}
36043556
#endif // HAVE_LIBBPF_SUPPORT
36053557

3606-
static bool trace__only_augmented_syscalls_evsels(struct trace *trace)
3607-
{
3608-
struct evsel *evsel;
3609-
3610-
evlist__for_each_entry(trace->evlist, evsel) {
3611-
if (evsel == trace->syscalls.events.augmented ||
3612-
evsel->bpf_obj == trace->bpf_obj)
3613-
continue;
3614-
3615-
return false;
3616-
}
3617-
3618-
return true;
3619-
}
3620-
36213558
static int trace__set_ev_qualifier_filter(struct trace *trace)
36223559
{
36233560
if (trace->syscalls.events.sys_enter)
@@ -3981,16 +3918,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
39813918
if (err < 0)
39823919
goto out_error_open;
39833920

3984-
err = bpf__apply_obj_config();
3985-
if (err) {
3986-
char errbuf[BUFSIZ];
3987-
3988-
bpf__strerror_apply_obj_config(err, errbuf, sizeof(errbuf));
3989-
pr_err("ERROR: Apply config to BPF failed: %s\n",
3990-
errbuf);
3991-
goto out_error_open;
3992-
}
3993-
39943921
err = trace__set_filter_pids(trace);
39953922
if (err < 0)
39963923
goto out_error_mem;
@@ -4922,77 +4849,6 @@ int cmd_trace(int argc, const char **argv)
49224849
"cgroup monitoring only available in system-wide mode");
49234850
}
49244851

4925-
evsel = bpf__setup_output_event(trace.evlist, "__augmented_syscalls__");
4926-
if (IS_ERR(evsel)) {
4927-
bpf__strerror_setup_output_event(trace.evlist, PTR_ERR(evsel), bf, sizeof(bf));
4928-
pr_err("ERROR: Setup trace syscalls enter failed: %s\n", bf);
4929-
goto out;
4930-
}
4931-
4932-
if (evsel) {
4933-
trace.syscalls.events.augmented = evsel;
4934-
4935-
evsel = evlist__find_tracepoint_by_name(trace.evlist, "raw_syscalls:sys_enter");
4936-
if (evsel == NULL) {
4937-
pr_err("ERROR: raw_syscalls:sys_enter not found in the augmented BPF object\n");
4938-
goto out;
4939-
}
4940-
4941-
if (evsel->bpf_obj == NULL) {
4942-
pr_err("ERROR: raw_syscalls:sys_enter not associated to a BPF object\n");
4943-
goto out;
4944-
}
4945-
4946-
trace.bpf_obj = evsel->bpf_obj;
4947-
4948-
/*
4949-
* If we have _just_ the augmenter event but don't have a
4950-
* explicit --syscalls, then assume we want all strace-like
4951-
* syscalls:
4952-
*/
4953-
if (!trace.trace_syscalls && trace__only_augmented_syscalls_evsels(&trace))
4954-
trace.trace_syscalls = true;
4955-
/*
4956-
* So, if we have a syscall augmenter, but trace_syscalls, aka
4957-
* strace-like syscall tracing is not set, then we need to trow
4958-
* away the augmenter, i.e. all the events that were created
4959-
* from that BPF object file.
4960-
*
4961-
* This is more to fix the current .perfconfig trace.add_events
4962-
* style of setting up the strace-like eBPF based syscall point
4963-
* payload augmenter.
4964-
*
4965-
* All this complexity will be avoided by adding an alternative
4966-
* to trace.add_events in the form of
4967-
* trace.bpf_augmented_syscalls, that will be only parsed if we
4968-
* need it.
4969-
*
4970-
* .perfconfig trace.add_events is still useful if we want, for
4971-
* instance, have msr_write.msr in some .perfconfig profile based
4972-
* 'perf trace --config determinism.profile' mode, where for some
4973-
* particular goal/workload type we want a set of events and
4974-
* output mode (with timings, etc) instead of having to add
4975-
* all via the command line.
4976-
*
4977-
* Also --config to specify an alternate .perfconfig file needs
4978-
* to be implemented.
4979-
*/
4980-
if (!trace.trace_syscalls) {
4981-
trace__delete_augmented_syscalls(&trace);
4982-
} else {
4983-
trace__set_bpf_map_filtered_pids(&trace);
4984-
trace__set_bpf_map_syscalls(&trace);
4985-
trace.syscalls.unaugmented_prog = trace__find_bpf_program_by_title(&trace, "!raw_syscalls:unaugmented");
4986-
}
4987-
}
4988-
4989-
err = bpf__setup_stdout(trace.evlist);
4990-
if (err) {
4991-
bpf__strerror_setup_stdout(trace.evlist, err, bf, sizeof(bf));
4992-
pr_err("ERROR: Setup BPF stdout failed: %s\n", bf);
4993-
goto out;
4994-
}
4995-
49964852
err = -1;
49974853

49984854
if (map_dump_str) {

tools/perf/perf.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <subcmd/run-command.h>
1919
#include "util/parse-events.h"
2020
#include <subcmd/parse-options.h>
21-
#include "util/bpf-loader.h"
2221
#include "util/debug.h"
2322
#include "util/event.h"
2423
#include "util/util.h" // usage()
@@ -324,7 +323,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
324323
perf_config__exit();
325324
exit_browser(status);
326325
perf_env__exit(&perf_env);
327-
bpf__clear();
328326

329327
if (status)
330328
return status & 0xff;

0 commit comments

Comments
 (0)