PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
multiplex2.c
Go to the documentation of this file.
1 /*
2 * File: multiplex.c
3 * CVS: $Id$
4 * Author: Philip Mucci
5 * mucci@cs.utk.edu
6 * Mods: <your name here>
7 * <your email address>
8 */
9 
10 /* This file tests the multiplex functionality, originally developed by
11  John May of LLNL. */
12 
13 #include "papi_test.h"
14 
15 void
16 init_papi( void )
17 {
18  int retval;
19 
20  /* Initialize the library */
21 
23  if ( retval != PAPI_VER_CURRENT )
24  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
25 
26 }
27 
28 /* Tests that we can really multiplex a lot. */
29 
30 int
31 case1( void )
32 {
33  int retval, i, EventSet = PAPI_NULL, j = 0, k = 0, allvalid = 1;
34  int max_mux, nev, *events;
35  long long *values;
36  PAPI_event_info_t pset;
37  char evname[PAPI_MAX_STR_LEN];
38 
39  init_papi( );
40  init_multiplex( );
41 
42 #if 0
44  test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
45 #endif
46  retval = PAPI_create_eventset( &EventSet );
47  if ( retval != PAPI_OK )
48  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
49 
50 #if 0
52  test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
53 #endif
54  /* In Component PAPI, EventSets must be assigned a component index
55  before you can fiddle with their internals.
56  0 is always the cpu component */
57  retval = PAPI_assign_eventset_component( EventSet, 0 );
58  if ( retval != PAPI_OK )
59  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
60  retval );
61 #if 0
63  test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
64 #endif
65 
66  retval = PAPI_set_multiplex( EventSet );
67  if ( retval == PAPI_ENOSUPP) {
68  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
69  }
70  else if ( retval != PAPI_OK )
71  test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
72 
73  max_mux = PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL );
74  if ( max_mux > 32 )
75  max_mux = 32;
76 
77 #if 0
79  test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
80 #endif
81 
82  /* Fill up the event set with as many non-derived events as we can */
83  printf
84  ( "\nFilling the event set with as many non-derived events as we can...\n" );
85 
86  i = PAPI_PRESET_MASK;
87  do {
88  if ( PAPI_get_event_info( i, &pset ) == PAPI_OK ) {
89  if ( pset.count && ( strcmp( pset.derived, "NOT_DERIVED" ) == 0 ) ) {
90  retval = PAPI_add_event( EventSet, ( int ) pset.event_code );
91  if ( retval != PAPI_OK ) {
92  printf("Failed trying to add %s\n",pset.symbol);
93  break;
94  }
95  else {
96  printf( "Added %s\n", pset.symbol );
97  j++;
98  }
99  }
100  }
101  } while ( ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK ) &&
102  ( j < max_mux ) );
103 
104  events = ( int * ) malloc( ( size_t ) j * sizeof ( int ) );
105  if ( events == NULL )
106  test_fail( __FILE__, __LINE__, "malloc events", 0 );
107 
108  values = ( long long * ) malloc( ( size_t ) j * sizeof ( long long ) );
109  if ( values == NULL )
110  test_fail( __FILE__, __LINE__, "malloc values", 0 );
111 
112  do_stuff( );
113 
114 #if 0
116  test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
117 #endif
118 
119  if ( PAPI_start( EventSet ) != PAPI_OK )
120  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
121 
122  do_stuff( );
123 
124  retval = PAPI_stop( EventSet, values );
125  if ( retval != PAPI_OK )
126  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
127 
128  nev = j;
129  retval = PAPI_list_events( EventSet, events, &nev );
130  if ( retval != PAPI_OK )
131  test_fail( __FILE__, __LINE__, "PAPI_list_events", retval );
132 
133  printf( "\nEvent Counts:\n" );
134  for ( i = 0, allvalid = 0; i < j; i++ ) {
135  PAPI_event_code_to_name( events[i], evname );
136  printf( TAB1, evname, values[i] );
137  if ( values[i] == 0 )
138  allvalid++;
139  }
140  printf( "\n" );
141  if ( allvalid ) {
142  printf( "Caution: %d counters had zero values\n", allvalid );
143  }
144 
145  if (allvalid==j) {
146  test_fail( __FILE__, __LINE__, "All counters returned zero", 5 );
147  }
148 
149  for ( i = 0, allvalid = 0; i < j; i++ ) {
150  for ( k = i + 1; k < j; k++ ) {
151  if ( ( i != k ) && ( values[i] == values[k] ) ) {
152  allvalid++;
153  break;
154  }
155  }
156  }
157 
158  if ( allvalid ) {
159  printf( "Caution: %d counter pair(s) had identical values\n",
160  allvalid );
161  }
162 
163  free( events );
164  free( values );
165 
166  retval = PAPI_cleanup_eventset( EventSet );
167  if ( retval != PAPI_OK )
168  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
169 
170  retval = PAPI_destroy_eventset( &EventSet );
171  if ( retval != PAPI_OK )
172  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
173 
174  return ( SUCCESS );
175 }
176 
177 int
178 main( int argc, char **argv )
179 {
180 
181  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
182 
183  printf( "%s: Does PAPI_multiplex_init() handle lots of events?\n",
184  argv[0] );
185  printf( "Using %d iterations\n", NUM_ITERS );
186 
187  case1( );
188  test_pass( __FILE__, NULL, 0 );
189  exit( 1 );
190 }
unsigned int count
Definition: papi.h:982
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
#define PAPI_NULL
Definition: fpapi.h:13
#define NUM_ITERS
Definition: multiplex.c:19
#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
void do_stuff(void)
Definition: do_loops.c:249
#define TAB1
Definition: papi_test.h:112
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1143
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
return PAPI_OK
Definition: linux-nvml.c:458
#define SUCCESS
Definition: test_utils.h:5
tests_quiet(argc, argv)
int case1()
Definition: multiplex1.c:90
#define PAPI_PRESET_MASK
#define PAPI_DOM_KERNEL
Definition: fpapi.h:22
#define printf
Definition: papi_test.h:125
void init_multiplex(void)
Definition: test_utils.c:888
test_pass(__FILE__, NULL, 0)
void init_papi(int *out_events, int *len)
Definition: multiplex1.c:33
int int argc
Definition: iozone.c:1609
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:841
char ** argv
Definition: iozone.c:1610
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_ENOSUPP
Definition: fpapi.h:123
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4030
free(dummyfile[xx])
#define PAPI_MAX_MPX_CTRS
Definition: fpapi.h:54
int k
Definition: iozone.c:19136
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
long long
Definition: iozone.c:19827
char events[MAX_EVENTS][BUFSIZ]
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2795
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1460
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:920
int EventSet
int
Definition: iozone.c:18528
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3230
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1937
int PAPI_set_domain(int domain)
Definition: papi.c:5552
int PAPI_start(int EventSet)
Definition: papi.c:2019
long j
Definition: iozone.c:19135
unsigned int event_code
Definition: papi.h:959
char derived[PAPI_MIN_STR_LEN]
Definition: papi.h:990
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
int PAPI_list_events(int EventSet, int *Events, int *number)
Definition: papi.c:5863