* [PATCH v1 0/4] Remove BPF event support
@ 2023-08-10 18:48 Ian Rogers
2023-08-10 18:48 ` [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton Ian Rogers
` (4 more replies)
0 siblings, 5 replies; 22+ messages in thread
From: Ian Rogers @ 2023-08-10 18:48 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Adrian Hunter, Nathan Chancellor, Nick Desaulniers, Tom Rix,
Fangrui Song, Anshuman Khandual, Andi Kleen, Leo Yan,
Madhavan Srinivasan, Carsten Haitzler, Ravi Bangoria,
Naveen N. Rao, Athira Rajeev, Kan Liang, Yang Jihong, James Clark,
Tiezhu Yang, Eduard Zingerman, Andrii Nakryiko, Yonghong Song,
Rob Herring, linux-kernel, linux-perf-users, bpf, llvm, Wang Nan,
Wang ShaoBo, YueHaibing, He Kuang, Brendan Gregg
Cc: Ian Rogers
The patch series removes BPF event support as past commits have shown
the support has bit rotten:
https://lore.kernel.org/lkml/20230728001212.457900-1-irogers@google.com/
Similar functionality is now available via the --filter option, that
uses a BPF skeleton, and is therefore more compact and simpler to
use. The simplicity coming from not having to build BPF object files.
A different use case for the events was for syscall augmentation in
perf trace. So that this isn't broken, and to make its use
significantly simpler, the support is migrated to use a BPF
skeleton. This means perf trace is much more likely to augment
syscalls for users.
Removal of BPF events was raised on LKML two weeks ago with the
original authors cc-ed:
https://lore.kernel.org/lkml/CAP-5=fXxGimJRXKf7bcaPqfjxxGcn1k3CspY_iSjQnpAKs3uFQ@mail.gmail.com/
BPF events are described publicly in very few places but one is:
https://www.brendangregg.com/perf.html#eBPF
"eBPF is currently a little restricted and difficult to use from
perf. It's getting better all the time. A different and currently
easier way to access eBPF is via the bcc Python interface, which is
described on my eBPF Tools page. On this page, I'll discuss perf."
I don't think the "getting better all the time" is any longer true as
BPF features are being added to perf primarily by using BPF
skeletons. The given example is a filter and would be better supported
via "perf record --filter".
Ian Rogers (4):
perf parse-events: Remove BPF event support
perf trace: Migrate BPF augmentation to use a skeleton
perf bpf examples: With no BPF events remove examples
perf trace: Tidy comments
tools/perf/Documentation/perf-config.txt | 33 -
tools/perf/Documentation/perf-record.txt | 22 -
tools/perf/Makefile.config | 43 -
tools/perf/Makefile.perf | 19 +-
tools/perf/builtin-record.c | 45 -
tools/perf/builtin-trace.c | 310 +--
tools/perf/examples/bpf/5sec.c | 53 -
tools/perf/examples/bpf/empty.c | 12 -
tools/perf/examples/bpf/hello.c | 27 -
tools/perf/examples/bpf/sys_enter_openat.c | 33 -
tools/perf/perf.c | 2 -
tools/perf/tests/.gitignore | 5 -
tools/perf/tests/Build | 31 -
tools/perf/tests/bpf-script-example.c | 60 -
tools/perf/tests/bpf-script-test-kbuild.c | 21 -
tools/perf/tests/bpf-script-test-prologue.c | 49 -
tools/perf/tests/bpf-script-test-relocation.c | 51 -
tools/perf/tests/bpf.c | 390 ----
tools/perf/tests/builtin-test.c | 3 -
tools/perf/tests/clang.c | 32 -
tools/perf/tests/llvm.c | 219 --
tools/perf/tests/llvm.h | 31 -
tools/perf/tests/make | 2 -
tools/perf/tests/tests.h | 2 -
tools/perf/trace/beauty/beauty.h | 15 +-
tools/perf/util/Build | 8 +-
tools/perf/util/bpf-loader.c | 2006 -----------------
tools/perf/util/bpf-loader.h | 216 --
.../bpf_skel/augmented_raw_syscalls.bpf.c} | 35 +-
tools/perf/util/c++/Build | 5 -
tools/perf/util/c++/clang-c.h | 43 -
tools/perf/util/c++/clang-test.cpp | 67 -
tools/perf/util/c++/clang.cpp | 225 --
tools/perf/util/c++/clang.h | 27 -
tools/perf/util/config.c | 4 -
tools/perf/util/llvm-utils.c | 612 -----
tools/perf/util/llvm-utils.h | 69 -
tools/perf/util/parse-events.c | 268 ---
tools/perf/util/parse-events.h | 15 -
tools/perf/util/parse-events.l | 31 -
tools/perf/util/parse-events.y | 44 +-
41 files changed, 133 insertions(+), 5052 deletions(-)
delete mode 100644 tools/perf/examples/bpf/5sec.c
delete mode 100644 tools/perf/examples/bpf/empty.c
delete mode 100644 tools/perf/examples/bpf/hello.c
delete mode 100644 tools/perf/examples/bpf/sys_enter_openat.c
delete mode 100644 tools/perf/tests/.gitignore
delete mode 100644 tools/perf/tests/bpf-script-example.c
delete mode 100644 tools/perf/tests/bpf-script-test-kbuild.c
delete mode 100644 tools/perf/tests/bpf-script-test-prologue.c
delete mode 100644 tools/perf/tests/bpf-script-test-relocation.c
delete mode 100644 tools/perf/tests/bpf.c
delete mode 100644 tools/perf/tests/clang.c
delete mode 100644 tools/perf/tests/llvm.c
delete mode 100644 tools/perf/tests/llvm.h
delete mode 100644 tools/perf/util/bpf-loader.c
delete mode 100644 tools/perf/util/bpf-loader.h
rename tools/perf/{examples/bpf/augmented_raw_syscalls.c => util/bpf_skel/augmented_raw_syscalls.bpf.c} (93%)
delete mode 100644 tools/perf/util/c++/Build
delete mode 100644 tools/perf/util/c++/clang-c.h
delete mode 100644 tools/perf/util/c++/clang-test.cpp
delete mode 100644 tools/perf/util/c++/clang.cpp
delete mode 100644 tools/perf/util/c++/clang.h
delete mode 100644 tools/perf/util/llvm-utils.c
delete mode 100644 tools/perf/util/llvm-utils.h
--
2.41.0.640.ga95def55d0-goog
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton
2023-08-10 18:48 [PATCH v1 0/4] Remove BPF event support Ian Rogers
@ 2023-08-10 18:48 ` Ian Rogers
2023-08-11 16:09 ` Jiri Olsa
` (2 more replies)
2023-08-10 18:48 ` [PATCH v1 3/4] perf bpf examples: With no BPF events remove examples Ian Rogers
` (3 subsequent siblings)
4 siblings, 3 replies; 22+ messages in thread
From: Ian Rogers @ 2023-08-10 18:48 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Adrian Hunter, Nathan Chancellor, Nick Desaulniers, Tom Rix,
Fangrui Song, Anshuman Khandual, Andi Kleen, Leo Yan,
Madhavan Srinivasan, Carsten Haitzler, Ravi Bangoria,
Naveen N. Rao, Athira Rajeev, Kan Liang, Yang Jihong, James Clark,
Tiezhu Yang, Eduard Zingerman, Andrii Nakryiko, Yonghong Song,
Rob Herring, linux-kernel, linux-perf-users, bpf, llvm, Wang Nan,
Wang ShaoBo, YueHaibing, He Kuang, Brendan Gregg
Cc: Ian Rogers
Previously a BPF event of augmented_raw_syscalls.c could be used to
enable augmentation of syscalls by perf trace. As BPF events are no
longer supported, switch to using a BPF skeleton which when attached
explicitly opens the sysenter and sysexit tracepoints.
The dump map is removed as debugging wasn't supported by the
augmentation and bpf_printk can be used when necessary.
Remove tools/perf/examples/bpf/augmented_raw_syscalls.c so that the
rename/migration to a BPF skeleton captures that this was the source.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/Makefile.perf | 1 +
tools/perf/builtin-trace.c | 180 +++++++++++-------
.../bpf_skel/augmented_raw_syscalls.bpf.c} | 27 +--
3 files changed, 131 insertions(+), 77 deletions(-)
rename tools/perf/{examples/bpf/augmented_raw_syscalls.c => util/bpf_skel/augmented_raw_syscalls.bpf.c} (96%)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 6ec5079fd697..0e1597712b95 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -1042,6 +1042,7 @@ SKELETONS += $(SKEL_OUT)/bperf_cgroup.skel.h $(SKEL_OUT)/func_latency.skel.h
SKELETONS += $(SKEL_OUT)/off_cpu.skel.h $(SKEL_OUT)/lock_contention.skel.h
SKELETONS += $(SKEL_OUT)/kwork_trace.skel.h $(SKEL_OUT)/sample_filter.skel.h
SKELETONS += $(SKEL_OUT)/bench_uprobe.skel.h
+SKELETONS += $(SKEL_OUT)/augmented_raw_syscalls.skel.h
$(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT):
$(Q)$(MKDIR) -p $@
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 59862467e781..8625fca42cd8 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -19,6 +19,9 @@
#ifdef HAVE_LIBBPF_SUPPORT
#include <bpf/bpf.h>
#include <bpf/libbpf.h>
+#ifdef HAVE_BPF_SKEL
+#include "bpf_skel/augmented_raw_syscalls.skel.h"
+#endif
#endif
#include "util/bpf_map.h"
#include "util/rlimit.h"
@@ -127,25 +130,19 @@ struct trace {
struct syscalltbl *sctbl;
struct {
struct syscall *table;
- struct { // per syscall BPF_MAP_TYPE_PROG_ARRAY
- struct bpf_map *sys_enter,
- *sys_exit;
- } prog_array;
struct {
struct evsel *sys_enter,
- *sys_exit,
- *augmented;
+ *sys_exit,
+ *bpf_output;
} events;
- struct bpf_program *unaugmented_prog;
} syscalls;
- struct {
- struct bpf_map *map;
- } dump;
+#ifdef HAVE_BPF_SKEL
+ struct augmented_raw_syscalls_bpf *skel;
+#endif
struct record_opts opts;
struct evlist *evlist;
struct machine *host;
struct thread *current;
- struct bpf_object *bpf_obj;
struct cgroup *cgroup;
u64 base_time;
FILE *output;
@@ -415,6 +412,7 @@ static int evsel__init_syscall_tp(struct evsel *evsel)
if (evsel__init_tp_uint_field(evsel, &sc->id, "__syscall_nr") &&
evsel__init_tp_uint_field(evsel, &sc->id, "nr"))
return -ENOENT;
+
return 0;
}
@@ -2845,7 +2843,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,
if (thread)
trace__fprintf_comm_tid(trace, thread, trace->output);
- if (evsel == trace->syscalls.events.augmented) {
+ if (evsel == trace->syscalls.events.bpf_output) {
int id = perf_evsel__sc_tp_uint(evsel, id, sample);
struct syscall *sc = trace__syscall_info(trace, evsel, id);
@@ -3278,24 +3276,16 @@ static int trace__set_ev_qualifier_tp_filter(struct trace *trace)
goto out;
}
-#ifdef HAVE_LIBBPF_SUPPORT
-static struct bpf_map *trace__find_bpf_map_by_name(struct trace *trace, const char *name)
-{
- if (trace->bpf_obj == NULL)
- return NULL;
-
- return bpf_object__find_map_by_name(trace->bpf_obj, name);
-}
-
+#ifdef HAVE_BPF_SKEL
static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace, const char *name)
{
struct bpf_program *pos, *prog = NULL;
const char *sec_name;
- if (trace->bpf_obj == NULL)
+ if (trace->skel->obj == NULL)
return NULL;
- bpf_object__for_each_program(pos, trace->bpf_obj) {
+ bpf_object__for_each_program(pos, trace->skel->obj) {
sec_name = bpf_program__section_name(pos);
if (sec_name && !strcmp(sec_name, name)) {
prog = pos;
@@ -3313,12 +3303,14 @@ static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, str
if (prog_name == NULL) {
char default_prog_name[256];
- scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->name);
+ scnprintf(default_prog_name, sizeof(default_prog_name), "tp/syscalls/sys_%s_%s",
+ type, sc->name);
prog = trace__find_bpf_program_by_title(trace, default_prog_name);
if (prog != NULL)
goto out_found;
if (sc->fmt && sc->fmt->alias) {
- scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->fmt->alias);
+ scnprintf(default_prog_name, sizeof(default_prog_name),
+ "tp/syscalls/sys_%s_%s", type, sc->fmt->alias);
prog = trace__find_bpf_program_by_title(trace, default_prog_name);
if (prog != NULL)
goto out_found;
@@ -3336,7 +3328,7 @@ static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, str
pr_debug("Couldn't find BPF prog \"%s\" to associate with syscalls:sys_%s_%s, not augmenting it\n",
prog_name, type, sc->name);
out_unaugmented:
- return trace->syscalls.unaugmented_prog;
+ return trace->skel->progs.syscall_unaugmented;
}
static void trace__init_syscall_bpf_progs(struct trace *trace, int id)
@@ -3353,13 +3345,21 @@ static void trace__init_syscall_bpf_progs(struct trace *trace, int id)
static int trace__bpf_prog_sys_enter_fd(struct trace *trace, int id)
{
struct syscall *sc = trace__syscall_info(trace, NULL, id);
- return sc ? bpf_program__fd(sc->bpf_prog.sys_enter) : bpf_program__fd(trace->syscalls.unaugmented_prog);
+
+ if (sc)
+ return bpf_program__fd(sc->bpf_prog.sys_enter);
+
+ return bpf_program__fd(trace->skel->progs.syscall_unaugmented);
}
static int trace__bpf_prog_sys_exit_fd(struct trace *trace, int id)
{
struct syscall *sc = trace__syscall_info(trace, NULL, id);
- return sc ? bpf_program__fd(sc->bpf_prog.sys_exit) : bpf_program__fd(trace->syscalls.unaugmented_prog);
+
+ if (sc)
+ return bpf_program__fd(sc->bpf_prog.sys_exit);
+
+ return bpf_program__fd(trace->skel->progs.syscall_unaugmented);
}
static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace, struct syscall *sc)
@@ -3384,7 +3384,7 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace
bool is_candidate = false;
if (pair == NULL || pair == sc ||
- pair->bpf_prog.sys_enter == trace->syscalls.unaugmented_prog)
+ pair->bpf_prog.sys_enter == trace->skel->progs.syscall_unaugmented)
continue;
for (field = sc->args, candidate_field = pair->args;
@@ -3437,7 +3437,7 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace
*/
if (pair_prog == NULL) {
pair_prog = trace__find_syscall_bpf_prog(trace, pair, pair->fmt ? pair->fmt->bpf_prog_name.sys_enter : NULL, "enter");
- if (pair_prog == trace->syscalls.unaugmented_prog)
+ if (pair_prog == trace->skel->progs.syscall_unaugmented)
goto next_candidate;
}
@@ -3452,8 +3452,8 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace
static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
{
- int map_enter_fd = bpf_map__fd(trace->syscalls.prog_array.sys_enter),
- map_exit_fd = bpf_map__fd(trace->syscalls.prog_array.sys_exit);
+ int map_enter_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_enter);
+ int map_exit_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_exit);
int err = 0, key;
for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
@@ -3515,7 +3515,7 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
* For now we're just reusing the sys_enter prog, and if it
* already has an augmenter, we don't need to find one.
*/
- if (sc->bpf_prog.sys_enter != trace->syscalls.unaugmented_prog)
+ if (sc->bpf_prog.sys_enter != trace->skel->progs.syscall_unaugmented)
continue;
/*
@@ -3538,22 +3538,9 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
break;
}
-
return err;
}
-
-#else // HAVE_LIBBPF_SUPPORT
-static struct bpf_map *trace__find_bpf_map_by_name(struct trace *trace __maybe_unused,
- const char *name __maybe_unused)
-{
- return NULL;
-}
-
-static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace __maybe_unused)
-{
- return 0;
-}
-#endif // HAVE_LIBBPF_SUPPORT
+#endif // HAVE_BPF_SKEL
static int trace__set_ev_qualifier_filter(struct trace *trace)
{
@@ -3917,13 +3904,31 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
err = evlist__open(evlist);
if (err < 0)
goto out_error_open;
+#ifdef HAVE_BPF_SKEL
+ {
+ struct perf_cpu cpu;
+ /*
+ * Set up the __augmented_syscalls__ BPF map to hold for each
+ * CPU the bpf-output event's file descriptor.
+ */
+ perf_cpu_map__for_each_cpu(cpu, i, trace->syscalls.events.bpf_output->core.cpus) {
+ bpf_map__update_elem(trace->skel->maps.__augmented_syscalls__,
+ &cpu.cpu, sizeof(int),
+ xyarray__entry(trace->syscalls.events.bpf_output->core.fd,
+ cpu.cpu, 0),
+ sizeof(__u32), BPF_ANY);
+ }
+ }
+#endif
err = trace__set_filter_pids(trace);
if (err < 0)
goto out_error_mem;
- if (trace->syscalls.prog_array.sys_enter)
+#ifdef HAVE_BPF_SKEL
+ if (trace->skel->progs.sys_enter)
trace__init_syscalls_bpf_prog_array_maps(trace);
+#endif
if (trace->ev_qualifier_ids.nr > 0) {
err = trace__set_ev_qualifier_filter(trace);
@@ -3956,9 +3961,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
if (err < 0)
goto out_error_apply_filters;
- if (trace->dump.map)
- bpf_map__fprintf(trace->dump.map, trace->output);
-
err = evlist__mmap(evlist, trace->opts.mmap_pages);
if (err < 0)
goto out_error_mmap;
@@ -4655,6 +4657,18 @@ static void trace__exit(struct trace *trace)
zfree(&trace->perfconfig_events);
}
+#ifdef HAVE_BPF_SKEL
+static int bpf__setup_bpf_output(struct evlist *evlist)
+{
+ int err = parse_event(evlist, "bpf-output/no-inherit=1,name=__augmented_syscalls__/");
+
+ if (err)
+ pr_debug("ERROR: failed to create the \"__augmented_syscalls__\" bpf-output event\n");
+
+ return err;
+}
+#endif
+
int cmd_trace(int argc, const char **argv)
{
const char *trace_usage[] = {
@@ -4686,7 +4700,6 @@ int cmd_trace(int argc, const char **argv)
.max_stack = UINT_MAX,
.max_events = ULONG_MAX,
};
- const char *map_dump_str = NULL;
const char *output_name = NULL;
const struct option trace_options[] = {
OPT_CALLBACK('e', "event", &trace, "event",
@@ -4720,9 +4733,6 @@ int cmd_trace(int argc, const char **argv)
OPT_CALLBACK(0, "duration", &trace, "float",
"show only events with duration > N.M ms",
trace__set_duration),
-#ifdef HAVE_LIBBPF_SUPPORT
- OPT_STRING(0, "map-dump", &map_dump_str, "BPF map", "BPF map to periodically dump"),
-#endif
OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"),
OPT_INCR('v', "verbose", &verbose, "be more verbose"),
OPT_BOOLEAN('T', "time", &trace.full_time,
@@ -4849,16 +4859,55 @@ int cmd_trace(int argc, const char **argv)
"cgroup monitoring only available in system-wide mode");
}
- err = -1;
+#ifdef HAVE_BPF_SKEL
+ trace.skel = augmented_raw_syscalls_bpf__open();
+ if (!trace.skel) {
+ pr_debug("Failed to open augmented syscalls BPF skeleton");
+ } else {
+ /*
+ * Disable attaching the BPF programs except for sys_enter and
+ * sys_exit that tail call into this as necessary.
+ */
+ bpf_program__set_autoattach(trace.skel->progs.syscall_unaugmented,
+ /*autoattach=*/false);
+ bpf_program__set_autoattach(trace.skel->progs.sys_enter_connect,
+ /*autoattach=*/false);
+ bpf_program__set_autoattach(trace.skel->progs.sys_enter_sendto,
+ /*autoattach=*/false);
+ bpf_program__set_autoattach(trace.skel->progs.sys_enter_open,
+ /*autoattach=*/false);
+ bpf_program__set_autoattach(trace.skel->progs.sys_enter_openat,
+ /*autoattach=*/false);
+ bpf_program__set_autoattach(trace.skel->progs.sys_enter_rename,
+ /*autoattach=*/false);
+ bpf_program__set_autoattach(trace.skel->progs.sys_enter_renameat,
+ /*autoattach=*/false);
+ bpf_program__set_autoattach(trace.skel->progs.sys_enter_perf_event_open,
+ /*autoattach=*/false);
+ bpf_program__set_autoattach(trace.skel->progs.sys_enter_clock_nanosleep,
+ /*autoattach=*/false);
+
+ err = augmented_raw_syscalls_bpf__load(trace.skel);
- if (map_dump_str) {
- trace.dump.map = trace__find_bpf_map_by_name(&trace, map_dump_str);
- if (trace.dump.map == NULL) {
- pr_err("ERROR: BPF map \"%s\" not found\n", map_dump_str);
- goto out;
+ if (err < 0) {
+ pr_debug("Failed to load augmented syscalls BPF skeleton\n");
+ } else {
+ augmented_raw_syscalls_bpf__attach(trace.skel);
+ trace__add_syscall_newtp(&trace);
}
}
+ err = bpf__setup_bpf_output(trace.evlist);
+ if (err) {
+ libbpf_strerror(err, bf, sizeof(bf));
+ pr_err("ERROR: Setup BPF output event failed: %s\n", bf);
+ goto out;
+ }
+ trace.syscalls.events.bpf_output = evlist__last(trace.evlist);
+ assert(!strcmp(evsel__name(trace.syscalls.events.bpf_output), "__augmented_syscalls__"));
+#endif
+ err = -1;
+
if (trace.trace_pgfaults) {
trace.opts.sample_address = true;
trace.opts.sample_time = true;
@@ -4909,7 +4958,7 @@ int cmd_trace(int argc, const char **argv)
* buffers that are being copied from kernel to userspace, think 'read'
* syscall.
*/
- if (trace.syscalls.events.augmented) {
+ if (trace.syscalls.events.bpf_output) {
evlist__for_each_entry(trace.evlist, evsel) {
bool raw_syscalls_sys_exit = strcmp(evsel__name(evsel), "raw_syscalls:sys_exit") == 0;
@@ -4918,9 +4967,9 @@ int cmd_trace(int argc, const char **argv)
goto init_augmented_syscall_tp;
}
- if (trace.syscalls.events.augmented->priv == NULL &&
+ if (trace.syscalls.events.bpf_output->priv == NULL &&
strstr(evsel__name(evsel), "syscalls:sys_enter")) {
- struct evsel *augmented = trace.syscalls.events.augmented;
+ struct evsel *augmented = trace.syscalls.events.bpf_output;
if (evsel__init_augmented_syscall_tp(augmented, evsel) ||
evsel__init_augmented_syscall_tp_args(augmented))
goto out;
@@ -5025,5 +5074,8 @@ int cmd_trace(int argc, const char **argv)
fclose(trace.output);
out:
trace__exit(&trace);
+#ifdef HAVE_BPF_SKEL
+ augmented_raw_syscalls_bpf__destroy(trace.skel);
+#endif
return err;
}
diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
similarity index 96%
rename from tools/perf/examples/bpf/augmented_raw_syscalls.c
rename to tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
index 9a03189d33d3..70478b9460ee 100644
--- a/tools/perf/examples/bpf/augmented_raw_syscalls.c
+++ b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
@@ -18,6 +18,8 @@
#include <bpf/bpf_helpers.h>
#include <linux/limits.h>
+#define MAX_CPUS 4096
+
// FIXME: These should come from system headers
typedef char bool;
typedef int pid_t;
@@ -34,7 +36,7 @@ struct __augmented_syscalls__ {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__type(key, int);
__type(value, __u32);
- __uint(max_entries, __NR_CPUS__);
+ __uint(max_entries, MAX_CPUS);
} __augmented_syscalls__ SEC(".maps");
/*
@@ -170,7 +172,7 @@ unsigned int augmented_arg__read_str(struct augmented_arg *augmented_arg, const
return augmented_len;
}
-SEC("!raw_syscalls:unaugmented")
+SEC("tp/raw_syscalls/sys_enter")
int syscall_unaugmented(struct syscall_enter_args *args)
{
return 1;
@@ -182,7 +184,7 @@ int syscall_unaugmented(struct syscall_enter_args *args)
* on from there, reading the first syscall arg as a string, i.e. open's
* filename.
*/
-SEC("!syscalls:sys_enter_connect")
+SEC("tp/syscalls/sys_enter_connect")
int sys_enter_connect(struct syscall_enter_args *args)
{
struct augmented_args_payload *augmented_args = augmented_args_payload();
@@ -201,7 +203,7 @@ int sys_enter_connect(struct syscall_enter_args *args)
return augmented__output(args, augmented_args, len + socklen);
}
-SEC("!syscalls:sys_enter_sendto")
+SEC("tp/syscalls/sys_enter_sendto")
int sys_enter_sendto(struct syscall_enter_args *args)
{
struct augmented_args_payload *augmented_args = augmented_args_payload();
@@ -220,7 +222,7 @@ int sys_enter_sendto(struct syscall_enter_args *args)
return augmented__output(args, augmented_args, len + socklen);
}
-SEC("!syscalls:sys_enter_open")
+SEC("tp/syscalls/sys_enter_open")
int sys_enter_open(struct syscall_enter_args *args)
{
struct augmented_args_payload *augmented_args = augmented_args_payload();
@@ -235,7 +237,7 @@ int sys_enter_open(struct syscall_enter_args *args)
return augmented__output(args, augmented_args, len);
}
-SEC("!syscalls:sys_enter_openat")
+SEC("tp/syscalls/sys_enter_openat")
int sys_enter_openat(struct syscall_enter_args *args)
{
struct augmented_args_payload *augmented_args = augmented_args_payload();
@@ -250,7 +252,7 @@ int sys_enter_openat(struct syscall_enter_args *args)
return augmented__output(args, augmented_args, len);
}
-SEC("!syscalls:sys_enter_rename")
+SEC("tp/syscalls/sys_enter_rename")
int sys_enter_rename(struct syscall_enter_args *args)
{
struct augmented_args_payload *augmented_args = augmented_args_payload();
@@ -267,7 +269,7 @@ int sys_enter_rename(struct syscall_enter_args *args)
return augmented__output(args, augmented_args, len);
}
-SEC("!syscalls:sys_enter_renameat")
+SEC("tp/syscalls/sys_enter_renameat")
int sys_enter_renameat(struct syscall_enter_args *args)
{
struct augmented_args_payload *augmented_args = augmented_args_payload();
@@ -295,7 +297,7 @@ struct perf_event_attr_size {
__u32 size;
};
-SEC("!syscalls:sys_enter_perf_event_open")
+SEC("tp/syscalls/sys_enter_perf_event_open")
int sys_enter_perf_event_open(struct syscall_enter_args *args)
{
struct augmented_args_payload *augmented_args = augmented_args_payload();
@@ -327,7 +329,7 @@ int sys_enter_perf_event_open(struct syscall_enter_args *args)
return 1; /* Failure: don't filter */
}
-SEC("!syscalls:sys_enter_clock_nanosleep")
+SEC("tp/syscalls/sys_enter_clock_nanosleep")
int sys_enter_clock_nanosleep(struct syscall_enter_args *args)
{
struct augmented_args_payload *augmented_args = augmented_args_payload();
@@ -358,7 +360,7 @@ static bool pid_filter__has(struct pids_filtered *pids, pid_t pid)
return bpf_map_lookup_elem(pids, &pid) != NULL;
}
-SEC("raw_syscalls:sys_enter")
+SEC("tp/raw_syscalls/sys_enter")
int sys_enter(struct syscall_enter_args *args)
{
struct augmented_args_payload *augmented_args;
@@ -371,7 +373,6 @@ int sys_enter(struct syscall_enter_args *args)
* We'll add to this as we add augmented syscalls right after that
* initial, non-augmented raw_syscalls:sys_enter payload.
*/
- unsigned int len = sizeof(augmented_args->args);
if (pid_filter__has(&pids_filtered, getpid()))
return 0;
@@ -393,7 +394,7 @@ int sys_enter(struct syscall_enter_args *args)
return 0;
}
-SEC("raw_syscalls:sys_exit")
+SEC("tp/raw_syscalls/sys_exit")
int sys_exit(struct syscall_exit_args *args)
{
struct syscall_exit_args exit_args;
--
2.41.0.640.ga95def55d0-goog
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v1 3/4] perf bpf examples: With no BPF events remove examples
2023-08-10 18:48 [PATCH v1 0/4] Remove BPF event support Ian Rogers
2023-08-10 18:48 ` [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton Ian Rogers
@ 2023-08-10 18:48 ` Ian Rogers
2023-08-10 18:48 ` [PATCH v1 4/4] perf trace: Tidy comments Ian Rogers
` (2 subsequent siblings)
4 siblings, 0 replies; 22+ messages in thread
From: Ian Rogers @ 2023-08-10 18:48 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Adrian Hunter, Nathan Chancellor, Nick Desaulniers, Tom Rix,
Fangrui Song, Anshuman Khandual, Andi Kleen, Leo Yan,
Madhavan Srinivasan, Carsten Haitzler, Ravi Bangoria,
Naveen N. Rao, Athira Rajeev, Kan Liang, Yang Jihong, James Clark,
Tiezhu Yang, Eduard Zingerman, Andrii Nakryiko, Yonghong Song,
Rob Herring, linux-kernel, linux-perf-users, bpf, llvm, Wang Nan,
Wang ShaoBo, YueHaibing, He Kuang, Brendan Gregg
Cc: Ian Rogers
The examples were used to give demonstrations of BPF events but such
functionality is now subsumed by using --filter with perf record or
the direct use of BPF skeletons.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/Makefile.perf | 5 --
tools/perf/examples/bpf/5sec.c | 53 ----------------------
tools/perf/examples/bpf/empty.c | 12 -----
tools/perf/examples/bpf/hello.c | 27 -----------
tools/perf/examples/bpf/sys_enter_openat.c | 33 --------------
5 files changed, 130 deletions(-)
delete mode 100644 tools/perf/examples/bpf/5sec.c
delete mode 100644 tools/perf/examples/bpf/empty.c
delete mode 100644 tools/perf/examples/bpf/hello.c
delete mode 100644 tools/perf/examples/bpf/sys_enter_openat.c
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 0e1597712b95..a76a2a8f59b7 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -962,11 +962,6 @@ ifndef NO_JVMTI
endif
$(call QUIET_INSTALL, libexec) \
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
-ifndef NO_LIBBPF
- $(call QUIET_INSTALL, bpf-examples) \
- $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'; \
- $(INSTALL) examples/bpf/*.c -m 644 -t '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
-endif
$(call QUIET_INSTALL, perf-archive) \
$(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
$(call QUIET_INSTALL, perf-iostat) \
diff --git a/tools/perf/examples/bpf/5sec.c b/tools/perf/examples/bpf/5sec.c
deleted file mode 100644
index 3bd7fc17631f..000000000000
--- a/tools/perf/examples/bpf/5sec.c
+++ /dev/null
@@ -1,53 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- Description:
-
- . Disable strace like syscall tracing (--no-syscalls), or try tracing
- just some (-e *sleep).
-
- . Attach a filter function to a kernel function, returning when it should
- be considered, i.e. appear on the output.
-
- . Run it system wide, so that any sleep of >= 5 seconds and < than 6
- seconds gets caught.
-
- . Ask for callgraphs using DWARF info, so that userspace can be unwound
-
- . While this is running, run something like "sleep 5s".
-
- . If we decide to add tv_nsec as well, then it becomes:
-
- int probe(hrtimer_nanosleep, rqtp->tv_sec rqtp->tv_nsec)(void *ctx, int err, long sec, long nsec)
-
- I.e. add where it comes from (rqtp->tv_nsec) and where it will be
- accessible in the function body (nsec)
-
- # perf trace --no-syscalls -e tools/perf/examples/bpf/5sec.c/call-graph=dwarf/
- 0.000 perf_bpf_probe:func:(ffffffff9811b5f0) tv_sec=5
- hrtimer_nanosleep ([kernel.kallsyms])
- __x64_sys_nanosleep ([kernel.kallsyms])
- do_syscall_64 ([kernel.kallsyms])
- entry_SYSCALL_64 ([kernel.kallsyms])
- __GI___nanosleep (/usr/lib64/libc-2.26.so)
- rpl_nanosleep (/usr/bin/sleep)
- xnanosleep (/usr/bin/sleep)
- main (/usr/bin/sleep)
- __libc_start_main (/usr/lib64/libc-2.26.so)
- _start (/usr/bin/sleep)
- ^C#
-
- Copyright (C) 2018 Red Hat, Inc., Arnaldo Carvalho de Melo <acme@redhat.com>
-*/
-
-#include <linux/bpf.h>
-#include <bpf/bpf_helpers.h>
-
-#define NSEC_PER_SEC 1000000000L
-
-SEC("hrtimer_nanosleep=hrtimer_nanosleep rqtp")
-int hrtimer_nanosleep(void *ctx, int err, long long sec)
-{
- return sec / NSEC_PER_SEC == 5ULL;
-}
-
-char _license[] SEC("license") = "GPL";
diff --git a/tools/perf/examples/bpf/empty.c b/tools/perf/examples/bpf/empty.c
deleted file mode 100644
index 3e296c0c53d7..000000000000
--- a/tools/perf/examples/bpf/empty.c
+++ /dev/null
@@ -1,12 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/bpf.h>
-#include <bpf/bpf_helpers.h>
-
-struct syscall_enter_args;
-
-SEC("raw_syscalls:sys_enter")
-int sys_enter(struct syscall_enter_args *args)
-{
- return 0;
-}
-char _license[] SEC("license") = "GPL";
diff --git a/tools/perf/examples/bpf/hello.c b/tools/perf/examples/bpf/hello.c
deleted file mode 100644
index e9080b0df158..000000000000
--- a/tools/perf/examples/bpf/hello.c
+++ /dev/null
@@ -1,27 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/bpf.h>
-#include <bpf/bpf_helpers.h>
-
-struct __bpf_stdout__ {
- __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
- __type(key, int);
- __type(value, __u32);
- __uint(max_entries, __NR_CPUS__);
-} __bpf_stdout__ SEC(".maps");
-
-#define puts(from) \
- ({ const int __len = sizeof(from); \
- char __from[sizeof(from)] = from; \
- bpf_perf_event_output(args, &__bpf_stdout__, BPF_F_CURRENT_CPU, \
- &__from, __len & (sizeof(from) - 1)); })
-
-struct syscall_enter_args;
-
-SEC("raw_syscalls:sys_enter")
-int sys_enter(struct syscall_enter_args *args)
-{
- puts("Hello, world\n");
- return 0;
-}
-
-char _license[] SEC("license") = "GPL";
diff --git a/tools/perf/examples/bpf/sys_enter_openat.c b/tools/perf/examples/bpf/sys_enter_openat.c
deleted file mode 100644
index c4481c390d23..000000000000
--- a/tools/perf/examples/bpf/sys_enter_openat.c
+++ /dev/null
@@ -1,33 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Hook into 'openat' syscall entry tracepoint
- *
- * Test it with:
- *
- * perf trace -e tools/perf/examples/bpf/sys_enter_openat.c cat /etc/passwd > /dev/null
- *
- * It'll catch some openat syscalls related to the dynamic linked and
- * the last one should be the one for '/etc/passwd'.
- *
- * The syscall_enter_openat_args can be used to get the syscall fields
- * and use them for filtering calls, i.e. use in expressions for
- * the return value.
- */
-
-#include <bpf/bpf.h>
-
-struct syscall_enter_openat_args {
- unsigned long long unused;
- long syscall_nr;
- long dfd;
- char *filename_ptr;
- long flags;
- long mode;
-};
-
-int syscall_enter(openat)(struct syscall_enter_openat_args *args)
-{
- return 1;
-}
-
-license(GPL);
--
2.41.0.640.ga95def55d0-goog
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v1 4/4] perf trace: Tidy comments
2023-08-10 18:48 [PATCH v1 0/4] Remove BPF event support Ian Rogers
2023-08-10 18:48 ` [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton Ian Rogers
2023-08-10 18:48 ` [PATCH v1 3/4] perf bpf examples: With no BPF events remove examples Ian Rogers
@ 2023-08-10 18:48 ` Ian Rogers
[not found] ` <20230810184853.2860737-2-irogers@google.com>
2023-08-11 16:09 ` [PATCH v1 0/4] " Jiri Olsa
4 siblings, 0 replies; 22+ messages in thread
From: Ian Rogers @ 2023-08-10 18:48 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Adrian Hunter, Nathan Chancellor, Nick Desaulniers, Tom Rix,
Fangrui Song, Anshuman Khandual, Andi Kleen, Leo Yan,
Madhavan Srinivasan, Carsten Haitzler, Ravi Bangoria,
Naveen N. Rao, Athira Rajeev, Kan Liang, Yang Jihong, James Clark,
Tiezhu Yang, Eduard Zingerman, Andrii Nakryiko, Yonghong Song,
Rob Herring, linux-kernel, linux-perf-users, bpf, llvm, Wang Nan,
Wang ShaoBo, YueHaibing, He Kuang, Brendan Gregg
Cc: Ian Rogers
Now tools/perf/examples/bpf/augmented_syscalls.c is
tools/perf/util/bpf_skel/augmented_syscalls.bpf.c and not enabled as a
BPF event, tidy the comments to reflect this.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/trace/beauty/beauty.h | 15 +++++++--------
.../util/bpf_skel/augmented_raw_syscalls.bpf.c | 8 --------
2 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h
index 3d12bf0f6d07..788e8f6bd90e 100644
--- a/tools/perf/trace/beauty/beauty.h
+++ b/tools/perf/trace/beauty/beauty.h
@@ -67,15 +67,14 @@ extern struct strarray strarray__socket_level;
/**
* augmented_arg: extra payload for syscall pointer arguments
- * If perf_sample->raw_size is more than what a syscall sys_enter_FOO puts,
- * then its the arguments contents, so that we can show more than just a
+ * If perf_sample->raw_size is more than what a syscall sys_enter_FOO puts, then
+ * its the arguments contents, so that we can show more than just a
* pointer. This will be done initially with eBPF, the start of that is at the
- * tools/perf/examples/bpf/augmented_syscalls.c example for the openat, but
- * will eventually be done automagically caching the running kernel tracefs
- * events data into an eBPF C script, that then gets compiled and its .o file
- * cached for subsequent use. For char pointers like the ones for 'open' like
- * syscalls its easy, for the rest we should use DWARF or better, BTF, much
- * more compact.
+ * tools/perf/util/bpf_skel/augmented_syscalls.bpf.c that will eventually be
+ * done automagically caching the running kernel tracefs events data into an
+ * eBPF C script, that then gets compiled and its .o file cached for subsequent
+ * use. For char pointers like the ones for 'open' like syscalls its easy, for
+ * the rest we should use DWARF or better, BTF, much more compact.
*
* @size: 8 if all we need is an integer, otherwise all of the augmented arg.
* @int_arg: will be used for integer like pointer contents, like 'accept's 'upeer_addrlen'
diff --git a/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
index 70478b9460ee..0586c4118656 100644
--- a/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
+++ b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
@@ -2,16 +2,8 @@
/*
* Augment the raw_syscalls tracepoints with the contents of the pointer arguments.
*
- * Test it with:
- *
- * perf trace -e tools/perf/examples/bpf/augmented_raw_syscalls.c cat /etc/passwd > /dev/null
- *
* This exactly matches what is marshalled into the raw_syscall:sys_enter
* payload expected by the 'perf trace' beautifiers.
- *
- * For now it just uses the existing tracepoint augmentation code in 'perf
- * trace', in the next csets we'll hook up these with the sys_enter/sys_exit
- * code that will combine entry/exit in a strace like way.
*/
#include <linux/bpf.h>
--
2.41.0.640.ga95def55d0-goog
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH v1 1/4] perf parse-events: Remove BPF event support
[not found] ` <ZNZJCWi9MT/HZdQ/@kernel.org>
@ 2023-08-11 15:41 ` Arnaldo Carvalho de Melo
2023-10-19 19:45 ` Manu Bretelle
0 siblings, 1 reply; 22+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-08-11 15:41 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Adrian Hunter, Nathan Chancellor,
Nick Desaulniers, Tom Rix, Fangrui Song, Anshuman Khandual,
Andi Kleen, Leo Yan, Madhavan Srinivasan, Carsten Haitzler,
Ravi Bangoria, Naveen N. Rao, Athira Rajeev, Kan Liang,
Yang Jihong, James Clark, Tiezhu Yang, Eduard Zingerman,
Andrii Nakryiko, Yonghong Song, Rob Herring, linux-kernel,
linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo, YueHaibing,
He Kuang, Brendan Gregg
Em Fri, Aug 11, 2023 at 11:43:22AM -0300, Arnaldo Carvalho de Melo escreveu:
> Right now it is not applying due to some clash with other changes and
> when I tried to apply it manually there were some formatting issues:
>
> ⬢[acme@toolbox perf-tools-next]$ head ~/wb/1.patch
> From SRS0=EALy=D3=flex--irogers.bounces.google.com=3IDHVZAcKBAUnwtljwxlttlqj.htrfhrjpjwsjq.twl@kernel.org Thu Aug 10 17:53:46 2023
> Delivered-To: arnaldo.melo@gmail.com
> Received: from imap.gmail.com [64.233.186.109]
> by quaco with IMAP (fetchmail-6.4.37)
> for <acme@localhost> (single-drop); Thu, 10 Aug 2023 17:53:46 -0300 (-03)
> Received: by 2002:a0c:ab03:0:b0:63d:780e:9480 with SMTP id h3csp908198qvb;
> Thu, 10 Aug 2023 11:49:52 -0700 (PDT)
> X-Google-Smtp-Source: AGHT+IH9N/knUCyQ0tQ2Q0XBH0gqf8A8DB8/37YHWAJDKBmz7AGSV9CvCKYDuE3EwxriZFBwtZMs
> X-Received: by 2002:a4a:6b4f:0:b0:56c:b2ab:9820 with SMTP id
> h15-20020a4a6b4f000000b0056cb2ab9820mr2695332oof.8.1691693392493; Thu, 10 Aug
> ⬢[acme@toolbox perf-tools-next]$ patch -p1 < ~/wb/1.patch
> patching file tools/perf/Documentation/perf-config.txt
> patch: **** malformed patch at line 234: ith
>
> ⬢[acme@toolbox perf-tools-next]$
>
> I'm trying to apply it manually.
I have this extracted from this patch as the first patch in the series:
From adc61b5774a9de62f34d593f164ca02daa6fb44c Mon Sep 17 00:00:00 2001
From: Ian Rogers <irogers@google.com>
Date: Fri, 11 Aug 2023 12:19:48 -0300
Subject: [PATCH 1/1] perf bpf: Remove support for embedding clang for
compiling BPF events (-e foo.c)
This never was in the default build for perf, is difficult to maintain
as it uses clang/llvm internals so ditch it, keeping, for now, the
external compilation of .c BPF into .o bytecode and its subsequent
loading, that is also going to be removed, do it separately to help
bisection and to properly document what is being removed and why.
Committer notes:
Extracted from a larger patch and removed some leftovers, namely
deleting these now unused feature tests:
tools/build/feature/test-clang.cpp
tools/build/feature/test-cxx.cpp
tools/build/feature/test-llvm-version.cpp
tools/build/feature/test-llvm.cpp
Testing the use of BPF events after applying this patch:
To use the external clang/llvm toolchain to compile a .c event and then
use libbpf to load it, to get the syscalls:sys_enter_open* tracepoints
and read the filename pointer, putting it into the ring buffer right
after the usual tracepoint payload for 'perf trace' to then print it:
[root@quaco ~]# perf trace -e /home/acme/git/perf-tools-next/tools/perf/examples/bpf/augmented_raw_syscalls.c,open* --max-events=10
0.000 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
0.083 abrt-dump-jour/1453 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
0.063 abrt-dump-jour/1454 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
0.082 abrt-dump-jour/1455 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
250.124 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
250.521 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.pressure", flags: RDONLY|CLOEXEC) = 12
251.047 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.current", flags: RDONLY|CLOEXEC) = 12
251.162 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.min", flags: RDONLY|CLOEXEC) = 12
251.242 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.low", flags: RDONLY|CLOEXEC) = 12
251.353 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.swap.current", flags: RDONLY|CLOEXEC) = 12
[root@quaco ~]#
Same thing, but with a prebuilt .o BPF bytecode:
[root@quaco ~]# perf trace -e /home/acme/git/perf-tools-next/tools/perf/examples/bpf/augmented_raw_syscalls.o,open* --max-events=10
0.000 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
0.083 abrt-dump-jour/1453 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
0.083 abrt-dump-jour/1455 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
0.062 abrt-dump-jour/1454 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
249.985 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
466.763 thermald/1234 openat(dfd: CWD, filename: "/sys/class/powercap/intel-rapl/intel-rapl:0/intel-rapl:0:2/energy_uj") = 13
467.145 thermald/1234 openat(dfd: CWD, filename: "/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj") = 13
467.311 thermald/1234 openat(dfd: CWD, filename: "/sys/class/thermal/thermal_zone2/temp") = 13
500.040 cgroupify/24006 openat(dfd: 4, filename: ".", flags: RDONLY|CLOEXEC|DIRECTORY|NONBLOCK) = 5
500.295 cgroupify/24006 openat(dfd: 4, filename: "24616/cgroup.procs") = 5
[root@quaco ~]#
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Carsten Haitzler <carsten.haitzler@arm.com>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Fangrui Song <maskray@google.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Tom Rix <trix@redhat.com>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Wang ShaoBo <bobo.shaobowang@huawei.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: YueHaibing <yuehaibing@huawei.com>
Link: https://lore.kernel.org/lkml/
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/build/feature/test-clang.cpp | 28 ---
tools/build/feature/test-cxx.cpp | 16 --
tools/build/feature/test-llvm-version.cpp | 12 --
tools/build/feature/test-llvm.cpp | 14 --
tools/perf/Makefile.config | 31 ---
tools/perf/Makefile.perf | 17 --
tools/perf/tests/Build | 1 -
tools/perf/tests/builtin-test.c | 1 -
tools/perf/tests/clang.c | 32 ---
tools/perf/tests/make | 1 -
tools/perf/util/Build | 2 -
tools/perf/util/bpf-loader.c | 15 +-
tools/perf/util/c++/Build | 5 -
tools/perf/util/c++/clang-c.h | 43 -----
tools/perf/util/c++/clang-test.cpp | 67 -------
tools/perf/util/c++/clang.cpp | 225 ----------------------
tools/perf/util/c++/clang.h | 27 ---
17 files changed, 4 insertions(+), 533 deletions(-)
delete mode 100644 tools/build/feature/test-clang.cpp
delete mode 100644 tools/build/feature/test-cxx.cpp
delete mode 100644 tools/build/feature/test-llvm-version.cpp
delete mode 100644 tools/build/feature/test-llvm.cpp
delete mode 100644 tools/perf/tests/clang.c
delete mode 100644 tools/perf/util/c++/Build
delete mode 100644 tools/perf/util/c++/clang-c.h
delete mode 100644 tools/perf/util/c++/clang-test.cpp
delete mode 100644 tools/perf/util/c++/clang.cpp
delete mode 100644 tools/perf/util/c++/clang.h
diff --git a/tools/build/feature/test-clang.cpp b/tools/build/feature/test-clang.cpp
deleted file mode 100644
index 7d87075cd1c5dd6e..0000000000000000
--- a/tools/build/feature/test-clang.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include "clang/Basic/Version.h"
-#if CLANG_VERSION_MAJOR < 8
-#include "clang/Basic/VirtualFileSystem.h"
-#endif
-#include "clang/Driver/Driver.h"
-#include "clang/Frontend/TextDiagnosticPrinter.h"
-#include "llvm/ADT/IntrusiveRefCntPtr.h"
-#include "llvm/Support/ManagedStatic.h"
-#if CLANG_VERSION_MAJOR >= 8
-#include "llvm/Support/VirtualFileSystem.h"
-#endif
-#include "llvm/Support/raw_ostream.h"
-
-using namespace clang;
-using namespace clang::driver;
-
-int main()
-{
- IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
- IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
-
- DiagnosticsEngine Diags(DiagID, &*DiagOpts);
- Driver TheDriver("test", "bpf-pc-linux", Diags);
-
- llvm::llvm_shutdown();
- return 0;
-}
diff --git a/tools/build/feature/test-cxx.cpp b/tools/build/feature/test-cxx.cpp
deleted file mode 100644
index 396aaedd2418dd65..0000000000000000
--- a/tools/build/feature/test-cxx.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <iostream>
-#include <memory>
-
-static void print_str(std::string s)
-{
- std::cout << s << std::endl;
-}
-
-int main()
-{
- std::string s("Hello World!");
- print_str(std::move(s));
- std::cout << "|" << s << "|" << std::endl;
- return 0;
-}
diff --git a/tools/build/feature/test-llvm-version.cpp b/tools/build/feature/test-llvm-version.cpp
deleted file mode 100644
index 8a091625446af985..0000000000000000
--- a/tools/build/feature/test-llvm-version.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <cstdio>
-#include "llvm/Config/llvm-config.h"
-
-#define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH)
-#define pass int main() {printf("%x\n", NUM_VERSION); return 0;}
-
-#if NUM_VERSION >= 0x030900
-pass
-#else
-# error This LLVM is not tested yet.
-#endif
diff --git a/tools/build/feature/test-llvm.cpp b/tools/build/feature/test-llvm.cpp
deleted file mode 100644
index 88a3d1bdd9f6978e..0000000000000000
--- a/tools/build/feature/test-llvm.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/raw_ostream.h"
-#define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH)
-
-#if NUM_VERSION < 0x030900
-# error "LLVM version too low"
-#endif
-int main()
-{
- llvm::errs() << "Hello World!\n";
- llvm::llvm_shutdown();
- return 0;
-}
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 1bf8dc53641fa093..e0592ed4c10f5904 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -1127,37 +1127,6 @@ ifndef NO_JVMTI
endif
endif
-USE_CXX = 0
-USE_CLANGLLVM = 0
-ifdef LIBCLANGLLVM
- $(call feature_check,cxx)
- ifneq ($(feature-cxx), 1)
- msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
- else
- $(call feature_check,llvm)
- $(call feature_check,llvm-version)
- ifneq ($(feature-llvm), 1)
- msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
- else
- $(call feature_check,clang)
- ifneq ($(feature-clang), 1)
- msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
- else
- CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
- CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
- $(call detected,CONFIG_CXX)
- $(call detected,CONFIG_CLANGLLVM)
- USE_CXX = 1
- USE_LLVM = 1
- USE_CLANG = 1
- ifneq ($(feature-llvm-version),1)
- msg := $(warning This version of LLVM is not tested. May cause build errors)
- endif
- endif
- endif
- endif
-endif
-
ifndef NO_LIBPFM4
$(call feature_check,libpfm4)
ifeq ($(feature-libpfm4), 1)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 0ed7ee0c1665a8cf..5370d7bf123e76af 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -99,10 +99,6 @@ include ../scripts/utilities.mak
# Define NO_JVMTI_CMLR (debug only) if you do not want to process CMLR
# data for java source lines.
#
-# Define LIBCLANGLLVM if you DO want builtin clang and llvm support.
-# When selected, pass LLVM_CONFIG=/path/to/llvm-config to `make' if
-# llvm-config is not in $PATH.
-#
# Define CORESIGHT if you DO WANT support for CoreSight trace decoding.
#
# Define NO_AIO if you do not want support of Posix AIO based trace
@@ -425,19 +421,6 @@ endif
EXTLIBS := $(call filter-out,$(EXCLUDE_EXTLIBS),$(EXTLIBS))
LIBS = -Wl,--whole-archive $(PERFLIBS) $(EXTRA_PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
-ifeq ($(USE_CLANG), 1)
- LIBS += -L$(shell $(LLVM_CONFIG) --libdir) -lclang-cpp
-endif
-
-ifeq ($(USE_LLVM), 1)
- LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs)
- LIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM)
-endif
-
-ifeq ($(USE_CXX), 1)
- LIBS += -lstdc++
-endif
-
export INSTALL SHELL_PATH
### Build rules
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index fb9ac5dc4079dab8..52df5923a8b9cc20 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -51,7 +51,6 @@ perf-y += sdt.o
perf-y += is_printable_array.o
perf-y += bitmap.o
perf-y += perf-hooks.o
-perf-y += clang.o
perf-y += unit_number__scnprintf.o
perf-y += mem2node.o
perf-y += maps.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 6accb5442a731842..0f3691fd31c2536f 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -108,7 +108,6 @@ static struct test_suite *generic_tests[] = {
&suite__is_printable_array,
&suite__bitmap_print,
&suite__perf_hooks,
- &suite__clang,
&suite__unit_number__scnprint,
&suite__mem2node,
&suite__time_utils,
diff --git a/tools/perf/tests/clang.c b/tools/perf/tests/clang.c
deleted file mode 100644
index a7111005d5b9f481..0000000000000000
--- a/tools/perf/tests/clang.c
+++ /dev/null
@@ -1,32 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include "tests.h"
-#include "c++/clang-c.h"
-#include <linux/kernel.h>
-
-#ifndef HAVE_LIBCLANGLLVM_SUPPORT
-static int test__clang_to_IR(struct test_suite *test __maybe_unused,
- int subtest __maybe_unused)
-{
- return TEST_SKIP;
-}
-
-static int test__clang_to_obj(struct test_suite *test __maybe_unused,
- int subtest __maybe_unused)
-{
- return TEST_SKIP;
-}
-#endif
-
-static struct test_case clang_tests[] = {
- TEST_CASE_REASON("builtin clang compile C source to IR", clang_to_IR,
- "not compiled in"),
- TEST_CASE_REASON("builtin clang compile C source to ELF object",
- clang_to_obj,
- "not compiled in"),
- { .name = NULL, }
-};
-
-struct test_suite suite__clang = {
- .desc = "builtin clang support",
- .test_cases = clang_tests,
-};
diff --git a/tools/perf/tests/make b/tools/perf/tests/make
index 58cf96d762d06a68..ea4c341f5af11741 100644
--- a/tools/perf/tests/make
+++ b/tools/perf/tests/make
@@ -95,7 +95,6 @@ make_with_babeltrace:= LIBBABELTRACE=1
make_with_coresight := CORESIGHT=1
make_no_sdt := NO_SDT=1
make_no_syscall_tbl := NO_SYSCALL_TABLE=1
-make_with_clangllvm := LIBCLANGLLVM=1
make_no_libpfm4 := NO_LIBPFM4=1
make_with_gtk2 := GTK2=1
make_refcnt_check := EXTRA_CFLAGS="-DREFCNT_CHECKING=1"
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 9699e31ff4c04925..ff3b55c7ed43cdad 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -232,8 +232,6 @@ perf-y += perf-hooks.o
perf-$(CONFIG_LIBBPF) += bpf-event.o
perf-$(CONFIG_LIBBPF) += bpf-utils.o
-perf-$(CONFIG_CXX) += c++/
-
perf-$(CONFIG_LIBPFM4) += pfm.o
CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 50e42698cbb721d1..b54e42f17926b17e 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -26,7 +26,6 @@
#include "strfilter.h"
#include "util.h"
#include "llvm-utils.h"
-#include "c++/clang-c.h"
#include "util/hashmap.h"
#include "asm/bug.h"
@@ -220,16 +219,10 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
void *obj_buf;
size_t obj_buf_sz;
- perf_clang__init();
- err = perf_clang__compile_bpf(filename, &obj_buf, &obj_buf_sz);
- perf_clang__cleanup();
- if (err) {
- pr_debug("bpf: builtin compilation failed: %d, try external compiler\n", err);
- err = llvm__compile_bpf(filename, &obj_buf, &obj_buf_sz);
- if (err)
- return ERR_PTR(-BPF_LOADER_ERRNO__COMPILE);
- } else
- pr_debug("bpf: successful builtin compilation\n");
+ err = llvm__compile_bpf(filename, &obj_buf, &obj_buf_sz);
+ if (err)
+ return ERR_PTR(-BPF_LOADER_ERRNO__COMPILE);
+
obj = bpf_object__open_mem(obj_buf, obj_buf_sz, &opts);
if (!IS_ERR_OR_NULL(obj) && llvm_param.dump_obj)
diff --git a/tools/perf/util/c++/Build b/tools/perf/util/c++/Build
deleted file mode 100644
index 8610d032ac19d8c5..0000000000000000
--- a/tools/perf/util/c++/Build
+++ /dev/null
@@ -1,5 +0,0 @@
-perf-$(CONFIG_CLANGLLVM) += clang.o
-perf-$(CONFIG_CLANGLLVM) += clang-test.o
-
-CXXFLAGS_clang.o += -Wno-unused-parameter
-CXXFLAGS_clang-test.o += -Wno-unused-parameter
diff --git a/tools/perf/util/c++/clang-c.h b/tools/perf/util/c++/clang-c.h
deleted file mode 100644
index d3731a876b6c10c5..0000000000000000
--- a/tools/perf/util/c++/clang-c.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef PERF_UTIL_CLANG_C_H
-#define PERF_UTIL_CLANG_C_H
-
-#include <stddef.h> /* for size_t */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef HAVE_LIBCLANGLLVM_SUPPORT
-extern void perf_clang__init(void);
-extern void perf_clang__cleanup(void);
-
-struct test_suite;
-extern int test__clang_to_IR(struct test_suite *test, int subtest);
-extern int test__clang_to_obj(struct test_suite *test, int subtest);
-
-extern int perf_clang__compile_bpf(const char *filename,
- void **p_obj_buf,
- size_t *p_obj_buf_sz);
-#else
-
-#include <errno.h>
-#include <linux/compiler.h> /* for __maybe_unused */
-
-static inline void perf_clang__init(void) { }
-static inline void perf_clang__cleanup(void) { }
-
-static inline int
-perf_clang__compile_bpf(const char *filename __maybe_unused,
- void **p_obj_buf __maybe_unused,
- size_t *p_obj_buf_sz __maybe_unused)
-{
- return -ENOTSUP;
-}
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/tools/perf/util/c++/clang-test.cpp b/tools/perf/util/c++/clang-test.cpp
deleted file mode 100644
index a4683ca536973c04..0000000000000000
--- a/tools/perf/util/c++/clang-test.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include "clang.h"
-#include "clang-c.h"
-extern "C" {
-#include "../util.h"
-}
-#include "llvm/IR/Function.h"
-#include "llvm/IR/LLVMContext.h"
-
-#include <tests/llvm.h>
-#include <string>
-
-class perf_clang_scope {
-public:
- explicit perf_clang_scope() {perf_clang__init();}
- ~perf_clang_scope() {perf_clang__cleanup();}
-};
-
-static std::unique_ptr<llvm::Module>
-__test__clang_to_IR(void)
-{
- unsigned int kernel_version;
-
- if (fetch_kernel_version(&kernel_version, NULL, 0))
- return std::unique_ptr<llvm::Module>(nullptr);
-
- std::string cflag_kver("-DLINUX_VERSION_CODE=" +
- std::to_string(kernel_version));
-
- std::unique_ptr<llvm::Module> M =
- perf::getModuleFromSource({cflag_kver.c_str()},
- "perf-test.c",
- test_llvm__bpf_base_prog);
- return M;
-}
-
-extern "C" {
-int test__clang_to_IR(struct test_suite *test __maybe_unused,
- int subtest __maybe_unused)
-{
- perf_clang_scope _scope;
-
- auto M = __test__clang_to_IR();
- if (!M)
- return -1;
- for (llvm::Function& F : *M)
- if (F.getName() == "bpf_func__SyS_epoll_pwait")
- return 0;
- return -1;
-}
-
-int test__clang_to_obj(struct test_suite *test __maybe_unused,
- int subtest __maybe_unused)
-{
- perf_clang_scope _scope;
-
- auto M = __test__clang_to_IR();
- if (!M)
- return -1;
-
- auto Buffer = perf::getBPFObjectFromModule(&*M);
- if (!Buffer)
- return -1;
- return 0;
-}
-
-}
diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp
deleted file mode 100644
index 1aad7d6d34aaa639..0000000000000000
--- a/tools/perf/util/c++/clang.cpp
+++ /dev/null
@@ -1,225 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * llvm C frontend for perf. Support dynamically compile C file
- *
- * Inspired by clang example code:
- * http://llvm.org/svn/llvm-project/cfe/trunk/examples/clang-interpreter/main.cpp
- *
- * Copyright (C) 2016 Wang Nan <wangnan0@huawei.com>
- * Copyright (C) 2016 Huawei Inc.
- */
-
-#include "clang/Basic/Version.h"
-#include "clang/CodeGen/CodeGenAction.h"
-#include "clang/Frontend/CompilerInvocation.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/TextDiagnosticPrinter.h"
-#include "clang/Tooling/Tooling.h"
-#include "llvm/IR/LegacyPassManager.h"
-#include "llvm/IR/Module.h"
-#include "llvm/Option/Option.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/ManagedStatic.h"
-#if CLANG_VERSION_MAJOR >= 14
-#include "llvm/MC/TargetRegistry.h"
-#else
-#include "llvm/Support/TargetRegistry.h"
-#endif
-#include "llvm/Support/TargetSelect.h"
-#include "llvm/Target/TargetMachine.h"
-#include "llvm/Target/TargetOptions.h"
-#include <memory>
-
-#include "clang.h"
-#include "clang-c.h"
-
-namespace perf {
-
-static std::unique_ptr<llvm::LLVMContext> LLVMCtx;
-
-using namespace clang;
-
-static CompilerInvocation *
-createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
- DiagnosticsEngine& Diags)
-{
- llvm::opt::ArgStringList CCArgs {
- "-cc1",
- "-triple", "bpf-pc-linux",
- "-fsyntax-only",
- "-O2",
- "-nostdsysteminc",
- "-nobuiltininc",
- "-vectorize-loops",
- "-vectorize-slp",
- "-Wno-unused-value",
- "-Wno-pointer-sign",
- "-x", "c"};
-
- CCArgs.append(CFlags.begin(), CFlags.end());
- CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs
-#if CLANG_VERSION_MAJOR >= 11
- ,/*BinaryName=*/nullptr
-#endif
- );
-
- FrontendOptions& Opts = CI->getFrontendOpts();
- Opts.Inputs.clear();
- Opts.Inputs.emplace_back(Path,
- FrontendOptions::getInputKindForExtension("c"));
- return CI;
-}
-
-static std::unique_ptr<llvm::Module>
-getModuleFromSource(llvm::opt::ArgStringList CFlags,
- StringRef Path, IntrusiveRefCntPtr<vfs::FileSystem> VFS)
-{
- CompilerInstance Clang;
- Clang.createDiagnostics();
-
-#if CLANG_VERSION_MAJOR < 9
- Clang.setVirtualFileSystem(&*VFS);
-#else
- Clang.createFileManager(&*VFS);
-#endif
-
-#if CLANG_VERSION_MAJOR < 4
- IntrusiveRefCntPtr<CompilerInvocation> CI =
- createCompilerInvocation(std::move(CFlags), Path,
- Clang.getDiagnostics());
- Clang.setInvocation(&*CI);
-#else
- std::shared_ptr<CompilerInvocation> CI(
- createCompilerInvocation(std::move(CFlags), Path,
- Clang.getDiagnostics()));
- Clang.setInvocation(CI);
-#endif
-
- std::unique_ptr<CodeGenAction> Act(new EmitLLVMOnlyAction(&*LLVMCtx));
- if (!Clang.ExecuteAction(*Act))
- return std::unique_ptr<llvm::Module>(nullptr);
-
- return Act->takeModule();
-}
-
-std::unique_ptr<llvm::Module>
-getModuleFromSource(llvm::opt::ArgStringList CFlags,
- StringRef Name, StringRef Content)
-{
- using namespace vfs;
-
- llvm::IntrusiveRefCntPtr<OverlayFileSystem> OverlayFS(
- new OverlayFileSystem(getRealFileSystem()));
- llvm::IntrusiveRefCntPtr<InMemoryFileSystem> MemFS(
- new InMemoryFileSystem(true));
-
- /*
- * pushOverlay helps setting working dir for MemFS. Must call
- * before addFile.
- */
- OverlayFS->pushOverlay(MemFS);
- MemFS->addFile(Twine(Name), 0, llvm::MemoryBuffer::getMemBuffer(Content));
-
- return getModuleFromSource(std::move(CFlags), Name, OverlayFS);
-}
-
-std::unique_ptr<llvm::Module>
-getModuleFromSource(llvm::opt::ArgStringList CFlags, StringRef Path)
-{
- IntrusiveRefCntPtr<vfs::FileSystem> VFS(vfs::getRealFileSystem());
- return getModuleFromSource(std::move(CFlags), Path, VFS);
-}
-
-std::unique_ptr<llvm::SmallVectorImpl<char>>
-getBPFObjectFromModule(llvm::Module *Module)
-{
- using namespace llvm;
-
- std::string TargetTriple("bpf-pc-linux");
- std::string Error;
- const Target* Target = TargetRegistry::lookupTarget(TargetTriple, Error);
- if (!Target) {
- llvm::errs() << Error;
- return std::unique_ptr<llvm::SmallVectorImpl<char>>(nullptr);
- }
-
- llvm::TargetOptions Opt;
- TargetMachine *TargetMachine =
- Target->createTargetMachine(TargetTriple,
- "generic", "",
- Opt, Reloc::Static);
-
- Module->setDataLayout(TargetMachine->createDataLayout());
- Module->setTargetTriple(TargetTriple);
-
- std::unique_ptr<SmallVectorImpl<char>> Buffer(new SmallVector<char, 0>());
- raw_svector_ostream ostream(*Buffer);
-
- legacy::PassManager PM;
- bool NotAdded;
- NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream
-#if CLANG_VERSION_MAJOR >= 7
- , /*DwoOut=*/nullptr
-#endif
-#if CLANG_VERSION_MAJOR < 10
- , TargetMachine::CGFT_ObjectFile
-#else
- , llvm::CGFT_ObjectFile
-#endif
- );
- if (NotAdded) {
- llvm::errs() << "TargetMachine can't emit a file of this type\n";
- return std::unique_ptr<llvm::SmallVectorImpl<char>>(nullptr);
- }
- PM.run(*Module);
-
- return Buffer;
-}
-
-}
-
-extern "C" {
-void perf_clang__init(void)
-{
- perf::LLVMCtx.reset(new llvm::LLVMContext());
- LLVMInitializeBPFTargetInfo();
- LLVMInitializeBPFTarget();
- LLVMInitializeBPFTargetMC();
- LLVMInitializeBPFAsmPrinter();
-}
-
-void perf_clang__cleanup(void)
-{
- perf::LLVMCtx.reset(nullptr);
- llvm::llvm_shutdown();
-}
-
-int perf_clang__compile_bpf(const char *filename,
- void **p_obj_buf,
- size_t *p_obj_buf_sz)
-{
- using namespace perf;
-
- if (!p_obj_buf || !p_obj_buf_sz)
- return -EINVAL;
-
- llvm::opt::ArgStringList CFlags;
- auto M = getModuleFromSource(std::move(CFlags), filename);
- if (!M)
- return -EINVAL;
- auto O = getBPFObjectFromModule(&*M);
- if (!O)
- return -EINVAL;
-
- size_t size = O->size_in_bytes();
- void *buffer;
-
- buffer = malloc(size);
- if (!buffer)
- return -ENOMEM;
- memcpy(buffer, O->data(), size);
- *p_obj_buf = buffer;
- *p_obj_buf_sz = size;
- return 0;
-}
-}
diff --git a/tools/perf/util/c++/clang.h b/tools/perf/util/c++/clang.h
deleted file mode 100644
index 6ce33e22f23c084a..0000000000000000
--- a/tools/perf/util/c++/clang.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef PERF_UTIL_CLANG_H
-#define PERF_UTIL_CLANG_H
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
-#include "llvm/Option/Option.h"
-#include <memory>
-
-namespace perf {
-
-using namespace llvm;
-
-std::unique_ptr<Module>
-getModuleFromSource(opt::ArgStringList CFlags,
- StringRef Name, StringRef Content);
-
-std::unique_ptr<Module>
-getModuleFromSource(opt::ArgStringList CFlags,
- StringRef Path);
-
-std::unique_ptr<llvm::SmallVectorImpl<char>>
-getBPFObjectFromModule(llvm::Module *Module);
-
-}
-#endif
--
2.37.1
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH v1 0/4] Remove BPF event support
2023-08-10 18:48 [PATCH v1 0/4] Remove BPF event support Ian Rogers
` (3 preceding siblings ...)
[not found] ` <20230810184853.2860737-2-irogers@google.com>
@ 2023-08-11 16:09 ` Jiri Olsa
4 siblings, 0 replies; 22+ messages in thread
From: Jiri Olsa @ 2023-08-11 16:09 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Namhyung Kim, Adrian Hunter,
Nathan Chancellor, Nick Desaulniers, Tom Rix, Fangrui Song,
Anshuman Khandual, Andi Kleen, Leo Yan, Madhavan Srinivasan,
Carsten Haitzler, Ravi Bangoria, Naveen N. Rao, Athira Rajeev,
Kan Liang, Yang Jihong, James Clark, Tiezhu Yang,
Eduard Zingerman, Andrii Nakryiko, Yonghong Song, Rob Herring,
linux-kernel, linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo,
YueHaibing, He Kuang, Brendan Gregg
On Thu, Aug 10, 2023 at 11:48:49AM -0700, Ian Rogers wrote:
> The patch series removes BPF event support as past commits have shown
> the support has bit rotten:
> https://lore.kernel.org/lkml/20230728001212.457900-1-irogers@google.com/
>
> Similar functionality is now available via the --filter option, that
> uses a BPF skeleton, and is therefore more compact and simpler to
> use. The simplicity coming from not having to build BPF object files.
>
> A different use case for the events was for syscall augmentation in
> perf trace. So that this isn't broken, and to make its use
> significantly simpler, the support is migrated to use a BPF
> skeleton. This means perf trace is much more likely to augment
> syscalls for users.
>
> Removal of BPF events was raised on LKML two weeks ago with the
> original authors cc-ed:
> https://lore.kernel.org/lkml/CAP-5=fXxGimJRXKf7bcaPqfjxxGcn1k3CspY_iSjQnpAKs3uFQ@mail.gmail.com/
>
> BPF events are described publicly in very few places but one is:
> https://www.brendangregg.com/perf.html#eBPF
> "eBPF is currently a little restricted and difficult to use from
> perf. It's getting better all the time. A different and currently
> easier way to access eBPF is via the bcc Python interface, which is
> described on my eBPF Tools page. On this page, I'll discuss perf."
>
> I don't think the "getting better all the time" is any longer true as
> BPF features are being added to perf primarily by using BPF
> skeletons. The given example is a filter and would be better supported
> via "perf record --filter".
agreed, I don't think it's being really used as well,
also caused problems with libbpf updates
>
> Ian Rogers (4):
> perf parse-events: Remove BPF event support
> perf trace: Migrate BPF augmentation to use a skeleton
> perf bpf examples: With no BPF events remove examples
> perf trace: Tidy comments
>
> tools/perf/Documentation/perf-config.txt | 33 -
> tools/perf/Documentation/perf-record.txt | 22 -
> tools/perf/Makefile.config | 43 -
> tools/perf/Makefile.perf | 19 +-
> tools/perf/builtin-record.c | 45 -
> tools/perf/builtin-trace.c | 310 +--
> tools/perf/examples/bpf/5sec.c | 53 -
> tools/perf/examples/bpf/empty.c | 12 -
> tools/perf/examples/bpf/hello.c | 27 -
> tools/perf/examples/bpf/sys_enter_openat.c | 33 -
> tools/perf/perf.c | 2 -
> tools/perf/tests/.gitignore | 5 -
> tools/perf/tests/Build | 31 -
> tools/perf/tests/bpf-script-example.c | 60 -
> tools/perf/tests/bpf-script-test-kbuild.c | 21 -
> tools/perf/tests/bpf-script-test-prologue.c | 49 -
> tools/perf/tests/bpf-script-test-relocation.c | 51 -
> tools/perf/tests/bpf.c | 390 ----
> tools/perf/tests/builtin-test.c | 3 -
> tools/perf/tests/clang.c | 32 -
> tools/perf/tests/llvm.c | 219 --
> tools/perf/tests/llvm.h | 31 -
> tools/perf/tests/make | 2 -
> tools/perf/tests/tests.h | 2 -
> tools/perf/trace/beauty/beauty.h | 15 +-
> tools/perf/util/Build | 8 +-
> tools/perf/util/bpf-loader.c | 2006 -----------------
> tools/perf/util/bpf-loader.h | 216 --
> .../bpf_skel/augmented_raw_syscalls.bpf.c} | 35 +-
> tools/perf/util/c++/Build | 5 -
> tools/perf/util/c++/clang-c.h | 43 -
> tools/perf/util/c++/clang-test.cpp | 67 -
> tools/perf/util/c++/clang.cpp | 225 --
> tools/perf/util/c++/clang.h | 27 -
> tools/perf/util/config.c | 4 -
> tools/perf/util/llvm-utils.c | 612 -----
> tools/perf/util/llvm-utils.h | 69 -
> tools/perf/util/parse-events.c | 268 ---
> tools/perf/util/parse-events.h | 15 -
> tools/perf/util/parse-events.l | 31 -
> tools/perf/util/parse-events.y | 44 +-
> 41 files changed, 133 insertions(+), 5052 deletions(-)
awesome :))
Acked-by: Jiri Olsa <jolsa@kernel.org>
thanks,
jirka
> delete mode 100644 tools/perf/examples/bpf/5sec.c
> delete mode 100644 tools/perf/examples/bpf/empty.c
> delete mode 100644 tools/perf/examples/bpf/hello.c
> delete mode 100644 tools/perf/examples/bpf/sys_enter_openat.c
> delete mode 100644 tools/perf/tests/.gitignore
> delete mode 100644 tools/perf/tests/bpf-script-example.c
> delete mode 100644 tools/perf/tests/bpf-script-test-kbuild.c
> delete mode 100644 tools/perf/tests/bpf-script-test-prologue.c
> delete mode 100644 tools/perf/tests/bpf-script-test-relocation.c
> delete mode 100644 tools/perf/tests/bpf.c
> delete mode 100644 tools/perf/tests/clang.c
> delete mode 100644 tools/perf/tests/llvm.c
> delete mode 100644 tools/perf/tests/llvm.h
> delete mode 100644 tools/perf/util/bpf-loader.c
> delete mode 100644 tools/perf/util/bpf-loader.h
> rename tools/perf/{examples/bpf/augmented_raw_syscalls.c => util/bpf_skel/augmented_raw_syscalls.bpf.c} (93%)
> delete mode 100644 tools/perf/util/c++/Build
> delete mode 100644 tools/perf/util/c++/clang-c.h
> delete mode 100644 tools/perf/util/c++/clang-test.cpp
> delete mode 100644 tools/perf/util/c++/clang.cpp
> delete mode 100644 tools/perf/util/c++/clang.h
> delete mode 100644 tools/perf/util/llvm-utils.c
> delete mode 100644 tools/perf/util/llvm-utils.h
>
> --
> 2.41.0.640.ga95def55d0-goog
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton
2023-08-10 18:48 ` [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton Ian Rogers
@ 2023-08-11 16:09 ` Jiri Olsa
2023-08-11 16:24 ` Ian Rogers
2023-08-11 18:46 ` Arnaldo Carvalho de Melo
2023-08-15 14:25 ` Arnaldo Carvalho de Melo
2 siblings, 1 reply; 22+ messages in thread
From: Jiri Olsa @ 2023-08-11 16:09 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Namhyung Kim, Adrian Hunter,
Nathan Chancellor, Nick Desaulniers, Tom Rix, Fangrui Song,
Anshuman Khandual, Andi Kleen, Leo Yan, Madhavan Srinivasan,
Carsten Haitzler, Ravi Bangoria, Naveen N. Rao, Athira Rajeev,
Kan Liang, Yang Jihong, James Clark, Tiezhu Yang,
Eduard Zingerman, Andrii Nakryiko, Yonghong Song, Rob Herring,
linux-kernel, linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo,
YueHaibing, He Kuang, Brendan Gregg
On Thu, Aug 10, 2023 at 11:48:51AM -0700, Ian Rogers wrote:
> Previously a BPF event of augmented_raw_syscalls.c could be used to
> enable augmentation of syscalls by perf trace. As BPF events are no
> longer supported, switch to using a BPF skeleton which when attached
> explicitly opens the sysenter and sysexit tracepoints.
>
> The dump map is removed as debugging wasn't supported by the
> augmentation and bpf_printk can be used when necessary.
>
> Remove tools/perf/examples/bpf/augmented_raw_syscalls.c so that the
> rename/migration to a BPF skeleton captures that this was the source.
there's still some:
[jolsa@krava perf]$ grep -r augmented_raw_syscalls.c
builtin-trace.c: * (now tools/perf/examples/bpf/augmented_raw_syscalls.c, so that it
builtin-trace.c: * tools/perf/examples/bpf/augmented_raw_syscalls.c,
Documentation/perf-trace.txt: living in tools/perf/examples/bpf/augmented_raw_syscalls.c. For now this
jirka
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> tools/perf/Makefile.perf | 1 +
> tools/perf/builtin-trace.c | 180 +++++++++++-------
> .../bpf_skel/augmented_raw_syscalls.bpf.c} | 27 +--
> 3 files changed, 131 insertions(+), 77 deletions(-)
> rename tools/perf/{examples/bpf/augmented_raw_syscalls.c => util/bpf_skel/augmented_raw_syscalls.bpf.c} (96%)
>
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 6ec5079fd697..0e1597712b95 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -1042,6 +1042,7 @@ SKELETONS += $(SKEL_OUT)/bperf_cgroup.skel.h $(SKEL_OUT)/func_latency.skel.h
> SKELETONS += $(SKEL_OUT)/off_cpu.skel.h $(SKEL_OUT)/lock_contention.skel.h
> SKELETONS += $(SKEL_OUT)/kwork_trace.skel.h $(SKEL_OUT)/sample_filter.skel.h
> SKELETONS += $(SKEL_OUT)/bench_uprobe.skel.h
> +SKELETONS += $(SKEL_OUT)/augmented_raw_syscalls.skel.h
>
> $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT):
> $(Q)$(MKDIR) -p $@
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index 59862467e781..8625fca42cd8 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -19,6 +19,9 @@
> #ifdef HAVE_LIBBPF_SUPPORT
> #include <bpf/bpf.h>
> #include <bpf/libbpf.h>
> +#ifdef HAVE_BPF_SKEL
> +#include "bpf_skel/augmented_raw_syscalls.skel.h"
> +#endif
> #endif
> #include "util/bpf_map.h"
> #include "util/rlimit.h"
> @@ -127,25 +130,19 @@ struct trace {
> struct syscalltbl *sctbl;
> struct {
> struct syscall *table;
> - struct { // per syscall BPF_MAP_TYPE_PROG_ARRAY
> - struct bpf_map *sys_enter,
> - *sys_exit;
> - } prog_array;
> struct {
> struct evsel *sys_enter,
> - *sys_exit,
> - *augmented;
> + *sys_exit,
> + *bpf_output;
> } events;
> - struct bpf_program *unaugmented_prog;
> } syscalls;
> - struct {
> - struct bpf_map *map;
> - } dump;
> +#ifdef HAVE_BPF_SKEL
> + struct augmented_raw_syscalls_bpf *skel;
> +#endif
> struct record_opts opts;
> struct evlist *evlist;
> struct machine *host;
> struct thread *current;
> - struct bpf_object *bpf_obj;
> struct cgroup *cgroup;
> u64 base_time;
> FILE *output;
> @@ -415,6 +412,7 @@ static int evsel__init_syscall_tp(struct evsel *evsel)
> if (evsel__init_tp_uint_field(evsel, &sc->id, "__syscall_nr") &&
> evsel__init_tp_uint_field(evsel, &sc->id, "nr"))
> return -ENOENT;
> +
> return 0;
> }
>
> @@ -2845,7 +2843,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,
> if (thread)
> trace__fprintf_comm_tid(trace, thread, trace->output);
>
> - if (evsel == trace->syscalls.events.augmented) {
> + if (evsel == trace->syscalls.events.bpf_output) {
> int id = perf_evsel__sc_tp_uint(evsel, id, sample);
> struct syscall *sc = trace__syscall_info(trace, evsel, id);
>
> @@ -3278,24 +3276,16 @@ static int trace__set_ev_qualifier_tp_filter(struct trace *trace)
> goto out;
> }
>
> -#ifdef HAVE_LIBBPF_SUPPORT
> -static struct bpf_map *trace__find_bpf_map_by_name(struct trace *trace, const char *name)
> -{
> - if (trace->bpf_obj == NULL)
> - return NULL;
> -
> - return bpf_object__find_map_by_name(trace->bpf_obj, name);
> -}
> -
> +#ifdef HAVE_BPF_SKEL
> static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace, const char *name)
> {
> struct bpf_program *pos, *prog = NULL;
> const char *sec_name;
>
> - if (trace->bpf_obj == NULL)
> + if (trace->skel->obj == NULL)
> return NULL;
>
> - bpf_object__for_each_program(pos, trace->bpf_obj) {
> + bpf_object__for_each_program(pos, trace->skel->obj) {
> sec_name = bpf_program__section_name(pos);
> if (sec_name && !strcmp(sec_name, name)) {
> prog = pos;
> @@ -3313,12 +3303,14 @@ static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, str
>
> if (prog_name == NULL) {
> char default_prog_name[256];
> - scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->name);
> + scnprintf(default_prog_name, sizeof(default_prog_name), "tp/syscalls/sys_%s_%s",
> + type, sc->name);
> prog = trace__find_bpf_program_by_title(trace, default_prog_name);
> if (prog != NULL)
> goto out_found;
> if (sc->fmt && sc->fmt->alias) {
> - scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->fmt->alias);
> + scnprintf(default_prog_name, sizeof(default_prog_name),
> + "tp/syscalls/sys_%s_%s", type, sc->fmt->alias);
> prog = trace__find_bpf_program_by_title(trace, default_prog_name);
> if (prog != NULL)
> goto out_found;
> @@ -3336,7 +3328,7 @@ static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, str
> pr_debug("Couldn't find BPF prog \"%s\" to associate with syscalls:sys_%s_%s, not augmenting it\n",
> prog_name, type, sc->name);
> out_unaugmented:
> - return trace->syscalls.unaugmented_prog;
> + return trace->skel->progs.syscall_unaugmented;
> }
>
> static void trace__init_syscall_bpf_progs(struct trace *trace, int id)
> @@ -3353,13 +3345,21 @@ static void trace__init_syscall_bpf_progs(struct trace *trace, int id)
> static int trace__bpf_prog_sys_enter_fd(struct trace *trace, int id)
> {
> struct syscall *sc = trace__syscall_info(trace, NULL, id);
> - return sc ? bpf_program__fd(sc->bpf_prog.sys_enter) : bpf_program__fd(trace->syscalls.unaugmented_prog);
> +
> + if (sc)
> + return bpf_program__fd(sc->bpf_prog.sys_enter);
> +
> + return bpf_program__fd(trace->skel->progs.syscall_unaugmented);
> }
>
> static int trace__bpf_prog_sys_exit_fd(struct trace *trace, int id)
> {
> struct syscall *sc = trace__syscall_info(trace, NULL, id);
> - return sc ? bpf_program__fd(sc->bpf_prog.sys_exit) : bpf_program__fd(trace->syscalls.unaugmented_prog);
> +
> + if (sc)
> + return bpf_program__fd(sc->bpf_prog.sys_exit);
> +
> + return bpf_program__fd(trace->skel->progs.syscall_unaugmented);
> }
>
> static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace, struct syscall *sc)
> @@ -3384,7 +3384,7 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace
> bool is_candidate = false;
>
> if (pair == NULL || pair == sc ||
> - pair->bpf_prog.sys_enter == trace->syscalls.unaugmented_prog)
> + pair->bpf_prog.sys_enter == trace->skel->progs.syscall_unaugmented)
> continue;
>
> for (field = sc->args, candidate_field = pair->args;
> @@ -3437,7 +3437,7 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace
> */
> if (pair_prog == NULL) {
> pair_prog = trace__find_syscall_bpf_prog(trace, pair, pair->fmt ? pair->fmt->bpf_prog_name.sys_enter : NULL, "enter");
> - if (pair_prog == trace->syscalls.unaugmented_prog)
> + if (pair_prog == trace->skel->progs.syscall_unaugmented)
> goto next_candidate;
> }
>
> @@ -3452,8 +3452,8 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace
>
> static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
> {
> - int map_enter_fd = bpf_map__fd(trace->syscalls.prog_array.sys_enter),
> - map_exit_fd = bpf_map__fd(trace->syscalls.prog_array.sys_exit);
> + int map_enter_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_enter);
> + int map_exit_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_exit);
> int err = 0, key;
>
> for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
> @@ -3515,7 +3515,7 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
> * For now we're just reusing the sys_enter prog, and if it
> * already has an augmenter, we don't need to find one.
> */
> - if (sc->bpf_prog.sys_enter != trace->syscalls.unaugmented_prog)
> + if (sc->bpf_prog.sys_enter != trace->skel->progs.syscall_unaugmented)
> continue;
>
> /*
> @@ -3538,22 +3538,9 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
> break;
> }
>
> -
> return err;
> }
> -
> -#else // HAVE_LIBBPF_SUPPORT
> -static struct bpf_map *trace__find_bpf_map_by_name(struct trace *trace __maybe_unused,
> - const char *name __maybe_unused)
> -{
> - return NULL;
> -}
> -
> -static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace __maybe_unused)
> -{
> - return 0;
> -}
> -#endif // HAVE_LIBBPF_SUPPORT
> +#endif // HAVE_BPF_SKEL
>
> static int trace__set_ev_qualifier_filter(struct trace *trace)
> {
> @@ -3917,13 +3904,31 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
> err = evlist__open(evlist);
> if (err < 0)
> goto out_error_open;
> +#ifdef HAVE_BPF_SKEL
> + {
> + struct perf_cpu cpu;
>
> + /*
> + * Set up the __augmented_syscalls__ BPF map to hold for each
> + * CPU the bpf-output event's file descriptor.
> + */
> + perf_cpu_map__for_each_cpu(cpu, i, trace->syscalls.events.bpf_output->core.cpus) {
> + bpf_map__update_elem(trace->skel->maps.__augmented_syscalls__,
> + &cpu.cpu, sizeof(int),
> + xyarray__entry(trace->syscalls.events.bpf_output->core.fd,
> + cpu.cpu, 0),
> + sizeof(__u32), BPF_ANY);
> + }
> + }
> +#endif
> err = trace__set_filter_pids(trace);
> if (err < 0)
> goto out_error_mem;
>
> - if (trace->syscalls.prog_array.sys_enter)
> +#ifdef HAVE_BPF_SKEL
> + if (trace->skel->progs.sys_enter)
> trace__init_syscalls_bpf_prog_array_maps(trace);
> +#endif
>
> if (trace->ev_qualifier_ids.nr > 0) {
> err = trace__set_ev_qualifier_filter(trace);
> @@ -3956,9 +3961,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
> if (err < 0)
> goto out_error_apply_filters;
>
> - if (trace->dump.map)
> - bpf_map__fprintf(trace->dump.map, trace->output);
> -
> err = evlist__mmap(evlist, trace->opts.mmap_pages);
> if (err < 0)
> goto out_error_mmap;
> @@ -4655,6 +4657,18 @@ static void trace__exit(struct trace *trace)
> zfree(&trace->perfconfig_events);
> }
>
> +#ifdef HAVE_BPF_SKEL
> +static int bpf__setup_bpf_output(struct evlist *evlist)
> +{
> + int err = parse_event(evlist, "bpf-output/no-inherit=1,name=__augmented_syscalls__/");
> +
> + if (err)
> + pr_debug("ERROR: failed to create the \"__augmented_syscalls__\" bpf-output event\n");
> +
> + return err;
> +}
> +#endif
> +
> int cmd_trace(int argc, const char **argv)
> {
> const char *trace_usage[] = {
> @@ -4686,7 +4700,6 @@ int cmd_trace(int argc, const char **argv)
> .max_stack = UINT_MAX,
> .max_events = ULONG_MAX,
> };
> - const char *map_dump_str = NULL;
> const char *output_name = NULL;
> const struct option trace_options[] = {
> OPT_CALLBACK('e', "event", &trace, "event",
> @@ -4720,9 +4733,6 @@ int cmd_trace(int argc, const char **argv)
> OPT_CALLBACK(0, "duration", &trace, "float",
> "show only events with duration > N.M ms",
> trace__set_duration),
> -#ifdef HAVE_LIBBPF_SUPPORT
> - OPT_STRING(0, "map-dump", &map_dump_str, "BPF map", "BPF map to periodically dump"),
> -#endif
> OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"),
> OPT_INCR('v', "verbose", &verbose, "be more verbose"),
> OPT_BOOLEAN('T', "time", &trace.full_time,
> @@ -4849,16 +4859,55 @@ int cmd_trace(int argc, const char **argv)
> "cgroup monitoring only available in system-wide mode");
> }
>
> - err = -1;
> +#ifdef HAVE_BPF_SKEL
> + trace.skel = augmented_raw_syscalls_bpf__open();
> + if (!trace.skel) {
> + pr_debug("Failed to open augmented syscalls BPF skeleton");
> + } else {
> + /*
> + * Disable attaching the BPF programs except for sys_enter and
> + * sys_exit that tail call into this as necessary.
> + */
> + bpf_program__set_autoattach(trace.skel->progs.syscall_unaugmented,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_connect,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_sendto,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_open,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_openat,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_rename,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_renameat,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_perf_event_open,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_clock_nanosleep,
> + /*autoattach=*/false);
> +
> + err = augmented_raw_syscalls_bpf__load(trace.skel);
>
> - if (map_dump_str) {
> - trace.dump.map = trace__find_bpf_map_by_name(&trace, map_dump_str);
> - if (trace.dump.map == NULL) {
> - pr_err("ERROR: BPF map \"%s\" not found\n", map_dump_str);
> - goto out;
> + if (err < 0) {
> + pr_debug("Failed to load augmented syscalls BPF skeleton\n");
> + } else {
> + augmented_raw_syscalls_bpf__attach(trace.skel);
> + trace__add_syscall_newtp(&trace);
> }
> }
>
> + err = bpf__setup_bpf_output(trace.evlist);
> + if (err) {
> + libbpf_strerror(err, bf, sizeof(bf));
> + pr_err("ERROR: Setup BPF output event failed: %s\n", bf);
> + goto out;
> + }
> + trace.syscalls.events.bpf_output = evlist__last(trace.evlist);
> + assert(!strcmp(evsel__name(trace.syscalls.events.bpf_output), "__augmented_syscalls__"));
> +#endif
> + err = -1;
> +
> if (trace.trace_pgfaults) {
> trace.opts.sample_address = true;
> trace.opts.sample_time = true;
> @@ -4909,7 +4958,7 @@ int cmd_trace(int argc, const char **argv)
> * buffers that are being copied from kernel to userspace, think 'read'
> * syscall.
> */
> - if (trace.syscalls.events.augmented) {
> + if (trace.syscalls.events.bpf_output) {
> evlist__for_each_entry(trace.evlist, evsel) {
> bool raw_syscalls_sys_exit = strcmp(evsel__name(evsel), "raw_syscalls:sys_exit") == 0;
>
> @@ -4918,9 +4967,9 @@ int cmd_trace(int argc, const char **argv)
> goto init_augmented_syscall_tp;
> }
>
> - if (trace.syscalls.events.augmented->priv == NULL &&
> + if (trace.syscalls.events.bpf_output->priv == NULL &&
> strstr(evsel__name(evsel), "syscalls:sys_enter")) {
> - struct evsel *augmented = trace.syscalls.events.augmented;
> + struct evsel *augmented = trace.syscalls.events.bpf_output;
> if (evsel__init_augmented_syscall_tp(augmented, evsel) ||
> evsel__init_augmented_syscall_tp_args(augmented))
> goto out;
> @@ -5025,5 +5074,8 @@ int cmd_trace(int argc, const char **argv)
> fclose(trace.output);
> out:
> trace__exit(&trace);
> +#ifdef HAVE_BPF_SKEL
> + augmented_raw_syscalls_bpf__destroy(trace.skel);
> +#endif
> return err;
> }
> diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
> similarity index 96%
> rename from tools/perf/examples/bpf/augmented_raw_syscalls.c
> rename to tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
> index 9a03189d33d3..70478b9460ee 100644
> --- a/tools/perf/examples/bpf/augmented_raw_syscalls.c
> +++ b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
> @@ -18,6 +18,8 @@
> #include <bpf/bpf_helpers.h>
> #include <linux/limits.h>
>
> +#define MAX_CPUS 4096
> +
> // FIXME: These should come from system headers
> typedef char bool;
> typedef int pid_t;
> @@ -34,7 +36,7 @@ struct __augmented_syscalls__ {
> __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
> __type(key, int);
> __type(value, __u32);
> - __uint(max_entries, __NR_CPUS__);
> + __uint(max_entries, MAX_CPUS);
> } __augmented_syscalls__ SEC(".maps");
>
> /*
> @@ -170,7 +172,7 @@ unsigned int augmented_arg__read_str(struct augmented_arg *augmented_arg, const
> return augmented_len;
> }
>
> -SEC("!raw_syscalls:unaugmented")
> +SEC("tp/raw_syscalls/sys_enter")
> int syscall_unaugmented(struct syscall_enter_args *args)
> {
> return 1;
> @@ -182,7 +184,7 @@ int syscall_unaugmented(struct syscall_enter_args *args)
> * on from there, reading the first syscall arg as a string, i.e. open's
> * filename.
> */
> -SEC("!syscalls:sys_enter_connect")
> +SEC("tp/syscalls/sys_enter_connect")
> int sys_enter_connect(struct syscall_enter_args *args)
> {
> struct augmented_args_payload *augmented_args = augmented_args_payload();
> @@ -201,7 +203,7 @@ int sys_enter_connect(struct syscall_enter_args *args)
> return augmented__output(args, augmented_args, len + socklen);
> }
>
> -SEC("!syscalls:sys_enter_sendto")
> +SEC("tp/syscalls/sys_enter_sendto")
> int sys_enter_sendto(struct syscall_enter_args *args)
> {
> struct augmented_args_payload *augmented_args = augmented_args_payload();
> @@ -220,7 +222,7 @@ int sys_enter_sendto(struct syscall_enter_args *args)
> return augmented__output(args, augmented_args, len + socklen);
> }
>
> -SEC("!syscalls:sys_enter_open")
> +SEC("tp/syscalls/sys_enter_open")
> int sys_enter_open(struct syscall_enter_args *args)
> {
> struct augmented_args_payload *augmented_args = augmented_args_payload();
> @@ -235,7 +237,7 @@ int sys_enter_open(struct syscall_enter_args *args)
> return augmented__output(args, augmented_args, len);
> }
>
> -SEC("!syscalls:sys_enter_openat")
> +SEC("tp/syscalls/sys_enter_openat")
> int sys_enter_openat(struct syscall_enter_args *args)
> {
> struct augmented_args_payload *augmented_args = augmented_args_payload();
> @@ -250,7 +252,7 @@ int sys_enter_openat(struct syscall_enter_args *args)
> return augmented__output(args, augmented_args, len);
> }
>
> -SEC("!syscalls:sys_enter_rename")
> +SEC("tp/syscalls/sys_enter_rename")
> int sys_enter_rename(struct syscall_enter_args *args)
> {
> struct augmented_args_payload *augmented_args = augmented_args_payload();
> @@ -267,7 +269,7 @@ int sys_enter_rename(struct syscall_enter_args *args)
> return augmented__output(args, augmented_args, len);
> }
>
> -SEC("!syscalls:sys_enter_renameat")
> +SEC("tp/syscalls/sys_enter_renameat")
> int sys_enter_renameat(struct syscall_enter_args *args)
> {
> struct augmented_args_payload *augmented_args = augmented_args_payload();
> @@ -295,7 +297,7 @@ struct perf_event_attr_size {
> __u32 size;
> };
>
> -SEC("!syscalls:sys_enter_perf_event_open")
> +SEC("tp/syscalls/sys_enter_perf_event_open")
> int sys_enter_perf_event_open(struct syscall_enter_args *args)
> {
> struct augmented_args_payload *augmented_args = augmented_args_payload();
> @@ -327,7 +329,7 @@ int sys_enter_perf_event_open(struct syscall_enter_args *args)
> return 1; /* Failure: don't filter */
> }
>
> -SEC("!syscalls:sys_enter_clock_nanosleep")
> +SEC("tp/syscalls/sys_enter_clock_nanosleep")
> int sys_enter_clock_nanosleep(struct syscall_enter_args *args)
> {
> struct augmented_args_payload *augmented_args = augmented_args_payload();
> @@ -358,7 +360,7 @@ static bool pid_filter__has(struct pids_filtered *pids, pid_t pid)
> return bpf_map_lookup_elem(pids, &pid) != NULL;
> }
>
> -SEC("raw_syscalls:sys_enter")
> +SEC("tp/raw_syscalls/sys_enter")
> int sys_enter(struct syscall_enter_args *args)
> {
> struct augmented_args_payload *augmented_args;
> @@ -371,7 +373,6 @@ int sys_enter(struct syscall_enter_args *args)
> * We'll add to this as we add augmented syscalls right after that
> * initial, non-augmented raw_syscalls:sys_enter payload.
> */
> - unsigned int len = sizeof(augmented_args->args);
>
> if (pid_filter__has(&pids_filtered, getpid()))
> return 0;
> @@ -393,7 +394,7 @@ int sys_enter(struct syscall_enter_args *args)
> return 0;
> }
>
> -SEC("raw_syscalls:sys_exit")
> +SEC("tp/raw_syscalls/sys_exit")
> int sys_exit(struct syscall_exit_args *args)
> {
> struct syscall_exit_args exit_args;
> --
> 2.41.0.640.ga95def55d0-goog
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton
2023-08-11 16:09 ` Jiri Olsa
@ 2023-08-11 16:24 ` Ian Rogers
0 siblings, 0 replies; 22+ messages in thread
From: Ian Rogers @ 2023-08-11 16:24 UTC (permalink / raw)
To: Jiri Olsa
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Namhyung Kim, Adrian Hunter,
Nathan Chancellor, Nick Desaulniers, Tom Rix, Fangrui Song,
Anshuman Khandual, Andi Kleen, Leo Yan, Madhavan Srinivasan,
Carsten Haitzler, Ravi Bangoria, Naveen N. Rao, Athira Rajeev,
Kan Liang, Yang Jihong, James Clark, Tiezhu Yang,
Eduard Zingerman, Andrii Nakryiko, Yonghong Song, Rob Herring,
linux-kernel, linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo,
YueHaibing, Brendan Gregg
On Fri, Aug 11, 2023 at 9:09 AM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> On Thu, Aug 10, 2023 at 11:48:51AM -0700, Ian Rogers wrote:
> > Previously a BPF event of augmented_raw_syscalls.c could be used to
> > enable augmentation of syscalls by perf trace. As BPF events are no
> > longer supported, switch to using a BPF skeleton which when attached
> > explicitly opens the sysenter and sysexit tracepoints.
> >
> > The dump map is removed as debugging wasn't supported by the
> > augmentation and bpf_printk can be used when necessary.
> >
> > Remove tools/perf/examples/bpf/augmented_raw_syscalls.c so that the
> > rename/migration to a BPF skeleton captures that this was the source.
>
> there's still some:
>
> [jolsa@krava perf]$ grep -r augmented_raw_syscalls.c
> builtin-trace.c: * (now tools/perf/examples/bpf/augmented_raw_syscalls.c, so that it
> builtin-trace.c: * tools/perf/examples/bpf/augmented_raw_syscalls.c,
> Documentation/perf-trace.txt: living in tools/perf/examples/bpf/augmented_raw_syscalls.c. For now this
Agreed, I'll double check but the later patches remove these. I was
trying to keep this patch down to a minimum one approach switch to the
other.
Thanks,
Ian
> jirka
>
> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> > tools/perf/Makefile.perf | 1 +
> > tools/perf/builtin-trace.c | 180 +++++++++++-------
> > .../bpf_skel/augmented_raw_syscalls.bpf.c} | 27 +--
> > 3 files changed, 131 insertions(+), 77 deletions(-)
> > rename tools/perf/{examples/bpf/augmented_raw_syscalls.c => util/bpf_skel/augmented_raw_syscalls.bpf.c} (96%)
> >
> > diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> > index 6ec5079fd697..0e1597712b95 100644
> > --- a/tools/perf/Makefile.perf
> > +++ b/tools/perf/Makefile.perf
> > @@ -1042,6 +1042,7 @@ SKELETONS += $(SKEL_OUT)/bperf_cgroup.skel.h $(SKEL_OUT)/func_latency.skel.h
> > SKELETONS += $(SKEL_OUT)/off_cpu.skel.h $(SKEL_OUT)/lock_contention.skel.h
> > SKELETONS += $(SKEL_OUT)/kwork_trace.skel.h $(SKEL_OUT)/sample_filter.skel.h
> > SKELETONS += $(SKEL_OUT)/bench_uprobe.skel.h
> > +SKELETONS += $(SKEL_OUT)/augmented_raw_syscalls.skel.h
> >
> > $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT):
> > $(Q)$(MKDIR) -p $@
> > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> > index 59862467e781..8625fca42cd8 100644
> > --- a/tools/perf/builtin-trace.c
> > +++ b/tools/perf/builtin-trace.c
> > @@ -19,6 +19,9 @@
> > #ifdef HAVE_LIBBPF_SUPPORT
> > #include <bpf/bpf.h>
> > #include <bpf/libbpf.h>
> > +#ifdef HAVE_BPF_SKEL
> > +#include "bpf_skel/augmented_raw_syscalls.skel.h"
> > +#endif
> > #endif
> > #include "util/bpf_map.h"
> > #include "util/rlimit.h"
> > @@ -127,25 +130,19 @@ struct trace {
> > struct syscalltbl *sctbl;
> > struct {
> > struct syscall *table;
> > - struct { // per syscall BPF_MAP_TYPE_PROG_ARRAY
> > - struct bpf_map *sys_enter,
> > - *sys_exit;
> > - } prog_array;
> > struct {
> > struct evsel *sys_enter,
> > - *sys_exit,
> > - *augmented;
> > + *sys_exit,
> > + *bpf_output;
> > } events;
> > - struct bpf_program *unaugmented_prog;
> > } syscalls;
> > - struct {
> > - struct bpf_map *map;
> > - } dump;
> > +#ifdef HAVE_BPF_SKEL
> > + struct augmented_raw_syscalls_bpf *skel;
> > +#endif
> > struct record_opts opts;
> > struct evlist *evlist;
> > struct machine *host;
> > struct thread *current;
> > - struct bpf_object *bpf_obj;
> > struct cgroup *cgroup;
> > u64 base_time;
> > FILE *output;
> > @@ -415,6 +412,7 @@ static int evsel__init_syscall_tp(struct evsel *evsel)
> > if (evsel__init_tp_uint_field(evsel, &sc->id, "__syscall_nr") &&
> > evsel__init_tp_uint_field(evsel, &sc->id, "nr"))
> > return -ENOENT;
> > +
> > return 0;
> > }
> >
> > @@ -2845,7 +2843,7 @@ static int trace__event_handler(struct trace *trace, struct evsel *evsel,
> > if (thread)
> > trace__fprintf_comm_tid(trace, thread, trace->output);
> >
> > - if (evsel == trace->syscalls.events.augmented) {
> > + if (evsel == trace->syscalls.events.bpf_output) {
> > int id = perf_evsel__sc_tp_uint(evsel, id, sample);
> > struct syscall *sc = trace__syscall_info(trace, evsel, id);
> >
> > @@ -3278,24 +3276,16 @@ static int trace__set_ev_qualifier_tp_filter(struct trace *trace)
> > goto out;
> > }
> >
> > -#ifdef HAVE_LIBBPF_SUPPORT
> > -static struct bpf_map *trace__find_bpf_map_by_name(struct trace *trace, const char *name)
> > -{
> > - if (trace->bpf_obj == NULL)
> > - return NULL;
> > -
> > - return bpf_object__find_map_by_name(trace->bpf_obj, name);
> > -}
> > -
> > +#ifdef HAVE_BPF_SKEL
> > static struct bpf_program *trace__find_bpf_program_by_title(struct trace *trace, const char *name)
> > {
> > struct bpf_program *pos, *prog = NULL;
> > const char *sec_name;
> >
> > - if (trace->bpf_obj == NULL)
> > + if (trace->skel->obj == NULL)
> > return NULL;
> >
> > - bpf_object__for_each_program(pos, trace->bpf_obj) {
> > + bpf_object__for_each_program(pos, trace->skel->obj) {
> > sec_name = bpf_program__section_name(pos);
> > if (sec_name && !strcmp(sec_name, name)) {
> > prog = pos;
> > @@ -3313,12 +3303,14 @@ static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, str
> >
> > if (prog_name == NULL) {
> > char default_prog_name[256];
> > - scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->name);
> > + scnprintf(default_prog_name, sizeof(default_prog_name), "tp/syscalls/sys_%s_%s",
> > + type, sc->name);
> > prog = trace__find_bpf_program_by_title(trace, default_prog_name);
> > if (prog != NULL)
> > goto out_found;
> > if (sc->fmt && sc->fmt->alias) {
> > - scnprintf(default_prog_name, sizeof(default_prog_name), "!syscalls:sys_%s_%s", type, sc->fmt->alias);
> > + scnprintf(default_prog_name, sizeof(default_prog_name),
> > + "tp/syscalls/sys_%s_%s", type, sc->fmt->alias);
> > prog = trace__find_bpf_program_by_title(trace, default_prog_name);
> > if (prog != NULL)
> > goto out_found;
> > @@ -3336,7 +3328,7 @@ static struct bpf_program *trace__find_syscall_bpf_prog(struct trace *trace, str
> > pr_debug("Couldn't find BPF prog \"%s\" to associate with syscalls:sys_%s_%s, not augmenting it\n",
> > prog_name, type, sc->name);
> > out_unaugmented:
> > - return trace->syscalls.unaugmented_prog;
> > + return trace->skel->progs.syscall_unaugmented;
> > }
> >
> > static void trace__init_syscall_bpf_progs(struct trace *trace, int id)
> > @@ -3353,13 +3345,21 @@ static void trace__init_syscall_bpf_progs(struct trace *trace, int id)
> > static int trace__bpf_prog_sys_enter_fd(struct trace *trace, int id)
> > {
> > struct syscall *sc = trace__syscall_info(trace, NULL, id);
> > - return sc ? bpf_program__fd(sc->bpf_prog.sys_enter) : bpf_program__fd(trace->syscalls.unaugmented_prog);
> > +
> > + if (sc)
> > + return bpf_program__fd(sc->bpf_prog.sys_enter);
> > +
> > + return bpf_program__fd(trace->skel->progs.syscall_unaugmented);
> > }
> >
> > static int trace__bpf_prog_sys_exit_fd(struct trace *trace, int id)
> > {
> > struct syscall *sc = trace__syscall_info(trace, NULL, id);
> > - return sc ? bpf_program__fd(sc->bpf_prog.sys_exit) : bpf_program__fd(trace->syscalls.unaugmented_prog);
> > +
> > + if (sc)
> > + return bpf_program__fd(sc->bpf_prog.sys_exit);
> > +
> > + return bpf_program__fd(trace->skel->progs.syscall_unaugmented);
> > }
> >
> > static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace, struct syscall *sc)
> > @@ -3384,7 +3384,7 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace
> > bool is_candidate = false;
> >
> > if (pair == NULL || pair == sc ||
> > - pair->bpf_prog.sys_enter == trace->syscalls.unaugmented_prog)
> > + pair->bpf_prog.sys_enter == trace->skel->progs.syscall_unaugmented)
> > continue;
> >
> > for (field = sc->args, candidate_field = pair->args;
> > @@ -3437,7 +3437,7 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace
> > */
> > if (pair_prog == NULL) {
> > pair_prog = trace__find_syscall_bpf_prog(trace, pair, pair->fmt ? pair->fmt->bpf_prog_name.sys_enter : NULL, "enter");
> > - if (pair_prog == trace->syscalls.unaugmented_prog)
> > + if (pair_prog == trace->skel->progs.syscall_unaugmented)
> > goto next_candidate;
> > }
> >
> > @@ -3452,8 +3452,8 @@ static struct bpf_program *trace__find_usable_bpf_prog_entry(struct trace *trace
> >
> > static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
> > {
> > - int map_enter_fd = bpf_map__fd(trace->syscalls.prog_array.sys_enter),
> > - map_exit_fd = bpf_map__fd(trace->syscalls.prog_array.sys_exit);
> > + int map_enter_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_enter);
> > + int map_exit_fd = bpf_map__fd(trace->skel->maps.syscalls_sys_exit);
> > int err = 0, key;
> >
> > for (key = 0; key < trace->sctbl->syscalls.nr_entries; ++key) {
> > @@ -3515,7 +3515,7 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
> > * For now we're just reusing the sys_enter prog, and if it
> > * already has an augmenter, we don't need to find one.
> > */
> > - if (sc->bpf_prog.sys_enter != trace->syscalls.unaugmented_prog)
> > + if (sc->bpf_prog.sys_enter != trace->skel->progs.syscall_unaugmented)
> > continue;
> >
> > /*
> > @@ -3538,22 +3538,9 @@ static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace)
> > break;
> > }
> >
> > -
> > return err;
> > }
> > -
> > -#else // HAVE_LIBBPF_SUPPORT
> > -static struct bpf_map *trace__find_bpf_map_by_name(struct trace *trace __maybe_unused,
> > - const char *name __maybe_unused)
> > -{
> > - return NULL;
> > -}
> > -
> > -static int trace__init_syscalls_bpf_prog_array_maps(struct trace *trace __maybe_unused)
> > -{
> > - return 0;
> > -}
> > -#endif // HAVE_LIBBPF_SUPPORT
> > +#endif // HAVE_BPF_SKEL
> >
> > static int trace__set_ev_qualifier_filter(struct trace *trace)
> > {
> > @@ -3917,13 +3904,31 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
> > err = evlist__open(evlist);
> > if (err < 0)
> > goto out_error_open;
> > +#ifdef HAVE_BPF_SKEL
> > + {
> > + struct perf_cpu cpu;
> >
> > + /*
> > + * Set up the __augmented_syscalls__ BPF map to hold for each
> > + * CPU the bpf-output event's file descriptor.
> > + */
> > + perf_cpu_map__for_each_cpu(cpu, i, trace->syscalls.events.bpf_output->core.cpus) {
> > + bpf_map__update_elem(trace->skel->maps.__augmented_syscalls__,
> > + &cpu.cpu, sizeof(int),
> > + xyarray__entry(trace->syscalls.events.bpf_output->core.fd,
> > + cpu.cpu, 0),
> > + sizeof(__u32), BPF_ANY);
> > + }
> > + }
> > +#endif
> > err = trace__set_filter_pids(trace);
> > if (err < 0)
> > goto out_error_mem;
> >
> > - if (trace->syscalls.prog_array.sys_enter)
> > +#ifdef HAVE_BPF_SKEL
> > + if (trace->skel->progs.sys_enter)
> > trace__init_syscalls_bpf_prog_array_maps(trace);
> > +#endif
> >
> > if (trace->ev_qualifier_ids.nr > 0) {
> > err = trace__set_ev_qualifier_filter(trace);
> > @@ -3956,9 +3961,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
> > if (err < 0)
> > goto out_error_apply_filters;
> >
> > - if (trace->dump.map)
> > - bpf_map__fprintf(trace->dump.map, trace->output);
> > -
> > err = evlist__mmap(evlist, trace->opts.mmap_pages);
> > if (err < 0)
> > goto out_error_mmap;
> > @@ -4655,6 +4657,18 @@ static void trace__exit(struct trace *trace)
> > zfree(&trace->perfconfig_events);
> > }
> >
> > +#ifdef HAVE_BPF_SKEL
> > +static int bpf__setup_bpf_output(struct evlist *evlist)
> > +{
> > + int err = parse_event(evlist, "bpf-output/no-inherit=1,name=__augmented_syscalls__/");
> > +
> > + if (err)
> > + pr_debug("ERROR: failed to create the \"__augmented_syscalls__\" bpf-output event\n");
> > +
> > + return err;
> > +}
> > +#endif
> > +
> > int cmd_trace(int argc, const char **argv)
> > {
> > const char *trace_usage[] = {
> > @@ -4686,7 +4700,6 @@ int cmd_trace(int argc, const char **argv)
> > .max_stack = UINT_MAX,
> > .max_events = ULONG_MAX,
> > };
> > - const char *map_dump_str = NULL;
> > const char *output_name = NULL;
> > const struct option trace_options[] = {
> > OPT_CALLBACK('e', "event", &trace, "event",
> > @@ -4720,9 +4733,6 @@ int cmd_trace(int argc, const char **argv)
> > OPT_CALLBACK(0, "duration", &trace, "float",
> > "show only events with duration > N.M ms",
> > trace__set_duration),
> > -#ifdef HAVE_LIBBPF_SUPPORT
> > - OPT_STRING(0, "map-dump", &map_dump_str, "BPF map", "BPF map to periodically dump"),
> > -#endif
> > OPT_BOOLEAN(0, "sched", &trace.sched, "show blocking scheduler events"),
> > OPT_INCR('v', "verbose", &verbose, "be more verbose"),
> > OPT_BOOLEAN('T', "time", &trace.full_time,
> > @@ -4849,16 +4859,55 @@ int cmd_trace(int argc, const char **argv)
> > "cgroup monitoring only available in system-wide mode");
> > }
> >
> > - err = -1;
> > +#ifdef HAVE_BPF_SKEL
> > + trace.skel = augmented_raw_syscalls_bpf__open();
> > + if (!trace.skel) {
> > + pr_debug("Failed to open augmented syscalls BPF skeleton");
> > + } else {
> > + /*
> > + * Disable attaching the BPF programs except for sys_enter and
> > + * sys_exit that tail call into this as necessary.
> > + */
> > + bpf_program__set_autoattach(trace.skel->progs.syscall_unaugmented,
> > + /*autoattach=*/false);
> > + bpf_program__set_autoattach(trace.skel->progs.sys_enter_connect,
> > + /*autoattach=*/false);
> > + bpf_program__set_autoattach(trace.skel->progs.sys_enter_sendto,
> > + /*autoattach=*/false);
> > + bpf_program__set_autoattach(trace.skel->progs.sys_enter_open,
> > + /*autoattach=*/false);
> > + bpf_program__set_autoattach(trace.skel->progs.sys_enter_openat,
> > + /*autoattach=*/false);
> > + bpf_program__set_autoattach(trace.skel->progs.sys_enter_rename,
> > + /*autoattach=*/false);
> > + bpf_program__set_autoattach(trace.skel->progs.sys_enter_renameat,
> > + /*autoattach=*/false);
> > + bpf_program__set_autoattach(trace.skel->progs.sys_enter_perf_event_open,
> > + /*autoattach=*/false);
> > + bpf_program__set_autoattach(trace.skel->progs.sys_enter_clock_nanosleep,
> > + /*autoattach=*/false);
> > +
> > + err = augmented_raw_syscalls_bpf__load(trace.skel);
> >
> > - if (map_dump_str) {
> > - trace.dump.map = trace__find_bpf_map_by_name(&trace, map_dump_str);
> > - if (trace.dump.map == NULL) {
> > - pr_err("ERROR: BPF map \"%s\" not found\n", map_dump_str);
> > - goto out;
> > + if (err < 0) {
> > + pr_debug("Failed to load augmented syscalls BPF skeleton\n");
> > + } else {
> > + augmented_raw_syscalls_bpf__attach(trace.skel);
> > + trace__add_syscall_newtp(&trace);
> > }
> > }
> >
> > + err = bpf__setup_bpf_output(trace.evlist);
> > + if (err) {
> > + libbpf_strerror(err, bf, sizeof(bf));
> > + pr_err("ERROR: Setup BPF output event failed: %s\n", bf);
> > + goto out;
> > + }
> > + trace.syscalls.events.bpf_output = evlist__last(trace.evlist);
> > + assert(!strcmp(evsel__name(trace.syscalls.events.bpf_output), "__augmented_syscalls__"));
> > +#endif
> > + err = -1;
> > +
> > if (trace.trace_pgfaults) {
> > trace.opts.sample_address = true;
> > trace.opts.sample_time = true;
> > @@ -4909,7 +4958,7 @@ int cmd_trace(int argc, const char **argv)
> > * buffers that are being copied from kernel to userspace, think 'read'
> > * syscall.
> > */
> > - if (trace.syscalls.events.augmented) {
> > + if (trace.syscalls.events.bpf_output) {
> > evlist__for_each_entry(trace.evlist, evsel) {
> > bool raw_syscalls_sys_exit = strcmp(evsel__name(evsel), "raw_syscalls:sys_exit") == 0;
> >
> > @@ -4918,9 +4967,9 @@ int cmd_trace(int argc, const char **argv)
> > goto init_augmented_syscall_tp;
> > }
> >
> > - if (trace.syscalls.events.augmented->priv == NULL &&
> > + if (trace.syscalls.events.bpf_output->priv == NULL &&
> > strstr(evsel__name(evsel), "syscalls:sys_enter")) {
> > - struct evsel *augmented = trace.syscalls.events.augmented;
> > + struct evsel *augmented = trace.syscalls.events.bpf_output;
> > if (evsel__init_augmented_syscall_tp(augmented, evsel) ||
> > evsel__init_augmented_syscall_tp_args(augmented))
> > goto out;
> > @@ -5025,5 +5074,8 @@ int cmd_trace(int argc, const char **argv)
> > fclose(trace.output);
> > out:
> > trace__exit(&trace);
> > +#ifdef HAVE_BPF_SKEL
> > + augmented_raw_syscalls_bpf__destroy(trace.skel);
> > +#endif
> > return err;
> > }
> > diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
> > similarity index 96%
> > rename from tools/perf/examples/bpf/augmented_raw_syscalls.c
> > rename to tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
> > index 9a03189d33d3..70478b9460ee 100644
> > --- a/tools/perf/examples/bpf/augmented_raw_syscalls.c
> > +++ b/tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c
> > @@ -18,6 +18,8 @@
> > #include <bpf/bpf_helpers.h>
> > #include <linux/limits.h>
> >
> > +#define MAX_CPUS 4096
> > +
> > // FIXME: These should come from system headers
> > typedef char bool;
> > typedef int pid_t;
> > @@ -34,7 +36,7 @@ struct __augmented_syscalls__ {
> > __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
> > __type(key, int);
> > __type(value, __u32);
> > - __uint(max_entries, __NR_CPUS__);
> > + __uint(max_entries, MAX_CPUS);
> > } __augmented_syscalls__ SEC(".maps");
> >
> > /*
> > @@ -170,7 +172,7 @@ unsigned int augmented_arg__read_str(struct augmented_arg *augmented_arg, const
> > return augmented_len;
> > }
> >
> > -SEC("!raw_syscalls:unaugmented")
> > +SEC("tp/raw_syscalls/sys_enter")
> > int syscall_unaugmented(struct syscall_enter_args *args)
> > {
> > return 1;
> > @@ -182,7 +184,7 @@ int syscall_unaugmented(struct syscall_enter_args *args)
> > * on from there, reading the first syscall arg as a string, i.e. open's
> > * filename.
> > */
> > -SEC("!syscalls:sys_enter_connect")
> > +SEC("tp/syscalls/sys_enter_connect")
> > int sys_enter_connect(struct syscall_enter_args *args)
> > {
> > struct augmented_args_payload *augmented_args = augmented_args_payload();
> > @@ -201,7 +203,7 @@ int sys_enter_connect(struct syscall_enter_args *args)
> > return augmented__output(args, augmented_args, len + socklen);
> > }
> >
> > -SEC("!syscalls:sys_enter_sendto")
> > +SEC("tp/syscalls/sys_enter_sendto")
> > int sys_enter_sendto(struct syscall_enter_args *args)
> > {
> > struct augmented_args_payload *augmented_args = augmented_args_payload();
> > @@ -220,7 +222,7 @@ int sys_enter_sendto(struct syscall_enter_args *args)
> > return augmented__output(args, augmented_args, len + socklen);
> > }
> >
> > -SEC("!syscalls:sys_enter_open")
> > +SEC("tp/syscalls/sys_enter_open")
> > int sys_enter_open(struct syscall_enter_args *args)
> > {
> > struct augmented_args_payload *augmented_args = augmented_args_payload();
> > @@ -235,7 +237,7 @@ int sys_enter_open(struct syscall_enter_args *args)
> > return augmented__output(args, augmented_args, len);
> > }
> >
> > -SEC("!syscalls:sys_enter_openat")
> > +SEC("tp/syscalls/sys_enter_openat")
> > int sys_enter_openat(struct syscall_enter_args *args)
> > {
> > struct augmented_args_payload *augmented_args = augmented_args_payload();
> > @@ -250,7 +252,7 @@ int sys_enter_openat(struct syscall_enter_args *args)
> > return augmented__output(args, augmented_args, len);
> > }
> >
> > -SEC("!syscalls:sys_enter_rename")
> > +SEC("tp/syscalls/sys_enter_rename")
> > int sys_enter_rename(struct syscall_enter_args *args)
> > {
> > struct augmented_args_payload *augmented_args = augmented_args_payload();
> > @@ -267,7 +269,7 @@ int sys_enter_rename(struct syscall_enter_args *args)
> > return augmented__output(args, augmented_args, len);
> > }
> >
> > -SEC("!syscalls:sys_enter_renameat")
> > +SEC("tp/syscalls/sys_enter_renameat")
> > int sys_enter_renameat(struct syscall_enter_args *args)
> > {
> > struct augmented_args_payload *augmented_args = augmented_args_payload();
> > @@ -295,7 +297,7 @@ struct perf_event_attr_size {
> > __u32 size;
> > };
> >
> > -SEC("!syscalls:sys_enter_perf_event_open")
> > +SEC("tp/syscalls/sys_enter_perf_event_open")
> > int sys_enter_perf_event_open(struct syscall_enter_args *args)
> > {
> > struct augmented_args_payload *augmented_args = augmented_args_payload();
> > @@ -327,7 +329,7 @@ int sys_enter_perf_event_open(struct syscall_enter_args *args)
> > return 1; /* Failure: don't filter */
> > }
> >
> > -SEC("!syscalls:sys_enter_clock_nanosleep")
> > +SEC("tp/syscalls/sys_enter_clock_nanosleep")
> > int sys_enter_clock_nanosleep(struct syscall_enter_args *args)
> > {
> > struct augmented_args_payload *augmented_args = augmented_args_payload();
> > @@ -358,7 +360,7 @@ static bool pid_filter__has(struct pids_filtered *pids, pid_t pid)
> > return bpf_map_lookup_elem(pids, &pid) != NULL;
> > }
> >
> > -SEC("raw_syscalls:sys_enter")
> > +SEC("tp/raw_syscalls/sys_enter")
> > int sys_enter(struct syscall_enter_args *args)
> > {
> > struct augmented_args_payload *augmented_args;
> > @@ -371,7 +373,6 @@ int sys_enter(struct syscall_enter_args *args)
> > * We'll add to this as we add augmented syscalls right after that
> > * initial, non-augmented raw_syscalls:sys_enter payload.
> > */
> > - unsigned int len = sizeof(augmented_args->args);
> >
> > if (pid_filter__has(&pids_filtered, getpid()))
> > return 0;
> > @@ -393,7 +394,7 @@ int sys_enter(struct syscall_enter_args *args)
> > return 0;
> > }
> >
> > -SEC("raw_syscalls:sys_exit")
> > +SEC("tp/raw_syscalls/sys_exit")
> > int sys_exit(struct syscall_exit_args *args)
> > {
> > struct syscall_exit_args exit_args;
> > --
> > 2.41.0.640.ga95def55d0-goog
> >
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton
2023-08-10 18:48 ` [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton Ian Rogers
2023-08-11 16:09 ` Jiri Olsa
@ 2023-08-11 18:46 ` Arnaldo Carvalho de Melo
2023-08-15 14:25 ` Arnaldo Carvalho de Melo
2 siblings, 0 replies; 22+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-08-11 18:46 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Adrian Hunter, Nathan Chancellor,
Nick Desaulniers, Tom Rix, Fangrui Song, Anshuman Khandual,
Andi Kleen, Leo Yan, Madhavan Srinivasan, Carsten Haitzler,
Ravi Bangoria, Naveen N. Rao, Athira Rajeev, Kan Liang,
Yang Jihong, James Clark, Tiezhu Yang, Eduard Zingerman,
Andrii Nakryiko, Yonghong Song, Rob Herring, linux-kernel,
linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo, YueHaibing,
He Kuang, Brendan Gregg
Em Thu, Aug 10, 2023 at 11:48:51AM -0700, Ian Rogers escreveu:
> Previously a BPF event of augmented_raw_syscalls.c could be used to
> enable augmentation of syscalls by perf trace. As BPF events are no
> longer supported, switch to using a BPF skeleton which when attached
> explicitly opens the sysenter and sysexit tracepoints.
>
> The dump map is removed as debugging wasn't supported by the
> augmentation and bpf_printk can be used when necessary.
>
> Remove tools/perf/examples/bpf/augmented_raw_syscalls.c so that the
> rename/migration to a BPF skeleton captures that this was the source.
So, there is a problem where the augmented_raw_syscalls connect/sendto
handlers are being rejected by the verifier, the way you did it makes it
to print the verifier output and then continue without augmentation,
unsure if this is a good default, opinions?
[root@quaco ~]# perf trace -e open*
libbpf: prog 'sys_enter_connect': BPF program load failed: Permission denied
libbpf: prog 'sys_enter_connect': -- BEGIN PROG LOAD LOG --
reg type unsupported for arg#0 function sys_enter_connect#59
0: R1=ctx(off=0,imm=0) R10=fp0
; int sys_enter_connect(struct syscall_enter_args *args)
0: (bf) r6 = r1 ; R1=ctx(off=0,imm=0) R6_w=ctx(off=0,imm=0)
1: (b7) r1 = 0 ; R1_w=0
; int key = 0;
2: (63) *(u32 *)(r10 -4) = r1 ; R1_w=0 R10=fp0 fp-8=0000????
3: (bf) r2 = r10 ; R2_w=fp0 R10=fp0
;
4: (07) r2 += -4 ; R2_w=fp-4
; return bpf_map_lookup_elem(&augmented_args_tmp, &key);
5: (18) r1 = 0xffff8de5ae1d4600 ; R1_w=map_ptr(off=0,ks=4,vs=8272,imm=0)
7: (85) call bpf_map_lookup_elem#1 ; R0_w=map_value_or_null(id=1,off=0,ks=4,vs=8272,imm=0)
8: (bf) r7 = r0 ; R0_w=map_value_or_null(id=1,off=0,ks=4,vs=8272,imm=0) R7_w=map_value_or_null(id=1,off=0,ks=4,vs=8272,imm=0)
9: (b7) r0 = 1 ; R0_w=1
; if (augmented_args == NULL)
10: (15) if r7 == 0x0 goto pc+25 ; R7_w=map_value(off=0,ks=4,vs=8272,imm=0)
; unsigned int socklen = args->args[2];
11: (79) r1 = *(u64 *)(r6 +32) ; R1_w=scalar() R6_w=ctx(off=0,imm=0)
;
12: (bf) r2 = r1 ; R1_w=scalar(id=2) R2_w=scalar(id=2)
13: (67) r2 <<= 32 ; R2_w=scalar(smax=9223372032559808512,umax=18446744069414584320,var_off=(0x0; 0xffffffff00000000),s32_min=0,s32_max=0,u32_max=0)
14: (77) r2 >>= 32 ; R2_w=scalar(umax=4294967295,var_off=(0x0; 0xffffffff))
15: (b7) r8 = 128 ; R8=128
; if (socklen > sizeof(augmented_args->saddr))
16: (25) if r2 > 0x80 goto pc+1 ; R2=scalar(umax=128,var_off=(0x0; 0xff))
17: (bf) r8 = r1 ; R1=scalar(id=2) R8_w=scalar(id=2)
; const void *sockaddr_arg = (const void *)args->args[1];
18: (79) r3 = *(u64 *)(r6 +24) ; R3_w=scalar() R6=ctx(off=0,imm=0)
; bpf_probe_read(&augmented_args->saddr, socklen, sockaddr_arg);
19: (bf) r1 = r7 ; R1_w=map_value(off=0,ks=4,vs=8272,imm=0) R7=map_value(off=0,ks=4,vs=8272,imm=0)
20: (07) r1 += 64 ; R1_w=map_value(off=64,ks=4,vs=8272,imm=0)
; bpf_probe_read(&augmented_args->saddr, socklen, sockaddr_arg);
21: (bf) r2 = r8 ; R2_w=scalar(id=2) R8_w=scalar(id=2)
22: (85) call bpf_probe_read#4
R2 min value is negative, either use unsigned or 'var &= const'
processed 22 insns (limit 1000000) max_states_per_insn 0 total_states 1 peak_states 1 mark_read 1
-- END PROG LOAD LOG --
libbpf: prog 'sys_enter_connect': failed to load: -13
libbpf: failed to load object 'augmented_raw_syscalls_bpf'
libbpf: failed to load BPF skeleton 'augmented_raw_syscalls_bpf': -13
0.000 systemd-oomd/959 openat(dfd: CWD, filename: 0xc0a2a2bd, flags: RDONLY|CLOEXEC) = 12
86.339 thermald/1234 openat(dfd: CWD, filename: 0xac000ba0) = 13
87.008 thermald/1234 openat(dfd: CWD, filename: 0xac000eb0) = 13
87.270 thermald/1234 openat(dfd: CWD, filename: 0xac000b70) = 13
89.657 thermald/1234 openat(dfd: CWD, filename: 0xac000eb0) = 13
^C
If I comment out the connect and sendto it doesn't build anymore,
whereas before it would continue with the other handlers:
CLANG /tmp/build/perf-tools-next/util/bpf_skel/.tmp/augmented_raw_syscalls.bpf.o
GENSKEL /tmp/build/perf-tools-next/util/bpf_skel/augmented_raw_syscalls.skel.h
CC /tmp/build/perf-tools-next/builtin-trace.o
builtin-trace.c: In function ‘cmd_trace’:
builtin-trace.c:4873:63: error: ‘struct <anonymous>’ has no member named ‘sys_enter_connect’; did you mean ‘sys_enter_openat’?
4873 | bpf_program__set_autoattach(trace.skel->progs.sys_enter_connect,
| ^~~~~~~~~~~~~~~~~
| sys_enter_openat
builtin-trace.c:4875:63: error: ‘struct <anonymous>’ has no member named ‘sys_enter_sendto’; did you mean ‘sys_enter_openat’?
4875 | bpf_program__set_autoattach(trace.skel->progs.sys_enter_sendto,
| ^~~~~~~~~~~~~~~~
| sys_enter_openat
make[3]: *** [/home/acme/git/perf-tools-next/tools/build/Makefile.build:97: /tmp/build/perf-tools-next/builtin-trace.o] Error 1
make[2]: *** [Makefile.perf:662: /tmp/build/perf-tools-next/perf-in.o] Error 2
make[1]: *** [Makefile.perf:238: sub-make] Error 2
make: *** [Makefile:113: install-bin] Error 2
make: Leaving directory '/home/acme/git/perf-tools-next/tools/perf'
[acme@quaco perf-tools-next]$
\x1a
I.e. no need for explicitely referring to those, I think in the past it
was just looking if it was there and if so, attaching, I'll try to fix
this.
If I remove the explicit references in builtin-trace.c:
[root@quaco ~]# perf trace -e open* --max-events=10
0.000 thermald/1234 openat(dfd: CWD, filename: "/sys/class/powercap/intel-rapl/intel-rapl:0/intel-rapl:0:2/energy_uj") = 13
0.236 thermald/1234 openat(dfd: CWD, filename: "/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj") = 13
0.334 thermald/1234 openat(dfd: CWD, filename: "/sys/class/thermal/thermal_zone2/temp") = 13
9.092 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
259.212 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
497.464 gpm/1049 openat(dfd: CWD, filename: "/dev/tty0") = 4
509.044 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
509.559 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/session.slice/memory.pressure", flags: RDONLY|CLOEXEC) = 12
509.917 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/session.slice/memory.current", flags: RDONLY|CLOEXEC) = 12
510.111 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/session.slice/memory.min", flags: RDONLY|CLOEXEC) = 12
[root@quaco ~]#
Cool!
Some inception:
[root@quaco ~]# perf trace -e perf_event_open perf stat -e cycles,instructions,cache-misses sleep 1
0.000 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0 (PERF_COUNT_HW_CPU_CYCLES), sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 232297 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 3
0.063 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0x1 (PERF_COUNT_HW_INSTRUCTIONS), sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 232297 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 4
0.070 perf_event_open(attr_uptr: { type: 0 (PERF_TYPE_HARDWARE), size: 136, config: 0x3 (PERF_COUNT_HW_CACHE_MISSES), sample_type: IDENTIFIER, read_format: TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING, disabled: 1, inherit: 1, enable_on_exec: 1, exclude_guest: 1 }, pid: 232297 (perf), cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 5
Performance counter stats for 'sleep 1':
2,669,464 cycles
1,842,319 instructions # 0.69 insn per cycle
27,716 cache-misses
1.001948592 seconds time elapsed
0.000000000 seconds user
0.001657000 seconds sys
[root@quaco ~]#
I'm putting what I have in the tmp.perf-tools-next branch, will continue
later today.
- Arnaldo
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton
2023-08-10 18:48 ` [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton Ian Rogers
2023-08-11 16:09 ` Jiri Olsa
2023-08-11 18:46 ` Arnaldo Carvalho de Melo
@ 2023-08-15 14:25 ` Arnaldo Carvalho de Melo
[not found] ` <CAP-5=fURf+vv3TA4cRx1MiV3DDp=3wo0g5dBYH43DKtPhNZQsQ@mail.gmail.com>
2 siblings, 1 reply; 22+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-08-15 14:25 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Adrian Hunter, Nathan Chancellor,
Nick Desaulniers, Tom Rix, Fangrui Song, Anshuman Khandual,
Andi Kleen, Leo Yan, Madhavan Srinivasan, Carsten Haitzler,
Ravi Bangoria, Naveen N. Rao, Athira Rajeev, Kan Liang,
Yang Jihong, James Clark, Tiezhu Yang, Eduard Zingerman,
Andrii Nakryiko, Yonghong Song, Rob Herring, linux-kernel,
linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo, YueHaibing,
He Kuang, Brendan Gregg
Em Thu, Aug 10, 2023 at 11:48:51AM -0700, Ian Rogers escreveu:
> Previously a BPF event of augmented_raw_syscalls.c could be used to
> enable augmentation of syscalls by perf trace. As BPF events are no
> longer supported, switch to using a BPF skeleton which when attached
> explicitly opens the sysenter and sysexit tracepoints.
>
> The dump map is removed as debugging wasn't supported by the
> augmentation and bpf_printk can be used when necessary.
>
> Remove tools/perf/examples/bpf/augmented_raw_syscalls.c so that the
> rename/migration to a BPF skeleton captures that this was the source.
> +#ifdef HAVE_BPF_SKEL
> + trace.skel = augmented_raw_syscalls_bpf__open();
> + if (!trace.skel) {
> + pr_debug("Failed to open augmented syscalls BPF skeleton");
> + } else {
> + /*
> + * Disable attaching the BPF programs except for sys_enter and
> + * sys_exit that tail call into this as necessary.
> + */
> + bpf_program__set_autoattach(trace.skel->progs.syscall_unaugmented,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_connect,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_sendto,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_open,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_openat,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_rename,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_renameat,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_perf_event_open,
> + /*autoattach=*/false);
> + bpf_program__set_autoattach(trace.skel->progs.sys_enter_clock_nanosleep,
> + /*autoattach=*/false);
> +
> + err = augmented_raw_syscalls_bpf__load(trace.skel);
>
So I converted the above to:
struct bpf_program *prog;
bpf_object__for_each_program(prog, trace.skel->obj) {
if (prog != trace.skel->progs.sys_enter && prog != trace.skel->progs.sys_exit)
bpf_program__set_autoattach(prog, /*autoattach=*/false);
}
So that we don't have to add new lines disabling attachment when adding
support for other pointer receiving syscalls.
- Arnaldo
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton
[not found] ` <CAP-5=fURf+vv3TA4cRx1MiV3DDp=3wo0g5dBYH43DKtPhNZQsQ@mail.gmail.com>
@ 2023-08-16 13:11 ` Arnaldo Carvalho de Melo
2023-08-16 13:22 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 22+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-08-16 13:11 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Adrian Hunter, Nathan Chancellor,
Nick Desaulniers, Tom Rix, Fangrui Song, Anshuman Khandual,
Andi Kleen, Leo Yan, Madhavan Srinivasan, Carsten Haitzler,
Ravi Bangoria, Naveen N. Rao, Athira Rajeev, Kan Liang,
Yang Jihong, James Clark, Tiezhu Yang, Eduard Zingerman,
Andrii Nakryiko, Yonghong Song, Rob Herring, LKML,
linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo, YueHaibing,
He Kuang, Brendan Gregg
Em Tue, Aug 15, 2023 at 07:34:08AM -0700, Ian Rogers escreveu:
> On Tue, Aug 15, 2023, 7:25 AM Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> > bpf_object__for_each_program(prog, trace.skel->obj) {
> > if (prog != trace.skel->progs.sys_enter && prog !=
> > trace.skel->progs.sys_exit)
> > bpf_program__set_autoattach(prog,
> > /*autoattach=*/false);
> > }
> >
> > So that we don't have to add new lines disabling attachment when adding
> > support for other pointer receiving syscalls.
> Makes sense. Thanks,
Just taking notes about things to work on top of what is in
tmp.perf-tools-next, that will move to perf-tools-next soon:
We need to make these libbpf error messages appear only in verbose mode,
and probably have a hint about unprivileged BPF, a quick attempt failed
after several attempts at getting privileges :-\
Probably attaching to tracepoints is off limits to !root even with
/proc/sys/kernel/unprivileged_bpf_disabled set to zero.
[acme@quaco perf-tools-next]$ perf trace ls
libbpf: Failed to bump RLIMIT_MEMLOCK (err = -1), you might need to do it explicitly!
libbpf: Error in bpf_object__probe_loading():Operation not permitted(1). Couldn't load trivial BPF program. Make sure your kernel supports BPF (CONFIG_BPF_SYSCALL=y) and/or that RLIMIT_MEMLOCK is set to big enough value.
libbpf: failed to load object 'augmented_raw_syscalls_bpf'
libbpf: failed to load BPF skeleton 'augmented_raw_syscalls_bpf': -1
Error: No permissions to read /sys/kernel/tracing//events/raw_syscalls/sys_(enter|exit)
Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/tracing/'
[acme@quaco perf-tools-next]$
[acme@quaco perf-tools-next]$ perf trace -e open* sleep 1
libbpf: Failed to bump RLIMIT_MEMLOCK (err = -1), you might need to do it explicitly!
libbpf: Error in bpf_object__probe_loading():Operation not permitted(1). Couldn't load trivial BPF program. Make sure your kernel supports BPF (CONFIG_BPF_SYSCALL=y) and/or that RLIMIT_MEMLOCK is set to big enough value.
libbpf: failed to load object 'augmented_raw_syscalls_bpf'
libbpf: failed to load BPF skeleton 'augmented_raw_syscalls_bpf': -1
Error: No permissions to read /sys/kernel/tracing//events/raw_syscalls/sys_(enter|exit)
Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/tracing/'
[acme@quaco perf-tools-next]$ sudo mount -o remount,mode=755 /sys/kernel/tracing/
[sudo] password for acme:
[acme@quaco perf-tools-next]$ perf trace -e open* sleep 1
libbpf: Failed to bump RLIMIT_MEMLOCK (err = -1), you might need to do it explicitly!
libbpf: Error in bpf_object__probe_loading():Operation not permitted(1). Couldn't load trivial BPF program. Make sure your kernel supports BPF (CONFIG_BPF_SYSCALL=y) and/or that RLIMIT_MEMLOCK is set to big enough value.
libbpf: failed to load object 'augmented_raw_syscalls_bpf'
libbpf: failed to load BPF skeleton 'augmented_raw_syscalls_bpf': -1
Error: No permissions to read /sys/kernel/tracing//events/raw_syscalls/sys_(enter|exit)
Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/tracing/'
[acme@quaco perf-tools-next]$ sudo mount -o remount,mode=755 /sys/kernel/debug
[acme@quaco perf-tools-next]$ perf trace -e open* sleep 1
libbpf: Failed to bump RLIMIT_MEMLOCK (err = -1), you might need to do it explicitly!
libbpf: Error in bpf_object__probe_loading():Operation not permitted(1). Couldn't load trivial BPF program. Make sure your kernel supports BPF (CONFIG_BPF_SYSCALL=y) and/or that RLIMIT_MEMLOCK is set to big enough value.
libbpf: failed to load object 'augmented_raw_syscalls_bpf'
libbpf: failed to load BPF skeleton 'augmented_raw_syscalls_bpf': -1
Error: No permissions to read /sys/kernel/tracing//events/raw_syscalls/sys_(enter|exit)
Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/tracing/'
[acme@quaco perf-tools-next]$ sudo sh -c "echo 0 > /proc/sys/kernel/unprivileged_bpf_disabled"
[acme@quaco perf-tools-next]$ perf trace -e open* sleep 1
libbpf: prog 'syscall_unaugmented': BPF program load failed: Operation not permitted
libbpf: prog 'syscall_unaugmented': failed to load: -1
libbpf: failed to load object 'augmented_raw_syscalls_bpf'
libbpf: failed to load BPF skeleton 'augmented_raw_syscalls_bpf': -1
Error: No permissions to read /sys/kernel/tracing//events/raw_syscalls/sys_(enter|exit)
Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/tracing/'
[acme@quaco perf-tools-next]$ cat /proc/sys/kernel/unprivileged_bpf_disabled
0
[acme@quaco perf-tools-next]$
[acme@quaco perf-tools-next]$
[acme@quaco perf-tools-next]$ cat /proc/sys/kernel/perf_event_paranoid
2
[acme@quaco perf-tools-next]$ sudo sh -c "echo -1 > /proc/sys/kernel/perf_event_paranoid"
[acme@quaco perf-tools-next]$ perf trace -e open* sleep 1
libbpf: prog 'syscall_unaugmented': BPF program load failed: Operation not permitted
libbpf: prog 'syscall_unaugmented': failed to load: -1
libbpf: failed to load object 'augmented_raw_syscalls_bpf'
libbpf: failed to load BPF skeleton 'augmented_raw_syscalls_bpf': -1
Error: No permissions to read /sys/kernel/tracing//events/raw_syscalls/sys_(enter|exit)
Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/tracing/'
[acme@quaco perf-tools-next]$
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton
2023-08-16 13:11 ` Arnaldo Carvalho de Melo
@ 2023-08-16 13:22 ` Arnaldo Carvalho de Melo
2023-08-16 16:08 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 22+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-08-16 13:22 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Adrian Hunter, Nathan Chancellor,
Nick Desaulniers, Tom Rix, Fangrui Song, Anshuman Khandual,
Andi Kleen, Leo Yan, Madhavan Srinivasan, Carsten Haitzler,
Ravi Bangoria, Naveen N. Rao, Athira Rajeev, Kan Liang,
Yang Jihong, James Clark, Tiezhu Yang, Eduard Zingerman,
Andrii Nakryiko, Yonghong Song, Rob Herring, LKML,
linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo, YueHaibing,
He Kuang, Brendan Gregg
Em Wed, Aug 16, 2023 at 10:11:11AM -0300, Arnaldo Carvalho de Melo escreveu:
> Just taking notes about things to work on top of what is in
> tmp.perf-tools-next, that will move to perf-tools-next soon:
>
> We need to make these libbpf error messages appear only in verbose mode,
> and probably have a hint about unprivileged BPF, a quick attempt failed
> after several attempts at getting privileges :-\
>
> Probably attaching to tracepoints is off limits to !root even with
> /proc/sys/kernel/unprivileged_bpf_disabled set to zero.
yep, the libbpf sys_bpf call to check if it could load a basic BPF
bytecode (prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2) succeeds,
but then, later we manage to create the maps, etc to then stumble on
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERCPU_ARRAY, key_size=4, value_size=8272, max_entries=1, map_flags=0, inner_map_fd=0, map_name="augmented_args_", map_ifindex=0, btf_fd=0, btf_key_type_id=0, btf_value_type_id=0, btf_vmlinux_value_type_id=0, map_extra=0}, 72) = 7
bpf(BPF_BTF_LOAD, {btf="\237\353\1\0\30\0\0\0\0\0\0\0000\0\0\0000\0\0\0\t\0\0\0\1\0\0\0\0\0\0\1"..., btf_log_buf=NULL, btf_size=81, btf_log_size=0, btf_log_level=0}, 32) = -1 EPERM (Operation not permitted)
and:
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_TRACEPOINT, insn_cnt=2, insns=0x1758340, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(6, 4, 7), prog_flags=0, prog_name="syscall_unaugme", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0, fd_array=NULL}, 144) = -1 EPERM (Operation not permitted)
So 'perf trace' should just not try to load the augmented_raw_syscalls
BPF skel for !root.
- Arnaldo
[acme@quaco perf-tools-next]$ strace -e bpf perf trace -vv -e open* sleep 1
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2, insns=0x7ffe95185300, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0}, 116) = 3
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2, insns=0x7ffe951854a0, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0, fd_array=NULL}, 144) = 3
bpf(BPF_BTF_LOAD, {btf="\237\353\1\0\30\0\0\0\0\0\0\0\20\0\0\0\20\0\0\0\5\0\0\0\1\0\0\0\0\0\0\1"..., btf_log_buf=NULL, btf_size=45, btf_log_size=0, btf_log_level=0}, 32) = -1 EPERM (Operation not permitted)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2, insns=0x7ffe95185110, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="libbpf_nametest"}, 64) = 3
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_HASH, key_size=4, value_size=1, max_entries=64, map_flags=0, inner_map_fd=0, map_name="pids_filtered", map_ifindex=0, btf_fd=0, btf_key_type_id=0, btf_value_type_id=0, btf_vmlinux_value_type_id=0, map_extra=0}, 72) = 3
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PROG_ARRAY, key_size=4, value_size=4, max_entries=512, map_flags=0, inner_map_fd=0, map_name="syscalls_sys_en", map_ifindex=0, btf_fd=0, btf_key_type_id=0, btf_value_type_id=0, btf_vmlinux_value_type_id=0, map_extra=0}, 72) = 4
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PROG_ARRAY, key_size=4, value_size=4, max_entries=512, map_flags=0, inner_map_fd=0, map_name="syscalls_sys_ex", map_ifindex=0, btf_fd=0, btf_key_type_id=0, btf_value_type_id=0, btf_vmlinux_value_type_id=0, map_extra=0}, 72) = 5
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERF_EVENT_ARRAY, key_size=4, value_size=4, max_entries=4096, map_flags=0, inner_map_fd=0, map_name="__augmented_sys", map_ifindex=0, btf_fd=0, btf_key_type_id=0, btf_value_type_id=0, btf_vmlinux_value_type_id=0, map_extra=0}, 72) = 6
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERCPU_ARRAY, key_size=4, value_size=8272, max_entries=1, map_flags=0, inner_map_fd=0, map_name="augmented_args_", map_ifindex=0, btf_fd=0, btf_key_type_id=0, btf_value_type_id=0, btf_vmlinux_value_type_id=0, map_extra=0}, 72) = 7
bpf(BPF_BTF_LOAD, {btf="\237\353\1\0\30\0\0\0\0\0\0\0000\0\0\0000\0\0\0\t\0\0\0\1\0\0\0\0\0\0\1"..., btf_log_buf=NULL, btf_size=81, btf_log_size=0, btf_log_level=0}, 32) = -1 EPERM (Operation not permitted)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_TRACEPOINT, insn_cnt=2, insns=0x1758340, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(6, 4, 7), prog_flags=0, prog_name="syscall_unaugme", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0, fd_array=NULL}, 144) = -1 EPERM (Operation not permitted)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_TRACEPOINT, insn_cnt=2, insns=0x1758340, license="GPL", log_level=1, log_size=16777215, log_buf="", kern_version=KERNEL_VERSION(6, 4, 7), prog_flags=0, prog_name="syscall_unaugme", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0, fd_array=NULL}, 144) = -1 EPERM (Operation not permitted)
libbpf: prog 'syscall_unaugmented': BPF program load failed: Operation not permitted
libbpf: prog 'syscall_unaugmented': failed to load: -1
libbpf: failed to load object 'augmented_raw_syscalls_bpf'
libbpf: failed to load BPF skeleton 'augmented_raw_syscalls_bpf': -1
Failed to load augmented syscalls BPF skeleton: Operation not permitted
Using CPUID GenuineIntel-6-8E-A
intel_pt default config: tsc,mtc,mtc_period=3,psb_period=3,pt,branch
Error: No permissions to read /sys/kernel/tracing//events/raw_syscalls/sys_(enter|exit)
Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/tracing/'
+++ exited with 255 +++
[acme@quaco perf-tools-next]$
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton
2023-08-16 13:22 ` Arnaldo Carvalho de Melo
@ 2023-08-16 16:08 ` Arnaldo Carvalho de Melo
2023-08-16 17:14 ` Arnaldo Carvalho de Melo
2023-08-16 18:15 ` Ian Rogers
0 siblings, 2 replies; 22+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-08-16 16:08 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Adrian Hunter, Nathan Chancellor,
Nick Desaulniers, Tom Rix, Fangrui Song, Anshuman Khandual,
Andi Kleen, Leo Yan, Madhavan Srinivasan, Carsten Haitzler,
Ravi Bangoria, Naveen N. Rao, Athira Rajeev, Kan Liang,
Yang Jihong, James Clark, Tiezhu Yang, Eduard Zingerman,
Andrii Nakryiko, Yonghong Song, Rob Herring, LKML,
linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo, YueHaibing,
He Kuang, Brendan Gregg
Em Wed, Aug 16, 2023 at 10:22:15AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Aug 16, 2023 at 10:11:11AM -0300, Arnaldo Carvalho de Melo escreveu:
> > Just taking notes about things to work on top of what is in
> > tmp.perf-tools-next, that will move to perf-tools-next soon:
> > We need to make these libbpf error messages appear only in verbose mode,
> > and probably have a hint about unprivileged BPF, a quick attempt failed
> > after several attempts at getting privileges :-\
> > Probably attaching to tracepoints is off limits to !root even with
> > /proc/sys/kernel/unprivileged_bpf_disabled set to zero.
> yep, the libbpf sys_bpf call to check if it could load a basic BPF
> bytecode (prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2) succeeds,
> but then, later we manage to create the maps, etc to then stumble on
> bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERCPU_ARRAY, key_size=4, value_size=8272, max_entries=1, map_flags=0, inner_map_fd=0, map_name="augmented_args_", map_ifindex=0, btf_fd=0, btf_key_type_id=0, btf_value_type_id=0, btf_vmlinux_value_type_id=0, map_extra=0}, 72) = 7
> bpf(BPF_BTF_LOAD, {btf="\237\353\1\0\30\0\0\0\0\0\0\0000\0\0\0000\0\0\0\t\0\0\0\1\0\0\0\0\0\0\1"..., btf_log_buf=NULL, btf_size=81, btf_log_size=0, btf_log_level=0}, 32) = -1 EPERM (Operation not permitted)
> and:
> bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_TRACEPOINT, insn_cnt=2, insns=0x1758340, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(6, 4, 7), prog_flags=0, prog_name="syscall_unaugme", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0, fd_array=NULL}, 144) = -1 EPERM (Operation not permitted)
> So 'perf trace' should just not try to load the augmented_raw_syscalls
> BPF skel for !root.
Not really, I insisted and it is (was?) possible to make it work,
testing on some other machine and after having to change the permissions
recursively on tracefs (before a remount with mode=755 seemed to
work?).
I managed to make it work for !root, BPF collecting the pointer args for
openat, access (perf trace looks for syscall signatures and reuses BPF
progs for the ones matching one of the explicitely provided)
clock_namosleep, etc.
(re)Reading Documentation/admin-guide/perf-security.rst and getting it
into the hints system of 'perf trace' may make this process simpler and
safer, by using a group, etc. But it is possible, great!
I didn't even had to touch /proc/sys/kernel/unprivileged_bpf_disabled,
just the capabilities for the perf binary (which is a pretty big window,
but way smaller than touching /proc/sys/kernel/unprivileged_bpf_disabled).
So now we need to get BUILD_BPF_SKEL=1 to be the default but just emit a
warning when what is needed isn't available, just like with other
features, in that case 'perf trace' continues as today, no pointer arg
contents collection.
Unfortunately it is too late in the process for v6.6 even, so as soon as
perf-tools-next becomes perf-tools and we reopen it for v6.7 the first
patch should be this build BPF skels if what is needed is available.
I'll also check if we can enable BUILD_BPF_SKEL=1 in the distro packages
so that we collect some info from them about possible problems.
What I have is now in perf-tools-next, so should get into linux-next and
hopefully help in testing it, IIRC there are CIs that enable
BUILD_BPF_SKEL=1.
- Arnaldo
[acme@five ~]$ uname -a
Linux five 6.2.15-100.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 11 16:51:53 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
[acme@five ~]$ id
uid=1000(acme) gid=1000(acme) groups=1000(acme),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[acme@five ~]$ perf trace sleep 1
? ( ): sleep/980735 ... [continued]: execve()) = 0
0.031 ( 0.002 ms): sleep/980735 brk() = 0x55c621548000
0.039 ( 0.001 ms): sleep/980735 arch_prctl(option: 0x3001, arg2: 0x7ffeb8a6a460) = -1 EINVAL (Invalid argument)
0.058 ( 0.006 ms): sleep/980735 access(filename: "/etc/ld.so.preload", mode: R) = -1 ENOENT (No such file or directory)
0.068 ( 0.005 ms): sleep/980735 openat(dfd: CWD, filename: "/etc/ld.so.cache", flags: RDONLY|CLOEXEC) = 3
0.074 ( 0.002 ms): sleep/980735 newfstatat(dfd: 3, filename: "", statbuf: 0x7ffeb8a69680, flag: 4096) = 0
0.077 ( 0.006 ms): sleep/980735 mmap(len: 54771, prot: READ, flags: PRIVATE, fd: 3) = 0x7f6b95ad9000
0.084 ( 0.001 ms): sleep/980735 close(fd: 3) = 0
0.094 ( 0.006 ms): sleep/980735 openat(dfd: CWD, filename: "/lib64/libc.so.6", flags: RDONLY|CLOEXEC) = 3
0.101 ( 0.002 ms): sleep/980735 read(fd: 3, buf: 0x7ffeb8a697e8, count: 832) = 832
0.105 ( 0.001 ms): sleep/980735 pread64(fd: 3, buf: 0x7ffeb8a693e0, count: 784, pos: 64) = 784
0.107 ( 0.001 ms): sleep/980735 pread64(fd: 3, buf: 0x7ffeb8a69380, count: 80, pos: 848) = 80
0.110 ( 0.001 ms): sleep/980735 pread64(fd: 3, buf: 0x7ffeb8a69330, count: 68, pos: 928) = 68
0.113 ( 0.002 ms): sleep/980735 newfstatat(dfd: 3, filename: "", statbuf: 0x7ffeb8a69680, flag: 4096) = 0
0.115 ( 0.003 ms): sleep/980735 mmap(len: 8192, prot: READ|WRITE, flags: PRIVATE|ANONYMOUS) = 0x7f6b95ad7000
0.122 ( 0.001 ms): sleep/980735 pread64(fd: 3, buf: 0x7ffeb8a692d0, count: 784, pos: 64) = 784
0.126 ( 0.006 ms): sleep/980735 mmap(len: 2104720, prot: READ, flags: PRIVATE|DENYWRITE, fd: 3) = 0x7f6b95800000
0.133 ( 0.013 ms): sleep/980735 mmap(addr: 0x7f6b95828000, len: 1523712, prot: READ|EXEC, flags: PRIVATE|FIXED|DENYWRITE, fd: 3, off: 0x28000) = 0x7f6b95828000
0.147 ( 0.008 ms): sleep/980735 mmap(addr: 0x7f6b9599c000, len: 360448, prot: READ, flags: PRIVATE|FIXED|DENYWRITE, fd: 3, off: 0x19c000) = 0x7f6b9599c000
0.156 ( 0.010 ms): sleep/980735 mmap(addr: 0x7f6b959f4000, len: 24576, prot: READ|WRITE, flags: PRIVATE|FIXED|DENYWRITE, fd: 3, off: 0x1f3000) = 0x7f6b959f4000
0.171 ( 0.005 ms): sleep/980735 mmap(addr: 0x7f6b959fa000, len: 32144, prot: READ|WRITE, flags: PRIVATE|FIXED|ANONYMOUS) = 0x7f6b959fa000
0.182 ( 0.001 ms): sleep/980735 close(fd: 3) = 0
0.193 ( 0.003 ms): sleep/980735 mmap(len: 12288, prot: READ|WRITE, flags: PRIVATE|ANONYMOUS) = 0x7f6b95ad4000
0.199 ( 0.001 ms): sleep/980735 arch_prctl(option: SET_FS, arg2: 0x7f6b95ad4740) = 0
0.202 ( 0.001 ms): sleep/980735 set_tid_address(tidptr: 0x7f6b95ad4a10) = 980735 (sleep)
0.204 ( 0.001 ms): sleep/980735 set_robust_list(head: 0x7f6b95ad4a20, len: 24) = 0
0.206 ( 0.001 ms): sleep/980735 rseq(rseq: 0x7f6b95ad50e0, rseq_len: 32, sig: 1392848979) = 0
0.277 ( 0.010 ms): sleep/980735 mprotect(start: 0x7f6b959f4000, len: 16384, prot: READ) = 0
0.306 ( 0.007 ms): sleep/980735 mprotect(start: 0x55c61fa4a000, len: 4096, prot: READ) = 0
0.320 ( 0.010 ms): sleep/980735 mprotect(start: 0x7f6b95b1c000, len: 8192, prot: READ) = 0
0.340 ( 0.002 ms): sleep/980735 prlimit64(resource: STACK, old_rlim: 0x7ffeb8a6a1c0) = 0
0.349 ( 0.009 ms): sleep/980735 munmap(addr: 0x7f6b95ad9000, len: 54771) = 0
0.381 ( 0.002 ms): sleep/980735 getrandom(ubuf: 0x7f6b959ff4d8, len: 8, flags: NONBLOCK) = 8
0.386 ( 0.001 ms): sleep/980735 brk() = 0x55c621548000
0.388 ( 0.006 ms): sleep/980735 brk(brk: 0x55c621569000) = 0x55c621569000
0.403 ( 0.012 ms): sleep/980735 openat(dfd: CWD, filename: "", flags: RDONLY|CLOEXEC) = 3
0.417 ( 0.003 ms): sleep/980735 newfstatat(dfd: 3, filename: "", statbuf: 0x7f6b959f9b80, flag: 4096) = 0
0.422 ( 0.008 ms): sleep/980735 mmap(len: 224096080, prot: READ, flags: PRIVATE, fd: 3) = 0x7f6b88200000
0.436 ( 0.002 ms): sleep/980735 close(fd: 3) = 0
0.480 (1000.041 ms): sleep/980735 clock_nanosleep(rqtp: { .tv_sec: 1, .tv_nsec: 0 }, rmtp: 0x7ffeb8a6a450) = 0
1000.552 ( 0.003 ms): sleep/980735 close(fd: 1) = 0
1000.558 ( 0.002 ms): sleep/980735 close(fd: 2) = 0
1000.565 ( ): sleep/980735 exit_group() = ?
[acme@five ~]$ getcap ~/bin/perf
/var/home/acme/bin/perf cap_perfmon,cap_bpf=ep
[acme@five ~]$ cat /proc/sys/kernel/unprivileged_bpf_disabled
2
[acme@five ~]$ cat /proc/sys/kernel/perf_event_paranoid
-1
[acme@five ~]$
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton
2023-08-16 16:08 ` Arnaldo Carvalho de Melo
@ 2023-08-16 17:14 ` Arnaldo Carvalho de Melo
2023-08-16 18:15 ` Ian Rogers
1 sibling, 0 replies; 22+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-08-16 17:14 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Adrian Hunter, Nathan Chancellor,
Nick Desaulniers, Tom Rix, Fangrui Song, Anshuman Khandual,
Andi Kleen, Leo Yan, Madhavan Srinivasan, Carsten Haitzler,
Ravi Bangoria, Naveen N. Rao, Athira Rajeev, Kan Liang,
Yang Jihong, James Clark, Tiezhu Yang, Eduard Zingerman,
Andrii Nakryiko, Yonghong Song, Rob Herring, LKML,
linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo, YueHaibing,
He Kuang, Brendan Gregg
Em Wed, Aug 16, 2023 at 01:08:14PM -0300, Arnaldo Carvalho de Melo escreveu:
> [acme@five ~]$ getcap ~/bin/perf
> /var/home/acme/bin/perf cap_perfmon,cap_bpf=ep
> [acme@five ~]$ cat /proc/sys/kernel/unprivileged_bpf_disabled
> 2
> [acme@five ~]$ cat /proc/sys/kernel/perf_event_paranoid
> -1
This last one can remain at 2:
[acme@five ~]$ cat /proc/sys/kernel/perf_event_paranoid
2
[acme@five ~]$ perf trace -e bpf*,perf*,openat,connect* --max-events=10
0.000 ( 0.031 ms): systemd-oomd/1151 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 11
25.532 ( ): gnome-terminal/3223 openat(dfd: CWD, filename: "/proc/1244100/cmdline") ...
249.996 ( 0.031 ms): systemd-oomd/1151 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 11
423.853 ( 0.036 ms): pool/2490 connect(fd: 7, uservaddr: { .family: LOCAL, path: /var/run/.heim_org.h5l.kcm-socket }, addrlen: 110) = 0
423.929 ( 0.021 ms): sssd_kcm/2514 openat(dfd: CWD, filename: "/proc/2486/cmdline") = 16
499.988 ( 0.030 ms): systemd-oomd/1151 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 11
749.981 ( 0.032 ms): systemd-oomd/1151 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 11
775.441 ( ): gnome-terminal/3223 openat(dfd: CWD, filename: "/proc/1244100/cmdline") ...
999.988 ( 0.044 ms): systemd-oomd/1151 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1001.slice/user@1001.service/memory.pressure", flags: RDONLY|CLOEXEC) = 11
1000.091 ( 0.010 ms): systemd-oomd/1151 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1001.slice/user@1001.service/memory.current", flags: RDONLY|CLOEXEC) = 11
[acme@five ~]$
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton
2023-08-16 16:08 ` Arnaldo Carvalho de Melo
2023-08-16 17:14 ` Arnaldo Carvalho de Melo
@ 2023-08-16 18:15 ` Ian Rogers
1 sibling, 0 replies; 22+ messages in thread
From: Ian Rogers @ 2023-08-16 18:15 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Adrian Hunter, Nathan Chancellor,
Nick Desaulniers, Tom Rix, Fangrui Song, Anshuman Khandual,
Andi Kleen, Leo Yan, Madhavan Srinivasan, Carsten Haitzler,
Ravi Bangoria, Naveen N. Rao, Athira Rajeev, Kan Liang,
Yang Jihong, James Clark, Tiezhu Yang, Eduard Zingerman,
Andrii Nakryiko, Yonghong Song, Rob Herring, LKML,
linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo, YueHaibing,
He Kuang, Brendan Gregg
On Wed, Aug 16, 2023 at 9:08 AM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> Em Wed, Aug 16, 2023 at 10:22:15AM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Wed, Aug 16, 2023 at 10:11:11AM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Just taking notes about things to work on top of what is in
> > > tmp.perf-tools-next, that will move to perf-tools-next soon:
>
> > > We need to make these libbpf error messages appear only in verbose mode,
> > > and probably have a hint about unprivileged BPF, a quick attempt failed
> > > after several attempts at getting privileges :-\
>
> > > Probably attaching to tracepoints is off limits to !root even with
> > > /proc/sys/kernel/unprivileged_bpf_disabled set to zero.
>
> > yep, the libbpf sys_bpf call to check if it could load a basic BPF
> > bytecode (prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2) succeeds,
> > but then, later we manage to create the maps, etc to then stumble on
>
> > bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERCPU_ARRAY, key_size=4, value_size=8272, max_entries=1, map_flags=0, inner_map_fd=0, map_name="augmented_args_", map_ifindex=0, btf_fd=0, btf_key_type_id=0, btf_value_type_id=0, btf_vmlinux_value_type_id=0, map_extra=0}, 72) = 7
> > bpf(BPF_BTF_LOAD, {btf="\237\353\1\0\30\0\0\0\0\0\0\0000\0\0\0000\0\0\0\t\0\0\0\1\0\0\0\0\0\0\1"..., btf_log_buf=NULL, btf_size=81, btf_log_size=0, btf_log_level=0}, 32) = -1 EPERM (Operation not permitted)
>
> > and:
>
> > bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_TRACEPOINT, insn_cnt=2, insns=0x1758340, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(6, 4, 7), prog_flags=0, prog_name="syscall_unaugme", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0, fd_array=NULL}, 144) = -1 EPERM (Operation not permitted)
>
> > So 'perf trace' should just not try to load the augmented_raw_syscalls
> > BPF skel for !root.
>
> Not really, I insisted and it is (was?) possible to make it work,
> testing on some other machine and after having to change the permissions
> recursively on tracefs (before a remount with mode=755 seemed to
> work?).
>
> I managed to make it work for !root, BPF collecting the pointer args for
> openat, access (perf trace looks for syscall signatures and reuses BPF
> progs for the ones matching one of the explicitely provided)
> clock_namosleep, etc.
>
> (re)Reading Documentation/admin-guide/perf-security.rst and getting it
> into the hints system of 'perf trace' may make this process simpler and
> safer, by using a group, etc. But it is possible, great!
>
> I didn't even had to touch /proc/sys/kernel/unprivileged_bpf_disabled,
> just the capabilities for the perf binary (which is a pretty big window,
> but way smaller than touching /proc/sys/kernel/unprivileged_bpf_disabled).
>
> So now we need to get BUILD_BPF_SKEL=1 to be the default but just emit a
> warning when what is needed isn't available, just like with other
> features, in that case 'perf trace' continues as today, no pointer arg
> contents collection.
>
> Unfortunately it is too late in the process for v6.6 even, so as soon as
> perf-tools-next becomes perf-tools and we reopen it for v6.7 the first
> patch should be this build BPF skels if what is needed is available.
Thanks Arnaldo! I think targeting this for 6.7 makes sense and thanks
for diving around all the permission issues.
Ian
> I'll also check if we can enable BUILD_BPF_SKEL=1 in the distro packages
> so that we collect some info from them about possible problems.
>
> What I have is now in perf-tools-next, so should get into linux-next and
> hopefully help in testing it, IIRC there are CIs that enable
> BUILD_BPF_SKEL=1.
>
> - Arnaldo
>
> [acme@five ~]$ uname -a
> Linux five 6.2.15-100.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 11 16:51:53 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
> [acme@five ~]$ id
> uid=1000(acme) gid=1000(acme) groups=1000(acme),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
> [acme@five ~]$ perf trace sleep 1
> ? ( ): sleep/980735 ... [continued]: execve()) = 0
> 0.031 ( 0.002 ms): sleep/980735 brk() = 0x55c621548000
> 0.039 ( 0.001 ms): sleep/980735 arch_prctl(option: 0x3001, arg2: 0x7ffeb8a6a460) = -1 EINVAL (Invalid argument)
> 0.058 ( 0.006 ms): sleep/980735 access(filename: "/etc/ld.so.preload", mode: R) = -1 ENOENT (No such file or directory)
> 0.068 ( 0.005 ms): sleep/980735 openat(dfd: CWD, filename: "/etc/ld.so.cache", flags: RDONLY|CLOEXEC) = 3
> 0.074 ( 0.002 ms): sleep/980735 newfstatat(dfd: 3, filename: "", statbuf: 0x7ffeb8a69680, flag: 4096) = 0
> 0.077 ( 0.006 ms): sleep/980735 mmap(len: 54771, prot: READ, flags: PRIVATE, fd: 3) = 0x7f6b95ad9000
> 0.084 ( 0.001 ms): sleep/980735 close(fd: 3) = 0
> 0.094 ( 0.006 ms): sleep/980735 openat(dfd: CWD, filename: "/lib64/libc.so.6", flags: RDONLY|CLOEXEC) = 3
> 0.101 ( 0.002 ms): sleep/980735 read(fd: 3, buf: 0x7ffeb8a697e8, count: 832) = 832
> 0.105 ( 0.001 ms): sleep/980735 pread64(fd: 3, buf: 0x7ffeb8a693e0, count: 784, pos: 64) = 784
> 0.107 ( 0.001 ms): sleep/980735 pread64(fd: 3, buf: 0x7ffeb8a69380, count: 80, pos: 848) = 80
> 0.110 ( 0.001 ms): sleep/980735 pread64(fd: 3, buf: 0x7ffeb8a69330, count: 68, pos: 928) = 68
> 0.113 ( 0.002 ms): sleep/980735 newfstatat(dfd: 3, filename: "", statbuf: 0x7ffeb8a69680, flag: 4096) = 0
> 0.115 ( 0.003 ms): sleep/980735 mmap(len: 8192, prot: READ|WRITE, flags: PRIVATE|ANONYMOUS) = 0x7f6b95ad7000
> 0.122 ( 0.001 ms): sleep/980735 pread64(fd: 3, buf: 0x7ffeb8a692d0, count: 784, pos: 64) = 784
> 0.126 ( 0.006 ms): sleep/980735 mmap(len: 2104720, prot: READ, flags: PRIVATE|DENYWRITE, fd: 3) = 0x7f6b95800000
> 0.133 ( 0.013 ms): sleep/980735 mmap(addr: 0x7f6b95828000, len: 1523712, prot: READ|EXEC, flags: PRIVATE|FIXED|DENYWRITE, fd: 3, off: 0x28000) = 0x7f6b95828000
> 0.147 ( 0.008 ms): sleep/980735 mmap(addr: 0x7f6b9599c000, len: 360448, prot: READ, flags: PRIVATE|FIXED|DENYWRITE, fd: 3, off: 0x19c000) = 0x7f6b9599c000
> 0.156 ( 0.010 ms): sleep/980735 mmap(addr: 0x7f6b959f4000, len: 24576, prot: READ|WRITE, flags: PRIVATE|FIXED|DENYWRITE, fd: 3, off: 0x1f3000) = 0x7f6b959f4000
> 0.171 ( 0.005 ms): sleep/980735 mmap(addr: 0x7f6b959fa000, len: 32144, prot: READ|WRITE, flags: PRIVATE|FIXED|ANONYMOUS) = 0x7f6b959fa000
> 0.182 ( 0.001 ms): sleep/980735 close(fd: 3) = 0
> 0.193 ( 0.003 ms): sleep/980735 mmap(len: 12288, prot: READ|WRITE, flags: PRIVATE|ANONYMOUS) = 0x7f6b95ad4000
> 0.199 ( 0.001 ms): sleep/980735 arch_prctl(option: SET_FS, arg2: 0x7f6b95ad4740) = 0
> 0.202 ( 0.001 ms): sleep/980735 set_tid_address(tidptr: 0x7f6b95ad4a10) = 980735 (sleep)
> 0.204 ( 0.001 ms): sleep/980735 set_robust_list(head: 0x7f6b95ad4a20, len: 24) = 0
> 0.206 ( 0.001 ms): sleep/980735 rseq(rseq: 0x7f6b95ad50e0, rseq_len: 32, sig: 1392848979) = 0
> 0.277 ( 0.010 ms): sleep/980735 mprotect(start: 0x7f6b959f4000, len: 16384, prot: READ) = 0
> 0.306 ( 0.007 ms): sleep/980735 mprotect(start: 0x55c61fa4a000, len: 4096, prot: READ) = 0
> 0.320 ( 0.010 ms): sleep/980735 mprotect(start: 0x7f6b95b1c000, len: 8192, prot: READ) = 0
> 0.340 ( 0.002 ms): sleep/980735 prlimit64(resource: STACK, old_rlim: 0x7ffeb8a6a1c0) = 0
> 0.349 ( 0.009 ms): sleep/980735 munmap(addr: 0x7f6b95ad9000, len: 54771) = 0
> 0.381 ( 0.002 ms): sleep/980735 getrandom(ubuf: 0x7f6b959ff4d8, len: 8, flags: NONBLOCK) = 8
> 0.386 ( 0.001 ms): sleep/980735 brk() = 0x55c621548000
> 0.388 ( 0.006 ms): sleep/980735 brk(brk: 0x55c621569000) = 0x55c621569000
> 0.403 ( 0.012 ms): sleep/980735 openat(dfd: CWD, filename: "", flags: RDONLY|CLOEXEC) = 3
> 0.417 ( 0.003 ms): sleep/980735 newfstatat(dfd: 3, filename: "", statbuf: 0x7f6b959f9b80, flag: 4096) = 0
> 0.422 ( 0.008 ms): sleep/980735 mmap(len: 224096080, prot: READ, flags: PRIVATE, fd: 3) = 0x7f6b88200000
> 0.436 ( 0.002 ms): sleep/980735 close(fd: 3) = 0
> 0.480 (1000.041 ms): sleep/980735 clock_nanosleep(rqtp: { .tv_sec: 1, .tv_nsec: 0 }, rmtp: 0x7ffeb8a6a450) = 0
> 1000.552 ( 0.003 ms): sleep/980735 close(fd: 1) = 0
> 1000.558 ( 0.002 ms): sleep/980735 close(fd: 2) = 0
> 1000.565 ( ): sleep/980735 exit_group() = ?
> [acme@five ~]$ getcap ~/bin/perf
> /var/home/acme/bin/perf cap_perfmon,cap_bpf=ep
> [acme@five ~]$ cat /proc/sys/kernel/unprivileged_bpf_disabled
> 2
> [acme@five ~]$ cat /proc/sys/kernel/perf_event_paranoid
> -1
> [acme@five ~]$
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 1/4] perf parse-events: Remove BPF event support
2023-08-11 15:41 ` [PATCH v1 1/4] perf parse-events: Remove BPF event support Arnaldo Carvalho de Melo
@ 2023-10-19 19:45 ` Manu Bretelle
2023-10-19 21:08 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 22+ messages in thread
From: Manu Bretelle @ 2023-10-19 19:45 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
Nathan Chancellor, Nick Desaulniers, Tom Rix, Fangrui Song,
Anshuman Khandual, Andi Kleen, Leo Yan, Madhavan Srinivasan,
Carsten Haitzler, Ravi Bangoria, Naveen N. Rao, Athira Rajeev,
Kan Liang, Yang Jihong, James Clark, Tiezhu Yang,
Eduard Zingerman, Andrii Nakryiko, Yonghong Song, Rob Herring,
linux-kernel, linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo,
YueHaibing, He Kuang, Brendan Gregg, Quentin Monnet
cc @quentin
On Fri, Aug 11, 2023 at 12:41:36PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Fri, Aug 11, 2023 at 11:43:22AM -0300, Arnaldo Carvalho de Melo escreveu:
> > Right now it is not applying due to some clash with other changes and
> > when I tried to apply it manually there were some formatting issues:
> >
> > ⬢[acme@toolbox perf-tools-next]$ head ~/wb/1.patch
> > From SRS0=EALy=D3=flex--irogers.bounces.google.com=3IDHVZAcKBAUnwtljwxlttlqj.htrfhrjpjwsjq.twl@kernel.org Thu Aug 10 17:53:46 2023
> > Delivered-To: arnaldo.melo@gmail.com
> > Received: from imap.gmail.com [64.233.186.109]
> > by quaco with IMAP (fetchmail-6.4.37)
> > for <acme@localhost> (single-drop); Thu, 10 Aug 2023 17:53:46 -0300 (-03)
> > Received: by 2002:a0c:ab03:0:b0:63d:780e:9480 with SMTP id h3csp908198qvb;
> > Thu, 10 Aug 2023 11:49:52 -0700 (PDT)
> > X-Google-Smtp-Source: AGHT+IH9N/knUCyQ0tQ2Q0XBH0gqf8A8DB8/37YHWAJDKBmz7AGSV9CvCKYDuE3EwxriZFBwtZMs
> > X-Received: by 2002:a4a:6b4f:0:b0:56c:b2ab:9820 with SMTP id
> > h15-20020a4a6b4f000000b0056cb2ab9820mr2695332oof.8.1691693392493; Thu, 10 Aug
> > ⬢[acme@toolbox perf-tools-next]$ patch -p1 < ~/wb/1.patch
> > patching file tools/perf/Documentation/perf-config.txt
> > patch: **** malformed patch at line 234: ith
> >
> > ⬢[acme@toolbox perf-tools-next]$
> >
> > I'm trying to apply it manually.
>
> I have this extracted from this patch as the first patch in the series:
>
> >From adc61b5774a9de62f34d593f164ca02daa6fb44c Mon Sep 17 00:00:00 2001
> From: Ian Rogers <irogers@google.com>
> Date: Fri, 11 Aug 2023 12:19:48 -0300
> Subject: [PATCH 1/1] perf bpf: Remove support for embedding clang for
> compiling BPF events (-e foo.c)
>
> This never was in the default build for perf, is difficult to maintain
> as it uses clang/llvm internals so ditch it, keeping, for now, the
> external compilation of .c BPF into .o bytecode and its subsequent
> loading, that is also going to be removed, do it separately to help
> bisection and to properly document what is being removed and why.
>
> Committer notes:
>
> Extracted from a larger patch and removed some leftovers, namely
> deleting these now unused feature tests:
>
> tools/build/feature/test-clang.cpp
> tools/build/feature/test-cxx.cpp
> tools/build/feature/test-llvm-version.cpp
> tools/build/feature/test-llvm.cpp
>
This seem to have broken `llvm` feature detection for `bpftool`.
The feature detections are still available in `tools/build/Makefile.feature` [0]
but the .cpp files are gone.
`bpftool` still rely on the `llvm` feature:
$ git --no-pager grep 'feature-llvm'
tools/bpf/bpftool/Makefile:ifeq ($(feature-llvm),1)
The result of testing llvm feature is:
$ cat tools/build/feature/test-llvm.make.output
cc1plus: fatal error: test-llvm.cpp: No such file or directory
compilation terminated.
With current head:
make -j $((4*$(nproc))) -C tools/bpf/bpftool && ./tools/bpf/bpftool/bpftool --version
...
Auto-detecting system features:
... clang-bpf-co-re: [ on ]
... llvm: [ OFF ]
... libcap: [ on ]
... libbfd: [ on ]
...
...
...
bpftool v7.3.0
using libbpf v1.3
features: libbfd, skeletons
After applying
git show 56b11a2126bf2f422831ecf6112b87a4485b221b tools/build/feature | \
patch -p1 -R
The feature gets properly detected again by:
make -j $((4*$(nproc))) -C tools/bpf/bpftool && ./tools/bpf/bpftool/bpftool --version
...
Auto-detecting system features:
... clang-bpf-co-re: [ on ]
... llvm: [ on ]
... libcap: [ on ]
... libbfd: [ on ]
...
...
bpftool v7.3.0
using libbpf v1.3
features: llvm, skeletons
make -C tools/bpf/bpftool
[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/build/Makefile.feature?id=74e9347ebc5be452935fe4f3eddb150aa5a6f4fe#n99
> Testing the use of BPF events after applying this patch:
>
> To use the external clang/llvm toolchain to compile a .c event and then
> use libbpf to load it, to get the syscalls:sys_enter_open* tracepoints
> and read the filename pointer, putting it into the ring buffer right
> after the usual tracepoint payload for 'perf trace' to then print it:
>
> [root@quaco ~]# perf trace -e /home/acme/git/perf-tools-next/tools/perf/examples/bpf/augmented_raw_syscalls.c,open* --max-events=10
> 0.000 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
> 0.083 abrt-dump-jour/1453 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
> 0.063 abrt-dump-jour/1454 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
> 0.082 abrt-dump-jour/1455 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
> 250.124 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
> 250.521 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.pressure", flags: RDONLY|CLOEXEC) = 12
> 251.047 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.current", flags: RDONLY|CLOEXEC) = 12
> 251.162 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.min", flags: RDONLY|CLOEXEC) = 12
> 251.242 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.low", flags: RDONLY|CLOEXEC) = 12
> 251.353 systemd-oomd/959 openat(dfd: CWD, filename: "/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/app.slice/memory.swap.current", flags: RDONLY|CLOEXEC) = 12
> [root@quaco ~]#
>
> Same thing, but with a prebuilt .o BPF bytecode:
>
> [root@quaco ~]# perf trace -e /home/acme/git/perf-tools-next/tools/perf/examples/bpf/augmented_raw_syscalls.o,open* --max-events=10
> 0.000 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
> 0.083 abrt-dump-jour/1453 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
> 0.083 abrt-dump-jour/1455 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
> 0.062 abrt-dump-jour/1454 openat(dfd: CWD, filename: "/var/log/journal/d6a97235307247e09f13f326fb607e3c/system.journal", flags: RDONLY|CLOEXEC|NONBLOCK) = 4
> 249.985 systemd-oomd/959 openat(dfd: CWD, filename: "/proc/meminfo", flags: RDONLY|CLOEXEC) = 12
> 466.763 thermald/1234 openat(dfd: CWD, filename: "/sys/class/powercap/intel-rapl/intel-rapl:0/intel-rapl:0:2/energy_uj") = 13
> 467.145 thermald/1234 openat(dfd: CWD, filename: "/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj") = 13
> 467.311 thermald/1234 openat(dfd: CWD, filename: "/sys/class/thermal/thermal_zone2/temp") = 13
> 500.040 cgroupify/24006 openat(dfd: 4, filename: ".", flags: RDONLY|CLOEXEC|DIRECTORY|NONBLOCK) = 5
> 500.295 cgroupify/24006 openat(dfd: 4, filename: "24616/cgroup.procs") = 5
> [root@quaco ~]#
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Andi Kleen <ak@linux.intel.com>
> Cc: Andrii Nakryiko <andrii@kernel.org>
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
> Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
> Cc: Carsten Haitzler <carsten.haitzler@arm.com>
> Cc: Eduard Zingerman <eddyz87@gmail.com>
> Cc: Fangrui Song <maskray@google.com>
> Cc: He Kuang <hekuang@huawei.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: James Clark <james.clark@arm.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Kan Liang <kan.liang@linux.intel.com>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Nathan Chancellor <nathan@kernel.org>
> Cc: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ravi Bangoria <ravi.bangoria@amd.com>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
> Cc: Tom Rix <trix@redhat.com>
> Cc: Wang Nan <wangnan0@huawei.com>
> Cc: Wang ShaoBo <bobo.shaobowang@huawei.com>
> Cc: Yang Jihong <yangjihong1@huawei.com>
> Cc: Yonghong Song <yhs@fb.com>
> Cc: YueHaibing <yuehaibing@huawei.com>
> Link: https://lore.kernel.org/lkml/
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> tools/build/feature/test-clang.cpp | 28 ---
> tools/build/feature/test-cxx.cpp | 16 --
> tools/build/feature/test-llvm-version.cpp | 12 --
> tools/build/feature/test-llvm.cpp | 14 --
> tools/perf/Makefile.config | 31 ---
> tools/perf/Makefile.perf | 17 --
> tools/perf/tests/Build | 1 -
> tools/perf/tests/builtin-test.c | 1 -
> tools/perf/tests/clang.c | 32 ---
> tools/perf/tests/make | 1 -
> tools/perf/util/Build | 2 -
> tools/perf/util/bpf-loader.c | 15 +-
> tools/perf/util/c++/Build | 5 -
> tools/perf/util/c++/clang-c.h | 43 -----
> tools/perf/util/c++/clang-test.cpp | 67 -------
> tools/perf/util/c++/clang.cpp | 225 ----------------------
> tools/perf/util/c++/clang.h | 27 ---
> 17 files changed, 4 insertions(+), 533 deletions(-)
> delete mode 100644 tools/build/feature/test-clang.cpp
> delete mode 100644 tools/build/feature/test-cxx.cpp
> delete mode 100644 tools/build/feature/test-llvm-version.cpp
> delete mode 100644 tools/build/feature/test-llvm.cpp
> delete mode 100644 tools/perf/tests/clang.c
> delete mode 100644 tools/perf/util/c++/Build
> delete mode 100644 tools/perf/util/c++/clang-c.h
> delete mode 100644 tools/perf/util/c++/clang-test.cpp
> delete mode 100644 tools/perf/util/c++/clang.cpp
> delete mode 100644 tools/perf/util/c++/clang.h
>
> diff --git a/tools/build/feature/test-clang.cpp b/tools/build/feature/test-clang.cpp
> deleted file mode 100644
> index 7d87075cd1c5dd6e..0000000000000000
> --- a/tools/build/feature/test-clang.cpp
> +++ /dev/null
> @@ -1,28 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include "clang/Basic/Version.h"
> -#if CLANG_VERSION_MAJOR < 8
> -#include "clang/Basic/VirtualFileSystem.h"
> -#endif
> -#include "clang/Driver/Driver.h"
> -#include "clang/Frontend/TextDiagnosticPrinter.h"
> -#include "llvm/ADT/IntrusiveRefCntPtr.h"
> -#include "llvm/Support/ManagedStatic.h"
> -#if CLANG_VERSION_MAJOR >= 8
> -#include "llvm/Support/VirtualFileSystem.h"
> -#endif
> -#include "llvm/Support/raw_ostream.h"
> -
> -using namespace clang;
> -using namespace clang::driver;
> -
> -int main()
> -{
> - IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
> - IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
> -
> - DiagnosticsEngine Diags(DiagID, &*DiagOpts);
> - Driver TheDriver("test", "bpf-pc-linux", Diags);
> -
> - llvm::llvm_shutdown();
> - return 0;
> -}
> diff --git a/tools/build/feature/test-cxx.cpp b/tools/build/feature/test-cxx.cpp
> deleted file mode 100644
> index 396aaedd2418dd65..0000000000000000
> --- a/tools/build/feature/test-cxx.cpp
> +++ /dev/null
> @@ -1,16 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include <iostream>
> -#include <memory>
> -
> -static void print_str(std::string s)
> -{
> - std::cout << s << std::endl;
> -}
> -
> -int main()
> -{
> - std::string s("Hello World!");
> - print_str(std::move(s));
> - std::cout << "|" << s << "|" << std::endl;
> - return 0;
> -}
> diff --git a/tools/build/feature/test-llvm-version.cpp b/tools/build/feature/test-llvm-version.cpp
> deleted file mode 100644
> index 8a091625446af985..0000000000000000
> --- a/tools/build/feature/test-llvm-version.cpp
> +++ /dev/null
> @@ -1,12 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include <cstdio>
> -#include "llvm/Config/llvm-config.h"
> -
> -#define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH)
> -#define pass int main() {printf("%x\n", NUM_VERSION); return 0;}
> -
> -#if NUM_VERSION >= 0x030900
> -pass
> -#else
> -# error This LLVM is not tested yet.
> -#endif
> diff --git a/tools/build/feature/test-llvm.cpp b/tools/build/feature/test-llvm.cpp
> deleted file mode 100644
> index 88a3d1bdd9f6978e..0000000000000000
> --- a/tools/build/feature/test-llvm.cpp
> +++ /dev/null
> @@ -1,14 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include "llvm/Support/ManagedStatic.h"
> -#include "llvm/Support/raw_ostream.h"
> -#define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH)
> -
> -#if NUM_VERSION < 0x030900
> -# error "LLVM version too low"
> -#endif
> -int main()
> -{
> - llvm::errs() << "Hello World!\n";
> - llvm::llvm_shutdown();
> - return 0;
> -}
> diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> index 1bf8dc53641fa093..e0592ed4c10f5904 100644
> --- a/tools/perf/Makefile.config
> +++ b/tools/perf/Makefile.config
> @@ -1127,37 +1127,6 @@ ifndef NO_JVMTI
> endif
> endif
>
> -USE_CXX = 0
> -USE_CLANGLLVM = 0
> -ifdef LIBCLANGLLVM
> - $(call feature_check,cxx)
> - ifneq ($(feature-cxx), 1)
> - msg := $(warning No g++ found, disable clang and llvm support. Please install g++)
> - else
> - $(call feature_check,llvm)
> - $(call feature_check,llvm-version)
> - ifneq ($(feature-llvm), 1)
> - msg := $(warning No suitable libLLVM found, disabling builtin clang and LLVM support. Please install llvm-dev(el) (>= 3.9.0))
> - else
> - $(call feature_check,clang)
> - ifneq ($(feature-clang), 1)
> - msg := $(warning No suitable libclang found, disabling builtin clang and LLVM support. Please install libclang-dev(el) (>= 3.9.0))
> - else
> - CFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT
> - CXXFLAGS += -DHAVE_LIBCLANGLLVM_SUPPORT -I$(shell $(LLVM_CONFIG) --includedir)
> - $(call detected,CONFIG_CXX)
> - $(call detected,CONFIG_CLANGLLVM)
> - USE_CXX = 1
> - USE_LLVM = 1
> - USE_CLANG = 1
> - ifneq ($(feature-llvm-version),1)
> - msg := $(warning This version of LLVM is not tested. May cause build errors)
> - endif
> - endif
> - endif
> - endif
> -endif
> -
> ifndef NO_LIBPFM4
> $(call feature_check,libpfm4)
> ifeq ($(feature-libpfm4), 1)
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 0ed7ee0c1665a8cf..5370d7bf123e76af 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -99,10 +99,6 @@ include ../scripts/utilities.mak
> # Define NO_JVMTI_CMLR (debug only) if you do not want to process CMLR
> # data for java source lines.
> #
> -# Define LIBCLANGLLVM if you DO want builtin clang and llvm support.
> -# When selected, pass LLVM_CONFIG=/path/to/llvm-config to `make' if
> -# llvm-config is not in $PATH.
> -#
> # Define CORESIGHT if you DO WANT support for CoreSight trace decoding.
> #
> # Define NO_AIO if you do not want support of Posix AIO based trace
> @@ -425,19 +421,6 @@ endif
> EXTLIBS := $(call filter-out,$(EXCLUDE_EXTLIBS),$(EXTLIBS))
> LIBS = -Wl,--whole-archive $(PERFLIBS) $(EXTRA_PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
>
> -ifeq ($(USE_CLANG), 1)
> - LIBS += -L$(shell $(LLVM_CONFIG) --libdir) -lclang-cpp
> -endif
> -
> -ifeq ($(USE_LLVM), 1)
> - LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs)
> - LIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM)
> -endif
> -
> -ifeq ($(USE_CXX), 1)
> - LIBS += -lstdc++
> -endif
> -
> export INSTALL SHELL_PATH
>
> ### Build rules
> diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
> index fb9ac5dc4079dab8..52df5923a8b9cc20 100644
> --- a/tools/perf/tests/Build
> +++ b/tools/perf/tests/Build
> @@ -51,7 +51,6 @@ perf-y += sdt.o
> perf-y += is_printable_array.o
> perf-y += bitmap.o
> perf-y += perf-hooks.o
> -perf-y += clang.o
> perf-y += unit_number__scnprintf.o
> perf-y += mem2node.o
> perf-y += maps.o
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index 6accb5442a731842..0f3691fd31c2536f 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -108,7 +108,6 @@ static struct test_suite *generic_tests[] = {
> &suite__is_printable_array,
> &suite__bitmap_print,
> &suite__perf_hooks,
> - &suite__clang,
> &suite__unit_number__scnprint,
> &suite__mem2node,
> &suite__time_utils,
> diff --git a/tools/perf/tests/clang.c b/tools/perf/tests/clang.c
> deleted file mode 100644
> index a7111005d5b9f481..0000000000000000
> --- a/tools/perf/tests/clang.c
> +++ /dev/null
> @@ -1,32 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include "tests.h"
> -#include "c++/clang-c.h"
> -#include <linux/kernel.h>
> -
> -#ifndef HAVE_LIBCLANGLLVM_SUPPORT
> -static int test__clang_to_IR(struct test_suite *test __maybe_unused,
> - int subtest __maybe_unused)
> -{
> - return TEST_SKIP;
> -}
> -
> -static int test__clang_to_obj(struct test_suite *test __maybe_unused,
> - int subtest __maybe_unused)
> -{
> - return TEST_SKIP;
> -}
> -#endif
> -
> -static struct test_case clang_tests[] = {
> - TEST_CASE_REASON("builtin clang compile C source to IR", clang_to_IR,
> - "not compiled in"),
> - TEST_CASE_REASON("builtin clang compile C source to ELF object",
> - clang_to_obj,
> - "not compiled in"),
> - { .name = NULL, }
> -};
> -
> -struct test_suite suite__clang = {
> - .desc = "builtin clang support",
> - .test_cases = clang_tests,
> -};
> diff --git a/tools/perf/tests/make b/tools/perf/tests/make
> index 58cf96d762d06a68..ea4c341f5af11741 100644
> --- a/tools/perf/tests/make
> +++ b/tools/perf/tests/make
> @@ -95,7 +95,6 @@ make_with_babeltrace:= LIBBABELTRACE=1
> make_with_coresight := CORESIGHT=1
> make_no_sdt := NO_SDT=1
> make_no_syscall_tbl := NO_SYSCALL_TABLE=1
> -make_with_clangllvm := LIBCLANGLLVM=1
> make_no_libpfm4 := NO_LIBPFM4=1
> make_with_gtk2 := GTK2=1
> make_refcnt_check := EXTRA_CFLAGS="-DREFCNT_CHECKING=1"
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index 9699e31ff4c04925..ff3b55c7ed43cdad 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -232,8 +232,6 @@ perf-y += perf-hooks.o
> perf-$(CONFIG_LIBBPF) += bpf-event.o
> perf-$(CONFIG_LIBBPF) += bpf-utils.o
>
> -perf-$(CONFIG_CXX) += c++/
> -
> perf-$(CONFIG_LIBPFM4) += pfm.o
>
> CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
> diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
> index 50e42698cbb721d1..b54e42f17926b17e 100644
> --- a/tools/perf/util/bpf-loader.c
> +++ b/tools/perf/util/bpf-loader.c
> @@ -26,7 +26,6 @@
> #include "strfilter.h"
> #include "util.h"
> #include "llvm-utils.h"
> -#include "c++/clang-c.h"
> #include "util/hashmap.h"
> #include "asm/bug.h"
>
> @@ -220,16 +219,10 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
> void *obj_buf;
> size_t obj_buf_sz;
>
> - perf_clang__init();
> - err = perf_clang__compile_bpf(filename, &obj_buf, &obj_buf_sz);
> - perf_clang__cleanup();
> - if (err) {
> - pr_debug("bpf: builtin compilation failed: %d, try external compiler\n", err);
> - err = llvm__compile_bpf(filename, &obj_buf, &obj_buf_sz);
> - if (err)
> - return ERR_PTR(-BPF_LOADER_ERRNO__COMPILE);
> - } else
> - pr_debug("bpf: successful builtin compilation\n");
> + err = llvm__compile_bpf(filename, &obj_buf, &obj_buf_sz);
> + if (err)
> + return ERR_PTR(-BPF_LOADER_ERRNO__COMPILE);
> +
> obj = bpf_object__open_mem(obj_buf, obj_buf_sz, &opts);
>
> if (!IS_ERR_OR_NULL(obj) && llvm_param.dump_obj)
> diff --git a/tools/perf/util/c++/Build b/tools/perf/util/c++/Build
> deleted file mode 100644
> index 8610d032ac19d8c5..0000000000000000
> --- a/tools/perf/util/c++/Build
> +++ /dev/null
> @@ -1,5 +0,0 @@
> -perf-$(CONFIG_CLANGLLVM) += clang.o
> -perf-$(CONFIG_CLANGLLVM) += clang-test.o
> -
> -CXXFLAGS_clang.o += -Wno-unused-parameter
> -CXXFLAGS_clang-test.o += -Wno-unused-parameter
> diff --git a/tools/perf/util/c++/clang-c.h b/tools/perf/util/c++/clang-c.h
> deleted file mode 100644
> index d3731a876b6c10c5..0000000000000000
> --- a/tools/perf/util/c++/clang-c.h
> +++ /dev/null
> @@ -1,43 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef PERF_UTIL_CLANG_C_H
> -#define PERF_UTIL_CLANG_C_H
> -
> -#include <stddef.h> /* for size_t */
> -
> -#ifdef __cplusplus
> -extern "C" {
> -#endif
> -
> -#ifdef HAVE_LIBCLANGLLVM_SUPPORT
> -extern void perf_clang__init(void);
> -extern void perf_clang__cleanup(void);
> -
> -struct test_suite;
> -extern int test__clang_to_IR(struct test_suite *test, int subtest);
> -extern int test__clang_to_obj(struct test_suite *test, int subtest);
> -
> -extern int perf_clang__compile_bpf(const char *filename,
> - void **p_obj_buf,
> - size_t *p_obj_buf_sz);
> -#else
> -
> -#include <errno.h>
> -#include <linux/compiler.h> /* for __maybe_unused */
> -
> -static inline void perf_clang__init(void) { }
> -static inline void perf_clang__cleanup(void) { }
> -
> -static inline int
> -perf_clang__compile_bpf(const char *filename __maybe_unused,
> - void **p_obj_buf __maybe_unused,
> - size_t *p_obj_buf_sz __maybe_unused)
> -{
> - return -ENOTSUP;
> -}
> -
> -#endif
> -
> -#ifdef __cplusplus
> -}
> -#endif
> -#endif
> diff --git a/tools/perf/util/c++/clang-test.cpp b/tools/perf/util/c++/clang-test.cpp
> deleted file mode 100644
> index a4683ca536973c04..0000000000000000
> --- a/tools/perf/util/c++/clang-test.cpp
> +++ /dev/null
> @@ -1,67 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include "clang.h"
> -#include "clang-c.h"
> -extern "C" {
> -#include "../util.h"
> -}
> -#include "llvm/IR/Function.h"
> -#include "llvm/IR/LLVMContext.h"
> -
> -#include <tests/llvm.h>
> -#include <string>
> -
> -class perf_clang_scope {
> -public:
> - explicit perf_clang_scope() {perf_clang__init();}
> - ~perf_clang_scope() {perf_clang__cleanup();}
> -};
> -
> -static std::unique_ptr<llvm::Module>
> -__test__clang_to_IR(void)
> -{
> - unsigned int kernel_version;
> -
> - if (fetch_kernel_version(&kernel_version, NULL, 0))
> - return std::unique_ptr<llvm::Module>(nullptr);
> -
> - std::string cflag_kver("-DLINUX_VERSION_CODE=" +
> - std::to_string(kernel_version));
> -
> - std::unique_ptr<llvm::Module> M =
> - perf::getModuleFromSource({cflag_kver.c_str()},
> - "perf-test.c",
> - test_llvm__bpf_base_prog);
> - return M;
> -}
> -
> -extern "C" {
> -int test__clang_to_IR(struct test_suite *test __maybe_unused,
> - int subtest __maybe_unused)
> -{
> - perf_clang_scope _scope;
> -
> - auto M = __test__clang_to_IR();
> - if (!M)
> - return -1;
> - for (llvm::Function& F : *M)
> - if (F.getName() == "bpf_func__SyS_epoll_pwait")
> - return 0;
> - return -1;
> -}
> -
> -int test__clang_to_obj(struct test_suite *test __maybe_unused,
> - int subtest __maybe_unused)
> -{
> - perf_clang_scope _scope;
> -
> - auto M = __test__clang_to_IR();
> - if (!M)
> - return -1;
> -
> - auto Buffer = perf::getBPFObjectFromModule(&*M);
> - if (!Buffer)
> - return -1;
> - return 0;
> -}
> -
> -}
> diff --git a/tools/perf/util/c++/clang.cpp b/tools/perf/util/c++/clang.cpp
> deleted file mode 100644
> index 1aad7d6d34aaa639..0000000000000000
> --- a/tools/perf/util/c++/clang.cpp
> +++ /dev/null
> @@ -1,225 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -/*
> - * llvm C frontend for perf. Support dynamically compile C file
> - *
> - * Inspired by clang example code:
> - * http://llvm.org/svn/llvm-project/cfe/trunk/examples/clang-interpreter/main.cpp
> - *
> - * Copyright (C) 2016 Wang Nan <wangnan0@huawei.com>
> - * Copyright (C) 2016 Huawei Inc.
> - */
> -
> -#include "clang/Basic/Version.h"
> -#include "clang/CodeGen/CodeGenAction.h"
> -#include "clang/Frontend/CompilerInvocation.h"
> -#include "clang/Frontend/CompilerInstance.h"
> -#include "clang/Frontend/TextDiagnosticPrinter.h"
> -#include "clang/Tooling/Tooling.h"
> -#include "llvm/IR/LegacyPassManager.h"
> -#include "llvm/IR/Module.h"
> -#include "llvm/Option/Option.h"
> -#include "llvm/Support/FileSystem.h"
> -#include "llvm/Support/ManagedStatic.h"
> -#if CLANG_VERSION_MAJOR >= 14
> -#include "llvm/MC/TargetRegistry.h"
> -#else
> -#include "llvm/Support/TargetRegistry.h"
> -#endif
> -#include "llvm/Support/TargetSelect.h"
> -#include "llvm/Target/TargetMachine.h"
> -#include "llvm/Target/TargetOptions.h"
> -#include <memory>
> -
> -#include "clang.h"
> -#include "clang-c.h"
> -
> -namespace perf {
> -
> -static std::unique_ptr<llvm::LLVMContext> LLVMCtx;
> -
> -using namespace clang;
> -
> -static CompilerInvocation *
> -createCompilerInvocation(llvm::opt::ArgStringList CFlags, StringRef& Path,
> - DiagnosticsEngine& Diags)
> -{
> - llvm::opt::ArgStringList CCArgs {
> - "-cc1",
> - "-triple", "bpf-pc-linux",
> - "-fsyntax-only",
> - "-O2",
> - "-nostdsysteminc",
> - "-nobuiltininc",
> - "-vectorize-loops",
> - "-vectorize-slp",
> - "-Wno-unused-value",
> - "-Wno-pointer-sign",
> - "-x", "c"};
> -
> - CCArgs.append(CFlags.begin(), CFlags.end());
> - CompilerInvocation *CI = tooling::newInvocation(&Diags, CCArgs
> -#if CLANG_VERSION_MAJOR >= 11
> - ,/*BinaryName=*/nullptr
> -#endif
> - );
> -
> - FrontendOptions& Opts = CI->getFrontendOpts();
> - Opts.Inputs.clear();
> - Opts.Inputs.emplace_back(Path,
> - FrontendOptions::getInputKindForExtension("c"));
> - return CI;
> -}
> -
> -static std::unique_ptr<llvm::Module>
> -getModuleFromSource(llvm::opt::ArgStringList CFlags,
> - StringRef Path, IntrusiveRefCntPtr<vfs::FileSystem> VFS)
> -{
> - CompilerInstance Clang;
> - Clang.createDiagnostics();
> -
> -#if CLANG_VERSION_MAJOR < 9
> - Clang.setVirtualFileSystem(&*VFS);
> -#else
> - Clang.createFileManager(&*VFS);
> -#endif
> -
> -#if CLANG_VERSION_MAJOR < 4
> - IntrusiveRefCntPtr<CompilerInvocation> CI =
> - createCompilerInvocation(std::move(CFlags), Path,
> - Clang.getDiagnostics());
> - Clang.setInvocation(&*CI);
> -#else
> - std::shared_ptr<CompilerInvocation> CI(
> - createCompilerInvocation(std::move(CFlags), Path,
> - Clang.getDiagnostics()));
> - Clang.setInvocation(CI);
> -#endif
> -
> - std::unique_ptr<CodeGenAction> Act(new EmitLLVMOnlyAction(&*LLVMCtx));
> - if (!Clang.ExecuteAction(*Act))
> - return std::unique_ptr<llvm::Module>(nullptr);
> -
> - return Act->takeModule();
> -}
> -
> -std::unique_ptr<llvm::Module>
> -getModuleFromSource(llvm::opt::ArgStringList CFlags,
> - StringRef Name, StringRef Content)
> -{
> - using namespace vfs;
> -
> - llvm::IntrusiveRefCntPtr<OverlayFileSystem> OverlayFS(
> - new OverlayFileSystem(getRealFileSystem()));
> - llvm::IntrusiveRefCntPtr<InMemoryFileSystem> MemFS(
> - new InMemoryFileSystem(true));
> -
> - /*
> - * pushOverlay helps setting working dir for MemFS. Must call
> - * before addFile.
> - */
> - OverlayFS->pushOverlay(MemFS);
> - MemFS->addFile(Twine(Name), 0, llvm::MemoryBuffer::getMemBuffer(Content));
> -
> - return getModuleFromSource(std::move(CFlags), Name, OverlayFS);
> -}
> -
> -std::unique_ptr<llvm::Module>
> -getModuleFromSource(llvm::opt::ArgStringList CFlags, StringRef Path)
> -{
> - IntrusiveRefCntPtr<vfs::FileSystem> VFS(vfs::getRealFileSystem());
> - return getModuleFromSource(std::move(CFlags), Path, VFS);
> -}
> -
> -std::unique_ptr<llvm::SmallVectorImpl<char>>
> -getBPFObjectFromModule(llvm::Module *Module)
> -{
> - using namespace llvm;
> -
> - std::string TargetTriple("bpf-pc-linux");
> - std::string Error;
> - const Target* Target = TargetRegistry::lookupTarget(TargetTriple, Error);
> - if (!Target) {
> - llvm::errs() << Error;
> - return std::unique_ptr<llvm::SmallVectorImpl<char>>(nullptr);
> - }
> -
> - llvm::TargetOptions Opt;
> - TargetMachine *TargetMachine =
> - Target->createTargetMachine(TargetTriple,
> - "generic", "",
> - Opt, Reloc::Static);
> -
> - Module->setDataLayout(TargetMachine->createDataLayout());
> - Module->setTargetTriple(TargetTriple);
> -
> - std::unique_ptr<SmallVectorImpl<char>> Buffer(new SmallVector<char, 0>());
> - raw_svector_ostream ostream(*Buffer);
> -
> - legacy::PassManager PM;
> - bool NotAdded;
> - NotAdded = TargetMachine->addPassesToEmitFile(PM, ostream
> -#if CLANG_VERSION_MAJOR >= 7
> - , /*DwoOut=*/nullptr
> -#endif
> -#if CLANG_VERSION_MAJOR < 10
> - , TargetMachine::CGFT_ObjectFile
> -#else
> - , llvm::CGFT_ObjectFile
> -#endif
> - );
> - if (NotAdded) {
> - llvm::errs() << "TargetMachine can't emit a file of this type\n";
> - return std::unique_ptr<llvm::SmallVectorImpl<char>>(nullptr);
> - }
> - PM.run(*Module);
> -
> - return Buffer;
> -}
> -
> -}
> -
> -extern "C" {
> -void perf_clang__init(void)
> -{
> - perf::LLVMCtx.reset(new llvm::LLVMContext());
> - LLVMInitializeBPFTargetInfo();
> - LLVMInitializeBPFTarget();
> - LLVMInitializeBPFTargetMC();
> - LLVMInitializeBPFAsmPrinter();
> -}
> -
> -void perf_clang__cleanup(void)
> -{
> - perf::LLVMCtx.reset(nullptr);
> - llvm::llvm_shutdown();
> -}
> -
> -int perf_clang__compile_bpf(const char *filename,
> - void **p_obj_buf,
> - size_t *p_obj_buf_sz)
> -{
> - using namespace perf;
> -
> - if (!p_obj_buf || !p_obj_buf_sz)
> - return -EINVAL;
> -
> - llvm::opt::ArgStringList CFlags;
> - auto M = getModuleFromSource(std::move(CFlags), filename);
> - if (!M)
> - return -EINVAL;
> - auto O = getBPFObjectFromModule(&*M);
> - if (!O)
> - return -EINVAL;
> -
> - size_t size = O->size_in_bytes();
> - void *buffer;
> -
> - buffer = malloc(size);
> - if (!buffer)
> - return -ENOMEM;
> - memcpy(buffer, O->data(), size);
> - *p_obj_buf = buffer;
> - *p_obj_buf_sz = size;
> - return 0;
> -}
> -}
> diff --git a/tools/perf/util/c++/clang.h b/tools/perf/util/c++/clang.h
> deleted file mode 100644
> index 6ce33e22f23c084a..0000000000000000
> --- a/tools/perf/util/c++/clang.h
> +++ /dev/null
> @@ -1,27 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -#ifndef PERF_UTIL_CLANG_H
> -#define PERF_UTIL_CLANG_H
> -
> -#include "llvm/ADT/StringRef.h"
> -#include "llvm/IR/LLVMContext.h"
> -#include "llvm/IR/Module.h"
> -#include "llvm/Option/Option.h"
> -#include <memory>
> -
> -namespace perf {
> -
> -using namespace llvm;
> -
> -std::unique_ptr<Module>
> -getModuleFromSource(opt::ArgStringList CFlags,
> - StringRef Name, StringRef Content);
> -
> -std::unique_ptr<Module>
> -getModuleFromSource(opt::ArgStringList CFlags,
> - StringRef Path);
> -
> -std::unique_ptr<llvm::SmallVectorImpl<char>>
> -getBPFObjectFromModule(llvm::Module *Module);
> -
> -}
> -#endif
> --
> 2.37.1
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 1/4] perf parse-events: Remove BPF event support
2023-10-19 19:45 ` Manu Bretelle
@ 2023-10-19 21:08 ` Arnaldo Carvalho de Melo
2023-10-19 21:57 ` Ian Rogers
2023-10-19 22:48 ` Manu Bretelle
0 siblings, 2 replies; 22+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-10-19 21:08 UTC (permalink / raw)
To: Manu Bretelle
Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
Nathan Chancellor, Nick Desaulniers, Tom Rix, Fangrui Song,
Anshuman Khandual, Andi Kleen, Leo Yan, Madhavan Srinivasan,
Carsten Haitzler, Ravi Bangoria, Naveen N. Rao, Athira Rajeev,
Kan Liang, Yang Jihong, James Clark, Tiezhu Yang,
Eduard Zingerman, Andrii Nakryiko, Yonghong Song, Rob Herring,
linux-kernel, linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo,
YueHaibing, He Kuang, Brendan Gregg, Quentin Monnet
Em Thu, Oct 19, 2023 at 12:45:08PM -0700, Manu Bretelle escreveu:
> cc @quentin
>
> On Fri, Aug 11, 2023 at 12:41:36PM -0300, Arnaldo Carvalho de Melo wrote:
> > Em Fri, Aug 11, 2023 at 11:43:22AM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Right now it is not applying due to some clash with other changes and
> > > when I tried to apply it manually there were some formatting issues:
> > >
> > > ⬢[acme@toolbox perf-tools-next]$ head ~/wb/1.patch
> > > From SRS0=EALy=D3=flex--irogers.bounces.google.com=3IDHVZAcKBAUnwtljwxlttlqj.htrfhrjpjwsjq.twl@kernel.org Thu Aug 10 17:53:46 2023
> > > Delivered-To: arnaldo.melo@gmail.com
> > > Received: from imap.gmail.com [64.233.186.109]
> > > by quaco with IMAP (fetchmail-6.4.37)
> > > for <acme@localhost> (single-drop); Thu, 10 Aug 2023 17:53:46 -0300 (-03)
> > > Received: by 2002:a0c:ab03:0:b0:63d:780e:9480 with SMTP id h3csp908198qvb;
> > > Thu, 10 Aug 2023 11:49:52 -0700 (PDT)
> > > X-Google-Smtp-Source: AGHT+IH9N/knUCyQ0tQ2Q0XBH0gqf8A8DB8/37YHWAJDKBmz7AGSV9CvCKYDuE3EwxriZFBwtZMs
> > > X-Received: by 2002:a4a:6b4f:0:b0:56c:b2ab:9820 with SMTP id
> > > h15-20020a4a6b4f000000b0056cb2ab9820mr2695332oof.8.1691693392493; Thu, 10 Aug
> > > ⬢[acme@toolbox perf-tools-next]$ patch -p1 < ~/wb/1.patch
> > > patching file tools/perf/Documentation/perf-config.txt
> > > patch: **** malformed patch at line 234: ith
> > >
> > > ⬢[acme@toolbox perf-tools-next]$
> > >
> > > I'm trying to apply it manually.
> >
> > I have this extracted from this patch as the first patch in the series:
> >
> > >From adc61b5774a9de62f34d593f164ca02daa6fb44c Mon Sep 17 00:00:00 2001
> > From: Ian Rogers <irogers@google.com>
> > Date: Fri, 11 Aug 2023 12:19:48 -0300
> > Subject: [PATCH 1/1] perf bpf: Remove support for embedding clang for
> > compiling BPF events (-e foo.c)
> >
> > This never was in the default build for perf, is difficult to maintain
> > as it uses clang/llvm internals so ditch it, keeping, for now, the
> > external compilation of .c BPF into .o bytecode and its subsequent
> > loading, that is also going to be removed, do it separately to help
> > bisection and to properly document what is being removed and why.
> >
> > Committer notes:
> >
> > Extracted from a larger patch and removed some leftovers, namely
> > deleting these now unused feature tests:
> >
> > tools/build/feature/test-clang.cpp
> > tools/build/feature/test-cxx.cpp
> > tools/build/feature/test-llvm-version.cpp
> > tools/build/feature/test-llvm.cpp
> >
>
> This seem to have broken `llvm` feature detection for `bpftool`.
>
> The feature detections are still available in `tools/build/Makefile.feature` [0]
> but the .cpp files are gone.
>
> `bpftool` still rely on the `llvm` feature:
>
> $ git --no-pager grep 'feature-llvm'
> tools/bpf/bpftool/Makefile:ifeq ($(feature-llvm),1)
>
> The result of testing llvm feature is:
>
> $ cat tools/build/feature/test-llvm.make.output
> cc1plus: fatal error: test-llvm.cpp: No such file or directory
> compilation terminated.
>
> With current head:
>
> make -j $((4*$(nproc))) -C tools/bpf/bpftool && ./tools/bpf/bpftool/bpftool --version
> ...
> Auto-detecting system features:
> ... clang-bpf-co-re: [ on ]
> ... llvm: [ OFF ]
> ... libcap: [ on ]
> ... libbfd: [ on ]
> ...
> ...
> ...
> bpftool v7.3.0
> using libbpf v1.3
> features: libbfd, skeletons
>
> After applying
>
> git show 56b11a2126bf2f422831ecf6112b87a4485b221b tools/build/feature | \
> patch -p1 -R
Ouch, so probably we need just to reintroduce that one
tools/build/feature/test-llvm.cpp file.
Building perf these days ends up using bpftool, and the end result as
noticed with me testing perf, perf trace with bpf, etc didn't change, so
I didn't notice :-\
And:
ifeq ($(feature-llvm),1)
# If LLVM is available, use it for JIT disassembly
CFLAGS += -DHAVE_LLVM_SUPPORT
LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler all-targets
CFLAGS += $(shell $(LLVM_CONFIG) --cflags --libs $(LLVM_CONFIG_LIB_COMPONENTS))
LIBS += $(shell $(LLVM_CONFIG) --libs $(LLVM_CONFIG_LIB_COMPONENTS))
ifeq ($(shell $(LLVM_CONFIG) --shared-mode),static)
LIBS += $(shell $(LLVM_CONFIG) --system-libs $(LLVM_CONFIG_LIB_COMPONENTS))
LIBS += -lstdc++
endif
LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags)
else
# Fall back on libbfd
ifeq ($(feature-libbfd),1)
LIBS += -lbfd -ldl -lopcodes
else ifeq ($(feature-libbfd-liberty),1)
LIBS += -lbfd -ldl -lopcodes -liberty
else ifeq ($(feature-libbfd-liberty-z),1)
LIBS += -lbfd -ldl -lopcodes -liberty -lz
endif
# If one of the above feature combinations is set, we support libbfd
ifneq ($(filter -lbfd,$(LIBS)),)
CFLAGS += -DHAVE_LIBBFD_SUPPORT
# Libbfd interface changed over time, figure out what we need
ifeq ($(feature-disassembler-four-args), 1)
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
endif
ifeq ($(feature-disassembler-init-styled), 1)
CFLAGS += -DDISASM_INIT_STYLED
endif
endif
endif
And there is a fallback to using binutils, so most people ended up not
noticing.
I wonder how to improve the current situation to detect these kinds of
problems in the future, i.e. how to notice that some file needed by some
Makefile, etc got removed or that some feature test fails because some
change in the test .c files makes them fail and thus activates fallbacks
like the one above :-\
So if I just get this back:
⬢[acme@toolbox perf-tools-next]$ cat tools/build/feature/test-llvm.cpp
// SPDX-License-Identifier: GPL-2.0
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/raw_ostream.h"
#define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH)
#if NUM_VERSION < 0x030900
# error "LLVM version too low"
#endif
int main()
{
llvm::errs() << "Hello World!\n";
llvm::llvm_shutdown();
return 0;
}
⬢[acme@toolbox perf-tools-next]$
And install the llvm-devel package then it back working:
⬢[acme@toolbox perf-tools-next]$ make -C tools/bpf/bpftool
make: Entering directory '/home/acme/git/perf-tools-next/tools/bpf/bpftool'
Auto-detecting system features:
... clang-bpf-co-re: [ on ]
... llvm: [ on ]
... libcap: [ on ]
... libbfd: [ on ]
<SNIP>
⬢[acme@toolbox perf-tools-next]$ cat tools/build/feature/test-llvm.make.output
⬢[acme@toolbox perf-tools-next]$ ls -la tools/build/feature/test-llvm.
test-llvm.bin test-llvm.cpp test-llvm.d test-llvm.make.output
⬢[acme@toolbox perf-tools-next]$ ls -la tools/build/feature/test-llvm.bin
-rwxr-xr-x. 1 acme acme 17712 Oct 19 18:04 tools/build/feature/test-llvm.bin
⬢[acme@toolbox perf-tools-next]$ ldd tools/build/feature/test-llvm.bin
linux-vdso.so.1 (0x00007ffcaf5d9000)
libLLVM-16.so => /lib64/libLLVM-16.so (0x00007fc4faefa000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fc4faca6000)
libm.so.6 => /lib64/libm.so.6 (0x00007fc4fabc5000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc4faba1000)
libc.so.6 => /lib64/libc.so.6 (0x00007fc4fa9c3000)
libffi.so.8 => /lib64/libffi.so.8 (0x00007fc4fa9b7000)
libedit.so.0 => /lib64/libedit.so.0 (0x00007fc4fa978000)
libz.so.1 => /lib64/libz.so.1 (0x00007fc4fa95e000)
libtinfo.so.6 => /lib64/libtinfo.so.6 (0x00007fc4fa92b000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc502404000)
⬢[acme@toolbox perf-tools-next]$ sudo dnf install llvm-devel
I'll get this merged in my perf-tools-fixes-for-v6.6 that I'll submit
tomorrow to Linus, thanks for reporting!
I'll add your:
Reported-by: Manu Bretelle <chantr4@gmail.com>
And:
Fixes: 56b11a2126bf2f42 ("perf bpf: Remove support for embedding clang for compiling BPF events (-e foo.c)")
Ok?
- Arnaldo
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 1/4] perf parse-events: Remove BPF event support
2023-10-19 21:08 ` Arnaldo Carvalho de Melo
@ 2023-10-19 21:57 ` Ian Rogers
2023-10-19 22:48 ` Manu Bretelle
1 sibling, 0 replies; 22+ messages in thread
From: Ian Rogers @ 2023-10-19 21:57 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Manu Bretelle, Peter Zijlstra, Ingo Molnar, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
Nathan Chancellor, Nick Desaulniers, Tom Rix, Fangrui Song,
Anshuman Khandual, Andi Kleen, Leo Yan, Madhavan Srinivasan,
Carsten Haitzler, Ravi Bangoria, Naveen N. Rao, Athira Rajeev,
Kan Liang, Yang Jihong, James Clark, Tiezhu Yang,
Eduard Zingerman, Andrii Nakryiko, Yonghong Song, Rob Herring,
linux-kernel, linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo,
YueHaibing, He Kuang, Brendan Gregg, Quentin Monnet
On Thu, Oct 19, 2023 at 2:08 PM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> Em Thu, Oct 19, 2023 at 12:45:08PM -0700, Manu Bretelle escreveu:
> > cc @quentin
> >
> > On Fri, Aug 11, 2023 at 12:41:36PM -0300, Arnaldo Carvalho de Melo wrote:
> > > Em Fri, Aug 11, 2023 at 11:43:22AM -0300, Arnaldo Carvalho de Melo escreveu:
> > > > Right now it is not applying due to some clash with other changes and
> > > > when I tried to apply it manually there were some formatting issues:
> > > >
> > > > ⬢[acme@toolbox perf-tools-next]$ head ~/wb/1.patch
> > > > From SRS0=EALy=D3=flex--irogers.bounces.google.com=3IDHVZAcKBAUnwtljwxlttlqj.htrfhrjpjwsjq.twl@kernel.org Thu Aug 10 17:53:46 2023
> > > > Delivered-To: arnaldo.melo@gmail.com
> > > > Received: from imap.gmail.com [64.233.186.109]
> > > > by quaco with IMAP (fetchmail-6.4.37)
> > > > for <acme@localhost> (single-drop); Thu, 10 Aug 2023 17:53:46 -0300 (-03)
> > > > Received: by 2002:a0c:ab03:0:b0:63d:780e:9480 with SMTP id h3csp908198qvb;
> > > > Thu, 10 Aug 2023 11:49:52 -0700 (PDT)
> > > > X-Google-Smtp-Source: AGHT+IH9N/knUCyQ0tQ2Q0XBH0gqf8A8DB8/37YHWAJDKBmz7AGSV9CvCKYDuE3EwxriZFBwtZMs
> > > > X-Received: by 2002:a4a:6b4f:0:b0:56c:b2ab:9820 with SMTP id
> > > > h15-20020a4a6b4f000000b0056cb2ab9820mr2695332oof.8.1691693392493; Thu, 10 Aug
> > > > ⬢[acme@toolbox perf-tools-next]$ patch -p1 < ~/wb/1.patch
> > > > patching file tools/perf/Documentation/perf-config.txt
> > > > patch: **** malformed patch at line 234: ith
> > > >
> > > > ⬢[acme@toolbox perf-tools-next]$
> > > >
> > > > I'm trying to apply it manually.
> > >
> > > I have this extracted from this patch as the first patch in the series:
> > >
> > > >From adc61b5774a9de62f34d593f164ca02daa6fb44c Mon Sep 17 00:00:00 2001
> > > From: Ian Rogers <irogers@google.com>
> > > Date: Fri, 11 Aug 2023 12:19:48 -0300
> > > Subject: [PATCH 1/1] perf bpf: Remove support for embedding clang for
> > > compiling BPF events (-e foo.c)
> > >
> > > This never was in the default build for perf, is difficult to maintain
> > > as it uses clang/llvm internals so ditch it, keeping, for now, the
> > > external compilation of .c BPF into .o bytecode and its subsequent
> > > loading, that is also going to be removed, do it separately to help
> > > bisection and to properly document what is being removed and why.
> > >
> > > Committer notes:
> > >
> > > Extracted from a larger patch and removed some leftovers, namely
> > > deleting these now unused feature tests:
> > >
> > > tools/build/feature/test-clang.cpp
> > > tools/build/feature/test-cxx.cpp
> > > tools/build/feature/test-llvm-version.cpp
> > > tools/build/feature/test-llvm.cpp
> > >
> >
> > This seem to have broken `llvm` feature detection for `bpftool`.
> >
> > The feature detections are still available in `tools/build/Makefile.feature` [0]
> > but the .cpp files are gone.
> >
> > `bpftool` still rely on the `llvm` feature:
> >
> > $ git --no-pager grep 'feature-llvm'
> > tools/bpf/bpftool/Makefile:ifeq ($(feature-llvm),1)
> >
> > The result of testing llvm feature is:
> >
> > $ cat tools/build/feature/test-llvm.make.output
> > cc1plus: fatal error: test-llvm.cpp: No such file or directory
> > compilation terminated.
> >
> > With current head:
> >
> > make -j $((4*$(nproc))) -C tools/bpf/bpftool && ./tools/bpf/bpftool/bpftool --version
> > ...
> > Auto-detecting system features:
> > ... clang-bpf-co-re: [ on ]
> > ... llvm: [ OFF ]
> > ... libcap: [ on ]
> > ... libbfd: [ on ]
> > ...
> > ...
> > ...
> > bpftool v7.3.0
> > using libbpf v1.3
> > features: libbfd, skeletons
> >
> > After applying
> >
> > git show 56b11a2126bf2f422831ecf6112b87a4485b221b tools/build/feature | \
> > patch -p1 -R
>
>
> Ouch, so probably we need just to reintroduce that one
> tools/build/feature/test-llvm.cpp file.
>
> Building perf these days ends up using bpftool, and the end result as
> noticed with me testing perf, perf trace with bpf, etc didn't change, so
> I didn't notice :-\
>
> And:
>
> ifeq ($(feature-llvm),1)
> # If LLVM is available, use it for JIT disassembly
> CFLAGS += -DHAVE_LLVM_SUPPORT
> LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler all-targets
> CFLAGS += $(shell $(LLVM_CONFIG) --cflags --libs $(LLVM_CONFIG_LIB_COMPONENTS))
> LIBS += $(shell $(LLVM_CONFIG) --libs $(LLVM_CONFIG_LIB_COMPONENTS))
> ifeq ($(shell $(LLVM_CONFIG) --shared-mode),static)
> LIBS += $(shell $(LLVM_CONFIG) --system-libs $(LLVM_CONFIG_LIB_COMPONENTS))
> LIBS += -lstdc++
> endif
> LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags)
> else
> # Fall back on libbfd
> ifeq ($(feature-libbfd),1)
> LIBS += -lbfd -ldl -lopcodes
> else ifeq ($(feature-libbfd-liberty),1)
> LIBS += -lbfd -ldl -lopcodes -liberty
> else ifeq ($(feature-libbfd-liberty-z),1)
> LIBS += -lbfd -ldl -lopcodes -liberty -lz
> endif
>
> # If one of the above feature combinations is set, we support libbfd
> ifneq ($(filter -lbfd,$(LIBS)),)
> CFLAGS += -DHAVE_LIBBFD_SUPPORT
>
> # Libbfd interface changed over time, figure out what we need
> ifeq ($(feature-disassembler-four-args), 1)
> CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
> endif
> ifeq ($(feature-disassembler-init-styled), 1)
> CFLAGS += -DDISASM_INIT_STYLED
> endif
> endif
> endif
>
> And there is a fallback to using binutils, so most people ended up not
> noticing.
>
> I wonder how to improve the current situation to detect these kinds of
> problems in the future, i.e. how to notice that some file needed by some
> Makefile, etc got removed or that some feature test fails because some
> change in the test .c files makes them fail and thus activates fallbacks
> like the one above :-\
>
>
> So if I just get this back:
>
> ⬢[acme@toolbox perf-tools-next]$ cat tools/build/feature/test-llvm.cpp
> // SPDX-License-Identifier: GPL-2.0
> #include "llvm/Support/ManagedStatic.h"
> #include "llvm/Support/raw_ostream.h"
> #define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH)
>
> #if NUM_VERSION < 0x030900
> # error "LLVM version too low"
> #endif
> int main()
> {
> llvm::errs() << "Hello World!\n";
> llvm::llvm_shutdown();
> return 0;
> }
> ⬢[acme@toolbox perf-tools-next]$
>
> And install the llvm-devel package then it back working:
>
> ⬢[acme@toolbox perf-tools-next]$ make -C tools/bpf/bpftool
> make: Entering directory '/home/acme/git/perf-tools-next/tools/bpf/bpftool'
>
> Auto-detecting system features:
> ... clang-bpf-co-re: [ on ]
> ... llvm: [ on ]
> ... libcap: [ on ]
> ... libbfd: [ on ]
> <SNIP>
> ⬢[acme@toolbox perf-tools-next]$ cat tools/build/feature/test-llvm.make.output
> ⬢[acme@toolbox perf-tools-next]$ ls -la tools/build/feature/test-llvm.
> test-llvm.bin test-llvm.cpp test-llvm.d test-llvm.make.output
> ⬢[acme@toolbox perf-tools-next]$ ls -la tools/build/feature/test-llvm.bin
> -rwxr-xr-x. 1 acme acme 17712 Oct 19 18:04 tools/build/feature/test-llvm.bin
> ⬢[acme@toolbox perf-tools-next]$ ldd tools/build/feature/test-llvm.bin
> linux-vdso.so.1 (0x00007ffcaf5d9000)
> libLLVM-16.so => /lib64/libLLVM-16.so (0x00007fc4faefa000)
> libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fc4faca6000)
> libm.so.6 => /lib64/libm.so.6 (0x00007fc4fabc5000)
> libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc4faba1000)
> libc.so.6 => /lib64/libc.so.6 (0x00007fc4fa9c3000)
> libffi.so.8 => /lib64/libffi.so.8 (0x00007fc4fa9b7000)
> libedit.so.0 => /lib64/libedit.so.0 (0x00007fc4fa978000)
> libz.so.1 => /lib64/libz.so.1 (0x00007fc4fa95e000)
> libtinfo.so.6 => /lib64/libtinfo.so.6 (0x00007fc4fa92b000)
> /lib64/ld-linux-x86-64.so.2 (0x00007fc502404000)
> ⬢[acme@toolbox perf-tools-next]$ sudo dnf install llvm-devel
>
> I'll get this merged in my perf-tools-fixes-for-v6.6 that I'll submit
> tomorrow to Linus, thanks for reporting!
>
> I'll add your:
>
> Reported-by: Manu Bretelle <chantr4@gmail.com>
>
> And:
>
> Fixes: 56b11a2126bf2f42 ("perf bpf: Remove support for embedding clang for compiling BPF events (-e foo.c)")
>
> Ok?
Reviewed-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> - Arnaldo
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 1/4] perf parse-events: Remove BPF event support
2023-10-19 21:08 ` Arnaldo Carvalho de Melo
2023-10-19 21:57 ` Ian Rogers
@ 2023-10-19 22:48 ` Manu Bretelle
2023-10-20 20:39 ` Arnaldo Carvalho de Melo
1 sibling, 1 reply; 22+ messages in thread
From: Manu Bretelle @ 2023-10-19 22:48 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
Nathan Chancellor, Nick Desaulniers, Tom Rix, Fangrui Song,
Anshuman Khandual, Andi Kleen, Leo Yan, Madhavan Srinivasan,
Carsten Haitzler, Ravi Bangoria, Naveen N. Rao, Athira Rajeev,
Kan Liang, Yang Jihong, James Clark, Tiezhu Yang,
Eduard Zingerman, Andrii Nakryiko, Yonghong Song, Rob Herring,
linux-kernel, linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo,
YueHaibing, He Kuang, Brendan Gregg, Quentin Monnet
On Thu, Oct 19, 2023 at 06:08:33PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Oct 19, 2023 at 12:45:08PM -0700, Manu Bretelle escreveu:
> > cc @quentin
> >
> > On Fri, Aug 11, 2023 at 12:41:36PM -0300, Arnaldo Carvalho de Melo wrote:
> > > Em Fri, Aug 11, 2023 at 11:43:22AM -0300, Arnaldo Carvalho de Melo escreveu:
> > > > Right now it is not applying due to some clash with other changes and
> > > > when I tried to apply it manually there were some formatting issues:
> > > >
> > > > ⬢[acme@toolbox perf-tools-next]$ head ~/wb/1.patch
> > > > From SRS0=EALy=D3=flex--irogers.bounces.google.com=3IDHVZAcKBAUnwtljwxlttlqj.htrfhrjpjwsjq.twl@kernel.org Thu Aug 10 17:53:46 2023
> > > > Delivered-To: arnaldo.melo@gmail.com
> > > > Received: from imap.gmail.com [64.233.186.109]
> > > > by quaco with IMAP (fetchmail-6.4.37)
> > > > for <acme@localhost> (single-drop); Thu, 10 Aug 2023 17:53:46 -0300 (-03)
> > > > Received: by 2002:a0c:ab03:0:b0:63d:780e:9480 with SMTP id h3csp908198qvb;
> > > > Thu, 10 Aug 2023 11:49:52 -0700 (PDT)
> > > > X-Google-Smtp-Source: AGHT+IH9N/knUCyQ0tQ2Q0XBH0gqf8A8DB8/37YHWAJDKBmz7AGSV9CvCKYDuE3EwxriZFBwtZMs
> > > > X-Received: by 2002:a4a:6b4f:0:b0:56c:b2ab:9820 with SMTP id
> > > > h15-20020a4a6b4f000000b0056cb2ab9820mr2695332oof.8.1691693392493; Thu, 10 Aug
> > > > ⬢[acme@toolbox perf-tools-next]$ patch -p1 < ~/wb/1.patch
> > > > patching file tools/perf/Documentation/perf-config.txt
> > > > patch: **** malformed patch at line 234: ith
> > > >
> > > > ⬢[acme@toolbox perf-tools-next]$
> > > >
> > > > I'm trying to apply it manually.
> > >
> > > I have this extracted from this patch as the first patch in the series:
> > >
> > > >From adc61b5774a9de62f34d593f164ca02daa6fb44c Mon Sep 17 00:00:00 2001
> > > From: Ian Rogers <irogers@google.com>
> > > Date: Fri, 11 Aug 2023 12:19:48 -0300
> > > Subject: [PATCH 1/1] perf bpf: Remove support for embedding clang for
> > > compiling BPF events (-e foo.c)
> > >
> > > This never was in the default build for perf, is difficult to maintain
> > > as it uses clang/llvm internals so ditch it, keeping, for now, the
> > > external compilation of .c BPF into .o bytecode and its subsequent
> > > loading, that is also going to be removed, do it separately to help
> > > bisection and to properly document what is being removed and why.
> > >
> > > Committer notes:
> > >
> > > Extracted from a larger patch and removed some leftovers, namely
> > > deleting these now unused feature tests:
> > >
> > > tools/build/feature/test-clang.cpp
> > > tools/build/feature/test-cxx.cpp
> > > tools/build/feature/test-llvm-version.cpp
> > > tools/build/feature/test-llvm.cpp
> > >
> >
> > This seem to have broken `llvm` feature detection for `bpftool`.
> >
> > The feature detections are still available in `tools/build/Makefile.feature` [0]
> > but the .cpp files are gone.
> >
> > `bpftool` still rely on the `llvm` feature:
> >
> > $ git --no-pager grep 'feature-llvm'
> > tools/bpf/bpftool/Makefile:ifeq ($(feature-llvm),1)
> >
> > The result of testing llvm feature is:
> >
> > $ cat tools/build/feature/test-llvm.make.output
> > cc1plus: fatal error: test-llvm.cpp: No such file or directory
> > compilation terminated.
> >
> > With current head:
> >
> > make -j $((4*$(nproc))) -C tools/bpf/bpftool && ./tools/bpf/bpftool/bpftool --version
> > ...
> > Auto-detecting system features:
> > ... clang-bpf-co-re: [ on ]
> > ... llvm: [ OFF ]
> > ... libcap: [ on ]
> > ... libbfd: [ on ]
> > ...
> > ...
> > ...
> > bpftool v7.3.0
> > using libbpf v1.3
> > features: libbfd, skeletons
> >
> > After applying
> >
> > git show 56b11a2126bf2f422831ecf6112b87a4485b221b tools/build/feature | \
> > patch -p1 -R
>
>
> Ouch, so probably we need just to reintroduce that one
> tools/build/feature/test-llvm.cpp file.
Yes, I believe so. From git-grepping `feature-<feature>`, only `feature-llvm` came up.
I suppose as part of the cleanup the features should have been
removed from tools/build/Makefile.feature too.
>
> Building perf these days ends up using bpftool, and the end result as
> noticed with me testing perf, perf trace with bpf, etc didn't change, so
> I didn't notice :-\
>
> And:
>
> ifeq ($(feature-llvm),1)
> # If LLVM is available, use it for JIT disassembly
> CFLAGS += -DHAVE_LLVM_SUPPORT
> LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler all-targets
> CFLAGS += $(shell $(LLVM_CONFIG) --cflags --libs $(LLVM_CONFIG_LIB_COMPONENTS))
> LIBS += $(shell $(LLVM_CONFIG) --libs $(LLVM_CONFIG_LIB_COMPONENTS))
> ifeq ($(shell $(LLVM_CONFIG) --shared-mode),static)
> LIBS += $(shell $(LLVM_CONFIG) --system-libs $(LLVM_CONFIG_LIB_COMPONENTS))
> LIBS += -lstdc++
> endif
> LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags)
> else
> # Fall back on libbfd
> ifeq ($(feature-libbfd),1)
> LIBS += -lbfd -ldl -lopcodes
> else ifeq ($(feature-libbfd-liberty),1)
> LIBS += -lbfd -ldl -lopcodes -liberty
> else ifeq ($(feature-libbfd-liberty-z),1)
> LIBS += -lbfd -ldl -lopcodes -liberty -lz
> endif
>
> # If one of the above feature combinations is set, we support libbfd
> ifneq ($(filter -lbfd,$(LIBS)),)
> CFLAGS += -DHAVE_LIBBFD_SUPPORT
>
> # Libbfd interface changed over time, figure out what we need
> ifeq ($(feature-disassembler-four-args), 1)
> CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
> endif
> ifeq ($(feature-disassembler-init-styled), 1)
> CFLAGS += -DDISASM_INIT_STYLED
> endif
> endif
> endif
>
> And there is a fallback to using binutils, so most people ended up not
> noticing.
Yes, definitely, the fallback make it harder to easily detect.
I detected it because I was manually building bpftool and it was odd that llvm
was not detected.
>
> I wonder how to improve the current situation to detect these kinds of
> problems in the future, i.e. how to notice that some file needed by some
> Makefile, etc got removed or that some feature test fails because some
> change in the test .c files makes them fail and thus activates fallbacks
> like the one above :-\
I think it is tricky. Specifically to this situation, some CI could try to build
the different combinaison of bpftool and check the features through the build
`bpftool --version`.
This is actually a test that I run internally to make sure our build has some
feature enabled.
This is actually tested by bpftool in the GH CI:
https://github.com/libbpf/bpftool/blob/main/.github/workflows/build.yaml#L62
As a matter of fact, it would not have been detected because that CI uses a
different Makefile.feature.
Quentin and I were talking offline how we could improve bpftool CI at diff time.
This is an example where it would have helped :)
>
>
> So if I just get this back:
>
> ⬢[acme@toolbox perf-tools-next]$ cat tools/build/feature/test-llvm.cpp
> // SPDX-License-Identifier: GPL-2.0
> #include "llvm/Support/ManagedStatic.h"
> #include "llvm/Support/raw_ostream.h"
> #define NUM_VERSION (((LLVM_VERSION_MAJOR) << 16) + (LLVM_VERSION_MINOR << 8) + LLVM_VERSION_PATCH)
>
> #if NUM_VERSION < 0x030900
> # error "LLVM version too low"
> #endif
> int main()
> {
> llvm::errs() << "Hello World!\n";
> llvm::llvm_shutdown();
> return 0;
> }
> ⬢[acme@toolbox perf-tools-next]$
>
> And install the llvm-devel package then it back working:
>
> ⬢[acme@toolbox perf-tools-next]$ make -C tools/bpf/bpftool
> make: Entering directory '/home/acme/git/perf-tools-next/tools/bpf/bpftool'
>
> Auto-detecting system features:
> ... clang-bpf-co-re: [ on ]
> ... llvm: [ on ]
> ... libcap: [ on ]
> ... libbfd: [ on ]
> <SNIP>
> ⬢[acme@toolbox perf-tools-next]$ cat tools/build/feature/test-llvm.make.output
> ⬢[acme@toolbox perf-tools-next]$ ls -la tools/build/feature/test-llvm.
> test-llvm.bin test-llvm.cpp test-llvm.d test-llvm.make.output
> ⬢[acme@toolbox perf-tools-next]$ ls -la tools/build/feature/test-llvm.bin
> -rwxr-xr-x. 1 acme acme 17712 Oct 19 18:04 tools/build/feature/test-llvm.bin
> ⬢[acme@toolbox perf-tools-next]$ ldd tools/build/feature/test-llvm.bin
> linux-vdso.so.1 (0x00007ffcaf5d9000)
> libLLVM-16.so => /lib64/libLLVM-16.so (0x00007fc4faefa000)
> libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fc4faca6000)
> libm.so.6 => /lib64/libm.so.6 (0x00007fc4fabc5000)
> libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc4faba1000)
> libc.so.6 => /lib64/libc.so.6 (0x00007fc4fa9c3000)
> libffi.so.8 => /lib64/libffi.so.8 (0x00007fc4fa9b7000)
> libedit.so.0 => /lib64/libedit.so.0 (0x00007fc4fa978000)
> libz.so.1 => /lib64/libz.so.1 (0x00007fc4fa95e000)
> libtinfo.so.6 => /lib64/libtinfo.so.6 (0x00007fc4fa92b000)
> /lib64/ld-linux-x86-64.so.2 (0x00007fc502404000)
> ⬢[acme@toolbox perf-tools-next]$ sudo dnf install llvm-devel
>
> I'll get this merged in my perf-tools-fixes-for-v6.6 that I'll submit
> tomorrow to Linus, thanks for reporting!
>
> I'll add your:
>
> Reported-by: Manu Bretelle <chantr4@gmail.com>
>
> And:
>
> Fixes: 56b11a2126bf2f42 ("perf bpf: Remove support for embedding clang for compiling BPF events (-e foo.c)")
>
> Ok?
SGTM. Thanks for the quick turnaround.
Reviewed-by: Manu Bretelle <chantr4@gmail.com>
>
> - Arnaldo
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 1/4] perf parse-events: Remove BPF event support
2023-10-19 22:48 ` Manu Bretelle
@ 2023-10-20 20:39 ` Arnaldo Carvalho de Melo
2023-10-20 22:37 ` Manu Bretelle
0 siblings, 1 reply; 22+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-10-20 20:39 UTC (permalink / raw)
To: Manu Bretelle
Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
Nathan Chancellor, Nick Desaulniers, Tom Rix, Fangrui Song,
Anshuman Khandual, Andi Kleen, Leo Yan, Madhavan Srinivasan,
Carsten Haitzler, Ravi Bangoria, Naveen N. Rao, Athira Rajeev,
Kan Liang, Yang Jihong, James Clark, Tiezhu Yang,
Eduard Zingerman, Andrii Nakryiko, Yonghong Song, Rob Herring,
linux-kernel, linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo,
YueHaibing, He Kuang, Brendan Gregg, Quentin Monnet
Em Thu, Oct 19, 2023 at 03:48:56PM -0700, Manu Bretelle escreveu:
> On Thu, Oct 19, 2023 at 06:08:33PM -0300, Arnaldo Carvalho de Melo wrote:
> > I wonder how to improve the current situation to detect these kinds of
> > problems in the future, i.e. how to notice that some file needed by some
> > Makefile, etc got removed or that some feature test fails because some
> > change in the test .c files makes them fail and thus activates fallbacks
> > like the one above :-\
> I think it is tricky. Specifically to this situation, some CI could try to build
> the different combinaison of bpftool and check the features through the build
> `bpftool --version`.
Right, if the right packages are installed, we expect to get some
bpftool build output, if that changes after some patch, flag it.
Does bpftool have something like:
⬢[acme@toolbox perf-tools-next]$ perf version --build-options
perf version 6.6.rc1.ga8dd62d05e56
dwarf: [ on ] # HAVE_DWARF_SUPPORT
dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS_SUPPORT
syscall_table: [ on ] # HAVE_SYSCALL_TABLE_SUPPORT
libbfd: [ OFF ] # HAVE_LIBBFD_SUPPORT
debuginfod: [ on ] # HAVE_DEBUGINFOD_SUPPORT
libelf: [ on ] # HAVE_LIBELF_SUPPORT
libnuma: [ on ] # HAVE_LIBNUMA_SUPPORT
numa_num_possible_cpus: [ on ] # HAVE_LIBNUMA_SUPPORT
libperl: [ on ] # HAVE_LIBPERL_SUPPORT
libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
libslang: [ on ] # HAVE_SLANG_SUPPORT
libcrypto: [ on ] # HAVE_LIBCRYPTO_SUPPORT
libunwind: [ on ] # HAVE_LIBUNWIND_SUPPORT
libdw-dwarf-unwind: [ on ] # HAVE_DWARF_SUPPORT
zlib: [ on ] # HAVE_ZLIB_SUPPORT
lzma: [ on ] # HAVE_LZMA_SUPPORT
get_cpuid: [ on ] # HAVE_AUXTRACE_SUPPORT
bpf: [ on ] # HAVE_LIBBPF_SUPPORT
aio: [ on ] # HAVE_AIO_SUPPORT
zstd: [ on ] # HAVE_ZSTD_SUPPORT
libpfm4: [ on ] # HAVE_LIBPFM
libtraceevent: [ on ] # HAVE_LIBTRACEEVENT
bpf_skeletons: [ on ] # HAVE_BPF_SKEL
⬢[acme@toolbox perf-tools-next]$
?
> This is actually a test that I run internally to make sure our build has some
> feature enabled.
> This is actually tested by bpftool in the GH CI:
> https://github.com/libbpf/bpftool/blob/main/.github/workflows/build.yaml#L62
> As a matter of fact, it would not have been detected because that CI uses a
> different Makefile.feature.
> Quentin and I were talking offline how we could improve bpftool CI at diff time.
> This is an example where it would have helped :)
>
> > I'll get this merged in my perf-tools-fixes-for-v6.6 that I'll submit
> > tomorrow to Linus, thanks for reporting!
> >
> > I'll add your:
> >
> > Reported-by: Manu Bretelle <chantr4@gmail.com>
> >
> > And:
> >
> > Fixes: 56b11a2126bf2f42 ("perf bpf: Remove support for embedding clang for compiling BPF events (-e foo.c)")
> >
> > Ok?
> SGTM. Thanks for the quick turnaround.
> Reviewed-by: Manu Bretelle <chantr4@gmail.com>
You're welcome, thanks for the detailed report, the patch was just sent
to Linus.
- Arnaldo
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 1/4] perf parse-events: Remove BPF event support
2023-10-20 20:39 ` Arnaldo Carvalho de Melo
@ 2023-10-20 22:37 ` Manu Bretelle
2023-10-23 9:01 ` Quentin Monnet
0 siblings, 1 reply; 22+ messages in thread
From: Manu Bretelle @ 2023-10-20 22:37 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
Nathan Chancellor, Nick Desaulniers, Tom Rix, Fangrui Song,
Anshuman Khandual, Andi Kleen, Leo Yan, Madhavan Srinivasan,
Carsten Haitzler, Ravi Bangoria, Naveen N. Rao, Athira Rajeev,
Kan Liang, Yang Jihong, James Clark, Tiezhu Yang,
Eduard Zingerman, Andrii Nakryiko, Yonghong Song, Rob Herring,
linux-kernel, linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo,
YueHaibing, He Kuang, Brendan Gregg, Quentin Monnet
On Fri, Oct 20, 2023 at 05:39:25PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Thu, Oct 19, 2023 at 03:48:56PM -0700, Manu Bretelle escreveu:
> > On Thu, Oct 19, 2023 at 06:08:33PM -0300, Arnaldo Carvalho de Melo wrote:
> > > I wonder how to improve the current situation to detect these kinds of
> > > problems in the future, i.e. how to notice that some file needed by some
> > > Makefile, etc got removed or that some feature test fails because some
> > > change in the test .c files makes them fail and thus activates fallbacks
> > > like the one above :-\
>
> > I think it is tricky. Specifically to this situation, some CI could try to build
> > the different combinaison of bpftool and check the features through the build
> > `bpftool --version`.
>
> Right, if the right packages are installed, we expect to get some
> bpftool build output, if that changes after some patch, flag it.
>
> Does bpftool have something like:
>
> ⬢[acme@toolbox perf-tools-next]$ perf version --build-options
> perf version 6.6.rc1.ga8dd62d05e56
> dwarf: [ on ] # HAVE_DWARF_SUPPORT
> dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS_SUPPORT
> syscall_table: [ on ] # HAVE_SYSCALL_TABLE_SUPPORT
> libbfd: [ OFF ] # HAVE_LIBBFD_SUPPORT
> debuginfod: [ on ] # HAVE_DEBUGINFOD_SUPPORT
> libelf: [ on ] # HAVE_LIBELF_SUPPORT
> libnuma: [ on ] # HAVE_LIBNUMA_SUPPORT
> numa_num_possible_cpus: [ on ] # HAVE_LIBNUMA_SUPPORT
> libperl: [ on ] # HAVE_LIBPERL_SUPPORT
> libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
> libslang: [ on ] # HAVE_SLANG_SUPPORT
> libcrypto: [ on ] # HAVE_LIBCRYPTO_SUPPORT
> libunwind: [ on ] # HAVE_LIBUNWIND_SUPPORT
> libdw-dwarf-unwind: [ on ] # HAVE_DWARF_SUPPORT
> zlib: [ on ] # HAVE_ZLIB_SUPPORT
> lzma: [ on ] # HAVE_LZMA_SUPPORT
> get_cpuid: [ on ] # HAVE_AUXTRACE_SUPPORT
> bpf: [ on ] # HAVE_LIBBPF_SUPPORT
> aio: [ on ] # HAVE_AIO_SUPPORT
> zstd: [ on ] # HAVE_ZSTD_SUPPORT
> libpfm4: [ on ] # HAVE_LIBPFM
> libtraceevent: [ on ] # HAVE_LIBTRACEEVENT
> bpf_skeletons: [ on ] # HAVE_BPF_SKEL
> ⬢[acme@toolbox perf-tools-next]$
>
> ?
>
It has
$ ./tools/bpf/bpftool/bpftool --version -j | jq .features
{
"libbfd": false,
"llvm": true,
"skeletons": true,
"bootstrap": false
}
Maybe Quentin knows of something else.
> > This is actually a test that I run internally to make sure our build has some
> > feature enabled.
> > This is actually tested by bpftool in the GH CI:
> > https://github.com/libbpf/bpftool/blob/main/.github/workflows/build.yaml#L62
>
> > As a matter of fact, it would not have been detected because that CI uses a
> > different Makefile.feature.
>
> > Quentin and I were talking offline how we could improve bpftool CI at diff time.
> > This is an example where it would have helped :)
> >
> > > I'll get this merged in my perf-tools-fixes-for-v6.6 that I'll submit
> > > tomorrow to Linus, thanks for reporting!
> > >
> > > I'll add your:
> > >
> > > Reported-by: Manu Bretelle <chantr4@gmail.com>
> > >
> > > And:
> > >
> > > Fixes: 56b11a2126bf2f42 ("perf bpf: Remove support for embedding clang for compiling BPF events (-e foo.c)")
> > >
> > > Ok?
>
> > SGTM. Thanks for the quick turnaround.
>
> > Reviewed-by: Manu Bretelle <chantr4@gmail.com>
>
> You're welcome, thanks for the detailed report, the patch was just sent
> to Linus.
>
> - Arnaldo
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v1 1/4] perf parse-events: Remove BPF event support
2023-10-20 22:37 ` Manu Bretelle
@ 2023-10-23 9:01 ` Quentin Monnet
0 siblings, 0 replies; 22+ messages in thread
From: Quentin Monnet @ 2023-10-23 9:01 UTC (permalink / raw)
To: Manu Bretelle, Arnaldo Carvalho de Melo
Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Namhyung Kim, Adrian Hunter,
Nathan Chancellor, Nick Desaulniers, Tom Rix, Fangrui Song,
Anshuman Khandual, Andi Kleen, Leo Yan, Madhavan Srinivasan,
Carsten Haitzler, Ravi Bangoria, Naveen N. Rao, Athira Rajeev,
Kan Liang, Yang Jihong, James Clark, Tiezhu Yang,
Eduard Zingerman, Andrii Nakryiko, Yonghong Song, Rob Herring,
linux-kernel, linux-perf-users, bpf, llvm, Wang Nan, Wang ShaoBo,
YueHaibing, He Kuang, Brendan Gregg
On 20/10/2023 23:37, Manu Bretelle wrote:
> On Fri, Oct 20, 2023 at 05:39:25PM -0300, Arnaldo Carvalho de Melo wrote:
>> Em Thu, Oct 19, 2023 at 03:48:56PM -0700, Manu Bretelle escreveu:
>>> On Thu, Oct 19, 2023 at 06:08:33PM -0300, Arnaldo Carvalho de Melo wrote:
>>>> I wonder how to improve the current situation to detect these kinds of
>>>> problems in the future, i.e. how to notice that some file needed by some
>>>> Makefile, etc got removed or that some feature test fails because some
>>>> change in the test .c files makes them fail and thus activates fallbacks
>>>> like the one above :-\
>>
>>> I think it is tricky. Specifically to this situation, some CI could try to build
>>> the different combinaison of bpftool and check the features through the build
>>> `bpftool --version`.
>>
>> Right, if the right packages are installed, we expect to get some
>> bpftool build output, if that changes after some patch, flag it.
Correct, this is what we do on the CI on the GitHub mirror (checking
that the mirrored version builds correctly, with the expected features).
>>
>> Does bpftool have something like:
>>
>> ⬢[acme@toolbox perf-tools-next]$ perf version --build-options
>> perf version 6.6.rc1.ga8dd62d05e56
>> dwarf: [ on ] # HAVE_DWARF_SUPPORT
>> dwarf_getlocations: [ on ] # HAVE_DWARF_GETLOCATIONS_SUPPORT
>> syscall_table: [ on ] # HAVE_SYSCALL_TABLE_SUPPORT
>> libbfd: [ OFF ] # HAVE_LIBBFD_SUPPORT
>> debuginfod: [ on ] # HAVE_DEBUGINFOD_SUPPORT
>> libelf: [ on ] # HAVE_LIBELF_SUPPORT
>> libnuma: [ on ] # HAVE_LIBNUMA_SUPPORT
>> numa_num_possible_cpus: [ on ] # HAVE_LIBNUMA_SUPPORT
>> libperl: [ on ] # HAVE_LIBPERL_SUPPORT
>> libpython: [ on ] # HAVE_LIBPYTHON_SUPPORT
>> libslang: [ on ] # HAVE_SLANG_SUPPORT
>> libcrypto: [ on ] # HAVE_LIBCRYPTO_SUPPORT
>> libunwind: [ on ] # HAVE_LIBUNWIND_SUPPORT
>> libdw-dwarf-unwind: [ on ] # HAVE_DWARF_SUPPORT
>> zlib: [ on ] # HAVE_ZLIB_SUPPORT
>> lzma: [ on ] # HAVE_LZMA_SUPPORT
>> get_cpuid: [ on ] # HAVE_AUXTRACE_SUPPORT
>> bpf: [ on ] # HAVE_LIBBPF_SUPPORT
>> aio: [ on ] # HAVE_AIO_SUPPORT
>> zstd: [ on ] # HAVE_ZSTD_SUPPORT
>> libpfm4: [ on ] # HAVE_LIBPFM
>> libtraceevent: [ on ] # HAVE_LIBTRACEEVENT
>> bpf_skeletons: [ on ] # HAVE_BPF_SKEL
>> ⬢[acme@toolbox perf-tools-next]$
>>
>> ?
>>
>
> It has
>
> $ ./tools/bpf/bpftool/bpftool --version -j | jq .features
> {
> "libbfd": false,
> "llvm": true,
> "skeletons": true,
> "bootstrap": false
> }
>
>
> Maybe Quentin knows of something else.
This, or ldd on the binary (unless it was a static build). But "bpftool
version" should be enough to tell whether the LLVM disassembler is built
in or not, so we haven't needed something else so far.
Quentin
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2023-10-23 9:01 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-10 18:48 [PATCH v1 0/4] Remove BPF event support Ian Rogers
2023-08-10 18:48 ` [PATCH v1 2/4] perf trace: Migrate BPF augmentation to use a skeleton Ian Rogers
2023-08-11 16:09 ` Jiri Olsa
2023-08-11 16:24 ` Ian Rogers
2023-08-11 18:46 ` Arnaldo Carvalho de Melo
2023-08-15 14:25 ` Arnaldo Carvalho de Melo
[not found] ` <CAP-5=fURf+vv3TA4cRx1MiV3DDp=3wo0g5dBYH43DKtPhNZQsQ@mail.gmail.com>
2023-08-16 13:11 ` Arnaldo Carvalho de Melo
2023-08-16 13:22 ` Arnaldo Carvalho de Melo
2023-08-16 16:08 ` Arnaldo Carvalho de Melo
2023-08-16 17:14 ` Arnaldo Carvalho de Melo
2023-08-16 18:15 ` Ian Rogers
2023-08-10 18:48 ` [PATCH v1 3/4] perf bpf examples: With no BPF events remove examples Ian Rogers
2023-08-10 18:48 ` [PATCH v1 4/4] perf trace: Tidy comments Ian Rogers
[not found] ` <20230810184853.2860737-2-irogers@google.com>
[not found] ` <ZNZJCWi9MT/HZdQ/@kernel.org>
2023-08-11 15:41 ` [PATCH v1 1/4] perf parse-events: Remove BPF event support Arnaldo Carvalho de Melo
2023-10-19 19:45 ` Manu Bretelle
2023-10-19 21:08 ` Arnaldo Carvalho de Melo
2023-10-19 21:57 ` Ian Rogers
2023-10-19 22:48 ` Manu Bretelle
2023-10-20 20:39 ` Arnaldo Carvalho de Melo
2023-10-20 22:37 ` Manu Bretelle
2023-10-23 9:01 ` Quentin Monnet
2023-08-11 16:09 ` [PATCH v1 0/4] " Jiri Olsa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).