Skip to contentSkip to conversation

perf stat: Fix uncore aggregation number

PATCH Superseded Chun-Tse Shao 3 participants 10 messages Jun 11, 2025 – Jun 24, 2025 perf events

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf stat: Fix uncore aggregation number

Follow up:
lore.kernel.org/CAP-5=fVDF4-qYL1Lm7efgiHk7X=_nw_nEFMBZFMcsnOOJgX4Kg@mail.gmail.com/

The patch adds unit aggregation during evsel merge the aggregated uncore counters.

Tested on a 2-socket machine with SNC3, uncore_imc_[0-11] and cpumask="0,120"
Before:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

       1.001085024 S0        1         9615386315      clockticks
       1.001085024 S1        1         9614287448      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        1         3205726984      clockticks
       1.001029867 N1        1         3205444421      clockticks
       1.001029867 N2        1         3205234018      clockticks
       1.001029867 N3        1         3205224660      clockticks
       1.001029867 N4        1         3205207213      clockticks
       1.001029867 N5        1         3205528246      clockticks
After:
  perf stat -e clockticks -I 1000 --per-socket
  #           time socket cpus             counts unit events
       1.001022937 S0       12         9621463177      clockticks
       1.001022937 S1       12         9619804949      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        4         3206782080      clockticks
       1.001029867 N1        4         3207025354      clockticks
       1.001029867 N2        4         3207067946      clockticks
       1.001029867 N3        4         3206871733      clockticks
       1.001029867 N4        4         3206199005      clockticks
       1.001029867 N5        4         3205525058      clockticks
---
 tools/perf/util/stat.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/stat.c +1 -0
index 355a7d5c8ab8..52266d773353 100644
@@ -527,6 +527,7 @@ static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias)
 		struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts;
 
 		/* NB: don't increase aggr.nr for aliases */
+		ps_a->aggr[i].nr += ps_b->aggr[i].nr;
 
 		aggr_counts_a->val += aggr_counts_b->val;
 		aggr_counts_a->ena += aggr_counts_b->ena;
Signature · 1 line
2.50.0.rc1.591.g9c95f17f64-goog
maintainer Acked-by on v1 1/1
#1 lore raw

Hello,

Quoted 35 lines · Chun-Tse Shao

Follow up:
lore.kernel.org/CAP-5=fVDF4-qYL1Lm7efgiHk7X=_nw_nEFMBZFMcsnOOJgX4Kg@mail.gmail.com/

The patch adds unit aggregation during evsel merge the aggregated uncore counters.

Tested on a 2-socket machine with SNC3, uncore_imc_[0-11] and cpumask="0,120"
Before:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

       1.001085024 S0        1         9615386315      clockticks
       1.001085024 S1        1         9614287448      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        1         3205726984      clockticks
       1.001029867 N1        1         3205444421      clockticks
       1.001029867 N2        1         3205234018      clockticks
       1.001029867 N3        1         3205224660      clockticks
       1.001029867 N4        1         3205207213      clockticks
       1.001029867 N5        1         3205528246      clockticks
After:
  perf stat -e clockticks -I 1000 --per-socket
  #           time socket cpus             counts unit events
       1.001022937 S0       12         9621463177      clockticks
       1.001022937 S1       12         9619804949      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        4         3206782080      clockticks
       1.001029867 N1        4         3207025354      clockticks
       1.001029867 N2        4         3207067946      clockticks
       1.001029867 N3        4         3206871733      clockticks
       1.001029867 N4        4         3206199005      clockticks
       1.001029867 N5        4         3205525058      clockticks
Quoted 2 lines

tools/perf/util/stat.c static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias) · line 529

Quoted 12 lines
---
 tools/perf/util/stat.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/stat.c +0 -0
index 355a7d5c8ab8..52266d773353 100644
@@ -527,6 +527,7 @@ static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias)
 		struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts;
 
 		/* NB: don't increase aggr.nr for aliases */

Probably we need to delete this comment.

Thanks,
namhyung

