Linux Perf Users
 help / color / mirror / Atom feed
From: Chun-Tse Shao <ctshao@google.com>
To: linux-kernel@vger.kernel.org
Cc: Chun-Tse Shao <ctshao@google.com>,
	peterz@infradead.org, mingo@redhat.com,  acme@kernel.org,
	namhyung@kernel.org, mark.rutland@arm.com,
	 alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	irogers@google.com,  adrian.hunter@intel.com,
	james.clark@linaro.org, kan.liang@linux.intel.com,
	 linux-perf-users@vger.kernel.org
Subject: [PATCH] perf stat: Check aliases in should_skip_zero_counter
Date: Fri,  1 May 2026 11:11:05 -0700	[thread overview]
Message-ID: <20260501181129.938256-1-ctshao@google.com> (raw)

Aggregation IDs (e.g. sockets, caches) with event zero counts are hidden
in aggregated modes (like `--per-socket`) because alias merging
aggregates counts but not CPU maps. This causes display logic to skip
aggregation IDs not present in the leader's map.

Instead of mutating CPU maps in `evsel__merge_aggr_counters` (which
could have side effects on shared CPU maps), check aliases in
`should_skip_zero_counter` to ensure all applicable aggregation IDs are
displayed.

Before the fix:
  $ perf stat -e amd_umc/config=0xff/ --per-socket -a -- sleep 1

   Performance counter stats for 'system wide':

  S0       12                  0      amd_umc/config=0xff/

         1.000721604 seconds time elapsed

After the fix:
  $ perf stat -e amd_umc/config=0xff/ --per-socket -a -- sleep 1

   Performance counter stats for 'system wide':

  S0       12                  0      amd_umc/config=0xff/
  S1       12                  0      amd_umc/config=0xff/

         1.000879376 seconds time elapsed

`perf test` looks good too.

Assisted-by: Gemini:gemini-3.1-pro-preview
Signed-off-by: Chun-Tse Shao <ctshao@google.com>
---
 tools/perf/util/stat-display.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index 993f4c4b8f44..c12a3405118a 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -945,6 +945,27 @@ static bool should_skip_zero_counter(struct perf_stat_config *config,
 		if (aggr_cpu_id__equal(id, &own_id))
 			return false;
 	}
+
+	/*
+	 * If the counter is a leader in alias merging, check if the aggr id
+	 * matches any of its aliases.
+	 */
+	if (config->aggr_mode != AGGR_NONE && counter->first_wildcard_match == NULL) {
+		struct evsel *alias;
+
+		evlist__for_each_entry(counter->evlist, alias) {
+			if (alias->first_wildcard_match == counter) {
+				perf_cpu_map__for_each_cpu(cpu, idx, alias->core.cpus) {
+					struct aggr_cpu_id own_id =
+						config->aggr_get_id(config, cpu);
+
+					if (aggr_cpu_id__equal(id, &own_id))
+						return false;
+				}
+			}
+		}
+	}
+
 	return true;
 }
 
-- 
2.54.0.545.g6539524ca2-goog


             reply	other threads:[~2026-05-01 18:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-01 18:11 Chun-Tse Shao [this message]
2026-05-01 18:26 ` [PATCH] perf stat: Check aliases in should_skip_zero_counter sashiko-bot
2026-05-01 19:12 ` Ian Rogers
2026-05-01 21:41   ` Chun-Tse Shao

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=20260501181129.938256-1-ctshao@google.com \
    --to=ctshao@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /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