powerapi-ng / powerapi

PowerAPI is a Python framework for building software-defined power meters.
https://powerapi.org
BSD 3-Clause "New" or "Revised" License
203 stars 35 forks source link

RAPL_ENERGY_PKG is invalid or unsupported by this machine #125

Open fmuyassarov opened 2 years ago

fmuyassarov commented 2 years ago

Hi Power API team,

I've tried to run a couple of tests, but apparently sensor is failing to start off, due to unsupported event group. The processor architecture in which I'm running tests has Willow Cove architecture, which is from 2020 (i.e. Sandy Brige +).

Machine characteristics:

Steps I took

  1. Install MongoDb (as docker container)
  2. Install powerapi-sensor (as docker container)
docker run --net=host --privileged --name powerapi-sensor -d \
           -v /tmp/sys:/sys -v /var/lib/docker/containers:/var/lib/docker/containers:ro \
           -v /tmp/powerapi-sensor-reporting:/reporting \
           powerapi/hwpc-sensor:latest \
           -n "powerapi" \
           -r "mongodb" -U "mongodb://127.0.0.1:27888" -D "db1" -C "col1" \
           -s "rapl" -o -e "RAPL_ENERGY_PKG" \
           -s "msr" -e "TSC" -e "APERF" -e "MPERF" \
           -c "core" -e "CPU_CLK_THREAD_UNHALTED:REF_P" -e "CPU_CLK_THREAD_UNHALTED:THREAD_P" \
                     -e "LLC_MISSES" -e "INSTRUCTIONS_RETIRED"

Container logs:

I: 21-12-07 11:14:26 build: version undefined (rev: undefined) (Sep 28 2021 - 14:40:24)
I: 21-12-07 11:14:26 uname: Linux 5.13.0-1020-oem #24-Ubuntu SMP Thu Nov 11 14:28:56 UTC 2021 x86_64
E: 21-12-07 11:14:26 config: event 'RAPL_ENERGY_PKG' is invalid or unsupported by this machine
E: 21-12-07 11:14:26 config: failed to parse the provided command-line arguments

I would appreciate if you could help out for me to move forward, do you think there is something I'm missing? Thanks.

fmuyassarov commented 2 years ago

/cc @altor @rouvoy

rouvoy commented 2 years ago

Thanks for reaching out @fmuyassarov, we will have a look to your issue with @ldesauw and come back to you asap.

fmuyassarov commented 2 years ago

Thanks a lot @rouvoy and @ldesauw . Let me know if there is more info needed from my side.

ldesauw commented 2 years ago

I've reproduced your problem on my machine using your command line. Could you try this one :

docker run --privileged --rm --name sensorhwpc --network="host" --pid host \
   -v /sys:/sys  \
   -v /var/lib/docker/containers:/var/lib/docker/containers:ro     \
   -v /tmp/powerapi-sensor-reporting:/reporting \
   powerapi/hwpc-sensor \
   -n sensor \
   -f 500 \
   -r mongodb -U "mongodb://127.0.0.1:27888" -D db -C col1 \
   -s "rapl" -o -e "RAPL_ENERGY_PKG" \
   -s "msr"     -e "TSC" -e "APERF" -e "MPERF" \
   -c "core"    -e "CPU_CLK_THREAD_UNHALTED:REF_P" \
                -e "CPU_CLK_THREAD_UNHALTED:THREAD_P" \
                -e "LLC_MISSES"\
                -e "INSTRUCTIONS_RETIRED"
ldesauw commented 2 years ago

The problem come from the fact that you are using /tmp/sys instead of /sys in the volumes. This folder is used to read rapl and /tmp/sys do not contain the needed information (like RAPL).

fmuyassarov commented 2 years ago

Thank you. That makes sense. But I still get the same error for the pkg + flags. I wonder if there is some kind of typo I'm doing when passing those arguments.

docker run --privileged --rm --name sensorhwpc --network="host" --pid host \
   -v /sys:/sys  \
   -v /var/lib/docker/containers:/var/lib/docker/containers:ro     \
   -v /tmp/powerapi-sensor-reporting:/reporting \
   powerapi/hwpc-sensor \
   -n sensor \
   -f 500 \
   -r mongodb -U "mongodb://127.0.0.1:27888" -D db1 -C col1 \
   -s "rapl" -o -e "RAPL_ENERGY_PKG"  \
   -s "msr" -e "TSC" -e "APERF" -e "MPERF"  \
   -c "core" -e "CPU_CLK_THREAD_UNHALTED:REF_P"  \
   -e "CPU_CLK_THREAD_UNHALTED:THREAD_P"  \
   -e "LLC_MISSES" \
   -e "INSTRUCTIONS_RETIRED"
