[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250718-perf_aux_pause_resume_bpf_rebase-v2-5-992557b8fb16@arm.com>
Date: Fri, 18 Jul 2025 16:25:39 +0100
From: Leo Yan <leo.yan@....com>
To: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Namhyung Kim <namhyung@...nel.org>, Jiri Olsa <jolsa@...nel.org>,
Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>,
KP Singh <kpsingh@...nel.org>, Matt Bobrowski <mattbobrowski@...gle.com>,
Song Liu <song@...nel.org>, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>, Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Eduard Zingerman <eddyz87@...il.com>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>,
Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>,
Steven Rostedt <rostedt@...dmis.org>,
Masami Hiramatsu <mhiramat@...nel.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
James Clark <james.clark@...aro.org>,
Suzuki K Poulose <suzuki.poulose@....com>,
Mike Leach <mike.leach@...aro.org>
Cc: linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
bpf@...r.kernel.org, linux-trace-kernel@...r.kernel.org,
Leo Yan <leo.yan@....com>
Subject: [PATCH PATCH v2 v2 5/6] perf record: Support AUX pause and resume
with BPF
This commit introduces an option "--bpf-aux-pause" for loading BPF
program to trigger AUX pause and resume.
After:
perf record -e cs_etm/aux-action=start-paused/ \
--bpf-aux-pause="kretprobe:p:__arm64_sys_openat,kprobe:r:__arm64_sys_openat,tp:r:sched:sched_switch" \
-a -- ls
perf record -e cs_etm/aux-action=start-paused/ \
--bpf-aux-pause="kretprobe:p:__arm64_sys_openat,kprobe:r:__arm64_sys_openat,tp:r:sched:sched_switch" \
--per-thread -- ls
Signed-off-by: Leo Yan <leo.yan@....com>
---
tools/perf/builtin-record.c | 20 +++++++++++++++++++-
tools/perf/util/evsel.c | 6 ++++++
tools/perf/util/record.h | 1 +
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 8059bce85a510b2dddc66f1b8b0013276840eddc..793609c0a59e8abcd248608f55e0af03a253138d 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -880,7 +880,12 @@ static int record__auxtrace_init(struct record *rec)
if (err)
return err;
- return auxtrace_parse_filters(rec->evlist);
+ err = auxtrace_parse_filters(rec->evlist);
+ if (err)
+ return err;
+
+ return auxtrace__prepare_bpf(rec->itr,
+ rec->opts.auxtrace_bpf_aux_pause_opts);
}
#else
@@ -2506,6 +2511,10 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
evlist__config(rec->evlist, opts, &callchain_param);
+ err = auxtrace__set_bpf_filter(rec->evlist, opts);
+ if (err)
+ goto out_free_threads;
+
/* Debug message used by test scripts */
pr_debug3("perf record opening and mmapping events\n");
if (record__open(rec) != 0) {
@@ -2579,6 +2588,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
if (record__start_threads(rec))
goto out_free_threads;
+ if (auxtrace__enable_bpf())
+ goto out_free_threads;
+
/*
* When perf is starting the traced process, all the events
* (apart from group members) have enable_on_exec=1 set,
@@ -2907,6 +2919,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
}
out_delete_session:
+ auxtrace__cleanup_bpf();
#ifdef HAVE_EVENTFD_SUPPORT
if (done_fd >= 0) {
fd = done_fd;
@@ -3629,6 +3642,11 @@ static struct option __record_options[] = {
OPT_CALLBACK(0, "off-cpu-thresh", &record.opts, "ms",
"Dump off-cpu samples if off-cpu time exceeds this threshold (in milliseconds). (Default: 500ms)",
record__parse_off_cpu_thresh),
+ OPT_STRING_OPTARG(0, "bpf-aux-pause", &record.opts.auxtrace_bpf_aux_pause_opts,
+ "{kprobe|kretprobe}:{p|r}:function_name\n"
+ "\t\t\t {uprobe|uretprobe}:{p|r}:executable:function_name\n"
+ "\t\t\t {tp|tracepoint}:{p|r}:category:tracepoint\n",
+ "Enable AUX pause with BPF backend", ""),
OPT_END()
};
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index d55482f094bf95ac7b5c5173c1341baeb0fa9c93..f240e48f41a3e7ca5ba81733efc58a25c5c829ba 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2650,6 +2650,12 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
bpf_counter__install_pe(evsel, idx, fd);
+ /* Update event info into BPF map for AUX trace */
+ if (auxtrace__update_bpf_map(evsel, idx, fd)) {
+ err = -EINVAL;
+ goto out_close;
+ }
+
if (unlikely(test_attr__enabled())) {
test_attr__open(&evsel->core.attr, pid, cpu,
fd, group_fd, evsel->open_flags);
diff --git a/tools/perf/util/record.h b/tools/perf/util/record.h
index ea3a6c4657eefb743dc3d54b0b791ea39117cc10..1b1c2ed7fcadae8b56408b3b1b154faef3996eb3 100644
--- a/tools/perf/util/record.h
+++ b/tools/perf/util/record.h
@@ -65,6 +65,7 @@ struct record_opts {
size_t auxtrace_snapshot_size;
const char *auxtrace_snapshot_opts;
const char *auxtrace_sample_opts;
+ const char *auxtrace_bpf_aux_pause_opts;
bool sample_transaction;
bool use_clockid;
clockid_t clockid;
--
2.34.1
Powered by blists - more mailing lists