Hardware Performance Counters, libcpc, and Solaris 10

I recently created a tutorial on using libcpc under Solaris 10. During my research I came across http://developers.sun.com/solaris/articles/optimizing_apps.html

This is an excellent article, but the sample application needed to be updated for Solaris 10. For my tutorial I updated the sample application.

The first interesting news is PAPI. see
http://icl.cs.utk.edu/papi/

PAPI proposes to solve one of the usability issues related to hw performance counters. Historically, one needed the chip architecture or programmers manual to determine what the available counters actually measured. With PAPI, generic events are defined that are valid across architectures. In OpenSolaris, there is a man page on generic_events. This man page explains the meaning of each generic event and maps generic events to chip specific events. This man page is useful for determining the chip specific events to use under Solaris 10, even though PAPI is not available under Solaris 10.

Here is an outline on how to use libcpc under Solaris 10 and OpenSolaris.

Open the library
rcw_cpc = cpc_open(cpuver);
If the open fails either hardware performance counters are not available or there is a library version mismatch.

create a cpc set
my_cpc_set = cpc_set_create(rcw_cpc);

define two events (Your hardware may support more)
my_event0 = "PAPI_tot_cyc";
my_event1 = "PAPI_tot_ins";

Add an event to my cpc set
i=cpc_set_add_request(rcw_cpc, my_cpc_set, my_event0, my_preset,CPC_COUNT_USER|CPC_COUNT_SYSTEM, 0, NULL);

create buffers to hold my results
diff = cpc_buf_create(rcw_cpc, my_cpc_set)

bind my set to my lwp and any threads it creates
i=cpc_bind_curlwp(rcw_cpc, my_cpc_set, CPC_BIND_LWP_INHERIT);

run my code
doit

doit will take samples
if (cpc_set_sample(rcw_cpc, my_cpc_set, before) == -1)
code
if (cpc_set_sample(rcw_cpc, my_cpc_set, after) == -1)

calculate the delta
cpc_buf_sub(rcw_cpc, diff, after, before);

retrieve the value
cpc_buf_get(rcw_cpc, diff, my_index[0], &pic0);

destroy the set prior to using new events
i=cpc_set_destroy(rcw_cpc, my_cpc_set);

since the set is destroyed, the buffers must be destroyed also
cpc_buf_destroy(rcw_cpc, diff)


The sample application is available here:

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

user12610965

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today