Quoted 7 lines
tools/perf/util/stat.c +1 -0
+		ps_a->aggr[i].nr += ps_b->aggr[i].nr;
 
 		aggr_counts_a->val += aggr_counts_b->val;
 		aggr_counts_a->ena += aggr_counts_b->ena;
Signature · 1 line
2.50.0.rc1.591.g9c95f17f64-goog
reviewer Tested-by on v1 1/1
#2 lore raw
In reply to Chun-Tse Shao
Quoted 22 lines · Chun-Tse Shao

Follow up:
lore.kernel.org/CAP-5=fVDF4-qYL1Lm7efgiHk7X=_nw_nEFMBZFMcsnOOJgX4Kg@mail.gmail.com/

The patch adds unit aggregation during evsel merge the aggregated uncore counters.

Tested on a 2-socket machine with SNC3, uncore_imc_[0-11] and cpumask="0,120"
Before:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

       1.001085024 S0        1         9615386315      clockticks
       1.001085024 S1        1         9614287448      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        1         3205726984      clockticks
       1.001029867 N1        1         3205444421      clockticks
       1.001029867 N2        1         3205234018      clockticks
       1.001029867 N3        1         3205224660      clockticks
       1.001029867 N4        1         3205207213      clockticks
       1.001029867 N5        1         3205528246      clockticks
Quoted 3 lines

After:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

I wonder if there is a better column heading than "cpus" given that these are imc PMUs.

Quoted 11 lines
       1.001022937 S0       12         9621463177      clockticks
       1.001022937 S1       12         9619804949      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        4         3206782080      clockticks
       1.001029867 N1        4         3207025354      clockticks
       1.001029867 N2        4         3207067946      clockticks
       1.001029867 N3        4         3206871733      clockticks
       1.001029867 N4        4         3206199005      clockticks
       1.001029867 N5        4         3205525058      clockticks
Quoted 2 lines

Thanks,
Ian

Quoted 19 lines
---
 tools/perf/util/stat.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/stat.c +1 -1
index 355a7d5c8ab8..52266d773353 100644
@@ -527,6 +527,7 @@ static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias)
                struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts;
 
                /* NB: don't increase aggr.nr for aliases */
+               ps_a->aggr[i].nr += ps_b->aggr[i].nr;
 
                aggr_counts_a->val += aggr_counts_b->val;
                aggr_counts_a->ena += aggr_counts_b->ena;
--

2.50.0.rc1.591.g9c95f17f64-goog

author Acked-by Namhyung Kim
#3 lore raw

Thanks for your test, Ian!

I wonder if nr_pmus makes sense, since the column would be shared with multiple different pmus. WDYT?

-CT

Quoted 28 lines · Ian Rogers
Quoted 22 lines · Chun-Tse Shao

Follow up:
lore.kernel.org/CAP-5=fVDF4-qYL1Lm7efgiHk7X=_nw_nEFMBZFMcsnOOJgX4Kg@mail.gmail.com/

The patch adds unit aggregation during evsel merge the aggregated uncore counters.

Tested on a 2-socket machine with SNC3, uncore_imc_[0-11] and cpumask="0,120"
Before:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

       1.001085024 S0        1         9615386315      clockticks
       1.001085024 S1        1         9614287448      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        1         3205726984      clockticks
       1.001029867 N1        1         3205444421      clockticks
       1.001029867 N2        1         3205234018      clockticks
       1.001029867 N3        1         3205224660      clockticks
       1.001029867 N4        1         3205207213      clockticks
       1.001029867 N5        1         3205528246      clockticks
Quoted 3 lines

After:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

Quoted 16 lines

I wonder if there is a better column heading than "cpus" given that these are imc PMUs.

Quoted 13 lines
       1.001022937 S0       12         9621463177      clockticks
       1.001022937 S1       12         9619804949      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        4         3206782080      clockticks
       1.001029867 N1        4         3207025354      clockticks
       1.001029867 N2        4         3207067946      clockticks
       1.001029867 N3        4         3206871733      clockticks
       1.001029867 N4        4         3206199005      clockticks
       1.001029867 N5        4         3205525058      clockticks

