PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test_utils.c
Go to the documentation of this file.
1 #include "papi_test.h"
2 
3 #include <unistd.h>
4 
5 /* Variable to hold reporting status
6  if TRUE, output is suppressed
7  if FALSE output is sent to stdout
8  initialized to FALSE
9  declared here so it can be available globally
10 */
11 int TESTS_QUIET = 0;
12 static int TESTS_COLOR = 0;
13 static int TEST_WARN = 0;
14 
15 /* Support routine to display header information to the screen
16  from the hardware info data structure. The same code was duplicated
17  in a number of tests and utilities. Seems to make sense to refactor.
18  This may not be the best place for it to live, but it works for now.
19  */
20 int
21 papi_print_header( char *prompt, const PAPI_hw_info_t ** hwinfo )
22 {
23  int cnt, mpx;
24 
25  if ( ( *hwinfo = PAPI_get_hardware_info( ) ) == NULL ) {
26  return PAPI_ESYS;
27  }
28 
29  printf( "%s", prompt );
30  printf
31  ( "--------------------------------------------------------------------------------\n" );
32  printf( "PAPI Version : %d.%d.%d.%d\n",
37  printf( "Vendor string and code : %s (%d)\n", ( *hwinfo )->vendor_string,
38  ( *hwinfo )->vendor );
39  printf( "Model string and code : %s (%d)\n", ( *hwinfo )->model_string,
40  ( *hwinfo )->model );
41  printf( "CPU Revision : %f\n", ( *hwinfo )->revision );
42  if ( ( *hwinfo )->cpuid_family > 0 )
43  printf
44  ( "CPUID Info : Family: %d Model: %d Stepping: %d\n",
45  ( *hwinfo )->cpuid_family, ( *hwinfo )->cpuid_model,
46  ( *hwinfo )->cpuid_stepping );
47  printf( "CPU Max Megahertz : %d\n", ( *hwinfo )->cpu_max_mhz );
48  printf( "CPU Min Megahertz : %d\n", ( *hwinfo )->cpu_min_mhz );
49  if ( ( *hwinfo )->threads > 0 )
50  printf( "Hdw Threads per core : %d\n", ( *hwinfo )->threads );
51  if ( ( *hwinfo )->cores > 0 )
52  printf( "Cores per Socket : %d\n", ( *hwinfo )->cores );
53  if ( ( *hwinfo )->sockets > 0 )
54  printf( "Sockets : %d\n", ( *hwinfo )->sockets );
55  if ( ( *hwinfo )->nnodes > 0 )
56  printf( "NUMA Nodes : %d\n", ( *hwinfo )->nnodes );
57  printf( "CPUs per Node : %d\n", ( *hwinfo )->ncpu );
58  printf( "Total CPUs : %d\n", ( *hwinfo )->totalcpus );
59  printf( "Running in a VM : %s\n", ( *hwinfo )->virtualized?
60  "yes":"no");
61  if ( (*hwinfo)->virtualized) {
62  printf( "VM Vendor: : %s\n", (*hwinfo)->virtual_vendor_string);
63  }
64  cnt = PAPI_get_opt( PAPI_MAX_HWCTRS, NULL );
65  mpx = PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL );
66  if ( cnt >= 0 ) {
67  printf( "Number Hardware Counters : %d\n",cnt );
68  } else {
69  printf( "Number Hardware Counters : PAPI error %d: %s\n", cnt, PAPI_strerror(cnt));
70  }
71  if ( mpx >= 0 ) {
72  printf( "Max Multiplex Counters : %d\n", mpx );
73  } else {
74  printf( "Max Multiplex Counters : PAPI error %d: %s\n", mpx, PAPI_strerror(mpx));
75  }
76  printf
77  ( "--------------------------------------------------------------------------------\n" );
78  printf( "\n" );
79  return PAPI_OK;
80 }
81 
82 
83 void
84 validate_string( char *name, char *s )
85 {
86  if ( ( s == NULL ) || ( strlen( s ) == 0 ) ) {
87  char s2[1024] = "";
88  sprintf( s2, "%s was NULL or length 0", name );
89  test_fail( __FILE__, __LINE__, s2, 0 );
90  }
91 }
92 
93 int
94 approx_equals( double a, double b )
95 {
96  if ( ( a >= b * ( 1.0 - TOLERANCE ) ) && ( a <= b * ( 1.0 + TOLERANCE ) ) )
97  return 1;
98  else {
99  printf( "Out of tolerance range %2.2f: %.0f vs %.0f [%.0f,%.0f]\n",
100  TOLERANCE, a, b, b * ( 1.0 - TOLERANCE ),
101  b * ( 1.0 + TOLERANCE ) );
102  return 0;
103  }
104 }
105 
106 long long **
108 {
109  long long **values;
110  int i;
111 
112  values =
113  ( long long ** ) malloc( ( size_t ) num_tests *
114  sizeof ( long long * ) );
115  if ( values == NULL )
116  exit( 1 );
117  memset( values, 0x0, ( size_t ) num_tests * sizeof ( long long * ) );
118 
119  for ( i = 0; i < num_tests; i++ ) {
120  values[i] =
121  ( long long * ) malloc( ( size_t ) num_events *
122  sizeof ( long long ) );
123  if ( values[i] == NULL )
124  exit( 1 );
125  memset( values[i], 0x00, ( size_t ) num_events * sizeof ( long long ) );
126  }
127  return ( values );
128 }
129 
130 void
131 free_test_space( long long **values, int num_tests )
132 {
133  int i;
134 
135  for ( i = 0; i < num_tests; i++ )
136  free( values[i] );
137  free( values );
138 }
139 
140 
141 
142 int is_event_derived(unsigned int event) {
143 
144  PAPI_event_info_t info;
145 
146  if (event & PAPI_PRESET_MASK) {
147 
148  PAPI_get_event_info(event,&info);
149 
150  if (strcmp(info.derived,"NOT_DERIVED")) {
151  // printf("%#x is derived\n",event);
152  return 1;
153  }
154  }
155  return 0;
156 }
157 
158 
160 {
161  /* query and set up the right event to monitor */
162  PAPI_event_info_t info;
163  int potential_evt_to_add[3] = { PAPI_FP_OPS, PAPI_FP_INS, PAPI_TOT_INS };
164  int i;
165 
166  for ( i = 0; i < 3; i++ ) {
167  if ( PAPI_query_event( potential_evt_to_add[i] ) == PAPI_OK ) {
168  if ( PAPI_get_event_info( potential_evt_to_add[i], &info ) ==
169  PAPI_OK ) {
170  if ( ( info.count > 0 ) &&
171  !strcmp( info.derived, "NOT_DERIVED" ) )
172  return ( potential_evt_to_add[i] );
173  }
174  }
175  }
176  return ( 0 );
177 }
178 
179 
180 /* Add events to an EventSet, as specified by a mask.
181 
182  Returns: number = number of events added
183 
184 */
185 
186 //struct test_events_t {
187 // unsigned int mask;
188 // unsigned int event;
189 //};
190 
201  { MASK_BR_CN, PAPI_BR_CN },
209 };
210 
211 
212 int
213 add_test_events( int *number, int *mask, int allow_derived )
214 {
215  int retval,i;
216  int EventSet = PAPI_NULL;
217  int num_counters = 0;
218  char name_string[BUFSIZ];
219 
220  *number = 0;
221 
222  /* get the number of available HW counters */
223  num_counters = PAPI_get_opt( PAPI_MAX_HWCTRS, NULL );
224  if ( num_counters < 1 ) {
225  test_fail( __FILE__, __LINE__, "Zero HW Counters available",
226  num_counters );
227  }
228 
229  /* create the eventset */
230  retval = PAPI_create_eventset( &EventSet );
231  if ( retval != PAPI_OK ) {
232  test_fail( __FILE__, __LINE__, "PAPI_create_eventset",
233  retval );
234  }
235 
236  /* check all the masks */
237  for(i=0;i<MAX_TEST_EVENTS;i++) {
238 
239  if ( *mask & test_events[i].mask ) {
240 
241  /* remove any derived events if told to */
242  if ((is_event_derived(test_events[i].event)) && (!allow_derived)) {
243  *mask = *mask ^ test_events[i].mask;
244  continue;
245  }
246 
247  retval = PAPI_add_event( EventSet, test_events[i].event );
248 
249  if ( retval == PAPI_OK ) {
250 
251  ( *number )++;
252 #if 0
253  if ((*number)==num_counters) {
254  if ( !TESTS_QUIET) {
255  fprintf(stdout, "Stopping with %d events due to HW limit\n",
256  num_counters);
257  }
258  break;
259  }
260 #endif
261  }
262  else {
263  if ( !TESTS_QUIET ) {
264  PAPI_event_code_to_name(test_events[i].event,name_string);
265  fprintf( stdout, "%#x %s is not available.\n",
266  test_events[i].event,name_string);
267  }
268  *mask = *mask ^ test_events[i].mask;
269  }
270  }
271  }
272 
273  return EventSet;
274 }
275 
276 int
278 {
279  int retval = PAPI_OK;
280 
281  if ( mask & MASK_L1_DCA ) {
282  retval = PAPI_remove_event( *EventSet, PAPI_L1_DCA );
283  if ( retval < PAPI_OK )
284  return ( retval );
285  }
286 
287  if ( mask & MASK_L1_DCW ) {
288  retval = PAPI_remove_event( *EventSet, PAPI_L1_DCW );
289  if ( retval < PAPI_OK )
290  return ( retval );
291  }
292 
293  if ( mask & MASK_L1_DCR ) {
294  retval = PAPI_remove_event( *EventSet, PAPI_L1_DCR );
295  if ( retval < PAPI_OK )
296  return ( retval );
297  }
298 
299  if ( mask & MASK_L2_TCH ) {
300  retval = PAPI_remove_event( *EventSet, PAPI_L2_TCH );
301  if ( retval < PAPI_OK )
302  return ( retval );
303  }
304 
305  if ( mask & MASK_L2_TCA ) {
306  retval = PAPI_remove_event( *EventSet, PAPI_L2_TCA );
307  if ( retval < PAPI_OK )
308  return ( retval );
309  }
310 
311  if ( mask & MASK_L2_TCM ) {
312  retval = PAPI_remove_event( *EventSet, PAPI_L2_TCM );
313  if ( retval < PAPI_OK )
314  return ( retval );
315  }
316 
317  if ( mask & MASK_L1_DCM ) {
318  retval = PAPI_remove_event( *EventSet, PAPI_L1_DCM );
319  if ( retval < PAPI_OK )
320  return ( retval );
321  }
322 
323  if ( mask & MASK_L1_ICM ) {
324  retval = PAPI_remove_event( *EventSet, PAPI_L1_ICM );
325  if ( retval < PAPI_OK )
326  return ( retval );
327  }
328 
329  if ( mask & MASK_L1_TCM ) {
330  retval = PAPI_remove_event( *EventSet, PAPI_L1_TCM );
331  if ( retval < PAPI_OK )
332  return ( retval );
333  }
334 
335  if ( mask & MASK_FP_OPS ) {
336  retval = PAPI_remove_event( *EventSet, PAPI_FP_OPS );
337  if ( retval < PAPI_OK )
338  return ( retval );
339  }
340 
341  if ( mask & MASK_FP_INS ) {
342  retval = PAPI_remove_event( *EventSet, PAPI_FP_INS );
343  if ( retval < PAPI_OK )
344  return ( retval );
345  }
346 
347  if ( mask & MASK_TOT_INS ) {
348  retval = PAPI_remove_event( *EventSet, PAPI_TOT_INS );
349  if ( retval < PAPI_OK )
350  return ( retval );
351  }
352 
353  if ( mask & MASK_TOT_IIS ) {
354  retval = PAPI_remove_event( *EventSet, PAPI_TOT_IIS );
355  if ( retval < PAPI_OK )
356  return ( retval );
357  }
358 
359  if ( mask & MASK_TOT_CYC ) {
360  retval = PAPI_remove_event( *EventSet, PAPI_TOT_CYC );
361  if ( retval < PAPI_OK )
362  return ( retval );
363  }
364 
365  return ( PAPI_destroy_eventset( EventSet ) );
366 }
367 
368 char *
369 stringify_all_domains( int domains )
370 {
371  static char buf[PAPI_HUGE_STR_LEN];
372  int i, did = 0;
373  buf[0] = '\0';
374 
375  for ( i = PAPI_DOM_MIN; i <= PAPI_DOM_MAX; i = i << 1 )
376  if ( domains & i ) {
377  if ( did )
378  strcpy( buf + strlen( buf ), "|" );
379  strcpy( buf + strlen( buf ), stringify_domain( domains & i ) );
380  did++;
381  }
382  if ( did == 0 )
383  test_fail( __FILE__, __LINE__, "Unrecognized domains!", 0 );
384  return ( buf );
385 }
386 
387 char *
388 stringify_domain( int domain )
389 {
390  switch ( domain ) {
391  case PAPI_DOM_SUPERVISOR:
392  return ( "PAPI_DOM_SUPERVISOR" );
393  case PAPI_DOM_USER:
394  return ( "PAPI_DOM_USER" );
395  case PAPI_DOM_KERNEL:
396  return ( "PAPI_DOM_KERNEL" );
397  case PAPI_DOM_OTHER:
398  return ( "PAPI_DOM_OTHER" );
399  case PAPI_DOM_ALL:
400  return ( "PAPI_DOM_ALL" );
401  default:
402  test_fail( __FILE__, __LINE__, "Unrecognized domains!", 0 );
403  }
404  return ( NULL );
405 }
406 
407 char *
408 stringify_all_granularities( int granularities )
409 {
410  static char buf[PAPI_HUGE_STR_LEN];
411  int i, did = 0;
412 
413  buf[0] = '\0';
414  for ( i = PAPI_GRN_MIN; i <= PAPI_GRN_MAX; i = i << 1 )
415  if ( granularities & i ) {
416  if ( did )
417  strcpy( buf + strlen( buf ), "|" );
418  strcpy( buf + strlen( buf ),
419  stringify_granularity( granularities & i ) );
420  did++;
421  }
422  if ( did == 0 )
423  test_fail( __FILE__, __LINE__, "Unrecognized granularity!", 0 );
424 
425  return ( buf );
426 }
427 
428 char *
429 stringify_granularity( int granularity )
430 {
431  switch ( granularity ) {
432  case PAPI_GRN_THR:
433  return ( "PAPI_GRN_THR" );
434  case PAPI_GRN_PROC:
435  return ( "PAPI_GRN_PROC" );
436  case PAPI_GRN_PROCG:
437  return ( "PAPI_GRN_PROCG" );
438  case PAPI_GRN_SYS_CPU:
439  return ( "PAPI_GRN_SYS_CPU" );
440  case PAPI_GRN_SYS:
441  return ( "PAPI_GRN_SYS" );
442  default:
443  test_fail( __FILE__, __LINE__, "Unrecognized granularity!", 0 );
444  }
445  return ( NULL );
446 }
447 
448 void
449 tests_quiet( int argc, char **argv )
450 {
451  if ( ( argc > 1 )
452  && ( ( strcasecmp( argv[1], "TESTS_QUIET" ) == 0 )
453  || ( strcasecmp( argv[1], "-q" ) == 0 ) ) ) {
454  TESTS_QUIET = 1;
455  } else {
456  int retval;
457 
458  retval = PAPI_set_debug( PAPI_VERB_ECONT );
459  if ( retval != PAPI_OK )
460  test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval );
461  }
462  if (getenv("TESTS_COLOR")!=NULL) {
463  TESTS_COLOR=1;
464  }
465 
466 }
467 
468 #define RED "\033[1;31m"
469 #define YELLOW "\033[1;33m"
470 #define GREEN "\033[1;32m"
471 #define NORMAL "\033[0m"
472 
473 void
474 test_pass( char *file, long long **values, int num_tests )
475 {
476  int line_pad;
477 
478  line_pad=(int)(50-strlen(file));
479  if (line_pad<0) line_pad=0;
480 
481  if ( TEST_WARN ) {
482  if (TESTS_COLOR) {
483  fprintf( stdout, "%-*s %sPASSED with WARNING%s\n",
484  line_pad, file, YELLOW, NORMAL);
485  }
486  else {
487  fprintf( stdout, "%-*s PASSED with WARNING\n",
488  line_pad, file );
489  }
490  }
491  else {
492  if (TESTS_COLOR) {
493  fprintf( stdout, "%-*s %sPASSED%s\n", line_pad, file,
494  GREEN, NORMAL );
495  }
496  else {
497  fprintf( stdout, "%-*s PASSED\n", line_pad, file );
498  }
499  }
500 
501  if ( values )
502  free_test_space( values, num_tests );
503 
504  if ( PAPI_is_initialized( ) )
505  PAPI_shutdown( );
506 
507  exit( 0 );
508 
509 }
510 
511 /* Use a positive value of retval to simply print an error message */
512 void
513 test_fail( char *file, int line, char *call, int retval )
514 {
515 
516  int line_pad;
517  char buf[128];
518 
519  line_pad=(int)(50-strlen(file));
520  if (line_pad<0) line_pad=0;
521 
522  memset( buf, '\0', sizeof ( buf ) );
523 
524  if (TESTS_COLOR) {
525  fprintf( stdout, "%-*s %sFAILED%s\nLine # %d\n", line_pad, file,
526  RED,NORMAL,line );
527  }
528  else {
529  fprintf( stdout, "%-*s FAILED\nLine # %d\n", line_pad, file, line );
530  }
531 
532  if ( retval == PAPI_ESYS ) {
533  sprintf( buf, "System error in %s", call );
534  perror( buf );
535  } else if ( retval > 0 ) {
536  fprintf( stdout, "Error: %s\n", call );
537  } else if ( retval == 0 ) {
538 #if defined(sgi)
539  fprintf( stdout, "SGI requires root permissions for this test\n" );
540 #else
541  fprintf( stdout, "Error: %s\n", call );
542 #endif
543  } else {
544  fprintf( stdout, "Error in %s: %s\n", call, PAPI_strerror( retval ) );
545  }
546 
547  fprintf( stdout, "\n" );
548 
549  /* NOTE: Because test_fail is called from thread functions,
550  calling PAPI_shutdown here could prevent some threads
551  from being able to free memory they have allocated.
552  */
553 
554  /* This is stupid. Threads are the rare case */
555  /* and in any case an exit() should clear everything out */
556  /* adding back the exit() call */
557 
558  exit(1);
559 }
560 
561 /* This routine mimics the previous implementation of test_fail()
562  by exiting on completion. It caused problems for threaded apps.
563  If you are not threaded and want to exit, replace calls to
564  test_fail() with calls to test_fail_exit().
565 */
566 void
567 test_fail_exit( char *file, int line, char *call, int retval )
568 {
569  test_fail( file, line, call, retval );
570  if ( PAPI_is_initialized( ) )
571  PAPI_shutdown( );
572  exit( 1 );
573 }
574 
575 
576 /* Use a positive value of retval to simply print an error message */
577 void
578 test_warn( char *file, int line, char *call, int retval )
579 {
580 
581  int line_pad;
582 
583  line_pad=(int)(50-strlen(file));
584  if (line_pad<0) line_pad=0;
585 
586  char buf[128];
587  memset( buf, '\0', sizeof ( buf ) );
588 
589  if (TESTS_COLOR) {
590  fprintf( stdout, "%-*s %sWARNING%s\nLine # %d\n", line_pad, file,
591  YELLOW, NORMAL, line );
592  }
593  else {
594  fprintf( stdout, "%-*s WARNING\nLine # %d\n", line_pad, file, line );
595  }
596 
597  if ( retval == PAPI_ESYS ) {
598  sprintf( buf, "System warning in %s", call );
599  perror( buf );
600  } else if ( retval > 0 ) {
601  fprintf( stdout, "Warning: %s\n", call );
602  } else if ( retval == 0 ) {
603  fprintf( stdout, "Warning: %s\n", call );
604  } else {
605  fprintf( stdout, "Warning in %s: %s\n", call, PAPI_strerror( retval ));
606  }
607 
608  fprintf( stdout, "\n" );
609  TEST_WARN++;
610 
611 }
612 
613 void
614 test_skip( char *file, int line, char *call, int retval )
615 {
616  char buf[128];
617 
618  memset( buf, '\0', sizeof ( buf ) );
619  fprintf( stdout, "%-40s SKIPPED\n", file );
620  if ( !TESTS_QUIET ) {
621  if ( retval == PAPI_ESYS ) {
622  fprintf( stdout, "Line # %d\n", line );
623  sprintf( buf, "System error in %s:", call );
624  perror( buf );
625  } else if ( retval == PAPI_EPERM ) {
626  fprintf( stdout, "Line # %d\n", line );
627  fprintf( stdout, "Invalid permissions for %s.", call );
628  } else if ( retval == PAPI_ECMP ) {
629  fprintf( stdout, "Line # %d\n", line );
630  fprintf( stdout, "%s.", call );
631  } else if ( retval >= 0 ) {
632  fprintf( stdout, "Line # %d\n", line );
633  fprintf( stdout, "Error calculating: %s\n", call );
634  } else if ( retval < 0 ) {
635  fprintf( stdout, "Line # %d\n", line );
636  fprintf( stdout, "Error in %s: %s\n", call, PAPI_strerror(retval) );
637  }
638  fprintf( stdout, "\n" );
639  }
640  exit( 0 );
641 }
642 
643 
644 void
645 test_print_event_header( char *call, int evset )
646 {
647  int *ev_ids;
648  int i, nev;
649  int retval;
650  char evname[PAPI_MAX_STR_LEN];
651 
652  if ( *call )
653  fprintf( stdout, "%s", call );
654 
655  if ((nev = PAPI_get_cmp_opt(PAPI_MAX_MPX_CTRS,NULL,0)) <= 0) {
656  fprintf( stdout, "Can not list event names.\n" );
657  return;
658  }
659 
660  if ((ev_ids = calloc(nev,sizeof(int))) == NULL) {
661  fprintf( stdout, "Can not list event names.\n" );
662  return;
663  }
664 
665  retval = PAPI_list_events( evset, ev_ids, &nev );
666 
667  if ( retval == PAPI_OK ) {
668  for ( i = 0; i < nev; i++ ) {
669  PAPI_event_code_to_name( ev_ids[i], evname );
670  printf( ONEHDR, evname );
671  }
672  } else {
673  fprintf( stdout, "Can not list event names." );
674  }
675  fprintf( stdout, "\n" );
676  free(ev_ids);
677 }
678 
679 int
680 add_two_events( int *num_events, int *papi_event, int *mask ) {
681 
682  /* query and set up the right event to monitor */
683  int EventSet = PAPI_NULL;
684  PAPI_event_info_t info;
685  unsigned int potential_evt_to_add[3][2] =
686  { {( unsigned int ) PAPI_FP_INS, MASK_FP_INS},
687  {( unsigned int ) PAPI_FP_OPS, MASK_FP_OPS},
688  {( unsigned int ) PAPI_TOT_INS, MASK_TOT_INS}
689  };
690  int i = 0;
691  int counters = 0;
692 
693  *mask = 0;
694  counters = PAPI_num_hwctrs( );
695 
696  if (counters<=0) {
697  test_fail(__FILE__,__LINE__,"Zero Counters Available! PAPI Won't like this!\n",0);
698  }
699 
700  /* This code tries to ensure that the event generated will fit in the */
701  /* number of available counters. It has the potential to leak up to */
702  /* two event sets if events fail to add successfully. */
703 
704  for(i=0;i<3;i++) {
705  if ( PAPI_query_event( (int) potential_evt_to_add[i][0] ) == PAPI_OK ) {
706  if ( PAPI_get_event_info( (int) potential_evt_to_add[i][0], &info ) == PAPI_OK ) {
707  if ( ( info.count > 0 ) && ( (unsigned) counters > info.count ) ) {
708  *papi_event = ( int ) potential_evt_to_add[i][0];
709  *mask = ( int ) potential_evt_to_add[i][1] | MASK_TOT_CYC;
710  EventSet = add_test_events( num_events, mask, 1 );
711  if ( *num_events == 2 ) break;
712  }
713  }
714  }
715  }
716  if ( i == 3 ) {
717  test_fail( __FILE__, __LINE__, "Not enough room to add an event!", 0 );
718  }
719  return EventSet;
720 }
721 
722 int
723 add_two_nonderived_events( int *num_events, int *papi_event, int *mask ) {
724 
725  /* query and set up the right event to monitor */
726  int EventSet = PAPI_NULL;
727 
728 #define POTENTIAL_EVENTS 3
729 
730  unsigned int potential_evt_to_add[POTENTIAL_EVENTS][2] =
731  { {( unsigned int ) PAPI_FP_INS, MASK_FP_INS},
732  {( unsigned int ) PAPI_FP_OPS, MASK_FP_OPS},
733  {( unsigned int ) PAPI_TOT_INS, MASK_TOT_INS}
734  };
735 
736  int i;
737 
738  *mask = 0;
739 
740  /* could leak up to two event sets. */
741  for(i=0;i<POTENTIAL_EVENTS;i++) {
742 
743  if ( PAPI_query_event( ( int ) potential_evt_to_add[i][0] ) == PAPI_OK ) {
744  if ( !is_event_derived(potential_evt_to_add[i][0])) {
745  *papi_event = ( int ) potential_evt_to_add[i][0];
746  *mask = ( int ) potential_evt_to_add[i][1] | MASK_TOT_CYC;
747  EventSet = add_test_events( num_events, mask, 0 );
748  if ( *num_events == 2 ) break;
749  }
750  }
751  }
752 
753  if ( i == POTENTIAL_EVENTS ) {
754  test_fail( __FILE__, __LINE__, "Can't find a non-derived event!", 0 );
755  }
756  return EventSet;
757 }
758 
759 /* add native events to use all counters */
760 int
761 enum_add_native_events( int *num_events, int **evtcodes,
762  int need_interrupt, int no_software_events,
763  int cidx)
764 {
765  /* query and set up the right event to monitor */
766  int EventSet = PAPI_NULL;
767  int i = 0, k, event_code, retval;
768  int counters, event_found = 0;
769  PAPI_event_info_t info;
770  const PAPI_component_info_t *s = NULL;
771  const PAPI_hw_info_t *hw_info = NULL;
772 
773  s = PAPI_get_component_info( cidx );
774  if ( s == NULL ) {
775  test_fail( __FILE__, __LINE__,
776  "PAPI_get_component_info", PAPI_ECMP );
777  }
778 
779  hw_info = PAPI_get_hardware_info( );
780  if ( hw_info == NULL ) {
781  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
782  }
783 
784  counters = PAPI_num_hwctrs( );
785  if (counters<1) {
786  test_fail(__FILE__,__LINE__, "No counters available!\n",1);
787  }
788 
789  if (!TESTS_QUIET) printf("Trying to fill %d hardware counters...\n",
790  counters);
791 
792  if (need_interrupt) {
793  if ( (!strcmp(hw_info->model_string,"POWER6")) ||
794  (!strcmp(hw_info->model_string,"POWER5")) ) {
795 
796  test_warn(__FILE__, __LINE__,
797  "Limiting num_counters because of LIMITED_PMC on Power5 and Power6",1);
798  counters=4;
799  }
800  }
801 
802  ( *evtcodes ) = ( int * ) calloc( counters, sizeof ( int ) );
803 
804  retval = PAPI_create_eventset( &EventSet );
805  if ( retval != PAPI_OK ) {
806  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
807  }
808 
809  /* For platform independence, always ASK FOR the first event */
810  /* Don't just assume it'll be the first numeric value */
811  i = 0 | PAPI_NATIVE_MASK;
812  retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cidx );
813  if ( retval != PAPI_OK )
814  {
815  test_fail( __FILE__, __LINE__, "PAPI_enum_cmp_event", retval );
816  }
817 
818  do {
819  retval = PAPI_get_event_info( i, &info );
820 
821  /* HACK! FIXME */
822  if (no_software_events && ( strstr(info.symbol,"PERF_COUNT_SW") || strstr(info.long_descr, "PERF_COUNT_SW") ) ) {
823  if (!TESTS_QUIET) {
824  printf("Blocking event %s as a SW event\n", info.symbol);
825  }
826  continue;
827  }
828 
829  if ( s->cntr_umasks ) {
830  k = i;
831 
832  if ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cidx ) == PAPI_OK ) {
833  do {
834  retval = PAPI_get_event_info( k, &info );
835  event_code = ( int ) info.event_code;
836 
837  retval = PAPI_add_event( EventSet, event_code );
838  if ( retval == PAPI_OK ) {
839  ( *evtcodes )[event_found] = event_code;
840  if ( !TESTS_QUIET ) {
841  printf( "event_code[%d] = %#x (%s)\n",
842  event_found, event_code, info.symbol );
843  }
844  event_found++;
845  } else {
846  if ( !TESTS_QUIET ) {
847  printf( "%#x (%s) can't be added to the EventSet.\n",
848  event_code, info.symbol );
849  }
850  }
851  } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cidx ) == PAPI_OK
852  && event_found < counters );
853  } else {
854  event_code = ( int ) info.event_code;
855  retval = PAPI_add_event( EventSet, event_code );
856  if ( retval == PAPI_OK ) {
857  ( *evtcodes )[event_found] = event_code;
858  if ( !TESTS_QUIET ) {
859  printf( "event_code[%d] = %#x (%s)\n",
860  event_found, event_code, info.symbol );
861  }
862  event_found++;
863  }
864  }
865  if ( !TESTS_QUIET && retval == PAPI_OK ) {
866  /* */
867  }
868  } else {
869  event_code = ( int ) info.event_code;
870  retval = PAPI_add_event( EventSet, event_code );
871  if ( retval == PAPI_OK ) {
872  ( *evtcodes )[event_found] = event_code;
873  event_found++;
874  } else {
875  if ( !TESTS_QUIET )
876  fprintf( stdout, "%#x is not available.\n", event_code );
877  }
878  }
879  }
880  while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cidx ) == PAPI_OK &&
881  event_found < counters );
882 
883  *num_events = ( int ) event_found;
884 
885  if (!TESTS_QUIET) printf("Tried to fill %d counters with events, "
886  "found %d\n",counters,event_found);
887 
888  return EventSet;
889 }
890 
891 void
893 {
894  int retval;
895  const PAPI_hw_info_t *hw_info;
896  const PAPI_component_info_t *cmpinfo;
897 
898  /* Initialize the library */
899 
900  /* for now, assume multiplexing on CPU compnent only */
901  cmpinfo = PAPI_get_component_info( 0 );
902  if ( cmpinfo == NULL )
903  test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 2 );
904 
905  hw_info = PAPI_get_hardware_info( );
906  if ( hw_info == NULL )
907  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
908 
909  if ( ( strstr( cmpinfo->name, "perfctr.c" ) ) && (hw_info !=NULL) &&
910  strcmp( hw_info->model_string, "POWER6" ) == 0 ) {
911  retval = PAPI_set_domain( PAPI_DOM_ALL );
912  if ( retval != PAPI_OK )
913  test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
914  }
915  retval = PAPI_multiplex_init( );
916  if ( retval != PAPI_OK )
917  test_fail( __FILE__, __LINE__, "PAPI multiplex init fail\n", retval );
918 }
919 
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:626
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
unsigned int count
Definition: papi.h:984
memset(eventId, 0, size)
int PAPI_is_initialized(void)
Definition: papi.c:6389
#define PAPI_NATIVE_MASK
#define PAPI_TOT_IIS
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:807
char * getenv()
#define PAPI_VERB_ECONT
Definition: papi.h:387
#define PAPI_L2_TCH
#define TOLERANCE
Definition: test_utils.h:13
#define PAPI_L2_TCM
#define MASK_BR_CN
Definition: papi_test.h:40
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
Hardware info structure.
Definition: papi.h:777
int is_event_derived(unsigned int event)
Definition: test_utils.c:142
#define PAPI_L1_DCM
#define PAPI_FP_OPS
#define GREEN
Definition: test_utils.c:470
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1717
char * stringify_granularity(int granularity)
Definition: test_utils.c:429
#define PAPI_L1_TCM
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
int papi_print_header(char *prompt, const PAPI_hw_info_t **hwinfo)
Definition: test_utils.c:21
#define PAPI_NULL
Definition: papi.h:290
#define PAPI_DOM_KERNEL
Definition: papi.h:298
#define PAPI_DOM_MIN
Definition: papi.h:297
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:966
int EventSet
Definition: data_range.c:25
int num_events
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
#define PAPI_TOT_INS
device[deviceId] domain[domainId] event
Definition: linux-cuda.c:306
#define PAPI_DOM_ALL
Definition: papi.h:301
#define MAX_TEST_EVENTS
Definition: papi_test.h:51
char * stringify_all_granularities(int granularities)
Definition: test_utils.c:408
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_L1_DCA
static int TESTS_COLOR
Definition: test_utils.c:12
tests_quiet(argc, argv)
#define PAPI_PRESET_MASK
#define PAPI_BR_MSP
#define PAPI_DOM_USER
Definition: papi.h:296
#define printf
Definition: papi_test.h:125
#define MASK_L1_TCM
Definition: papi_test.h:46
#define PAPI_EPERM
Definition: papi.h:266
void init_multiplex(void)
Definition: test_utils.c:892
test_pass(__FILE__, NULL, 0)
unsigned int cntr_umasks
Definition: papi.h:665
int int argc
Definition: iozone.c:1609
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
#define PAPI_HUGE_STR_LEN
Definition: papi.h:465
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
#define MASK_FP_INS
Definition: papi_test.h:47
#define PAPI_L1_DCR
#define PAPI_BR_CN
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int i
Definition: fileop.c:140
void test_warn(char *file, int line, char *call, int retval)
Definition: test_utils.c:578
char buf[200]
Definition: iozone.c:19609
int PAPI_num_hwctrs(void)
Definition: papi.c:3848
#define PAPI_L2_TCA
#define PAPI_VERSION_MAJOR(x)
Definition: papi.h:215
char * stringify_all_domains(int domains)
Definition: test_utils.c:369
void PAPI_shutdown(void)
Definition: papi.c:4400
#define PAPI_TOT_CYC
int PAPI_get_cmp_opt(int option, PAPI_option_t *ptr, int cidx)
Definition: papi.c:4274
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4082
const char FILE * file
Definition: pscanf.h:13
free(dummyfile[xx])
int k
Definition: iozone.c:19136
static int cidx
Definition: event_info.c:40
#define PAPI_VERSION_REVISION(x)
Definition: papi.h:217
#define PAPI_ESYS
Definition: papi.h:253
#define MASK_L2_TCH
Definition: papi_test.h:41
#define MASK_BR_PRC
Definition: papi_test.h:38
#define MASK_L2_TCA
Definition: papi_test.h:42
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:680
s
Definition: iozone.c:20289
long long
Definition: iozone.c:19827
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:131
int approx_equals(double a, double b)
Definition: test_utils.c:94
#define PAPI_ECMP
Definition: papi.h:254
#define PAPI_GRN_MAX
Definition: papi.h:366
#define PAPI_MAX_MPX_CTRS
Definition: papi.h:437
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1324
#define NORMAL
Definition: test_utils.c:471
#define PAPI_GRN_THR
Definition: papi.h:360
#define PAPI_VERSION_MINOR(x)
Definition: papi.h:216
#define PAPI_GRN_SYS_CPU
Definition: papi.h:365
#define MASK_TOT_CYC
Definition: papi_test.h:49
double s2
Definition: byte_profile.c:31
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
#define PAPI_L1_ICM
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
#define MASK_FP_OPS
Definition: papi_test.h:33
int num_tests
Definition: zero_fork.c:46
#define ONEHDR
Definition: papi_test.h:107
#define MASK_L1_DCR
Definition: papi_test.h:36
strcpy(filename, default_filename)
int enum_add_native_events(int *num_events, int **evtcodes, int need_interrupts, int no_software_events, int cidx)
Definition: test_utils.c:761
int PAPI_query_event(int EventCode)
Definition: papi.c:698
#define MASK_L1_DCA
Definition: papi_test.h:34
int PAPI_multiplex_init(void)
Definition: papi.c:2926
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
#define MASK_TOT_INS
Definition: papi_test.h:48
struct test_events_t test_events[]
Definition: test_utils.c:191
#define PAPI_VERSION
Definition: papi.h:222
char * PAPI_strerror(int errorCode)
Definition: papi.c:4529
char * name
Definition: iozone.c:23648
#define PAPI_L1_DCW
#define MASK_TOT_IIS
Definition: papi_test.h:37
void validate_string(char *name, char *s)
Definition: test_utils.c:84
#define POTENTIAL_EVENTS
int
Definition: iozone.c:18528
#define YELLOW
Definition: test_utils.c:469
#define PAPI_MAX_HWCTRS
Definition: papi.h:441
#define MASK_L2_TCM
Definition: papi_test.h:43
#define MASK_L1_ICM
Definition: papi_test.h:45
#define MASK_L1_DCM
Definition: papi_test.h:44
add PAPI preset or native hardware event to an event set
static int TEST_WARN
Definition: test_utils.c:13
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1971
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int add_two_nonderived_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:723
char * stringify_domain(int domain)
Definition: test_utils.c:388
int PAPI_set_domain(int domain)
Definition: papi.c:5614
#define PAPI_GRN_PROCG
Definition: papi.h:363
#define MASK_L1_DCW
Definition: papi_test.h:35
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:787
int find_nonderived_event(void)
Definition: test_utils.c:159
#define RED
Definition: test_utils.c:468
#define PAPI_DOM_OTHER
Definition: papi.h:299
#define MASK_BR_MSP
Definition: papi_test.h:39
#define PAPI_DOM_SUPERVISOR
Definition: papi.h:300
void test_print_event_header(char *call, int evset)
Definition: test_utils.c:645
#define PAPI_GRN_SYS
Definition: papi.h:364
void test_fail_exit(char *file, int line, char *call, int retval)
Definition: test_utils.c:567
unsigned int event_code
Definition: papi.h:961
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6111
char derived[PAPI_MIN_STR_LEN]
Definition: papi.h:992
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
#define PAPI_GRN_MIN
Definition: papi.h:361
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
#define PAPI_DOM_MAX
Definition: papi.h:303
#define PAPI_VERSION_INCREMENT(x)
Definition: papi.h:218
void exit()
#define PAPI_BR_PRC
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277
int PAPI_set_debug(int level)
Definition: papi.c:3070
unsigned int mask
Definition: papi_test.h:54
int add_test_events(int *number, int *mask, int allow_derived)
Definition: test_utils.c:213
#define PAPI_FP_INS
int PAPI_list_events(int EventSet, int *Events, int *number)
Definition: papi.c:5927
#define PAPI_GRN_PROC
Definition: papi.h:362