PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
papi.c
Go to the documentation of this file.
1 /****************************/
2 /* THIS IS OPEN SOURCE CODE */
3 /****************************/
4 
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 
29 #include "papi.h"
30 #include "papi_internal.h"
31 #include "papi_vector.h"
32 #include "papi_memory.h"
33 
34 #include "papi_user_events.h"
35 
36 #include "cpus.h"
37 #include "extras.h"
38 #include "sw_multiplex.h"
39 #include "papi_hl.h"
40 
41 /*******************************/
42 /* BEGIN EXTERNAL DECLARATIONS */
43 /*******************************/
44 
45 
46 #ifdef DEBUG
47 #define papi_return(a) do { \
48  int b = a; \
49  if (b != PAPI_OK) {\
50  _papi_hwi_errno = b;\
51  } \
52  APIDBG("EXIT: return: %d\n", b);\
53  return((_papi_hwi_debug_handler ? _papi_hwi_debug_handler(b) : b)); \
54 } while (0)
55 #else
56 #define papi_return(a) do { \
57  int b = a; \
58  if (b != PAPI_OK) {\
59  _papi_hwi_errno = b;\
60  } \
61  APIDBG("EXIT: return: %d\n", b);\
62  return(b);\
63 } while(0)
64 #endif
65 
66 
67 /*
68 #ifdef DEBUG
69 #define papi_return(a) return((_papi_hwi_debug_handler ? _papi_hwi_debug_handler(a) : a))
70 #else
71 #define papi_return(a) return(a)
72 #endif
73 */
74 
75 #ifdef DEBUG
77 #endif
78 
79 
80 static int init_retval = DEADBEEF;
81 
82 inline_static int
84 {
85  if ( _papi_hwi_invalid_cmp( cidx ) )
86  return ( PAPI_ENOCMP );
87  return ( cidx );
88 }
89 
90 inline_static int
92 {
93  return ( valid_component( ESI->CmpIdx ) );
94 }
95 
119 int
120 PAPI_thread_init( unsigned long int ( *id_fn ) ( void ) )
121 {
122  /* Thread support not implemented on Alpha/OSF because the OSF pfm
123  * counter device driver does not support per-thread counters.
124  * When this is updated, we can remove this if statement
125  */
126  if ( init_level == PAPI_NOT_INITED )
128 
130  papi_return( PAPI_OK );
131 
134 }
135 
158 unsigned long
160 {
161  if ( _papi_hwi_thread_id_fn != NULL )
162  return ( ( *_papi_hwi_thread_id_fn ) ( ) );
163  else
164 #ifdef DEBUG
166  return ( unsigned long ) _papi_hwi_debug_handler( PAPI_EMISC );
167 #endif
168  return ( unsigned long ) PAPI_EMISC;
169 }
170 
171 /* Thread Functions */
172 
173 /*
174  * Notify PAPI that a thread has 'appeared'
175  * We lookup the thread, if it does not exist we create it
176  */
177 
204 int
206 {
208 
209  if ( init_level == PAPI_NOT_INITED )
212 }
213 
214 /*
215  * Notify PAPI that a thread has 'disappeared'
216  * We lookup the thread, if it does not exist we return an error
217  */
240 int
242 {
244 
245  if ( thread )
246  papi_return( _papi_hwi_shutdown_thread( thread, 0 ) );
247 
249 }
250 
282 int
283 PAPI_list_threads( PAPI_thread_id_t *tids, int *number )
284 {
286  int retval;
287 
288  /* If tids == NULL, then just count the threads, don't gather a list. */
289  /* If tids != NULL, then we need the length of the tids array in num. */
290 
291  if ( ( number == NULL ) || ( tids && ( *number <= 0 ) ) )
293 
294  memset( &tmp, 0x0, sizeof ( tmp ) );
295 
296  /* data == NULL, since we don't want the thread specific pointers. */
297  /* tids may be NULL, if the user doesn't want the thread IDs. */
298 
299  tmp.num = *number;
300  tmp.id = tids;
301  tmp.data = NULL;
302 
303  retval = _papi_hwi_gather_all_thrspec_data( 0, &tmp );
304  if ( retval == PAPI_OK )
305  *number = tmp.num;
306 
307  papi_return( retval );
308 }
309 
358 int
359 PAPI_get_thr_specific( int tag, void **ptr )
360 {
362  int doall = 0, retval = PAPI_OK;
363 
364  if ( init_level == PAPI_NOT_INITED )
366  if ( tag & PAPI_TLS_ALL_THREADS ) {
367  tag = tag ^ PAPI_TLS_ALL_THREADS;
368  doall = 1;
369  }
370  if ( ( tag < 0 ) || ( tag > PAPI_TLS_NUM ) )
372 
373  if ( doall )
375  ( tag, ( PAPI_all_thr_spec_t * ) ptr ) );
376 
378  if ( retval == PAPI_OK )
379  *ptr = thread->thread_storage[tag];
380  else
381  papi_return( retval );
382 
383  return ( PAPI_OK );
384 }
385 
434 int
435 PAPI_set_thr_specific( int tag, void *ptr )
436 {
438  int retval = PAPI_OK;
439 
440  if ( init_level == PAPI_NOT_INITED )
442  if ( ( tag < 0 ) || ( tag > PAPI_NUM_TLS ) )
444 
445  retval = _papi_hwi_lookup_or_create_thread( &thread, 0 );
446  if ( retval == PAPI_OK ) {
448  thread->thread_storage[tag] = ptr;
450  }
451  else
452  return ( retval );
453 
454  return ( PAPI_OK );
455 }
456 
457 
496 int
498 {
499  APIDBG( "Entry: version: %#x\n", version);
500  char *filename;
501  int tmp = 0, tmpel;
502 
503  /* This is a poor attempt at a lock.
504  For 3.1 this should be replaced with a
505  true UNIX semaphore. We cannot use PAPI
506  locks here because they are not initialized yet */
507  static int _in_papi_library_init_cnt = 0;
508 #ifdef DEBUG
509  char *var;
510 #endif
512 
513  if ( version != PAPI_VER_CURRENT )
515 
516  ++_in_papi_library_init_cnt;
517  while ( _in_papi_library_init_cnt > 1 ) {
518  PAPIERROR( "Multiple callers of PAPI_library_init" );
519  sleep( 1 );
520  }
521 
522  /* This checks to see if we have forked or called init more than once.
523  If we have forked, then we continue to init. If we have not forked,
524  we check to see the status of initialization. */
525 
526  APIDBG( "Initializing library: current PID %d, old PID %d\n",
527  getpid( ), _papi_hwi_system_info.pid );
528 
529  if ( _papi_hwi_system_info.pid == getpid( ) ) {
530  /* If the magic environment variable PAPI_ALLOW_STOLEN is set,
531  we call shutdown if PAPI has been initialized. This allows
532  tools that use LD_PRELOAD to run on applications that use PAPI.
533  In this circumstance, PAPI_ALLOW_STOLEN will be set to 'stolen'
534  so the tool can check for this case. */
535 
536  if ( getenv( "PAPI_ALLOW_STOLEN" ) ) {
537  char buf[PAPI_HUGE_STR_LEN];
538  if ( init_level != PAPI_NOT_INITED )
539  PAPI_shutdown( );
540  sprintf( buf, "%s=%s", "PAPI_ALLOW_STOLEN", "stolen" );
541  putenv( buf );
542  }
543 
544  /* If the library has been successfully initialized *OR*
545  the library attempted initialization but failed. */
546 
547  else if ( ( init_level != PAPI_NOT_INITED ) ||
548  ( init_retval != DEADBEEF ) ) {
549  _in_papi_library_init_cnt--;
550  if ( init_retval < PAPI_OK )
552  else
553  return ( init_retval );
554  }
555 
556  APIDBG( "system_info was initialized, but init did not succeed\n" );
557  }
558 #ifdef DEBUG
559  var = ( char * ) getenv( "PAPI_DEBUG" );
560  _papi_hwi_debug = 0;
561 
562  if ( var != NULL ) {
563  if ( strlen( var ) != 0 ) {
564  if ( strstr( var, "SUBSTRATE" ) )
566  if ( strstr( var, "API" ) )
568  if ( strstr( var, "INTERNAL" ) )
570  if ( strstr( var, "THREADS" ) )
572  if ( strstr( var, "MULTIPLEX" ) )
574  if ( strstr( var, "OVERFLOW" ) )
576  if ( strstr( var, "PROFILE" ) )
578  if ( strstr( var, "MEMORY" ) )
580  if ( strstr( var, "LEAK" ) )
582  if ( strstr( var, "ALL" ) )
584  }
585 
586  if ( _papi_hwi_debug == 0 )
588  }
589 #endif
590 
591  /* Be verbose for now */
592 
593  tmpel = _papi_hwi_error_level;
595 
596  /* Initialize internal globals */
598  _in_papi_library_init_cnt--;
599  _papi_hwi_error_level = tmpel;
601  }
602 
603  /* Initialize OS */
604  tmp = _papi_hwi_init_os();
605  if ( tmp ) {
606  init_retval = tmp;
608  _in_papi_library_init_cnt--;
609  _papi_hwi_error_level = tmpel;
611  }
612 
613  /* Initialize component globals */
614 
615  tmp = _papi_hwi_init_global( );
616  if ( tmp ) {
617  init_retval = tmp;
619  _in_papi_library_init_cnt--;
620  _papi_hwi_error_level = tmpel;
622  }
623 
624  /* Initialize thread globals, including the main threads */
625 
627  if ( tmp ) {
628  int i;
629  init_retval = tmp;
631  for ( i = 0; i < papi_num_components; i++ ) {
632  if (!_papi_hwd[i]->cmp_info.disabled) {
634  }
635  }
636  _in_papi_library_init_cnt--;
637  _papi_hwi_error_level = tmpel;
639  }
640 
642  _in_papi_library_init_cnt--;
643  _papi_hwi_error_level = tmpel;
644 
645 #ifdef STATIC_USER_EVENTS
647 #endif
648 
649  if ( (filename = getenv( "PAPI_USER_EVENTS_FILE" )) != NULL ) {
651  }
652 
653  return ( init_retval = PAPI_VER_CURRENT );
654 }
655 
697 int
698 PAPI_query_event( int EventCode )
699 {
700  APIDBG( "Entry: EventCode: %#x\n", EventCode);
701  if ( IS_PRESET(EventCode) ) {
702  EventCode &= PAPI_PRESET_AND_MASK;
703  if ( EventCode >= PAPI_MAX_PRESET_EVENTS )
705 
706  if ( _papi_hwi_presets[EventCode].count )
708  else
709  return PAPI_ENOEVNT;
710  }
711 
712  if ( IS_NATIVE(EventCode) ) {
714  ( ( unsigned int ) EventCode ) );
715  }
716 
717  if ( IS_USER_DEFINED(EventCode) ) {
718  EventCode &= PAPI_UE_AND_MASK;
719  if ( EventCode < 0 || EventCode > (int)_papi_user_events_count)
720  return ( PAPI_EINVAL );
721 
722  papi_return( PAPI_OK );
723  }
724 
726 }
727 
766 int
767 PAPI_query_named_event( char *EventName )
768 {
769  int ret, code;
770 
771  ret = PAPI_event_name_to_code( EventName, &code );
772  if ( ret == PAPI_OK ) ret = PAPI_query_event( code );
773  papi_return( ret);
774 }
775 
776 
806 const PAPI_component_info_t *
808 {
809  APIDBG( "Entry: Component Index %d\n", cidx);
810  if ( _papi_hwi_invalid_cmp( cidx ) )
811  return ( NULL );
812  else
813  return ( &( _papi_hwd[cidx]->cmp_info ) );
814 }
815 
816 /* PAPI_get_event_info:
817  tests input EventCode and returns a filled in PAPI_event_info_t
818  structure containing descriptive strings and values for the
819  specified event. Handles both preset and native events by
820  calling either _papi_hwi_get_event_info or
821  _papi_hwi_get_native_event_info.
822 */
845 int
846 PAPI_get_event_info( int EventCode, PAPI_event_info_t *info )
847 {
848  APIDBG( "Entry: EventCode: 0x%x, info: %p\n", EventCode, info);
849  int i;
850 
851  if ( info == NULL )
853 
854  if ( IS_PRESET(EventCode) ) {
855  i = EventCode & PAPI_PRESET_AND_MASK;
856  if ( i >= PAPI_MAX_PRESET_EVENTS )
858  papi_return( _papi_hwi_get_preset_event_info( EventCode, info ) );
859  }
860 
861  if ( IS_NATIVE(EventCode) ) {
863  ( ( unsigned int ) EventCode, info ) );
864  }
865 
866  if ( IS_USER_DEFINED(EventCode) ) {
867  papi_return( PAPI_OK );
868  }
870 }
871 
872 
925 int
926 PAPI_event_code_to_name( int EventCode, char *out )
927 {
928  APIDBG( "Entry: EventCode: %#x, out: %p\n", EventCode, out);
929  if ( out == NULL )
931 
932  if ( IS_PRESET(EventCode) ) {
933  EventCode &= PAPI_PRESET_AND_MASK;
934  if ( ( EventCode >= PAPI_MAX_PRESET_EVENTS )
935  || ( _papi_hwi_presets[EventCode].symbol == NULL ) )
937 
938  strncpy( out, _papi_hwi_presets[EventCode].symbol,
940  papi_return( PAPI_OK );
941  }
942 
943  if ( IS_NATIVE(EventCode) ) {
945  ( ( unsigned int ) EventCode, out, PAPI_MAX_STR_LEN ) );
946  }
947 
948  if ( IS_USER_DEFINED(EventCode) ) {
949  EventCode &= PAPI_UE_AND_MASK;
950 
951  if ( EventCode < 0 || EventCode > (int)_papi_user_events_count )
953 
954  strncpy( out, _papi_user_events[EventCode].symbol,
956  papi_return( PAPI_OK );
957  }
958 
960 }
961 
1009 int
1010 PAPI_event_name_to_code( char *in, int *out )
1011 {
1012  APIDBG("Entry: in: %p, name: %s, out: %p\n", in, in, out);
1013  int i;
1014 
1015  if ( ( in == NULL ) || ( out == NULL ) )
1017 
1018  if ( init_level == PAPI_NOT_INITED )
1020 
1021  /* All presets start with "PAPI_" so no need to */
1022  /* do an exhaustive search if that's not there */
1023  if (strncmp(in, "PAPI_", 5) == 0) {
1024  for(i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
1025  if ( ( _papi_hwi_presets[i].symbol )
1026  && ( strcasecmp( _papi_hwi_presets[i].symbol, in ) == 0) ) {
1027  *out = ( int ) ( i | PAPI_PRESET_MASK );
1028  papi_return( PAPI_OK );
1029  }
1030  }
1031  }
1032 
1033  for ( i=0; i < (int)_papi_user_events_count; i++ ) {
1034  if ( strcasecmp( _papi_user_events[i].symbol, in ) == 0 ) {
1035  *out = (int) ( i | PAPI_UE_MASK );
1036  papi_return( PAPI_OK );
1037  }
1038  }
1039 
1041 }
1042 
1043 /* Updates EventCode to next valid value, or returns error;
1044  modifier can specify {all / available} for presets, or other values for native tables
1045  and may be platform specific (Major groups / all mask bits; P / M / E chip, etc) */
1046 
1149 int
1150 PAPI_enum_event( int *EventCode, int modifier )
1151 {
1152  APIDBG( "Entry: EventCode: %#x, modifier: %d\n", *EventCode, modifier);
1153  int i = *EventCode;
1154  int retval;
1155  int cidx;
1156  int event_code;
1157  char *evt_name;
1158 
1159  cidx = _papi_hwi_component_index( *EventCode );
1160  if (cidx < 0) return PAPI_ENOCMP;
1161 
1162  /* Do we handle presets in componets other than CPU? */
1163  /* if (( IS_PRESET(i) ) && cidx > 0 )) return PAPI_ENOCMP; */
1164 
1165  if ( IS_PRESET(i) ) {
1166  if ( modifier == PAPI_ENUM_FIRST ) {
1167  *EventCode = ( int ) PAPI_PRESET_MASK;
1168  return ( PAPI_OK );
1169  }
1170  i &= PAPI_PRESET_AND_MASK;
1171  while ( ++i < PAPI_MAX_PRESET_EVENTS ) {
1172  if ( _papi_hwi_presets[i].symbol == NULL )
1173  return ( PAPI_ENOEVNT ); /* NULL pointer terminates list */
1174  if ( modifier & PAPI_PRESET_ENUM_AVAIL ) {
1175  if ( _papi_hwi_presets[i].count == 0 )
1176  continue;
1177  }
1178  *EventCode = ( int ) ( i | PAPI_PRESET_MASK );
1179  return ( PAPI_OK );
1180  }
1181  } else if ( IS_NATIVE(i) ) {
1182  // save event code so components can get it with call to: _papi_hwi_get_papi_event_code()
1183  _papi_hwi_set_papi_event_code(*EventCode, 0);
1184 
1185  /* Should check against num native events here */
1186 
1187  event_code=_papi_hwi_eventcode_to_native((int)*EventCode);
1188  retval = _papi_hwd[cidx]->ntv_enum_events((unsigned int *)&event_code, modifier );
1189 
1190  if (retval!=PAPI_OK) {
1191  APIDBG("VMW: retval=%d\n",retval);
1192  return PAPI_EINVAL;
1193  }
1194 
1195  evt_name = _papi_hwi_get_papi_event_string();
1196  *EventCode = _papi_hwi_native_to_eventcode(cidx, event_code, -1, evt_name);
1198 
1199  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1200  return retval;
1201  } else if ( IS_USER_DEFINED(i) ) {
1202  if ( modifier == PAPI_ENUM_FIRST ) {
1203  *EventCode = (int) 0x0;
1204  return ( PAPI_OK );
1205  }
1206 
1207  i &= PAPI_UE_AND_MASK;
1208  ++i;
1209 
1210  if ( (int)_papi_user_events_count <= i )
1211  *EventCode = i;
1212  return ( PAPI_OK );
1213  }
1214 
1216 }
1217 
1218 
1323 int
1324 PAPI_enum_cmp_event( int *EventCode, int modifier, int cidx )
1325 {
1326  APIDBG( "Entry: EventCode: %#x, modifier: %d, cidx: %d\n", *EventCode, modifier, cidx);
1327  int i = *EventCode;
1328  int retval;
1329  int event_code;
1330  char *evt_name;
1331 
1332  if ( _papi_hwi_invalid_cmp(cidx) || ( (IS_PRESET(i)) && cidx > 0 ) ) {
1333  return PAPI_ENOCMP;
1334  }
1335 
1336  if (_papi_hwd[cidx]->cmp_info.disabled) {
1337  return PAPI_ENOCMP;
1338  }
1339 
1340  if ( IS_PRESET(i) ) {
1341  if ( modifier == PAPI_ENUM_FIRST ) {
1342  *EventCode = ( int ) PAPI_PRESET_MASK;
1343  return PAPI_OK;
1344  }
1345  i &= PAPI_PRESET_AND_MASK;
1346  while ( ++i < PAPI_MAX_PRESET_EVENTS ) {
1347  if ( _papi_hwi_presets[i].symbol == NULL )
1348  return ( PAPI_ENOEVNT ); /* NULL pointer terminates list */
1349  if ( modifier & PAPI_PRESET_ENUM_AVAIL ) {
1350  if ( _papi_hwi_presets[i].count == 0 )
1351  continue;
1352  }
1353  *EventCode = ( int ) ( i | PAPI_PRESET_MASK );
1354  return PAPI_OK;
1355  }
1356  } else if ( IS_NATIVE(i) ) {
1357  // save event code so components can get it with call to: _papi_hwi_get_papi_event_code()
1358  _papi_hwi_set_papi_event_code(*EventCode, 0);
1359 
1360  /* Should we check against num native events here? */
1361  event_code=_papi_hwi_eventcode_to_native(*EventCode);
1362  retval = _papi_hwd[cidx]->ntv_enum_events((unsigned int *)&event_code, modifier );
1363 
1364  if (retval!=PAPI_OK) {
1365  APIDBG("VMW: retval=%d\n",retval);
1366  return PAPI_EINVAL;
1367  }
1368 
1369  evt_name = _papi_hwi_get_papi_event_string();
1370  *EventCode = _papi_hwi_native_to_eventcode(cidx, event_code, -1, evt_name);
1372 
1373  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1374  return retval;
1375  }
1376 
1378 }
1379 
1423 int
1425 {
1426  APIDBG("Entry: EventSet: %p\n", EventSet);
1427  ThreadInfo_t *master;
1428  int retval;
1429 
1430  if ( init_level == PAPI_NOT_INITED )
1432  retval = _papi_hwi_lookup_or_create_thread( &master, 0 );
1433  if ( retval )
1434  papi_return( retval );
1435 
1436  papi_return( _papi_hwi_create_eventset( EventSet, master ) );
1437 }
1438 
1484 int
1486 {
1487  EventSetInfo_t *ESI;
1488  int retval;
1489 
1490  ESI = _papi_hwi_lookup_EventSet( EventSet );
1491  if ( ESI == NULL )
1493 
1494 /* validate cidx */
1495  retval = valid_component( cidx );
1496  if ( retval < 0 )
1497  papi_return( retval );
1498 
1499 /* cowardly refuse to reassign eventsets */
1500  if ( ESI->CmpIdx >= 0 )
1501  return PAPI_EINVAL;
1502 
1503  return ( _papi_hwi_assign_eventset( ESI, cidx ) );
1504 }
1505 
1527 int
1529 {
1530  EventSetInfo_t *ESI;
1531  int retval;
1532 
1533 /* validate eventset */
1534  ESI = _papi_hwi_lookup_EventSet( EventSet );
1535  if ( ESI == NULL )
1537 
1538 /* check if a component has been assigned */
1539  if ( ESI->CmpIdx < 0 )
1541 
1542 /* validate CmpIdx */
1543  retval = valid_component( ESI->CmpIdx );
1544  if ( retval < 0 )
1545  papi_return( retval );
1546 
1547 /* return the index */
1548  return ( ESI->CmpIdx );
1549 }
1550 
1551 
1621 int
1622 PAPI_add_event( int EventSet, int EventCode )
1623 {
1624  APIDBG("Entry: EventSet: %d, EventCode: %#x\n", EventSet, EventCode);
1625  EventSetInfo_t *ESI;
1626 
1627  /* Is the EventSet already in existence? */
1628 
1629  ESI = _papi_hwi_lookup_EventSet( EventSet );
1630  if ( ESI == NULL )
1632 
1633  /* Check argument for validity */
1634 
1635  if ( ( ( EventCode & PAPI_PRESET_MASK ) == 0 ) &&
1636  ( EventCode & PAPI_NATIVE_MASK ) == 0 )
1638 
1639  /* Of course, it must be stopped in order to modify it. */
1640 
1641  if ( ESI->state & PAPI_RUNNING )
1643 
1644  /* Now do the magic. */
1645  int retval = _papi_hwi_add_event( ESI, EventCode );
1646  papi_return( retval );
1647 }
1648 
1716 int
1717 PAPI_remove_event( int EventSet, int EventCode )
1718 {
1719  APIDBG("Entry: EventSet: %d, EventCode: %#x\n", EventSet, EventCode);
1720  EventSetInfo_t *ESI;
1721  int i,retval;
1722 
1723  /* check for pre-existing ESI */
1724 
1725  ESI = _papi_hwi_lookup_EventSet( EventSet );
1726  if ( ESI == NULL )
1728 
1729  /* Check argument for validity */
1730 
1731  if ( ( !IS_PRESET(EventCode) ) &&
1732  ( !IS_NATIVE(EventCode) ) &&
1733  ( !IS_USER_DEFINED(EventCode) ))
1735 
1736  /* Of course, it must be stopped in order to modify it. */
1737 
1738  if ( !( ESI->state & PAPI_STOPPED ) )
1740 
1741  /* if the state is PAPI_OVERFLOWING, you must first call
1742  PAPI_overflow with threshold=0 to remove the overflow flag */
1743 
1744  /* Turn off the event that is overflowing */
1745  if ( ESI->state & PAPI_OVERFLOWING ) {
1746  for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
1747  if ( ESI->overflow.EventCode[i] == EventCode ) {
1748  retval = PAPI_overflow( EventSet, EventCode, 0, 0,
1749  ESI->overflow.handler );
1750  if (retval!=PAPI_OK) return retval;
1751  break;
1752  }
1753  }
1754  }
1755 
1756  /* force the user to call PAPI_profil to clear the PAPI_PROFILING flag */
1757  if ( ESI->state & PAPI_PROFILING ) {
1758  for ( i = 0; i < ESI->profile.event_counter; i++ ) {
1759  if ( ESI->profile.EventCode[i] == EventCode ) {
1760  PAPI_sprofil( NULL, 0, EventSet, EventCode, 0, 0 );
1761  break;
1762  }
1763  }
1764  }
1765 
1766  /* Now do the magic. */
1767 
1768  papi_return( _papi_hwi_remove_event( ESI, EventCode ) );
1769 }
1770 
1834 int
1835 PAPI_add_named_event( int EventSet, char *EventName )
1836 {
1837  APIDBG("Entry: EventSet: %d, EventName: %s\n", EventSet, EventName);
1838  int ret, code;
1839 
1840  ret = PAPI_event_name_to_code( EventName, &code );
1841  if ( ret != PAPI_OK ) {
1842  APIDBG("EXIT: return: %d\n", ret);
1843  return ret; // do not use papi_return here because if there was an error PAPI_event_name_to_code already reported it
1844  }
1845 
1846  ret = PAPI_add_event( EventSet, code );
1847  APIDBG("EXIT: return: %d\n", ret);
1848  return ret; // do not use papi_return here because if there was an error PAPI_add_event already reported it
1849 }
1850 
1918 int
1919 PAPI_remove_named_event( int EventSet, char *EventName )
1920 {
1921  APIDBG("Entry: EventSet: %d, EventName: %s\n", EventSet, EventName);
1922  int ret, code;
1923 
1924  ret = PAPI_event_name_to_code( EventName, &code );
1925  if ( ret == PAPI_OK ) ret = PAPI_remove_event( EventSet, code );
1926  papi_return( ret );
1927 }
1928 
1970 int
1972 {
1973  APIDBG("Entry: EventSet: %p, *EventSet: %d\n", EventSet, *EventSet);
1974 
1975  EventSetInfo_t *ESI;
1976 
1977  /* check for pre-existing ESI */
1978 
1979  if ( EventSet == NULL )
1981 
1982  ESI = _papi_hwi_lookup_EventSet( *EventSet );
1983  if ( ESI == NULL )
1985 
1986  if ( !( ESI->state & PAPI_STOPPED ) )
1988 
1989  if ( ESI->NumberOfEvents )
1991 
1993  *EventSet = PAPI_NULL;
1994 
1995  return PAPI_OK;
1996 }
1997 
1998 /* simply checks for valid EventSet, calls component start() call */
2052 int
2054 {
2055  APIDBG("Entry: EventSet: %d\n", EventSet);
2056 
2057  int is_dirty=0;
2058  int retval;
2059  EventSetInfo_t *ESI;
2060  ThreadInfo_t *thread = NULL;
2061  CpuInfo_t *cpu = NULL;
2062  hwd_context_t *context;
2063  int cidx;
2064 
2065  ESI = _papi_hwi_lookup_EventSet( EventSet );
2066  if ( ESI == NULL ) {
2068  }
2069 
2070  APIDBG("EventSet: %p\n", ESI);
2071 
2072  cidx = valid_ESI_component( ESI );
2073  if ( cidx < 0 ) {
2074  papi_return( cidx );
2075  }
2076 
2077  /* only one event set per thread can be running at any time, */
2078  /* so if another event set is running, the user must stop that */
2079  /* event set explicitly */
2080 
2081  /* We used to check and not let multiple events be attached */
2082  /* to the same CPU, but this was unnecessary? */
2083 
2084  thread = ESI->master;
2085  cpu = ESI->CpuInfo;
2086 
2087  if ( thread->running_eventset[cidx] ) {
2088  APIDBG("Thread Running already (Only one active Eventset per component)\n");
2090  }
2091 
2092  /* Check that there are added events */
2093  if ( ESI->NumberOfEvents < 1 ) {
2095  }
2096 
2097  /* If multiplexing is enabled for this eventset,
2098  call John May's code. */
2099 
2100  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2101  retval = MPX_start( ESI->multiplex.mpx_evset );
2102  if ( retval != PAPI_OK ) {
2103  papi_return( retval );
2104  }
2105 
2106  /* Update the state of this EventSet */
2107  ESI->state ^= PAPI_STOPPED;
2108  ESI->state |= PAPI_RUNNING;
2109 
2110  return PAPI_OK;
2111  }
2112 
2113  /* get the context we should use for this event set */
2114  context = _papi_hwi_get_context( ESI, &is_dirty );
2115  if (is_dirty) {
2116  /* we need to reset the context state because it was last used */
2117  /* for some other event set and does not contain the information */
2118  /* for our events. */
2119  retval = _papi_hwd[ESI->CmpIdx]->update_control_state(
2120  ESI->ctl_state,
2121  ESI->NativeInfoArray,
2122  ESI->NativeCount,
2123  context);
2124  if ( retval != PAPI_OK ) {
2125  papi_return( retval );
2126  }
2127 
2128  /* now that the context contains this event sets information, */
2129  /* make sure the position array in the EventInfoArray is correct */
2130 
2131  /* We have to do this because ->update_control_state() can */
2132  /* in theory re-order the native events out from under us. */
2134 
2135  }
2136 
2137  /* If overflowing is enabled, turn it on */
2138  if ( ( ESI->state & PAPI_OVERFLOWING ) &&
2139  !( ESI->overflow.flags & PAPI_OVERFLOW_HARDWARE ) ) {
2141  NEED_CONTEXT, cidx );
2142  if ( retval != PAPI_OK ) {
2143  papi_return( retval );
2144  }
2145 
2146  /* Update the state of this EventSet and thread */
2147  /* before to avoid races */
2148  ESI->state ^= PAPI_STOPPED;
2149  ESI->state |= PAPI_RUNNING;
2150  /* can not be attached to thread or cpu if overflowing */
2151  thread->running_eventset[cidx] = ESI;
2152 
2153  retval = _papi_hwd[cidx]->start( context, ESI->ctl_state );
2154  if ( retval != PAPI_OK ) {
2156  ESI->state ^= PAPI_RUNNING;
2157  ESI->state |= PAPI_STOPPED;
2158  thread->running_eventset[cidx] = NULL;
2159  papi_return( retval );
2160  }
2161 
2165  if ( retval != PAPI_OK ) {
2167  _papi_hwd[cidx]->stop( context, ESI->ctl_state );
2168  ESI->state ^= PAPI_RUNNING;
2169  ESI->state |= PAPI_STOPPED;
2170  thread->running_eventset[cidx] = NULL;
2171  papi_return( retval );
2172  }
2173  } else {
2174  /* Update the state of this EventSet and thread before */
2175  /* to avoid races */
2176  ESI->state ^= PAPI_STOPPED;
2177  ESI->state |= PAPI_RUNNING;
2178 
2179  /* if not attached to cpu or another process */
2180  if ( !(ESI->state & PAPI_CPU_ATTACHED) ) {
2181  if ( !( ESI->state & PAPI_ATTACHED ) ) {
2182  thread->running_eventset[cidx] = ESI;
2183  }
2184  } else {
2185  cpu->running_eventset[cidx] = ESI;
2186  }
2187 
2188  retval = _papi_hwd[cidx]->start( context, ESI->ctl_state );
2189  if ( retval != PAPI_OK ) {
2190  _papi_hwd[cidx]->stop( context, ESI->ctl_state );
2191  ESI->state ^= PAPI_RUNNING;
2192  ESI->state |= PAPI_STOPPED;
2193  if ( !(ESI->state & PAPI_CPU_ATTACHED) ) {
2194  if ( !( ESI->state & PAPI_ATTACHED ) )
2195  thread->running_eventset[cidx] = NULL;
2196  } else {
2197  cpu->running_eventset[cidx] = NULL;
2198  }
2199  papi_return( retval );
2200  }
2201  }
2202 
2203  return retval;
2204 }
2205 
2206 /* checks for valid EventSet, calls component stop() function. */
2257 int
2258 PAPI_stop( int EventSet, long long *values )
2259 {
2260  APIDBG("Entry: EventSet: %d, values: %p\n", EventSet, values);
2261  EventSetInfo_t *ESI;
2262  hwd_context_t *context;
2263  int cidx, retval;
2264 
2265  ESI = _papi_hwi_lookup_EventSet( EventSet );
2266  if ( ESI == NULL )
2268 
2269  cidx = valid_ESI_component( ESI );
2270  if ( cidx < 0 )
2271  papi_return( cidx );
2272 
2273  if ( !( ESI->state & PAPI_RUNNING ) )
2275 
2276  /* If multiplexing is enabled for this eventset, turn if off */
2277 
2278  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2279  retval = MPX_stop( ESI->multiplex.mpx_evset, values );
2280  if ( retval != PAPI_OK )
2281  papi_return( retval );
2282 
2283  /* Update the state of this EventSet */
2284 
2285  ESI->state ^= PAPI_RUNNING;
2286  ESI->state |= PAPI_STOPPED;
2287 
2288  return ( PAPI_OK );
2289  }
2290 
2291  /* get the context we should use for this event set */
2292  context = _papi_hwi_get_context( ESI, NULL );
2293  /* Read the current counter values into the EventSet */
2294  retval = _papi_hwi_read( context, ESI, ESI->sw_stop );
2295  if ( retval != PAPI_OK )
2296  papi_return( retval );
2297 
2298  /* Remove the control bits from the active counter config. */
2299  retval = _papi_hwd[cidx]->stop( context, ESI->ctl_state );
2300  if ( retval != PAPI_OK )
2301  papi_return( retval );
2302  if ( values )
2303  memcpy( values, ESI->sw_stop,
2304  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2305 
2306  /* If kernel profiling is in use, flush and process the kernel buffer */
2307 
2308  if ( ESI->state & PAPI_PROFILING ) {
2309  if ( _papi_hwd[cidx]->cmp_info.kernel_profile &&
2310  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
2311  retval = _papi_hwd[cidx]->stop_profiling( ESI->master, ESI );
2312  if ( retval < PAPI_OK )
2313  papi_return( retval );
2314  }
2315  }
2316 
2317  /* If overflowing is enabled, turn it off */
2318 
2319  if ( ESI->state & PAPI_OVERFLOWING ) {
2320  if ( !( ESI->overflow.flags & PAPI_OVERFLOW_HARDWARE ) ) {
2323  if ( retval != PAPI_OK )
2324  papi_return( retval );
2326  }
2327  }
2328 
2329  /* Update the state of this EventSet */
2330 
2331  ESI->state ^= PAPI_RUNNING;
2332  ESI->state |= PAPI_STOPPED;
2333 
2334  /* Update the running event set for this thread */
2335  if ( !(ESI->state & PAPI_CPU_ATTACHED) ) {
2336  if ( !( ESI->state & PAPI_ATTACHED ))
2337  ESI->master->running_eventset[cidx] = NULL;
2338  } else {
2339  ESI->CpuInfo->running_eventset[cidx] = NULL;
2340  }
2341 
2342 #if defined(DEBUG)
2343  if ( _papi_hwi_debug & DEBUG_API ) {
2344  int i;
2345  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2346  APIDBG( "PAPI_stop ESI->sw_stop[%d]:\t%llu\n", i, ESI->sw_stop[i] );
2347  }
2348  }
2349 #endif
2350 
2351  return ( PAPI_OK );
2352 }
2353 
2402 int
2404 {
2405  APIDBG("Entry: EventSet: %d\n", EventSet);
2406  int retval = PAPI_OK;
2407  EventSetInfo_t *ESI;
2408  hwd_context_t *context;
2409  int cidx;
2410 
2411  ESI = _papi_hwi_lookup_EventSet( EventSet );
2412  if ( ESI == NULL )
2414 
2415  cidx = valid_ESI_component( ESI );
2416  if ( cidx < 0 )
2417  papi_return( cidx );
2418 
2419  if ( ESI->state & PAPI_RUNNING ) {
2420  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2421  retval = MPX_reset( ESI->multiplex.mpx_evset );
2422  } else {
2423  /* If we're not the only one running, then just
2424  read the current values into the ESI->start
2425  array. This holds the starting value for counters
2426  that are shared. */
2427  /* get the context we should use for this event set */
2428  context = _papi_hwi_get_context( ESI, NULL );
2429  retval = _papi_hwd[cidx]->reset( context, ESI->ctl_state );
2430  }
2431  } else {
2432 #ifdef __bgp__
2433  // For BG/P, we always want to reset the 'real' hardware counters. The counters
2434  // can be controlled via multiple interfaces, and we need to ensure that the values
2435  // are truly zero...
2436  /* get the context we should use for this event set */
2437  context = _papi_hwi_get_context( ESI, NULL );
2438  retval = _papi_hwd[cidx]->reset( context, ESI->ctl_state );
2439 #endif
2440  memset( ESI->sw_stop, 0x00,
2441  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2442  }
2443 
2444  APIDBG( "EXIT: retval %d\n", retval );
2445  papi_return( retval );
2446 }
2447 
2502 int
2503 PAPI_read( int EventSet, long long *values )
2504 {
2505  APIDBG( "Entry: EventSet: %d, values: %p\n", EventSet, values);
2506  EventSetInfo_t *ESI;
2507  hwd_context_t *context;
2508  int cidx, retval = PAPI_OK;
2509 
2510  ESI = _papi_hwi_lookup_EventSet( EventSet );
2511  if ( ESI == NULL )
2513 
2514  cidx = valid_ESI_component( ESI );
2515  if ( cidx < 0 )
2516  papi_return( cidx );
2517 
2518  if ( values == NULL )
2520 
2521  if ( ESI->state & PAPI_RUNNING ) {
2522  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2523  retval = MPX_read( ESI->multiplex.mpx_evset, values, 0 );
2524  } else {
2525  /* get the context we should use for this event set */
2526  context = _papi_hwi_get_context( ESI, NULL );
2527  retval = _papi_hwi_read( context, ESI, values );
2528  }
2529  if ( retval != PAPI_OK )
2530  papi_return( retval );
2531  } else {
2532  memcpy( values, ESI->sw_stop,
2533  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2534  }
2535 
2536 #if defined(DEBUG)
2537  if ( ISLEVEL( DEBUG_API ) ) {
2538  int i;
2539  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2540  APIDBG( "PAPI_read values[%d]:\t%lld\n", i, values[i] );
2541  }
2542  }
2543 #endif
2544 
2545  APIDBG( "PAPI_read returns %d\n", retval );
2546  return ( PAPI_OK );
2547 }
2548 
2591 int
2592 PAPI_read_ts( int EventSet, long long *values, long long *cycles )
2593 {
2594  APIDBG( "Entry: EventSet: %d, values: %p, cycles: %p\n", EventSet, values, cycles);
2595  EventSetInfo_t *ESI;
2596  hwd_context_t *context;
2597  int cidx, retval = PAPI_OK;
2598 
2599  ESI = _papi_hwi_lookup_EventSet( EventSet );
2600  if ( ESI == NULL )
2602 
2603  cidx = valid_ESI_component( ESI );
2604  if ( cidx < 0 )
2605  papi_return( cidx );
2606 
2607  if ( values == NULL )
2609 
2610  if ( ESI->state & PAPI_RUNNING ) {
2611  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2612  retval = MPX_read( ESI->multiplex.mpx_evset, values, 0 );
2613  } else {
2614  /* get the context we should use for this event set */
2615  context = _papi_hwi_get_context( ESI, NULL );
2616  retval = _papi_hwi_read( context, ESI, values );
2617  }
2618  if ( retval != PAPI_OK )
2619  papi_return( retval );
2620  } else {
2621  memcpy( values, ESI->sw_stop,
2622  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2623  }
2624 
2625  *cycles = _papi_os_vector.get_real_cycles( );
2626 
2627 #if defined(DEBUG)
2628  if ( ISLEVEL( DEBUG_API ) ) {
2629  int i;
2630  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2631  APIDBG( "PAPI_read values[%d]:\t%lld\n", i, values[i] );
2632  }
2633  }
2634 #endif
2635 
2636  APIDBG( "PAPI_read_ts returns %d\n", retval );
2637  return PAPI_OK;
2638 }
2639 
2688 int
2689 PAPI_accum( int EventSet, long long *values )
2690 {
2691  APIDBG("Entry: EventSet: %d, values: %p\n", EventSet, values);
2692  EventSetInfo_t *ESI;
2693  hwd_context_t *context;
2694  int i, cidx, retval;
2695  long long a, b, c;
2696 
2697  ESI = _papi_hwi_lookup_EventSet( EventSet );
2698  if ( ESI == NULL )
2700 
2701  cidx = valid_ESI_component( ESI );
2702  if ( cidx < 0 )
2703  papi_return( cidx );
2704 
2705  if ( values == NULL )
2707 
2708  if ( ESI->state & PAPI_RUNNING ) {
2709  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2710  retval = MPX_read( ESI->multiplex.mpx_evset, ESI->sw_stop, 0 );
2711  } else {
2712  /* get the context we should use for this event set */
2713  context = _papi_hwi_get_context( ESI, NULL );
2714  retval = _papi_hwi_read( context, ESI, ESI->sw_stop );
2715  }
2716  if ( retval != PAPI_OK )
2717  papi_return( retval );
2718  }
2719 
2720  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2721  a = ESI->sw_stop[i];
2722  b = values[i];
2723  c = a + b;
2724  values[i] = c;
2725  }
2726 
2727  papi_return( PAPI_reset( EventSet ) );
2728 }
2729 
2756 int
2757 PAPI_write( int EventSet, long long *values )
2758 {
2759  APIDBG("Entry: EventSet: %d, values: %p\n", EventSet, values);
2760 
2761  int cidx, retval = PAPI_OK;
2762  EventSetInfo_t *ESI;
2763  hwd_context_t *context;
2764 
2765  ESI = _papi_hwi_lookup_EventSet( EventSet );
2766  if ( ESI == NULL )
2768 
2769  cidx = valid_ESI_component( ESI );
2770  if ( cidx < 0 )
2771  papi_return( cidx );
2772 
2773  if ( values == NULL )
2775 
2776  if ( ESI->state & PAPI_RUNNING ) {
2777  /* get the context we should use for this event set */
2778  context = _papi_hwi_get_context( ESI, NULL );
2779  retval = _papi_hwd[cidx]->write( context, ESI->ctl_state, values );
2780  if ( retval != PAPI_OK )
2781  return ( retval );
2782  }
2783 
2784  memcpy( ESI->hw_start, values,
2785  ( size_t ) _papi_hwd[cidx]->cmp_info.num_cntrs *
2786  sizeof ( long long ) );
2787 
2788  return ( retval );
2789 }
2790 
2833 int
2835 {
2836  APIDBG("Entry: EventSet: %d\n",EventSet);
2837 
2838  EventSetInfo_t *ESI;
2839  int i, cidx, total, retval;
2840 
2841  /* Is the EventSet already in existence? */
2842 
2843  ESI = _papi_hwi_lookup_EventSet( EventSet );
2844  if ( ESI == NULL )
2846 
2847  /* if the eventset has no index and no events, return OK
2848  otherwise return NOCMP */
2849  cidx = valid_ESI_component( ESI );
2850  if ( cidx < 0 ) {
2851  if ( ESI->NumberOfEvents )
2852  papi_return( cidx );
2853  papi_return( PAPI_OK );
2854  }
2855 
2856  /* Of course, it must be stopped in order to modify it. */
2857 
2858  if ( ESI->state & PAPI_RUNNING )
2860 
2861  /* clear overflow flag and turn off hardware overflow handler */
2862  if ( ESI->state & PAPI_OVERFLOWING ) {
2863  total = ESI->overflow.event_counter;
2864  for ( i = 0; i < total; i++ ) {
2865  retval = PAPI_overflow( EventSet,
2866  ESI->overflow.EventCode[0], 0, 0, NULL );
2867  if ( retval != PAPI_OK )
2868  papi_return( retval );
2869  }
2870  }
2871 
2872  /* clear profile flag and turn off hardware profile handler */
2873  if ( ( ESI->state & PAPI_PROFILING ) &&
2874  _papi_hwd[cidx]->cmp_info.hardware_intr &&
2875  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
2876  total = ESI->profile.event_counter;
2877  for ( i = 0; i < total; i++ ) {
2878  retval =
2879  PAPI_sprofil( NULL, 0, EventSet, ESI->profile.EventCode[0], 0,
2881  if ( retval != PAPI_OK )
2882  papi_return( retval );
2883  }
2884  }
2885 
2886  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2887  retval = MPX_cleanup( &ESI->multiplex.mpx_evset );
2888  if ( retval != PAPI_OK )
2889  papi_return( retval );
2890  }
2891 
2892  retval = _papi_hwd[cidx]->cleanup_eventset( ESI->ctl_state );
2893  if ( retval != PAPI_OK )
2894  papi_return( retval );
2895 
2896  /* Now do the magic */
2898 }
2899 
2925 int
2927 {
2928  APIDBG("Entry:\n");
2929 
2930  int retval;
2931 
2932  retval = mpx_init( _papi_os_info.itimer_ns );
2933  papi_return( retval );
2934 }
2935 
2996 int
2998 {
2999  APIDBG("Entry: EventSet: %d, status: %p\n", EventSet, status);
3000 
3001  EventSetInfo_t *ESI;
3002 
3003  if ( status == NULL )
3005 
3006  /* check for good EventSetIndex value */
3007 
3008  ESI = _papi_hwi_lookup_EventSet( EventSet );
3009  if ( ESI == NULL )
3011 
3012  /*read status FROM ESI->state */
3013 
3014  *status = ESI->state;
3015 
3016  return ( PAPI_OK );
3017 }
3018 
3069 int
3070 PAPI_set_debug( int level )
3071 {
3072  APIDBG("Entry: level: %d\n", level);
3073  PAPI_option_t option;
3074 
3075  memset( &option, 0x0, sizeof ( option ) );
3076  option.debug.level = level;
3078  return ( PAPI_set_opt( PAPI_DEBUG, &option ) );
3079 }
3080 
3081 /* Attaches to or detaches from the specified thread id */
3082 inline_static int
3083 _papi_set_attach( int option, int EventSet, unsigned long tid )
3084 {
3085  APIDBG("Entry: option: %d, EventSet: %d, tid: %lu\n", option, EventSet, tid);
3087 
3088  memset( &attach, 0x0, sizeof ( attach ) );
3089  attach.attach.eventset = EventSet;
3090  attach.attach.tid = tid;
3091  return ( PAPI_set_opt( option, &attach ) );
3092 }
3093 
3144 int
3145 PAPI_attach( int EventSet, unsigned long tid )
3146 {
3147  APIDBG( "Entry: EventSet: %d, tid: %lu\n", EventSet, tid);
3148  return ( _papi_set_attach( PAPI_ATTACH, EventSet, tid ) );
3149 }
3150 
3201 int
3203 {
3204  APIDBG( "Entry: EventSet: %d\n", EventSet);
3205  return ( _papi_set_attach( PAPI_DETACH, EventSet, 0 ) );
3206 }
3207 
3276 int
3278 {
3279  APIDBG( "Entry: EventSet: %d\n", EventSet);
3280 
3281  PAPI_option_t mpx;
3282  EventSetInfo_t *ESI;
3283  int cidx;
3284  int ret;
3285 
3286  /* Is the EventSet already in existence? */
3287 
3288  ESI = _papi_hwi_lookup_EventSet( EventSet );
3289 
3290  if ( ESI == NULL )
3292 
3293  /* if the eventset has no index return NOCMP */
3294  cidx = valid_ESI_component( ESI );
3295  if ( cidx < 0 )
3296  papi_return( cidx );
3297 
3298  if ( ( ret = mpx_check( EventSet ) ) != PAPI_OK )
3299  papi_return( ret );
3300 
3301  memset( &mpx, 0x0, sizeof ( mpx ) );
3302  mpx.multiplex.eventset = EventSet;
3305  return ( PAPI_set_opt( PAPI_MULTIPLEX, &mpx ) );
3306 }
3307 
3408 int
3410 {
3411  APIDBG("Entry: option: %d, ptr: %p\n", option, ptr);
3412 
3413  _papi_int_option_t internal;
3414  int retval = PAPI_OK;
3415  hwd_context_t *context;
3416  int cidx;
3417 
3418  if ( ( option != PAPI_DEBUG ) && ( init_level == PAPI_NOT_INITED ) )
3420  if ( ptr == NULL )
3422 
3423  memset( &internal, 0x0, sizeof ( _papi_int_option_t ) );
3424 
3425  switch ( option ) {
3426  case PAPI_DETACH:
3427  {
3428  internal.attach.ESI = _papi_hwi_lookup_EventSet( ptr->attach.eventset );
3429  if ( internal.attach.ESI == NULL )
3431 
3432  cidx = valid_ESI_component( internal.attach.ESI );
3433  if ( cidx < 0 )
3434  papi_return( cidx );
3435 
3436  if ( _papi_hwd[cidx]->cmp_info.attach == 0 )
3438 
3439  /* if attached to a cpu, return an error */
3440  if (internal.attach.ESI->state & PAPI_CPU_ATTACHED)
3442 
3443  if ( ( internal.attach.ESI->state & PAPI_STOPPED ) == 0 )
3445 
3446  if ( ( internal.attach.ESI->state & PAPI_ATTACHED ) == 0 )
3448 
3449  internal.attach.tid = internal.attach.ESI->attach.tid;
3450  /* get the context we should use for this event set */
3451  context = _papi_hwi_get_context( internal.attach.ESI, NULL );
3452  retval = _papi_hwd[cidx]->ctl( context, PAPI_DETACH, &internal );
3453  if ( retval != PAPI_OK )
3454  papi_return( retval );
3455 
3456  internal.attach.ESI->state ^= PAPI_ATTACHED;
3457  internal.attach.ESI->attach.tid = 0;
3458  return ( PAPI_OK );
3459  }
3460  case PAPI_ATTACH:
3461  {
3462  internal.attach.ESI = _papi_hwi_lookup_EventSet( ptr->attach.eventset );
3463  if ( internal.attach.ESI == NULL )
3465 
3466  cidx = valid_ESI_component( internal.attach.ESI );
3467  if ( cidx < 0 )
3468  papi_return( cidx );
3469 
3470  if ( _papi_hwd[cidx]->cmp_info.attach == 0 )
3472 
3473  if ( ( internal.attach.ESI->state & PAPI_STOPPED ) == 0 )
3475 
3476  if ( internal.attach.ESI->state & PAPI_ATTACHED )
3478 
3479  /* if attached to a cpu, return an error */
3480  if (internal.attach.ESI->state & PAPI_CPU_ATTACHED)
3482 
3483  internal.attach.tid = ptr->attach.tid;
3484  /* get the context we should use for this event set */
3485  context = _papi_hwi_get_context( internal.attach.ESI, NULL );
3486  retval = _papi_hwd[cidx]->ctl( context, PAPI_ATTACH, &internal );
3487  if ( retval != PAPI_OK )
3488  papi_return( retval );
3489 
3490  internal.attach.ESI->state |= PAPI_ATTACHED;
3491  internal.attach.ESI->attach.tid = ptr->attach.tid;
3492 
3494  &(internal.attach.ESI->master), ptr->attach.tid ));
3495  }
3496  case PAPI_CPU_ATTACH:
3497  {
3498  APIDBG("eventset: %d, cpu_num: %d\n", ptr->cpu.eventset, ptr->cpu.cpu_num);
3499  internal.cpu.ESI = _papi_hwi_lookup_EventSet( ptr->cpu.eventset );
3500  if ( internal.cpu.ESI == NULL )
3502 
3503  internal.cpu.cpu_num = ptr->cpu.cpu_num;
3504  APIDBG("internal: %p, ESI: %p, cpu_num: %d\n", &internal, internal.cpu.ESI, internal.cpu.cpu_num);
3505 
3506  cidx = valid_ESI_component( internal.cpu.ESI );
3507  if ( cidx < 0 )
3508  papi_return( cidx );
3509 
3510  if ( _papi_hwd[cidx]->cmp_info.cpu == 0 )
3512 
3513  // can not attach to a cpu if already attached to a process or
3514  // counters set to be inherited by child processes
3515  if ( internal.cpu.ESI->state & (PAPI_ATTACHED | PAPI_INHERIT) )
3517 
3518  if ( ( internal.cpu.ESI->state & PAPI_STOPPED ) == 0 )
3520 
3521  retval = _papi_hwi_lookup_or_create_cpu(&internal.cpu.ESI->CpuInfo, internal.cpu.cpu_num);
3522  if( retval != PAPI_OK) {
3523  papi_return( retval );
3524  }
3525 
3526  /* get the context we should use for this event set */
3527  context = _papi_hwi_get_context( internal.cpu.ESI, NULL );
3528  retval = _papi_hwd[cidx]->ctl( context, PAPI_CPU_ATTACH, &internal );
3529  if ( retval != PAPI_OK )
3530  papi_return( retval );
3531 
3532  /* set to show this event set is attached to a cpu not a thread */
3533  internal.cpu.ESI->state |= PAPI_CPU_ATTACHED;
3534  return ( PAPI_OK );
3535  }
3536  case PAPI_DEF_MPX_NS:
3537  {
3538  cidx = 0; /* xxxx for now, assume we only check against cpu component */
3539  if ( ptr->multiplex.ns < 0 )
3541  /* We should check the resolution here with the system, either
3542  component if kernel multiplexing or PAPI if SW multiplexing. */
3543  internal.multiplex.ns = ( unsigned long ) ptr->multiplex.ns;
3544  /* get the context we should use for this event set */
3545  context = _papi_hwi_get_context( internal.cpu.ESI, NULL );
3546  /* Low level just checks/adjusts the args for this component */
3547  retval = _papi_hwd[cidx]->ctl( context, PAPI_DEF_MPX_NS, &internal );
3548  if ( retval == PAPI_OK ) {
3549  _papi_os_info.itimer_ns = ( int ) internal.multiplex.ns;
3550  ptr->multiplex.ns = ( int ) internal.multiplex.ns;
3551  }
3552  papi_return( retval );
3553  }
3554  case PAPI_DEF_ITIMER_NS:
3555  {
3556  cidx = 0; /* xxxx for now, assume we only check against cpu component */
3557  if ( ptr->itimer.ns < 0 )
3559  internal.itimer.ns = ptr->itimer.ns;
3560  /* Low level just checks/adjusts the args for this component */
3561  retval = _papi_hwd[cidx]->ctl( NULL, PAPI_DEF_ITIMER_NS, &internal );
3562  if ( retval == PAPI_OK ) {
3563  _papi_os_info.itimer_ns = internal.itimer.ns;
3564  ptr->itimer.ns = internal.itimer.ns;
3565  }
3566  papi_return( retval );
3567  }
3568  case PAPI_DEF_ITIMER:
3569  {
3570  cidx = 0; /* xxxx for now, assume we only check against cpu component */
3571  if ( ptr->itimer.ns < 0 )
3573  memcpy( &internal.itimer, &ptr->itimer,
3575  /* Low level just checks/adjusts the args for this component */
3576  retval = _papi_hwd[cidx]->ctl( NULL, PAPI_DEF_ITIMER, &internal );
3577  if ( retval == PAPI_OK ) {
3580  if ( ptr->itimer.ns > 0 )
3582  /* flags are currently ignored, eventually the flags will be able
3583  to specify whether or not we use POSIX itimers (clock_gettimer) */
3584  }
3585  papi_return( retval );
3586  }
3587  case PAPI_MULTIPLEX:
3588  {
3589  EventSetInfo_t *ESI;
3591 
3592  if ( ESI == NULL )
3594 
3595  cidx = valid_ESI_component( ESI );
3596  if ( cidx < 0 )
3597  papi_return( cidx );
3598 
3599  if ( !( ESI->state & PAPI_STOPPED ) )
3601  if ( ESI->state & PAPI_MULTIPLEXING )
3603 
3604  if ( ptr->multiplex.ns < 0 )
3606  internal.multiplex.ESI = ESI;
3607  internal.multiplex.ns = ( unsigned long ) ptr->multiplex.ns;
3608  internal.multiplex.flags = ptr->multiplex.flags;
3609  if ( ( _papi_hwd[cidx]->cmp_info.kernel_multiplex ) &&
3610  ( ( ptr->multiplex.flags & PAPI_MULTIPLEX_FORCE_SW ) == 0 ) ) {
3611  /* get the context we should use for this event set */
3612  context = _papi_hwi_get_context( ESI, NULL );
3613  retval = _papi_hwd[cidx]->ctl( context, PAPI_MULTIPLEX, &internal );
3614  }
3615  /* Kernel or PAPI may have changed this value so send it back out to the user */
3616  ptr->multiplex.ns = ( int ) internal.multiplex.ns;
3617  if ( retval == PAPI_OK )
3619  ( &internal.multiplex ) );
3620  return ( retval );
3621  }
3622  case PAPI_DEBUG:
3623  {
3624  int level = ptr->debug.level;
3625  switch ( level ) {
3626  case PAPI_QUIET:
3627  case PAPI_VERB_ESTOP:
3628  case PAPI_VERB_ECONT:
3629  _papi_hwi_error_level = level;
3630  break;
3631  default:
3633  }
3635  return ( PAPI_OK );
3636  }
3637  case PAPI_DEFDOM:
3638  {
3639  int dom = ptr->defdomain.domain;
3640  if ( ( dom < PAPI_DOM_MIN ) || ( dom > PAPI_DOM_MAX ) )
3642 
3643  /* Change the global structure. The _papi_hwd_init_control_state function
3644  in the components gets information from the global structure instead of
3645  per-thread information. */
3646  cidx = valid_component( ptr->defdomain.def_cidx );
3647  if ( cidx < 0 )
3648  papi_return( cidx );
3649 
3650  /* Check what the component supports */
3651 
3652  if ( dom == PAPI_DOM_ALL )
3654 
3655  if ( dom & ~_papi_hwd[cidx]->cmp_info.available_domains )
3657 
3659 
3660  return ( PAPI_OK );
3661  }
3662  case PAPI_DOMAIN:
3663  {
3664  int dom = ptr->domain.domain;
3665  if ( ( dom < PAPI_DOM_MIN ) || ( dom > PAPI_DOM_MAX ) )
3667 
3668  internal.domain.ESI = _papi_hwi_lookup_EventSet( ptr->domain.eventset );
3669  if ( internal.domain.ESI == NULL )
3671 
3672  cidx = valid_ESI_component( internal.domain.ESI );
3673  if ( cidx < 0 )
3674  papi_return( cidx );
3675 
3676  /* Check what the component supports */
3677 
3678  if ( dom == PAPI_DOM_ALL )
3680 
3681  if ( dom & ~_papi_hwd[cidx]->cmp_info.available_domains )
3683 
3684  if ( !( internal.domain.ESI->state & PAPI_STOPPED ) )
3686 
3687  /* Try to change the domain of the eventset in the hardware */
3688  internal.domain.domain = dom;
3689  internal.domain.eventset = ptr->domain.eventset;
3690  /* get the context we should use for this event set */
3691  context = _papi_hwi_get_context( internal.domain.ESI, NULL );
3692  retval = _papi_hwd[cidx]->ctl( context, PAPI_DOMAIN, &internal );
3693  if ( retval < PAPI_OK )
3694  papi_return( retval );
3695 
3696  /* Change the domain of the eventset in the library */
3697 
3698  internal.domain.ESI->domain.domain = dom;
3699 
3700  return ( retval );
3701  }
3702  case PAPI_DEFGRN:
3703  {
3704  int grn = ptr->defgranularity.granularity;
3705  if ( ( grn < PAPI_GRN_MIN ) || ( grn > PAPI_GRN_MAX ) )
3707 
3708  cidx = valid_component( ptr->defgranularity.def_cidx );
3709  if ( cidx < 0 )
3710  papi_return( cidx );
3711 
3712  /* Change the component structure. The _papi_hwd_init_control_state function
3713  in the components gets information from the global structure instead of
3714  per-thread information. */
3715 
3716  /* Check what the component supports */
3717 
3718  if ( grn & ~_papi_hwd[cidx]->cmp_info.available_granularities )
3720 
3721  /* Make sure there is only 1 set. */
3722  if ( grn ^ ( 1 << ( ffs( grn ) - 1 ) ) )
3724 
3726 
3727  return ( PAPI_OK );
3728  }
3729  case PAPI_GRANUL:
3730  {
3731  int grn = ptr->granularity.granularity;
3732 
3733  if ( ( grn < PAPI_GRN_MIN ) || ( grn > PAPI_GRN_MAX ) )
3735 
3736  internal.granularity.ESI =
3738  if ( internal.granularity.ESI == NULL )
3740 
3741  cidx = valid_ESI_component( internal.granularity.ESI );
3742  if ( cidx < 0 )
3743  papi_return( cidx );
3744 
3745  /* Check what the component supports */
3746 
3747  if ( grn & ~_papi_hwd[cidx]->cmp_info.available_granularities )
3749 
3750  /* Make sure there is only 1 set. */
3751  if ( grn ^ ( 1 << ( ffs( grn ) - 1 ) ) )
3753 
3754  internal.granularity.granularity = grn;
3755  internal.granularity.eventset = ptr->granularity.eventset;
3756  retval = _papi_hwd[cidx]->ctl( NULL, PAPI_GRANUL, &internal );
3757  if ( retval < PAPI_OK )
3758  return ( retval );
3759 
3760  internal.granularity.ESI->granularity.granularity = grn;
3761  return ( retval );
3762  }
3763  case PAPI_INHERIT:
3764  {
3765  EventSetInfo_t *ESI;
3767  if ( ESI == NULL )
3769 
3770  cidx = valid_ESI_component( ESI );
3771  if ( cidx < 0 )
3772  papi_return( cidx );
3773 
3774  if ( _papi_hwd[cidx]->cmp_info.inherit == 0 )
3776 
3777  if ( ( ESI->state & PAPI_STOPPED ) == 0 )
3779 
3780  /* if attached to a cpu, return an error */
3781  if (ESI->state & PAPI_CPU_ATTACHED)
3783 
3784  internal.inherit.ESI = ESI;
3785  internal.inherit.inherit = ptr->inherit.inherit;
3786 
3787  /* get the context we should use for this event set */
3788  context = _papi_hwi_get_context( internal.inherit.ESI, NULL );
3789  retval = _papi_hwd[cidx]->ctl( context, PAPI_INHERIT, &internal );
3790  if ( retval < PAPI_OK )
3791  return ( retval );
3792 
3793  ESI->inherit.inherit = ptr->inherit.inherit;
3794  return ( retval );
3795  }
3796  case PAPI_DATA_ADDRESS:
3797  case PAPI_INSTR_ADDRESS:
3798  {
3799 
3800  EventSetInfo_t *ESI;
3801 
3802  ESI = _papi_hwi_lookup_EventSet( ptr->addr.eventset );
3803  if ( ESI == NULL )
3805 
3806  cidx = valid_ESI_component( ESI );
3807  if ( cidx < 0 )
3808  papi_return( cidx );
3809 
3810  internal.address_range.ESI = ESI;
3811 
3812  if ( !( internal.address_range.ESI->state & PAPI_STOPPED ) )
3814 
3815  /*set domain to be PAPI_DOM_USER */
3816  internal.address_range.domain = PAPI_DOM_USER;
3817 
3818  internal.address_range.start = ptr->addr.start;
3819  internal.address_range.end = ptr->addr.end;
3820  /* get the context we should use for this event set */
3821  context = _papi_hwi_get_context( internal.address_range.ESI, NULL );
3822  retval = _papi_hwd[cidx]->ctl( context, option, &internal );
3823  ptr->addr.start_off = internal.address_range.start_off;
3824  ptr->addr.end_off = internal.address_range.end_off;
3825  papi_return( retval );
3826  }
3827  case PAPI_USER_EVENTS_FILE:
3828  {
3829  APIDBG("Filename is -%s-\n", ptr->events_file);
3831  return( PAPI_OK );
3832  }
3833  default:
3835  }
3836 }
3837 
3847 int
3849 {
3850  APIDBG( "Entry:\n");
3851  return ( PAPI_num_cmp_hwctrs( 0 ) );
3852 }
3853 
3903 int
3905 {
3906  APIDBG( "Entry: cidx: %d\n", cidx);
3907  return ( PAPI_get_cmp_opt( PAPI_MAX_HWCTRS, NULL, cidx ) );
3908 }
3909 
3966 int
3968 {
3969  APIDBG( "Entry: EventSet: %d\n", EventSet);
3970  PAPI_option_t popt;
3971  int retval;
3972 
3973  popt.multiplex.eventset = EventSet;
3974  retval = PAPI_get_opt( PAPI_MULTIPLEX, &popt );
3975  if ( retval < 0 )
3976  retval = 0;
3977  return retval;
3978 }
3979 
4081 int
4083 {
4084  APIDBG( "Entry: option: %d, ptr: %p\n", option, ptr);
4085  EventSetInfo_t *ESI;
4086 
4087  if ( ( option != PAPI_DEBUG ) && ( init_level == PAPI_NOT_INITED ) )
4089 
4090  switch ( option ) {
4091  case PAPI_DETACH:
4092  {
4093  if ( ptr == NULL )
4096  if ( ESI == NULL )
4098  ptr->attach.tid = ESI->attach.tid;
4099  return ( ( ESI->state & PAPI_ATTACHED ) == 0 );
4100  }
4101  case PAPI_ATTACH:
4102  {
4103  if ( ptr == NULL )
4106  if ( ESI == NULL )
4108  ptr->attach.tid = ESI->attach.tid;
4109  return ( ( ESI->state & PAPI_ATTACHED ) != 0 );
4110  }
4111  case PAPI_CPU_ATTACH:
4112  {
4113  if ( ptr == NULL )
4116  if ( ESI == NULL )
4118  ptr->cpu.cpu_num = ESI->CpuInfo->cpu_num;
4119  return ( ( ESI->state & PAPI_CPU_ATTACHED ) != 0 );
4120  }
4121  case PAPI_DEF_MPX_NS:
4122  {
4123  /* xxxx for now, assume we only check against cpu component */
4124  if ( ptr == NULL )
4127  return ( PAPI_OK );
4128  }
4129  case PAPI_DEF_ITIMER_NS:
4130  {
4131  /* xxxx for now, assume we only check against cpu component */
4132  if ( ptr == NULL )
4135  return ( PAPI_OK );
4136  }
4137  case PAPI_DEF_ITIMER:
4138  {
4139  /* xxxx for now, assume we only check against cpu component */
4140  if ( ptr == NULL )
4145  ptr->itimer.flags = 0;
4146  return ( PAPI_OK );
4147  }
4148  case PAPI_MULTIPLEX:
4149  {
4150  if ( ptr == NULL )
4153  if ( ESI == NULL )
4155  ptr->multiplex.ns = ESI->multiplex.ns;
4156  ptr->multiplex.flags = ESI->multiplex.flags;
4157  return ( ESI->state & PAPI_MULTIPLEXING ) != 0;
4158  }
4159  case PAPI_PRELOAD:
4160  if ( ptr == NULL )
4162  memcpy( &ptr->preload, &_papi_hwi_system_info.preload_info,
4164  break;
4165  case PAPI_DEBUG:
4166  if ( ptr == NULL )
4170  break;
4171  case PAPI_CLOCKRATE:
4172  return ( ( int ) _papi_hwi_system_info.hw_info.cpu_max_mhz );
4173  case PAPI_MAX_CPUS:
4174  return ( _papi_hwi_system_info.hw_info.ncpu );
4175  /* For now, MAX_HWCTRS and MAX CTRS are identical.
4176  At some future point, they may map onto different values.
4177  */
4178  case PAPI_INHERIT:
4179  {
4180  if ( ptr == NULL )
4183  if ( ESI == NULL )
4185  ptr->inherit.inherit = ESI->inherit.inherit;
4186  return ( PAPI_OK );
4187  }
4188  case PAPI_GRANUL:
4189  if ( ptr == NULL )
4192  if ( ESI == NULL )
4195  break;
4196  case PAPI_EXEINFO:
4197  if ( ptr == NULL )
4200  break;
4201  case PAPI_HWINFO:
4202  if ( ptr == NULL )
4205  break;
4206 
4207  case PAPI_DOMAIN:
4208  if ( ptr == NULL )
4211  if ( ESI == NULL )
4213  ptr->domain.domain = ESI->domain.domain;
4214  return ( PAPI_OK );
4215  case PAPI_LIB_VERSION:
4216  return ( PAPI_VERSION );
4217 /* The following cases all require a component index
4218  and are handled by PAPI_get_cmp_opt() with cidx == 0*/
4219  case PAPI_MAX_HWCTRS:
4220  case PAPI_MAX_MPX_CTRS:
4221  case PAPI_DEFDOM:
4222  case PAPI_DEFGRN:
4223  case PAPI_SHLIBINFO:
4224  case PAPI_COMPONENTINFO:
4225  return ( PAPI_get_cmp_opt( option, ptr, 0 ) );
4226  default:
4228  }
4229  return ( PAPI_OK );
4230 }
4231 
4273 int
4275 {
4276  APIDBG( "Entry: option: %d, ptr: %p, cidx: %d\n", option, ptr, cidx);
4277 
4278  if (_papi_hwi_invalid_cmp(cidx)) {
4279  return PAPI_ECMP;
4280  }
4281 
4282  switch ( option ) {
4283  /* For now, MAX_HWCTRS and MAX CTRS are identical.
4284  At some future point, they may map onto different values.
4285  */
4286  case PAPI_MAX_HWCTRS:
4287  return ( _papi_hwd[cidx]->cmp_info.num_cntrs );
4288  case PAPI_MAX_MPX_CTRS:
4289  return ( _papi_hwd[cidx]->cmp_info.num_mpx_cntrs );
4290  case PAPI_DEFDOM:
4291  return ( _papi_hwd[cidx]->cmp_info.default_domain );
4292  case PAPI_DEFGRN:
4293  return ( _papi_hwd[cidx]->cmp_info.default_granularity );
4294  case PAPI_SHLIBINFO:
4295  {
4296  int retval;
4297  if ( ptr == NULL )
4301  papi_return( retval );
4302  }
4303  case PAPI_COMPONENTINFO:
4304  if ( ptr == NULL )
4306  ptr->cmp_info = &( _papi_hwd[cidx]->cmp_info );
4307  return PAPI_OK;
4308  default:
4310  }
4311  return PAPI_OK;
4312 }
4313 
4325 int
4327 {
4328  APIDBG( "Entry:\n");
4329  return ( papi_num_components );
4330 }
4331 
4364 int
4366 {
4367  APIDBG( "Entry: EventSet: %d\n", EventSet);
4368  EventSetInfo_t *ESI;
4369 
4370  ESI = _papi_hwi_lookup_EventSet( EventSet );
4371  if ( !ESI )
4373 
4374 #ifdef DEBUG
4375  /* Not necessary */
4376  if ( ESI->NumberOfEvents == 0 )
4378 #endif
4379 
4380  return ( ESI->NumberOfEvents );
4381 }
4382 
4383 
4399 void
4401 {
4402  APIDBG( "Entry:\n");
4403 
4404  EventSetInfo_t *ESI;
4405  ThreadInfo_t *master;
4407  int i, j = 0, retval;
4408 
4409 
4410  if ( init_retval == DEADBEEF ) {
4412  return;
4413  }
4414 
4415  MPX_shutdown( );
4416 
4417  /* Free all EventSets for this thread */
4418 
4419  master = _papi_hwi_lookup_thread( 0 );
4420 
4421  /* Count number of running EventSets AND */
4422  /* Stop any running EventSets in this thread */
4423 
4424 #ifdef DEBUG
4425 again:
4426 #endif
4427  for( i = 0; i < map->totalSlots; i++ ) {
4428  ESI = map->dataSlotArray[i];
4429  if ( ESI ) {
4430  if ( ESI->master == master ) {
4431  if ( ESI->state & PAPI_RUNNING ) {
4432  if((retval = PAPI_stop( i, NULL )) != PAPI_OK) {
4433  APIDBG("Call to PAPI_stop failed: %d\n", retval);
4434  }
4435  }
4437  if (retval!=PAPI_OK) PAPIERROR("Error during cleanup.");
4438  _papi_hwi_free_EventSet( ESI );
4439  }
4440  else {
4441  if ( ESI->state & PAPI_RUNNING ) {
4442  j++;
4443  }
4444  }
4445  }
4446  }
4447 
4448  /* No locking required, we're just waiting for the others
4449  to call shutdown or stop their eventsets. */
4450 
4451 #ifdef DEBUG
4452  if ( j != 0 ) {
4454  sleep( 1 );
4455  j = 0;
4456  goto again;
4457  }
4458 #endif
4459 
4460  /* Shutdown the entire component */
4461 
4463 
4467  for( i = 0; i < papi_num_components; i++ ) {
4468  if (!_papi_hwd[i]->cmp_info.disabled) {
4470  }
4471  }
4472 
4473  /* Now it is safe to call re-init */
4474 
4478 }
4479 
4528 char *
4529 PAPI_strerror( int errorCode )
4530 {
4531  if ( ( errorCode > 0 ) || ( -errorCode > _papi_hwi_num_errors ) )
4532  return ( NULL );
4533 
4534  return ( _papi_errlist[-errorCode] );
4535 }
4536 
4578 void
4579 PAPI_perror( char *msg )
4580 {
4581  char *foo;
4582 
4583  foo = PAPI_strerror( _papi_hwi_errno );
4584  if ( foo == NULL )
4585  return;
4586 
4587  if ( msg )
4588  if ( *msg )
4589  fprintf( stderr, "%s: ", msg );
4590 
4591  fprintf( stderr, "%s\n", foo );
4592 }
4593 
4713 int
4714 PAPI_overflow( int EventSet, int EventCode, int threshold, int flags,
4716 {
4717  APIDBG( "Entry: EventSet: %d, EventCode: %#x, threshold: %d, flags: %#x, handler: %p\n", EventSet, EventCode, threshold, flags, handler);
4718  int retval, cidx, index, i;
4719  EventSetInfo_t *ESI;
4720 
4721  ESI = _papi_hwi_lookup_EventSet( EventSet );
4722  if ( ESI == NULL ) {
4723  OVFDBG("No EventSet\n");
4725  }
4726 
4727  cidx = valid_ESI_component( ESI );
4728  if ( cidx < 0 ) {
4729  OVFDBG("Component Error\n");
4730  papi_return( cidx );
4731  }
4732 
4733  if ( ( ESI->state & PAPI_STOPPED ) != PAPI_STOPPED ) {
4734  OVFDBG("Already running\n");
4736  }
4737 
4738  if ( ESI->state & PAPI_ATTACHED ) {
4739  OVFDBG("Attached\n");
4741  }
4742 
4743  if ( ESI->state & PAPI_CPU_ATTACHED ) {
4744  OVFDBG("CPU attached\n");
4746  }
4747 
4748  if ( ( index = _papi_hwi_lookup_EventCodeIndex( ESI,
4749  ( unsigned int ) EventCode ) ) < 0 ) {
4751  }
4752 
4753  if ( threshold < 0 ) {
4754  OVFDBG("Threshold below zero\n");
4756  }
4757 
4758  /* We do not support derived events in overflow */
4759  /* Unless it's DERIVED_CMPD in which no calculations are done */
4760 
4761  if ( !( flags & PAPI_OVERFLOW_FORCE_SW ) && threshold != 0 &&
4762  ( ESI->EventInfoArray[index].derived ) &&
4763  ( ESI->EventInfoArray[index].derived != DERIVED_CMPD ) ) {
4764  OVFDBG("Derived event in overflow\n");
4766  }
4767 
4768  /* the first time to call PAPI_overflow function */
4769 
4770  if ( !( ESI->state & PAPI_OVERFLOWING ) ) {
4771  if ( handler == NULL ) {
4772  OVFDBG("NULL handler\n");
4774  }
4775  if ( threshold == 0 ) {
4776  OVFDBG("Zero threshold\n");
4778  }
4779  }
4780  if ( threshold > 0 &&
4783 
4784  if ( threshold == 0 ) {
4785  for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
4786  if ( ESI->overflow.EventCode[i] == EventCode )
4787  break;
4788  }
4789  /* EventCode not found */
4790  if ( i == ESI->overflow.event_counter )
4792  /* compact these arrays */
4793  while ( i < ESI->overflow.event_counter - 1 ) {
4794  ESI->overflow.deadline[i] = ESI->overflow.deadline[i + 1];
4795  ESI->overflow.threshold[i] = ESI->overflow.threshold[i + 1];
4796  ESI->overflow.EventIndex[i] = ESI->overflow.EventIndex[i + 1];
4797  ESI->overflow.EventCode[i] = ESI->overflow.EventCode[i + 1];
4798  i++;
4799  }
4800  ESI->overflow.deadline[i] = 0;
4801  ESI->overflow.threshold[i] = 0;
4802  ESI->overflow.EventIndex[i] = 0;
4803  ESI->overflow.EventCode[i] = 0;
4804  ESI->overflow.event_counter--;
4805  } else {
4806  if ( ESI->overflow.event_counter > 0 ) {
4807  if ( ( flags & PAPI_OVERFLOW_FORCE_SW ) &&
4810  if ( !( flags & PAPI_OVERFLOW_FORCE_SW ) &&
4811  ( ESI->overflow.flags & PAPI_OVERFLOW_FORCE_SW ) )
4813  }
4814  for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
4815  if ( ESI->overflow.EventCode[i] == EventCode )
4816  break;
4817  }
4818  /* A new entry */
4819  if ( i == ESI->overflow.event_counter ) {
4820  ESI->overflow.EventCode[i] = EventCode;
4821  ESI->overflow.event_counter++;
4822  }
4823  /* New or existing entry */
4824  ESI->overflow.deadline[i] = threshold;
4825  ESI->overflow.threshold[i] = threshold;
4826  ESI->overflow.EventIndex[i] = index;
4827  ESI->overflow.flags = flags;
4828 
4829  }
4830 
4831  /* If overflowing is already active, we should check to
4832  make sure that we don't specify a different handler
4833  or different flags here. You can't mix them. */
4834 
4835  ESI->overflow.handler = handler;
4836 
4837  /* Set up the option structure for the low level.
4838  If we have hardware interrupts and we are not using
4839  forced software emulated interrupts */
4840 
4841  if ( _papi_hwd[cidx]->cmp_info.hardware_intr &&
4842  !( ESI->overflow.flags & PAPI_OVERFLOW_FORCE_SW ) ) {
4843  retval = _papi_hwd[cidx]->set_overflow( ESI, index, threshold );
4844  if ( retval == PAPI_OK )
4846  else {
4847  papi_return( retval ); /* We should undo stuff here */
4848  }
4849  } else {
4850  /* Make sure hardware overflow is not set */
4851  ESI->overflow.flags &= ~( PAPI_OVERFLOW_HARDWARE );
4852  }
4853 
4854  APIDBG( "Overflow using: %s\n",
4855  ( ESI->overflow.
4856  flags & PAPI_OVERFLOW_HARDWARE ? "[Hardware]" : ESI->overflow.
4857  flags & PAPI_OVERFLOW_FORCE_SW ? "[Forced Software]" :
4858  "[Software]" ) );
4859 
4860  /* Toggle the overflow flags and ESI state */
4861 
4862  if ( ESI->overflow.event_counter >= 1 )
4863  ESI->state |= PAPI_OVERFLOWING;
4864  else {
4865  ESI->state ^= PAPI_OVERFLOWING;
4866  ESI->overflow.flags = 0;
4867  ESI->overflow.handler = NULL;
4868  }
4869 
4870  return PAPI_OK;
4871 }
4872 
4969 int
4970 PAPI_sprofil( PAPI_sprofil_t *prof, int profcnt, int EventSet,
4971  int EventCode, int threshold, int flags )
4972 {
4973  APIDBG( "Entry: prof: %p, profcnt: %d, EventSet: %d, EventCode: %#x, threshold: %d, flags: %#x\n", prof, profcnt, EventSet, EventCode, threshold, flags);
4974  EventSetInfo_t *ESI;
4975  int retval, index, i, buckets;
4976  int forceSW = 0;
4977  int cidx;
4978 
4979  /* Check to make sure EventSet exists */
4980  ESI = _papi_hwi_lookup_EventSet( EventSet );
4981  if ( ESI == NULL ) {
4983  }
4984 
4985  /* Check to make sure EventSet is stopped */
4986  if ( ( ESI->state & PAPI_STOPPED ) != PAPI_STOPPED ) {
4988  }
4989 
4990  /* We cannot profile if attached */
4991  if ( ESI->state & PAPI_ATTACHED ) {
4993  }
4994 
4995  /* We cannot profile if cpu attached */
4996  if ( ESI->state & PAPI_CPU_ATTACHED ) {
4998  }
4999 
5000  /* Get component for EventSet */
5001  cidx = valid_ESI_component( ESI );
5002  if ( cidx < 0 ) {
5003  papi_return( cidx );
5004  }
5005 
5006  /* Get index of the Event we want to profile */
5007  if ( ( index = _papi_hwi_lookup_EventCodeIndex( ESI,
5008  (unsigned int) EventCode ) ) < 0 ) {
5010  }
5011 
5012  /* We do not support derived events in overflow */
5013  /* Unless it's DERIVED_CMPD in which no calculations are done */
5014  if ( ( ESI->EventInfoArray[index].derived ) &&
5015  ( ESI->EventInfoArray[index].derived != DERIVED_CMPD ) &&
5016  !( flags & PAPI_PROFIL_FORCE_SW ) ) {
5018  }
5019 
5020  /* If no prof structures, then make sure count is 0 */
5021  if ( prof == NULL ) {
5022  profcnt = 0;
5023  }
5024 
5025  /* check all profile regions for valid scale factors of:
5026  2 (131072/65536),
5027  1 (65536/65536),
5028  or < 1 (65535 -> 2) as defined in unix profil()
5029  2/65536 is reserved for single bucket profiling
5030  {0,1}/65536 are traditionally used to terminate profiling
5031  but are unused here since PAPI uses threshold instead
5032  */
5033  for( i = 0; i < profcnt; i++ ) {
5034  if ( !( ( prof[i].pr_scale == 131072 ) ||
5035  ( ( prof[i].pr_scale <= 65536 && prof[i].pr_scale > 1 ) ) ) ) {
5036  APIDBG( "Improper scale factor: %d\n", prof[i].pr_scale );
5038  }
5039  }
5040 
5041  /* Make sure threshold is valid */
5042  if ( threshold < 0 ) {
5044  }
5045 
5046  /* the first time to call PAPI_sprofil */
5047  if ( !( ESI->state & PAPI_PROFILING ) ) {
5048  if ( threshold == 0 ) {
5050  }
5051  }
5052 
5053  /* ??? */
5054  if ( (threshold > 0) &&
5055  (ESI->profile.event_counter >= _papi_hwd[cidx]->cmp_info.num_cntrs) ) {
5057  }
5058 
5059  if ( threshold == 0 ) {
5060  for( i = 0; i < ESI->profile.event_counter; i++ ) {
5061  if ( ESI->profile.EventCode[i] == EventCode ) {
5062  break;
5063  }
5064  }
5065 
5066  /* EventCode not found */
5067  if ( i == ESI->profile.event_counter ) {
5069  }
5070 
5071  /* compact these arrays */
5072  while ( i < ESI->profile.event_counter - 1 ) {
5073  ESI->profile.prof[i] = ESI->profile.prof[i + 1];
5074  ESI->profile.count[i] = ESI->profile.count[i + 1];
5075  ESI->profile.threshold[i] = ESI->profile.threshold[i + 1];
5076  ESI->profile.EventIndex[i] = ESI->profile.EventIndex[i + 1];
5077  ESI->profile.EventCode[i] = ESI->profile.EventCode[i + 1];
5078  i++;
5079  }
5080  ESI->profile.prof[i] = NULL;
5081  ESI->profile.count[i] = 0;
5082  ESI->profile.threshold[i] = 0;
5083  ESI->profile.EventIndex[i] = 0;
5084  ESI->profile.EventCode[i] = 0;
5085  ESI->profile.event_counter--;
5086  } else {
5087  if ( ESI->profile.event_counter > 0 ) {
5088  if ( ( flags & PAPI_PROFIL_FORCE_SW ) &&
5089  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
5091  }
5092  if ( !( flags & PAPI_PROFIL_FORCE_SW ) &&
5093  ( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
5095  }
5096  }
5097 
5098  for( i = 0; i < ESI->profile.event_counter; i++ ) {
5099  if ( ESI->profile.EventCode[i] == EventCode ) {
5100  break;
5101  }
5102  }
5103 
5104  if ( i == ESI->profile.event_counter ) {
5105  i = ESI->profile.event_counter;
5106  ESI->profile.event_counter++;
5107  ESI->profile.EventCode[i] = EventCode;
5108  }
5109  ESI->profile.prof[i] = prof;
5110  ESI->profile.count[i] = profcnt;
5111  ESI->profile.threshold[i] = threshold;
5112  ESI->profile.EventIndex[i] = index;
5113  }
5114 
5115  APIDBG( "Profile event counter is %d\n", ESI->profile.event_counter );
5116 
5117  /* Clear out old flags */
5118  if ( threshold == 0 ) {
5119  flags |= ESI->profile.flags;
5120  }
5121 
5122  /* make sure no invalid flags are set */
5123  if ( flags &
5125  PAPI_PROFIL_COMPRESS | PAPI_PROFIL_BUCKETS | PAPI_PROFIL_FORCE_SW |
5128  }
5129 
5130  /* if we have kernel-based profiling, then we're just asking for
5131  signals on interrupt. */
5132  /* if we don't have kernel-based profiling, then we're asking for
5133  emulated PMU interrupt */
5134  if ( ( flags & PAPI_PROFIL_FORCE_SW ) &&
5135  ( _papi_hwd[cidx]->cmp_info.kernel_profile == 0 ) ) {
5136  forceSW = PAPI_OVERFLOW_FORCE_SW;
5137  }
5138 
5139  /* make sure one and only one bucket size is set */
5140  buckets = flags & PAPI_PROFIL_BUCKETS;
5141  if ( !buckets ) {
5142  flags |= PAPI_PROFIL_BUCKET_16; /* default to 16 bit if nothing set */
5143  }
5144  else {
5145  /* return error if more than one set */
5146  if ( !( ( buckets == PAPI_PROFIL_BUCKET_16 ) ||
5147  ( buckets == PAPI_PROFIL_BUCKET_32 ) ||
5148  ( buckets == PAPI_PROFIL_BUCKET_64 ) ) ) {
5150  }
5151  }
5152 
5153  /* Set up the option structure for the low level */
5154  ESI->profile.flags = flags;
5155 
5156  if ( _papi_hwd[cidx]->cmp_info.kernel_profile &&
5157  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
5158  retval = _papi_hwd[cidx]->set_profile( ESI, index, threshold );
5159  if ( ( retval == PAPI_OK ) && ( threshold > 0 ) ) {
5160  /* We need overflowing because we use the overflow dispatch handler */
5161  ESI->state |= PAPI_OVERFLOWING;
5163  }
5164  } else {
5165  retval = PAPI_overflow( EventSet, EventCode, threshold, forceSW,
5167  }
5168 
5169  if ( retval < PAPI_OK ) {
5170  papi_return( retval ); /* We should undo stuff here */
5171  }
5172 
5173  /* Toggle the profiling flags and ESI state */
5174 
5175  if ( ESI->profile.event_counter >= 1 ) {
5176  ESI->state |= PAPI_PROFILING;
5177  }
5178  else {
5179  ESI->state ^= PAPI_PROFILING;
5180  ESI->profile.flags = 0;
5181  }
5182 
5183  return PAPI_OK;
5184 }
5185 
5363 int
5364 PAPI_profil( void *buf, unsigned bufsiz, caddr_t offset,
5365  unsigned scale, int EventSet, int EventCode, int threshold,
5366  int flags )
5367 {
5368  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);
5369  EventSetInfo_t *ESI;
5370  int i;
5371  int retval;
5372 
5373  ESI = _papi_hwi_lookup_EventSet( EventSet );
5374  if ( ESI == NULL )
5376 
5377  /* scale factors are checked for validity in PAPI_sprofil */
5378 
5379  if ( threshold > 0 ) {
5380  PAPI_sprofil_t *prof;
5381 
5382  for ( i = 0; i < ESI->profile.event_counter; i++ ) {
5383  if ( ESI->profile.EventCode[i] == EventCode )
5384  break;
5385  }
5386 
5387  if ( i == ESI->profile.event_counter ) {
5388  prof =
5389  ( PAPI_sprofil_t * ) papi_malloc( sizeof ( PAPI_sprofil_t ) );
5390  memset( prof, 0x0, sizeof ( PAPI_sprofil_t ) );
5391  prof->pr_base = buf;
5392  prof->pr_size = bufsiz;
5393  prof->pr_off = offset;
5394  prof->pr_scale = scale;
5395 
5396  retval =
5397  PAPI_sprofil( prof, 1, EventSet, EventCode, threshold, flags );
5398 
5399  if ( retval != PAPI_OK )
5400  papi_free( prof );
5401  } else {
5402  prof = ESI->profile.prof[i];
5403  prof->pr_base = buf;
5404  prof->pr_size = bufsiz;
5405  prof->pr_off = offset;
5406  prof->pr_scale = scale;
5407  retval =
5408  PAPI_sprofil( prof, 1, EventSet, EventCode, threshold, flags );
5409  }
5410  papi_return( retval );
5411  }
5412 
5413  for ( i = 0; i < ESI->profile.event_counter; i++ ) {
5414  if ( ESI->profile.EventCode[i] == EventCode )
5415  break;
5416  }
5417  /* EventCode not found */
5418  if ( i == ESI->profile.event_counter )
5420 
5421  papi_free( ESI->profile.prof[i] );
5422  ESI->profile.prof[i] = NULL;
5423 
5424  papi_return( PAPI_sprofil( NULL, 0, EventSet, EventCode, 0, flags ) );
5425 }
5426 
5427 /* This function sets the low level default granularity
5428  for all newly manufactured eventsets. The first function
5429  preserves API compatibility and assumes component 0;
5430  The second function takes a component argument. */
5431 
5482 int
5483 PAPI_set_granularity( int granularity )
5484 {
5485  return ( PAPI_set_cmp_granularity( granularity, 0 ) );
5486 }
5487 
5547 int
5548 PAPI_set_cmp_granularity( int granularity, int cidx )
5549 {
5551 
5552  memset( &ptr, 0, sizeof ( ptr ) );
5554  ptr.defgranularity.granularity = granularity;
5555  papi_return( PAPI_set_opt( PAPI_DEFGRN, &ptr ) );
5556 }
5557 
5558 /* This function sets the low level default counting domain
5559  for all newly manufactured eventsets. The first function
5560  preserves API compatibility and assumes component 0;
5561  The second function takes a component argument. */
5562 
5613 int
5614 PAPI_set_domain( int domain )
5615 {
5616  return ( PAPI_set_cmp_domain( domain, 0 ) );
5617 }
5618 
5683 int
5684 PAPI_set_cmp_domain( int domain, int cidx )
5685 {
5687 
5688  memset( &ptr, 0, sizeof ( ptr ) );
5689  ptr.defdomain.def_cidx = cidx;
5690  ptr.defdomain.domain = domain;
5691  papi_return( PAPI_set_opt( PAPI_DEFDOM, &ptr ) );
5692 }
5693 
5768 int
5769 PAPI_add_events( int EventSet, int *Events, int number )
5770 {
5771  APIDBG( "Entry: EventSet: %d, Events: %p, number: %d\n", EventSet, Events, number);
5772  int i, retval;
5773 
5774  if ( ( Events == NULL ) || ( number <= 0 ) )
5776 
5777  for ( i = 0; i < number; i++ ) {
5778  retval = PAPI_add_event( EventSet, Events[i] );
5779  if ( retval != PAPI_OK ) {
5780  if ( i == 0 )
5781  papi_return( retval );
5782  else
5783  return ( i );
5784  }
5785  }
5786  return ( PAPI_OK );
5787 }
5788 
5856 int
5857 PAPI_remove_events( int EventSet, int *Events, int number )
5858 {
5859  APIDBG( "Entry: EventSet: %d, Events: %p, number: %d\n", EventSet, Events, number);
5860  int i, retval;
5861 
5862  if ( ( Events == NULL ) || ( number <= 0 ) )
5864 
5865  for ( i = 0; i < number; i++ ) {
5866  retval = PAPI_remove_event( EventSet, Events[i] );
5867  if ( retval != PAPI_OK ) {
5868  if ( i == 0 )
5869  papi_return( retval );
5870  else
5871  return ( i );
5872  }
5873  }
5874  return ( PAPI_OK );
5875 }
5876 
5926 int
5927 PAPI_list_events( int EventSet, int *Events, int *number )
5928 {
5929  APIDBG( "Entry: EventSet: %d, Events: %p, number: %p\n", EventSet, Events, number);
5930  EventSetInfo_t *ESI;
5931  int i, j;
5932 
5933  if ( *number < 0 )
5935 
5936  if ( ( Events == NULL ) && ( *number > 0 ) )
5938 
5939  ESI = _papi_hwi_lookup_EventSet( EventSet );
5940  if ( !ESI )
5942 
5943  if ( ( Events == NULL ) || ( *number == 0 ) ) {
5944  *number = ESI->NumberOfEvents;
5945  papi_return( PAPI_OK );
5946  }
5947 
5948  for ( i = 0, j = 0; j < ESI->NumberOfEvents; i++ ) {
5949  if ( ( int ) ESI->EventInfoArray[i].event_code != PAPI_NULL ) {
5950  Events[j] = ( int ) ESI->EventInfoArray[i].event_code;
5951  j++;
5952  if ( j == *number )
5953  break;
5954  }
5955  }
5956 
5957  *number = j;
5958 
5959  return ( PAPI_OK );
5960 }
5961 
5962 /* xxx This is OS dependent, not component dependent, right? */
5988 int
5990 {
5991  if ( dest == NULL )
5992  return PAPI_EINVAL;
5993 
5994  memset( ( void * ) dest, 0x0, sizeof ( PAPI_dmem_info_t ) );
5995  return ( _papi_os_vector.get_dmem_info( dest ) );
5996 }
5997 
5998 
6039 const PAPI_exe_info_t *
6041 {
6043  int retval;
6044 
6045  memset( &ptr, 0, sizeof ( ptr ) );
6046  retval = PAPI_get_opt( PAPI_EXEINFO, &ptr );
6047  if ( retval == PAPI_OK )
6048  return ( ptr.exe_info );
6049  else
6050  return ( NULL );
6051 }
6052 
6069 const PAPI_shlib_info_t *
6071 {
6073  int retval;
6074 
6075  memset( &ptr, 0, sizeof ( ptr ) );
6076  retval = PAPI_get_opt( PAPI_SHLIBINFO, &ptr );
6077  if ( retval == PAPI_OK )
6078  return ( ptr.shlib_info );
6079  else
6080  return ( NULL );
6081 }
6110 const PAPI_hw_info_t *
6112 {
6114  int retval;
6115 
6116  memset( &ptr, 0, sizeof ( ptr ) );
6117  retval = PAPI_get_opt( PAPI_HWINFO, &ptr );
6118  if ( retval == PAPI_OK )
6119  return ( ptr.hw_info );
6120  else
6121  return ( NULL );
6122 }
6123 
6124 
6125 /* The next 4 timing functions always use component 0 */
6126 
6142 long long
6144 {
6145  return ( _papi_os_vector.get_real_cycles( ) );
6146 }
6147 
6161 /* FIXME */
6162 long long
6164 {
6165  return ( ( _papi_os_vector.get_real_nsec( )));
6166 
6167 }
6168 
6189 long long
6191 {
6192  return ( _papi_os_vector.get_real_usec( ) );
6193 }
6194 
6225 long long
6227 {
6228 
6229  return ( ( long long ) _papi_os_vector.get_virt_cycles( ) );
6230 }
6231 
6255 long long
6257 {
6258 
6259  return ( ( _papi_os_vector.get_virt_nsec()));
6260 
6261 }
6262 
6297 long long
6299 {
6300 
6301  return ( ( long long ) _papi_os_vector.get_virt_usec() );
6302 }
6303 
6326 int
6327 PAPI_lock( int lck )
6328 {
6329  if ( ( lck < 0 ) || ( lck >= PAPI_NUM_LOCK ) )
6331 
6332  papi_return( _papi_hwi_lock( lck ) );
6333 }
6334 
6346 int
6347 PAPI_unlock( int lck )
6348 {
6349  if ( ( lck < 0 ) || ( lck >= PAPI_NUM_LOCK ) )
6351 
6352  papi_return( _papi_hwi_unlock( lck ) );
6353 }
6354 
6388 int
6390 {
6391  return ( init_level );
6392 }
6393 
6394 /* This function maps the overflow_vector to event indexes in the event
6395  set, so that user can know which PAPI event overflowed.
6396  int *array---- an array of event indexes in eventset; the first index
6397  maps to the highest set bit in overflow_vector
6398  int *number--- this is an input/output parameter, user should put the
6399  size of the array into this parameter, after the function
6400  is executed, the number of indexes in *array is written
6401  to this parameter
6402 */
6403 
6442 int
6443 PAPI_get_overflow_event_index( int EventSet, long long overflow_vector,
6444  int *array, int *number )
6445 {
6446  APIDBG( "Entry: EventSet: %d, overflow_vector: %lld, array: %p, number: %p\n", EventSet, overflow_vector, array, number);
6447  EventSetInfo_t *ESI;
6448  int set_bit, j, pos;
6449  int count = 0, k;
6450 
6451  if ( overflow_vector == ( long long ) 0 )
6453 
6454  if ( ( array == NULL ) || ( number == NULL ) )
6456 
6457  if ( *number < 1 )
6459 
6460  ESI = _papi_hwi_lookup_EventSet( EventSet );
6461  if ( ESI == NULL )
6463 
6464  /* in case the eventset is empty */
6465  if ( ESI->NumberOfEvents == 0 )
6467 
6468  while ( ( set_bit = ffsll( overflow_vector ) ) ) {
6469  set_bit -= 1;
6470  overflow_vector ^= ( long long ) 1 << set_bit;
6471  for ( j = 0; j < ESI->NumberOfEvents; j++ ) {
6472  for ( k = 0, pos = 0; k < PAPI_EVENTS_IN_DERIVED_EVENT && pos >= 0; k++ ) {
6473  pos = ESI->EventInfoArray[j].pos[k];
6474  if ( ( set_bit == pos ) &&
6475  ( ( ESI->EventInfoArray[j].derived == NOT_DERIVED ) ||
6476  ( ESI->EventInfoArray[j].derived == DERIVED_CMPD ) ) ) {
6477  array[count++] = j;
6478  if ( count == *number )
6479  return PAPI_OK;
6480 
6481  break;
6482  }
6483  }
6484  }
6485  }
6486  *number = count;
6487  return PAPI_OK;
6488 }
6489 
6490 
6508 int
6510 {
6511  APIDBG( "Entry: EventCode: %#x\n", EventCode);
6512  return _papi_hwi_component_index( EventCode);
6513 }
6514 
6537 {
6538  APIDBG( "Entry: name: %s\n", name);
6539  int cidx;
6540 
6541  const PAPI_component_info_t *cinfo;
6542 
6543  for(cidx=0;cidx<papi_num_components;cidx++) {
6544 
6545  cinfo=PAPI_get_component_info(cidx);
6546  if (cinfo==NULL) return PAPI_ENOCMP;
6547 
6548  if (!strcmp(name,cinfo->name)) {
6549  return cidx;
6550  }
6551  }
6552 
6553  return PAPI_ENOCMP;
6554 }
6555 
6556 
6591 int
6593 {
6594  APIDBG( "Entry: cidx: %d\n", cidx);
6595 
6596  const PAPI_component_info_t *cinfo;
6597 
6598  /* Can only run before PAPI_library_init() is called */
6599  if (init_level != PAPI_NOT_INITED) {
6600  return PAPI_ENOINIT;
6601  }
6602 
6603  cinfo=PAPI_get_component_info(cidx);
6604  if (cinfo==NULL) return PAPI_ENOCMP;
6605 
6606  ((PAPI_component_info_t *)cinfo)->disabled=1;
6607  strcpy(((PAPI_component_info_t *)cinfo)->disabled_reason,
6608  "Disabled by PAPI_disable_component()");
6609 
6610  return PAPI_OK;
6611 
6612 }
6613 
6642 int
6644 {
6645  APIDBG( "Entry: name: %s\n", name);
6646  int cidx;
6647 
6648  /* I can only be called before init time */
6649  if (init_level!=PAPI_NOT_INITED) {
6650  return PAPI_ENOINIT;
6651  }
6652 
6653  cidx = PAPI_get_component_index(name);
6654  if (cidx>=0) {
6655  return PAPI_disable_component(cidx);
6656  }
6657 
6658  return PAPI_ENOCMP;
6659 }
#define PAPI_NUM_LOCK
Definition: papi.h:333
int _papi_hwi_is_sw_multiplex(EventSetInfo_t *ESI)
#define PAPI_ATTACHED
Definition: papi.h:379
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:626
i inherit inherit
#define PAPI_ENOEVNT
Definition: papi.h:258
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
memset(eventId, 0, size)
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
int PAPI_is_initialized(void)
Definition: papi.c:6389
int _papi_hwi_convert_eventset_to_multiplex(_papi_int_multiplex_t *mpx)
#define PAPI_NATIVE_MASK
#define DEBUG_MULTIPLEX
Definition: papi_debug.h:31
int _papi_hwi_init_global_internal(void)
#define PAPI_OVERFLOWING
Definition: papi.h:376
#define IS_PRESET(EventCode)
Definition: papi.h:227
char * _papi_hwi_get_papi_event_string()
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:807
#define DEBUG_PROFILE
Definition: papi_debug.h:33
#define PAPI_CPU_ATTACH
Definition: papi.h:455
char * getenv()
long long(* get_real_nsec)(void)
Definition: papi_vector.h:65
#define PAPI_VERB_ECONT
Definition: papi.h:387
sleep(1)
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
void PAPI_perror(char *msg)
Definition: papi.c:4579
Hardware info structure.
Definition: papi.h:777
inline_static int _papi_set_attach(int option, int EventSet, unsigned long tid)
Definition: papi.c:3083
long long PAPI_get_virt_usec(void)
Definition: papi.c:6298
int PAPI_set_cmp_granularity(int granularity, int cidx)
Definition: papi.c:5548
int PAPI_reset(int EventSet)
Definition: papi.c:2403
#define PAPI_SHUTDOWN_str
Definition: papi_internal.h:42
long long flags
Definition: iozone.c:12330
#define PAPI_DEF_ITIMER_NS
Definition: papi.h:453
int PAPI_add_named_event(int EventSet, char *EventName)
Definition: papi.c:1835
int _papi_hwi_set_thread_id_fn(unsigned long(*id_fn)(void))
Definition: threads.c:352
#define IS_USER_DEFINED(EventCode)
Definition: papi.h:228
const PAPI_shlib_info_t * PAPI_get_shared_lib_info(void)
Definition: papi.c:6070
#define papi_free(a)
Definition: papi_memory.h:35
#define PAPI_INSTR_ADDRESS
Definition: papi.h:451
void ** data
Definition: papi.h:561
int _papi_hwi_query_native_event(unsigned int EventCode)
static int Events[NUM_EVENTS]
Definition: init_fini.c:8
int _papi_hwi_cleanup_eventset(EventSetInfo_t *ESI)
EventSetInfo_t ** running_eventset
Definition: cpus.h:15
unsigned long PAPI_thread_id(void)
Definition: papi.c:159
#define PAPI_PROFIL_DATA_EAR
Definition: papi.h:402
int PAPI_write(int EventSet, long long *values)
Definition: papi.c:2757
int _papi_hwi_debug
Definition: papi.c:76
#define papi_return(a)
Definition: papi.c:47
#define PAPI_DEF_MPX_NS
Definition: papi.h:434
cpu
Definition: iozone.c:3872
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1717
#define papi_malloc(a)
Definition: papi_memory.h:34
long long PAPI_get_virt_cyc(void)
Definition: papi.c:6226
int default_granularity
Definition: papi.h:642
PAPI_debug_handler_t _papi_hwi_debug_handler
Definition: papi_internal.c:56
void MPX_shutdown(void)
long long(* get_real_usec)(void)
Definition: papi_vector.h:63
#define PAPI_NULL
Definition: papi.h:290
#define PAPI_LOW_LEVEL_INITED
Definition: papi.h:279
off64_t offset
Definition: iozone.c:1279
#define PAPI_PROFIL_BUCKET_16
Definition: papi.h:398
#define PAPI_DATA_ADDRESS
Definition: papi.h:450
MPX_EventSet * mpx_evset
Definition: sw_multiplex.h:32
#define PAPI_DOM_MIN
Definition: papi.h:297
int EventSet
Definition: data_range.c:25
int PAPI_num_components(void)
Definition: papi.c:4326
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1150
#define PAPI_MAX_PRESET_EVENTS
int _papi_hwi_native_code_to_name(unsigned int EventCode, char *hwi_name, int len)
void _papi_hwi_dummy_handler(int EventSet, void *address, long long overflow_vector, void *context)
EventSetAttachInfo_t attach
PAPI_granularity_option_t granularity
Definition: papi.h:850
int _papi_user_defined_events_setup(char *name)
int MPX_stop(MPX_EventSet *mpx_events, long long *values)
Definition: sw_multiplex.c:974
#define PAPI_MULTIPLEXING
Definition: papi.h:378
#define PAPI_MULTIPLEX_FORCE_SW
Definition: papi.h:417
caddr_t pr_off
Definition: papi.h:581
#define PAPI_DOM_ALL
Definition: papi.h:301
int PAPI_detach(int EventSet)
Definition: papi.c:3202
int(* update_shlib_info)(papi_mdi_t *mdi)
Definition: papi_vector.h:67
void _papi_hwi_free_papi_event_string()
void(* PAPI_overflow_handler_t)(int EventSet, void *address, long long overflow_vector, void *context)
Definition: papi.h:564
EventSetDomainInfo_t domain
get the executable&#39;s info
Definition: papi.h:704
int PAPI_register_thread(void)
Definition: papi.c:205
int _papi_hwi_errno
Definition: papi_internal.c:58
int _papi_hwi_remove_EventSet(EventSetInfo_t *ESI)
#define PAPI_TLS_NUM
Definition: papi.h:324
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
PAPI_inherit_option_t inherit
Definition: papi.h:849
PAPI_preload_info_t preload_info
char filename[MAXNAMESIZE]
Definition: iozone.c:1360
#define PAPI_ENOTRUN
Definition: papi.h:260
PAPI_exe_info_t exe_info
long long(* get_virt_usec)(void)
Definition: papi_vector.h:64
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4714
#define PAPI_PRESET_MASK
#define PAPI_DOM_USER
Definition: papi.h:296
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:845
int PAPI_remove_events(int EventSet, int *Events, int number)
Definition: papi.c:5857
long long PAPI_get_virt_nsec(void)
Definition: papi.c:6256
return PAPI_EINVAL
Definition: linux-nvml.c:408
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
int PAPI_sprofil(PAPI_sprofil_t *prof, int profcnt, int EventSet, int EventCode, int threshold, int flags)
Definition: papi.c:4970
void _papi_hwi_init_errors(void)
#define PAPI_NOT_INITED
Definition: papi.h:278
int _papi_hwi_remove_event(EventSetInfo_t *ESI, int EventCode)
#define DEBUG_MEMORY
Definition: papi_debug.h:34
EventSetInfo_t * _papi_hwi_lookup_EventSet(int eventset)
#define DERIVED_CMPD
Definition: papi_internal.h:73
PAPI_hw_info_t * hw_info
Definition: papi.h:858
double c
Definition: multiplex.c:22
#define PAPI_ENOTPRESET
Definition: papi.h:263
PAPI_user_defined_events_file_t events_file
Definition: papi.h:863
int _papi_hwi_native_name_to_code(char *in, int *out)
papi_vector_t * _papi_hwd[]
#define DEBUG_API
Definition: papi_debug.h:28
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3409
long long(* get_real_cycles)(void)
Definition: papi_vector.h:61
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
int PAPI_add_events(int EventSet, int *Events, int number)
Definition: papi.c:5769
unsigned int cpu_num
Definition: papi.h:821
#define PAPI_INHERIT
Definition: papi.h:456
#define PAPI_PRELOAD
Definition: papi.h:439
#define PAPI_HUGE_STR_LEN
Definition: papi.h:465
unsigned pr_scale
Definition: papi.h:582
PAPI_shlib_info_t shlib_info
Return codes and api definitions.
int MPX_read(MPX_EventSet *mpx_events, long long *values, int called_by_stop)
Definition: sw_multiplex.c:823
#define PAPI_CPU_ATTACHED
Definition: papi.h:380
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:846
int PAPI_disable_component_by_name(char *name)
Definition: papi.c:6643
void * thread_storage[PAPI_MAX_TLS]
Definition: threads.h:29
PAPI_addr_range_option_t addr
Definition: papi.h:862
#define APIDBG(format, args...)
Definition: papi_debug.h:64
int _papi_hwi_shutdown_global_threads(void)
Definition: threads.c:457
int multiplex(void)
Definition: multiplex.c:35
int PAPI_set_cmp_domain(int domain, int cidx)
Definition: papi.c:5684
long long ret
Definition: iozone.c:1346
int PAPI_disable_component(int cidx)
Definition: papi.c:6592
unsigned pr_size
Definition: papi.h:580
#define PAPI_EMISC
Definition: papi.h:265
int PAPI_num_cmp_hwctrs(int cidx)
Definition: papi.c:3904
void _papi_mem_cleanup_all()
Definition: papi_memory.c:303
int PAPI_get_thr_specific(int tag, void **ptr)
Definition: papi.c:359
int PAPI_accum(int EventSet, long long *values)
Definition: papi.c:2689
void _papi_hwi_shutdown_highlevel()
Definition: papi_hl.c:836
#define PAPI_TLS_ALL_THREADS
Definition: papi.h:325
int(* shutdown_component)(void)
Definition: papi_vector.h:54
#define PAPI_USER_EVENTS_FILE
Definition: papi.h:457
#define DEADBEEF
Definition: papi_internal.h:26
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:120
#define DEBUG_ALL
Definition: papi_debug.h:36
void _papi_cleanup_user_events()
int PAPI_library_init(int version)
Definition: papi.c:497
int PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset, unsigned scale, int EventSet, int EventCode, int threshold, int flags)
Definition: papi.c:5364
#define PAPI_THREAD_LEVEL_INITED
Definition: papi.h:281
papi_os_vector_t _papi_os_vector
Definition: aix.c:1288
#define PAPI_PROFIL_COMPRESS
Definition: papi.h:397
int i
Definition: fileop.c:140
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
int _papi_hwi_native_to_eventcode(int cidx, int event_code, int ntv_idx, const char *event_name)
EventSetOverflowInfo_t overflow
int(* stop_profiling)(ThreadInfo_t *, EventSetInfo_t *)
Definition: papi_vector.h:34
char buf[200]
Definition: iozone.c:19609
int PAPI_num_hwctrs(void)
Definition: papi.c:3848
#define PAPI_OVERFLOW_HARDWARE
Definition: papi.h:410
EventSetInheritInfo_t inherit
#define PAPI_SHUTDOWN_SYNC_str
Definition: papi_internal.h:43
struct _CpuInfo * CpuInfo
PAPI_os_info_t _papi_os_info
Definition: aix.c:1210
DynamicArray_t global_eventset_map
struct _ThreadInfo * master
#define PAPI_ENOEVST
Definition: papi.h:262
A pointer to the following is passed to PAPI_get_dmem_info()
Definition: papi.h:868
int MPX_start(MPX_EventSet *mpx_events)
Definition: sw_multiplex.c:692
#define PAPI_LIB_VERSION
Definition: papi.h:447
void PAPI_shutdown(void)
Definition: papi.c:4400
Definition: cpus.h:10
#define IS_NATIVE(EventCode)
Definition: papi.h:226
int PAPI_get_cmp_opt(int option, PAPI_option_t *ptr, int cidx)
Definition: papi.c:4274
int(* write)(hwd_context_t *, hwd_control_state_t *, long long[])
Definition: papi_vector.h:32
const PAPI_exe_info_t * PAPI_get_executable_info(void)
Definition: papi.c:6040
#define PAPI_PROFIL_BUCKET_64
Definition: papi.h:400
int PAPI_num_events(int EventSet)
Definition: papi.c:4365
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4082
#define NOT_DERIVED
Definition: papi_internal.h:69
int ffsll(long long lli)
Definition: extras.c:497
int k
Definition: iozone.c:19136
static int cidx
Definition: event_info.c:40
#define OVFDBG(format, args...)
Definition: papi_debug.h:68
int _papi_hwi_read(hwd_context_t *context, EventSetInfo_t *ESI, long long *values)
PAPI_sprofil_t ** prof
hwi_presets_t _papi_hwi_presets[PAPI_MAX_PRESET_EVENTS]
#define PAPI_EXEINFO
Definition: papi.h:443
int _papi_hwi_stop_timer(int timer, int signal)
Definition: extras.c:461
int(* start)(hwd_context_t *, hwd_control_state_t *)
Definition: papi_vector.h:28
int PAPI_state(int EventSet, int *status)
Definition: papi.c:2997
pthread_attr_t foo
Definition: iozone.c:18592
#define PAPI_PROFIL_RANDOM
Definition: papi.h:395
#define PAPI_GRANUL
Definition: papi.h:433
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
void * thread(void *arg)
Definition: kufrin.c:31
#define PAPI_MAX_CPUS
Definition: papi.h:444
int(* reset)(hwd_context_t *, hwd_control_state_t *)
Definition: papi_vector.h:31
void *long long tid
Definition: iozone.c:18586
#define PAPI_DEFGRN
Definition: papi.h:432
int MPX_cleanup(MPX_EventSet **mpx_events)
#define PAPI_PROFIL_INST_EAR
Definition: papi.h:403
#define DEBUG_LEAK
Definition: papi_debug.h:35
int _papi_hwi_start_timer(int timer, int signal, int ns)
Definition: extras.c:366
int _papi_hwi_lookup_EventCodeIndex(const EventSetInfo_t *ESI, unsigned int EventCode)
int _papi_hwi_add_event(EventSetInfo_t *ESI, int EventCode)
long long
Definition: iozone.c:19827
#define PAPI_ECNFLCT
Definition: papi.h:259
int _papi_hwi_get_native_event_info(unsigned int EventCode, PAPI_event_info_t *info)
#define PAPI_DETACH
Definition: papi.h:427
void PAPIERROR(char *format,...)
int _papi_hwi_start_signal(int signal, int need_context, int cidx)
Definition: extras.c:401
PAPI_cpu_option_t cpu
Definition: papi.h:855
void _papi_hwi_shutdown_global_internal(void)
int _papi_hwi_get_preset_event_info(int EventCode, PAPI_event_info_t *info)
int PAPI_set_granularity(int granularity)
Definition: papi.c:5483
int PAPI_get_component_index(char *name)
Definition: papi.c:6536
#define PAPI_ATTACH
Definition: papi.h:445
#define inline_static
#define DEBUG_INTERNAL
Definition: papi_debug.h:29
#define PAPI_ECMP
Definition: papi.h:254
int(* ctl)(hwd_context_t *, int, _papi_int_option_t *)
Definition: papi_vector.h:39
#define PAPI_GRN_MAX
Definition: papi.h:366
#define PAPI_MAX_MPX_CTRS
Definition: papi.h:437
#define PAPI_MULTIPLEX_DEFAULT
Definition: papi.h:416
#define PAPI_PROFIL_BUCKET_32
Definition: papi.h:399
#define PAPI_EISRUN
Definition: papi.h:261
int _papi_hwi_error_level
Definition: papi_internal.c:55
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1324
PAPI_multiplex_option_t multiplex
Definition: papi.h:856
#define PAPI_MULTIPLEX
Definition: papi.h:429
int _papi_hwi_stop_signal(int signal)
Definition: extras.c:441
long long(* get_virt_nsec)(void)
Definition: papi_vector.h:66
#define THREADS_LOCK
Definition: papi_internal.h:87
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:16
inline_static int valid_ESI_component(EventSetInfo_t *ESI)
Definition: papi.c:91
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2834
int mpx_init(int interval_ns)
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1485
NativeInfo_t * NativeInfoArray
int _papi_hwi_num_errors
Definition: papi_internal.c:59
char version[]
Definition: fileop.c:134
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
EventInfo_t * EventInfoArray
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
long long * hw_start
int threshold
PAPI_thread_id_t * id
Definition: papi.h:560
static int init_retval
Definition: papi.c:80
unsigned int hardware_intr
Definition: papi.h:649
#define DEBUG_OVERFLOW
Definition: papi_debug.h:32
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:57
strcpy(filename, default_filename)
PAPI_hw_info_t hw_info
again struct sockaddr sizeof(struct sockaddr_in))
#define PAPI_ENOCMP
Definition: papi.h:268
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1010
int PAPI_get_dmem_info(PAPI_dmem_info_t *dest)
Definition: papi.c:5989
#define PAPI_DOMAIN
Definition: papi.h:431
EventSetMultiplexInfo_t multiplex
goto out
Definition: pscanf.h:20
EventSetGranularityInfo_t granularity
hwd_context_t * _papi_hwi_get_context(EventSetInfo_t *ESI, int *is_dirty)
EventSetInfo_t ** dataSlotArray
int(* stop)(hwd_context_t *, hwd_control_state_t *)
Definition: papi_vector.h:29
#define PAPI_COMPONENTINFO
Definition: papi.h:448
int PAPI_query_event(int EventCode)
Definition: papi.c:698
int pos[PAPI_EVENTS_IN_DERIVED_EVENT]
PAPI_debug_handler_t handler
Definition: papi.h:687
#define PAPI_NUM_TLS
Definition: papi.h:320
int PAPI_get_overflow_event_index(int EventSet, long long overflow_vector, int *array, int *number)
Definition: papi.c:6443
unsigned long tid
Definition: papi.h:815
int MPX_reset(MPX_EventSet *mpx_events)
Definition: sw_multiplex.c:937
long long * sw_stop
int PAPI_multiplex_init(void)
Definition: papi.c:2926
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
PAPI_attach_option_t attach
Definition: papi.h:854
void _papi_hwi_set_papi_event_code(unsigned int event_code, int update_flag)
PAPI_granularity_option_t defgranularity
Definition: papi.h:851
long long buckets[BUCKETS]
Definition: iozone.c:24212
int papi_num_components
int(* cleanup_eventset)(hwd_control_state_t *)
Definition: papi_vector.h:33
int PAPI_read_ts(int EventSet, long long *values, long long *cycles)
Definition: papi.c:2592
long long PAPI_get_real_usec(void)
Definition: papi.c:6190
PAPI_exe_info_t * exe_info
Definition: papi.h:860
#define PAPI_PROFIL_POSIX
Definition: papi.h:394
#define PAPI_PROFIL_WEIGHTED
Definition: papi.h:396
int _papi_hwi_init_os(void)
Definition: aix.c:1213
#define PAPI_OVERFLOW_FORCE_SW
Definition: papi.h:409
#define PAPI_DEF_ITIMER
Definition: papi.h:452
long long status
Definition: iozone.c:1335
#define PAPI_PROFILING
Definition: papi.h:377
EventSetInfo_t ** running_eventset
Definition: threads.h:30
int PAPI_unregister_thread(void)
Definition: papi.c:241
#define PAPI_VERSION
Definition: papi.h:222
int _papi_hwi_lookup_or_create_cpu(CpuInfo_t **here, unsigned int cpu_num)
Definition: cpus.c:59
int PAPI_set_thr_specific(int tag, void *ptr)
Definition: papi.c:435
int(* ntv_enum_events)(unsigned int *, int)
Definition: papi_vector.h:43
char * PAPI_strerror(int errorCode)
Definition: papi.c:4529
char * name
Definition: iozone.c:23648
int PAPI_query_named_event(char *EventName)
Definition: papi.c:767
int _papi_hwi_assign_eventset(EventSetInfo_t *ESI, int cidx)
static int total
Definition: rapl_overflow.c:5
int _papi_hwi_init_global(void)
inline_static int _papi_hwi_lookup_or_create_thread(ThreadInfo_t **here, int tid)
Definition: threads.h:145
#define NEED_CONTEXT
Definition: papi_internal.h:97
#define PAPI_HWINFO
Definition: papi.h:442
int _papi_hwi_gather_all_thrspec_data(int tag, PAPI_all_thr_spec_t *where)
Definition: threads.c:554
#define PAPI_CLOCKRATE
Definition: papi.h:440
long long(* get_virt_cycles)(void)
Definition: papi_vector.h:62
char ** _papi_errlist
Definition: papi_internal.c:80
PAPI_debug_option_t debug
Definition: papi.h:848
int PAPI_unlock(int lck)
Definition: papi.c:6347
int cpu_max_mhz
Definition: papi.h:793
#define PAPI_EINVAL_DOM
Definition: papi.h:272
int
Definition: iozone.c:18528
#define PAPI_RUNNING
Definition: papi.h:373
#define PAPI_MIN_STR_LEN
Definition: papi.h:462
int(* update_control_state)(hwd_control_state_t *, NativeInfo_t *, int, hwd_context_t *)
Definition: papi_vector.h:38
long long PAPI_get_real_nsec(void)
Definition: papi.c:6163
#define ISLEVEL(a)
Definition: papi_debug.h:54
inline_static ThreadInfo_t * _papi_hwi_lookup_thread(int custom_tid)
Definition: threads.h:92
#define PAPI_MAX_HWCTRS
Definition: papi.h:441
int _papi_hwi_component_index(int event_code)
#define PAPI_PROFIL_FORCE_SW
Definition: papi.h:401
#define PAPI_QUIET
Definition: papi.h:386
unsigned int event_code
#define PAPI_DEFDOM
Definition: papi.h:430
#define PAPI_STOPPED
Definition: papi.h:372
#define PAPI_ENOINIT
Definition: papi.h:267
#define PAPI_UE_AND_MASK
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3277
#define PAPI_PRESET_AND_MASK
unsigned long PAPI_thread_id_t
Definition: papi.h:555
#define PAPI_PROFIL_BUCKETS
Definition: papi.h:404
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1971
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int(* set_profile)(EventSetInfo_t *, int, int)
Definition: papi_vector.h:41
PAPI_domain_option_t domain
Definition: papi.h:852
int _papi_hwi_invalid_cmp(int cidx)
user_defined_event_t * _papi_user_events
#define DEBUG_THREADS
Definition: papi_debug.h:30
int PAPI_set_domain(int domain)
Definition: papi.c:5614
void _papi_hwi_free_EventSet(EventSetInfo_t *ESI)
int PAPI_attach(int EventSet, unsigned long tid)
Definition: papi.c:3145
int _papi_hwi_eventcode_to_native(int event_code)
void * pr_base
Definition: papi.h:579
static int attach(hwd_control_state_t *ctl, unsigned long tid)
Definition: perfctr.c:242
long long PAPI_get_real_cyc(void)
Definition: papi.c:6143
PAPI_shlib_info_t * shlib_info
Definition: papi.h:859
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2503
int _papi_hwi_shutdown_thread(ThreadInfo_t *thread, int force_shutdown)
Definition: threads.c:418
int PAPI_start(int EventSet)
Definition: papi.c:2053
#define PAPI_VERB_ESTOP
Definition: papi.h:388
EventSetProfileInfo_t profile
PAPI_preload_info_t preload
Definition: papi.h:847
int(* get_dmem_info)(PAPI_dmem_info_t *)
Definition: papi_vector.h:70
int init_level
Definition: papi_internal.c:54
hwd_control_state_t * ctl_state
long j
Definition: iozone.c:19135
int PAPI_get_multiplex(int EventSet)
Definition: papi.c:3967
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6111
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
int PAPI_lock(int lck)
Definition: papi.c:6327
long long tmp
Definition: iozone.c:12031
#define PAPI_GRN_MIN
Definition: papi.h:361
#define PAPI_VER_CURRENT
Definition: papi.h:223
int PAPI_remove_named_event(int EventSet, char *EventName)
Definition: papi.c:1919
#define PAPI_UE_MASK
unsigned int _papi_user_events_count
#define PAPI_DOM_MAX
Definition: papi.h:303
inline_static int valid_component(int cidx)
Definition: papi.c:83
int _papi_hwi_init_global_threads(void)
Definition: threads.c:527
int PAPI_list_threads(PAPI_thread_id_t *tids, int *number)
Definition: papi.c:283
PAPI_itimer_option_t itimer
Definition: papi.h:857
int PAPI_get_event_component(int EventCode)
Definition: papi.c:6509
int PAPI_set_debug(int level)
Definition: papi.c:3070
int mpx_check(int EventSet)
void _papi_hwi_map_events_to_native(EventSetInfo_t *ESI)
PAPI_domain_option_t defdomain
Definition: papi.h:853
PAPI_overflow_handler_t handler
int(* set_overflow)(EventSetInfo_t *, int, int)
Definition: papi_vector.h:40
if(gettimeofday(&tp,(struct timezone *) NULL)==-1) perror("gettimeofday")
int _papi_hwi_create_eventset(int *EventSet, ThreadInfo_t *handle)
#define PAPI_DEBUG
Definition: papi.h:428
int PAPI_list_events(int EventSet, int *Events, int *number)
Definition: papi.c:5927
PAPI_component_info_t * cmp_info
Definition: papi.h:861
#define DEBUG_SUBSTRATE
Definition: papi_debug.h:27
int ncpu
Definition: papi.h:778
int PAPI_get_eventset_component(int EventSet)
Definition: papi.c:1528
char * ptr
Definition: iozone.c:23586
#define PAPI_SHLIBINFO
Definition: papi.h:446