|
PAPI
5.0.1.0
|
00001 /* 00002 * File: overflow.c 00003 * CVS: $Id$ 00004 * Author: Nils Smeds [Based on tests/overflow.c by Philip Mucci] 00005 * smeds@pdc.kth.se 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 (overflow monitor) 00014 + PAPI_FP_INS 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 int total = 0; /* total overflows */ 00031 extern int TESTS_QUIET; /* Declared in test_utils.c */ 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, retval; 00051 int PAPI_event, mythreshold; 00052 char event_name[PAPI_MAX_STR_LEN]; 00053 const PAPI_hw_info_t *hw_info = NULL; 00054 00055 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00056 00057 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00058 if ( retval != PAPI_VER_CURRENT ) 00059 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00060 00061 hw_info = PAPI_get_hardware_info( ); 00062 if ( hw_info == NULL ) 00063 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); 00064 00065 #if defined(POWER3) || defined(__sparc__) 00066 PAPI_event = PAPI_TOT_INS; 00067 #else 00068 /* query and set up the right instruction to monitor */ 00069 PAPI_event = find_nonderived_event( ); 00070 #endif 00071 00072 if (( PAPI_event == PAPI_FP_OPS ) || ( PAPI_event == PAPI_FP_INS )) 00073 mythreshold = THRESHOLD; 00074 else 00075 #if defined(linux) 00076 mythreshold = ( int ) hw_info->cpu_max_mhz * 10000 * 2; 00077 #else 00078 mythreshold = THRESHOLD * 2; 00079 #endif 00080 00081 retval = PAPI_create_eventset( &EventSet ); 00082 if ( retval != PAPI_OK ) 00083 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); 00084 00085 retval = PAPI_add_event( EventSet, PAPI_event ); 00086 if ( retval != PAPI_OK ) 00087 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); 00088 00089 retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ); 00090 if ( retval != PAPI_OK ) 00091 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); 00092 00093 retval = PAPI_start( EventSet ); 00094 if ( retval != PAPI_OK ) 00095 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00096 00097 do_flops( NUM_FLOPS ); 00098 00099 retval = PAPI_stop( EventSet, values[0] ); 00100 if ( retval != PAPI_OK ) 00101 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00102 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 retval = PAPI_start( EventSet ); 00108 if ( retval != PAPI_OK ) 00109 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00110 00111 do_flops( NUM_FLOPS ); 00112 00113 retval = PAPI_stop( EventSet, values[1] ); 00114 if ( retval != PAPI_OK ) 00115 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00116 00117 retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler ); 00118 if ( retval != PAPI_OK ) 00119 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00120 00121 num_flops = NUM_FLOPS; 00122 #if defined(linux) || defined(__ia64__) || defined(_POWER4) 00123 num_flops *= 2; 00124 #endif 00125 00126 if ( !TESTS_QUIET ) { 00127 if ( ( retval = 00128 PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK ) 00129 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00130 00131 printf 00132 ( "Test case: Overflow dispatch of 1st event in set with 2 events.\n" ); 00133 printf 00134 ( "---------------------------------------------------------------\n" ); 00135 printf( "Threshold for overflow is: %d\n", mythreshold ); 00136 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS ); 00137 printf( "-----------------------------------------------\n" ); 00138 00139 printf( "Test type : %16d%16d\n", 1, 2 ); 00140 printf( OUT_FMT, event_name, ( values[0] )[0], ( values[1] )[0] ); 00141 printf( OUT_FMT, "PAPI_TOT_CYC", ( values[0] )[1], ( values[1] )[1] ); 00142 printf( "Overflows : %16s%16d\n", "", total ); 00143 printf( "-----------------------------------------------\n" ); 00144 00145 printf( "Verification:\n" ); 00146 /* 00147 if (PAPI_event == PAPI_FP_INS) 00148 printf("Row 1 approximately equals %d %d\n", num_flops, num_flops); 00149 */ 00150 /* Note that the second run prints output on stdout. On some systems 00151 * this is costly. PAPI_TOT_INS or PAPI_TOT_CYC are likely to be _very_ 00152 * different between the two runs. 00153 * printf("Column 1 approximately equals column 2\n"); 00154 */ 00155 printf( "Row 3 approximately equals %u +- %u %%\n", 00156 ( unsigned ) ( ( values[0] )[0] / ( long long ) mythreshold ), 00157 ( unsigned ) ( OVR_TOLERANCE * 100.0 ) ); 00158 } 00159 /* 00160 min = (long long)((values[0])[0]*(1.0-TOLERANCE)); 00161 max = (long long)((values[0])[0]*(1.0+TOLERANCE)); 00162 if ( (values[1])[0] > max || (values[1])[0] < min ) 00163 test_fail(__FILE__, __LINE__, event_name, 1); 00164 */ 00165 00166 min = 00167 ( long long ) ( ( ( double ) values[0][0] * ( 1.0 - OVR_TOLERANCE ) ) / 00168 ( double ) mythreshold ); 00169 max = 00170 ( long long ) ( ( ( double ) values[0][0] * ( 1.0 + OVR_TOLERANCE ) ) / 00171 ( double ) mythreshold ); 00172 if ( total > max || total < min ) 00173 test_fail( __FILE__, __LINE__, "Overflows", 1 ); 00174 00175 test_pass( __FILE__, NULL, 0 ); 00176 exit( 1 ); 00177 }