The Low Level API

Functions

int ffsll (long long lli)
int PAPI_accum (int EventSet, long long *values)
int PAPI_add_event (int EventSet, int Event)
int PAPI_add_named_event (int EventSet, char *EventName)
int PAPI_add_events (int EventSet, int *Events, int number)
int PAPI_assign_eventset_component (int EventSet, int cidx)
int PAPI_attach (int EventSet, unsigned long tid)
int PAPI_cleanup_eventset (int EventSet)
int PAPI_create_eventset (int *EventSet)
int PAPI_detach (int EventSet)
int PAPI_destroy_eventset (int *EventSet)
int PAPI_enum_event (int *EventCode, int modifier)
int PAPI_enum_cmp_event (int *EventCode, int modifier, int cidx)
int PAPI_event_code_to_name (int EventCode, char *out)
int PAPI_event_name_to_code (char *in, int *out)
int PAPI_get_dmem_info (PAPI_dmem_info_t *dest)
int PAPI_get_event_info (int EventCode, PAPI_event_info_t *info)
const PAPI_exe_info_tPAPI_get_executable_info (void)
const PAPI_hw_info_tPAPI_get_hardware_info (void)
const PAPI_component_info_tPAPI_get_component_info (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)
long long PAPI_get_real_cyc (void)
long long PAPI_get_real_nsec (void)
long long PAPI_get_real_usec (void)
const PAPI_shlib_info_tPAPI_get_shared_lib_info (void)
int PAPI_get_thr_specific (int tag, void **ptr)
int PAPI_get_overflow_event_index (int Eventset, long long overflow_vector, int *array, int *number)
long long PAPI_get_virt_cyc (void)
long long PAPI_get_virt_nsec (void)
long long PAPI_get_virt_usec (void)
int PAPI_is_initialized (void)
int PAPI_library_init (int version)
int PAPI_list_events (int EventSet, int *Events, int *number)
int PAPI_list_threads (unsigned long *tids, int *number)
int PAPI_lock (int)
int PAPI_multiplex_init (void)
int PAPI_num_cmp_hwctrs (int cidx)
int PAPI_num_events (int EventSet)
int PAPI_overflow (int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
void PAPI_perror (char *msg)
int PAPI_profil (void *buf, unsigned bufsiz, caddr_t offset, unsigned scale, int EventSet, int EventCode, int threshold, int flags)
int PAPI_query_event (int EventCode)
int PAPI_query_named_event (char *EventName)
int PAPI_read (int EventSet, long long *values)
int PAPI_read_ts (int EventSet, long long *values, long long *cyc)
int PAPI_register_thread (void)
int PAPI_remove_event (int EventSet, int EventCode)
int PAPI_remove_named_event (int EventSet, char *EventName)
int PAPI_remove_events (int EventSet, int *Events, int number)
int PAPI_reset (int EventSet)
int PAPI_set_debug (int level)
int PAPI_set_cmp_domain (int domain, int cidx)
int PAPI_set_domain (int domain)
int PAPI_set_cmp_granularity (int granularity, int cidx)
int PAPI_set_granularity (int granularity)
int PAPI_set_multiplex (int EventSet)
int PAPI_set_opt (int option, PAPI_option_t *ptr)
int PAPI_set_thr_specific (int tag, void *ptr)
void PAPI_shutdown (void)
int PAPI_sprofil (PAPI_sprofil_t *prof, int profcnt, int EventSet, int EventCode, int threshold, int flags)
int PAPI_start (int EventSet)
int PAPI_state (int EventSet, int *status)
int PAPI_stop (int EventSet, long long *values)
char * PAPI_strerror (int)
unsigned long PAPI_thread_id (void)
int PAPI_thread_init (unsigned long(*id_fn)(void))
int PAPI_unlock (int)
int PAPI_unregister_thread (void)
int PAPI_write (int EventSet, long long *values)
int PAPI_get_event_component (int EventCode)
int PAPI_get_eventset_component (int EventSet)
int PAPI_get_component_index (char *name)
int PAPI_disable_component (int cidx)
int PAPI_disable_component_by_name (char *name)

Detailed Description

For internal use only.


Function Documentation

int ffsll ( long long  lli  ) 

Definition at line 502 of file extras.c.

00503 {
00504     int i, num, t, tmpint, len;
00505 
00506     num = sizeof ( long long ) / sizeof ( int );
00507     if ( num == 1 )
00508         return ( ffs( ( int ) lli ) );
00509     len = sizeof ( int ) * CHAR_BIT;
00510 
00511     for ( i = 0; i < num; i++ ) {
00512         tmpint = ( int ) ( ( ( lli >> len ) << len ) ^ lli );
00513 
00514         t = ffs( tmpint );
00515         if ( t ) {
00516             return ( t + i * len );
00517         }
00518         lli = lli >> len;
00519     }
00520     return PAPI_OK;
00521 }

Here is the caller graph for this function:

int PAPI_accum ( int  EventSet,
long long *  values 
)

accumulate and reset hardware events from an event set

Definition at line 2753 of file papi.c.

02754 {
02755     APIDBG("Entry: EventSet: %d, values: %p\n", EventSet, values);
02756     EventSetInfo_t *ESI;
02757     hwd_context_t *context;
02758     int i, cidx, retval;
02759     long long a, b, c;
02760 
02761     ESI = _papi_hwi_lookup_EventSet( EventSet );
02762     if ( ESI == NULL )
02763         papi_return( PAPI_ENOEVST );
02764 
02765     cidx = valid_ESI_component( ESI );
02766     if ( cidx < 0 )
02767         papi_return( cidx );
02768 
02769     if ( values == NULL )
02770         papi_return( PAPI_EINVAL );
02771 
02772     if ( ESI->state & PAPI_RUNNING ) {
02773         if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
02774           retval = MPX_read( ESI->multiplex.mpx_evset, ESI->sw_stop, 0 );
02775         } else {
02776             /* get the context we should use for this event set */
02777             context = _papi_hwi_get_context( ESI, NULL );
02778             retval = _papi_hwi_read( context, ESI, ESI->sw_stop );
02779         }
02780         if ( retval != PAPI_OK )
02781             papi_return( retval );
02782     }
02783 
02784     for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
02785         a = ESI->sw_stop[i];
02786         b = values[i];
02787         c = a + b;
02788         values[i] = c;
02789     }
02790 
02791     papi_return( PAPI_reset( EventSet ) );
02792 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_add_event ( int  EventSet,
int  Event 
)

add single PAPI preset or native hardware event to an event set

Definition at line 1672 of file papi.c.

