|
PAPI
5.0.1.0
|
00001 /* 00002 * File: overflow_force_software.c 00003 * CVS: $Id$ 00004 * Author: Kevin London 00005 * london@cs.utk.edu 00006 * Mods: Maynard Johnson 00007 * maynardj@us.ibm.com 00008 * Philip Mucci 00009 * mucci@cs.utk.edu 00010 * Haihang You 00011 * you@cs.utk.edu 00012 * <your name here> 00013 * <your email address> 00014 */ 00015 00016 /* This file performs the following test: overflow dispatch of an eventset 00017 with just a single event. Using both Hardware and software overflows 00018 00019 The Eventset contains: 00020 + PAPI_FP_INS (overflow monitor) 00021 00022 - Start eventset 1 00023 - Do flops 00024 - Stop and measure eventset 1 00025 - Set up overflow on eventset 1 00026 - Start eventset 1 00027 - Do flops 00028 - Stop eventset 1 00029 - Set up forced software overflow on eventset 1 00030 - Start eventset 1 00031 - Do flops 00032 - Stop eventset 1 00033 */ 00034 00035 #include "papi_test.h" 00036 00037 #define OVER_FMT "handler(%d) Overflow at %p overflow_vector=0x%llx!\n" 00038 #define OUT_FMT "%-12s : %16lld%16d%16lld\n" 00039 00040 #define SOFT_TOLERANCE 0.90 00041 #define MY_NUM_TESTS 5 00042 00043 static int total[MY_NUM_TESTS] = { 0, }; /* total overflows */ 00044 static int use_total = 0; /* which total field to bump */ 00045 static long long values[MY_NUM_TESTS] = { 0, }; 00046 00047 void 00048 handler( int EventSet, void *address, long long overflow_vector, void *context ) 00049 { 00050 ( void ) context; 00051 00052 if ( !TESTS_QUIET ) { 00053 fprintf( stderr, OVER_FMT, EventSet, address, overflow_vector ); 00054 } 00055 00056 total[use_total]++; 00057 } 00058 00059 int 00060 main( int argc, char **argv ) 00061 { 00062 int EventSet = PAPI_NULL; 00063 long long hard_min, hard_max, soft_min, soft_max; 00064 int retval; 00065 int PAPI_event = 0, mythreshold; 00066 char event_name[PAPI_MAX_STR_LEN]; 00067 PAPI_option_t opt; 00068 PAPI_event_info_t info; 00069 PAPI_option_t itimer; 00070 const PAPI_hw_info_t *hw_info = NULL; 00071 00072 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00073 00074 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00075 if ( retval != PAPI_VER_CURRENT ) 00076 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00077 00078 /* query and set up the right instruction to monitor */ 00079 if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) { 00080 if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) { 00081 PAPI_get_event_info( PAPI_FP_INS, &info ); 00082 if ( info.count == 1 || 00083 !strcmp( info.derived, "DERIVED_CMPD" ) ) 00084 PAPI_event = PAPI_FP_INS; 00085 } 00086 } 00087 if ( PAPI_event == 0 ) { 00088 if ( PAPI_query_event( PAPI_FP_OPS ) == PAPI_OK ) { 00089 PAPI_get_event_info( PAPI_FP_OPS, &info ); 00090 if ( info.count == 1 || 00091 !strcmp( info.derived, "DERIVED_CMPD" ) ) 00092 PAPI_event = PAPI_FP_OPS; 00093 } 00094 } 00095 if ( PAPI_event == 0 ) { 00096 if ( PAPI_query_event( PAPI_TOT_INS ) == PAPI_OK ) { 00097 PAPI_get_event_info( PAPI_TOT_INS, &info ); 00098 if ( info.count == 1 || 00099 !strcmp( info.derived, "DERIVED_CMPD" ) ) 00100 PAPI_event = PAPI_TOT_INS; 00101 } 00102 } 00103 00104 if ( PAPI_event == 0 ) 00105 test_skip( __FILE__, __LINE__, "No suitable event for this test found!", 00106 0 ); 00107 00108 hw_info = PAPI_get_hardware_info( ); 00109 if ( hw_info == NULL ) 00110 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); 00111 00112 if ( PAPI_event == PAPI_FP_INS ) 00113 mythreshold = THRESHOLD; 00114 else 00115 #if defined(linux) 00116 mythreshold = ( int ) hw_info->cpu_max_mhz * 20000; 00117 #else 00118 mythreshold = THRESHOLD * 2; 00119 #endif 00120 00121 retval = PAPI_create_eventset( &EventSet ); 00122 if ( retval != PAPI_OK ) 00123 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); 00124 00125 retval = PAPI_add_event( EventSet, PAPI_event ); 00126 if ( retval != PAPI_OK ) 00127 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); 00128 00129 retval = PAPI_get_opt( PAPI_COMPONENTINFO, &opt ); 00130 if ( retval != PAPI_OK ) 00131 test_skip( __FILE__, __LINE__, 00132 "Platform does not support Hardware overflow", 0 ); 00133 00134 do_stuff( ); 00135 00136 /* Do reference count */ 00137 00138 retval = PAPI_start( EventSet ); 00139 if ( retval != PAPI_OK ) 00140 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00141 00142 do_stuff( ); 00143 00144 retval = PAPI_stop( EventSet, &values[use_total] ); 00145 if ( retval != PAPI_OK ) 00146 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00147 use_total++; 00148 00149 /* Now do hardware overflow reference count */ 00150 00151 retval = PAPI_overflow( EventSet, PAPI_event, mythreshold, 0, handler ); 00152 if ( retval != PAPI_OK ) 00153 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00154 00155 retval = PAPI_start( EventSet ); 00156 if ( retval != PAPI_OK ) 00157 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00158 00159 do_stuff( ); 00160 00161 retval = PAPI_stop( EventSet, &values[use_total] ); 00162 if ( retval != PAPI_OK ) 00163 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00164 use_total++; 00165 00166 retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler ); 00167 if ( retval != PAPI_OK ) 00168 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00169 00170 /* Now do software overflow reference count, uses SIGPROF */ 00171 00172 retval = 00173 PAPI_overflow( EventSet, PAPI_event, mythreshold, 00174 PAPI_OVERFLOW_FORCE_SW, handler ); 00175 if ( retval != PAPI_OK ) 00176 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00177 00178 retval = PAPI_start( EventSet ); 00179 if ( retval != PAPI_OK ) 00180 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00181 00182 do_stuff( ); 00183 00184 retval = PAPI_stop( EventSet, &values[use_total] ); 00185 if ( retval != PAPI_OK ) 00186 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00187 use_total++; 00188 00189 retval = 00190 PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW, 00191 handler ); 00192 if ( retval != PAPI_OK ) 00193 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00194 00195 /* Now do software overflow with SIGVTALRM */ 00196 00197 memset( &itimer, 0, sizeof ( itimer ) ); 00198 itimer.itimer.itimer_num = ITIMER_VIRTUAL; 00199 itimer.itimer.itimer_sig = SIGVTALRM; 00200 00201 if ( PAPI_set_opt( PAPI_DEF_ITIMER, &itimer ) != PAPI_OK ) 00202 test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval ); 00203 00204 retval = 00205 PAPI_overflow( EventSet, PAPI_event, mythreshold, 00206 PAPI_OVERFLOW_FORCE_SW, handler ); 00207 if ( retval != PAPI_OK ) 00208 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00209 00210 retval = PAPI_start( EventSet ); 00211 if ( retval != PAPI_OK ) 00212 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00213 00214 do_stuff( ); 00215 00216 retval = PAPI_stop( EventSet, &values[use_total] ); 00217 if ( retval != PAPI_OK ) 00218 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00219 use_total++; 00220 00221 retval = 00222 PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW, 00223 handler ); 00224 if ( retval != PAPI_OK ) 00225 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00226 00227 /* Now do software overflow with SIGALRM */ 00228 00229 memset( &itimer, 0, sizeof ( itimer ) ); 00230 itimer.itimer.itimer_num = ITIMER_REAL; 00231 itimer.itimer.itimer_sig = SIGALRM; 00232 if ( PAPI_set_opt( PAPI_DEF_ITIMER, &itimer ) != PAPI_OK ) 00233 test_fail( __FILE__, __LINE__, "PAPI_set_opt", retval ); 00234 00235 retval = 00236 PAPI_overflow( EventSet, PAPI_event, mythreshold, 00237 PAPI_OVERFLOW_FORCE_SW, handler ); 00238 if ( retval != PAPI_OK ) 00239 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00240 00241 retval = PAPI_start( EventSet ); 00242 if ( retval != PAPI_OK ) 00243 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00244 00245 do_stuff( ); 00246 00247 retval = PAPI_stop( EventSet, &values[use_total] ); 00248 if ( retval != PAPI_OK ) 00249 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00250 use_total++; 00251 00252 retval = 00253 PAPI_overflow( EventSet, PAPI_event, 0, PAPI_OVERFLOW_FORCE_SW, 00254 handler ); 00255 if ( retval != PAPI_OK ) 00256 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00257 00258 if ( !TESTS_QUIET ) { 00259 if ( ( retval = 00260 PAPI_event_code_to_name( PAPI_event, event_name ) ) != PAPI_OK ) 00261 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00262 00263 printf 00264 ( "Test case: Software overflow of various types with 1 event in set.\n" ); 00265 printf 00266 ( "------------------------------------------------------------------------------\n" ); 00267 printf( "Threshold for overflow is: %d\n", mythreshold ); 00268 printf 00269 ( "------------------------------------------------------------------------------\n" ); 00270 00271 printf( "Test type : %11s%13s%13s%13s%13s\n", "Reference", "Hardware", 00272 "ITIMER_PROF", "ITIMER_VIRT", "ITIMER_REAL" ); 00273 printf( "%-12s: %11lld%13lld%13lld%13lld%13lld\n", info.symbol, 00274 values[0], values[1], values[2], values[3], values[4] ); 00275 printf( "Overflows : %11d%13d%13d%13d%13d\n", total[0], total[1], 00276 total[2], total[3], total[4] ); 00277 printf 00278 ( "------------------------------------------------------------------------------\n" ); 00279 00280 printf( "Verification:\n" ); 00281 00282 printf 00283 ( "Overflow in Column 2 greater than or equal to overflows in Columns 3, 4, 5\n" ); 00284 printf( "Overflow in Columns 3, 4, 5 greater than 0\n" ); 00285 } 00286 00287 hard_min = 00288 ( long long ) ( ( ( double ) values[0] * ( 1.0 - OVR_TOLERANCE ) ) / 00289 ( double ) mythreshold ); 00290 hard_max = 00291 ( long long ) ( ( ( double ) values[0] * ( 1.0 + OVR_TOLERANCE ) ) / 00292 ( double ) mythreshold ); 00293 soft_min = 00294 ( long long ) ( ( ( double ) values[0] * ( 1.0 - SOFT_TOLERANCE ) ) / 00295 ( double ) mythreshold ); 00296 soft_max = 00297 ( long long ) ( ( ( double ) values[0] * ( 1.0 + SOFT_TOLERANCE ) ) / 00298 ( double ) mythreshold ); 00299 00300 if ( total[1] > hard_max || total[1] < hard_min ) 00301 test_fail( __FILE__, __LINE__, "Hardware Overflows outside limits", 1 ); 00302 00303 if ( total[2] > soft_max || total[3] > soft_max || total[4] > soft_max ) 00304 test_fail( __FILE__, __LINE__, 00305 "Software Overflows exceed theoretical maximum", 1 ); 00306 00307 if ( total[2] < soft_min || total[3] < soft_min || total[4] < soft_min ) 00308 printf( "WARNING: Software Overflow occuring but suspiciously low\n" ); 00309 00310 if ( ( total[2] == 0 ) || ( total[3] == 0 ) || ( total[4] == 0 ) ) 00311 test_fail( __FILE__, __LINE__, "Software Overflows", 1 ); 00312 00313 test_pass( __FILE__, NULL, 0 ); 00314 exit( 1 ); 00315 }