PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
multiplex1.c
Go to the documentation of this file.
1 /*
2 * File: multiplex.c
3 * Author: Philip Mucci
4 * mucci@cs.utk.edu
5 * Mods: <your name here>
6 * <your email address>
7 */
8 
9 /* This file tests the multiplex functionality, originally developed by
10  John May of LLNL. */
11 
12 #include "papi_test.h"
13 
14 /* Event to use in all cases; initialized in init_papi() */
15 
16 #define TOTAL_EVENTS 6
17 
20 };
23 };
26 };
27 static int PAPI_events[TOTAL_EVENTS] = { 0, };
28 static int PAPI_events_len = 0;
29 
30 #define CPP_TEST_FAIL(string, retval) test_fail(__FILE__, __LINE__, string, retval)
31 
32 void
33 init_papi( int *out_events, int *len )
34 {
35  int retval;
36  int i, real_len = 0;
37  int *in_events = preset_PAPI_events;
38  const PAPI_hw_info_t *hw_info;
39 
40  /* Initialize the library */
42  if ( retval != PAPI_VER_CURRENT )
43  CPP_TEST_FAIL( "PAPI_library_init", retval );
44 
45  hw_info = PAPI_get_hardware_info( );
46  if ( hw_info == NULL )
47  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
48 
49  if ( strstr( hw_info->model_string, "UltraSPARC" ) ) {
50  in_events = solaris_preset_PAPI_events;
51  }
52 
53  if ( strcmp( hw_info->model_string, "POWER6" ) == 0 ) {
54  in_events = power6_preset_PAPI_events;
55  retval = PAPI_set_domain( PAPI_DOM_ALL );
56  if ( retval != PAPI_OK )
57  CPP_TEST_FAIL( "PAPI_set_domain", retval );
58  }
59 
60  retval = PAPI_multiplex_init( );
61  if ( retval == PAPI_ENOSUPP) {
62  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
63  }
64  else if ( retval != PAPI_OK )
65  CPP_TEST_FAIL( "PAPI_multiplex_init", retval );
66 
67  for ( i = 0; in_events[i] != 0; i++ ) {
68  char out[PAPI_MAX_STR_LEN];
69  /* query and set up the right instruction to monitor */
70  retval = PAPI_query_event( in_events[i] );
71  if ( retval == PAPI_OK ) {
72  out_events[real_len++] = in_events[i];
73  PAPI_event_code_to_name( in_events[i], out );
74  if ( real_len == *len )
75  break;
76  } else {
77  PAPI_event_code_to_name( in_events[i], out );
78  if ( !TESTS_QUIET )
79  printf( "%s does not exist\n", out );
80  }
81  }
82  if ( real_len < 1 )
83  CPP_TEST_FAIL( "No counters available", 0 );
84  *len = real_len;
85 }
86 
87 /* Tests that PAPI_multiplex_init does not mess with normal operation. */
88 
89 int
91 {
92  int retval, i, EventSet = PAPI_NULL;
93  long long values[2];
94 
95  PAPI_events_len = 2;
97 
98  retval = PAPI_create_eventset( &EventSet );
99  if ( retval != PAPI_OK )
100  CPP_TEST_FAIL( "PAPI_create_eventset", retval );
101 
102  for ( i = 0; i < PAPI_events_len; i++ ) {
103  char out[PAPI_MAX_STR_LEN];
104 
105  retval = PAPI_add_event( EventSet, PAPI_events[i] );
106  if ( retval != PAPI_OK )
107  CPP_TEST_FAIL( "PAPI_add_event", retval );
109  if ( !TESTS_QUIET )
110  printf( "Added %s\n", out );
111  }
112 
113  do_stuff( );
114 
115  if ( PAPI_start( EventSet ) != PAPI_OK )
116  CPP_TEST_FAIL( "PAPI_start", retval );
117 
118  do_stuff( );
119 
120  retval = PAPI_stop( EventSet, values );
121  if ( retval != PAPI_OK )
122  CPP_TEST_FAIL( "PAPI_stop", retval );
123 
124  if ( !TESTS_QUIET ) {
125  test_print_event_header( "case1:", EventSet );
126  printf( TAB2, "case1:", values[0], values[1] );
127  }
128  retval = PAPI_cleanup_eventset( EventSet ); /* JT */
129  if ( retval != PAPI_OK )
130  CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );
131 
132  PAPI_shutdown( );
133  return ( SUCCESS );
134 }
135 
136 /* Tests that PAPI_set_multiplex() works before adding events */
137 
138 int
140 {
141  int retval, i, EventSet = PAPI_NULL;
142  long long values[2];
143 
144  PAPI_events_len = 2;
146 
147  retval = PAPI_create_eventset( &EventSet );
148  if ( retval != PAPI_OK )
149  CPP_TEST_FAIL( "PAPI_create_eventset", retval );
150 
151  /* In Component PAPI, EventSets must be assigned a component index
152  before you can fiddle with their internals.
153  0 is always the cpu component */
154  retval = PAPI_assign_eventset_component( EventSet, 0 );
155  if ( retval != PAPI_OK )
156  CPP_TEST_FAIL( "PAPI_assign_eventset_component", retval );
157 
158  retval = PAPI_set_multiplex( EventSet );
159  if ( retval == PAPI_ENOSUPP) {
160  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
161  }
162  else if ( retval != PAPI_OK )
163  CPP_TEST_FAIL( "PAPI_set_multiplex", retval );
164 
165  for ( i = 0; i < PAPI_events_len; i++ ) {
166  char out[PAPI_MAX_STR_LEN];
167 
168  retval = PAPI_add_event( EventSet, PAPI_events[i] );
169  if ( retval != PAPI_OK )
170  CPP_TEST_FAIL( "PAPI_add_event", retval );
172  if ( !TESTS_QUIET )
173  printf( "Added %s\n", out );
174  }
175 
176  do_stuff( );
177 
178  if ( PAPI_start( EventSet ) != PAPI_OK )
179  CPP_TEST_FAIL( "PAPI_start", retval );
180 
181  do_stuff( );
182 
183  retval = PAPI_stop( EventSet, values );
184  if ( retval != PAPI_OK )
185  CPP_TEST_FAIL( "PAPI_stop", retval );
186 
187  if ( !TESTS_QUIET ) {
188  test_print_event_header( "case2:", EventSet );
189  printf( TAB2, "case2:", values[0], values[1] );
190  }
191 
192  retval = PAPI_cleanup_eventset( EventSet );
193  if ( retval != PAPI_OK )
194  CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );
195 
196  PAPI_shutdown( );
197  return ( SUCCESS );
198 }
199 
200 /* Tests that PAPI_set_multiplex() works after adding events */
201 
202 int
204 {
205  int retval, i, EventSet = PAPI_NULL;
206  long long values[2];
207 
208  PAPI_events_len = 2;
210 
211  retval = PAPI_create_eventset( &EventSet );
212  if ( retval != PAPI_OK )
213  CPP_TEST_FAIL( "PAPI_create_eventset", retval );
214 
215  for ( i = 0; i < PAPI_events_len; i++ ) {
216  char out[PAPI_MAX_STR_LEN];
217 
218  retval = PAPI_add_event( EventSet, PAPI_events[i] );
219  if ( retval != PAPI_OK )
220  CPP_TEST_FAIL( "PAPI_add_event", retval );
222  if ( !TESTS_QUIET )
223  printf( "Added %s\n", out );
224  }
225 
226  retval = PAPI_set_multiplex( EventSet );
227  if ( retval == PAPI_ENOSUPP) {
228  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
229  } else if ( retval != PAPI_OK )
230  CPP_TEST_FAIL( "PAPI_set_multiplex", retval );
231 
232  do_stuff( );
233 
234  if ( PAPI_start( EventSet ) != PAPI_OK )
235  CPP_TEST_FAIL( "PAPI_start", retval );
236 
237  do_stuff( );
238 
239  retval = PAPI_stop( EventSet, values );
240  if ( retval != PAPI_OK )
241  CPP_TEST_FAIL( "PAPI_stop", retval );
242 
243  if ( !TESTS_QUIET ) {
244  test_print_event_header( "case3:", EventSet );
245  printf( TAB2, "case3:", values[0], values[1] );
246  }
247 
248  retval = PAPI_cleanup_eventset( EventSet ); /* JT */
249  if ( retval != PAPI_OK )
250  CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );
251 
252  PAPI_shutdown( );
253  return ( SUCCESS );
254 }
255 
256 /* Tests that PAPI_set_multiplex() works before adding events */
257 
258 /* Tests that PAPI_add_event() works after
259  PAPI_add_event()/PAPI_set_multiplex() */
260 
261 int
263 {
264  int retval, i, EventSet = PAPI_NULL;
265  long long values[4];
266  char out[PAPI_MAX_STR_LEN];
267 
268  PAPI_events_len = 2;
270 
271  retval = PAPI_create_eventset( &EventSet );
272  if ( retval != PAPI_OK )
273  CPP_TEST_FAIL( "PAPI_create_eventset", retval );
274 
275  i = 0;
276  retval = PAPI_add_event( EventSet, PAPI_events[i] );
277  if ( retval != PAPI_OK )
278  CPP_TEST_FAIL( "PAPI_add_event", retval );
280  printf( "Added %s\n", out );
281 
282  retval = PAPI_set_multiplex( EventSet );
283  if ( retval == PAPI_ENOSUPP) {
284  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
285  }
286  else if ( retval != PAPI_OK )
287  CPP_TEST_FAIL( "PAPI_set_multiplex", retval );
288 
289  i = 1;
290  retval = PAPI_add_event( EventSet, PAPI_events[i] );
291  if ( retval != PAPI_OK )
292  CPP_TEST_FAIL( "PAPI_add_event", retval );
294  printf( "Added %s\n", out );
295 
296  do_stuff( );
297 
298  if ( PAPI_start( EventSet ) != PAPI_OK )
299  CPP_TEST_FAIL( "PAPI_start", retval );
300 
301  do_stuff( );
302 
303  retval = PAPI_stop( EventSet, values );
304  if ( retval != PAPI_OK )
305  CPP_TEST_FAIL( "PAPI_stop", retval );
306 
307  if ( !TESTS_QUIET ) {
308  test_print_event_header( "case4:", EventSet );
309  printf( TAB2, "case4:", values[0], values[1] );
310  }
311 
312  retval = PAPI_cleanup_eventset( EventSet ); /* JT */
313  if ( retval != PAPI_OK )
314  CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );
315 
316  PAPI_shutdown( );
317  return ( SUCCESS );
318 }
319 
320 /* Tests that PAPI_read() works immediately after
321  PAPI_start() */
322 
323 int
325 {
326  int retval, i, j, EventSet = PAPI_NULL;
327  long long start_values[4] = { 0,0,0,0 }, values[4] = {0,0,0,0};
328  char out[PAPI_MAX_STR_LEN];
329 
330  PAPI_events_len = 2;
332 
333  retval = PAPI_create_eventset( &EventSet );
334  if ( retval != PAPI_OK )
335  CPP_TEST_FAIL( "PAPI_create_eventset", retval );
336 
337  /* In Component PAPI, EventSets must be assigned a component index
338  before you can fiddle with their internals.
339  0 is always the cpu component */
340 
341  retval = PAPI_assign_eventset_component( EventSet, 0 );
342  if ( retval != PAPI_OK )
343  CPP_TEST_FAIL( "PAPI_assign_eventset_component", retval );
344 
345  retval = PAPI_set_multiplex( EventSet );
346  if ( retval == PAPI_ENOSUPP) {
347  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
348  }
349  else if ( retval != PAPI_OK )
350  CPP_TEST_FAIL( "PAPI_set_multiplex", retval );
351 
352  /* Add 2 events... */
353 
354  i = 0;
355  retval = PAPI_add_event( EventSet, PAPI_events[i] );
356  if ( retval != PAPI_OK )
357  CPP_TEST_FAIL( "PAPI_add_event", retval );
359  printf( "Added %s\n", out );
360  i++;
361  retval = PAPI_add_event( EventSet, PAPI_events[i] );
362  if ( retval != PAPI_OK )
363  CPP_TEST_FAIL( "PAPI_add_event", retval );
365  printf( "Added %s\n", out );
366  i++;
367 
368  do_stuff( );
369 
370  retval = PAPI_start( EventSet );
371  if ( retval != PAPI_OK )
372  CPP_TEST_FAIL( "PAPI_start", retval );
373 
374  retval = PAPI_read( EventSet, start_values );
375  if ( retval != PAPI_OK )
376  CPP_TEST_FAIL( "PAPI_read", retval );
377 
378  do_stuff( );
379 
380  retval = PAPI_stop( EventSet, values );
381  if ( retval != PAPI_OK )
382  CPP_TEST_FAIL( "PAPI_stop", retval );
383 
384  for (j=0;j<i;j++)
385  {
386  printf("read @start counter[%d]: %lld\n", j, start_values[j]);
387  printf("read @stop counter[%d]: %lld\n", j, values[j]);
388  printf("difference counter[%d]: %lld\n ", j, values[j]-start_values[j]);
389  if (values[j]-start_values[j] < 0LL)
390  CPP_TEST_FAIL( "Difference in start and stop resulted in negative value!", 0 );
391  }
392 
393  retval = PAPI_cleanup_eventset( EventSet ); /* JT */
394  if ( retval != PAPI_OK )
395  CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );
396 
397  PAPI_shutdown( );
398  return ( SUCCESS );
399 }
400 
401 int
402 main( int argc, char **argv )
403 {
404 
405  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
406 
407  printf
408  ( "case1: Does PAPI_multiplex_init() not break regular operation?\n" );
409  case1( );
410 
411  printf( "\ncase2: Does setmpx/add work?\n" );
412  case2( );
413 
414  printf( "\ncase3: Does add/setmpx work?\n" );
415  case3( );
416 
417  printf( "\ncase4: Does add/setmpx/add work?\n" );
418  case4( );
419 
420  printf( "\ncase5: Does setmpx/add/add/start/read work?\n" );
421  case5( );
422 
423  test_pass( __FILE__, NULL, 0 );
424  exit( 0 );
425 }
int case5()
Definition: multiplex1.c:324
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define PAPI_L2_TCM
Definition: fpapi.h:142
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
Hardware info structure.
Definition: papi.h:775
#define PAPI_NULL
Definition: fpapi.h:13
int preset_PAPI_events[TOTAL_EVENTS]
Definition: multiplex1.c:24
#define PAPI_L1_ICM
Definition: fpapi.h:136
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
#define PAPI_DOM_ALL
Definition: fpapi.h:25
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define CPP_TEST_FAIL(string, retval)
Definition: multiplex1.c:30
#define PAPI_TOT_INS
Definition: fpapi.h:185
void do_stuff(void)
Definition: do_loops.c:249
#define TOTAL_EVENTS
Definition: multiplex1.c:16
static int PAPI_events_len
Definition: multiplex1.c:28
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
int power6_preset_PAPI_events[TOTAL_EVENTS]
Definition: multiplex1.c:21
#define printf
Definition: papi_test.h:125
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 case2()
Definition: multiplex1.c:139
int TESTS_QUIET
Definition: test_utils.c:11
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
#define PAPI_TOT_CYC
Definition: fpapi.h:194
void PAPI_shutdown(void)
Definition: papi.c:4357
#define TAB2
Definition: papi_test.h:113
int solaris_preset_PAPI_events[TOTAL_EVENTS]
Definition: multiplex1.c:18
int case3()
Definition: multiplex1.c:203
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define PAPI_BR_MSP
Definition: fpapi.h:181
#define PAPI_FP_INS
Definition: fpapi.h:187
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2805
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1467
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 PAPI_query_event(int EventCode)
Definition: papi.c:696
int EventSet
int PAPI_multiplex_init(void)
Definition: papi.c:2897
#define PAPI_L1_DCM
Definition: fpapi.h:135
unsigned int PAPI_events[EVENTSLEN]
Definition: derived.c:20
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3241
int PAPI_set_domain(int domain)
Definition: papi.c:5565
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:785
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2476
void test_print_event_header(char *call, int evset)
Definition: test_utils.c:645
int PAPI_start(int EventSet)
Definition: papi.c:2026
long j
Definition: iozone.c:19135
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6059
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
int case4()
Definition: multiplex1.c:262