11 #include <machine/atomic.h>
15 main(int ac
, char **av
)
24 volatile int *counterp
;
29 if (ac
< 2 || ac
> 5) {
30 fprintf(stderr
, "%s <device> [bufsize:512 [range%:90 [nprocs:32]]]\n",
36 bytes
= (size_t)strtoul(av
[2], NULL
, 0);
37 if (bytes
< 512 || (bytes
^ (bytes
- 1)) != ((bytes
<< 1) - 1)) {
38 fprintf(stderr
, "bytes must be a power of 2 >= 512\n");
45 range
= strtod(av
[3], NULL
);
49 nprocs
= strtol(av
[4], NULL
, 0);
50 if (nprocs
< 0 || nprocs
> 512) {
51 fprintf(stderr
, "absurd nprocs (%d)\n", nprocs
);
56 fd
= open(av
[1], O_RDONLY
);
58 fprintf(stderr
, "open %s: %s\n", av
[1], strerror(errno
));
63 limit
= lseek(fd
, 0L, 1);
64 limit
= (off_t
)((double)limit
* range
/ 100.0);
65 limit
&= ~(off_t
)(bytes
- 1);
66 printf("device %s bufsize %zd limit %4.3fGB nprocs %d\n",
67 av
[1], bytes
, (double)limit
/ (1024.0*1024.0*1024.0), nprocs
);
69 counterp
= mmap(NULL
, sizeof(int), PROT_READ
|PROT_WRITE
,
70 MAP_SHARED
|MAP_ANON
, -1, 0);
72 for (i
= 0; i
< nprocs
; ++i
) {
75 fd
= open(av
[1], O_RDONLY
);
80 pos
= random() ^ ((long)random() << 31);
81 pos
&= 0x7FFFFFFFFFFFFFFFLLU
;
82 pos
= (pos
% limit
) & ~(off_t
)(bytes
- 1);
85 atomic_add_int(counterp
, 1);
97 cdelta
= cnext
- clast
;
99 stop_timing(cdelta
, "randread");