PAPI  5.3.2.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,PAPI_MIN_STR_LEN);
174  data_type[num_events] = evinfo.data_type;
175 
176  retval = PAPI_add_event( EventSet, code );
177  if (retval != PAPI_OK) {
178  break; /* We've hit an event limit */
179  }
180  num_events++;
181 
182  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, rapl_cid );
183  }
184 
185  values=calloc(num_events,sizeof(long long));
186  if (values==NULL) {
187  test_fail(__FILE__, __LINE__,
188  "No memory",retval);
189  }
190 
191  if (!TESTS_QUIET) {
192  printf("\nStarting measurements...\n\n");
193  }
194 
195  /* Start Counting */
196  before_time=PAPI_get_real_nsec();
197  retval = PAPI_start( EventSet);
198  if (retval != PAPI_OK) {
199  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
200  }
201 
202  /* Run test */
204 
205  /* Stop Counting */
206  after_time=PAPI_get_real_nsec();
207  retval = PAPI_stop( EventSet, values);
208  if (retval != PAPI_OK) {
209  test_fail(__FILE__, __LINE__, "PAPI_stop()",retval);
210  }
211 
212  elapsed_time=((double)(after_time-before_time))/1.0e9;
213 
214  if (!TESTS_QUIET) {
215  printf("\nStopping measurements, took %.3fs, gathering results...\n\n",
216  elapsed_time);
217 
218  printf("Scaled energy measurements:\n");
219 
220  for(i=0;i<num_events;i++) {
221  if (strstr(units[i],"nJ")) {
222 
223  printf("%-40s%12.6f J\t(Average Power %.1fW)\n",
224  event_names[i],
225  (double)values[i]/1.0e9,
226  ((double)values[i]/1.0e9)/elapsed_time);
227  }
228  }
229 
230  printf("\n");
231  printf("Energy measurement counts:\n");
232 
233  for(i=0;i<num_events;i++) {
234  if (strstr(event_names[i],"ENERGY_CNT")) {
235  printf("%-40s%12lld\t%#08x\n", event_names[i], values[i], values[i]);
236  }
237  }
238 
239  printf("\n");
240  printf("Scaled Fixed values:\n");
241 
242  for(i=0;i<num_events;i++) {
243  if (!strstr(event_names[i],"ENERGY")) {
244  if (data_type[i] == PAPI_DATATYPE_FP64) {
245 
246  union {
247  long long ll;
248  double fp;
249  } result;
250 
251  result.ll=values[i];
252  printf("%-40s%12.3f %s\n", event_names[i], result.fp, units[i]);
253  }
254  }
255  }
256 
257  printf("\n");
258  printf("Fixed value counts:\n");
259 
260  for(i=0;i<num_events;i++) {
261  if (!strstr(event_names[i],"ENERGY")) {
262  if (data_type[i] == PAPI_DATATYPE_UINT64) {
263  printf("%-40s%12lld\t%#08x\n", event_names[i], values[i], values[i]);
264  }
265  }
266  }
267 
268  }
269 
270 #ifdef WRAP_TEST
271  double max_time;
272  unsigned long long max_value = 0;
273  int repeat;
274 
275  for(i=0;i<num_events;i++) {
276  if (strstr(event_names[i],"ENERGY_CNT")) {
277  if (max_value < values[i]) {
278  max_value = values[i];
279  }
280  }
281  }
282  max_time = elapsed_time * (0xffffffff / max_value);
283  printf("\n");
284  printf ("Approximate time to energy measurement wraparound: %.3f sec or %.3f min.\n",
285  max_time, max_time/60);
286 
287  if (do_wrap) {
288  printf ("Beginning wraparound execution.");
289  /* Start Counting */
290  before_time=PAPI_get_real_nsec();
291  retval = PAPI_start( EventSet);
292  if (retval != PAPI_OK) {
293  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
294  }
295 
296  /* Run test */
297  repeat = (int)(max_time/elapsed_time);
298  for (i=0;i< repeat;i++) {
299  run_test(1);
300  printf("."); fflush(stdout);
301  }
302  printf("\n");
303 
304  /* Stop Counting */
305  after_time=PAPI_get_real_nsec();
306  retval = PAPI_stop( EventSet, values);
307  if (retval != PAPI_OK) {
308  test_fail(__FILE__, __LINE__, "PAPI_stop()",retval);
309  }
310 
311  elapsed_time=((double)(after_time-before_time))/1.0e9;
312  printf("\nStopping measurements, took %.3fs\n\n", elapsed_time);
313 
314  printf("Scaled energy measurements:\n");
315 
316  for(i=0;i<num_events;i++) {
317  if (strstr(units[i],"nJ")) {
318 
319  printf("%-40s%12.6f J\t(Average Power %.1fW)\n",
320  event_names[i],
321  (double)values[i]/1.0e9,
322  ((double)values[i]/1.0e9)/elapsed_time);
323  }
324  }
325  printf("\n");
326  printf("Energy measurement counts:\n");
327 
328  for(i=0;i<num_events;i++) {
329  if (strstr(event_names[i],"ENERGY_CNT")) {
330  printf("%-40s%12lld\t%#08x\n", event_names[i], values[i], values[i]);
331  }
332  }
333  }
334 
335 #endif
336 
337  /* Done, clean up */
338  retval = PAPI_cleanup_eventset( EventSet );
339  if (retval != PAPI_OK) {
340  test_fail(__FILE__, __LINE__,
341  "PAPI_cleanup_eventset()",retval);
342  }
343 
344  retval = PAPI_destroy_eventset( &EventSet );
345  if (retval != PAPI_OK) {
346  test_fail(__FILE__, __LINE__,
347  "PAPI_destroy_eventset()",retval);
348  }
349 
350  test_pass( __FILE__, NULL, 0 );
351 
352  return 0;
353 }
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define PAPI_NATIVE_MASK
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:805
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_MIN_STR_LEN
Definition: fpapi.h:41
int PAPI_num_components(void)
Definition: papi.c:4285
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:844
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:632
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
static FILE * fp
long long before_time
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1311
#define MAX_RAPL_EVENTS
Tests basic functionality of RAPL component.
Definition: rapl_basic.c:18
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2805
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:924
int EventSet
long long after_time
int
Definition: iozone.c:18528
long long PAPI_get_real_nsec(void)
Definition: papi.c:6111
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1944
int PAPI_start(int EventSet)
Definition: papi.c:2026
double elapsed_time
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
void run_test(int quiet)
Definition: rapl_basic.c:42
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:970

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.