Skip to contentSkip to conversation

perf stat: Avoid merging/aggregating metric counts twice

PATCH Applied Ian Rogers 3 participants 3 messages Feb 9, 2023 perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf stat: Avoid merging/aggregating metric counts twice

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()")
---
 tools/perf/util/stat-shadow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/stat-shadow.c +1 -1
index cadb2df23c87..4cd05d9205e3 100644
@@ -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;
Signature · 1 line
2.39.1.519.gcb327c4b5f-goog
maintainer Acked-by on v1 1/1
#1 lore raw

Hi Ian,

Quoted 8 lines · Ian Rogers

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.

Quoted 4 lines

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

Quoted 4 lines
Fixes 942c5593393d ("perf stat: Add perf_stat_merge_counters()")

Thanks,
Namhyung

Quoted 20 lines
---
 tools/perf/util/stat-shadow.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/stat-shadow.c +1 -2
index cadb2df23c87..4cd05d9205e3 100644
@@ -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

maintainer Applied
#2 lore raw

Em Thu, Feb 09, 2023 at 11:06:22AM -0800, Namhyung Kim escreveu:

Quoted 9 lines · Ian Rogers
Quoted 7 lines

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.

Quoted 6 lines
Quoted 4 lines

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.

Quoted 6 lines
Quoted 4 lines
Fixes 942c5593393d ("perf stat: Add perf_stat_merge_counters()")

Thanks, applied.

- Arnaldo