* [PATCH v2] perf stat: Count kernel events in a group led by a tool event
@ 2026-11-11 6:04 Hang Zhengyang via B4 Relay
2026-11-11 6:18 ` sashiko-bot
2026-11-11 11:06 ` [PATCH v3] " TAKANO Mitsuhiro
0 siblings, 2 replies; 10+ messages in thread
From: Hang Zhengyang via B4 Relay @ 2026-11-11 6:04 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, James Clark
Cc: linux-perf-users, linux-kernel, TAKANO Mitsuhiro, Hang Zhengyang
From: Hang Zhengyang <hang.zhengyang1010@gmail.com>
A tool event like user_time has no perf event in the kernel, but
get_group_fd() still passes its fd, the /proc/stat fd, as the group_fd
of the members. The kernel rejects each member with EBADF and nothing
is counted:
$ perf stat -a -e '{user_time,cycles,instructions}' -- sleep 0.05
0 user_time
<not supported> cycles
<not supported> instructions
Open the members with group_fd = -1, as the enable/disable code already
assumes. They are then on their own, so read them without
PERF_FORMAT_GROUP and open them disabled like a leader, so that -D,
--control and enable_on_exec still apply. Keep reporting a broken
group when the leader failed to open.
$ perf stat -a -e '{user_time,cycles,instructions}' -- sleep 0.05
0 user_time
38257394 cycles
21228043 instructions
The kernel events in such a group are no longer scheduled together.
Fixes: 6828d6929b76 ("perf evsel: Refactor tool events")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com>
---
This goes on top of TAKANO's segfault fix, as asked in that thread.
A tool event as a member, as in '{cycles,user_time}', is still not
counted; I'll send that separately.
Ian, the other way is to take tool events out of such groups in perf
stat with a warning, the way mismatched cpus are handled, which also
covers the member case. I went with the group_fd = -1 that
0b18bced5444 describes; happy to switch if you'd rather split them.
---
Changes in v2:
- Open the members disabled like a leader, so -D, --control and
enable_on_exec apply to them (sashiko)
- Report a broken group when the leader failed to open, as before, so
perf record is unchanged (sashiko)
- Limit to tool event leaders: a hwmon leader can't enable its members
- Link to v1: https://lore.kernel.org/r/20261111-tool-pmu-leader-v1-1-6173b5569f59@gmail.com
---
tools/perf/builtin-stat.c | 10 ++++++----
tools/perf/util/evsel.c | 8 ++++++++
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 37752d6bfef4..07d01028bdea 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -719,9 +719,10 @@ static int create_perf_stat_counter(struct evsel *evsel,
/*
* The event is part of non trivial group, let's enable
* the group read (for leader) and ID retrieval for all
- * members.
+ * members. Members of a tool event leader are opened and
+ * read on their own.
*/
- if (leader->core.nr_members > 1)
+ if (leader->core.nr_members > 1 && !evsel__is_tool(leader))
attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP;
attr->inherit = !config->no_inherit && list_empty(&evsel->bpf_counter_list);
@@ -748,9 +749,10 @@ static int create_perf_stat_counter(struct evsel *evsel,
/*
* Disabling all counters initially, they will be enabled
* either manually by us or by kernel via enable_on_exec
- * set later.
+ * set later. Members of a tool event leader are opened on
+ * their own and enabled with it, so they need it too.
*/
- if (evsel__is_group_leader(evsel)) {
+ if (evsel__is_group_leader(evsel) || evsel__is_tool(leader)) {
attr->disabled = 1;
if (target__enable_on_exec(&target))
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 560741d9599d..e3ed645cc289 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2378,6 +2378,14 @@ static int get_group_fd(struct evsel *evsel, int cpu_map_idx, int thread)
if (!evsel->supported || evsel__is_group_leader(evsel))
return -1;
+ /*
+ * A tool event leader has no perf event to group with, so open
+ * the member on its own, or report the group as broken (-2) if
+ * the leader failed to open.
+ */
+ if (evsel__is_tool(leader))
+ return leader->supported ? -1 : -2;
+
/*
* Leader must be already processed/open,
* if not it's a bug.
---
base-commit: cc905a18a647a8e3ad42cd1596baa0e08fba26eb
change-id: 20261111-tool-pmu-leader-d25fe8153599
prerequisite-message-id: <20261023085629.1694941-1-takano32@gmail.com>
prerequisite-patch-id: b92ce8b0c6248a4af182670458912b760b98a410
Best regards,
--
Hang Zhengyang <hang.zhengyang1010@gmail.com>
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2] perf stat: Count kernel events in a group led by a tool event 2026-11-11 6:04 [PATCH v2] perf stat: Count kernel events in a group led by a tool event Hang Zhengyang via B4 Relay @ 2026-11-11 6:18 ` sashiko-bot 2026-11-11 11:06 ` [PATCH v3] " TAKANO Mitsuhiro 1 sibling, 0 replies; 10+ messages in thread From: sashiko-bot @ 2026-11-11 6:18 UTC (permalink / raw) To: Hang Zhengyang; +Cc: linux-perf-users > From: Hang Zhengyang <hang.zhengyang1010@gmail.com> > > A tool event like user_time has no perf event in the kernel, but > get_group_fd() still passes its fd, the /proc/stat fd, as the group_fd > of the members. The kernel rejects each member with EBADF and nothing > is counted: > > $ perf stat -a -e '{user_time,cycles,instructions}' -- sleep 0.05 > 0 user_time > <not supported> cycles > <not supported> instructions > > Open the members with group_fd = -1, as the enable/disable code already > assumes. They are then on their own, so read them without > PERF_FORMAT_GROUP and open them disabled like a leader, so that -D, > --control and enable_on_exec still apply. Keep reporting a broken > group when the leader failed to open. > > $ perf stat -a -e '{user_time,cycles,instructions}' -- sleep 0.05 > 0 user_time > 38257394 cycles > 21228043 instructions > > The kernel events in such a group are no longer scheduled together. > > Fixes: 6828d6929b76 ("perf evsel: Refactor tool events") > Assisted-by: Claude:claude-opus-5-5 > Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com> Sashiko has reviewed this patch and found no issues. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261111-tool-pmu-leader-v2-1-3faa0fb98c51@gmail.com?part=1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3] perf stat: Count kernel events in a group led by a tool event 2026-11-11 6:04 [PATCH v2] perf stat: Count kernel events in a group led by a tool event Hang Zhengyang via B4 Relay 2026-11-11 6:18 ` sashiko-bot @ 2026-11-11 11:06 ` TAKANO Mitsuhiro 2026-11-11 11:33 ` sashiko-bot ` (2 more replies) 1 sibling, 3 replies; 10+ messages in thread From: TAKANO Mitsuhiro @ 2026-11-11 11:06 UTC (permalink / raw) To: linux-perf-users, Arnaldo Carvalho de Melo, Namhyung Kim Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland, Hang Zhengyang, linux-kernel, TAKANO Mitsuhiro From: Hang Zhengyang <hang.zhengyang1010@gmail.com> A tool event like user_time has no perf event in the kernel, but get_group_fd() still passes its fd, the /proc/stat fd, as the group_fd of the members. The kernel rejects each member with EBADF and nothing is counted: $ perf stat -a -e '{user_time,cycles,instructions}' -- sleep 0.05 0 user_time <not supported> cycles <not supported> instructions Open the members with group_fd = -1, as the enable/disable code already assumes, and read them on their own: the leader is not asked for counts of events that are not in its kernel group. A kernel event member is opened disabled, as a leader is, so that it starts with the workload and still honours -D and --control. A tool event member is left as it is: it counts from open and an explicit disable is what stops it, so disabling it here would leave nobody to start it when perf relies on enable_on_exec. $ perf stat -a -e '{user_time,cycles,instructions}' -- sleep 0.05 0 user_time 38257394 cycles 21228043 instructions The kernel events in such a group are no longer scheduled together, which is the price of counting them at all. A tool event used as a member, as in '{cycles,user_time}', is still not counted; that also needs the leader's group read to be handled and is left for a follow-up. Fixes: 6828d6929b76 ("perf evsel: Refactor tool events") Written with LLM assistants: the group_fd change and its testing by Hang Zhengyang with Claude, the v3 condition and its measurement by TAKANO Mitsuhiro with Hermes Agent. perf was built here and 'perf test -v 10' passes with and without the change. Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com> Signed-off-by: TAKANO Mitsuhiro <takano32@gmail.com> --- v3: open only the kernel event members disabled. A tool event member counts from open and an explicit disable is what stops it, so opening it disabled left nobody to start it when perf relies on enable_on_exec: 'perf stat -e "{user_time,system_time}" -- sleep 0.2' went from ~2.7 ms of system_time to 0 on an arm64 KVM guest. The non-standard Assisted-by tag is replaced by a prose disclosure, and the patch is regenerated on 7.4-rc2. The libperf fix that stops the NULL dereference is a separate patch (<20261111101625.2204836-1-takano32@gmail.com>); this one does not depend on it. tools/perf/builtin-stat.c | 16 ++++++++++++---- tools/perf/util/evsel.c | 8 ++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 37752d6bfef4..57956f55ea09 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -719,9 +719,10 @@ static int create_perf_stat_counter(struct evsel *evsel, /* * The event is part of non trivial group, let's enable * the group read (for leader) and ID retrieval for all - * members. + * members. Members of a tool event leader are opened and + * read on their own. */ - if (leader->core.nr_members > 1) + if (leader->core.nr_members > 1 && !evsel__is_tool(leader)) attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP; attr->inherit = !config->no_inherit && list_empty(&evsel->bpf_counter_list); @@ -748,9 +749,16 @@ static int create_perf_stat_counter(struct evsel *evsel, /* * Disabling all counters initially, they will be enabled * either manually by us or by kernel via enable_on_exec - * set later. + * set later. A kernel event that a tool event leader has as + * a member is not in the kernel's group either, so it has to + * be opened disabled to start together with the workload. + * A tool event member counts from open and is only stopped by + * an explicit disable, so leaving it enabled here keeps its + * count; disabling it would leave nobody to start it when + * perf relies on enable_on_exec. */ - if (evsel__is_group_leader(evsel)) { + if (evsel__is_group_leader(evsel) || + (evsel__is_tool(leader) && !evsel__is_tool(evsel))) { attr->disabled = 1; if (target__enable_on_exec(&target)) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d060fca8090f..7f514cde6840 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2370,6 +2370,14 @@ static int get_group_fd(struct evsel *evsel, int cpu_map_idx, int thread) if (!evsel->supported || evsel__is_group_leader(evsel)) return -1; + /* + * A tool event leader has no perf event to group with, so open + * the member on its own, or report the group as broken (-2) if + * the leader failed to open. + */ + if (evsel__is_tool(leader)) + return leader->supported ? -1 : -2; + /* * Leader must be already processed/open, * if not it's a bug. base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb -- 2.53.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v3] perf stat: Count kernel events in a group led by a tool event 2026-11-11 11:06 ` [PATCH v3] " TAKANO Mitsuhiro @ 2026-11-11 11:33 ` sashiko-bot 2026-11-12 3:49 ` Hang Zhengyang 2026-11-19 8:06 ` Namhyung Kim 2026-11-22 8:59 ` [PATCH v4] perf stat: Refuse a group mixing tool and kernel events TAKANO Mitsuhiro 2 siblings, 1 reply; 10+ messages in thread From: sashiko-bot @ 2026-11-11 11:33 UTC (permalink / raw) To: TAKANO Mitsuhiro, linux-perf-users Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] perf stat: broken tool event enable/disable for -D, --control, and exec in create_perf_stat_counter() -- commit 0e981d5b2ece1f32ac47445309993697c6cdb096 Author: Hang Zhengyang <hang.zhengyang1010@gmail.com> perf stat: Count kernel events in a group led by a tool event This commit opens members of a group led by a tool event on their own with group_fd = -1 and without PERF_FORMAT_GROUP, while opening kernel event members initially disabled. > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index 37752d6bfef45..57956f55ea09b 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c [ ... ] > @@ -748,9 +749,16 @@ static int create_perf_stat_counter(struct evsel *evsel, > /* > * Disabling all counters initially, they will be enabled > * either manually by us or by kernel via enable_on_exec > - * set later. > + * set later. A kernel event that a tool event leader has as > + * a member is not in the kernel's group either, so it has to > + * be opened disabled to start together with the workload. > + * A tool event member counts from open and is only stopped by > + * an explicit disable, so leaving it enabled here keeps its > + * count; disabling it would leave nobody to start it when > + * perf relies on enable_on_exec. > */ > - if (evsel__is_group_leader(evsel)) { > + if (evsel__is_group_leader(evsel) || > + (evsel__is_tool(leader) && !evsel__is_tool(evsel))) { > attr->disabled = 1; > > if (target__enable_on_exec(&target)) [Severity: Medium] Does conditioning attr->disabled on leader vs. member rather than target__enable_on_exec(&target) leave tool event members enabled during -D / --control and leave tool event leaders disabled during exec workloads? In evsel__tool_pmu_open(), attr->disabled sets evsel->disabled = true and start_time = INVALID_START_TIME; otherwise evsel->disabled is false and start_time is sampled immediately at open. When !target__enable_on_exec(&target) (such as with -D or --control), enable_counters() calls evlist__enable(), and evsel__enable_cpu() enables each member of a tool-led group via evsel__tool_pmu_enable_cpu(): tools/perf/util/tool_pmu.c:evsel__tool_pmu_enable_cpu() { if (!evsel->disabled) return 0; ... } Because a tool event member in a group like '{user_time,system_time}' is skipped by !evsel__is_tool(evsel) and opened with attr->disabled == 0, evsel__tool_pmu_enable_cpu() returns early without resetting start_time, so the member counts continuously through the disabled delay window. Conversely, when target__enable_on_exec(&target) is true (such as 'perf stat -e "{user_time,cycles}" -- sleep 0.2'), enable_counters() skips evlist__enable() because kernel events are enabled on exec. A tool event leader still matches evsel__is_group_leader(evsel) and opens with evsel->disabled = true; nothing enables it on exec, so evsel__tool_pmu_read() returns 0. Should tool events instead set attr->disabled = 1 only when !target__enable_on_exec(&target), regardless of whether they are the group leader or a member? -- Sashiko AI review · https://sashiko.dev/#/patchset/20261111110616.2249764-1-takano32@gmail.com?part=1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3] perf stat: Count kernel events in a group led by a tool event 2026-11-11 11:33 ` sashiko-bot @ 2026-11-12 3:49 ` Hang Zhengyang 0 siblings, 0 replies; 10+ messages in thread From: Hang Zhengyang @ 2026-11-12 3:49 UTC (permalink / raw) To: TAKANO Mitsuhiro, linux-perf-users Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, linux-kernel On Wed, 11 Nov 2026 11:33:19 +0000, sashiko-bot@kernel.org wrote: > [...] leave tool event members enabled during -D / --control and > leave tool event leaders disabled during exec workloads? Both happen without this patch too, with tool events outside any group (perf-tools-next cc905a18a647): $ perf stat -e user_time,system_time -- dd if=/dev/zero of=/dev/null bs=1 count=300000 -> user_time 0, system_time 0 $ perf stat -D 400 -e user_time,system_time -- sh -c 'dd ... ; sleep 0.6' -> user_time 173 ms, system_time 137 ms, though dd ends within 400 ms The first is what TAKANO's "perf stat: Start tool events when enable_on_exec is used" fixes. Thanks, Hang ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3] perf stat: Count kernel events in a group led by a tool event 2026-11-11 11:06 ` [PATCH v3] " TAKANO Mitsuhiro 2026-11-11 11:33 ` sashiko-bot @ 2026-11-19 8:06 ` Namhyung Kim 2026-11-19 10:08 ` TAKANO Mitsuhiro 2026-11-22 8:59 ` [PATCH v4] perf stat: Refuse a group mixing tool and kernel events TAKANO Mitsuhiro 2 siblings, 1 reply; 10+ messages in thread From: Namhyung Kim @ 2026-11-19 8:06 UTC (permalink / raw) To: TAKANO Mitsuhiro, Ian Rogers Cc: linux-perf-users, Arnaldo Carvalho de Melo, Peter Zijlstra, Ingo Molnar, Mark Rutland, Hang Zhengyang, linux-kernel Hello, On Wed, Nov 11, 2026 at 11:06:16AM +0000, TAKANO Mitsuhiro wrote: > From: Hang Zhengyang <hang.zhengyang1010@gmail.com> > > A tool event like user_time has no perf event in the kernel, but > get_group_fd() still passes its fd, the /proc/stat fd, as the group_fd > of the members. The kernel rejects each member with EBADF and nothing > is counted: > > $ perf stat -a -e '{user_time,cycles,instructions}' -- sleep 0.05 > 0 user_time > <not supported> cycles > <not supported> instructions Thanks for reporting this. Looks like a tricky case for tool events. I think it's better to make the first non-tool event as a leader, but I'm afraid it'd make evlist management complex. Ian, any thoughts? Thanks, Namhyung > > Open the members with group_fd = -1, as the enable/disable code already > assumes, and read them on their own: the leader is not asked for counts > of events that are not in its kernel group. A kernel event member is > opened disabled, as a leader is, so that it starts with the workload > and still honours -D and --control. A tool event member is left as it > is: it counts from open and an explicit disable is what stops it, so > disabling it here would leave nobody to start it when perf relies on > enable_on_exec. > > $ perf stat -a -e '{user_time,cycles,instructions}' -- sleep 0.05 > 0 user_time > 38257394 cycles > 21228043 instructions > > The kernel events in such a group are no longer scheduled together, > which is the price of counting them at all. A tool event used as a > member, as in '{cycles,user_time}', is still not counted; that also > needs the leader's group read to be handled and is left for a > follow-up. > > Fixes: 6828d6929b76 ("perf evsel: Refactor tool events") > Written with LLM assistants: the group_fd change and its testing by > Hang Zhengyang with Claude, the v3 condition and its measurement by > TAKANO Mitsuhiro with Hermes Agent. perf was built here and > 'perf test -v 10' passes with and without the change. > Signed-off-by: Hang Zhengyang <hang.zhengyang1010@gmail.com> > Signed-off-by: TAKANO Mitsuhiro <takano32@gmail.com> > --- > v3: open only the kernel event members disabled. A tool event member > counts from open and an explicit disable is what stops it, so > opening it disabled left nobody to start it when perf relies on > enable_on_exec: 'perf stat -e "{user_time,system_time}" -- sleep > 0.2' went from ~2.7 ms of system_time to 0 on an arm64 KVM guest. > The non-standard Assisted-by tag is replaced by a prose > disclosure, and the patch is regenerated on 7.4-rc2. > > The libperf fix that stops the NULL dereference is a separate > patch (<20261111101625.2204836-1-takano32@gmail.com>); this one > does not depend on it. > > tools/perf/builtin-stat.c | 16 ++++++++++++---- > tools/perf/util/evsel.c | 8 ++++++++ > 2 files changed, 20 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index 37752d6bfef4..57956f55ea09 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -719,9 +719,10 @@ static int create_perf_stat_counter(struct evsel *evsel, > /* > * The event is part of non trivial group, let's enable > * the group read (for leader) and ID retrieval for all > - * members. > + * members. Members of a tool event leader are opened and > + * read on their own. > */ > - if (leader->core.nr_members > 1) > + if (leader->core.nr_members > 1 && !evsel__is_tool(leader)) > attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP; > > attr->inherit = !config->no_inherit && list_empty(&evsel->bpf_counter_list); > @@ -748,9 +749,16 @@ static int create_perf_stat_counter(struct evsel *evsel, > /* > * Disabling all counters initially, they will be enabled > * either manually by us or by kernel via enable_on_exec > - * set later. > + * set later. A kernel event that a tool event leader has as > + * a member is not in the kernel's group either, so it has to > + * be opened disabled to start together with the workload. > + * A tool event member counts from open and is only stopped by > + * an explicit disable, so leaving it enabled here keeps its > + * count; disabling it would leave nobody to start it when > + * perf relies on enable_on_exec. > */ > - if (evsel__is_group_leader(evsel)) { > + if (evsel__is_group_leader(evsel) || > + (evsel__is_tool(leader) && !evsel__is_tool(evsel))) { > attr->disabled = 1; > > if (target__enable_on_exec(&target)) > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > index d060fca8090f..7f514cde6840 100644 > --- a/tools/perf/util/evsel.c > +++ b/tools/perf/util/evsel.c > @@ -2370,6 +2370,14 @@ static int get_group_fd(struct evsel *evsel, int cpu_map_idx, int thread) > if (!evsel->supported || evsel__is_group_leader(evsel)) > return -1; > > + /* > + * A tool event leader has no perf event to group with, so open > + * the member on its own, or report the group as broken (-2) if > + * the leader failed to open. > + */ > + if (evsel__is_tool(leader)) > + return leader->supported ? -1 : -2; > + > /* > * Leader must be already processed/open, > * if not it's a bug. > > base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb > -- > 2.53.0 > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3] perf stat: Count kernel events in a group led by a tool event 2026-11-19 8:06 ` Namhyung Kim @ 2026-11-19 10:08 ` TAKANO Mitsuhiro 2026-11-20 21:45 ` Namhyung Kim 0 siblings, 1 reply; 10+ messages in thread From: TAKANO Mitsuhiro @ 2026-11-19 10:08 UTC (permalink / raw) To: Namhyung Kim Cc: Ian Rogers, Hang Zhengyang, Arnaldo Carvalho de Melo, Peter Zijlstra, Ingo Molnar, Mark Rutland, linux-perf-users, linux-kernel, TAKANO Mitsuhiro Hi Namhyung, > I think it's better to make the first non-tool event as a leader I agree, and I think that is where this ends up. What stops me from doing it in this patch is the group read: with a kernel event as the leader, evsel__group_read_nr_members() still counts a tool event member, while the kernel knows nothing about it (a tool event is not opened through perf_event_open, it reads /proc/stat) and returns one entry fewer. evsel__process_group_data() then rejects the read with -EINVAL and the kernel events of that group come out as <not counted> as well. The smallest version of that is a few lines, but it changes what every group with a tool event member prints, so it wants its own test and its own commit rather than riding along with the EBADF fix. > but I'm afraid it'd make evlist management complex v3 leaves the group structure alone: no new evlist entry, nr_members unchanged, and evsel->leader stays whoever it already was. What changes is how the members are opened: - get_group_fd(): with group_fd = -1 instead of the tool event's /proc/stat fd, or -2 when the leader failed to open, the same -2 the skipped-leader case already returns for a broken group; - create_perf_stat_counter(): a kernel event member is opened disabled, as a leader is, so that it starts with the workload, and PERF_FORMAT_GROUP is not requested for the members - read_format is per fd, and GROUP is what would send each member's read down the group path that only a leader can take. PERF_FORMAT_ID goes with it: without a group read nothing demuxes ids. The cost is real and the changelog states it: in -e '{user_time,a,b}', a and b no longer share an on/off window. Two things this does not change, both of which happen without the patch: a tool event member still counts through a -D / --control window, and a tool event leader under enable_on_exec is still not started by anything - that is what "perf stat: Start tool events when enable_on_exec is used" is for. Either way the leader move is a separate series; I can post it once the direction is settled. Thanks, TAKANO ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3] perf stat: Count kernel events in a group led by a tool event 2026-11-19 10:08 ` TAKANO Mitsuhiro @ 2026-11-20 21:45 ` Namhyung Kim 0 siblings, 0 replies; 10+ messages in thread From: Namhyung Kim @ 2026-11-20 21:45 UTC (permalink / raw) To: TAKANO Mitsuhiro Cc: Ian Rogers, Hang Zhengyang, Arnaldo Carvalho de Melo, Peter Zijlstra, Ingo Molnar, Mark Rutland, linux-perf-users, linux-kernel On Thu, Nov 19, 2026 at 10:08:38AM +0000, TAKANO Mitsuhiro wrote: > Hi Namhyung, > > > I think it's better to make the first non-tool event as a leader > > I agree, and I think that is where this ends up. What stops me from > doing it in this patch is the group read: with a kernel event as the > leader, evsel__group_read_nr_members() still counts a tool event member, > while the kernel knows nothing about it (a tool event is not opened > through perf_event_open, it reads /proc/stat) and returns one entry > fewer. evsel__process_group_data() then rejects the read with -EINVAL > and the kernel events of that group come out as <not counted> as well. > The smallest version of that is a few lines, but it changes what every > group with a tool event member prints, so it wants its own test and its > own commit rather than riding along with the EBADF fix. > > > but I'm afraid it'd make evlist management complex > > v3 leaves the group structure alone: no new evlist entry, nr_members > unchanged, and evsel->leader stays whoever it already was. What changes > is how the members are opened: > > - get_group_fd(): with group_fd = -1 instead of the tool event's > /proc/stat fd, or -2 when the leader failed to open, the same -2 the > skipped-leader case already returns for a broken group; > - create_perf_stat_counter(): a kernel event member is opened disabled, > as a leader is, so that it starts with the workload, and > PERF_FORMAT_GROUP is not requested for the members - read_format is > per fd, and GROUP is what would send each member's read down the > group path that only a leader can take. PERF_FORMAT_ID goes with it: > without a group read nothing demuxes ids. > > The cost is real and the changelog states it: in -e '{user_time,a,b}', > a and b no longer share an on/off window. > > Two things this does not change, both of which happen without the patch: > a tool event member still counts through a -D / --control window, and a > tool event leader under enable_on_exec is still not started by anything - > that is what "perf stat: Start tool events when enable_on_exec is used" > is for. > > Either way the leader move is a separate series; I can post it once the > direction is settled. I think grouping with tool events would cause more headaches. Probably the simplest fix is to prohibit grouping. Thanks, Namhyung ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v4] perf stat: Refuse a group mixing tool and kernel events 2026-11-11 11:06 ` [PATCH v3] " TAKANO Mitsuhiro 2026-11-11 11:33 ` sashiko-bot 2026-11-19 8:06 ` Namhyung Kim @ 2026-11-22 8:59 ` TAKANO Mitsuhiro 2026-11-22 9:22 ` sashiko-bot 2 siblings, 1 reply; 10+ messages in thread From: TAKANO Mitsuhiro @ 2026-11-22 8:59 UTC (permalink / raw) To: linux-perf-users, Arnaldo Carvalho de Melo, Namhyung Kim Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland, Hang Zhengyang, linux-kernel, TAKANO Mitsuhiro A tool event has no event in the kernel. user_time and system_time read /proc/stat, or /proc/<pid>/stat for a workload, and duration_time keeps its value in perf itself. perf-list(1) says that events from different PMUs cannot be grouped, with some exceptions for software events; the tool PMU counts as software there, so a tool event stays in a group a user writes and, when it leads, the members are opened with its descriptor as the group fd. Two things split such a group before it is opened: the parser splits a tool event from an event of another software PMU, such as cpu-clock, and evlist__check_cpu_maps() drops members whose CPUs do not match the leader under -a or -C. The group this patch is about is the one left after that, and it cannot be counted. With user_time or system_time as the leader, get_group_fd() hands the procfs descriptor to the members, and the kernel rejects each of them with EBADF. With duration_time as the leader there is no descriptor at all: its members get -2 and fail with "broken group leader" in the debug log. Either way perf stat prints the tool event and "<not supported>" for the rest of the group: $ perf stat -e '{user_time,cycles}' -- sleep 0.05 0 user_time <not supported> cycles With a kernel event as the leader the kernel events do open, but the group read is rejected: evsel__group_read_nr_members() counts the tool event, while the kernel returns one entry fewer, so evsel__process_group_data() fails and the events come out as "<not counted>". The form -e '{cycles,instructions,duration_time}', with the tool event inside the braces, is in that shape and has not been counted since 6828d6929b76. Counting such a group means moving the leader to a kernel event, which changes the order of a group the user wrote with a tool event first, and it also needs the group read to skip the tool members; that is left to a separate series. Opening the members outside the group, as my v3 did and as Hang's v2 does, drops the group semantics, and a group that has a tool event as a member still cannot be counted. Taking the tool event out of the group and warning, as Hang offered in the notes of his v2 patch and as evlist__check_cpu_maps() does for members whose CPUs do not match the leader, would let the kernel events count, but the group would no longer be scheduled as one, so the tool event and the kernel events would have different enabled and running times, and the warning is easy to lose in a script. For -e the braces are the user's explicit request, so perf stat should not quietly reinterpret them; metricgroup moves tool events out of the groups it builds itself, which is a different case. Refuse the group instead: $ perf stat -e '{user_time,cycles}' -- sleep 0.05 A tool event cannot be grouped with kernel events: user_time followed by a hint to put the tool event outside the braces, as in -e '{cycles,instructions},duration_time'. perf stat now exits 22 before the workload is started, where it used to leave the rest of the group uncounted and exit 0. A group of tool events only is still accepted, as before. A weak group led by user_time or system_time is left to the weak group handling, which splits it when a member fails the open with EBADF; any other weak group that mixes them does not fail that way and is refused like a strong one. The code, the test, the man page and this message were written with Hermes Agent (deepseek-v4.1-flash); the work started from Hang's report and the review thread linked below, and I reviewed the result, built perf, and ran tools/perf/tests/shell/stat+tool_group.sh and checkpatch --strict. Kernel events cannot be opened on this machine (perf_event_paranoid=4), so the EBADF and the group read were not re-observed here; the group is refused before any event is opened. Reported-by: Hang Zhengyang <hang.zhengyang1010@gmail.com> Link: https://lore.kernel.org/all/20261111-tool-pmu-leader-v2-1-3faa0fb98c51@gmail.com/ Suggested-by: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/all/awC_aZXD5FBGu4mO@google.com/ Fixes: 6828d6929b76 ("perf evsel: Refactor tool events") Signed-off-by: TAKANO Mitsuhiro <takano32@gmail.com> --- v4: refuse the group instead of counting it, as suggested by Namhyung Kim in https://lore.kernel.org/all/awC_aZXD5FBGu4mO@google.com/ This replaces v3, which is withdrawn: its group_fd, read_format and disabled changes are dropped and no code from it remains. I read "prohibit grouping" as the group that mixes a tool event with an event the kernel opens: -e '{user_time,system_time}' is read by perf itself and is not refused today. If you meant every group that holds a tool event, dropping the has_kernel test, and the weak check with it, is a couple of lines. The parser still splits a tool event from another software PMU, and -a or -C still split a group whose members do not share the leader's CPUs; this refuses the group that is left after that. A weak group led by user_time or system_time is left to the weak group handling, which splits it when a member fails with EBADF; any other weak group is refused. Ian: Hang offered, in his v2, to take tool events out of such groups with a warning instead. I did not do that because the group would no longer be scheduled as one and the warning is easy to lose in a script. If you would rather have that, I can redo it. Namhyung asked for the leader to move, then for grouping to be prohibited. Hang's v2 (Link) takes a third route, group_fd = -1, and is still open; only one of v2 and this patch should be applied: v2 counts the members outside the group, this refuses the group. On this base, -a or -C with a weak group led by a tool event crashes in the enable loop with a released fd array. That is older than this patch, and the libperf fix "libperf: Handle an evsel without an fd array in enable/disable" (https://lore.kernel.org/all/20261111101625.2204836-1-takano32@gmail.com/), which is in perf-tools-next, removes it. tools/perf/Documentation/perf-stat.txt | 14 +++ tools/perf/builtin-stat.c | 76 ++++++++++++ tools/perf/tests/shell/stat+tool_group.sh | 144 ++++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100755 tools/perf/tests/shell/stat+tool_group.sh diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 8ea17da89976..34323f446e92 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -65,6 +65,20 @@ report:: Multiple PMU instances are typical for uncore PMUs, so the prefix 'uncore_' is also ignored when performing this match. + Tool events such as duration_time and user_time are read by perf + itself and have no event in the kernel. A group of a tool event and + an event from a different software PMU, such as cpu-clock, is split by + the parser, which warns that events were regrouped; -a and -C split + a group whose members do not share the CPUs of the leader in the + same way. A group that is not split and mixes a tool event with an + event the kernel opens is refused, as in -e '{user_time,cycles}', + instead of printing the tool event and leaving the rest of the group + uncounted. Put the tool event outside the braces instead, as in + -e '{cycles,instructions},duration_time'. A group of tool events + only is accepted. A weak group (:W) led by user_time or system_time + is left to the weak group handling, which splits it when the kernel + refuses the members with EBADF; any other weak group that mixes them is + refused like a strong group. -i:: --no-inherit:: diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 37752d6bfef4..7396cd92346a 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2469,6 +2469,77 @@ static int parse_tpebs_mode(const struct option *opt, const char *str, } #endif // HAVE_ARCH_X86_64_SUPPORT +/* + * A tool event like user_time has no event in the kernel: it reads + * /proc/stat, or keeps its value in perf itself. A group that mixes one + * with an event the kernel opens cannot be counted. + * get_group_fd() passes the leader's descriptor as the group fd, and the + * tool event has a procfs descriptor or none at all, so the kernel rejects + * the members with EBADF or perf gives up with "broken group leader"; with + * a kernel event as the leader the members do open, but the group read is + * rejected as the kernel knows only the members it opened. perf stat used + * to leave the rest of the group uncounted in both cases, when the CPU maps + * had not split the group first; refuse the group instead. A group with no + * event the kernel opens is left alone, as perf reads each event in it. A + * weak group led by user_time or system_time is left to the weak group + * handling in the open loop, which splits it when a member fails with + * EBADF; any other weak group is refused like a strong one. + */ +static int check_tool_groups(struct evlist *evlist) +{ + struct evsel *leader, *evsel; + + evlist__for_each_entry(evlist, leader) { + struct evsel *tool = NULL; + bool has_kernel = false, weak = false; + + if (!evsel__is_group_leader(leader) || leader->core.nr_members < 2) + continue; + + /* + * The members of a group are not necessarily adjacent in the + * evlist: evlist__check_cpu_maps() makes a removed member a + * leader of its own without moving it, and so does a weak + * group split in the open loop. + */ + evlist__for_each_entry(evlist, evsel) { + if (!evsel__has_leader(evsel, leader)) + continue; + if (evsel__is_tool(evsel)) { + if (!tool) + tool = evsel; + } else if (!evsel__is_non_perf_event_open_pmu(evsel)) { + has_kernel = true; + } + weak |= evsel->weak_group; + } + + if (!tool || !has_kernel) + continue; + + /* + * A weak group led by user_time or system_time is split by the + * weak group handling in the open loop, as the kernel refuses + * the members with EBADF, and that is what :W asks for. Any + * other weak group does not get that far, so it is refused + * like a strong group. + */ + if (weak && evsel__is_tool(leader)) { + enum tool_pmu_event ev = evsel__tool_event(leader); + + if (ev == TOOL_PMU__EVENT_USER_TIME || + ev == TOOL_PMU__EVENT_SYSTEM_TIME) + continue; + } + + pr_err("A tool event cannot be grouped with kernel events: %s\n", + evsel__name(tool)); + pr_err("Put it outside the braces, as in -e '{cycles,instructions},duration_time'.\n"); + return -EINVAL; + } + return 0; +} + int cmd_stat(int argc, const char **argv) { struct opt_aggr_mode opt_mode = {}; @@ -2947,6 +3018,11 @@ int cmd_stat(int argc, const char **argv) evlist__check_cpu_maps(evsel_list); + if (check_tool_groups(evsel_list)) { + status = -EINVAL; + goto out; + } + /* * Initialize thread_map with comm names, * so we could print it out on output. diff --git a/tools/perf/tests/shell/stat+tool_group.sh b/tools/perf/tests/shell/stat+tool_group.sh new file mode 100755 index 000000000000..3d5e468f7ccb --- /dev/null +++ b/tools/perf/tests/shell/stat+tool_group.sh @@ -0,0 +1,144 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# perf stat tool events in an event group (no_mlock) + +set -e + +out=$(mktemp /tmp/__perf_test.stat_tool_group.XXXXXX) +stderr=$(mktemp /tmp/__perf_test.stat_tool_group.XXXXXX) +err=0 + +cleanup() { + rm -f "${out}" "${stderr}" + + trap - EXIT TERM INT +} + +trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +# A tool event reads /proc/stat, or keeps its value in perf itself, so it +# cannot be a member of a group that is opened with perf_event_open(). Such +# a group used to print the tool event and leave the rest of the group +# uncounted, so perf stat has to say what is wrong instead. +refused() { + local group="$1" tool="$2" rc=0 + shift 2 + + echo "Testing that perf stat refuses ${group} $*" + perf stat "$@" -e "${group}" -o "${out}" -- true 2> "${stderr}" || rc=$? + + if [ "${rc}" = 0 ]; then + echo "perf stat accepted ${group} [Failed]" + err=1 + return + fi + if [ "${rc}" != 22 ]; then + echo "perf stat failed with ${rc}, expected 22 [Failed]" + cat "${stderr}" + err=1 + fi + if ! grep -qE "A tool event cannot be grouped with kernel events: (${tool})" \ + "${stderr}"; then + echo "perf stat failed without naming ${tool} [Failed]" + cat "${stderr}" + err=1 + fi + if ! grep -q "Put it outside the braces" "${stderr}"; then + echo "perf stat failed without saying how to write it [Failed]" + cat "${stderr}" + err=1 + fi +} + +# The events named after the group have to show up in the output. +accepted() { + local group="$1" name rc=0 + + shift + echo "Testing that perf stat accepts ${group}" + perf stat -e "${group}" -o "${out}" -- true 2> "${stderr}" || rc=$? + + if [ "${rc}" != 0 ]; then + cat "${stderr}" + echo "perf stat failed for ${group} (${rc}) [Failed]" + err=1 + return + fi + if grep -q "cannot be grouped with kernel events" "${stderr}"; then + cat "${stderr}" + echo "perf stat refused ${group} [Failed]" + err=1 + return + fi + for name in "$@"; do + if ! grep -q -- "${name}" "${out}"; then + echo "perf stat did not print ${name} [Failed]" + cat "${out}" + err=1 + fi + done +} + +# The tool event as the leader and as a member, a common group that puts +# the tool event last, a weak group led by a kernel event (it opens and +# then fails its group read), and a weak group led by a tool event that +# has no descriptor to fail with. +refused '{user_time,cycles}' user_time +refused '{cycles,user_time}' user_time +refused '{duration_time,instructions}' duration_time +refused '{cycles,instructions,duration_time}' duration_time +refused '{cycles,user_time}:W' user_time +refused '{duration_time,cycles}:W' duration_time + +# The tool event in the middle of a group, and the first of two tool +# events, which is the one the message names. +refused '{cycles,user_time,instructions}' user_time +refused '{user_time,system_time,cycles}' user_time + +# evlist__check_cpu_maps() takes duration_time out of this group (it is +# read on one CPU only), which leaves cycles and user_time apart in the +# evlist; the tool event has to be found anyway. On a machine with one +# CPU there is nothing to split, so either tool event can be the first. +refused '{cycles,duration_time,user_time}' 'user_time|duration_time' -a + +# A group of tool events only is read by perf itself, a single event in +# braces is not a group, a tool event outside the braces is not a member, +# and a weak group led by user_time or system_time is split by the weak +# group handling. +accepted '{user_time,system_time}' user_time system_time +accepted '{duration_time,user_time}' duration_time user_time +accepted '{user_time}' user_time +accepted '{cycles,instructions},duration_time' duration_time +accepted '{user_time,cycles}:W' user_time cycles +accepted '{system_time,cycles}:W' system_time cycles + +echo "Testing that a tool event on its own is accepted" +if ! perf stat -e user_time -o "${out}" -- true; then + echo "perf stat rejected a tool event on its own [Failed]" + err=1 +elif ! grep -q "user_time" "${out}"; then + echo "perf stat did not print user_time [Failed]" + cat "${out}" + err=1 +fi + +echo "Testing that the default events still work" +if ! perf stat -o "${out}" -- true; then + echo "perf stat without -e failed [Failed]" + err=1 +fi + +cleanup + +if [ "${err}" = 0 ]; then + echo "perf stat tool event group test [Success]" +else + echo "perf stat tool event group test [Failed]" +fi + +exit "${err}" base-commit: c44104f3642da720164042623e4832836aefdd8e -- 2.53.0 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v4] perf stat: Refuse a group mixing tool and kernel events 2026-11-22 8:59 ` [PATCH v4] perf stat: Refuse a group mixing tool and kernel events TAKANO Mitsuhiro @ 2026-11-22 9:22 ` sashiko-bot 0 siblings, 0 replies; 10+ messages in thread From: sashiko-bot @ 2026-11-22 9:22 UTC (permalink / raw) To: TAKANO Mitsuhiro, linux-perf-users Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] perf stat: weak group exemption in check_tool_groups() causes NULL deref - [Medium] perf stat: evlist__check_cpu_maps() splits hybrid tool groups before check -- commit fce47ddb742e055cde4f936f3597701fcf5103c2 Author: TAKANO Mitsuhiro <takano32@gmail.com> perf stat: Refuse a group mixing tool and kernel events This commit adds check_tool_groups() to refuse event groups that mix tool events with kernel events, together with documentation and a shell test. Link: https://lore.kernel.org/all/20261111-tool-pmu-leader-v2-1-3faa0fb98c51@gmail.com/ Link: https://lore.kernel.org/all/awC_aZXD5FBGu4mO@google.com/ > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index 37752d6bfef45..7396cd92346af 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -2469,6 +2469,77 @@ static int parse_tpebs_mode(const struct option *opt, const char *str, > } > #endif // HAVE_ARCH_X86_64_SUPPORT > > +/* > + * A tool event like user_time has no event in the kernel: it reads > + * /proc/stat, or keeps its value in perf itself. A group that mixes one > + * with an event the kernel opens cannot be counted. > + * get_group_fd() passes the leader's descriptor as the group fd, and the > + * tool event has a procfs descriptor or none at all, so the kernel rejects > + * the members with EBADF or perf gives up with "broken group leader"; with > + * a kernel event as the leader the members do open, but the group read is > + * rejected as the kernel knows only the members it opened. perf stat used > + * to leave the rest of the group uncounted in both cases, when the CPU maps > + * had not split the group first; refuse the group instead. A group with no > + * event the kernel opens is left alone, as perf reads each event in it. A > + * weak group led by user_time or system_time is left to the weak group > + * handling in the open loop, which splits it when a member fails with > + * EBADF; any other weak group is refused like a strong one. > + */ > +static int check_tool_groups(struct evlist *evlist) > +{ > + struct evsel *leader, *evsel; > + > + evlist__for_each_entry(evlist, leader) { > + struct evsel *tool = NULL; > + bool has_kernel = false, weak = false; > + > + if (!evsel__is_group_leader(leader) || leader->core.nr_members < 2) > + continue; > + > + /* > + * The members of a group are not necessarily adjacent in the > + * evlist: evlist__check_cpu_maps() makes a removed member a > + * leader of its own without moving it, and so does a weak > + * group split in the open loop. > + */ > + evlist__for_each_entry(evlist, evsel) { > + if (!evsel__has_leader(evsel, leader)) > + continue; > + if (evsel__is_tool(evsel)) { > + if (!tool) > + tool = evsel; > + } else if (!evsel__is_non_perf_event_open_pmu(evsel)) { > + has_kernel = true; > + } > + weak |= evsel->weak_group; > + } > + > + if (!tool || !has_kernel) > + continue; > + > + /* > + * A weak group led by user_time or system_time is split by the > + * weak group handling in the open loop, as the kernel refuses > + * the members with EBADF, and that is what :W asks for. Any > + * other weak group does not get that far, so it is refused > + * like a strong group. > + */ > + if (weak && evsel__is_tool(leader)) { > + enum tool_pmu_event ev = evsel__tool_event(leader); > + > + if (ev == TOOL_PMU__EVENT_USER_TIME || > + ev == TOOL_PMU__EVENT_SYSTEM_TIME) > + continue; > + } [Severity: Medium] Can a weak group led by user_time or system_time still bypass the EBADF split in __run_perf_stat() and trigger a NULL pointer dereference of evsel->fd? In the kernel, sys_perf_event_open() checks security_perf_event_open() and perf_allow_kernel() before looking up group_fd with is_perf_file(group). If a kernel member fails there with EACCES (for example, running perf stat -a -e '{user_time,cycles:k}:W' -- true unprivileged under the default kernel.perf_event_paranoid=2, where evsel__fallback() cannot fall back because exclude_user is set), __run_perf_stat() does not call evlist__reset_weak_group() because it only splits on EINVAL or EBADF. __run_perf_stat() then calls perf_evsel__free_fd(&counter->core) on the unsupported member while leaving it attached to the user_time leader, and evlist__enable() -> evsel__enable_cpu() -> perf_evsel__run_ioctl() dereferences NULL evsel->fd in xyarray__max_y(evsel->fd). [ ... ] > @@ -2947,6 +3018,11 @@ int cmd_stat(int argc, const char **argv) > > evlist__check_cpu_maps(evsel_list); > > + if (check_tool_groups(evsel_list)) { > + status = -EINVAL; > + goto out; > + } [Severity: Medium] On hybrid CPU systems, doesn't running evlist__check_cpu_maps() before check_tool_groups() split all tool events out of a core PMU group under -a before check_tool_groups() can refuse it? On a hybrid machine (such as Intel cpu_core and cpu_atom), core PMU events like cycles have core.cpus restricted to that PMU's CPU subset, while duration_time has 1 CPU and user_time has all online CPUs. Under -a, perf_cpu_map__equal(leader->core.cpus, evsel->core.cpus) is false for both tool events, so evlist__check_cpu_maps() removes both from the group and reduces leader->core.nr_members to 1. check_tool_groups() then sees no group left to refuse, and the new test case in stat+tool_group.sh: refused '{cycles,duration_time,user_time}' 'user_time|duration_time' -a exits 0 and fails on hybrid machines. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261122085947.3107661-1-takano32@gmail.com?part=1 ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-22 9:22 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-11 6:04 [PATCH v2] perf stat: Count kernel events in a group led by a tool event Hang Zhengyang via B4 Relay 2026-11-11 6:18 ` sashiko-bot 2026-11-11 11:06 ` [PATCH v3] " TAKANO Mitsuhiro 2026-11-11 11:33 ` sashiko-bot 2026-11-12 3:49 ` Hang Zhengyang 2026-11-19 8:06 ` Namhyung Kim 2026-11-19 10:08 ` TAKANO Mitsuhiro 2026-11-20 21:45 ` Namhyung Kim 2026-11-22 8:59 ` [PATCH v4] perf stat: Refuse a group mixing tool and kernel events TAKANO Mitsuhiro 2026-11-22 9:22 ` sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox