/* Support routine to display header information to the screen from the hardware info data structure. The same code was duplicated in a number of tests and utilities. Seems to make sense to refactor. This may not be the best place for it to live, but it works for now. */ int papi_print_header( char *prompt, const PAPI_hw_info_t ** hwinfo ) { if ( ( *hwinfo = PAPI_get_hardware_info( ) ) == NULL ) return ( PAPI_ESBSTR ); printf( "%s", prompt ); printf ( "--------------------------------------------------------------------------------\n" ); printf( "PAPI Version : %d.%d.%d.%d\n", PAPI_VERSION_MAJOR( PAPI_VERSION ), PAPI_VERSION_MINOR( PAPI_VERSION ), PAPI_VERSION_REVISION( PAPI_VERSION ), PAPI_VERSION_INCREMENT( PAPI_VERSION ) ); printf( "Vendor string and code : %s (%d)\n", ( *hwinfo )->vendor_string, ( *hwinfo )->vendor ); printf( "Model string and code : %s (%d)\n", ( *hwinfo )->model_string, ( *hwinfo )->model ); printf( "CPU Revision : %f\n", ( *hwinfo )->revision ); if ( ( *hwinfo )->cpuid_family > 0 ) printf ( "CPUID Info : Family: %d Model: %d Stepping: %d\n", ( *hwinfo )->cpuid_family, ( *hwinfo )->cpuid_model, ( *hwinfo )->cpuid_stepping ); printf( "CPU Megahertz : %f\n", ( *hwinfo )->mhz ); printf( "CPU Clock Megahertz : %d\n", ( *hwinfo )->clock_mhz ); if ( ( *hwinfo )->threads > 0 ) printf( "Hdw Threads per core : %d\n", ( *hwinfo )->threads ); if ( ( *hwinfo )->cores > 0 ) printf( "Cores per Socket : %d\n", ( *hwinfo )->cores ); if ( ( *hwinfo )->sockets > 0 ) printf( "Sockets : %d\n", ( *hwinfo )->sockets ); if ( ( *hwinfo )->nnodes > 0 ) printf( "NUMA Nodes : %d\n", ( *hwinfo )->nnodes ); printf( "CPUs per Node : %d\n", ( *hwinfo )->ncpu ); printf( "Total CPUs : %d\n", ( *hwinfo )->totalcpus ); printf( "Running in a VM : %s\n", ( *hwinfo )->virtualized? "yes":"no"); if ( (*hwinfo)->virtualized) { printf( "VM Vendor: : %s\n", (*hwinfo)->virtual_vendor_string); } printf( "Number Hardware Counters : %d\n", PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ) ); printf( "Max Multiplex Counters : %d\n", PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ) ); printf ( "--------------------------------------------------------------------------------\n" ); printf( "\n" ); return PAPI_OK; }
/* Support routine to display header information to the screen from the hardware info data structure. The same code was duplicated in a number of tests and utilities. Seems to make sense to refactor. This may not be the best place for it to live, but it works for now. */ int papi_print_header( char *prompt, int event_flag, const PAPI_hw_info_t ** hwinfo ) { if ( ( *hwinfo = PAPI_get_hardware_info( ) ) == NULL ) return ( PAPI_ESBSTR ); printf( "%s", prompt ); printf ( "--------------------------------------------------------------------------------\n" ); printf( "PAPI Version : %d.%d.%d.%d\n", PAPI_VERSION_MAJOR( PAPI_VERSION ), PAPI_VERSION_MINOR( PAPI_VERSION ), PAPI_VERSION_REVISION( PAPI_VERSION ), PAPI_VERSION_INCREMENT( PAPI_VERSION ) ); printf( "Vendor string and code : %s (%d)\n", ( *hwinfo )->vendor_string, ( *hwinfo )->vendor ); printf( "Model string and code : %s (%d)\n", ( *hwinfo )->model_string, ( *hwinfo )->model ); printf( "CPU Revision : %f\n", ( *hwinfo )->revision ); if ( ( *hwinfo )->cpuid_family > 0 ) printf ( "CPUID Info : Family: %d Model: %d Stepping: %d\n", ( *hwinfo )->cpuid_family, ( *hwinfo )->cpuid_model, ( *hwinfo )->cpuid_stepping ); printf( "CPU Megahertz : %f\n", ( *hwinfo )->mhz ); printf( "CPU Clock Megahertz : %d\n", ( *hwinfo )->clock_mhz ); if ( ( *hwinfo )->threads > 0 ) printf( "Hdw Threads per core : %d\n", ( *hwinfo )->threads ); if ( ( *hwinfo )->cores > 0 ) printf( "Cores per Socket : %d\n", ( *hwinfo )->cores ); if ( ( *hwinfo )->sockets > 0 ) printf( "Sockets : %d\n", ( *hwinfo )->sockets ); if ( ( *hwinfo )->nnodes > 0 ) printf( "NUMA Nodes : %d\n", ( *hwinfo )->nnodes ); printf( "CPU's per Node : %d\n", ( *hwinfo )->ncpu ); printf( "Total CPU's : %d\n", ( *hwinfo )->totalcpus ); printf( "Number Hardware Counters : %d\n", PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ) ); printf( "Max Multiplex Counters : %d\n", PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ) ); printf ( "--------------------------------------------------------------------------------\n" ); if ( event_flag ) printf ( "The following correspond to fields in the PAPI_event_info_t structure.\n" ); printf( "\n" ); return ( PAPI_OK ); }
void event_create_eventList(int *eventSet, int eventCodeSetSize, int *eventCodeSet, int threadID) { int retval, i, maxNumberHwCounters, eventCodeSetMaxSize; PAPI_event_info_t info; maxNumberHwCounters = PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ); printf("Max number of hardware counters = %d \n", maxNumberHwCounters); eventCodeSetMaxSize = PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ); printf("Max number of multiplexed counters = %d \n", eventCodeSetMaxSize); if ( eventCodeSetMaxSize < eventCodeSetSize) test_fail( __FILE__, __LINE__, "eventCodeSetMaxSize < eventCodeSetSize, too many performance events defined! ", retval ); retval = PAPI_register_thread(); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); retval = PAPI_create_eventset( eventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); retval = PAPI_assign_eventset_component( *eventSet, 0 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); retval = PAPI_set_multiplex( *eventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval ); for (i = 0; i < eventCodeSetSize; i++) { retval = PAPI_get_event_info(eventCodeSet[i], &info); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval ); retval = PAPI_add_event( *eventSet, info.event_code); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); else printf("Adding %s \n", info.symbol); } printf("event_create_eventList done \n"); }
/* * How many hardware counters does this platform support? */ int PAPI_num_counters(void) { int retval; HighLevelInfo *tmp = NULL; /* Make sure the Library is initialized, etc... */ if ((retval = _internal_check_state(&tmp)) != PAPI_OK) return (retval); return (PAPI_get_opt(PAPI_MAX_HWCTRS, NULL)); }
void init_test(int SoftwareMPX, int KernelMPX, int* Events) { int i; int retval; PAPI_option_t option, itimer; if ( ( retval = PAPI_assign_eventset_component( SoftwareMPX, 0 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval); if ( ( retval = PAPI_assign_eventset_component( KernelMPX, 0 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval); if ( ( retval = PAPI_set_multiplex( KernelMPX ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval ); PAPI_get_opt(PAPI_DEF_ITIMER,&itimer); memset(&option,0x0,sizeof(option)); option.multiplex.flags = PAPI_MULTIPLEX_FORCE_SW; option.multiplex.eventset = SoftwareMPX; option.multiplex.ns = itimer.itimer.ns; PAPI_set_opt( PAPI_MULTIPLEX, &option ); for (i = 0; i < options.min - 1; i++) { if ( options.kernel_mpx ) { if ( ( retval = PAPI_add_event( KernelMPX, Events[i]) ) != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); } } if ( options.force_sw ) { if ( ( retval = PAPI_add_event( SoftwareMPX, Events[i]) ) != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); } } } }
int main(int argc, char **argv) { int retval, num_tests = 5, num_events, tmp; long long **values; int EventSet=PAPI_NULL; int PAPI_event, mask; char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN]; const PAPI_hw_info_t *hw_info; 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", 2); /* 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 */ EventSet = add_two_events(&num_events, &PAPI_event, hw_info, &mask); retval = PAPI_event_code_to_name(PAPI_event, event_name); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_event_code_to_name", retval); sprintf(add_event_str, "PAPI_add_event[%s]", event_name); values = allocate_test_space(num_tests, num_events); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS); retval = PAPI_read(EventSet, values[0]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_read", retval); retval = PAPI_reset(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_reset", retval); do_flops(NUM_FLOPS); retval = PAPI_read(EventSet, values[1]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_read", retval); do_flops(NUM_FLOPS); retval = PAPI_read(EventSet, values[2]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_read", retval); do_flops(NUM_FLOPS); retval = PAPI_stop(EventSet, values[3]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_read(EventSet, values[4]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_read", retval); remove_test_events(&EventSet, mask); if (!TESTS_QUIET) { printf("Test case 1: Non-overlapping start, stop, read.\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 : 1 2 3 4 5\n"); sprintf(add_event_str, "%s:", event_name); printf(TAB5, add_event_str, (values[0])[0], (values[1])[0], (values[2])[0], (values[3])[0], (values[4])[0]); printf(TAB5, "PAPI_TOT_CYC:", (values[0])[1], (values[1])[1], (values[2])[1], (values[3])[1], (values[4])[1]); printf ("-------------------------------------------------------------------------\n"); printf("Verification:\n"); printf("Row 1 Column 1 at least %d\n", NUM_FLOPS); printf("%% difference between %s 1 & 2: %.2f\n",add_event_str,100.0*(float)(values[0])[0]/(float)(values[1])[0]); printf("%% difference between %s 1 & 2: %.2f\n","PAPI_TOT_CYC",100.0*(float)(values[0])[1]/(float)(values[1])[1]); printf("Column 1 approximately equals column 2\n"); printf("Column 3 approximately equals 2 * column 2\n"); printf("Column 4 approximately equals 3 * column 2\n"); printf("Column 4 exactly equals column 5\n"); } { long long min, max; min = (long long) (values[1][0] * .9); max = (long long) (values[1][0] * 1.1); if (values[0][0] > max || values[0][0] < min || values[2][0] > (2 * max) || values[2][0] < (2 * min) || values[3][0] > (3 * max) || values[3][0] < (3 * min) || values[3][0] != values[4][0] || values[0][0] < (long long)NUM_FLOPS) { /* printf("min: "); printf(LLDFMT, min); printf("max: "); printf(LLDFMT, max); printf("1st: "); printf(LLDFMT, values[0][0]); printf("2nd: "); printf(LLDFMT, values[1][0]); printf("3rd: "); printf(LLDFMT, values[2][0]); printf("4th: "); printf(LLDFMT, values[3][0]); printf("5th: "); printf(LLDFMT, values[4][0]); printf("\n"); */ test_fail(__FILE__, __LINE__, event_name, 1); } min = (long long) (values[1][1] * .8); max = (long long) (values[1][1] * 1.2); if (values[0][1] > max || values[0][1] < min || values[2][1] > (2 * max) || values[2][1] < (2 * min) || values[3][1] > (3 * max) || values[3][1] < (3 * min) || values[3][1] != values[4][1]) { test_fail(__FILE__, __LINE__, "PAPI_TOT_CYC", 1); } } test_pass(__FILE__, values, num_tests); exit(1); }
int main( int argc, char *argv[] ) { int EventSet = PAPI_NULL; int retval, i, dash = 0, evt3 = PAPI_L1_DCM; PAPI_option_t options; PAPI_option_t options2; const PAPI_hw_info_t *hwinfo; long long lwrflow = 0, error, max_error = 0; long long vals[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT && retval > 0 ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); retval = PAPI_get_opt( PAPI_HWINFO, &options ); if ( retval < 0 ) test_fail( __FILE__, __LINE__, "PAPI_get_opt", retval ); printf( "ovf_info = %d (%#x)\n", options.ovf_info.type, options.ovf_info.type ); retval = PAPI_get_opt( PAPI_SUBSTRATEINFO, &options2 ); if ( retval < 0 ) test_fail( __FILE__, __LINE__, "PAPI_get_opt", retval ); printf( "sub_info->hardware_intr = %d\n\n", options2.sub_info->hardware_intr ); if ( ( hwinfo = PAPI_get_hardware_info( ) ) == NULL ) test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", PAPI_EMISC ); printf( "Architecture %s, %d\n", hwinfo->model_string, hwinfo->model ); /* processing exceptions is a pain */ #if ((defined(linux) && (defined(__i386__) || (defined __x86_64__))) ) if ( !strncmp( hwinfo->model_string, "Intel Pentium 4", 15 ) ) { evt3 = PAPI_L2_TCM; } else if ( !strncmp( hwinfo->model_string, "AMD K7", 6 ) ) { /* do nothing */ } else if ( !strncmp( hwinfo->model_string, "AMD K8", 6 ) ) { /* do nothing */ } else if ( !strncmp( hwinfo->model_string, "Intel Core", 10 ) ) { evt3 = 0; } else evt3 = 0; /* for default PIII */ #endif retval = PAPI_create_eventset( &EventSet ); if ( retval < 0 ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); retval = PAPI_add_event( EventSet, PAPI_TOT_INS ); if ( retval < 0 ) test_fail( __FILE__, __LINE__, "PAPI_add_event:PAPI_TOT_INS", retval ); retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ); if ( retval < 0 ) test_fail( __FILE__, __LINE__, "PAPI_add_event:PAPI_TOT_CYC", retval ); if ( evt3 ) { retval = PAPI_add_event( EventSet, evt3 ); if ( retval < 0 ) test_fail( __FILE__, __LINE__, "PAPI_add_event:evt3", retval ); } retval = PAPI_overflow( EventSet, PAPI_TOT_INS, OVRFLOW, 0, handler ); if ( retval < 0 ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); retval = PAPI_start( EventSet ); if ( retval < 0 ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); for ( i = 0; i < 1000000; i++ ) { if ( i % 1000 == 0 ) { int i; PAPI_read( EventSet, vals ); if ( vals[0] % OVRFLOW > LOWERFLOW || vals[0] % OVRFLOW < UPPERFLOW ) { dash = 0; printf( "Main loop read vals :" ); for ( i = 0; i < 3 /* 8 */ ; i++ ) printf( "%lld ", vals[i] ); printf( "\n" ); if ( ovrflow ) { error = ovrflow - ( lwrflow + vals[0] ) / 2; printf( "Difference: %lld\n", error ); ovrflow = 0; if ( abs( error ) > max_error ) max_error = abs( error ); } lwrflow = vals[0]; } else if ( vals[0] % OVRFLOW > UPPERFLOW && !dash ) { dash = 1; printf( "---------------------\n" ); } } } retval = PAPI_stop( EventSet, vals ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 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 ); printf( "Verification:\n" ); printf ( "Maximum absolute difference between overflow value\nand adjacent measured values is: %lld\n", max_error ); if ( max_error >= ERRORFLOW ) { printf( "This exceeds the error limit: %d\n", ERRORFLOW ); test_fail( __FILE__, __LINE__, "Overflows", 1 ); } printf( "This is within the error limit: %d\n", ERRORFLOW ); test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
int main() { double *a; double *b; double *c; int i = 0, j = 0, k = 0; int *events; // Array of events long long *values; // Array of values events int EventSet = PAPI_NULL; // Handle for a PAPI event set as created by PAPI_create_eventset (3) int retval; // Test fail function int num_event = 0; // Number of events int max_event; // Number of available events int EventCode = 0; // Event code PAPI_event_info_t pset; // PAPI_event_info_t Struct Reference char evname[PAPI_MAX_STR_LEN]; // Symbol event /* Memory asignament to matrixs*/ if((a = (double *)malloc(mrows * ncolumns * sizeof(double))) == NULL) printf("Error malloc matrix a[%d]\n",mrows * ncolumns); if((b = (double *)malloc(ncolumns * pcolumns * sizeof(double))) == NULL) printf("Error malloc matrix b[%d]\n",mrows * ncolumns); if((c = (double *)malloc(mrows * pcolumns * sizeof(double))) == NULL) printf("Error malloc matrix c[%d]\n",mrows * ncolumns); /* Initialize the Matrix arrays */ initmat(a, b, mrows, ncolumns, pcolumns); /* Initialize the PAPI library */ retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); /* Enable and initialize multiplex support */ retval = PAPI_multiplex_init(); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", retval ); /* Create an EventSet */ retval = PAPI_create_eventset(&EventSet); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); /* Assign it to the CPU component */ retval = PAPI_assign_eventset_component(EventSet, 0); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); /* Convert the EventSet to a multiplexed event set */ retval = PAPI_set_multiplex(EventSet); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval ); /* Obtaining the number of available events */ max_event = PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ); printf("\nNumber of available events: %d", max_event ); /* Fill up the event set with as many non-derived events as we can */ EventCode = PAPI_PRESET_MASK; do { if ( PAPI_get_event_info( EventCode, &pset ) == PAPI_OK ) { if ( pset.count && ( strcmp( pset.derived, "NOT_DERIVED" ) == 0 ) ) { retval = PAPI_add_event( EventSet, ( int ) pset.event_code ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); else { //printf( "Added %s\n", pset.symbol ); num_event++; } } } } while ( ( PAPI_enum_event( &EventCode, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK ) && ( num_event < max_event ) ); /* Memory asignament to values and events*/ events = ( int * ) malloc( ( size_t ) num_event * sizeof ( int ) ); if ( events == NULL ) test_fail( __FILE__, __LINE__, "Error malloc events", 0 ); values = ( long long * ) malloc( ( size_t ) num_event * sizeof ( long long ) ); if ( values == NULL ) test_fail( __FILE__, __LINE__, "Erro malloc values", 0 ); /* Start counting events */ if ((retval=PAPI_start(EventSet)) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); /* Matrix-Matrix multiply */ matmul(a, b, c, mrows, ncolumns, pcolumns); /* Read the counters */ if ((retval=PAPI_read( EventSet, values )) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_read_counters", retval); /* Stop counting events */ if ((retval=PAPI_stop( EventSet, values )) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop_counters", retval); /* List the events in the event set */ retval = PAPI_list_events( EventSet, events, &num_event ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_list_events", retval ); /* Print results */ printf("\nNumber of non-zero events: %d\n", num_event ); printf( "\nCounts of non-zero available events........................................................\n" ); printf("Name: \t\t\t Value: \t Description:\n"); for ( i = 0; i < num_event; i++ ) { PAPI_event_code_to_name( events[i], evname ); // Obtaining name of available events PAPI_get_event_info(events[i], &pset); if ( values[i] != 0 ) printf("%s \t %15lld \t %s\n", evname, values[i], pset.long_descr); } printf( "\nCounts of zero available events............................................................\n" ); printf("Name: \t\t\t Value: \t Description:\n"); for ( i = 0; i < num_event; i++ ) { PAPI_event_code_to_name( events[i], evname ); // Obtaining name of available events PAPI_get_event_info(events[i], &pset); if ( values[i] == 0 ) printf("%s \t %15lld \t %s\n", evname, values[i], pset.long_descr); } /* Check if counter pair(s) had identical values */ for ( i = 0; i < num_event; i++ ) { for ( i = j+1; j < num_event; j++ ) { if ( ( i != j ) && ( values[i] == values[j] ) ) k++; } } if ( k != 0 ) { printf( "\nCaution: %d counter pair(s) had identical values\n", k ); } printf("\n"); /* Free memory */ free( events ); free( values ); free( a ); free( b ); free( c ); /* Cleaning events */ retval = PAPI_cleanup_eventset( EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); /* Destroying events */ 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 retval, num_tests = 2, eventcnt, events[2], i, tmp; int EventSet1 = PAPI_NULL, EventSet2 = PAPI_NULL; int PAPI_event; long_long values1[2], values2[2]; long_long elapsed_cyc; char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN]; retval = PAPI_library_init(PAPI_VER_CURRENT); retval = PAPI_set_debug(PAPI_VERB_ECONT); /* query and set up the right instruction to monitor */ if (PAPI_query_event(PAPI_FP_OPS) == PAPI_OK) PAPI_event = PAPI_FP_OPS; else PAPI_event = PAPI_TOT_INS; retval = PAPI_event_code_to_name(PAPI_event, event_name); sprintf(add_event_str, "PAPI_add_event[%s]", event_name); retval = PAPI_create_eventset(&EventSet1); /* Add the events */ retval = PAPI_add_event(EventSet1, PAPI_event); retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC); /* Add them reversed to EventSet2 */ retval = PAPI_create_eventset(&EventSet2); eventcnt = 2; retval = PAPI_list_events(EventSet1, events, &eventcnt); for (i = eventcnt - 1; i >= 0; i--) { retval = PAPI_event_code_to_name(events[i], event_name); retval = PAPI_add_event(EventSet2, events[i]); } elapsed_cyc = PAPI_get_real_cyc(); retval = PAPI_start(EventSet1); do_flops(NUM_FLOPS); retval = PAPI_stop(EventSet1, values1); retval = PAPI_start(EventSet2); do_flops(NUM_FLOPS); retval = PAPI_stop(EventSet2, values2); elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc; retval = PAPI_cleanup_eventset(EventSet1); /* JT */ retval = PAPI_destroy_eventset(&EventSet1); retval = PAPI_cleanup_eventset(EventSet2); /* JT */ retval = PAPI_destroy_eventset(&EventSet2); printf("Test case 0: start, stop.\n"); printf("-----------------------------------------------\n"); tmp = PAPI_get_opt(PAPI_DEFDOM, NULL); tmp = PAPI_get_opt(PAPI_DEFGRN, NULL); printf("Using %d iterations of c += a*b\n", NUM_FLOPS); printf ("-------------------------------------------------------------------------\n"); printf("Test type : \t 1\t 2\n"); printf("%ld %ld\n", values1[0], values2[1]); printf("%d %d\n", "PAPI_TOT_INS : \t", values1[1], values2[0]); printf("%ld\n", "Real cycles : \t", elapsed_cyc); printf ("-------------------------------------------------------------------------\n"); printf("Verification: none\n"); exit(1); }
int main( int argc, char **argv ) { int status, retval, num_tests = 2, tmp; int EventSet1 = PAPI_NULL, EventSet2 = PAPI_NULL; int PAPI_event, PAPI_event2, mask1, mask2; int num_events1, num_events2; long long **values; long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc; char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN]; const PAPI_component_info_t *cmpinfo; pid_t pid, pid2; double ratio1,ratio2; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Initialize the library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval ); } /* get the component info and check if we support attach */ 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 ); } /* fork off first child */ pid = fork( ); if ( pid < 0 ) { test_fail_exit( __FILE__, __LINE__, "fork()", PAPI_ESYS ); } if ( pid == 0 ) { exit( wait_for_attach_and_loop( 1 ) ); } /* fork off second child, does twice as much */ pid2 = fork( ); if ( pid2 < 0 ) { test_fail_exit( __FILE__, __LINE__, "fork()", PAPI_ESYS ); } if ( pid2 == 0 ) { exit( wait_for_attach_and_loop( 2 ) ); } /* 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 */ EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 ); EventSet2 = add_two_events( &num_events2, &PAPI_event2, &mask2 ); if ( cmpinfo->attach_must_ptrace ) { if ( ptrace( PTRACE_ATTACH, pid, NULL, NULL ) == -1 ) { perror( "ptrace(PTRACE_ATTACH)" ); return 1 ; } if ( waitpid( pid, &status, 0 ) == -1 ) { perror( "waitpid()" ); exit( 1 ); } if ( WIFSTOPPED( status ) == 0 ) { test_fail( __FILE__, __LINE__, "Child process didnt return true to WIFSTOPPED", 0 ); } if ( ptrace( PTRACE_ATTACH, pid2, NULL, NULL ) == -1 ) { perror( "ptrace(PTRACE_ATTACH)" ); return 1; } if ( waitpid( pid2, &status, 0 ) == -1 ) { perror( "waitpid()" ); exit( 1 ); } if ( WIFSTOPPED( status ) == 0 ) { test_fail( __FILE__, __LINE__, "Child process didnt return true to WIFSTOPPED", 0 ); } } retval = PAPI_attach( EventSet1, ( unsigned long ) pid ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_attach", retval ); } retval = PAPI_attach( EventSet2, ( unsigned long ) pid2 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_attach", retval ); } retval = PAPI_event_code_to_name( PAPI_event, event_name ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); } sprintf( add_event_str, "PAPI_add_event[%s]", event_name ); /* num_events1 is greater than num_events2 so don't worry. */ values = allocate_test_space( num_tests, num_events1 ); /* Gather before values */ 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( ); /* Wait for the SIGSTOP. */ if ( cmpinfo->attach_must_ptrace ) { if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) { perror( "ptrace(PTRACE_CONT)" ); return 1; } if ( waitpid( pid, &status, 0 ) == -1 ) { perror( "waitpid()" ); exit( 1 ); } if ( WIFSTOPPED( status ) == 0 ) { test_fail( __FILE__, __LINE__, "Child process didn't return true to WIFSTOPPED", 0 ); } if ( WSTOPSIG( status ) != SIGSTOP ) { test_fail( __FILE__, __LINE__, "Child process didn't stop on SIGSTOP", 0 ); } if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) { perror( "ptrace(PTRACE_CONT)" ); return 1; } if ( waitpid( pid2, &status, 0 ) == -1 ) { perror( "waitpid()" ); exit( 1 ); } if ( WIFSTOPPED( status ) == 0 ) { test_fail( __FILE__, __LINE__, "Child process didn't return true to WIFSTOPPED", 0 ); } if ( WSTOPSIG( status ) != SIGSTOP ) { test_fail( __FILE__, __LINE__, "Child process didn't stop on SIGSTOP", 0 ); } } /* start first child */ retval = PAPI_start( EventSet1 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } /* start second child */ retval = PAPI_start( EventSet2 ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", retval ); } /* Wait for the SIGSTOP. */ if ( cmpinfo->attach_must_ptrace ) { if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) { perror( "ptrace(PTRACE_ATTACH)" ); return 1; } if ( waitpid( pid, &status, 0 ) == -1 ) { perror( "waitpid()" ); exit( 1 ); } if ( WIFSTOPPED( status ) == 0 ) { test_fail( __FILE__, __LINE__, "Child process didn't return true to WIFSTOPPED", 0 ); } if ( WSTOPSIG( status ) != SIGSTOP ) { test_fail( __FILE__, __LINE__, "Child process didn't stop on SIGSTOP", 0 ); } if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) { perror( "ptrace(PTRACE_ATTACH)" ); return 1; } if ( waitpid( pid2, &status, 0 ) == -1 ) { perror( "waitpid()" ); exit( 1 ); } if ( WIFSTOPPED( status ) == 0 ) { test_fail( __FILE__, __LINE__, "Child process didn't return true to WIFSTOPPED", 0 ); } if ( WSTOPSIG( status ) != SIGSTOP ) { test_fail( __FILE__, __LINE__, "Child process didn't stop on SIGSTOP", 0 ); } } 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; /* stop first child */ retval = PAPI_stop( EventSet1, values[0] ); if ( retval != PAPI_OK ) { printf( "Warning: PAPI_stop returned error %d, probably ok.\n", retval ); } /* stop second child */ retval = PAPI_stop( EventSet2, values[1] ); if ( retval != PAPI_OK ) { printf( "Warning: PAPI_stop returned error %d, probably ok.\n", retval ); } remove_test_events( &EventSet1, mask1 ); remove_test_events( &EventSet2, mask2 ); if ( cmpinfo->attach_must_ptrace ) { if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) { perror( "ptrace(PTRACE_CONT)" ); return 1; } if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) { perror( "ptrace(PTRACE_CONT)" ); return 1; } } if ( waitpid( pid, &status, 0 ) == -1 ) { perror( "waitpid()" ); exit( 1 ); } if ( WIFEXITED( status ) == 0 ) { test_fail( __FILE__, __LINE__, "Child process didn't return true to WIFEXITED", 0 ); } if ( waitpid( pid2, &status, 0 ) == -1 ) { perror( "waitpid()" ); exit( 1 ); } if ( WIFEXITED( status ) == 0 ) { test_fail( __FILE__, __LINE__, "Child process didn't return true to WIFEXITED", 0 ); } /* This code isn't necessary as we know the child has exited, */ /* it *may* return an error if the component so chooses. You */ /* should use read() instead. */ printf( "Test case: multiple 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" ); sprintf( add_event_str, "(PID %jd) %-12s : \t", ( intmax_t ) pid, event_name ); printf( TAB1, add_event_str, values[0][1] ); sprintf( add_event_str, "(PID %jd) PAPI_TOT_CYC : \t", ( intmax_t ) pid ); printf( TAB1, add_event_str, values[0][0] ); sprintf( add_event_str, "(PID %jd) %-12s : \t", ( intmax_t ) pid2, event_name ); printf( TAB1, add_event_str,values[1][1] ); sprintf( add_event_str, "(PID %jd) PAPI_TOT_CYC : \t", ( intmax_t ) pid2 ); printf( TAB1, add_event_str, values[1][0] ); 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: pid %d results should be twice pid %d\n",pid2,pid ); ratio1=(double)values[1][0]/(double)values[0][0]; ratio2=(double)values[1][1]/(double)values[0][1]; printf("\t%lld/%lld = %lf\n",values[1][0],values[0][0],ratio1); if ((ratio1 >2.15 ) || (ratio1 < 1.85)) { printf("Ratio out of range, should be ~2.0 not %lf\n",ratio1); test_fail( __FILE__, __LINE__, "Error: Counter ratio not two", 0 ); } printf("\t%lld/%lld = %lf\n",values[1][1],values[0][1],ratio2); if ((ratio2 >2.75 ) || (ratio2 < 1.25)) { printf("Ratio out of range, should be ~2.0, not %lf\n",ratio2); test_fail( __FILE__, __LINE__, "Known issue: Counter ratio not two", 0 ); } test_pass( __FILE__, values, num_tests ); return 0; }
int add_test_events( int *number, int *mask, int allow_derived ) { int retval,i; int EventSet = PAPI_NULL; int num_counters = 0; char name_string[BUFSIZ]; *number = 0; /* get the number of available HW counters */ num_counters = PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ); if ( num_counters < 1 ) { test_fail( __FILE__, __LINE__, "Zero HW Counters available", num_counters ); } /* create the eventset */ retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); } /* check all the masks */ for(i=0;i<MAX_TEST_EVENTS;i++) { if ( *mask & test_events[i].mask ) { /* remove any derived events if told to */ if ((is_event_derived(test_events[i].event)) && (!allow_derived)) { *mask = *mask ^ test_events[i].mask; continue; } retval = PAPI_add_event( EventSet, test_events[i].event ); if ( retval == PAPI_OK ) { ( *number )++; #if 0 if ((*number)==num_counters) { if ( !TESTS_QUIET) { fprintf(stdout, "Stopping with %d events due to HW limit\n", num_counters); } break; } #endif } else { if ( !TESTS_QUIET ) { PAPI_event_code_to_name(test_events[i].event,name_string); fprintf( stdout, "%x %s is not available.\n", test_events[i].event,name_string); } *mask = *mask ^ test_events[i].mask; } } } return EventSet; }
int main( int argc, char **argv ) { int EventSet = PAPI_NULL; long long hard_min, hard_max, soft_min, soft_max; int retval; int PAPI_event = 0, mythreshold; char event_name[PAPI_MAX_STR_LEN]; PAPI_option_t opt; PAPI_event_info_t info; PAPI_option_t itimer; const PAPI_hw_info_t *hw_info = NULL; 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 ); /* query and set up the right instruction to monitor */ if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) { if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) { PAPI_get_event_info( PAPI_FP_INS, &info ); if ( info.count == 1 || !strcmp( info.derived, "DERIVED_CMPD" ) ) PAPI_event = PAPI_FP_INS; } } if ( PAPI_event == 0 ) { if ( PAPI_query_event( PAPI_FP_OPS ) == PAPI_OK ) { PAPI_get_event_info( PAPI_FP_OPS, &info ); if ( info.count == 1 || !strcmp( info.derived, "DERIVED_CMPD" ) ) PAPI_event = PAPI_FP_OPS; } } if ( PAPI_event == 0 ) { if ( PAPI_query_event( PAPI_TOT_INS ) == PAPI_OK ) { PAPI_get_event_info( PAPI_TOT_INS, &info ); if ( info.count == 1 || !strcmp( info.derived, "DERIVED_CMPD" ) ) PAPI_event = PAPI_TOT_INS; } } if ( PAPI_event == 0 ) test_skip( __FILE__, __LINE__, "No suitable event for this test found!", 0 ); hw_info = PAPI_get_hardware_info( ); if ( hw_info == NULL ) test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); if ( PAPI_event == PAPI_FP_INS ) mythreshold = THRESHOLD; else #if defined(linux) mythreshold = ( int ) hw_info->cpu_max_mhz * 20000; #else mythreshold = THRESHOLD * 2; #endif retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); retval = PAPI_add_event( EventSet, PAPI_event ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); retval = PAPI_get_opt( PAPI_COMPONENTINFO, &opt ); if ( retval != PAPI_OK ) test_skip( __FILE__, __LINE__, "Platform does not support Hardware overflow", 0 ); do_stuff( ); /* Do reference count */ retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_stuff( ); retval = PAPI_stop( EventSet, &values[use_total] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); use_total++; /* Now do hardware overflow reference count */ retval = PAPI_overflow( EventSet, PAPI_event, 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_stuff( ); retval = PAPI_stop( EventSet, &values[use_total] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); use_total++; retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); /* Now do software overflow reference count, uses SIGPROF */ retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, PAPI_OVERFLOW_FORCE_SW, 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_stuff( ); retval = PAPI_stop( EventSet, &values[use_total] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); use_total++; retval = PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW, handler ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); /* Now do software overflow with SIGVTALRM */ memset( &itimer, 0, sizeof ( itimer ) ); itimer.itimer.itimer_num = ITIMER_VIRTUAL; itimer.itimer.itimer_sig = SIGVTALRM; if ( PAPI_set_opt( PAPI_DEF_ITIMER, &itimer ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval ); retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, PAPI_OVERFLOW_FORCE_SW, 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_stuff( ); retval = PAPI_stop( EventSet, &values[use_total] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); use_total++; retval = PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW, handler ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); /* Now do software overflow with SIGALRM */ memset( &itimer, 0, sizeof ( itimer ) ); itimer.itimer.itimer_num = ITIMER_REAL; itimer.itimer.itimer_sig = SIGALRM; if ( PAPI_set_opt( PAPI_DEF_ITIMER, &itimer ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval ); retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, PAPI_OVERFLOW_FORCE_SW, 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_stuff( ); retval = PAPI_stop( EventSet, &values[use_total] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); use_total++; retval = PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW, handler ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); if ( !TESTS_QUIET ) { if ( ( retval = PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); printf ( "Test case: Software overflow of various types with 1 event in set.\n" ); printf ( "------------------------------------------------------------------------------\n" ); printf( "Threshold for overflow is: %d\n", mythreshold ); printf ( "------------------------------------------------------------------------------\n" ); printf( "Test type : %11s%13s%13s%13s%13s\n", "Reference", "Hardware", "ITIMER_PROF", "ITIMER_VIRT", "ITIMER_REAL" ); printf( "%-12s: %11lld%13lld%13lld%13lld%13lld\n", info.symbol, values[0], values[1], values[2], values[3], values[4] ); printf( "Overflows : %11d%13d%13d%13d%13d\n", total[0], total[1], total[2], total[3], total[4] ); printf ( "------------------------------------------------------------------------------\n" ); printf( "Verification:\n" ); printf ( "Overflow in Column 2 greater than or equal to overflows in Columns 3, 4, 5\n" ); printf( "Overflow in Columns 3, 4, 5 greater than 0\n" ); } hard_min = ( long long ) ( ( ( double ) values[0] * ( 1.0 - OVR_TOLERANCE ) ) / ( double ) mythreshold ); hard_max = ( long long ) ( ( ( double ) values[0] * ( 1.0 + OVR_TOLERANCE ) ) / ( double ) mythreshold ); soft_min = ( long long ) ( ( ( double ) values[0] * ( 1.0 - SOFT_TOLERANCE ) ) / ( double ) mythreshold ); soft_max = ( long long ) ( ( ( double ) values[0] * ( 1.0 + SOFT_TOLERANCE ) ) / ( double ) mythreshold ); if ( total[1] > hard_max || total[1] < hard_min ) test_fail( __FILE__, __LINE__, "Hardware Overflows outside limits", 1 ); if ( total[2] > soft_max || total[3] > soft_max || total[4] > soft_max ) test_fail( __FILE__, __LINE__, "Software Overflows exceed theoretical maximum", 1 ); if ( total[2] < soft_min || total[3] < soft_min || total[4] < soft_min ) printf( "WARNING: Software Overflow occuring but suspiciously low\n" ); if ( ( total[2] == 0 ) || ( total[3] == 0 ) || ( total[4] == 0 ) ) test_fail( __FILE__, __LINE__, "Software Overflows", 1 ); test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
int case1(void) { int retval, i, EventSet = PAPI_NULL, j = 0, k = 0, allvalid = 1; int max_mux, nev, *events; long long *values; PAPI_event_info_t pset; char evname[PAPI_MAX_STR_LEN]; init_papi(); init_multiplex(); retval = PAPI_create_eventset(&EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ retval = PAPI_assign_eventset_component(EventSet, 0); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval); retval = PAPI_set_multiplex(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_set_multiplex", retval); max_mux = PAPI_get_opt(PAPI_MAX_MPX_CTRS, NULL); if (max_mux > 32) max_mux = 32; /* Fill up the event set with as many non-derived events as we can */ printf("\nFilling the event set with as many non-derived events as we can...\n"); i = PAPI_PRESET_MASK; do { if (PAPI_get_event_info(i, &pset) == PAPI_OK) { if (pset.count && (strcmp(pset.derived,"NOT_DERIVED") == 0)) { retval = PAPI_add_event(EventSet, pset.event_code); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); else { printf("Added %s\n", pset.symbol); j++; } } } } while ((PAPI_enum_event(&i, PAPI_PRESET_ENUM_AVAIL) == PAPI_OK) && (j < max_mux)); events = (int *) malloc(j * sizeof(int)); if (events == NULL) test_fail(__FILE__, __LINE__, "malloc events", 0); values = (long long *) malloc(j * sizeof(long long)); if (values == NULL) test_fail(__FILE__, __LINE__, "malloc values", 0); do_stuff(); if (PAPI_start(EventSet) != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_stuff(); retval = PAPI_stop(EventSet, values); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); nev =j; retval = PAPI_list_events(EventSet, events, &nev); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_list_events", retval); printf("\nEvent Counts:\n"); for (i = 0, allvalid = 0; i < j; i++) { PAPI_event_code_to_name(events[i], evname); printf(TAB1, evname, values[i]); if (values[i] == 0) allvalid++; } printf("\n"); if (allvalid){ printf("Caution: %d counters had zero values\n", allvalid); } for (i = 0, allvalid = 0; i < j; i++) { for (k = i+1; k < j; k++) { if ((i != k) && (values[i] == values[k])) { allvalid++; break; } } } if (allvalid){ printf("Caution: %d counter pair(s) had identical values\n", allvalid); } free(events); free(values); 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 (SUCCESS); }
int main(int argc, char **argv) { int retval, num_tests = 6, tmp; long long **values; int EventSet=PAPI_NULL; const PAPI_hw_info_t *hw_info; #ifndef PENTIUM4 test_skip(__FILE__, __LINE__, "This test is intended only for Pentium 4.", 1); #endif 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", 2); retval = PAPI_create_eventset(&EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); values = allocate_test_space(num_tests, 2); /* First test: just PAPI_LD_INS */ retval = PAPI_add_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[0]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_remove_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval); /* Second test: just PAPI_SR_INS */ retval = PAPI_add_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[1]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_remove_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval); /* Third test: just PAPI_LST_INS */ retval = PAPI_add_event(EventSet, PAPI_LST_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LST_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[2]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); /* Fourth test: PAPI_LST_INS and PAPI_LD_INS */ retval = PAPI_add_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[3]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_remove_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval); /* Fifth test: PAPI_LST_INS and PAPI_SR_INS */ retval = PAPI_add_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[4]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_remove_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval); retval = PAPI_remove_event(EventSet, PAPI_LST_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LST_INS", retval); /* Sixth test: PAPI_LD_INS and PAPI_SR_INS */ retval = PAPI_add_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_LD_INS", retval); retval = PAPI_add_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_add_event: PAPI_SR_INS", retval); retval = PAPI_start(EventSet); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_start", retval); do_flops(NUM_FLOPS/10); retval = PAPI_stop(EventSet, values[5]); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); retval = PAPI_remove_event(EventSet, PAPI_LD_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_LD_INS", retval); retval = PAPI_remove_event(EventSet, PAPI_SR_INS); if (retval != PAPI_OK) test_fail(__FILE__, __LINE__, "PAPI_remove_event: PAPI_SR_INS", retval); if (!TESTS_QUIET) { printf("Pentium 4 Load / Store tests.\n"); printf("These PAPI events are counted by setting a tag at the front of the pipeline,\n"); printf("and counting tags at the back of the pipeline. All the tags are the same 'color'\n"); printf("and can't be distinguished from each other. Therefore, PAPI_LD_INS and PAPI_SR_INS\n"); printf("cannot be counted with the other two events, or the answer will always == PAPI_LST_INS.\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/10); printf("-------------------------------------------------------------------------------------------\n"); printf("Test: 1 2 3 4 5 6\n"); printf("%s %12lld %12s %12s %12lld %12s %12lld\n", "PAPI_LD_INS: ", (values[0])[0], "------", "------", (values[3])[1], "------", (values[5])[0]); printf("%s %12s %12lld %12s %12s %12lld %12lld\n", "PAPI_SR_INS: ", "------", (values[1])[0], "------", "------", (values[4])[1], (values[5])[1]); printf("%s %12s %12s %12lld %12lld %12lld %12s\n", "PAPI_LST_INS:", "------", "------", (values[2])[0], (values[3])[0], (values[4])[0], "------"); printf("-------------------------------------------------------------------------------------------\n"); printf("Test 1: PAPI_LD_INS only.\n"); printf("Test 2: PAPI_SR_INS only.\n"); printf("Test 3: PAPI_LST_INS only.\n"); printf("Test 4: PAPI_LD_INS and PAPI_LST_INS.\n"); printf("Test 5: PAPI_SR_INS and PAPI_LST_INS.\n"); printf("Test 6: PAPI_LD_INS and PAPI_SR_INS.\n"); printf("Verification: Values within each column should be the same.\n"); printf(" R3C3 ~= (R1C1 + R2C2) ~= all other entries.\n"); } test_pass(__FILE__, values, num_tests); 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 num_events; unsigned* events; int i; int rc; if (argc < 2) { fprintf (stderr, "Error: You must provide a set of PAPI counters\n"); return -1; } rc = PAPI_library_init(PAPI_VER_CURRENT); if (rc != PAPI_VER_CURRENT && rc > 0) { fprintf (stderr, "Error: PAPI library version mismatch!\n"); return -2; } events = (unsigned*) malloc (sizeof(unsigned)*(argc-1)); if (events == NULL) { fprintf (stderr, "Error: Cannot allocate memory for %d events\n", argc-1); return -3; } fprintf (stdout, "This binary was built using PAPI found in %s\n", PAPI_HOME); #if 0 fprintf (stdout, "\nNumber Hardware Counters : %d\n", PAPI_get_opt(PAPI_MAX_HWCTRS, NULL)); fprintf (stdout, "Max Multiplex Counters : %d\n", PAPI_get_opt(PAPI_MAX_MPX_CTRS, NULL)); #endif fprintf (stdout, "\nChecking the following counters:\n"); for (num_events = 0, i = 1; i < argc; i++) { PAPI_event_info_t info; int Event; char EventName[PAPI_MAX_STR_LEN]; char *strtoul_check; char *counter_last_position = &(argv[i][strlen(argv[i])]); /* Check if the user gave us the code or the name */ Event = strtoul (argv[i], &strtoul_check, 16); if (strtoul_check != counter_last_position) { rc = PAPI_event_name_to_code (argv[i], &Event); if (rc != PAPI_OK) { fprintf (stdout, "Warning! Counter '%s' is not available\n", argv[i]); continue; } } /* Get the event name */ rc = PAPI_event_code_to_name (Event, EventName); if (rc != PAPI_OK) strcpy (EventName, "unknown"); /* Get event info, native counters can have info.count == 0 */ rc = PAPI_get_event_info (Event, &info); if (rc != PAPI_OK) { fprintf (stdout, "Warning! Counter '%s' is not available\n", argv[i]); continue; } else if (info.count == 0 && (Event & PAPI_NATIVE_MASK) == 0) { fprintf (stdout, "Warning! Counter '%s' is not available\n", argv[i]); continue; } else { events[num_events++] = Event; #if 0 fprintf (stdout, "Counter %s (code %08x): Native? %s (if not, depends on %d native counters)\n", EventName, Event, Event&PAPI_NATIVE_MASK?"yes":"no", info.count); #endif fprintf (stdout, "Counter %s (code %08x): %s", EventName, Event, Event&PAPI_NATIVE_MASK?"native":"derived"); if (!(Event&PAPI_NATIVE_MASK)) fprintf (stdout, " (depends on %d native counters)", info.count); fprintf (stdout, "\n"); } } if (num_events == 0) { fprintf (stdout, "\n"); fprintf (stdout, "Sorry, no hardware counters were given\n"); fprintf (stdout, "Check %s/bin/papi_avail or \n", PAPI_HOME); fprintf (stdout, " %s/bin/papi_native_avail \n", PAPI_HOME); fprintf (stdout, "to get a list from the available counters\n"); return -4; } fprintf (stdout, "\n"); CheckInOrder (num_events, events); CheckMaxEventSet (num_events, events); return 0; }
int main(int argc, char **argv) { int retval,max_multiplex,i,EventSet=PAPI_NULL; PAPI_event_info_t info; int added=0; int events_tried=0; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); /* Initialize the library */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); } retval = PAPI_multiplex_init( ); if ( retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "Multiplex not supported", 1); } max_multiplex=PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ); if (!TESTS_QUIET) { printf("Maximum multiplexed counters=%d\n",max_multiplex); } if (!TESTS_QUIET) { printf("Trying to multiplex as many as possible:\n"); } retval = PAPI_create_eventset( &EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval ); } retval = PAPI_assign_eventset_component( EventSet, 0 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); } retval = PAPI_set_multiplex( EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__, "PAPI_create_multiplex", retval ); } i = 0 | PAPI_PRESET_MASK; PAPI_enum_event( &i, PAPI_ENUM_FIRST ); do { retval = PAPI_get_event_info( i, &info ); if (retval==PAPI_OK) { if (!TESTS_QUIET) printf("Adding %s: ",info.symbol); } retval = PAPI_add_event( EventSet, info.event_code ); if (retval!=PAPI_OK) { if (!TESTS_QUIET) printf("Fail!\n"); } else { if (!TESTS_QUIET) printf("Success!\n"); added++; } events_tried++; } while (PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK ); PAPI_shutdown( ); if (!TESTS_QUIET) { printf("Added %d of theoretical max %d\n",added,max_multiplex); } if (events_tried<max_multiplex) { if (!TESTS_QUIET) { printf("Ran out of events before we ran out of room\n"); } } else if (added!=max_multiplex) { test_fail(__FILE__, __LINE__, "Couldn't max out multiplexed events", 1); } test_pass( __FILE__, NULL, 0 ); exit( 0 ); }
int main( int argc, char **argv ) { int retval, num_tests = 30, tmp; int EventSet1 = PAPI_NULL; int EventSet2 = PAPI_NULL; int EventSet3 = PAPI_NULL; int mask1 = MASK1; int mask2 = MASK2; int mask3 = MASK3; int num_events1; int num_events2; int num_events3; long long **values; int i, j; long long min[3]; long long max[3]; long long sum[3]; 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 ); /* Make sure that required resources are available */ /* Skip (don't fail!) if they are not */ retval = PAPI_query_event( EVT1 ); if ( retval != PAPI_OK ) test_skip( __FILE__, __LINE__, EVT1_STR, retval ); retval = PAPI_query_event( EVT2 ); if ( retval != PAPI_OK ) test_skip( __FILE__, __LINE__, EVT2_STR, retval ); retval = PAPI_query_event( EVT3 ); if ( retval != PAPI_OK ) test_skip( __FILE__, __LINE__, EVT3_STR, retval ); EventSet1 = add_test_events( &num_events1, &mask1, 1 ); EventSet2 = add_test_events( &num_events2, &mask2, 1 ); EventSet3 = add_test_events( &num_events3, &mask3, 1 ); values = allocate_test_space( num_tests, 1 ); /* Warm me up */ do_l1misses( ITERS ); do_misses( 1, 1024 * 1024 * 4 ); for ( i = 0; i < 10; i++ ) { retval = PAPI_start( EventSet1 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_l1misses( ITERS ); do_misses( 1, 1024 * 1024 * 4 ); retval = PAPI_stop( EventSet1, values[( i * 3 ) + 0] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); retval = PAPI_start( EventSet2 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_l1misses( ITERS ); do_misses( 1, 1024 * 1024 * 4 ); retval = PAPI_stop( EventSet2, values[( i * 3 ) + 1] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); retval = PAPI_start( EventSet3 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); do_l1misses( ITERS ); do_misses( 1, 1024 * 1024 * 4 ); retval = PAPI_stop( EventSet3, values[( i * 3 ) + 2] ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } remove_test_events( &EventSet1, mask1 ); remove_test_events( &EventSet2, mask2 ); remove_test_events( &EventSet3, mask3 ); for ( j = 0; j < 3; j++ ) { min[j] = 65535; max[j] = sum[j] = 0; } for ( i = 0; i < 10; i++ ) { for ( j = 0; j < 3; j++ ) { if ( min[j] > values[( i * 3 ) + j][0] ) min[j] = values[( i * 3 ) + j][0]; if ( max[j] < values[( i * 3 ) + j][0] ) max[j] = values[( i * 3 ) + j][0]; sum[j] += values[( i * 3 ) + j][0]; } } if ( !TESTS_QUIET ) { printf( "Test case 10: start, stop for derived event %s.\n", CACHE_LEVEL ); 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", ITERS ); printf( "Repeated 10 times\n" ); printf ( "-------------------------------------------------------------------------\n" ); /* for (i=0;i<10;i++) { printf("Test type : %12s%13s%13s\n", "1", "2", "3"); printf(TAB3, EVT1_STR, values[(i*3)+0][0], (long long)0, (long long)0); printf(TAB3, EVT2_STR, (long long)0, values[(i*3)+1][0], (long long)0); printf(TAB3, EVT3_STR, (long long)0, (long long)0, values[(i*3)+2][0]); printf ("-------------------------------------------------------------------------\n"); } */ printf( "Test type : %12s%13s%13s\n", "min", "max", "sum" ); printf( TAB3, EVT1_STR, min[0], max[0], sum[0] ); printf( TAB3, EVT2_STR, min[1], max[1], sum[1] ); printf( TAB3, EVT3_STR, min[2], max[2], sum[2] ); printf ( "-------------------------------------------------------------------------\n" ); printf( "Verification:\n" ); #if defined(sun) && defined(sparc) printf( TAB1, "Sum 1 approximately equals sum 2 - sum 3 or", ( sum[1] - sum[2] ) ); #else printf( TAB1, "Sum 1 approximately equals sum 2 + sum 3 or", ( sum[1] + sum[2] ) ); #endif } { long long tmin, tmax; #if defined(sun) && defined(sparc) tmax = ( long long ) ( sum[1] - sum[2] ); #else tmax = ( long long ) ( sum[1] + sum[2] ); #endif printf( "percent error: %f\n", ( float ) ( abs( ( int ) ( tmax - sum[0] ) ) * 100 / sum[0] ) ); tmin = ( long long ) ( ( double ) tmax * 0.8 ); tmax = ( long long ) ( ( double ) tmax * 1.2 ); if ( sum[0] > tmax || sum[0] < tmin ) test_fail( __FILE__, __LINE__, CACHE_LEVEL, 1 ); } test_pass( __FILE__, values, num_tests ); exit( 1 ); }