| 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 |
#include <sys/file.h> |
| 36 |
#include <sys/types.h> |
| 37 |
#include <stdlib.h> |
| 38 |
#include <string.h> |
| 39 |
|
| 40 |
#ifdef SYSV_V2 |
| 41 |
#include <sys/times.h> |
| 42 |
#else |
| 43 |
#include <sys/timeb.h> |
| 44 |
#endif |
| 45 |
|
| 46 |
#ifndef CLK_TCK |
| 47 |
#define CLK_TCK 60 |
| 48 |
#endif |
| 49 |
|
| 50 |
#include <sys/stat.h> |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
#define MBYTES 16 |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
#define MAX_MEM 512 |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
#define SLEEP_TIME 10 |
| 67 |
|
| 68 |
|
| 69 |
main( argc, argv) |
| 70 |
char **argv; |
| 71 |
{ |
| 72 |
register int i, j; |
| 73 |
register char *buf; |
| 74 |
#ifdef SYSV_V2 |
| 75 |
struct tms buffer; |
| 76 |
int start, end; |
| 77 |
#else |
| 78 |
struct timeb start, end; |
| 79 |
#endif |
| 80 |
float writetime, readtime; |
| 81 |
struct stat sbuf; |
| 82 |
int nblocks; |
| 83 |
float filesize; |
| 84 |
register char * max_mem_ptr; |
| 85 |
|
| 86 |
|
| 87 |
printf("Allocating %d MB RAM to remove cache...\n",MAX_MEM); |
| 88 |
max_mem_ptr = calloc(1024*1024*MAX_MEM,1); |
| 89 |
free(max_mem_ptr); |
| 90 |
printf("and freeing it\n"); |
| 91 |
|
| 92 |
printf("Sleeping %d second to let system to recover\n", SLEEP_TIME); |
| 93 |
sleep(SLEEP_TIME); |
| 94 |
|
| 95 |
|
| 96 |
printf("Run this on an idle system.\n"); |
| 97 |
if (argc < 2) { |
| 98 |
printf("Give filename as argument.\n"); |
| 99 |
exit(1); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
j = creat(argv[1], 0666); |
| 106 |
fstat(j, &sbuf); |
| 107 |
printf("blocksize = %d\n", sbuf.st_blksize); |
| 108 |
buf = (char *) malloc((size_t)sbuf.st_blksize); |
| 109 |
nblocks = (MBYTES*1024*1000)/sbuf.st_blksize; |
| 110 |
filesize = (nblocks * sbuf.st_blksize)/(1024*1000); |
| 111 |
#ifdef SYSV_V2 |
| 112 |
start=times(&buffer); |
| 113 |
for (i = 0; i < nblocks; i++) write(j, buf, sbuf.st_blksize); |
| 114 |
end=times(&buffer); |
| 115 |
writetime = (float)(end - start)/(float)CLK_TCK; |
| 116 |
#else |
| 117 |
ftime(&start); |
| 118 |
for (i = 0; i < nblocks; i++) write(j, buf, sbuf.st_blksize); |
| 119 |
ftime(&end); |
| 120 |
writetime = ((end.time - 1) - start.time) + |
| 121 |
((end.millitm + 1000) - start.millitm)/1000.0; |
| 122 |
#endif |
| 123 |
printf("write time = %.3f, speed = %.3f Mbytes/sec\n", |
| 124 |
writetime, filesize/writetime); |
| 125 |
close(j); |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
j = open(argv[2], 0); |
| 131 |
#ifdef SYSV_V2 |
| 132 |
start=times(&buffer); |
| 133 |
for (i = 0; i < nblocks; i++) read(j, buf, sbuf.st_blksize); |
| 134 |
end=times(&buffer); |
| 135 |
readtime = (float)(end - start)/(float)CLK_TCK; |
| 136 |
#else |
| 137 |
ftime(&start); |
| 138 |
for (i = 0; i < nblocks; i++) read(j, buf, sbuf.st_blksize); |
| 139 |
ftime(&end); |
| 140 |
readtime = ((end.time - 1) - start.time) + |
| 141 |
((end.millitm + 1000) - start.millitm)/1000.0; |
| 142 |
#endif |
| 143 |
printf("read time = %.3f, speed = %.3f Mbytes/sec\n", |
| 144 |
readtime, filesize/readtime); |
| 145 |
close(j); |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
printf("Average I/O performance = %.3f Mbytes/sec\n", |
| 155 |
filesize/((writetime + readtime)/2)); |
| 156 |
exit(0); |
| 157 |
} |