PAPI 7.1.0.0
Loading...
Searching...
No Matches
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 */
32int
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 */
48int
50{
51#ifdef DEBUG_BGQ
52 printf( "CNKUNIT_init_component\n" );
53#endif
54
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 */
68int
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 */
89int
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 */
116int
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 */
137int
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 */
169int
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 */
184int
185CNKUNIT_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 */
201int
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 */
247int
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 */
275int
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 */
306int
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 */
329int
330CNKUNIT_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 */
365int
366CNKUNIT_ntv_name_to_code( const 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 */
395int
396CNKUNIT_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 */
425int
426CNKUNIT_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 */
446int
447CNKUNIT_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 */
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_native_events = CNKUNIT_MAX_COUNTERS-OFFSET+1,
468 .num_cntrs = CNKUNIT_MAX_COUNTERS,
469 .num_mpx_cntrs = CNKUNIT_MAX_COUNTERS,
470 .default_domain = PAPI_DOM_USER,
471 .available_domains = PAPI_DOM_USER | PAPI_DOM_KERNEL,
472 .default_granularity = PAPI_GRN_THR,
473 .available_granularities = PAPI_GRN_THR,
474
475 .hardware_intr_sig = PAPI_INT_SIGNAL,
476 .hardware_intr = 1,
477
478 .kernel_multiplex = 0,
479
480 /* component specific cmp_info initializations */
481 .fast_real_timer = 0,
482 .fast_virtual_timer = 0,
483 .attach = 0,
484 .attach_must_ptrace = 0,
485
486 }
487 ,
488
489 /* sizes of framework-opaque component-private structures */
490 .size = {
491 .context = sizeof ( CNKUNIT_context_t ),
492 .control_state = sizeof ( CNKUNIT_control_state_t ),
493 .reg_value = sizeof ( CNKUNIT_register_t ),
494 .reg_alloc = sizeof ( CNKUNIT_reg_alloc_t ),
495 }
496 ,
497 /* function pointers in this component */
498 .init_thread = CNKUNIT_init_thread,
499 .init_component = CNKUNIT_init_component,
500 .init_control_state = CNKUNIT_init_control_state,
501 .start = CNKUNIT_start,
502 .stop = CNKUNIT_stop,
503 .read = CNKUNIT_read,
504 .shutdown_thread = CNKUNIT_shutdown_thread,
505 .cleanup_eventset = CNKUNIT_cleanup_eventset,
506 .ctl = CNKUNIT_ctl,
507
508 .update_control_state = CNKUNIT_update_control_state,
509 .set_domain = CNKUNIT_set_domain,
510 .reset = CNKUNIT_reset,
511
512 .ntv_name_to_code = CNKUNIT_ntv_name_to_code,
513 .ntv_enum_events = CNKUNIT_ntv_enum_events,
514 .ntv_code_to_name = CNKUNIT_ntv_code_to_name,
515 .ntv_code_to_descr = CNKUNIT_ntv_code_to_descr,
516 .ntv_code_to_bits = CNKUNIT_ntv_code_to_bits
517};
int i
static long count
#define PAPI_DOM_USER
Definition: f90papi.h:174
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_DOM_OTHER
Definition: f90papi.h:21
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_DOM_KERNEL
Definition: f90papi.h:254
#define PAPI_ENOEVNT
Definition: f90papi.h:139
#define PAPI_EINVAL
Definition: f90papi.h:115
#define PAPI_GRN_THR
Definition: f90papi.h:265
char events[MAX_EVENTS][BUFSIZ]
int CNKUNIT_ntv_name_to_code(const char *name, unsigned int *event_code)
int CNKUNIT_ntv_code_to_name(unsigned int EventCode, char *name, int len)
int CNKUNIT_init_thread(hwd_context_t *ctx)
Definition: linux-CNKunit.c:33
int CNKUNIT_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
papi_vector_t _CNKunit_vector
Definition: linux-CNKunit.c:23
int CNKUNIT_set_domain(hwd_control_state_t *cntrl, int domain)
int CNKUNIT_update_control_state(hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
int CNKUNIT_stop(hwd_context_t *ctx, hwd_control_state_t *ptr)
int CNKUNIT_ntv_code_to_descr(unsigned int EventCode, char *name, int len)
int CNKUNIT_start(hwd_context_t *ctx, hwd_control_state_t *ptr)
Definition: linux-CNKunit.c:90
int CNKUNIT_shutdown_thread(hwd_context_t *ctx)
int CNKUNIT_init_control_state(hwd_control_state_t *ptr)
Definition: linux-CNKunit.c:69
int CNKUNIT_cleanup_eventset(hwd_control_state_t *ctrl)
int CNKUNIT_reset(hwd_context_t *ctx, hwd_control_state_t *ptr)
int CNKUNIT_init_component(int cidx)
Definition: linux-CNKunit.c:49
int CNKUNIT_ntv_code_to_bits(unsigned int EventCode, hwd_register_t *bits)
int CNKUNIT_read(hwd_context_t *ctx, hwd_control_state_t *ptr, long_long **events, int flags)
int CNKUNIT_ntv_enum_events(unsigned int *EventCode, int modifier)
This file has the source code for a component that enables PAPI-C to access hardware monitoring count...
#define OFFSET
Definition: linux-CNKunit.h:36
#define CNKUNIT_MAX_COUNTERS
Definition: linux-CNKunit.h:35
int _common_deleteRecreate(int *EventGroup_ptr)
long_long _common_getEventValue(unsigned event_id, int EventGroup)
int _check_BGPM_error(int err, char *bgpmfunc)
#define long_long
Definition: papi.h:559
#define PAPI_INT_SIGNAL
Definition: papi_internal.h:52
static int native
static int cidx
#define MAX_COUNTERS
Definition: perfctr-x86.h:8
const char * name
Definition: rocs.c:225
long long counts[CNKUNIT_MAX_COUNTERS]
Definition: linux-CNKunit.h:57
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
int retval
Definition: zero_fork.c:53