Re: [PATCH v12] perf stat: Refuse a group mixing tool and kernel events

From: Ian Rogers

Date: Thu Dec 03 2026 - 16:14:55 EST


On Wed, Dec 2, 2026 at 5:33 AM TAKANO Mitsuhiro <takano32@xxxxxxxxx> wrote:
> +hybrid_core_types() {
> + awk 'function bare(name) {
> + gsub(/\/$/, "", name)
> + sub(/^[^\/]*\//, "", name)
> + return name
> + }
> + FNR == NR {
> + sub(/#.*/, "")
> + if ($1 ~ /^[0-9][0-9,.]*$/)
> + counted[bare($(NF))] = 1
> + next
> + }
> + /<not counted>/ {
> + sub(/#.*/, "")
> + if (bare($(NF)) in counted)
> + found = 1
> + }
> + END { exit !found }' "${out}" "${out}"
> +}

Thanks for fixing the get_group_fd() errno handling and the
perf-stat.txt wording I verified the C changes on a hybrid Intel x86
machine (`perf stat -e '{cycles:k,instructions:k}' -- true` now shows
the expected perf_event_paranoid diagnostic, and mixed tool/kernel
groups are cleanly refused).

When testing `stat+tool_group.sh` on that hybrid x86 box (cpu_core on
CPUs 0-15, cpu_atom on CPUs 16-27), I hit two test issues:

1. In `hybrid_core_types()`, perf stat appends `(0.00%)` at the end of
`<not counted>` lines:

<not counted> cpu_atom/cycles/u
(0.00%)
300325 cpu_core/cycles/u

Because `sub(/#.*/, "")` does not strip `(0.00%)`, `$(NF)` evaluates
to `"(0.00%)"` rather than `cpu_atom/cycles/u` (`$3`), so
`hybrid_core_types()` returns false and all four accepted `cycles`
cases fail on hybrid x86. Using `$3` on `<not counted>` lines (or
stripping the trailing `([0-9.]+%)` before `$(NF)`) should fix it.

2. Expanding on Sashiko's `-C 0` comment: once the `cpu/online` regex
is fixed to match ranges like `0-27`, running
`perf stat -C 0 -e '{cycles,duration_time}' -- true` on this hybrid
machine actually hits a pre-existing infinite loop in
`evsel__group_desc()` (`util/evsel.c`), because
`perf_evlist__propagate_maps()` removes `cpu_atom/cycles/` (empty
CPU intersection with `-C 0`) via `list_del_init()` while
`duration_time->core.leader` still points to the removed evsel.
Using an explicit core PMU that covers the chosen CPU (e.g. picking
an online CPU from the PMU's `cpus` file, such as
`cpu_core/cycles/` on `-C 0` or `-C 16` for `cpu_atom`) avoids
triggering that separate libperf bug in this test.

Otherwise the C and documentation changes look good to me.

Thanks,
Ian