|
PAPI
5.0.1.0
|
00001 /* 00002 * File: overflow_allcounters.c 00003 * Author: Haihang You 00004 * you@cs.utk.edu 00005 * Mods: Vince Weaver 00006 * vweaver1@eecs.utk.edu 00007 * Mods: <your name here> 00008 * <your email address> 00009 */ 00010 00011 /* This file performs the following test: overflow all counters 00012 to test availability of overflow of all counters 00013 00014 - Start eventset 1 00015 - Do flops 00016 - Stop and measure eventset 1 00017 - Set up overflow on eventset 1 00018 - Start eventset 1 00019 - Do flops 00020 - Stop eventset 1 00021 */ 00022 00023 #include "papi_test.h" 00024 00025 #define OVER_FMT "handler(%d ) Overflow at %p! bit=0x%llx \n" 00026 #define OUT_FMT "%-12s : %16lld%16lld\n" 00027 00028 static int total = 0; /* total overflows */ 00029 00030 00031 void 00032 handler( int EventSet, void *address, long long overflow_vector, void *context ) 00033 { 00034 00035 ( void ) context; 00036 00037 if ( !TESTS_QUIET ) { 00038 printf( OVER_FMT, EventSet, address, overflow_vector ); 00039 } 00040 total++; 00041 } 00042 00043 int 00044 main( int argc, char **argv ) 00045 { 00046 int EventSet = PAPI_NULL; 00047 long long *values; 00048 int num_flops, retval, i, j; 00049 int *events, mythreshold; 00050 char **names; 00051 const PAPI_hw_info_t *hw_info = NULL; 00052 int num_events, *ovt; 00053 char name[PAPI_MAX_STR_LEN]; 00054 int using_perfmon = 0; 00055 int using_aix = 0; 00056 int cid; 00057 00058 /* Set TESTS_QUIET variable */ 00059 tests_quiet( argc, argv ); 00060 00061 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00062 if ( retval != PAPI_VER_CURRENT ) { 00063 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00064 } 00065 00066 hw_info = PAPI_get_hardware_info( ); 00067 if ( hw_info == NULL ) { 00068 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", retval ); 00069 } 00070 00071 cid = PAPI_get_component_index("perfmon"); 00072 if (cid>=0) using_perfmon = 1; 00073 00074 cid = PAPI_get_component_index("aix"); 00075 if (cid>=0) using_aix = 1; 00076 00077 /* add PAPI_TOT_CYC and one of the events in */ 00078 /* PAPI_FP_INS, PAPI_FP_OPS PAPI_TOT_INS, */ 00079 /* depending on the availability of the event*/ 00080 /* on the platform */ 00081 EventSet = enum_add_native_events( &num_events, &events, 1 , 1, 0); 00082 00083 if (!TESTS_QUIET) printf("Trying %d events\n",num_events); 00084 00085 names = ( char ** ) calloc( ( unsigned int ) num_events, 00086 sizeof ( char * ) ); 00087 00088 for ( i = 0; i < num_events; i++ ) { 00089 if ( PAPI_event_code_to_name( events[i], name ) != PAPI_OK ) { 00090 test_fail( __FILE__, __LINE__,"PAPI_event_code_to_name", retval); 00091 } 00092 else { 00093 names[i] = strdup( name ); 00094 if (!TESTS_QUIET) printf("%i: %s\n",i,names[i]); 00095 } 00096 } 00097 00098 values = ( long long * ) 00099 calloc( ( unsigned int ) ( num_events * ( num_events + 1 ) ), 00100 sizeof ( long long ) ); 00101 ovt = ( int * ) calloc( ( unsigned int ) num_events, sizeof ( int ) ); 00102 00103 #if defined(linux) 00104 { 00105 char *tmp = getenv( "THRESHOLD" ); 00106 if ( tmp ) { 00107 mythreshold = atoi( tmp ); 00108 } 00109 else if (hw_info->cpu_max_mhz!=0) { 00110 mythreshold = ( int ) hw_info->cpu_max_mhz * 20000; 00111 if (!TESTS_QUIET) printf("Using a threshold of %d (20,000 * MHz)\n",mythreshold); 00112 00113 } 00114 else { 00115 if (!TESTS_QUIET) printf("Using default threshold of %d\n",THRESHOLD); 00116 mythreshold = THRESHOLD; 00117 } 00118 } 00119 #else 00120 mythreshold = THRESHOLD; 00121 #endif 00122 00123 num_flops = NUM_FLOPS * 2; 00124 00125 /* initial test to make sure they all work */ 00126 if (!TESTS_QUIET) printf("Testing that the events all work with no overflow\n"); 00127 00128 retval = PAPI_start( EventSet ); 00129 if ( retval != PAPI_OK ) { 00130 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00131 } 00132 00133 do_flops( num_flops ); 00134 00135 retval = PAPI_stop( EventSet, values ); 00136 if ( retval != PAPI_OK ) { 00137 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00138 } 00139 00140 /* done with initial test */ 00141 00142 /* keep adding events? */ 00143 for ( i = 0; i < num_events; i++ ) { 00144 00145 /* Enable overflow */ 00146 if (!TESTS_QUIET) printf("Testing with overflow set on %s\n", 00147 names[i]); 00148 00149 retval = PAPI_overflow( EventSet, events[i], 00150 mythreshold, 0, handler ); 00151 if ( retval != PAPI_OK ) { 00152 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00153 } 00154 00155 retval = PAPI_start( EventSet ); 00156 if ( retval != PAPI_OK ) { 00157 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00158 } 00159 00160 do_flops( num_flops ); 00161 00162 retval = PAPI_stop( EventSet, values + ( i + 1 ) * num_events ); 00163 if ( retval != PAPI_OK ) { 00164 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00165 } 00166 00167 /* Disable overflow */ 00168 retval = PAPI_overflow( EventSet, events[i], 0, 0, handler ); 00169 if ( retval != PAPI_OK ) { 00170 test_fail( __FILE__, __LINE__, "PAPI_overflow", retval ); 00171 } 00172 ovt[i] = total; 00173 total = 0; 00174 } 00175 00176 if ( !TESTS_QUIET ) { 00177 00178 printf("\nResults in Matrix-view:\n"); 00179 printf( "Test Overflow on %d counters with %d events.\n", 00180 num_events,num_events ); 00181 printf( "-----------------------------------------------\n" ); 00182 printf( "Threshold for overflow is: %d\n", mythreshold ); 00183 printf( "Using %d iterations of c += a*b\n", num_flops ); 00184 printf( "-----------------------------------------------\n" ); 00185 00186 printf( "Test type : " ); 00187 for ( i = 0; i < num_events + 1; i++ ) { 00188 printf( "%16d", i ); 00189 } 00190 printf( "\n" ); 00191 for ( j = 0; j < num_events; j++ ) { 00192 printf( "%-27s : ", names[j] ); 00193 for ( i = 0; i < num_events + 1; i++ ) { 00194 printf( "%16lld", *( values + j + num_events * i ) ); 00195 } 00196 printf( "\n" ); 00197 } 00198 printf( "Overflows : %16s", "" ); 00199 for ( i = 0; i < num_events; i++ ) { 00200 printf( "%16d", ovt[i] ); 00201 } 00202 printf( "\n" ); 00203 printf( "-----------------------------------------------\n" ); 00204 } 00205 00206 /* validation */ 00207 00208 if ( !TESTS_QUIET ) { 00209 printf("\nResults broken out for validation\n"); 00210 } 00211 00212 if (!TESTS_QUIET) { 00213 00214 for ( j = 0; j < num_events+1; j++ ) { 00215 if (j==0) { 00216 printf("Test results, no overflow:\n\t"); 00217 } 00218 else { 00219 printf("Overflow of event %d, %s\n\t",j-1,names[j-1]); 00220 } 00221 for(i=0; i < num_events; i++) { 00222 if (i==j-1) { 00223 printf("*%lld* ",values[(num_events*j)+i]); 00224 } 00225 else { 00226 printf("%lld ",values[(num_events*j)+i]); 00227 } 00228 } 00229 printf("\n"); 00230 if (j!=0) { 00231 printf("\tOverflow should be %lld / %d = %lld\n", 00232 values[(num_events*j)+(j-1)], 00233 mythreshold, 00234 values[(num_events*j)+(j-1)]/mythreshold); 00235 printf("\tOverflow was %d\n",ovt[j-1]); 00236 } 00237 } 00238 } 00239 00240 for ( j = 0; j < num_events; j++ ) { 00241 //printf("Validation: %lld / %d != %d (%lld)\n", 00242 // *( values + j + num_events * (j+1) ) , 00243 // mythreshold, 00244 // ovt[j], 00245 // *(values+j+num_events*(j+1))/mythreshold); 00246 if ( *( values + j + num_events * ( j + 1 ) ) / mythreshold != ovt[j] ) { 00247 char error_string[BUFSIZ]; 00248 00249 if ( using_perfmon ) 00250 test_warn( __FILE__, __LINE__, 00251 "perfmon component handles overflow differently than perf_events", 00252 1 ); 00253 else if ( using_aix ) 00254 test_warn( __FILE__, __LINE__, 00255 "AIX (pmapi) component handles overflow differently than various other components", 00256 1 ); 00257 else { 00258 sprintf( error_string, 00259 "Overflow value differs from expected %lld / %d != %d (%lld)", 00260 *( values + j + num_events * ( j + 1 ) ), mythreshold, 00261 ovt[j], 00262 *( values + j + 00263 num_events * ( j + 1 ) ) / mythreshold ); 00264 test_fail( __FILE__, __LINE__, error_string, 1 ); 00265 } 00266 } 00267 } 00268 00269 retval = PAPI_cleanup_eventset( EventSet ); 00270 if ( retval != PAPI_OK ) 00271 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval ); 00272 00273 retval = PAPI_destroy_eventset( &EventSet ); 00274 if ( retval != PAPI_OK ) 00275 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval ); 00276 00277 free( ovt ); 00278 for ( i = 0; i < num_events; i++ ) 00279 free( names[i] ); 00280 free( names ); 00281 free( events ); 00282 free( values ); 00283 test_pass( __FILE__, NULL, 0 ); 00284 exit( 1 ); 00285 }