|
PAPI
5.0.1.0
|
00001 /* 00002 * File: tenth.c 00003 * Mods: Maynard Johnson 00004 * maynardj@us.ibm.com 00005 */ 00006 #define ITERS 100 00007 00008 /* This file performs the following test: start, stop and timer functionality for 00009 PAPI_L1_TCM derived event 00010 00011 - They are counted in the default counting domain and default 00012 granularity, depending on the platform. Usually this is 00013 the user domain (PAPI_DOM_USER) and thread context (PAPI_GRN_THR). 00014 - Get us. 00015 - Start counters 00016 - Do flops 00017 - Stop and read counters 00018 - Get us. 00019 */ 00020 00021 00022 #if defined(sun) && defined(sparc) 00023 #define CACHE_LEVEL "PAPI_L2_TCM" 00024 #define EVT1 PAPI_L2_TCM 00025 #define EVT2 PAPI_L2_TCA 00026 #define EVT3 PAPI_L2_TCH 00027 #define EVT1_STR "PAPI_L2_TCM: " 00028 #define EVT2_STR "PAPI_L2_TCA: " 00029 #define EVT3_STR "PAPI_L2_TCH: " 00030 #define MASK1 MASK_L2_TCM 00031 #define MASK2 MASK_L2_TCA 00032 #define MASK3 MASK_L2_TCH 00033 #else 00034 #if defined(__powerpc__) 00035 #define CACHE_LEVEL "PAPI_L1_DCA" 00036 #define EVT1 PAPI_L1_DCA 00037 #define EVT2 PAPI_L1_DCW 00038 #define EVT3 PAPI_L1_DCR 00039 #define EVT1_STR "PAPI_L1_DCA: " 00040 #define EVT2_STR "PAPI_L1_DCW: " 00041 #define EVT3_STR "PAPI_L1_DCR: " 00042 #define MASK1 MASK_L1_DCA 00043 #define MASK2 MASK_L1_DCW 00044 #define MASK3 MASK_L1_DCR 00045 #else 00046 #define CACHE_LEVEL "PAPI_L1_TCM" 00047 #define EVT1 PAPI_L1_TCM 00048 #define EVT2 PAPI_L1_ICM 00049 #define EVT3 PAPI_L1_DCM 00050 #define EVT1_STR "PAPI_L1_TCM: " 00051 #define EVT2_STR "PAPI_L1_ICM: " 00052 #define EVT3_STR "PAPI_L1_DCM: " 00053 #define MASK1 MASK_L1_TCM 00054 #define MASK2 MASK_L1_ICM 00055 #define MASK3 MASK_L1_DCM 00056 #endif 00057 #endif 00058 00059 #include "papi_test.h" 00060 00061 extern int TESTS_QUIET; /* Declared in test_utils.c */ 00062 00063 int 00064 main( int argc, char **argv ) 00065 { 00066 int retval, num_tests = 30, tmp; 00067 int EventSet1 = PAPI_NULL; 00068 int EventSet2 = PAPI_NULL; 00069 int EventSet3 = PAPI_NULL; 00070 int mask1 = MASK1; 00071 int mask2 = MASK2; 00072 int mask3 = MASK3; 00073 int num_events1; 00074 int num_events2; 00075 int num_events3; 00076 long long **values; 00077 int i, j; 00078 long long min[3]; 00079 long long max[3]; 00080 long long sum[3]; 00081 00082 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00083 00084 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00085 if ( retval != PAPI_VER_CURRENT ) 00086 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00087 00088 /* Make sure that required resources are available */ 00089 /* Skip (don't fail!) if they are not */ 00090 retval = PAPI_query_event( EVT1 ); 00091 if ( retval != PAPI_OK ) 00092 test_skip( __FILE__, __LINE__, EVT1_STR, retval ); 00093 00094 retval = PAPI_query_event( EVT2 ); 00095 if ( retval != PAPI_OK ) 00096 test_skip( __FILE__, __LINE__, EVT2_STR, retval ); 00097 00098 retval = PAPI_query_event( EVT3 ); 00099 if ( retval != PAPI_OK ) 00100 test_skip( __FILE__, __LINE__, EVT3_STR, retval ); 00101 00102 00103 EventSet1 = add_test_events( &num_events1, &mask1, 1 ); 00104 EventSet2 = add_test_events( &num_events2, &mask2, 1 ); 00105 EventSet3 = add_test_events( &num_events3, &mask3, 1 ); 00106 00107 values = allocate_test_space( num_tests, 1 ); 00108 00109 /* Warm me up */ 00110 do_l1misses( ITERS ); 00111 do_misses( 1, 1024 * 1024 * 4 ); 00112 00113 for ( i = 0; i < 10; i++ ) { 00114 retval = PAPI_start( EventSet1 ); 00115 if ( retval != PAPI_OK ) 00116 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00117 00118 do_l1misses( ITERS ); 00119 do_misses( 1, 1024 * 1024 * 4 ); 00120 00121 retval = PAPI_stop( EventSet1, values[( i * 3 ) + 0] ); 00122 if ( retval != PAPI_OK ) 00123 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00124 00125 retval = PAPI_start( EventSet2 ); 00126 if ( retval != PAPI_OK ) 00127 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00128 00129 do_l1misses( ITERS ); 00130 do_misses( 1, 1024 * 1024 * 4 ); 00131 00132 retval = PAPI_stop( EventSet2, values[( i * 3 ) + 1] ); 00133 if ( retval != PAPI_OK ) 00134 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00135 00136 retval = PAPI_start( EventSet3 ); 00137 if ( retval != PAPI_OK ) 00138 test_fail( __FILE__, __LINE__, "PAPI_start", retval ); 00139 00140 do_l1misses( ITERS ); 00141 do_misses( 1, 1024 * 1024 * 4 ); 00142 00143 retval = PAPI_stop( EventSet3, values[( i * 3 ) + 2] ); 00144 if ( retval != PAPI_OK ) 00145 test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); 00146 } 00147 00148 remove_test_events( &EventSet1, mask1 ); 00149 remove_test_events( &EventSet2, mask2 ); 00150 remove_test_events( &EventSet3, mask3 ); 00151 00152 for ( j = 0; j < 3; j++ ) { 00153 min[j] = 65535; 00154 max[j] = sum[j] = 0; 00155 } 00156 for ( i = 0; i < 10; i++ ) { 00157 for ( j = 0; j < 3; j++ ) { 00158 if ( min[j] > values[( i * 3 ) + j][0] ) 00159 min[j] = values[( i * 3 ) + j][0]; 00160 if ( max[j] < values[( i * 3 ) + j][0] ) 00161 max[j] = values[( i * 3 ) + j][0]; 00162 sum[j] += values[( i * 3 ) + j][0]; 00163 } 00164 } 00165 00166 if ( !TESTS_QUIET ) { 00167 printf( "Test case 10: start, stop for derived event %s.\n", 00168 CACHE_LEVEL ); 00169 printf( "--------------------------------------------------------\n" ); 00170 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL ); 00171 printf( "Default domain is: %d (%s)\n", tmp, 00172 stringify_all_domains( tmp ) ); 00173 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL ); 00174 printf( "Default granularity is: %d (%s)\n", tmp, 00175 stringify_granularity( tmp ) ); 00176 printf( "Using %d iterations of c += a*b\n", ITERS ); 00177 printf( "Repeated 10 times\n" ); 00178 printf 00179 ( "-------------------------------------------------------------------------\n" ); 00180 /* 00181 for (i=0;i<10;i++) { 00182 printf("Test type : %12s%13s%13s\n", "1", "2", "3"); 00183 printf(TAB3, EVT1_STR, values[(i*3)+0][0], (long long)0, (long long)0); 00184 printf(TAB3, EVT2_STR, (long long)0, values[(i*3)+1][0], (long long)0); 00185 printf(TAB3, EVT3_STR, (long long)0, (long long)0, values[(i*3)+2][0]); 00186 printf 00187 ("-------------------------------------------------------------------------\n"); 00188 } 00189 */ 00190 printf( "Test type : %12s%13s%13s\n", "min", "max", "sum" ); 00191 printf( TAB3, EVT1_STR, min[0], max[0], sum[0] ); 00192 printf( TAB3, EVT2_STR, min[1], max[1], sum[1] ); 00193 printf( TAB3, EVT3_STR, min[2], max[2], sum[2] ); 00194 printf 00195 ( "-------------------------------------------------------------------------\n" ); 00196 printf( "Verification:\n" ); 00197 #if defined(sun) && defined(sparc) 00198 printf( TAB1, "Sum 1 approximately equals sum 2 - sum 3 or", 00199 ( sum[1] - sum[2] ) ); 00200 #else 00201 printf( TAB1, "Sum 1 approximately equals sum 2 + sum 3 or", 00202 ( sum[1] + sum[2] ) ); 00203 #endif 00204 } 00205 00206 { 00207 long long tmin, tmax; 00208 00209 #if defined(sun) && defined(sparc) 00210 tmax = ( long long ) ( sum[1] - sum[2] ); 00211 #else 00212 tmax = ( long long ) ( sum[1] + sum[2] ); 00213 #endif 00214 00215 printf( "percent error: %f\n", 00216 ( float ) ( abs( ( int ) ( tmax - sum[0] ) ) * 100 / sum[0] ) ); 00217 tmin = ( long long ) ( ( double ) tmax * 0.8 ); 00218 tmax = ( long long ) ( ( double ) tmax * 1.2 ); 00219 if ( sum[0] > tmax || sum[0] < tmin ) 00220 test_fail( __FILE__, __LINE__, CACHE_LEVEL, 1 ); 00221 } 00222 test_pass( __FILE__, values, num_tests ); 00223 exit( 1 ); 00224 }