PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rapl_basic.c File Reference
Include dependency graph for rapl_basic.c:

Go to the source code of this file.

Macros

#define MAX_RAPL_EVENTS   64
 Tests basic functionality of RAPL component. More...
 
#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]
 

Macro Definition Documentation

#define MATRIX_SIZE   1024

Definition at line 39 of file rapl_basic.c.

#define MAX_RAPL_EVENTS   64
Author
Vince Weaver

test case for RAPL component

Definition at line 22 of file rapl_basic.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 84 of file rapl_basic.c.

85 {
86 
87  int retval,cid,rapl_cid=-1,numcmp;
88  int EventSet = PAPI_NULL;
89  long long *values;
90  int num_events=0;
91  int code;
92  char event_names[MAX_RAPL_EVENTS][PAPI_MAX_STR_LEN];
95  int r,i;
96  const PAPI_component_info_t *cmpinfo = NULL;
97  PAPI_event_info_t evinfo;
98  long long before_time,after_time;
99  double elapsed_time;
100 
101 #ifdef WRAP_TEST
102 
103  int do_wrap=0;
104 
105  if ( argc > 1 ) {
106  if ( strstr( argv[1], "-w" ) ) {
107  do_wrap = 1;
108  }
109  }
110 
111 #endif
112 
113  /* Set TESTS_QUIET variable */
114  tests_quiet( argc, argv );
115 
116  /* PAPI Initialization */
118  if ( retval != PAPI_VER_CURRENT ) {
119  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
120  }
121 
122  if (!TESTS_QUIET) {
123  printf("Trying all RAPL events\n");
124  }
125 
126  numcmp = PAPI_num_components();
127 
128  for(cid=0; cid<numcmp; cid++) {
129 
130  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
131  test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
132  }
133 
134  if (strstr(cmpinfo->name,"rapl")) {
135 
136  rapl_cid=cid;
137 
138  if (!TESTS_QUIET) {
139  printf("Found rapl component at cid %d\n",rapl_cid);
140  }
141 
142  if (cmpinfo->disabled) {
143  if (!TESTS_QUIET) {
144  printf("RAPL component disabled: %s\n",
145  cmpinfo->disabled_reason);
146  }
147  test_skip(__FILE__,__LINE__,"RAPL component disabled",0);
148  }
149  break;
150  }
151  }
152 
153  /* Component not found */
154  if (cid==numcmp) {
155  test_skip(__FILE__,__LINE__,"No rapl component found\n",0);
156  }
157 
158  /* Create EventSet */
159  retval = PAPI_create_eventset( &EventSet );
160  if (retval != PAPI_OK) {
161  test_fail(__FILE__, __LINE__,
162  "PAPI_create_eventset()",retval);
163  }
164 
165  /* Add all events */
166 
167  code = PAPI_NATIVE_MASK;
168 
169  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, rapl_cid );
170 
171  while ( r == PAPI_OK ) {
172 
173  retval = PAPI_event_code_to_name( code, event_names[num_events] );
174  if ( retval != PAPI_OK ) {
175  printf("Error translating %#x\n",code);
176  test_fail( __FILE__, __LINE__,
177  "PAPI_event_code_to_name", retval );
178  }
179 
180  retval = PAPI_get_event_info(code,&evinfo);
181  if (retval != PAPI_OK) {
182  test_fail( __FILE__, __LINE__,
183  "Error getting event info\n",retval);
184  }
185 
186  strncpy(units[num_events],evinfo.units,sizeof(units[0])-1);
187  // buffer must be null terminated to safely use strstr operation on it below
188  units[num_events][sizeof(units[0])-1] = '\0';
189 
190  data_type[num_events] = evinfo.data_type;
191 
192  retval = PAPI_add_event( EventSet, code );
193  if (retval != PAPI_OK) {
194  break; /* We've hit an event limit */
195  }
196  num_events++;
197 
198  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, rapl_cid );
199  }
200 
201  values=calloc(num_events,sizeof(long long));
202  if (values==NULL) {
203  test_fail(__FILE__, __LINE__,
204  "No memory",retval);
205  }
206 
207  if (!TESTS_QUIET) {
208  printf("\nStarting measurements...\n\n");
209  }
210 
211  /* Start Counting */
212  before_time=PAPI_get_real_nsec();
213  retval = PAPI_start( EventSet);
214  if (retval != PAPI_OK) {
215  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
216  }
217 
218  /* Run test */
220 
221  /* Stop Counting */
222  after_time=PAPI_get_real_nsec();
223  retval = PAPI_stop( EventSet, values);
224  if (retval != PAPI_OK) {
225  test_fail(__FILE__, __LINE__, "PAPI_stop()",retval);
226  }
227 
228  elapsed_time=((double)(after_time-before_time))/1.0e9;
229 
230  if (!TESTS_QUIET) {
231  printf("\nStopping measurements, took %.3fs, gathering results...\n\n",
232  elapsed_time);
233 
234  printf("Scaled energy measurements:\n");
235 
236  for(i=0;i<num_events;i++) {
237  if (strstr(units[i],"nJ")) {
238 
239  printf("%-40s%12.6f J\t(Average Power %.1fW)\n",
240  event_names[i],
241  (double)values[i]/1.0e9,
242  ((double)values[i]/1.0e9)/elapsed_time);
243  }
244  }
245 
246  printf("\n");
247  printf("Energy measurement counts:\n");
248 
249  for(i=0;i<num_events;i++) {
250  if (strstr(event_names[i],"ENERGY_CNT")) {
251  printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
252  }
253  }
254 
255  printf("\n");
256  printf("Scaled Fixed values:\n");
257 
258  for(i=0;i<num_events;i++) {
259  if (!strstr(event_names[i],"ENERGY")) {
260  if (data_type[i] == PAPI_DATATYPE_FP64) {
261 
262  union {
263  long long ll;
264  double fp;
265  } result;
266 
267  result.ll=values[i];
268  printf("%-40s%12.3f %s\n", event_names[i], result.fp, units[i]);
269  }
270  }
271  }
272 
273  printf("\n");
274  printf("Fixed value counts:\n");
275 
276  for(i=0;i<num_events;i++) {
277  if (!strstr(event_names[i],"ENERGY")) {
278  if (data_type[i] == PAPI_DATATYPE_UINT64) {
279  printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
280  }
281  }
282  }
283 
284  }
285 
286 #ifdef WRAP_TEST
287  double max_time;
288  unsigned long long max_value = 0;
289  int repeat;
290 
291  for(i=0;i<num_events;i++) {
292  if (strstr(event_names[i],"ENERGY_CNT")) {
293  if (max_value < (unsigned) values[i]) {
294  max_value = values[i];
295  }
296  }
297  }
298  max_time = elapsed_time * ( (double)0xffffffff / (double)max_value );
299  printf("\n");
300  printf ("Approximate time to energy measurement wraparound: %.3f sec or %.3f min.\n",
301  max_time, max_time/60);
302 
303  if (do_wrap) {
304  printf ("Beginning wraparound execution.");
305  /* Start Counting */
306  before_time=PAPI_get_real_nsec();
307  retval = PAPI_start( EventSet);
308  if (retval != PAPI_OK) {
309  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
310  }
311 
312  /* Run test */
313  repeat = (int)(max_time/elapsed_time);
314  for (i=0;i< repeat;i++) {
315  run_test(1);
316  printf("."); fflush(stdout);
317  }
318  printf("\n");
319 
320  /* Stop Counting */
321  after_time=PAPI_get_real_nsec();
322  retval = PAPI_stop( EventSet, values);
323  if (retval != PAPI_OK) {
324  test_fail(__FILE__, __LINE__, "PAPI_stop()",retval);
325  }
326 
327  elapsed_time=((double)(after_time-before_time))/1.0e9;
328  printf("\nStopping measurements, took %.3fs\n\n", elapsed_time);
329 
330  printf("Scaled energy measurements:\n");
331 
332  for(i=0;i<num_events;i++) {
333  if (strstr(units[i],"nJ")) {
334 
335  printf("%-40s%12.6f J\t(Average Power %.1fW)\n",
336  event_names[i],
337  (double)values[i]/1.0e9,
338  ((double)values[i]/1.0e9)/elapsed_time);
339  }
340  }
341  printf("\n");
342  printf("Energy measurement counts:\n");
343 
344  for(i=0;i<num_events;i++) {
345  if (strstr(event_names[i],"ENERGY_CNT")) {
346  printf("%-40s%12lld\t%#08llx\n", event_names[i], values[i], values[i]);
347  }
348  }
349  }
350 
351 #endif
352 
353  /* Done, clean up */
354  retval = PAPI_cleanup_eventset( EventSet );
355  if (retval != PAPI_OK) {
356  test_fail(__FILE__, __LINE__,
357  "PAPI_cleanup_eventset()",retval);
358  }
359 
360  retval = PAPI_destroy_eventset( &EventSet );
361  if (retval != PAPI_OK) {
362  test_fail(__FILE__, __LINE__,
363  "PAPI_destroy_eventset()",retval);
364  }
365 
366  test_pass( __FILE__ );
367 
368  return 0;
369 }
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:629
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
#define PAPI_NATIVE_MASK
double f(double a)
Definition: cpi.c:23
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:796
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
#define PAPI_NULL
Definition: papi.h:292
static int num_events
int PAPI_num_components(void)
Definition: papi.c:4387
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
char units[MAX_EVENTS][BUFSIZ]
Definition: powercap_plot.c:15
fflush(stdout)
static FILE * fp
static double
Definition: fileop.c:1281
int int argc
Definition: iozone.c:1609
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:835
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:636
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
void run_test(int quiet)
Definition: libmsr_basic.c:43
#define min(x, y)
Definition: darwin-common.h:4
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1357
#define MAX_RAPL_EVENTS
Tests basic functionality of RAPL component.
Definition: rapl_basic.c:22
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int
Definition: iozone.c:18528
#define PAPI_MIN_STR_LEN
Definition: papi.h:464
long long PAPI_get_real_nsec(void)
Definition: papi.c:6237
int data_type[MAX_EVENTS]
Definition: powercap_plot.c:16
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:975
if(gettimeofday(&tp,(struct timezone *) NULL)==-1) perror("gettimeofday")