Added Namhyung's ack from the previous email.

Quoted 25 lines

Thanks,
Ian

Quoted 19 lines
---
 tools/perf/util/stat.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/stat.c +1 -1
index 355a7d5c8ab8..52266d773353 100644
@@ -527,6 +527,7 @@ static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias)
                struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts;
 
                /* NB: don't increase aggr.nr for aliases */
+               ps_a->aggr[i].nr += ps_b->aggr[i].nr;
 
                aggr_counts_a->val += aggr_counts_b->val;
                aggr_counts_a->ena += aggr_counts_b->ena;
--

2.50.0.rc1.591.g9c95f17f64-goog

reviewer
#4 lore raw
Quoted 5 lines · Chun-Tse Shao

Thanks for your test, Ian!

I wonder if nr_pmus makes sense, since the column would be shared with multiple different pmus. WDYT?

So each PMU in sysfs has a cpumask that specifies which CPUs perf should pass to perf_event_open. For example, on a two socket machine the cpumask will typically have the first CPU of each socket. If the cpumask (or cpus) file isn't present then the cpumask is implicitly all online CPUs. Given that the aggregation number is the number of CPUs in the cpumask multiplied by the number of PMUs, I think the most neutral name is probably "counters" possibly shortened down to "ctrs". I suspect others have better suggestions :-)

Thanks,
Ian

Quoted 76 lines

-CT

Quoted 28 lines · Ian Rogers
Quoted 22 lines · Chun-Tse Shao

Follow up:
lore.kernel.org/CAP-5=fVDF4-qYL1Lm7efgiHk7X=_nw_nEFMBZFMcsnOOJgX4Kg@mail.gmail.com/

The patch adds unit aggregation during evsel merge the aggregated uncore counters.

Tested on a 2-socket machine with SNC3, uncore_imc_[0-11] and cpumask="0,120"
Before:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

       1.001085024 S0        1         9615386315      clockticks
       1.001085024 S1        1         9614287448      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        1         3205726984      clockticks
       1.001029867 N1        1         3205444421      clockticks
       1.001029867 N2        1         3205234018      clockticks
       1.001029867 N3        1         3205224660      clockticks
       1.001029867 N4        1         3205207213      clockticks
       1.001029867 N5        1         3205528246      clockticks
Quoted 3 lines

After:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

Quoted 16 lines

I wonder if there is a better column heading than "cpus" given that these are imc PMUs.

Quoted 13 lines
       1.001022937 S0       12         9621463177      clockticks
       1.001022937 S1       12         9619804949      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        4         3206782080      clockticks
       1.001029867 N1        4         3207025354      clockticks
       1.001029867 N2        4         3207067946      clockticks
       1.001029867 N3        4         3206871733      clockticks
       1.001029867 N4        4         3206199005      clockticks
       1.001029867 N5        4         3205525058      clockticks

Added Namhyung's ack from the previous email.

Quoted 25 lines

Thanks,
Ian

Quoted 19 lines
---
 tools/perf/util/stat.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/stat.c +1 -1
index 355a7d5c8ab8..52266d773353 100644
@@ -527,6 +527,7 @@ static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias)
                struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts;
 
                /* NB: don't increase aggr.nr for aliases */
+               ps_a->aggr[i].nr += ps_b->aggr[i].nr;
 
                aggr_counts_a->val += aggr_counts_b->val;
                aggr_counts_a->ena += aggr_counts_b->ena;
--

2.50.0.rc1.591.g9c95f17f64-goog

#5 lore raw

Hi Ian, I actually renamed it to aggr_nr in v2 patch so it should be better aligned to json mode, which is using aggregate-nunber. But anyway I think any name other than cpus is better.
v2 patch: lore.kernel.org/[email protected]

Thanks,
CT

Quoted 96 lines · Ian Rogers
Quoted 5 lines · Chun-Tse Shao

