Measuring Power with PAPI Examples?

867 views
Skip to first unread message

Khaled Z Mahmoud

unread,
Mar 27, 2018, 8:51:00 PM3/27/18
to ptools-...@icl.utk.edu
Any source code sample of how to measure energy/power with PAPI ?

--
Regards,
Khaled Mahmoud

Heike Jagode

unread,
Mar 27, 2018, 9:18:30 PM3/27/18
to Khaled Z Mahmoud, ptools-perfapi
Yes, each PAPI component for energy/power monitoring also ships with tests. For CPU power monitoring and capping, check out the tests directory under:
<papi dir>/src/components/rapl/tests
<papi dir>/src/components/powercap/tests

The same is true for the nvml component which enables power monitoring and capping features for NVIDIA GPUs:
<papi dir>/src/components/nvml/tests

Heike

--
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-perfapi+unsubscribe@icl.utk.edu.
To post to this group, send email to ptools-...@icl.utk.edu.
Visit this group at https://groups.google.com/a/icl.utk.edu/group/ptools-perfapi/.



--
___________________________________
Heike Jagode
Innovative Computing Laboratory (ICL)
University of Tennessee, Knoxville
http://icl.utk.edu/~jagode/

Khaled Z Mahmoud

unread,
Mar 28, 2018, 9:13:02 PM3/28/18
to Heike Jagode, ptools-perfapi
The PAPI_num_components() only returns "perf_event" and "perf_event_uncore".
No rapl is returned

Any ideas ?!
--
Regards,
Khaled Mahmoud

Khaled Z Mahmoud

unread,
Mar 28, 2018, 9:16:37 PM3/28/18
to Heike Jagode, ptools-perfapi
Will try "--with-components="rapl" and see.
I thought it is included by default in the compilation.
--
Regards,
Khaled Mahmoud

Khaled Z Mahmoud

unread,
Mar 28, 2018, 11:16:06 PM3/28/18
to Heike Jagode, ptools-perfapi
What does an event code with "-17" mean ?
All other events are being nicely added to the set excep the rapl ones.

PAPI RAPL Event codes should be static per platform ... Correct ?


    #define PACKAGE_ENERGY_PACKAGE0 1073741882
    #define DRAM_ENERGY_PACKAGE0 1073741883

        int retval=0;

        if ((retval = PAPI_add_event(EventSet, PACKAGE_ENERGY_PACKAGE0)) != PAPI_OK) {
                printf("Cannot add event to event set %s %d \n", "PACKAGE_ENERGY_PACKAGE0", retval);
                exit(0);
        }


        if ((retval = PAPI_add_event(EventSet, DRAM_ENERGY_PACKAGE0)) != PAPI_OK) {
                printf("Cannot add event to event set %s %d \n", "DRAM_ENERGY_PACKAGE0", retval);
                exit(0);
        }
}
--
Regards,
Khaled Mahmoud

Vince Weaver

unread,
Mar 29, 2018, 8:05:57 AM3/29/18
to Khaled Z Mahmoud, Heike Jagode, ptools-perfapi
On Wed, 28 Mar 2018, Khaled Z Mahmoud wrote:

> What does an event code with "-17" mean ?
> All other events are being nicely added to the set excep the rapl ones.

You can use PAPI_strerror() to translate the error messages.

> PAPI RAPL Event codes should be static per platform ... Correct ?
>
>
>     #define PACKAGE_ENERGY_PACKAGE0 1073741882
>     #define DRAM_ENERGY_PACKAGE0 1073741883

You should probably use PAPI_add_event_named() and the string names for
the events, I don't think these events numbers are guaranteed to be
stable.

what does "papi_component_avail" say? You probably need special
permissions on /dev/msr or else run as root assuming you're using the
regular RAPL component.

Vince

Khaled Z Mahmoud

unread,
Mar 29, 2018, 11:30:12 AM3/29/18
to Vince Weaver, Heike Jagode, ptools-perfapi
The PAPI_strerror() does not return anything. -17 is not even in the range of valid error codes.

