PAPI  5.6.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 #include "papi_preset.h"
34 
35 #include "cpus.h"
36 #include "extras.h"
37 #include "sw_multiplex.h"
38 #include "papi_hl.h"
39 
40 /*******************************/
41 /* BEGIN EXTERNAL DECLARATIONS */
42 /*******************************/
43 
44 
46 extern int user_defined_events_count;
47 
48 
49 #ifdef DEBUG
50 #define papi_return(a) do { \
51  int b = a; \
52  if (b != PAPI_OK) {\
53  _papi_hwi_errno = b;\
54  } \
55  APIDBG("EXIT: return: %d\n", b);\
56  return((_papi_hwi_debug_handler ? _papi_hwi_debug_handler(b) : b)); \
57 } while (0)
58 #else
59 #define papi_return(a) do { \
60  int b = a; \
61  if (b != PAPI_OK) {\
62  _papi_hwi_errno = b;\
63  } \
64  APIDBG("EXIT: return: %d\n", b);\
65  return(b);\
66 } while(0)
67 #endif
68 
69 
70 /*
71 #ifdef DEBUG
72 #define papi_return(a) return((_papi_hwi_debug_handler ? _papi_hwi_debug_handler(a) : a))
73 #else
74 #define papi_return(a) return(a)
75 #endif
76 */
77 
78 #ifdef DEBUG
80 #endif
81 
82 
83 static int init_retval = DEADBEEF;
84 
85 inline_static int
87 {
88  if ( _papi_hwi_invalid_cmp( cidx ) )
89  return ( PAPI_ENOCMP );
90  return ( cidx );
91 }
92 
93 inline_static int
95 {
96  return ( valid_component( ESI->CmpIdx ) );
97 }
98 
122 int
123 PAPI_thread_init( unsigned long int ( *id_fn ) ( void ) )
124 {
125  /* Thread support not implemented on Alpha/OSF because the OSF pfm
126  * counter device driver does not support per-thread counters.
127  * When this is updated, we can remove this if statement
128  */
129  if ( init_level == PAPI_NOT_INITED )
131 
133  papi_return( PAPI_OK );
134 
137 }
138 
161 unsigned long
163 {
164  if ( _papi_hwi_thread_id_fn != NULL )
165  return ( ( *_papi_hwi_thread_id_fn ) ( ) );
166  else
167 #ifdef DEBUG
169  return ( unsigned long ) _papi_hwi_debug_handler( PAPI_EMISC );
170 #endif
171  return ( unsigned long ) PAPI_EMISC;
172 }
173 
174 /* Thread Functions */
175 
176 /*
177  * Notify PAPI that a thread has 'appeared'
178  * We lookup the thread, if it does not exist we create it
179  */
180 
207 int
209 {
211 
212  if ( init_level == PAPI_NOT_INITED )
215 }
216 
217 /*
218  * Notify PAPI that a thread has 'disappeared'
219  * We lookup the thread, if it does not exist we return an error
220  */
243 int
245 {
247 
248  if ( thread )
249  papi_return( _papi_hwi_shutdown_thread( thread, 0 ) );
250 
252 }
253 
285 int
286 PAPI_list_threads( PAPI_thread_id_t *tids, int *number )
287 {
289  int retval;
290 
291  /* If tids == NULL, then just count the threads, don't gather a list. */
292  /* If tids != NULL, then we need the length of the tids array in num. */
293 
294  if ( ( number == NULL ) || ( tids && ( *number <= 0 ) ) )
296 
297  memset( &tmp, 0x0, sizeof ( tmp ) );
298 
299  /* data == NULL, since we don't want the thread specific pointers. */
300  /* tids may be NULL, if the user doesn't want the thread IDs. */
301 
302  tmp.num = *number;
303  tmp.id = tids;
304  tmp.data = NULL;
305 
306  retval = _papi_hwi_gather_all_thrspec_data( 0, &tmp );
307  if ( retval == PAPI_OK )
308  *number = tmp.num;
309 
310  papi_return( retval );
311 }
312 
361 int
362 PAPI_get_thr_specific( int tag, void **ptr )
363 {
365  int doall = 0, retval = PAPI_OK;
366 
367  if ( init_level == PAPI_NOT_INITED )
369  if ( tag & PAPI_TLS_ALL_THREADS ) {
370  tag = tag ^ PAPI_TLS_ALL_THREADS;
371  doall = 1;
372  }
373  if ( ( tag < 0 ) || ( tag > PAPI_TLS_NUM ) )
375 
376  if ( doall )
378  ( tag, ( PAPI_all_thr_spec_t * ) ptr ) );
379 
381  if ( retval == PAPI_OK )
382  *ptr = thread->thread_storage[tag];
383  else
384  papi_return( retval );
385 
386  return ( PAPI_OK );
387 }
388 
437 int
438 PAPI_set_thr_specific( int tag, void *ptr )
439 {
441  int retval = PAPI_OK;
442 
443  if ( init_level == PAPI_NOT_INITED )
445  if ( ( tag < 0 ) || ( tag > PAPI_NUM_TLS ) )
447 
448  retval = _papi_hwi_lookup_or_create_thread( &thread, 0 );
449  if ( retval == PAPI_OK ) {
451  thread->thread_storage[tag] = ptr;
453  }
454  else
455  return ( retval );
456 
457  return ( PAPI_OK );
458 }
459 
460 
499 int
501 {
502  APIDBG( "Entry: version: %#x\n", version);
503 
504  int tmp = 0;
505 
506  /* This is a poor attempt at a lock.
507  For 3.1 this should be replaced with a
508  true UNIX semaphore. We cannot use PAPI
509  locks here because they are not initialized yet */
510  static int _in_papi_library_init_cnt = 0;
511 #ifdef DEBUG
512  char *var;
513 #endif
515 
516  if ( version != PAPI_VER_CURRENT )
518 
519  ++_in_papi_library_init_cnt;
520  while ( _in_papi_library_init_cnt > 1 ) {
521  PAPIERROR( "Multiple callers of PAPI_library_init" );
522  sleep( 1 );
523  }
524 
525  /* This checks to see if we have forked or called init more than once.
526  If we have forked, then we continue to init. If we have not forked,
527  we check to see the status of initialization. */
528 
529  APIDBG( "Initializing library: current PID %d, old PID %d\n",
530  getpid( ), _papi_hwi_system_info.pid );
531 
532  if ( _papi_hwi_system_info.pid == getpid( ) ) {
533  /* If the magic environment variable PAPI_ALLOW_STOLEN is set,
534  we call shutdown if PAPI has been initialized. This allows
535  tools that use LD_PRELOAD to run on applications that use PAPI.
536  In this circumstance, PAPI_ALLOW_STOLEN will be set to 'stolen'
537  so the tool can check for this case. */
538 
539  if ( getenv( "PAPI_ALLOW_STOLEN" ) ) {
540  char buf[PAPI_HUGE_STR_LEN];
541  if ( init_level != PAPI_NOT_INITED )
542  PAPI_shutdown( );
543  sprintf( buf, "%s=%s", "PAPI_ALLOW_STOLEN", "stolen" );
544  putenv( buf );
545  }
546 
547  /* If the library has been successfully initialized *OR*
548  the library attempted initialization but failed. */
549 
550  else if ( ( init_level != PAPI_NOT_INITED ) ||
551  ( init_retval != DEADBEEF ) ) {
552  _in_papi_library_init_cnt--;
553  if ( init_retval < PAPI_OK )
555  else
556  return ( init_retval );
557  }
558 
559  APIDBG( "system_info was initialized, but init did not succeed\n" );
560  }
561 #ifdef DEBUG
562  var = ( char * ) getenv( "PAPI_DEBUG" );
563  _papi_hwi_debug = 0;
564 
565  if ( var != NULL ) {
566  if ( strlen( var ) != 0 ) {
567  if ( strstr( var, "SUBSTRATE" ) )
569  if ( strstr( var, "API" ) )
571  if ( strstr( var, "INTERNAL" ) )
573  if ( strstr( var, "THREADS" ) )
575  if ( strstr( var, "MULTIPLEX" ) )
577  if ( strstr( var, "OVERFLOW" ) )
579  if ( strstr( var, "PROFILE" ) )
581  if ( strstr( var, "MEMORY" ) )
583  if ( strstr( var, "LEAK" ) )
585  if ( strstr( var, "ALL" ) )
587  }
588 
589  if ( _papi_hwi_debug == 0 )
591  }
592 #endif
593 
594 
595  /* Initialize internal globals */
597  _in_papi_library_init_cnt--;
599  }
600 
601  /* Initialize OS */
602  tmp = _papi_hwi_init_os();
603  if ( tmp ) {
604  init_retval = tmp;
606  _in_papi_library_init_cnt--;
608  }
609 
610  /* Initialize component globals */
611 
612  tmp = _papi_hwi_init_global( );
613  if ( tmp ) {
614  init_retval = tmp;
616  _in_papi_library_init_cnt--;
618  }
619 
620  /* Initialize thread globals, including the main threads */
621 
623  if ( tmp ) {
624  int i;
625  init_retval = tmp;
627  for ( i = 0; i < papi_num_components; i++ ) {
628  if (!_papi_hwd[i]->cmp_info.disabled) {
630  }
631  }
632  _in_papi_library_init_cnt--;
634  }
635 
637  _in_papi_library_init_cnt--;
638 
639  return ( init_retval = PAPI_VER_CURRENT );
640 }
641 
683 int
684 PAPI_query_event( int EventCode )
685 {
686  APIDBG( "Entry: EventCode: %#x\n", EventCode);
687  if ( IS_PRESET(EventCode) ) {
688  EventCode &= PAPI_PRESET_AND_MASK;
689  if ( EventCode < 0 || EventCode >= PAPI_MAX_PRESET_EVENTS )
691 
692  if ( _papi_hwi_presets[EventCode].count )
694  else
695  return PAPI_ENOEVNT;
696  }
697 
698  if ( IS_NATIVE(EventCode) ) {
700  ( ( unsigned int ) EventCode ) );
701  }
702 
703  if ( IS_USER_DEFINED(EventCode) ) {
704  EventCode &= PAPI_UE_AND_MASK;
705  if ( EventCode < 0 || EventCode >= PAPI_MAX_USER_EVENTS)
707 
708  if ( user_defined_events[EventCode].count )
710  else
712  }
713 
715 }
716 
755 int
756 PAPI_query_named_event( const char *EventName )
757 {
758  int ret, code;
759 
760  ret = PAPI_event_name_to_code( EventName, &code );
761  if ( ret == PAPI_OK ) ret = PAPI_query_event( code );
762  papi_return( ret);
763 }
764 
765 
795 const PAPI_component_info_t *
797 {
798  APIDBG( "Entry: Component Index %d\n", cidx);
799  if ( _papi_hwi_invalid_cmp( cidx ) )
800  return ( NULL );
801  else
802  return ( &( _papi_hwd[cidx]->cmp_info ) );
803 }
804 
805 /* PAPI_get_event_info:
806  tests input EventCode and returns a filled in PAPI_event_info_t
807  structure containing descriptive strings and values for the
808  specified event. Handles both preset and native events by
809  calling either _papi_hwi_get_event_info or
810  _papi_hwi_get_native_event_info.
811 */
834 int
835 PAPI_get_event_info( int EventCode, PAPI_event_info_t *info )
836 {
837  APIDBG( "Entry: EventCode: 0x%x, info: %p\n", EventCode, info);
838  int i;
839 
840  if ( info == NULL )
842 
843  if ( IS_PRESET(EventCode) ) {
844  i = EventCode & PAPI_PRESET_AND_MASK;
845  if ( i >= PAPI_MAX_PRESET_EVENTS )
847  papi_return( _papi_hwi_get_preset_event_info( EventCode, info ) );
848  }
849 
850  if ( IS_NATIVE(EventCode) ) {
852  ( ( unsigned int ) EventCode, info ) );
853  }
854 
855  if ( IS_USER_DEFINED(EventCode) ) {
856  papi_return( _papi_hwi_get_user_event_info( EventCode, info ));
857  }
859 }
860 
861 
914 int
915 PAPI_event_code_to_name( int EventCode, char *out )
916 {
917  APIDBG( "Entry: EventCode: %#x, out: %p\n", EventCode, out);
918  if ( out == NULL )
920 
921  if ( IS_PRESET(EventCode) ) {
922  EventCode &= PAPI_PRESET_AND_MASK;
923  if ( EventCode < 0 || EventCode >= PAPI_MAX_PRESET_EVENTS )
925 
926  if (_papi_hwi_presets[EventCode].symbol == NULL )
928 
929  strncpy( out, _papi_hwi_presets[EventCode].symbol, PAPI_MAX_STR_LEN-1 );
930  out[PAPI_MAX_STR_LEN-1] = '\0';
931  papi_return( PAPI_OK );
932  }
933 
934  if ( IS_NATIVE(EventCode) ) {
936  ( ( unsigned int ) EventCode, out, PAPI_MAX_STR_LEN ) );
937  }
938 
939  if ( IS_USER_DEFINED(EventCode) ) {
940  EventCode &= PAPI_UE_AND_MASK;
941 
942  if ( EventCode < 0 || EventCode >= user_defined_events_count )
944 
945  if (user_defined_events[EventCode].symbol == NULL )
947 
948  strncpy( out, user_defined_events[EventCode].symbol, PAPI_MAX_STR_LEN-1);
949  out[PAPI_MAX_STR_LEN-1] = '\0';
950  papi_return( PAPI_OK );
951  }
952 
954 }
955 
1003 int
1004 PAPI_event_name_to_code( const char *in, int *out )
1005 {
1006  APIDBG("Entry: in: %p, name: %s, out: %p\n", in, in, out);
1007  int i;
1008 
1009  if ( ( in == NULL ) || ( out == NULL ) )
1011 
1012  if ( init_level == PAPI_NOT_INITED )
1014 
1015  /* All presets start with "PAPI_" so no need to */
1016  /* do an exhaustive search if that's not there */
1017  if (strncmp(in, "PAPI_", 5) == 0) {
1018  for(i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
1019  if ( ( _papi_hwi_presets[i].symbol )
1020  && ( strcasecmp( _papi_hwi_presets[i].symbol, in ) == 0) ) {
1021  *out = ( int ) ( i | PAPI_PRESET_MASK );
1022  papi_return( PAPI_OK );
1023  }
1024  }
1025  }
1026 
1027  // check to see if it is a user defined event
1028  for ( i=0; i < user_defined_events_count ; i++ ) {
1029  APIDBG("&user_defined_events[%d]: %p, user_defined_events[%d].symbol: %s, user_defined_events[%d].count: %d\n",
1030  i, &user_defined_events[i], i, user_defined_events[i].symbol, i, user_defined_events[i].count);
1031  if (user_defined_events[i].symbol == NULL)
1032  break;
1033  if (user_defined_events[i].count == 0)
1034  break;
1035  if ( strcasecmp( user_defined_events[i].symbol, in ) == 0 ) {
1036  *out = (int) ( i | PAPI_UE_MASK );
1037  papi_return( PAPI_OK );
1038  }
1039  }
1040 
1041  // go look for native events defined by one of the components
1043 }
1044 
1045 /* Updates EventCode to next valid value, or returns error;
1046  modifier can specify {all / available} for presets, or other values for native tables
1047  and may be platform specific (Major groups / all mask bits; P / M / E chip, etc) */
1048 
1151 int
1152 PAPI_enum_event( int *EventCode, int modifier )
1153 {
1154  APIDBG( "Entry: EventCode: %#x, modifier: %d\n", *EventCode, modifier);
1155  int i = *EventCode;
1156  int retval;
1157  int cidx;
1158  int event_code;
1159  char *evt_name;
1160 
1161  cidx = _papi_hwi_component_index( *EventCode );
1162  if (cidx < 0) return PAPI_ENOCMP;
1163 
1164  /* Do we handle presets in componets other than CPU? */
1165  /* if (( IS_PRESET(i) ) && cidx > 0 )) return PAPI_ENOCMP; */
1166 
1167  if ( IS_PRESET(i) ) {
1168  if ( modifier == PAPI_ENUM_FIRST ) {
1169  *EventCode = ( int ) PAPI_PRESET_MASK;
1170  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1171  return ( PAPI_OK );
1172  }
1173  i &= PAPI_PRESET_AND_MASK;
1174  while ( ++i < PAPI_MAX_PRESET_EVENTS ) {
1175  if ( _papi_hwi_presets[i].symbol == NULL ) {
1176  APIDBG("EXIT: PAPI_ENOEVNT\n");
1177  return ( PAPI_ENOEVNT ); /* NULL pointer terminates list */
1178  }
1179  if ( modifier & PAPI_PRESET_ENUM_AVAIL ) {
1180  if ( _papi_hwi_presets[i].count == 0 )
1181  continue;
1182  }
1183  *EventCode = ( int ) ( i | PAPI_PRESET_MASK );
1184  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1185  return ( PAPI_OK );
1186  }
1188  }
1189 
1190  if ( IS_NATIVE(i) ) {
1191  // save event code so components can get it with call to: _papi_hwi_get_papi_event_code()
1192  _papi_hwi_set_papi_event_code(*EventCode, 0);
1193 
1194  /* Should check against num native events here */
1195 
1196  event_code=_papi_hwi_eventcode_to_native((int)*EventCode);
1197  retval = _papi_hwd[cidx]->ntv_enum_events((unsigned int *)&event_code, modifier );
1198 
1199  if (retval!=PAPI_OK) {
1200  APIDBG("VMW: retval=%d\n",retval);
1201  return PAPI_EINVAL;
1202  }
1203 
1204  evt_name = _papi_hwi_get_papi_event_string();
1205  *EventCode = _papi_hwi_native_to_eventcode(cidx, event_code, -1, evt_name);
1207 
1208  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1209  return retval;
1210  }
1211 
1212  if ( IS_USER_DEFINED(i) ) {
1213  if (user_defined_events_count == 0) {
1214  APIDBG("EXIT: PAPI_ENOEVNT\n");
1215  return PAPI_ENOEVNT;
1216  }
1217  if ( modifier == PAPI_ENUM_FIRST ) {
1218  *EventCode = (int) (0 | PAPI_UE_MASK);
1219  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1220  return ( PAPI_OK );
1221  }
1222 
1223  i &= PAPI_UE_AND_MASK;
1224  ++i;
1225 
1226  if ( i <= 0 || i >= user_defined_events_count ) {
1227  APIDBG("EXIT: PAPI_ENOEVNT\n");
1228  return ( PAPI_ENOEVNT );
1229  }
1230 
1231  // if next entry does not have an event name, we are done
1232  if (user_defined_events[i].symbol == NULL) {
1233  APIDBG("EXIT: PAPI_ENOEVNT\n");
1234  return ( PAPI_ENOEVNT );
1235  }
1236 
1237  // if next entry does not map to any other events, we are done
1238  if (user_defined_events[i].count == 0) {
1239  APIDBG("EXIT: PAPI_ENOEVNT\n");
1240  return ( PAPI_ENOEVNT );
1241  }
1242 
1243  *EventCode = (int) (i | PAPI_UE_MASK);
1244  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1245  return ( PAPI_OK );
1246  }
1247 
1249 }
1250 
1251 
1356 int
1357 PAPI_enum_cmp_event( int *EventCode, int modifier, int cidx )
1358 {
1359  APIDBG( "Entry: EventCode: %#x, modifier: %d, cidx: %d\n", *EventCode, modifier, cidx);
1360  int i = *EventCode;
1361  int retval;
1362  int event_code;
1363  char *evt_name;
1364 
1365  if ( _papi_hwi_invalid_cmp(cidx) || ( (IS_PRESET(i)) && cidx > 0 ) ) {
1366  return PAPI_ENOCMP;
1367  }
1368 
1369  if (_papi_hwd[cidx]->cmp_info.disabled) {
1370  return PAPI_ENOCMP;
1371  }
1372 
1373  if ( IS_PRESET(i) ) {
1374  if ( modifier == PAPI_ENUM_FIRST ) {
1375  *EventCode = ( int ) PAPI_PRESET_MASK;
1376  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1377  return PAPI_OK;
1378  }
1379  i &= PAPI_PRESET_AND_MASK;
1380  while ( ++i < PAPI_MAX_PRESET_EVENTS ) {
1381  if ( _papi_hwi_presets[i].symbol == NULL ) {
1382  APIDBG("EXIT: PAPI_ENOEVNT\n");
1383  return ( PAPI_ENOEVNT ); /* NULL pointer terminates list */
1384  }
1385  if ( modifier & PAPI_PRESET_ENUM_AVAIL ) {
1386  if ( _papi_hwi_presets[i].count == 0 )
1387  continue;
1388  }
1389  *EventCode = ( int ) ( i | PAPI_PRESET_MASK );
1390  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1391  return PAPI_OK;
1392  }
1394  }
1395 
1396  if ( IS_NATIVE(i) ) {
1397  // save event code so components can get it with call to: _papi_hwi_get_papi_event_code()
1398  _papi_hwi_set_papi_event_code(*EventCode, 0);
1399 
1400  /* Should we check against num native events here? */
1401  event_code=_papi_hwi_eventcode_to_native(*EventCode);
1402  retval = _papi_hwd[cidx]->ntv_enum_events((unsigned int *)&event_code, modifier );
1403 
1404  if (retval!=PAPI_OK) {
1405  APIDBG("EXIT: PAPI_EINVAL retval=%d\n",retval);
1406  return PAPI_EINVAL;
1407  }
1408 
1409  evt_name = _papi_hwi_get_papi_event_string();
1410  *EventCode = _papi_hwi_native_to_eventcode(cidx, event_code, -1, evt_name);
1412 
1413  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1414  return retval;
1415  }
1416 
1418 }
1419 
1463 int
1465 {
1466  APIDBG("Entry: EventSet: %p\n", EventSet);
1467 
1468  ThreadInfo_t *master;
1469  int retval;
1470 
1471  if ( init_level == PAPI_NOT_INITED )
1473  retval = _papi_hwi_lookup_or_create_thread( &master, 0 );
1474  if ( retval )
1475  papi_return( retval );
1476 
1477  papi_return( _papi_hwi_create_eventset( EventSet, master ) );
1478 }
1479 
1525 int
1527 {
1528  EventSetInfo_t *ESI;
1529  int retval;
1530 
1531  ESI = _papi_hwi_lookup_EventSet( EventSet );
1532  if ( ESI == NULL )
1534 
1535 /* validate cidx */
1536  retval = valid_component( cidx );
1537  if ( retval < 0 )
1538  papi_return( retval );
1539 
1540 /* cowardly refuse to reassign eventsets */
1541  if ( ESI->CmpIdx >= 0 )
1542  return PAPI_EINVAL;
1543 
1544  return ( _papi_hwi_assign_eventset( ESI, cidx ) );
1545 }
1546 
1568 int
1570 {
1571  EventSetInfo_t *ESI;
1572  int retval;
1573 
1574 /* validate eventset */
1575  ESI = _papi_hwi_lookup_EventSet( EventSet );
1576  if ( ESI == NULL )
1578 
1579 /* check if a component has been assigned */
1580  if ( ESI->CmpIdx < 0 )
1582 
1583 /* validate CmpIdx */
1584  retval = valid_component( ESI->CmpIdx );
1585  if ( retval < 0 )
1586  papi_return( retval );
1587 
1588 /* return the index */
1589  return ( ESI->CmpIdx );
1590 }
1591 
1592 
1662 int
1663 PAPI_add_event( int EventSet, int EventCode )
1664 {
1665  APIDBG("Entry: EventSet: %d, EventCode: %#x\n", EventSet, EventCode);
1666  EventSetInfo_t *ESI;
1667 
1668  /* Is the EventSet already in existence? */
1669 
1670  ESI = _papi_hwi_lookup_EventSet( EventSet );
1671  if ( ESI == NULL )
1673 
1674  /* Check argument for validity */
1675 
1676  if ( ( ( EventCode & PAPI_PRESET_MASK ) == 0 ) &&
1677  ( EventCode & PAPI_NATIVE_MASK ) == 0 )
1679 
1680  /* Of course, it must be stopped in order to modify it. */
1681 
1682  if ( ESI->state & PAPI_RUNNING )
1684 
1685  /* Now do the magic. */
1686  int retval = _papi_hwi_add_event( ESI, EventCode );
1687  papi_return( retval );
1688 }
1689 
1757 int
1758 PAPI_remove_event( int EventSet, int EventCode )
1759 {
1760  APIDBG("Entry: EventSet: %d, EventCode: %#x\n", EventSet, EventCode);
1761  EventSetInfo_t *ESI;
1762  int i,retval;
1763 
1764  /* check for pre-existing ESI */
1765 
1766  ESI = _papi_hwi_lookup_EventSet( EventSet );
1767  if ( ESI == NULL )
1769 
1770  /* Check argument for validity */
1771 
1772  if ( ( !IS_PRESET(EventCode) ) &&
1773  ( !IS_NATIVE(EventCode) ) &&
1774  ( !IS_USER_DEFINED(EventCode) ))
1776 
1777  /* Of course, it must be stopped in order to modify it. */
1778 
1779  if ( !( ESI->state & PAPI_STOPPED ) )
1781 
1782  /* if the state is PAPI_OVERFLOWING, you must first call
1783  PAPI_overflow with threshold=0 to remove the overflow flag */
1784 
1785  /* Turn off the event that is overflowing */
1786  if ( ESI->state & PAPI_OVERFLOWING ) {
1787  for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
1788  if ( ESI->overflow.EventCode[i] == EventCode ) {
1789  retval = PAPI_overflow( EventSet, EventCode, 0, 0,
1790  ESI->overflow.handler );
1791  if (retval!=PAPI_OK) return retval;
1792  break;
1793  }
1794  }
1795  }
1796 
1797  /* force the user to call PAPI_profil to clear the PAPI_PROFILING flag */
1798  if ( ESI->state & PAPI_PROFILING ) {
1799  for ( i = 0; i < ESI->profile.event_counter; i++ ) {
1800  if ( ESI->profile.EventCode[i] == EventCode ) {
1801  PAPI_sprofil( NULL, 0, EventSet, EventCode, 0, 0 );
1802  break;
1803  }
1804  }
1805  }
1806 
1807  /* Now do the magic. */
1808 
1809  papi_return( _papi_hwi_remove_event( ESI, EventCode ) );
1810 }
1811 
1875 int
1876 PAPI_add_named_event( int EventSet, const char *EventName )
1877 {
1878  APIDBG("Entry: EventSet: %d, EventName: %s\n", EventSet, EventName);
1879 
1880  int ret, code;
1881 
1882  ret = PAPI_event_name_to_code( EventName, &code );
1883  if ( ret != PAPI_OK ) {
1884  APIDBG("EXIT: return: %d\n", ret);
1885  return ret; // do not use papi_return here because if there was an error PAPI_event_name_to_code already reported it
1886  }
1887 
1888  ret = PAPI_add_event( EventSet, code );
1889  APIDBG("EXIT: return: %d\n", ret);
1890  return ret; // do not use papi_return here because if there was an error PAPI_add_event already reported it
1891 }
1892 
1960 int
1961 PAPI_remove_named_event( int EventSet, const char *EventName )
1962 {
1963  APIDBG("Entry: EventSet: %d, EventName: %s\n", EventSet, EventName);
1964  int ret, code;
1965 
1966  ret = PAPI_event_name_to_code( EventName, &code );
1967  if ( ret == PAPI_OK ) ret = PAPI_remove_event( EventSet, code );
1968  papi_return( ret );
1969 
1970 }
1971 
2013 int
2015 {
2016  APIDBG("Entry: EventSet: %p, *EventSet: %d\n", EventSet, *EventSet);
2017 
2018  EventSetInfo_t *ESI;
2019 
2020  /* check for pre-existing ESI */
2021 
2022  if ( EventSet == NULL )
2024 
2025  ESI = _papi_hwi_lookup_EventSet( *EventSet );
2026  if ( ESI == NULL )
2028 
2029  if ( !( ESI->state & PAPI_STOPPED ) )
2031 
2032  if ( ESI->NumberOfEvents )
2034 
2036  *EventSet = PAPI_NULL;
2037 
2038  return PAPI_OK;
2039 }
2040 
2041 /* simply checks for valid EventSet, calls component start() call */
2095 int
2097 {
2098  APIDBG("Entry: EventSet: %d\n", EventSet);
2099 
2100  int is_dirty=0;
2101  int i,retval;
2102  EventSetInfo_t *ESI;
2103  ThreadInfo_t *thread = NULL;
2104  CpuInfo_t *cpu = NULL;
2105  hwd_context_t *context;
2106  int cidx;
2107 
2108  ESI = _papi_hwi_lookup_EventSet( EventSet );
2109  if ( ESI == NULL ) {
2111  }
2112 
2113  APIDBG("EventSet: %p\n", ESI);
2114 
2115  cidx = valid_ESI_component( ESI );
2116  if ( cidx < 0 ) {
2117  papi_return( cidx );
2118  }
2119 
2120  /* only one event set per thread can be running at any time, */
2121  /* so if another event set is running, the user must stop that */
2122  /* event set explicitly */
2123 
2124  /* We used to check and not let multiple events be attached */
2125  /* to the same CPU, but this was unnecessary? */
2126 
2127  thread = ESI->master;
2128  cpu = ESI->CpuInfo;
2129 
2130  if ( thread->running_eventset[cidx] ) {
2131  APIDBG("Thread Running already (Only one active Eventset per component)\n");
2133  }
2134 
2135  /* Check that there are added events */
2136  if ( ESI->NumberOfEvents < 1 ) {
2138  }
2139 
2140  /* If multiplexing is enabled for this eventset,
2141  call John May's code. */
2142 
2143  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2144  retval = MPX_start( ESI->multiplex.mpx_evset );
2145  if ( retval != PAPI_OK ) {
2146  papi_return( retval );
2147  }
2148 
2149  /* Update the state of this EventSet */
2150  ESI->state ^= PAPI_STOPPED;
2151  ESI->state |= PAPI_RUNNING;
2152 
2153  return PAPI_OK;
2154  }
2155 
2156  /* get the context we should use for this event set */
2157  context = _papi_hwi_get_context( ESI, &is_dirty );
2158  if (is_dirty) {
2159  /* we need to reset the context state because it was last used */
2160  /* for some other event set and does not contain the information */
2161  /* for our events. */
2162  retval = _papi_hwd[ESI->CmpIdx]->update_control_state(
2163  ESI->ctl_state,
2164  ESI->NativeInfoArray,
2165  ESI->NativeCount,
2166  context);
2167  if ( retval != PAPI_OK ) {
2168  papi_return( retval );
2169  }
2170 
2171  //update_control_state disturbs the overflow settings so set
2172  //it to initial values again
2173  if ( ESI->overflow.flags & PAPI_OVERFLOW_HARDWARE ) {
2174  for( i = 0; i < ESI->overflow.event_counter; i++ ) {
2175  retval = _papi_hwd[ESI->CmpIdx]->set_overflow( ESI,
2176  ESI->overflow.EventIndex[i],
2177  ESI->overflow.threshold[i] );
2178  if ( retval != PAPI_OK ) {
2179  break;
2180  }
2181  }
2182  }
2183 
2184  /* now that the context contains this event sets information, */
2185  /* make sure the position array in the EventInfoArray is correct */
2186 
2187  /* We have to do this because ->update_control_state() can */
2188  /* in theory re-order the native events out from under us. */
2190 
2191  }
2192 
2193  /* If overflowing is enabled, turn it on */
2194  if ( ( ESI->state & PAPI_OVERFLOWING ) &&
2195  !( ESI->overflow.flags & PAPI_OVERFLOW_HARDWARE ) ) {
2197  NEED_CONTEXT, cidx );
2198  if ( retval != PAPI_OK ) {
2199  papi_return( retval );
2200  }
2201 
2202  /* Update the state of this EventSet and thread */
2203  /* before to avoid races */
2204  ESI->state ^= PAPI_STOPPED;
2205  ESI->state |= PAPI_RUNNING;
2206  /* can not be attached to thread or cpu if overflowing */
2207  thread->running_eventset[cidx] = ESI;
2208 
2209  retval = _papi_hwd[cidx]->start( context, ESI->ctl_state );
2210  if ( retval != PAPI_OK ) {
2212  ESI->state ^= PAPI_RUNNING;
2213  ESI->state |= PAPI_STOPPED;
2214  thread->running_eventset[cidx] = NULL;
2215  papi_return( retval );
2216  }
2217 
2221  if ( retval != PAPI_OK ) {
2223  _papi_hwd[cidx]->stop( context, ESI->ctl_state );
2224  ESI->state ^= PAPI_RUNNING;
2225  ESI->state |= PAPI_STOPPED;
2226  thread->running_eventset[cidx] = NULL;
2227  papi_return( retval );
2228  }
2229  } else {
2230  /* Update the state of this EventSet and thread before */
2231  /* to avoid races */
2232  ESI->state ^= PAPI_STOPPED;
2233  ESI->state |= PAPI_RUNNING;
2234 
2235  /* if not attached to cpu or another process */
2236  if ( !(ESI->state & PAPI_CPU_ATTACHED) ) {
2237  if ( !( ESI->state & PAPI_ATTACHED ) ) {
2238  thread->running_eventset[cidx] = ESI;
2239  }
2240  } else {
2241  cpu->running_eventset[cidx] = ESI;
2242  }
2243 
2244  retval = _papi_hwd[cidx]->start( context, ESI->ctl_state );
2245  if ( retval != PAPI_OK ) {
2246  _papi_hwd[cidx]->stop( context, ESI->ctl_state );
2247  ESI->state ^= PAPI_RUNNING;
2248  ESI->state |= PAPI_STOPPED;
2249  if ( !(ESI->state & PAPI_CPU_ATTACHED) ) {
2250  if ( !( ESI->state & PAPI_ATTACHED ) )
2251  thread->running_eventset[cidx] = NULL;
2252  } else {
2253  cpu->running_eventset[cidx] = NULL;
2254  }
2255  papi_return( retval );
2256  }
2257  }
2258 
2259  return retval;
2260 }
2261 
2262 /* checks for valid EventSet, calls component stop() function. */
2313 int
2314 PAPI_stop( int EventSet, long long *values )
2315 {
2316  APIDBG("Entry: EventSet: %d, values: %p\n", EventSet, values);
2317  EventSetInfo_t *ESI;
2318  hwd_context_t *context;
2319  int cidx, retval;
2320 
2321  ESI = _papi_hwi_lookup_EventSet( EventSet );
2322  if ( ESI == NULL )
2324 
2325  cidx = valid_ESI_component( ESI );
2326  if ( cidx < 0 )
2327  papi_return( cidx );
2328 
2329  if ( !( ESI->state & PAPI_RUNNING ) )
2331 
2332  /* If multiplexing is enabled for this eventset, turn if off */
2333 
2334  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2335  retval = MPX_stop( ESI->multiplex.mpx_evset, values );
2336  if ( retval != PAPI_OK )
2337  papi_return( retval );
2338 
2339  /* Update the state of this EventSet */
2340 
2341  ESI->state ^= PAPI_RUNNING;
2342  ESI->state |= PAPI_STOPPED;
2343 
2344  return ( PAPI_OK );
2345  }
2346 
2347  /* get the context we should use for this event set */
2348  context = _papi_hwi_get_context( ESI, NULL );
2349  /* Read the current counter values into the EventSet */
2350  retval = _papi_hwi_read( context, ESI, ESI->sw_stop );
2351  if ( retval != PAPI_OK )
2352  papi_return( retval );
2353 
2354  /* Remove the control bits from the active counter config. */
2355  retval = _papi_hwd[cidx]->stop( context, ESI->ctl_state );
2356  if ( retval != PAPI_OK )
2357  papi_return( retval );
2358  if ( values )
2359  memcpy( values, ESI->sw_stop,
2360  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2361 
2362  /* If kernel profiling is in use, flush and process the kernel buffer */
2363 
2364  if ( ESI->state & PAPI_PROFILING ) {
2365  if ( _papi_hwd[cidx]->cmp_info.kernel_profile &&
2366  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
2367  retval = _papi_hwd[cidx]->stop_profiling( ESI->master, ESI );
2368  if ( retval < PAPI_OK )
2369  papi_return( retval );
2370  }
2371  }
2372 
2373  /* If overflowing is enabled, turn it off */
2374 
2375  if ( ESI->state & PAPI_OVERFLOWING ) {
2376  if ( !( ESI->overflow.flags & PAPI_OVERFLOW_HARDWARE ) ) {
2379  if ( retval != PAPI_OK )
2380  papi_return( retval );
2382  }
2383  }
2384 
2385  /* Update the state of this EventSet */
2386 
2387  ESI->state ^= PAPI_RUNNING;
2388  ESI->state |= PAPI_STOPPED;
2389 
2390  /* Update the running event set for this thread */
2391  if ( !(ESI->state & PAPI_CPU_ATTACHED) ) {
2392  if ( !( ESI->state & PAPI_ATTACHED ))
2393  ESI->master->running_eventset[cidx] = NULL;
2394  } else {
2395  ESI->CpuInfo->running_eventset[cidx] = NULL;
2396  }
2397 
2398 #if defined(DEBUG)
2399  if ( _papi_hwi_debug & DEBUG_API ) {
2400  int i;
2401  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2402  APIDBG( "PAPI_stop ESI->sw_stop[%d]:\t%llu\n", i, ESI->sw_stop[i] );
2403  }
2404  }
2405 #endif
2406 
2407  return ( PAPI_OK );
2408 }
2409 
2458 int
2460 {
2461  APIDBG("Entry: EventSet: %d\n", EventSet);
2462  int retval = PAPI_OK;
2463  EventSetInfo_t *ESI;
2464  hwd_context_t *context;
2465  int cidx;
2466 
2467  ESI = _papi_hwi_lookup_EventSet( EventSet );
2468  if ( ESI == NULL )
2470 
2471  cidx = valid_ESI_component( ESI );
2472  if ( cidx < 0 )
2473  papi_return( cidx );
2474 
2475  if ( ESI->state & PAPI_RUNNING ) {
2476  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2477  retval = MPX_reset( ESI->multiplex.mpx_evset );
2478  } else {
2479  /* If we're not the only one running, then just
2480  read the current values into the ESI->start
2481  array. This holds the starting value for counters
2482  that are shared. */
2483  /* get the context we should use for this event set */
2484  context = _papi_hwi_get_context( ESI, NULL );
2485  retval = _papi_hwd[cidx]->reset( context, ESI->ctl_state );
2486  }
2487  } else {
2488 #ifdef __bgp__
2489  // For BG/P, we always want to reset the 'real' hardware counters. The counters
2490  // can be controlled via multiple interfaces, and we need to ensure that the values
2491  // are truly zero...
2492  /* get the context we should use for this event set */
2493  context = _papi_hwi_get_context( ESI, NULL );
2494  retval = _papi_hwd[cidx]->reset( context, ESI->ctl_state );
2495 #endif
2496  memset( ESI->sw_stop, 0x00,
2497  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2498  }
2499 
2500  APIDBG( "EXIT: retval %d\n", retval );
2501  papi_return( retval );
2502 }
2503 
2558 int
2559 PAPI_read( int EventSet, long long *values )
2560 {
2561  APIDBG( "Entry: EventSet: %d, values: %p\n", EventSet, values);
2562  EventSetInfo_t *ESI;
2563  hwd_context_t *context;
2564  int cidx, retval = PAPI_OK;
2565 
2566  ESI = _papi_hwi_lookup_EventSet( EventSet );
2567  if ( ESI == NULL )
2569 
2570  cidx = valid_ESI_component( ESI );
2571  if ( cidx < 0 )
2572  papi_return( cidx );
2573 
2574  if ( values == NULL )
2576 
2577  if ( ESI->state & PAPI_RUNNING ) {
2578  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2579  retval = MPX_read( ESI->multiplex.mpx_evset, values, 0 );
2580  } else {
2581  /* get the context we should use for this event set */
2582  context = _papi_hwi_get_context( ESI, NULL );
2583  retval = _papi_hwi_read( context, ESI, values );
2584  }
2585  if ( retval != PAPI_OK )
2586  papi_return( retval );
2587  } else {
2588  memcpy( values, ESI->sw_stop,
2589  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2590  }
2591 
2592 #if defined(DEBUG)
2593  if ( ISLEVEL( DEBUG_API ) ) {
2594  int i;
2595  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2596  APIDBG( "PAPI_read values[%d]:\t%lld\n", i, values[i] );
2597  }
2598  }
2599 #endif
2600 
2601  APIDBG( "PAPI_read returns %d\n", retval );
2602  return ( PAPI_OK );
2603 }
2604 
2647 int
2648 PAPI_read_ts( int EventSet, long long *values, long long *cycles )
2649 {
2650  APIDBG( "Entry: EventSet: %d, values: %p, cycles: %p\n", EventSet, values, cycles);
2651  EventSetInfo_t *ESI;
2652  hwd_context_t *context;
2653  int cidx, retval = PAPI_OK;
2654 
2655  ESI = _papi_hwi_lookup_EventSet( EventSet );
2656  if ( ESI == NULL )
2658 
2659  cidx = valid_ESI_component( ESI );
2660  if ( cidx < 0 )
2661  papi_return( cidx );
2662 
2663  if ( values == NULL )
2665 
2666  if ( ESI->state & PAPI_RUNNING ) {
2667  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2668  retval = MPX_read( ESI->multiplex.mpx_evset, values, 0 );
2669  } else {
2670  /* get the context we should use for this event set */
2671  context = _papi_hwi_get_context( ESI, NULL );
2672  retval = _papi_hwi_read( context, ESI, values );
2673  }
2674  if ( retval != PAPI_OK )
2675  papi_return( retval );
2676  } else {
2677  memcpy( values, ESI->sw_stop,
2678  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2679  }
2680 
2681  *cycles = _papi_os_vector.get_real_cycles( );
2682 
2683 #if defined(DEBUG)
2684  if ( ISLEVEL( DEBUG_API ) ) {
2685  int i;
2686  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2687  APIDBG( "PAPI_read values[%d]:\t%lld\n", i, values[i] );
2688  }
2689  }
2690 #endif
2691 
2692  APIDBG( "PAPI_read_ts returns %d\n", retval );
2693  return PAPI_OK;
2694 }
2695 
2744 int
2745 PAPI_accum( int EventSet, long long *values )
2746 {
2747  APIDBG("Entry: EventSet: %d, values: %p\n", EventSet, values);
2748  EventSetInfo_t *ESI;
2749  hwd_context_t *context;
2750  int i, cidx, retval;
2751  long long a, b, c;
2752 
2753  ESI = _papi_hwi_lookup_EventSet( EventSet );
2754  if ( ESI == NULL )
2756 
2757  cidx = valid_ESI_component( ESI );
2758  if ( cidx < 0 )
2759  papi_return( cidx );
2760 
2761  if ( values == NULL )
2763 
2764  if ( ESI->state & PAPI_RUNNING ) {
2765  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2766  retval = MPX_read( ESI->multiplex.mpx_evset, ESI->sw_stop, 0 );
2767  } else {
2768  /* get the context we should use for this event set */
2769  context = _papi_hwi_get_context( ESI, NULL );
2770  retval = _papi_hwi_read( context, ESI, ESI->sw_stop );
2771  }
2772  if ( retval != PAPI_OK )
2773  papi_return( retval );
2774  }
2775 
2776  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2777  a = ESI->sw_stop[i];
2778  b = values[i];
2779  c = a + b;
2780  values[i] = c;
2781  }
2782 
2783  papi_return( PAPI_reset( EventSet ) );
2784 }
2785 
2812 int
2813 PAPI_write( int EventSet, long long *values )
2814 {
2815  APIDBG("Entry: EventSet: %d, values: %p\n", EventSet, values);
2816 
2817  int cidx, retval = PAPI_OK;
2818  EventSetInfo_t *ESI;
2819  hwd_context_t *context;
2820 
2821  ESI = _papi_hwi_lookup_EventSet( EventSet );
2822  if ( ESI == NULL )
2824 
2825  cidx = valid_ESI_component( ESI );
2826  if ( cidx < 0 )
2827  papi_return( cidx );
2828 
2829  if ( values == NULL )
2831 
2832  if ( ESI->state & PAPI_RUNNING ) {
2833  /* get the context we should use for this event set */
2834  context = _papi_hwi_get_context( ESI, NULL );
2835  retval = _papi_hwd[cidx]->write( context, ESI->ctl_state, values );
2836  if ( retval != PAPI_OK )
2837  return ( retval );
2838  }
2839 
2840  memcpy( ESI->hw_start, values,
2841  ( size_t ) _papi_hwd[cidx]->cmp_info.num_cntrs *
2842  sizeof ( long long ) );
2843 
2844  return ( retval );
2845 }
2846 
2889 int
2891 {
2892  APIDBG("Entry: EventSet: %d\n",EventSet);
2893 
2894  EventSetInfo_t *ESI;
2895  int i, cidx, total, retval;
2896 
2897  /* Is the EventSet already in existence? */
2898 
2899  ESI = _papi_hwi_lookup_EventSet( EventSet );
2900  if ( ESI == NULL )
2902 
2903  /* if the eventset has no index and no events, return OK
2904  otherwise return NOCMP */
2905  cidx = valid_ESI_component( ESI );
2906  if ( cidx < 0 ) {
2907  if ( ESI->NumberOfEvents )
2908  papi_return( cidx );
2909  papi_return( PAPI_OK );
2910  }
2911 
2912  /* Of course, it must be stopped in order to modify it. */
2913 
2914  if ( ESI->state & PAPI_RUNNING )
2916 
2917  /* clear overflow flag and turn off hardware overflow handler */
2918  if ( ESI->state & PAPI_OVERFLOWING ) {
2919  total = ESI->overflow.event_counter;
2920  for ( i = 0; i < total; i++ ) {
2921  retval = PAPI_overflow( EventSet,
2922  ESI->overflow.EventCode[0], 0, 0, NULL );
2923  if ( retval != PAPI_OK )
2924  papi_return( retval );
2925  }
2926  }
2927 
2928  /* clear profile flag and turn off hardware profile handler */
2929  if ( ( ESI->state & PAPI_PROFILING ) &&
2930  _papi_hwd[cidx]->cmp_info.hardware_intr &&
2931  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
2932  total = ESI->profile.event_counter;
2933  for ( i = 0; i < total; i++ ) {
2934  retval =
2935  PAPI_sprofil( NULL, 0, EventSet, ESI->profile.EventCode[0], 0,
2937  if ( retval != PAPI_OK )
2938  papi_return( retval );
2939  }
2940  }
2941 
2942  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2943  retval = MPX_cleanup( &ESI->multiplex.mpx_evset );
2944  if ( retval != PAPI_OK )
2945  papi_return( retval );
2946  }
2947 
2948  retval = _papi_hwd[cidx]->cleanup_eventset( ESI->ctl_state );
2949  if ( retval != PAPI_OK )
2950  papi_return( retval );
2951 
2952  /* Now do the magic */
2954 }
2955 
2981 int
2983 {
2984  APIDBG("Entry:\n");
2985 
2986  int retval;
2987 
2988  retval = mpx_init( _papi_os_info.itimer_ns );
2989  papi_return( retval );
2990 }
2991 
3052 int
3054 {
3055  APIDBG("Entry: EventSet: %d, status: %p\n", EventSet, status);
3056 
3057  EventSetInfo_t *ESI;
3058 
3059  if ( status == NULL )
3061 
3062  /* check for good EventSetIndex value */
3063 
3064  ESI = _papi_hwi_lookup_EventSet( EventSet );
3065  if ( ESI == NULL )
3067 
3068  /*read status FROM ESI->state */
3069 
3070  *status = ESI->state;
3071 
3072  return ( PAPI_OK );
3073 }
3074 
3125 int
3126 PAPI_set_debug( int level )
3127 {
3128  APIDBG("Entry: level: %d\n", level);
3129  PAPI_option_t option;
3130 
3131  memset( &option, 0x0, sizeof ( option ) );
3132  option.debug.level = level;
3134  return ( PAPI_set_opt( PAPI_DEBUG, &option ) );
3135 }
3136 
3137 /* Attaches to or detaches from the specified thread id */
3138 inline_static int
3139 _papi_set_attach( int option, int EventSet, unsigned long tid )
3140 {
3141  APIDBG("Entry: option: %d, EventSet: %d, tid: %lu\n", option, EventSet, tid);
3143 
3144  memset( &attach, 0x0, sizeof ( attach ) );
3145  attach.attach.eventset = EventSet;
3146  attach.attach.tid = tid;
3147  return ( PAPI_set_opt( option, &attach ) );
3148 }
3149 
3200 int
3201 PAPI_attach( int EventSet, unsigned long tid )
3202 {
3203  APIDBG( "Entry: EventSet: %d, tid: %lu\n", EventSet, tid);
3204  return ( _papi_set_attach( PAPI_ATTACH, EventSet, tid ) );
3205 }
3206 
3257 int
3259 {
3260  APIDBG( "Entry: EventSet: %d\n", EventSet);
3261  return ( _papi_set_attach( PAPI_DETACH, EventSet, 0 ) );
3262 }
3263 
3332 int
3334 {
3335  APIDBG( "Entry: EventSet: %d\n", EventSet);
3336 
3337  PAPI_option_t mpx;
3338  EventSetInfo_t *ESI;
3339  int cidx;
3340  int ret;
3341 
3342  /* Is the EventSet already in existence? */
3343 
3344  ESI = _papi_hwi_lookup_EventSet( EventSet );
3345 
3346  if ( ESI == NULL )
3348 
3349  /* if the eventset has no index return NOCMP */
3350  cidx = valid_ESI_component( ESI );
3351  if ( cidx < 0 )
3352  papi_return( cidx );
3353 
3354  if ( ( ret = mpx_check( EventSet ) ) != PAPI_OK )
3355  papi_return( ret );
3356 
3357  memset( &mpx, 0x0, sizeof ( mpx ) );
3358  mpx.multiplex.eventset = EventSet;
3361  return ( PAPI_set_opt( PAPI_MULTIPLEX, &mpx ) );
3362 }
3363 
3464 int
3466 {
3467  APIDBG("Entry: option: %d, ptr: %p\n", option, ptr);
3468 
3469  _papi_int_option_t internal;
3470  int retval = PAPI_OK;
3471  hwd_context_t *context;
3472  int cidx;
3473 
3474  if ( ( option != PAPI_DEBUG ) && ( init_level == PAPI_NOT_INITED ) )
3476  if ( ptr == NULL )
3478 
3479  memset( &internal, 0x0, sizeof ( _papi_int_option_t ) );
3480 
3481  switch ( option ) {
3482  case PAPI_DETACH:
3483  {
3484  internal.attach.ESI = _papi_hwi_lookup_EventSet( ptr->attach.eventset );
3485  if ( internal.attach.ESI == NULL )
3487 
3488  cidx = valid_ESI_component( internal.attach.ESI );
3489  if ( cidx < 0 )
3490  papi_return( cidx );
3491 
3492  if ( _papi_hwd[cidx]->cmp_info.attach == 0 )
3494 
3495  /* if attached to a cpu, return an error */
3496  if (internal.attach.ESI->state & PAPI_CPU_ATTACHED)
3498 
3499  if ( ( internal.attach.ESI->state & PAPI_STOPPED ) == 0 )
3501 
3502  if ( ( internal.attach.ESI->state & PAPI_ATTACHED ) == 0 )
3504 
3505  internal.attach.tid = internal.attach.ESI->attach.tid;
3506  /* get the context we should use for this event set */
3507  context = _papi_hwi_get_context( internal.attach.ESI, NULL );
3508  retval = _papi_hwd[cidx]->ctl( context, PAPI_DETACH, &internal );
3509  if ( retval != PAPI_OK )
3510  papi_return( retval );
3511 
3512  internal.attach.ESI->state ^= PAPI_ATTACHED;
3513  internal.attach.ESI->attach.tid = 0;
3514  return ( PAPI_OK );
3515  }
3516  case PAPI_ATTACH:
3517  {
3518  internal.attach.ESI = _papi_hwi_lookup_EventSet( ptr->attach.eventset );
3519  if ( internal.attach.ESI == NULL )
3521 
3522  cidx = valid_ESI_component( internal.attach.ESI );
3523  if ( cidx < 0 )
3524  papi_return( cidx );
3525 
3526  if ( _papi_hwd[cidx]->cmp_info.attach == 0 )
3528 
3529  if ( ( internal.attach.ESI->state & PAPI_STOPPED ) == 0 )
3531 
3532  if ( internal.attach.ESI->state & PAPI_ATTACHED )
3534 
3535  /* if attached to a cpu, return an error */
3536  if (internal.attach.ESI->state & PAPI_CPU_ATTACHED)
3538 
3539  internal.attach.tid = ptr->attach.tid;
3540  /* get the context we should use for this event set */
3541  context = _papi_hwi_get_context( internal.attach.ESI, NULL );
3542  retval = _papi_hwd[cidx]->ctl( context, PAPI_ATTACH, &internal );
3543  if ( retval != PAPI_OK )
3544  papi_return( retval );
3545 
3546  internal.attach.ESI->state |= PAPI_ATTACHED;
3547  internal.attach.ESI->attach.tid = ptr->attach.tid;
3548 
3550  &(internal.attach.ESI->master), ptr->attach.tid ));
3551  }
3552  case PAPI_CPU_ATTACH:
3553  {
3554  APIDBG("eventset: %d, cpu_num: %d\n", ptr->cpu.eventset, ptr->cpu.cpu_num);
3555  internal.cpu.ESI = _papi_hwi_lookup_EventSet( ptr->cpu.eventset );
3556  if ( internal.cpu.ESI == NULL )
3558 
3559  internal.cpu.cpu_num = ptr->cpu.cpu_num;
3560  APIDBG("internal: %p, ESI: %p, cpu_num: %d\n", &internal, internal.cpu.ESI, internal.cpu.cpu_num);
3561 
3562  cidx = valid_ESI_component( internal.cpu.ESI );
3563  if ( cidx < 0 )
3564  papi_return( cidx );
3565 
3566  if ( _papi_hwd[cidx]->cmp_info.cpu == 0 )
3568 
3569  // can not attach to a cpu if already attached to a process or
3570  // counters set to be inherited by child processes
3571  if ( internal.cpu.ESI->state & (PAPI_ATTACHED | PAPI_INHERIT) )
3573 
3574  if ( ( internal.cpu.ESI->state & PAPI_STOPPED ) == 0 )
3576 
3577  retval = _papi_hwi_lookup_or_create_cpu(&internal.cpu.ESI->CpuInfo, internal.cpu.cpu_num);
3578  if( retval != PAPI_OK) {
3579  papi_return( retval );
3580  }
3581 
3582  /* get the context we should use for this event set */
3583  context = _papi_hwi_get_context( internal.cpu.ESI, NULL );
3584  retval = _papi_hwd[cidx]->ctl( context, PAPI_CPU_ATTACH, &internal );
3585  if ( retval != PAPI_OK )
3586  papi_return( retval );
3587 
3588  /* set to show this event set is attached to a cpu not a thread */
3589  internal.cpu.ESI->state |= PAPI_CPU_ATTACHED;
3590  return ( PAPI_OK );
3591  }
3592  case PAPI_DEF_MPX_NS:
3593  {
3594  cidx = 0; /* xxxx for now, assume we only check against cpu component */
3595  if ( ptr->multiplex.ns < 0 )
3597  /* We should check the resolution here with the system, either
3598  component if kernel multiplexing or PAPI if SW multiplexing. */
3599  internal.multiplex.ns = ( unsigned long ) ptr->multiplex.ns;
3600  /* get the context we should use for this event set */
3601  context = _papi_hwi_get_context( internal.cpu.ESI, NULL );
3602  /* Low level just checks/adjusts the args for this component */
3603  retval = _papi_hwd[cidx]->ctl( context, PAPI_DEF_MPX_NS, &internal );
3604  if ( retval == PAPI_OK ) {
3605  _papi_os_info.itimer_ns = ( int ) internal.multiplex.ns;
3606  ptr->multiplex.ns = ( int ) internal.multiplex.ns;
3607  }
3608  papi_return( retval );
3609  }
3610  case PAPI_DEF_ITIMER_NS:
3611  {
3612  cidx = 0; /* xxxx for now, assume we only check against cpu component */
3613  if ( ptr->itimer.ns < 0 )
3615  internal.itimer.ns = ptr->itimer.ns;
3616  /* Low level just checks/adjusts the args for this component */
3617  retval = _papi_hwd[cidx]->ctl( NULL, PAPI_DEF_ITIMER_NS, &internal );
3618  if ( retval == PAPI_OK ) {
3619  _papi_os_info.itimer_ns = internal.itimer.ns;
3620  ptr->itimer.ns = internal.itimer.ns;
3621  }
3622  papi_return( retval );
3623  }
3624  case PAPI_DEF_ITIMER:
3625  {
3626  cidx = 0; /* xxxx for now, assume we only check against cpu component */
3627  if ( ptr->itimer.ns < 0 )
3629  memcpy( &internal.itimer, &ptr->itimer,
3631  /* Low level just checks/adjusts the args for this component */
3632  retval = _papi_hwd[cidx]->ctl( NULL, PAPI_DEF_ITIMER, &internal );
3633  if ( retval == PAPI_OK ) {
3636  if ( ptr->itimer.ns > 0 )
3638  /* flags are currently ignored, eventually the flags will be able
3639  to specify whether or not we use POSIX itimers (clock_gettimer) */
3640  }
3641  papi_return( retval );
3642  }
3643  case PAPI_MULTIPLEX:
3644  {
3645  EventSetInfo_t *ESI;
3647 
3648  if ( ESI == NULL )
3650 
3651  cidx = valid_ESI_component( ESI );
3652  if ( cidx < 0 )
3653  papi_return( cidx );
3654 
3655  if ( !( ESI->state & PAPI_STOPPED ) )
3657  if ( ESI->state & PAPI_MULTIPLEXING )
3659 
3660  if ( ptr->multiplex.ns < 0 )
3662  internal.multiplex.ESI = ESI;
3663  internal.multiplex.ns = ( unsigned long ) ptr->multiplex.ns;
3664  internal.multiplex.flags = ptr->multiplex.flags;
3665  if ( ( _papi_hwd[cidx]->cmp_info.kernel_multiplex ) &&
3666  ( ( ptr->multiplex.flags & PAPI_MULTIPLEX_FORCE_SW ) == 0 ) ) {
3667  /* get the context we should use for this event set */
3668  context = _papi_hwi_get_context( ESI, NULL );
3669  retval = _papi_hwd[cidx]->ctl( context, PAPI_MULTIPLEX, &internal );
3670  }
3671  /* Kernel or PAPI may have changed this value so send it back out to the user */
3672  ptr->multiplex.ns = ( int ) internal.multiplex.ns;
3673  if ( retval == PAPI_OK )
3675  ( &internal.multiplex ) );
3676  return ( retval );
3677  }
3678  case PAPI_DEBUG:
3679  {
3680  int level = ptr->debug.level;
3681  switch ( level ) {
3682  case PAPI_QUIET:
3683  case PAPI_VERB_ESTOP:
3684  case PAPI_VERB_ECONT:
3685  _papi_hwi_error_level = level;
3686  break;
3687  default:
3689  }
3691  return ( PAPI_OK );
3692  }
3693  case PAPI_DEFDOM:
3694  {
3695  int dom = ptr->defdomain.domain;
3696  if ( ( dom < PAPI_DOM_MIN ) || ( dom > PAPI_DOM_MAX ) )
3698 
3699  /* Change the global structure. The _papi_hwd_init_control_state function
3700  in the components gets information from the global structure instead of
3701  per-thread information. */
3702  cidx = valid_component( ptr->defdomain.def_cidx );
3703  if ( cidx < 0 )
3704  papi_return( cidx );
3705 
3706  /* Check what the component supports */
3707 
3708  if ( dom == PAPI_DOM_ALL )
3710 
3711  if ( dom & ~_papi_hwd[cidx]->cmp_info.available_domains )
3713 
3715 
3716  return ( PAPI_OK );
3717  }
3718  case PAPI_DOMAIN:
3719  {
3720  int dom = ptr->domain.domain;
3721  if ( ( dom < PAPI_DOM_MIN ) || ( dom > PAPI_DOM_MAX ) )
3723 
3724  internal.domain.ESI = _papi_hwi_lookup_EventSet( ptr->domain.eventset );
3725  if ( internal.domain.ESI == NULL )
3727 
3728  cidx = valid_ESI_component( internal.domain.ESI );
3729  if ( cidx < 0 )
3730  papi_return( cidx );
3731 
3732  /* Check what the component supports */
3733 
3734  if ( dom == PAPI_DOM_ALL )
3736 
3737  if ( dom & ~_papi_hwd[cidx]->cmp_info.available_domains )
3739 
3740  if ( !( internal.domain.ESI->state & PAPI_STOPPED ) )
3742 
3743  /* Try to change the domain of the eventset in the hardware */
3744  internal.domain.domain = dom;
3745  internal.domain.eventset = ptr->domain.eventset;
3746  /* get the context we should use for this event set */
3747  context = _papi_hwi_get_context( internal.domain.ESI, NULL );
3748  retval = _papi_hwd[cidx]->ctl( context, PAPI_DOMAIN, &internal );
3749  if ( retval < PAPI_OK )
3750  papi_return( retval );
3751 
3752  /* Change the domain of the eventset in the library */
3753 
3754  internal.domain.ESI->domain.domain = dom;
3755 
3756  return ( retval );
3757  }
3758  case PAPI_DEFGRN:
3759  {
3760  int grn = ptr->defgranularity.granularity;
3761  if ( ( grn < PAPI_GRN_MIN ) || ( grn > PAPI_GRN_MAX ) )
3763 
3764  cidx = valid_component( ptr->defgranularity.def_cidx );
3765  if ( cidx < 0 )
3766  papi_return( cidx );
3767 
3768  /* Change the component structure. The _papi_hwd_init_control_state function
3769  in the components gets information from the global structure instead of
3770  per-thread information. */
3771 
3772  /* Check what the component supports */
3773 
3774  if ( grn & ~_papi_hwd[cidx]->cmp_info.available_granularities )
3776 
3777  /* Make sure there is only 1 set. */
3778  if ( grn ^ ( 1 << ( ffs( grn ) - 1 ) ) )
3780 
3782 
3783  return ( PAPI_OK );
3784  }
3785  case PAPI_GRANUL:
3786  {
3787  int grn = ptr->granularity.granularity;
3788 
3789  if ( ( grn < PAPI_GRN_MIN ) || ( grn > PAPI_GRN_MAX ) )
3791 
3792  internal.granularity.ESI =
3794  if ( internal.granularity.ESI == NULL )
3796 
3797  cidx = valid_ESI_component( internal.granularity.ESI );
3798  if ( cidx < 0 )
3799  papi_return( cidx );
3800 
3801  /* Check what the component supports */
3802 
3803  if ( grn & ~_papi_hwd[cidx]->cmp_info.available_granularities )
3805 
3806  /* Make sure there is only 1 set. */
3807  if ( grn ^ ( 1 << ( ffs( grn ) - 1 ) ) )
3809 
3810  internal.granularity.granularity = grn;
3811  internal.granularity.eventset = ptr->granularity.eventset;
3812  retval = _papi_hwd[cidx]->ctl( NULL, PAPI_GRANUL, &internal );
3813  if ( retval < PAPI_OK )
3814  return ( retval );
3815 
3816  internal.granularity.ESI->granularity.granularity = grn;
3817  return ( retval );
3818  }
3819  case PAPI_INHERIT:
3820  {
3821  EventSetInfo_t *ESI;
3823  if ( ESI == NULL )
3825 
3826  cidx = valid_ESI_component( ESI );
3827  if ( cidx < 0 )
3828  papi_return( cidx );
3829 
3830  if ( _papi_hwd[cidx]->cmp_info.inherit == 0 )
3832 
3833  if ( ( ESI->state & PAPI_STOPPED ) == 0 )
3835 
3836  /* if attached to a cpu, return an error */
3837  if (ESI->state & PAPI_CPU_ATTACHED)
3839 
3840  internal.inherit.ESI = ESI;
3841  internal.inherit.inherit = ptr->inherit.inherit;
3842 
3843  /* get the context we should use for this event set */
3844  context = _papi_hwi_get_context( internal.inherit.ESI, NULL );
3845  retval = _papi_hwd[cidx]->ctl( context, PAPI_INHERIT, &internal );
3846  if ( retval < PAPI_OK )
3847  return ( retval );
3848 
3849  ESI->inherit.inherit = ptr->inherit.inherit;
3850  return ( retval );
3851  }
3852  case PAPI_DATA_ADDRESS:
3853  case PAPI_INSTR_ADDRESS:
3854  {
3855 
3856  EventSetInfo_t *ESI;
3857 
3858  ESI = _papi_hwi_lookup_EventSet( ptr->addr.eventset );
3859  if ( ESI == NULL )
3861 
3862  cidx = valid_ESI_component( ESI );
3863  if ( cidx < 0 )
3864  papi_return( cidx );
3865 
3866  internal.address_range.ESI = ESI;
3867 
3868  if ( !( internal.address_range.ESI->state & PAPI_STOPPED ) )
3870 
3871  /*set domain to be PAPI_DOM_USER */
3872  internal.address_range.domain = PAPI_DOM_USER;
3873 
3874  internal.address_range.start = ptr->addr.start;
3875  internal.address_range.end = ptr->addr.end;
3876  /* get the context we should use for this event set */
3877  context = _papi_hwi_get_context( internal.address_range.ESI, NULL );
3878  retval = _papi_hwd[cidx]->ctl( context, option, &internal );
3879  ptr->addr.start_off = internal.address_range.start_off;
3880  ptr->addr.end_off = internal.address_range.end_off;
3881  papi_return( retval );
3882  }
3883  case PAPI_USER_EVENTS_FILE:
3884  {
3885  APIDBG("User Events Filename is -%s-\n", ptr->events_file);
3886 
3887  // go load the user defined event definitions from the applications event definition file
3888  // do not know how to find a pmu name and type for this operation yet
3889 // retval = papi_load_derived_events(pmu_str, pmu_type, cidx, 0);
3890 
3891 // _papi_user_defined_events_setup(ptr->events_file);
3892  return( PAPI_OK );
3893  }
3894  default:
3896  }
3897 }
3898 
3908 int
3910 {
3911  APIDBG( "Entry:\n");
3912  return ( PAPI_num_cmp_hwctrs( 0 ) );
3913 }
3914 
3964 int
3966 {
3967  APIDBG( "Entry: cidx: %d\n", cidx);
3968  return ( PAPI_get_cmp_opt( PAPI_MAX_HWCTRS, NULL, cidx ) );
3969 }
3970 
4027 int
4029 {
4030  APIDBG( "Entry: EventSet: %d\n", EventSet);
4031  PAPI_option_t popt;
4032  int retval;
4033 
4034  popt.multiplex.eventset = EventSet;
4035  retval = PAPI_get_opt( PAPI_MULTIPLEX, &popt );
4036  if ( retval < 0 )
4037  retval = 0;
4038  return retval;
4039 }
4040 
4142 int
4144 {
4145  APIDBG( "Entry: option: %d, ptr: %p\n", option, ptr);
4146  EventSetInfo_t *ESI;
4147 
4148  if ( ( option != PAPI_DEBUG ) && ( init_level == PAPI_NOT_INITED ) )
4150 
4151  switch ( option ) {
4152  case PAPI_DETACH:
4153  {
4154  if ( ptr == NULL )
4157  if ( ESI == NULL )
4159  ptr->attach.tid = ESI->attach.tid;
4160  return ( ( ESI->state & PAPI_ATTACHED ) == 0 );
4161  }
4162  case PAPI_ATTACH:
4163  {
4164  if ( ptr == NULL )
4167  if ( ESI == NULL )
4169  ptr->attach.tid = ESI->attach.tid;
4170  return ( ( ESI->state & PAPI_ATTACHED ) != 0 );
4171  }
4172  case PAPI_CPU_ATTACH:
4173  {
4174  if ( ptr == NULL )
4177  if ( ESI == NULL )
4179  ptr->cpu.cpu_num = ESI->CpuInfo->cpu_num;
4180  return ( ( ESI->state & PAPI_CPU_ATTACHED ) != 0 );
4181  }
4182  case PAPI_DEF_MPX_NS:
4183  {
4184  /* xxxx for now, assume we only check against cpu component */
4185  if ( ptr == NULL )
4188  return ( PAPI_OK );
4189  }
4190  case PAPI_DEF_ITIMER_NS:
4191  {
4192  /* xxxx for now, assume we only check against cpu component */
4193  if ( ptr == NULL )
4196  return ( PAPI_OK );
4197  }
4198  case PAPI_DEF_ITIMER:
4199  {
4200  /* xxxx for now, assume we only check against cpu component */
4201  if ( ptr == NULL )
4206  ptr->itimer.flags = 0;
4207  return ( PAPI_OK );
4208  }
4209  case PAPI_MULTIPLEX:
4210  {
4211  if ( ptr == NULL )
4214  if ( ESI == NULL )
4216  ptr->multiplex.ns = ESI->multiplex.ns;
4217  ptr->multiplex.flags = ESI->multiplex.flags;
4218  return ( ESI->state & PAPI_MULTIPLEXING ) != 0;
4219  }
4220  case PAPI_PRELOAD:
4221  if ( ptr == NULL )
4223  memcpy( &ptr->preload, &_papi_hwi_system_info.preload_info,
4225  break;
4226  case PAPI_DEBUG:
4227  if ( ptr == NULL )
4231  break;
4232  case PAPI_CLOCKRATE:
4233  return ( ( int ) _papi_hwi_system_info.hw_info.cpu_max_mhz );
4234  case PAPI_MAX_CPUS:
4235  return ( _papi_hwi_system_info.hw_info.ncpu );
4236  /* For now, MAX_HWCTRS and MAX CTRS are identical.
4237  At some future point, they may map onto different values.
4238  */
4239  case PAPI_INHERIT:
4240  {
4241  if ( ptr == NULL )
4244  if ( ESI == NULL )
4246  ptr->inherit.inherit = ESI->inherit.inherit;
4247  return ( PAPI_OK );
4248  }
4249  case PAPI_GRANUL:
4250  if ( ptr == NULL )
4253  if ( ESI == NULL )
4256  break;
4257  case PAPI_EXEINFO:
4258  if ( ptr == NULL )
4261  break;
4262  case PAPI_HWINFO:
4263  if ( ptr == NULL )
4266  break;
4267 
4268  case PAPI_DOMAIN:
4269  if ( ptr == NULL )
4272  if ( ESI == NULL )
4274  ptr->domain.domain = ESI->domain.domain;
4275  return ( PAPI_OK );
4276  case PAPI_LIB_VERSION:
4277  return ( PAPI_VERSION );
4278 /* The following cases all require a component index
4279  and are handled by PAPI_get_cmp_opt() with cidx == 0*/
4280  case PAPI_MAX_HWCTRS:
4281  case PAPI_MAX_MPX_CTRS:
4282  case PAPI_DEFDOM:
4283  case PAPI_DEFGRN:
4284  case PAPI_SHLIBINFO:
4285  case PAPI_COMPONENTINFO:
4286  return ( PAPI_get_cmp_opt( option, ptr, 0 ) );
4287  default:
4289  }
4290  return ( PAPI_OK );
4291 }
4292 
4334 int
4336 {
4337  APIDBG( "Entry: option: %d, ptr: %p, cidx: %d\n", option, ptr, cidx);
4338 
4339  if (_papi_hwi_invalid_cmp(cidx)) {
4340  return PAPI_ECMP;
4341  }
4342 
4343  switch ( option ) {
4344  /* For now, MAX_HWCTRS and MAX CTRS are identical.
4345  At some future point, they may map onto different values.
4346  */
4347  case PAPI_MAX_HWCTRS:
4348  return ( _papi_hwd[cidx]->cmp_info.num_cntrs );
4349  case PAPI_MAX_MPX_CTRS:
4350  return ( _papi_hwd[cidx]->cmp_info.num_mpx_cntrs );
4351  case PAPI_DEFDOM:
4352  return ( _papi_hwd[cidx]->cmp_info.default_domain );
4353  case PAPI_DEFGRN:
4354  return ( _papi_hwd[cidx]->cmp_info.default_granularity );
4355  case PAPI_SHLIBINFO:
4356  {
4357  int retval;
4358  if ( ptr == NULL )
4362  papi_return( retval );
4363  }
4364  case PAPI_COMPONENTINFO:
4365  if ( ptr == NULL )
4367  ptr->cmp_info = &( _papi_hwd[cidx]->cmp_info );
4368  return PAPI_OK;
4369  default:
4371  }
4372  return PAPI_OK;
4373 }
4374 
4386 int
4388 {
4389  APIDBG( "Entry:\n");
4390  return ( papi_num_components );
4391 }
4392 
4425 int
4427 {
4428  APIDBG( "Entry: EventSet: %d\n", EventSet);
4429  EventSetInfo_t *ESI;
4430 
4431  ESI = _papi_hwi_lookup_EventSet( EventSet );
4432  if ( !ESI )
4434 
4435 #ifdef DEBUG
4436  /* Not necessary */
4437  if ( ESI->NumberOfEvents == 0 )
4439 #endif
4440 
4441  return ( ESI->NumberOfEvents );
4442 }
4443 
4444 
4460 void
4462 {
4463  APIDBG( "Entry:\n");
4464 
4465  EventSetInfo_t *ESI;
4466  ThreadInfo_t *master;
4468  int i, j = 0, k, retval;
4469 
4470 
4471  if ( init_retval == DEADBEEF ) {
4473  return;
4474  }
4475 
4476  MPX_shutdown( );
4477 
4478  /* Free all EventSets for this thread */
4479 
4480  master = _papi_hwi_lookup_thread( 0 );
4481 
4482  /* Count number of running EventSets AND */
4483  /* Stop any running EventSets in this thread */
4484 
4485 #ifdef DEBUG
4486 again:
4487 #endif
4488  for( i = 0; i < map->totalSlots; i++ ) {
4489  ESI = map->dataSlotArray[i];
4490  if ( ESI ) {
4491  if ( ESI->master == master ) {
4492  if ( ESI->state & PAPI_RUNNING ) {
4493  if((retval = PAPI_stop( i, NULL )) != PAPI_OK) {
4494  APIDBG("Call to PAPI_stop failed: %d\n", retval);
4495  }
4496  }
4497  retval=PAPI_cleanup_eventset( i );
4498  if (retval!=PAPI_OK) PAPIERROR("Error during cleanup.");
4499  _papi_hwi_free_EventSet( ESI );
4500  }
4501  else {
4502  if ( ESI->state & PAPI_RUNNING ) {
4503  j++;
4504  }
4505  }
4506  }
4507  }
4508 
4509  /* No locking required, we're just waiting for the others
4510  to call shutdown or stop their eventsets. */
4511 
4512 #ifdef DEBUG
4513  if ( j != 0 ) {
4515  sleep( 1 );
4516  j = 0;
4517  goto again;
4518  }
4519 #endif
4520 
4521  // if we have some user events defined, release the space they allocated
4522  // give back the strings which were allocated when each event was created
4523  for ( i=0 ; i<user_defined_events_count ; i++) {
4524  papi_free (user_defined_events[i].symbol);
4525  papi_free (user_defined_events[i].postfix);
4526  papi_free (user_defined_events[i].long_descr);
4527  papi_free (user_defined_events[i].short_descr);
4528  papi_free (user_defined_events[i].note);
4529  for ( k=0 ; k<(int)(user_defined_events[i].count) ; k++) {
4530  papi_free (user_defined_events[i].name[k]);
4531  }
4532  }
4533  // make sure the user events list is empty
4534  memset (user_defined_events, '\0' , sizeof(user_defined_events));
4535  user_defined_events_count = 0;
4536 
4537  /* Shutdown the entire component */
4541  for( i = 0; i < papi_num_components; i++ ) {
4542  if (!_papi_hwd[i]->cmp_info.disabled) {
4544  }
4545  }
4546 
4547  /* Now it is safe to call re-init */
4548 
4552 }
4553 
4602 char *
4603 PAPI_strerror( int errorCode )
4604 {
4605  if ( ( errorCode > 0 ) || ( -errorCode > _papi_hwi_num_errors ) )
4606  return ( NULL );
4607 
4608  return ( _papi_errlist[-errorCode] );
4609 }
4610 
4652 void
4653 PAPI_perror( const char *msg )
4654 {
4655  char *foo;
4656 
4657  foo = PAPI_strerror( _papi_hwi_errno );
4658  if ( foo == NULL )
4659  return;
4660 
4661  if ( msg )
4662  if ( *msg )
4663  fprintf( stderr, "%s: ", msg );
4664 
4665  fprintf( stderr, "%s\n", foo );
4666 }
4667 
4787 int
4788 PAPI_overflow( int EventSet, int EventCode, int threshold, int flags,
4790 {
4791  APIDBG( "Entry: EventSet: %d, EventCode: %#x, threshold: %d, flags: %#x, handler: %p\n", EventSet, EventCode, threshold, flags, handler);
4792  int retval, cidx, index, i;
4793  EventSetInfo_t *ESI;
4794 
4795  ESI = _papi_hwi_lookup_EventSet( EventSet );
4796  if ( ESI == NULL ) {
4797  OVFDBG("No EventSet\n");
4799  }
4800 
4801  cidx = valid_ESI_component( ESI );
4802  if ( cidx < 0 ) {
4803  OVFDBG("Component Error\n");
4804  papi_return( cidx );
4805  }
4806 
4807  if ( ( ESI->state & PAPI_STOPPED ) != PAPI_STOPPED ) {
4808  OVFDBG("Already running\n");
4810  }
4811 
4812  if ( ESI->state & PAPI_ATTACHED ) {
4813  OVFDBG("Attached\n");
4815  }
4816 
4817  if ( ESI->state & PAPI_CPU_ATTACHED ) {
4818  OVFDBG("CPU attached\n");
4820  }
4821 
4822  if ( ( index = _papi_hwi_lookup_EventCodeIndex( ESI,
4823  ( unsigned int ) EventCode ) ) < 0 ) {
4825  }
4826 
4827  if ( threshold < 0 ) {
4828  OVFDBG("Threshold below zero\n");
4830  }
4831 
4832  /* We do not support derived events in overflow */
4833  /* Unless it's DERIVED_CMPD in which no calculations are done */
4834 
4835  if ( !( flags & PAPI_OVERFLOW_FORCE_SW ) && threshold != 0 &&
4836  ( ESI->EventInfoArray[index].derived ) &&
4837  ( ESI->EventInfoArray[index].derived != DERIVED_CMPD ) ) {
4838  OVFDBG("Derived event in overflow\n");
4840  }
4841 
4842  /* the first time to call PAPI_overflow function */
4843 
4844  if ( !( ESI->state & PAPI_OVERFLOWING ) ) {
4845  if ( handler == NULL ) {
4846  OVFDBG("NULL handler\n");
4848  }
4849  if ( threshold == 0 ) {
4850  OVFDBG("Zero threshold\n");
4852  }
4853  }
4854  if ( threshold > 0 &&
4857 
4858  if ( threshold == 0 ) {
4859  for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
4860  if ( ESI->overflow.EventCode[i] == EventCode )
4861  break;
4862  }
4863  /* EventCode not found */
4864  if ( i == ESI->overflow.event_counter )
4866  /* compact these arrays */
4867  while ( i < ESI->overflow.event_counter - 1 ) {
4868  ESI->overflow.deadline[i] = ESI->overflow.deadline[i + 1];
4869  ESI->overflow.threshold[i] = ESI->overflow.threshold[i + 1];
4870  ESI->overflow.EventIndex[i] = ESI->overflow.EventIndex[i + 1];
4871  ESI->overflow.EventCode[i] = ESI->overflow.EventCode[i + 1];
4872  i++;
4873  }
4874  ESI->overflow.deadline[i] = 0;
4875  ESI->overflow.threshold[i] = 0;
4876  ESI->overflow.EventIndex[i] = 0;
4877  ESI->overflow.EventCode[i] = 0;
4878  ESI->overflow.event_counter--;
4879  } else {
4880  if ( ESI->overflow.event_counter > 0 ) {
4881  if ( ( flags & PAPI_OVERFLOW_FORCE_SW ) &&
4884  if ( !( flags & PAPI_OVERFLOW_FORCE_SW ) &&
4885  ( ESI->overflow.flags & PAPI_OVERFLOW_FORCE_SW ) )
4887  }
4888  for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
4889  if ( ESI->overflow.EventCode[i] == EventCode )
4890  break;
4891  }
4892  /* A new entry */
4893  if ( i == ESI->overflow.event_counter ) {
4894  ESI->overflow.EventCode[i] = EventCode;
4895  ESI->overflow.event_counter++;
4896  }
4897  /* New or existing entry */
4898  ESI->overflow.deadline[i] = threshold;
4899  ESI->overflow.threshold[i] = threshold;
4900  ESI->overflow.EventIndex[i] = index;
4901  ESI->overflow.flags = flags;
4902 
4903  }
4904 
4905  /* If overflowing is already active, we should check to
4906  make sure that we don't specify a different handler
4907  or different flags here. You can't mix them. */
4908 
4909  ESI->overflow.handler = handler;
4910 
4911  /* Set up the option structure for the low level.
4912  If we have hardware interrupts and we are not using
4913  forced software emulated interrupts */
4914 
4915  if ( _papi_hwd[cidx]->cmp_info.hardware_intr &&
4916  !( ESI->overflow.flags & PAPI_OVERFLOW_FORCE_SW ) ) {
4917  retval = _papi_hwd[cidx]->set_overflow( ESI, index, threshold );
4918  if ( retval == PAPI_OK )
4920  else {
4921  papi_return( retval ); /* We should undo stuff here */
4922  }
4923  } else {
4924  /* Make sure hardware overflow is not set */
4925  ESI->overflow.flags &= ~( PAPI_OVERFLOW_HARDWARE );
4926  }
4927 
4928  APIDBG( "Overflow using: %s\n",
4929  ( ESI->overflow.
4930  flags & PAPI_OVERFLOW_HARDWARE ? "[Hardware]" : ESI->overflow.
4931  flags & PAPI_OVERFLOW_FORCE_SW ? "[Forced Software]" :
4932  "[Software]" ) );
4933 
4934  /* Toggle the overflow flags and ESI state */
4935 
4936  if ( ESI->overflow.event_counter >= 1 )
4937  ESI->state |= PAPI_OVERFLOWING;
4938  else {
4939  ESI->state ^= PAPI_OVERFLOWING;
4940  ESI->overflow.flags = 0;
4941  ESI->overflow.handler = NULL;
4942  }
4943 
4944  return PAPI_OK;
4945 }
4946 
5043 int
5044 PAPI_sprofil( PAPI_sprofil_t *prof, int profcnt, int EventSet,
5045  int EventCode, int threshold, int flags )
5046 {
5047  APIDBG( "Entry: prof: %p, profcnt: %d, EventSet: %d, EventCode: %#x, threshold: %d, flags: %#x\n", prof, profcnt, EventSet, EventCode, threshold, flags);
5048  EventSetInfo_t *ESI;
5049  int retval, index, i, buckets;
5050  int forceSW = 0;
5051  int cidx;
5052 
5053  /* Check to make sure EventSet exists */
5054  ESI = _papi_hwi_lookup_EventSet( EventSet );
5055  if ( ESI == NULL ) {
5057  }
5058 
5059  /* Check to make sure EventSet is stopped */
5060  if ( ( ESI->state & PAPI_STOPPED ) != PAPI_STOPPED ) {
5062  }
5063 
5064  /* We cannot profile if attached */
5065  if ( ESI->state & PAPI_ATTACHED ) {
5067  }
5068 
5069  /* We cannot profile if cpu attached */
5070  if ( ESI->state & PAPI_CPU_ATTACHED ) {
5072  }
5073 
5074  /* Get component for EventSet */
5075  cidx = valid_ESI_component( ESI );
5076  if ( cidx < 0 ) {
5077  papi_return( cidx );
5078  }
5079 
5080  /* Get index of the Event we want to profile */
5081  if ( ( index = _papi_hwi_lookup_EventCodeIndex( ESI,
5082  (unsigned int) EventCode ) ) < 0 ) {
5084  }
5085 
5086  /* We do not support derived events in overflow */
5087  /* Unless it's DERIVED_CMPD in which no calculations are done */
5088  if ( ( ESI->EventInfoArray[index].derived ) &&
5089  ( ESI->EventInfoArray[index].derived != DERIVED_CMPD ) &&
5090  !( flags & PAPI_PROFIL_FORCE_SW ) ) {
5092  }
5093 
5094  /* If no prof structures, then make sure count is 0 */
5095  if ( prof == NULL ) {
5096  profcnt = 0;
5097  }
5098 
5099  /* check all profile regions for valid scale factors of:
5100  2 (131072/65536),
5101  1 (65536/65536),
5102  or < 1 (65535 -> 2) as defined in unix profil()
5103  2/65536 is reserved for single bucket profiling
5104  {0,1}/65536 are traditionally used to terminate profiling
5105  but are unused here since PAPI uses threshold instead
5106  */
5107  for( i = 0; i < profcnt; i++ ) {
5108  if ( !( ( prof[i].pr_scale == 131072 ) ||
5109  ( ( prof[i].pr_scale <= 65536 && prof[i].pr_scale > 1 ) ) ) ) {
5110  APIDBG( "Improper scale factor: %d\n", prof[i].pr_scale );
5112  }
5113  }
5114 
5115  /* Make sure threshold is valid */
5116  if ( threshold < 0 ) {
5118  }
5119 
5120  /* the first time to call PAPI_sprofil */
5121  if ( !( ESI->state & PAPI_PROFILING ) ) {
5122  if ( threshold == 0 ) {
5124  }
5125  }
5126 
5127  /* ??? */
5128  if ( (threshold > 0) &&
5129  (ESI->profile.event_counter >= _papi_hwd[cidx]->cmp_info.num_cntrs) ) {
5131  }
5132 
5133  if ( threshold == 0 ) {
5134  for( i = 0; i < ESI->profile.event_counter; i++ ) {
5135  if ( ESI->profile.EventCode[i] == EventCode ) {
5136  break;
5137  }
5138  }
5139 
5140  /* EventCode not found */
5141  if ( i == ESI->profile.event_counter ) {
5143  }
5144 
5145  /* compact these arrays */
5146  while ( i < ESI->profile.event_counter - 1 ) {
5147  ESI->profile.prof[i] = ESI->profile.prof[i + 1];
5148  ESI->profile.count[i] = ESI->profile.count[i + 1];
5149  ESI->profile.threshold[i] = ESI->profile.threshold[i + 1];
5150  ESI->profile.EventIndex[i] = ESI->profile.EventIndex[i + 1];
5151  ESI->profile.EventCode[i] = ESI->profile.EventCode[i + 1];
5152  i++;
5153  }
5154  ESI->profile.prof[i] = NULL;
5155  ESI->profile.count[i] = 0;
5156  ESI->profile.threshold[i] = 0;
5157  ESI->profile.EventIndex[i] = 0;
5158  ESI->profile.EventCode[i] = 0;
5159  ESI->profile.event_counter--;
5160  } else {
5161  if ( ESI->profile.event_counter > 0 ) {
5162  if ( ( flags & PAPI_PROFIL_FORCE_SW ) &&
5163  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
5165  }
5166  if ( !( flags & PAPI_PROFIL_FORCE_SW ) &&
5167  ( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
5169  }
5170  }
5171 
5172  for( i = 0; i < ESI->profile.event_counter; i++ ) {
5173  if ( ESI->profile.EventCode[i] == EventCode ) {
5174  break;
5175  }
5176  }
5177 
5178  if ( i == ESI->profile.event_counter ) {
5179  i = ESI->profile.event_counter;
5180  ESI->profile.event_counter++;
5181  ESI->profile.EventCode[i] = EventCode;
5182  }
5183  ESI->profile.prof[i] = prof;
5184  ESI->profile.count[i] = profcnt;
5185  ESI->profile.threshold[i] = threshold;
5186  ESI->profile.EventIndex[i] = index;
5187  }
5188 
5189  APIDBG( "Profile event counter is %d\n", ESI->profile.event_counter );
5190 
5191  /* Clear out old flags */
5192  if ( threshold == 0 ) {
5193  flags |= ESI->profile.flags;
5194  }
5195 
5196  /* make sure no invalid flags are set */
5197  if ( flags &
5199  PAPI_PROFIL_COMPRESS | PAPI_PROFIL_BUCKETS | PAPI_PROFIL_FORCE_SW |
5202  }
5203 
5204  /* if we have kernel-based profiling, then we're just asking for
5205  signals on interrupt. */
5206  /* if we don't have kernel-based profiling, then we're asking for
5207  emulated PMU interrupt */
5208  if ( ( flags & PAPI_PROFIL_FORCE_SW ) &&
5209  ( _papi_hwd[cidx]->cmp_info.kernel_profile == 0 ) ) {
5210  forceSW = PAPI_OVERFLOW_FORCE_SW;
5211  }
5212 
5213  /* make sure one and only one bucket size is set */
5214  buckets = flags & PAPI_PROFIL_BUCKETS;
5215  if ( !buckets ) {
5216  flags |= PAPI_PROFIL_BUCKET_16; /* default to 16 bit if nothing set */
5217  }
5218  else {
5219  /* return error if more than one set */
5220  if ( !( ( buckets == PAPI_PROFIL_BUCKET_16 ) ||
5221  ( buckets == PAPI_PROFIL_BUCKET_32 ) ||
5222  ( buckets == PAPI_PROFIL_BUCKET_64 ) ) ) {
5224  }
5225  }
5226 
5227  /* Set up the option structure for the low level */
5228  ESI->profile.flags = flags;
5229 
5230  if ( _papi_hwd[cidx]->cmp_info.kernel_profile &&
5231  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
5232  retval = _papi_hwd[cidx]->set_profile( ESI, index, threshold );
5233  if ( ( retval == PAPI_OK ) && ( threshold > 0 ) ) {
5234  /* We need overflowing because we use the overflow dispatch handler */
5235  ESI->state |= PAPI_OVERFLOWING;
5237  }
5238  } else {
5239  retval = PAPI_overflow( EventSet, EventCode, threshold, forceSW,
5241  }
5242 
5243  if ( retval < PAPI_OK ) {
5244  papi_return( retval ); /* We should undo stuff here */
5245  }
5246 
5247  /* Toggle the profiling flags and ESI state */
5248 
5249  if ( ESI->profile.event_counter >= 1 ) {
5250  ESI->state |= PAPI_PROFILING;
5251  }
5252  else {
5253  ESI->state ^= PAPI_PROFILING;
5254  ESI->profile.flags = 0;
5255  }
5256 
5257  return PAPI_OK;
5258 }
5259 
5437 int
5438 PAPI_profil( void *buf, unsigned bufsiz, caddr_t offset,
5439  unsigned scale, int EventSet, int EventCode, int threshold,
5440  int flags )
5441 {
5442  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);
5443  EventSetInfo_t *ESI;
5444  int i;
5445  int retval;
5446 
5447  ESI = _papi_hwi_lookup_EventSet( EventSet );
5448  if ( ESI == NULL )
5450 
5451  /* scale factors are checked for validity in PAPI_sprofil */
5452 
5453  if ( threshold > 0 ) {
5454  PAPI_sprofil_t *prof;
5455 
5456  for ( i = 0; i < ESI->profile.event_counter; i++ ) {
5457  if ( ESI->profile.EventCode[i] == EventCode )
5458  break;
5459  }
5460 
5461  if ( i == ESI->profile.event_counter ) {
5462  prof =
5463  ( PAPI_sprofil_t * ) papi_malloc( sizeof ( PAPI_sprofil_t ) );
5464  memset( prof, 0x0, sizeof ( PAPI_sprofil_t ) );
5465  prof->pr_base = buf;
5466  prof->pr_size = bufsiz;
5467  prof->pr_off = offset;
5468  prof->pr_scale = scale;
5469 
5470  retval =
5471  PAPI_sprofil( prof, 1, EventSet, EventCode, threshold, flags );
5472 
5473  if ( retval != PAPI_OK )
5474  papi_free( prof );
5475  } else {
5476  prof = ESI->profile.prof[i];
5477  prof->pr_base = buf;
5478  prof->pr_size = bufsiz;
5479  prof->pr_off = offset;
5480  prof->pr_scale = scale;
5481  retval =
5482  PAPI_sprofil( prof, 1, EventSet, EventCode, threshold, flags );
5483  }
5484  papi_return( retval );
5485  }
5486 
5487  for ( i = 0; i < ESI->profile.event_counter; i++ ) {
5488  if ( ESI->profile.EventCode[i] == EventCode )
5489  break;
5490  }
5491  /* EventCode not found */
5492  if ( i == ESI->profile.event_counter )
5494 
5495  papi_free( ESI->profile.prof[i] );
5496  ESI->profile.prof[i] = NULL;
5497 
5498  papi_return( PAPI_sprofil( NULL, 0, EventSet, EventCode, 0, flags ) );
5499 }
5500 
5501 /* This function sets the low level default granularity
5502  for all newly manufactured eventsets. The first function
5503  preserves API compatibility and assumes component 0;
5504  The second function takes a component argument. */
5505 
5556 int
5557 PAPI_set_granularity( int granularity )
5558 {
5559  return ( PAPI_set_cmp_granularity( granularity, 0 ) );
5560 }
5561 
5621 int
5622 PAPI_set_cmp_granularity( int granularity, int cidx )
5623 {
5625 
5626  memset( &ptr, 0, sizeof ( ptr ) );
5628  ptr.defgranularity.granularity = granularity;
5629  papi_return( PAPI_set_opt( PAPI_DEFGRN, &ptr ) );
5630 }
5631 
5632 /* This function sets the low level default counting domain
5633  for all newly manufactured eventsets. The first function
5634  preserves API compatibility and assumes component 0;
5635  The second function takes a component argument. */
5636 
5687 int
5688 PAPI_set_domain( int domain )
5689 {
5690  return ( PAPI_set_cmp_domain( domain, 0 ) );
5691 }
5692 
5757 int
5758 PAPI_set_cmp_domain( int domain, int cidx )
5759 {
5761 
5762  memset( &ptr, 0, sizeof ( ptr ) );
5763  ptr.defdomain.def_cidx = cidx;
5764  ptr.defdomain.domain = domain;
5765  papi_return( PAPI_set_opt( PAPI_DEFDOM, &ptr ) );
5766 }
5767 
5842 int
5843 PAPI_add_events( int EventSet, int *Events, int number )
5844 {
5845  APIDBG( "Entry: EventSet: %d, Events: %p, number: %d\n", EventSet, Events, number);
5846  int i, retval;
5847 
5848  if ( ( Events == NULL ) || ( number <= 0 ) )
5850 
5851  for ( i = 0; i < number; i++ ) {
5852  retval = PAPI_add_event( EventSet, Events[i] );
5853  if ( retval != PAPI_OK ) {
5854  if ( i == 0 )
5855  papi_return( retval );
5856  else
5857  return ( i );
5858  }
5859  }
5860  return ( PAPI_OK );
5861 }
5862 
5930 int
5931 PAPI_remove_events( int EventSet, int *Events, int number )
5932 {
5933  APIDBG( "Entry: EventSet: %d, Events: %p, number: %d\n", EventSet, Events, number);
5934  int i, retval;
5935 
5936  if ( ( Events == NULL ) || ( number <= 0 ) )
5938 
5939  for ( i = 0; i < number; i++ ) {
5940  retval = PAPI_remove_event( EventSet, Events[i] );
5941  if ( retval != PAPI_OK ) {
5942  if ( i == 0 )
5943  papi_return( retval );
5944  else
5945  return ( i );
5946  }
5947  }
5948  return ( PAPI_OK );
5949 }
5950 
6000 int
6001 PAPI_list_events( int EventSet, int *Events, int *number )
6002 {
6003  APIDBG( "Entry: EventSet: %d, Events: %p, number: %p\n", EventSet, Events, number);
6004  EventSetInfo_t *ESI;
6005  int i, j;
6006 
6007  if ( *number < 0 )
6009 
6010  if ( ( Events == NULL ) && ( *number > 0 ) )
6012 
6013  ESI = _papi_hwi_lookup_EventSet( EventSet );
6014  if ( !ESI )
6016 
6017  if ( ( Events == NULL ) || ( *number == 0 ) ) {
6018  *number = ESI->NumberOfEvents;
6019  papi_return( PAPI_OK );
6020  }
6021 
6022  for ( i = 0, j = 0; j < ESI->NumberOfEvents; i++ ) {
6023  if ( ( int ) ESI->EventInfoArray[i].event_code != PAPI_NULL ) {
6024  Events[j] = ( int ) ESI->EventInfoArray[i].event_code;
6025  j++;
6026  if ( j == *number )
6027  break;
6028  }
6029  }
6030 
6031  *number = j;
6032 
6033  return ( PAPI_OK );
6034 }
6035 
6036 /* xxx This is OS dependent, not component dependent, right? */
6062 int
6064 {
6065  if ( dest == NULL )
6066  return PAPI_EINVAL;
6067 
6068  memset( ( void * ) dest, 0x0, sizeof ( PAPI_dmem_info_t ) );
6069  return ( _papi_os_vector.get_dmem_info( dest ) );
6070 }
6071 
6072 
6113 const PAPI_exe_info_t *
6115 {
6117  int retval;
6118 
6119  memset( &ptr, 0, sizeof ( ptr ) );
6120  retval = PAPI_get_opt( PAPI_EXEINFO, &ptr );
6121  if ( retval == PAPI_OK )
6122  return ( ptr.exe_info );
6123  else
6124  return ( NULL );
6125 }
6126 
6143 const PAPI_shlib_info_t *
6145 {
6147  int retval;
6148 
6149  memset( &ptr, 0, sizeof ( ptr ) );
6150  retval = PAPI_get_opt( PAPI_SHLIBINFO, &ptr );
6151  if ( retval == PAPI_OK )
6152  return ( ptr.shlib_info );
6153  else
6154  return ( NULL );
6155 }
6184 const PAPI_hw_info_t *
6186 {
6188  int retval;
6189 
6190  memset( &ptr, 0, sizeof ( ptr ) );
6191  retval = PAPI_get_opt( PAPI_HWINFO, &ptr );
6192  if ( retval == PAPI_OK )
6193  return ( ptr.hw_info );
6194  else
6195  return ( NULL );
6196 }
6197 
6198 
6199 /* The next 4 timing functions always use component 0 */
6200 
6216 long long
6218 {
6219  return ( _papi_os_vector.get_real_cycles( ) );
6220 }
6221 
6235 /* FIXME */
6236 long long
6238 {
6239  return ( ( _papi_os_vector.get_real_nsec( )));
6240 
6241 }
6242 
6263 long long
6265 {
6266  return ( _papi_os_vector.get_real_usec( ) );
6267 }
6268 
6299 long long
6301 {
6302 
6303  return ( ( long long ) _papi_os_vector.get_virt_cycles( ) );
6304 }
6305 
6329 long long
6331 {
6332 
6333  return ( ( _papi_os_vector.get_virt_nsec()));
6334 
6335 }
6336 
6371 long long
6373 {
6374 
6375  return ( ( long long ) _papi_os_vector.get_virt_usec() );
6376 }
6377 
6400 int
6401 PAPI_lock( int lck )
6402 {
6403  if ( ( lck < 0 ) || ( lck >= PAPI_NUM_LOCK ) )
6405 
6406  papi_return( _papi_hwi_lock( lck ) );
6407 }
6408 
6420 int
6421 PAPI_unlock( int lck )
6422 {
6423  if ( ( lck < 0 ) || ( lck >= PAPI_NUM_LOCK ) )
6425 
6426  papi_return( _papi_hwi_unlock( lck ) );
6427 }
6428 
6462 int
6464 {
6465  return ( init_level );
6466 }
6467 
6468 /* This function maps the overflow_vector to event indexes in the event
6469  set, so that user can know which PAPI event overflowed.
6470  int *array---- an array of event indexes in eventset; the first index
6471  maps to the highest set bit in overflow_vector
6472  int *number--- this is an input/output parameter, user should put the
6473  size of the array into this parameter, after the function
6474  is executed, the number of indexes in *array is written
6475  to this parameter
6476 */
6477 
6516 int
6517 PAPI_get_overflow_event_index( int EventSet, long long overflow_vector,
6518  int *array, int *number )
6519 {
6520  APIDBG( "Entry: EventSet: %d, overflow_vector: %lld, array: %p, number: %p\n", EventSet, overflow_vector, array, number);
6521  EventSetInfo_t *ESI;
6522  int set_bit, j, pos;
6523  int count = 0, k;
6524 
6525  if ( overflow_vector == ( long long ) 0 )
6527 
6528  if ( ( array == NULL ) || ( number == NULL ) )
6530 
6531  if ( *number < 1 )
6533 
6534  ESI = _papi_hwi_lookup_EventSet( EventSet );
6535  if ( ESI == NULL )
6537 
6538  /* in case the eventset is empty */
6539  if ( ESI->NumberOfEvents == 0 )
6541 
6542  while ( ( set_bit = ffsll( overflow_vector ) ) ) {
6543  set_bit -= 1;
6544  overflow_vector ^= ( long long ) 1 << set_bit;
6545  for ( j = 0; j < ESI->NumberOfEvents; j++ ) {
6546  for ( k = 0, pos = 0; k < PAPI_EVENTS_IN_DERIVED_EVENT && pos >= 0; k++ ) {
6547  pos = ESI->EventInfoArray[j].pos[k];
6548  if ( ( set_bit == pos ) &&
6549  ( ( ESI->EventInfoArray[j].derived == NOT_DERIVED ) ||
6550  ( ESI->EventInfoArray[j].derived == DERIVED_CMPD ) ) ) {
6551  array[count++] = j;
6552  if ( count == *number )
6553  return PAPI_OK;
6554 
6555  break;
6556  }
6557  }
6558  }
6559  }
6560  *number = count;
6561  return PAPI_OK;
6562 }
6563 
6564 
6582 int
6584 {
6585  APIDBG( "Entry: EventCode: %#x\n", EventCode);
6586  return _papi_hwi_component_index( EventCode);
6587 }
6588 
6611 {
6612  APIDBG( "Entry: name: %s\n", name);
6613  int cidx;
6614 
6615  const PAPI_component_info_t *cinfo;
6616 
6617  for(cidx=0;cidx<papi_num_components;cidx++) {
6618 
6619  cinfo=PAPI_get_component_info(cidx);
6620  if (cinfo==NULL) return PAPI_ENOCMP;
6621 
6622  if (!strcmp(name,cinfo->name)) {
6623  return cidx;
6624  }
6625  }
6626 
6627  return PAPI_ENOCMP;
6628 }
6629 
6630 
6665 int
6667 {
6668  APIDBG( "Entry: cidx: %d\n", cidx);
6669 
6670  const PAPI_component_info_t *cinfo;
6671 
6672  /* Can only run before PAPI_library_init() is called */
6673  if (init_level != PAPI_NOT_INITED) {
6674  return PAPI_ENOINIT;
6675  }
6676 
6677  cinfo=PAPI_get_component_info(cidx);
6678  if (cinfo==NULL) return PAPI_ENOCMP;
6679 
6680  ((PAPI_component_info_t *)cinfo)->disabled=1;
6681  strcpy(((PAPI_component_info_t *)cinfo)->disabled_reason,
6682  "Disabled by PAPI_disable_component()");
6683 
6684  return PAPI_OK;
6685 
6686 }
6687 
6716 int
6718 {
6719  APIDBG( "Entry: name: %s\n", name);
6720  int cidx;
6721 
6722  /* I can only be called before init time */
6723  if (init_level!=PAPI_NOT_INITED) {
6724  return PAPI_ENOINIT;
6725  }
6726 
6727  cidx = PAPI_get_component_index(name);
6728  if (cidx>=0) {
6729  return PAPI_disable_component(cidx);
6730  }
6731 
6732  return PAPI_ENOCMP;
6733 }
#define PAPI_NUM_LOCK
Definition: papi.h:335
int _papi_hwi_is_sw_multiplex(EventSetInfo_t *ESI)
#define PAPI_ATTACHED
Definition: papi.h:381
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:629
i inherit inherit
#define PAPI_ENOEVNT
Definition: papi.h:260
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int PAPI_is_initialized(void)
Definition: papi.c:6463
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:378
#define IS_PRESET(EventCode)
Definition: papi.h:229
char * _papi_hwi_get_papi_event_string()
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:796
#define DEBUG_PROFILE
Definition: papi_debug.h:33
#define PAPI_CPU_ATTACH
Definition: papi.h:457
char * getenv()
long long(* get_real_nsec)(void)
Definition: papi_vector.h:65
#define PAPI_VERB_ECONT
Definition: papi.h:389
sleep(1)
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
Hardware info structure.
Definition: papi.h:780
inline_static int _papi_set_attach(int option, int EventSet, unsigned long tid)
Definition: papi.c:3139
long long PAPI_get_virt_usec(void)
Definition: papi.c:6372
int PAPI_set_cmp_granularity(int granularity, int cidx)
Definition: papi.c:5622
int PAPI_reset(int EventSet)
Definition: papi.c:2459
#define PAPI_SHUTDOWN_str
Definition: papi_internal.h:42
long long flags
Definition: iozone.c:12330
#define PAPI_DEF_ITIMER_NS
Definition: papi.h:455
int _papi_hwi_set_thread_id_fn(unsigned long(*id_fn)(void))
Definition: threads.c:352
#define IS_USER_DEFINED(EventCode)
Definition: papi.h:230
#define PAPI_UE_AND_MASK
const PAPI_shlib_info_t * PAPI_get_shared_lib_info(void)
Definition: papi.c:6144
#define papi_free(a)
Definition: papi_memory.h:35
int PAPI_disable_component_by_name(const char *name)
Definition: papi.c:6717
#define PAPI_INSTR_ADDRESS
Definition: papi.h:453
void ** data
Definition: papi.h:563
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:162
#define PAPI_PROFIL_DATA_EAR
Definition: papi.h:404
int PAPI_write(int EventSet, long long *values)
Definition: papi.c:2813
int _papi_hwi_debug
Definition: papi.c:79
#define papi_return(a)
Definition: papi.c:50
#define PAPI_DEF_MPX_NS
Definition: papi.h:436
cpu
Definition: iozone.c:3872
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1758
#define papi_malloc(a)
Definition: papi_memory.h:34
long long PAPI_get_virt_cyc(void)
Definition: papi.c:6300
int default_granularity
Definition: papi.h:645
#define PAPI_ENOSUPP
Definition: papi.h:271
PAPI_debug_handler_t _papi_hwi_debug_handler
Definition: papi_internal.c:55
void MPX_shutdown(void)
long long(* get_real_usec)(void)
Definition: papi_vector.h:63
#define PAPI_NULL
Definition: papi.h:292
#define PAPI_LOW_LEVEL_INITED
Definition: papi.h:281
off64_t offset
Definition: iozone.c:1279
#define PAPI_PROFIL_BUCKET_16
Definition: papi.h:400
#define PAPI_DATA_ADDRESS
Definition: papi.h:452
MPX_EventSet * mpx_evset
Definition: sw_multiplex.h:32
#define PAPI_DOM_MIN
Definition: papi.h:299
int PAPI_num_components(void)
Definition: papi.c:4387
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1152
#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:853
int MPX_stop(MPX_EventSet *mpx_events, long long *values)
Definition: sw_multiplex.c:974
#define PAPI_MULTIPLEXING
Definition: papi.h:380
#define PAPI_MULTIPLEX_FORCE_SW
Definition: papi.h:419
caddr_t pr_off
Definition: papi.h:584
#define PAPI_DOM_ALL
Definition: papi.h:303
int PAPI_detach(int EventSet)
Definition: papi.c:3258
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:566
EventSetDomainInfo_t domain
int EventSet
get the executable&#39;s info
Definition: papi.h:707
int PAPI_register_thread(void)
Definition: papi.c:208
int _papi_hwi_errno
Definition: papi_internal.c:57
int _papi_hwi_remove_EventSet(EventSetInfo_t *ESI)
#define PAPI_TLS_NUM
Definition: papi.h:326
return PAPI_OK
Definition: linux-nvml.c:497
int count
Definition: iozone.c:22422
PAPI_inherit_option_t inherit
Definition: papi.h:852
PAPI_preload_info_t preload_info
#define PAPI_ENOTRUN
Definition: papi.h:262
PAPI_exe_info_t exe_info
int PAPI_event_name_to_code(const char *in, int *out)
Definition: papi.c:1004
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:4788
#define PAPI_PRESET_MASK
#define PAPI_DOM_USER
Definition: papi.h:298
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:848
int PAPI_remove_events(int EventSet, int *Events, int number)
Definition: papi.c:5931
long long PAPI_get_virt_nsec(void)
Definition: papi.c:6330
return PAPI_EINVAL
Definition: linux-nvml.c:436
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:5044
void _papi_hwi_init_errors(void)
#define PAPI_NOT_INITED
Definition: papi.h:280
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
int _papi_hwi_get_user_event_info(int EventCode, PAPI_event_info_t *info)
PAPI_hw_info_t * hw_info
Definition: papi.h:861
double c
Definition: multiplex.c:22
#define PAPI_ENOTPRESET
Definition: papi.h:265
PAPI_user_defined_events_file_t events_file
Definition: papi.h:866
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:3465
long long(* get_real_cycles)(void)
Definition: papi_vector.h:61
int PAPI_add_events(int EventSet, int *Events, int number)
Definition: papi.c:5843
unsigned int cpu_num
Definition: papi.h:824
#define PAPI_INHERIT
Definition: papi.h:458
#define PAPI_PRELOAD
Definition: papi.h:441
#define PAPI_HUGE_STR_LEN
Definition: papi.h:467
unsigned pr_scale
Definition: papi.h:585
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:382
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:835
void * thread_storage[PAPI_MAX_TLS]
Definition: threads.h:29
PAPI_addr_range_option_t addr
Definition: papi.h:865
#define APIDBG(format, args...)
Definition: papi_debug.h:64
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
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:5758
long long ret
Definition: iozone.c:1346
int PAPI_disable_component(int cidx)
Definition: papi.c:6666
unsigned pr_size
Definition: papi.h:583
#define PAPI_EMISC
Definition: papi.h:267
int PAPI_num_cmp_hwctrs(int cidx)
Definition: papi.c:3965
void _papi_mem_cleanup_all()
Definition: papi_memory.c:303
int PAPI_get_thr_specific(int tag, void **ptr)
Definition: papi.c:362
int PAPI_accum(int EventSet, long long *values)
Definition: papi.c:2745
void _papi_hwi_shutdown_highlevel()
Definition: papi_hl.c:836
#define PAPI_TLS_ALL_THREADS
Definition: papi.h:327
int(* shutdown_component)(void)
Definition: papi_vector.h:54
#define PAPI_USER_EVENTS_FILE
Definition: papi.h:459
static int cidx
#define DEADBEEF
Definition: papi_internal.h:26
#define PAPI_MAX_USER_EVENTS
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:123
#define DEBUG_ALL
Definition: papi_debug.h:36
int PAPI_library_init(int version)
Definition: papi.c:500
int PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset, unsigned scale, int EventSet, int EventCode, int threshold, int flags)
Definition: papi.c:5438
#define PAPI_THREAD_LEVEL_INITED
Definition: papi.h:283
papi_os_vector_t _papi_os_vector
Definition: aix.c:1288
#define PAPI_PROFIL_COMPRESS
Definition: papi.h:399
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:3909
#define PAPI_OVERFLOW_HARDWARE
Definition: papi.h:412
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:264
A pointer to the following is passed to PAPI_get_dmem_info()
Definition: papi.h:871
int MPX_start(MPX_EventSet *mpx_events)
Definition: sw_multiplex.c:692
#define PAPI_LIB_VERSION
Definition: papi.h:449
void PAPI_shutdown(void)
Definition: papi.c:4461
Definition: cpus.h:10
#define IS_NATIVE(EventCode)
Definition: papi.h:228
int PAPI_get_cmp_opt(int option, PAPI_option_t *ptr, int cidx)
Definition: papi.c:4335
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:6114
#define PAPI_PROFIL_BUCKET_64
Definition: papi.h:402
int PAPI_num_events(int EventSet)
Definition: papi.c:4426
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4143
#define NOT_DERIVED
Definition: papi_internal.h:69
int ffsll(long long lli)
Definition: extras.c:499
int k
Definition: iozone.c:19136
int PAPI_get_component_index(const char *name)
Definition: papi.c:6610
#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:445
int _papi_hwi_stop_timer(int timer, int signal)
Definition: extras.c:463
int(* start)(hwd_context_t *, hwd_control_state_t *)
Definition: papi_vector.h:28
int PAPI_state(int EventSet, int *status)
Definition: papi.c:3053
pthread_attr_t foo
Definition: iozone.c:18592
#define PAPI_PROFIL_RANDOM
Definition: papi.h:397
int PAPI_query_named_event(const char *EventName)
Definition: papi.c:756
#define PAPI_GRANUL
Definition: papi.h:435
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
void * thread(void *arg)
Definition: kufrin.c:38
int user_defined_events_count
Definition: papi_internal.c:60
#define PAPI_MAX_CPUS
Definition: papi.h:446
int(* reset)(hwd_context_t *, hwd_control_state_t *)
Definition: papi_vector.h:31
hwi_presets_t user_defined_events[PAPI_MAX_USER_EVENTS]
Definition: papi_internal.c:59
void *long long tid
Definition: iozone.c:18586
#define PAPI_DEFGRN
Definition: papi.h:434
int MPX_cleanup(MPX_EventSet **mpx_events)
#define PAPI_PROFIL_INST_EAR
Definition: papi.h:405
#define DEBUG_LEAK
Definition: papi_debug.h:35
int _papi_hwi_start_timer(int timer, int signal, int ns)
Definition: extras.c:368
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:261
int _papi_hwi_get_native_event_info(unsigned int EventCode, PAPI_event_info_t *info)
#define PAPI_DETACH
Definition: papi.h:429
void PAPIERROR(char *format,...)
int _papi_hwi_start_signal(int signal, int need_context, int cidx)
Definition: extras.c:403
PAPI_cpu_option_t cpu
Definition: papi.h:858
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:5557
#define PAPI_ATTACH
Definition: papi.h:447
#define inline_static
#define DEBUG_INTERNAL
Definition: papi_debug.h:29
#define PAPI_ECMP
Definition: papi.h:256
int(* ctl)(hwd_context_t *, int, _papi_int_option_t *)
Definition: papi_vector.h:39
#define PAPI_GRN_MAX
Definition: papi.h:368
#define PAPI_MAX_MPX_CTRS
Definition: papi.h:439
#define PAPI_MULTIPLEX_DEFAULT
Definition: papi.h:418
#define PAPI_PROFIL_BUCKET_32
Definition: papi.h:401
#define PAPI_EISRUN
Definition: papi.h:263
int _papi_hwi_error_level
Definition: papi_internal.c:54
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1357
PAPI_multiplex_option_t multiplex
Definition: papi.h:859
#define PAPI_MULTIPLEX
Definition: papi.h:431
int _papi_hwi_stop_signal(int signal)
Definition: extras.c:443
long long(* get_virt_nsec)(void)
Definition: papi_vector.h:66
#define THREADS_LOCK
Definition: papi_internal.h:88
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:20
inline_static int valid_ESI_component(EventSetInfo_t *ESI)
Definition: papi.c:94
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int mpx_init(int interval_ns)
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1526
NativeInfo_t * NativeInfoArray
int _papi_hwi_num_errors
Definition: papi_internal.c:58
char version[]
Definition: fileop.c:134
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
EventInfo_t * EventInfoArray
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
long long * hw_start
static int threshold
PAPI_thread_id_t * id
Definition: papi.h:562
static int init_retval
Definition: papi.c:83
unsigned int hardware_intr
Definition: papi.h:652
#define DEBUG_OVERFLOW
Definition: papi_debug.h:32
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:56
strcpy(filename, default_filename)
PAPI_hw_info_t hw_info
again struct sockaddr sizeof(struct sockaddr_in))
#define PAPI_ENOCMP
Definition: papi.h:270
int PAPI_get_dmem_info(PAPI_dmem_info_t *dest)
Definition: papi.c:6063
#define PAPI_DOMAIN
Definition: papi.h:433
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:450
int PAPI_query_event(int EventCode)
Definition: papi.c:684
int pos[PAPI_EVENTS_IN_DERIVED_EVENT]
PAPI_debug_handler_t handler
Definition: papi.h:690
#define PAPI_NUM_TLS
Definition: papi.h:322
int PAPI_get_overflow_event_index(int EventSet, long long overflow_vector, int *array, int *number)
Definition: papi.c:6517
unsigned long tid
Definition: papi.h:818
int MPX_reset(MPX_EventSet *mpx_events)
Definition: sw_multiplex.c:937
long long * sw_stop
int PAPI_multiplex_init(void)
Definition: papi.c:2982
PAPI_attach_option_t attach
Definition: papi.h:857
void _papi_hwi_set_papi_event_code(unsigned int event_code, int update_flag)
PAPI_granularity_option_t defgranularity
Definition: papi.h:854
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:2648
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
PAPI_exe_info_t * exe_info
Definition: papi.h:863
#define PAPI_PROFIL_POSIX
Definition: papi.h:396
#define PAPI_PROFIL_WEIGHTED
Definition: papi.h:398
int _papi_hwi_init_os(void)
Definition: aix.c:1213
#define PAPI_OVERFLOW_FORCE_SW
Definition: papi.h:411
#define PAPI_DEF_ITIMER
Definition: papi.h:454
long long status
Definition: iozone.c:1335
#define PAPI_PROFILING
Definition: papi.h:379
EventSetInfo_t ** running_eventset
Definition: threads.h:30
int PAPI_unregister_thread(void)
Definition: papi.c:244
#define PAPI_VERSION
Definition: papi.h:224
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:438
int(* ntv_enum_events)(unsigned int *, int)
Definition: papi_vector.h:43
char * PAPI_strerror(int errorCode)
Definition: papi.c:4603
char * name
Definition: iozone.c:23648
int _papi_hwi_assign_eventset(EventSetInfo_t *ESI, int cidx)
static int total
Definition: rapl_overflow.c:9
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:98
#define PAPI_HWINFO
Definition: papi.h:444
int _papi_hwi_gather_all_thrspec_data(int tag, PAPI_all_thr_spec_t *where)
Definition: threads.c:555
#define PAPI_CLOCKRATE
Definition: papi.h:442
long long(* get_virt_cycles)(void)
Definition: papi_vector.h:62
char ** _papi_errlist
Definition: papi_internal.c:81
PAPI_debug_option_t debug
Definition: papi.h:851
int PAPI_unlock(int lck)
Definition: papi.c:6421
int cpu_max_mhz
Definition: papi.h:796
#define PAPI_EINVAL_DOM
Definition: papi.h:274
int
Definition: iozone.c:18528
#define PAPI_RUNNING
Definition: papi.h:375
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:6237
#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:443
int _papi_hwi_component_index(int event_code)
#define PAPI_PROFIL_FORCE_SW
Definition: papi.h:403
#define PAPI_QUIET
Definition: papi.h:388
unsigned int event_code
#define PAPI_DEFDOM
Definition: papi.h:432
#define PAPI_STOPPED
Definition: papi.h:374
#define PAPI_ENOINIT
Definition: papi.h:269
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3333
#define PAPI_PRESET_AND_MASK
unsigned long PAPI_thread_id_t
Definition: papi.h:557
#define PAPI_PROFIL_BUCKETS
Definition: papi.h:406
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
int PAPI_remove_named_event(int EventSet, const char *EventName)
Definition: papi.c:1961
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int(* set_profile)(EventSetInfo_t *, int, int)
Definition: papi_vector.h:41
PAPI_domain_option_t domain
Definition: papi.h:855
int _papi_hwi_invalid_cmp(int cidx)
#define DEBUG_THREADS
Definition: papi_debug.h:30
int PAPI_set_domain(int domain)
Definition: papi.c:5688
void _papi_hwi_free_EventSet(EventSetInfo_t *ESI)
int PAPI_attach(int EventSet, unsigned long tid)
Definition: papi.c:3201
int _papi_hwi_eventcode_to_native(int event_code)
void * pr_base
Definition: papi.h:582
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:6217
PAPI_shlib_info_t * shlib_info
Definition: papi.h:862
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int _papi_hwi_shutdown_thread(ThreadInfo_t *thread, int force_shutdown)
Definition: threads.c:418
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define PAPI_VERB_ESTOP
Definition: papi.h:390
EventSetProfileInfo_t profile
PAPI_preload_info_t preload
Definition: papi.h:850
void PAPI_perror(const char *msg)
Definition: papi.c:4653
int(* get_dmem_info)(PAPI_dmem_info_t *)
Definition: papi_vector.h:70
int init_level
Definition: papi_internal.c:53
hwd_control_state_t * ctl_state
#define PAPI_UE_MASK
long j
Definition: iozone.c:19135
int PAPI_get_multiplex(int EventSet)
Definition: papi.c:4028
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
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:6401
long long tmp
Definition: iozone.c:12031
#define PAPI_GRN_MIN
Definition: papi.h:363
#define PAPI_VER_CURRENT
Definition: papi.h:225
#define PAPI_DOM_MAX
Definition: papi.h:305
inline_static int valid_component(int cidx)
Definition: papi.c:86
int _papi_hwi_init_global_threads(void)
Definition: threads.c:528
int PAPI_list_threads(PAPI_thread_id_t *tids, int *number)
Definition: papi.c:286
PAPI_itimer_option_t itimer
Definition: papi.h:860
int PAPI_get_event_component(int EventCode)
Definition: papi.c:6583
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
int PAPI_set_debug(int level)
Definition: papi.c:3126
int mpx_check(int EventSet)
void _papi_hwi_map_events_to_native(EventSetInfo_t *ESI)
PAPI_domain_option_t defdomain
Definition: papi.h:856
PAPI_overflow_handler_t handler
int _papi_hwi_native_name_to_code(const char *in, int *out)
int(* set_overflow)(EventSetInfo_t *, int, int)
Definition: papi_vector.h:40
if(gettimeofday(&tp,(struct timezone *) NULL)==-1) perror("gettimeofday")
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
int _papi_hwi_create_eventset(int *EventSet, ThreadInfo_t *handle)
#define PAPI_DEBUG
Definition: papi.h:430
int PAPI_list_events(int EventSet, int *Events, int *number)
Definition: papi.c:6001
PAPI_component_info_t * cmp_info
Definition: papi.h:864
#define DEBUG_SUBSTRATE
Definition: papi_debug.h:27
int ncpu
Definition: papi.h:781
int PAPI_get_eventset_component(int EventSet)
Definition: papi.c:1569
char * ptr
Definition: iozone.c:23586
#define PAPI_SHLIBINFO
Definition: papi.h:448