Skip to contentSkip to conversation

perf stat: Fix the hard-coded metrics calculation on the hybrid

PATCH Superseded [email protected] 3 participants 4 messages Jun 5, 2024 – Jun 6, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf stat: Fix the hard-coded metrics calculation on the hybrid

From: Kan Liang <[email protected]>

The hard-coded metrics is wrongly calculated on the hybrid machine.

$ perf stat -e cycles,instructions -a sleep 1

Performance counter stats for 'system wide':

        18,205,487      cpu_atom/cycles/
         9,733,603      cpu_core/cycles/
         9,423,111      cpu_atom/instructions/     #  0.52  insn per cycle
         4,268,965      cpu_core/instructions/     #  0.23  insn per cycle

The insn per cycle for cpu_core should be 4,268,965 / 9,733,603 = 0.44.

When finding the metric events, the find_stat() doesn't take the PMU type into account. The cpu_atom/cycles/ is wrongly used to calculate the IPC of the cpu_core.

Fixes 0a57b910807a ("perf stat: Use counts rather than saved_value")
---
 tools/perf/util/stat-shadow.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/stat-shadow.c +4 -0
index 3466aa952442..4d0edc061f1a 100644
@@ -176,6 +176,10 @@ static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat_type
 		if (type != evsel__stat_type(cur))
 			continue;
 
+		/* Ignore if not the PMU we're looking for. */
+		if (evsel->pmu != cur->pmu)
+			continue;
+
 		aggr = &cur->stats->aggr[aggr_idx];
 		if (type == STAT_NSECS)
 			return aggr->counts.val;
Signature · 1 line
2.35.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · On Wed, Jun 5, 2024 at 9:10 AM <[email protected]> wrote:

From: Kan Liang <[email protected]>

The hard-coded metrics is wrongly calculated on the hybrid machine.

$ perf stat -e cycles,instructions -a sleep 1

Performance counter stats for 'system wide':

        18,205,487      cpu_atom/cycles/
         9,733,603      cpu_core/cycles/
         9,423,111      cpu_atom/instructions/     #  0.52  insn per cycle
         4,268,965      cpu_core/instructions/     #  0.23  insn per cycle

The insn per cycle for cpu_core should be 4,268,965 / 9,733,603 = 0.44.

Quoted 7 lines

When finding the metric events, the find_stat() doesn't take the PMU type into account. The cpu_atom/cycles/ is wrongly used to calculate the IPC of the cpu_core.

Fixes 0a57b910807a ("perf stat: Use counts rather than saved_value")

Thanks,
Ian

Quoted 23 lines
---
 tools/perf/util/stat-shadow.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/stat-shadow.c +4 -1
index 3466aa952442..4d0edc061f1a 100644
@@ -176,6 +176,10 @@ static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat_type
                if (type != evsel__stat_type(cur))
                        continue;
 
+               /* Ignore if not the PMU we're looking for. */
+               if (evsel->pmu != cur->pmu)
+                       continue;
+
                aggr = &cur->stats->aggr[aggr_idx];
                if (type == STAT_NSECS)
                        return aggr->counts.val;
--

2.35.1

maintainer
#2 lore raw
Quoted 44 lines · Ian Rogers
Quoted 16 lines · On Wed, Jun 5, 2024 at 9:10 AM <[email protected]> wrote:

From: Kan Liang <[email protected]>

The hard-coded metrics is wrongly calculated on the hybrid machine.

$ perf stat -e cycles,instructions -a sleep 1

Performance counter stats for 'system wide':

        18,205,487      cpu_atom/cycles/
         9,733,603      cpu_core/cycles/
         9,423,111      cpu_atom/instructions/     #  0.52  insn per cycle
         4,268,965      cpu_core/instructions/     #  0.23  insn per cycle

The insn per cycle for cpu_core should be 4,268,965 / 9,733,603 = 0.44.

Quoted 7 lines

When finding the metric events, the find_stat() doesn't take the PMU type into account. The cpu_atom/cycles/ is wrongly used to calculate the IPC of the cpu_core.

