PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
linux-CNKunit.c
Go to the documentation of this file.
1 /****************************/
2 /* THIS IS OPEN SOURCE CODE */
3 /****************************/
4 
20 #include "linux-CNKunit.h"
21 
22 /* Declare our vector in advance */
24 
25 /*****************************************************************************
26  ******************* BEGIN PAPI's COMPONENT REQUIRED FUNCTIONS *************
27  *****************************************************************************/
28 
29 /*
30  * This is called whenever a thread is initialized
31  */
32 int
34 {
35 #ifdef DEBUG_BGQ
36  printf( "CNKUNIT_init_thread\n" );
37 #endif
38 
39  ( void ) ctx;
40  return PAPI_OK;
41 }
42 
43 
44 /* Initialize hardware counters, setup the function vector table
45  * and get hardware information, this routine is called when the
46  * PAPI process is initialized (IE PAPI_library_init)
47  */
48 int
50 {
51 #ifdef DEBUG_BGQ
52  printf( "CNKUNIT_init_component\n" );
53 #endif
54 
55  _CNKunit_vector.cmp_info.CmpIdx = cidx;
56 #ifdef DEBUG_BGQ
57  printf( "CNKUNIT_init_component cidx = %d\n", cidx );
58 #endif
59 
60  return ( PAPI_OK );
61 }
62 
63 
64 /*
65  * Control of counters (Reading/Writing/Starting/Stopping/Setup)
66  * functions
67  */
68 int
70 {
71 #ifdef DEBUG_BGQ
72  printf( "CNKUNIT_init_control_state\n" );
73 #endif
74  int retval;
75 
76  CNKUNIT_control_state_t * this_state = ( CNKUNIT_control_state_t * ) ptr;
77 
78  this_state->EventGroup = Bgpm_CreateEventSet();
79  retval = _check_BGPM_error( this_state->EventGroup, "Bgpm_CreateEventSet" );
80  if ( retval < 0 ) return retval;
81 
82  return PAPI_OK;
83 }
84 
85 
86 /*
87  *
88  */
89 int
91 {
92 #ifdef DEBUG_BGQ
93  printf( "CNKUNIT_start\n" );
94 #endif
95  ( void ) ctx;
96  int retval;
97  CNKUNIT_control_state_t * this_state = ( CNKUNIT_control_state_t * ) ptr;
98 
99  retval = Bgpm_Apply( this_state->EventGroup );
100  retval = _check_BGPM_error( retval, "Bgpm_Apply" );
101  if ( retval < 0 ) return retval;
102 
103  /* Bgpm_Apply() does an implicit reset;
104  hence no need to use Bgpm_ResetStart */
105  retval = Bgpm_Start( this_state->EventGroup );
106  retval = _check_BGPM_error( retval, "Bgpm_Start" );
107  if ( retval < 0 ) return retval;
108 
109  return ( PAPI_OK );
110 }
111 
112 
113 /*
114  *
115  */
116 int
118 {
119 #ifdef DEBUG_BGQ
120  printf( "CNKUNIT_stop\n" );
121 #endif
122  ( void ) ctx;
123  int retval;
124  CNKUNIT_control_state_t * this_state = ( CNKUNIT_control_state_t * ) ptr;
125 
126  retval = Bgpm_Stop( this_state->EventGroup );
127  retval = _check_BGPM_error( retval, "Bgpm_Stop" );
128  if ( retval < 0 ) return retval;
129 
130  return ( PAPI_OK );
131 }
132 
133 
134 /*
135  *
136  */
137 int
139  long_long ** events, int flags )
140 {
141 #ifdef DEBUG_BGQ
142  printf( "CNKUNIT_read\n" );
143 #endif
144  ( void ) ctx;
145  ( void ) flags;
146  int i, numEvts;
147  CNKUNIT_control_state_t * this_state = ( CNKUNIT_control_state_t * ) ptr;
148 
149  numEvts = Bgpm_NumEvents( this_state->EventGroup );
150  if ( numEvts == 0 ) {
151 #ifdef DEBUG_BGPM
152  printf ("Error: ret value is %d for BGPM API function Bgpm_NumEvents.\n", numEvts );
153 #endif
154  //return ( EXIT_FAILURE );
155  }
156 
157  for ( i = 0; i < numEvts; i++ )
158  this_state->counts[i] = _common_getEventValue( i, this_state->EventGroup );
159 
160  *events = this_state->counts;
161 
162  return ( PAPI_OK );
163 }
164 
165 
166 /*
167  *
168  */
169 int
171 {
172 #ifdef DEBUG_BGQ
173  printf( "CNKUNIT_shutdown_thread\n" );
174 #endif
175  ( void ) ctx;
176  return ( PAPI_OK );
177 }
178 
179 
180 /* This function sets various options in the component
181  * The valid codes being passed in are PAPI_SET_DEFDOM,
182  * PAPI_SET_DOMAIN, PAPI_SETDEFGRN, PAPI_SET_GRANUL * and PAPI_SET_INHERIT
183  */
184 int
185 CNKUNIT_ctl( hwd_context_t * ctx, int code, _papi_int_option_t * option )
186 {
187 #ifdef DEBUG_BGQ
188  printf( "CNKUNIT_ctl\n" );
189 #endif
190  ( void ) ctx;
191  ( void ) code;
192  ( void ) option;
193  return ( PAPI_OK );
194 }
195 
196 
197 
198 /*
199  *
200  */
201 int
203  NativeInfo_t * native, int count,
204  hwd_context_t * ctx )
205 {
206 #ifdef DEBUG_BGQ
207  printf( "CNKUNIT_update_control_state: count = %d\n", count );
208 #endif
209  ( void ) ctx;
210  int retval, index, i;
211  CNKUNIT_control_state_t * this_state = ( CNKUNIT_control_state_t * ) ptr;
212 
213  // Delete and re-create BGPM eventset
214  retval = _common_deleteRecreate( &this_state->EventGroup );
215  if ( retval < 0 ) return retval;
216 
217  // otherwise, add the events to the eventset
218  for ( i = 0; i < count; i++ ) {
219  index = ( native[i].ni_event ) + OFFSET;
220 
221  native[i].ni_position = i;
222 
223 #ifdef DEBUG_BGQ
224  printf("CNKUNIT_update_control_state: ADD event: i = %d, index = %d\n", i, index );
225 #endif
226 
227  /* Add events to the BGPM eventGroup */
228  retval = Bgpm_AddEvent( this_state->EventGroup, index );
229  retval = _check_BGPM_error( retval, "Bgpm_AddEvent" );
230  if ( retval < 0 ) return retval;
231  }
232 
233  return ( PAPI_OK );
234 }
235 
236 
237 /*
238  * This function has to set the bits needed to count different domains
239  * In particular: PAPI_DOM_USER, PAPI_DOM_KERNEL PAPI_DOM_OTHER
240  * By default return PAPI_EINVAL if none of those are specified
241  * and PAPI_OK with success
242  * PAPI_DOM_USER is only user context is counted
243  * PAPI_DOM_KERNEL is only the Kernel/OS context is counted
244  * PAPI_DOM_OTHER is Exception/transient mode (like user TLB misses)
245  * PAPI_DOM_ALL is all of the domains
246  */
247 int
249 {
250 #ifdef DEBUG_BGQ
251  printf( "CNKUNIT_set_domain\n" );
252 #endif
253  int found = 0;
254  ( void ) cntrl;
255 
256  if ( PAPI_DOM_USER & domain )
257  found = 1;
258 
259  if ( PAPI_DOM_KERNEL & domain )
260  found = 1;
261 
262  if ( PAPI_DOM_OTHER & domain )
263  found = 1;
264 
265  if ( !found )
266  return ( PAPI_EINVAL );
267 
268  return ( PAPI_OK );
269 }
270 
271 
272 /*
273  *
274  */
275 int
277 {
278 #ifdef DEBUG_BGQ
279  printf( "CNKUNIT_reset\n" );
280 #endif
281  ( void ) ctx;
282  int retval;
283  CNKUNIT_control_state_t * this_state = ( CNKUNIT_control_state_t * ) ptr;
284 
285  /* we can't simply call Bgpm_Reset() since PAPI doesn't have the
286  restriction that an EventSet has to be stopped before resetting is
287  possible. However, BGPM does have this restriction.
288  Hence we need to stop, reset and start */
289  retval = Bgpm_Stop( this_state->EventGroup );
290  retval = _check_BGPM_error( retval, "Bgpm_Stop" );
291  if ( retval < 0 ) return retval;
292 
293  retval = Bgpm_ResetStart( this_state->EventGroup );
294  retval = _check_BGPM_error( retval, "Bgpm_ResetStart" );
295  if ( retval < 0 ) return retval;
296 
297  return ( PAPI_OK );
298 }
299 
300 
301 /*
302  * PAPI Cleanup Eventset
303  *
304  * Destroy and re-create the BGPM / CNKunit EventSet
305  */
306 int
308 {
309 #ifdef DEBUG_BGQ
310  printf( "CNKUNIT_cleanup_eventset\n" );
311 #endif
312  int retval;
313 
314  CNKUNIT_control_state_t * this_state = ( CNKUNIT_control_state_t * ) ctrl;
315 
316  // create a new empty bgpm eventset
317  // reason: bgpm doesn't permit to remove events from an eventset;
318  // hence we delete the old eventset and create a new one
319  retval = _common_deleteRecreate( &this_state->EventGroup ); // HJ try to use delete() only
320  if ( retval < 0 ) return retval;
321 
322  return ( PAPI_OK );
323 }
324 
325 
326 /*
327  * Native Event functions
328  */
329 int
330 CNKUNIT_ntv_enum_events( unsigned int *EventCode, int modifier )
331 {
332 #ifdef DEBUG_BGQ
333 // printf( "CNKUNIT_ntv_enum_events\n" );
334 #endif
335 
336  switch ( modifier ) {
337  case PAPI_ENUM_FIRST:
338  *EventCode = 0;
339 
340  return ( PAPI_OK );
341  break;
342 
343  case PAPI_ENUM_EVENTS:
344  {
345  int index = ( *EventCode ) + OFFSET;
346 
347  if ( index < CNKUNIT_MAX_COUNTERS ) {
348  *EventCode = *EventCode + 1;
349  return ( PAPI_OK );
350  } else
351  return ( PAPI_ENOEVNT );
352 
353  break;
354  }
355  default:
356  return ( PAPI_EINVAL );
357  }
358  return ( PAPI_EINVAL );
359 }
360 
361 
362 /*
363  *
364  */
365 int
366 CNKUNIT_ntv_name_to_code( char *name, unsigned int *event_code )
367 {
368 #ifdef DEBUG_BGQ
369  printf( "CNKUNIT_ntv_name_to_code\n" );
370 #endif
371  int ret;
372 
373  /* Return event id matching a given event label string */
374  ret = Bgpm_GetEventIdFromLabel ( name );
375 
376  if ( ret <= 0 ) {
377 #ifdef DEBUG_BGPM
378  printf ("Error: ret value is %d for BGPM API function '%s'.\n",
379  ret, "Bgpm_GetEventIdFromLabel" );
380 #endif
381  return PAPI_ENOEVNT;
382  }
383  else if ( ret < OFFSET || ret > CNKUNIT_MAX_COUNTERS ) // not a CNKUnit event
384  return PAPI_ENOEVNT;
385  else
386  *event_code = ( ret - OFFSET ) ;
387 
388  return PAPI_OK;
389 }
390 
391 
392 /*
393  *
394  */
395 int
396 CNKUNIT_ntv_code_to_name( unsigned int EventCode, char *name, int len )
397 {
398 #ifdef DEBUG_BGQ
399  //printf( "CNKUNIT_ntv_code_to_name\n" );
400 #endif
401  int index;
402 
403  index = ( EventCode ) + OFFSET;
404 
405  if ( index >= MAX_COUNTERS )
406  return PAPI_ENOEVNT;
407 
408  strncpy( name, Bgpm_GetEventIdLabel( index ), len );
409  //printf("----%s----\n", name);
410 
411  if ( name == NULL ) {
412 #ifdef DEBUG_BGPM
413  printf ("Error: ret value is NULL for BGPM API function Bgpm_GetEventIdLabel.\n" );
414 #endif
415  return PAPI_ENOEVNT;
416  }
417 
418  return ( PAPI_OK );
419 }
420 
421 
422 /*
423  *
424  */
425 int
426 CNKUNIT_ntv_code_to_descr( unsigned int EventCode, char *name, int len )
427 {
428 #ifdef DEBUG_BGQ
429  //printf( "CNKUNIT_ntv_code_to_descr\n" );
430 #endif
431  int retval, index;
432 
433  index = ( EventCode ) + OFFSET;
434 
435  retval = Bgpm_GetLongDesc( index, name, &len );
436  retval = _check_BGPM_error( retval, "Bgpm_GetLongDesc" );
437  if ( retval < 0 ) return retval;
438 
439  return ( PAPI_OK );
440 }
441 
442 
443 /*
444  *
445  */
446 int
447 CNKUNIT_ntv_code_to_bits( unsigned int EventCode, hwd_register_t * bits )
448 {
449 #ifdef DEBUG_BGQ
450  printf( "CNKUNIT_ntv_code_to_bits\n" );
451 #endif
452  ( void ) EventCode;
453  ( void ) bits;
454  return ( PAPI_OK );
455 }
456 
457 
458 /*
459  *
460  */
461 papi_vector_t _CNKunit_vector = {
462  .cmp_info = {
463  /* default component information (unspecified values are initialized to 0) */
464  .name = "bgpm/CNKUnit",
465  .short_name = "CNKUnit",
466  .description = "Blue Gene/Q CNKUnit component",
467  .num_cntrs = CNKUNIT_MAX_COUNTERS,
468  .num_mpx_cntrs = CNKUNIT_MAX_COUNTERS,
469  .default_domain = PAPI_DOM_USER,
470  .available_domains = PAPI_DOM_USER | PAPI_DOM_KERNEL,
471  .default_granularity = PAPI_GRN_THR,
472  .available_granularities = PAPI_GRN_THR,
473 
474  .hardware_intr_sig = PAPI_INT_SIGNAL,
475  .hardware_intr = 1,
476 
477  .kernel_multiplex = 0,
478 
479  /* component specific cmp_info initializations */
480  .fast_real_timer = 0,
481  .fast_virtual_timer = 0,
482  .attach = 0,
483  .attach_must_ptrace = 0,
484 
485  }
486  ,
487 
488  /* sizes of framework-opaque component-private structures */
489  .size = {
490  .context = sizeof ( CNKUNIT_context_t ),
491  .control_state = sizeof ( CNKUNIT_control_state_t ),
492  .reg_value = sizeof ( CNKUNIT_register_t ),
493  .reg_alloc = sizeof ( CNKUNIT_reg_alloc_t ),
494  }
495  ,
496  /* function pointers in this component */
497  .init_thread = CNKUNIT_init_thread,
498  .init_component = CNKUNIT_init_component,
499  .init_control_state = CNKUNIT_init_control_state,
500  .start = CNKUNIT_start,
501  .stop = CNKUNIT_stop,
502  .read = CNKUNIT_read,
503  .shutdown_thread = CNKUNIT_shutdown_thread,
504  .cleanup_eventset = CNKUNIT_cleanup_eventset,
505  .ctl = CNKUNIT_ctl,
506 
507  .update_control_state = CNKUNIT_update_control_state,
508  .set_domain = CNKUNIT_set_domain,
509  .reset = CNKUNIT_reset,
510 
511  .ntv_name_to_code = CNKUNIT_ntv_name_to_code,
512  .ntv_enum_events = CNKUNIT_ntv_enum_events,
513  .ntv_code_to_name = CNKUNIT_ntv_code_to_name,
514  .ntv_code_to_descr = CNKUNIT_ntv_code_to_descr,
515  .ntv_code_to_bits = CNKUNIT_ntv_code_to_bits
516 };
int CNKUNIT_shutdown_thread(hwd_context_t *ctx)
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
int CNKUNIT_init_control_state(hwd_control_state_t *ptr)
Definition: linux-CNKunit.c:69
#define CNKUNIT_MAX_COUNTERS
Definition: linux-CNKunit.h:35
long long flags
Definition: iozone.c:12330
#define PAPI_ENOEVNT
Definition: fpapi.h:112
int _common_deleteRecreate(int *EventGroup_ptr)
int _check_BGPM_error(int err, char *bgpmfunc)
#define MAX_COUNTERS
Definition: perfctr-x86.h:8
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
#define PAPI_DOM_OTHER
Definition: fpapi.h:23
#define PAPI_DOM_KERNEL
Definition: fpapi.h:22
void
Definition: iozone.c:18627
return PAPI_EINVAL
Definition: linux-nvml.c:408
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
#define printf
Definition: papi_test.h:125
long long ret
Definition: iozone.c:1346
int CNKUNIT_ntv_code_to_name(unsigned int EventCode, char *name, int len)
papi_vector_t _CNKunit_vector
Definition: linux-CNKunit.c:23
int CNKUNIT_update_control_state(hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
int i
Definition: fileop.c:140
int CNKUNIT_start(hwd_context_t *ctx, hwd_control_state_t *ptr)
Definition: linux-CNKunit.c:90
long long found
Definition: libasync.c:735
static int cidx
Definition: event_info.c:40
int CNKUNIT_init_thread(hwd_context_t *ctx)
Definition: linux-CNKunit.c:33
This file has the source code for a component that enables PAPI-C to access hardware monitoring count...
int CNKUNIT_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
static int native
Definition: event_info.c:39
long long counts[CNKUNIT_MAX_COUNTERS]
Definition: linux-CNKunit.h:57
#define OFFSET
Definition: linux-CNKunit.h:36
char events[MAX_EVENTS][BUFSIZ]
long_long _common_getEventValue(unsigned event_id, int EventGroup)
#define PAPI_INT_SIGNAL
Definition: papi_internal.h:53
int CNKUNIT_ntv_name_to_code(char *name, unsigned int *event_code)
int CNKUNIT_cleanup_eventset(hwd_control_state_t *ctrl)
int CNKUNIT_read(hwd_context_t *ctx, hwd_control_state_t *ptr, long_long **events, int flags)
int CNKUNIT_ntv_code_to_bits(unsigned int EventCode, hwd_register_t *bits)
char * name
Definition: iozone.c:23648
int CNKUNIT_ntv_code_to_descr(unsigned int EventCode, char *name, int len)
#define long_long
Definition: papi.h:549
int CNKUNIT_set_domain(hwd_control_state_t *cntrl, int domain)
int CNKUNIT_reset(hwd_context_t *ctx, hwd_control_state_t *ptr)
int CNKUNIT_ntv_enum_events(unsigned int *EventCode, int modifier)
int CNKUNIT_init_component(int cidx)
Definition: linux-CNKunit.c:49
#define PAPI_DOM_USER
Definition: fpapi.h:21
ssize_t retval
Definition: libasync.c:338
#define PAPI_GRN_THR
Definition: fpapi.h:67
int CNKUNIT_stop(hwd_context_t *ctx, hwd_control_state_t *ptr)
char * ptr
Definition: iozone.c:23586