PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
do_loops.c
Go to the documentation of this file.
1 /* Compile me with -O0 or else you'll get none. */
2 
3 #include "papi_test.h"
4 
6 volatile int buf_dummy = 0;
7 volatile int *flush = NULL;
8 volatile int flush_dummy = 0;
9 volatile double a = 0.5, b = 2.2;
10 
11 void
12 do_reads( int n )
13 {
14  int i, retval;
15  static int fd = -1;
16  char buf;
17 
18  if ( fd == -1 ) {
19  fd = open( "/dev/zero", O_RDONLY );
20  if ( fd == -1 ) {
21  perror( "open(/dev/zero)" );
22  exit( 1 );
23  }
24  }
25 
26  for ( i = 0; i < n; i++ ) {
27  retval = ( int ) read( fd, &buf, sizeof ( buf ) );
28  if ( retval != sizeof ( buf ) ) {
29  if ( retval < 0 )
30  perror( "/dev/zero cannot be read" );
31  else
32  fprintf( stderr,
33  "/dev/zero cannot be read: only got %d bytes.\n",
34  retval );
35  exit( 1 );
36  }
37  }
38 }
39 
40 void
41 fdo_reads( int *n )
42 {
43  do_reads( *n );
44 }
45 
46 void
47 fdo_reads_( int *n )
48 {
49  do_reads( *n );
50 }
51 
52 void
53 fdo_reads__( int *n )
54 {
55  do_reads( *n );
56 }
57 
58 void
59 FDO_READS( int *n )
60 {
61  do_reads( *n );
62 }
63 
64 void
65 _FDO_READS( int *n )
66 {
67  do_reads( *n );
68 }
69 
70 void
71 do_flops( int n )
72 {
73  int i;
74  double c = 0.11;
75 
76  for ( i = 0; i < n; i++ ) {
77  c += a * b;
78  }
79  dummy( ( void * ) &c );
80 }
81 
82 void
83 fdo_flops( int *n )
84 {
85  do_flops( *n );
86 }
87 
88 void
89 fdo_flops_( int *n )
90 {
91  do_flops( *n );
92 }
93 
94 void
95 fdo_flops__( int *n )
96 {
97  do_flops( *n );
98 }
99 
100 void
101 FDO_FLOPS( int *n )
102 {
103  do_flops( *n );
104 }
105 
106 void
107 _FDO_FLOPS( int *n )
108 {
109  do_flops( *n );
110 }
111 
112 void
113 do_misses( int n, int bytes )
114 {
115  register int i, j, tmp = buf_dummy, len = bytes / ( int ) sizeof ( int );
116  dummy( ( void * ) buf );
117  dummy( ( void * ) &buf_dummy );
118  assert( len <= CACHE_FLUSH_BUFFER_SIZE_INTS );
119  for ( j = 0; j < n; j++ ) {
120  for ( i = 0; i < len; i++ ) {
121  /* We need to read, modify, write here to look
122  out for the write allocate policies. */
123  buf[i] += tmp;
124  /* Fake out some naive prefetchers */
125  buf[len - 1 - i] -= tmp;
126  }
127  tmp += len;
128  }
129  buf_dummy = tmp;
130  dummy( ( void * ) buf );
131  dummy( ( void * ) &buf_dummy );
132 }
133 
134 void
135 fdo_misses( int *n, int *size )
136 {
137  do_misses( *n, *size );
138 }
139 
140 void
141 fdo_misses_( int *n, int *size )
142 {
143  do_misses( *n, *size );
144 }
145 
146 void
147 fdo_misses__( int *n, int *size )
148 {
149  do_misses( *n, *size );
150 }
151 
152 void
153 FDO_MISSES( int *n, int *size )
154 {
155  do_misses( *n, *size );
156 }
157 
158 void
159 _FDO_MISSES( int *n, int *size )
160 {
161  do_misses( *n, *size );
162 }
163 
164 void
165 do_flush( void )
166 {
167  register int i;
168  if ( flush == NULL )
169  flush = ( int * ) malloc( ( 1024 * 1024 * 16 ) * sizeof ( int ) );
170  if ( !flush )
171  return;
172 
173  dummy( ( void * ) flush );
174  for ( i = 0; i < ( 1024 * 1024 * 16 ); i++ ) {
175  flush[i] += flush_dummy;
176  }
177  flush_dummy++;
178  dummy( ( void * ) flush );
179  dummy( ( void * ) &flush_dummy );
180 }
181 
182 void
183 fdo_flush( void )
184 {
185  do_flush( );
186 }
187 
188 void
189 fdo_flush_( void )
190 {
191  do_flush( );
192 }
193 
194 void
195 fdo_flush__( void )
196 {
197  do_flush( );
198 }
199 
200 void
201 FDO_FLUSH( void )
202 {
203  do_flush( );
204 }
205 
206 void
207 _FDO_FLUSH( void )
208 {
209  do_flush( );
210 }
211 
212 void
214 {
216 }
217 
218 void
220 {
221  do_l1misses( *n );
222 }
223 
224 void
226 {
227  do_l1misses( *n );
228 }
229 
230 void
232 {
233  do_l1misses( *n );
234 }
235 
236 void
238 {
239  do_l1misses( *n );
240 }
241 
242 void
244 {
245  do_l1misses( *n );
246 }
247 
248 void
249 do_stuff( void )
250 {
251  static int loops = 0;
252 
253  if ( loops == 0 ) {
254  struct timeval now, then;
255  gettimeofday( &then, NULL );
256  do {
257  do_flops( NUM_FLOPS );
258  do_reads( NUM_READS );
259  do_misses( 1, 1024 * 1024 );
260  gettimeofday( &now, NULL );
261  loops++;
262  } while ( now.tv_sec - then.tv_sec < NUM_WORK_SECONDS );
263  } else {
264  int i = 0;
265  do {
266  do_flops( NUM_FLOPS );
267  do_reads( NUM_READS );
268  do_misses( 1, 1024 * 1024 );
269  i++;
270  } while ( i < loops );
271  }
272 }
273 
274 void
275 do_stuff_( void )
276 {
277  do_stuff( );
278 }
279 
280 void
281 do_stuff__( void )
282 {
283  do_stuff( );
284 }
285 
286 void
287 DO_STUFF( void )
288 {
289  do_stuff( );
290 }
291 
292 void
293 _DO_STUFF( void )
294 {
295  do_stuff( );
296 }
void do_stuff__(void)
Definition: do_loops.c:281
void fdo_flush(void)
Definition: do_loops.c:183
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:225
#define NUM_FLOPS
volatile int flush_dummy
Definition: do_loops.c:8
void _DO_STUFF(void)
Definition: do_loops.c:293
void _FDO_L1MISSES(int *n)
Definition: do_loops.c:243
void do_reads(int n)
Definition: do_loops.c:12
void fdo_l1misses(int *n)
Definition: do_loops.c:219
void FDO_READS(int *n)
Definition: do_loops.c:59
void FDO_FLOPS(int *n)
Definition: do_loops.c:101
void fdo_misses__(int *n, int *size)
Definition: do_loops.c:147
void do_stuff(void)
Definition: do_loops.c:249
int fd
Definition: iozone.c:1291
void _FDO_FLOPS(int *n)
Definition: do_loops.c:107
double c
Definition: multiplex.c:22
void do_l1misses(int n)
Definition: do_loops.c:213
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
int dummy
Definition: iozone.c:19741
volatile int * flush
Definition: do_loops.c:7
void DO_STUFF(void)
Definition: do_loops.c:287
void fdo_l1misses__(int *n)
Definition: do_loops.c:231
void _FDO_FLUSH(void)
Definition: do_loops.c:207
void do_stuff_(void)
Definition: do_loops.c:275
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:184
int i
Definition: fileop.c:140
void fdo_flops__(int *n)
Definition: do_loops.c:95
void FDO_FLUSH(void)
Definition: do_loops.c:201
char buf[200]
Definition: iozone.c:19609
void fdo_l1misses_(int *n)
Definition: do_loops.c:225
#define NUM_WORK_SECONDS
Definition: test_utils.h:1
char *long long size
Definition: iozone.c:12023
void do_misses(int n, int bytes)
Definition: do_loops.c:113
void fdo_reads_(int *n)
Definition: do_loops.c:47
void fdo_flush_(void)
Definition: do_loops.c:189
#define CACHE_FLUSH_BUFFER_SIZE_INTS
Definition: test_utils.h:12
void FDO_L1MISSES(int *n)
Definition: do_loops.c:237
void fdo_flush__(void)
Definition: do_loops.c:195
void fdo_misses(int *n, int *size)
Definition: do_loops.c:135
void do_flops(int n)
Definition: multiplex.c:23
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
void do_flush(void)
Definition: do_loops.c:165
void fdo_reads__(int *n)
Definition: do_loops.c:53
int
Definition: iozone.c:18528
void _FDO_MISSES(int *n, int *size)
Definition: do_loops.c:159
void _FDO_READS(int *n)
Definition: do_loops.c:65
void fdo_misses_(int *n, int *size)
Definition: do_loops.c:141
void fdo_flops_(int *n)
Definition: do_loops.c:89
long j
Definition: iozone.c:19135
void fdo_reads(int *n)
Definition: do_loops.c:41
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
#define L1_MISS_BUFFER_SIZE_INTS
Definition: test_utils.h:11
#define NUM_READS
Definition: test_utils.h:4
void fdo_flops(int *n)
Definition: do_loops.c:83
void FDO_MISSES(int *n, int *size)
Definition: do_loops.c:153
volatile int buf_dummy
Definition: do_loops.c:6
void exit()
int n
Definition: mendes-alt.c:164