Skip to contentSkip to conversation

perf pmu: Fix perf stat output with correct scale and unit

PATCH Applied Wyes Karny 3 participants 6 messages Sep 20, 2023 – Sep 30, 2023 perf events

lore
Share & tools
lore

Wyes Karny

author
#0 lore raw

PATCH 1/1 perf pmu: Fix perf stat output with correct scale and unit

The perf_pmu__parse_* functions for the sysfs files of pmu event’s scale, unit, per-pkg and snapshot were updated in commit 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs"). However, the paths for these sysfs files were incorrect. This resulted in perf stat reporting values with wrong scaling and missing units. This is fixed by correcting the paths for these sysfs files.

Before this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Performance counter stats for 'system wide':

351,217,188,864 power/energy-pkg/

          2.004127961 seconds time elapsed

After this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Performance counter stats for 'system wide':

             80.58 Joules power/energy-pkg/

2.004009749 seconds time elapsed

Fixes 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs")
---
 tools/perf/util/pmu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/pmu.c +4 -4
index 0d81c059c91c..93feee29d054 100644
@@ -295,7 +295,7 @@ static int perf_pmu__parse_scale(struct perf_pmu *pmu, struct perf_pmu_alias *al
 	len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
 	if (!len)
 		return 0;
-	scnprintf(path + len, sizeof(path) - len, "%s/%s.scale", pmu->name, alias->name);
+	scnprintf(path + len, sizeof(path) - len, "%s/events/%s.scale", pmu->name, alias->name);
 
 	fd = open(path, O_RDONLY);
 	if (fd == -1)
@@ -330,7 +330,7 @@ static int perf_pmu__parse_unit(struct perf_pmu *pmu, struct perf_pmu_alias *ali
 	len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
 	if (!len)
 		return 0;
-	scnprintf(path + len, sizeof(path) - len, "%s/%s.unit", pmu->name, alias->name);
+	scnprintf(path + len, sizeof(path) - len, "%s/events/%s.unit", pmu->name, alias->name);
 
 	fd = open(path, O_RDONLY);
 	if (fd == -1)
@@ -364,7 +364,7 @@ perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
 	len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
 	if (!len)
 		return 0;
-	scnprintf(path + len, sizeof(path) - len, "%s/%s.per-pkg", pmu->name, alias->name);
+	scnprintf(path + len, sizeof(path) - len, "%s/events/%s.per-pkg", pmu->name, alias->name);
 
 	fd = open(path, O_RDONLY);
 	if (fd == -1)
@@ -385,7 +385,7 @@ static int perf_pmu__parse_snapshot(struct perf_pmu *pmu, struct perf_pmu_alias
 	len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
 	if (!len)
 		return 0;
-	scnprintf(path + len, sizeof(path) - len, "%s/%s.snapshot", pmu->name, alias->name);
+	scnprintf(path + len, sizeof(path) - len, "%s/events/%s.snapshot", pmu->name, alias->name);
 
 	fd = open(path, O_RDONLY);
 	if (fd == -1)
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Wyes Karny

The perf_pmu__parse_* functions for the sysfs files of pmu event’s scale, unit, per-pkg and snapshot were updated in commit 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs"). However, the paths for these sysfs files were incorrect. This resulted in perf stat reporting values with wrong scaling and missing units. This is fixed by correcting the paths for these sysfs files.

Before this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Performance counter stats for 'system wide':

   351,217,188,864      power/energy-pkg/

          2.004127961 seconds time elapsed

After this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Quoted 8 lines

Performance counter stats for 'system wide':

             80.58 Joules power/energy-pkg/

             2.004009749 seconds time elapsed
Fixes 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs")

Thanks!
Ian

Quoted 47 lines
---
 tools/perf/util/pmu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/pmu.c +4 -5
index 0d81c059c91c..93feee29d054 100644
@@ -295,7 +295,7 @@ static int perf_pmu__parse_scale(struct perf_pmu *pmu, struct perf_pmu_alias *al
        len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
        if (!len)
                return 0;
-       scnprintf(path + len, sizeof(path) - len, "%s/%s.scale", pmu->name, alias->name);
+       scnprintf(path + len, sizeof(path) - len, "%s/events/%s.scale", pmu->name, alias->name);
 
        fd = open(path, O_RDONLY);
        if (fd == -1)
@@ -330,7 +330,7 @@ static int perf_pmu__parse_unit(struct perf_pmu *pmu, struct perf_pmu_alias *ali
        len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
        if (!len)
                return 0;
-       scnprintf(path + len, sizeof(path) - len, "%s/%s.unit", pmu->name, alias->name);
+       scnprintf(path + len, sizeof(path) - len, "%s/events/%s.unit", pmu->name, alias->name);
 
        fd = open(path, O_RDONLY);
        if (fd == -1)
@@ -364,7 +364,7 @@ perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_alias *alias)
        len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
        if (!len)
                return 0;
-       scnprintf(path + len, sizeof(path) - len, "%s/%s.per-pkg", pmu->name, alias->name);
+       scnprintf(path + len, sizeof(path) - len, "%s/events/%s.per-pkg", pmu->name, alias->name);
 
        fd = open(path, O_RDONLY);
        if (fd == -1)
@@ -385,7 +385,7 @@ static int perf_pmu__parse_snapshot(struct perf_pmu *pmu, struct perf_pmu_alias
        len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path));
        if (!len)
                return 0;
-       scnprintf(path + len, sizeof(path) - len, "%s/%s.snapshot", pmu->name, alias->name);
+       scnprintf(path + len, sizeof(path) - len, "%s/events/%s.snapshot", pmu->name, alias->name);
 
        fd = open(path, O_RDONLY);
        if (fd == -1)
--

2.34.1

maintainer Applied
#2 lore raw
Quoted 26 lines · Ian Rogers
Quoted 24 lines · Wyes Karny

The perf_pmu__parse_* functions for the sysfs files of pmu event’s scale, unit, per-pkg and snapshot were updated in commit 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs"). However, the paths for these sysfs files were incorrect. This resulted in perf stat reporting values with wrong scaling and missing units. This is fixed by correcting the paths for these sysfs files.

Before this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Performance counter stats for 'system wide':

   351,217,188,864      power/energy-pkg/

          2.004127961 seconds time elapsed

After this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Performance counter stats for 'system wide':

Quoted 8 lines
Quoted 6 lines
             80.58 Joules power/energy-pkg/

             2.004009749 seconds time elapsed
Fixes 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs")

Applied to perf-tools-next, thanks!

reviewer
#3 lore raw
Quoted 30 lines · Namhyung Kim
Quoted 28 lines · Ian Rogers
Quoted 26 lines · Wyes Karny

The perf_pmu__parse_* functions for the sysfs files of pmu event’s scale, unit, per-pkg and snapshot were updated in commit 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs"). However, the paths for these sysfs files were incorrect. This resulted in perf stat reporting values with wrong scaling and missing units. This is fixed by correcting the paths for these sysfs files.

Before this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Performance counter stats for 'system wide':

   351,217,188,864      power/energy-pkg/

          2.004127961 seconds time elapsed

After this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Performance counter stats for 'system wide':

             80.58 Joules power/energy-pkg/
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
             2.004009749 seconds time elapsed
Fixes 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs")

Applied to perf-tools-next, thanks!

Thanks Namhyung, I think this should be a candidate for perf-tools so that 6.6 doesn't regress for sysfs events.

Ian

maintainer
#4 lore raw

Hi Ian,

Quoted 37 lines · Ian Rogers
Quoted 35 lines · Namhyung Kim
Quoted 33 lines · Ian Rogers
Quoted 30 lines · Wyes Karny

The perf_pmu__parse_* functions for the sysfs files of pmu event’s scale, unit, per-pkg and snapshot were updated in commit 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs"). However, the paths for these sysfs files were incorrect. This resulted in perf stat reporting values with wrong scaling and missing units. This is fixed by correcting the paths for these sysfs files.

Before this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Performance counter stats for 'system wide':

   351,217,188,864      power/energy-pkg/

          2.004127961 seconds time elapsed

After this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Performance counter stats for 'system wide':

             80.58 Joules power/energy-pkg/

             2.004009749 seconds time elapsed
Fixes 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs")
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Applied to perf-tools-next, thanks!

Thanks Namhyung, I think this should be a candidate for perf-tools so that 6.6 doesn't regress for sysfs events.

I see, I overlooked that it's for the current cycle. I'll move it to perf-tools.

Thanks,
Namhyung

maintainer Applied
#5 lore raw
Quoted 43 lines · Namhyung Kim

Hi Ian,

Quoted 39 lines · Ian Rogers
Quoted 37 lines · Namhyung Kim
Quoted 34 lines · Ian Rogers
Quoted 22 lines · Wyes Karny

The perf_pmu__parse_* functions for the sysfs files of pmu event’s scale, unit, per-pkg and snapshot were updated in commit 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs"). However, the paths for these sysfs files were incorrect. This resulted in perf stat reporting values with wrong scaling and missing units. This is fixed by correcting the paths for these sysfs files.

Before this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Performance counter stats for 'system wide':

   351,217,188,864      power/energy-pkg/

          2.004127961 seconds time elapsed

After this fix:

$sudo perf stat -e power/energy-pkg/ -- sleep 2

Quoted 8 lines

Performance counter stats for 'system wide':

             80.58 Joules power/energy-pkg/

             2.004009749 seconds time elapsed
Fixes 7b723dbb96e8 ("perf pmu: Be lazy about loading event info files from sysfs")
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Applied to perf-tools-next, thanks!

Thanks Namhyung, I think this should be a candidate for perf-tools so that 6.6 doesn't regress for sysfs events.

I see, I overlooked that it's for the current cycle. I'll move it to perf-tools.

Applied to perf-tools, thanks!