Vince Weaver

unread,
Mar 29, 2018, 11:37:20 AM3/29/18
to Khaled Z Mahmoud, Heike Jagode, ptools-perfapi
On Thu, 29 Mar 2018, Khaled Z Mahmoud wrote:

> The PAPI_strerror() does not return anything.

That seems unlikely. What does your code look like?

> -17 is not even in the range of valid error codes.

Traditionally error codes are returned as negative, so you would look up
error code 17 if you were trying to do this manually for some reason.
Error code 17 is PAPI_ENOCMP, so as I said earlier your best bet of seeing
what is wrong is running "papi_component_avail".


Khaled Z Mahmoud

unread,
Mar 29, 2018, 8:21:57 PM3/29/18
to Vince Weaver, Heike Jagode, ptools-perfapi
Do I add energy energy counters and performance counters in the same EventSet ?
--
Regards,
Khaled Mahmoud

Khaled Z Mahmoud

unread,
Mar 29, 2018, 10:09:04 PM3/29/18
to Vince Weaver, Heike Jagode, ptools-perfapi
Seems the answer is no. I have to have two events sets, one for the performance counters(perf) and one for rapl.

How about someone adding this to the Wiki ?

Heike Jagode

unread,
Mar 29, 2018, 10:23:23 PM3/29/18
to Khaled Z Mahmoud, Vince Weaver, ptools-perfapi
The following wiki page provides details about PAPI components and how to properly use them:
http://icl.cs.utk.edu/projects/papi/wiki/Introduction_to_PAPI-C

See:
An EventSet is bound to a specific PAPI component. Therefore, events from different component can't be added to the same EventSet. However, multiple EventSets can be defined and active simultaneously, but only one EventSet per Component can be enabled.

Bharadwaj Gorthy

unread,
Oct 12, 2018, 8:14:23 PM10/12/18
to ptools-perfapi
So, I am trying to measure power consumption of an algorithm that I have using PAPI calls and performance counters. I was able to do this on my intel skylake X86_64 processor using perf tools on ubuntu 16.04 and since this is an intel processor, I am assuming that PAPI reads from hardware counters using intel's RAPL. Although, what I actually want to measure is the power that is consumed on an ARM A9 cortex processor with armv7l architecture in a Zynq SoC which I was able to run linux on it with a kernel of some 3.x on it.

So, typically there are a lot of limitations in an embedded linux environment and is hard to "./configure" or "make" and things unless it is implemented in the kernel that is to be built. An alternative is to cross-compile PAPI for the Arm processor. I have seen a lot of posts where people were able to do it but am really not sure as to how even "./configure" is working or I mean since I am new to all of this and is being hard for me to follow up to.

After a while, with a lot of posts and looking at things, I was able to figure out how to configure but am facing issues.
I have done : 

./configure --with-CPU=arm --with-arch=armv7l --with-os=linux --with-libpfm4 --with-ffsll --with-walltimer=clock_realtime --with-virtualtimer=clock_cputime_id --with-tls=__thread CC="arm-linux-gnueabi-gcc" CXX="arm-linux-gnueabi-g++" --host=arm-none-linux-gnueabi

and then make the files but am not able to understand how the entire "cross-compile configure" thing works.

When I configured it just as is with the command on my processor and for the same processor (native-compilation) with "./configure" and no funky options, it worked well and I was able to see "libpapi.a" under /usr/local/lib and all the other files. I was also able to call some PAPI functions and was able to see how many hardware counters were on my processor using PAPI but no power measurements whatsoever (Didn't know how to read the counters and all).

Is there a way to read the power consumption at all using PAPI and not involving RAPL because I don't think that is available on the ARM processor?

But now, when I am trying to configure for ARM processor, it just seems not to work at all, for me. I could use some help here. Any of it is appreciated.
Thanks
Reply all
Reply to author
Forward
0 new messages