|
PAPI
5.0.1.0
|
00001 #include <stdio.h> 00002 #include "papi.h" 00003 #include "papi_test.h" 00004 00005 static int total = 0; /* total overflows */ 00006 00007 static long long values[2]; 00008 static long long rapl_values[2]; 00009 static long long old_rapl_values[2] = {0,0}; 00010 static int rapl_backward=0; 00011 00012 int EventSet2=PAPI_NULL; 00013 00014 int quiet=0; 00015 00016 void handler( int EventSet, void *address, 00017 long long overflow_vector, void *context ) { 00018 00019 ( void ) context; 00020 ( void ) address; 00021 ( void ) overflow_vector; 00022 00023 #if 0 00024 fprintf( stderr, "handler(%d ) Overflow at %p! bit=0x%llx \n", 00025 EventSet, address, overflow_vector ); 00026 #endif 00027 00028 PAPI_read(EventSet,values); 00029 if (!quiet) printf("%lld %lld\t",values[0],values[1]); 00030 PAPI_read(EventSet2,rapl_values); 00031 if (!quiet) printf("RAPL: %lld %lld\n",rapl_values[0],rapl_values[1]); 00032 00033 if ((rapl_values[0]<old_rapl_values[0]) || 00034 (rapl_values[1]<old_rapl_values[1])) { 00035 if (!quiet) printf("RAPL decreased!\n"); 00036 rapl_backward=1; 00037 } 00038 old_rapl_values[0]=rapl_values[0]; 00039 old_rapl_values[1]=rapl_values[1]; 00040 00041 00042 total++; 00043 } 00044 00045 00046 void do_ints(int n,int quiet) 00047 { 00048 int i,c=n; 00049 00050 for(i=0;i<n;i++) { 00051 c+=c*i*n; 00052 } 00053 if (!quiet) printf("%d\n",c); 00054 } 00055 00056 00057 00058 int 00059 main( int argc, char **argv ) 00060 { 00061 int EventSet = PAPI_NULL; 00062 long long values0[2],values1[2],values2[2]; 00063 int num_flops = 3000000, retval; 00064 int mythreshold = 1000000; 00065 char event_name1[PAPI_MAX_STR_LEN]; 00066 int PAPI_event; 00067 int cid,numcmp,rapl_cid; 00068 const PAPI_component_info_t *cmpinfo = NULL; 00069 00070 /* Set TESTS_QUIET variable */ 00071 tests_quiet( argc, argv ); 00072 00073 quiet=TESTS_QUIET; 00074 00075 /* Init PAPI */ 00076 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00077 if ( retval != PAPI_VER_CURRENT ) { 00078 test_fail(__FILE__, __LINE__,"PAPI_library_init",retval); 00079 } 00080 00081 numcmp = PAPI_num_components(); 00082 00083 for(cid=0; cid<numcmp; cid++) { 00084 00085 if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { 00086 test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); 00087 } 00088 00089 if (strstr(cmpinfo->name,"rapl")) { 00090 rapl_cid=cid; 00091 if (!TESTS_QUIET) printf("Found rapl component at cid %d\n", 00092 rapl_cid); 00093 if (cmpinfo->num_native_events==0) { 00094 test_skip(__FILE__,__LINE__,"No rapl events found",0); 00095 } 00096 break; 00097 } 00098 } 00099 00100 /* Component not found */ 00101 if (cid==numcmp) { 00102 test_skip(__FILE__,__LINE__,"No rapl component found\n",0); 00103 } 00104 00105 00106 /* add PAPI_TOT_CYC and PAPI_TOT_INS */ 00107 retval=PAPI_create_eventset(&EventSet); 00108 if ( retval != PAPI_OK ) { 00109 test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval); 00110 } 00111 00112 retval=PAPI_add_event(EventSet,PAPI_TOT_CYC); 00113 if ( retval != PAPI_OK ) { 00114 test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); 00115 } 00116 00117 retval=PAPI_add_event(EventSet,PAPI_TOT_INS); 00118 if ( retval != PAPI_OK ) { 00119 test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); 00120 } 00121 00122 /* Add some RAPL events */ 00123 retval=PAPI_create_eventset(&EventSet2); 00124 if ( retval != PAPI_OK ) { 00125 test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval); 00126 } 00127 00128 retval=PAPI_add_named_event(EventSet2,"rapl:::PACKAGE_ENERGY:PACKAGE0"); 00129 if ( retval != PAPI_OK ) { 00130 test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); 00131 } 00132 00133 retval=PAPI_add_named_event(EventSet2,"rapl:::PACKAGE_ENERGY:PACKAGE1"); 00134 if ( retval != PAPI_OK ) { 00135 test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); 00136 } 00137 00138 PAPI_event=PAPI_TOT_CYC; 00139 00140 /* arbitrary */ 00141 mythreshold = 2000000; 00142 if (!TESTS_QUIET) { 00143 printf("Using %x for the overflow event, threshold %d\n", 00144 PAPI_event,mythreshold); 00145 } 00146 00147 /* Start the run calibration run */ 00148 retval = PAPI_start( EventSet ); 00149 if ( retval != PAPI_OK ) { 00150 test_fail(__FILE__, __LINE__,"PAPI_start",retval); 00151 } 00152 00153 do_ints(num_flops,TESTS_QUIET); 00154 do_flops( 3000000 ); 00155 00156 /* stop the calibration run */ 00157 retval = PAPI_stop( EventSet, values0 ); 00158 if ( retval != PAPI_OK ) { 00159 test_fail(__FILE__, __LINE__,"PAPI_stop",retval); 00160 } 00161 00162 00163 /* set up overflow handler */ 00164 retval = PAPI_overflow( EventSet,PAPI_event,mythreshold, 0, handler ); 00165 if ( retval != PAPI_OK ) { 00166 test_fail(__FILE__, __LINE__,"PAPI_overflow",retval); 00167 } 00168 00169 /* Start overflow run */ 00170 retval = PAPI_start( EventSet ); 00171 if ( retval != PAPI_OK ) { 00172 test_fail(__FILE__, __LINE__,"PAPI_start",retval); 00173 } 00174 retval = PAPI_start( EventSet2 ); 00175 if ( retval != PAPI_OK ) { 00176 test_fail(__FILE__, __LINE__,"PAPI_start",retval); 00177 } 00178 00179 do_ints(num_flops,TESTS_QUIET); 00180 do_flops( num_flops ); 00181 00182 /* stop overflow run */ 00183 retval = PAPI_stop( EventSet, values1 ); 00184 if ( retval != PAPI_OK ) { 00185 test_fail(__FILE__, __LINE__,"PAPI_stop",retval); 00186 } 00187 00188 retval = PAPI_stop( EventSet2, values2 ); 00189 if ( retval != PAPI_OK ) { 00190 test_fail(__FILE__, __LINE__,"PAPI_stop",retval); 00191 } 00192 00193 retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler ); 00194 if ( retval != PAPI_OK ) { 00195 test_fail(__FILE__, __LINE__,"PAPI_overflow",retval); 00196 } 00197 00198 retval = PAPI_event_code_to_name( PAPI_event, event_name1 ); 00199 if (retval != PAPI_OK) { 00200 test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n", retval); 00201 } 00202 00203 if (!TESTS_QUIET) { 00204 printf("%s: %lld %lld\n",event_name1,values0[0],values1[0]); 00205 } 00206 00207 retval = PAPI_event_code_to_name( PAPI_TOT_INS, event_name1 ); 00208 if (retval != PAPI_OK) { 00209 test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n",retval); 00210 } 00211 00212 if (!TESTS_QUIET) { 00213 printf("%s: %lld %lld\n",event_name1,values0[1],values1[1]); 00214 } 00215 00216 retval = PAPI_cleanup_eventset( EventSet ); 00217 if ( retval != PAPI_OK ) { 00218 test_fail(__FILE__, __LINE__,"PAPI_cleanup_eventset",retval); 00219 } 00220 00221 retval = PAPI_destroy_eventset( &EventSet ); 00222 if ( retval != PAPI_OK ) { 00223 test_fail(__FILE__, __LINE__,"PAPI_destroy_eventset",retval); 00224 } 00225 00226 if (rapl_backward) { 00227 test_fail(__FILE__, __LINE__,"RAPL counts went backward!",0); 00228 } 00229 00230 test_pass( __FILE__, NULL, 0 ); 00231 00232 00233 return 0; 00234 }