Thanks for your test, Ian!

I wonder if nr_pmus makes sense, since the column would be shared with multiple different pmus. WDYT?

So each PMU in sysfs has a cpumask that specifies which CPUs perf should pass to perf_event_open. For example, on a two socket machine the cpumask will typically have the first CPU of each socket. If the cpumask (or cpus) file isn't present then the cpumask is implicitly all online CPUs. Given that the aggregation number is the number of CPUs in the cpumask multiplied by the number of PMUs, I think the most neutral name is probably "counters" possibly shortened down to "ctrs". I suspect others have better suggestions :-)

Thanks,
Ian

Quoted 76 lines

-CT

Quoted 28 lines · Ian Rogers
Quoted 22 lines · Chun-Tse Shao

Follow up:
lore.kernel.org/CAP-5=fVDF4-qYL1Lm7efgiHk7X=_nw_nEFMBZFMcsnOOJgX4Kg@mail.gmail.com/

The patch adds unit aggregation during evsel merge the aggregated uncore counters.

Tested on a 2-socket machine with SNC3, uncore_imc_[0-11] and cpumask="0,120"
Before:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

       1.001085024 S0        1         9615386315      clockticks
       1.001085024 S1        1         9614287448      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        1         3205726984      clockticks
       1.001029867 N1        1         3205444421      clockticks
       1.001029867 N2        1         3205234018      clockticks
       1.001029867 N3        1         3205224660      clockticks
       1.001029867 N4        1         3205207213      clockticks
       1.001029867 N5        1         3205528246      clockticks
Quoted 3 lines

After:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

Quoted 16 lines

I wonder if there is a better column heading than "cpus" given that these are imc PMUs.

Quoted 13 lines
       1.001022937 S0       12         9621463177      clockticks
       1.001022937 S1       12         9619804949      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        4         3206782080      clockticks
       1.001029867 N1        4         3207025354      clockticks
       1.001029867 N2        4         3207067946      clockticks
       1.001029867 N3        4         3206871733      clockticks
       1.001029867 N4        4         3206199005      clockticks
       1.001029867 N5        4         3205525058      clockticks

Added Namhyung's ack from the previous email.

Quoted 25 lines

Thanks,
Ian

Quoted 19 lines
---
 tools/perf/util/stat.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/stat.c +1 -1
index 355a7d5c8ab8..52266d773353 100644
@@ -527,6 +527,7 @@ static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias)
                struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts;
 
                /* NB: don't increase aggr.nr for aliases */
+               ps_a->aggr[i].nr += ps_b->aggr[i].nr;
 
                aggr_counts_a->val += aggr_counts_b->val;
                aggr_counts_a->ena += aggr_counts_b->ena;
--

2.50.0.rc1.591.g9c95f17f64-goog

maintainer
#6 lore raw

Hi CT,

Quoted 4 lines · Chun-Tse Shao

Hi Ian, I actually renamed it to aggr_nr in v2 patch so it should be better aligned to json mode, which is using aggregate-nunber. But anyway I think any name other than cpus is better.
v2 patch: lore.kernel.org/[email protected]

I think "aggregation-count" is a better name, maybe abbreviated to "ag_cnt". Can we rename the JSON as well? I'm not sure if it's documented somewhere.

Thanks,
Namhyung

Quoted 99 lines · Ian Rogers
Quoted 96 lines · Chun-Tse Shao
Quoted 5 lines

Thanks for your test, Ian!

I wonder if nr_pmus makes sense, since the column would be shared with multiple different pmus. WDYT?

So each PMU in sysfs has a cpumask that specifies which CPUs perf should pass to perf_event_open. For example, on a two socket machine the cpumask will typically have the first CPU of each socket. If the cpumask (or cpus) file isn't present then the cpumask is implicitly all online CPUs. Given that the aggregation number is the number of CPUs in the cpumask multiplied by the number of PMUs, I think the most neutral name is probably "counters" possibly shortened down to "ctrs". I suspect others have better suggestions :-)

Thanks,
Ian

