PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi.c File Reference

Most of the low-level API is here. More...

Include dependency graph for papi.c:

Go to the source code of this file.

Data Structures

struct  RateInfo
 

Macros

#define STOP   0
 
#define FLIP   1
 
#define FLOP   2
 
#define IPC   3
 
#define EPC   4
 
#define papi_return(a)
 

Functions

static void _internal_papi_init (void)
 
static void _internal_onetime_papi_init (void)
 
static int _start_new_rate_call (float *real_time, float *proc_time, int *events, int num_events, long long *ins, float *rate)
 
static int _rate_calls (float *real_time, float *proc_time, int *events, long long *values, long long *ins, float *rate, int mode)
 
static int _internal_check_rate_state ()
 
int PAPI_flips_rate (int event, float *rtime, float *ptime, long long *flpins, float *mflips)
 
int PAPI_flops_rate (int event, float *rtime, float *ptime, long long *flpops, float *mflops)
 
int PAPI_ipc (float *rtime, float *ptime, long long *ins, float *ipc)
 
int PAPI_epc (int event, float *rtime, float *ptime, long long *ref, long long *core, long long *evt, float *epc)
 
int PAPI_rate_stop ()
 
inline_static int valid_component (int cidx)
 
inline_static int valid_ESI_component (EventSetInfo_t *ESI)
 
int PAPI_thread_init (unsigned long int(*id_fn)(void))
 
unsigned long PAPI_thread_id (void)
 
int PAPI_register_thread (void)
 
int PAPI_unregister_thread (void)
 
int PAPI_list_threads (PAPI_thread_id_t *tids, int *number)
 
int PAPI_get_thr_specific (int tag, void **ptr)
 
int PAPI_set_thr_specific (int tag, void *ptr)
 
int PAPI_library_init (int version)
 
int PAPI_query_event (int EventCode)
 
int PAPI_query_named_event (const char *EventName)
 
const PAPI_component_info_tPAPI_get_component_info (int cidx)
 
int PAPI_get_event_info (int EventCode, PAPI_event_info_t *info)
 
int PAPI_event_code_to_name (int EventCode, char *out)
 
int PAPI_event_name_to_code (const char *in, int *out)
 
int PAPI_enum_event (int *EventCode, int modifier)
 
int PAPI_enum_cmp_event (int *EventCode, int modifier, int cidx)
 
int PAPI_create_eventset (int *EventSet)
 
int PAPI_assign_eventset_component (int EventSet, int cidx)
 
int PAPI_get_eventset_component (int EventSet)
 
int PAPI_add_event (int EventSet, int EventCode)
 
int PAPI_remove_event (int EventSet, int EventCode)
 
int PAPI_add_named_event (int EventSet, const char *EventName)
 
int PAPI_remove_named_event (int EventSet, const char *EventName)
 
int PAPI_destroy_eventset (int *EventSet)
 
int PAPI_start (int EventSet)
 
int PAPI_stop (int EventSet, long long *values)
 
int PAPI_reset (int EventSet)
 
int PAPI_read (int EventSet, long long *values)
 
int PAPI_read_ts (int EventSet, long long *values, long long *cycles)
 
int PAPI_accum (int EventSet, long long *values)
 
int PAPI_write (int EventSet, long long *values)
 
int PAPI_cleanup_eventset (int EventSet)
 
int PAPI_multiplex_init (void)
 
int PAPI_state (int EventSet, int *status)
 
int PAPI_set_debug (int level)
 
inline_static int _papi_set_attach (int option, int EventSet, unsigned long tid)
 
int PAPI_attach (int EventSet, unsigned long tid)
 
int PAPI_detach (int EventSet)
 
int PAPI_set_multiplex (int EventSet)
 
int PAPI_set_opt (int option, PAPI_option_t *ptr)
 
int PAPI_num_hwctrs (void)
 
int PAPI_num_cmp_hwctrs (int cidx)
 
int PAPI_get_multiplex (int EventSet)
 
