From 3d7d00a35f8230451b8113804cfdc713cfdc7664 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 10 Jan 2019 15:42:07 -0700 Subject: [PATCH] io_uring: cleanup sq thread poll/cpu setup Signed-off-by: Jens Axboe --- engines/io_uring.c | 33 +++++++++++++++++++++++++-------- t/io_uring.c | 11 +++++------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/engines/io_uring.c b/engines/io_uring.c index 39359af9..7591190a 100644 --- a/engines/io_uring.c +++ b/engines/io_uring.c @@ -73,6 +73,7 @@ struct ioring_options { void *pad; unsigned int hipri; unsigned int fixedbufs; + unsigned int sqpoll_thread; unsigned int sqpoll_set; unsigned int sqpoll_cpu; }; @@ -107,10 +108,19 @@ static struct fio_option options[] = { }, { .name = "sqthread_poll", - .lname = "Kernel SQ thread should poll", + .lname = "Kernel SQ thread polling", + .type = FIO_OPT_INT, + .off1 = offsetof(struct ioring_options, sqpoll_thread), + .help = "Offload submission/completion to kernel thread", + .category = FIO_OPT_C_ENGINE, + .group = FIO_OPT_G_LIBAIO, + }, + { + .name = "sqthread_poll_cpu", + .lname = "SQ Thread Poll CPU", .type = FIO_OPT_INT, .cb = fio_ioring_sqpoll_cb, - .help = "Offload submission to kernel thread", + .help = "What CPU to run SQ thread polling on", .category = FIO_OPT_C_ENGINE, .group = FIO_OPT_G_LIBAIO, }, @@ -231,7 +241,7 @@ static int fio_ioring_getevents(struct thread_data *td, unsigned int min, continue; } - if (!o->sqpoll_set) { + if (!o->sqpoll_thread) { r = io_uring_enter(ld, 0, actual_min, IORING_ENTER_GETEVENTS); if (r < 0) { @@ -313,8 +323,12 @@ static int fio_ioring_commit(struct thread_data *td) if (!ld->queued) return 0; - /* Nothing to do */ - if (o->sqpoll_set) { + /* + * Kernel side does submission. just need to check if the ring is + * flagged as needing a kick, if so, call io_uring_enter(). This + * only happens if we've been idle too long. + */ + if (o->sqpoll_thread) { struct io_sq_ring *ring = &ld->sq_ring; read_barrier(); @@ -434,9 +448,12 @@ static int fio_ioring_queue_init(struct thread_data *td) if (o->hipri) p.flags |= IORING_SETUP_IOPOLL; - if (o->sqpoll_set) { - p.flags |= IORING_SETUP_SQPOLL | IORING_SETUP_SQ_AFF; - p.sq_thread_cpu = o->sqpoll_cpu; + if (o->sqpoll_thread) { + p.flags |= IORING_SETUP_SQPOLL; + if (o->sqpoll_set) { + p.flags |= IORING_SETUP_SQ_AFF; + p.sq_thread_cpu = o->sqpoll_cpu; + } } if (o->fixedbufs) { diff --git a/t/io_uring.c b/t/io_uring.c index af20bbf3..12591c97 100644 --- a/t/io_uring.c +++ b/t/io_uring.c @@ -85,8 +85,8 @@ static volatile int finish; static int polled = 1; /* use IO polling */ static int fixedbufs = 0; /* use fixed user buffers */ static int buffered = 0; /* use buffered IO, not O_DIRECT */ -static int sq_thread = 0; /* use kernel submission/poller thread */ -static int sq_thread_cpu = 0; /* pin above thread to this CPU */ +static int sq_thread_poll = 0; /* use kernel submission/poller thread */ +static int sq_thread_cpu = -1; /* pin above thread to this CPU */ static int io_uring_register_buffers(struct submitter *s) { @@ -324,11 +324,10 @@ static int setup_ring(struct submitter *s) memset(&p, 0, sizeof(p)); - if (polled) - p.flags |= IORING_SETUP_IOPOLL; - if (sq_thread) { + if (sq_thread_poll) { p.flags |= IORING_SETUP_SQPOLL; - p.sq_thread_cpu = sq_thread_cpu; + if (sq_thread_cpu != -1) + p.flags |= IORING_SETUP_SQ_AFF; } fd = io_uring_setup(DEPTH, &p); -- 2.25.1