From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 23/30] perf metricgroup: Share metric events by their counter encoding
Date: Fri, 13 Nov 2026 20:59:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-213687@kernel.org> (raw)
In-Reply-To: <20261113195335.2865725-24-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf metricgroup: counter_key__equal() ignores evsel CPU mask
--
commit 0da7bf02bed3bcc6d69ab37b6322595a7c6b2573
Author: Ian Rogers <irogers@google.com>
perf metricgroup: Share metric events by their counter encoding
This commit replaces identifier-name metric event sharing with an evsel
matcher that compares counter encodings, modifiers, and cgroups so metrics
can share equivalent events across expressions and with events already in
the evlist.
> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> index f25709750c3e1..f4a2b280091cd 100644
> --- a/tools/perf/util/metricgroup.c
> +++ b/tools/perf/util/metricgroup.c
[ ... ]
> @@ -471,6 +479,512 @@ int metricgroup__for_each_metric(struct perf_pmus *pmus, const struct pmu_metric
> return pmu_for_each_sys_metric(metricgroup__sys_event_iter, &sys_data);
> }
>
> +/*
> + * A key identifying the counter an evsel programs, used to find evsels counting
> + * the same thing, such as when metrics share events.
> + */
> +struct counter_key {
> + /** @pmu_name: Name of the evsel's PMU, or NULL if unknown. */
> + const char *pmu_name;
> + /** @cgrp: The cgroup the evsel counts. */
> + const struct cgroup *cgrp;
[ ... ]
> +static void evsel_matcher__key(struct evsel_matcher *matcher, struct evsel *evsel,
> + struct counter_key *key)
> +{
> + struct perf_pmu *pmu = evsel__find_pmu(evsel);
> +
> + counter_key__init_attr(key, pmu ? pmu->name : NULL, &evsel->core.attr);
> + key->cgrp = evsel->cgrp;
> + if (evsel->percore)
> + key->modifiers |= COUNTER_KEY_MOD_PERCORE;
> + if (evsel__is_retire_lat(evsel))
> + key->modifiers |= COUNTER_KEY_MOD_RETIRE_LAT;
> + if (evsel->precise_max)
> + key->modifiers |= COUNTER_KEY_MOD_PRECISE_MAX;
> + if (evsel->bpf_counter)
> + key->modifiers |= COUNTER_KEY_MOD_BPF;
> + if (key->type == PERF_TYPE_HARDWARE && pmu && pmu->is_core)
> + legacy_hw_key(matcher, pmu->name, key->config, key);
> +}
> +
> +/* Do @a and @b count the same thing? */
> +static bool counter_key__equal(const struct counter_key *a, const struct counter_key *b)
> +{
> + if (a->type != b->type || a->config != b->config ||
> + a->config1 != b->config1 || a->config2 != b->config2 ||
> + a->config3 != b->config3 || a->config4 != b->config4)
> + return false;
> +
> + if ((a->type == PERF_TYPE_RAW || a->type >= PERF_TYPE_MAX) &&
> + !a->pmu_name != !b->pmu_name)
> + return false;
> +
> + if (a->pmu_name && b->pmu_name && strcmp(a->pmu_name, b->pmu_name))
> + return false;
> +
> + return a->exclude == b->exclude && a->modifiers == b->modifiers &&
> + a->precise_ip == b->precise_ip && a->cgrp == b->cgrp;
> +}
[Severity: Medium]
Should counter_key also compare evsel->core.cpus (for example with
perf_cpu_map__equal())?
On Intel hybrid platforms, JSON metrics specify per-PMU CPU restrictions
on shared PMUs, such as msr/tsc,cpu=cpu_core/, msr/tsc,cpu=cpu_atom/, and
unrestricted msr/tsc/. Because parse_events_add_pmu() stores the cpu=
term in evsel->core.cpus without changing perf_event_attr or pmu_name,
counter_key__equal() treats these events as identical and
metric__adopt_events() merges them into whichever evsel was added first,
causing the second metric to read counts from the wrong CPU subset.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261113195335.2865725-1-irogers@google.com?part=23
next prev parent reply other threads:[~2026-11-13 20:59 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 19:53 [PATCH v2 00/30] perf: Per-env PMUs, metric event sharing, and recorded event metrics Ian Rogers
2026-11-13 19:53 ` [PATCH v2 01/30] perf pmus: Don't skip core PMUs as duplicates Ian Rogers
2026-11-13 20:04 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 02/30] perf script: Fix metrics computed from samples Ian Rogers
2026-11-13 20:05 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 03/30] perf script: Don't drop metric samples for CPUs missing from the evsel Ian Rogers
2026-11-13 20:02 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 04/30] perf metricgroup: Don't prefer tool events for displaying a metric Ian Rogers
2026-11-13 19:59 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 05/30] perf env: Make lazy perf_env initialization thread-safe Ian Rogers
2026-11-13 20:05 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 06/30] perf env: Add host_env() singleton Ian Rogers
2026-11-13 20:47 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 07/30] perf pmu: Add from_env parameter to perf_pmu__init() Ian Rogers
2026-11-13 20:10 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 08/30] perf pmus: Introduce struct perf_pmus and perf_env__pmus() Ian Rogers
2026-11-13 20:36 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 09/30] perf pmus: Pass struct perf_pmus to find helpers Ian Rogers
2026-11-13 20:11 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 10/30] perf pmus: Pass struct perf_pmus to scan helpers Ian Rogers
2026-11-13 20:06 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 11/30] perf pmu-events: Add e_machine to struct pmu_events_map Ian Rogers
2026-11-13 20:12 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 12/30] perf pmu-events: Pass e_machine to find_core_*_table() Ian Rogers
2026-11-13 20:05 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 13/30] perf header: Pass e_machine to strcmp_cpuid_str() Ian Rogers
2026-11-13 20:01 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 14/30] perf header: Support CPUID matching across all architectures Ian Rogers
2026-11-13 20:05 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 15/30] perf test: Make the CPUID matching test architecture independent Ian Rogers
2026-11-13 20:02 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 16/30] perf test: Add CPUID matching tests for other architectures Ian Rogers
2026-11-13 20:03 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 17/30] perf dwarf-regs: Add e_machine__same_arch() Ian Rogers
2026-11-13 20:00 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 18/30] perf metricgroup: Pass struct perf_pmus to metricgroup__for_each_metric() Ian Rogers
2026-11-13 20:37 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 19/30] perf metricgroup: Move matching of metrics to recorded events from perf script Ian Rogers
2026-11-13 20:59 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 20/30] perf parse-events: Decode metric-id terms when adding events Ian Rogers
2026-11-13 20:33 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 21/30] perf evsel: Generalize metric_id to a set of metric_ids Ian Rogers
2026-11-13 20:31 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 22/30] perf pmu: Add perf_pmu__for_each_name_from_config() Ian Rogers
2026-11-13 20:13 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 23/30] perf metricgroup: Share metric events by their counter encoding Ian Rogers
2026-11-13 20:59 ` sashiko-bot [this message]
2026-11-13 19:53 ` [PATCH v2 24/30] perf stat: Share events between metrics and command line events Ian Rogers
2026-11-13 20:14 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 25/30] perf pmus: Add perf_pmus__read_from_env() Ian Rogers
2026-11-13 21:05 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 26/30] perf metricgroup: Improve matching of metrics to recorded events Ian Rogers
2026-11-13 20:37 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 27/30] perf metricgroup: Add metricgroup__add_recorded_metrics() Ian Rogers
2026-11-13 20:42 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 28/30] perf stat report: Display metrics for recorded events Ian Rogers
2026-11-13 20:44 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 29/30] perf script: Display metrics for perf stat record data Ian Rogers
2026-11-13 20:47 ` sashiko-bot
2026-11-13 19:53 ` [PATCH v2 30/30] perf test: Add stat record metrics test Ian Rogers
2026-11-13 20:14 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-213687@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox