From beda9d8d9e9148ff34eaa0eeb0cde19a36f47494 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 19 Nov 2021 10:44:15 -0700 Subject: [PATCH] t/io_uring: add -R option for random/sequential IO If -R1 is used, which is the default, then a random IO pattern is used. If -R0 is used, then the IO will be sequential. Signed-off-by: Jens Axboe --- t/io_uring.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/t/io_uring.c b/t/io_uring.c index 5b8a00fa..b79822d7 100644 --- a/t/io_uring.c +++ b/t/io_uring.c @@ -60,6 +60,8 @@ static unsigned sq_ring_mask, cq_ring_mask; struct file { unsigned long max_blocks; + unsigned long max_size; + unsigned long cur_off; unsigned pending_ios; int real_fd; int fixed_fd; @@ -123,7 +125,8 @@ static int do_nop = 0; /* no-op SQ ring commands */ static int nthreads = 1; static int stats = 0; /* generate IO stats */ static int aio = 0; /* use libaio */ -static int runtime = 0; /* runtime */ +static int runtime = 0; /* runtime */ +static int random_io = 1; /* random or sequential IO */ static unsigned long tsc_rate; @@ -451,8 +454,15 @@ static void init_io(struct submitter *s, unsigned index) } f->pending_ios++; - r = __rand64(&s->rand_state); - offset = (r % (f->max_blocks - 1)) * bs; + if (random_io) { + r = __rand64(&s->rand_state); + offset = (r % (f->max_blocks - 1)) * bs; + } else { + offset = f->cur_off; + f->cur_off += bs; + if (f->cur_off + bs > f->max_size) + f->cur_off = 0; + } if (register_files) { sqe->flags = IOSQE_FIXED_FILE; @@ -520,9 +530,11 @@ static int get_file_size(struct file *f) return -1; f->max_blocks = bytes / bs; + f->max_size = bytes; return 0; } else if (S_ISREG(st.st_mode)) { f->max_blocks = st.st_size / bs; + f->max_size = st.st_size; return 0; } @@ -1070,11 +1082,12 @@ static void usage(char *argv, int status) " -N : Perform just no-op requests, default %d\n" " -t : Track IO latencies, default %d\n" " -T : TSC rate in HZ\n" - " -a : Use legacy aio, default %d\n" - " -r : Runtime in seconds, default %s\n", + " -r : Runtime in seconds, default %s\n" + " -R : Use random IO, default %d\n" + " -a : Use legacy aio, default %d\n", argv, DEPTH, BATCH_SUBMIT, BATCH_COMPLETE, BS, polled, fixedbufs, dma_map, register_files, nthreads, !buffered, do_nop, - stats, aio, runtime == 0 ? "unlimited" : runtime_str); + stats, runtime == 0 ? "unlimited" : runtime_str, aio, random_io); exit(status); } @@ -1134,7 +1147,7 @@ int main(int argc, char *argv[]) if (!do_nop && argc < 2) usage(argv[0], 1); - while ((opt = getopt(argc, argv, "d:s:c:b:p:B:F:n:N:O:t:T:a:r:D:h?")) != -1) { + while ((opt = getopt(argc, argv, "d:s:c:b:p:B:F:n:N:O:t:T:a:r:D:R:h?")) != -1) { switch (opt) { case 'a': aio = !!atoi(optarg); @@ -1198,6 +1211,9 @@ int main(int argc, char *argv[]) case 'D': dma_map = !!atoi(optarg); break; + case 'R': + random_io = !!atoi(optarg); + break; case 'h': case '?': default: -- 2.25.1