Using RAPL with the High Level API

250 views
Skip to first unread message

Akshat Ahuja

unread,
Feb 3, 2022, 9:27:52 AM2/3/22
to ptools-perfapi
Hello everybody,

I want to be able to use the RAPL functionality along with PAPI's high level API. I want to include it in the environment variable PAPI_EVENTS simply, like
export PAPI_EVENTS="PAPI_TOT_CYC,PAPI_L1_DCA,PAPI_L2_ICH,PAPI_L2_ICR", which works for my computer.

I have tried the basic tests for RAPL from the PAPI Bitbucket Repository and they work out fine. I am able to see the PP0 energy from them.

I have attached some sections from outputs that might be helpful for finding a solution.

1) papi_component_avail
--------------------------------------------------------------------------------
PAPI version             : 6.0.0.1
Operating system         : Linux 5.11.0-44-generic
Vendor string and code   : AuthenticAMD (2, 0x2)
Model string and code    : AMD Ryzen 5 4600H with Radeon Graphics (96, 0x60)
CPU revision             : 1.000000
CPUID                    : Family/Model/Stepping 23/96/1, 0x17/0x60/0x01
CPU Max MHz              : 3000
CPU Min MHz              : 1400
Total cores              : 12
SMT threads per core     : 2
Cores per socket         : 6
Sockets                  : 1
Cores per NUMA region    : 12
NUMA regions             : 1
Running in a VM          : no
Number Hardware Counters : 5
Max Multiplex Counters   : 384
Fast counter read (rdpmc): yes
--------------------------------------------------------------------------------

Compiled-in components:
Name:   perf_event              Linux perf_event CPU counters
Name:   perf_event_uncore       Linux perf_event CPU uncore and northbridge

Active components:
Name:   perf_event              Linux perf_event CPU counters
                                Native: 141, Preset: 17, Counters: 5
                                PMUs supported: perf, perf_raw, amd64_fam17h_zen2

Name:   perf_event_uncore       Linux perf_event CPU uncore and northbridge
                                Native: 1, Preset: 0, Counters: 3
                                PMUs supported: amd64_rapl


--------------------------------------------------------------------------------

2) papi_native_avail
 Native Events in Component: perf_event_uncore
===============================================================================
| amd64_rapl::RAPL_ENERGY_PKG                                                  |
|            Number of Joules consumed by all cores and Last level cache on the|
|             package. Unit is 2^-32 Joules                                    |
|     :u=0                                                                     |
|            monitor at user level                                             |
|     :k=0                                                                     |
|            monitor at kernel level                                           |
|     :period=0                                                                |
|            sampling period                                                   |
|     :freq=0                                                                  |
|            sampling frequency (Hz)                                           |
|     :excl=0                                                                  |
|            exclusive access                                                  |
|     :mg=0                                                                    |
|            monitor guest execution                                           |
|     :mh=0                                                                    |
|            monitor host execution                                            |
|     :cpu=0                                                                   |
|            CPU to program                                                    |
|     :pinned=0                                                                |
|            pin event to counters                                             |
--------------------------------------------------------------------------------

