rapl_basic.c File Reference

Include dependency graph for rapl_basic.c:

Go to the source code of this file.

Defines

#define MAX_RAPL_EVENTS   64
 Tests basic functionality of RAPL component.
#define MATRIX_SIZE   1024

Functions

void run_test (int quiet)
int main (int argc, char **argv)

Variables

static double a [MATRIX_SIZE][MATRIX_SIZE]
static double b [MATRIX_SIZE][MATRIX_SIZE]
static double c [MATRIX_SIZE][MATRIX_SIZE]

Define Documentation

#define MATRIX_SIZE   1024

Definition at line 35 of file rapl_basic.c.

#define MAX_RAPL_EVENTS   64
Author:
Vince Weaver

test case for RAPL component

Definition at line 18 of file rapl_basic.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 80 of file rapl_basic.c.

00081 {
00082 
00083     int retval,cid,rapl_cid=-1,numcmp;
00084     int EventSet = PAPI_NULL;
00085     long long *values;
00086     int num_events=0;
00087     int code;
00088     char event_names[MAX_RAPL_EVENTS][PAPI_MAX_STR_LEN];
00089     char units[MAX_RAPL_EVENTS][PAPI_MIN_STR_LEN];
00090     int data_type[MAX_RAPL_EVENTS];
00091     int r,i, do_wrap = 0;
00092     const PAPI_component_info_t *cmpinfo = NULL;
00093     PAPI_event_info_t evinfo;
00094     long long before_time,after_time;
00095     double elapsed_time;
00096 
00097         /* Set TESTS_QUIET variable */
00098      tests_quiet( argc, argv );
00099      if ( argc > 1 )
00100         if ( strstr( argv[1], "-w" ) )
00101             do_wrap = 1;
00102 
00103     /* PAPI Initialization */
00104      retval = PAPI_library_init( PAPI_VER_CURRENT );
00105      if ( retval != PAPI_VER_CURRENT ) {
00106     test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
00107      }
00108 
00109      if (!TESTS_QUIET) {
00110         printf("Trying all RAPL events\n");
00111      }
00112 
00113      numcmp = PAPI_num_components();
00114 
00115      for(cid=0; cid<numcmp; cid++) {
00116 
00117     if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
00118        test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
00119     }
00120 
00121     if (strstr(cmpinfo->name,"rapl")) {
00122 
00123        rapl_cid=cid;
00124 
00125        if (!TESTS_QUIET) {
00126           printf("Found rapl component at cid %d\n",rapl_cid);
00127        }
00128 
00129            if (cmpinfo->disabled) {
00130           if (!TESTS_QUIET) {
00131          printf("RAPL component disabled: %s\n",
00132                         cmpinfo->disabled_reason);
00133           } 
00134               test_skip(__FILE__,__LINE__,"RAPL component disabled",0);
00135            }
00136        break;
00137     }
00138      }
00139 
00140      /* Component not found */
00141      if (cid==numcmp) {
00142        test_skip(__FILE__,__LINE__,"No rapl component found\n",0);
00143      }
00144 
00145      /* Create EventSet */
00146      retval = PAPI_create_eventset( &EventSet );
00147      if (retval != PAPI_OK) {
00148     test_fail(__FILE__, __LINE__, 
00149                               "PAPI_create_eventset()",retval);
00150      }
00151 
00152      /* Add all events */
00153 
00154      code = PAPI_NATIVE_MASK;
00155 
00156      r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, rapl_cid );
00157 
00158      while ( r == PAPI_OK ) {
00159 
00160         retval = PAPI_event_code_to_name( code, event_names[num_events] );
00161     if ( retval != PAPI_OK ) {
00162        printf("Error translating %#x\n",code);
00163        test_fail( __FILE__, __LINE__, 
00164                             "PAPI_event_code_to_name", retval );
00165     }
00166 
00167     retval = PAPI_get_event_info(code,&evinfo);
00168     if (retval != PAPI_OK) {
00169       test_fail( __FILE__, __LINE__,
00170              "Error getting event info\n",retval);
00171     }
00172 
00173     strncpy(units[num_events],evinfo.units,sizeof(units[0])-1);
00174     // buffer must be null terminated to safely use strstr operation on it below
00175     units[num_events][sizeof(units[0])-1] = '\0';
00176 
00177     data_type[num_events] = evinfo.data_type;
00178 
00179         retval = PAPI_add_event( EventSet, code );
00180         if (retval != PAPI_OK) {
00181       break; /* We've hit an event limit */
00182     }
00183     num_events++;
00184           
00185         r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, rapl_cid );
00186      }
00187 
00188      values=calloc(num_events,sizeof(long long));
00189      if (values==NULL) {
00190     test_fail(__FILE__, __LINE__, 
00191                               "No memory",retval);
00192      }
00193 
00194      if (!TESTS_QUIET) {
00195     printf("\nStarting measurements...\n\n");
00196      }
00197 
00198      /* Start Counting */
00199      before_time=PAPI_get_real_nsec();
00200      retval = PAPI_start( EventSet);
00201      if (retval != PAPI_OK) {
00202     test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
00203      }
00204 
00205      /* Run test */
00206      run_test(TESTS_QUIET);
00207 
00208      /* Stop Counting */
00209      after_time=PAPI_get_real_nsec();
00210      retval = PAPI_stop( EventSet, values);
00211      if (retval != PAPI_OK) {
00212     test_fail(__FILE__, __LINE__, "PAPI_stop()",retval);
00213      }
00214 
00215      elapsed_time=((double)(after_time-before_time))/1.0e9;
00216 
00217      if (!TESTS_QUIET) {
00218         printf("\nStopping measurements, took %.3fs, gathering results...\n\n",
00219            elapsed_time);
00220 
00221         printf("Scaled energy measurements:\n");
00222 
00223         for(i=0;i<num_events;i++) {
00224            if (strstr(units[i],"nJ")) {
00225 
00226               printf("%-40s%12.6f J\t(Average Power %.1fW)\n",
00227                 event_names[i],
00228                 (double)values[i]/1.0e9,
00229                 ((double)values[i]/1.0e9)/elapsed_time);
00230            }
00231         }
00232 
00233         printf("\n");
00234         printf("Energy measurement counts:\n");
00235 
00236         for(i=0;i<num_events;i++) {
00237            if (strstr(event_names[i],"ENERGY_CNT")) {
00238               printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
00239            }
00240         }
00241 
00242         printf("\n");
00243         printf("Scaled Fixed values:\n");
00244 
00245         for(i=0;i<num_events;i++) {
00246            if (!strstr(event_names[i],"ENERGY")) {
00247              if (data_type[i] == PAPI_DATATYPE_FP64) {
00248 
00249                  union {
00250                    long long ll;
00251                    double fp;
00252                  } result;
00253 
00254                 result.ll=values[i];
00255                 printf("%-40s%12.3f %s\n", event_names[i], result.fp, units[i]);
00256               }
00257            }
00258         }
00259     
00260         printf("\n");
00261         printf("Fixed value counts:\n");
00262 
00263         for(i=0;i<num_events;i++) {
00264            if (!strstr(event_names[i],"ENERGY")) {
00265               if (data_type[i] == PAPI_DATATYPE_UINT64) {
00266                 printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
00267               }
00268            }
00269         }
00270 
00271      }
00272 
00273 #ifdef WRAP_TEST
00274     double max_time;
00275     unsigned long long max_value = 0;
00276     int repeat;
00277     
00278     for(i=0;i<num_events;i++) {
00279         if (strstr(event_names[i],"ENERGY_CNT")) {
00280             if (max_value < (unsigned) values[i]) {
00281                 max_value = values[i];
00282             }
00283         }
00284     }
00285     max_time = elapsed_time * (0xffffffff / max_value);
00286     printf("\n");
00287     printf ("Approximate time to energy measurement wraparound: %.3f sec or %.3f min.\n", 
00288         max_time, max_time/60);
00289     
00290     if (do_wrap) {
00291          printf ("Beginning wraparound execution.");
00292          /* Start Counting */
00293          before_time=PAPI_get_real_nsec();
00294          retval = PAPI_start( EventSet);
00295          if (retval != PAPI_OK) {
00296             test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
00297          }
00298 
00299          /* Run test */
00300         repeat = (int)(max_time/elapsed_time);
00301         for (i=0;i< repeat;i++) {
00302             run_test(1);
00303             printf("."); fflush(stdout);
00304         }
00305         printf("\n");
00306      
00307          /* Stop Counting */
00308          after_time=PAPI_get_real_nsec();
00309          retval = PAPI_stop( EventSet, values);
00310          if (retval != PAPI_OK) {
00311             test_fail(__FILE__, __LINE__, "PAPI_stop()",retval);
00312          }
00313 
00314         elapsed_time=((double)(after_time-before_time))/1.0e9;
00315         printf("\nStopping measurements, took %.3fs\n\n", elapsed_time);
00316 
00317         printf("Scaled energy measurements:\n");
00318 
00319         for(i=0;i<num_events;i++) {
00320            if (strstr(units[i],"nJ")) {
00321 
00322               printf("%-40s%12.6f J\t(Average Power %.1fW)\n",
00323                 event_names[i],
00324                 (double)values[i]/1.0e9,
00325                 ((double)values[i]/1.0e9)/elapsed_time);
00326            }
00327         }
00328         printf("\n");
00329         printf("Energy measurement counts:\n");
00330 
00331         for(i=0;i<num_events;i++) {
00332            if (strstr(event_names[i],"ENERGY_CNT")) {
00333               printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
00334            }
00335         }
00336     }
00337 
00338 #endif
00339 
00340      /* Done, clean up */
00341      retval = PAPI_cleanup_eventset( EventSet );
00342      if (retval != PAPI_OK) {
00343     test_fail(__FILE__, __LINE__, 
00344                               "PAPI_cleanup_eventset()",retval);
00345      }
00346 
00347      retval = PAPI_destroy_eventset( &EventSet );
00348      if (retval != PAPI_OK) {
00349     test_fail(__FILE__, __LINE__, 
00350                               "PAPI_destroy_eventset()",retval);
00351      }
00352         
00353      test_pass( __FILE__, NULL, 0 );
00354         
00355      return 0;
00356 }

