/* Copyright 2005 Intel Corporation. All Rights Reserved. * Please distribute under the terms of the GPLv2 or later. * Written by Benjamin LaHaise. */ #define _GNU_SOURCE 1 #include #include #include #include #include #include #include #include #define NR_BUFFERS 20480 #define BUFSIZE 512 #define BLOCKSIZE 4096 int main(int argc, char *argv[]) { long bufsize = BUFSIZE; struct iocb ios[NR_BUFFERS], *iocbps[NR_BUFFERS]; struct io_event events[NR_BUFFERS]; io_context_t ctx; char *buffers; long err; int i, completed; int min_nr = NR_BUFFERS; int repeats = 1; int j; int fd; long total = 0; if (argc > 1 && !strcmp("--bufsize", argv[1])) { bufsize = atol(argv[2]); argv += 2; argc -= 2; if (bufsize & 511) { fprintf(stderr, "bufsize must be a multiple of 512\n"); exit(2); } printf("bufsize %ld\n", bufsize); } if (argc > 1) min_nr = atoi(argv[1]); if (min_nr < 1) min_nr = 1; if (argc > 2) repeats = atoi(argv[2]); if (repeats < 1) repeats = 1; fd = open("testfile", O_RDONLY | O_DIRECT); if (fd < 0) { perror("open(testfile, O_RDONLY|O_DIRECT)"); exit(1); } buffers = mmap(NULL, NR_BUFFERS * bufsize, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (MAP_FAILED == (void *)buffers) { perror("mmap"); exit(1); } memset(buffers, 0, NR_BUFFERS * bufsize); err = io_setup(NR_BUFFERS * 2, &ctx); if (err) { fprintf(stderr, "io_setup: %ld: %s\n", err, strerror(-err)); exit(1); } for (i=0; i 0) total += events[i].res; if (bufsize == events[i].res) continue; if ((long)events[i].res < 0) { int idx = events[i].obj - ios; fprintf(stderr, "iocb[%d] = %ld\n", idx, events[i].res); } } } } printf("completed %d repeats. read a total of %ld bytes\n", j, total); return 0; }