lib/pattern: Support binary pattern buffers on windows
[fio.git] / engines / libaio.c
index 8b965fe28f6158917501e579729cc7f7f002481d..33b8c12f96fb191af478114d1a1feb563ffb0440 100644 (file)
@@ -52,13 +52,13 @@ struct libaio_data {
        unsigned int head;
        unsigned int tail;
 
-       bool use_cmdprio;
+       struct cmdprio cmdprio;
 };
 
 struct libaio_options {
-       void *pad;
+       struct thread_data *td;
        unsigned int userspace_reap;
-       struct cmdprio cmdprio;
+       struct cmdprio_options cmdprio_options;
        unsigned int nowait;
 };
 
@@ -78,9 +78,9 @@ static struct fio_option options[] = {
                .lname  = "high priority percentage",
                .type   = FIO_OPT_INT,
                .off1   = offsetof(struct libaio_options,
-                                  cmdprio.percentage[DDIR_READ]),
+                                  cmdprio_options.percentage[DDIR_READ]),
                .off2   = offsetof(struct libaio_options,
-                                  cmdprio.percentage[DDIR_WRITE]),
+                                  cmdprio_options.percentage[DDIR_WRITE]),
                .minval = 0,
                .maxval = 100,
                .help   = "Send high priority I/O this percentage of the time",
@@ -92,9 +92,9 @@ static struct fio_option options[] = {
                .lname  = "Asynchronous I/O priority class",
                .type   = FIO_OPT_INT,
                .off1   = offsetof(struct libaio_options,
-                                  cmdprio.class[DDIR_READ]),
+                                  cmdprio_options.class[DDIR_READ]),
                .off2   = offsetof(struct libaio_options,
-                                  cmdprio.class[DDIR_WRITE]),
+                                  cmdprio_options.class[DDIR_WRITE]),
                .help   = "Set asynchronous IO priority class",
                .minval = IOPRIO_MIN_PRIO_CLASS + 1,
                .maxval = IOPRIO_MAX_PRIO_CLASS,
@@ -107,9 +107,9 @@ static struct fio_option options[] = {
                .lname  = "Asynchronous I/O priority level",
                .type   = FIO_OPT_INT,
                .off1   = offsetof(struct libaio_options,
-                                  cmdprio.level[DDIR_READ]),
+                                  cmdprio_options.level[DDIR_READ]),
                .off2   = offsetof(struct libaio_options,
-                                  cmdprio.level[DDIR_WRITE]),
+                                  cmdprio_options.level[DDIR_WRITE]),
                .help   = "Set asynchronous IO priority level",
                .minval = IOPRIO_MIN_PRIO,
                .maxval = IOPRIO_MAX_PRIO,
@@ -117,6 +117,16 @@ static struct fio_option options[] = {
                .category = FIO_OPT_C_ENGINE,
                .group  = FIO_OPT_G_LIBAIO,
        },
