From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v1 2/4] perf stat: Don't corrupt zero or prev_raw_counts on skipped per-pkg CPUs
Date: Wed, 18 Nov 2026 08:22:02 +0000 [thread overview]
Message-ID: <sashiko-outbox-220428@kernel.org> (raw)
In-Reply-To: <20261118075516.1278903-3-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf stat: zero count on skipped CPUs in
process_counter_values() fails aggr
--
commit 90a7348e9c069c01e179e728774f2e1d53d53fb3
Author: Ian Rogers <irogers@google.com>
perf stat: Don't corrupt zero or prev_raw_counts on skipped per-pkg CPUs
This commit replaces the static zero perf_counts_values structure in
process_counter_values() with a stack variable and computes interval deltas
before substituting zero for skipped per-package CPUs.
> diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
> index 6da3dbbde0e2a..267e280c5aa23 100644
> --- a/tools/perf/util/stat.c
> +++ b/tools/perf/util/stat.c
> @@ -398,7 +398,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
> struct perf_counts_values *count)
> {
> struct perf_stat_evsel *ps = evsel->stats;
> - static struct perf_counts_values zero;
> + struct perf_counts_values zero = {};
> bool skip = false;
>
> if (check_per_pkg(evsel, count, cpu_map_idx, &skip)) {
> @@ -406,12 +406,12 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
> return -1;
> }
>
> - if (skip)
> - count = &zero;
> -
> if (!evsel->snapshot)
> evsel__compute_deltas(evsel, cpu_map_idx, thread, count);
> - perf_counts_values__scale(count, config->scale, NULL);
> + if (skip)
> + count = &zero;
> + else
> + perf_counts_values__scale(count, config->scale, NULL);
[Severity: Medium]
Should process_counter_values() return 0 when skip is true instead of
falling through with count = &zero?
In non-global aggregation modes such as AGGR_SOCKET (--per-socket) or
AGGR_DIE (--per-die), a skipped secondary CPU maps to the same ps_aggr entry
as the first CPU in that package or die:
tools/perf/util/stat.c:process_counter_values() {
...
ps_aggr = &ps->aggr[i];
ps_aggr->nr++;
...
if (evsel__count_has_error(evsel, count, config) && !ps_aggr->failed) {
ps_aggr->counts.val = 0;
ps_aggr->counts.ena = 0;
ps_aggr->counts.run = 0;
ps_aggr->failed = true;
}
...
}
Because zero has ena == 0 and run == 0, evsel__count_has_error() returns
true for non-cgroup events, wiping out the package count accumulated from
the primary CPU and marking the bucket failed (<not counted>) while also
inflating ps_aggr->nr. In interval mode, where underflow previously gave
the static zero structure non-zero ena and run after the first interval,
this regression causes every subsequent interval to fail too.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118075516.1278903-1-irogers@google.com?part=2
next prev parent reply other threads:[~2026-11-18 8:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 7:55 [PATCH v1 0/4] perf tools: Fix thread cache race, stat per-pkg delta bug, and memory leaks Ian Rogers
2026-11-18 7:55 ` [PATCH v1 1/4] perf threads: Don't resurrect removed threads in last_match Ian Rogers
2026-11-18 8:03 ` sashiko-bot
2026-11-18 7:55 ` [PATCH v1 2/4] perf stat: Don't corrupt zero or prev_raw_counts on skipped per-pkg CPUs Ian Rogers
2026-11-18 8:22 ` sashiko-bot [this message]
2026-11-18 7:55 ` [PATCH v1 3/4] perf metricgroup: Fix realloc() leaks in resolve_metric() and __add_metric() Ian Rogers
2026-11-18 7:58 ` sashiko-bot
2026-11-18 7:55 ` [PATCH v1 4/4] perf pmu: Free alias on error paths in perf_pmu__new_alias() Ian Rogers
2026-11-18 7:59 ` 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-220428@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