PAPI  5.6.0.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 <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 
16 #include "papi.h"
17 #include "papi_test.h"
18 
19 #include "do_loops.h"
20 
21 /* Event to use in all cases; initialized in init_papi() */
22 
23 #define TOTAL_EVENTS 6
24 
27 };
30 };
33 };
34 
35 static int PAPI_events[TOTAL_EVENTS] = { 0, };
36 static int PAPI_events_len = 0;
37 
38 static void
39 init_papi( int *out_events, int *len )
40 {
41  int retval;
42  int i, real_len = 0;
43  int *in_events = preset_PAPI_events;
44  const PAPI_hw_info_t *hw_info;
45 
46  /* Initialize the library */
48  if ( retval != PAPI_VER_CURRENT ) {
49  test_fail(__FILE__,__LINE__, "PAPI_library_init", retval );
50  }
51 
52  hw_info = PAPI_get_hardware_info( );
53  if ( hw_info == NULL ) {
54  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
55  }
56 
57  if ( strstr( hw_info->model_string, "UltraSPARC" ) ) {
58  in_events = solaris_preset_PAPI_events;
59  }
60 
61  if ( strcmp( hw_info->model_string, "POWER6" ) == 0 ) {
62  in_events = power6_preset_PAPI_events;
63  retval = PAPI_set_domain( PAPI_DOM_ALL );
64  if ( retval != PAPI_OK )
65  test_fail(__FILE__,__LINE__, "PAPI_set_domain", retval );
66  }
67 
68  retval = PAPI_multiplex_init( );
69  if ( retval == PAPI_ENOSUPP) {
70  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
71  }
72  else if ( retval != PAPI_OK ) {
73  test_fail(__FILE__,__LINE__, "PAPI_multiplex_init", retval );
74  }
75 
76  for ( i = 0; in_events[i] != 0; i++ ) {
77  char out[PAPI_MAX_STR_LEN];
78  /* query and set up the right instruction to monitor */
79  retval = PAPI_query_event( in_events[i] );
80  if ( retval == PAPI_OK ) {
81  out_events[real_len++] = in_events[i];
82  PAPI_event_code_to_name( in_events[i], out );
83  if ( real_len == *len )
84  break;
85  } else {
86  PAPI_event_code_to_name( in_events[i], out );
87  if ( !TESTS_QUIET )
88  printf( "%s does not exist\n", out );
89  }
90  }
91 
92  if ( real_len < 1 ) {
93  if (!TESTS_QUIET) printf("Trouble adding events\n");
94  test_skip(__FILE__,__LINE__, "No counters available", 0 );
95  }
96  *len = real_len;
97 }
98 
99 /* Tests that PAPI_multiplex_init does not mess with normal operation. */
100 
101 int
102 case1( void )
103 {
104  int retval, i, EventSet = PAPI_NULL;
105  long long values[2];
106 
107  PAPI_events_len = 2;
109 
110  retval = PAPI_create_eventset( &EventSet );
111  if ( retval != PAPI_OK )
112  test_fail(__FILE__,__LINE__, "PAPI_create_eventset", retval );
113 
114  for ( i = 0; i < PAPI_events_len; i++ ) {
115  char out[PAPI_MAX_STR_LEN];
116 
117  retval = PAPI_add_event( EventSet, PAPI_events[i] );
118  if ( retval != PAPI_OK )
119  test_fail(__FILE__,__LINE__, "PAPI_add_event", retval );
121  if ( !TESTS_QUIET )
122  printf( "Added %s\n", out );
123  }
124 
125  do_stuff( );
126 
127  if ( PAPI_start( EventSet ) != PAPI_OK )
128  test_fail(__FILE__,__LINE__, "PAPI_start", retval );
129 
130  do_stuff( );
131 
132  retval = PAPI_stop( EventSet, values );
133  if ( retval != PAPI_OK )
134  test_fail(__FILE__,__LINE__, "PAPI_stop", retval );
135 
136  if ( !TESTS_QUIET ) {
137  test_print_event_header( "case1:", EventSet );
138  printf( TAB2, "case1:", values[0], values[1] );
139  }
140  retval = PAPI_cleanup_eventset( EventSet ); /* JT */
141  if ( retval != PAPI_OK )
142  test_fail(__FILE__,__LINE__, "PAPI_cleanup_eventset", retval );
143 
144  PAPI_shutdown( );
145  return ( SUCCESS );
146 }
147 
148 /* Tests that PAPI_set_multiplex() works before adding events */
149 
150 int
151 case2( void )
152 {
153  int retval, i, EventSet = PAPI_NULL;
154  long long values[2];
155 
156  PAPI_events_len = 2;
158 
159  retval = PAPI_create_eventset( &EventSet );
160  if ( retval != PAPI_OK )
161  test_fail(__FILE__,__LINE__, "PAPI_create_eventset", retval );
162 
163  /* In Component PAPI, EventSets must be assigned a component index
164  before you can fiddle with their internals.
165  0 is always the cpu component */
166  retval = PAPI_assign_eventset_component( EventSet, 0 );
167  if ( retval != PAPI_OK )
168  test_fail(__FILE__,__LINE__, "PAPI_assign_eventset_component", retval );
169 
170  retval = PAPI_set_multiplex( EventSet );
171  if ( retval == PAPI_ENOSUPP) {
172  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
173  }
174  else if ( retval != PAPI_OK )
175  test_fail(__FILE__,__LINE__, "PAPI_set_multiplex", retval );
176 
177  for ( i = 0; i < PAPI_events_len; i++ ) {
178  char out[PAPI_MAX_STR_LEN];
179 
180  retval = PAPI_add_event( EventSet, PAPI_events[i] );
181  if ( retval != PAPI_OK )
182  test_fail(__FILE__,__LINE__, "PAPI_add_event", retval );
184  if ( !TESTS_QUIET )
185  printf( "Added %s\n", out );
186  }
187 
188  do_stuff( );
189 
190  if ( PAPI_start( EventSet ) != PAPI_OK )
191  test_fail(__FILE__,__LINE__, "PAPI_start", retval );
192 
193  do_stuff( );
194 
195  retval = PAPI_stop( EventSet, values );
196  if ( retval != PAPI_OK )
197  test_fail(__FILE__,__LINE__, "PAPI_stop", retval );
198 
199  if ( !TESTS_QUIET ) {
200  test_print_event_header( "case2:", EventSet );
201  printf( TAB2, "case2:", values[0], values[1] );
202  }
203 
204  retval = PAPI_cleanup_eventset( EventSet );
205  if ( retval != PAPI_OK )
206  test_fail(__FILE__,__LINE__, "PAPI_cleanup_eventset", retval );
207 
208  PAPI_shutdown( );
209  return ( SUCCESS );
210 }
211 
212 /* Tests that PAPI_set_multiplex() works after adding events */
213 
214 int
215 case3( void )
216 {
217  int retval, i, EventSet = PAPI_NULL;
218  long long values[2];
219 
220  PAPI_events_len = 2;
222 
223  retval = PAPI_create_eventset( &EventSet );
224  if ( retval != PAPI_OK )
225  test_fail(__FILE__,__LINE__, "PAPI_create_eventset", retval );
226 
227  for ( i = 0; i < PAPI_events_len; i++ ) {
228  char out[PAPI_MAX_STR_LEN];
229 
230  retval = PAPI_add_event( EventSet, PAPI_events[i] );
231  if ( retval != PAPI_OK )
232  test_fail(__FILE__,__LINE__, "PAPI_add_event", retval );
234  if ( !TESTS_QUIET )
235  printf( "Added %s\n", out );
236  }
237 
238  retval = PAPI_set_multiplex( EventSet );
239  if ( retval == PAPI_ENOSUPP) {
240  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
241  } else if ( retval != PAPI_OK )
242  test_fail(__FILE__,__LINE__, "PAPI_set_multiplex", retval );
243 
244  do_stuff( );
245 
246  if ( PAPI_start( EventSet ) != PAPI_OK )
247  test_fail(__FILE__,__LINE__, "PAPI_start", retval );
248 
249  do_stuff( );
250 
251  retval = PAPI_stop( EventSet, values );
252  if ( retval != PAPI_OK )
253  test_fail(__FILE__,__LINE__, "PAPI_stop", retval );
254 
255  if ( !TESTS_QUIET ) {
256  test_print_event_header( "case3:", EventSet );
257  printf( TAB2, "case3:", values[0], values[1] );
258  }
259 
260  retval = PAPI_cleanup_eventset( EventSet ); /* JT */
261  if ( retval != PAPI_OK )
262  test_fail(__FILE__,__LINE__, "PAPI_cleanup_eventset", retval );
263 
264  PAPI_shutdown( );
265  return ( SUCCESS );
266 }
267 
268 /* Tests that PAPI_set_multiplex() works before adding events */
269 
270 /* Tests that PAPI_add_event() works after
271  PAPI_add_event()/PAPI_set_multiplex() */
272 
273 int
274 case4( void )
275 {
276  int retval, i, EventSet = PAPI_NULL;
277  long long values[4];
278  char out[PAPI_MAX_STR_LEN];
279 
280  PAPI_events_len = 2;
282 
283  retval = PAPI_create_eventset( &EventSet );
284  if ( retval != PAPI_OK )
285  test_fail(__FILE__,__LINE__, "PAPI_create_eventset", retval );
286 
287  i = 0;
288  retval = PAPI_add_event( EventSet, PAPI_events[i] );
289  if ( retval != PAPI_OK )
290  test_fail(__FILE__,__LINE__, "PAPI_add_event", retval );
292  if (!TESTS_QUIET) printf( "Added %s\n", out );
293 
294  retval = PAPI_set_multiplex( EventSet );
295  if ( retval == PAPI_ENOSUPP) {
296  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
297  }
298  else if ( retval != PAPI_OK )
299  test_fail(__FILE__,__LINE__, "PAPI_set_multiplex", retval );
300 
301  i = 1;
302  retval = PAPI_add_event( EventSet, PAPI_events[i] );
303  if ( retval != PAPI_OK )
304  test_fail(__FILE__,__LINE__, "PAPI_add_event", retval );
306  if (!TESTS_QUIET) printf( "Added %s\n", out );
307 
308  do_stuff( );
309 
310  if ( PAPI_start( EventSet ) != PAPI_OK )
311  test_fail(__FILE__,__LINE__, "PAPI_start", retval );
312 
313  do_stuff( );
314 
315  retval = PAPI_stop( EventSet, values );
316  if ( retval != PAPI_OK )
317  test_fail(__FILE__,__LINE__, "PAPI_stop", retval );
318 
319  if ( !TESTS_QUIET ) {
320  test_print_event_header( "case4:", EventSet );
321  printf( TAB2, "case4:", values[0], values[1] );
322  }
323 
324  retval = PAPI_cleanup_eventset( EventSet ); /* JT */
325  if ( retval != PAPI_OK )
326  test_fail(__FILE__,__LINE__, "PAPI_cleanup_eventset", retval );
327 
328  PAPI_shutdown( );
329  return ( SUCCESS );
330 }
331 
332 /* Tests that PAPI_read() works immediately after
333  PAPI_start() */
334 
335 int
336 case5( void )
337 {
338  int retval, i, j, EventSet = PAPI_NULL;
339  long long start_values[4] = { 0,0,0,0 }, values[4] = {0,0,0,0};
340  char out[PAPI_MAX_STR_LEN];
341 
342  PAPI_events_len = 2;
344 
345  retval = PAPI_create_eventset( &EventSet );
346  if ( retval != PAPI_OK )
347  test_fail(__FILE__,__LINE__, "PAPI_create_eventset", retval );
348 
349  /* In Component PAPI, EventSets must be assigned a component index
350  before you can fiddle with their internals.
351  0 is always the cpu component */
352 
353  retval = PAPI_assign_eventset_component( EventSet, 0 );
354  if ( retval != PAPI_OK )
355  test_fail(__FILE__,__LINE__, "PAPI_assign_eventset_component", retval );
356 
357  retval = PAPI_set_multiplex( EventSet );
358  if ( retval == PAPI_ENOSUPP) {
359  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
360  }
361  else if ( retval != PAPI_OK ) {
362  test_fail(__FILE__,__LINE__, "PAPI_set_multiplex", retval );
363  }
364 
365  /* Add 2 events... */
366 
367  i = 0;
368  retval = PAPI_add_event( EventSet, PAPI_events[i] );
369  if ( retval != PAPI_OK )
370  test_fail(__FILE__,__LINE__, "PAPI_add_event", retval );
372  if (!TESTS_QUIET) printf( "Added %s\n", out );
373  i++;
374  retval = PAPI_add_event( EventSet, PAPI_events[i] );
375  if ( retval != PAPI_OK )
376  test_fail(__FILE__,__LINE__, "PAPI_add_event", retval );
378  if (!TESTS_QUIET) printf( "Added %s\n", out );
379  i++;
380 
381  do_stuff( );
382 
383  retval = PAPI_start( EventSet );
384  if ( retval != PAPI_OK )
385  test_fail(__FILE__,__LINE__, "PAPI_start", retval );
386 
387  retval = PAPI_read( EventSet, start_values );
388  if ( retval != PAPI_OK )
389  test_fail(__FILE__,__LINE__, "PAPI_read", retval );
390 
391  do_stuff( );
392 
393  retval = PAPI_stop( EventSet, values );
394  if ( retval != PAPI_OK )
395  test_fail(__FILE__,__LINE__, "PAPI_stop", retval );
396 
397  for (j=0;j<i;j++) {
398  if (!TESTS_QUIET) {
399  printf("read @start counter[%d]: %lld\n",
400  j, start_values[j]);
401  printf("read @stop counter[%d]: %lld\n",
402  j, values[j]);
403  printf("difference counter[%d]: %lld\n ",
404  j, values[j]-start_values[j]);
405  }
406  if (values[j]-start_values[j] < 0LL) {
407  test_fail(__FILE__,__LINE__, "Difference in start and stop resulted in negative value!", 0 );
408  }
409  }
410 
411  retval = PAPI_cleanup_eventset( EventSet ); /* JT */
412  if ( retval != PAPI_OK )
413  test_fail(__FILE__,__LINE__, "PAPI_cleanup_eventset", retval );
414 
415  PAPI_shutdown( );
416  return ( SUCCESS );
417 }
418 
419 int
420 main( int argc, char **argv )
421 {
422 
423  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
424 
425  if (!TESTS_QUIET) {
426  printf( "case1: Does PAPI_multiplex_init() not break regular operation?\n" );
427  }
428  case1( );
429 
430  if (!TESTS_QUIET) {
431  printf( "\ncase2: Does setmpx/add work?\n" );
432  }
433  case2( );
434 
435  if (!TESTS_QUIET) {
436  printf( "\ncase3: Does add/setmpx work?\n" );
437  }
438  case3( );
439 
440  if (!TESTS_QUIET) {
441  printf( "\ncase4: Does add/setmpx/add work?\n" );
442  }
443  case4( );
444 
445  if (!TESTS_QUIET) {
446  printf( "\ncase5: Does setmpx/add/add/start/read work?\n" );
447  }
448  case5( );
449 
450  test_pass( __FILE__ );
451 
452  return 0;
453 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_L2_TCM
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
Hardware info structure.
Definition: papi.h:780
#define PAPI_L1_DCM
int preset_PAPI_events[TOTAL_EVENTS]
Definition: multiplex1.c:31
#define PAPI_ENOSUPP
Definition: papi.h:271
#define PAPI_NULL
Definition: papi.h:292
void do_stuff(void)
Definition: do_loops.c:256
void test_print_event_header(const char *call, int evset)
Definition: test_utils.c:580
#define PAPI_TOT_INS
#define TOTAL_EVENTS
Definition: multiplex1.c:23
#define PAPI_DOM_ALL
Definition: papi.h:303
static int PAPI_events_len
Definition: multiplex1.c:36
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
#define SUCCESS
Definition: do_loops.h:5
#define PAPI_BR_MSP
int power6_preset_PAPI_events[TOTAL_EVENTS]
Definition: multiplex1.c:28
int int argc
Definition: iozone.c:1609
int case2(void)
Definition: multiplex1.c:151
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
static void init_papi(int *out_events, int *len)
Definition: multiplex1.c:39
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
void PAPI_shutdown(void)
Definition: papi.c:4461
#define PAPI_TOT_CYC
#define TAB2
Definition: papi_test.h:89
int solaris_preset_PAPI_events[TOTAL_EVENTS]
Definition: multiplex1.c:25
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1526
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
#define PAPI_L1_ICM
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
goto out
Definition: pscanf.h:20
int case4(void)
Definition: multiplex1.c:274
int PAPI_query_event(int EventCode)
Definition: papi.c:684
int PAPI_multiplex_init(void)
Definition: papi.c:2982
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
int case5(void)
Definition: multiplex1.c:336
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
unsigned int PAPI_events[EVENTSLEN]
Definition: derived.c:13
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3333
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int PAPI_set_domain(int domain)
Definition: papi.c:5688
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:790
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int PAPI_start(int EventSet)
Definition: papi.c:2096
long j
Definition: iozone.c:19135
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
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:225
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
int main(int argc, char **argv)
List all appio events codes and names.
int case1(void)
Definition: multiplex1.c:102
int case3(void)
Definition: multiplex1.c:215
#define PAPI_FP_INS