Quoted 76 lines

-CT

Quoted 28 lines · Ian Rogers
Quoted 22 lines · Chun-Tse Shao

Follow up:
lore.kernel.org/CAP-5=fVDF4-qYL1Lm7efgiHk7X=_nw_nEFMBZFMcsnOOJgX4Kg@mail.gmail.com/

The patch adds unit aggregation during evsel merge the aggregated uncore counters.

Tested on a 2-socket machine with SNC3, uncore_imc_[0-11] and cpumask="0,120"
Before:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

       1.001085024 S0        1         9615386315      clockticks
       1.001085024 S1        1         9614287448      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        1         3205726984      clockticks
       1.001029867 N1        1         3205444421      clockticks
       1.001029867 N2        1         3205234018      clockticks
       1.001029867 N3        1         3205224660      clockticks
       1.001029867 N4        1         3205207213      clockticks
       1.001029867 N5        1         3205528246      clockticks
Quoted 3 lines

After:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

Quoted 16 lines

I wonder if there is a better column heading than "cpus" given that these are imc PMUs.

Quoted 13 lines
       1.001022937 S0       12         9621463177      clockticks
       1.001022937 S1       12         9619804949      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        4         3206782080      clockticks
       1.001029867 N1        4         3207025354      clockticks
       1.001029867 N2        4         3207067946      clockticks
       1.001029867 N3        4         3206871733      clockticks
       1.001029867 N4        4         3206199005      clockticks
       1.001029867 N5        4         3205525058      clockticks

Added Namhyung's ack from the previous email.

Quoted 25 lines

Thanks,
Ian

Quoted 19 lines
---
 tools/perf/util/stat.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/stat.c +1 -1
index 355a7d5c8ab8..52266d773353 100644
@@ -527,6 +527,7 @@ static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias)
                struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts;
 
                /* NB: don't increase aggr.nr for aliases */
+               ps_a->aggr[i].nr += ps_b->aggr[i].nr;
 
                aggr_counts_a->val += aggr_counts_b->val;
                aggr_counts_a->ena += aggr_counts_b->ena;
--

2.50.0.rc1.591.g9c95f17f64-goog

reviewer
#7 lore raw
Quoted 4 lines · Namhyung Kim

Hi CT,

On Thu, Jun 12, 2025 at 03:55:59PM -0700, Chun-Tse Shao wrote:

Quoted 8 lines
Quoted 4 lines

Hi Ian, I actually renamed it to aggr_nr in v2 patch so it should be better aligned to json mode, which is using aggregate-nunber. But anyway I think any name other than cpus is better.
v2 patch: lore.kernel.org/[email protected]

I think "aggregation-count" is a better name, maybe abbreviated to "ag_cnt". Can we rename the JSON as well? I'm not sure if it's documented somewhere.

Fwiw, I still think "counters" is a clearer, more intention revealing definition than "aggregation count" or "aggregation number". The term counter appears in the perf-stat and perf_event_open man page. In the perf-stat man page we have a pattern of:

--per-XXX
Aggregate counts per XXX for system-wide mode measurements. This is a useful mode to .... To enable this mode, use --per-XXX in addition to -a. (system-wide). The output includes the ...
This is useful to gauge the amount of aggregation.

It seems that the aggregated value of the counters could be confused for being an "aggregation count" or "aggregation number" given the man page definition. I think "counters" to some extent avoids this, we giving the number of counters aggregated. The perf-stat man page could certainly be clearer :-)

Thanks,
Ian

Quoted 102 lines

Thanks,
Namhyung

Quoted 99 lines · Ian Rogers
Quoted 96 lines · Chun-Tse Shao
Quoted 5 lines

Thanks for your test, Ian!

I wonder if nr_pmus makes sense, since the column would be shared with multiple different pmus. WDYT?

