[PATCH v2 07/13] perf evlist: Enable tool PMU events when starting a workload
From: Ian Rogers
Date: Thu Dec 03 2026 - 16:53:01 EST
Commit 0228a8013de2 ("perf stat: Start tool events when enable_on_exec
is used") enabled tool PMU events inside builtin-stat's
enable_counters() when target__enable_on_exec() is true. Move that
enablement into evlist__start_workload() right before uncorking the
workload pipe so that:
1. Tool events start right as the workload is uncorked to exec rather
than earlier in enable_counters(), and for all callers of
evlist__start_workload(), not only perf stat.
2. Non-leader tool events in a group whose leader has enable_on_exec
set (such as '{user_time,system_time}') are also enabled.
Fixes: 0b18bced5444 ("perf tool_pmu: Make tool PMU events respect enable/disable")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/builtin-stat.c | 13 -------------
tools/perf/util/evlist.c | 17 +++++++++++++++++
2 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index e68168ad67f0..a470e2c0f392 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -510,19 +510,6 @@ static int enable_counters(void)
if (!target__enable_on_exec(&target)) {
if (!all_counters_use_bpf)
evlist__enable(evsel_list);
- } else {
- /*
- * Tool events are emulated in perf, so enable_on_exec above
- * does not start them. Start them here rather than through
- * evsel__enable(), which also walks the members of a mixed
- * PMU group; those are not opened here and their core.fd can
- * be NULL.
- */
- evlist__for_each_entry(evsel_list, evsel) {
- if (evsel__is_tool(evsel) && evsel->supported &&
- !evsel__tool_pmu_enable(evsel))
- evsel->disabled = false;
- }
}
return 0;
}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c2402e4791b6..d8aab032b4d8 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -69,6 +69,7 @@
#include "string2.h"
#include "target.h"
#include "thread_map.h"
+#include "tool_pmu.h"
#include "units.h"
#include "util.h"
@@ -1909,6 +1910,22 @@ int evlist__start_workload(struct evlist *evlist)
if (evlist__workload_cork_fd(evlist) >= 0) {
char bf = 0;
int ret;
+ struct evsel *pos;
+
+ /*
+ * Tool PMU events aren't opened with perf_event_open and so
+ * aren't enabled by the kernel on exec. Enable them directly
+ * (without walking group members that the kernel enables on
+ * exec) as the workload is started.
+ */
+ evlist__for_each_entry(evlist, pos) {
+ if (evsel__is_tool(pos) &&
+ (pos->core.attr.enable_on_exec ||
+ evsel__leader(pos)->core.attr.enable_on_exec) &&
+ pos->core.fd && pos->supported &&
+ !evsel__tool_pmu_enable(pos))
+ pos->disabled = false;
+ }
/*
* Remove the cork, let it rip!
*/
--
2.56.1.915.g69d5ec7298-goog