Using native events

Open discussion of PAPI.

Using native events

Postby iomartin » Wed Feb 19, 2014 4:33 pm

Hello,

I would like to know how to add native events with PAPI_add_event(). For example, below is one of the outputs of papi_native_avail. How do I use it and use unit masks as well?

Also, can I use raw event numbers, taken directly from the manufacturer's manual? How should I do this?

Thank you

Code: Select all
===============================================================================
 Native Events in Component: perf_event
===============================================================================
| ix86arch::UNHALTED_CORE_CYCLES                                               |
|            count core clock cycles whenever the clock signal on the specific  |
|            core is running (not halted)                                      |
|     :e=0                                                                     |
|            edge level (may require counter-mask >= 1)                        |
|     :i=0                                                                     |
|            invert                                                            |
|     :c=0                                                                     |
|            counter-mask in range [0-255]                                     |
|     :t=0                                                                     |
|            measure any thread                                                |
|     :u=0                                                                     |
|            monitor at user level                                             |
|     :k=0                                                                     |
|            monitor at kernel level                                           |
--------------------------------------------------------------------------------
iomartin
 
Posts: 4
Joined: Wed Feb 19, 2014 4:26 pm

Re: Using native events

Postby danterpstra » Fri Feb 21, 2014 5:33 pm

Using native events is not much different than using PAPI preset events. You must use the low level PAPI interface, because native events aren't supported by the high level interface, but it requires basically the same steps:
  • Create an event set
  • Add (native) events to that event set, either by name or by event code
  • Start, stop and read the eventset as usual.
It's ok to mix and match native and preset events in the same event set, but you must use PAPI's internal opaque event codes as produced by PAPI_event_name_to_code(), not bitmaps from vendor documentation.
The unit masks shown in the example you provide allow access to some of the more esoteric flags that are available for many events. You generally don't need to use them. If you do, simply append them to the end of the native event name, separated by a colon(:). Multiple masks can be appended to the same event name, but keep in mind that sometimes they are mutually exclusive.
For more examples of how unit masks are used in practice, take a look at the papi_events.csv file, which contains preset event definitions in terms of the native events they contain.
danterpstra
 
Posts: 63
Joined: Wed Jun 23, 2010 2:21 pm

Re: Using native events

Postby iomartin » Wed Feb 26, 2014 9:57 am

Hi,

I copied the code from PAPI_add_remove_event.c from the examples directory and just added a new event to the Event Set:

Code: Select all
if ( (retval = PAPI_add_event(EventSet, CPU_TO_DRAM_REQUESTS_TO_TARGET_NODE:LOCAL_TO_NODE_0)) != PAPI_OK)
    ERROR_RETURN(retval);


When I tried compiling, though, gcc complained about CPU_TO_DRAM_REQUESTS_TO_TARGET_NODE being undeclared. I looked through the header files and couldn't find the one to include. Which one such i add? Or do I need to add any other flag when compiling? The command below compiles fine without my new event.

Code: Select all
gcc -I $PAPI_SRC papi.c $PAPI_SRC/libpapi.a
iomartin
 
Posts: 4
Joined: Wed Feb 19, 2014 4:26 pm

Re: Using native events

Postby James Ralph » Wed Feb 26, 2014 1:14 pm

For historical reasons, PAPI_add_event uses an internal 'event code'.
You probably want to use PAPI_add_named_event().

eg
if ( (retval = PAPI_add_named_event(EventSet, "CPU_TO_DRAM_REQUESTS_TO_TARGET_NODE:LOCAL_TO_NODE_0")) != PAPI_OK)
James Ralph
 
Posts: 20
Joined: Tue Aug 25, 2009 2:43 pm

Re: Using native events

Postby iomartin » Wed Feb 26, 2014 4:02 pm

Thanks, James.

I hadn't realized that I should be using the event name between quotation marks. Anyway, I compiled my code and ran it, but PAPI_add_named_event returned error code -1.

My processor is an AMD Interlagos (family 15h) and I'm running Linux 3.8. I'm not sure if PAPI uses perf under the hood, if it does the problem is then that perf only added support for Northbridge events on version 3.9. If that's not the case, I don't know what I'm doing wrong. Any help is appreciated. I have PAPI's latest version.

I was able to profile other "simpler" (non-northbridge) events, such as RETIRED_BRANCH_PREDICTION and CYCLES_FPU_EMPTY.

I just realized that northbridge events are disabled:

Code: Select all
$ papi_component_avail
Compiled-in components:
Name:   perf_event              Linux perf_event CPU counters
Name:   perf_event_uncore       Linux perf_event CPU uncore and northbridge
   \-> Disabled: No uncore PMUs or events found

Active components:
Name:   perf_event              Linux perf_event CPU counters
                                Native: 194, Preset: 40, Counters: 6


--------------------------------------------------------------------------------
component.c                             PASSED


What did I miss during compilation?
iomartin
 
Posts: 4
Joined: Wed Feb 19, 2014 4:26 pm

Re: Using native events

Postby James Ralph » Wed Feb 26, 2014 4:28 pm

Thats exactly it, PAPI relies on perf to access the hardware.
James Ralph
 
Posts: 20
Joined: Tue Aug 25, 2009 2:43 pm

Re: Using native events

Postby iomartin » Thu Feb 27, 2014 10:40 pm

I updated Linux to 3.10 and reinstalled PAPI. I still get the same error (-1) when I try to use PAPI_add_named_even() and papi_component_avail returns the same output:

Code: Select all
Name:   perf_event_uncore       Linux perf_event CPU uncore and northbridge
   \-> Disabled: No uncore PMUs or events found


What am I missing?
iomartin
 
Posts: 4
Joined: Wed Feb 19, 2014 4:26 pm


Return to General discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron