PAPI  5.4.1.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, tmpel;
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  /* Be verbose for now */
595 
596  tmpel = _papi_hwi_error_level;
598 
599  /* Initialize internal globals */
601  _in_papi_library_init_cnt--;
602  _papi_hwi_error_level = tmpel;
604  }
605 
606  /* Initialize OS */
607  tmp = _papi_hwi_init_os();
608  if ( tmp ) {
609  init_retval = tmp;
611  _in_papi_library_init_cnt--;
612  _papi_hwi_error_level = tmpel;
614  }
615 
616  /* Initialize component globals */
617 
618  tmp = _papi_hwi_init_global( );
619  if ( tmp ) {
620  init_retval = tmp;
622  _in_papi_library_init_cnt--;
623  _papi_hwi_error_level = tmpel;
625  }
626 
627  /* Initialize thread globals, including the main threads */
628 
630  if ( tmp ) {
631  int i;
632  init_retval = tmp;
634  for ( i = 0; i < papi_num_components; i++ ) {
635  if (!_papi_hwd[i]->cmp_info.disabled) {
637  }
638  }
639  _in_papi_library_init_cnt--;
640  _papi_hwi_error_level = tmpel;
642  }
643 
645  _in_papi_library_init_cnt--;
646  _papi_hwi_error_level = tmpel;
647 
648  return ( init_retval = PAPI_VER_CURRENT );
649 }
650 
692 int
693 PAPI_query_event( int EventCode )
694 {
695  APIDBG( "Entry: EventCode: %#x\n", EventCode);
696  if ( IS_PRESET(EventCode) ) {
697  EventCode &= PAPI_PRESET_AND_MASK;
698  if ( EventCode < 0 || EventCode >= PAPI_MAX_PRESET_EVENTS )
700 
701  if ( _papi_hwi_presets[EventCode].count )
703  else
704  return PAPI_ENOEVNT;
705  }
706 
707  if ( IS_NATIVE(EventCode) ) {
709  ( ( unsigned int ) EventCode ) );
710  }
711 
712  if ( IS_USER_DEFINED(EventCode) ) {
713  EventCode &= PAPI_UE_AND_MASK;
714  if ( EventCode < 0 || EventCode >= PAPI_MAX_USER_EVENTS)
716 
717  if ( user_defined_events[EventCode].count )
719  else
721  }
722 
724 }
725 
764 int
765 PAPI_query_named_event( char *EventName )
766 {
767  int ret, code;
768 
769  ret = PAPI_event_name_to_code( EventName, &code );
770  if ( ret == PAPI_OK ) ret = PAPI_query_event( code );
771  papi_return( ret);
772 }
773 
774 
804 const PAPI_component_info_t *
806 {
807  APIDBG( "Entry: Component Index %d\n", cidx);
808  if ( _papi_hwi_invalid_cmp( cidx ) )
809  return ( NULL );
810  else
811  return ( &( _papi_hwd[cidx]->cmp_info ) );
812 }
813 
814 /* PAPI_get_event_info:
815  tests input EventCode and returns a filled in PAPI_event_info_t
816  structure containing descriptive strings and values for the
817  specified event. Handles both preset and native events by
818  calling either _papi_hwi_get_event_info or
819  _papi_hwi_get_native_event_info.
820 */
843 int
844 PAPI_get_event_info( int EventCode, PAPI_event_info_t *info )
845 {
846  APIDBG( "Entry: EventCode: 0x%x, info: %p\n", EventCode, info);
847  int i;
848 
849  if ( info == NULL )
851 
852  if ( IS_PRESET(EventCode) ) {
853  i = EventCode & PAPI_PRESET_AND_MASK;
854  if ( i >= PAPI_MAX_PRESET_EVENTS )
856  papi_return( _papi_hwi_get_preset_event_info( EventCode, info ) );
857  }
858 
859  if ( IS_NATIVE(EventCode) ) {
861  ( ( unsigned int ) EventCode, info ) );
862  }
863 
864  if ( IS_USER_DEFINED(EventCode) ) {
865  papi_return( _papi_hwi_get_user_event_info( EventCode, info ));
866  }
868 }
869 
870 
923 int
924 PAPI_event_code_to_name( int EventCode, char *out )
925 {
926  APIDBG( "Entry: EventCode: %#x, out: %p\n", EventCode, out);
927  if ( out == NULL )
929 
930  if ( IS_PRESET(EventCode) ) {
931  EventCode &= PAPI_PRESET_AND_MASK;
932  if ( EventCode < 0 || EventCode >= PAPI_MAX_PRESET_EVENTS )
934 
935  if (_papi_hwi_presets[EventCode].symbol == NULL )
937 
938  strncpy( out, _papi_hwi_presets[EventCode].symbol, PAPI_MAX_STR_LEN-1 );
939  out[PAPI_MAX_STR_LEN-1] = '\0';
940  papi_return( PAPI_OK );
941  }
942 
943  if ( IS_NATIVE(EventCode) ) {
945  ( ( unsigned int ) EventCode, out, PAPI_MAX_STR_LEN ) );
946  }
947 
948  if ( IS_USER_DEFINED(EventCode) ) {
949  EventCode &= PAPI_UE_AND_MASK;
950 
951  if ( EventCode < 0 || EventCode >= user_defined_events_count )
953 
954  if (user_defined_events[EventCode].symbol == NULL )
956 
957  strncpy( out, user_defined_events[EventCode].symbol, PAPI_MAX_STR_LEN-1);
958  out[PAPI_MAX_STR_LEN-1] = '\0';
959  papi_return( PAPI_OK );
960  }
961 
963 }
964 
1012 int
1013 PAPI_event_name_to_code( char *in, int *out )
1014 {
1015  APIDBG("Entry: in: %p, name: %s, out: %p\n", in, in, out);
1016  int i;
1017 
1018  if ( ( in == NULL ) || ( out == NULL ) )
1020 
1021  if ( init_level == PAPI_NOT_INITED )
1023 
1024  /* All presets start with "PAPI_" so no need to */
1025  /* do an exhaustive search if that's not there */
1026  if (strncmp(in, "PAPI_", 5) == 0) {
1027  for(i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
1028  if ( ( _papi_hwi_presets[i].symbol )
1029  && ( strcasecmp( _papi_hwi_presets[i].symbol, in ) == 0) ) {
1030  *out = ( int ) ( i | PAPI_PRESET_MASK );
1031  papi_return( PAPI_OK );
1032  }
1033  }
1034  }
1035 
1036  // check to see if it is a user defined event
1037  for ( i=0; i < user_defined_events_count ; i++ ) {
1038  APIDBG("&user_defined_events[%d]: %p, user_defined_events[%d].symbol: %s, user_defined_events[%d].count: %d\n",
1039  i, &user_defined_events[i], i, user_defined_events[i].symbol, i, user_defined_events[i].count);
1040  if (user_defined_events[i].symbol == NULL)
1041  break;
1042  if (user_defined_events[i].count == 0)
1043  break;
1044  if ( strcasecmp( user_defined_events[i].symbol, in ) == 0 ) {
1045  *out = (int) ( i | PAPI_UE_MASK );
1046  papi_return( PAPI_OK );
1047  }
1048  }
1049 
1050  // go look for native events defined by one of the components
1052 }
1053 
1054 /* Updates EventCode to next valid value, or returns error;
1055  modifier can specify {all / available} for presets, or other values for native tables
1056  and may be platform specific (Major groups / all mask bits; P / M / E chip, etc) */
1057 
1160 int
1161 PAPI_enum_event( int *EventCode, int modifier )
1162 {
1163  APIDBG( "Entry: EventCode: %#x, modifier: %d\n", *EventCode, modifier);
1164  int i = *EventCode;
1165  int retval;
1166  int cidx;
1167  int event_code;
1168  char *evt_name;
1169 
1170  cidx = _papi_hwi_component_index( *EventCode );
1171  if (cidx < 0) return PAPI_ENOCMP;
1172 
1173  /* Do we handle presets in componets other than CPU? */
1174  /* if (( IS_PRESET(i) ) && cidx > 0 )) return PAPI_ENOCMP; */
1175 
1176  if ( IS_PRESET(i) ) {
1177  if ( modifier == PAPI_ENUM_FIRST ) {
1178  *EventCode = ( int ) PAPI_PRESET_MASK;
1179  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1180  return ( PAPI_OK );
1181  }
1182  i &= PAPI_PRESET_AND_MASK;
1183  while ( ++i < PAPI_MAX_PRESET_EVENTS ) {
1184  if ( _papi_hwi_presets[i].symbol == NULL ) {
1185  APIDBG("EXIT: PAPI_ENOEVNT\n");
1186  return ( PAPI_ENOEVNT ); /* NULL pointer terminates list */
1187  }
1188  if ( modifier & PAPI_PRESET_ENUM_AVAIL ) {
1189  if ( _papi_hwi_presets[i].count == 0 )
1190  continue;
1191  }
1192  *EventCode = ( int ) ( i | PAPI_PRESET_MASK );
1193  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1194  return ( PAPI_OK );
1195  }
1197  }
1198 
1199  if ( IS_NATIVE(i) ) {
1200  // save event code so components can get it with call to: _papi_hwi_get_papi_event_code()
1201  _papi_hwi_set_papi_event_code(*EventCode, 0);
1202 
1203  /* Should check against num native events here */
1204 
1205  event_code=_papi_hwi_eventcode_to_native((int)*EventCode);
1206  retval = _papi_hwd[cidx]->ntv_enum_events((unsigned int *)&event_code, modifier );
1207 
1208  if (retval!=PAPI_OK) {
1209  APIDBG("VMW: retval=%d\n",retval);
1210  return PAPI_EINVAL;
1211  }
1212 
1213  evt_name = _papi_hwi_get_papi_event_string();
1214  *EventCode = _papi_hwi_native_to_eventcode(cidx, event_code, -1, evt_name);
1216 
1217  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1218  return retval;
1219  }
1220 
1221  if ( IS_USER_DEFINED(i) ) {
1222  if ( modifier == PAPI_ENUM_FIRST ) {
1223  *EventCode = (int) (0 | PAPI_UE_MASK);
1224  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1225  return ( PAPI_OK );
1226  }
1227 
1228  i &= PAPI_UE_AND_MASK;
1229  ++i;
1230 
1231  if ( i <= 0 || i >= user_defined_events_count ) {
1232  APIDBG("EXIT: PAPI_ENOEVNT\n");
1233  return ( PAPI_ENOEVNT );
1234  }
1235 
1236  // if next entry does not have an event name, we are done
1237  if (user_defined_events[i].symbol == NULL) {
1238  APIDBG("EXIT: PAPI_ENOEVNT\n");
1239  return ( PAPI_ENOEVNT );
1240  }
1241 
1242  // if next entry does not map to any other events, we are done
1243  if (user_defined_events[i].count == 0) {
1244  APIDBG("EXIT: PAPI_ENOEVNT\n");
1245  return ( PAPI_ENOEVNT );
1246  }
1247 
1248  *EventCode = (int) (i | PAPI_UE_MASK);
1249  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1250  return ( PAPI_OK );
1251  }
1252 
1254 }
1255 
1256 
1361 int
1362 PAPI_enum_cmp_event( int *EventCode, int modifier, int cidx )
1363 {
1364  APIDBG( "Entry: EventCode: %#x, modifier: %d, cidx: %d\n", *EventCode, modifier, cidx);
1365  int i = *EventCode;
1366  int retval;
1367  int event_code;
1368  char *evt_name;
1369 
1370  if ( _papi_hwi_invalid_cmp(cidx) || ( (IS_PRESET(i)) && cidx > 0 ) ) {
1371  return PAPI_ENOCMP;
1372  }
1373 
1374  if (_papi_hwd[cidx]->cmp_info.disabled) {
1375  return PAPI_ENOCMP;
1376  }
1377 
1378  if ( IS_PRESET(i) ) {
1379  if ( modifier == PAPI_ENUM_FIRST ) {
1380  *EventCode = ( int ) PAPI_PRESET_MASK;
1381  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1382  return PAPI_OK;
1383  }
1384  i &= PAPI_PRESET_AND_MASK;
1385  while ( ++i < PAPI_MAX_PRESET_EVENTS ) {
1386  if ( _papi_hwi_presets[i].symbol == NULL ) {
1387  APIDBG("EXIT: PAPI_ENOEVNT\n");
1388  return ( PAPI_ENOEVNT ); /* NULL pointer terminates list */
1389  }
1390  if ( modifier & PAPI_PRESET_ENUM_AVAIL ) {
1391  if ( _papi_hwi_presets[i].count == 0 )
1392  continue;
1393  }
1394  *EventCode = ( int ) ( i | PAPI_PRESET_MASK );
1395  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1396  return PAPI_OK;
1397  }
1399  }
1400 
1401  if ( IS_NATIVE(i) ) {
1402  // save event code so components can get it with call to: _papi_hwi_get_papi_event_code()
1403  _papi_hwi_set_papi_event_code(*EventCode, 0);
1404 
1405  /* Should we check against num native events here? */
1406  event_code=_papi_hwi_eventcode_to_native(*EventCode);
1407  retval = _papi_hwd[cidx]->ntv_enum_events((unsigned int *)&event_code, modifier );
1408 
1409  if (retval!=PAPI_OK) {
1410  APIDBG("EXIT: PAPI_EINVAL retval=%d\n",retval);
1411  return PAPI_EINVAL;
1412  }
1413 
1414  evt_name = _papi_hwi_get_papi_event_string();
1415  *EventCode = _papi_hwi_native_to_eventcode(cidx, event_code, -1, evt_name);
1417 
1418  APIDBG("EXIT: *EventCode: %#x\n", *EventCode);
1419  return retval;
1420  }
1421 
1423 }
1424 
1468 int
1470 {
1471  APIDBG("Entry: EventSet: %p\n", EventSet);
1472 
1473  ThreadInfo_t *master;
1474  int retval;
1475 
1476  if ( init_level == PAPI_NOT_INITED )
1478  retval = _papi_hwi_lookup_or_create_thread( &master, 0 );
1479  if ( retval )
1480  papi_return( retval );
1481 
1482  papi_return( _papi_hwi_create_eventset( EventSet, master ) );
1483 }
1484 
1530 int
1532 {
1533  EventSetInfo_t *ESI;
1534  int retval;
1535 
1536  ESI = _papi_hwi_lookup_EventSet( EventSet );
1537  if ( ESI == NULL )
1539 
1540 /* validate cidx */
1541  retval = valid_component( cidx );
1542  if ( retval < 0 )
1543  papi_return( retval );
1544 
1545 /* cowardly refuse to reassign eventsets */
1546  if ( ESI->CmpIdx >= 0 )
1547  return PAPI_EINVAL;
1548 
1549  return ( _papi_hwi_assign_eventset( ESI, cidx ) );
1550 }
1551 
1573 int
1575 {
1576  EventSetInfo_t *ESI;
1577  int retval;
1578 
1579 /* validate eventset */
1580  ESI = _papi_hwi_lookup_EventSet( EventSet );
1581  if ( ESI == NULL )
1583 
1584 /* check if a component has been assigned */
1585  if ( ESI->CmpIdx < 0 )
1587 
1588 /* validate CmpIdx */
1589  retval = valid_component( ESI->CmpIdx );
1590  if ( retval < 0 )
1591  papi_return( retval );
1592 
1593 /* return the index */
1594  return ( ESI->CmpIdx );
1595 }
1596 
1597 
1667 int
1668 PAPI_add_event( int EventSet, int EventCode )
1669 {
1670  APIDBG("Entry: EventSet: %d, EventCode: %#x\n", EventSet, EventCode);
1671  EventSetInfo_t *ESI;
1672 
1673  /* Is the EventSet already in existence? */
1674 
1675  ESI = _papi_hwi_lookup_EventSet( EventSet );
1676  if ( ESI == NULL )
1678 
1679  /* Check argument for validity */
1680 
1681  if ( ( ( EventCode & PAPI_PRESET_MASK ) == 0 ) &&
1682  ( EventCode & PAPI_NATIVE_MASK ) == 0 )
1684 
1685  /* Of course, it must be stopped in order to modify it. */
1686 
1687  if ( ESI->state & PAPI_RUNNING )
1689 
1690  /* Now do the magic. */
1691  int retval = _papi_hwi_add_event( ESI, EventCode );
1692  papi_return( retval );
1693 }
1694 
1762 int
1763 PAPI_remove_event( int EventSet, int EventCode )
1764 {
1765  APIDBG("Entry: EventSet: %d, EventCode: %#x\n", EventSet, EventCode);
1766  EventSetInfo_t *ESI;
1767  int i,retval;
1768 
1769  /* check for pre-existing ESI */
1770 
1771  ESI = _papi_hwi_lookup_EventSet( EventSet );
1772  if ( ESI == NULL )
1774 
1775  /* Check argument for validity */
1776 
1777  if ( ( !IS_PRESET(EventCode) ) &&
1778  ( !IS_NATIVE(EventCode) ) &&
1779  ( !IS_USER_DEFINED(EventCode) ))
1781 
1782  /* Of course, it must be stopped in order to modify it. */
1783 
1784  if ( !( ESI->state & PAPI_STOPPED ) )
1786 
1787  /* if the state is PAPI_OVERFLOWING, you must first call
1788  PAPI_overflow with threshold=0 to remove the overflow flag */
1789 
1790  /* Turn off the event that is overflowing */
1791  if ( ESI->state & PAPI_OVERFLOWING ) {
1792  for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
1793  if ( ESI->overflow.EventCode[i] == EventCode ) {
1794  retval = PAPI_overflow( EventSet, EventCode, 0, 0,
1795  ESI->overflow.handler );
1796  if (retval!=PAPI_OK) return retval;
1797  break;
1798  }
1799  }
1800  }
1801 
1802  /* force the user to call PAPI_profil to clear the PAPI_PROFILING flag */
1803  if ( ESI->state & PAPI_PROFILING ) {
1804  for ( i = 0; i < ESI->profile.event_counter; i++ ) {
1805  if ( ESI->profile.EventCode[i] == EventCode ) {
1806  PAPI_sprofil( NULL, 0, EventSet, EventCode, 0, 0 );
1807  break;
1808  }
1809  }
1810  }
1811 
1812  /* Now do the magic. */
1813 
1814  papi_return( _papi_hwi_remove_event( ESI, EventCode ) );
1815 }
1816 
1880 int
1881 PAPI_add_named_event( int EventSet, char *EventName )
1882 {
1883  APIDBG("Entry: EventSet: %d, EventName: %s\n", EventSet, EventName);
1884 
1885  int ret, code;
1886 
1887  ret = PAPI_event_name_to_code( EventName, &code );
1888  if ( ret != PAPI_OK ) {
1889  APIDBG("EXIT: return: %d\n", ret);
1890  return ret; // do not use papi_return here because if there was an error PAPI_event_name_to_code already reported it
1891  }
1892 
1893  ret = PAPI_add_event( EventSet, code );
1894  APIDBG("EXIT: return: %d\n", ret);
1895  return ret; // do not use papi_return here because if there was an error PAPI_add_event already reported it
1896 }
1897 
1965 int
1966 PAPI_remove_named_event( int EventSet, char *EventName )
1967 {
1968  APIDBG("Entry: EventSet: %d, EventName: %s\n", EventSet, EventName);
1969  int ret, code;
1970 
1971  ret = PAPI_event_name_to_code( EventName, &code );
1972  if ( ret == PAPI_OK ) ret = PAPI_remove_event( EventSet, code );
1973  papi_return( ret );
1974 }
1975 
2017 int
2019 {
2020  APIDBG("Entry: EventSet: %p, *EventSet: %d\n", EventSet, *EventSet);
2021 
2022  EventSetInfo_t *ESI;
2023 
2024  /* check for pre-existing ESI */
2025 
2026  if ( EventSet == NULL )
2028 
2029  ESI = _papi_hwi_lookup_EventSet( *EventSet );
2030  if ( ESI == NULL )
2032 
2033  if ( !( ESI->state & PAPI_STOPPED ) )
2035 
2036  if ( ESI->NumberOfEvents )
2038 
2040  *EventSet = PAPI_NULL;
2041 
2042  return PAPI_OK;
2043 }
2044 
2045 /* simply checks for valid EventSet, calls component start() call */
2099 int
2101 {
2102  APIDBG("Entry: EventSet: %d\n", EventSet);
2103 
2104  int is_dirty=0;
2105  int retval;
2106  EventSetInfo_t *ESI;
2107  ThreadInfo_t *thread = NULL;
2108  CpuInfo_t *cpu = NULL;
2109  hwd_context_t *context;
2110  int cidx;
2111 
2112  ESI = _papi_hwi_lookup_EventSet( EventSet );
2113  if ( ESI == NULL ) {
2115  }
2116 
2117  APIDBG("EventSet: %p\n", ESI);
2118 
2119  cidx = valid_ESI_component( ESI );
2120  if ( cidx < 0 ) {
2121  papi_return( cidx );
2122  }
2123 
2124  /* only one event set per thread can be running at any time, */
2125  /* so if another event set is running, the user must stop that */
2126  /* event set explicitly */
2127 
2128  /* We used to check and not let multiple events be attached */
2129  /* to the same CPU, but this was unnecessary? */
2130 
2131  thread = ESI->master;
2132  cpu = ESI->CpuInfo;
2133 
2134  if ( thread->running_eventset[cidx] ) {
2135  APIDBG("Thread Running already (Only one active Eventset per component)\n");
2137  }
2138 
2139  /* Check that there are added events */
2140  if ( ESI->NumberOfEvents < 1 ) {
2142  }
2143 
2144  /* If multiplexing is enabled for this eventset,
2145  call John May's code. */
2146 
2147  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2148  retval = MPX_start( ESI->multiplex.mpx_evset );
2149  if ( retval != PAPI_OK ) {
2150  papi_return( retval );
2151  }
2152 
2153  /* Update the state of this EventSet */
2154  ESI->state ^= PAPI_STOPPED;
2155  ESI->state |= PAPI_RUNNING;
2156 
2157  return PAPI_OK;
2158  }
2159 
2160  /* get the context we should use for this event set */
2161  context = _papi_hwi_get_context( ESI, &is_dirty );
2162  if (is_dirty) {
2163  /* we need to reset the context state because it was last used */
2164  /* for some other event set and does not contain the information */
2165  /* for our events. */
2166  retval = _papi_hwd[ESI->CmpIdx]->update_control_state(
2167  ESI->ctl_state,
2168  ESI->NativeInfoArray,
2169  ESI->NativeCount,
2170  context);
2171  if ( retval != PAPI_OK ) {
2172  papi_return( retval );
2173  }
2174 
2175  /* now that the context contains this event sets information, */
2176  /* make sure the position array in the EventInfoArray is correct */
2177 
2178  /* We have to do this because ->update_control_state() can */
2179  /* in theory re-order the native events out from under us. */
2181 
2182  }
2183 
2184  /* If overflowing is enabled, turn it on */
2185  if ( ( ESI->state & PAPI_OVERFLOWING ) &&
2186  !( ESI->overflow.flags & PAPI_OVERFLOW_HARDWARE ) ) {
2188  NEED_CONTEXT, cidx );
2189  if ( retval != PAPI_OK ) {
2190  papi_return( retval );
2191  }
2192 
2193  /* Update the state of this EventSet and thread */
2194  /* before to avoid races */
2195  ESI->state ^= PAPI_STOPPED;
2196  ESI->state |= PAPI_RUNNING;
2197  /* can not be attached to thread or cpu if overflowing */
2198  thread->running_eventset[cidx] = ESI;
2199 
2200  retval = _papi_hwd[cidx]->start( context, ESI->ctl_state );
2201  if ( retval != PAPI_OK ) {
2203  ESI->state ^= PAPI_RUNNING;
2204  ESI->state |= PAPI_STOPPED;
2205  thread->running_eventset[cidx] = NULL;
2206  papi_return( retval );
2207  }
2208 
2212  if ( retval != PAPI_OK ) {
2214  _papi_hwd[cidx]->stop( context, ESI->ctl_state );
2215  ESI->state ^= PAPI_RUNNING;
2216  ESI->state |= PAPI_STOPPED;
2217  thread->running_eventset[cidx] = NULL;
2218  papi_return( retval );
2219  }
2220  } else {
2221  /* Update the state of this EventSet and thread before */
2222  /* to avoid races */
2223  ESI->state ^= PAPI_STOPPED;
2224  ESI->state |= PAPI_RUNNING;
2225 
2226  /* if not attached to cpu or another process */
2227  if ( !(ESI->state & PAPI_CPU_ATTACHED) ) {
2228  if ( !( ESI->state & PAPI_ATTACHED ) ) {
2229  thread->running_eventset[cidx] = ESI;
2230  }
2231  } else {
2232  cpu->running_eventset[cidx] = ESI;
2233  }
2234 
2235  retval = _papi_hwd[cidx]->start( context, ESI->ctl_state );
2236  if ( retval != PAPI_OK ) {
2237  _papi_hwd[cidx]->stop( context, ESI->ctl_state );
2238  ESI->state ^= PAPI_RUNNING;
2239  ESI->state |= PAPI_STOPPED;
2240  if ( !(ESI->state & PAPI_CPU_ATTACHED) ) {
2241  if ( !( ESI->state & PAPI_ATTACHED ) )
2242  thread->running_eventset[cidx] = NULL;
2243  } else {
2244  cpu->running_eventset[cidx] = NULL;
2245  }
2246  papi_return( retval );
2247  }
2248  }
2249 
2250  return retval;
2251 }
2252 
2253 /* checks for valid EventSet, calls component stop() function. */
2304 int
2305 PAPI_stop( int EventSet, long long *values )
2306 {
2307  APIDBG("Entry: EventSet: %d, values: %p\n", EventSet, values);
2308  EventSetInfo_t *ESI;
2309  hwd_context_t *context;
2310  int cidx, retval;
2311 
2312  ESI = _papi_hwi_lookup_EventSet( EventSet );
2313  if ( ESI == NULL )
2315 
2316  cidx = valid_ESI_component( ESI );
2317  if ( cidx < 0 )
2318  papi_return( cidx );
2319 
2320  if ( !( ESI->state & PAPI_RUNNING ) )
2322 
2323  /* If multiplexing is enabled for this eventset, turn if off */
2324 
2325  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2326  retval = MPX_stop( ESI->multiplex.mpx_evset, values );
2327  if ( retval != PAPI_OK )
2328  papi_return( retval );
2329 
2330  /* Update the state of this EventSet */
2331 
2332  ESI->state ^= PAPI_RUNNING;
2333  ESI->state |= PAPI_STOPPED;
2334 
2335  return ( PAPI_OK );
2336  }
2337 
2338  /* get the context we should use for this event set */
2339  context = _papi_hwi_get_context( ESI, NULL );
2340  /* Read the current counter values into the EventSet */
2341  retval = _papi_hwi_read( context, ESI, ESI->sw_stop );
2342  if ( retval != PAPI_OK )
2343  papi_return( retval );
2344 
2345  /* Remove the control bits from the active counter config. */
2346  retval = _papi_hwd[cidx]->stop( context, ESI->ctl_state );
2347  if ( retval != PAPI_OK )
2348  papi_return( retval );
2349  if ( values )
2350  memcpy( values, ESI->sw_stop,
2351  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2352 
2353  /* If kernel profiling is in use, flush and process the kernel buffer */
2354 
2355  if ( ESI->state & PAPI_PROFILING ) {
2356  if ( _papi_hwd[cidx]->cmp_info.kernel_profile &&
2357  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
2358  retval = _papi_hwd[cidx]->stop_profiling( ESI->master, ESI );
2359  if ( retval < PAPI_OK )
2360  papi_return( retval );
2361  }
2362  }
2363 
2364  /* If overflowing is enabled, turn it off */
2365 
2366  if ( ESI->state & PAPI_OVERFLOWING ) {
2367  if ( !( ESI->overflow.flags & PAPI_OVERFLOW_HARDWARE ) ) {
2370  if ( retval != PAPI_OK )
2371  papi_return( retval );
2373  }
2374  }
2375 
2376  /* Update the state of this EventSet */
2377 
2378  ESI->state ^= PAPI_RUNNING;
2379  ESI->state |= PAPI_STOPPED;
2380 
2381  /* Update the running event set for this thread */
2382  if ( !(ESI->state & PAPI_CPU_ATTACHED) ) {
2383  if ( !( ESI->state & PAPI_ATTACHED ))
2384  ESI->master->running_eventset[cidx] = NULL;
2385  } else {
2386  ESI->CpuInfo->running_eventset[cidx] = NULL;
2387  }
2388 
2389 #if defined(DEBUG)
2390  if ( _papi_hwi_debug & DEBUG_API ) {
2391  int i;
2392  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2393  APIDBG( "PAPI_stop ESI->sw_stop[%d]:\t%llu\n", i, ESI->sw_stop[i] );
2394  }
2395  }
2396 #endif
2397 
2398  return ( PAPI_OK );
2399 }
2400 
2449 int
2451 {
2452  APIDBG("Entry: EventSet: %d\n", EventSet);
2453  int retval = PAPI_OK;
2454  EventSetInfo_t *ESI;
2455  hwd_context_t *context;
2456  int cidx;
2457 
2458  ESI = _papi_hwi_lookup_EventSet( EventSet );
2459  if ( ESI == NULL )
2461 
2462  cidx = valid_ESI_component( ESI );
2463  if ( cidx < 0 )
2464  papi_return( cidx );
2465 
2466  if ( ESI->state & PAPI_RUNNING ) {
2467  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2468  retval = MPX_reset( ESI->multiplex.mpx_evset );
2469  } else {
2470  /* If we're not the only one running, then just
2471  read the current values into the ESI->start
2472  array. This holds the starting value for counters
2473  that are shared. */
2474  /* get the context we should use for this event set */
2475  context = _papi_hwi_get_context( ESI, NULL );
2476  retval = _papi_hwd[cidx]->reset( context, ESI->ctl_state );
2477  }
2478  } else {
2479 #ifdef __bgp__
2480  // For BG/P, we always want to reset the 'real' hardware counters. The counters
2481  // can be controlled via multiple interfaces, and we need to ensure that the values
2482  // are truly zero...
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 #endif
2487  memset( ESI->sw_stop, 0x00,
2488  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2489  }
2490 
2491  APIDBG( "EXIT: retval %d\n", retval );
2492  papi_return( retval );
2493 }
2494 
2549 int
2550 PAPI_read( int EventSet, long long *values )
2551 {
2552  APIDBG( "Entry: EventSet: %d, values: %p\n", EventSet, values);
2553  EventSetInfo_t *ESI;
2554  hwd_context_t *context;
2555  int cidx, retval = PAPI_OK;
2556 
2557  ESI = _papi_hwi_lookup_EventSet( EventSet );
2558  if ( ESI == NULL )
2560 
2561  cidx = valid_ESI_component( ESI );
2562  if ( cidx < 0 )
2563  papi_return( cidx );
2564 
2565  if ( values == NULL )
2567 
2568  if ( ESI->state & PAPI_RUNNING ) {
2569  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2570  retval = MPX_read( ESI->multiplex.mpx_evset, values, 0 );
2571  } else {
2572  /* get the context we should use for this event set */
2573  context = _papi_hwi_get_context( ESI, NULL );
2574  retval = _papi_hwi_read( context, ESI, values );
2575  }
2576  if ( retval != PAPI_OK )
2577  papi_return( retval );
2578  } else {
2579  memcpy( values, ESI->sw_stop,
2580  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2581  }
2582 
2583 #if defined(DEBUG)
2584  if ( ISLEVEL( DEBUG_API ) ) {
2585  int i;
2586  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2587  APIDBG( "PAPI_read values[%d]:\t%lld\n", i, values[i] );
2588  }
2589  }
2590 #endif
2591 
2592  APIDBG( "PAPI_read returns %d\n", retval );
2593  return ( PAPI_OK );
2594 }
2595 
2638 int
2639 PAPI_read_ts( int EventSet, long long *values, long long *cycles )
2640 {
2641  APIDBG( "Entry: EventSet: %d, values: %p, cycles: %p\n", EventSet, values, cycles);
2642  EventSetInfo_t *ESI;
2643  hwd_context_t *context;
2644  int cidx, retval = PAPI_OK;
2645 
2646  ESI = _papi_hwi_lookup_EventSet( EventSet );
2647  if ( ESI == NULL )
2649 
2650  cidx = valid_ESI_component( ESI );
2651  if ( cidx < 0 )
2652  papi_return( cidx );
2653 
2654  if ( values == NULL )
2656 
2657  if ( ESI->state & PAPI_RUNNING ) {
2658  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2659  retval = MPX_read( ESI->multiplex.mpx_evset, values, 0 );
2660  } else {
2661  /* get the context we should use for this event set */
2662  context = _papi_hwi_get_context( ESI, NULL );
2663  retval = _papi_hwi_read( context, ESI, values );
2664  }
2665  if ( retval != PAPI_OK )
2666  papi_return( retval );
2667  } else {
2668  memcpy( values, ESI->sw_stop,
2669  ( size_t ) ESI->NumberOfEvents * sizeof ( long long ) );
2670  }
2671 
2672  *cycles = _papi_os_vector.get_real_cycles( );
2673 
2674 #if defined(DEBUG)
2675  if ( ISLEVEL( DEBUG_API ) ) {
2676  int i;
2677  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2678  APIDBG( "PAPI_read values[%d]:\t%lld\n", i, values[i] );
2679  }
2680  }
2681 #endif
2682 
2683  APIDBG( "PAPI_read_ts returns %d\n", retval );
2684  return PAPI_OK;
2685 }
2686 
2735 int
2736 PAPI_accum( int EventSet, long long *values )
2737 {
2738  APIDBG("Entry: EventSet: %d, values: %p\n", EventSet, values);
2739  EventSetInfo_t *ESI;
2740  hwd_context_t *context;
2741  int i, cidx, retval;
2742  long long a, b, c;
2743 
2744  ESI = _papi_hwi_lookup_EventSet( EventSet );
2745  if ( ESI == NULL )
2747 
2748  cidx = valid_ESI_component( ESI );
2749  if ( cidx < 0 )
2750  papi_return( cidx );
2751 
2752  if ( values == NULL )
2754 
2755  if ( ESI->state & PAPI_RUNNING ) {
2756  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2757  retval = MPX_read( ESI->multiplex.mpx_evset, ESI->sw_stop, 0 );
2758  } else {
2759  /* get the context we should use for this event set */
2760  context = _papi_hwi_get_context( ESI, NULL );
2761  retval = _papi_hwi_read( context, ESI, ESI->sw_stop );
2762  }
2763  if ( retval != PAPI_OK )
2764  papi_return( retval );
2765  }
2766 
2767  for ( i = 0; i < ESI->NumberOfEvents; i++ ) {
2768  a = ESI->sw_stop[i];
2769  b = values[i];
2770  c = a + b;
2771  values[i] = c;
2772  }
2773 
2774  papi_return( PAPI_reset( EventSet ) );
2775 }
2776 
2803 int
2804 PAPI_write( int EventSet, long long *values )
2805 {
2806  APIDBG("Entry: EventSet: %d, values: %p\n", EventSet, values);
2807 
2808  int cidx, retval = PAPI_OK;
2809  EventSetInfo_t *ESI;
2810  hwd_context_t *context;
2811 
2812  ESI = _papi_hwi_lookup_EventSet( EventSet );
2813  if ( ESI == NULL )
2815 
2816  cidx = valid_ESI_component( ESI );
2817  if ( cidx < 0 )
2818  papi_return( cidx );
2819 
2820  if ( values == NULL )
2822 
2823  if ( ESI->state & PAPI_RUNNING ) {
2824  /* get the context we should use for this event set */
2825  context = _papi_hwi_get_context( ESI, NULL );
2826  retval = _papi_hwd[cidx]->write( context, ESI->ctl_state, values );
2827  if ( retval != PAPI_OK )
2828  return ( retval );
2829  }
2830 
2831  memcpy( ESI->hw_start, values,
2832  ( size_t ) _papi_hwd[cidx]->cmp_info.num_cntrs *
2833  sizeof ( long long ) );
2834 
2835  return ( retval );
2836 }
2837 
2880 int
2882 {
2883  APIDBG("Entry: EventSet: %d\n",EventSet);
2884 
2885  EventSetInfo_t *ESI;
2886  int i, cidx, total, retval;
2887 
2888  /* Is the EventSet already in existence? */
2889 
2890  ESI = _papi_hwi_lookup_EventSet( EventSet );
2891  if ( ESI == NULL )
2893 
2894  /* if the eventset has no index and no events, return OK
2895  otherwise return NOCMP */
2896  cidx = valid_ESI_component( ESI );
2897  if ( cidx < 0 ) {
2898  if ( ESI->NumberOfEvents )
2899  papi_return( cidx );
2900  papi_return( PAPI_OK );
2901  }
2902 
2903  /* Of course, it must be stopped in order to modify it. */
2904 
2905  if ( ESI->state & PAPI_RUNNING )
2907 
2908  /* clear overflow flag and turn off hardware overflow handler */
2909  if ( ESI->state & PAPI_OVERFLOWING ) {
2910  total = ESI->overflow.event_counter;
2911  for ( i = 0; i < total; i++ ) {
2912  retval = PAPI_overflow( EventSet,
2913  ESI->overflow.EventCode[0], 0, 0, NULL );
2914  if ( retval != PAPI_OK )
2915  papi_return( retval );
2916  }
2917  }
2918 
2919  /* clear profile flag and turn off hardware profile handler */
2920  if ( ( ESI->state & PAPI_PROFILING ) &&
2921  _papi_hwd[cidx]->cmp_info.hardware_intr &&
2922  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
2923  total = ESI->profile.event_counter;
2924  for ( i = 0; i < total; i++ ) {
2925  retval =
2926  PAPI_sprofil( NULL, 0, EventSet, ESI->profile.EventCode[0], 0,
2928  if ( retval != PAPI_OK )
2929  papi_return( retval );
2930  }
2931  }
2932 
2933  if ( _papi_hwi_is_sw_multiplex( ESI ) ) {
2934  retval = MPX_cleanup( &ESI->multiplex.mpx_evset );
2935  if ( retval != PAPI_OK )
2936  papi_return( retval );
2937  }
2938 
2939  retval = _papi_hwd[cidx]->cleanup_eventset( ESI->ctl_state );
2940  if ( retval != PAPI_OK )
2941  papi_return( retval );
2942 
2943  /* Now do the magic */
2945 }
2946 
2972 int
2974 {
2975  APIDBG("Entry:\n");
2976 
2977  int retval;
2978 
2979  retval = mpx_init( _papi_os_info.itimer_ns );
2980  papi_return( retval );
2981 }
2982 
3043 int
3045 {
3046  APIDBG("Entry: EventSet: %d, status: %p\n", EventSet, status);
3047 
3048  EventSetInfo_t *ESI;
3049 
3050  if ( status == NULL )
3052 
3053  /* check for good EventSetIndex value */
3054 
3055  ESI = _papi_hwi_lookup_EventSet( EventSet );
3056  if ( ESI == NULL )
3058 
3059  /*read status FROM ESI->state */
3060 
3061  *status = ESI->state;
3062 
3063  return ( PAPI_OK );
3064 }
3065 
3116 int
3117 PAPI_set_debug( int level )
3118 {
3119  APIDBG("Entry: level: %d\n", level);
3120  PAPI_option_t option;
3121 
3122  memset( &option, 0x0, sizeof ( option ) );
3123  option.debug.level = level;
3125  return ( PAPI_set_opt( PAPI_DEBUG, &option ) );
3126 }
3127 
3128 /* Attaches to or detaches from the specified thread id */
3129 inline_static int
3130 _papi_set_attach( int option, int EventSet, unsigned long tid )
3131 {
3132  APIDBG("Entry: option: %d, EventSet: %d, tid: %lu\n", option, EventSet, tid);
3134 
3135  memset( &attach, 0x0, sizeof ( attach ) );
3136  attach.attach.eventset = EventSet;
3137  attach.attach.tid = tid;
3138  return ( PAPI_set_opt( option, &attach ) );
3139 }
3140 
3191 int
3192 PAPI_attach( int EventSet, unsigned long tid )
3193 {
3194  APIDBG( "Entry: EventSet: %d, tid: %lu\n", EventSet, tid);
3195  return ( _papi_set_attach( PAPI_ATTACH, EventSet, tid ) );
3196 }
3197 
3248 int
3250 {
3251  APIDBG( "Entry: EventSet: %d\n", EventSet);
3252  return ( _papi_set_attach( PAPI_DETACH, EventSet, 0 ) );
3253 }
3254 
3323 int
3325 {
3326  APIDBG( "Entry: EventSet: %d\n", EventSet);
3327 
3328  PAPI_option_t mpx;
3329  EventSetInfo_t *ESI;
3330  int cidx;
3331  int ret;
3332 
3333  /* Is the EventSet already in existence? */
3334 
3335  ESI = _papi_hwi_lookup_EventSet( EventSet );
3336 
3337  if ( ESI == NULL )
3339 
3340  /* if the eventset has no index return NOCMP */
3341  cidx = valid_ESI_component( ESI );
3342  if ( cidx < 0 )
3343  papi_return( cidx );
3344 
3345  if ( ( ret = mpx_check( EventSet ) ) != PAPI_OK )
3346  papi_return( ret );
3347 
3348  memset( &mpx, 0x0, sizeof ( mpx ) );
3349  mpx.multiplex.eventset = EventSet;
3352  return ( PAPI_set_opt( PAPI_MULTIPLEX, &mpx ) );
3353 }
3354 
3455 int
3457 {
3458  APIDBG("Entry: option: %d, ptr: %p\n", option, ptr);
3459 
3460  _papi_int_option_t internal;
3461  int retval = PAPI_OK;
3462  hwd_context_t *context;
3463  int cidx;
3464 
3465  if ( ( option != PAPI_DEBUG ) && ( init_level == PAPI_NOT_INITED ) )
3467  if ( ptr == NULL )
3469 
3470  memset( &internal, 0x0, sizeof ( _papi_int_option_t ) );
3471 
3472  switch ( option ) {
3473  case PAPI_DETACH:
3474  {
3475  internal.attach.ESI = _papi_hwi_lookup_EventSet( ptr->attach.eventset );
3476  if ( internal.attach.ESI == NULL )
3478 
3479  cidx = valid_ESI_component( internal.attach.ESI );
3480  if ( cidx < 0 )
3481  papi_return( cidx );
3482 
3483  if ( _papi_hwd[cidx]->cmp_info.attach == 0 )
3485 
3486  /* if attached to a cpu, return an error */
3487  if (internal.attach.ESI->state & PAPI_CPU_ATTACHED)
3489 
3490  if ( ( internal.attach.ESI->state & PAPI_STOPPED ) == 0 )
3492 
3493  if ( ( internal.attach.ESI->state & PAPI_ATTACHED ) == 0 )
3495 
3496  internal.attach.tid = internal.attach.ESI->attach.tid;
3497  /* get the context we should use for this event set */
3498  context = _papi_hwi_get_context( internal.attach.ESI, NULL );
3499  retval = _papi_hwd[cidx]->ctl( context, PAPI_DETACH, &internal );
3500  if ( retval != PAPI_OK )
3501  papi_return( retval );
3502 
3503  internal.attach.ESI->state ^= PAPI_ATTACHED;
3504  internal.attach.ESI->attach.tid = 0;
3505  return ( PAPI_OK );
3506  }
3507  case PAPI_ATTACH:
3508  {
3509  internal.attach.ESI = _papi_hwi_lookup_EventSet( ptr->attach.eventset );
3510  if ( internal.attach.ESI == NULL )
3512 
3513  cidx = valid_ESI_component( internal.attach.ESI );
3514  if ( cidx < 0 )
3515  papi_return( cidx );
3516 
3517  if ( _papi_hwd[cidx]->cmp_info.attach == 0 )
3519 
3520  if ( ( internal.attach.ESI->state & PAPI_STOPPED ) == 0 )
3522 
3523  if ( internal.attach.ESI->state & PAPI_ATTACHED )
3525 
3526  /* if attached to a cpu, return an error */
3527  if (internal.attach.ESI->state & PAPI_CPU_ATTACHED)
3529 
3530  internal.attach.tid = ptr->attach.tid;
3531  /* get the context we should use for this event set */
3532  context = _papi_hwi_get_context( internal.attach.ESI, NULL );
3533  retval = _papi_hwd[cidx]->ctl( context, PAPI_ATTACH, &internal );
3534  if ( retval != PAPI_OK )
3535  papi_return( retval );
3536 
3537  internal.attach.ESI->state |= PAPI_ATTACHED;
3538  internal.attach.ESI->attach.tid = ptr->attach.tid;
3539 
3541  &(internal.attach.ESI->master), ptr->attach.tid ));
3542  }
3543  case PAPI_CPU_ATTACH:
3544  {
3545  APIDBG("eventset: %d, cpu_num: %d\n", ptr->cpu.eventset, ptr->cpu.cpu_num);
3546  internal.cpu.ESI = _papi_hwi_lookup_EventSet( ptr->cpu.eventset );
3547  if ( internal.cpu.ESI == NULL )
3549 
3550  internal.cpu.cpu_num = ptr->cpu.cpu_num;
3551  APIDBG("internal: %p, ESI: %p, cpu_num: %d\n", &internal, internal.cpu.ESI, internal.cpu.cpu_num);
3552 
3553  cidx = valid_ESI_component( internal.cpu.ESI );
3554  if ( cidx < 0 )
3555  papi_return( cidx );
3556 
3557  if ( _papi_hwd[cidx]->cmp_info.cpu == 0 )
3559 
3560  // can not attach to a cpu if already attached to a process or
3561  // counters set to be inherited by child processes
3562  if ( internal.cpu.ESI->state & (PAPI_ATTACHED | PAPI_INHERIT) )
3564 
3565  if ( ( internal.cpu.ESI->state & PAPI_STOPPED ) == 0 )
3567 
3568  retval = _papi_hwi_lookup_or_create_cpu(&internal.cpu.ESI->CpuInfo, internal.cpu.cpu_num);
3569  if( retval != PAPI_OK) {
3570  papi_return( retval );
3571  }
3572 
3573  /* get the context we should use for this event set */
3574  context = _papi_hwi_get_context( internal.cpu.ESI, NULL );
3575  retval = _papi_hwd[cidx]->ctl( context, PAPI_CPU_ATTACH, &internal );
3576  if ( retval != PAPI_OK )
3577  papi_return( retval );
3578 
3579  /* set to show this event set is attached to a cpu not a thread */
3580  internal.cpu.ESI->state |= PAPI_CPU_ATTACHED;
3581  return ( PAPI_OK );
3582  }
3583  case PAPI_DEF_MPX_NS:
3584  {
3585  cidx = 0; /* xxxx for now, assume we only check against cpu component */
3586  if ( ptr->multiplex.ns < 0 )
3588  /* We should check the resolution here with the system, either
3589  component if kernel multiplexing or PAPI if SW multiplexing. */
3590  internal.multiplex.ns = ( unsigned long ) ptr->multiplex.ns;
3591  /* get the context we should use for this event set */
3592  context = _papi_hwi_get_context( internal.cpu.ESI, NULL );
3593  /* Low level just checks/adjusts the args for this component */
3594  retval = _papi_hwd[cidx]->ctl( context, PAPI_DEF_MPX_NS, &internal );
3595  if ( retval == PAPI_OK ) {
3596  _papi_os_info.itimer_ns = ( int ) internal.multiplex.ns;
3597  ptr->multiplex.ns = ( int ) internal.multiplex.ns;
3598  }
3599  papi_return( retval );
3600  }
3601  case PAPI_DEF_ITIMER_NS:
3602  {
3603  cidx = 0; /* xxxx for now, assume we only check against cpu component */
3604  if ( ptr->itimer.ns < 0 )
3606  internal.itimer.ns = ptr->itimer.ns;
3607  /* Low level just checks/adjusts the args for this component */
3608  retval = _papi_hwd[cidx]->ctl( NULL, PAPI_DEF_ITIMER_NS, &internal );
3609  if ( retval == PAPI_OK ) {
3610  _papi_os_info.itimer_ns = internal.itimer.ns;
3611  ptr->itimer.ns = internal.itimer.ns;
3612  }
3613  papi_return( retval );
3614  }
3615  case PAPI_DEF_ITIMER:
3616  {
3617  cidx = 0; /* xxxx for now, assume we only check against cpu component */
3618  if ( ptr->itimer.ns < 0 )
3620  memcpy( &internal.itimer, &ptr->itimer,
3622  /* Low level just checks/adjusts the args for this component */
3623  retval = _papi_hwd[cidx]->ctl( NULL, PAPI_DEF_ITIMER, &internal );
3624  if ( retval == PAPI_OK ) {
3627  if ( ptr->itimer.ns > 0 )
3629  /* flags are currently ignored, eventually the flags will be able
3630  to specify whether or not we use POSIX itimers (clock_gettimer) */
3631  }
3632  papi_return( retval );
3633  }
3634  case PAPI_MULTIPLEX:
3635  {
3636  EventSetInfo_t *ESI;
3638 
3639  if ( ESI == NULL )
3641 
3642  cidx = valid_ESI_component( ESI );
3643  if ( cidx < 0 )
3644  papi_return( cidx );
3645 
3646  if ( !( ESI->state & PAPI_STOPPED ) )
3648  if ( ESI->state & PAPI_MULTIPLEXING )
3650 
3651  if ( ptr->multiplex.ns < 0 )
3653  internal.multiplex.ESI = ESI;
3654  internal.multiplex.ns = ( unsigned long ) ptr->multiplex.ns;
3655  internal.multiplex.flags = ptr->multiplex.flags;
3656  if ( ( _papi_hwd[cidx]->cmp_info.kernel_multiplex ) &&
3657  ( ( ptr->multiplex.flags & PAPI_MULTIPLEX_FORCE_SW ) == 0 ) ) {
3658  /* get the context we should use for this event set */
3659  context = _papi_hwi_get_context( ESI, NULL );
3660  retval = _papi_hwd[cidx]->ctl( context, PAPI_MULTIPLEX, &internal );
3661  }
3662  /* Kernel or PAPI may have changed this value so send it back out to the user */
3663  ptr->multiplex.ns = ( int ) internal.multiplex.ns;
3664  if ( retval == PAPI_OK )
3666  ( &internal.multiplex ) );
3667  return ( retval );
3668  }
3669  case PAPI_DEBUG:
3670  {
3671  int level = ptr->debug.level;
3672  switch ( level ) {
3673  case PAPI_QUIET:
3674  case PAPI_VERB_ESTOP:
3675  case PAPI_VERB_ECONT:
3676  _papi_hwi_error_level = level;
3677  break;
3678  default:
3680  }
3682  return ( PAPI_OK );
3683  }
3684  case PAPI_DEFDOM:
3685  {
3686  int dom = ptr->defdomain.domain;
3687  if ( ( dom < PAPI_DOM_MIN ) || ( dom > PAPI_DOM_MAX ) )
3689 
3690  /* Change the global structure. The _papi_hwd_init_control_state function
3691  in the components gets information from the global structure instead of
3692  per-thread information. */
3693  cidx = valid_component( ptr->defdomain.def_cidx );
3694  if ( cidx < 0 )
3695  papi_return( cidx );
3696 
3697  /* Check what the component supports */
3698 
3699  if ( dom == PAPI_DOM_ALL )
3701 
3702  if ( dom & ~_papi_hwd[cidx]->cmp_info.available_domains )
3704 
3706 
3707  return ( PAPI_OK );
3708  }
3709  case PAPI_DOMAIN:
3710  {
3711  int dom = ptr->domain.domain;
3712  if ( ( dom < PAPI_DOM_MIN ) || ( dom > PAPI_DOM_MAX ) )
3714 
3715  internal.domain.ESI = _papi_hwi_lookup_EventSet( ptr->domain.eventset );
3716  if ( internal.domain.ESI == NULL )
3718 
3719  cidx = valid_ESI_component( internal.domain.ESI );
3720  if ( cidx < 0 )
3721  papi_return( cidx );
3722 
3723  /* Check what the component supports */
3724 
3725  if ( dom == PAPI_DOM_ALL )
3727 
3728  if ( dom & ~_papi_hwd[cidx]->cmp_info.available_domains )
3730 
3731  if ( !( internal.domain.ESI->state & PAPI_STOPPED ) )
3733 
3734  /* Try to change the domain of the eventset in the hardware */
3735  internal.domain.domain = dom;
3736  internal.domain.eventset = ptr->domain.eventset;
3737  /* get the context we should use for this event set */
3738  context = _papi_hwi_get_context( internal.domain.ESI, NULL );
3739  retval = _papi_hwd[cidx]->ctl( context, PAPI_DOMAIN, &internal );
3740  if ( retval < PAPI_OK )
3741  papi_return( retval );
3742 
3743  /* Change the domain of the eventset in the library */
3744 
3745  internal.domain.ESI->domain.domain = dom;
3746 
3747  return ( retval );
3748  }
3749  case PAPI_DEFGRN:
3750  {
3751  int grn = ptr->defgranularity.granularity;
3752  if ( ( grn < PAPI_GRN_MIN ) || ( grn > PAPI_GRN_MAX ) )
3754 
3755  cidx = valid_component( ptr->defgranularity.def_cidx );
3756  if ( cidx < 0 )
3757  papi_return( cidx );
3758 
3759  /* Change the component structure. The _papi_hwd_init_control_state function
3760  in the components gets information from the global structure instead of
3761  per-thread information. */
3762 
3763  /* Check what the component supports */
3764 
3765  if ( grn & ~_papi_hwd[cidx]->cmp_info.available_granularities )
3767 
3768  /* Make sure there is only 1 set. */
3769  if ( grn ^ ( 1 << ( ffs( grn ) - 1 ) ) )
3771 
3773 
3774  return ( PAPI_OK );
3775  }
3776  case PAPI_GRANUL:
3777  {
3778  int grn = ptr->granularity.granularity;
3779 
3780  if ( ( grn < PAPI_GRN_MIN ) || ( grn > PAPI_GRN_MAX ) )
3782 
3783  internal.granularity.ESI =
3785  if ( internal.granularity.ESI == NULL )
3787 
3788  cidx = valid_ESI_component( internal.granularity.ESI );
3789  if ( cidx < 0 )
3790  papi_return( cidx );
3791 
3792  /* Check what the component supports */
3793 
3794  if ( grn & ~_papi_hwd[cidx]->cmp_info.available_granularities )
3796 
3797  /* Make sure there is only 1 set. */
3798  if ( grn ^ ( 1 << ( ffs( grn ) - 1 ) ) )
3800 
3801  internal.granularity.granularity = grn;
3802  internal.granularity.eventset = ptr->granularity.eventset;
3803  retval = _papi_hwd[cidx]->ctl( NULL, PAPI_GRANUL, &internal );
3804  if ( retval < PAPI_OK )
3805  return ( retval );
3806 
3807  internal.granularity.ESI->granularity.granularity = grn;
3808  return ( retval );
3809  }
3810  case PAPI_INHERIT:
3811  {
3812  EventSetInfo_t *ESI;
3814  if ( ESI == NULL )
3816 
3817  cidx = valid_ESI_component( ESI );
3818  if ( cidx < 0 )
3819  papi_return( cidx );
3820 
3821  if ( _papi_hwd[cidx]->cmp_info.inherit == 0 )
3823 
3824  if ( ( ESI->state & PAPI_STOPPED ) == 0 )
3826 
3827  /* if attached to a cpu, return an error */
3828  if (ESI->state & PAPI_CPU_ATTACHED)
3830 
3831  internal.inherit.ESI = ESI;
3832  internal.inherit.inherit = ptr->inherit.inherit;
3833 
3834  /* get the context we should use for this event set */
3835  context = _papi_hwi_get_context( internal.inherit.ESI, NULL );
3836  retval = _papi_hwd[cidx]->ctl( context, PAPI_INHERIT, &internal );
3837  if ( retval < PAPI_OK )
3838  return ( retval );
3839 
3840  ESI->inherit.inherit = ptr->inherit.inherit;
3841  return ( retval );
3842  }
3843  case PAPI_DATA_ADDRESS:
3844  case PAPI_INSTR_ADDRESS:
3845  {
3846 
3847  EventSetInfo_t *ESI;
3848 
3849  ESI = _papi_hwi_lookup_EventSet( ptr->addr.eventset );
3850  if ( ESI == NULL )
3852 
3853  cidx = valid_ESI_component( ESI );
3854  if ( cidx < 0 )
3855  papi_return( cidx );
3856 
3857  internal.address_range.ESI = ESI;
3858 
3859  if ( !( internal.address_range.ESI->state & PAPI_STOPPED ) )
3861 
3862  /*set domain to be PAPI_DOM_USER */
3863  internal.address_range.domain = PAPI_DOM_USER;
3864 
3865  internal.address_range.start = ptr->addr.start;
3866  internal.address_range.end = ptr->addr.end;
3867  /* get the context we should use for this event set */
3868  context = _papi_hwi_get_context( internal.address_range.ESI, NULL );
3869  retval = _papi_hwd[cidx]->ctl( context, option, &internal );
3870  ptr->addr.start_off = internal.address_range.start_off;
3871  ptr->addr.end_off = internal.address_range.end_off;
3872  papi_return( retval );
3873  }
3874  case PAPI_USER_EVENTS_FILE:
3875  {
3876  APIDBG("User Events Filename is -%s-\n", ptr->events_file);
3877 
3878  // go load the user defined event definitions from the applications event definition file
3879  // do not know how to find a pmu name and type for this operation yet
3880 // retval = papi_load_derived_events(pmu_str, pmu_type, cidx, 0);
3881 
3882 // _papi_user_defined_events_setup(ptr->events_file);
3883  return( PAPI_OK );
3884  }
3885  default:
3887  }
3888 }
3889 
3899 int
3901 {
3902  APIDBG( "Entry:\n");
3903  return ( PAPI_num_cmp_hwctrs( 0 ) );
3904 }
3905 
3955 int
3957 {
3958  APIDBG( "Entry: cidx: %d\n", cidx);
3959  return ( PAPI_get_cmp_opt( PAPI_MAX_HWCTRS, NULL, cidx ) );
3960 }
3961 
4018 int
4020 {
4021  APIDBG( "Entry: EventSet: %d\n", EventSet);
4022  PAPI_option_t popt;
4023  int retval;
4024 
4025  popt.multiplex.eventset = EventSet;
4026  retval = PAPI_get_opt( PAPI_MULTIPLEX, &popt );
4027  if ( retval < 0 )
4028  retval = 0;
4029  return retval;
4030 }
4031 
4133 int
4135 {
4136  APIDBG( "Entry: option: %d, ptr: %p\n", option, ptr);
4137  EventSetInfo_t *ESI;
4138 
4139  if ( ( option != PAPI_DEBUG ) && ( init_level == PAPI_NOT_INITED ) )
4141 
4142  switch ( option ) {
4143  case PAPI_DETACH:
4144  {
4145  if ( ptr == NULL )
4148  if ( ESI == NULL )
4150  ptr->attach.tid = ESI->attach.tid;
4151  return ( ( ESI->state & PAPI_ATTACHED ) == 0 );
4152  }
4153  case PAPI_ATTACH:
4154  {
4155  if ( ptr == NULL )
4158  if ( ESI == NULL )
4160  ptr->attach.tid = ESI->attach.tid;
4161  return ( ( ESI->state & PAPI_ATTACHED ) != 0 );
4162  }
4163  case PAPI_CPU_ATTACH:
4164  {
4165  if ( ptr == NULL )
4168  if ( ESI == NULL )
4170  ptr->cpu.cpu_num = ESI->CpuInfo->cpu_num;
4171  return ( ( ESI->state & PAPI_CPU_ATTACHED ) != 0 );
4172  }
4173  case PAPI_DEF_MPX_NS:
4174  {
4175  /* xxxx for now, assume we only check against cpu component */
4176  if ( ptr == NULL )
4179  return ( PAPI_OK );
4180  }
4181  case PAPI_DEF_ITIMER_NS:
4182  {
4183  /* xxxx for now, assume we only check against cpu component */
4184  if ( ptr == NULL )
4187  return ( PAPI_OK );
4188  }
4189  case PAPI_DEF_ITIMER:
4190  {
4191  /* xxxx for now, assume we only check against cpu component */
4192  if ( ptr == NULL )
4197  ptr->itimer.flags = 0;
4198  return ( PAPI_OK );
4199  }
4200  case PAPI_MULTIPLEX:
4201  {
4202  if ( ptr == NULL )
4205  if ( ESI == NULL )
4207  ptr->multiplex.ns = ESI->multiplex.ns;
4208  ptr->multiplex.flags = ESI->multiplex.flags;
4209  return ( ESI->state & PAPI_MULTIPLEXING ) != 0;
4210  }
4211  case PAPI_PRELOAD:
4212  if ( ptr == NULL )
4214  memcpy( &ptr->preload, &_papi_hwi_system_info.preload_info,
4216  break;
4217  case PAPI_DEBUG:
4218  if ( ptr == NULL )
4222  break;
4223  case PAPI_CLOCKRATE:
4224  return ( ( int ) _papi_hwi_system_info.hw_info.cpu_max_mhz );
4225  case PAPI_MAX_CPUS:
4226  return ( _papi_hwi_system_info.hw_info.ncpu );
4227  /* For now, MAX_HWCTRS and MAX CTRS are identical.
4228  At some future point, they may map onto different values.
4229  */
4230  case PAPI_INHERIT:
4231  {
4232  if ( ptr == NULL )
4235  if ( ESI == NULL )
4237  ptr->inherit.inherit = ESI->inherit.inherit;
4238  return ( PAPI_OK );
4239  }
4240  case PAPI_GRANUL:
4241  if ( ptr == NULL )
4244  if ( ESI == NULL )
4247  break;
4248  case PAPI_EXEINFO:
4249  if ( ptr == NULL )
4252  break;
4253  case PAPI_HWINFO:
4254  if ( ptr == NULL )
4257  break;
4258 
4259  case PAPI_DOMAIN:
4260  if ( ptr == NULL )
4263  if ( ESI == NULL )
4265  ptr->domain.domain = ESI->domain.domain;
4266  return ( PAPI_OK );
4267  case PAPI_LIB_VERSION:
4268  return ( PAPI_VERSION );
4269 /* The following cases all require a component index
4270  and are handled by PAPI_get_cmp_opt() with cidx == 0*/
4271  case PAPI_MAX_HWCTRS:
4272  case PAPI_MAX_MPX_CTRS:
4273  case PAPI_DEFDOM:
4274  case PAPI_DEFGRN:
4275  case PAPI_SHLIBINFO:
4276  case PAPI_COMPONENTINFO:
4277  return ( PAPI_get_cmp_opt( option, ptr, 0 ) );
4278  default:
4280  }
4281  return ( PAPI_OK );
4282 }
4283 
4325 int
4327 {
4328  APIDBG( "Entry: option: %d, ptr: %p, cidx: %d\n", option, ptr, cidx);
4329 
4330  if (_papi_hwi_invalid_cmp(cidx)) {
4331  return PAPI_ECMP;
4332  }
4333 
4334  switch ( option ) {
4335  /* For now, MAX_HWCTRS and MAX CTRS are identical.
4336  At some future point, they may map onto different values.
4337  */
4338  case PAPI_MAX_HWCTRS:
4339  return ( _papi_hwd[cidx]->cmp_info.num_cntrs );
4340  case PAPI_MAX_MPX_CTRS:
4341  return ( _papi_hwd[cidx]->cmp_info.num_mpx_cntrs );
4342  case PAPI_DEFDOM:
4343  return ( _papi_hwd[cidx]->cmp_info.default_domain );
4344  case PAPI_DEFGRN:
4345  return ( _papi_hwd[cidx]->cmp_info.default_granularity );
4346  case PAPI_SHLIBINFO:
4347  {
4348  int retval;
4349  if ( ptr == NULL )
4353  papi_return( retval );
4354  }
4355  case PAPI_COMPONENTINFO:
4356  if ( ptr == NULL )
4358  ptr->cmp_info = &( _papi_hwd[cidx]->cmp_info );
4359  return PAPI_OK;
4360  default:
4362  }
4363  return PAPI_OK;
4364 }
4365 
4377 int
4379 {
4380  APIDBG( "Entry:\n");
4381  return ( papi_num_components );
4382 }
4383 
4416 int
4418 {
4419  APIDBG( "Entry: EventSet: %d\n", EventSet);
4420  EventSetInfo_t *ESI;
4421 
4422  ESI = _papi_hwi_lookup_EventSet( EventSet );
4423  if ( !ESI )
4425 
4426 #ifdef DEBUG
4427  /* Not necessary */
4428  if ( ESI->NumberOfEvents == 0 )
4430 #endif
4431 
4432  return ( ESI->NumberOfEvents );
4433 }
4434 
4435 
4451 void
4453 {
4454  APIDBG( "Entry:\n");
4455 
4456  EventSetInfo_t *ESI;
4457  ThreadInfo_t *master;
4459  int i, j = 0, k, retval;
4460 
4461 
4462  if ( init_retval == DEADBEEF ) {
4464  return;
4465  }
4466 
4467  MPX_shutdown( );
4468 
4469  /* Free all EventSets for this thread */
4470 
4471  master = _papi_hwi_lookup_thread( 0 );
4472 
4473  /* Count number of running EventSets AND */
4474  /* Stop any running EventSets in this thread */
4475 
4476 #ifdef DEBUG
4477 again:
4478 #endif
4479  for( i = 0; i < map->totalSlots; i++ ) {
4480  ESI = map->dataSlotArray[i];
4481  if ( ESI ) {
4482  if ( ESI->master == master ) {
4483  if ( ESI->state & PAPI_RUNNING ) {
4484  if((retval = PAPI_stop( i, NULL )) != PAPI_OK) {
4485  APIDBG("Call to PAPI_stop failed: %d\n", retval);
4486  }
4487  }
4488  retval=PAPI_cleanup_eventset( i );
4489  if (retval!=PAPI_OK) PAPIERROR("Error during cleanup.");
4490  _papi_hwi_free_EventSet( ESI );
4491  }
4492  else {
4493  if ( ESI->state & PAPI_RUNNING ) {
4494  j++;
4495  }
4496  }
4497  }
4498  }
4499 
4500  /* No locking required, we're just waiting for the others
4501  to call shutdown or stop their eventsets. */
4502 
4503 #ifdef DEBUG
4504  if ( j != 0 ) {
4506  sleep( 1 );
4507  j = 0;
4508  goto again;
4509  }
4510 #endif
4511 
4512  // if we have some user events defined, release the space they allocated
4513  // give back the strings which were allocated when each event was created
4514  for ( i=0 ; i<user_defined_events_count ; i++) {
4515  papi_free (user_defined_events[i].symbol);
4516  papi_free (user_defined_events[i].postfix);
4517  papi_free (user_defined_events[i].long_descr);
4518  papi_free (user_defined_events[i].short_descr);
4519  papi_free (user_defined_events[i].note);
4520  for ( k=0 ; k<(int)(user_defined_events[i].count) ; k++) {
4521  papi_free (user_defined_events[i].name[k]);
4522  }
4523  }
4524  // make sure the user events list is empty
4525  memset (user_defined_events, '\0' , sizeof(user_defined_events));
4526  user_defined_events_count = 0;
4527 
4528  /* Shutdown the entire component */
4532  for( i = 0; i < papi_num_components; i++ ) {
4533  if (!_papi_hwd[i]->cmp_info.disabled) {
4535  }
4536  }
4537 
4538  /* Now it is safe to call re-init */
4539 
4543 }
4544 
4593 char *
4594 PAPI_strerror( int errorCode )
4595 {
4596  if ( ( errorCode > 0 ) || ( -errorCode > _papi_hwi_num_errors ) )
4597  return ( NULL );
4598 
4599  return ( _papi_errlist[-errorCode] );
4600 }
4601 
4643 void
4644 PAPI_perror( char *msg )
4645 {
4646  char *foo;
4647 
4648  foo = PAPI_strerror( _papi_hwi_errno );
4649  if ( foo == NULL )
4650  return;
4651 
4652  if ( msg )
4653  if ( *msg )
4654  fprintf( stderr, "%s: ", msg );
4655 
4656  fprintf( stderr, "%s\n", foo );
4657 }
4658 
4778 int
4779 PAPI_overflow( int EventSet, int EventCode, int threshold, int flags,
4781 {
4782  APIDBG( "Entry: EventSet: %d, EventCode: %#x, threshold: %d, flags: %#x, handler: %p\n", EventSet, EventCode, threshold, flags, handler);
4783  int retval, cidx, index, i;
4784  EventSetInfo_t *ESI;
4785 
4786  ESI = _papi_hwi_lookup_EventSet( EventSet );
4787  if ( ESI == NULL ) {
4788  OVFDBG("No EventSet\n");
4790  }
4791 
4792  cidx = valid_ESI_component( ESI );
4793  if ( cidx < 0 ) {
4794  OVFDBG("Component Error\n");
4795  papi_return( cidx );
4796  }
4797 
4798  if ( ( ESI->state & PAPI_STOPPED ) != PAPI_STOPPED ) {
4799  OVFDBG("Already running\n");
4801  }
4802 
4803  if ( ESI->state & PAPI_ATTACHED ) {
4804  OVFDBG("Attached\n");
4806  }
4807 
4808  if ( ESI->state & PAPI_CPU_ATTACHED ) {
4809  OVFDBG("CPU attached\n");
4811  }
4812 
4813  if ( ( index = _papi_hwi_lookup_EventCodeIndex( ESI,
4814  ( unsigned int ) EventCode ) ) < 0 ) {
4816  }
4817 
4818  if ( threshold < 0 ) {
4819  OVFDBG("Threshold below zero\n");
4821  }
4822 
4823  /* We do not support derived events in overflow */
4824  /* Unless it's DERIVED_CMPD in which no calculations are done */
4825 
4826  if ( !( flags & PAPI_OVERFLOW_FORCE_SW ) && threshold != 0 &&
4827  ( ESI->EventInfoArray[index].derived ) &&
4828  ( ESI->EventInfoArray[index].derived != DERIVED_CMPD ) ) {
4829  OVFDBG("Derived event in overflow\n");
4831  }
4832 
4833  /* the first time to call PAPI_overflow function */
4834 
4835  if ( !( ESI->state & PAPI_OVERFLOWING ) ) {
4836  if ( handler == NULL ) {
4837  OVFDBG("NULL handler\n");
4839  }
4840  if ( threshold == 0 ) {
4841  OVFDBG("Zero threshold\n");
4843  }
4844  }
4845  if ( threshold > 0 &&
4848 
4849  if ( threshold == 0 ) {
4850  for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
4851  if ( ESI->overflow.EventCode[i] == EventCode )
4852  break;
4853  }
4854  /* EventCode not found */
4855  if ( i == ESI->overflow.event_counter )
4857  /* compact these arrays */
4858  while ( i < ESI->overflow.event_counter - 1 ) {
4859  ESI->overflow.deadline[i] = ESI->overflow.deadline[i + 1];
4860  ESI->overflow.threshold[i] = ESI->overflow.threshold[i + 1];
4861  ESI->overflow.EventIndex[i] = ESI->overflow.EventIndex[i + 1];
4862  ESI->overflow.EventCode[i] = ESI->overflow.EventCode[i + 1];
4863  i++;
4864  }
4865  ESI->overflow.deadline[i] = 0;
4866  ESI->overflow.threshold[i] = 0;
4867  ESI->overflow.EventIndex[i] = 0;
4868  ESI->overflow.EventCode[i] = 0;
4869  ESI->overflow.event_counter--;
4870  } else {
4871  if ( ESI->overflow.event_counter > 0 ) {
4872  if ( ( flags & PAPI_OVERFLOW_FORCE_SW ) &&
4875  if ( !( flags & PAPI_OVERFLOW_FORCE_SW ) &&
4876  ( ESI->overflow.flags & PAPI_OVERFLOW_FORCE_SW ) )
4878  }
4879  for ( i = 0; i < ESI->overflow.event_counter; i++ ) {
4880  if ( ESI->overflow.EventCode[i] == EventCode )
4881  break;
4882  }
4883  /* A new entry */
4884  if ( i == ESI->overflow.event_counter ) {
4885  ESI->overflow.EventCode[i] = EventCode;
4886  ESI->overflow.event_counter++;
4887  }
4888  /* New or existing entry */
4889  ESI->overflow.deadline[i] = threshold;
4890  ESI->overflow.threshold[i] = threshold;
4891  ESI->overflow.EventIndex[i] = index;
4892  ESI->overflow.flags = flags;
4893 
4894  }
4895 
4896  /* If overflowing is already active, we should check to
4897  make sure that we don't specify a different handler
4898  or different flags here. You can't mix them. */
4899 
4900  ESI->overflow.handler = handler;
4901 
4902  /* Set up the option structure for the low level.
4903  If we have hardware interrupts and we are not using
4904  forced software emulated interrupts */
4905 
4906  if ( _papi_hwd[cidx]->cmp_info.hardware_intr &&
4907  !( ESI->overflow.flags & PAPI_OVERFLOW_FORCE_SW ) ) {
4908  retval = _papi_hwd[cidx]->set_overflow( ESI, index, threshold );
4909  if ( retval == PAPI_OK )
4911  else {
4912  papi_return( retval ); /* We should undo stuff here */
4913  }
4914  } else {
4915  /* Make sure hardware overflow is not set */
4916  ESI->overflow.flags &= ~( PAPI_OVERFLOW_HARDWARE );
4917  }
4918 
4919  APIDBG( "Overflow using: %s\n",
4920  ( ESI->overflow.
4921  flags & PAPI_OVERFLOW_HARDWARE ? "[Hardware]" : ESI->overflow.
4922  flags & PAPI_OVERFLOW_FORCE_SW ? "[Forced Software]" :
4923  "[Software]" ) );
4924 
4925  /* Toggle the overflow flags and ESI state */
4926 
4927  if ( ESI->overflow.event_counter >= 1 )
4928  ESI->state |= PAPI_OVERFLOWING;
4929  else {
4930  ESI->state ^= PAPI_OVERFLOWING;
4931  ESI->overflow.flags = 0;
4932  ESI->overflow.handler = NULL;
4933  }
4934 
4935  return PAPI_OK;
4936 }
4937 
5034 int
5035 PAPI_sprofil( PAPI_sprofil_t *prof, int profcnt, int EventSet,
5036  int EventCode, int threshold, int flags )
5037 {
5038  APIDBG( "Entry: prof: %p, profcnt: %d, EventSet: %d, EventCode: %#x, threshold: %d, flags: %#x\n", prof, profcnt, EventSet, EventCode, threshold, flags);
5039  EventSetInfo_t *ESI;
5040  int retval, index, i, buckets;
5041  int forceSW = 0;
5042  int cidx;
5043 
5044  /* Check to make sure EventSet exists */
5045  ESI = _papi_hwi_lookup_EventSet( EventSet );
5046  if ( ESI == NULL ) {
5048  }
5049 
5050  /* Check to make sure EventSet is stopped */
5051  if ( ( ESI->state & PAPI_STOPPED ) != PAPI_STOPPED ) {
5053  }
5054 
5055  /* We cannot profile if attached */
5056  if ( ESI->state & PAPI_ATTACHED ) {
5058  }
5059 
5060  /* We cannot profile if cpu attached */
5061  if ( ESI->state & PAPI_CPU_ATTACHED ) {
5063  }
5064 
5065  /* Get component for EventSet */
5066  cidx = valid_ESI_component( ESI );
5067  if ( cidx < 0 ) {
5068  papi_return( cidx );
5069  }
5070 
5071  /* Get index of the Event we want to profile */
5072  if ( ( index = _papi_hwi_lookup_EventCodeIndex( ESI,
5073  (unsigned int) EventCode ) ) < 0 ) {
5075  }
5076 
5077  /* We do not support derived events in overflow */
5078  /* Unless it's DERIVED_CMPD in which no calculations are done */
5079  if ( ( ESI->EventInfoArray[index].derived ) &&
5080  ( ESI->EventInfoArray[index].derived != DERIVED_CMPD ) &&
5081  !( flags & PAPI_PROFIL_FORCE_SW ) ) {
5083  }
5084 
5085  /* If no prof structures, then make sure count is 0 */
5086  if ( prof == NULL ) {
5087  profcnt = 0;
5088  }
5089 
5090  /* check all profile regions for valid scale factors of:
5091  2 (131072/65536),
5092  1 (65536/65536),
5093  or < 1 (65535 -> 2) as defined in unix profil()
5094  2/65536 is reserved for single bucket profiling
5095  {0,1}/65536 are traditionally used to terminate profiling
5096  but are unused here since PAPI uses threshold instead
5097  */
5098  for( i = 0; i < profcnt; i++ ) {
5099  if ( !( ( prof[i].pr_scale == 131072 ) ||
5100  ( ( prof[i].pr_scale <= 65536 && prof[i].pr_scale > 1 ) ) ) ) {
5101  APIDBG( "Improper scale factor: %d\n", prof[i].pr_scale );
5103  }
5104  }
5105 
5106  /* Make sure threshold is valid */
5107  if ( threshold < 0 ) {
5109  }
5110 
5111  /* the first time to call PAPI_sprofil */
5112  if ( !( ESI->state & PAPI_PROFILING ) ) {
5113  if ( threshold == 0 ) {
5115  }
5116  }
5117 
5118  /* ??? */
5119  if ( (threshold > 0) &&
5120  (ESI->profile.event_counter >= _papi_hwd[cidx]->cmp_info.num_cntrs) ) {
5122  }
5123 
5124  if ( threshold == 0 ) {
5125  for( i = 0; i < ESI->profile.event_counter; i++ ) {
5126  if ( ESI->profile.EventCode[i] == EventCode ) {
5127  break;
5128  }
5129  }
5130 
5131  /* EventCode not found */
5132  if ( i == ESI->profile.event_counter ) {
5134  }
5135 
5136  /* compact these arrays */
5137  while ( i < ESI->profile.event_counter - 1 ) {
5138  ESI->profile.prof[i] = ESI->profile.prof[i + 1];
5139  ESI->profile.count[i] = ESI->profile.count[i + 1];
5140  ESI->profile.threshold[i] = ESI->profile.threshold[i + 1];
5141  ESI->profile.EventIndex[i] = ESI->profile.EventIndex[i + 1];
5142  ESI->profile.EventCode[i] = ESI->profile.EventCode[i + 1];
5143  i++;
5144  }
5145  ESI->profile.prof[i] = NULL;
5146  ESI->profile.count[i] = 0;
5147  ESI->profile.threshold[i] = 0;
5148  ESI->profile.EventIndex[i] = 0;
5149  ESI->profile.EventCode[i] = 0;
5150  ESI->profile.event_counter--;
5151  } else {
5152  if ( ESI->profile.event_counter > 0 ) {
5153  if ( ( flags & PAPI_PROFIL_FORCE_SW ) &&
5154  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
5156  }
5157  if ( !( flags & PAPI_PROFIL_FORCE_SW ) &&
5158  ( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
5160  }
5161  }
5162 
5163  for( i = 0; i < ESI->profile.event_counter; i++ ) {
5164  if ( ESI->profile.EventCode[i] == EventCode ) {
5165  break;
5166  }
5167  }
5168 
5169  if ( i == ESI->profile.event_counter ) {
5170  i = ESI->profile.event_counter;
5171  ESI->profile.event_counter++;
5172  ESI->profile.EventCode[i] = EventCode;
5173  }
5174  ESI->profile.prof[i] = prof;
5175  ESI->profile.count[i] = profcnt;
5176  ESI->profile.threshold[i] = threshold;
5177  ESI->profile.EventIndex[i] = index;
5178  }
5179 
5180  APIDBG( "Profile event counter is %d\n", ESI->profile.event_counter );
5181 
5182  /* Clear out old flags */
5183  if ( threshold == 0 ) {
5184  flags |= ESI->profile.flags;
5185  }
5186 
5187  /* make sure no invalid flags are set */
5188  if ( flags &
5190  PAPI_PROFIL_COMPRESS | PAPI_PROFIL_BUCKETS | PAPI_PROFIL_FORCE_SW |
5193  }
5194 
5195  /* if we have kernel-based profiling, then we're just asking for
5196  signals on interrupt. */
5197  /* if we don't have kernel-based profiling, then we're asking for
5198  emulated PMU interrupt */
5199  if ( ( flags & PAPI_PROFIL_FORCE_SW ) &&
5200  ( _papi_hwd[cidx]->cmp_info.kernel_profile == 0 ) ) {
5201  forceSW = PAPI_OVERFLOW_FORCE_SW;
5202  }
5203 
5204  /* make sure one and only one bucket size is set */
5205  buckets = flags & PAPI_PROFIL_BUCKETS;
5206  if ( !buckets ) {
5207  flags |= PAPI_PROFIL_BUCKET_16; /* default to 16 bit if nothing set */
5208  }
5209  else {
5210  /* return error if more than one set */
5211  if ( !( ( buckets == PAPI_PROFIL_BUCKET_16 ) ||
5212  ( buckets == PAPI_PROFIL_BUCKET_32 ) ||
5213  ( buckets == PAPI_PROFIL_BUCKET_64 ) ) ) {
5215  }
5216  }
5217 
5218  /* Set up the option structure for the low level */
5219  ESI->profile.flags = flags;
5220 
5221  if ( _papi_hwd[cidx]->cmp_info.kernel_profile &&
5222  !( ESI->profile.flags & PAPI_PROFIL_FORCE_SW ) ) {
5223  retval = _papi_hwd[cidx]->set_profile( ESI, index, threshold );
5224  if ( ( retval == PAPI_OK ) && ( threshold > 0 ) ) {
5225  /* We need overflowing because we use the overflow dispatch handler */
5226  ESI->state |= PAPI_OVERFLOWING;
5228  }
5229  } else {
5230  retval = PAPI_overflow( EventSet, EventCode, threshold, forceSW,
5232  }
5233 
5234  if ( retval < PAPI_OK ) {
5235  papi_return( retval ); /* We should undo stuff here */
5236  }
5237 
5238  /* Toggle the profiling flags and ESI state */
5239 
5240  if ( ESI->profile.event_counter >= 1 ) {
5241  ESI->state |= PAPI_PROFILING;
5242  }
5243  else {
5244  ESI->state ^= PAPI_PROFILING;
5245  ESI->profile.flags = 0;
5246  }
5247 
5248  return PAPI_OK;
5249 }
5250 
5428 int
5429 PAPI_profil( void *buf, unsigned bufsiz, caddr_t offset,
5430  unsigned scale, int EventSet, int EventCode, int threshold,
5431  int flags )
5432 {
5433  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);
5434  EventSetInfo_t *ESI;
5435  int i;
5436  int retval;
5437 
5438  ESI = _papi_hwi_lookup_EventSet( EventSet );
5439  if ( ESI == NULL )
5441 
5442  /* scale factors are checked for validity in PAPI_sprofil */
5443 
5444  if ( threshold > 0 ) {
5445  PAPI_sprofil_t *prof;
5446 
5447  for ( i = 0; i < ESI->profile.event_counter; i++ ) {
5448  if ( ESI->profile.EventCode[i] == EventCode )
5449  break;
5450  }
5451 
5452  if ( i == ESI->profile.event_counter ) {
5453  prof =
5454  ( PAPI_sprofil_t * ) papi_malloc( sizeof ( PAPI_sprofil_t ) );
5455  memset( prof, 0x0, sizeof ( PAPI_sprofil_t ) );
5456  prof->pr_base = buf;
5457  prof->pr_size = bufsiz;
5458  prof->pr_off = offset;
5459  prof->pr_scale = scale;
5460 
5461  retval =
5462  PAPI_sprofil( prof, 1, EventSet, EventCode, threshold, flags );
5463 
5464  if ( retval != PAPI_OK )
5465  papi_free( prof );
5466  } else {
5467  prof = ESI->profile.prof[i];
5468  prof->pr_base = buf;
5469  prof->pr_size = bufsiz;
5470  prof->pr_off = offset;
5471  prof->pr_scale = scale;
5472  retval =
5473  PAPI_sprofil( prof, 1, EventSet, EventCode, threshold, flags );
5474  }
5475  papi_return( retval );
5476  }
5477 
5478  for ( i = 0; i < ESI->profile.event_counter; i++ ) {
5479  if ( ESI->profile.EventCode[i] == EventCode )
5480  break;
5481  }
5482  /* EventCode not found */
5483  if ( i == ESI->profile.event_counter )
5485 
5486  papi_free( ESI->profile.prof[i] );
5487  ESI->profile.prof[i] = NULL;
5488 
5489  papi_return( PAPI_sprofil( NULL, 0, EventSet, EventCode, 0, flags ) );
5490 }
5491 
5492 /* This function sets the low level default granularity
5493  for all newly manufactured eventsets. The first function
5494  preserves API compatibility and assumes component 0;
5495  The second function takes a component argument. */
5496 
5547 int
5548 PAPI_set_granularity( int granularity )
5549 {
5550  return ( PAPI_set_cmp_granularity( granularity, 0 ) );
5551 }
5552 
5612 int
5613 PAPI_set_cmp_granularity( int granularity, int cidx )
5614 {
5616 
5617  memset( &ptr, 0, sizeof ( ptr ) );
5619  ptr.defgranularity.granularity = granularity;
5620  papi_return( PAPI_set_opt( PAPI_DEFGRN, &ptr ) );
5621 }
5622 
5623 /* This function sets the low level default counting domain
5624  for all newly manufactured eventsets. The first function
5625  preserves API compatibility and assumes component 0;
5626  The second function takes a component argument. */
5627 
5678 int
5679 PAPI_set_domain( int domain )
5680 {
5681  return ( PAPI_set_cmp_domain( domain, 0 ) );
5682 }
5683 
5748 int
5749 PAPI_set_cmp_domain( int domain, int cidx )
5750 {
5752 
5753  memset( &ptr, 0, sizeof ( ptr ) );
5754  ptr.defdomain.def_cidx = cidx;
5755  ptr.defdomain.domain = domain;
5756  papi_return( PAPI_set_opt( PAPI_DEFDOM, &ptr ) );
5757 }
5758 
5833 int
5834 PAPI_add_events( int EventSet, int *Events, int number )
5835 {
5836  APIDBG( "Entry: EventSet: %d, Events: %p, number: %d\n", EventSet, Events, number);
5837  int i, retval;
5838 
5839  if ( ( Events == NULL ) || ( number <= 0 ) )
5841 
5842  for ( i = 0; i < number; i++ ) {
5843  retval = PAPI_add_event( EventSet, Events[i] );
5844  if ( retval != PAPI_OK ) {
5845  if ( i == 0 )
5846  papi_return( retval );
5847  else
5848  return ( i );
5849  }
5850  }
5851  return ( PAPI_OK );
5852 }
5853 
5921 int
5922 PAPI_remove_events( int EventSet, int *Events, int number )
5923 {
5924  APIDBG( "Entry: EventSet: %d, Events: %p, number: %d\n", EventSet, Events, number);
5925  int i, retval;
5926 
5927  if ( ( Events == NULL ) || ( number <= 0 ) )
5929 
5930  for ( i = 0; i < number; i++ ) {
5931  retval = PAPI_remove_event( EventSet, Events[i] );
5932  if ( retval != PAPI_OK ) {
5933  if ( i == 0 )
5934  papi_return( retval );
5935  else
5936  return ( i );
5937  }
5938  }
5939  return ( PAPI_OK );
5940 }
5941 
5991 int
5992 PAPI_list_events( int EventSet, int *Events, int *number )
5993 {
5994  APIDBG( "Entry: EventSet: %d, Events: %p, number: %p\n", EventSet, Events, number);
5995  EventSetInfo_t *ESI;
5996  int i, j;
5997 
5998  if ( *number < 0 )
6000 
6001  if ( ( Events == NULL ) && ( *number > 0 ) )
6003 
6004  ESI = _papi_hwi_lookup_EventSet( EventSet );
6005  if ( !ESI )
6007 
6008  if ( ( Events == NULL ) || ( *number == 0 ) ) {
6009  *number = ESI->NumberOfEvents;
6010  papi_return( PAPI_OK );
6011  }
6012 
6013  for ( i = 0, j = 0; j < ESI->NumberOfEvents; i++ ) {
6014  if ( ( int ) ESI->EventInfoArray[i].event_code != PAPI_NULL ) {
6015  Events[j] = ( int ) ESI->EventInfoArray[i].event_code;
6016  j++;
6017  if ( j == *number )
6018  break;
6019  }
6020  }
6021 
6022  *number = j;
6023 
6024  return ( PAPI_OK );
6025 }
6026 
6027 /* xxx This is OS dependent, not component dependent, right? */
6053 int
6055 {
6056  if ( dest == NULL )
6057  return PAPI_EINVAL;
6058 
6059  memset( ( void * ) dest, 0x0, sizeof ( PAPI_dmem_info_t ) );
6060  return ( _papi_os_vector.get_dmem_info( dest ) );
6061 }
6062 
6063 
6104 const PAPI_exe_info_t *
6106 {
6108  int retval;
6109 
6110  memset( &ptr, 0, sizeof ( ptr ) );
6111  retval = PAPI_get_opt( PAPI_EXEINFO, &ptr );
6112  if ( retval == PAPI_OK )
6113  return ( ptr.exe_info );
6114  else
6115  return ( NULL );
6116 }
6117 
6134 const PAPI_shlib_info_t *
6136 {
6138  int retval;
6139 
6140  memset( &ptr, 0, sizeof ( ptr ) );
6141  retval = PAPI_get_opt( PAPI_SHLIBINFO, &ptr );
6142  if ( retval == PAPI_OK )
6143  return ( ptr.shlib_info );
6144  else
6145  return ( NULL );
6146 }
6175 const PAPI_hw_info_t *
6177 {
6179  int retval;
6180 
6181  memset( &ptr, 0, sizeof ( ptr ) );
6182  retval = PAPI_get_opt( PAPI_HWINFO, &ptr );
6183  if ( retval == PAPI_OK )
6184  return ( ptr.hw_info );
6185  else
6186  return ( NULL );
6187 }
6188 
6189 
6190 /* The next 4 timing functions always use component 0 */
6191 
6207 long long
6209 {
6210  return ( _papi_os_vector.get_real_cycles( ) );
6211 }
6212 
6226 /* FIXME */
6227 long long
6229 {
6230  return ( ( _papi_os_vector.get_real_nsec( )));
6231 
6232 }
6233 
6254 long long
6256 {
6257  return ( _papi_os_vector.get_real_usec( ) );
6258 }
6259 
6290 long long
6292 {
6293 
6294  return ( ( long long ) _papi_os_vector.get_virt_cycles( ) );
6295 }
6296 
6320 long long
6322 {
6323 
6324  return ( ( _papi_os_vector.get_virt_nsec()));
6325 
6326 }
6327 
6362 long long
6364 {
6365 
6366  return ( ( long long ) _papi_os_vector.get_virt_usec() );
6367 }
6368 
6391 int
6392 PAPI_lock( int lck )
6393 {
6394  if ( ( lck < 0 ) || ( lck >= PAPI_NUM_LOCK ) )
6396 
6397  papi_return( _papi_hwi_lock( lck ) );
6398 }
6399 
6411 int
6412 PAPI_unlock( int lck )
6413 {
6414  if ( ( lck < 0 ) || ( lck >= PAPI_NUM_LOCK ) )
6416 
6417  papi_return( _papi_hwi_unlock( lck ) );
6418 }
6419 
6453 int
6455 {
6456  return ( init_level );
6457 }
6458 
6459 /* This function maps the overflow_vector to event indexes in the event
6460  set, so that user can know which PAPI event overflowed.
6461  int *array---- an array of event indexes in eventset; the first index
6462  maps to the highest set bit in overflow_vector
6463  int *number--- this is an input/output parameter, user should put the
6464  size of the array into this parameter, after the function
6465  is executed, the number of indexes in *array is written
6466  to this parameter
6467 */
6468 
6507 int
6508 PAPI_get_overflow_event_index( int EventSet, long long overflow_vector,
6509  int *array, int *number )
6510 {
6511  APIDBG( "Entry: EventSet: %d, overflow_vector: %lld, array: %p, number: %p\n", EventSet, overflow_vector, array, number);
6512  EventSetInfo_t *ESI;
6513  int set_bit, j, pos;
6514  int count = 0, k;
6515 
6516  if ( overflow_vector == ( long long ) 0 )
6518 
6519  if ( ( array == NULL ) || ( number == NULL ) )
6521 
6522  if ( *number < 1 )
6524 
6525  ESI = _papi_hwi_lookup_EventSet( EventSet );
6526  if ( ESI == NULL )
6528 
6529  /* in case the eventset is empty */
6530  if ( ESI->NumberOfEvents == 0 )
6532 
6533  while ( ( set_bit = ffsll( overflow_vector ) ) ) {
6534  set_bit -= 1;
6535  overflow_vector ^= ( long long ) 1 << set_bit;
6536  for ( j = 0; j < ESI->NumberOfEvents; j++ ) {
6537  for ( k = 0, pos = 0; k < PAPI_EVENTS_IN_DERIVED_EVENT && pos >= 0; k++ ) {
6538  pos = ESI->EventInfoArray[j].pos[k];
6539  if ( ( set_bit == pos ) &&
6540  ( ( ESI->EventInfoArray[j].derived == NOT_DERIVED ) ||
6541  ( ESI->EventInfoArray[j].derived == DERIVED_CMPD ) ) ) {
6542  array[count++] = j;
6543  if ( count == *number )
6544  return PAPI_OK;
6545 
6546  break;
6547  }
6548  }
6549  }
6550  }
6551  *number = count;
6552  return PAPI_OK;
6553 }
6554 
6555 
6573 int
6575 {
6576  APIDBG( "Entry: EventCode: %#x\n", EventCode);
6577  return _papi_hwi_component_index( EventCode);
6578 }
6579 
6602 {
6603  APIDBG( "Entry: name: %s\n", name);
6604  int cidx;
6605 
6606  const PAPI_component_info_t *cinfo;
6607 
6608  for(cidx=0;cidx<papi_num_components;cidx++) {
6609 
6610  cinfo=PAPI_get_component_info(cidx);
6611  if (cinfo==NULL) return PAPI_ENOCMP;
6612 
6613  if (!strcmp(name,cinfo->name)) {
6614  return cidx;
6615  }
6616  }
6617 
6618  return PAPI_ENOCMP;
6619 }
6620 
6621 
6656 int
6658 {
6659  APIDBG( "Entry: cidx: %d\n", cidx);
6660 
6661  const PAPI_component_info_t *cinfo;
6662 
6663  /* Can only run before PAPI_library_init() is called */
6664  if (init_level != PAPI_NOT_INITED) {
6665  return PAPI_ENOINIT;
6666  }
6667 
6668  cinfo=PAPI_get_component_info(cidx);
6669  if (cinfo==NULL) return PAPI_ENOCMP;
6670 
6671  ((PAPI_component_info_t *)cinfo)->disabled=1;
6672  strcpy(((PAPI_component_info_t *)cinfo)->disabled_reason,
6673  "Disabled by PAPI_disable_component()");
6674 
6675  return PAPI_OK;
6676 
6677 }
6678 
6707 int
6709 {
6710  APIDBG( "Entry: name: %s\n", name);
6711  int cidx;
6712 
6713  /* I can only be called before init time */
6714  if (init_level!=PAPI_NOT_INITED) {
6715  return PAPI_ENOINIT;
6716  }
6717 
6718  cidx = PAPI_get_component_index(name);
6719  if (cidx>=0) {
6720  return PAPI_disable_component(cidx);
6721  }
6722 
6723  return PAPI_ENOCMP;
6724 }
#define PAPI_NUM_LOCK
Definition: papi.h:333
int _papi_hwi_is_sw_multiplex(EventSetInfo_t *ESI)
#define PAPI_ATTACHED
Definition: papi.h:379
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:626
i inherit inherit
#define PAPI_ENOEVNT
Definition: papi.h:258
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2305
int PAPI_is_initialized(void)
Definition: papi.c:6454
int _papi_hwi_convert_eventset_to_multiplex(_papi_int_multiplex_t *mpx)
#define PAPI_NATIVE_MASK
#define DEBUG_MULTIPLEX
Definition: papi_debug.h:31
int _papi_hwi_init_global_internal(void)
#define PAPI_OVERFLOWING
Definition: papi.h:376
#define IS_PRESET(EventCode)
Definition: papi.h:227
char * _papi_hwi_get_papi_event_string()
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:805
#define DEBUG_PROFILE
Definition: papi_debug.h:33
#define PAPI_CPU_ATTACH
Definition: papi.h:455
char * getenv()
long long(* get_real_nsec)(void)
Definition: papi_vector.h:65
#define PAPI_VERB_ECONT
Definition: papi.h:387
sleep(1)
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1668
void PAPI_perror(char *msg)
Definition: papi.c:4644
Hardware info structure.
Definition: papi.h:777
inline_static int _papi_set_attach(int option, int EventSet, unsigned long tid)
Definition: papi.c:3130
long long PAPI_get_virt_usec(void)
Definition: papi.c:6363
int PAPI_set_cmp_granularity(int granularity, int cidx)
Definition: papi.c:5613
int PAPI_reset(int EventSet)
Definition: papi.c:2450
#define PAPI_SHUTDOWN_str
Definition: papi_internal.h:42
long long flags
Definition: iozone.c:12330
#define PAPI_DEF_ITIMER_NS
Definition: papi.h:453
int PAPI_add_named_event(int EventSet, char *EventName)
Definition: papi.c:1881
int _papi_hwi_set_thread_id_fn(unsigned long(*id_fn)(void))
Definition: threads.c:352
#define IS_USER_DEFINED(EventCode)
Definition: papi.h:228
#define PAPI_UE_AND_MASK
const PAPI_shlib_info_t * PAPI_get_shared_lib_info(void)
Definition: papi.c:6135
#define papi_free(a)
Definition: papi_memory.h:35
#define PAPI_INSTR_ADDRESS
Definition: papi.h:451
void ** data
Definition: papi.h:561
int _papi_hwi_query_native_event(unsigned int EventCode)
static int Events[NUM_EVENTS]
Definition: init_fini.c:8
int _papi_hwi_cleanup_eventset(EventSetInfo_t *ESI)
EventSetInfo_t ** running_eventset
Definition: cpus.h:15
unsigned long PAPI_thread_id(void)
Definition: papi.c:162
#define PAPI_PROFIL_DATA_EAR
Definition: papi.h:402
int PAPI_write(int EventSet, long long *values)
Definition: papi.c:2804
int _papi_hwi_debug
Definition: papi.c:79
#define papi_return(a)
Definition: papi.c:50
#define PAPI_DEF_MPX_NS
Definition: papi.h:434
cpu
Definition: iozone.c:3872
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1763
#define papi_malloc(a)
Definition: papi_memory.h:34
long long PAPI_get_virt_cyc(void)
Definition: papi.c:6291
int default_granularity
Definition: papi.h:642
PAPI_debug_handler_t _papi_hwi_debug_handler
Definition: papi_internal.c:54
void MPX_shutdown(void)
long long(* get_real_usec)(void)
Definition: papi_vector.h:63
#define PAPI_NULL
Definition: papi.h:290
#define PAPI_LOW_LEVEL_INITED
Definition: papi.h:279
off64_t offset
Definition: iozone.c:1279
#define PAPI_PROFIL_BUCKET_16
Definition: papi.h:398
#define PAPI_DATA_ADDRESS
Definition: papi.h:450
MPX_EventSet * mpx_evset
Definition: sw_multiplex.h:32
#define PAPI_DOM_MIN
Definition: papi.h:297
int EventSet
Definition: data_range.c:25
int PAPI_num_components(void)
Definition: papi.c:4378
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1161
#define PAPI_MAX_PRESET_EVENTS
int _papi_hwi_native_code_to_name(unsigned int EventCode, char *hwi_name, int len)
void _papi_hwi_dummy_handler(int EventSet, void *address, long long overflow_vector, void *context)
EventSetAttachInfo_t attach
PAPI_granularity_option_t granularity
Definition: papi.h:850
int MPX_stop(MPX_EventSet *mpx_events, long long *values)
Definition: sw_multiplex.c:974
#define PAPI_MULTIPLEXING
Definition: papi.h:378
#define PAPI_MULTIPLEX_FORCE_SW
Definition: papi.h:417
caddr_t pr_off
Definition: papi.h:581
#define PAPI_DOM_ALL
Definition: papi.h:301
int PAPI_detach(int EventSet)
Definition: papi.c:3249
int(* update_shlib_info)(papi_mdi_t *mdi)
Definition: papi_vector.h:67
void _papi_hwi_free_papi_event_string()
void(* PAPI_overflow_handler_t)(int EventSet, void *address, long long overflow_vector, void *context)
Definition: papi.h:564
EventSetDomainInfo_t domain
get the executable&#39;s info
Definition: papi.h:704
int PAPI_register_thread(void)
Definition: papi.c:208
int _papi_hwi_errno
Definition: papi_internal.c:56
int _papi_hwi_remove_EventSet(EventSetInfo_t *ESI)
#define PAPI_TLS_NUM
Definition: papi.h:324
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
PAPI_inherit_option_t inherit
Definition: papi.h:849
PAPI_preload_info_t preload_info
#define PAPI_ENOTRUN
Definition: papi.h:260
PAPI_exe_info_t exe_info
long long(* get_virt_usec)(void)
Definition: papi_vector.h:64
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4779
#define PAPI_PRESET_MASK
#define PAPI_DOM_USER
Definition: papi.h:296
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:845
int PAPI_remove_events(int EventSet, int *Events, int number)
Definition: papi.c:5922
long long PAPI_get_virt_nsec(void)
Definition: papi.c:6321
return PAPI_EINVAL
Definition: linux-nvml.c:408
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
int PAPI_sprofil(PAPI_sprofil_t *prof, int profcnt, int EventSet, int EventCode, int threshold, int flags)
Definition: papi.c:5035
void _papi_hwi_init_errors(void)
#define PAPI_NOT_INITED
Definition: papi.h:278
int _papi_hwi_remove_event(EventSetInfo_t *ESI, int EventCode)
#define DEBUG_MEMORY
Definition: papi_debug.h:34
EventSetInfo_t * _papi_hwi_lookup_EventSet(int eventset)
#define DERIVED_CMPD
Definition: papi_internal.h:73
int _papi_hwi_get_user_event_info(int EventCode, PAPI_event_info_t *info)
PAPI_hw_info_t * hw_info
Definition: papi.h:858
double c
Definition: multiplex.c:22
#define PAPI_ENOTPRESET
Definition: papi.h:263
PAPI_user_defined_events_file_t events_file
Definition: papi.h:863
int _papi_hwi_native_name_to_code(char *in, int *out)
papi_vector_t * _papi_hwd[]
#define DEBUG_API
Definition: papi_debug.h:28
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3456
long long(* get_real_cycles)(void)
Definition: papi_vector.h:61
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
int PAPI_add_events(int EventSet, int *Events, int number)
Definition: papi.c:5834
unsigned int cpu_num
Definition: papi.h:821
#define PAPI_INHERIT
Definition: papi.h:456
#define PAPI_PRELOAD
Definition: papi.h:439
#define PAPI_HUGE_STR_LEN
Definition: papi.h:465
unsigned pr_scale
Definition: papi.h:582
PAPI_shlib_info_t shlib_info
Return codes and api definitions.
int MPX_read(MPX_EventSet *mpx_events, long long *values, int called_by_stop)
Definition: sw_multiplex.c:823
#define PAPI_CPU_ATTACHED
Definition: papi.h:380
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:844
int PAPI_disable_component_by_name(char *name)
Definition: papi.c:6708
void * thread_storage[PAPI_MAX_TLS]
Definition: threads.h:29
PAPI_addr_range_option_t addr
Definition: papi.h:862
#define APIDBG(format, args...)
Definition: papi_debug.h:64
int _papi_hwi_shutdown_global_threads(void)
Definition: threads.c:457
int multiplex(void)
Definition: multiplex.c:35
int PAPI_set_cmp_domain(int domain, int cidx)
Definition: papi.c:5749
long long ret
Definition: iozone.c:1346
int PAPI_disable_component(int cidx)
Definition: papi.c:6657
unsigned pr_size
Definition: papi.h:580
#define PAPI_EMISC
Definition: papi.h:265
int PAPI_num_cmp_hwctrs(int cidx)
Definition: papi.c:3956
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:2736
void _papi_hwi_shutdown_highlevel()
Definition: papi_hl.c:836
#define PAPI_TLS_ALL_THREADS
Definition: papi.h:325
int(* shutdown_component)(void)
Definition: papi_vector.h:54
#define PAPI_USER_EVENTS_FILE
Definition: papi.h:457
#define DEADBEEF
Definition: papi_internal.h:26
#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:5429
#define PAPI_THREAD_LEVEL_INITED
Definition: papi.h:281
papi_os_vector_t _papi_os_vector
Definition: aix.c:1288
#define PAPI_PROFIL_COMPRESS
Definition: papi.h:397
int i
Definition: fileop.c:140
inline_static int _papi_hwi_lock(int lck)
Definition: threads.h:64
int _papi_hwi_native_to_eventcode(int cidx, int event_code, int ntv_idx, const char *event_name)
EventSetOverflowInfo_t overflow
int(* stop_profiling)(ThreadInfo_t *, EventSetInfo_t *)
Definition: papi_vector.h:34
char buf[200]
Definition: iozone.c:19609
int PAPI_num_hwctrs(void)
Definition: papi.c:3900
#define PAPI_OVERFLOW_HARDWARE
Definition: papi.h:410
EventSetInheritInfo_t inherit
#define PAPI_SHUTDOWN_SYNC_str
Definition: papi_internal.h:43
struct _CpuInfo * CpuInfo
PAPI_os_info_t _papi_os_info
Definition: aix.c:1210
DynamicArray_t global_eventset_map
struct _ThreadInfo * master
#define PAPI_ENOEVST
Definition: papi.h:262
A pointer to the following is passed to PAPI_get_dmem_info()
Definition: papi.h:868
int MPX_start(MPX_EventSet *mpx_events)
Definition: sw_multiplex.c:692
#define PAPI_LIB_VERSION
Definition: papi.h:447
void PAPI_shutdown(void)
Definition: papi.c:4452
Definition: cpus.h:10
#define IS_NATIVE(EventCode)
Definition: papi.h:226
int PAPI_get_cmp_opt(int option, PAPI_option_t *ptr, int cidx)
Definition: papi.c:4326
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:6105
#define PAPI_PROFIL_BUCKET_64
Definition: papi.h:400
int PAPI_num_events(int EventSet)
Definition: papi.c:4417
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4134
#define NOT_DERIVED
Definition: papi_internal.h:69
int ffsll(long long lli)
Definition: extras.c:497
int k
Definition: iozone.c:19136
static int cidx
Definition: event_info.c:40
#define OVFDBG(format, args...)
Definition: papi_debug.h:68
int _papi_hwi_read(hwd_context_t *context, EventSetInfo_t *ESI, long long *values)
PAPI_sprofil_t ** prof
hwi_presets_t _papi_hwi_presets[PAPI_MAX_PRESET_EVENTS]
#define PAPI_EXEINFO
Definition: papi.h:443
int _papi_hwi_stop_timer(int timer, int signal)
Definition: extras.c:461
int(* start)(hwd_context_t *, hwd_control_state_t *)
Definition: papi_vector.h:28
int PAPI_state(int EventSet, int *status)
Definition: papi.c:3044
pthread_attr_t foo
Definition: iozone.c:18592
#define PAPI_PROFIL_RANDOM
Definition: papi.h:395
#define PAPI_GRANUL
Definition: papi.h:433
inline_static int _papi_hwi_unlock(int lck)
Definition: threads.h:78
void * thread(void *arg)
Definition: kufrin.c:31
int user_defined_events_count
Definition: papi_internal.c:59
#define PAPI_MAX_CPUS
Definition: papi.h:444
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:58
void *long long tid
Definition: iozone.c:18586
#define PAPI_DEFGRN
Definition: papi.h:432
int MPX_cleanup(MPX_EventSet **mpx_events)
#define PAPI_PROFIL_INST_EAR
Definition: papi.h:403
#define DEBUG_LEAK
Definition: papi_debug.h:35
int _papi_hwi_start_timer(int timer, int signal, int ns)
Definition: extras.c:366
int _papi_hwi_lookup_EventCodeIndex(const EventSetInfo_t *ESI, unsigned int EventCode)
int _papi_hwi_add_event(EventSetInfo_t *ESI, int EventCode)
long long
Definition: iozone.c:19827
#define PAPI_ECNFLCT
Definition: papi.h:259
int _papi_hwi_get_native_event_info(unsigned int EventCode, PAPI_event_info_t *info)
#define PAPI_DETACH
Definition: papi.h:427
void PAPIERROR(char *format,...)
int _papi_hwi_start_signal(int signal, int need_context, int cidx)
Definition: extras.c:401
PAPI_cpu_option_t cpu
Definition: papi.h:855
void _papi_hwi_shutdown_global_internal(void)
int _papi_hwi_get_preset_event_info(int EventCode, PAPI_event_info_t *info)
int PAPI_set_granularity(int granularity)
Definition: papi.c:5548
int PAPI_get_component_index(char *name)
Definition: papi.c:6601
#define PAPI_ATTACH
Definition: papi.h:445
#define inline_static
#define DEBUG_INTERNAL
Definition: papi_debug.h:29
#define PAPI_ECMP
Definition: papi.h:254
int(* ctl)(hwd_context_t *, int, _papi_int_option_t *)
Definition: papi_vector.h:39
#define PAPI_GRN_MAX
Definition: papi.h:366
#define PAPI_MAX_MPX_CTRS
Definition: papi.h:437
#define PAPI_MULTIPLEX_DEFAULT
Definition: papi.h:416
#define PAPI_PROFIL_BUCKET_32
Definition: papi.h:399
#define PAPI_EISRUN
Definition: papi.h:261
int _papi_hwi_error_level
Definition: papi_internal.c:53
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1362
PAPI_multiplex_option_t multiplex
Definition: papi.h:856
#define PAPI_MULTIPLEX
Definition: papi.h:429
int _papi_hwi_stop_signal(int signal)
Definition: extras.c:441
long long(* get_virt_nsec)(void)
Definition: papi_vector.h:66
#define THREADS_LOCK
Definition: papi_internal.h:88
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:16
inline_static int valid_ESI_component(EventSetInfo_t *ESI)
Definition: papi.c:94
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2881
int mpx_init(int interval_ns)
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1531
NativeInfo_t * NativeInfoArray
int _papi_hwi_num_errors
Definition: papi_internal.c:57
char version[]
Definition: fileop.c:134
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1469
EventInfo_t * EventInfoArray
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:924
unsigned long int(* _papi_hwi_thread_id_fn)(void)
Definition: threads.c:42
long long * hw_start
int threshold
PAPI_thread_id_t * id
Definition: papi.h:560
static int init_retval
Definition: papi.c:83
unsigned int hardware_intr
Definition: papi.h:649
#define DEBUG_OVERFLOW
Definition: papi_debug.h:32
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:55
strcpy(filename, default_filename)
PAPI_hw_info_t hw_info
again struct sockaddr sizeof(struct sockaddr_in))
#define PAPI_ENOCMP
Definition: papi.h:268
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1013
int PAPI_get_dmem_info(PAPI_dmem_info_t *dest)
Definition: papi.c:6054
#define PAPI_DOMAIN
Definition: papi.h:431
EventSetMultiplexInfo_t multiplex
goto out
Definition: pscanf.h:20
EventSetGranularityInfo_t granularity
hwd_context_t * _papi_hwi_get_context(EventSetInfo_t *ESI, int *is_dirty)
EventSetInfo_t ** dataSlotArray
int(* stop)(hwd_context_t *, hwd_control_state_t *)
Definition: papi_vector.h:29
#define PAPI_COMPONENTINFO
Definition: papi.h:448
int PAPI_query_event(int EventCode)
Definition: papi.c:693
int pos[PAPI_EVENTS_IN_DERIVED_EVENT]
PAPI_debug_handler_t handler
Definition: papi.h:687
#define PAPI_NUM_TLS
Definition: papi.h:320
int PAPI_get_overflow_event_index(int EventSet, long long overflow_vector, int *array, int *number)
Definition: papi.c:6508
unsigned long tid
Definition: papi.h:815
int MPX_reset(MPX_EventSet *mpx_events)
Definition: sw_multiplex.c:937
long long * sw_stop
int PAPI_multiplex_init(void)
Definition: papi.c:2973
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
PAPI_attach_option_t attach
Definition: papi.h:854
void _papi_hwi_set_papi_event_code(unsigned int event_code, int update_flag)
PAPI_granularity_option_t defgranularity
Definition: papi.h:851
long long buckets[BUCKETS]
Definition: iozone.c:24212
int papi_num_components
int(* cleanup_eventset)(hwd_control_state_t *)
Definition: papi_vector.h:33
int PAPI_read_ts(int EventSet, long long *values, long long *cycles)
Definition: papi.c:2639
long long PAPI_get_real_usec(void)
Definition: papi.c:6255
PAPI_exe_info_t * exe_info
Definition: papi.h:860
#define PAPI_PROFIL_POSIX
Definition: papi.h:394
#define PAPI_PROFIL_WEIGHTED
Definition: papi.h:396
int _papi_hwi_init_os(void)
Definition: aix.c:1213
#define PAPI_OVERFLOW_FORCE_SW
Definition: papi.h:409
#define PAPI_DEF_ITIMER
Definition: papi.h:452
long long status
Definition: iozone.c:1335
#define PAPI_PROFILING
Definition: papi.h:377
EventSetInfo_t ** running_eventset
Definition: threads.h:30
int PAPI_unregister_thread(void)
Definition: papi.c:244
#define PAPI_VERSION
Definition: papi.h:222
int _papi_hwi_lookup_or_create_cpu(CpuInfo_t **here, unsigned int cpu_num)
Definition: cpus.c:59
int PAPI_set_thr_specific(int tag, void *ptr)
Definition: papi.c:438
int(* ntv_enum_events)(unsigned int *, int)
Definition: papi_vector.h:43
char * PAPI_strerror(int errorCode)
Definition: papi.c:4594
char * name
Definition: iozone.c:23648
int PAPI_query_named_event(char *EventName)
Definition: papi.c:765
int _papi_hwi_assign_eventset(EventSetInfo_t *ESI, int cidx)
static int total
Definition: rapl_overflow.c:5
int _papi_hwi_init_global(void)
inline_static int _papi_hwi_lookup_or_create_thread(ThreadInfo_t **here, int tid)
Definition: threads.h:145
#define NEED_CONTEXT
Definition: papi_internal.h:98
#define PAPI_HWINFO
Definition: papi.h:442
int _papi_hwi_gather_all_thrspec_data(int tag, PAPI_all_thr_spec_t *where)
Definition: threads.c:554
#define PAPI_CLOCKRATE
Definition: papi.h:440
long long(* get_virt_cycles)(void)
Definition: papi_vector.h:62
char ** _papi_errlist
Definition: papi_internal.c:80
PAPI_debug_option_t debug
Definition: papi.h:848
int PAPI_unlock(int lck)
Definition: papi.c:6412
int cpu_max_mhz
Definition: papi.h:793
#define PAPI_EINVAL_DOM
Definition: papi.h:272
int
Definition: iozone.c:18528
#define PAPI_RUNNING
Definition: papi.h:373
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:6228
#define ISLEVEL(a)
Definition: papi_debug.h:54
inline_static ThreadInfo_t * _papi_hwi_lookup_thread(int custom_tid)
Definition: threads.h:92
#define PAPI_MAX_HWCTRS
Definition: papi.h:441
int _papi_hwi_component_index(int event_code)
#define PAPI_PROFIL_FORCE_SW
Definition: papi.h:401
#define PAPI_QUIET
Definition: papi.h:386
unsigned int event_code
#define PAPI_DEFDOM
Definition: papi.h:430
#define PAPI_STOPPED
Definition: papi.h:372
#define PAPI_ENOINIT
Definition: papi.h:267
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3324
#define PAPI_PRESET_AND_MASK
unsigned long PAPI_thread_id_t
Definition: papi.h:555
#define PAPI_PROFIL_BUCKETS
Definition: papi.h:404
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2018
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int(* set_profile)(EventSetInfo_t *, int, int)
Definition: papi_vector.h:41
PAPI_domain_option_t domain
Definition: papi.h:852
int _papi_hwi_invalid_cmp(int cidx)
#define DEBUG_THREADS
Definition: papi_debug.h:30
int PAPI_set_domain(int domain)
Definition: papi.c:5679
void _papi_hwi_free_EventSet(EventSetInfo_t *ESI)
int PAPI_attach(int EventSet, unsigned long tid)
Definition: papi.c:3192
int _papi_hwi_eventcode_to_native(int event_code)
void * pr_base
Definition: papi.h:579
static int attach(hwd_control_state_t *ctl, unsigned long tid)
Definition: perfctr.c:242
long long PAPI_get_real_cyc(void)
Definition: papi.c:6208
PAPI_shlib_info_t * shlib_info
Definition: papi.h:859
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2550
int _papi_hwi_shutdown_thread(ThreadInfo_t *thread, int force_shutdown)
Definition: threads.c:418
int PAPI_start(int EventSet)
Definition: papi.c:2100
#define PAPI_VERB_ESTOP
Definition: papi.h:388
EventSetProfileInfo_t profile
PAPI_preload_info_t preload
Definition: papi.h:847
int(* get_dmem_info)(PAPI_dmem_info_t *)
Definition: papi_vector.h:70
int init_level
Definition: papi_internal.c:52
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:4019
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6176
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:6392
long long tmp
Definition: iozone.c:12031
#define PAPI_GRN_MIN
Definition: papi.h:361
#define PAPI_VER_CURRENT
Definition: papi.h:223
int PAPI_remove_named_event(int EventSet, char *EventName)
Definition: papi.c:1966
#define PAPI_DOM_MAX
Definition: papi.h:303
inline_static int valid_component(int cidx)
Definition: papi.c:86
int _papi_hwi_init_global_threads(void)
Definition: threads.c:527
int PAPI_list_threads(PAPI_thread_id_t *tids, int *number)
Definition: papi.c:286
PAPI_itimer_option_t itimer
Definition: papi.h:857
int PAPI_get_event_component(int EventCode)
Definition: papi.c:6574
int PAPI_set_debug(int level)
Definition: papi.c:3117
int mpx_check(int EventSet)
void _papi_hwi_map_events_to_native(EventSetInfo_t *ESI)
PAPI_domain_option_t defdomain
Definition: papi.h:853
PAPI_overflow_handler_t handler
int(* set_overflow)(EventSetInfo_t *, int, int)
Definition: papi_vector.h:40
if(gettimeofday(&tp,(struct timezone *) NULL)==-1) perror("gettimeofday")
int _papi_hwi_create_eventset(int *EventSet, ThreadInfo_t *handle)
#define PAPI_DEBUG
Definition: papi.h:428
int PAPI_list_events(int EventSet, int *Events, int *number)
Definition: papi.c:5992
PAPI_component_info_t * cmp_info
Definition: papi.h:861
#define DEBUG_SUBSTRATE
Definition: papi_debug.h:27
int ncpu
Definition: papi.h:778
int PAPI_get_eventset_component(int EventSet)
Definition: papi.c:1574
char * ptr
Definition: iozone.c:23586
#define PAPI_SHLIBINFO
Definition: papi.h:446