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);
78 long pos = (random() % limit) & ~(off_t)(bytes - 1);
81 atomic_add_int(counterp, 1);
93 cdelta = cnext - clast;
95 stop_timing(cdelta, "randread");