int PAPI_get_opt (int option, PAPI_option_t *ptr)
 
int PAPI_get_cmp_opt (int option, PAPI_option_t *ptr, int cidx)
 
int PAPI_num_components (void)
 
int PAPI_num_events (int EventSet)
 
void PAPI_shutdown (void)
 
char * PAPI_strerror (int errorCode)
 
void PAPI_perror (const char *msg)
 
int PAPI_overflow (int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
 
int PAPI_sprofil (PAPI_sprofil_t *prof, int profcnt, int EventSet, int EventCode, int threshold, int flags)
 
int PAPI_profil (void *buf, unsigned bufsiz, vptr_t offset, unsigned scale, int EventSet, int EventCode, int threshold, int flags)
 
int PAPI_set_granularity (int granularity)
 
int PAPI_set_cmp_granularity (int granularity, int cidx)
 
int PAPI_set_domain (int domain)
 
int PAPI_set_cmp_domain (int domain, int cidx)
 
int PAPI_add_events (int EventSet, int *Events, int number)
 
int PAPI_remove_events (int EventSet, int *Events, int number)
 
int PAPI_list_events (int EventSet, int *Events, int *number)
 
int PAPI_get_dmem_info (PAPI_dmem_info_t *dest)
 
const PAPI_exe_info_tPAPI_get_executable_info (void)
 
const PAPI_shlib_info_tPAPI_get_shared_lib_info (void)
 
const PAPI_hw_info_tPAPI_get_hardware_info (void)
 
long long PAPI_get_real_cyc (void)
 
long long PAPI_get_real_nsec (void)
 
long long PAPI_get_real_usec (void)
 
long long PAPI_get_virt_cyc (void)
 
long long PAPI_get_virt_nsec (void)
 
long long PAPI_get_virt_usec (void)
 
int PAPI_lock (int lck)
 
int PAPI_unlock (int lck)
 
int PAPI_is_initialized (void)
 
int PAPI_get_overflow_event_index (int EventSet, long long overflow_vector, int *array, int *number)
 
int PAPI_get_event_component (int EventCode)
 
int PAPI_get_component_index (const char *name)
 
int PAPI_disable_component (int cidx)
 
int PAPI_disable_component_by_name (const char *name)
 
int PAPI_enum_dev_type (int enum_modifier, void **handle)
 
int PAPI_get_dev_type_attr (void *handle, PAPI_dev_type_attr_e attr, void *val)
 
int PAPI_get_dev_attr (void *handle, int id, PAPI_dev_attr_e attr, void *val)
 

Variables

THREAD_LOCAL_STORAGE_KEYWORD RateInfo_rate_state = NULL
 
bool _papi_rate_initiated = false
 
hwi_presets_t user_defined_events [PAPI_MAX_USER_EVENTS]
 
int user_defined_events_count
 
int _papi_hwi_debug
 
static int init_retval = DEADBEEF
 

Detailed Description

Macro Definition Documentation

◆ EPC

#define EPC   4

Definition at line 55 of file papi.c.

◆ FLIP

#define FLIP   1

Definition at line 52 of file papi.c.

◆ FLOP

#define FLOP   2

Definition at line 53 of file papi.c.

◆ IPC

#define IPC   3

Definition at line 54 of file papi.c.

◆ papi_return

#define papi_return (   a)
Value:
do { \
int b = a; \
if (b != PAPI_OK) {\
} \
APIDBG("EXIT: return: %d\n", b);\
} while (0)
#define PAPI_OK
Definition: f90papi.h:73
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
int _papi_hwi_errno
Definition: papi_internal.c:57
PAPI_debug_handler_t _papi_hwi_debug_handler
Definition: papi_internal.c:55

Definition at line 592 of file papi.c.

◆ STOP

#define STOP   0

Definition at line 51 of file papi.c.

Function Documentation

◆ _internal_check_rate_state()

static int _internal_check_rate_state ( )
static

Definition at line 123 of file papi.c.

124{
125 /* check if PAPI is initialized for rate functions */
126 if ( _papi_rate_initiated == false ) {
128
129 if ( _papi_rate_initiated == false )
130 return ( PAPI_EINVAL );
131 }
132
133 if ( _rate_state== NULL ) {
134 _rate_state= ( RateInfo* ) papi_malloc( sizeof ( RateInfo ) );
135 if ( _rate_state== NULL )
136 return ( PAPI_ENOMEM );
137
138 memset( _rate_state, 0, sizeof ( RateInfo ) );
140 }
141 return ( PAPI_OK );
142}
#define PAPI_EINVAL
Definition: f90papi.h:115
#define PAPI_ENOMEM
Definition: f90papi.h:16
THREAD_LOCAL_STORAGE_KEYWORD RateInfo * _rate_state
Definition: papi.c:69
bool _papi_rate_initiated
Definition: papi.c:70
#define STOP
Definition: papi.c:51
static void _internal_onetime_papi_init(void)
Definition: papi.c:104
#define papi_malloc(a)
Definition: papi_memory.h:34
Definition: papi.c:61
short int running
Definition: papi.c:64
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _internal_onetime_papi_init()

static void _internal_onetime_papi_init ( void  )
static

Definition at line 104 of file papi.c.

105{
106 static pthread_once_t library_is_initialized = PTHREAD_ONCE_INIT;
107 if ( pthread_once ) {
108 /* we assume that this function was called from a parallel region */
109 pthread_once(&library_is_initialized, _internal_papi_init);
110 /* wait until first thread has finished */
111 int i = 0;
112 /* give it 5 seconds in case PAPI_thread_init crashes */
113 while ( !_papi_rate_initiated && (i++) < 500000 )
114 usleep(10);
115 } else {
116 /* we assume that this function was called from a serial application
117 * that was not linked against libpthread */
119 }
120}
int i
static void _internal_papi_init(void)
Definition: papi.c:81
int pthread_once_t
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _internal_papi_init()

static void _internal_papi_init ( void  )
static

Definition at line 81 of file papi.c.

82{
83 /* This function is only called by the first thread! */
84 int retval;
85
86 /* check if user has already initialzed PAPI with thread support */
89 fprintf( stderr, "PAPI Error: PAPI_library_init failed with return value %d.\n", retval);
90 } else {
91
93 fprintf( stderr, "PAPI Error: PAPI_thread_init failed with return value %d.\n", retval);
94 fprintf( stderr, "PAPI Error: PAPI could not be initiated!\n");
95 } else {
97 }
98 }
99 } else {
101 }
102}
initialize the PAPI library.
Initialize thread support in the PAPI library.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_LOW_LEVEL_INITED
Definition: f90papi.h:269
#define PAPI_THREAD_LEVEL_INITED
Definition: f90papi.h:48
FILE * stderr
int init_level
Definition: papi_internal.c:53
unsigned long _papi_gettid(void)
Definition: threads.c:613
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_set_attach()

