* [PATCH v1] perf stat: Avoid merging/aggregating metric counts twice
@ 2023-02-09 6:44 Ian Rogers
2023-02-09 19:06 ` Namhyung Kim
0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2023-02-09 6:44 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Ian Rogers, James Clark, Eduard Zingerman, Florian Fischer,
Zhengjun Xing, linux-perf-users, linux-kernel
Cc: Stephane Eranian, Perry Taylor
The added perf_stat_merge_counters combines uncore counters. When
metrics are enabled, the counts are merged into a metric_leader
via the stat-shadow saved_value logic. As the leader now is
passed an aggregated count, it leads to all counters being added
together twice and counts appearing approximately doubled in
metrics.
This change disables the saved_value merging of counts for evsels
that are merged. It is recommended that later changes remove the
saved_value entirely as the two layers of aggregation in the code
is confusing.
Fixes: 942c5593393d ("perf stat: Add perf_stat_merge_counters()")
Reported-by: Perry Taylor <perry.taylor@intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/stat-shadow.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index cadb2df23c87..4cd05d9205e3 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -311,7 +311,7 @@ void perf_stat__update_shadow_stats(struct evsel *counter, u64 count,
update_stats(&v->stats, count);
if (counter->metric_leader)
v->metric_total += count;
- } else if (counter->metric_leader) {
+ } else if (counter->metric_leader && !counter->merged_stat) {
v = saved_value_lookup(counter->metric_leader,
map_idx, true, STAT_NONE, 0, st, rsd.cgrp);
v->metric_total += count;
--
2.39.1.519.gcb327c4b5f-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1] perf stat: Avoid merging/aggregating metric counts twice
2023-02-09 6:44 [PATCH v1] perf stat: Avoid merging/aggregating metric counts twice Ian Rogers
@ 2023-02-09 19:06 ` Namhyung Kim
2023-02-09 21:29 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 3+ messages in thread
From: Namhyung Kim @ 2023-02-09 19:06 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, James Clark,
Eduard Zingerman, Florian Fischer, Zhengjun Xing,
linux-perf-users, linux-kernel, Stephane Eranian, Perry Taylor
Hi Ian,
On Wed, Feb 8, 2023 at 10:45 PM Ian Rogers <irogers@google.com> wrote:
>
> The added perf_stat_merge_counters combines uncore counters. When
> metrics are enabled, the counts are merged into a metric_leader
> via the stat-shadow saved_value logic. As the leader now is
> passed an aggregated count, it leads to all counters being added
> together twice and counts appearing approximately doubled in
> metrics.
>
> This change disables the saved_value merging of counts for evsels
> that are merged. It is recommended that later changes remove the
> saved_value entirely as the two layers of aggregation in the code
> is confusing.
+1
>
> Fixes: 942c5593393d ("perf stat: Add perf_stat_merge_counters()")
> Reported-by: Perry Taylor <perry.taylor@intel.com>
> Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Thanks,
Namhyung
> ---
> tools/perf/util/stat-shadow.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
> index cadb2df23c87..4cd05d9205e3 100644
> --- a/tools/perf/util/stat-shadow.c
> +++ b/tools/perf/util/stat-shadow.c
> @@ -311,7 +311,7 @@ void perf_stat__update_shadow_stats(struct evsel *counter, u64 count,
> update_stats(&v->stats, count);
> if (counter->metric_leader)
> v->metric_total += count;
> - } else if (counter->metric_leader) {
> + } else if (counter->metric_leader && !counter->merged_stat) {
> v = saved_value_lookup(counter->metric_leader,
> map_idx, true, STAT_NONE, 0, st, rsd.cgrp);
> v->metric_total += count;
> --
> 2.39.1.519.gcb327c4b5f-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] perf stat: Avoid merging/aggregating metric counts twice
2023-02-09 19:06 ` Namhyung Kim
@ 2023-02-09 21:29 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-02-09 21:29 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
Alexander Shishkin, Jiri Olsa, James Clark, Eduard Zingerman,
Florian Fischer, Zhengjun Xing, linux-perf-users, linux-kernel,
Stephane Eranian, Perry Taylor
Em Thu, Feb 09, 2023 at 11:06:22AM -0800, Namhyung Kim escreveu:
> On Wed, Feb 8, 2023 at 10:45 PM Ian Rogers <irogers@google.com> wrote:
> > The added perf_stat_merge_counters combines uncore counters. When
> > metrics are enabled, the counts are merged into a metric_leader
> > via the stat-shadow saved_value logic. As the leader now is
> > passed an aggregated count, it leads to all counters being added
> > together twice and counts appearing approximately doubled in
> > metrics.
> > This change disables the saved_value merging of counts for evsels
> > that are merged. It is recommended that later changes remove the
> > saved_value entirely as the two layers of aggregation in the code
> > is confusing.
> +1
'perf stat' code needs help, that I'm sure, its great that you guys are
looking/working at/on it, please continue.
> >
> > Fixes: 942c5593393d ("perf stat: Add perf_stat_merge_counters()")
> > Reported-by: Perry Taylor <perry.taylor@intel.com>
> > Signed-off-by: Ian Rogers <irogers@google.com>
>
> Acked-by: Namhyung Kim <namhyung@kernel.org>
Thanks, applied.
- Arnaldo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-09 21:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-09 6:44 [PATCH v1] perf stat: Avoid merging/aggregating metric counts twice Ian Rogers
2023-02-09 19:06 ` Namhyung Kim
2023-02-09 21:29 ` Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).