Skip to contentSkip to conversation

perf/x86/rapl: Enable Core RAPL for AMD

PATCH Superseded Wyes Karny 5 participants 10 messages Feb 17, 2023 – Mar 1, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wyes Karny

author
#0 lore raw

PATCH 1/1 perf/x86/rapl: Enable Core RAPL for AMD

AMD processors support per-package and per-core energy monitoring through RAPL counters which can be accessed by users running in supervisor mode.

Core RAPL counters gives power consumption information per core. For AMD processors the package level RAPL counter are already exposed to perf. Expose the core level RAPL counters also.

sudo perf stat -a --per-core -C 0-127 -e power/energy-cores/

Output:

S0-D0-C0           2               8.73 Joules power/energy-cores/
S0-D0-C1           2               8.73 Joules power/energy-cores/
S0-D0-C2           2               8.73 Joules power/energy-cores/
S0-D0-C3           2               8.73 Joules power/energy-cores/
S0-D0-C4           2               8.73 Joules power/energy-cores/
---
 arch/x86/events/rapl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/events/rapl.c +3 -2
index 52e6e7ed4f78..d301bbbc3b93 100644
@@ -537,7 +537,7 @@ static struct perf_msr intel_rapl_spr_msrs[] = {
  * - want to use same event codes across both architectures
  */
 static struct perf_msr amd_rapl_msrs[] = {
-	[PERF_RAPL_PP0]  = { 0, &rapl_events_cores_group, 0, false, 0 },
+	[PERF_RAPL_PP0]  = { MSR_AMD_CORE_ENERGY_STATUS, &rapl_events_cores_group, test_msr, false, RAPL_MSR_MASK },
 	[PERF_RAPL_PKG]  = { MSR_AMD_PKG_ENERGY_STATUS,  &rapl_events_pkg_group,   test_msr, false, RAPL_MSR_MASK },
 	[PERF_RAPL_RAM]  = { 0, &rapl_events_ram_group,   0, false, 0 },
 	[PERF_RAPL_PP1]  = { 0, &rapl_events_gpu_group,   0, false, 0 },
@@ -764,7 +764,8 @@ static struct rapl_model model_spr = {
 };
 
 static struct rapl_model model_amd_hygon = {
-	.events		= BIT(PERF_RAPL_PKG),
+	.events		= BIT(PERF_RAPL_PP0) |
+			  BIT(PERF_RAPL_PKG),
 	.msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
 	.rapl_msrs      = amd_rapl_msrs,
 };
Signature · 1 line
2.34.1
Tested-by on v1 1/1
#1 lore raw

Hello.

Quoted 37 lines · On pátek 17. února 2023 17:13:54 CET Wyes Karny wrote:

AMD processors support per-package and per-core energy monitoring through RAPL counters which can be accessed by users running in supervisor mode.

Core RAPL counters gives power consumption information per core. For AMD processors the package level RAPL counter are already exposed to perf. Expose the core level RAPL counters also.

sudo perf stat -a --per-core -C 0-127 -e power/energy-cores/

Output:

S0-D0-C0           2               8.73 Joules power/energy-cores/
S0-D0-C1           2               8.73 Joules power/energy-cores/
S0-D0-C2           2               8.73 Joules power/energy-cores/
S0-D0-C3           2               8.73 Joules power/energy-cores/
S0-D0-C4           2               8.73 Joules power/energy-cores/
---
 arch/x86/events/rapl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/events/rapl.c +1 -1
index 52e6e7ed4f78..d301bbbc3b93 100644
@@ -537,7 +537,7 @@ static struct perf_msr intel_rapl_spr_msrs[] = {
  * - want to use same event codes across both architectures
  */
 static struct perf_msr amd_rapl_msrs[] = {
-	[PERF_RAPL_PP0]  = { 0, &rapl_events_cores_group, 0, false, 0 },
+	[PERF_RAPL_PP0]  = { MSR_AMD_CORE_ENERGY_STATUS, &rapl_events_cores_group, test_msr, false, RAPL_MSR_MASK },
 	[PERF_RAPL_PKG]  = { MSR_AMD_PKG_ENERGY_STATUS,  &rapl_events_pkg_group,   test_msr, false, RAPL_MSR_MASK },
 	[PERF_RAPL_RAM]  = { 0, &rapl_events_ram_group,   0, false, 0 },
 	[PERF_RAPL_PP1]  = { 0, &rapl_events_gpu_group,   0, false, 0 },

arch/x86/events/rapl.c static struct rapl_model model_spr = { · line 771

Quoted 9 lines
arch/x86/events/rapl.c +2 -1
@@ -764,7 +764,8 @@ static struct rapl_model model_spr = {
 };
 
 static struct rapl_model model_amd_hygon = {
-	.events		= BIT(PERF_RAPL_PKG),
+	.events		= BIT(PERF_RAPL_PP0) |
+			  BIT(PERF_RAPL_PKG),
 	.msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
 	.rapl_msrs      = amd_rapl_msrs,
 };

With this patch:

```
$ lscpu | grep 'Model name'
Model name:                      AMD Ryzen 9 5950X 16-Core Processor

$ sudo perf stat -a --per-core -C 0-15 -e power/energy-cores/ -- dd if=/dev/zero of=/dev/null bs=1M count=100000
100000+0 records in
100000+0 records out
104857600000 bytes (105 GB, 98 GiB) copied, 1,59252 s, 65,8 GB/s

Performance counter stats for 'system wide':

S0-D0-C0           1               1,56 Joules power/energy-cores/
S0-D0-C1           1               1,56 Joules power/energy-cores/
S0-D0-C2           1               1,56 Joules power/energy-cores/
S0-D0-C3           1               1,56 Joules power/energy-cores/
S0-D0-C4           1               1,56 Joules power/energy-cores/
S0-D0-C5           1               1,56 Joules power/energy-cores/
S0-D0-C6           1               1,56 Joules power/energy-cores/
S0-D0-C7           1               1,56 Joules power/energy-cores/
S0-D0-C8           1               1,56 Joules power/energy-cores/
S0-D0-C9           1               1,56 Joules power/energy-cores/
S0-D0-C10          1               1,56 Joules power/energy-cores/
S0-D0-C11          1               1,56 Joules power/energy-cores/
S0-D0-C12          1               1,56 Joules power/energy-cores/
S0-D0-C13          1               1,56 Joules power/energy-cores/
S0-D0-C14          1               1,56 Joules power/energy-cores/
S0-D0-C15          1               1,56 Joules power/energy-cores/

1,593982452 seconds time elapsed
```

Hence,

Thank you.

Signature · 1 line
Oleksandr Natalenko (post-factum)
author
#2 lore raw

Hi Oleksandr,

Quoted 83 lines · Oleksandr Natalenko

Hello.

Quoted 37 lines · On pátek 17. února 2023 17:13:54 CET Wyes Karny wrote:

AMD processors support per-package and per-core energy monitoring through RAPL counters which can be accessed by users running in supervisor mode.

Core RAPL counters gives power consumption information per core. For AMD processors the package level RAPL counter are already exposed to perf. Expose the core level RAPL counters also.

sudo perf stat -a --per-core -C 0-127 -e power/energy-cores/

Output:

S0-D0-C0           2               8.73 Joules power/energy-cores/
S0-D0-C1           2               8.73 Joules power/energy-cores/
S0-D0-C2           2               8.73 Joules power/energy-cores/
S0-D0-C3           2               8.73 Joules power/energy-cores/
S0-D0-C4           2               8.73 Joules power/energy-cores/
---
 arch/x86/events/rapl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/events/rapl.c +1 -1
index 52e6e7ed4f78..d301bbbc3b93 100644
@@ -537,7 +537,7 @@ static struct perf_msr intel_rapl_spr_msrs[] = {
  * - want to use same event codes across both architectures
  */
 static struct perf_msr amd_rapl_msrs[] = {
-	[PERF_RAPL_PP0]  = { 0, &rapl_events_cores_group, 0, false, 0 },
+	[PERF_RAPL_PP0]  = { MSR_AMD_CORE_ENERGY_STATUS, &rapl_events_cores_group, test_msr, false, RAPL_MSR_MASK },
 	[PERF_RAPL_PKG]  = { MSR_AMD_PKG_ENERGY_STATUS,  &rapl_events_pkg_group,   test_msr, false, RAPL_MSR_MASK },
 	[PERF_RAPL_RAM]  = { 0, &rapl_events_ram_group,   0, false, 0 },
 	[PERF_RAPL_PP1]  = { 0, &rapl_events_gpu_group,   0, false, 0 },

arch/x86/events/rapl.c static struct rapl_model model_spr = { · line 771

Quoted 9 lines
arch/x86/events/rapl.c +2 -1
@@ -764,7 +764,8 @@ static struct rapl_model model_spr = {
 };
 
 static struct rapl_model model_amd_hygon = {
-	.events		= BIT(PERF_RAPL_PKG),
+	.events		= BIT(PERF_RAPL_PP0) |
+			  BIT(PERF_RAPL_PKG),
 	.msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
 	.rapl_msrs      = amd_rapl_msrs,
 };

With this patch:

```
$ lscpu | grep 'Model name'
Model name:                      AMD Ryzen 9 5950X 16-Core Processor

$ sudo perf stat -a --per-core -C 0-15 -e power/energy-cores/ -- dd if=/dev/zero of=/dev/null bs=1M count=100000
100000+0 records in
100000+0 records out
104857600000 bytes (105 GB, 98 GiB) copied, 1,59252 s, 65,8 GB/s

Performance counter stats for 'system wide':

S0-D0-C0           1               1,56 Joules power/energy-cores/
S0-D0-C1           1               1,56 Joules power/energy-cores/
S0-D0-C2           1               1,56 Joules power/energy-cores/
S0-D0-C3           1               1,56 Joules power/energy-cores/
S0-D0-C4           1               1,56 Joules power/energy-cores/
S0-D0-C5           1               1,56 Joules power/energy-cores/
S0-D0-C6           1               1,56 Joules power/energy-cores/
S0-D0-C7           1               1,56 Joules power/energy-cores/
S0-D0-C8           1               1,56 Joules power/energy-cores/
S0-D0-C9           1               1,56 Joules power/energy-cores/
S0-D0-C10          1               1,56 Joules power/energy-cores/
S0-D0-C11          1               1,56 Joules power/energy-cores/
S0-D0-C12          1               1,56 Joules power/energy-cores/
S0-D0-C13          1               1,56 Joules power/energy-cores/
S0-D0-C14          1               1,56 Joules power/energy-cores/
S0-D0-C15          1               1,56 Joules power/energy-cores/

1,593982452 seconds time elapsed
```
Quoted 3 lines

Hence,

I haven't put your tested-by tag in v2 as I've added a new patch there. Please let me know if v2 works well for you and if I can add tested-by on v2.

Quoted 3 lines

Thank you.

Signature · 2 lines
Thanks & Regards,
Wyes
maintainer
#3 lore raw
In reply to Wyes Karny
Quoted 27 lines · Wyes Karny

AMD processors support per-package and per-core energy monitoring through RAPL counters which can be accessed by users running in supervisor mode.

Core RAPL counters gives power consumption information per core. For AMD processors the package level RAPL counter are already exposed to perf. Expose the core level RAPL counters also.

sudo perf stat -a --per-core -C 0-127 -e power/energy-cores/

Output:

S0-D0-C0           2               8.73 Joules power/energy-cores/
S0-D0-C1           2               8.73 Joules power/energy-cores/
S0-D0-C2           2               8.73 Joules power/energy-cores/
S0-D0-C3           2               8.73 Joules power/energy-cores/
S0-D0-C4           2               8.73 Joules power/energy-cores/
---
 arch/x86/events/rapl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/events/rapl.c +0 -0
index 52e6e7ed4f78..d301bbbc3b93 100644

arch/x86/events/rapl.c static struct perf_msr intel_rapl_spr_msrs[] = { · line 540

Quoted 5 lines
arch/x86/events/rapl.c +1 -1
@@ -537,7 +537,7 @@ static struct perf_msr intel_rapl_spr_msrs[] = {
  * - want to use same event codes across both architectures
  */
 static struct perf_msr amd_rapl_msrs[] = {
-	[PERF_RAPL_PP0]  = { 0, &rapl_events_cores_group, 0, false, 0 },
+	[PERF_RAPL_PP0]  = { MSR_AMD_CORE_ENERGY_STATUS, &rapl_events_cores_group, test_msr, false, RAPL_MSR_MASK },

Stephane, this was an oversight?

Quoted 16 lines
arch/x86/events/rapl.c +2 -1
 	[PERF_RAPL_PKG]  = { MSR_AMD_PKG_ENERGY_STATUS,  &rapl_events_pkg_group,   test_msr, false, RAPL_MSR_MASK },
 	[PERF_RAPL_RAM]  = { 0, &rapl_events_ram_group,   0, false, 0 },
 	[PERF_RAPL_PP1]  = { 0, &rapl_events_gpu_group,   0, false, 0 },
@@ -764,7 +764,8 @@ static struct rapl_model model_spr = {
 };
 
 static struct rapl_model model_amd_hygon = {
-	.events		= BIT(PERF_RAPL_PKG),
+	.events		= BIT(PERF_RAPL_PP0) |
+			  BIT(PERF_RAPL_PKG),
 	.msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
 	.rapl_msrs      = amd_rapl_msrs,
 };
Signature · 1 line
2.34.1
#4 lore raw
Quoted 24 lines · Peter Zijlstra
Quoted 22 lines · Wyes Karny

AMD processors support per-package and per-core energy monitoring through RAPL counters which can be accessed by users running in supervisor mode.

Core RAPL counters gives power consumption information per core. For AMD processors the package level RAPL counter are already exposed to perf. Expose the core level RAPL counters also.

sudo perf stat -a --per-core -C 0-127 -e power/energy-cores/

Output:

S0-D0-C0           2               8.73 Joules power/energy-cores/
S0-D0-C1           2               8.73 Joules power/energy-cores/
S0-D0-C2           2               8.73 Joules power/energy-cores/
S0-D0-C3           2               8.73 Joules power/energy-cores/
S0-D0-C4           2               8.73 Joules power/energy-cores/
---
 arch/x86/events/rapl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 13 lines

arch/x86/events/rapl.c static struct perf_msr intel_rapl_spr_msrs[] = { · line 540

Quoted 10 lines
arch/x86/events/rapl.c +1 -1
index 52e6e7ed4f78..d301bbbc3b93 100644
@@ -537,7 +537,7 @@ static struct perf_msr intel_rapl_spr_msrs[] = {
  * - want to use same event codes across both architectures
  */
 static struct perf_msr amd_rapl_msrs[] = {
-     [PERF_RAPL_PP0]  = { 0, &rapl_events_cores_group, 0, false, 0 },
+     [PERF_RAPL_PP0]  = { MSR_AMD_CORE_ENERGY_STATUS, &rapl_events_cores_group, test_msr, false, RAPL_MSR_MASK },

Stephane, this was an oversight?

I think it may depend on the CPU model. I remember it returning either 0 or bogus values on my systems. They may have improved that. The commit msg does not show which CPU model this is run on.

Quoted 17 lines
Quoted 17 lines
arch/x86/events/rapl.c +2 -2
      [PERF_RAPL_PKG]  = { MSR_AMD_PKG_ENERGY_STATUS,  &rapl_events_pkg_group,   test_msr, false, RAPL_MSR_MASK },
      [PERF_RAPL_RAM]  = { 0, &rapl_events_ram_group,   0, false, 0 },
      [PERF_RAPL_PP1]  = { 0, &rapl_events_gpu_group,   0, false, 0 },
@@ -764,7 +764,8 @@ static struct rapl_model model_spr = {
 };
 
 static struct rapl_model model_amd_hygon = {
-     .events         = BIT(PERF_RAPL_PKG),
+     .events         = BIT(PERF_RAPL_PP0) |
+                       BIT(PERF_RAPL_PKG),
      .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
      .rapl_msrs      = amd_rapl_msrs,
 };
--

2.34.1

author
#5 lore raw
Quoted 38 lines · Stephane Eranian
Quoted 24 lines · Peter Zijlstra
Quoted 22 lines · Wyes Karny

AMD processors support per-package and per-core energy monitoring through RAPL counters which can be accessed by users running in supervisor mode.

Core RAPL counters gives power consumption information per core. For AMD processors the package level RAPL counter are already exposed to perf. Expose the core level RAPL counters also.

sudo perf stat -a --per-core -C 0-127 -e power/energy-cores/

Output:

S0-D0-C0           2               8.73 Joules power/energy-cores/
S0-D0-C1           2               8.73 Joules power/energy-cores/
S0-D0-C2           2               8.73 Joules power/energy-cores/
S0-D0-C3           2               8.73 Joules power/energy-cores/
S0-D0-C4           2               8.73 Joules power/energy-cores/
---
 arch/x86/events/rapl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 13 lines

arch/x86/events/rapl.c static struct perf_msr intel_rapl_spr_msrs[] = { · line 540

Quoted 10 lines
arch/x86/events/rapl.c +1 -1
index 52e6e7ed4f78..d301bbbc3b93 100644
@@ -537,7 +537,7 @@ static struct perf_msr intel_rapl_spr_msrs[] = {
  * - want to use same event codes across both architectures
  */
 static struct perf_msr amd_rapl_msrs[] = {
-     [PERF_RAPL_PP0]  = { 0, &rapl_events_cores_group, 0, false, 0 },
+     [PERF_RAPL_PP0]  = { MSR_AMD_CORE_ENERGY_STATUS, &rapl_events_cores_group, test_msr, false, RAPL_MSR_MASK },

Stephane, this was an oversight?

Quoted 3 lines

I think it may depend on the CPU model. I remember it returning either 0 or bogus values on my systems. They may have improved that. The commit msg does not show which CPU model this is run on.

I've tested this on Zen 2, 3 and 4 server systems.

Thanks,
Wyes

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
arch/x86/events/rapl.c +2 -2
      [PERF_RAPL_PKG]  = { MSR_AMD_PKG_ENERGY_STATUS,  &rapl_events_pkg_group,   test_msr, false, RAPL_MSR_MASK },
      [PERF_RAPL_RAM]  = { 0, &rapl_events_ram_group,   0, false, 0 },
      [PERF_RAPL_PP1]  = { 0, &rapl_events_gpu_group,   0, false, 0 },
@@ -764,7 +764,8 @@ static struct rapl_model model_spr = {
 };
 
 static struct rapl_model model_amd_hygon = {
-     .events         = BIT(PERF_RAPL_PKG),
+     .events         = BIT(PERF_RAPL_PP0) |
+                       BIT(PERF_RAPL_PKG),
      .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
      .rapl_msrs      = amd_rapl_msrs,
 };
--

2.34.1

#6 lore raw

Hi,

Testing Wyes' patch for energy-cores on Zen3 server loaded with triad bench on socket0:

$ perf stat --per-core -a -C0-63 -I 1000 -e
power/energy-cores/,power/energy-pkg/
#           time core               cpus             counts   unit events
     1.001019203 S0-D0-C0              1               1.28 Joules
power/energy-cores/
     1.001019203 S0-D0-C0              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C1              1   4,294,967,130.96 Joules
power/energy-cores/
     1.001019203 S0-D0-C1              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C2              1   4,294,967,126.23 Joules
power/energy-cores/
     1.001019203 S0-D0-C2              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C3              1   4,294,967,122.50 Joules
power/energy-cores/
     1.001019203 S0-D0-C3              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C4              1   4,294,967,129.92 Joules
power/energy-cores/
     1.001019203 S0-D0-C4              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C5              1   4,294,967,121.49 Joules
power/energy-cores/
     1.001019203 S0-D0-C5              1             231.39 Joules
power/energy-pkg/

I think the result of energy-cores is not reliable and I think that is why I did not
include it in the patch.

Could also be a problem with the kernel code, but I don't know why it would only impact energy-cores given energy-pkg looks reasonable here.

Quoted 66 lines · Wyes Karny
Quoted 38 lines · Stephane Eranian
Quoted 24 lines · Peter Zijlstra
Quoted 22 lines · Wyes Karny

AMD processors support per-package and per-core energy monitoring through RAPL counters which can be accessed by users running in supervisor mode.

Core RAPL counters gives power consumption information per core. For AMD processors the package level RAPL counter are already exposed to perf. Expose the core level RAPL counters also.

sudo perf stat -a --per-core -C 0-127 -e power/energy-cores/

Output:

S0-D0-C0           2               8.73 Joules power/energy-cores/
S0-D0-C1           2               8.73 Joules power/energy-cores/
S0-D0-C2           2               8.73 Joules power/energy-cores/
S0-D0-C3           2               8.73 Joules power/energy-cores/
S0-D0-C4           2               8.73 Joules power/energy-cores/
---
 arch/x86/events/rapl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 13 lines

arch/x86/events/rapl.c static struct perf_msr intel_rapl_spr_msrs[] = { · line 540

Quoted 10 lines
arch/x86/events/rapl.c +1 -1
index 52e6e7ed4f78..d301bbbc3b93 100644
@@ -537,7 +537,7 @@ static struct perf_msr intel_rapl_spr_msrs[] = {
  * - want to use same event codes across both architectures
  */
 static struct perf_msr amd_rapl_msrs[] = {
-     [PERF_RAPL_PP0]  = { 0, &rapl_events_cores_group, 0, false, 0 },
+     [PERF_RAPL_PP0]  = { MSR_AMD_CORE_ENERGY_STATUS, &rapl_events_cores_group, test_msr, false, RAPL_MSR_MASK },

Stephane, this was an oversight?

Quoted 3 lines

I think it may depend on the CPU model. I remember it returning either 0 or bogus values on my systems. They may have improved that. The commit msg does not show which CPU model this is run on.

I've tested this on Zen 2, 3 and 4 server systems.

Thanks,
Wyes

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
arch/x86/events/rapl.c +2 -2
      [PERF_RAPL_PKG]  = { MSR_AMD_PKG_ENERGY_STATUS,  &rapl_events_pkg_group,   test_msr, false, RAPL_MSR_MASK },
      [PERF_RAPL_RAM]  = { 0, &rapl_events_ram_group,   0, false, 0 },
      [PERF_RAPL_PP1]  = { 0, &rapl_events_gpu_group,   0, false, 0 },
@@ -764,7 +764,8 @@ static struct rapl_model model_spr = {
 };
 
 static struct rapl_model model_amd_hygon = {
-     .events         = BIT(PERF_RAPL_PKG),
+     .events         = BIT(PERF_RAPL_PP0) |
+                       BIT(PERF_RAPL_PKG),
      .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
      .rapl_msrs      = amd_rapl_msrs,
 };
--

2.34.1

#7 lore raw
Quoted 33 lines · Stephane Eranian

Hi,

Testing Wyes' patch for energy-cores on Zen3 server loaded with triad bench on socket0:

$ perf stat --per-core -a -C0-63 -I 1000 -e
power/energy-cores/,power/energy-pkg/
#           time core               cpus             counts   unit events
     1.001019203 S0-D0-C0              1               1.28 Joules
power/energy-cores/
     1.001019203 S0-D0-C0              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C1              1   4,294,967,130.96 Joules
power/energy-cores/
     1.001019203 S0-D0-C1              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C2              1   4,294,967,126.23 Joules
power/energy-cores/
     1.001019203 S0-D0-C2              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C3              1   4,294,967,122.50 Joules
power/energy-cores/
     1.001019203 S0-D0-C3              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C4              1   4,294,967,129.92 Joules
power/energy-cores/
     1.001019203 S0-D0-C4              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C5              1   4,294,967,121.49 Joules
power/energy-cores/
     1.001019203 S0-D0-C5              1             231.39 Joules
power/energy-pkg/
Quoted 7 lines

I think the result of energy-cores is not reliable and I think that is why I did not
include it in the patch.

Could also be a problem with the kernel code, but I don't know why it would only impact energy-cores given energy-pkg looks reasonable here.

I'm getting consistent per core energy measurements on AMD Custom APU 405. Probably consistency depends on the chip.

sudo perf stat -a --per-core -C 0-7 -e power/energy-cores/

Performance counter stats for 'system wide':

 S0-D0-C0           2               0.51 Joules power/energy-cores/
 S0-D0-C1           2               0.51 Joules power/energy-cores/
 S0-D0-C2           2               0.51 Joules power/energy-cores/
 S0-D0-C3           2               0.51 Joules power/energy-cores/

What is the fate of this patch now?

[..]

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

Stephane, this was an oversight?

I think it may depend on the CPU model. I remember it returning either 0 or bogus values on my systems. They may have improved that. The commit msg does not show which CPU model this is run on.

I've tested this on Zen 2, 3 and 4 server systems.

Thanks,
Wyes

Signature · 2 lines
BR,
Muhammad Usama Anjum
author
#8 lore raw

Hi Muhammad,

Quoted 47 lines · Muhammad Usama Anjum
Quoted 33 lines · Stephane Eranian

Hi,

Testing Wyes' patch for energy-cores on Zen3 server loaded with triad bench on socket0:

$ perf stat --per-core -a -C0-63 -I 1000 -e
power/energy-cores/,power/energy-pkg/
#           time core               cpus             counts   unit events
     1.001019203 S0-D0-C0              1               1.28 Joules
power/energy-cores/
     1.001019203 S0-D0-C0              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C1              1   4,294,967,130.96 Joules
power/energy-cores/
     1.001019203 S0-D0-C1              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C2              1   4,294,967,126.23 Joules
power/energy-cores/
     1.001019203 S0-D0-C2              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C3              1   4,294,967,122.50 Joules
power/energy-cores/
     1.001019203 S0-D0-C3              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C4              1   4,294,967,129.92 Joules
power/energy-cores/
     1.001019203 S0-D0-C4              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C5              1   4,294,967,121.49 Joules
power/energy-cores/
     1.001019203 S0-D0-C5              1             231.39 Joules
power/energy-pkg/
Quoted 7 lines

I think the result of energy-cores is not reliable and I think that is why I did not
include it in the patch.

Could also be a problem with the kernel code, but I don't know why it would only impact energy-cores given energy-pkg looks reasonable here.

I'm getting consistent per core energy measurements on AMD Custom APU 405. Probably consistency depends on the chip.

sudo perf stat -a --per-core -C 0-7 -e power/energy-cores/

Quoted 8 lines

Performance counter stats for 'system wide':

 S0-D0-C0           2               0.51 Joules power/energy-cores/
 S0-D0-C1           2               0.51 Joules power/energy-cores/
 S0-D0-C2           2               0.51 Joules power/energy-cores/
 S0-D0-C3           2               0.51 Joules power/energy-cores/

What is the fate of this patch now?

I'm working on the issue reported by Stephane. Will send v2 very soon.

Thanks,
Wyes

Quoted 17 lines

[..]

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

Stephane, this was an oversight?

I think it may depend on the CPU model. I remember it returning either 0 or bogus values on my systems. They may have improved that. The commit msg does not show which CPU model this is run on.

I've tested this on Zen 2, 3 and 4 server systems.

Thanks,
Wyes

Signature · 2 lines
BR,
Muhammad Usama Anjum
author
#9 lore raw
In reply to Stephane Eranian

Hi Stephane,

Quoted 33 lines · Stephane Eranian

Hi,

Testing Wyes' patch for energy-cores on Zen3 server loaded with triad bench on socket0:

$ perf stat --per-core -a -C0-63 -I 1000 -e
power/energy-cores/,power/energy-pkg/
#           time core               cpus             counts   unit events
     1.001019203 S0-D0-C0              1               1.28 Joules
power/energy-cores/
     1.001019203 S0-D0-C0              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C1              1   4,294,967,130.96 Joules
power/energy-cores/
     1.001019203 S0-D0-C1              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C2              1   4,294,967,126.23 Joules
power/energy-cores/
     1.001019203 S0-D0-C2              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C3              1   4,294,967,122.50 Joules
power/energy-cores/
     1.001019203 S0-D0-C3              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C4              1   4,294,967,129.92 Joules
power/energy-cores/
     1.001019203 S0-D0-C4              1             231.38 Joules
power/energy-pkg/
     1.001019203 S0-D0-C5              1   4,294,967,121.49 Joules
power/energy-cores/
     1.001019203 S0-D0-C5              1             231.39 Joules
power/energy-pkg/
Quoted 6 lines

I think the result of energy-cores is not reliable and I think that is why I did not
include it in the patch.

Could also be a problem with the kernel code, but I don't know why it would only impact energy-cores given energy-pkg looks reasonable here.

This is a kernel issue. I've addressed this in v2.

Thanks,
Wyes

Quoted 69 lines · Wyes Karny
Quoted 66 lines · Stephane Eranian
Quoted 38 lines · Peter Zijlstra
Quoted 24 lines · Wyes Karny
Quoted 22 lines

AMD processors support per-package and per-core energy monitoring through RAPL counters which can be accessed by users running in supervisor mode.

Core RAPL counters gives power consumption information per core. For AMD processors the package level RAPL counter are already exposed to perf. Expose the core level RAPL counters also.

sudo perf stat -a --per-core -C 0-127 -e power/energy-cores/

Output:

S0-D0-C0           2               8.73 Joules power/energy-cores/
S0-D0-C1           2               8.73 Joules power/energy-cores/
S0-D0-C2           2               8.73 Joules power/energy-cores/
S0-D0-C3           2               8.73 Joules power/energy-cores/
S0-D0-C4           2               8.73 Joules power/energy-cores/
---
 arch/x86/events/rapl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 13 lines

arch/x86/events/rapl.c static struct perf_msr intel_rapl_spr_msrs[] = { · line 540

Quoted 10 lines
arch/x86/events/rapl.c +1 -1
index 52e6e7ed4f78..d301bbbc3b93 100644
@@ -537,7 +537,7 @@ static struct perf_msr intel_rapl_spr_msrs[] = {
  * - want to use same event codes across both architectures
  */
 static struct perf_msr amd_rapl_msrs[] = {
-     [PERF_RAPL_PP0]  = { 0, &rapl_events_cores_group, 0, false, 0 },
+     [PERF_RAPL_PP0]  = { MSR_AMD_CORE_ENERGY_STATUS, &rapl_events_cores_group, test_msr, false, RAPL_MSR_MASK },

Stephane, this was an oversight?

Quoted 3 lines

I think it may depend on the CPU model. I remember it returning either 0 or bogus values on my systems. They may have improved that. The commit msg does not show which CPU model this is run on.

I've tested this on Zen 2, 3 and 4 server systems.

Thanks,
Wyes

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
arch/x86/events/rapl.c +2 -2
      [PERF_RAPL_PKG]  = { MSR_AMD_PKG_ENERGY_STATUS,  &rapl_events_pkg_group,   test_msr, false, RAPL_MSR_MASK },
      [PERF_RAPL_RAM]  = { 0, &rapl_events_ram_group,   0, false, 0 },
      [PERF_RAPL_PP1]  = { 0, &rapl_events_gpu_group,   0, false, 0 },
@@ -764,7 +764,8 @@ static struct rapl_model model_spr = {
 };
 
 static struct rapl_model model_amd_hygon = {
-     .events         = BIT(PERF_RAPL_PKG),
+     .events         = BIT(PERF_RAPL_PP0) |
+                       BIT(PERF_RAPL_PKG),
      .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
      .rapl_msrs      = amd_rapl_msrs,
 };
--

2.34.1

Signature · 2 lines
Thanks & Regards,
Wyes