#energy #sustainability #benchmarking

rapl-energy

Small library for getting the CPU energy consumption from RAPL

18 releases

new 0.1.17 Nov 19, 2024
0.1.16 Nov 6, 2024
0.1.15 Oct 22, 2024
0.1.13 Sep 17, 2024
0.1.2 Jun 26, 2024

#247 in Profiling

Download history 32/week @ 2024-07-27 381/week @ 2024-09-07 197/week @ 2024-09-14 54/week @ 2024-09-21 34/week @ 2024-09-28 4/week @ 2024-10-05 94/week @ 2024-10-12 197/week @ 2024-10-19 42/week @ 2024-10-26 132/week @ 2024-11-02 20/week @ 2024-11-09

484 downloads per month
Used in energy-bench

Apache-2.0

21KB
516 lines

Rapl Energy

Small library for getting the CPU energy consumption from RAPL and friends.

This project is very much still a work in progress, and is mainly intended for internal use. However I share it here should it be useful to anyone.

RAPL permissions

Reading RAPL requires elevated permissions.

I suggest adding a new rapl group.

sudo addgroup rapl
sudo usermod -aG rapl $(whoami)

And then adding the necessary entries to /etc/sysfs.conf. (Requires sysfsutils to be installed.)

mode class/powercap/intel-rapl:0/energy_uj = 0440
owner class/powercap/intel-rapl:0/energy_uj = root:rapl
mode class/powercap/intel-rapl:0:0/energy_uj = 0440
owner class/powercap/intel-rapl:0:0/energy_uj = root:rapl

MSR permissions

Reading model-specific registers (MSR) requires elevated permissions.

sudo apt install msr-tools

You might need to run modprobe as well.

modprobe msr

One can then print the accumulated energy value as follows. (Where -a prints all CPUs, and -u prints the value as an unsigned decimal.)

sudo rdmsr 0xC001029A -au

It seems that the executable must be run with sudo though. I still need to figure out if perhaps this can be done instead with a group.

sudo ./target/debug/examples/amd

MSR group

It might be useful to create a group for MSR. Sadly this does not resolve the above issue however.

sudo groupadd msr
sudo chgrp msr /dev/cpu/*/msr
sudo chmod g+rw /dev/cpu/*/msr
sudo usermod -aG msr $(whoami)
newgrp msr

Dependencies

~1.2–8MB
~69K SLoC