So each PMU in sysfs has a cpumask that specifies which CPUs perf should pass to perf_event_open. For example, on a two socket machine the cpumask will typically have the first CPU of each socket. If the cpumask (or cpus) file isn't present then the cpumask is implicitly all online CPUs. Given that the aggregation number is the number of CPUs in the cpumask multiplied by the number of PMUs, I think the most neutral name is probably "counters" possibly shortened down to "ctrs". I suspect others have better suggestions :-)

Thanks,
Ian

Quoted 76 lines

-CT

Quoted 28 lines · Ian Rogers
Quoted 22 lines · Chun-Tse Shao

Follow up:
lore.kernel.org/CAP-5=fVDF4-qYL1Lm7efgiHk7X=_nw_nEFMBZFMcsnOOJgX4Kg@mail.gmail.com/

The patch adds unit aggregation during evsel merge the aggregated uncore counters.

Tested on a 2-socket machine with SNC3, uncore_imc_[0-11] and cpumask="0,120"
Before:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

       1.001085024 S0        1         9615386315      clockticks
       1.001085024 S1        1         9614287448      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        1         3205726984      clockticks
       1.001029867 N1        1         3205444421      clockticks
       1.001029867 N2        1         3205234018      clockticks
       1.001029867 N3        1         3205224660      clockticks
       1.001029867 N4        1         3205207213      clockticks
       1.001029867 N5        1         3205528246      clockticks
Quoted 3 lines

After:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

Quoted 16 lines

I wonder if there is a better column heading than "cpus" given that these are imc PMUs.

Quoted 13 lines
       1.001022937 S0       12         9621463177      clockticks
       1.001022937 S1       12         9619804949      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        4         3206782080      clockticks
       1.001029867 N1        4         3207025354      clockticks
       1.001029867 N2        4         3207067946      clockticks
       1.001029867 N3        4         3206871733      clockticks
       1.001029867 N4        4         3206199005      clockticks
       1.001029867 N5        4         3205525058      clockticks

Added Namhyung's ack from the previous email.

Quoted 25 lines

Thanks,
Ian

Quoted 19 lines
---
 tools/perf/util/stat.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/stat.c +1 -1
index 355a7d5c8ab8..52266d773353 100644
@@ -527,6 +527,7 @@ static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias)
                struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts;
 
                /* NB: don't increase aggr.nr for aliases */
+               ps_a->aggr[i].nr += ps_b->aggr[i].nr;
 
                aggr_counts_a->val += aggr_counts_b->val;
                aggr_counts_a->ena += aggr_counts_b->ena;
--

2.50.0.rc1.591.g9c95f17f64-goog

maintainer
#8 lore raw
Quoted 25 lines · Ian Rogers
Quoted 4 lines · Namhyung Kim

Hi CT,

On Thu, Jun 12, 2025 at 03:55:59PM -0700, Chun-Tse Shao wrote:

Quoted 8 lines
Quoted 4 lines

Hi Ian, I actually renamed it to aggr_nr in v2 patch so it should be better aligned to json mode, which is using aggregate-nunber. But anyway I think any name other than cpus is better.
v2 patch: lore.kernel.org/[email protected]

I think "aggregation-count" is a better name, maybe abbreviated to "ag_cnt". Can we rename the JSON as well? I'm not sure if it's documented somewhere.

Fwiw, I still think "counters" is a clearer, more intention revealing definition than "aggregation count" or "aggregation number". The term counter appears in the perf-stat and perf_event_open man page. In the perf-stat man page we have a pattern of:

--per-XXX
Aggregate counts per XXX for system-wide mode measurements. This is a useful mode to .... To enable this mode, use --per-XXX in addition to -a. (system-wide). The output includes the ...
This is useful to gauge the amount of aggregation.

Quoted 5 lines

It seems that the aggregated value of the counters could be confused for being an "aggregation count" or "aggregation number" given the man page definition. I think "counters" to some extent avoids this, we giving the number of counters aggregated. The perf-stat man page could certainly be clearer :-)

I'm fine with "counters" (and "ctrs").

Thanks,
Namhyung

Quoted 98 lines
Quoted 98 lines
Quoted 98 lines · Ian Rogers
Quoted 96 lines · Chun-Tse Shao
Quoted 5 lines

