|
PAPI
5.0.1.0
|
00001 /* 00002 * File: multiplex.c 00003 * Author: Philip Mucci 00004 * mucci@cs.utk.edu 00005 * Mods: <your name here> 00006 * <your email address> 00007 */ 00008 00009 /* This file tests the multiplex functionality, originally developed by 00010 John May of LLNL. */ 00011 00012 #include "papi_test.h" 00013 00014 /* Event to use in all cases; initialized in init_papi() */ 00015 00016 #define TOTAL_EVENTS 6 00017 00018 int solaris_preset_PAPI_events[TOTAL_EVENTS] = { 00019 PAPI_TOT_CYC, PAPI_BR_MSP, PAPI_L2_TCM, PAPI_L1_ICM, 0 00020 }; 00021 int power6_preset_PAPI_events[TOTAL_EVENTS] = { 00022 PAPI_TOT_CYC, PAPI_FP_INS, PAPI_L1_DCM, PAPI_L1_ICM, 0 00023 }; 00024 int preset_PAPI_events[TOTAL_EVENTS] = { 00025 PAPI_TOT_CYC, PAPI_FP_INS, PAPI_TOT_INS, PAPI_L1_DCM, PAPI_L1_ICM, 0 00026 }; 00027 static int PAPI_events[TOTAL_EVENTS] = { 0, }; 00028 static int PAPI_events_len = 0; 00029 00030 #define CPP_TEST_FAIL(string, retval) test_fail(__FILE__, __LINE__, string, retval) 00031 00032 void 00033 init_papi( int *out_events, int *len ) 00034 { 00035 int retval; 00036 int i, real_len = 0; 00037 int *in_events = preset_PAPI_events; 00038 const PAPI_hw_info_t *hw_info; 00039 00040 /* Initialize the library */ 00041 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00042 if ( retval != PAPI_VER_CURRENT ) 00043 CPP_TEST_FAIL( "PAPI_library_init", retval ); 00044 00045 hw_info = PAPI_get_hardware_info( ); 00046 if ( hw_info == NULL ) 00047 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); 00048 00049 if ( strstr( hw_info->model_string, "UltraSPARC" ) ) { 00050 in_events = solaris_preset_PAPI_events; 00051 } 00052 00053 if ( strcmp( hw_info->model_string, "POWER6" ) == 0 ) { 00054 in_events = power6_preset_PAPI_events; 00055 retval = PAPI_set_domain( PAPI_DOM_ALL ); 00056 if ( retval != PAPI_OK ) 00057 CPP_TEST_FAIL( "PAPI_set_domain", retval ); 00058 } 00059 00060 retval = PAPI_multiplex_init( ); 00061 if ( retval == PAPI_ENOSUPP) { 00062 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1); 00063 } 00064 else if ( retval != PAPI_OK ) 00065 CPP_TEST_FAIL( "PAPI_multiplex_init", retval ); 00066 00067 for ( i = 0; in_events[i] != 0; i++ ) { 00068 char out[PAPI_MAX_STR_LEN]; 00069 /* query and set up the right instruction to monitor */ 00070 retval = PAPI_query_event( in_events[i] ); 00071 if ( retval == PAPI_OK ) { 00072 out_events[real_len++] = in_events[i]; 00073 PAPI_event_code_to_name( in_events[i], out ); 00074 if ( real_len == *len ) 00075 break; 00076 } else { 00077 PAPI_event_code_to_name( in_events[i], out ); 00078 if ( !TESTS_QUIET ) 00079 printf( "%s does not exist\n", out ); 00080 } 00081 } 00082 if ( real_len < 1 ) 00083 CPP_TEST_FAIL( "No counters available", 0 ); 00084 *len = real_len; 00085 } 00086 00087 /* Tests that PAPI_multiplex_init does not mess with normal operation. */ 00088 00089 int 00090 case1( ) 00091 { 00092 int retval, i, EventSet = PAPI_NULL; 00093 long long values[2]; 00094 00095 PAPI_events_len = 2; 00096 init_papi( PAPI_events, &PAPI_events_len ); 00097 00098 retval = PAPI_create_eventset( &EventSet ); 00099 if ( retval != PAPI_OK ) 00100 CPP_TEST_FAIL( "PAPI_create_eventset", retval ); 00101 00102 for ( i = 0; i < PAPI_events_len; i++ ) { 00103 char out[PAPI_MAX_STR_LEN]; 00104 00105 retval = PAPI_add_event( EventSet, PAPI_events[i] ); 00106 if ( retval != PAPI_OK ) 00107 CPP_TEST_FAIL( "PAPI_add_event", retval ); 00108 PAPI_event_code_to_name( PAPI_events[i], out ); 00109 if ( !TESTS_QUIET ) 00110 printf( "Added %s\n", out ); 00111 } 00112 00113 do_stuff( ); 00114 00115 if ( PAPI_start( EventSet ) != PAPI_OK ) 00116 CPP_TEST_FAIL( "PAPI_start", retval ); 00117 00118 do_stuff( ); 00119 00120 retval = PAPI_stop( EventSet, values ); 00121 if ( retval != PAPI_OK ) 00122 CPP_TEST_FAIL( "PAPI_stop", retval ); 00123 00124 if ( !TESTS_QUIET ) { 00125 test_print_event_header( "case1:", EventSet ); 00126 printf( TAB2, "case1:", values[0], values[1] ); 00127 } 00128 retval = PAPI_cleanup_eventset( EventSet ); /* JT */ 00129 if ( retval != PAPI_OK ) 00130 CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval ); 00131 00132 PAPI_shutdown( ); 00133 return ( SUCCESS ); 00134 } 00135 00136 /* Tests that PAPI_set_multiplex() works before adding events */ 00137 00138 int 00139 case2( ) 00140 { 00141 int retval, i, EventSet = PAPI_NULL; 00142 long long values[2]; 00143 00144 PAPI_events_len = 2; 00145 init_papi( PAPI_events, &PAPI_events_len ); 00146 00147 retval = PAPI_create_eventset( &EventSet ); 00148 if ( retval != PAPI_OK ) 00149 CPP_TEST_FAIL( "PAPI_create_eventset", retval ); 00150 00151 /* In Component PAPI, EventSets must be assigned a component index 00152 before you can fiddle with their internals. 00153 0 is always the cpu component */ 00154 retval = PAPI_assign_eventset_component( EventSet, 0 ); 00155 if ( retval != PAPI_OK ) 00156 CPP_TEST_FAIL( "PAPI_assign_eventset_component", retval ); 00157 00158 retval = PAPI_set_multiplex( EventSet ); 00159 if ( retval == PAPI_ENOSUPP) { 00160 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1); 00161 } 00162 else if ( retval != PAPI_OK ) 00163 CPP_TEST_FAIL( "PAPI_set_multiplex", retval ); 00164 00165 for ( i = 0; i < PAPI_events_len; i++ ) { 00166 char out[PAPI_MAX_STR_LEN]; 00167 00168 retval = PAPI_add_event( EventSet, PAPI_events[i] ); 00169 if ( retval != PAPI_OK ) 00170 CPP_TEST_FAIL( "PAPI_add_event", retval ); 00171 PAPI_event_code_to_name( PAPI_events[i], out ); 00172 if ( !TESTS_QUIET ) 00173 printf( "Added %s\n", out ); 00174 } 00175 00176 do_stuff( ); 00177 00178 if ( PAPI_start( EventSet ) != PAPI_OK ) 00179 CPP_TEST_FAIL( "PAPI_start", retval ); 00180 00181 do_stuff( ); 00182 00183 retval = PAPI_stop( EventSet, values ); 00184 if ( retval != PAPI_OK ) 00185 CPP_TEST_FAIL( "PAPI_stop", retval ); 00186 00187 if ( !TESTS_QUIET ) { 00188 test_print_event_header( "case2:", EventSet ); 00189 printf( TAB2, "case2:", values[0], values[1] ); 00190 } 00191 00192 retval = PAPI_cleanup_eventset( EventSet ); 00193 if ( retval != PAPI_OK ) 00194 CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval ); 00195 00196 PAPI_shutdown( ); 00197 return ( SUCCESS ); 00198 } 00199 00200 /* Tests that PAPI_set_multiplex() works after adding events */ 00201 00202 int 00203 case3( ) 00204 { 00205 int retval, i, EventSet = PAPI_NULL; 00206 long long values[2]; 00207 00208 PAPI_events_len = 2; 00209 init_papi( PAPI_events, &PAPI_events_len ); 00210 00211 retval = PAPI_create_eventset( &EventSet ); 00212 if ( retval != PAPI_OK ) 00213 CPP_TEST_FAIL( "PAPI_create_eventset", retval ); 00214 00215 for ( i = 0; i < PAPI_events_len; i++ ) { 00216 char out[PAPI_MAX_STR_LEN]; 00217 00218 retval = PAPI_add_event( EventSet, PAPI_events[i] ); 00219 if ( retval != PAPI_OK ) 00220 CPP_TEST_FAIL( "PAPI_add_event", retval ); 00221 PAPI_event_code_to_name( PAPI_events[i], out ); 00222 if ( !TESTS_QUIET ) 00223 printf( "Added %s\n", out ); 00224 } 00225 00226 retval = PAPI_set_multiplex( EventSet ); 00227 if ( retval == PAPI_ENOSUPP) { 00228 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1); 00229 } else if ( retval != PAPI_OK ) 00230 CPP_TEST_FAIL( "PAPI_set_multiplex", retval ); 00231 00232 do_stuff( ); 00233 00234 if ( PAPI_start( EventSet ) != PAPI_OK ) 00235 CPP_TEST_FAIL( "PAPI_start", retval ); 00236 00237 do_stuff( ); 00238 00239 retval = PAPI_stop( EventSet, values ); 00240 if ( retval != PAPI_OK ) 00241 CPP_TEST_FAIL( "PAPI_stop", retval ); 00242 00243 if ( !TESTS_QUIET ) { 00244 test_print_event_header( "case3:", EventSet ); 00245 printf( TAB2, "case3:", values[0], values[1] ); 00246 } 00247 00248 retval = PAPI_cleanup_eventset( EventSet ); /* JT */ 00249 if ( retval != PAPI_OK ) 00250 CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval ); 00251 00252 PAPI_shutdown( ); 00253 return ( SUCCESS ); 00254 } 00255 00256 /* Tests that PAPI_set_multiplex() works before adding events */ 00257 00258 /* Tests that PAPI_add_event() works after 00259 PAPI_add_event()/PAPI_set_multiplex() */ 00260 00261 int 00262 case4( ) 00263 { 00264 int retval, i, EventSet = PAPI_NULL; 00265 long long values[4]; 00266 char out[PAPI_MAX_STR_LEN]; 00267 00268 PAPI_events_len = 2; 00269 init_papi( PAPI_events, &PAPI_events_len ); 00270 00271 retval = PAPI_create_eventset( &EventSet ); 00272 if ( retval != PAPI_OK ) 00273 CPP_TEST_FAIL( "PAPI_create_eventset", retval ); 00274 00275 i = 0; 00276 retval = PAPI_add_event( EventSet, PAPI_events[i] ); 00277 if ( retval != PAPI_OK ) 00278 CPP_TEST_FAIL( "PAPI_add_event", retval ); 00279 PAPI_event_code_to_name( PAPI_events[i], out ); 00280 printf( "Added %s\n", out ); 00281 00282 retval = PAPI_set_multiplex( EventSet ); 00283 if ( retval == PAPI_ENOSUPP) { 00284 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1); 00285 } 00286 else if ( retval != PAPI_OK ) 00287 CPP_TEST_FAIL( "PAPI_set_multiplex", retval ); 00288 00289 i = 1; 00290 retval = PAPI_add_event( EventSet, PAPI_events[i] ); 00291 if ( retval != PAPI_OK ) 00292 CPP_TEST_FAIL( "PAPI_add_event", retval ); 00293 PAPI_event_code_to_name( PAPI_events[i], out ); 00294 printf( "Added %s\n", out ); 00295 00296 do_stuff( ); 00297 00298 if ( PAPI_start( EventSet ) != PAPI_OK ) 00299 CPP_TEST_FAIL( "PAPI_start", retval ); 00300 00301 do_stuff( ); 00302 00303 retval = PAPI_stop( EventSet, values ); 00304 if ( retval != PAPI_OK ) 00305 CPP_TEST_FAIL( "PAPI_stop", retval ); 00306 00307 if ( !TESTS_QUIET ) { 00308 test_print_event_header( "case4:", EventSet ); 00309 printf( TAB2, "case4:", values[0], values[1] ); 00310 } 00311 00312 retval = PAPI_cleanup_eventset( EventSet ); /* JT */ 00313 if ( retval != PAPI_OK ) 00314 CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval ); 00315 00316 PAPI_shutdown( ); 00317 return ( SUCCESS ); 00318 } 00319 00320 /* Tests that PAPI_read() works immediately after 00321 PAPI_start() */ 00322 00323 int 00324 case5( ) 00325 { 00326 int retval, i, j, EventSet = PAPI_NULL; 00327 long long start_values[4] = { 0,0,0,0 }, values[4] = {0,0,0,0}; 00328 char out[PAPI_MAX_STR_LEN]; 00329 00330 PAPI_events_len = 2; 00331 init_papi( PAPI_events, &PAPI_events_len ); 00332 00333 retval = PAPI_create_eventset( &EventSet ); 00334 if ( retval != PAPI_OK ) 00335 CPP_TEST_FAIL( "PAPI_create_eventset", retval ); 00336 00337 /* In Component PAPI, EventSets must be assigned a component index 00338 before you can fiddle with their internals. 00339 0 is always the cpu component */ 00340 00341 retval = PAPI_assign_eventset_component( EventSet, 0 ); 00342 if ( retval != PAPI_OK ) 00343 CPP_TEST_FAIL( "PAPI_assign_eventset_component", retval ); 00344 00345 retval = PAPI_set_multiplex( EventSet ); 00346 if ( retval == PAPI_ENOSUPP) { 00347 test_skip(__FILE__, __LINE__, "Multiplex not supported", 1); 00348 } 00349 else if ( retval != PAPI_OK ) 00350 CPP_TEST_FAIL( "PAPI_set_multiplex", retval ); 00351 00352 /* Add 2 events... */ 00353 00354 i = 0; 00355 retval = PAPI_add_event( EventSet, PAPI_events[i] ); 00356 if ( retval != PAPI_OK ) 00357 CPP_TEST_FAIL( "PAPI_add_event", retval ); 00358 PAPI_event_code_to_name( PAPI_events[i], out ); 00359 printf( "Added %s\n", out ); 00360 i++; 00361 retval = PAPI_add_event( EventSet, PAPI_events[i] ); 00362 if ( retval != PAPI_OK ) 00363 CPP_TEST_FAIL( "PAPI_add_event", retval ); 00364 PAPI_event_code_to_name( PAPI_events[i], out ); 00365 printf( "Added %s\n", out ); 00366 i++; 00367 00368 do_stuff( ); 00369 00370 retval = PAPI_start( EventSet ); 00371 if ( retval != PAPI_OK ) 00372 CPP_TEST_FAIL( "PAPI_start", retval ); 00373 00374 retval = PAPI_read( EventSet, start_values ); 00375 if ( retval != PAPI_OK ) 00376 CPP_TEST_FAIL( "PAPI_read", retval ); 00377 00378 do_stuff( ); 00379 00380 retval = PAPI_stop( EventSet, values ); 00381 if ( retval != PAPI_OK ) 00382 CPP_TEST_FAIL( "PAPI_stop", retval ); 00383 00384 for (j=0;j<i;j++) 00385 { 00386 printf("read @start counter[%d]: %lld\n", j, start_values[j]); 00387 printf("read @stop counter[%d]: %lld\n", j, values[j]); 00388 printf("difference counter[%d]: %lld\n ", j, values[j]-start_values[j]); 00389 if (values[j]-start_values[j] < 0LL) 00390 CPP_TEST_FAIL( "Difference in start and stop resulted in negative value!", 0 ); 00391 } 00392 00393 retval = PAPI_cleanup_eventset( EventSet ); /* JT */ 00394 if ( retval != PAPI_OK ) 00395 CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval ); 00396 00397 PAPI_shutdown( ); 00398 return ( SUCCESS ); 00399 } 00400 00401 int 00402 main( int argc, char **argv ) 00403 { 00404 00405 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00406 00407 printf 00408 ( "case1: Does PAPI_multiplex_init() not break regular operation?\n" ); 00409 case1( ); 00410 00411 printf( "\ncase2: Does setmpx/add work?\n" ); 00412 case2( ); 00413 00414 printf( "\ncase3: Does add/setmpx work?\n" ); 00415 case3( ); 00416 00417 printf( "\ncase4: Does add/setmpx/add work?\n" ); 00418 case4( ); 00419 00420 printf( "\ncase5: Does setmpx/add/add/start/read work?\n" ); 00421 case5( ); 00422 00423 test_pass( __FILE__, NULL, 0 ); 00424 exit( 0 ); 00425 }