PAPI 7.1.0.0
Loading...
Searching...
No Matches
linux-NWunit.c
Go to the documentation of this file.
1/****************************/
2/* THIS IS OPEN SOURCE CODE */
3/****************************/
4
20#include "linux-NWunit.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( "NWUNIT_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( "NWUNIT_init_component\n" );
53#endif
54
56#ifdef DEBUG_BGQ
57 printf( "NWUNIT_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( "NWUNIT_init_control_state\n" );
73#endif
74 int retval;
75
76 NWUNIT_control_state_t * this_state = ( NWUNIT_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( "NWUNIT_start\n" );
94#endif
95
96 ( void ) ctx;
97 int retval;
98 NWUNIT_control_state_t * this_state = ( NWUNIT_control_state_t * ) ptr;
99
100 retval = Bgpm_Attach( this_state->EventGroup, UPC_NW_ALL_LINKS, 0);
101 retval = _check_BGPM_error( retval, "Bgpm_Attach" );
102 if ( retval < 0 ) return retval;
103
104 retval = Bgpm_ResetStart( this_state->EventGroup );
105 retval = _check_BGPM_error( retval, "Bgpm_ResetStart" );
106 if ( retval < 0 ) return retval;
107
108 return ( PAPI_OK );
109}
110
111
112/*
113 *
114 */
115int
117{
118#ifdef DEBUG_BGQ
119 printf( "NWUNIT_stop\n" );
120#endif
121 ( void ) ctx;
122 int retval;
123 NWUNIT_control_state_t * this_state = ( NWUNIT_control_state_t * ) ptr;
124
125 retval = Bgpm_Stop( this_state->EventGroup );
126 retval = _check_BGPM_error( retval, "Bgpm_Stop" );
127 if ( retval < 0 ) return retval;
128
129 return ( PAPI_OK );
130}
131
132
133/*
134 *
135 */
136int
138 long_long ** events, int flags )
139{
140#ifdef DEBUG_BGQ
141 printf( "NWUNIT_read\n" );
142#endif
143 ( void ) ctx;
144 ( void ) flags;
145 int i, numEvts;
146 NWUNIT_control_state_t * this_state = ( NWUNIT_control_state_t * ) ptr;
147
148 numEvts = Bgpm_NumEvents( this_state->EventGroup );
149 if ( numEvts == 0 ) {
150#ifdef DEBUG_BGPM
151 printf ("Error: ret value is %d for BGPM API function Bgpm_NumEvents.\n", numEvts );
152#endif
153 //return ( EXIT_FAILURE );
154 }
155
156 for ( i = 0; i < numEvts; i++ )
157 this_state->counts[i] = _common_getEventValue( i, this_state->EventGroup );
158
159 *events = this_state->counts;
160
161 return ( PAPI_OK );
162}
163
164
165/*
166 *
167 */
168int
170{
171#ifdef DEBUG_BGQ
172 printf( "NWUNIT_shutdown_thread\n" );
173#endif
174
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
185NWUNIT_ctl( hwd_context_t * ctx, int code, _papi_int_option_t * option )
186{
187#ifdef DEBUG_BGQ
188 printf( "NWUNIT_ctl\n" );
189#endif
190
191 ( void ) ctx;
192 ( void ) code;
193 ( void ) option;
194 return ( PAPI_OK );
195}
196
197
198//int NWUNIT_ntv_code_to_bits ( unsigned int EventCode, hwd_register_t * bits );
199
200
201/*
202 *
203 */
204int
207 hwd_context_t * ctx )
208{
209#ifdef DEBUG_BGQ
210 printf( "NWUNIT_update_control_state: count = %d\n", count );
211#endif
212 ( void ) ctx;
213 int retval, index, i;
214 NWUNIT_control_state_t * this_state = ( NWUNIT_control_state_t * ) ptr;
215
216 // Delete and re-create BGPM eventset
217 retval = _common_deleteRecreate( &this_state->EventGroup );
218 if ( retval < 0 ) return retval;
219
220 // otherwise, add the events to the eventset
221 for ( i = 0; i < count; i++ ) {
222 index = ( native[i].ni_event ) + OFFSET;
223
224 native[i].ni_position = i;
225
226#ifdef DEBUG_BGQ
227 printf("NWUNIT_update_control_state: ADD event: i = %d, index = %d\n", i, index );
228#endif
229
230 /* Add events to the BGPM eventGroup */
231 retval = Bgpm_AddEvent( this_state->EventGroup, index );
232 retval = _check_BGPM_error( retval, "Bgpm_AddEvent" );
233 if ( retval < 0 ) return retval;
234 }
235
236 return ( PAPI_OK );
237}
238
239
240/*
241 * This function has to set the bits needed to count different domains
242 * In particular: PAPI_DOM_USER, PAPI_DOM_KERNEL PAPI_DOM_OTHER
243 * By default return PAPI_EINVAL if none of those are specified
244 * and PAPI_OK with success
245 * PAPI_DOM_USER is only user context is counted
246 * PAPI_DOM_KERNEL is only the Kernel/OS context is counted
247 * PAPI_DOM_OTHER is Exception/transient mode (like user TLB misses)
248 * PAPI_DOM_ALL is all of the domains
249 */
250int
252{
253#ifdef DEBUG_BGQ
254 printf( "NWUNIT_set_domain\n" );
255#endif
256 int found = 0;
257 ( void ) cntrl;
258
259 if ( PAPI_DOM_USER & domain )
260 found = 1;
261
262 if ( PAPI_DOM_KERNEL & domain )
263 found = 1;
264
265 if ( PAPI_DOM_OTHER & domain )
266 found = 1;
267
268 if ( !found )
269 return ( PAPI_EINVAL );
270
271 return ( PAPI_OK );
272}
273
274
275/*
276 *
277 */
278int
280{
281#ifdef DEBUG_BGQ
282 printf( "NWUNIT_reset\n" );
283#endif
284 ( void ) ctx;
285 int retval;
286 NWUNIT_control_state_t * this_state = ( NWUNIT_control_state_t * ) ptr;
287
288 /* we can't simply call Bgpm_Reset() since PAPI doesn't have the
289 restriction that an EventSet has to be stopped before resetting is
290 possible. However, BGPM does have this restriction.
291 Hence we need to stop, reset and start */
292 retval = Bgpm_Stop( this_state->EventGroup );
293 retval = _check_BGPM_error( retval, "Bgpm_Stop" );
294 if ( retval < 0 ) return retval;
295
296 retval = Bgpm_ResetStart( this_state->EventGroup );
297 retval = _check_BGPM_error( retval, "Bgpm_ResetStart" );
298 if ( retval < 0 ) return retval;
299
300 return ( PAPI_OK );
301}
302
303
304/*
305 * PAPI Cleanup Eventset
306 *
307 * Destroy and re-create the BGPM / NWunit EventSet
308 */
309int
311{
312#ifdef DEBUG_BGQ
313 printf( "NWUNIT_cleanup_eventset\n" );
314#endif
315 int retval;
316
317 NWUNIT_control_state_t * this_state = ( NWUNIT_control_state_t * ) ctrl;
318
319 // create a new empty bgpm eventset
320 // reason: bgpm doesn't permit to remove events from an eventset;
321 // hence we delete the old eventset and create a new one
322 retval = _common_deleteRecreate( &this_state->EventGroup ); // HJ try to use delete() only
323 if ( retval < 0 ) return retval;
324
325 return ( PAPI_OK );
326}
327
328
329/*
330 * Native Event functions
331 */
332int
333NWUNIT_ntv_enum_events( unsigned int *EventCode, int modifier )
334{
335 //printf( "NWUNIT_ntv_enum_events\n" );
336
337 switch ( modifier ) {
338 case PAPI_ENUM_FIRST:
339 *EventCode = 0;
340
341 return ( PAPI_OK );
342 break;
343
344 case PAPI_ENUM_EVENTS:
345 {
346 int index = ( *EventCode ) + OFFSET;
347
348 if ( index < NWUNIT_MAX_EVENTS ) {
349 *EventCode = *EventCode + 1;
350 return ( PAPI_OK );
351 } else
352 return ( PAPI_ENOEVNT );
353
354 break;
355 }
356 default:
357 return ( PAPI_EINVAL );
358 }
359 return ( PAPI_EINVAL );
360}
361
362
363/*
364 *
365 */
366int
367NWUNIT_ntv_name_to_code( const char *name, unsigned int *event_code )
368{
369#ifdef DEBUG_BGQ
370 printf( "NWUNIT_ntv_name_to_code\n" );
371#endif
372 int ret;
373
374 /* Return event id matching a given event label string */
375 ret = Bgpm_GetEventIdFromLabel ( name );
376
377 if ( ret <= 0 ) {
378#ifdef DEBUG_BGPM
379 printf ("Error: ret value is %d for BGPM API function '%s'.\n",
380 ret, "Bgpm_GetEventIdFromLabel" );
381#endif
382 return PAPI_ENOEVNT;
383 }
384 else if ( ret < OFFSET || ret > NWUNIT_MAX_EVENTS ) // not a NWUnit event
385 return PAPI_ENOEVNT;
386 else
387 *event_code = ( ret - OFFSET ) ;
388
389 return PAPI_OK;
390}
391
392
393/*
394 *
395 */
396int
397NWUNIT_ntv_code_to_name( unsigned int EventCode, char *name, int len )
398{
399#ifdef DEBUG_BGQ
400 //printf( "NWUNIT_ntv_code_to_name\n" );
401#endif
402 int index;
403
404 index = ( EventCode ) + OFFSET;
405
406 if ( index >= MAX_COUNTERS )
407 return PAPI_ENOEVNT;
408
409 strncpy( name, Bgpm_GetEventIdLabel( index ), len );
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
426NWUNIT_ntv_code_to_descr( unsigned int EventCode, char *name, int len )
427{
428#ifdef DEBUG_BGQ
429 //printf( "NWUNIT_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
447NWUNIT_ntv_code_to_bits( unsigned int EventCode, hwd_register_t * bits )
448{
449#ifdef DEBUG_BGQ
450 printf( "NWUNIT_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/NWUnit",
465 .short_name = "NWUnit",
466 .description = "Blue Gene/Q NWUnit component",
467 .num_cntrs = NWUNIT_MAX_COUNTERS,
468 .num_native_events = NWUNIT_MAX_EVENTS-OFFSET+1,
469 .num_mpx_cntrs = NWUNIT_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 ( NWUNIT_context_t ),
492 .control_state = sizeof ( NWUNIT_control_state_t ),
493 .reg_value = sizeof ( NWUNIT_register_t ),
494 .reg_alloc = sizeof ( NWUNIT_reg_alloc_t ),
495 }
496 ,
497 /* function pointers in this component */
498 .init_thread = NWUNIT_init_thread,
499 .init_component = NWUNIT_init_component,
500 .init_control_state = NWUNIT_init_control_state,
501 .start = NWUNIT_start,
502 .stop = NWUNIT_stop,
503 .read = NWUNIT_read,
504 .shutdown_thread = NWUNIT_shutdown_thread,
505 .cleanup_eventset = NWUNIT_cleanup_eventset,
506 .ctl = NWUNIT_ctl,
507
508 .update_control_state = NWUNIT_update_control_state,
509 .set_domain = NWUNIT_set_domain,
510 .reset = NWUNIT_reset,
511
512 .ntv_name_to_code = NWUNIT_ntv_name_to_code,
513 .ntv_enum_events = NWUNIT_ntv_enum_events,
514 .ntv_code_to_name = NWUNIT_ntv_code_to_name,
515 .ntv_code_to_descr = NWUNIT_ntv_code_to_descr,
516 .ntv_code_to_bits = NWUNIT_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]
#define OFFSET
Definition: linux-CNKunit.h:36
int NWUNIT_stop(hwd_context_t *ctx, hwd_control_state_t *ptr)
Definition: linux-NWunit.c:116
int NWUNIT_reset(hwd_context_t *ctx, hwd_control_state_t *ptr)
Definition: linux-NWunit.c:279
papi_vector_t _NWunit_vector
Definition: linux-NWunit.c:23
int NWUNIT_update_control_state(hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
Definition: linux-NWunit.c:205
int NWUNIT_init_component(int cidx)
Definition: linux-NWunit.c:49
int NWUNIT_ntv_code_to_bits(unsigned int EventCode, hwd_register_t *bits)
Definition: linux-NWunit.c:447
int NWUNIT_cleanup_eventset(hwd_control_state_t *ctrl)
Definition: linux-NWunit.c:310
int NWUNIT_ntv_code_to_name(unsigned int EventCode, char *name, int len)
Definition: linux-NWunit.c:397
int NWUNIT_set_domain(hwd_control_state_t *cntrl, int domain)
Definition: linux-NWunit.c:251
int NWUNIT_init_control_state(hwd_control_state_t *ptr)
Definition: linux-NWunit.c:69
int NWUNIT_read(hwd_context_t *ctx, hwd_control_state_t *ptr, long_long **events, int flags)
Definition: linux-NWunit.c:137
int NWUNIT_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
Definition: linux-NWunit.c:185
int NWUNIT_start(hwd_context_t *ctx, hwd_control_state_t *ptr)
Definition: linux-NWunit.c:90
int NWUNIT_shutdown_thread(hwd_context_t *ctx)
Definition: linux-NWunit.c:169
int NWUNIT_ntv_enum_events(unsigned int *EventCode, int modifier)
Definition: linux-NWunit.c:333
int NWUNIT_init_thread(hwd_context_t *ctx)
Definition: linux-NWunit.c:33
int NWUNIT_ntv_code_to_descr(unsigned int EventCode, char *name, int len)
Definition: linux-NWunit.c:426
int NWUNIT_ntv_name_to_code(const char *name, unsigned int *event_code)
Definition: linux-NWunit.c:367
This file has the source code for a component that enables PAPI-C to access hardware monitoring count...
#define NWUNIT_MAX_EVENTS
Definition: linux-NWunit.h:37
#define NWUNIT_MAX_COUNTERS
Definition: linux-NWunit.h:36
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[NWUNIT_MAX_COUNTERS]
Definition: linux-NWunit.h:59
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