Thanks for your test, Ian!

I wonder if nr_pmus makes sense, since the column would be shared with multiple different pmus. WDYT?

So each PMU in sysfs has a cpumask that specifies which CPUs perf should pass to perf_event_open. For example, on a two socket machine the cpumask will typically have the first CPU of each socket. If the cpumask (or cpus) file isn't present then the cpumask is implicitly all online CPUs. Given that the aggregation number is the number of CPUs in the cpumask multiplied by the number of PMUs, I think the most neutral name is probably "counters" possibly shortened down to "ctrs". I suspect others have better suggestions :-)

Thanks,
Ian

Quoted 76 lines

-CT

Quoted 28 lines · Ian Rogers
Quoted 22 lines · Chun-Tse Shao

Follow up:
lore.kernel.org/CAP-5=fVDF4-qYL1Lm7efgiHk7X=_nw_nEFMBZFMcsnOOJgX4Kg@mail.gmail.com/

The patch adds unit aggregation during evsel merge the aggregated uncore counters.

Tested on a 2-socket machine with SNC3, uncore_imc_[0-11] and cpumask="0,120"
Before:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

       1.001085024 S0        1         9615386315      clockticks
       1.001085024 S1        1         9614287448      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        1         3205726984      clockticks
       1.001029867 N1        1         3205444421      clockticks
       1.001029867 N2        1         3205234018      clockticks
       1.001029867 N3        1         3205224660      clockticks
       1.001029867 N4        1         3205207213      clockticks
       1.001029867 N5        1         3205528246      clockticks
Quoted 3 lines

After:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

Quoted 16 lines

I wonder if there is a better column heading than "cpus" given that these are imc PMUs.

Quoted 13 lines
       1.001022937 S0       12         9621463177      clockticks
       1.001022937 S1       12         9619804949      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        4         3206782080      clockticks
       1.001029867 N1        4         3207025354      clockticks
       1.001029867 N2        4         3207067946      clockticks
       1.001029867 N3        4         3206871733      clockticks
       1.001029867 N4        4         3206199005      clockticks
       1.001029867 N5        4         3205525058      clockticks

Added Namhyung's ack from the previous email.

Quoted 25 lines

Thanks,
Ian

Quoted 19 lines
---
 tools/perf/util/stat.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/stat.c +1 -1
index 355a7d5c8ab8..52266d773353 100644
@@ -527,6 +527,7 @@ static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias)
                struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts;
 
                /* NB: don't increase aggr.nr for aliases */
+               ps_a->aggr[i].nr += ps_b->aggr[i].nr;
 
                aggr_counts_a->val += aggr_counts_b->val;
                aggr_counts_a->ena += aggr_counts_b->ena;
--

2.50.0.rc1.591.g9c95f17f64-goog

#9 lore raw

Thanks for your suggestions, Namhyung and Ian. I submitted v3 patch:
https://lore.kernel.org/linux-perf-users/[email protected]

BTW, I just realized the --metric-only option makes the output unaligned. It is hard to show in an email but if you try:
perf stat -M uncore_frequency,uncore_frequency --metric-only -I 1000 --per-socket
You would see the problem. I will take a look once I have a chance.

-CT

Quoted 136 lines · Namhyung Kim
Quoted 25 lines · Ian Rogers
Quoted 4 lines · Namhyung Kim

Hi CT,

On Thu, Jun 12, 2025 at 03:55:59PM -0700, Chun-Tse Shao wrote:

Quoted 8 lines
Quoted 4 lines

Hi Ian, I actually renamed it to aggr_nr in v2 patch so it should be better aligned to json mode, which is using aggregate-nunber. But anyway I think any name other than cpus is better.
v2 patch: lore.kernel.org/[email protected]

I think "aggregation-count" is a better name, maybe abbreviated to "ag_cnt". Can we rename the JSON as well? I'm not sure if it's documented somewhere.

