Linux Perf Users
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Chun-Tse Shao <ctshao@google.com>
Cc: peterz@infradead.org, mingo@redhat.com, acme@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, sandipan.das@amd.com, leo.yan@arm.com,
	thomas.falcon@intel.com, yang.lee@linux.alibaba.com,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 0/2] perf stat: Fix uncore metric scaling across aggregation modes
Date: Thu, 28 May 2026 12:17:57 -0700	[thread overview]
Message-ID: <ahiU5Te_KR7KRI9Z@google.com> (raw)
In-Reply-To: <20260521201505.124690-1-ctshao@google.com>

On Thu, May 21, 2026 at 01:15:03PM -0700, Chun-Tse Shao wrote:
> This series fixes a scaling issue for metrics (like lpm_miss_lat) across
> different runtime aggregation modes.
> 
> Uncore metrics currently use `source_count` to scale events. However,
> `source_count` returns the total uncore unit count regardless of the
> selected aggregation mode. When evaluating metrics in different
> aggregation mode other than `--per-socket`, this incorrectly divides
> aggregated uncore events against the total uncore count rather than the
> uncores belonging to the aggregation, leading to wrong metric results.
> 
> To fix this, we:
> 1. Introduce the aggr_nr() keyword to the metric parser, which
> dynamically resolves to the active units in the current aggregation
> group (`gr->nr`).
> 
> 2. Update the python metrics to use `aggr_nr` instead of `source_count`,
> ensuring correct scaling across all runtime aggregation boundaries.
> 
> Before the fix (incorrect low latency in global mode):
>   $ perf stat -M lpm_miss_lat --metric-only -a -j -- sleep 1
>   {"ns  lpm_miss_lat_rem" : "122.8", "ns  lpm_miss_lat_loc" : "114.5"}
>   $ perf stat -M lpm_miss_lat --per-socket --metric-only -a -j -- sleep 1
>   {"socket" : "S0", "ns  lpm_miss_lat_rem" : "232.1", "ns  lpm_miss_lat_loc" : "278.2"}
>   {"socket" : "S1", "ns  lpm_miss_lat_rem" : "233.9", "ns  lpm_miss_lat_loc" : "257.5"}
> 
> After the fix (correct scaled latency in all aggregation modes):
>   $ perf stat -M lpm_miss_lat --metric-only -a -j -- sleep 1
>   {"ns  lpm_miss_lat_rem" : "231.7", "ns  lpm_miss_lat_loc" : "245.0"}
>   $ perf stat -M lpm_miss_lat --per-socket --metric-only -a -j -- sleep 1
>   {"socket" : "S0", "ns  lpm_miss_lat_rem" : "238.3", "ns  lpm_miss_lat_loc" : "249.4"}
>   {"socket" : "S1", "ns  lpm_miss_lat_rem" : "259.1", "ns  lpm_miss_lat_loc" : "253.1"}
> 
> v3:
>   Fixed based on Sashiko review:
>   - Removed the unnecessary, copied `redefined-builtin` pylint-disable
>     comment from `aggr_nr` definition inside `metric.py`.
> 
> v2: lore.kernel.org/20260521035941.3860145-1-ctshao@google.com
>   Fixed based on Sashiko review:
>   - Fixed `aggr_nr` setting when an uncore event fails to run
>     (counts.run == 0) to explicitly set it to 0 instead of defaulting to
>     1.
>   - Accumulated `aggr_nr` when multiple unmerged PMU events are
>     associated with the same metric ID to prevent incorrect scaling
>     across active sockets.
>   - Removed unused `List` import from `typing` in `intel_metrics.py`.
> 
> v1: lore.kernel.org/20260520180032.3045144-1-ctshao@google.com
> 
> Chun-Tse Shao (2):
>   perf stat: Add aggr_nr metric parser support
>   perf stat: Use aggr_nr scaling for Intel uncore miss latency metrics

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung

> 
>  tools/perf/pmu-events/intel_metrics.py |  6 +++---
>  tools/perf/pmu-events/metric.py        |  9 +++++++--
>  tools/perf/util/expr.c                 | 26 ++++++++++++++++++++++----
>  tools/perf/util/expr.h                 |  6 +++++-
>  tools/perf/util/expr.l                 |  1 +
>  tools/perf/util/expr.y                 | 24 +++++++++++++++++-------
>  tools/perf/util/stat-shadow.c          |  6 +++++-
>  7 files changed, 60 insertions(+), 18 deletions(-)
> 
> --
> 2.54.0.746.g67dd491aae-goog
> 

      parent reply	other threads:[~2026-05-28 19:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 20:15 [PATCH v3 0/2] perf stat: Fix uncore metric scaling across aggregation modes Chun-Tse Shao
2026-05-21 20:15 ` [PATCH v3 1/2] perf stat: Add aggr_nr metric parser support Chun-Tse Shao
2026-05-21 20:15 ` [PATCH v3 2/2] perf stat: Use aggr_nr scaling for Intel uncore miss latency metrics Chun-Tse Shao
2026-05-21 21:08   ` sashiko-bot
2026-05-21 22:01     ` Chun-Tse Shao
2026-05-27 19:10 ` [PATCH v3 0/2] perf stat: Fix uncore metric scaling across aggregation modes Chen, Zide
2026-05-28 19:17 ` Namhyung Kim [this message]

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=ahiU5Te_KR7KRI9Z@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ctshao@google.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=leo.yan@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sandipan.das@amd.com \
    --cc=thomas.falcon@intel.com \
    --cc=yang.lee@linux.alibaba.com \
    /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