This is an example component, it demos the component interface and implements three example counters.
More...
Go to the source code of this file.
|
| static void | example_hardware_reset (example_context_t *ctx) |
| |
| static long long | example_hardware_read (int which_one, example_context_t *ctx) |
| |
| static int | example_hardware_write (int which_one, example_context_t *ctx, long long value) |
| |
| static int | detect_example (void) |
| |
| static int | _example_init_component (int cidx) |
| |
| static int | _example_init_thread (hwd_context_t *ctx) |
| |
| static int | _example_init_control_state (hwd_control_state_t *ctl) |
| |
| static int | _example_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx) |
| |
| static int | _example_start (hwd_context_t *ctx, hwd_control_state_t *ctl) |
| |
| static int | _example_stop (hwd_context_t *ctx, hwd_control_state_t *ctl) |
| |
| static int | _example_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags) |
| |
| static int | _example_write (hwd_context_t *ctx, hwd_control_state_t *ctl, long long *events) |
| |
| static int | _example_reset (hwd_context_t *ctx, hwd_control_state_t *ctl) |
| |
| static int | _example_shutdown_component (void) |
| |
| static int | _example_shutdown_thread (hwd_context_t *ctx) |
| |
| static int | _example_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option) |
| |
| static int | _example_set_domain (hwd_control_state_t *cntrl, int domain) |
| |
| static int | _example_ntv_enum_events (unsigned int *EventCode, int modifier) |
| |
| static int | _example_ntv_code_to_name (unsigned int EventCode, char *name, int len) |
| |
| static int | _example_ntv_code_to_descr (unsigned int EventCode, char *descr, int len) |
| |
◆ EXAMPLE_AUTOINC_REG
| #define EXAMPLE_AUTOINC_REG 2 |
◆ EXAMPLE_CONSTANT_REG
| #define EXAMPLE_CONSTANT_REG 1 |
◆ EXAMPLE_GLOBAL_AUTOINC_REG
| #define EXAMPLE_GLOBAL_AUTOINC_REG 3 |
◆ EXAMPLE_MAX_MULTIPLEX_COUNTERS
| #define EXAMPLE_MAX_MULTIPLEX_COUNTERS 4 |
◆ EXAMPLE_MAX_SIMULTANEOUS_COUNTERS
| #define EXAMPLE_MAX_SIMULTANEOUS_COUNTERS 3 |
This driver supports three counters counting at once
Definition at line 28 of file example.c.
◆ EXAMPLE_TOTAL_EVENTS
| #define EXAMPLE_TOTAL_EVENTS 4 |
◆ EXAMPLE_ZERO_REG
| #define EXAMPLE_ZERO_REG 0 |
◆ HANDLE_STRING_ERROR
| #define HANDLE_STRING_ERROR {fprintf(stderr,"%s:%i unexpected string function error.\n",__FILE__,__LINE__); exit(-1);} |
◆ _example_ctl()
This function sets various options in the component
- Parameters
-
| [in] | ctx | – hardware context |
| [in] | code | valid are PAPI_SET_DEFDOM, PAPI_SET_DOMAIN, PAPI_SETDEFGRN, PAPI_SET_GRANUL and PAPI_SET_INHERIT |
| [in] | option | – options to be set |
Definition at line 477 of file example.c.
478{
479
480 (void) ctx;
481 (void) code;
482 (void) option;
483
484 SUBDBG(
"example_ctl..." );
485
487}
#define SUBDBG(format, args...)
◆ _example_init_component()
| static int _example_init_component |
( |
int |
cidx | ) |
|
|
static |
Initialize hardware counters, setup the function vector table and get hardware information, this routine is called when the PAPI process is initialized (IE PAPI_library_init)
Definition at line 192 of file example.c.
193{
195
196 SUBDBG(
"_example_init_component..." );
197
198
201 "Example Hardware not present.");
205 goto fn_fail;
206 }
207
208
209
211
212
222 goto fn_fail;
223 }
224
225
226
227
228
231 "This is an example counter, that always returns 0" );
233
236 "This is an example counter, that always returns a constant value of 42" );
238
241 "This is an example counter, that reports a per-thread auto-incrementing value" );
243
246 "This is an example counter, that reports a global auto-incrementing value" );
248
249
251
252
254
255 fn_exit:
258 fn_fail:
259 goto fn_exit;
260}
struct papi_vectors * _papi_hwd[]
static int detect_example(void)
static example_native_event_entry_t * example_native_table
papi_vector_t _example_vector
#define EXAMPLE_TOTAL_EVENTS
#define HANDLE_STRING_ERROR
#define papi_calloc(a, b)
char disabled_reason[PAPI_HUGE_STR_LEN]
PAPI_component_info_t cmp_info
◆ _example_init_control_state()
Setup a counter control state. In general a control state holds the hardware info for an EventSet.
Definition at line 284 of file example.c.
285{
286 SUBDBG(
"example_init_control_state... %p\n", ctl );
287
290
292}
◆ _example_init_thread()
This is called whenever a thread is initialized
Definition at line 264 of file example.c.
265{
266
268
270
271 SUBDBG(
"_example_init_thread %p...", ctx );
272
274}
◆ _example_ntv_code_to_descr()
| static int _example_ntv_code_to_descr |
( |
unsigned int |
EventCode, |
|
|
char * |
descr, |
|
|
int |
len |
|
) |
| |
|
static |
Takes a native event code and passes back the event description
- Parameters
-
| EventCode | is the native event code |
| descr | is a pointer for the description to be copied to |
| len | is the size of the descr string |
Definition at line 604 of file example.c.
605{
606 int index;
607 index = EventCode;
608
609
613 }
614
616}
◆ _example_ntv_code_to_name()
| static int _example_ntv_code_to_name |
( |
unsigned int |
EventCode, |
|
|
char * |
name, |
|
|
int |
len |
|
) |
| |
|
static |
Takes a native event code and passes back the name
- Parameters
-
| EventCode | is the native event code |
| name | is a pointer for the name to be copied to |
| len | is the size of the name string |
Definition at line 583 of file example.c.
584{
585 int index;
586
587 index = EventCode;
588
589
593 }
594
596}
◆ _example_ntv_enum_events()
| static int _example_ntv_enum_events |
( |
unsigned int * |
EventCode, |
|
|
int |
modifier |
|
) |
| |
|
static |
Enumerate Native Events
- Parameters
-
| EventCode | is the event of interest |
| modifier | is one of PAPI_ENUM_FIRST, PAPI_ENUM_EVENTS If your component has attribute masks then these need to be handled here as well. |
Definition at line 541 of file example.c.
542{
543 int index;
544
545
546 switch ( modifier ) {
547
548
550
551
552 *EventCode = 0;
554
555
557 index = *EventCode;
558
559
561
562
563 *EventCode = *EventCode + 1;
565 } else {
567 }
568 break;
569
570 default:
572 }
573
575}
◆ _example_read()
Triggered by PAPI_read()
Definition at line 372 of file example.c.
374{
375
376 (void) flags;
377
380
381 SUBDBG(
"example_read... %p %d", ctx, flags );
382
384
385
389 example_ctx );
390 }
391
392
394
396}
static long long example_hardware_read(int which_one, example_context_t *ctx)
char events[MAX_EVENTS][BUFSIZ]
long long counter[EXAMPLE_MAX_MULTIPLEX_COUNTERS]
int which_counter[EXAMPLE_MAX_SIMULTANEOUS_COUNTERS]
◆ _example_reset()
Triggered by PAPI_reset() but only if the EventSet is currently running
Definition at line 427 of file example.c.
428{
430 (void) ctl;
431
432 SUBDBG(
"example_reset ctx=%p ctrl=%p...", ctx, ctl );
433
434
436
438}
static void example_hardware_reset(example_context_t *ctx)
◆ _example_set_domain()
This function has to set the bits needed to count different domains In particular: PAPI_DOM_USER, PAPI_DOM_KERNEL PAPI_DOM_OTHER By default return PAPI_EINVAL if none of those are specified and PAPI_OK with success PAPI_DOM_USER is only user context is counted PAPI_DOM_KERNEL is only the Kernel/OS context is counted PAPI_DOM_OTHER is Exception/transient mode (like user TLB misses) PAPI_DOM_ALL is all of the domains
Definition at line 499 of file example.c.
500{
501 (void) cntrl;
502
503 int found = 0;
504 SUBDBG(
"example_set_domain..." );
505
507 SUBDBG(
" PAPI_DOM_USER " );
508 found = 1;
509 }
511 SUBDBG(
" PAPI_DOM_KERNEL " );
512 found = 1;
513 }
515 SUBDBG(
" PAPI_DOM_OTHER " );
516 found = 1;
517 }
519 SUBDBG(
" PAPI_DOM_ALL " );
520 found = 1;
521 }
522 if ( !found )
524
526}
◆ _example_shutdown_component()
| static int _example_shutdown_component |
( |
void |
| ) |
|
|
static |
◆ _example_shutdown_thread()
Called at thread shutdown
Definition at line 456 of file example.c.
457{
458
459 (void) ctx;
460
461 SUBDBG(
"example_shutdown_thread... %p", ctx );
462
463
464
466}
◆ _example_start()
Triggered by PAPI_start()
Definition at line 331 of file example.c.
332{
333
334 (void) ctx;
335 (void) ctl;
336
337 SUBDBG(
"example_start %p %p...", ctx, ctl );
338
339
340
341
342
343
344
345
346
348}
◆ _example_stop()
Triggered by PAPI_stop()
Definition at line 353 of file example.c.
354{
355
356 (void) ctx;
357 (void) ctl;
358
359 SUBDBG(
"example_stop %p %p...", ctx, ctl );
360
361
362
363
364
366}
◆ _example_update_control_state()
Triggered by eventset operations like add or remove
Definition at line 297 of file example.c.
301{
302
303 (void) ctx;
305
307
308 SUBDBG(
"_example_update_control_state %p %p...", ctl, ctx );
309
310
312
315
316
318
319
320
322 }
323
325
327}
◆ _example_write()
Triggered by PAPI_write(), but only if the counters are running
Definition at line 401 of file example.c.
403{
404
407
409
410 SUBDBG(
"example_write... %p %p", ctx, ctl );
411
412
415 example_ctx,
417 }
418
420}
static int example_hardware_write(int which_one, example_context_t *ctx, long long value)
◆ detect_example()
| static int detect_example |
( |
void |
| ) |
|
|
static |
◆ example_hardware_read()
Code that reads event values.
Definition at line 126 of file example.c.
127{
128 long long old_value;
129
130 switch ( which_one ) {
132 return 0;
134 return 42;
138 return old_value;
142 return old_value;
143 default:
144 fprintf(
stderr,
"Invalid counter read %#x\n",which_one );
145 return -1;
146 }
147
148 return 0;
149}
#define EXAMPLE_GLOBAL_AUTOINC_REG
#define EXAMPLE_CONSTANT_REG
#define EXAMPLE_AUTOINC_REG
static long long example_global_autoinc_value
◆ example_hardware_reset()
Code that resets the hardware.
Definition at line 113 of file example.c.
◆ example_hardware_write()
Code that writes event values.
Definition at line 153 of file example.c.
156{
157
158 switch ( which_one ) {
168 default:
169 perror( "Invalid counter write" );
170 return -1;
171 }
172
173 return 0;
174}
◆ _example_vector
Vector that points to entry points for our component
Definition at line 38 of file example.c.
◆ example_global_autoinc_value
| long long example_global_autoinc_value = 0 |
|
static |
◆ example_native_table
This table contains the native events
Definition at line 92 of file example.c.
◆ num_events
number of events in the table
Definition at line 95 of file example.c.