Here is the call graph for this function:

void run_test ( int  quiet)

Definition at line 46 of file rapl_basic.c.

46  {
47 
48  double s;
49  int i,j,k;
50 
51  if (!quiet) {
52  printf("Doing a naive %dx%d MMM...\n",MATRIX_SIZE,MATRIX_SIZE);
53  }
54 
55  for(i=0;i<MATRIX_SIZE;i++) {
56  for(j=0;j<MATRIX_SIZE;j++) {
57  a[i][j]=(double)i*(double)j;
58  b[i][j]=(double)i/(double)(j+5);
59  }
60  }
61 
62  for(j=0;j<MATRIX_SIZE;j++) {
63  for(i=0;i<MATRIX_SIZE;i++) {
64  s=0;
65  for(k=0;k<MATRIX_SIZE;k++) {
66  s+=a[i][k]*b[k][j];
67  }
68  c[i][j] = s;
69  }
70  }
71 
72  s=0.0;
73  for(i=0;i<MATRIX_SIZE;i++) {
74  for(j=0;j<MATRIX_SIZE;j++) {
75  s+=c[i][j];
76  }
77  }
78 
79  if (!quiet) printf("Matrix multiply sum: s=%lf\n",s);
80 }
static double
Definition: fileop.c:1281
static double c[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:40
int i
Definition: fileop.c:140
int quiet
Definition: rapl_overflow.c:18
int k
Definition: iozone.c:19136
s
Definition: iozone.c:20289
#define MATRIX_SIZE
Definition: rapl_basic.c:39
printf("\tTry: -i 0 -i 1 \n\n")
long j
Definition: iozone.c:19135
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38

Here is the call graph for this function:

Variable Documentation

Definition at line 41 of file rapl_basic.c.

Definition at line 42 of file rapl_basic.c.

Definition at line 43 of file rapl_basic.c.