Fwiw, I still think "counters" is a clearer, more intention revealing definition than "aggregation count" or "aggregation number". The term counter appears in the perf-stat and perf_event_open man page. In the perf-stat man page we have a pattern of:

--per-XXX
Aggregate counts per XXX for system-wide mode measurements. This is a useful mode to .... To enable this mode, use --per-XXX in addition to -a. (system-wide). The output includes the ...
This is useful to gauge the amount of aggregation.

Quoted 5 lines

It seems that the aggregated value of the counters could be confused for being an "aggregation count" or "aggregation number" given the man page definition. I think "counters" to some extent avoids this, we giving the number of counters aggregated. The perf-stat man page could certainly be clearer :-)

I'm fine with "counters" (and "ctrs").

Thanks,
Namhyung

Quoted 98 lines
Quoted 98 lines
Quoted 98 lines · Ian Rogers
Quoted 96 lines · Chun-Tse Shao
Quoted 5 lines

Thanks for your test, Ian!

I wonder if nr_pmus makes sense, since the column would be shared with multiple different pmus. WDYT?

So each PMU in sysfs has a cpumask that specifies which CPUs perf should pass to perf_event_open. For example, on a two socket machine the cpumask will typically have the first CPU of each socket. If the cpumask (or cpus) file isn't present then the cpumask is implicitly all online CPUs. Given that the aggregation number is the number of CPUs in the cpumask multiplied by the number of PMUs, I think the most neutral name is probably "counters" possibly shortened down to "ctrs". I suspect others have better suggestions :-)

Thanks,
Ian

Quoted 76 lines

-CT

Quoted 28 lines · Ian Rogers
Quoted 22 lines · Chun-Tse Shao

Follow up:
lore.kernel.org/CAP-5=fVDF4-qYL1Lm7efgiHk7X=_nw_nEFMBZFMcsnOOJgX4Kg@mail.gmail.com/

The patch adds unit aggregation during evsel merge the aggregated uncore counters.

Tested on a 2-socket machine with SNC3, uncore_imc_[0-11] and cpumask="0,120"
Before:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

       1.001085024 S0        1         9615386315      clockticks
       1.001085024 S1        1         9614287448      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        1         3205726984      clockticks
       1.001029867 N1        1         3205444421      clockticks
       1.001029867 N2        1         3205234018      clockticks
       1.001029867 N3        1         3205224660      clockticks
       1.001029867 N4        1         3205207213      clockticks
       1.001029867 N5        1         3205528246      clockticks
Quoted 3 lines

After:
perf stat -e clockticks -I 1000 --per-socket
# time socket cpus counts unit events

Quoted 16 lines

I wonder if there is a better column heading than "cpus" given that these are imc PMUs.

Quoted 13 lines
       1.001022937 S0       12         9621463177      clockticks
       1.001022937 S1       12         9619804949      clockticks
  perf stat -e clockticks -I 1000 --per-node
  #           time node   cpus             counts unit events
       1.001029867 N0        4         3206782080      clockticks
       1.001029867 N1        4         3207025354      clockticks
       1.001029867 N2        4         3207067946      clockticks
       1.001029867 N3        4         3206871733      clockticks
       1.001029867 N4        4         3206199005      clockticks
       1.001029867 N5        4         3205525058      clockticks

Added Namhyung's ack from the previous email.

Quoted 25 lines

Thanks,
Ian

Quoted 19 lines
---
 tools/perf/util/stat.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/stat.c +1 -1
index 355a7d5c8ab8..52266d773353 100644
@@ -527,6 +527,7 @@ static int evsel__merge_aggr_counters(struct evsel *evsel, struct evsel *alias)
                struct perf_counts_values *aggr_counts_b = &ps_b->aggr[i].counts;
 
                /* NB: don't increase aggr.nr for aliases */
+               ps_a->aggr[i].nr += ps_b->aggr[i].nr;
 
                aggr_counts_a->val += aggr_counts_b->val;
                aggr_counts_a->ena += aggr_counts_b->ena;
--

2.50.0.rc1.591.g9c95f17f64-goog