int main (int argc, char **argv) { int retval,cid,numcmp; int EventSet = PAPI_NULL; long long values[NUM_EVENTS]; int code; char event_name[PAPI_MAX_STR_LEN]; int total_events=0; int r; const PAPI_component_info_t *cmpinfo = NULL; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); } numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if (!TESTS_QUIET) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); } printf("\tComponent %d - %s\n", cid, cmpinfo->name); } code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); while ( r == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { printf("Error translating %x\n",code); test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } if (!strncmp(event_name,"micpower",8)) { if (!TESTS_QUIET) printf("0x%x %s ",code,event_name); EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()",retval); } retval = PAPI_add_event( EventSet, code ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_event()",retval); } retval = PAPI_start( EventSet); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } retval = PAPI_stop( EventSet, values); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } if (!TESTS_QUIET) printf(" value: %lld\n",values[0]); retval = PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()",retval); } retval = PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()",retval); } total_events++; } r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); } } if (total_events==0) { test_skip(__FILE__,__LINE__,"No coretemp events found",0); } test_pass( __FILE__, NULL, 0 ); return 0; }
int main( int argc, char **argv ) { int i, j = 0, k; int retval; PAPI_event_info_t info; const PAPI_hw_info_t *hwinfo = NULL; command_flags_t flags; int enum_modifier; int numcmp, cid; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Initialize before parsing the input arguments */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } /* Parse the command-line arguments */ parse_args( argc, argv, &flags ); /* Set enum modifier mask */ if ( flags.dear ) enum_modifier = PAPI_NTV_ENUM_DEAR; else if ( flags.darr ) enum_modifier = PAPI_NTV_ENUM_DARR; else if ( flags.iear ) enum_modifier = PAPI_NTV_ENUM_IEAR; else if ( flags.iarr ) enum_modifier = PAPI_NTV_ENUM_IARR; else if ( flags.opcm ) enum_modifier = PAPI_NTV_ENUM_OPCM; else enum_modifier = PAPI_ENUM_EVENTS; if ( !TESTS_QUIET ) { retval = PAPI_set_debug( PAPI_VERB_ECONT ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval ); } } retval = papi_print_header( "Available native events and hardware information.\n", &hwinfo ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); } /* Do this code if an event name was specified on the commandline */ if ( flags.named ) { if ( PAPI_event_name_to_code( flags.name, &i ) == PAPI_OK ) { if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) { printf( "%-30s%s\n%-30s%d\n", "Event name:", info.symbol, "Number of Register Values:", info.count ); printf( "%-29s|%s|\n", "Description:", info.long_descr ); for ( k = 0; k < ( int ) info.count; k++ ) printf( " Register[%2d]: |%s|\n", k, info.name[k] ); /* if unit masks exist but none specified, process all */ if ( !strchr( flags.name, ':' ) ) { if ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { printf( "\nUnit Masks:\n" ); do { retval = PAPI_get_event_info( i, &info ); if ( retval == PAPI_OK ) { if ( parse_unit_masks( &info ) ) { printf( "%-29s|%s|%s|\n", " Mask Info:", info.symbol, info.long_descr ); for ( k = 0; k < ( int ) info.count; k++ ) printf( " Register[%2d]: 0x%08x |%s|\n", k, info.code[k], info.name[k] ); } } } while ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ); } } } } else { printf("Sorry, an event by the name '%s' could not be found.\n", flags.name); printf("Is it typed correctly?\n\n"); exit( 1 ); } } else { /* Print *ALL* available events */ numcmp = PAPI_num_components( ); j = 0; for ( cid = 0; cid < numcmp; cid++ ) { const PAPI_component_info_t *component; component=PAPI_get_component_info(cid); /* Skip if requested enumeration not available */ if (( flags.dear ) && !( component->cntr_DEAR_events )) { continue; } if (( flags.darr ) && !( component->data_address_range)) { continue; } if (( flags.iear ) && !( component->cntr_IEAR_events )) { continue; } if (( flags.iarr ) && !( component->instr_address_range )) { continue; } if (( flags.opcm ) && !( component->cntr_OPCM_events )) { continue; } printf( "===============================================================================\n" ); printf( " Events in Component: %s\n",component->name); printf( "===============================================================================\n" ); /* Always ASK FOR the first event */ /* Don't just assume it'll be the first numeric value */ i = 0 | PAPI_NATIVE_MASK | PAPI_COMPONENT_MASK( cid ); /* UGH PAPI_enum_event() really needs a component field */ PAPI_enum_event( &i, PAPI_ENUM_FIRST ); do { memset( &info, 0, sizeof ( info ) ); retval = PAPI_get_event_info( i, &info ); /* This event may not exist */ if ( retval != PAPI_OK ) continue; /* count only events that as supported by host cpu */ j++; print_event( &info, 0 ); /* Does this matter on anything but perfctr? */ if ( flags.details ) { for ( k = 0; k < ( int ) info.count; k++ ) { if ( strlen( info.name[k] ) ) { printf( " Register[%d] Name: %-20s Value: 0x%-28x|\n", k, info.name[k], info.code[k] ); } } } /* modifier = PAPI_NTV_ENUM_GROUPS returns event codes with a groups id for each group in which this native event lives, in bits 16 - 23 of event code terminating with PAPI_ENOEVNT at the end of the list. */ /* This is an IBM Power issue */ if ( flags.groups ) { k = i; if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) == PAPI_OK ) { printf( "Groups: " ); do { printf( "%4d", ( ( k & PAPI_NTV_GROUP_AND_MASK ) >> PAPI_NTV_GROUP_SHIFT ) - 1 ); } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) ==PAPI_OK ); printf( "\n" ); } } /* Print umasks */ /* components that don't have them can just ignore */ if ( flags.umask ) { k = i; if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { do { retval = PAPI_get_event_info( k, &info ); if ( retval == PAPI_OK ) { if ( parse_unit_masks( &info ) ) print_event( &info, 2 ); } } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ); } } printf( "--------------------------------------------------------------------------------\n" ); } while ( PAPI_enum_event( &i, enum_modifier ) == PAPI_OK ); }
int main( int argc, char **argv ) { int EventSet = PAPI_NULL; long long *values; int num_flops, retval, i, j; int *events, mythreshold; char **names; const PAPI_hw_info_t *hw_info = NULL; int num_events, *ovt; char name[PAPI_MAX_STR_LEN]; const PAPI_component_info_t *comp_info = NULL; int using_perfmon = 0; int using_aix = 0; int numcmp, cid; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } hw_info = PAPI_get_hardware_info( ); if ( hw_info == NULL ) { test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", retval ); } numcmp = PAPI_num_components( ); for ( cid = 0; cid < numcmp; cid++ ) { comp_info = PAPI_get_component_info( cid ); if ( comp_info == NULL ) { test_fail( __FILE__, __LINE__, "PAPI_get_component_info", retval ); } if ( strstr( comp_info->name, "perfmon.c" ) ) { using_perfmon = 1; } if ( strstr( comp_info->name, "aix.c" ) ) { using_aix = 1; } } /* add PAPI_TOT_CYC and one of the events in */ /* PAPI_FP_INS, PAPI_FP_OPS PAPI_TOT_INS, */ /* depending on the availability of the event*/ /* on the platform */ EventSet = enum_add_native_events( &num_events, &events, 1 , 1); if (!TESTS_QUIET) printf("Trying %d events\n",num_events); names = ( char ** ) calloc( ( unsigned int ) num_events, sizeof ( char * ) ); for ( i = 0; i < num_events; i++ ) { if ( PAPI_event_code_to_name( events[i], name ) != PAPI_OK ) { test_fail( __FILE__, __LINE__,"PAPI_event_code_to_name", retval); } else { names[i] = strdup( name ); if (!TESTS_QUIET) printf("%i: %s\n",i,names[i]); } } values = ( long long * ) calloc( ( unsigned int ) ( num_events * ( num_events + 1 ) ), sizeof ( long long ) ); ovt = ( int * ) calloc( ( unsigned int ) num_events, sizeof ( int ) ); #if defined(linux) { char *tmp = getenv( "THRESHOLD" ); if ( tmp ) { mythreshold = atoi( tmp ); } else if (hw_info->mhz!=0) { mythreshold = ( int ) hw_info->mhz * 20000; if (!TESTS_QUIET) printf("Using a threshold of %d (20,000 * MHz)\n",mythreshold); } else { if (!TESTS_QUIET) printf("Using default threshold of %d\n",THRESHOLD); mythreshold = THRESHOLD; } } #else mythreshold = THRESHOLD; #endif num_flops = NUM_FLOPS * 2; /* initial test to make sure they all work */ if (!TESTS_QUIET) printf("Testing that the events all work with no overflow\n"); retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( num_flops ); retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } /* done with initial test */ /* keep adding events? */ for ( i = 0; i < num_events; i++ ) { /* Enable overflow */ if (!TESTS_QUIET) printf("Testing with overflow set on %s\n", names[i]); retval = PAPI_overflow( EventSet, events[i], mythreshold, 0, handler ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } do_flops( num_flops ); retval = PAPI_stop( EventSet, values + ( i + 1 ) * num_events ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } /* Disable overflow */ retval = PAPI_overflow( EventSet, events[i], 0, 0, handler ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); } ovt[i] = total; total = 0; } if ( !TESTS_QUIET ) { printf("\nResults in Matrix-view:\n"); printf( "Test Overflow on %d counters with %d events.\n", num_events,num_events ); printf( "-----------------------------------------------\n" ); printf( "Threshold for overflow is: %d\n", mythreshold ); printf( "Using %d iterations of c += a*b\n", num_flops ); printf( "-----------------------------------------------\n" ); printf( "Test type : " ); for ( i = 0; i < num_events + 1; i++ ) { printf( "%16d", i ); } printf( "\n" ); for ( j = 0; j < num_events; j++ ) { printf( "%-27s : ", names[j] ); for ( i = 0; i < num_events + 1; i++ ) { printf( "%16lld", *( values + j + num_events * i ) ); } printf( "\n" ); } printf( "Overflows : %16s", "" ); for ( i = 0; i < num_events; i++ ) { printf( "%16d", ovt[i] ); } printf( "\n" ); printf( "-----------------------------------------------\n" ); } /* validation */ if ( !TESTS_QUIET ) { printf("\nResults broken out for validation\n"); } if (!TESTS_QUIET) { for ( j = 0; j < num_events+1; j++ ) { if (j==0) { printf("Test results, no overflow:\n\t"); } else { printf("Overflow of event %d, %s\n\t",j-1,names[j-1]); } for(i=0; i < num_events; i++) { if (i==j-1) { printf("*%lld* ",values[(num_events*j)+i]); } else { printf("%lld ",values[(num_events*j)+i]); } } printf("\n"); if (j!=0) { printf("\tOverflow should be %lld / %d = %lld\n", values[(num_events*j)+(j-1)], mythreshold, values[(num_events*j)+(j-1)]/mythreshold); printf("\tOverflow was %d\n",ovt[j-1]); } } } for ( j = 0; j < num_events; j++ ) { //printf("Validation: %lld / %d != %d (%lld)\n", // *( values + j + num_events * (j+1) ) , // mythreshold, // ovt[j], // *(values+j+num_events*(j+1))/mythreshold); if ( *( values + j + num_events * ( j + 1 ) ) / mythreshold != ovt[j] ) { char error_string[BUFSIZ]; if ( using_perfmon ) test_warn( __FILE__, __LINE__, "perfmon substrate handles overflow differently than perf_events", 1 ); else if ( using_aix ) test_warn( __FILE__, __LINE__, "AIX (pmapi) substrate handles overflow differently than various other substrates", 1 ); else { sprintf( error_string, "Overflow value differs from expected %lld / %d != %d (%lld)", *( values + j + num_events * ( j + 1 ) ), mythreshold, ovt[j], *( values + j + num_events * ( j + 1 ) ) / mythreshold ); test_fail( __FILE__, __LINE__, error_string, 1 ); } } } retval = PAPI_cleanup_eventset( EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); retval = PAPI_destroy_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); free( ovt ); for ( i = 0; i < num_events; i++ ) free( names[i] ); free( names ); free( events ); free( values ); test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
int main (int argc, char **argv) { int retval,cid,numcmp; int EventSet = PAPI_NULL; long long values[NUM_EVENTS]; int code; char event_name[PAPI_MAX_STR_LEN]; int total_events=0; int r; const PAPI_component_info_t *cmpinfo = NULL; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); } if (!TESTS_QUIET) { printf("Trying all vmware events\n"); } /* Find our Component */ numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); } if (strstr(cmpinfo->name,"vmware")) { if (!TESTS_QUIET) printf("\tFound vmware component %d - %s\n", cid, cmpinfo->name); } else { continue; } PAPI_event_info_t info; /* Try all events one by one */ code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); while ( r == PAPI_OK ) { retval=PAPI_get_event_info(code,&info); if (retval!=PAPI_OK) { printf("Error getting event info\n"); test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval ); } retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { printf("Error translating %x\n",code); test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } if (!TESTS_QUIET) printf(" %s ",event_name); EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()",retval); } retval = PAPI_add_event( EventSet, code ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_event()",retval); } /* start */ retval = PAPI_start( EventSet); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } /* do something */ usleep(100); /* stop */ retval = PAPI_stop( EventSet, values); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } if (!TESTS_QUIET) printf(" value: %lld %s\n",values[0], info.units); retval = PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()",retval); } retval = PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()",retval); } total_events++; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); } } if (total_events==0) { test_skip(__FILE__,__LINE__,"No vmware events found",0); } if (!TESTS_QUIET) { printf("\n"); } test_pass( __FILE__, NULL, 0 ); return 0; }
int main( int argc, char **argv ) { int i, k, add_count = 0, err_count = 0, unc_count = 0, offcore_count = 0; int retval; PAPI_event_info_t info, info1; const PAPI_hw_info_t *hwinfo = NULL; const PAPI_component_info_t* cmpinfo; char *Intel_i7; int event_code; int numcmp, cid; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Init PAPI library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } retval = papi_print_header( "Test case ALL_NATIVE_EVENTS: Available " "native events and hardware " "information.\n", &hwinfo ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); } numcmp = PAPI_num_components( ); /* we need a little exception processing if it's a Core i7 */ /* Unfortunately, this test never succeeds... */ Intel_i7 = strstr( hwinfo->model_string, "Intel Core i7" ); /* Loop through all components */ for( cid = 0; cid < numcmp; cid++ ) { cmpinfo = PAPI_get_component_info( cid ); if (cmpinfo == NULL) { test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 ); } if (cmpinfo->disabled) { printf( "Name: %-23s %s\n", cmpinfo->name ,cmpinfo->description); printf(" \\-> Disabled: %s\n",cmpinfo->disabled_reason); continue; } /* For platform independence, always ASK FOR the first event */ /* Don't just assume it'll be the first numeric value */ i = 0 | PAPI_NATIVE_MASK; retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid ); do { retval = PAPI_get_event_info( i, &info ); /* Skip OFFCORE and UNCORE events */ /* Adding them will fail currently */ if ( Intel_i7 || ( hwinfo->vendor == PAPI_VENDOR_INTEL ) ) { if ( !strncmp( info.symbol, "UNC_", 4 ) ) { unc_count++; continue; } if ( !strncmp( info.symbol, "OFFCORE_RESPONSE_0", 18 ) ) { offcore_count++; continue; } } /* Enumerate all umasks */ k = i; if ( PAPI_enum_cmp_event(&k, PAPI_NTV_ENUM_UMASKS, cid )==PAPI_OK ) { do { retval = PAPI_get_event_info( k, &info1 ); event_code = ( int ) info1.event_code; if ( check_event( event_code, info1.symbol ) ) { add_count++; } else { err_count++; } } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cid ) == PAPI_OK ); } else { /* Event didn't have any umasks */ event_code = ( int ) info.event_code; if ( check_event( event_code, info.symbol ) ) { add_count++; } else { err_count++; } } } while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cid ) == PAPI_OK ); } printf( "\n\nSuccessfully found and added %d events " "(in %d eventsets).\n", add_count , add_count); if ( err_count ) { printf( "Failed to add %d events.\n", err_count ); } if (( unc_count ) || (offcore_count)) { char warning[BUFSIZ]; sprintf(warning,"%d Uncore and %d Offcore events were ignored", unc_count,offcore_count); test_warn( __FILE__, __LINE__, warning, 1 ); } if ( add_count > 0 ) { test_pass( __FILE__, NULL, 0 ); } else { test_fail( __FILE__, __LINE__, "No events added", 1 ); } exit( 1 ); }
int main (int argc, char **argv) { int retval,cid,rapl_cid=-1,numcmp; int EventSet = PAPI_NULL; long long *values; int num_events=0; int code; char event_names[MAX_RAPL_EVENTS][PAPI_MAX_STR_LEN]; char units[MAX_RAPL_EVENTS][PAPI_MIN_STR_LEN]; int r,i; const PAPI_component_info_t *cmpinfo = NULL; PAPI_event_info_t evinfo; long long before_time,after_time; double elapsed_time; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); } if (!TESTS_QUIET) { printf("Trying all RAPL events\n"); } numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); } if (strstr(cmpinfo->name,"rapl")) { rapl_cid=cid; if (!TESTS_QUIET) { printf("Found rapl component at cid %d\n",rapl_cid); } if (cmpinfo->disabled) { if (!TESTS_QUIET) { printf("RAPL component disabled: %s\n", cmpinfo->disabled_reason); } test_skip(__FILE__,__LINE__,"RAPL component disabled",0); } break; } } /* Component not found */ if (cid==numcmp) { test_skip(__FILE__,__LINE__,"No rapl component found\n",0); } /* Create EventSet */ retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()",retval); } /* Add all events */ code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, rapl_cid ); while ( r == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_names[num_events] ); if ( retval != PAPI_OK ) { printf("Error translating %#x\n",code); test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } retval = PAPI_get_event_info(code,&evinfo); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "Error getting event info\n",retval); } strncpy(units[num_events],evinfo.units,PAPI_MIN_STR_LEN); retval = PAPI_add_event( EventSet, code ); if (retval != PAPI_OK) { break; /* We've hit an event limit */ } num_events++; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, rapl_cid ); } values=calloc(num_events,sizeof(long long)); if (values==NULL) { test_fail(__FILE__, __LINE__, "No memory",retval); } if (!TESTS_QUIET) { printf("\nStarting measurements...\n\n"); } /* Start Counting */ before_time=PAPI_get_real_nsec(); retval = PAPI_start( EventSet); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } /* Run test */ run_test(TESTS_QUIET); /* Stop Counting */ after_time=PAPI_get_real_nsec(); retval = PAPI_stop( EventSet, values); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } elapsed_time=((double)(after_time-before_time))/1.0e9; if (!TESTS_QUIET) { printf("\nStopping measurements, took %.3fs, gathering results...\n\n", elapsed_time); printf("Energy measurements:\n"); for(i=0;i<num_events;i++) { if (strstr(units[i],"nJ")) { printf("%s\t%.6fJ\t(Average Power %.1fW)\n", event_names[i], (double)values[i]/1.0e9, ((double)values[i]/1.0e9)/elapsed_time); } } printf("\n"); printf("Fixed values:\n"); for(i=0;i<num_events;i++) { if (!strstr(units[i],"nJ")) { union { long long ll; double fp; } result; result.ll=values[i]; printf("%s\t%0.3f%s\n", event_names[i], result.fp, units[i]); } } } /* Done, clean up */ retval = PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()",retval); } retval = PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()",retval); } test_pass( __FILE__, NULL, 0 ); return 0; }
static int papi_internal_init(pmdaInterface *dp) { int ec; int sts; PAPI_event_info_t info; char entry[PAPI_HUGE_STR_LEN+12]; // the length papi uses for the symbol name unsigned int i = 0; pmID pmid; sts = sprintf(papi_version, "%d.%d.%d", PAPI_VERSION_MAJOR(PAPI_VERSION), PAPI_VERSION_MINOR(PAPI_VERSION), PAPI_VERSION_REVISION(PAPI_VERSION)); if (sts < 0) { __pmNotifyErr(LOG_ERR, "%s failed to create papi version metric.\n",pmProgname); return PM_ERR_GENERIC; } if ((sts = __pmNewPMNS(&papi_tree)) < 0) { __pmNotifyErr(LOG_ERR, "%s failed to create dynamic papi pmns: %s\n", pmProgname, pmErrStr(sts)); papi_tree = NULL; return PM_ERR_GENERIC; } number_of_counters = PAPI_num_counters(); if (number_of_counters < 0) { __pmNotifyErr(LOG_ERR, "hardware does not support performance counters\n"); return PM_ERR_APPVERSION; } else if (number_of_counters == 0) { __pmNotifyErr(LOG_WARNING, "no performance counters\n"); } sts = PAPI_library_init(PAPI_VER_CURRENT); if (sts != PAPI_VER_CURRENT) { __pmNotifyErr(LOG_ERR, "PAPI_library_init error (%d)\n", sts); return PM_ERR_GENERIC; } ec = PAPI_PRESET_MASK; PAPI_enum_event(&ec, PAPI_ENUM_FIRST); do { if (PAPI_get_event_info(ec, &info) == PAPI_OK) { if (info.count && PAPI_PRESET_ENUM_AVAIL) { expand_papi_info(i); memcpy(&papi_info[i].info, &info, sizeof(PAPI_event_info_t)); memcpy(&papi_info[i].papi_string_code, info.symbol + 5, strlen(info.symbol)-5); snprintf(entry, sizeof(entry),"papi.system.%s", papi_info[i].papi_string_code); pmid = pmid_build(dp->domain, CLUSTER_PAPI, i); papi_info[i].pmid = pmid; __pmAddPMNSNode(papi_tree, pmid, entry); memset(&entry[0], 0, sizeof(entry)); papi_info[i].position = -1; papi_info[i].metric_enabled = 0; expand_values(i); i++; } } } while(PAPI_enum_event(&ec, 0) == PAPI_OK); #if defined(HAVE_PAPI_DISABLED_COMP) char *tokenized_string; int number_of_components; int component_id; int native; number_of_components = PAPI_num_components(); native = 0 | PAPI_NATIVE_MASK; for (component_id = 0; component_id < number_of_components; component_id++) { const PAPI_component_info_t *component; component = PAPI_get_component_info(component_id); if (component->disabled || (strcmp("perf_event", component->name) && strcmp("perf_event_uncore", component->name))) continue; sts = PAPI_enum_cmp_event (&native, PAPI_ENUM_FIRST, component_id); if (sts == PAPI_OK) do { if (PAPI_get_event_info(native, &info) == PAPI_OK) { char local_native_metric_name[PAPI_HUGE_STR_LEN] = ""; int was_tokenized = 0; expand_papi_info(i); memcpy(&papi_info[i].info, &info, sizeof(PAPI_event_info_t)); tokenized_string = strtok(info.symbol, "::: -"); while (tokenized_string != NULL) { size_t remaining = sizeof(local_native_metric_name) - strlen(local_native_metric_name) - 1; if (remaining < 1) break; strncat(local_native_metric_name, tokenized_string, remaining); was_tokenized = 1; tokenized_string=strtok(NULL, "::: -"); if (tokenized_string) { remaining = sizeof(local_native_metric_name) - strlen(local_native_metric_name) - 1; if (remaining < 1) break; strncat(local_native_metric_name, ".", remaining); } } if (!was_tokenized) { strncpy(papi_info[i].papi_string_code, info.symbol, sizeof(papi_info[i].papi_string_code) - 1); } else { strncpy(papi_info[i].papi_string_code, local_native_metric_name, sizeof(papi_info[i].papi_string_code) - 1); } snprintf(entry, sizeof(entry),"papi.system.%s", papi_info[i].papi_string_code); pmid = pmid_build(dp->domain, CLUSTER_PAPI, i); papi_info[i].pmid = pmid; __pmAddPMNSNode(papi_tree, pmid, entry); memset(&entry[0], 0, sizeof(entry)); papi_info[i].position = -1; papi_info[i].metric_enabled = 0; expand_values(i); i++; } } while (PAPI_enum_cmp_event(&native, PAPI_ENUM_EVENTS, component_id) == PAPI_OK); } #endif pmdaTreeRebuildHash(papi_tree, number_of_events); /* Set one-time settings for all future EventSets. */ if ((sts = PAPI_set_domain(PAPI_DOM_ALL)) != PAPI_OK) { handle_papi_error(sts, 0); return PM_ERR_GENERIC; } if ((sts = PAPI_multiplex_init()) != PAPI_OK) { handle_papi_error(sts, 0); return PM_ERR_GENERIC; } sts = refresh_metrics(0); if (sts != PAPI_OK) return PM_ERR_GENERIC; return 0; }
int main (int argc, char **argv) { int retval,i; int EventSet = PAPI_NULL; long long values[NUM_EVENTS]; const PAPI_component_info_t *cmpinfo = NULL; int numcmp,cid,example_cid=-1; int code,maximum_code=0; char event_name[PAPI_MAX_STR_LEN]; PAPI_event_info_t event_info; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); } if (!TESTS_QUIET) { printf( "Testing example component with PAPI %d.%d.%d\n", PAPI_VERSION_MAJOR( PAPI_VERSION ), PAPI_VERSION_MINOR( PAPI_VERSION ), PAPI_VERSION_REVISION( PAPI_VERSION ) ); } /* Find our component */ numcmp = PAPI_num_components(); for( cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__, "PAPI_get_component_info failed\n", 0); } if (!TESTS_QUIET) { printf("\tComponent %d - %d events - %s\n", cid, cmpinfo->num_native_events, cmpinfo->name); } if (strstr(cmpinfo->name,"example.c")) { /* FOUND! */ example_cid=cid; } } if (example_cid<0) { test_skip(__FILE__, __LINE__, "Example component not found\n", 0); } if (!TESTS_QUIET) { printf("\nFound Example Component at id %d\n",example_cid); printf("\nListing all events in this component:\n"); } /**************************************************/ /* Listing all available events in this component */ /* Along with descriptions */ /**************************************************/ code = PAPI_NATIVE_MASK | PAPI_COMPONENT_MASK(example_cid); retval = PAPI_enum_event( &code, PAPI_ENUM_FIRST ); while ( retval == PAPI_OK ) { if (PAPI_event_code_to_name( code, event_name )!=PAPI_OK) { printf("Error translating %x\n",code); test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } if (PAPI_get_event_info( code, &event_info)!=PAPI_OK) { printf("Error getting info for event %x\n",code); test_fail( __FILE__, __LINE__, "PAPI_get_event_info()", retval ); } if (!TESTS_QUIET) { printf("\tEvent 0x%x: %s -- %s\n", code,event_name,event_info.long_descr); } maximum_code=code; retval = PAPI_enum_event( &code, PAPI_ENUM_EVENTS ); } if (!TESTS_QUIET) printf("\n"); /**********************************/ /* Try accessing an invalid event */ /**********************************/ retval=PAPI_event_code_to_name( maximum_code+10, event_name ); if (retval!=PAPI_ENOEVNT) { test_fail( __FILE__, __LINE__, "Failed to return PAPI_ENOEVNT on invalid event", retval ); } /***********************************/ /* Test the EXAMPLE_ZERO event */ /***********************************/ retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_create_eventset() failed\n", retval ); } retval = PAPI_event_name_to_code("EXAMPLE_ZERO", &code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "EXAMPLE_ZERO not found\n",retval ); } retval = PAPI_add_event( EventSet, code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events failed\n", retval ); } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start failed\n",retval ); } retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval); } if (!TESTS_QUIET) printf("Testing EXAMPLE_ZERO: %lld\n",values[0]); if (values[0]!=0) { test_fail( __FILE__, __LINE__, "Result should be 0!\n", 0); } retval = PAPI_cleanup_eventset(EventSet); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval); } retval = PAPI_destroy_eventset(&EventSet); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval); } EventSet=PAPI_NULL; /***********************************/ /* Test the EXAMPLE_CONSTANT event */ /***********************************/ retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_create_eventset() failed\n", retval ); } retval = PAPI_event_name_to_code("EXAMPLE_CONSTANT", &code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "EXAMPLE_CONSTANT not found\n",retval ); } retval = PAPI_add_event( EventSet, code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events failed\n", retval ); } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start failed\n",retval ); } retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval); } if (!TESTS_QUIET) printf("Testing EXAMPLE_CONSTANT: %lld\n",values[0]); if (values[0]!=42) { test_fail( __FILE__, __LINE__, "Result should be 42!\n", 0); } retval = PAPI_cleanup_eventset(EventSet); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval); } retval = PAPI_destroy_eventset(&EventSet); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval); } EventSet=PAPI_NULL; /***********************************/ /* Test the EXAMPLE_AUTOINC event */ /***********************************/ retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_create_eventset() failed\n", retval ); } retval = PAPI_event_name_to_code("EXAMPLE_AUTOINC", &code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "EXAMPLE_AUTOINC not found\n",retval ); } retval = PAPI_add_event( EventSet, code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events failed\n", retval ); } if (!TESTS_QUIET) printf("Testing EXAMPLE_AUTOINC: "); for(i=0;i<10;i++) { retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start failed\n",retval ); } retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval); } if (!TESTS_QUIET) printf("%lld ",values[0]); if (values[0]!=i) { test_fail( __FILE__, __LINE__, "Result wrong!\n", 0); } } if (!TESTS_QUIET) printf("\n"); /***********************************/ /* Test multiple reads */ /***********************************/ retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start failed\n",retval ); } for(i=0;i<10;i++) { retval=PAPI_read( EventSet, values); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_read failed\n", retval); } if (!TESTS_QUIET) printf("%lld ",values[0]); } retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval); } if (!TESTS_QUIET) printf("%lld\n",values[0]); // if (values[0]!=i) { // test_fail( __FILE__, __LINE__, "Result wrong!\n", 0); //} /***********************************/ /* Test PAPI_reset() */ /***********************************/ retval = PAPI_reset( EventSet); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_reset() failed\n",retval ); } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start failed\n",retval ); } retval = PAPI_reset( EventSet); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_reset() failed\n",retval ); } retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval); } if (!TESTS_QUIET) printf("Testing EXAMPLE_AUTOINC after PAPI_reset(): %lld\n", values[0]); if (values[0]!=0) { test_fail( __FILE__, __LINE__, "Result not zero!\n", 0); } retval = PAPI_cleanup_eventset(EventSet); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval); } retval = PAPI_destroy_eventset(&EventSet); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval); } EventSet=PAPI_NULL; /***********************************/ /* Test multiple events */ /***********************************/ if (!TESTS_QUIET) printf("Testing Multiple Events: "); retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_create_eventset() failed\n", retval ); } retval = PAPI_event_name_to_code("EXAMPLE_CONSTANT", &code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "EXAMPLE_CONSTANT not found\n",retval ); } retval = PAPI_add_event( EventSet, code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events failed\n", retval ); } retval = PAPI_event_name_to_code("EXAMPLE_GLOBAL_AUTOINC", &code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "EXAMPLE_GLOBAL_AUTOINC not found\n",retval ); } retval = PAPI_add_event( EventSet, code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events failed\n", retval ); } retval = PAPI_event_name_to_code("EXAMPLE_ZERO", &code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "EXAMPLE_ZERO not found\n",retval ); } retval = PAPI_add_event( EventSet, code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events failed\n", retval ); } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start failed\n",retval ); } retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval); } if (!TESTS_QUIET) { for(i=0;i<3;i++) { printf("%lld ",values[i]); } printf("\n"); } if (values[0]!=42) { test_fail( __FILE__, __LINE__, "Result should be 42!\n", 0); } if (values[2]!=0) { test_fail( __FILE__, __LINE__, "Result should be 0!\n", 0); } retval = PAPI_cleanup_eventset(EventSet); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval); } retval = PAPI_destroy_eventset(&EventSet); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval); } EventSet=PAPI_NULL; /***********************************/ /* Test writing to an event */ /***********************************/ if (!TESTS_QUIET) printf("Testing Write\n"); retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_create_eventset() failed\n", retval ); } retval = PAPI_event_name_to_code("EXAMPLE_CONSTANT", &code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "EXAMPLE_CONSTANT not found\n",retval ); } retval = PAPI_add_event( EventSet, code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events failed\n", retval ); } retval = PAPI_event_name_to_code("EXAMPLE_GLOBAL_AUTOINC", &code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "EXAMPLE_GLOBAL_AUTOINC not found\n",retval ); } retval = PAPI_add_event( EventSet, code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events failed\n", retval ); } retval = PAPI_event_name_to_code("EXAMPLE_ZERO", &code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "EXAMPLE_ZERO not found\n",retval ); } retval = PAPI_add_event( EventSet, code); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events failed\n", retval ); } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start failed\n",retval ); } retval = PAPI_read ( EventSet, values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_read failed\n",retval ); } if (!TESTS_QUIET) { printf("Before values: "); for(i=0;i<3;i++) { printf("%lld ",values[i]); } printf("\n"); } values[0]=100; values[1]=200; values[2]=300; retval = PAPI_write ( EventSet, values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_write failed\n",retval ); } retval = PAPI_stop( EventSet, values ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval); } if (!TESTS_QUIET) { printf("After values: "); for(i=0;i<3;i++) { printf("%lld ",values[i]); } printf("\n"); } if (values[0]!=42) { test_fail( __FILE__, __LINE__, "Result should be 42!\n", 0); } if (values[1]!=200) { test_fail( __FILE__, __LINE__, "Result should be 200!\n", 0); } if (values[2]!=0) { test_fail( __FILE__, __LINE__, "Result should be 0!\n", 0); } retval = PAPI_cleanup_eventset(EventSet); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval); } retval = PAPI_destroy_eventset(&EventSet); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval); } EventSet=PAPI_NULL; /************/ /* All Done */ /************/ if (!TESTS_QUIET) printf("\n"); test_pass( __FILE__, NULL, 0 ); return 0; }
void PAPI_HW_COUNTER_open(int tid){ // set events to measure int *Events; int EventCode; int event_ctr = 0; int retval; #ifdef MEASURE_TIME #endif #ifdef MEASURE_CPI thr_vars[tid].papi_idx_inst = thr_vars[tid].num_events++; thr_vars[tid].papi_idx_cyc = thr_vars[tid].num_events++; #endif #ifdef MEASURE_MEMACC thr_vars[tid].papi_idx_load = thr_vars[tid].num_events++; thr_vars[tid].papi_idx_store = thr_vars[tid].num_events++; #endif #ifdef MEASURE_LLCMISS thr_vars[tid].papi_idx_llcmiss = thr_vars[tid].num_events++; #endif #ifdef MEASURE_ICACHEMISS thr_vars[tid].papi_idx_icachemiss = thr_vars[tid].num_events++; #endif #ifdef MEASURE_DCACHEMISS thr_vars[tid].papi_idx_l1dcm = thr_vars[tid].num_events++; thr_vars[tid].papi_idx_l1dca = thr_vars[tid].num_events++; #endif #ifdef MEASURE_ENERGY #endif event_ctr = 0; // reset event counter if((Events=(int*)malloc(sizeof(int)*thr_vars[tid].num_events)) == NULL){ printf("ERROR: Failed to allocate memory for Events."); } if((thr_vars[tid].values=(long long int*)malloc(sizeof(long long)*thr_vars[tid].num_events)) == NULL){ printf("ERROR: Failed to allocate memory for Events."); } #ifdef __ARM_ARCH_7A__ // pin processor only on arm arch. pid_t pid = getpid(); int core = 0; printf("Pinning thread %d to cores %d..%d\n", pid, 0, 0); printf("Observe in terminal via \"ps -p <PID> -L -o pid,tid,psr\"\n"); pin_cpu(pid, core); printf("Pinned to core %d\n", core); #endif // Open file to output char filename_id[2*sizeof(int)]; snprintf(filename_id, sizeof(filename_id),"%d",tid); char* filename_w_id; filename_w_id=(char*)malloc(strlen(OUTFILEID)+strlen(OUTFILEEXT)+strlen(filename_id)+1); strcpy(filename_w_id, OUTFILEID); strcat(filename_w_id, filename_id); strcat(filename_w_id, OUTFILEEXT); thr_vars[tid].f=fopen(filename_w_id, "w"); if (thr_vars[tid].f == NULL){ printf("failed to open file %s.\n", filename_w_id); exit(1); } // Measure clock frequency long long elapsed_cyc; elapsed_cyc = PAPI_get_real_cyc(); sleep(1); elapsed_cyc = PAPI_get_real_cyc()-elapsed_cyc; thr_vars[tid].PAPI_CLOCK_RATE = elapsed_cyc; printf("Measured clock frequency: %.0lld Hz\n",thr_vars[tid].PAPI_CLOCK_RATE); // Set EventSet thr_vars[tid].EventSet = PAPI_NULL;/*EventSet*/ retval=PAPI_create_eventset(&(thr_vars[tid].EventSet)); if (retval != PAPI_OK){ papi_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval); } #ifdef MEASURE_TIME #endif #ifdef MEASURE_CPI retval = PAPI_event_name_to_code( PAPI_INST , &EventCode ); if (retval != PAPI_OK ) { papi_fail(__FILE__, __LINE__, "PAPI_event_name_to_code, inst", retval); } Events[event_ctr++] = EventCode; retval = PAPI_event_name_to_code( PAPI_CYC , &EventCode ); if (retval != PAPI_OK ) { papi_fail(__FILE__, __LINE__, "PAPI_event_name_to_code, cyc", retval); } Events[event_ctr++] = EventCode; #endif #ifdef MEASURE_MEMACC retval = PAPI_event_name_to_code( PAPI_MEM_LOAD , &EventCode ); if (retval != PAPI_OK ) { papi_fail(__FILE__, __LINE__, "PAPI_event_name_to_code, loads", retval); } Events[event_ctr++] = EventCode; retval=PAPI_event_name_to_code( PAPI_MEM_STORE , &EventCode ); if (retval != PAPI_OK ) { papi_fail(__FILE__, __LINE__, "PAPI_event_name_to_code, stores", retval); } Events[event_ctr++] = EventCode; #endif #ifdef MEASURE_LLCMISS retval = PAPI_event_name_to_code( PAPI_LLC_MISS , &EventCode ); if (retval != PAPI_OK ) { papi_fail(__FILE__, __LINE__, "PAPI_event_name_to_code, llc miss", retval); } Events[event_ctr++] = EventCode; #endif #ifdef MEASURE_ICACHEMISS retval = PAPI_event_name_to_code( PAPI_IC_MISS , &EventCode ); if (retval != PAPI_OK ) { papi_fail(__FILE__, __LINE__, "PAPI_event_name_to_code, llc miss", retval); } Events[event_ctr++] = EventCode; #endif #ifdef MEASURE_DCACHEMISS retval = PAPI_event_name_to_code( PAPI_L1_DC_MISS , &EventCode ); if (retval != PAPI_OK ) { papi_fail(__FILE__, __LINE__, "PAPI_event_name_to_code, Level 1 data cache misses", retval); } Events[event_ctr++] = EventCode; retval = PAPI_event_name_to_code( PAPI_L1_DC_ACCESS, &EventCode ); if (retval != PAPI_OK ) { papi_fail(__FILE__, __LINE__, "PAPI_event_name_to_code, Level 1 data cache accesses", retval); } Events[event_ctr++] = EventCode; #endif #ifdef MEASURE_ENERGY printf("Probing all RAPL events\n"); thr_vars[tid].numcmp = PAPI_num_components(); for(thr_vars[tid].cid=0; thr_vars[tid].cid<thr_vars[tid].numcmp; thr_vars[tid].cid++) { if ( (thr_vars[tid].cmpinfo = PAPI_get_component_info(thr_vars[tid].cid)) == NULL) { papi_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); } if (strstr(thr_vars[tid].cmpinfo->name,"rapl")) { thr_vars[tid].rapl_cid=thr_vars[tid].cid; printf("Found rapl component at cid %d.\n",thr_vars[tid].rapl_cid); if (thr_vars[tid].cmpinfo->disabled) { printf("RAPL component disabled: %s\n", thr_vars[tid].cmpinfo->disabled_reason); exit(EXIT_FAILURE); } break; } } if (thr_vars[tid].cid==thr_vars[tid].numcmp) { // Component not found: papi_fail(__FILE__,__LINE__,"No rapl component found\n",0); } retval = PAPI_create_eventset( &(thr_vars[tid].EnergyEventSet) ); if (retval != PAPI_OK){ papi_fail(__FILE__,__LINE__, "PAPI_create_eventset()", retval); } // Add all events: int r; thr_vars[tid].code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &(thr_vars[tid].code), PAPI_ENUM_FIRST, thr_vars[tid].rapl_cid ); while ( r == PAPI_OK ) { retval = PAPI_event_code_to_name( thr_vars[tid].code, thr_vars[tid].event_names[thr_vars[tid].num_energy_events] ); if ( retval != PAPI_OK ) { printf("Error translating %#x\n",thr_vars[tid].code); papi_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } printf("Found event: %s\n", thr_vars[tid].event_names[thr_vars[tid].num_energy_events]); retval = PAPI_get_event_info(thr_vars[tid].code,&(thr_vars[tid].evinfo)); if (retval != PAPI_OK) { papi_fail(__FILE__, __LINE__, "Error getting event info\n",retval); } strncpy(thr_vars[tid].units[thr_vars[tid].num_energy_events],thr_vars[tid].evinfo.units,PAPI_MIN_STR_LEN); thr_vars[tid].data_type[thr_vars[tid].num_energy_events] = thr_vars[tid].evinfo.data_type; retval = PAPI_add_event(thr_vars[tid].EnergyEventSet, thr_vars[tid].code); if (retval != PAPI_OK ) { papi_fail( __FILE__, __LINE__, "PAPI_add_event()", retval); } r = PAPI_enum_cmp_event( &(thr_vars[tid].code), PAPI_ENUM_EVENTS, thr_vars[tid].rapl_cid ); thr_vars[tid].num_energy_events++; } if((thr_vars[tid].energy_values=(long long int*)malloc(sizeof(long long)*thr_vars[tid].num_energy_events)) == NULL){ printf("ERROR: Failed to allocate memory for Events."); } #endif #ifdef MEASURE_HW_COUNTER int k; for(k = 0; k < thr_vars[tid].num_events; k++){ retval = PAPI_add_event(thr_vars[tid].EventSet, Events[k]); if (retval != PAPI_OK ) { printf("At event %d:\n",k); papi_fail( __FILE__, __LINE__, "PAPI_add_event()", retval); } } retval=PAPI_start(thr_vars[tid].EventSet); if (retval != PAPI_OK){ papi_fail(__FILE__, __LINE__, "PAPI_start()", retval); } #endif #ifdef MEASURE_ENERGY retval=PAPI_start(thr_vars[tid].EnergyEventSet); if (retval != PAPI_OK){ papi_fail(__FILE__, __LINE__, "PAPI_start() on energy", retval); } #endif }
int main (int argc, char **argv) { int retval,cid,coretemp_cid=-1,numcmp; int EventSet = PAPI_NULL; long long values[NUM_EVENTS]; int code; char event_name[PAPI_MAX_STR_LEN]; int r; const PAPI_component_info_t *cmpinfo = NULL; PAPI_event_info_t evinfo; double temperature; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); } if (!TESTS_QUIET) { printf("Trying all coretemp events\n"); } numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); } if (strstr(cmpinfo->name,"linux-coretemp")) { coretemp_cid=cid; if (!TESTS_QUIET) printf("Found coretemp component at cid %d\n", coretemp_cid); if (cmpinfo->num_native_events==0) { test_skip(__FILE__,__LINE__,"No coretemp events found",0); } break; } } code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, coretemp_cid ); while ( r == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { printf("Error translating %x\n",code); test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } retval = PAPI_get_event_info(code,&evinfo); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "Error getting event info\n",retval); } /****************************/ /* Print Temperature Inputs */ /****************************/ if (strstr(event_name,"temp")) { /* Only print inputs */ if (strstr(event_name,"_input")) { if (!TESTS_QUIET) printf("%s ",event_name); EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()",retval); } retval = PAPI_add_event( EventSet, code ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_event()",retval); } retval = PAPI_start( EventSet); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } retval = PAPI_stop( EventSet, values); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } temperature=(values[0]/1000.0); if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n", temperature, evinfo.long_descr ); retval = PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()",retval); } retval = PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()",retval); } } } /****************************/ /* Print Voltage Inputs */ /****************************/ if (strstr(event_name,".in")) { /* Only print inputs */ if (strstr(event_name,"_input")) { if (!TESTS_QUIET) printf("%s ",event_name); EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()",retval); } retval = PAPI_add_event( EventSet, code ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_event()",retval); } retval = PAPI_start( EventSet); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } retval = PAPI_stop( EventSet, values); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } temperature=(values[0]/1000.0); if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n", temperature, evinfo.long_descr ); retval = PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()",retval); } retval = PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()",retval); } } } /********************/ /* Print Fan Inputs */ /********************/ else if (strstr(event_name,"fan")) { /* Only print inputs */ if (strstr(event_name,"_input")) { if (!TESTS_QUIET) printf("%s ",event_name); EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()",retval); } retval = PAPI_add_event( EventSet, code ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_event()",retval); } retval = PAPI_start( EventSet); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } retval = PAPI_stop( EventSet, values); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } if (!TESTS_QUIET) printf("\tvalue: %lld %s\n",values[0], evinfo.long_descr); retval = PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()",retval); } retval = PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()",retval); } } } else { /* Skip unknown */ } r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, coretemp_cid ); } test_pass( __FILE__, NULL, 0 ); return 0; }
int main (int argc, char **argv) { int retval,cid,rapl_cid=-1,numcmp; int EventSet = PAPI_NULL; long long values[MAX_EVENTS]; int i,code,enum_retval; const PAPI_component_info_t *cmpinfo = NULL; long long start_time,before_time,after_time; double elapsed_time,total_time; char event_name[BUFSIZ]; /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { fprintf(stderr,"PAPI_library_init failed\n"); exit(1); } numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { fprintf(stderr,"PAPI_get_component_info failed\n"); exit(1); } if (strstr(cmpinfo->name,"rapl")) { rapl_cid=cid; printf("Found rapl component at cid %d\n", rapl_cid); if (cmpinfo->disabled) { fprintf(stderr,"No rapl events found: %s\n", cmpinfo->disabled_reason); exit(1); } break; } } /* Component not found */ if (cid==numcmp) { fprintf(stderr,"No rapl component found\n"); exit(1); } /* Find Events */ code = PAPI_NATIVE_MASK; enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); while ( enum_retval == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { printf("Error translating %#x\n",code); exit(1); } printf("Found: %s\n",event_name); strncpy(events[num_events],event_name,BUFSIZ); sprintf(filenames[num_events],"results.%s",event_name); num_events++; if (num_events==MAX_EVENTS) { printf("Too many events! %d\n",num_events); exit(1); } enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); } if (num_events==0) { printf("Error! No RAPL events found!\n"); exit(1); } /* Open output files */ for(i=0;i<num_events;i++) { fff[i]=fopen(filenames[i],"w"); if (fff[i]==NULL) { fprintf(stderr,"Could not open %s\n",filenames[i]); exit(1); } } /* Create EventSet */ retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { fprintf(stderr,"Error creating eventset!\n"); } for(i=0;i<num_events;i++) { retval = PAPI_add_named_event( EventSet, events[i] ); if (retval != PAPI_OK) { fprintf(stderr,"Error adding event %s\n",events[i]); } } start_time=PAPI_get_real_nsec(); while(1) { /* Start Counting */ before_time=PAPI_get_real_nsec(); retval = PAPI_start( EventSet); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_start() failed\n"); exit(1); } usleep(100000); /* Stop Counting */ after_time=PAPI_get_real_nsec(); retval = PAPI_stop( EventSet, values); if (retval != PAPI_OK) { fprintf(stderr, "PAPI_start() failed\n"); } total_time=((double)(after_time-start_time))/1.0e9; elapsed_time=((double)(after_time-before_time))/1.0e9; for(i=0;i<num_events;i++) { fprintf(fff[i],"%.4f %.1f (* Average Power for %s *)\n", total_time, ((double)values[i]/1.0e9)/elapsed_time, events[i]); fflush(fff[i]); } } return 0; }
int main( int argc, char **argv ) { int i; int retval; PAPI_event_info_t info; int numcmp, cid, our_cid; const PAPI_component_info_t* cmpinfo; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Init PAPI library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } numcmp = PAPI_num_components( ); /* Loop through all components */ for( cid = 0; cid < numcmp; cid++ ) { cmpinfo = PAPI_get_component_info( cid ); if (cmpinfo == NULL) { test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 ); } if (cmpinfo->disabled && !TESTS_QUIET) { printf( "Name: %-23s %s\n", cmpinfo->name ,cmpinfo->description); printf(" \\-> Disabled: %s\n",cmpinfo->disabled_reason); continue; } i = 0 | PAPI_NATIVE_MASK; retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid ); if (retval!=PAPI_OK) continue; do { if (PAPI_get_event_info( i, &info ) != PAPI_OK) { if (!TESTS_QUIET) { printf("Getting information about event: %#x failed\n", i); } continue; } our_cid=PAPI_get_event_component(i); if (our_cid!=cid) { if (!TESTS_QUIET) { printf("%d %d %s\n",cid,our_cid,info.symbol); } test_fail( __FILE__, __LINE__, "component mismatch", 1 ); } if (!TESTS_QUIET) { printf("%d %d %s\n",cid,our_cid,info.symbol); } } while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cid ) == PAPI_OK ); } test_pass( __FILE__, NULL, 0 ); return 0; }
int main( int argc, char **argv ) { int i, k, add_count = 0, err_count = 0, unc_count = 0, offcore_count = 0; int retval; PAPI_event_info_t info, info1; const PAPI_hw_info_t *hwinfo = NULL; char *Intel_i7; int event_code; const PAPI_component_info_t *s = NULL; int numcmp, cid; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } retval = papi_print_header( "Test case ALL_NATIVE_EVENTS: Available " "native events and hardware " "information.\n", 0, &hwinfo ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); } numcmp = PAPI_num_components( ); /* we need a little exception processing if it's a Core i7 */ /* Unfortunately, this test never succeeds... */ Intel_i7 = strstr( hwinfo->model_string, "Intel Core i7" ); for ( cid = 0; cid < numcmp; cid++ ) { if ( ( s = PAPI_get_component_info( cid ) ) == NULL ) test_fail( __FILE__, __LINE__, "PAPI_get_substrate_info", 2 ); /* For platform independence, always ASK FOR the first event */ /* Don't just assume it'll be the first numeric value */ i = 0 | PAPI_NATIVE_MASK | PAPI_COMPONENT_MASK( cid ); PAPI_enum_event( &i, PAPI_ENUM_FIRST ); do { retval = PAPI_get_event_info( i, &info ); if ( Intel_i7 || ( hwinfo->vendor == PAPI_VENDOR_INTEL ) ) { if ( !strncmp( info.symbol, "UNC_", 4 ) ) { unc_count++; continue; } if ( !strncmp( info.symbol, "OFFCORE_RESPONSE_0", 18 ) ) { offcore_count++; continue; } } if ( s->cntr_umasks ) { k = i; if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { do { retval = PAPI_get_event_info( k, &info1 ); event_code = ( int ) info1.event_code; if ( check_event ( event_code, info1.symbol ) ) add_count++; else err_count++; } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ); } else { event_code = ( int ) info.event_code; if ( check_event( event_code, info.symbol ) ) add_count++; else err_count++; } } else { event_code = ( int ) info.event_code; if ( s->cntr_groups ) event_code &= ~PAPI_NTV_GROUP_AND_MASK; if ( check_event( event_code, info.symbol ) ) add_count++; else err_count++; } } while ( PAPI_enum_event( &i, PAPI_ENUM_EVENTS ) == PAPI_OK ); } printf( "\n\nSuccessfully found and added %d events (in %d eventsets).\n", add_count , add_count); if ( err_count ) printf( "Failed to add %d events.\n", err_count ); if (( unc_count ) || (offcore_count)) { char warning[BUFSIZ]; sprintf(warning,"%d Uncore and %d Offcore events were ignored", unc_count,offcore_count); test_warn( __FILE__, __LINE__, warning, 1 ); } if ( add_count > 0 ) test_pass( __FILE__, NULL, 0 ); else test_fail( __FILE__, __LINE__, "No events added", 1 ); exit( 1 ); }
void init_energy(pwr_ctx_t *ctx) { char buf[1024] = { '\0' }; int ret, num_comp, cid, code = 0; const PAPI_component_info_t *comp_info = NULL; PAPI_event_info_t evinfo; assert(ctx != NULL); assert(pwr_is_initialized(ctx, PWR_MODULE_STRUCT)); assert(!pwr_is_initialized(ctx, PWR_MODULE_ENERGY)); // Initialize PAPI if ( !PAPI_is_initialized() ) { ret = PAPI_library_init(PAPI_VER_CURRENT); if (PAPI_VER_CURRENT != ret ) { PAPI_shutdown(); if (ctx->err_fd) { fprintf(ctx->err_fd, "Unexpected PAPI version\n"); } ctx->error = PWR_ARCH_UNSUPPORTED; return; } } // Search PAPI components for RAPL (Intel energy counting) events num_comp = PAPI_num_components(); for (cid = 0; cid < num_comp; ++cid) { comp_info = PAPI_get_component_info(cid); if (NULL == comp_info) { PAPI_shutdown(); if (ctx->err_fd) { fprintf(ctx->err_fd, "Invalid PAPI module found\n"); } ctx->error = PWR_INIT_ERR; return; } if (strstr(comp_info->name, "rapl")) { if (0 == comp_info->num_native_events) { PAPI_shutdown(); if (ctx->err_fd) { fprintf(ctx->err_fd, "RAPL counters not available\n"); } ctx->error = PWR_UNAVAILABLE; return; } break; } } if (cid == num_comp) { if (ctx->err_fd) { fprintf(ctx->err_fd, "Cannot find RAPL module in PAPI\n"); } ctx->error = PWR_UNAVAILABLE; return; } // Create PAPI event set ctx->event_set = PAPI_NULL; ret = PAPI_create_eventset(&ctx->event_set); if (PAPI_OK != ret) { PAPI_shutdown(); if (ctx->err_fd) { fprintf(ctx->err_fd, "Failed to create a PAPI event set\n"); } ctx->error = PWR_INIT_ERR; return; } // count how many counters can be added ctx->emeas = malloc(sizeof(*ctx->emeas)); ctx->emeas->nbValues = 0; for (int i = 0; i < PWR_MAX_PHYS_CPU; ++i) { snprintf(buf, 1024, "PACKAGE_ENERGY:PACKAGE%d", i); ret = PAPI_query_named_event(buf); if (PAPI_OK != ret) { break; } ++ctx->emeas->nbValues; } for (int i = 0; i < PWR_MAX_PHYS_CPU; ++i) { snprintf(buf, 1024, "DRAM_ENERGY:PACKAGE%d", i); ret = PAPI_query_named_event(buf); if (PAPI_OK != ret) { break; } ++ctx->emeas->nbValues; } ctx->emeas->values = malloc(ctx->emeas->nbValues * sizeof(*ctx->emeas->values)); ctx->emeas->units = malloc(ctx->emeas->nbValues * sizeof(*ctx->emeas->units)); ctx->emeas->names = malloc(ctx->emeas->nbValues * sizeof(*ctx->emeas->names)); // fetch the counter information unsigned int cpt_i = 0; for (int i = 0; i < PWR_MAX_PHYS_CPU; ++i) { snprintf(buf, 1024, "PACKAGE_ENERGY:PACKAGE%d", i); ret = PAPI_query_named_event(buf); if (PAPI_OK != ret) { break; } ret = PAPI_add_named_event(ctx->event_set, buf); PAPI_event_name_to_code(buf, &code); PAPI_get_event_info(code, &evinfo); ctx->emeas->units[cpt_i] = strdup(evinfo.units); ctx->emeas->names[cpt_i] = strdup(buf); ++cpt_i; } // same for DRAM for (int i = 0; i < PWR_MAX_PHYS_CPU; ++i) { snprintf(buf, 1024, "DRAM_ENERGY:PACKAGE%d", i); ret = PAPI_query_named_event(buf); if (PAPI_OK != ret) { break; } ret = PAPI_add_named_event(ctx->event_set, buf); PAPI_event_name_to_code(buf, &code); PAPI_get_event_info(code, &evinfo); ctx->emeas->units[cpt_i] = strdup(evinfo.units); ctx->emeas->names[cpt_i] = strdup(buf); ++cpt_i; } ctx->emeas_running = false; ctx->error = PWR_OK; ctx->module_init |= (1U << PWR_MODULE_ENERGY); return; }
int main (int argc, char **argv) { int retval,cid,rapl_cid=-1,numcmp; int EventSet = PAPI_NULL; long long values[MAX_EVENTS]; int i,code,enum_retval; const PAPI_component_info_t *cmpinfo = NULL; long long start_time,write_start_time,write_end_time,read_start_time,read_end_time; char event_name[BUFSIZ]; union { long long ll; double dbl; } event_value_union; static int num_events=0; FILE *fileout; /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { fprintf(stderr,"PAPI_library_init failed\n"); exit(1); } /* Find the libmsr component */ numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { fprintf(stderr,"PAPI_get_component_info failed\n"); exit(1); } if (strstr(cmpinfo->name,"libmsr")) { rapl_cid=cid; printf("Found libmsr component at cid %d\n", rapl_cid); if (cmpinfo->disabled) { fprintf(stderr,"No libmsr events found: %s\n", cmpinfo->disabled_reason); exit(1); } break; } } /* Component not found */ if (cid==numcmp) { fprintf(stderr,"No libmsr component found\n"); exit(1); } /* Find events in the component */ code = PAPI_NATIVE_MASK; enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); while ( enum_retval == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { printf("Error translating %#x\n",code); exit(1); } printf("Found: %s\n",event_name); strncpy(events[num_events],event_name,BUFSIZ); sprintf(filenames[num_events],"results.%s",event_name); num_events++; if (num_events==MAX_EVENTS) { printf("Too many events! %d\n",num_events); exit(1); } enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); } if (num_events==0) { printf("Error! No libmsr events found!\n"); exit(1); } /* Open output file */ char fileoutname[]="libmsr_write_test_output.txt"; fileout=fopen( fileoutname ,"w" ); if ( fileout==NULL) { fprintf( stderr,"Could not open %s\n",fileoutname ); exit(1); } /* Create EventSet */ retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { fprintf(stderr,"Error creating eventset!\n"); } for(i=0;i<num_events;i++) { retval = PAPI_add_named_event( EventSet, events[i] ); if (retval != PAPI_OK) fprintf(stderr,"Error adding event %s\n",events[i]); } start_time=PAPI_get_real_nsec(); /* Grab the initial values for the events */ retval = PAPI_start( EventSet); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_start() failed\n"); exit(1); } /* Initial checking read */ retval = PAPI_read( EventSet, values); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); } /* Write a header line */ fprintf( fileout, "ACTION TIME-STAMP TIME-FOR-UNIT-WORK TIME-OVERHEAD-RW\t" ); for(i=0; i<num_events; i++) fprintf( fileout, "%s ", events[i]+9 ); fprintf( fileout, "\n" ); /* Read the initial values */ retval = PAPI_read( EventSet, values); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); } fprintf( fileout, "INIT %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, 0.0 ); fprintf( fileout, "%8.3e ", 0.0); for(i=0; i<num_events; i++) { event_value_union.ll = values[i]; fprintf( fileout, "%8.3f ", event_value_union.dbl ); } fprintf( fileout, "\n" ); int rpt=0; int limit1base=10; int limit2base=10; while(rpt++<200) { //printf("rpt %d\n", rpt); if ( rpt % 10 == 0 ) { for (i=0; i<num_events; i++) { event_value_union.ll = values[i]; if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_1:PACKAGE0" )) event_value_union.dbl=limit1base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_1:PACKAGE0" )) event_value_union.dbl=1.0; else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_2:PACKAGE0" )) event_value_union.dbl=limit2base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_2:PACKAGE0" )) event_value_union.dbl=1.0; else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_1:PACKAGE1" )) event_value_union.dbl=limit1base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_1:PACKAGE1" )) event_value_union.dbl=1.0; else if ( !strcmp( events[i], "libmsr:::PKG_POWER_LIMIT_2:PACKAGE1" )) event_value_union.dbl=limit2base+(rpt/2); else if ( !strcmp( events[i], "libmsr:::PKG_TIME_WINDOW_POWER_LIMIT_2:PACKAGE1" )) event_value_union.dbl=1.0; else event_value_union.dbl=PAPI_NULL; values[i]=event_value_union.ll; } write_start_time=PAPI_get_real_nsec(); retval = PAPI_write( EventSet, values ); write_end_time=PAPI_get_real_nsec(); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_write() failed\n"); exit(1); } fprintf( fileout, "SET %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, 0.0 ); fprintf( fileout, "%8.3e ", ((double)(write_end_time-write_start_time))/1.0e9 ); for(i=0; i<num_events; i++) { event_value_union.ll = values[i]; fprintf( fileout, "%8.3f ", event_value_union.dbl ); } fprintf( fileout, "\n" ); } /* DO SOME WORK TO USE ENERGY */ //usleep(100000); double work_start_time=PAPI_get_real_nsec(); ompcpuloadprimes( 100000 ); double work_time=PAPI_get_real_nsec()-work_start_time; //printf("primescount %d\n", primescount); /* Read and output the values */ read_start_time=PAPI_get_real_nsec(); retval = PAPI_read( EventSet, values ); read_end_time=PAPI_get_real_nsec(); if (retval != PAPI_OK) { fprintf(stderr,"PAPI_read() failed\n"); exit(1); } fprintf( fileout, "READ %8.3f %8.3f ", ((double)(PAPI_get_real_nsec()-start_time))/1.0e9, work_time/1.0e9 ); fprintf( fileout, "%8.3e ", ((double)(read_end_time-read_start_time))/1.0e9 ); for(i=0; i<num_events; i++) { event_value_union.ll = values[i]; fprintf( fileout, "%8.3f ", event_value_union.dbl ); } fprintf( fileout, "\n" ); } retval = PAPI_stop( EventSet, values); return 0; }
int main (int argc, char **argv) { int retval,cid,rapl_cid=-1,numcmp; int EventSet = PAPI_NULL; long long *values; int num_events=0; int code; char event_names[MAX_RAPL_EVENTS][PAPI_MAX_STR_LEN]; char units[MAX_RAPL_EVENTS][PAPI_MIN_STR_LEN]; int data_type[MAX_RAPL_EVENTS]; int r,i, do_wrap = 0; const PAPI_component_info_t *cmpinfo = NULL; PAPI_event_info_t evinfo; long long before_time,after_time; double elapsed_time; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); if ( argc > 1 ) if ( strstr( argv[1], "-w" ) ) do_wrap = 1; /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); } if (!TESTS_QUIET) { printf("Trying all RAPL events\n"); } numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); } if (strstr(cmpinfo->name,"rapl")) { rapl_cid=cid; if (!TESTS_QUIET) { printf("Found rapl component at cid %d\n",rapl_cid); } if (cmpinfo->disabled) { if (!TESTS_QUIET) { printf("RAPL component disabled: %s\n", cmpinfo->disabled_reason); } test_skip(__FILE__,__LINE__,"RAPL component disabled",0); } break; } } /* Component not found */ if (cid==numcmp) { test_skip(__FILE__,__LINE__,"No rapl component found\n",0); } /* Create EventSet */ retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()",retval); } /* Add all events */ code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, rapl_cid ); while ( r == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_names[num_events] ); if ( retval != PAPI_OK ) { printf("Error translating %#x\n",code); test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } retval = PAPI_get_event_info(code,&evinfo); if (retval != PAPI_OK) { test_fail( __FILE__, __LINE__, "Error getting event info\n",retval); } strncpy(units[num_events],evinfo.units,sizeof(units[0])-1); // buffer must be null terminated to safely use strstr operation on it below units[num_events][sizeof(units[0])-1] = '\0'; data_type[num_events] = evinfo.data_type; retval = PAPI_add_event( EventSet, code ); if (retval != PAPI_OK) { break; /* We've hit an event limit */ } num_events++; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, rapl_cid ); } values=calloc(num_events,sizeof(long long)); if (values==NULL) { test_fail(__FILE__, __LINE__, "No memory",retval); } if (!TESTS_QUIET) { printf("\nStarting measurements...\n\n"); } /* Start Counting */ before_time=PAPI_get_real_nsec(); retval = PAPI_start( EventSet); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } /* Run test */ run_test(TESTS_QUIET); /* Stop Counting */ after_time=PAPI_get_real_nsec(); retval = PAPI_stop( EventSet, values); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_stop()",retval); } elapsed_time=((double)(after_time-before_time))/1.0e9; if (!TESTS_QUIET) { printf("\nStopping measurements, took %.3fs, gathering results...\n\n", elapsed_time); printf("Scaled energy measurements:\n"); for(i=0;i<num_events;i++) { if (strstr(units[i],"nJ")) { printf("%-40s%12.6f J\t(Average Power %.1fW)\n", event_names[i], (double)values[i]/1.0e9, ((double)values[i]/1.0e9)/elapsed_time); } } printf("\n"); printf("Energy measurement counts:\n"); for(i=0;i<num_events;i++) { if (strstr(event_names[i],"ENERGY_CNT")) { printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]); } } printf("\n"); printf("Scaled Fixed values:\n"); for(i=0;i<num_events;i++) { if (!strstr(event_names[i],"ENERGY")) { if (data_type[i] == PAPI_DATATYPE_FP64) { union { long long ll; double fp; } result; result.ll=values[i]; printf("%-40s%12.3f %s\n", event_names[i], result.fp, units[i]); } } } printf("\n"); printf("Fixed value counts:\n"); for(i=0;i<num_events;i++) { if (!strstr(event_names[i],"ENERGY")) { if (data_type[i] == PAPI_DATATYPE_UINT64) { printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]); } } } } #ifdef WRAP_TEST double max_time; unsigned long long max_value = 0; int repeat; for(i=0;i<num_events;i++) { if (strstr(event_names[i],"ENERGY_CNT")) { if (max_value < (unsigned) values[i]) { max_value = values[i]; } } } max_time = elapsed_time * (0xffffffff / max_value); printf("\n"); printf ("Approximate time to energy measurement wraparound: %.3f sec or %.3f min.\n", max_time, max_time/60); if (do_wrap) { printf ("Beginning wraparound execution."); /* Start Counting */ before_time=PAPI_get_real_nsec(); retval = PAPI_start( EventSet); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()",retval); } /* Run test */ repeat = (int)(max_time/elapsed_time); for (i=0;i< repeat;i++) { run_test(1); printf("."); fflush(stdout); } printf("\n"); /* Stop Counting */ after_time=PAPI_get_real_nsec(); retval = PAPI_stop( EventSet, values); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_stop()",retval); } elapsed_time=((double)(after_time-before_time))/1.0e9; printf("\nStopping measurements, took %.3fs\n\n", elapsed_time); printf("Scaled energy measurements:\n"); for(i=0;i<num_events;i++) { if (strstr(units[i],"nJ")) { printf("%-40s%12.6f J\t(Average Power %.1fW)\n", event_names[i], (double)values[i]/1.0e9, ((double)values[i]/1.0e9)/elapsed_time); } } printf("\n"); printf("Energy measurement counts:\n"); for(i=0;i<num_events;i++) { if (strstr(event_names[i],"ENERGY_CNT")) { printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]); } } } #endif /* Done, clean up */ retval = PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()",retval); } retval = PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()",retval); } test_pass( __FILE__, NULL, 0 ); return 0; }
int main (int argc, char **argv) { int retval,cid,numcmp; int EventSet = PAPI_NULL; long long value; int code; char event_name[PAPI_MAX_STR_LEN]; int total_events=0; int r; const PAPI_component_info_t *cmpinfo = NULL; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); } if (!TESTS_QUIET) { printf("Trying all net events\n"); } numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1); } if (!TESTS_QUIET) { printf("Component %d - %d events - %s\n", cid, cmpinfo->num_native_events, cmpinfo->name); } if ( strstr(cmpinfo->name, "infiniband") == NULL) { continue; } code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); while ( r == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_name ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } if (!TESTS_QUIET) { printf("%#x %-24s = ", code, event_name); } EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval); } retval = PAPI_add_event( EventSet, code ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval); } retval = PAPI_start( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()", retval); } if (strcmp(event_name, "_recv") == 0) { /* XXX figure out a general method to generate some traffic * for infiniband * the operation should take more than one second in order * to guarantee that the network counters are updated */ retval = system("ping -c 4 " PINGADDR " > /dev/null"); if (retval < 0) { test_fail(__FILE__, __LINE__, "Unable to start ping", retval); } } retval = PAPI_stop( EventSet, &value ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_stop()", retval); } if (!TESTS_QUIET) printf("%lld\n", value); retval = PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval); } retval = PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval); } total_events++; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); } } if (total_events==0) { test_skip(__FILE__,__LINE__,"No net events found", 0); } test_pass( __FILE__, NULL, 0 ); return 0; }
int main (int argc, char **argv) { int retval,cid,numcmp; int EventSet = PAPI_NULL; long long value; int code; char event_names[MAX_EVENTS][PAPI_MAX_STR_LEN]; int event_codes[MAX_EVENTS]; long long event_values[MAX_EVENTS]; int total_events=0; /* events added so far */ int r; const PAPI_component_info_t *cmpinfo = NULL; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* PAPI Initialization */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); } if (!TESTS_QUIET) { printf("Trying all appio events\n"); } numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1); } if (!TESTS_QUIET) { printf("Component %d - %d events - %s\n", cid, cmpinfo->num_native_events, cmpinfo->name); } if ( strstr(cmpinfo->name, "appio") == NULL) { continue; } code = PAPI_NATIVE_MASK; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); /* Create and populate the EventSet */ EventSet = PAPI_NULL; retval = PAPI_create_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval); } while ( r == PAPI_OK ) { retval = PAPI_event_code_to_name( code, event_names[total_events] ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } if (!TESTS_QUIET) { printf("Added event %s (code=%#x)\n", event_names[total_events], code); } event_codes[total_events++] = code; r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); } } int fdin,fdout; const char* infile = "/etc/group"; printf("This program will read %s and write it to /dev/null\n", infile); int bytes = 0; char buf[1024]; retval = PAPI_add_events( EventSet, event_codes, total_events); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval); } retval = PAPI_start( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_start()", retval); } fdin=open(infile, O_RDONLY); if (fdin < 0) perror("Could not open file for reading: \n"); fdout = open("/dev/null", O_WRONLY); if (fdout < 0) perror("Could not open /dev/null for writing: \n"); while ((bytes = read(fdin, buf, 1024)) > 0) { write(fdout, buf, bytes); } retval = PAPI_stop( EventSet, event_values ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_stop()", retval); } close(fdin); close(fdout); int i; if (!TESTS_QUIET) { for ( i=0; i<total_events; i++ ) { printf("%#x %-24s = %lld\n", event_codes[i], event_names[i], event_values[i]); } } retval = PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval); } retval = PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval); } if (total_events==0) { test_skip(__FILE__,__LINE__,"No appio events found", 0); } test_pass( __FILE__, NULL, 0 ); retval = PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval); } retval = PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval); } return 0; }
int main( int argc, char **argv ) { int EventSet = PAPI_NULL; long long values0[2],values1[2],values2[2]; int num_flops = 3000000, retval; int mythreshold = 1000000; char event_name1[PAPI_MAX_STR_LEN]; int PAPI_event; int cid,numcmp,rapl_cid; const PAPI_component_info_t *cmpinfo = NULL; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); quiet=TESTS_QUIET; /* Init PAPI */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init",retval); } numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); } if (strstr(cmpinfo->name,"linux-rapl")) { rapl_cid=cid; if (!TESTS_QUIET) printf("Found rapl component at cid %d\n", rapl_cid); if (cmpinfo->num_native_events==0) { test_skip(__FILE__,__LINE__,"No rapl events found",0); } break; } } /* Component not found */ if (cid==numcmp) { test_skip(__FILE__,__LINE__,"No rapl component found\n",0); } /* add PAPI_TOT_CYC and PAPI_TOT_INS */ retval=PAPI_create_eventset(&EventSet); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval); } retval=PAPI_add_event(EventSet,PAPI_TOT_CYC); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } retval=PAPI_add_event(EventSet,PAPI_TOT_INS); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } /* Add some RAPL events */ retval=PAPI_create_eventset(&EventSet2); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval); } retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE0"); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE1"); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } PAPI_event=PAPI_TOT_CYC; /* arbitrary */ mythreshold = 2000000; if (!TESTS_QUIET) { printf("Using %x for the overflow event, threshold %d\n", PAPI_event,mythreshold); } /* Start the run calibration run */ retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_start",retval); } do_ints(num_flops,TESTS_QUIET); do_flops( 3000000 ); /* stop the calibration run */ retval = PAPI_stop( EventSet, values0 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_stop",retval); } /* set up overflow handler */ retval = PAPI_overflow( EventSet,PAPI_event,mythreshold, 0, handler ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_overflow",retval); } /* Start overflow run */ retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_start",retval); } retval = PAPI_start( EventSet2 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_start",retval); } do_ints(num_flops,TESTS_QUIET); do_flops( num_flops ); /* stop overflow run */ retval = PAPI_stop( EventSet, values1 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_stop",retval); } retval = PAPI_stop( EventSet2, values2 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_stop",retval); } retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_overflow",retval); } retval = PAPI_event_code_to_name( PAPI_event, event_name1 ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n", retval); } if (!TESTS_QUIET) { printf("%s: %lld %lld\n",event_name1,values0[0],values1[0]); } retval = PAPI_event_code_to_name( PAPI_TOT_INS, event_name1 ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n",retval); } if (!TESTS_QUIET) { printf("%s: %lld %lld\n",event_name1,values0[1],values1[1]); } retval = PAPI_cleanup_eventset( EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_cleanup_eventset",retval); } retval = PAPI_destroy_eventset( &EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_destroy_eventset",retval); } if (rapl_backward) { test_fail(__FILE__, __LINE__,"RAPL counts went backward!",0); } test_pass( __FILE__, NULL, 0 ); return 0; }
int main( int argc, char **argv ) { int i, k, num_umasks; int retval,rc; PAPI_event_info_t info; int numcmp, cid; int quiet; char test_string[]="Checking for event create race..."; char *ptr; char temp_name[BUFSIZ]; pthread_attr_t attr; pthread_t threads[NUM_THREADS]; quiet=test_quiet(); /* Initialize PAPI library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(test_string); } numcmp = PAPI_num_components( ); num_events = 0; for(cid=0; cid<numcmp; cid++ ) { i = 0 | PAPI_NATIVE_MASK; PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid ); do { memset( &info, 0, sizeof ( info ) ); retval = PAPI_get_event_info( i, &info ); /* This event may not exist */ if ( retval != PAPI_OK ) continue; /* save the main event name */ strncpy(temp_name,info.symbol,BUFSIZ); /* Handle umasks */ k = i; num_umasks=0; if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { do { retval = PAPI_get_event_info( k, &info ); if ( retval == PAPI_OK ) { /* handle libpfm4-style events which have a */ /* pmu::event type event name */ if ((ptr=strstr(info.symbol, "::"))) { ptr+=2; } else { ptr=info.symbol; } if ( ( strchr( ptr, ':' ) ) == NULL ) { /* shouldn't happen */ if (!quiet) printf("Weird umask!\n"); test_fail(test_string); } else { // if (!quiet) printf("%s\n",info.symbol); num_umasks++; if (num_events<MAX_EVENTS) { strncpy(event_names[num_events],info.symbol,BUFSIZ); } num_events++; } } } while ( PAPI_enum_event( &k,PAPI_NTV_ENUM_UMASKS) == PAPI_OK ); } if (num_umasks==0) { // if (!quiet) printf("%s\n",temp_name); if (num_events<MAX_EVENTS) { strncpy(event_names[num_events],temp_name,BUFSIZ); } num_events++; } } while ( PAPI_enum_event( &i, PAPI_ENUM_EVENTS ) == PAPI_OK ); } if (!quiet) printf( "Total events reported: %d\n", num_events ); if (num_events>MAX_EVENTS) num_events=MAX_EVENTS; /* shut down the library */ PAPI_shutdown(); /* Initialize PAPI library again */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(test_string); } // for(i=0;i<num_events;i++) { // PAPI_event_name_to_code (event_names[i], &event_codes[i]); //} /* start some threads */ retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) ); pthread_attr_init( &attr ); if (!quiet) printf("Starting threads...\n"); for(i=0;i<NUM_THREADS;i++) { rc = pthread_create( &threads[i], &attr, our_thread, NULL); if ( rc ) { test_fail( test_string); } } pthread_attr_destroy( &attr ); for(i=0;i<NUM_THREADS;i++) { pthread_join( threads[i], NULL ); } if (!quiet) printf("Done with threads...\n"); for(i=0;i<num_events;i++) { if (!quiet) printf("%x %s\n",event_codes[i],event_names[i]); } /* shut down the library again */ PAPI_shutdown(); test_pass(test_string); // pthread_exit( NULL ); return 0; }