01673 {
01674    APIDBG("Entry: EventSet: %d, EventCode: %#x\n", EventSet, EventCode);
01675     EventSetInfo_t *ESI;
01676 
01677     /* Is the EventSet already in existence? */
01678 
01679     ESI = _papi_hwi_lookup_EventSet( EventSet );
01680     if ( ESI == NULL )
01681         papi_return( PAPI_ENOEVST );
01682 
01683     /* Check argument for validity */
01684 
01685     if ( ( ( EventCode & PAPI_PRESET_MASK ) == 0 ) &&
01686          ( EventCode & PAPI_NATIVE_MASK ) == 0 )
01687         papi_return( PAPI_EINVAL );
01688 
01689     /* Of course, it must be stopped in order to modify it. */
01690 
01691     if ( ESI->state & PAPI_RUNNING )
01692         papi_return( PAPI_EISRUN );
01693 
01694     /* Now do the magic. */
01695     int retval = _papi_hwi_add_event( ESI, EventCode );
01696     papi_return( retval );
01697 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_add_events ( int  EventSet,
int *  Events,
int  number 
)

add array of PAPI preset or native hardware events to an event set

Definition at line 5851 of file papi.c.

05852 {
05853     APIDBG( "Entry: EventSet: %d, Events: %p, number: %d\n", EventSet, Events, number);
05854     int i, retval;
05855 
05856     if ( ( Events == NULL ) || ( number <= 0 ) )
05857         papi_return( PAPI_EINVAL );
05858 
05859     for ( i = 0; i < number; i++ ) {
05860         retval = PAPI_add_event( EventSet, Events[i] );
05861         if ( retval != PAPI_OK ) {
05862             if ( i == 0 )
05863                 papi_return( retval );
05864             else
05865                 return ( i );
05866         }
05867     }
05868     return ( PAPI_OK );
05869 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_add_named_event ( int  EventSet,
char *  EventName 
)

add an event by name to a PAPI event set

Definition at line 1885 of file papi.c.

01886 {
01887     APIDBG("Entry: EventSet: %d, EventName: %s\n", EventSet, EventName);
01888 
01889     int ret, code;
01890     
01891     ret = PAPI_event_name_to_code( EventName, &code );
01892     if ( ret != PAPI_OK ) {
01893         APIDBG("EXIT: return: %d\n", ret);
01894         return ret;   // do not use papi_return here because if there was an error PAPI_event_name_to_code already reported it
01895     }
01896 
01897     ret = PAPI_add_event( EventSet, code );
01898     APIDBG("EXIT: return: %d\n", ret);
01899     return ret;   // do not use papi_return here because if there was an error PAPI_add_event already reported it
01900 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_assign_eventset_component ( int  EventSet,
int  cidx 
)

assign a component index to an existing but empty eventset

Definition at line 1535 of file papi.c.

01536 {
01537     EventSetInfo_t *ESI;
01538     int retval;
01539 
01540     ESI = _papi_hwi_lookup_EventSet( EventSet );
01541     if ( ESI == NULL )
01542         papi_return( PAPI_ENOEVST );
01543 
01544 /* validate cidx */
01545     retval = valid_component( cidx );
01546     if ( retval < 0 )
01547         papi_return( retval );
01548 
01549 /* cowardly refuse to reassign eventsets */ 
01550     if ( ESI->CmpIdx >= 0 )
01551       return PAPI_EINVAL;
01552 
01553     return ( _papi_hwi_assign_eventset( ESI, cidx ) );
01554 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_attach ( int  EventSet,
unsigned long  tid 
)

attach specified event set to a specific process or thread id

Definition at line 3209 of file papi.c.

03210 {
03211     APIDBG( "Entry: EventSet: %d, tid: %lu\n", EventSet, tid);
03212     return ( _papi_set_attach( PAPI_ATTACH, EventSet, tid ) );
03213 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_cleanup_eventset ( int  EventSet  ) 

remove all PAPI events from an event set

Definition at line 2898 of file papi.c.

02899 {
02900     APIDBG("Entry: EventSet: %d\n",EventSet);
02901 
02902     EventSetInfo_t *ESI;
02903     int i, cidx, total, retval;
02904 
02905     /* Is the EventSet already in existence? */
02906 
02907     ESI = _papi_hwi_lookup_EventSet( EventSet );
02908     if ( ESI == NULL )
02909         papi_return( PAPI_ENOEVST );
02910 
02911     /* if the eventset has no index and no events, return OK
02912        otherwise return NOCMP */
02913     cidx = valid_ESI_component( ESI );
02914     if ( cidx < 0 ) {
02915         if ( ESI->NumberOfEvents )
02916             papi_return( cidx );
02917         papi_return( PAPI_OK );
02918     }
02919 
02920     /* Of course, it must be stopped in order to modify it. */
02921 
02922     if ( ESI->state & PAPI_RUNNING )
02923         papi_return( PAPI_EISRUN );
02924 
02925     /* clear overflow flag and turn off hardware overflow handler */
02926     if ( ESI->state & PAPI_OVERFLOWING ) {
02927         total = ESI->overflow.event_counter;
02928         for ( i = 0; i < total; i++ ) {
02929             retval = PAPI_overflow( EventSet,
02930                                     ESI->overflow.EventCode[0], 0, 0, NULL );
02931             if ( retval != PAPI_OK )
02932                 papi_return( retval );
02933         }
02934     }
02935 
02936     /* clear profile flag and turn off hardware profile handler */
02937     if ( ( ESI->state & PAPI_PROFILING ) &&
02938          _papi_hwd[cidx]->cmp_info.hardware_intr &&
02939          !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
02940         total = ESI->profile.event_counter;
02941         for ( i = 0; i < total; i++ ) {
02942             retval =
02943                 PAPI_sprofil( NULL, 0, EventSet, ESI->profile.EventCode[0], 0,
02944                               PAPI_PROFIL_POSIX );
02945             if ( retval != PAPI_OK )
02946                 papi_return( retval );
02947         }
02948     }
02949 
02950     if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
02951         retval = MPX_cleanup( &ESI->multiplex.mpx_evset );
02952         if ( retval != PAPI_OK )
02953             papi_return( retval );
02954     }
02955 
02956     retval = _papi_hwd[cidx]->cleanup_eventset( ESI->ctl_state );
02957     if ( retval != PAPI_OK ) 
02958         papi_return( retval );
02959 
02960     /* Now do the magic */
02961     papi_return( _papi_hwi_cleanup_eventset( ESI ) );
02962 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_create_eventset ( int *  EventSet  ) 

create a new empty PAPI event set

Definition at line 1473 of file papi.c.

01474 {
01475    APIDBG("Entry: EventSet: %p\n", EventSet);
01476 
01477     ThreadInfo_t *master;
01478     int retval;
01479 
01480     if ( init_level == PAPI_NOT_INITED )
01481         papi_return( PAPI_ENOINIT );
01482     retval = _papi_hwi_lookup_or_create_thread( &master, 0 );
01483     if ( retval )
01484         papi_return( retval );
01485 
01486     papi_return( _papi_hwi_create_eventset( EventSet, master ) );
01487 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_destroy_eventset ( int *  EventSet  ) 

deallocates memory associated with an empty PAPI event set

Definition at line 2022 of file papi.c.

02023 {
02024     APIDBG("Entry: EventSet: %p, *EventSet: %d\n", EventSet, *EventSet);
02025 
02026     EventSetInfo_t *ESI;
02027 
02028     /* check for pre-existing ESI */
02029 
02030     if ( EventSet == NULL )
02031         papi_return( PAPI_EINVAL );
02032 
02033     ESI = _papi_hwi_lookup_EventSet( *EventSet );
02034     if ( ESI == NULL )
02035         papi_return( PAPI_ENOEVST );
02036 
02037     if ( !( ESI->state & PAPI_STOPPED ) )
02038         papi_return( PAPI_EISRUN );
02039 
02040     if ( ESI->NumberOfEvents )
02041         papi_return( PAPI_EINVAL );
02042 
02043     _papi_hwi_remove_EventSet( ESI );
02044     *EventSet = PAPI_NULL;
02045 
02046     return PAPI_OK;
02047 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_detach ( int  EventSet  ) 

detach specified event set from a previously specified process or thread id

Definition at line 3266 of file papi.c.

03267 {
03268     APIDBG( "Entry: EventSet: %d\n", EventSet);
03269     return ( _papi_set_attach( PAPI_DETACH, EventSet, 0 ) );
03270 }

Here is the call graph for this function:

int PAPI_disable_component ( int  cidx  ) 

Disables a component before init

Definition at line 6674 of file papi.c.

06675 {
06676     APIDBG( "Entry: cidx: %d\n", cidx);
06677 
06678    const PAPI_component_info_t *cinfo;
06679 
06680    /* Can only run before PAPI_library_init() is called */
06681    if (init_level != PAPI_NOT_INITED) {
06682       return PAPI_ENOINIT;
06683    }
06684      
06685    cinfo=PAPI_get_component_info(cidx); 
06686    if (cinfo==NULL) return PAPI_ENOCMP;
06687 
06688    ((PAPI_component_info_t *)cinfo)->disabled=1;
06689    strcpy(((PAPI_component_info_t *)cinfo)->disabled_reason,
06690            "Disabled by PAPI_disable_component()");
06691 
06692    return PAPI_OK;
06693  
06694 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_disable_component_by_name ( char *  name  ) 

Disable, before library init, a component by name.

Definition at line 6725 of file papi.c.

06726 {
06727     APIDBG( "Entry: name: %s\n", name);
06728     int cidx;
06729 
06730     /* I can only be called before init time */
06731     if (init_level!=PAPI_NOT_INITED) {
06732         return PAPI_ENOINIT;
06733     }
06734 
06735     cidx = PAPI_get_component_index(name);
06736     if (cidx>=0) {
06737         return PAPI_disable_component(cidx);
06738     } 
06739 
06740     return PAPI_ENOCMP;
06741 }

Here is the call graph for this function:

int PAPI_enum_cmp_event ( int *  EventCode,
int  modifier,
int  cidx 
)

return the event code for the next available component event

Definition at line 1366 of file papi.c.

01367 {
01368     APIDBG( "Entry: EventCode: %#x, modifier: %d, cidx: %d\n", *EventCode, modifier, cidx);
01369     int i = *EventCode;
01370     int retval;
01371     int event_code;
01372     char *evt_name;
01373 
01374     if ( _papi_hwi_invalid_cmp(cidx) || ( (IS_PRESET(i)) && cidx > 0 ) ) {
01375         return PAPI_ENOCMP;
01376     }
01377 
01378     if (_papi_hwd[cidx]->cmp_info.disabled) {
01379       return PAPI_ENOCMP;
01380     }
01381 
01382     if ( IS_PRESET(i) ) {
01383         if ( modifier == PAPI_ENUM_FIRST ) {
01384             *EventCode = ( int ) PAPI_PRESET_MASK;
01385             APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
01386             return PAPI_OK;
01387         }
01388         i &= PAPI_PRESET_AND_MASK;
01389         while ( ++i < PAPI_MAX_PRESET_EVENTS ) {
01390             if ( _papi_hwi_presets[i].symbol == NULL ) {
01391                 APIDBG("EXIT: PAPI_ENOEVNT\n");
01392                 return ( PAPI_ENOEVNT );    /* NULL pointer terminates list */
01393             }
01394             if ( modifier & PAPI_PRESET_ENUM_AVAIL ) {
01395                 if ( _papi_hwi_presets[i].count == 0 )
01396                     continue;
01397             }
01398             *EventCode = ( int ) ( i | PAPI_PRESET_MASK );
01399             APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
01400             return PAPI_OK;
01401         }
01402         papi_return( PAPI_EINVAL );
01403     }
01404 
01405     if ( IS_NATIVE(i) ) {
01406         // save event code so components can get it with call to: _papi_hwi_get_papi_event_code()
01407         _papi_hwi_set_papi_event_code(*EventCode, 0);
01408 
01409         /* Should we check against num native events here? */
01410         event_code=_papi_hwi_eventcode_to_native(*EventCode);
01411         retval = _papi_hwd[cidx]->ntv_enum_events((unsigned int *)&event_code, modifier );
01412 
01413         if (retval!=PAPI_OK) {
01414            APIDBG("EXIT: PAPI_EINVAL retval=%d\n",retval);
01415            return PAPI_EINVAL;
01416         }
01417 
01418         evt_name = _papi_hwi_get_papi_event_string();
01419         *EventCode = _papi_hwi_native_to_eventcode(cidx, event_code, -1, evt_name);
01420         _papi_hwi_free_papi_event_string();
01421 
01422         APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
01423         return retval;
01424     } 
01425 
01426     papi_return( PAPI_EINVAL );
01427 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_enum_event ( int *  EventCode,
int  modifier 
)

return the event code for the next available preset or natvie event

Definition at line 1161 of file papi.c.

01162 {
01163     APIDBG( "Entry: EventCode: %#x, modifier: %d\n", *EventCode, modifier);
01164     int i = *EventCode;
01165     int retval;
01166     int cidx;
01167     int event_code;
01168     char *evt_name;
01169 
01170     cidx = _papi_hwi_component_index( *EventCode );
01171     if (cidx < 0) return PAPI_ENOCMP;
01172 
01173     /* Do we handle presets in componets other than CPU? */
01174     /* if (( IS_PRESET(i) ) && cidx > 0 )) return PAPI_ENOCMP; */
01175         
01176     if ( IS_PRESET(i) ) {
01177         if ( modifier == PAPI_ENUM_FIRST ) {
01178             *EventCode = ( int ) PAPI_PRESET_MASK;
01179             APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
01180             return ( PAPI_OK );
01181         }
01182         i &= PAPI_PRESET_AND_MASK;
01183         while ( ++i < PAPI_MAX_PRESET_EVENTS ) {
01184             if ( _papi_hwi_presets[i].symbol == NULL ) {
01185                 APIDBG("EXIT: PAPI_ENOEVNT\n");
01186                 return ( PAPI_ENOEVNT );    /* NULL pointer terminates list */
01187             }
01188             if ( modifier & PAPI_PRESET_ENUM_AVAIL ) {
01189                 if ( _papi_hwi_presets[i].count == 0 )
01190                     continue;
01191             }
01192             *EventCode = ( int ) ( i | PAPI_PRESET_MASK );
01193             APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
01194             return ( PAPI_OK );
01195         }
01196         papi_return( PAPI_EINVAL );
01197     }
01198 
01199     if ( IS_NATIVE(i) ) {
01200         // save event code so components can get it with call to: _papi_hwi_get_papi_event_code()
01201         _papi_hwi_set_papi_event_code(*EventCode, 0);
01202 
01203         /* Should check against num native events here */
01204 
01205         event_code=_papi_hwi_eventcode_to_native((int)*EventCode);
01206         retval = _papi_hwd[cidx]->ntv_enum_events((unsigned int *)&event_code, modifier );
01207 
01208         if (retval!=PAPI_OK) {
01209            APIDBG("VMW: retval=%d\n",retval);
01210            return PAPI_EINVAL;
01211         }
01212 
01213         evt_name = _papi_hwi_get_papi_event_string();
01214         *EventCode = _papi_hwi_native_to_eventcode(cidx, event_code, -1, evt_name);
01215         _papi_hwi_free_papi_event_string();
01216 
01217         APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
01218         return retval;
01219     }
01220 
01221     if ( IS_USER_DEFINED(i) ) {
01222         if (user_defined_events_count == 0) {
01223             APIDBG("EXIT: PAPI_ENOEVNT\n");
01224             return PAPI_ENOEVNT;
01225         }
01226         if ( modifier == PAPI_ENUM_FIRST ) {
01227             *EventCode = (int) (0 | PAPI_UE_MASK);
01228             APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
01229             return ( PAPI_OK );
01230         }
01231 
01232         i &= PAPI_UE_AND_MASK;
01233         ++i;
01234 
01235         if ( i <= 0  ||  i >= user_defined_events_count ) {
01236             APIDBG("EXIT: PAPI_ENOEVNT\n");
01237             return ( PAPI_ENOEVNT );
01238         }
01239 
01240         // if next entry does not have an event name, we are done
01241         if (user_defined_events[i].symbol == NULL) {
01242             APIDBG("EXIT: PAPI_ENOEVNT\n");
01243             return ( PAPI_ENOEVNT );
01244         }
01245 
01246         // if next entry does not map to any other events, we are done
01247         if (user_defined_events[i].count == 0) {
01248             APIDBG("EXIT: PAPI_ENOEVNT\n");
01249             return ( PAPI_ENOEVNT );
01250         }
01251 
01252         *EventCode = (int) (i | PAPI_UE_MASK);
01253         APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
01254         return ( PAPI_OK );
01255     }
01256 
01257     papi_return( PAPI_EINVAL );
01258 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_event_code_to_name ( int  EventCode,
char *  out 
)

translate an integer PAPI event code into an ASCII PAPI preset or native name

Definition at line 924 of file papi.c.

00925 {
00926     APIDBG( "Entry: EventCode: %#x, out: %p\n", EventCode, out);
00927     if ( out == NULL )
00928         papi_return( PAPI_EINVAL );
00929 
00930     if ( IS_PRESET(EventCode) ) {
00931         EventCode &= PAPI_PRESET_AND_MASK;
00932         if ( EventCode < 0 || EventCode >= PAPI_MAX_PRESET_EVENTS )
00933             papi_return( PAPI_ENOTPRESET );
00934 
00935         if (_papi_hwi_presets[EventCode].symbol == NULL )
00936             papi_return( PAPI_ENOTPRESET );
00937 
00938         strncpy( out, _papi_hwi_presets[EventCode].symbol, PAPI_MAX_STR_LEN-1 );
00939         out[PAPI_MAX_STR_LEN-1] = '\0';
00940         papi_return( PAPI_OK );
00941     }
00942 
00943     if ( IS_NATIVE(EventCode) ) {
00944         return ( _papi_hwi_native_code_to_name
00945                  ( ( unsigned int ) EventCode, out, PAPI_MAX_STR_LEN ) );
00946     }
00947 
00948     if ( IS_USER_DEFINED(EventCode) ) {
00949         EventCode &= PAPI_UE_AND_MASK;
00950 
00951         if ( EventCode < 0 || EventCode >= user_defined_events_count )
00952             papi_return( PAPI_ENOEVNT );
00953 
00954         if (user_defined_events[EventCode].symbol == NULL )
00955             papi_return( PAPI_ENOEVNT );
00956 
00957         strncpy( out, user_defined_events[EventCode].symbol, PAPI_MAX_STR_LEN-1);
00958         out[PAPI_MAX_STR_LEN-1] = '\0';
00959         papi_return( PAPI_OK );
00960     }
00961 
00962     papi_return( PAPI_ENOEVNT );
00963 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_event_name_to_code ( char *  in,
int *  out 
)

translate an ASCII PAPI preset or native name into an integer PAPI event code

Definition at line 1013 of file papi.c.

01014 {
01015    APIDBG("Entry: in: %p, name: %s, out: %p\n", in, in, out);
01016     int i;
01017 
01018     if ( ( in == NULL ) || ( out == NULL ) )
01019         papi_return( PAPI_EINVAL );
01020 
01021     if ( init_level == PAPI_NOT_INITED )
01022         papi_return( PAPI_ENOINIT );
01023 
01024     /* All presets start with "PAPI_" so no need to */
01025     /* do an exhaustive search if that's not there  */
01026     if (strncmp(in, "PAPI_", 5) == 0) {
01027        for(i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
01028           if ( ( _papi_hwi_presets[i].symbol )
01029            && ( strcasecmp( _papi_hwi_presets[i].symbol, in ) == 0) ) {
01030          *out = ( int ) ( i | PAPI_PRESET_MASK );
01031          papi_return( PAPI_OK );
01032           }
01033        }
01034     }
01035 
01036     // check to see if it is a user defined event
01037     for ( i=0; i < user_defined_events_count ; i++ ) {
01038         APIDBG("&user_defined_events[%d]: %p, user_defined_events[%d].symbol: %s, user_defined_events[%d].count: %d\n",
01039                 i, &user_defined_events[i], i, user_defined_events[i].symbol, i, user_defined_events[i].count);
01040         if (user_defined_events[i].symbol == NULL)
01041             break;
01042         if (user_defined_events[i].count == 0)
01043             break;
01044         if ( strcasecmp( user_defined_events[i].symbol, in ) == 0 ) {
01045             *out = (int) ( i | PAPI_UE_MASK );
01046             papi_return( PAPI_OK );
01047         }
01048     }
01049 
01050     // go look for native events defined by one of the components
01051     papi_return( _papi_hwi_native_name_to_code( in, out ) );
01052 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_get_cmp_opt ( int  option,
PAPI_option_t ptr,
int  cidx 
)

query the component specific option settings of a specific event set

Definition at line 4343 of file papi.c.

04344 {
04345     APIDBG( "Entry: option: %d, ptr: %p, cidx: %d\n", option, ptr, cidx);
04346 
04347   if (_papi_hwi_invalid_cmp(cidx)) {
04348      return PAPI_ECMP;
04349   }
04350 
04351     switch ( option ) {
04352         /* For now, MAX_HWCTRS and MAX CTRS are identical.
04353            At some future point, they may map onto different values.
04354          */
04355     case PAPI_MAX_HWCTRS:
04356         return ( _papi_hwd[cidx]->cmp_info.num_cntrs );
04357     case PAPI_MAX_MPX_CTRS:
04358         return ( _papi_hwd[cidx]->cmp_info.num_mpx_cntrs );
04359     case PAPI_DEFDOM:
04360         return ( _papi_hwd[cidx]->cmp_info.default_domain );
04361     case PAPI_DEFGRN:
04362         return ( _papi_hwd[cidx]->cmp_info.default_granularity );
04363     case PAPI_SHLIBINFO:
04364     {
04365         int retval;
04366         if ( ptr == NULL )
04367             papi_return( PAPI_EINVAL );
04368         retval = _papi_os_vector.update_shlib_info( &_papi_hwi_system_info );
04369         ptr->shlib_info = &_papi_hwi_system_info.shlib_info;
04370         papi_return( retval );
04371     }
04372     case PAPI_COMPONENTINFO:
04373         if ( ptr == NULL )
04374             papi_return( PAPI_EINVAL );
04375         ptr->cmp_info = &( _papi_hwd[cidx]->cmp_info );
04376         return PAPI_OK;
04377     default:
04378       papi_return( PAPI_EINVAL );
04379     }
04380     return PAPI_OK;
04381 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_get_component_index ( char *  name  ) 

Return component index for component with matching name

Definition at line 6618 of file papi.c.

06619 {
06620     APIDBG( "Entry: name: %s\n", name);
06621   int cidx;
06622 
06623   const PAPI_component_info_t *cinfo;
06624 
06625   for(cidx=0;cidx<papi_num_components;cidx++) {
06626 
06627      cinfo=PAPI_get_component_info(cidx); 
06628      if (cinfo==NULL) return PAPI_ENOCMP;
06629 
06630      if (!strcmp(name,cinfo->name)) {
06631         return cidx;
06632      }
06633   }
06634 
06635   return PAPI_ENOCMP;
06636 }

Here is the call graph for this function:

Here is the caller graph for this function:

get information about the component features

Definition at line 805 of file papi.c.

00806 {
00807     APIDBG( "Entry: Component Index %d\n", cidx);
00808     if ( _papi_hwi_invalid_cmp( cidx ) )
00809         return ( NULL );
00810     else
00811         return ( &( _papi_hwd[cidx]->cmp_info ) );
00812 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_get_dmem_info ( PAPI_dmem_info_t dest  ) 

get dynamic memory usage information

Definition at line 6071 of file papi.c.

06072 {
06073     if ( dest == NULL )
06074         return PAPI_EINVAL;
06075 
06076     memset( ( void * ) dest, 0x0, sizeof ( PAPI_dmem_info_t ) );
06077     return ( _papi_os_vector.get_dmem_info( dest ) );
06078 }

Here is the caller graph for this function:

int PAPI_get_event_component ( int  EventCode  ) 

return which component an EventCode belongs to

Definition at line 6591 of file papi.c.

06592 {
06593     APIDBG( "Entry: EventCode: %#x\n", EventCode);
06594     return _papi_hwi_component_index( EventCode);
06595 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_get_event_info ( int  EventCode,
PAPI_event_info_t info 
)

get the name and descriptions for a given preset or native event code

Definition at line 844 of file papi.c.

00845 {
00846     APIDBG( "Entry: EventCode: 0x%x, info: %p\n", EventCode, info);
00847         int i;
00848 
00849     if ( info == NULL )
00850        papi_return( PAPI_EINVAL );
00851 
00852     if ( IS_PRESET(EventCode) ) {
00853            i = EventCode & PAPI_PRESET_AND_MASK;
00854        if ( i >= PAPI_MAX_PRESET_EVENTS )
00855           papi_return( PAPI_ENOTPRESET );
00856        papi_return( _papi_hwi_get_preset_event_info( EventCode, info ) );
00857     }
00858 
00859     if ( IS_NATIVE(EventCode) ) {
00860        papi_return( _papi_hwi_get_native_event_info
00861               ( ( unsigned int ) EventCode, info ) );
00862     }
00863 
00864     if ( IS_USER_DEFINED(EventCode) ) {
00865        papi_return( _papi_hwi_get_user_event_info( EventCode, info ));
00866     }
00867     papi_return( PAPI_ENOTPRESET );
00868 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_get_eventset_component ( int  EventSet  ) 

return which component an EventSet is assigned to

Definition at line 1578 of file papi.c.

01579 {
01580     EventSetInfo_t *ESI;
01581     int retval;
01582 
01583 /* validate eventset */
01584     ESI = _papi_hwi_lookup_EventSet( EventSet );
01585     if ( ESI == NULL )
01586         papi_return( PAPI_ENOEVST );
01587 
01588 /* check if a component has been assigned */ 
01589     if ( ESI->CmpIdx < 0 )
01590       papi_return( PAPI_ENOCMP );
01591 
01592 /* validate CmpIdx */
01593     retval = valid_component( ESI->CmpIdx );
01594     if ( retval < 0 )
01595         papi_return( retval );
01596 
01597 /* return the index */
01598     return ( ESI->CmpIdx );
01599 }

Here is the call graph for this function:

get the executable's address space information

Definition at line 6122 of file papi.c.

06123 {
06124     PAPI_option_t ptr;
06125     int retval;
06126 
06127     memset( &ptr, 0, sizeof ( ptr ) );
06128     retval = PAPI_get_opt( PAPI_EXEINFO, &ptr );
06129     if ( retval == PAPI_OK )
06130         return ( ptr.exe_info );
06131     else
06132         return ( NULL );
06133 }

Here is the call graph for this function:

Here is the caller graph for this function:

const PAPI_hw_info_t* PAPI_get_hardware_info ( void   ) 

get information about the system hardware

Definition at line 6193 of file papi.c.

06194 {
06195     PAPI_option_t ptr;
06196     int retval;
06197 
06198     memset( &ptr, 0, sizeof ( ptr ) );
06199     retval = PAPI_get_opt( PAPI_HWINFO, &ptr );
06200     if ( retval == PAPI_OK )
06201         return ( ptr.hw_info );
06202     else
06203         return ( NULL );
06204 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_get_multiplex ( int  EventSet  ) 

get the multiplexing status of specified event set

Definition at line 4036 of file papi.c.

04037 {
04038     APIDBG( "Entry: EventSet: %d\n", EventSet);
04039     PAPI_option_t popt;
04040     int retval;
04041 
04042     popt.multiplex.eventset = EventSet;
04043     retval = PAPI_get_opt( PAPI_MULTIPLEX, &popt );
04044     if ( retval < 0 )
04045         retval = 0;
04046     return retval;
04047 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_get_opt ( int  option,
PAPI_option_t ptr 
)

query the option settings of the PAPI library or a specific event set

Definition at line 4151 of file papi.c.

04152 {
04153     APIDBG( "Entry: option: %d, ptr: %p\n", option, ptr);
04154     EventSetInfo_t *ESI;
04155 
04156     if ( ( option != PAPI_DEBUG ) && ( init_level == PAPI_NOT_INITED ) )
04157         papi_return( PAPI_ENOINIT );
04158 
04159     switch ( option ) {
04160     case PAPI_DETACH:
04161     {
04162         if ( ptr == NULL )
04163             papi_return( PAPI_EINVAL );
04164         ESI = _papi_hwi_lookup_EventSet( ptr->attach.eventset );
04165         if ( ESI == NULL )
04166             papi_return( PAPI_ENOEVST );
04167         ptr->attach.tid = ESI->attach.tid;
04168         return ( ( ESI->state & PAPI_ATTACHED ) == 0 );
04169     }
04170     case PAPI_ATTACH:
04171     {
04172         if ( ptr == NULL )
04173             papi_return( PAPI_EINVAL );
04174         ESI = _papi_hwi_lookup_EventSet( ptr->attach.eventset );
04175         if ( ESI == NULL )
04176             papi_return( PAPI_ENOEVST );
04177         ptr->attach.tid = ESI->attach.tid;
04178         return ( ( ESI->state & PAPI_ATTACHED ) != 0 );
04179     }
04180     case PAPI_CPU_ATTACH:
04181     {
04182         if ( ptr == NULL )
04183             papi_return( PAPI_EINVAL );
04184         ESI = _papi_hwi_lookup_EventSet( ptr->attach.eventset );
04185         if ( ESI == NULL )
04186             papi_return( PAPI_ENOEVST );
04187         ptr->cpu.cpu_num = ESI->CpuInfo->cpu_num;
04188         return ( ( ESI->state & PAPI_CPU_ATTACHED ) != 0 );
04189     }
04190     case PAPI_DEF_MPX_NS:
04191     {
04192         /* xxxx for now, assume we only check against cpu component */
04193         if ( ptr == NULL )
04194             papi_return( PAPI_EINVAL );
04195         ptr->multiplex.ns = _papi_os_info.itimer_ns;
04196         return ( PAPI_OK );
04197     }
04198     case PAPI_DEF_ITIMER_NS:
04199     {
04200         /* xxxx for now, assume we only check against cpu component */
04201         if ( ptr == NULL )
04202             papi_return( PAPI_EINVAL );
04203         ptr->itimer.ns = _papi_os_info.itimer_ns;
04204         return ( PAPI_OK );
04205     }
04206     case PAPI_DEF_ITIMER:
04207     {
04208         /* xxxx for now, assume we only check against cpu component */
04209         if ( ptr == NULL )
04210             papi_return( PAPI_EINVAL );
04211         ptr->itimer.itimer_num = _papi_os_info.itimer_num;
04212         ptr->itimer.itimer_sig = _papi_os_info.itimer_sig;
04213         ptr->itimer.ns = _papi_os_info.itimer_ns;
04214         ptr->itimer.flags = 0;
04215         return ( PAPI_OK );
04216     }
04217     case PAPI_MULTIPLEX:
04218     {
04219         if ( ptr == NULL )
04220             papi_return( PAPI_EINVAL );
04221         ESI = _papi_hwi_lookup_EventSet( ptr->multiplex.eventset );
04222         if ( ESI == NULL )
04223             papi_return( PAPI_ENOEVST );
04224         ptr->multiplex.ns = ESI->multiplex.ns;
04225         ptr->multiplex.flags = ESI->multiplex.flags;
04226         return ( ESI->state & PAPI_MULTIPLEXING ) != 0;
04227     }
04228     case PAPI_PRELOAD:
04229         if ( ptr == NULL )
04230             papi_return( PAPI_EINVAL );
04231         memcpy( &ptr->preload, &_papi_hwi_system_info.preload_info,
04232                 sizeof ( PAPI_preload_info_t ) );
04233         break;
04234     case PAPI_DEBUG:
04235         if ( ptr == NULL )
04236             papi_return( PAPI_EINVAL );
04237         ptr->debug.level = _papi_hwi_error_level;
04238         ptr->debug.handler = _papi_hwi_debug_handler;
04239         break;
04240     case PAPI_CLOCKRATE:
04241         return ( ( int ) _papi_hwi_system_info.hw_info.cpu_max_mhz );
04242     case PAPI_MAX_CPUS:
04243         return ( _papi_hwi_system_info.hw_info.ncpu );
04244         /* For now, MAX_HWCTRS and MAX CTRS are identical.
04245            At some future point, they may map onto different values.
04246          */
04247     case PAPI_INHERIT:
04248     {
04249         if ( ptr == NULL )
04250             papi_return( PAPI_EINVAL );
04251         ESI = _papi_hwi_lookup_EventSet( ptr->inherit.eventset );
04252         if ( ESI == NULL )
04253             papi_return( PAPI_ENOEVST );
04254         ptr->inherit.inherit = ESI->inherit.inherit;
04255         return ( PAPI_OK );
04256     }
04257     case PAPI_GRANUL:
04258         if ( ptr == NULL )
04259             papi_return( PAPI_EINVAL );
04260         ESI = _papi_hwi_lookup_EventSet( ptr->granularity.eventset );
04261         if ( ESI == NULL )
04262             papi_return( PAPI_ENOEVST );
04263         ptr->granularity.granularity = ESI->granularity.granularity;
04264         break;
04265     case PAPI_EXEINFO:
04266         if ( ptr == NULL )
04267             papi_return( PAPI_EINVAL );
04268         ptr->exe_info = &_papi_hwi_system_info.exe_info;
04269         break;
04270     case PAPI_HWINFO:
04271         if ( ptr == NULL )
04272             papi_return( PAPI_EINVAL );
04273         ptr->hw_info = &_papi_hwi_system_info.hw_info;
04274         break;
04275 
04276     case PAPI_DOMAIN:
04277         if ( ptr == NULL )
04278             papi_return( PAPI_EINVAL );
04279         ESI = _papi_hwi_lookup_EventSet( ptr->domain.eventset );
04280         if ( ESI == NULL )
04281             papi_return( PAPI_ENOEVST );
04282         ptr->domain.domain = ESI->domain.domain;
04283         return ( PAPI_OK );
04284     case PAPI_LIB_VERSION:
04285         return ( PAPI_VERSION );
04286 /* The following cases all require a component index 
04287     and are handled by PAPI_get_cmp_opt() with cidx == 0*/
04288     case PAPI_MAX_HWCTRS:
04289     case PAPI_MAX_MPX_CTRS:
04290     case PAPI_DEFDOM:
04291     case PAPI_DEFGRN:
04292     case PAPI_SHLIBINFO:
04293     case PAPI_COMPONENTINFO:
04294         return ( PAPI_get_cmp_opt( option, ptr, 0 ) );
04295     default:
04296         papi_return( PAPI_EINVAL );
04297     }
04298     return ( PAPI_OK );
04299 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_get_overflow_event_index ( int  Eventset,
long long  overflow_vector,
int *  array,
int *  number 
)

# decomposes an overflow_vector into an event index array

Definition at line 6525 of file papi.c.

06527 {
06528     APIDBG( "Entry: EventSet: %d, overflow_vector: %lld, array: %p, number: %p\n", EventSet, overflow_vector, array, number);
06529     EventSetInfo_t *ESI;
06530     int set_bit, j, pos;
06531     int count = 0, k;
06532 
06533     if ( overflow_vector == ( long long ) 0 )
06534         papi_return( PAPI_EINVAL );
06535 
06536     if ( ( array == NULL ) || ( number == NULL ) )
06537         papi_return( PAPI_EINVAL );
06538 
06539     if ( *number < 1 )
06540         papi_return( PAPI_EINVAL );
06541 
06542     ESI = _papi_hwi_lookup_EventSet( EventSet );
06543     if ( ESI == NULL )
06544         papi_return( PAPI_ENOEVST );
06545 
06546     /* in case the eventset is empty */
06547     if ( ESI->NumberOfEvents == 0 )
06548         papi_return( PAPI_EINVAL );
06549 
06550     while ( ( set_bit = ffsll( overflow_vector ) ) ) {
06551         set_bit -= 1;
06552         overflow_vector ^= ( long long ) 1 << set_bit;
06553         for ( j = 0; j < ESI->NumberOfEvents; j++ ) {
06554             for ( k = 0, pos = 0; k < PAPI_EVENTS_IN_DERIVED_EVENT && pos >= 0; k++ ) {
06555                 pos = ESI->EventInfoArray[j].pos[k];
06556                 if ( ( set_bit == pos ) &&
06557                      ( ( ESI->EventInfoArray[j].derived == NOT_DERIVED ) ||
06558                        ( ESI->EventInfoArray[j].derived == DERIVED_CMPD ) ) ) {
06559                     array[count++] = j;
06560                     if ( count == *number )
06561                         return PAPI_OK;
06562 
06563                     break;
06564                 }
06565             }
06566         }
06567     }
06568     *number = count;
06569     return PAPI_OK;
06570 }

Here is the call graph for this function:

Here is the caller graph for this function:

long long PAPI_get_real_cyc ( void   ) 

return the total number of cycles since some arbitrary starting point

Definition at line 6225 of file papi.c.

06226 {
06227     return ( _papi_os_vector.get_real_cycles(  ) );
06228 }

Here is the caller graph for this function:

long long PAPI_get_real_nsec ( void   ) 

return the total number of nanoseconds since some arbitrary starting point

Definition at line 6245 of file papi.c.

06246 {
06247   return ( ( _papi_os_vector.get_real_nsec(  )));
06248 
06249 }

Here is the caller graph for this function:

long long PAPI_get_real_usec ( void   ) 

return the total number of microseconds since some arbitrary starting point

Definition at line 6272 of file papi.c.

06273 {
06274     return ( _papi_os_vector.get_real_usec(  ) );
06275 }

Here is the caller graph for this function:

get information about the shared libraries used by the process

Definition at line 6152 of file papi.c.

06153 {
06154     PAPI_option_t ptr;
06155     int retval;
06156 
06157     memset( &ptr, 0, sizeof ( ptr ) );
06158     retval = PAPI_get_opt( PAPI_SHLIBINFO, &ptr );
06159     if ( retval == PAPI_OK )
06160         return ( ptr.shlib_info );
06161     else
06162         return ( NULL );
06163 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_get_thr_specific ( int  tag,
void **  ptr 
)

return a pointer to a thread specific stored data structure

Definition at line 362 of file papi.c.

00363 {
00364     ThreadInfo_t *thread;
00365     int doall = 0, retval = PAPI_OK;
00366 
00367     if ( init_level == PAPI_NOT_INITED )
00368         papi_return( PAPI_ENOINIT );
00369     if ( tag & PAPI_TLS_ALL_THREADS ) {
00370         tag = tag ^ PAPI_TLS_ALL_THREADS;
00371         doall = 1;
00372     }
00373     if ( ( tag < 0 ) || ( tag > PAPI_TLS_NUM ) )
00374         papi_return( PAPI_EINVAL );
00375 
00376     if ( doall )
00377         papi_return( _papi_hwi_gather_all_thrspec_data
00378                      ( tag, ( PAPI_all_thr_spec_t * ) ptr ) );
00379 
00380     retval = _papi_hwi_lookup_or_create_thread( &thread, 0 );
00381     if ( retval == PAPI_OK )
00382         *ptr = thread->thread_storage[tag];
00383     else
00384         papi_return( retval );
00385 
00386     return ( PAPI_OK );
00387 }

Here is the call graph for this function:

Here is the caller graph for this function:

long long PAPI_get_virt_cyc ( void   ) 

return the process cycles since some arbitrary starting point

Definition at line 6308 of file papi.c.

06309 {
06310 
06311     return ( ( long long ) _papi_os_vector.get_virt_cycles( ) );
06312 }

Here is the caller graph for this function:

long long PAPI_get_virt_nsec ( void   ) 

return the process nanoseconds since some arbitrary starting point

Definition at line 6338 of file papi.c.

06339 {
06340 
06341   return ( ( _papi_os_vector.get_virt_nsec()));
06342 
06343 }

long long PAPI_get_virt_usec ( void   ) 

return the process microseconds since some arbitrary starting point

Definition at line 6380 of file papi.c.

06381 {
06382 
06383     return ( ( long long ) _papi_os_vector.get_virt_usec() );
06384 }

Here is the caller graph for this function:

int PAPI_is_initialized ( void   ) 

return the initialized state of the PAPI library

Definition at line 6471 of file papi.c.

06472 {
06473     return ( init_level );
06474 }

Here is the caller graph for this function:

int PAPI_library_init ( int  version  ) 

initialize the PAPI library

Definition at line 500 of file papi.c.

00501 {
00502     APIDBG( "Entry: version: %#x\n", version);
00503 
00504     int tmp = 0, tmpel;
00505 
00506     /* This is a poor attempt at a lock. 
00507        For 3.1 this should be replaced with a 
00508        true UNIX semaphore. We cannot use PAPI
00509        locks here because they are not initialized yet */
00510     static int _in_papi_library_init_cnt = 0;
00511 #ifdef DEBUG
00512     char *var;
00513 #endif
00514     _papi_hwi_init_errors();
00515 
00516     if ( version != PAPI_VER_CURRENT )
00517         papi_return( PAPI_EINVAL );
00518 
00519     ++_in_papi_library_init_cnt;
00520     while ( _in_papi_library_init_cnt > 1 ) {
00521         PAPIERROR( "Multiple callers of PAPI_library_init" );
00522         sleep( 1 );
00523     }
00524 
00525     /* This checks to see if we have forked or called init more than once.
00526        If we have forked, then we continue to init. If we have not forked, 
00527        we check to see the status of initialization. */
00528 
00529     APIDBG( "Initializing library: current PID %d, old PID %d\n", 
00530                 getpid(  ), _papi_hwi_system_info.pid );
00531 
00532     if ( _papi_hwi_system_info.pid == getpid(  ) ) {
00533         /* If the magic environment variable PAPI_ALLOW_STOLEN is set,
00534            we call shutdown if PAPI has been initialized. This allows
00535            tools that use LD_PRELOAD to run on applications that use PAPI.
00536            In this circumstance, PAPI_ALLOW_STOLEN will be set to 'stolen'
00537            so the tool can check for this case. */
00538 
00539         if ( getenv( "PAPI_ALLOW_STOLEN" ) ) {
00540             char buf[PAPI_HUGE_STR_LEN];
00541             if ( init_level != PAPI_NOT_INITED )
00542                 PAPI_shutdown(  );
00543             sprintf( buf, "%s=%s", "PAPI_ALLOW_STOLEN", "stolen" );
00544             putenv( buf );
00545         }
00546 
00547         /* If the library has been successfully initialized *OR*
00548            the library attempted initialization but failed. */
00549 
00550         else if ( ( init_level != PAPI_NOT_INITED ) ||
00551                   ( init_retval != DEADBEEF ) ) {
00552             _in_papi_library_init_cnt--;
00553             if ( init_retval < PAPI_OK )
00554                 papi_return( init_retval );
00555             else
00556                 return ( init_retval );
00557         }
00558 
00559         APIDBG( "system_info was initialized, but init did not succeed\n" );
00560     }
00561 #ifdef DEBUG
00562     var = ( char * ) getenv( "PAPI_DEBUG" );
00563     _papi_hwi_debug = 0;
00564 
00565     if ( var != NULL ) {
00566         if ( strlen( var ) != 0 ) {
00567             if ( strstr( var, "SUBSTRATE" ) )
00568                 _papi_hwi_debug |= DEBUG_SUBSTRATE;
00569             if ( strstr( var, "API" ) )
00570                 _papi_hwi_debug |= DEBUG_API;
00571             if ( strstr( var, "INTERNAL" ) )
00572                 _papi_hwi_debug |= DEBUG_INTERNAL;
00573             if ( strstr( var, "THREADS" ) )
00574                 _papi_hwi_debug |= DEBUG_THREADS;
00575             if ( strstr( var, "MULTIPLEX" ) )
00576                 _papi_hwi_debug |= DEBUG_MULTIPLEX;
00577             if ( strstr( var, "OVERFLOW" ) )
00578                 _papi_hwi_debug |= DEBUG_OVERFLOW;
00579             if ( strstr( var, "PROFILE" ) )
00580                 _papi_hwi_debug |= DEBUG_PROFILE;
00581             if ( strstr( var, "MEMORY" ) )
00582                 _papi_hwi_debug |= DEBUG_MEMORY;
00583             if ( strstr( var, "LEAK" ) )
00584                 _papi_hwi_debug |= DEBUG_LEAK;
00585             if ( strstr( var, "ALL" ) )
00586                 _papi_hwi_debug |= DEBUG_ALL;
00587         }
00588 
00589         if ( _papi_hwi_debug == 0 )
00590             _papi_hwi_debug |= DEBUG_API;
00591     }
00592 #endif
00593 
00594     /* Be verbose for now */
00595 
00596     tmpel = _papi_hwi_error_level;
00597     _papi_hwi_error_level = PAPI_VERB_ECONT;
00598 
00599     /* Initialize internal globals */
00600     if ( _papi_hwi_init_global_internal(  ) != PAPI_OK ) {
00601         _in_papi_library_init_cnt--;
00602         _papi_hwi_error_level = tmpel;
00603         papi_return( PAPI_EINVAL );
00604     }
00605 
00606     /* Initialize OS */
00607     tmp = _papi_hwi_init_os();
00608     if ( tmp ) {
00609        init_retval = tmp;
00610        _papi_hwi_shutdown_global_internal(  );
00611        _in_papi_library_init_cnt--;
00612        _papi_hwi_error_level = tmpel;
00613        papi_return( init_retval );
00614     }
00615 
00616     /* Initialize component globals */
00617 
00618     tmp = _papi_hwi_init_global(  );
00619     if ( tmp ) {
00620         init_retval = tmp;
00621         _papi_hwi_shutdown_global_internal(  );
00622         _in_papi_library_init_cnt--;
00623         _papi_hwi_error_level = tmpel;
00624         papi_return( init_retval );
00625     }
00626     
00627     /* Initialize thread globals, including the main threads  */
00628 
00629     tmp = _papi_hwi_init_global_threads(  );
00630     if ( tmp ) {
00631         int i;
00632         init_retval = tmp;
00633         _papi_hwi_shutdown_global_internal(  );
00634         for ( i = 0; i < papi_num_components; i++ ) {
00635             if (!_papi_hwd[i]->cmp_info.disabled) {
00636                        _papi_hwd[i]->shutdown_component(  );
00637             }
00638         }
00639         _in_papi_library_init_cnt--;
00640         _papi_hwi_error_level = tmpel;
00641         papi_return( init_retval );
00642     }
00643 
00644     init_level = PAPI_LOW_LEVEL_INITED;
00645     _in_papi_library_init_cnt--;
00646     _papi_hwi_error_level = tmpel;
00647 
00648     return ( init_retval = PAPI_VER_CURRENT );
00649 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_list_events ( int  EventSet,
int *  Events,
int *  number 
)

list the events that are members of an event set

Definition at line 6009 of file papi.c.

06010 {
06011     APIDBG( "Entry: EventSet: %d, Events: %p, number: %p\n", EventSet, Events, number);
06012     EventSetInfo_t *ESI;
06013     int i, j;
06014 
06015     if ( *number < 0 )
06016         papi_return( PAPI_EINVAL );
06017 
06018     if ( ( Events == NULL ) && ( *number > 0 ) )
06019         papi_return( PAPI_EINVAL );
06020 
06021     ESI = _papi_hwi_lookup_EventSet( EventSet );
06022     if ( !ESI )
06023         papi_return( PAPI_ENOEVST );
06024 
06025     if ( ( Events == NULL ) || ( *number == 0 ) ) {
06026         *number = ESI->NumberOfEvents;
06027         papi_return( PAPI_OK );
06028     }
06029 
06030     for ( i = 0, j = 0; j < ESI->NumberOfEvents; i++ ) {
06031         if ( ( int ) ESI->EventInfoArray[i].event_code != PAPI_NULL ) {
06032             Events[j] = ( int ) ESI->EventInfoArray[i].event_code;
06033             j++;
06034             if ( j == *number )
06035                 break;
06036         }
06037     }
06038 
06039     *number = j;
06040 
06041     return ( PAPI_OK );
06042 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_list_threads ( unsigned long *  tids,
int *  number 
)

list the thread ids currently known to PAPI

Definition at line 286 of file papi.c.

00287 {
00288     PAPI_all_thr_spec_t tmp;
00289     int retval;
00290 
00291     /* If tids == NULL, then just count the threads, don't gather a list. */
00292     /* If tids != NULL, then we need the length of the tids array in num. */
00293 
00294     if ( ( number == NULL ) || ( tids && ( *number <= 0 ) ) )
00295         papi_return( PAPI_EINVAL );
00296 
00297     memset( &tmp, 0x0, sizeof ( tmp ) );
00298 
00299     /* data == NULL, since we don't want the thread specific pointers. */
00300     /* tids may be NULL, if the user doesn't want the thread IDs. */
00301 
00302     tmp.num = *number;
00303     tmp.id = tids;
00304     tmp.data = NULL;
00305 
00306     retval = _papi_hwi_gather_all_thrspec_data( 0, &tmp );
00307     if ( retval == PAPI_OK )
00308         *number = tmp.num;
00309 
00310     papi_return( retval );
00311 }

Here is the call graph for this function:

int PAPI_lock ( int   ) 

lock one of two PAPI internal user mutex variables

Definition at line 6409 of file papi.c.

06410 {
06411     if ( ( lck < 0 ) || ( lck >= PAPI_NUM_LOCK ) )
06412         papi_return( PAPI_EINVAL );
06413 
06414     papi_return( _papi_hwi_lock( lck ) );
06415 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_multiplex_init ( void   ) 

initialize multiplex support in the PAPI library

Definition at line 2990 of file papi.c.

02991 {
02992     APIDBG("Entry:\n");
02993 
02994     int retval;
02995 
02996     retval = mpx_init( _papi_os_info.itimer_ns );
02997     papi_return( retval );
02998 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_num_cmp_hwctrs ( int  cidx  ) 

return the number of hardware counters for a specified component

Definition at line 3973 of file papi.c.

03974 {
03975     APIDBG( "Entry: cidx: %d\n", cidx);
03976     return ( PAPI_get_cmp_opt( PAPI_MAX_HWCTRS, NULL, cidx ) );
03977 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_num_events ( int  EventSet  ) 

return the number of events in an event set

Definition at line 4434 of file papi.c.

04435 {
04436     APIDBG( "Entry: EventSet: %d\n", EventSet);
04437     EventSetInfo_t *ESI;
04438 
04439     ESI = _papi_hwi_lookup_EventSet( EventSet );
04440     if ( !ESI )
04441         papi_return( PAPI_ENOEVST );
04442 
04443 #ifdef DEBUG
04444     /* Not necessary */
04445     if ( ESI->NumberOfEvents == 0 )
04446         papi_return( PAPI_EINVAL );
04447 #endif
04448 
04449     return ( ESI->NumberOfEvents );
04450 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_overflow ( int  EventSet,
int  EventCode,
int  threshold,
int  flags,
PAPI_overflow_handler_t  handler 
)

set up an event set to begin registering overflows

Definition at line 4796 of file papi.c.

04798 {
04799     APIDBG( "Entry: EventSet: %d, EventCode: %#x, threshold: %d, flags: %#x, handler: %p\n", EventSet, EventCode, threshold, flags, handler);
04800     int retval, cidx, index, i;
04801     EventSetInfo_t *ESI;
04802 
04803     ESI = _papi_hwi_lookup_EventSet( EventSet );
04804     if ( ESI == NULL ) {
04805         OVFDBG("No EventSet\n");
04806         papi_return( PAPI_ENOEVST );
04807         }
04808 
04809     cidx = valid_ESI_component( ESI );
04810     if ( cidx < 0 ) {
04811         OVFDBG("Component Error\n");
04812         papi_return( cidx );
04813     }
04814 
04815     if ( ( ESI->state & PAPI_STOPPED ) != PAPI_STOPPED ) {
04816         OVFDBG("Already running\n");
04817         papi_return( PAPI_EISRUN );
04818     }
04819 
04820     if ( ESI->state & PAPI_ATTACHED ) {
04821         OVFDBG("Attached\n");
04822         papi_return( PAPI_EINVAL );
04823     }
04824     
04825     if ( ESI->state & PAPI_CPU_ATTACHED ) {
04826         OVFDBG("CPU attached\n");
04827         papi_return( PAPI_EINVAL );
04828     }
04829     
04830     if ( ( index = _papi_hwi_lookup_EventCodeIndex( ESI,
04831                         ( unsigned int ) EventCode ) ) < 0 ) {
04832         papi_return( PAPI_ENOEVNT );
04833     }
04834 
04835     if ( threshold < 0 ) {
04836         OVFDBG("Threshold below zero\n");
04837         papi_return( PAPI_EINVAL );
04838     }
04839 
04840     /* We do not support derived events in overflow */
04841     /* Unless it's DERIVED_CMPD in which no calculations are done */
04842 
04843     if ( !( flags & PAPI_OVERFLOW_FORCE_SW ) && threshold != 0 &&
04844          ( ESI->EventInfoArray[index].derived ) &&
04845          ( ESI->EventInfoArray[index].derived != DERIVED_CMPD ) ) {
04846         OVFDBG("Derived event in overflow\n");
04847         papi_return( PAPI_EINVAL );
04848     }
04849 
04850     /* the first time to call PAPI_overflow function */
04851 
04852     if ( !( ESI->state & PAPI_OVERFLOWING ) ) {
04853         if ( handler == NULL ) {
04854             OVFDBG("NULL handler\n");
04855             papi_return( PAPI_EINVAL );
04856         }
04857         if ( threshold == 0 ) {
04858             OVFDBG("Zero threshold\n");
04859             papi_return( PAPI_EINVAL );
04860         }
04861     }
04862     if ( threshold > 0 &&
04863          ESI->overflow.event_counter >= _papi_hwd[cidx]->cmp_info.num_cntrs )
04864         papi_return( PAPI_ECNFLCT );
04865 
04866     if ( threshold == 0 ) {
04867         for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
04868             if ( ESI->overflow.EventCode[i] == EventCode )
04869                 break;
04870         }
04871         /* EventCode not found */
04872         if ( i == ESI->overflow.event_counter )
04873             papi_return( PAPI_EINVAL );
04874         /* compact these arrays */
04875         while ( i < ESI->overflow.event_counter - 1 ) {
04876             ESI->overflow.deadline[i] = ESI->overflow.deadline[i + 1];
04877             ESI->overflow.threshold[i] = ESI->overflow.threshold[i + 1];
04878             ESI->overflow.EventIndex[i] = ESI->overflow.EventIndex[i + 1];
04879             ESI->overflow.EventCode[i] = ESI->overflow.EventCode[i + 1];
04880             i++;
04881         }
04882         ESI->overflow.deadline[i] = 0;
04883         ESI->overflow.threshold[i] = 0;
04884         ESI->overflow.EventIndex[i] = 0;
04885         ESI->overflow.EventCode[i] = 0;
04886         ESI->overflow.event_counter--;
04887     } else {
04888         if ( ESI->overflow.event_counter > 0 ) {
04889             if ( ( flags & PAPI_OVERFLOW_FORCE_SW ) &&
04890                  ( ESI->overflow.flags & PAPI_OVERFLOW_HARDWARE ) )
04891                 papi_return( PAPI_ECNFLCT );
04892             if ( !( flags & PAPI_OVERFLOW_FORCE_SW ) &&
04893                  ( ESI->overflow.flags & PAPI_OVERFLOW_FORCE_SW ) )
04894                 papi_return( PAPI_ECNFLCT );
04895         }
04896         for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
04897             if ( ESI->overflow.EventCode[i] == EventCode )
04898                 break;
04899         }
04900         /* A new entry */
04901         if ( i == ESI->overflow.event_counter ) {
04902             ESI->overflow.EventCode[i] = EventCode;
04903             ESI->overflow.event_counter++;
04904         }
04905         /* New or existing entry */
04906         ESI->overflow.deadline[i] = threshold;
04907         ESI->overflow.threshold[i] = threshold;
04908         ESI->overflow.EventIndex[i] = index;
04909         ESI->overflow.flags = flags;
04910 
04911     }
04912 
04913     /* If overflowing is already active, we should check to
04914        make sure that we don't specify a different handler
04915        or different flags here. You can't mix them. */
04916 
04917     ESI->overflow.handler = handler;
04918 
04919     /* Set up the option structure for the low level.
04920        If we have hardware interrupts and we are not using
04921        forced software emulated interrupts */
04922 
04923     if ( _papi_hwd[cidx]->cmp_info.hardware_intr &&
04924          !( ESI->overflow.flags & PAPI_OVERFLOW_FORCE_SW ) ) {
04925         retval = _papi_hwd[cidx]->set_overflow( ESI, index, threshold );
04926         if ( retval == PAPI_OK )
04927             ESI->overflow.flags |= PAPI_OVERFLOW_HARDWARE;
04928         else {
04929             papi_return( retval );  /* We should undo stuff here */
04930         }
04931     } else {
04932         /* Make sure hardware overflow is not set */
04933         ESI->overflow.flags &= ~( PAPI_OVERFLOW_HARDWARE );
04934     }
04935 
04936     APIDBG( "Overflow using: %s\n",
04937             ( ESI->overflow.
04938               flags & PAPI_OVERFLOW_HARDWARE ? "[Hardware]" : ESI->overflow.
04939               flags & PAPI_OVERFLOW_FORCE_SW ? "[Forced Software]" :
04940               "[Software]" ) );
04941 
04942     /* Toggle the overflow flags and ESI state */
04943 
04944     if ( ESI->overflow.event_counter >= 1 )
04945         ESI->state |= PAPI_OVERFLOWING;
04946     else {
04947         ESI->state ^= PAPI_OVERFLOWING;
04948         ESI->overflow.flags = 0;
04949         ESI->overflow.handler = NULL;
04950     }
04951 
04952     return PAPI_OK;
04953 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PAPI_perror ( char *  msg  ) 

Print a PAPI error message

Definition at line 4661 of file papi.c.

04662 {
04663     char *foo;
04664 
04665     foo = PAPI_strerror( _papi_hwi_errno );
04666     if ( foo == NULL )
04667         return;
04668 
04669     if ( msg )
04670         if ( *msg )
04671                 fprintf( stderr, "%s: ", msg );
04672 
04673     fprintf( stderr, "%s\n", foo );
04674 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_profil ( void *  buf,
unsigned  bufsiz,
caddr_t  offset,
unsigned  scale,
int  EventSet,
int  EventCode,
int  threshold,
int  flags 
)

generate PC histogram data where hardware counter overflow occurs

Definition at line 5446 of file papi.c.

05449 {
05450     APIDBG( "Entry: buf: %p, bufsiz: %d, offset: %p, scale: %u, EventSet: %d, EventCode: %#x, threshold: %d, flags: %#x\n", buf, bufsiz, offset, scale, EventSet, EventCode, threshold, flags);
05451     EventSetInfo_t *ESI;
05452     int i;
05453     int retval;
05454 
05455     ESI = _papi_hwi_lookup_EventSet( EventSet );
05456     if ( ESI == NULL )
05457         papi_return( PAPI_ENOEVST );
05458 
05459     /* scale factors are checked for validity in PAPI_sprofil */
05460 
05461     if ( threshold > 0 ) {
05462         PAPI_sprofil_t *prof;
05463 
05464         for ( i = 0; i < ESI->profile.event_counter; i++ ) {
05465             if ( ESI->profile.EventCode[i] == EventCode )
05466                 break;
05467         }
05468 
05469         if ( i == ESI->profile.event_counter ) {
05470             prof =
05471                 ( PAPI_sprofil_t * ) papi_malloc( sizeof ( PAPI_sprofil_t ) );
05472             memset( prof, 0x0, sizeof ( PAPI_sprofil_t ) );
05473             prof->pr_base = buf;
05474             prof->pr_size = bufsiz;
05475             prof->pr_off = offset;
05476             prof->pr_scale = scale;
05477 
05478             retval =
05479                 PAPI_sprofil( prof, 1, EventSet, EventCode, threshold, flags );
05480 
05481             if ( retval != PAPI_OK )
05482                 papi_free( prof );
05483         } else {
05484             prof = ESI->profile.prof[i];
05485             prof->pr_base = buf;
05486             prof->pr_size = bufsiz;
05487             prof->pr_off = offset;
05488             prof->pr_scale = scale;
05489             retval =
05490                 PAPI_sprofil( prof, 1, EventSet, EventCode, threshold, flags );
05491         }
05492         papi_return( retval );
05493     }
05494 
05495     for ( i = 0; i < ESI->profile.event_counter; i++ ) {
05496         if ( ESI->profile.EventCode[i] == EventCode )
05497             break;
05498     }
05499     /* EventCode not found */
05500     if ( i == ESI->profile.event_counter )
05501         papi_return( PAPI_EINVAL );
05502 
05503     papi_free( ESI->profile.prof[i] );
05504     ESI->profile.prof[i] = NULL;
05505 
05506     papi_return( PAPI_sprofil( NULL, 0, EventSet, EventCode, 0, flags ) );
05507 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_query_event ( int  EventCode  ) 

query if a PAPI event exists

Definition at line 693 of file papi.c.

00694 {
00695     APIDBG( "Entry: EventCode: %#x\n", EventCode);
00696     if ( IS_PRESET(EventCode) ) {
00697         EventCode &= PAPI_PRESET_AND_MASK;
00698         if ( EventCode < 0 || EventCode >= PAPI_MAX_PRESET_EVENTS )
00699             papi_return( PAPI_ENOTPRESET );
00700 
00701         if ( _papi_hwi_presets[EventCode].count )
00702                 papi_return (PAPI_OK);
00703         else
00704             return PAPI_ENOEVNT;
00705     }
00706 
00707     if ( IS_NATIVE(EventCode) ) {
00708         papi_return( _papi_hwi_query_native_event
00709                      ( ( unsigned int ) EventCode ) );
00710     }
00711 
00712     if ( IS_USER_DEFINED(EventCode) ) {
00713       EventCode &= PAPI_UE_AND_MASK;
00714       if ( EventCode < 0 || EventCode >= PAPI_MAX_USER_EVENTS)
00715           papi_return ( PAPI_ENOEVNT );
00716 
00717         if ( user_defined_events[EventCode].count )
00718             papi_return (PAPI_OK);
00719         else
00720             papi_return (PAPI_ENOEVNT);
00721     }
00722 
00723     papi_return( PAPI_ENOEVNT );
00724 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_query_named_event ( char *  EventName  ) 

query if a named PAPI event exists

Definition at line 765 of file papi.c.

00766 {
00767     int ret, code;
00768     
00769     ret = PAPI_event_name_to_code( EventName, &code );
00770     if ( ret == PAPI_OK ) ret = PAPI_query_event( code );
00771     papi_return( ret);
00772 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_read ( int  EventSet,
long long *  values 
)

read hardware events from an event set with no reset

Definition at line 2567 of file papi.c.

02568 {
02569     APIDBG( "Entry: EventSet: %d, values: %p\n", EventSet, values);
02570     EventSetInfo_t *ESI;
02571     hwd_context_t *context;
02572     int cidx, retval = PAPI_OK;
02573 
02574     ESI = _papi_hwi_lookup_EventSet( EventSet );
02575     if ( ESI == NULL )
02576         papi_return( PAPI_ENOEVST );
02577 
02578     cidx = valid_ESI_component( ESI );
02579     if ( cidx < 0 )
02580         papi_return( cidx );
02581 
02582     if ( values == NULL )
02583         papi_return( PAPI_EINVAL );
02584 
02585     if ( ESI->state & PAPI_RUNNING ) {
02586         if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
02587           retval = MPX_read( ESI->multiplex.mpx_evset, values, 0 );
02588         } else {
02589             /* get the context we should use for this event set */
02590             context = _papi_hwi_get_context( ESI, NULL );
02591             retval = _papi_hwi_read( context, ESI, values );
02592         }
02593         if ( retval != PAPI_OK )
02594             papi_return( retval );
02595     } else {
02596         memcpy( values, ESI->sw_stop,
02597                 ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
02598     }
02599 
02600 #if defined(DEBUG)
02601     if ( ISLEVEL( DEBUG_API ) ) {
02602         int i;
02603         for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
02604             APIDBG( "PAPI_read values[%d]:\t%lld\n", i, values[i] );
02605         }
02606     }
02607 #endif
02608 
02609     APIDBG( "PAPI_read returns %d\n", retval );
02610     return ( PAPI_OK );
02611 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_read_ts ( int  EventSet,
long long *  values,
long long *  cyc 
)

read from an eventset with a real-time cycle timestamp

Definition at line 2656 of file papi.c.

02657 {
02658     APIDBG( "Entry: EventSet: %d, values: %p, cycles: %p\n", EventSet, values, cycles);
02659     EventSetInfo_t *ESI;
02660     hwd_context_t *context;
02661     int cidx, retval = PAPI_OK;
02662 
02663     ESI = _papi_hwi_lookup_EventSet( EventSet );
02664     if ( ESI == NULL )
02665         papi_return( PAPI_ENOEVST );
02666 
02667     cidx = valid_ESI_component( ESI );
02668     if ( cidx < 0 )
02669         papi_return( cidx );
02670 
02671     if ( values == NULL )
02672         papi_return( PAPI_EINVAL );
02673 
02674     if ( ESI->state & PAPI_RUNNING ) {
02675         if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
02676           retval = MPX_read( ESI->multiplex.mpx_evset, values, 0 );
02677         } else {
02678             /* get the context we should use for this event set */
02679             context = _papi_hwi_get_context( ESI, NULL );
02680             retval = _papi_hwi_read( context, ESI, values );
02681         }
02682         if ( retval != PAPI_OK )
02683             papi_return( retval );
02684     } else {
02685         memcpy( values, ESI->sw_stop,
02686                 ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
02687     }
02688 
02689     *cycles = _papi_os_vector.get_real_cycles(  );
02690 
02691 #if defined(DEBUG)
02692     if ( ISLEVEL( DEBUG_API ) ) {
02693         int i;
02694         for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
02695             APIDBG( "PAPI_read values[%d]:\t%lld\n", i, values[i] );
02696         }
02697     }
02698 #endif
02699 
02700     APIDBG( "PAPI_read_ts returns %d\n", retval );
02701     return PAPI_OK;
02702 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_register_thread ( void   ) 

inform PAPI of the existence of a new thread

Definition at line 208 of file papi.c.

00209 {
00210     ThreadInfo_t *thread;
00211 
00212     if ( init_level == PAPI_NOT_INITED )
00213         papi_return( PAPI_ENOINIT );
00214     papi_return( _papi_hwi_lookup_or_create_thread( &thread, 0 ) );
00215 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_remove_event ( int  EventSet,
int  EventCode 
)

remove a hardware event from a PAPI event set

Definition at line 1767 of file papi.c.

01768 {
01769     APIDBG("Entry: EventSet: %d, EventCode: %#x\n", EventSet, EventCode);
01770     EventSetInfo_t *ESI;
01771     int i,retval;
01772 
01773     /* check for pre-existing ESI */
01774 
01775     ESI = _papi_hwi_lookup_EventSet( EventSet );
01776     if ( ESI == NULL )
01777         papi_return( PAPI_ENOEVST );
01778 
01779     /* Check argument for validity */
01780 
01781     if ( ( !IS_PRESET(EventCode) ) &&
01782         ( !IS_NATIVE(EventCode) ) &&
01783         ( !IS_USER_DEFINED(EventCode) ))
01784         papi_return( PAPI_EINVAL );
01785 
01786     /* Of course, it must be stopped in order to modify it. */
01787 
01788     if ( !( ESI->state & PAPI_STOPPED ) )
01789         papi_return( PAPI_EISRUN );
01790 
01791     /* if the state is PAPI_OVERFLOWING, you must first call
01792        PAPI_overflow with threshold=0 to remove the overflow flag */
01793 
01794     /* Turn off the event that is overflowing */
01795     if ( ESI->state & PAPI_OVERFLOWING ) {
01796        for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
01797            if ( ESI->overflow.EventCode[i] == EventCode ) {
01798           retval = PAPI_overflow( EventSet, EventCode, 0, 0,
01799                       ESI->overflow.handler );
01800           if (retval!=PAPI_OK) return retval;
01801           break;
01802            }
01803        }
01804     }
01805 
01806     /* force the user to call PAPI_profil to clear the PAPI_PROFILING flag */
01807     if ( ESI->state & PAPI_PROFILING ) {
01808         for ( i = 0; i < ESI->profile.event_counter; i++ ) {
01809             if ( ESI->profile.EventCode[i] == EventCode ) {
01810                 PAPI_sprofil( NULL, 0, EventSet, EventCode, 0, 0 );
01811                 break;
01812             }
01813         }
01814     }
01815 
01816     /* Now do the magic. */
01817 
01818     papi_return( _papi_hwi_remove_event( ESI, EventCode ) );
01819 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_remove_events ( int  EventSet,
int *  Events,
int  number 
)

remove an array of hardware events from a PAPI event set

Definition at line 5939 of file papi.c.

05940 {
05941     APIDBG( "Entry: EventSet: %d, Events: %p, number: %d\n", EventSet, Events, number);
05942     int i, retval;
05943 
05944     if ( ( Events == NULL ) || ( number <= 0 ) )
05945         papi_return( PAPI_EINVAL );
05946 
05947     for ( i = 0; i < number; i++ ) {
05948         retval = PAPI_remove_event( EventSet, Events[i] );
05949         if ( retval != PAPI_OK ) {
05950             if ( i == 0 )
05951                 papi_return( retval );
05952             else
05953                 return ( i );
05954         }
05955     }
05956     return ( PAPI_OK );
05957 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_remove_named_event ( int  EventSet,
char *  EventName 
)

remove a named event from a PAPI event set

Definition at line 1970 of file papi.c.

01971 {
01972     APIDBG("Entry: EventSet: %d, EventName: %s\n", EventSet, EventName);
01973     int ret, code;
01974     
01975     ret = PAPI_event_name_to_code( EventName, &code );
01976     if ( ret == PAPI_OK ) ret = PAPI_remove_event( EventSet, code );
01977     papi_return( ret );
01978 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_reset ( int  EventSet  ) 

reset the hardware event counts in an event set

Definition at line 2467 of file papi.c.

02468 {
02469     APIDBG("Entry: EventSet: %d\n", EventSet);
02470     int retval = PAPI_OK;
02471     EventSetInfo_t *ESI;
02472     hwd_context_t *context;
02473     int cidx;
02474 
02475     ESI = _papi_hwi_lookup_EventSet( EventSet );
02476     if ( ESI == NULL )
02477         papi_return( PAPI_ENOEVST );
02478 
02479     cidx = valid_ESI_component( ESI );
02480     if ( cidx < 0 )
02481         papi_return( cidx );
02482 
02483     if ( ESI->state & PAPI_RUNNING ) {
02484         if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
02485             retval = MPX_reset( ESI->multiplex.mpx_evset );
02486         } else {
02487             /* If we're not the only one running, then just
02488                read the current values into the ESI->start
02489                array. This holds the starting value for counters
02490                that are shared. */
02491             /* get the context we should use for this event set */
02492             context = _papi_hwi_get_context( ESI, NULL );
02493             retval = _papi_hwd[cidx]->reset( context, ESI->ctl_state );
02494         }
02495     } else {
02496 #ifdef __bgp__
02497         //  For BG/P, we always want to reset the 'real' hardware counters.  The counters
02498         //  can be controlled via multiple interfaces, and we need to ensure that the values
02499         //  are truly zero...
02500         /* get the context we should use for this event set */
02501         context = _papi_hwi_get_context( ESI, NULL );
02502         retval = _papi_hwd[cidx]->reset( context, ESI->ctl_state );
02503 #endif
02504         memset( ESI->sw_stop, 0x00,
02505                 ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
02506     }
02507 
02508     APIDBG( "EXIT: retval %d\n", retval );
02509     papi_return( retval );
02510 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_set_cmp_domain ( int  domain,
int  cidx 
)

set the component specific default execution domain for new event sets

Definition at line 5766 of file papi.c.

05767 {
05768     PAPI_option_t ptr;
05769 
05770     memset( &ptr, 0, sizeof ( ptr ) );
05771     ptr.defdomain.def_cidx = cidx;
05772     ptr.defdomain.domain = domain;
05773     papi_return( PAPI_set_opt( PAPI_DEFDOM, &ptr ) );
05774 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_set_cmp_granularity ( int  granularity,
int  cidx 
)

set the component specific default granularity for new event sets

Definition at line 5630 of file papi.c.

05631 {
05632     PAPI_option_t ptr;
05633 
05634     memset( &ptr, 0, sizeof ( ptr ) );
05635     ptr.defgranularity.def_cidx = cidx;
05636     ptr.defgranularity.granularity = granularity;
05637     papi_return( PAPI_set_opt( PAPI_DEFGRN, &ptr ) );
05638 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_set_debug ( int  level  ) 

set the current debug level for PAPI

Definition at line 3134 of file papi.c.

03135 {
03136     APIDBG("Entry: level: %d\n", level);
03137     PAPI_option_t option;
03138 
03139     memset( &option, 0x0, sizeof ( option ) );
03140     option.debug.level = level;
03141     option.debug.handler = _papi_hwi_debug_handler;
03142     return ( PAPI_set_opt( PAPI_DEBUG, &option ) );
03143 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_set_domain ( int  domain  ) 

set the default execution domain for new event sets

Definition at line 5696 of file papi.c.

05697 {
05698     return ( PAPI_set_cmp_domain( domain, 0 ) );
05699 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_set_granularity ( int  granularity  ) 

set the default granularity for new event sets

Definition at line 5565 of file papi.c.

05566 {
05567     return ( PAPI_set_cmp_granularity( granularity, 0 ) );
05568 }

Here is the call graph for this function:

int PAPI_set_multiplex ( int  EventSet  ) 

convert a standard event set to a multiplexed event set

Definition at line 3341 of file papi.c.

03342 {
03343     APIDBG( "Entry: EventSet: %d\n", EventSet);
03344 
03345     PAPI_option_t mpx;
03346     EventSetInfo_t *ESI;
03347     int cidx;
03348     int ret;
03349 
03350     /* Is the EventSet already in existence? */
03351 
03352     ESI = _papi_hwi_lookup_EventSet( EventSet );
03353 
03354     if ( ESI == NULL )
03355         papi_return( PAPI_ENOEVST );
03356 
03357     /* if the eventset has no index return NOCMP */
03358     cidx = valid_ESI_component( ESI );
03359     if ( cidx < 0 )
03360         papi_return( cidx );
03361 
03362     if ( ( ret = mpx_check( EventSet ) ) != PAPI_OK )
03363         papi_return( ret );
03364 
03365     memset( &mpx, 0x0, sizeof ( mpx ) );
03366     mpx.multiplex.eventset = EventSet;
03367     mpx.multiplex.flags = PAPI_MULTIPLEX_DEFAULT;
03368     mpx.multiplex.ns = _papi_os_info.itimer_ns;
03369     return ( PAPI_set_opt( PAPI_MULTIPLEX, &mpx ) );
03370 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_set_opt ( int  option,
PAPI_option_t ptr 
)

change the option settings of the PAPI library or a specific event set

Definition at line 3473 of file papi.c.

03474 {
03475     APIDBG("Entry:  option: %d, ptr: %p\n", option, ptr);
03476 
03477     _papi_int_option_t internal;
03478     int retval = PAPI_OK;
03479     hwd_context_t *context;
03480     int cidx;
03481 
03482     if ( ( option != PAPI_DEBUG ) && ( init_level == PAPI_NOT_INITED ) )
03483         papi_return( PAPI_ENOINIT );
03484     if ( ptr == NULL )
03485         papi_return( PAPI_EINVAL );
03486 
03487     memset( &internal, 0x0, sizeof ( _papi_int_option_t ) );
03488 
03489     switch ( option ) {
03490     case PAPI_DETACH:
03491     {
03492         internal.attach.ESI = _papi_hwi_lookup_EventSet( ptr->attach.eventset );
03493         if ( internal.attach.ESI == NULL )
03494             papi_return( PAPI_ENOEVST );
03495 
03496         cidx = valid_ESI_component( internal.attach.ESI );
03497         if ( cidx < 0 )
03498             papi_return( cidx );
03499 
03500         if ( _papi_hwd[cidx]->cmp_info.attach == 0 )
03501             papi_return( PAPI_ECMP );
03502 
03503         /* if attached to a cpu, return an error */
03504         if (internal.attach.ESI->state & PAPI_CPU_ATTACHED)
03505             papi_return( PAPI_ECMP );
03506 
03507         if ( ( internal.attach.ESI->state & PAPI_STOPPED ) == 0 )
03508             papi_return( PAPI_EISRUN );
03509 
03510         if ( ( internal.attach.ESI->state & PAPI_ATTACHED ) == 0 )
03511             papi_return( PAPI_EINVAL );
03512 
03513         internal.attach.tid = internal.attach.ESI->attach.tid;
03514         /* get the context we should use for this event set */
03515         context = _papi_hwi_get_context( internal.attach.ESI, NULL );
03516         retval = _papi_hwd[cidx]->ctl( context, PAPI_DETACH, &internal );
03517         if ( retval != PAPI_OK )
03518             papi_return( retval );
03519 
03520         internal.attach.ESI->state ^= PAPI_ATTACHED;
03521         internal.attach.ESI->attach.tid = 0;
03522         return ( PAPI_OK );
03523     }
03524     case PAPI_ATTACH:
03525     {
03526         internal.attach.ESI = _papi_hwi_lookup_EventSet( ptr->attach.eventset );
03527         if ( internal.attach.ESI == NULL )
03528             papi_return( PAPI_ENOEVST );
03529 
03530         cidx = valid_ESI_component( internal.attach.ESI );
03531         if ( cidx < 0 )
03532             papi_return( cidx );
03533 
03534         if ( _papi_hwd[cidx]->cmp_info.attach == 0 )
03535             papi_return( PAPI_ECMP );
03536 
03537         if ( ( internal.attach.ESI->state & PAPI_STOPPED ) == 0 )
03538             papi_return( PAPI_EISRUN );
03539 
03540         if ( internal.attach.ESI->state & PAPI_ATTACHED )
03541             papi_return( PAPI_EINVAL );
03542 
03543         /* if attached to a cpu, return an error */
03544         if (internal.attach.ESI->state & PAPI_CPU_ATTACHED)
03545             papi_return( PAPI_ECMP );
03546 
03547         internal.attach.tid = ptr->attach.tid;
03548         /* get the context we should use for this event set */
03549         context = _papi_hwi_get_context( internal.attach.ESI, NULL );
03550         retval = _papi_hwd[cidx]->ctl( context, PAPI_ATTACH, &internal );
03551         if ( retval != PAPI_OK )
03552             papi_return( retval );
03553 
03554         internal.attach.ESI->state |= PAPI_ATTACHED;
03555         internal.attach.ESI->attach.tid = ptr->attach.tid;
03556 
03557         papi_return (_papi_hwi_lookup_or_create_thread( 
03558                       &(internal.attach.ESI->master), ptr->attach.tid ));
03559     }
03560     case PAPI_CPU_ATTACH:
03561     {
03562         APIDBG("eventset: %d, cpu_num: %d\n", ptr->cpu.eventset, ptr->cpu.cpu_num);
03563         internal.cpu.ESI = _papi_hwi_lookup_EventSet( ptr->cpu.eventset );
03564         if ( internal.cpu.ESI == NULL )
03565             papi_return( PAPI_ENOEVST );
03566 
03567         internal.cpu.cpu_num = ptr->cpu.cpu_num;
03568         APIDBG("internal: %p, ESI: %p, cpu_num: %d\n", &internal, internal.cpu.ESI, internal.cpu.cpu_num);
03569 
03570         cidx = valid_ESI_component( internal.cpu.ESI );
03571         if ( cidx < 0 )
03572             papi_return( cidx );
03573 
03574         if ( _papi_hwd[cidx]->cmp_info.cpu == 0 )
03575             papi_return( PAPI_ECMP );
03576 
03577         // can not attach to a cpu if already attached to a process or 
03578         // counters set to be inherited by child processes
03579         if ( internal.cpu.ESI->state & (PAPI_ATTACHED | PAPI_INHERIT) )
03580             papi_return( PAPI_EINVAL );
03581 
03582         if ( ( internal.cpu.ESI->state & PAPI_STOPPED ) == 0 )
03583             papi_return( PAPI_EISRUN );
03584 
03585         retval = _papi_hwi_lookup_or_create_cpu(&internal.cpu.ESI->CpuInfo, internal.cpu.cpu_num);
03586         if( retval != PAPI_OK) {
03587             papi_return( retval );
03588         }
03589 
03590         /* get the context we should use for this event set */
03591         context = _papi_hwi_get_context( internal.cpu.ESI, NULL );
03592         retval = _papi_hwd[cidx]->ctl( context, PAPI_CPU_ATTACH, &internal );
03593         if ( retval != PAPI_OK )
03594             papi_return( retval );
03595 
03596         /* set to show this event set is attached to a cpu not a thread */
03597         internal.cpu.ESI->state |= PAPI_CPU_ATTACHED;
03598         return ( PAPI_OK );
03599     }
03600     case PAPI_DEF_MPX_NS:
03601     {
03602         cidx = 0;            /* xxxx for now, assume we only check against cpu component */
03603         if ( ptr->multiplex.ns < 0 )
03604             papi_return( PAPI_EINVAL );
03605         /* We should check the resolution here with the system, either
03606            component if kernel multiplexing or PAPI if SW multiplexing. */
03607         internal.multiplex.ns = ( unsigned long ) ptr->multiplex.ns;
03608         /* get the context we should use for this event set */
03609         context = _papi_hwi_get_context( internal.cpu.ESI, NULL );
03610         /* Low level just checks/adjusts the args for this component */
03611         retval = _papi_hwd[cidx]->ctl( context, PAPI_DEF_MPX_NS, &internal );
03612         if ( retval == PAPI_OK ) {
03613             _papi_os_info.itimer_ns = ( int ) internal.multiplex.ns;
03614             ptr->multiplex.ns = ( int ) internal.multiplex.ns;
03615         }
03616         papi_return( retval );
03617     }
03618     case PAPI_DEF_ITIMER_NS:
03619     {
03620         cidx = 0;            /* xxxx for now, assume we only check against cpu component */
03621         if ( ptr->itimer.ns < 0 )
03622             papi_return( PAPI_EINVAL );
03623         internal.itimer.ns = ptr->itimer.ns;
03624         /* Low level just checks/adjusts the args for this component */
03625         retval = _papi_hwd[cidx]->ctl( NULL, PAPI_DEF_ITIMER_NS, &internal );
03626         if ( retval == PAPI_OK ) {
03627             _papi_os_info.itimer_ns = internal.itimer.ns;
03628             ptr->itimer.ns = internal.itimer.ns;
03629         }
03630         papi_return( retval );
03631     }
03632     case PAPI_DEF_ITIMER:
03633     {
03634         cidx = 0;            /* xxxx for now, assume we only check against cpu component */
03635         if ( ptr->itimer.ns < 0 )
03636             papi_return( PAPI_EINVAL );
03637         memcpy( &internal.itimer, &ptr->itimer,
03638                 sizeof ( PAPI_itimer_option_t ) );
03639         /* Low level just checks/adjusts the args for this component */
03640         retval = _papi_hwd[cidx]->ctl( NULL, PAPI_DEF_ITIMER, &internal );
03641         if ( retval == PAPI_OK ) {
03642             _papi_os_info.itimer_num = ptr->itimer.itimer_num;
03643             _papi_os_info.itimer_sig = ptr->itimer.itimer_sig;
03644             if ( ptr->itimer.ns > 0 )
03645                 _papi_os_info.itimer_ns = ptr->itimer.ns;
03646             /* flags are currently ignored, eventually the flags will be able
03647                to specify whether or not we use POSIX itimers (clock_gettimer) */
03648         }
03649         papi_return( retval );
03650     }
03651     case PAPI_MULTIPLEX:
03652     {
03653         EventSetInfo_t *ESI;
03654         ESI = _papi_hwi_lookup_EventSet( ptr->multiplex.eventset );
03655        
03656         if ( ESI == NULL )
03657             papi_return( PAPI_ENOEVST );
03658 
03659         cidx = valid_ESI_component( ESI );
03660         if ( cidx < 0 )
03661             papi_return( cidx );
03662        
03663         if ( !( ESI->state & PAPI_STOPPED ) )
03664             papi_return( PAPI_EISRUN );
03665         if ( ESI->state & PAPI_MULTIPLEXING )
03666             papi_return( PAPI_EINVAL );
03667 
03668         if ( ptr->multiplex.ns < 0 )
03669             papi_return( PAPI_EINVAL );
03670         internal.multiplex.ESI = ESI;
03671         internal.multiplex.ns = ( unsigned long ) ptr->multiplex.ns;
03672         internal.multiplex.flags = ptr->multiplex.flags;
03673         if ( ( _papi_hwd[cidx]->cmp_info.kernel_multiplex ) &&
03674              ( ( ptr->multiplex.flags & PAPI_MULTIPLEX_FORCE_SW ) == 0 ) ) {
03675             /* get the context we should use for this event set */
03676             context = _papi_hwi_get_context( ESI, NULL );
03677             retval = _papi_hwd[cidx]->ctl( context, PAPI_MULTIPLEX, &internal );
03678         }
03679         /* Kernel or PAPI may have changed this value so send it back out to the user */
03680         ptr->multiplex.ns = ( int ) internal.multiplex.ns;
03681         if ( retval == PAPI_OK )
03682             papi_return( _papi_hwi_convert_eventset_to_multiplex
03683                          ( &internal.multiplex ) );
03684         return ( retval );
03685     }
03686     case PAPI_DEBUG:
03687     {
03688         int level = ptr->debug.level;
03689         switch ( level ) {
03690         case PAPI_QUIET:
03691         case PAPI_VERB_ESTOP:
03692         case PAPI_VERB_ECONT:
03693             _papi_hwi_error_level = level;
03694             break;
03695         default:
03696             papi_return( PAPI_EINVAL );
03697         }
03698         _papi_hwi_debug_handler = ptr->debug.handler;
03699         return ( PAPI_OK );
03700     }
03701     case PAPI_DEFDOM:
03702     {
03703         int dom = ptr->defdomain.domain;
03704         if ( ( dom < PAPI_DOM_MIN ) || ( dom > PAPI_DOM_MAX ) )
03705             papi_return( PAPI_EINVAL );
03706 
03707         /* Change the global structure. The _papi_hwd_init_control_state function 
03708            in the components gets information from the global structure instead of
03709            per-thread information. */
03710         cidx = valid_component( ptr->defdomain.def_cidx );
03711         if ( cidx < 0 )
03712             papi_return( cidx );
03713 
03714         /* Check what the component supports */
03715 
03716         if ( dom == PAPI_DOM_ALL )
03717             dom = _papi_hwd[cidx]->cmp_info.available_domains;
03718 
03719         if ( dom & ~_papi_hwd[cidx]->cmp_info.available_domains )
03720             papi_return( PAPI_ENOSUPP );
03721 
03722         _papi_hwd[cidx]->cmp_info.default_domain = dom;
03723 
03724         return ( PAPI_OK );
03725     }
03726     case PAPI_DOMAIN:
03727     {
03728         int dom = ptr->domain.domain;
03729         if ( ( dom < PAPI_DOM_MIN ) || ( dom > PAPI_DOM_MAX ) )
03730             papi_return( PAPI_EINVAL_DOM );
03731 
03732         internal.domain.ESI = _papi_hwi_lookup_EventSet( ptr->domain.eventset );
03733         if ( internal.domain.ESI == NULL )
03734             papi_return( PAPI_ENOEVST );
03735 
03736         cidx = valid_ESI_component( internal.domain.ESI );
03737         if ( cidx < 0 )
03738             papi_return( cidx );
03739 
03740         /* Check what the component supports */
03741 
03742         if ( dom == PAPI_DOM_ALL )
03743             dom = _papi_hwd[cidx]->cmp_info.available_domains;
03744 
03745         if ( dom & ~_papi_hwd[cidx]->cmp_info.available_domains )
03746             papi_return( PAPI_EINVAL_DOM );
03747 
03748         if ( !( internal.domain.ESI->state & PAPI_STOPPED ) )
03749             papi_return( PAPI_EISRUN );
03750 
03751         /* Try to change the domain of the eventset in the hardware */
03752         internal.domain.domain = dom;
03753         internal.domain.eventset = ptr->domain.eventset;
03754         /* get the context we should use for this event set */
03755         context = _papi_hwi_get_context( internal.domain.ESI, NULL );
03756         retval = _papi_hwd[cidx]->ctl( context, PAPI_DOMAIN, &internal );
03757         if ( retval < PAPI_OK )
03758             papi_return( retval );
03759 
03760         /* Change the domain of the eventset in the library */
03761 
03762         internal.domain.ESI->domain.domain = dom;
03763 
03764         return ( retval );
03765     }
03766     case PAPI_DEFGRN:
03767     {
03768         int grn = ptr->defgranularity.granularity;
03769         if ( ( grn < PAPI_GRN_MIN ) || ( grn > PAPI_GRN_MAX ) )
03770             papi_return( PAPI_EINVAL );
03771 
03772         cidx = valid_component( ptr->defgranularity.def_cidx );
03773         if ( cidx < 0 )
03774             papi_return( cidx );
03775 
03776         /* Change the component structure. The _papi_hwd_init_control_state function 
03777            in the components gets information from the global structure instead of
03778            per-thread information. */
03779 
03780         /* Check what the component supports */
03781 
03782         if ( grn & ~_papi_hwd[cidx]->cmp_info.available_granularities )
03783             papi_return( PAPI_EINVAL );
03784 
03785         /* Make sure there is only 1 set. */
03786         if ( grn ^ ( 1 << ( ffs( grn ) - 1 ) ) )
03787             papi_return( PAPI_EINVAL );
03788 
03789         _papi_hwd[cidx]->cmp_info.default_granularity = grn;
03790 
03791         return ( PAPI_OK );
03792     }
03793     case PAPI_GRANUL:
03794     {
03795         int grn = ptr->granularity.granularity;
03796 
03797         if ( ( grn < PAPI_GRN_MIN ) || ( grn > PAPI_GRN_MAX ) )
03798             papi_return( PAPI_EINVAL );
03799 
03800         internal.granularity.ESI =
03801             _papi_hwi_lookup_EventSet( ptr->granularity.eventset );
03802         if ( internal.granularity.ESI == NULL )
03803             papi_return( PAPI_ENOEVST );
03804 
03805         cidx = valid_ESI_component( internal.granularity.ESI );
03806         if ( cidx < 0 )
03807             papi_return( cidx );
03808 
03809         /* Check what the component supports */
03810 
03811         if ( grn & ~_papi_hwd[cidx]->cmp_info.available_granularities )
03812             papi_return( PAPI_EINVAL );
03813 
03814         /* Make sure there is only 1 set. */
03815         if ( grn ^ ( 1 << ( ffs( grn ) - 1 ) ) )
03816             papi_return( PAPI_EINVAL );
03817 
03818         internal.granularity.granularity = grn;
03819         internal.granularity.eventset = ptr->granularity.eventset;
03820         retval = _papi_hwd[cidx]->ctl( NULL, PAPI_GRANUL, &internal );
03821         if ( retval < PAPI_OK )
03822             return ( retval );
03823 
03824         internal.granularity.ESI->granularity.granularity = grn;
03825         return ( retval );
03826     }
03827     case PAPI_INHERIT:
03828     {
03829         EventSetInfo_t *ESI;
03830         ESI = _papi_hwi_lookup_EventSet( ptr->inherit.eventset );
03831         if ( ESI == NULL )
03832             papi_return( PAPI_ENOEVST );
03833 
03834         cidx = valid_ESI_component( ESI );
03835         if ( cidx < 0 )
03836             papi_return( cidx );
03837 
03838         if ( _papi_hwd[cidx]->cmp_info.inherit == 0 )
03839             papi_return( PAPI_ECMP );
03840 
03841         if ( ( ESI->state & PAPI_STOPPED ) == 0 )
03842             papi_return( PAPI_EISRUN );
03843 
03844         /* if attached to a cpu, return an error */
03845         if (ESI->state & PAPI_CPU_ATTACHED)
03846             papi_return( PAPI_ECMP );
03847 
03848         internal.inherit.ESI = ESI;
03849         internal.inherit.inherit = ptr->inherit.inherit;
03850 
03851         /* get the context we should use for this event set */
03852         context = _papi_hwi_get_context( internal.inherit.ESI, NULL );
03853         retval = _papi_hwd[cidx]->ctl( context, PAPI_INHERIT, &internal );
03854         if ( retval < PAPI_OK )
03855             return ( retval );
03856 
03857         ESI->inherit.inherit = ptr->inherit.inherit;
03858         return ( retval );
03859     }
03860     case PAPI_DATA_ADDRESS:
03861     case PAPI_INSTR_ADDRESS:
03862     {
03863 
03864         EventSetInfo_t *ESI;
03865 
03866         ESI = _papi_hwi_lookup_EventSet( ptr->addr.eventset );
03867         if ( ESI == NULL )
03868             papi_return( PAPI_ENOEVST );
03869 
03870         cidx = valid_ESI_component( ESI );
03871         if ( cidx < 0 )
03872             papi_return( cidx );
03873 
03874         internal.address_range.ESI = ESI;
03875 
03876         if ( !( internal.address_range.ESI->state & PAPI_STOPPED ) )
03877             papi_return( PAPI_EISRUN );
03878 
03879         /*set domain to be PAPI_DOM_USER */
03880         internal.address_range.domain = PAPI_DOM_USER;
03881 
03882         internal.address_range.start = ptr->addr.start;
03883         internal.address_range.end = ptr->addr.end;
03884         /* get the context we should use for this event set */
03885         context = _papi_hwi_get_context( internal.address_range.ESI, NULL );
03886         retval = _papi_hwd[cidx]->ctl( context, option, &internal );
03887         ptr->addr.start_off = internal.address_range.start_off;
03888         ptr->addr.end_off = internal.address_range.end_off;
03889         papi_return( retval );
03890     }
03891     case PAPI_USER_EVENTS_FILE:
03892     {
03893         APIDBG("User Events Filename is -%s-\n", ptr->events_file);
03894 
03895         // go load the user defined event definitions from the applications event definition file
03896         // do not know how to find a pmu name and type for this operation yet
03897 //      retval = papi_load_derived_events(pmu_str, pmu_type, cidx, 0);
03898 
03899 //      _papi_user_defined_events_setup(ptr->events_file);
03900         return( PAPI_OK );
03901     }
03902     default:
03903         papi_return( PAPI_EINVAL );
03904     }
03905 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_set_thr_specific ( int  tag,
void *  ptr 
)

save a pointer as a thread specific stored data structure

Definition at line 438 of file papi.c.

00439 {
00440     ThreadInfo_t *thread;
00441     int retval = PAPI_OK;
00442 
00443     if ( init_level == PAPI_NOT_INITED )
00444         papi_return( PAPI_ENOINIT );
00445     if ( ( tag < 0 ) || ( tag > PAPI_NUM_TLS ) )
00446         papi_return( PAPI_EINVAL );
00447 
00448     retval = _papi_hwi_lookup_or_create_thread( &thread, 0 );
00449     if ( retval == PAPI_OK ) {
00450        _papi_hwi_lock( THREADS_LOCK );
00451        thread->thread_storage[tag] = ptr;
00452        _papi_hwi_unlock( THREADS_LOCK );
00453     }
00454     else
00455         return ( retval );
00456 
00457     return ( PAPI_OK );
00458 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PAPI_shutdown ( void   ) 

finish using PAPI and free all related resources

Definition at line 4469 of file papi.c.

04470 {
04471     APIDBG( "Entry:\n");
04472 
04473         EventSetInfo_t *ESI;
04474         ThreadInfo_t *master;
04475         DynamicArray_t *map = &_papi_hwi_system_info.global_eventset_map;
04476         int i, j = 0, k, retval;
04477 
04478 
04479     if ( init_retval == DEADBEEF ) {
04480         PAPIERROR( PAPI_SHUTDOWN_str );
04481         return;
04482     }
04483 
04484     MPX_shutdown(  );
04485 
04486     /* Free all EventSets for this thread */
04487 
04488    master = _papi_hwi_lookup_thread( 0 );
04489 
04490       /* Count number of running EventSets AND */
04491       /* Stop any running EventSets in this thread */
04492 
04493 #ifdef DEBUG
04494 again:
04495 #endif
04496    for( i = 0; i < map->totalSlots; i++ ) {
04497       ESI = map->dataSlotArray[i];
04498       if ( ESI ) {
04499      if ( ESI->master == master ) {
04500         if ( ESI->state & PAPI_RUNNING ) {
04501            if((retval = PAPI_stop( i, NULL )) != PAPI_OK) {
04502                APIDBG("Call to PAPI_stop failed: %d\n", retval);
04503            }
04504         }
04505         retval=PAPI_cleanup_eventset( i );
04506         if (retval!=PAPI_OK) PAPIERROR("Error during cleanup.");
04507         _papi_hwi_free_EventSet( ESI );
04508      } 
04509          else {
04510             if ( ESI->state & PAPI_RUNNING ) {
04511            j++;
04512         }
04513      }
04514       }
04515    }
04516 
04517     /* No locking required, we're just waiting for the others
04518        to call shutdown or stop their eventsets. */
04519 
04520 #ifdef DEBUG
04521     if ( j != 0 ) {
04522         PAPIERROR( PAPI_SHUTDOWN_SYNC_str );
04523         sleep( 1 );
04524         j = 0;
04525         goto again;
04526     }
04527 #endif
04528 
04529     // if we have some user events defined, release the space they allocated
04530     // give back the strings which were allocated when each event was created
04531     for ( i=0 ; i<user_defined_events_count ; i++) {
04532         papi_free (user_defined_events[i].symbol);
04533         papi_free (user_defined_events[i].postfix);
04534         papi_free (user_defined_events[i].long_descr);
04535         papi_free (user_defined_events[i].short_descr);
04536         papi_free (user_defined_events[i].note);
04537         for ( k=0 ; k<(int)(user_defined_events[i].count) ; k++) {
04538             papi_free (user_defined_events[i].name[k]);
04539         }
04540     }
04541     // make sure the user events list is empty
04542     memset (user_defined_events, '\0' , sizeof(user_defined_events));
04543     user_defined_events_count = 0;
04544 
04545     /* Shutdown the entire component */
04546     _papi_hwi_shutdown_highlevel(  );
04547     _papi_hwi_shutdown_global_internal(  );
04548     _papi_hwi_shutdown_global_threads(  );
04549     for( i = 0; i < papi_num_components; i++ ) {
04550        if (!_papi_hwd[i]->cmp_info.disabled) {
04551               _papi_hwd[i]->shutdown_component(  );
04552        }
04553     }
04554 
04555     /* Now it is safe to call re-init */
04556 
04557     init_retval = DEADBEEF;
04558     init_level = PAPI_NOT_INITED;
04559     _papi_mem_cleanup_all(  );
04560 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_sprofil ( PAPI_sprofil_t prof,
int  profcnt,
int  EventSet,
int  EventCode,
int  threshold,
int  flags 
)

generate hardware counter profiles from multiple code regions

Definition at line 5052 of file papi.c.

05054 {
05055     APIDBG( "Entry: prof: %p, profcnt: %d, EventSet: %d, EventCode: %#x, threshold: %d, flags: %#x\n", prof, profcnt, EventSet, EventCode, threshold, flags);
05056    EventSetInfo_t *ESI;
05057    int retval, index, i, buckets;
05058    int forceSW = 0;
05059    int cidx;
05060 
05061    /* Check to make sure EventSet exists */
05062    ESI = _papi_hwi_lookup_EventSet( EventSet );
05063    if ( ESI == NULL ) {
05064       papi_return( PAPI_ENOEVST );
05065    }
05066 
05067    /* Check to make sure EventSet is stopped */
05068    if ( ( ESI->state & PAPI_STOPPED ) != PAPI_STOPPED ) {
05069       papi_return( PAPI_EISRUN );
05070    }
05071 
05072    /* We cannot profile if attached */
05073    if ( ESI->state & PAPI_ATTACHED ) {
05074       papi_return( PAPI_EINVAL );
05075    }
05076 
05077    /* We cannot profile if cpu attached */
05078    if ( ESI->state & PAPI_CPU_ATTACHED ) {
05079       papi_return( PAPI_EINVAL );
05080    }
05081 
05082    /* Get component for EventSet */
05083    cidx = valid_ESI_component( ESI );
05084    if ( cidx < 0 ) {
05085       papi_return( cidx );
05086    }
05087 
05088    /* Get index of the Event we want to profile */
05089    if ( ( index = _papi_hwi_lookup_EventCodeIndex( ESI,
05090                       (unsigned int) EventCode ) ) < 0 ) {
05091       papi_return( PAPI_ENOEVNT );
05092    }
05093 
05094    /* We do not support derived events in overflow */
05095    /* Unless it's DERIVED_CMPD in which no calculations are done */
05096    if ( ( ESI->EventInfoArray[index].derived ) &&
05097     ( ESI->EventInfoArray[index].derived != DERIVED_CMPD ) &&
05098     !( flags & PAPI_PROFIL_FORCE_SW ) ) {
05099       papi_return( PAPI_EINVAL );
05100    }
05101 
05102    /* If no prof structures, then make sure count is 0 */
05103    if ( prof == NULL ) {
05104       profcnt = 0;
05105    }
05106 
05107    /* check all profile regions for valid scale factors of:
05108       2 (131072/65536),
05109       1 (65536/65536),
05110       or < 1 (65535 -> 2) as defined in unix profil()
05111       2/65536 is reserved for single bucket profiling
05112       {0,1}/65536 are traditionally used to terminate profiling
05113       but are unused here since PAPI uses threshold instead
05114     */
05115    for( i = 0; i < profcnt; i++ ) {
05116       if ( !( ( prof[i].pr_scale == 131072 ) ||
05117        ( ( prof[i].pr_scale <= 65536 && prof[i].pr_scale > 1 ) ) ) ) {
05118      APIDBG( "Improper scale factor: %d\n", prof[i].pr_scale );
05119      papi_return( PAPI_EINVAL );
05120       }
05121    }
05122 
05123    /* Make sure threshold is valid */
05124    if ( threshold < 0 ) {
05125       papi_return( PAPI_EINVAL );
05126    }
05127 
05128    /* the first time to call PAPI_sprofil */
05129    if ( !( ESI->state & PAPI_PROFILING ) ) {
05130       if ( threshold == 0 ) {
05131      papi_return( PAPI_EINVAL );
05132       }
05133    }
05134 
05135    /* ??? */
05136    if ( (threshold > 0) &&
05137     (ESI->profile.event_counter >= _papi_hwd[cidx]->cmp_info.num_cntrs) ) {
05138       papi_return( PAPI_ECNFLCT );
05139    }
05140 
05141    if ( threshold == 0 ) {
05142       for( i = 0; i < ESI->profile.event_counter; i++ ) {
05143      if ( ESI->profile.EventCode[i] == EventCode ) {
05144         break;
05145      }
05146       }
05147         
05148       /* EventCode not found */
05149       if ( i == ESI->profile.event_counter ) {
05150      papi_return( PAPI_EINVAL );
05151       }
05152 
05153       /* compact these arrays */
05154       while ( i < ESI->profile.event_counter - 1 ) {
05155          ESI->profile.prof[i] = ESI->profile.prof[i + 1];
05156      ESI->profile.count[i] = ESI->profile.count[i + 1];
05157      ESI->profile.threshold[i] = ESI->profile.threshold[i + 1];
05158      ESI->profile.EventIndex[i] = ESI->profile.EventIndex[i + 1];
05159      ESI->profile.EventCode[i] = ESI->profile.EventCode[i + 1];
05160      i++;
05161       }
05162       ESI->profile.prof[i] = NULL;
05163       ESI->profile.count[i] = 0;
05164       ESI->profile.threshold[i] = 0;
05165       ESI->profile.EventIndex[i] = 0;
05166       ESI->profile.EventCode[i] = 0;
05167       ESI->profile.event_counter--;
05168    } else {
05169       if ( ESI->profile.event_counter > 0 ) {
05170      if ( ( flags & PAPI_PROFIL_FORCE_SW ) &&
05171           !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
05172         papi_return( PAPI_ECNFLCT );
05173      }
05174      if ( !( flags & PAPI_PROFIL_FORCE_SW ) &&
05175           ( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
05176         papi_return( PAPI_ECNFLCT );
05177      }
05178       }
05179 
05180       for( i = 0; i < ESI->profile.event_counter; i++ ) {
05181      if ( ESI->profile.EventCode[i] == EventCode ) {
05182         break;
05183      }
05184       }
05185 
05186       if ( i == ESI->profile.event_counter ) {
05187      i = ESI->profile.event_counter;
05188      ESI->profile.event_counter++;
05189      ESI->profile.EventCode[i] = EventCode;
05190       }
05191       ESI->profile.prof[i] = prof;
05192       ESI->profile.count[i] = profcnt;
05193       ESI->profile.threshold[i] = threshold;
05194       ESI->profile.EventIndex[i] = index;
05195    }
05196 
05197    APIDBG( "Profile event counter is %d\n", ESI->profile.event_counter );
05198 
05199    /* Clear out old flags */
05200    if ( threshold == 0 ) {
05201       flags |= ESI->profile.flags;
05202    }
05203 
05204    /* make sure no invalid flags are set */
05205    if ( flags &
05206     ~( PAPI_PROFIL_POSIX | PAPI_PROFIL_RANDOM | PAPI_PROFIL_WEIGHTED |
05207        PAPI_PROFIL_COMPRESS | PAPI_PROFIL_BUCKETS | PAPI_PROFIL_FORCE_SW |
05208        PAPI_PROFIL_INST_EAR | PAPI_PROFIL_DATA_EAR ) ) {
05209       papi_return( PAPI_EINVAL );
05210    }
05211 
05212    /* if we have kernel-based profiling, then we're just asking for 
05213       signals on interrupt. */
05214    /* if we don't have kernel-based profiling, then we're asking for 
05215       emulated PMU interrupt */
05216    if ( ( flags & PAPI_PROFIL_FORCE_SW ) &&
05217     ( _papi_hwd[cidx]->cmp_info.kernel_profile == 0 ) ) {
05218       forceSW = PAPI_OVERFLOW_FORCE_SW;
05219    }
05220 
05221    /* make sure one and only one bucket size is set */
05222    buckets = flags & PAPI_PROFIL_BUCKETS;
05223    if ( !buckets ) {
05224       flags |= PAPI_PROFIL_BUCKET_16;   /* default to 16 bit if nothing set */
05225    }
05226    else {
05227       /* return error if more than one set */
05228       if ( !( ( buckets == PAPI_PROFIL_BUCKET_16 ) ||
05229           ( buckets == PAPI_PROFIL_BUCKET_32 ) ||
05230           ( buckets == PAPI_PROFIL_BUCKET_64 ) ) ) {
05231      papi_return( PAPI_EINVAL );
05232       }
05233    }
05234 
05235    /* Set up the option structure for the low level */
05236    ESI->profile.flags = flags;
05237 
05238    if ( _papi_hwd[cidx]->cmp_info.kernel_profile &&
05239     !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
05240       retval = _papi_hwd[cidx]->set_profile( ESI, index, threshold );
05241       if ( ( retval == PAPI_OK ) && ( threshold > 0 ) ) {
05242      /* We need overflowing because we use the overflow dispatch handler */
05243      ESI->state |= PAPI_OVERFLOWING;
05244      ESI->overflow.flags |= PAPI_OVERFLOW_HARDWARE;
05245       }
05246    } else {
05247       retval = PAPI_overflow( EventSet, EventCode, threshold, forceSW,
05248                   _papi_hwi_dummy_handler );
05249    }
05250     
05251    if ( retval < PAPI_OK ) {
05252       papi_return( retval );    /* We should undo stuff here */
05253    }
05254 
05255    /* Toggle the profiling flags and ESI state */
05256 
05257    if ( ESI->profile.event_counter >= 1 ) {
05258       ESI->state |= PAPI_PROFILING;
05259    }
05260    else {
05261       ESI->state ^= PAPI_PROFILING;
05262       ESI->profile.flags = 0;
05263    }
05264 
05265    return PAPI_OK;
05266 }

Here is the call graph for this function:

Here is the caller graph for this function:

int PAPI_start ( int  EventSet  ) 

start counting hardware events in an event set

Definition at line 2104 of file papi.c.

02105 {
02106     APIDBG("Entry: EventSet: %d\n", EventSet);
02107 
02108     int is_dirty=0;
02109     int i,retval;
02110     EventSetInfo_t *ESI;
02111     ThreadInfo_t *thread = NULL;
02112     CpuInfo_t *cpu = NULL;
02113     hwd_context_t *context;
02114     int cidx;
02115 
02116     ESI = _papi_hwi_lookup_EventSet( EventSet );
02117     if ( ESI == NULL ) {
02118        papi_return( PAPI_ENOEVST );
02119     }
02120 
02121     APIDBG("EventSet: %p\n", ESI);
02122 
02123     cidx = valid_ESI_component( ESI );
02124     if ( cidx < 0 ) {
02125        papi_return( cidx );
02126     }
02127 
02128     /* only one event set per thread  can be running at any time,    */
02129     /* so if another event set is running, the user must stop that   */
02130         /* event set explicitly */
02131 
02132     /* We used to check and not let multiple events be attached */
02133     /* to the same CPU, but this was unnecessary?               */
02134 
02135         thread = ESI->master;
02136     cpu = ESI->CpuInfo;
02137 
02138     if ( thread->running_eventset[cidx] ) {
02139            APIDBG("Thread Running already (Only one active Eventset per component)\n");
02140        papi_return( PAPI_EISRUN );
02141     }
02142 
02143     /* Check that there are added events */
02144     if ( ESI->NumberOfEvents < 1 ) {
02145        papi_return( PAPI_EINVAL );
02146     }
02147 
02148     /* If multiplexing is enabled for this eventset,
02149        call John May's code. */
02150 
02151     if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
02152        retval = MPX_start( ESI->multiplex.mpx_evset );
02153        if ( retval != PAPI_OK ) {
02154           papi_return( retval );
02155        }
02156 
02157        /* Update the state of this EventSet */
02158        ESI->state ^= PAPI_STOPPED;
02159        ESI->state |= PAPI_RUNNING;
02160 
02161        return PAPI_OK;
02162     }
02163 
02164     /* get the context we should use for this event set */
02165     context = _papi_hwi_get_context( ESI, &is_dirty );
02166     if (is_dirty) {
02167        /* we need to reset the context state because it was last used   */
02168        /* for some other event set and does not contain the information */
02169            /* for our events.                                               */
02170        retval = _papi_hwd[ESI->CmpIdx]->update_control_state(
02171                                                         ESI->ctl_state,
02172                             ESI->NativeInfoArray,
02173                             ESI->NativeCount,
02174                             context);
02175        if ( retval != PAPI_OK ) {
02176           papi_return( retval );
02177        }
02178 
02179        //update_control_state disturbs the overflow settings so set 
02180        //it to initial values again
02181        if ( ESI->overflow.flags & PAPI_OVERFLOW_HARDWARE ) {
02182             for( i = 0; i < ESI->overflow.event_counter; i++ ) {
02183                     retval = _papi_hwd[ESI->CmpIdx]->set_overflow( ESI,
02184                                                                        ESI->overflow.EventIndex[i],
02185                                                                        ESI->overflow.threshold[i] );
02186                        if ( retval != PAPI_OK ) {
02187                             break;
02188                     }
02189             }
02190           } 
02191 
02192        /* now that the context contains this event sets information,    */
02193        /* make sure the position array in the EventInfoArray is correct */
02194 
02195        /* We have to do this because ->update_control_state() can */
02196        /* in theory re-order the native events out from under us. */
02197        _papi_hwi_map_events_to_native( ESI );
02198 
02199     }
02200 
02201     /* If overflowing is enabled, turn it on */
02202     if ( ( ESI->state & PAPI_OVERFLOWING ) &&
02203          !( ESI->overflow.flags & PAPI_OVERFLOW_HARDWARE ) ) {
02204        retval = _papi_hwi_start_signal( _papi_os_info.itimer_sig,
02205                         NEED_CONTEXT, cidx );
02206        if ( retval != PAPI_OK ) {
02207           papi_return( retval );
02208        }
02209 
02210        /* Update the state of this EventSet and thread */
02211        /* before to avoid races                        */
02212        ESI->state ^= PAPI_STOPPED;
02213        ESI->state |= PAPI_RUNNING;
02214            /* can not be attached to thread or cpu if overflowing */
02215        thread->running_eventset[cidx] = ESI;
02216 
02217        retval = _papi_hwd[cidx]->start( context, ESI->ctl_state );
02218        if ( retval != PAPI_OK ) {
02219           _papi_hwi_stop_signal( _papi_os_info.itimer_sig );
02220           ESI->state ^= PAPI_RUNNING;
02221           ESI->state |= PAPI_STOPPED;
02222           thread->running_eventset[cidx] = NULL;
02223           papi_return( retval );
02224        }
02225 
02226        retval = _papi_hwi_start_timer( _papi_os_info.itimer_num,
02227                        _papi_os_info.itimer_sig,
02228                        _papi_os_info.itimer_ns );
02229        if ( retval != PAPI_OK ) {
02230           _papi_hwi_stop_signal( _papi_os_info.itimer_sig );
02231           _papi_hwd[cidx]->stop( context, ESI->ctl_state );
02232           ESI->state ^= PAPI_RUNNING;
02233           ESI->state |= PAPI_STOPPED;
02234           thread->running_eventset[cidx] = NULL;
02235           papi_return( retval );
02236        }
02237     } else {
02238        /* Update the state of this EventSet and thread before */
02239        /* to avoid races                                      */
02240        ESI->state ^= PAPI_STOPPED;
02241        ESI->state |= PAPI_RUNNING;
02242 
02243        /* if not attached to cpu or another process */
02244        if ( !(ESI->state & PAPI_CPU_ATTACHED) ) {
02245           if ( !( ESI->state & PAPI_ATTACHED ) ) {
02246          thread->running_eventset[cidx] = ESI;
02247           }
02248        } else {
02249           cpu->running_eventset[cidx] = ESI;
02250        }
02251 
02252        retval = _papi_hwd[cidx]->start( context, ESI->ctl_state );
02253        if ( retval != PAPI_OK ) {
02254           _papi_hwd[cidx]->stop( context, ESI->ctl_state );
02255           ESI->state ^= PAPI_RUNNING;
02256           ESI->state |= PAPI_STOPPED;
02257           if ( !(ESI->state & PAPI_CPU_ATTACHED) ) {
02258          if ( !( ESI->state & PAPI_ATTACHED ) ) 
02259             thread->running_eventset[cidx] = NULL;
02260           } else {
02261          cpu->running_eventset[cidx] = NULL;
02262           }
02263           papi_return( retval );
02264        }
02265     }
02266 
02267     return retval;
02268 }

Here is the call graph for this function: