|
PAPI
5.0.1.0
|
00001 /* 00002 * File: overflow.c 00003 * CVS: $Id$ 00004 * Author: Philip Mucci 00005 * mucci@cs.utk.edu 00006 * Mods: <your name here> 00007 * <your email address> 00008 */ 00009 00010 /* This file performs the following test: overflow dispatch 00011 00012 The Eventset contains: 00013 + PAPI_TOT_CYC 00014 + PAPI_FP_INS (overflow monitor) 00015 00016 - Start eventset 1 00017 - Do flops 00018 - Stop and measure eventset 1 00019 - Set up overflow on eventset 1 00020 - Start eventset 1 00021 - Do flops 00022 - Stop eventset 1 00023 */ 00024 00025 #include "papi_test.h" 00026 00027 #define OVER_FMT "handler(%d ) Overflow at %p! bit=0x%llx \n" 00028 #define OUT_FMT "%-12s : %16lld%16lld\n" 00029 00030 static int total = 0; /* total overflows */ 00031 00032 00033 void 00034 handler( int EventSet, void *address, long long overflow_vector, void *context ) 00035 { 00036 ( void ) context; 00037 00038 if ( !TESTS_QUIET ) { 00039 fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector ); 00040 } 00041 total++; 00042 } 00043 00044 int 00045 main( int argc, char **argv ) 00046 { 00047 int EventSet = PAPI_NULL; 00048 long long ( values[2] )[2]; 00049 long long min, max; 00050 int num_flops = NUM_FLOPS, retval; 00051 int PAPI_event, mythreshold = THRESHOLD; 00052 char event_name1[PAPI_MAX_STR_LEN]; 00053 const PAPI_hw_info_t *hw_info = NULL; 00054 int num_events, mask; 00055 00056 /* Set TESTS_QUIET variable */ 00057 tests_quiet( argc, argv ); 00058 00059 /* Init PAPI */ 00060 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00061 if ( retval != PAPI_VER_CURRENT ) 00062 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00063 00064 /* Get hardware info */ 00065 hw_info = PAPI_get_hardware_info( ); 00066 if ( hw_info == NULL ) 00067 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); 00068 00069 /* add PAPI_TOT_CYC and one of the events in */ 00070 /* PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS, */ 00071 /* depending on the availability of the event on */ 00072 /* the platform */ 00073 EventSet = 00074 add_two_nonderived_events( &num_events, &PAPI_event, &mask ); 00075 00076 printf("Using %x for the overflow event\n",PAPI_event); 00077 00078 if ( PAPI_event == PAPI_FP_INS ) { 00079 mythreshold = THRESHOLD; 00080 } 00081 else { 00082 #if defined(linux) 00083 mythreshold = ( int ) hw_info->cpu_max_mhz * 20000; 00084 #else 00085 mythreshold = THRESHOLD * 2; 00086 #endif 00087 } 00088 00089 /* Start the run calibration run */ 00090 retval = PAPI_start( EventSet ); 00091 if ( retval != PAPI_OK ) 00092 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00093 00094 do_flops( NUM_FLOPS ); 00095 00096 /* stop the calibration run */ 00097 retval = PAPI_stop( EventSet, values[0] ); 00098 if ( retval != PAPI_OK ) 00099 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00100 00101 00102 /* set up overflow handler */ 00103 retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler ); 00104 if ( retval != PAPI_OK ) { 00105 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00106 } 00107 00108 /* Start overflow run */ 00109 retval = PAPI_start( EventSet ); 00110 if ( retval != PAPI_OK ) { 00111 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00112 } 00113 00114 do_flops( num_flops ); 00115 00116 /* stop overflow run */ 00117 retval = PAPI_stop( EventSet, values[1] ); 00118 if ( retval != PAPI_OK ) 00119 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00120 retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler ); 00121 if ( retval != PAPI_OK ) 00122 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00123 00124 if ( !TESTS_QUIET ) { 00125 if ( ( retval = 00126 PAPI_event_code_to_name( PAPI_event, event_name1 ) ) != PAPI_OK ) 00127 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00128 00129 printf 00130 ( "Test case: Overflow dispatch of 2nd event in set with 2 events.\n" ); 00131 printf 00132 ( "---------------------------------------------------------------\n" ); 00133 printf( "Threshold for overflow is: %d\n", mythreshold ); 00134 printf( "Using %d iterations of c += a*b\n", num_flops ); 00135 printf( "-----------------------------------------------\n" ); 00136 00137 printf( "Test type : %16d%16d\n", 1, 2 ); 00138 printf( OUT_FMT, event_name1, ( values[0] )[1], ( values[1] )[1] ); 00139 printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[0], ( values[1] )[0] ); 00140 printf( "Overflows : %16s%16d\n", "", total ); 00141 printf( "-----------------------------------------------\n" ); 00142 } 00143 00144 retval = PAPI_cleanup_eventset( EventSet ); 00145 if ( retval != PAPI_OK ) 00146 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); 00147 00148 retval = PAPI_destroy_eventset( &EventSet ); 00149 if ( retval != PAPI_OK ) 00150 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); 00151 00152 if ( !TESTS_QUIET ) { 00153 printf( "Verification:\n" ); 00154 #if defined(linux) || defined(__ia64__) || defined(_POWER4) 00155 num_flops *= 2; 00156 #endif 00157 if ( PAPI_event == PAPI_FP_INS || PAPI_event == PAPI_FP_OPS ) { 00158 printf( "Row 1 approximately equals %d %d\n", num_flops, 00159 num_flops ); 00160 } 00161 printf( "Column 1 approximately equals column 2\n" ); 00162 printf( "Row 3 approximately equals %u +- %u %%\n", 00163 ( unsigned ) ( ( values[0] )[1] / ( long long ) mythreshold ), 00164 ( unsigned ) ( OVR_TOLERANCE * 100.0 ) ); 00165 } 00166 /* 00167 min = (long long)((values[0])[1]*(1.0-TOLERANCE)); 00168 max = (long long)((values[0])[1]*(1.0+TOLERANCE)); 00169 if ( (values[0])[1] > max || (values[0])[1] < min ) 00170 test_fail(__FILE__, __LINE__, event_name, 1); 00171 */ 00172 00173 min = 00174 ( long long ) ( ( ( double ) values[0][1] * ( 1.0 - OVR_TOLERANCE ) ) / 00175 ( double ) mythreshold ); 00176 max = 00177 ( long long ) ( ( ( double ) values[0][1] * ( 1.0 + OVR_TOLERANCE ) ) / 00178 ( double ) mythreshold ); 00179 printf( "Overflows: total(%d) > max(%lld) || total(%d) < min(%lld) \n", total, 00180 max, total, min ); 00181 if ( total > max || total < min ) 00182 test_fail( __FILE__, __LINE__, "Overflows", 1 ); 00183 00184 test_pass( __FILE__, NULL, 0 ); 00185 exit( 1 ); 00186 }