-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiozone_test.c
645 lines (560 loc) · 14.8 KB
/
iozone_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
#define _GNU_SOURCE
#include <sys/mman.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <sys/times.h>
#include <sys/file.h>
#include <sys/resource.h>
#include <sys/shm.h>
long long page_size = 4096;
char *mainbuffer;
off64_t offset64 = 0;
static double time_so_far(void)
{
struct timeval tp;
if (gettimeofday(&tp, (struct timezone *) NULL) == -1)
perror("gettimeofday");
printf("Time: %f\n",((double) (tp.tv_sec)) +
(((double) tp.tv_usec) * 0.000001 ));
return ((double) (tp.tv_sec)) +
(((double) tp.tv_usec) * 0.000001 );
}
/************************************************************************/
/* read_perf_test */
/* Read and re-fread test */
/************************************************************************/
void
read_perf_test(unsigned long kilo64,long long reclen,long long *data1,long long *data2)
{
double starttime2;
double compute_val = (double)0;
double readtime[2];
double walltime[2], cputime[2];
long long j;
long long traj_size;
unsigned long i,numrecs64,traj_offset;
unsigned long lock_offset=0;
long long Index = 0;
unsigned long long readrate[2];
unsigned long filebytes64;
volatile char *buffer1;
char *nbuff;
int fd,open_flags;
int test_foo,ltest;
long wval;
double qtime_start,qtime_stop;
double hist_time;
unsigned long r_traj_ops_completed=0;
unsigned long r_traj_bytes_completed=0;
long long *gc=0;
char *filename = "/mnt/ramdisk/test1";
size_t len = reclen;
struct timespec start, end;
long long time;
hist_time=qtime_start=qtime_stop=0;
traj_offset=0;
test_foo=0;
numrecs64 = (kilo64*1024)/reclen;
open_flags = O_RDONLY;
filebytes64 = numrecs64*reclen;
fd = 0;
// mainbuffer = (char *)malloc(4 * 1024 * 4096);
/*
* begin real testing
*/
ltest=3;
printf("%s: filename %s, test %d, reclen %lld, numrecs64 %llu, filebytes64 %llu\n", __func__, filename, ltest, reclen, numrecs64, filebytes64);
// fd = open(filename, open_flags,0640);
for( j=0; j<ltest; j++ )
{
// lseek(fd,0,SEEK_SET);
if((fd = open(filename, open_flags,0))<0)
{
printf("\nCan not open temporary file %s for read\n",filename);
perror("open");
exit(58);
}
printf("fd: %d, reclen %lu\n", fd, reclen);
fsync(fd);
/*
* Need to prime the instruction cache & TLB
*/
nbuff=mainbuffer;
// read(fd, (void *)nbuff, (size_t)reclen);
// if(fetchon)
// fetchit(nbuff,reclen);
if(read(fd, (void *)nbuff, 4096) != reclen)
{
#ifdef _64BIT_ARCH_
printf("\nError reading block %d %llx\n", 0,
(unsigned long long)nbuff);
#else
printf("\nError reading block %d %lx\n", 0,
(long)nbuff);
#endif
perror("read");
exit(60);
}
lseek(fd,0,SEEK_SET);
nbuff=mainbuffer;
starttime2 = time_so_far();
compute_val=(double)0;
r_traj_ops_completed=0;
r_traj_bytes_completed=0;
clock_gettime(CLOCK_MONOTONIC, &start);
for(i=0; i<numrecs64; i++)
{
wval=read((int)fd, (void*)nbuff, 4096);
if(wval != reclen)
{
printf("\nError reading block %lld %llx\n", i,
(unsigned long long)nbuff);
perror("read");
exit(61);
}
r_traj_ops_completed++;
r_traj_bytes_completed+=reclen;
}
clock_gettime(CLOCK_MONOTONIC, &end);
time = (end.tv_sec - start.tv_sec) * 1e9 + (end.tv_nsec - start.tv_nsec);
printf("%lld ns\n", time);
readtime[j] = ((time_so_far() - starttime2))-compute_val;
if(readtime[j] < (double).000001)
{
readtime[j]= (double)0.000001;
}
fsync(fd);
close(fd);
}
filebytes64=r_traj_bytes_completed;
printf("%s: completed %llu\n", __func__, filebytes64);
for(j=0;j<ltest;j++)
{
readrate[j] =
(unsigned long long) ((double) filebytes64 / readtime[j]);
printf("%s: ltest %d readrate %llu\n", __func__, j, readrate[j]);
}
}
void
write_perf_test(unsigned long kilo64,long long reclen,long long *data1,long long *data2)
{
double starttime2;
double compute_val = (double)0;
double readtime[2];
double walltime[2], cputime[2];
long long j;
long long traj_size;
unsigned long i,numrecs64,traj_offset;
unsigned long lock_offset=0;
long long Index = 0;
unsigned long long readrate[2];
unsigned long filebytes64;
volatile char *buffer1;
char *nbuff;
int fd,open_flags;
int test_foo,ltest;
long wval;
double qtime_start,qtime_stop;
double hist_time;
unsigned long r_traj_ops_completed=0;
unsigned long r_traj_bytes_completed=0;
long long *gc=0;
char *filename = "/mnt/ramdisk/test1";
size_t len = reclen;
struct timespec start, end;
long long time;
hist_time=qtime_start=qtime_stop=0;
traj_offset=0;
test_foo=0;
numrecs64 = (kilo64*1024)/reclen;
open_flags = O_RDWR | O_CREAT;
filebytes64 = numrecs64*reclen;
fd = 0;
// posix_memalign(&mainbuffer, (4 * 1024 * 4096), (4 * 1024 *4096));
/*
* begin real testing
*/
ltest=3;
printf("%s: filename %s, test %d, reclen %lld, numrecs64 %llu, filebytes64 %llu\n", __func__, filename, ltest, reclen, numrecs64, filebytes64);
// fd = open(filename, open_flags,0640);
for( j=0; j<ltest; j++ )
{
// lseek(fd,0,SEEK_SET);
if((fd = open(filename, open_flags,0))<0)
{
printf("\nCan not open temporary file %s for read\n",filename);
perror("open");
exit(58);
}
printf("fd: %d, reclen %lu\n", fd, reclen);
fsync(fd);
/*
* Need to prime the instruction cache & TLB
*/
nbuff=mainbuffer;
// read(fd, (void *)nbuff, (size_t)reclen);
// if(fetchon)
// fetchit(nbuff,reclen);
if(write(fd, (void *)nbuff, 4096) != reclen)
{
#ifdef _64BIT_ARCH_
printf("\nError writing block %d %llx\n", 0,
(unsigned long long)nbuff);
#else
printf("\nError writing block %d %lx\n", 0,
(long)nbuff);
#endif
perror("read");
exit(60);
}
lseek(fd,0,SEEK_SET);
nbuff=mainbuffer;
starttime2 = time_so_far();
compute_val=(double)0;
r_traj_ops_completed=0;
r_traj_bytes_completed=0;
clock_gettime(CLOCK_MONOTONIC, &start);
for(i=0; i<numrecs64; i++)
{
wval=write((int)fd, (void*)nbuff, 4096);
if(wval != reclen)
{
printf("\nError writing block %lld %llx\n", i,
(unsigned long long)nbuff);
perror("read");
exit(61);
}
r_traj_ops_completed++;
r_traj_bytes_completed+=reclen;
}
clock_gettime(CLOCK_MONOTONIC, &end);
time = (end.tv_sec - start.tv_sec) * 1e9 + (end.tv_nsec - start.tv_nsec);
printf("%lld ns\n", time);
readtime[j] = ((time_so_far() - starttime2))-compute_val;
if(readtime[j] < (double).000001)
{
readtime[j]= (double)0.000001;
}
fsync(fd);
close(fd);
}
filebytes64=r_traj_bytes_completed;
printf("%s: completed %llu\n", __func__, filebytes64);
for(j=0;j<ltest;j++)
{
readrate[j] =
(unsigned long long) ((double) filebytes64 / readtime[j]);
printf("%s: ltest %d writerate %llu\n", __func__, j, readrate[j]);
}
}
/************************************************************************/
/* write_perf_test () */
/* Write and re-write test */
/************************************************************************/
void write_perf_test1(off64_t kilo64,long long reclen ,long long *data1,long long *data2)
{
double starttime1;
double writetime[2];
double walltime[2], cputime[2];
double qtime_start,qtime_stop;
double hist_time;
double compute_val = (double)0;
long long i,j;
off64_t numrecs64,traj_offset;
off64_t lock_offset=0;
long long Index = 0;
long long file_flags = 0;
long long traj_size;
unsigned long long writerate[2];
off64_t filebytes64;
int ltest;
char *maddr;
char *wmaddr,*free_addr;
char *pbuff;
char *nbuff;
int fd,wval;
int notruncate = 1;
unsigned long w_traj_ops_completed=0;
unsigned long w_traj_bytes_completed=0;
char *filename = "/mnt/ramdisk/test1";
int test_foo;
nbuff=wmaddr=free_addr=0;
traj_offset=0;
test_foo=0;
hist_time=qtime_start=qtime_stop=0;
maddr=0;
pbuff=mainbuffer;
numrecs64 = (kilo64*1024)/reclen;
filebytes64 = numrecs64*reclen;
fd = 0;
file_flags = O_RDWR;
/* Sanity check */
/* Some filesystems do not behave correctly and fail
* when this sequence is performned. This is a very
* bad thing. It breaks many applications and lurks
* around quietly. This code should never get
* triggered, but in the case of running iozone on
* an NFS client, the filesystem type on the server
* that is being exported can cause this failure.
* If this failure happens, then the NFS client is
* going to going to have problems, but the acutal
* problem is the filesystem on the NFS server.
* It's not NFS, it's the local filesystem on the
* NFS server that is not correctly permitting
* the sequence to function.
*/
/* _SUA_ Services for Unix Applications, under Windows
does not have a truncate, so this must be skipped */
if((fd = open(filename, (int)O_CREAT|O_RDWR,0))<0)
{
printf("\nCan not open temp file: %s\n",
filename);
perror("open");
exit(44);
}
if(!notruncate)
{
wval=ftruncate(fd,0);
if(wval < 0)
{
printf("\n\nSanity check failed. Do not deploy this filesystem in a production environment !\n");
exit(44);
}
close(fd);
}
/* Sanity check */
ltest=3;
for( j=0; j<ltest; j++)
{
if(j==0)
{
if(!notruncate)
{
if((fd = creat(filename, 0640))<0)
{
printf("\nCan not create temp file: %s\n",
filename);
perror("creat");
exit(42);
}
}
}
if(fd)
close(fd);
if((fd = open(filename, (int)file_flags,0))<0)
{
printf("\nCan not open temp file: %s\n",
filename);
perror("open");
exit(44);
}
wval=fsync(fd);
if(wval==-1){
perror("fsync");
}
pbuff=mainbuffer;
starttime1 = time_so_far();
compute_val=(double)0;
w_traj_ops_completed=0;
w_traj_bytes_completed=0;
for(i=0; i<numrecs64; i++){
wval=write(fd, pbuff, (size_t ) reclen);
if(wval != reclen)
{
#ifdef NO_PRINT_LLD
printf("\nError writing block %ld, fd= %d\n", i,
fd);
#else
printf("\nError writing block %lld, fd= %d\n", i,
fd);
#endif
if(wval == -1)
perror("write");
}
w_traj_ops_completed++;
w_traj_bytes_completed+=reclen;
}
writetime[j] = ((time_so_far() - starttime1))
-compute_val;
if(writetime[j] < (double).000001)
{
writetime[j]=(double).000001;
}
wval=close(fd);
if(wval==-1){
perror("close");
}
}
filebytes64=w_traj_bytes_completed;
for(j=0;j<ltest;j++)
{
writerate[j] =
(unsigned long long) ((double) filebytes64 / writetime[j]);
printf("%s: ltest %d writerate %llu\n", __func__, j, writerate[j]);
}
}
/************************************************************************/
/* random_perf_test */
/* Random read and write test */
/************************************************************************/
void random_perf_test(off64_t kilo64,long long reclen,long long *data1,long long *data2)
{
double randreadtime[2];
double starttime2;
double walltime[2], cputime[2];
double compute_val = (double)0;
unsigned long long big_rand;
long long j;
off64_t i,numrecs64;
long long Index=0;
int flags;
unsigned long long randreadrate[2];
off64_t filebytes64;
off64_t lock_offset=0;
volatile char *buffer1;
char *wmaddr,*nbuff;
char *maddr,*free_addr;
int fd,wval;
long long *recnum= 0;
long long *gc=0;
char *filename = "/mnt/ramdisk/test1";
maddr=free_addr=0;
numrecs64 = (kilo64*1024)/reclen;
srand48(0);
recnum = (long long *)malloc(sizeof(*recnum)*numrecs64);
if (recnum){
/* pre-compute random sequence based on
Fischer-Yates (Knuth) card shuffle */
for(i = 0; i < numrecs64; i++){
recnum[i] = i;
}
for(i = 0; i < numrecs64; i++) {
long long tmp;
big_rand = lrand48();
big_rand = big_rand%numrecs64;
tmp = recnum[i];
recnum[i] = recnum[big_rand];
recnum[big_rand] = tmp;
}
}
else
{
fprintf(stderr,"Random uniqueness fallback.\n");
}
flags = O_RDWR;
fd=0;
filebytes64 = numrecs64*reclen;
for( j=0; j<2; j++ )
{
if(j==0)
flags |=O_CREAT;
if((fd = open(filename, ((int)flags),0640))<0){
printf("\nCan not open temporary file for read/write\n");
perror("open");
exit(66);
}
nbuff=mainbuffer;
srand48(0);
compute_val=(double)0;
starttime2 = time_so_far();
if ( j==0 ){
for(i=0; i<numrecs64; i++) {
if (recnum) {
offset64 = reclen * (long long)recnum[i];
}
else
{
offset64 = reclen * (lrand48()%numrecs64);
}
if(lseek( fd, offset64, SEEK_SET )<0)
{
perror("lseek");
exit(68);
}
if(read(fd, (void *)nbuff, (size_t)reclen) != reclen)
{
#ifdef NO_PRINT_LLD
printf("\nError reading block at %ld\n",
offset64);
#else
printf("\nError reading block at %lld\n",
offset64);
#endif
perror("read");
exit(70);
}
}
}
else
{
for(i=0; i<numrecs64; i++)
{
if (recnum) {
offset64 = reclen * (long long)recnum[i];
}
else
{
offset64 = reclen * (lrand48()%numrecs64);
}
lseek( fd, offset64, SEEK_SET );
wval=write(fd, nbuff,(size_t)reclen);
if(wval != reclen)
{
#ifdef NO_PRINT_LLD
printf("\nError writing block at %ld\n",
offset64);
#else
printf("\nError writing block at %lld\n",
offset64);
#endif
if(wval==-1)
perror("write");
}
}
} /* end of modifications *kcollins:2-5-96 */
randreadtime[j] = ((time_so_far() - starttime2))-
compute_val;
if(randreadtime[j] < (double).000001)
{
randreadtime[j]=(double).000001;
}
wval=fsync(fd);
if(wval==-1){
perror("fsync");
// signal_handler();
}
wval=close(fd);
if(wval==-1){
perror("close");
// signal_handler();
}
}
for(j=0;j<2;j++)
{
randreadrate[j] =
(unsigned long long) ((double) filebytes64 / randreadtime[j]);
printf("%s: ltest %d randomrate %llu\n", __func__, j, randreadrate[j]);
}
/* Must save walltime & cputime before calling store_value() for each/any cell.*/
if(recnum)
free(recnum);
}
int main(void)
{
// mainbuffer = (char *)malloc(4 * 1024 * 4096);
posix_memalign(&mainbuffer, (4 * 1024 * 4096), (4 * 1024 *4096));
write_perf_test1(1048576, 4096, NULL, NULL);
read_perf_test(1048576, 4096, NULL, NULL);
random_perf_test(1048576, 4096, NULL, NULL);
free(mainbuffer);
return 0;
}