Reading RAPL energy measurements from Linux

Reading RAPL energy measurements from Linux


RAPL support

I also have a list of processors and when Linux added support for their power interfaces.

RAPL validation

I also have a page describing my RAPL validation work.

RAPL on Linux

There are currently *three* ways to read RAPL results using the Linux kernel: Not that you cannot get readings for individual processes, the results are for the entire CPU socket.


Userspace Access without perf

Here is some quick code to read the RAPL values without the perf tool. It can read all three interfaces (syfs powercap, perf_event, or msr) depending on the command line options.

You need to either run as root or have the /dev/cpu/*/msr permissions set for msr access.

The sample program produces results like the following.

Power units = 0.125W
Energy units = 0.00001526J
Time units = 0.00097656s

Package thermal spec: 130.000W
Package minimum power: 51.000W
Package maximum power: 200.000W
Package maximum time window: 0.046s

Package energy before: 48460.887909J
PowerPlane0 (core) for core 0 energy before: 36127.280838J
DRAM energy before: 0.000000J

Sleeping 1 second

Package energy after: 48468.194504  (7.306595J consumed)
PowerPlane0 (core) for core 0 energy after: 36128.297287  (1.016449J consumed)
DRAM energy after: 0.000000  (0.000000J consumed)

Note: the energy measurements can overflow in 60s or so
      so try to sample the counters more often than that.


Source code: rapl-read.c

Also available from: https://github.com/deater/uarch-configure

PAPI

PAPI can read the RAPL values in various ways. We are working on consolidating them into one component rather than having multiple confusing ways of gathering the info.
Trying all RAPL events
Found rapl component at cid 2

Starting measurements...

Doing a naive 1024x1024 MMM...
Matrix multiply sum: s=1016404871450364.375000

Stopping measurements, took 4.110s, gathering results...

Energy measurements:
PACKAGE_ENERGY:PACKAGE0   176.450363J   (Average Power 42.9W)
PACKAGE_ENERGY:PACKAGE1    75.812454J   (Average Power 18.4W)
DRAM_ENERGY:PACKAGE0       11.899246J   (Average Power 2.9W)
DRAM_ENERGY:PACKAGE1        8.341141J   (Average Power 2.0W)
PP0_ENERGY:PACKAGE0       118.029236J   (Average Power 28.7W)
PP0_ENERGY:PACKAGE1        16.759064J   (Average Power 4.1W)

Fixed values:
THERMAL_SPEC:PACKAGE0        135.000W
THERMAL_SPEC:PACKAGE1        135.000W
MINIMUM_POWER:PACKAGE0        51.000W
MINIMUM_POWER:PACKAGE1        51.000W
MAXIMUM_POWER:PACKAGE0       215.000W
MAXIMUM_POWER:PACKAGE1       215.000W
MAXIMUM_TIME_WINDOW:PACKAGE0   0.046s
MAXIMUM_TIME_WINDOW:PACKAGE1   0.046s
rapl_basic.c                           PASSED

RAPL Tool

This tool uses PAPI to poll a machine's RAPL energy usage and dump the results to various files which can then be plotted.

Here is some sample results generated using the tool:


And here is the tool. To use it you'll need to modify the Makefile to build against a recent version of PAPI compiled with --with-component="rapl".


Documentation

More details on the RAPL interface can be found in the Intel Dev manuals, Volume 3.

For notes on possibly measuring these values on Windows see here
Back to my projects page