Re: [PATCH] perf/x86/rapl: Enable Core RAPL for AMD
From: Wyes Karny
Date: Wed Mar 01 2023 - 13:33:38 EST
Hi Oleksandr,
On 2/19/2023 5:22 PM, Oleksandr Natalenko wrote:
> Hello.
>
> 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/
>>
>> Signed-off-by: Wyes Karny <wyes.karny@xxxxxxx>
>> ---
>> arch/x86/events/rapl.c | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
>> index 52e6e7ed4f78..d301bbbc3b93 100644
>> --- a/arch/x86/events/rapl.c
>> +++ b/arch/x86/events/rapl.c
>> @@ -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,
>> };
>>
>
> 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,
>
> Tested-by: Oleksandr Natalenko <oleksandr@xxxxxxxxxxxxxx>
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.
>
> Thank you.
>
--
Thanks & Regards,
Wyes