PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
reset_multiplex.c
Go to the documentation of this file.
1 /* This file performs the same tests as the reset test
2  but does it with the events multiplexed.
3 
4  This is mostly to test perf_event, where resetting
5  multiplexed events is handled differently than grouped events.
6 
7 */
8 
9 #include <stdio.h>
10 
11 #include "papi.h"
12 #include "papi_test.h"
13 
14 #include "do_loops.h"
15 
16 int
17 main( int argc, char **argv )
18 {
19  int retval, num_tests = 9, num_events, tmp, i;
20  long long **values;
21  int EventSet = PAPI_NULL;
22  int PAPI_event, mask;
23  char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
24  int quiet;
25 
26  /* Set TESTS_QUIET variable */
27  quiet = tests_quiet( argc, argv );
28 
29  /* Init the PAPI library */
31  if ( retval != PAPI_VER_CURRENT ) {
32  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
33  }
34 
35  retval = PAPI_multiplex_init( );
36  if ( retval == PAPI_ENOSUPP) {
37  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
38  }
39  else if ( retval != PAPI_OK ) {
40  test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", retval );
41  }
42 
43 
44  /* add PAPI_TOT_CYC and one of the events in
45  PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
46  depending on the availability of the event
47  on the platform */
48  EventSet = add_two_events( &num_events, &PAPI_event, &mask );
49 
50  /* Set multiplexing on the eventset */
51 
52  retval = PAPI_set_multiplex( EventSet );
53  if ( retval != PAPI_OK) {
54  test_fail(__FILE__, __LINE__, "Setting multiplex", retval);
55  }
56 
57  retval = PAPI_event_code_to_name( PAPI_event, event_name );
58  if ( retval != PAPI_OK ) {
59  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
60  }
61  sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
62 
63  values = allocate_test_space( num_tests, num_events );
64 
65  /*===== Test 1: Start/Stop =======================*/
66 
67  retval = PAPI_start( EventSet );
68  if ( retval != PAPI_OK ) {
69  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
70  }
71 
73 
74  retval = PAPI_stop( EventSet, values[0] );
75  if ( retval != PAPI_OK ) {
76  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
77  }
78 
79  /*===== Test 2 Start/Stop =======================*/
80 
81  retval = PAPI_start( EventSet );
82  if ( retval != PAPI_OK ) {
83  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
84  }
85 
87 
88  retval = PAPI_stop( EventSet, values[1] );
89  if ( retval != PAPI_OK ) {
90  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
91  }
92 
93  /*===== Test 3: Reset/Start/Stop =======================*/
94 
95  retval = PAPI_reset( EventSet );
96  if ( retval != PAPI_OK ) {
97  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
98  }
99 
100  retval = PAPI_start( EventSet );
101  if ( retval != PAPI_OK ) {
102  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
103  }
104 
105  do_flops( NUM_FLOPS );
106 
107  retval = PAPI_stop( EventSet, values[2] );
108  if ( retval != PAPI_OK ) {
109  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
110  }
111 
112  /*===== Test 4: Start/Read =======================*/
113 
114  retval = PAPI_start( EventSet );
115  if ( retval != PAPI_OK ) {
116  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
117  }
118 
119  do_flops( NUM_FLOPS / 2 );
120 
121  retval = PAPI_read( EventSet, values[3] );
122  if ( retval != PAPI_OK ) {
123  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
124  }
125 
126  /*===== Test 5: Read =======================*/
127 
128  do_flops( NUM_FLOPS / 2 );
129 
130  retval = PAPI_read( EventSet, values[4] );
131  if ( retval != PAPI_OK ) {
132  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
133  }
134 
135  /*===== Test 6: Read/Accum =======================*/
136 
137  do_flops( NUM_FLOPS / 2 );
138 
139  retval = PAPI_read( EventSet, values[5] );
140  if ( retval != PAPI_OK ) {
141  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
142  }
143 
144  retval = PAPI_accum( EventSet, values[5] );
145 
146  if ( retval != PAPI_OK ) {
147  test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
148  }
149 
150  /*===== Test 7: Read =======================*/
151 
152  do_flops( NUM_FLOPS / 2 );
153 
154  retval = PAPI_read( EventSet, values[6] );
155  if ( retval != PAPI_OK ) {
156  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
157  }
158 
159  /*===== Test 8 Reset/Stop =======================*/
160  retval = PAPI_reset( EventSet );
161  if ( retval != PAPI_OK ) {
162  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
163  }
164 
165  do_flops( NUM_FLOPS / 2 );
166 
167  retval = PAPI_stop( EventSet, values[7] );
168  if ( retval != PAPI_OK ) {
169  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
170  }
171 
172  /*===== Test 9: Reset/Read =======================*/
173  retval = PAPI_reset( EventSet );
174  if ( retval != PAPI_OK ) {
175  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
176  }
177 
178  retval = PAPI_read( EventSet, values[8] );
179  if ( retval != PAPI_OK ) {
180  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
181  }
182 
183  remove_test_events( &EventSet, mask );
184 
185  if (!quiet) {
186  printf( "Test case: Start/Stop/Read/Accum/Reset.\n" );
187  printf( "----------------------------------------------------------------\n" );
188  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
189  printf( "Default domain is: %d (%s)\n", tmp,
190  stringify_all_domains( tmp ) );
191  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
192  printf( "Default granularity is: %d (%s)\n", tmp,
193  stringify_granularity( tmp ) );
194  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
195  printf( "-------------------------------------------------------------------------\n" );
196 
197  sprintf( add_event_str, "%s:", event_name );
198  printf( " PAPI_TOT_CYC %s\n", event_name );
199  printf( "1. start,ops,stop %10lld %10lld\n", values[0][0],
200  values[0][1] );
201  printf( "2. start,ops,stop %10lld %10lld\n", values[1][0],
202  values[1][1] );
203  printf( "3. reset,start,ops,stop %10lld %10lld\n", values[2][0],
204  values[2][1] );
205  printf( "4. start,ops/2,read %10lld %10lld\n", values[3][0],
206  values[3][1] );
207  printf( "5. ops/2,read %10lld %10lld\n", values[4][0],
208  values[4][1] );
209  printf( "6. ops/2,accum %10lld %10lld\n", values[5][0],
210  values[5][1] );
211  printf( "7. ops/2,read %10lld %10lld\n", values[6][0],
212  values[6][1] );
213  printf( "8. reset,ops/2,stop %10lld %10lld\n", values[7][0],
214  values[7][1] );
215  printf( "9. reset,read %10lld %10lld\n", values[8][0],
216  values[8][1] );
217  printf( "-------------------------------------------------------------------------\n" );
218  printf( "Verification:\n" );
219  printf( "Row 1 approximately equals rows 2 and 3 \n" );
220  printf( "Row 4 approximately equals 1/2 of row 3\n" );
221  printf( "Row 5 approximately equals twice row 4\n" );
222  printf( "Row 6 approximately equals 6 times row 4\n" );
223  printf( "Rows 7 and 8 approximately equal row 4\n" );
224  printf( "Row 9 equals 0\n" );
225  printf( "%% difference between %s 1 & 2: %.2f\n", "PAPI_TOT_CYC",
226  100.0 * ( float ) values[0][0] / ( float ) values[1][0] );
227  printf( "%% difference between %s 1 & 2: %.2f\n", add_event_str,
228  100.0 * ( float ) values[0][1] / ( float ) values[1][1] );
229  }
230 
231  for ( i = 0; i <= 1; i++ ) {
232  if ( !approx_equals
233  ( ( double ) values[0][i], ( double ) values[1][i] ) )
234  test_fail( __FILE__, __LINE__,
235  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
236  if ( !approx_equals
237  ( ( double ) values[1][i], ( double ) values[2][i] ) )
238  test_fail( __FILE__, __LINE__,
239  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
240  if ( !approx_equals
241  ( ( double ) values[2][i], ( double ) values[3][i] * 2.0 ) )
242  test_fail( __FILE__, __LINE__,
243  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
244  if ( !approx_equals
245  ( ( double ) values[2][i], ( double ) values[4][i] ) )
246  test_fail( __FILE__, __LINE__,
247  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
248  if ( !approx_equals
249  ( ( double ) values[5][i], ( double ) values[3][i] * 6.0 ) )
250  test_fail( __FILE__, __LINE__,
251  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
252  if ( !approx_equals
253  ( ( double ) values[6][i], ( double ) values[3][i] ) )
254  test_fail( __FILE__, __LINE__,
255  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
256  if ( !approx_equals
257  ( ( double ) values[7][i], ( double ) values[3][i] ) )
258  test_fail( __FILE__, __LINE__,
259  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
260  if ( values[8][i] != 0LL )
261  test_fail( __FILE__, __LINE__,
262  ( ( i == 0 ) ? "PAPI_TOT_CYC" : add_event_str ), 1 );
263  }
264 
265  test_pass( __FILE__ );
266 
267  return 0;
268 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int PAPI_event[2]
Definition: data_range.c:30
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_reset(int EventSet)
Definition: papi.c:2459
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
#define PAPI_ENOSUPP
Definition: papi.h:271
#define PAPI_NULL
Definition: papi.h:292
static int num_events
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_accum(int EventSet, long long *values)
Definition: papi.c:2745
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
int quiet
Definition: rapl_overflow.c:18
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4143
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:615
#define PAPI_DEFGRN
Definition: papi.h:434
int approx_equals(double a, double b)
Definition: test_utils.c:33
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
int num_tests
Definition: zero_fork.c:53
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_multiplex_init(void)
Definition: papi.c:2982
printf("\tTry: -i 0 -i 1 \n\n")
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
#define PAPI_DEFDOM
Definition: papi.h:432
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3333
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
#define PAPI_VER_CURRENT
Definition: papi.h:225
int main(int argc, char **argv)
List all appio events codes and names.
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201