io_uring: cleanup sq thread poll/cpu setup
authorJens Axboe <axboe@kernel.dk>
Thu, 10 Jan 2019 22:42:07 +0000 (15:42 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 10 Jan 2019 22:47:38 +0000 (15:47 -0700)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
engines/io_uring.c
t/io_uring.c

index 39359af909c7b199677dcadf784778435873b28c..7591190a8cb4fee649ab6d67732612040e0aa644 100644 (file)
@@ -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) {
index af20bbf3dad3800d7645ce208aa9f75d4db5a6d9..12591c97fd905cf09e973b8915cb59762ffd3823 100644 (file)
@@ -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);