inline_static int _papi_set_attach ( int  option,
int  EventSet,
unsigned long  tid 
)

Definition at line 3698 of file papi.c.

3699{
3700 APIDBG("Entry: option: %d, EventSet: %d, tid: %lu\n", option, EventSet, tid);
3702
3703 memset( &attach, 0x0, sizeof ( attach ) );
3704 attach.attach.eventset = EventSet;
3705 attach.attach.tid = tid;
3706 return ( PAPI_set_opt( option, &attach ) );
3707}
Set PAPI library or event set options.
static int EventSet
Definition: init_fini.c:8
#define APIDBG(format, args...)
Definition: papi_debug.h:65
static int attach(hwd_control_state_t *ctl, unsigned long tid)
Definition: perfctr.c:248
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _rate_calls()

static int _rate_calls ( float *  real_time,
float *  proc_time,
int events,
long long values,
long long ins,
float *  rate,
int  mode 
)
static

Definition at line 467 of file papi.c.

469{
470
471 // printf("_rate_calls event %d, mode %d\n", events[0], mode);
472
473 long long rt, pt; // current elapsed real and process times in usec
474 int num_events = 2;
475 int retval = 0;
476
477 /* if a high-level event set is running stop it */
478 if ( _papi_hl_events_running == 1 ) {
479 if ( ( retval = PAPI_hl_stop() ) != PAPI_OK )
480 return ( retval );
481 }
482
483 if ( ( retval = _internal_check_rate_state() ) != PAPI_OK ) {
484 return ( retval );
485 }
486
487
488 switch (mode) {
489 case FLOP:
490 case FLIP:
491 if ( (retval = PAPI_query_event(events[0])) != PAPI_OK)
492 return retval;
493 num_events = 1;
494 break;
495 case IPC:
496 break;
497 case EPC:
498 if ( (retval = PAPI_query_event(events[0])) != PAPI_OK)
499 return retval;
500 if ( (retval = PAPI_query_event(events[2])) == PAPI_OK)
501 num_events = 3;
502 break;
503 default:
504 return PAPI_EINVAL;
505 }
506
507 /* STOP means the first call of a rate function */
508 if ( _rate_state->running == STOP ) {
509
510 if ( ( retval = _start_new_rate_call(real_time, proc_time, events, num_events, ins, rate)) != PAPI_OK )
511 return retval;
512 _rate_state->running = mode;
513
514 } else {
515 // check last mode
516 // printf("current mode: %d, last mode: %d\n", mode, _rate_state->running);
517 // printf("current event: %d, last event: %d\n", events[0], _rate_state->event_0);
518
519 if ( mode != _rate_state->running || events[0] != _rate_state->event_0 ) {
520
521 long long tmp_values[3];
522 retval = PAPI_stop( _rate_state->EventSet, tmp_values );
523 if ( retval == PAPI_OK ) {
525 } else {
526 return retval;
527 }
528
529 if ( ( retval = _start_new_rate_call(real_time, proc_time, events, num_events, ins, rate)) != PAPI_OK )
530 return retval;
531 _rate_state->running = mode;
533 return ( PAPI_OK );
534 }
535
536 if ( ( retval = PAPI_stop( _rate_state->EventSet, values ) ) != PAPI_OK ) {
538 return retval;
539 }
540
541 /* Read elapsed real and process times */
542 rt = PAPI_get_real_usec();
543 pt = PAPI_get_virt_usec();
544
545 /* Convert to seconds with multiplication because it is much faster */
546 *real_time = ((float)( rt - _rate_state->last_real_time )) * .000001;
547 *proc_time = ((float)( pt - _rate_state->last_proc_time )) * .000001;
548
549 *ins = values[0];
550
551 switch (mode) {
552 case FLOP:
553 case FLIP:
554 /* Calculate MFLOP and MFLIP rates */
555 if ( pt > 0 ) {
556 *rate = (float)values[0] / (pt - _rate_state->last_proc_time);
557 } else *rate = 0;
558 break;
559 case IPC:
560 case EPC:
561 /* Calculate IPC */
562 if (values[1]!=0) {
563 *rate = (float) ((float)values[0] / (float) ( values[1]));
564 }
565 break;
566 default:
567 return PAPI_EINVAL;
568 }
571
572 if ( ( retval = PAPI_start( _rate_state->EventSet ) ) != PAPI_OK ) {
574 return retval;
575 }
576 }
578 return PAPI_OK;
579}
Empty and destroy an EventSet.
Stop a running high-level event set.
Query if PAPI event exists.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
long long PAPI_get_virt_usec(void)
Definition: papi.c:6932
long long PAPI_get_real_usec(void)
Definition: papi.c:6824
char events[MAX_EVENTS][BUFSIZ]
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_events
#define FLIP
Definition: papi.c:52
static int _start_new_rate_call(float *real_time, float *proc_time, int *events, int num_events, long long *ins, float *rate)
Definition: papi.c:437
static int _internal_check_rate_state()
Definition: papi.c:123
#define IPC
Definition: papi.c:54
#define FLOP
Definition: papi.c:53
#define EPC
Definition: papi.c:55
THREAD_LOCAL_STORAGE_KEYWORD int _papi_hl_events_running
Definition: papi_internal.c:63
THREAD_LOCAL_STORAGE_KEYWORD int _papi_rate_events_running
Definition: papi_internal.c:62
int event_0
Definition: papi.c:63
int EventSet
Definition: papi.c:62
long long last_real_time
Definition: papi.c:65
long long last_proc_time
Definition: papi.c:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _start_new_rate_call()

