Merge branch 'master' of https://github.com/DevriesL/fio
[fio.git] / engines / io_uring.c
index ca5b90c91be78b3d8964dc87c130d41ccdc6de24..b962e8041b6f8d113669b4b2a31224a68d19aa0f 100644 (file)
@@ -66,6 +66,7 @@ struct ioring_data {
        unsigned iodepth;
        bool ioprio_class_set;
        bool ioprio_set;
+       int prepped;
 
        struct ioring_mmap mmap[3];
 };
@@ -82,6 +83,7 @@ struct ioring_options {
        unsigned int nonvectored;
        unsigned int uncached;
        unsigned int nowait;
+       unsigned int force_async;
 };
 
 static const int ddir_to_op[2][2] = {
@@ -197,6 +199,15 @@ static struct fio_option options[] = {
                .category = FIO_OPT_C_ENGINE,
                .group  = FIO_OPT_G_IOURING,
        },
+       {
+               .name   = "force_async",
+               .lname  = "Force async",
+               .type   = FIO_OPT_INT,
+               .off1   = offsetof(struct ioring_options, force_async),
+               .help   = "Set IOSQE_ASYNC every N requests",
+               .category = FIO_OPT_C_ENGINE,
+               .group  = FIO_OPT_G_IOURING,
+       },
        {
                .name   = NULL,
        },
@@ -277,6 +288,11 @@ static int fio_ioring_prep(struct thread_data *td, struct io_u *io_u)
                }
        }
 
+       if (o->force_async && ++ld->prepped == o->force_async) {
+               ld->prepped = 0;
+               sqe->flags |= IOSQE_ASYNC;
+       }
+
        sqe->user_data = (unsigned long) io_u;
        return 0;
 }
@@ -491,7 +507,7 @@ static void fio_ioring_unmap(struct ioring_data *ld)
 {
        int i;
 
-       for (i = 0; i < ARRAY_SIZE(ld->mmap); i++)
+       for (i = 0; i < FIO_ARRAY_SIZE(ld->mmap); i++)
                munmap(ld->mmap[i].ptr, ld->mmap[i].len);
        close(ld->ring_fd);
 }
@@ -680,7 +696,11 @@ static int fio_ioring_post_init(struct thread_data *td)
 
        err = fio_ioring_queue_init(td);
        if (err) {
-               td_verror(td, errno, "io_queue_init");
+               int init_err = errno;
+
+               if (init_err == ENOSYS)
+                       log_err("fio: your kernel doesn't support io_uring\n");
+               td_verror(td, init_err, "io_queue_init");
                return 1;
        }
 
@@ -708,6 +728,12 @@ static int fio_ioring_init(struct thread_data *td)
        struct ioring_data *ld;
        struct thread_options *to = &td->o;
 
+       if (to->io_submit_mode == IO_MODE_OFFLOAD) {
+               log_err("fio: io_submit_mode=offload is not compatible (or "
+                       "useful) with io_uring\n");
+               return 1;
+       }
+
        /* sqthread submission requires registered files */
        if (o->sqpoll_thread)
                o->registerfiles = 1;
@@ -784,7 +810,7 @@ static int fio_ioring_close_file(struct thread_data *td, struct fio_file *f)
 static struct ioengine_ops ioengine = {
        .name                   = "io_uring",
        .version                = FIO_IOOPS_VERSION,
-       .flags                  = FIO_ASYNCIO_SYNC_TRIM,
+       .flags                  = FIO_ASYNCIO_SYNC_TRIM | FIO_NO_OFFLOAD,
        .init                   = fio_ioring_init,
        .post_init              = fio_ioring_post_init,
        .io_u_init              = fio_ioring_io_u_init,