Fixes 0a57b910807a ("perf stat: Use counts rather than saved_value")

Thanks,
Ian

Quoted 13 lines
---
 tools/perf/util/stat-shadow.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/stat-shadow.c +0 -0
index 3466aa952442..4d0edc061f1a 100644
@@ -176,6 +176,10 @@ static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat_type
                if (type != evsel__stat_type(cur))
                        continue;
 
Quoted 3 lines

tools/perf/util/stat-shadow.c static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat_type · line 181

Quoted 3 lines
tools/perf/util/stat-shadow.c +3 -0
+               /* Ignore if not the PMU we're looking for. */
+               if (evsel->pmu != cur->pmu)
+                       continue;

Hmm.. Don't some metrics need events from different PMU? Like cycles per sec or branch instructions per sec..

Thanks,
Namhyung

Quoted 7 lines
Quoted 7 lines
tools/perf/util/stat-shadow.c +1 -1
+
                aggr = &cur->stats->aggr[aggr_idx];
                if (type == STAT_NSECS)
                        return aggr->counts.val;
--

2.35.1

author
#3 lore raw
Quoted 45 lines · Namhyung Kim
Quoted 44 lines · Ian Rogers
Quoted 16 lines · On Wed, Jun 5, 2024 at 9:10 AM <[email protected]> wrote:

From: Kan Liang <[email protected]>

The hard-coded metrics is wrongly calculated on the hybrid machine.

$ perf stat -e cycles,instructions -a sleep 1

Performance counter stats for 'system wide':

        18,205,487      cpu_atom/cycles/
         9,733,603      cpu_core/cycles/
         9,423,111      cpu_atom/instructions/     #  0.52  insn per cycle
         4,268,965      cpu_core/instructions/     #  0.23  insn per cycle

The insn per cycle for cpu_core should be 4,268,965 / 9,733,603 = 0.44.

Quoted 7 lines

When finding the metric events, the find_stat() doesn't take the PMU type into account. The cpu_atom/cycles/ is wrongly used to calculate the IPC of the cpu_core.

Fixes 0a57b910807a ("perf stat: Use counts rather than saved_value")

Thanks,
Ian

Quoted 13 lines
---
 tools/perf/util/stat-shadow.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/stat-shadow.c +0 -0
index 3466aa952442..4d0edc061f1a 100644
@@ -176,6 +176,10 @@ static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat_type
                if (type != evsel__stat_type(cur))
                        continue;
 
Quoted 7 lines
Quoted 3 lines

tools/perf/util/stat-shadow.c static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat_type · line 181

Quoted 3 lines
tools/perf/util/stat-shadow.c +3 -0
+               /* Ignore if not the PMU we're looking for. */
+               if (evsel->pmu != cur->pmu)
+                       continue;

Hmm.. Don't some metrics need events from different PMU? Like cycles per sec or branch instructions per sec..

Right.

In the hard-coded metrics, the events from a different PMU are SW_CPU_CLOCK and SW_TASK_CLOCK. They both have the stat type, STAT_NSECS. Perf should ignore the PMU checking for the type as below. I will send a V2 to fix it.

tools/perf/util/stat-shadow.c +0 -0
index 3466aa952442..d01335f18808 100644
@@ -176,6 +176,9 @@ static double find_stat(const struct evsel *evsel,

int aggr_idx, enum stat_type

		if (type != evsel__stat_type(cur))
			continue;

+ if ((type != STAT_NSECS) && (evsel->pmu != cur->pmu))
+ continue;
+

		aggr = &cur->stats->aggr[aggr_idx];
		if (type == STAT_NSECS)
			return aggr->counts.val;

Thanks,
Kan

Quoted 12 lines

Thanks,
Namhyung

Quoted 7 lines
Quoted 7 lines
tools/perf/util/stat-shadow.c +1 -1
+
                aggr = &cur->stats->aggr[aggr_idx];
                if (type == STAT_NSECS)
                        return aggr->counts.val;
--

2.35.1