static int _start_new_rate_call ( float *  real_time,
float *  proc_time,
int events,
int  num_events,
long long ins,
float *  rate 
)
static

Definition at line 437 of file papi.c.

439{
440 int retval;
441 _rate_state->EventSet = -1;
442
444 return ( retval );
445
447 return retval;
448
449 /* remember the event for subsequent calls of PAPI_flips_rate and PAPI_flops_rate */
451 *real_time = 0.0;
452 *proc_time = 0.0;
453 *rate = 0.0;
454 *ins = 0;
455
458
459 if ( ( retval = PAPI_start( _rate_state->EventSet ) ) != PAPI_OK ) {
460 return retval;
461 }
462
463 return ( PAPI_OK );
464}
add multiple PAPI presets or native hardware events to an event set
Create a new empty PAPI EventSet.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PAPI_num_hwctrs()

int PAPI_num_hwctrs ( void  )

return the number of hardware counters for the cpu. for backward compatibility. Don't use!

Definition at line 4468 of file papi.c.

4469{
4470 APIDBG( "Entry:\n");
4471 return ( PAPI_num_cmp_hwctrs( 0 ) );
4472}
Return the number of hardware counters for the specified component.
Here is the caller graph for this function:

◆ PAPI_thread_init()

int PAPI_thread_init ( unsigned long int(*)(void)  id_fn)

