PAPI  5.4.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 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.

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

Here is the call graph for this function:

void run_test ( int  quiet)

Definition at line 42 of file rapl_basic.c.

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

Here is the caller graph for this function:

Variable Documentation

Definition at line 37 of file rapl_basic.c.

Definition at line 38 of file rapl_basic.c.

Definition at line 39 of file rapl_basic.c.