static int check_event( int event_code, char *name ) { int retval; char errstring[PAPI_MAX_STR_LEN]; long long values; int EventSet = PAPI_NULL; /* Is there an issue with older machines? */ /* Disable for now, add back once we can reproduce */ // if ( PENTIUM4 ) { // if ( strcmp( name, "REPLAY_EVENT:BR_MSP" ) == 0 ) { // return 1; // } // } retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); retval = PAPI_add_event( EventSet, event_code ); if ( retval != PAPI_OK ) { printf( "Error adding %s\n", name ); return 0; } else { // printf( "Added %s successfully ", name ); } retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error starting %s : %s\n", name, errstring ); } else { retval = PAPI_stop( EventSet, &values ); if ( retval != PAPI_OK ) { PAPI_perror( retval, errstring, PAPI_MAX_STR_LEN ); fprintf( stdout, "Error stopping %s: %s\n", name, errstring ); return 0; } else { printf( "Added and Stopped %s successfully.\n", name ); } } retval=PAPI_cleanup_eventset( EventSet ); if (retval != PAPI_OK ) { test_warn( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval); } retval=PAPI_destroy_eventset( &EventSet ); if (retval != PAPI_OK ) { test_warn( __FILE__, __LINE__, "PAPI_destroy_eventset", retval); } return ( 1 ); }
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 status, retval, num_tests = 1, tmp; int EventSet1 = PAPI_NULL; long long **values; long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc; char event_name[PAPI_MAX_STR_LEN];; const PAPI_hw_info_t *hw_info; const PAPI_component_info_t *cmpinfo; pid_t pid; /* Fork before doing anything with the PMU */ setbuf(stdout,NULL); pid = fork( ); if ( pid < 0 ) test_fail( __FILE__, __LINE__, "fork()", PAPI_ESYS ); if ( pid == 0 ) exit( wait_for_attach_and_loop( ) ); tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ /* Master only process below here */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval ); if ( ( cmpinfo = PAPI_get_component_info( 0 ) ) == NULL ) test_fail_exit( __FILE__, __LINE__, "PAPI_get_component_info", 0 ); if ( cmpinfo->attach == 0 ) test_skip( __FILE__, __LINE__, "Platform does not support attaching", 0 ); hw_info = PAPI_get_hardware_info( ); if ( hw_info == NULL ) test_fail_exit( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 ); /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, depending on the availability of the event on the platform */ retval = PAPI_create_eventset(&EventSet1); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval ); /* Force addition of component */ retval = PAPI_assign_eventset_component( EventSet1, 0 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); /* The following call causes this test to fail for perf_events */ retval = PAPI_attach( EventSet1, ( unsigned long ) pid ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval ); sprintf(event_name,"PAPI_TOT_CYC"); retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval ); retval = PAPI_add_event(EventSet1, PAPI_FP_INS); if ( retval == PAPI_ENOEVNT ) { test_warn( __FILE__, __LINE__, "PAPI_FP_INS", retval); } else if ( retval != PAPI_OK ) { test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval ); } values = allocate_test_space( 1, 2); elapsed_us = PAPI_get_real_usec( ); elapsed_cyc = PAPI_get_real_cyc( ); elapsed_virt_us = PAPI_get_virt_usec( ); elapsed_virt_cyc = PAPI_get_virt_cyc( ); printf("must_ptrace is %d\n",cmpinfo->attach_must_ptrace); pid_t child = wait( &status ); printf( "Debugger exited wait() with %d\n",child ); if (WIFSTOPPED( status )) { printf( "Child has stopped due to signal %d (%s)\n", WSTOPSIG( status ), strsignal(WSTOPSIG( status )) ); } if (WIFSIGNALED( status )) { printf( "Child %ld received signal %d (%s)\n", (long)child, WTERMSIG(status) , strsignal(WTERMSIG( status )) ); } printf("After %d\n",retval); retval = PAPI_start( EventSet1 ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval ); printf("Continuing\n"); if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) { perror( "ptrace(PTRACE_CONT)" ); return 1; } do { child = wait( &status ); printf( "Debugger exited wait() with %d\n", child); if (WIFSTOPPED( status )) { printf( "Child has stopped due to signal %d (%s)\n", WSTOPSIG( status ), strsignal(WSTOPSIG( status )) ); } if (WIFSIGNALED( status )) { printf( "Child %ld received signal %d (%s)\n", (long)child, WTERMSIG(status) , strsignal(WTERMSIG( status )) ); } } while (!WIFEXITED( status )); printf("Child exited with value %d\n",WEXITSTATUS(status)); if (WEXITSTATUS(status) != 0) test_fail_exit( __FILE__, __LINE__, "Exit status of child to attach to", PAPI_EMISC); retval = PAPI_stop( EventSet1, values[0] ); if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval ); elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us; elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc; elapsed_us = PAPI_get_real_usec( ) - elapsed_us; elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; retval = PAPI_cleanup_eventset(EventSet1); if (retval != PAPI_OK) test_fail_exit( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); retval = PAPI_destroy_eventset(&EventSet1); if (retval != PAPI_OK) test_fail_exit( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); printf( "Test case: 3rd party attach start, stop.\n" ); printf( "-----------------------------------------------\n" ); tmp = PAPI_get_opt( PAPI_DEFDOM, NULL ); printf( "Default domain is: %d (%s)\n", tmp, stringify_all_domains( tmp ) ); tmp = PAPI_get_opt( PAPI_DEFGRN, NULL ); printf( "Default granularity is: %d (%s)\n", tmp, stringify_granularity( tmp ) ); printf( "Using %d iterations of c += a*b\n", NUM_FLOPS ); printf ( "-------------------------------------------------------------------------\n" ); printf( "Test type : \t 1\n" ); printf( TAB1, "PAPI_TOT_CYC : \t", ( values[0] )[0] ); printf( TAB1, "PAPI_FP_INS : \t", ( values[0] )[1] ); printf( TAB1, "Real usec : \t", elapsed_us ); printf( TAB1, "Real cycles : \t", elapsed_cyc ); printf( TAB1, "Virt usec : \t", elapsed_virt_us ); printf( TAB1, "Virt cycles : \t", elapsed_virt_cyc ); printf ( "-------------------------------------------------------------------------\n" ); printf( "Verification: none\n" ); test_pass( __FILE__, values, num_tests ); exit( 1 ); }
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, pid, status, EventSet = PAPI_NULL; long long int values[] = {0,0}; PAPI_option_t opt; tests_quiet( argc, argv ); if ( ( retval = PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval ); if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_create_eventset", retval ); if ( ( retval = PAPI_assign_eventset_component( EventSet, 0 ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); memset( &opt, 0x0, sizeof ( PAPI_option_t ) ); opt.inherit.inherit = PAPI_INHERIT_ALL; opt.inherit.eventset = EventSet; if ( ( retval = PAPI_set_opt( PAPI_INHERIT, &opt ) ) != PAPI_OK ) { if ( retval == PAPI_ECMP) { test_skip( __FILE__, __LINE__, "Inherit not supported by current component.\n", retval ); } else { test_fail_exit( __FILE__, __LINE__, "PAPI_set_opt", retval ); } } if ( ( retval = PAPI_query_event( PAPI_TOT_CYC ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_query_event", retval ); if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval ); retval = PAPI_query_event( PAPI_FP_INS ); if ( retval == PAPI_ENOEVNT ) { test_warn( __FILE__, __LINE__, "PAPI_FP_INS", retval); values[1] = NUM_FLOPS; /* fake a return value to pass the test */ } else if ( retval != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_query_event", retval ); else if ( ( retval = PAPI_add_event( EventSet, PAPI_FP_INS ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval ); if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval ); pid = fork( ); if ( pid == 0 ) { do_flops( NUM_FLOPS ); exit( 0 ); } if ( waitpid( pid, &status, 0 ) == -1 ) { perror( "waitpid()" ); exit( 1 ); } if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK ) test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval ); if (!TESTS_QUIET) { printf( "Test case inherit: parent starts, child works, parent stops.\n" ); printf( "------------------------------------------------------------\n" ); printf( "Test run : \t1\n" ); printf( "PAPI_FP_INS : \t%lld\n", values[1] ); printf( "PAPI_TOT_CYC: \t%lld\n", values[0] ); printf( "------------------------------------------------------------\n" ); printf( "Verification:\n" ); printf( "Row 1 at least %d\n", NUM_FLOPS ); printf( "Row 2 greater than row 1\n"); } if ( values[1] < NUM_FLOPS) { test_fail( __FILE__, __LINE__, "PAPI_FP_INS", 1 ); } if ( values[0] < values[1]) { test_fail( __FILE__, __LINE__, "PAPI_TOT_CYC < PAPI_FP_INS", 1 ); } test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
static int do_profile( caddr_t start, unsigned long plength, unsigned scale, int thresh, int bucket, unsigned int mask ) { int i, retval; unsigned long blength; int num_buckets,j=0; int num_bufs = num_events; int event = num_events; int events[MAX_TEST_EVENTS]; char header[BUFSIZ]; strncpy(header,"address\t\t",BUFSIZ); //= "address\t\t\tcyc\tins\tfp_ins\n"; for(i=0;i<MAX_TEST_EVENTS;i++) { if (mask & test_events[i].mask) { events[j]=test_events[i].event; if (events[j]==PAPI_TOT_CYC) { strncat(header,"\tcyc",BUFSIZ-1); } if (events[j]==PAPI_TOT_INS) { strncat(header,"\tins",BUFSIZ-1); } if (events[j]==PAPI_FP_INS) { strncat(header,"\tfp_ins",BUFSIZ-1); } if (events[j]==PAPI_FP_OPS) { strncat(header,"\tfp_ops",BUFSIZ-1); } if (events[j]==PAPI_L2_TCM) { strncat(header,"\tl2_tcm",BUFSIZ-1); } j++; } } strncat(header,"\n",BUFSIZ-1); blength = prof_size( plength, scale, bucket, &num_buckets ); prof_alloc( num_bufs, blength ); if ( !TESTS_QUIET ) printf( "Overall event counts:\n" ); for ( i = 0; i < num_events; i++ ) { if ( ( retval = PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale, EventSet, events[i], thresh, PAPI_PROFIL_POSIX | bucket ) ) != PAPI_OK ) { if (retval == PAPI_EINVAL) { test_warn( __FILE__, __LINE__, "Trying to profile with derived event", 1); num_events=i; break; } else { printf("Failed with event %d 0x%x\n",i,events[i]); test_fail( __FILE__, __LINE__, "PAPI_profil", retval ); } } } if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); my_main( ); if ( ( retval = PAPI_stop( EventSet, values[0] ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); if ( !TESTS_QUIET ) { printf( TAB1, "PAPI_TOT_CYC:", ( values[0] )[--event] ); if ( strcmp( hw_info->model_string, "POWER6" ) != 0 ) { printf( TAB1, "PAPI_TOT_INS:", ( values[0] )[--event] ); } #if defined(__powerpc__) printf( TAB1, "PAPI_FP_INS", ( values[0] )[--event] ); #else if ( strcmp( hw_info->model_string, "Intel Pentium III" ) != 0 ) { printf( TAB1, "PAPI_FP_OPS:", ( values[0] )[--event] ); printf( TAB1, "PAPI_L2_TCM:", ( values[0] )[--event] ); } #endif } for ( i = 0; i < num_events; i++ ) { if ( ( retval = PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale, EventSet, events[i], 0, PAPI_PROFIL_POSIX ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_profil", retval ); } prof_head( blength, bucket, num_buckets, header ); prof_out( start, num_events, bucket, num_buckets, scale ); retval = prof_check( num_bufs, bucket, num_buckets ); for ( i = 0; i < num_bufs; i++ ) { free( profbuf[i] ); } return retval; }
/* add native events to use all counters */ int enum_add_native_events( int *num_events, int **evtcodes, int need_interrupt, int no_software_events ) { /* query and set up the right event to monitor */ int EventSet = PAPI_NULL; int i = 0, k, event_code, retval; int counters, event_found = 0; PAPI_event_info_t info; const PAPI_component_info_t *s = NULL; const PAPI_hw_info_t *hw_info = NULL; s = PAPI_get_component_info( 0 ); if ( s == NULL ) { test_fail( __FILE__, __LINE__, "PAPI_get_component_info", PAPI_ESBSTR ); } hw_info = PAPI_get_hardware_info( ); if ( hw_info == NULL ) { test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); } counters = PAPI_num_hwctrs( ); if (counters<1) { test_fail(__FILE__,__LINE__, "No counters available!\n",1); } if (!TESTS_QUIET) printf("Trying to fill %d hardware counters...\n", counters); if (need_interrupt) { if ( (!strcmp(hw_info->model_string,"POWER6")) || (!strcmp(hw_info->model_string,"POWER5")) ) { test_warn(__FILE__, __LINE__, "Limiting num_counters because of LIMITED_PMC on Power5 and Power6",1); counters=4; } } ( *evtcodes ) = ( int * ) calloc( counters, sizeof ( int ) ); retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); } /* 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_enum_event( &i, PAPI_ENUM_FIRST ); do { retval = PAPI_get_event_info( i, &info ); /* HACK! FIXME */ if (no_software_events && ( strstr(info.symbol,"PERF_COUNT_SW") || strstr(info.long_descr, "PERF_COUNT_SW") ) ) { if (!TESTS_QUIET) { printf("Blocking event %s as a SW event\n", info.symbol); } 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, &info ); event_code = ( int ) info.event_code; retval = PAPI_add_event( EventSet, event_code ); if ( retval == PAPI_OK ) { ( *evtcodes )[event_found] = event_code; if ( !TESTS_QUIET ) { printf( "event_code[%d] = 0x%x (%s)\n", event_found, event_code, info.symbol ); } event_found++; } else { if ( !TESTS_QUIET ) { printf( "0x%x (%s) can't be added to the EventSet.\n", event_code, info.symbol ); } } } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK && event_found < counters ); } else { event_code = ( int ) info.event_code; retval = PAPI_add_event( EventSet, event_code ); if ( retval == PAPI_OK ) { ( *evtcodes )[event_found] = event_code; if ( !TESTS_QUIET ) { printf( "event_code[%d] = 0x%x (%s)\n", event_found, event_code, info.symbol ); } event_found++; } } if ( !TESTS_QUIET && retval == PAPI_OK ) { /* */ } } else { event_code = ( int ) info.event_code; retval = PAPI_add_event( EventSet, event_code ); if ( retval == PAPI_OK ) { ( *evtcodes )[event_found] = event_code; event_found++; } else { if ( !TESTS_QUIET ) fprintf( stdout, "0x%x is not available.\n", event_code ); } } } while ( PAPI_enum_event( &i, PAPI_ENUM_EVENTS ) == PAPI_OK && event_found < counters ); *num_events = ( int ) event_found; if (!TESTS_QUIET) printf("Tried to fill %d counters with events, " "found %d\n",counters,event_found); return EventSet; }
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 ); }