+       {
+               .name   = "cmdprio_bssplit",
+               .lname  = "Priority percentage block size split",
+               .type   = FIO_OPT_STR_STORE,
+               .off1   = offsetof(struct libaio_options,
+                                  cmdprio_options.bssplit_str),
+               .help   = "Set priority percentages for different block sizes",
+               .category = FIO_OPT_C_ENGINE,
+               .group  = FIO_OPT_G_LIBAIO,
+       },
 #else
        {
                .name   = "cmdprio_percentage",
@@ -136,6 +146,12 @@ static struct fio_option options[] = {
                .type   = FIO_OPT_UNSUPPORTED,
                .help   = "Your platform does not support I/O priority classes",
        },
+       {
+               .name   = "cmdprio_bssplit",
+               .lname  = "Priority percentage block size split",
+               .type   = FIO_OPT_UNSUPPORTED,
+               .help   = "Your platform does not support I/O priority classes",
+       },
 #endif
        {
                .name   = "nowait",
@@ -180,18 +196,15 @@ static int fio_libaio_prep(struct thread_data *td, struct io_u *io_u)
        return 0;
 }
 
-static void fio_libaio_prio_prep(struct thread_data *td, struct io_u *io_u)
+static inline void fio_libaio_cmdprio_prep(struct thread_data *td,
+                                          struct io_u *io_u)
 {
-       struct libaio_options *o = td->eo;
-       struct cmdprio *cmdprio = &o->cmdprio;
-       enum fio_ddir ddir = io_u->ddir;
-       unsigned int p = cmdprio->percentage[ddir];
+       struct libaio_data *ld = td->io_ops_data;
+       struct cmdprio *cmdprio = &ld->cmdprio;
 
-       if (p && rand_between(&td->prio_state, 0, 99) < p) {
-               io_u->iocb.aio_reqprio =
-                       ioprio_value(cmdprio->class[ddir], cmdprio->level[ddir]);
+       if (fio_cmdprio_set_ioprio(td, cmdprio, io_u)) {
+               io_u->iocb.aio_reqprio = io_u->ioprio;
                io_u->iocb.u.c.flags |= IOCB_FLAG_IOPRIO;
-               io_u->flags |= IO_U_F_PRIORITY;
        }
 }
 
@@ -328,8 +341,8 @@ static enum fio_q_status fio_libaio_queue(struct thread_data *td,
                return FIO_Q_COMPLETED;
        }
 
-       if (ld->use_cmdprio)
-               fio_libaio_prio_prep(td, io_u);
+       if (ld->cmdprio.mode != CMDPRIO_MODE_NONE)
+               fio_libaio_cmdprio_prep(td, io_u);
 
        ld->iocbs[ld->head] = &io_u->iocb;
        ld->io_us[ld->head] = io_u;
@@ -355,6 +368,12 @@ static void fio_libaio_queued(struct thread_data *td, struct io_u **io_us,
                memcpy(&io_u->issue_time, &now, sizeof(now));
                io_u_queued(td, io_u);
        }
+
+       /*
+        * only used for iolog
+        */
+       if (td->o.read_iolog_file)
+               memcpy(&td->last_issue, &now, sizeof(now));
 }
 
 static int fio_libaio_commit(struct thread_data *td)
@@ -447,6 +466,8 @@ static void fio_libaio_cleanup(struct thread_data *td)
                 */
                if (!(td->flags & TD_F_CHILD))
                        io_destroy(ld->aio_ctx);
+
+               fio_cmdprio_cleanup(&ld->cmdprio);
                free(ld->aio_events);
                free(ld->iocbs);
                free(ld->io_us);
@@ -472,7 +493,6 @@ static int fio_libaio_init(struct thread_data *td)
 {
        struct libaio_data *ld;
        struct libaio_options *o = td->eo;
-       struct cmdprio *cmdprio = &o->cmdprio;
        int ret;
 
        ld = calloc(1, sizeof(*ld));
@@ -485,7 +505,7 @@ static int fio_libaio_init(struct thread_data *td)
 
        td->io_ops_data = ld;
 
-       ret = fio_cmdprio_init(td, cmdprio, &ld->use_cmdprio);
+       ret = fio_cmdprio_init(td, &ld->cmdprio, &o->cmdprio_options);
        if (ret) {
                td_verror(td, EINVAL, "fio_libaio_init");
                return 1;
@@ -497,7 +517,8 @@ static int fio_libaio_init(struct thread_data *td)
 FIO_STATIC struct ioengine_ops ioengine = {
        .name                   = "libaio",
        .version                = FIO_IOOPS_VERSION,
-       .flags                  = FIO_ASYNCIO_SYNC_TRIM,
+       .flags                  = FIO_ASYNCIO_SYNC_TRIM |
+                                       FIO_ASYNCIO_SETS_ISSUE_TIME,
        .init                   = fio_libaio_init,
        .post_init              = fio_libaio_post_init,
        .prep                   = fio_libaio_prep,