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