Here is the call graph for this function:

void run_test ( int  quiet  ) 

Definition at line 42 of file rapl_basic.c.

00042                          {
00043 
00044        double s;
00045        int i,j,k;
00046 
00047        if (!quiet) {
00048             printf("Doing a naive %dx%d MMM...\n",MATRIX_SIZE,MATRIX_SIZE);
00049        }
00050 
00051        for(i=0;i<MATRIX_SIZE;i++) {
00052      for(j=0;j<MATRIX_SIZE;j++) {
00053        a[i][j]=(double)i*(double)j;
00054        b[i][j]=(double)i/(double)(j+5);
00055      }
00056        }
00057 
00058        for(j=0;j<MATRIX_SIZE;j++) {
00059      for(i=0;i<MATRIX_SIZE;i++) {
00060        s=0;
00061        for(k=0;k<MATRIX_SIZE;k++) {
00062          s+=a[i][k]*b[k][j];
00063        }
00064        c[i][j] = s;
00065      }
00066        }
00067 
00068        s=0.0;
00069        for(i=0;i<MATRIX_SIZE;i++) {
00070         for(j=0;j<MATRIX_SIZE;j++) {
00071             s+=c[i][j];
00072         }
00073        }
00074 
00075        if (!quiet) printf("Matrix multiply sum: s=%lf\n",s);
00076 }


Variable Documentation

double a[MATRIX_SIZE][MATRIX_SIZE] [static]

Definition at line 37 of file rapl_basic.c.

double b[MATRIX_SIZE][MATRIX_SIZE] [static]

Definition at line 38 of file rapl_basic.c.

double c[MATRIX_SIZE][MATRIX_SIZE] [static]

Definition at line 39 of file rapl_basic.c.


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1