Re: [PATCH v1 06/13] perf pmu: Don't treat tool PMU as a kernel software PMU for event grouping

From: Namhyung Kim

Date: Mon Nov 23 2026 - 19:17:00 EST


Hello,

On Mon, Nov 23, 2026 at 11:12:12PM +0000, TAKANO Mitsuhiro wrote:
> Hi Ian,
>
> 06/13 keeps a group that mixes a tool event with a kernel event from
> reaching the BUG_ON and the group read; I am not disputing that. What I
> want settled is whether such a group should be split or refused.
>
> The 06/13 commit message says:
>
> > Return false for PERF_PMU_TYPE_TOOL in perf_pmu__is_software(), matching
> > hwmon and drm PMUs, and ensure evsel__compute_group_pmu_name() only
> > substitutes perf_event_open PMU names for software and AUX events [...]
>
> I took the other approach: perf stat refuses a group that mixes a tool
> event with a kernel event (one that perf_event_open() opens), unless the
> group is weak and its leader is user_time or system_time. With that patch,
> perf stat rejects -e '{user_time,cycles}' with "A tool event cannot be
> grouped with kernel events: user_time" and exits with status 22, instead of
> printing a value for the tool event and "<not supported>" for the rest.
> This is v4 of "perf stat: Refuse a group mixing tool and kernel events":
>
> https://lore.kernel.org/all/20261122085947.3107661-1-takano32@xxxxxxxxx/
>
> In v4's test, the -a case expects a refusal that the cpu-map split in
> evlist__check_cpu_maps() makes impossible on a machine with more than one
> core PMU. Only the test needs to change; the refusal code does not. I
> will post v5 with that fix.
>
> The parser's split for events of another software PMU, and the split -a
> causes in evlist__check_cpu_maps(), are not what this is about, and I am
> not asking to change either. The -e '{user_time,cycles}' case is not a
> regression: perf stat opens it as one group today, the kernel rejects the
> cycles member with EBADF, and cycles prints "<not supported>". 06/13 would
> count both, as two groups. I would rather be told the group is refused,
> with a hint at the form that does work
> (-e '{cycles,instructions},user_time'), than have perf choose a grouping
> for me. That is a preference about what the braces mean, not a claim that
> 06/13 is broken, and it is yours to weigh. A warning would tell the user
> what happened, but the two groups would still start and stop separately,
> which is the part I cannot square with the braces. If a warning is what
> you have in mind, say so and I will take the refusal off the table.
>
> With 06/13 as posted, the tool event keeps its own PMU name, so the group is
> already split by the time perf stat's check runs. Moving my check before
> the parser regroups the events would refuse a group over members that -a
> would have taken out of it, so the check has to come after both the regroup
> and the split in evlist__check_cpu_maps(). If 06/13 keeps both changes --
> the one in perf_pmu__is_software() and the one in
> evsel__compute_group_pmu_name() -- the groups my test expects to be refused
> would be accepted instead.
>
> The refusal does not reintroduce the fd == -1 case 06/13 guards against:
> the check runs before perf_event_open(), so a group it refuses never reaches
> get_group_fd().
>
> On v3 of Hang's patch, which I posted for him, Namhyung wrote (2026-11-20,
> <awC_aZXD5FBGu4mO@xxxxxxxxxx>):
>
> > I think grouping with tool events would cause more headaches. Probably
> > the simplest fix is to prohibit grouping.
>
> Namhyung, by "prohibit grouping", did you mean that perf stat should refuse
> such a group, or that it should count each event on its own and print a
> value for it? 06/13 does the second. When I wrote v4 I read you as asking
> for the first, and v4 refuses exactly those groups; a group of tool events
> alone, such as -e '{user_time,system_time}', is still accepted.

Right, but there's no reason to group tool events IIUC.

I was afraid that events like '{user_time,instructions,system_time,cycles}'
can complicate parsing and evlist handling. As they cannot be a group,
it'd be easier to reject them with a message instead of adding seemingly
unnecessary complexity.

Thanks,
Namhyung

>
> 07/13 ("perf evlist: Enable tool PMU events when starting a workload")
> fixes the enable_on_exec case my patch does not touch; I would like to see
> it land regardless of how this is settled.
>
> So which should it be: the split in 06/13, or the refusal in v4? If the
> split wins, I will withdraw v4. If the refusal wins, 06/13 would have to
> leave the PERF_PMU_TYPE_TOOL case alone in perf_pmu__is_software() and drop
> the PERF_PMU_KIND checks in evsel__compute_group_pmu_name().
>
> If you would rather leave it to Namhyung, I will go with whatever he says.
> I am asking you because 06/13 is your patch.
>
> Thanks,
> TAKANO Mitsuhiro
>