3) Running rapl_basic
$ sudo chmod 666 /dev/cpu/*/msr
$ sudo setcap cap_sys_rawio=ep rapl_basic
$ ./rapl_basic
Trying all RAPL events
Found rapl component at cid 2

Starting measurements...

Sleeping 1 second...

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

Scaled energy measurements:
rapl:::PACKAGE_ENERGY:PACKAGE0              3.902161 J        (Average Power 3.9W)
rapl:::PP0_ENERGY:PACKAGE0                  0.011475 J        (Average Power 0.0W)

Energy measurement counts:
rapl:::PACKAGE_ENERGY_CNT:PACKAGE0            255732        0x03e6f4
rapl:::PP0_ENERGY_CNT:PACKAGE0                   752        0x0002f0

Scaled Fixed values:

Fixed value counts:
PASSED

4) RAPL added in the event set of the high level API and not working

$ gcc helloworld2.c -lpapi -o helloworld2
$ sudo setcap cap_sys_rawio=ep helloworld2
$ export PAPI_EVENTS="amd64_rapl::RAPL_ENERGY_PKG"
$ ./helloworld2

PAPI-HL Info: PAPI has been initiated!
PAPI-HL Warning: "amd64_rapl::RAPL_ENERGY_PKG" does not exist or is not supported on this machine.
PAPI-HL Warning: All requested events do not work, using default.
PAPI-HL Info: Using the following events:
  perf::TASK-CLOCK
  PAPI_TOT_INS
  PAPI_TOT_CYC
  PAPI_FP_INS
  PAPI_FP_OPS
Hello, World22222!PAPI-HL Info: Print results...



I have tried to use several different options for event name like "amd64_rapl::RAPL_ENERGY_PKG",  "RAPL_ENERGY_PKG",   "rapl::RAPL_ENERGY_PKG" for this, but I get the same output as above all the time.

I had doubts that RAPL is not compatible for my AMD laptop, however rapl_basic is working fine. So, I expected RAPL to work along with the High Level API as well. Does it not work with that?

Sincerely,
Akshat Ahuja
Department of Physics
IIT Kharagpur

Akash Dutta

unread,
Feb 3, 2022, 11:38:32 AM2/3/22
to Akshat Ahuja, ptools-perfapi
Hi Akshat,

To the best of my knowledge, RAPL events can be profiled using PAPI the same way you profile CPU events. However, in my experience it has to be tied to specific components. I had used the low-level API for doing something like this. 
For example in my system, regular CPU events can be collected on component 0. For RAPL events, it can be collected on component 2.
The main idea is to create an event set and then tie that event set to a specific component. 
You will of course have to identify the RAPL component number.

Thanks,
Akash

--
You received this message because you are subscribed to the Google Groups "ptools-perfapi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ptools-perfap...@icl.utk.edu.
To view this discussion on the web visit https://groups.google.com/a/icl.utk.edu/d/msgid/ptools-perfapi/957c64e9-0eec-4433-8353-344c05acc837n%40icl.utk.edu.

Frank Winkler

unread,
Feb 3, 2022, 11:44:52 AM2/3/22
to Akshat Ahuja, ptools-perfapi
Hi Akshat,

"amd64_rapl::RAPL_ENERGY_PKG" is an uncore event provided per CPU package/ socket. You need to specify the CPU package you want to monitor.

See: https://bitbucket.org/icl/papi/src/master/src/components/perf_event_uncore/README.md

Best,
Frank

On 3. Feb 2022, at 16:57, Akshat Ahuja <akshat...@gmail.com> wrote:

Thanks a lot for the suggestion. It worked wonderfully.
papi_command_line amd64_rapl::RAPL_ENERGY_PKG:cpu=0 works well.

However, I tried using RAPL as an instantaneous event, but that didn't work since RAPL_ENERGY_PKG is not an instantaneous event. So, I tried doing -
export PAPI_EVENTS="amd64_rapl::RAPL_ENERGY_PKG:cpu=0". This worked perfectly.

My issue was that I had not included the argument "cpu=0" along with the rest of the command as I did not know that I had to do that.
If possible, could you please point me to some source where I can understand the correct usage of commands and arguments like this as I want to use RAPL with the high level API for a project optimally and it would be great if similar to this I can also access the power values for DRAM (However, upto my understanding RAPL doesn't give values for that in AMD) and other subsystems in my computer. Even after reading all the documentation I came across, it did not occur to me to include "cpu=0" to my commands. So, I want to know if there is some other piece of knowledge that I am missing regarding the usage of RAPL.

Sincerely,
Akshat

On Thu, Feb 3, 2022 at 8:28 PM Frank Winkler <frank....@icl.utk.edu> wrote:
Hi Akshat,

Can you please try:

papi_command_line amd64_rapl::RAPL_ENERGY_PKG:cpu=0

If this works, please try:

export PAPI_EVENTS="amd64_rapl::RAPL_ENERGY_PKG:cpu=0=instant"

Note: You have to specify instantaneous events via =instant if using the high-level API.

Best,
Frank

Akshat Ahuja

unread,
Feb 3, 2022, 1:28:59 PM2/3/22
to ptools-perfapi, Frank Winkler, ptools-perfapi, Akshat Ahuja
Thanks a lot. This clears my doubts.
Reply all
Reply to author
Forward
0 new messages