Crates.io | rapl-energy |
lib.rs | rapl-energy |
version | 0.1.19 |
source | src |
created_at | 2024-06-21 08:58:14.921836 |
updated_at | 2024-11-22 10:18:07.464126 |
description | Small library for getting the CPU energy consumption from RAPL |
homepage | |
repository | https://github.com/JordyAaldering/rapl-energy |
max_upload_size | |
id | 1279272 |
size | 61,633 |
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.
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
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
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