PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tenth.c
Go to the documentation of this file.
1 /*
2 * File: tenth.c
3 * Mods: Maynard Johnson
4 * maynardj@us.ibm.com
5 */
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 
10 #include "papi.h"
11 #include "papi_test.h"
12 
13 #include "do_loops.h"
14 
15 #define ITERS 100
16 
17 /* This file performs the following test: start, stop and timer functionality for
18  PAPI_L1_TCM derived event
19 
20  - They are counted in the default counting domain and default
21  granularity, depending on the platform. Usually this is
22  the user domain (PAPI_DOM_USER) and thread context (PAPI_GRN_THR).
23  - Get us.
24  - Start counters
25  - Do flops
26  - Stop and read counters
27  - Get us.
28 */
29 
30 
31 #if defined(sun) && defined(sparc)
32 #define CACHE_LEVEL "PAPI_L2_TCM"
33 #define EVT1 PAPI_L2_TCM
34 #define EVT2 PAPI_L2_TCA
35 #define EVT3 PAPI_L2_TCH
36 #define EVT1_STR "PAPI_L2_TCM"
37 #define EVT2_STR "PAPI_L2_TCA"
38 #define EVT3_STR "PAPI_L2_TCH"
39 #define MASK1 MASK_L2_TCM
40 #define MASK2 MASK_L2_TCA
41 #define MASK3 MASK_L2_TCH
42 #else
43 #if defined(__powerpc__)
44 #define CACHE_LEVEL "PAPI_L1_DCA"
45 #define EVT1 PAPI_L1_DCA
46 #define EVT2 PAPI_L1_DCW
47 #define EVT3 PAPI_L1_DCR
48 #define EVT1_STR "PAPI_L1_DCA"
49 #define EVT2_STR "PAPI_L1_DCW"
50 #define EVT3_STR "PAPI_L1_DCR"
51 #define MASK1 MASK_L1_DCA
52 #define MASK2 MASK_L1_DCW
53 #define MASK3 MASK_L1_DCR
54 #else
55 #define CACHE_LEVEL "PAPI_L1_TCM"
56 #define EVT1 PAPI_L1_TCM
57 #define EVT2 PAPI_L1_ICM
58 #define EVT3 PAPI_L1_DCM
59 #define EVT1_STR "PAPI_L1_TCM"
60 #define EVT2_STR "PAPI_L1_ICM"
61 #define EVT3_STR "PAPI_L1_DCM"
62 #define MASK1 MASK_L1_TCM
63 #define MASK2 MASK_L1_ICM
64 #define MASK3 MASK_L1_DCM
65 #endif
66 #endif
67 
68 
69 int
70 main( int argc, char **argv )
71 {
72  int retval, num_tests = 30, tmp;
73  int EventSet1 = PAPI_NULL;
74  int EventSet2 = PAPI_NULL;
75  int EventSet3 = PAPI_NULL;
76  int mask1 = MASK1;
77  int mask2 = MASK2;
78  int mask3 = MASK3;
79  int num_events1;
80  int num_events2;
81  int num_events3;
82  long long **values;
83  int i, j;
84  long long min[3];
85  long long max[3];
86  long long sum[3];
87  int quiet;
88 
89  /* Set TESTS_QUIET variable */
90  quiet = tests_quiet( argc, argv );
91 
93  if ( retval != PAPI_VER_CURRENT ) {
94  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
95  }
96 
97  /* Make sure that required resources are available */
98  /* Skip (don't fail!) if they are not */
99  retval = PAPI_query_event( EVT1 );
100  if ( retval != PAPI_OK ) {
101  test_skip( __FILE__, __LINE__, EVT1_STR, retval );
102  }
103 
104  retval = PAPI_query_event( EVT2 );
105  if ( retval != PAPI_OK ) {
106  test_skip( __FILE__, __LINE__, EVT2_STR, retval );
107  }
108 
109  retval = PAPI_query_event( EVT3 );
110  if ( retval != PAPI_OK ) {
111  test_skip( __FILE__, __LINE__, EVT3_STR, retval );
112  }
113 
114  EventSet1 = add_test_events( &num_events1, &mask1, 1 );
115  EventSet2 = add_test_events( &num_events2, &mask2, 1 );
116  EventSet3 = add_test_events( &num_events3, &mask3, 1 );
117 
118  values = allocate_test_space( num_tests, 1 );
119 
120  /* Warm me up */
121  do_l1misses( ITERS );
122  do_misses( 1, 1024 * 1024 * 4 );
123 
124  for ( i = 0; i < 10; i++ ) {
125  retval = PAPI_start( EventSet1 );
126  if ( retval != PAPI_OK )
127  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
128 
129  do_l1misses( ITERS );
130  do_misses( 1, 1024 * 1024 * 4 );
131 
132  retval = PAPI_stop( EventSet1, values[( i * 3 ) + 0] );
133  if ( retval != PAPI_OK )
134  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
135 
136  retval = PAPI_start( EventSet2 );
137  if ( retval != PAPI_OK )
138  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
139 
140  do_l1misses( ITERS );
141  do_misses( 1, 1024 * 1024 * 4 );
142 
143  retval = PAPI_stop( EventSet2, values[( i * 3 ) + 1] );
144  if ( retval != PAPI_OK )
145  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
146 
147  retval = PAPI_start( EventSet3 );
148  if ( retval != PAPI_OK )
149  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
150 
151  do_l1misses( ITERS );
152  do_misses( 1, 1024 * 1024 * 4 );
153 
154  retval = PAPI_stop( EventSet3, values[( i * 3 ) + 2] );
155  if ( retval != PAPI_OK )
156  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
157  }
158 
159  remove_test_events( &EventSet1, mask1 );
160  remove_test_events( &EventSet2, mask2 );
161  remove_test_events( &EventSet3, mask3 );
162 
163  for ( j = 0; j < 3; j++ ) {
164  min[j] = 65535;
165  max[j] = sum[j] = 0;
166  }
167  for ( i = 0; i < 10; i++ ) {
168  for ( j = 0; j < 3; j++ ) {
169  if ( min[j] > values[( i * 3 ) + j][0] )
170  min[j] = values[( i * 3 ) + j][0];
171  if ( max[j] < values[( i * 3 ) + j][0] )
172  max[j] = values[( i * 3 ) + j][0];
173  sum[j] += values[( i * 3 ) + j][0];
174  }
175  }
176 
177  if ( !quiet ) {
178  printf( "Test case 10: start, stop for derived event %s.\n",
179  CACHE_LEVEL );
180  printf( "--------------------------------------------------------\n" );
181  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
182  printf( "Default domain is: %d (%s)\n", tmp,
184  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
185  printf( "Default granularity is: %d (%s)\n", tmp,
187  printf( "Using %d iterations of c += a*b\n", ITERS );
188  printf( "Repeated 10 times\n" );
189  printf
190  ( "-------------------------------------------------------------------------\n" );
191 /*
192  for (i=0;i<10;i++) {
193  printf("Test type : %12s%13s%13s\n", "1", "2", "3");
194  printf(TAB3, EVT1_STR, values[(i*3)+0][0], (long long)0, (long long)0);
195  printf(TAB3, EVT2_STR, (long long)0, values[(i*3)+1][0], (long long)0);
196  printf(TAB3, EVT3_STR, (long long)0, (long long)0, values[(i*3)+2][0]);
197  printf
198  ("-------------------------------------------------------------------------\n");
199  }
200 */
201  printf( "Test type : %12s%13s%13s\n", "min", "max", "sum" );
202  printf( TAB3, EVT1_STR, min[0], max[0], sum[0] );
203  printf( TAB3, EVT2_STR, min[1], max[1], sum[1] );
204  printf( TAB3, EVT3_STR, min[2], max[2], sum[2] );
205  printf
206  ( "-------------------------------------------------------------------------\n" );
207  printf( "Verification:\n" );
208 #if defined(sun) && defined(sparc)
209  printf( TAB1, "Sum 1 approximately equals sum 2 - sum 3 or",
210  ( sum[1] - sum[2] ) );
211 #else
212  printf( TAB1, "Sum 1 approximately equals sum 2 + sum 3 or",
213  ( sum[1] + sum[2] ) );
214 #endif
215  }
216 
217  {
218  long long tmin, tmax;
219 
220 #if defined(sun) && defined(sparc)
221  tmax = ( long long ) ( sum[1] - sum[2] );
222 #else
223  tmax = ( long long ) ( sum[1] + sum[2] );
224 #endif
225 
226  if (!quiet) {
227  printf( "percent error: %f\n",
228  (( float ) abs( ( int ) ( tmax - sum[0] ) ) /
229  (float) sum[0] ) * 100.0 );
230  }
231  tmin = ( long long ) ( ( double ) tmax * 0.8 );
232  tmax = ( long long ) ( ( double ) tmax * 1.2 );
233  if ( sum[0] > tmax || sum[0] < tmin ) {
234  test_fail( __FILE__, __LINE__, CACHE_LEVEL, 1 );
235  }
236  }
237 
238  test_pass( __FILE__ );
239 
240  return 0;
241 }
#define EVT3_STR
Definition: tenth.c:61
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int mask1
Definition: zero_fork.c:48
#define EVT2_STR
Definition: tenth.c:60
off64_t max
Definition: libasync.c:331
#define EVT2
Definition: tenth.c:57
#define MASK2
Definition: tenth.c:63
void test_pass(const char *filename)
Definition: test_utils.c:432
#define EVT1_STR
Definition: tenth.c:59
#define MASK1
Definition: tenth.c:62
#define EVT3
Definition: tenth.c:58
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
#define TAB3
Definition: papi_test.h:90
#define PAPI_NULL
Definition: papi.h:292
int num_events1
Definition: zero_fork.c:49
#define TAB1
Definition: papi_test.h:88
return PAPI_OK
Definition: linux-nvml.c:497
void do_l1misses(int n)
Definition: do_loops.c:220
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_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
void do_misses(int n, int bytes)
Definition: do_loops.c:120
#define PAPI_DEFGRN
Definition: papi.h:434
long long
Definition: iozone.c:19827
#define min(x, y)
Definition: darwin-common.h:4
int EventSet2
Definition: rapl_overflow.c:16
#define EVT1
Definition: tenth.c:56
int num_tests
Definition: zero_fork.c:53
#define ITERS
Definition: tenth.c:15
int PAPI_query_event(int EventCode)
Definition: papi.c:684
#define MASK3
Definition: tenth.c:64
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_start(int EventSet)
Definition: papi.c:2096
long j
Definition: iozone.c:19135
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
#define CACHE_LEVEL
Definition: tenth.c:55
int add_test_events(int *number, int *mask, int allow_derived)
Definition: test_utils.c:152
int EventSet1
Definition: zero_fork.c:47