I: 21-12-07 13:55:40 build: version undefined (rev: undefined) (Sep 28 2021 - 14:40:24)
I: 21-12-07 13:55:40 uname: Linux 5.13.0-1020-oem #24-Ubuntu SMP Thu Nov 11 14:28:56 UTC 2021 x86_64
E: 21-12-07 13:55:40 config: event 'RAPL_ENERGY_PKG' is invalid or unsupported by this machine
E: 21-12-07 13:55:40 config: failed to parse the provided command-line arguments
fmuyassarov commented 2 years ago

Just a heads up, there are some RAPL results available in the machine

$ ls /sys/class/powercap/intel-rapl:0
constraint_0_max_power_uw    constraint_0_time_window_us  constraint_1_power_limit_uw  constraint_2_name            device     intel-rapl:0:0       name       uevent
constraint_0_name            constraint_1_max_power_uw    constraint_1_time_window_us  constraint_2_power_limit_uw  enabled    intel-rapl:0:1       power
constraint_0_power_limit_uw  constraint_1_name            constraint_2_max_power_uw    constraint_2_time_window_us  energy_uj  max_energy_range_uj  subsystem
ldesauw commented 2 years ago

It appears that recent change in the kernel broke the way we acceded the perf counter, we are currently working on solving that.

fmuyassarov commented 2 years ago

I see, thanks for verifying. Do you know the hash of the commit that you think potentially broke the counter? Perhaps, meanwhile I can go back on the git history and try it out with older releases.

ldesauw commented 2 years ago

It's not a commit that broke the counter but an update on the linux kernel change the way to access counters via perf_event and we did not updated to the last version of the kernel yet. If you can try on a system with an older linux kernel it should work.

ldesauw commented 2 years ago

@fmuyassarov could you provide me your kernel version ?

fmuyassarov commented 2 years ago

Sure, it is 5.13.0-1020-oem

PierreRustOrange commented 2 years ago

Hi @fmuyassarov could you check you the module for rapl access is loaded ? see powerapi-ng/hwpc-sensor#20 for details.

fmuyassarov commented 2 years ago

Hi @PierreRustOrange . I think it isn't unfortunately

$ perf list | grep energy
$ sudo perf stat -a -e "power/energy-cores/" /bin/ls                              
event syntax error: 'power/energy-cores/'
                     \___ Cannot find PMU `power'. Missing kernel support?
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 events
fmuyassarov commented 2 years ago

I'm wondering if it's just issue with perf access

fmuyassarov commented 2 years ago

as you said I have rapl values, but the issue is with the access probably

$ sudo ./rapl-read

RAPL read -- use -s for sysfs, -p for perf_event, -m for msr

Found Unsupported model 140
 Processor type
    0 (0), 1 (0), 2 (0), 3 (0), 4 (0), 5 (0), 6 (0), 7 (0)

    Detected 8 cores in 1 packages

Trying sysfs powercap interface to gather results

    Sleeping 1 second

    Package 0
        package-0   : 6.549300J
        core    : 3.245536J
        uncore  : 0.044190J
fmuyassarov commented 2 years ago

@ldesauw I was able to run the sensor on 5.11.0-40-generic Kernel with no issues.

PierreRustOrange commented 2 years ago

@fmuyassarov : ok, correct me if I did not get this right :

Can you check that you have the right module when using 5.13.0-1020-oem ?

lsmod | grep rap
intel_rapl_msr         20480  0
intel_rapl_common      28672  2 intel_rapl_msr,processor_thermal_device
intel_rapl_perf        20480  0

If it's not the case you should be able to install it (see powerapi-ng/hwpc-sensor#20), please tell us if that solve the issue on that kernel version.

psolve commented 1 year ago

I was having the same issue with following setup, though my system has rapl drivers and perf is able to access it perfectly.

OS: Ubuntu 20.04.5 LTS
Linux Kernel: 5.15.0-58-generic
Processor: 12th Gen Intel® Core™ i5-12500 × 12 

After debugging the hwpc-sensor, I found that it's using _pfm_get_os_eventencoding from libpfm to verify the provided events.

Unfortunately, that library has not been updated according to the latest Linux perf interface.

So as a quick hack I commented the call in _src/events.c:setup_perf_eventattr and it works fine for me.

I don't have the time to create a proper fix. I hope it helps!