Definition at line 665 of file papi.c.

666{
667 /* Thread support not implemented on Alpha/OSF because the OSF pfm
668 * counter device driver does not support per-thread counters.
669 * When this is updated, we can remove this if statement
670 */
673
676
679}
#define PAPI_NOT_INITED
Definition: f90papi.h:231
#define PAPI_ENOINIT
Definition: f90papi.h:160
#define papi_return(a)
Definition: papi.c:592
int _papi_hwi_set_thread_id_fn(unsigned long(*id_fn)(void))
Definition: threads.c:358
Here is the call graph for this function:

◆ valid_component()

inline_static int valid_component ( int  cidx)

Definition at line 628 of file papi.c.

629{
631 return ( PAPI_ENOCMP );
632 return ( cidx );
633}
#define PAPI_ENOCMP
Definition: f90papi.h:79
int _papi_hwi_invalid_cmp(int cidx)
static int cidx
Here is the call graph for this function:
Here is the caller graph for this function:

◆ valid_ESI_component()

inline_static int valid_ESI_component ( EventSetInfo_t ESI)

Definition at line 636 of file papi.c.

637{
638 return ( valid_component( ESI->CmpIdx ) );
639}
inline_static int valid_component(int cidx)
Definition: papi.c:628
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _papi_hwi_debug

int _papi_hwi_debug

Definition at line 621 of file papi.c.

◆ _papi_rate_initiated

bool _papi_rate_initiated = false

Definition at line 70 of file papi.c.

◆ _rate_state

Definition at line 69 of file papi.c.

◆ init_retval

int init_retval = DEADBEEF
static

Definition at line 625 of file papi.c.

◆ user_defined_events

hwi_presets_t user_defined_events[PAPI_MAX_USER_EVENTS]
extern

Definition at line 59 of file papi_internal.c.

◆ user_defined_events_count

int user_defined_events_count
extern

Definition at line 60 of file papi_internal.c.