performancelinux-kernelperfenergy

I can't see perf's power/energy-cores option for measure power consumption


My system use Intel(R) Xeon(R) Gold processor and Centos, Linux kernel 5.5.2 version

perf version output is 5.5.2-1.el7.elrepo.x86_64

I won't get the power consumption of each core. so I tried this.

>>>  sudo perf stat -a -r 1 -e "power/energy-cores/" ./run
event syntax error: 'power/energy-cores/'
                           \___ unknown term

valid terms: event,config,config1,config2,name,period,percore

Initial error:
event syntax error: 'power/energy-cores/'
                           \___ unknown term

valid terms: event,config,config1,config2,name,period,percore
Run 'perf list' for a list of valid events

 Usage: perf stat [<options>] [<command>]

    -e, --event <event>   event selector. use 'perf list' to list available event

As you can see, an error occurred.

So I looked in /sys/bus/event_source/devices/power/events directory to see what events were here.

under results.

>>> ls /sys/bus/event_source/devices/power/events

energy-pkg  energy-pkg.scale  energy-pkg.unit  energy-ram  energy-ram.scale  energy-ram.unit

I can't see the power/energy-cores option. I just have only a power/energy-pkg and power/energy-ram option.

and some people had power/energy-gpu.

How can get energy-cores and energy-gpu?

>>> perf list | grep energy
  power/energy-pkg/                                  [Kernel PMU event]
  power/energy-ram/                                  [Kernel PMU event]


>>> sudo perf stat -a -r 1 -e "power/energy-pkg/" -e "power/energy-ram/" ./run
6765
 Performance counter stats for 'system wide':

              0.06 Joules power/energy-pkg/
              0.01 Joules power/energy-ram/

       0.001452589 seconds time elapsed

Solution

  • perf has added an uncore PMU to expose the Intel RAPL energy consumption counters. The events power/energy-cores and power/gpu in perf are mapped to the RAPL domains PP0 and PP1 respectively. You can see this here.

    static struct perf_msr rapl_msrs[] = {
        [PERF_RAPL_PP0]  = { MSR_PP0_ENERGY_STATUS,      &rapl_events_cores_group, test_msr },
        [PERF_RAPL_PKG]  = { MSR_PKG_ENERGY_STATUS,      &rapl_events_pkg_group,   test_msr },
        [PERF_RAPL_RAM]  = { MSR_DRAM_ENERGY_STATUS,     &rapl_events_ram_group,   test_msr },
        [PERF_RAPL_PP1]  = { MSR_PP1_ENERGY_STATUS,      &rapl_events_gpu_group,   test_msr },
        [PERF_RAPL_PSYS] = { MSR_PLATFORM_ENERGY_STATUS, &rapl_events_psys_group,  test_msr },
    };
    

    To read about RAPL domains, please visit the Intel Software Developers Manual Vol 3b (Chapter on Power and Thermal management).

    Each of these domains come with their own architectural capabilities. These capabilities will be indicated by presence of certain non-architectural MSRs in the processor. But the presence of these domains vary across different Intel processor model types. Some processor models will support all of these domains, some will only support a few.

    perf tries to probe for these RAPL MSRs and creates a rapl_model_match device table based on the model of the processor, following the msr and cstate module design.

    A snapshot of this is here.

    For example, you can see here that only the domains Package and DRAM are supported.

    static struct rapl_model model_knl = {
        .events     = BIT(PERF_RAPL_PKG) |
                      BIT(PERF_RAPL_RAM),
        .apply_quirk    = true,
    };
    

    So, in order to get the other events, you would have to use a system having a different processor model, thereby ensuring the presence of all the relevant RAPL MSRs. You cannot just build support into your existing system to magically use the energy-cores and gpu events.