windowsaio: initialize and map windowsaio IO structure to io_u
authorJens Axboe <axboe@kernel.dk>
Thu, 6 Dec 2012 19:30:38 +0000 (20:30 +0100)
committerJens Axboe <axboe@kernel.dk>
Thu, 6 Dec 2012 19:30:38 +0000 (20:30 +0100)
Instead of searching for a free entry everytime we enter
queue, do this when the io_u is setup. It's cleaner and
faster.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c
engines/windowsaio.c
ioengine.h

index faa861cf64d303e993d3fe2c3044dcda2b3367a4..1b5c2eb0a6bb7f86587281106adb90e63af42fc9 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -803,6 +803,10 @@ static void cleanup_io_u(struct thread_data *td)
                io_u = flist_entry(entry, struct io_u, list);
 
                flist_del(&io_u->list);
+
+               if (td->io_ops->io_u_free)
+                       td->io_ops->io_u_free(td, io_u);
+
                fio_memfree(io_u, sizeof(*io_u));
        }
 
@@ -885,6 +889,16 @@ static int init_io_u(struct thread_data *td)
                io_u->index = i;
                io_u->flags = IO_U_F_FREE;
                flist_add(&io_u->list, &td->io_u_freelist);
+
+               if (td->io_ops->io_u_init) {
+                       int ret = td->io_ops->io_u_init(td, io_u);
+
+                       if (ret) {
+                               log_err("fio: failed to init engine data: %d\n", ret);
+                               return 1;
+                       }
+               }
+
                p += max_bs;
        }
 
index db7573049600b6686c74c241c719057544a0d099..96ec0f4b87622c6ba0873b1f8bc40f1a11f7c7c6 100644 (file)
@@ -20,11 +20,9 @@ struct fio_overlapped {
        OVERLAPPED o;
        struct io_u *io_u;
        BOOL io_complete;
-       BOOL io_free;
 };
 
 struct windowsaio_data {
-       struct fio_overlapped *ovls;
        struct io_u **aio_events;
        HANDLE iothread;
        HANDLE iocomplete_event;
@@ -139,7 +137,6 @@ static int fio_windowsaio_init(struct thread_data *td)
        struct windowsaio_data *wd;
        HANDLE hKernel32Dll;
        int rc = 0;
-       int i;
 
        wd = malloc(sizeof(struct windowsaio_data));
        if (wd != NULL)
@@ -153,25 +150,6 @@ static int fio_windowsaio_init(struct thread_data *td)
                        rc = 1;
        }
 
-       if (!rc) {
-               wd->ovls = malloc(td->o.iodepth * sizeof(struct fio_overlapped));
-               if (wd->ovls == NULL)
-                       rc = 1;
-       }
-
-       if (!rc) {
-               for (i = 0; i < td->o.iodepth; i++) {
-                       wd->ovls[i].io_free = TRUE;
-                       wd->ovls[i].io_complete = FALSE;
-
-                       wd->ovls[i].o.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
-                       if (wd->ovls[i].o.hEvent == NULL) {
-                               rc = 1;
-                               break;
-                       }
-               }
-       }
-
        if (!rc) {
                /* Create an auto-reset event */
                wd->iocomplete_event = CreateEvent(NULL, FALSE, FALSE, NULL);
@@ -181,8 +159,6 @@ static int fio_windowsaio_init(struct thread_data *td)
 
        if (rc) {
                if (wd != NULL) {
-                       if (wd->ovls != NULL)
-                               free(wd->ovls);
                        if (wd->aio_events != NULL)
                                free(wd->aio_events);
 
@@ -199,7 +175,6 @@ static int fio_windowsaio_init(struct thread_data *td)
 
 static void fio_windowsaio_cleanup(struct thread_data *td)
 {
-       int i;
        struct windowsaio_data *wd;
 
        wd = td->io_ops->data;
@@ -211,12 +186,7 @@ static void fio_windowsaio_cleanup(struct thread_data *td)
                CloseHandle(wd->iothread);
                CloseHandle(wd->iocomplete_event);
 
-               for (i = 0; i < td->o.iodepth; i++) {
-                       CloseHandle(wd->ovls[i].o.hEvent);
-               }
-
                free(wd->aio_events);
-               free(wd->ovls);
                free(wd);
 
                td->io_ops->data = NULL;
@@ -364,7 +334,6 @@ static int fio_windowsaio_getevents(struct thread_data *td, unsigned int min,
 
                        if (fov->io_complete) {
                                fov->io_complete = FALSE;
-                               fov->io_free  = TRUE;
                                ResetEvent(fov->o.hEvent);
                                wd->aio_events[dequeued] = io_u;
                                dequeued++;
@@ -389,32 +358,18 @@ static int fio_windowsaio_getevents(struct thread_data *td, unsigned int min,
 
 static int fio_windowsaio_queue(struct thread_data *td, struct io_u *io_u)
 {
-       LPOVERLAPPED lpOvl = NULL;
-       struct windowsaio_data *wd;
+       struct fio_overlapped *o = io_u->engine_data;
+       LPOVERLAPPED lpOvl = &o->o;
        DWORD iobytes;
        BOOL success = FALSE;
-       int index;
        int rc = FIO_Q_COMPLETED;
 
        fio_ro_check(td, io_u);
 
-       wd = td->io_ops->data;
-
-       for (index = 0; index < td->o.iodepth; index++) {
-               if (wd->ovls[index].io_free)
-                       break;
-       }
-
-       assert(index < td->o.iodepth);
-
-       wd->ovls[index].io_free = FALSE;
-       wd->ovls[index].io_u = io_u;
-       lpOvl = &wd->ovls[index].o;
        lpOvl->Internal = STATUS_PENDING;
        lpOvl->InternalHigh = 0;
        lpOvl->Offset = io_u->offset & 0xFFFFFFFF;
        lpOvl->OffsetHigh = io_u->offset >> 32;
-       io_u->engine_data = &wd->ovls[index];
 
        switch (io_u->ddir) {
        case DDIR_WRITE:
@@ -510,6 +465,34 @@ static int fio_windowsaio_cancel(struct thread_data *td,
        return rc;
 }
 
+static void fio_windowsaio_io_u_free(struct thread_data *td, struct io_u *io_u)
+{
+       struct fio_overlapped *o = io_u->engine_data;
+
+       if (o) {
+               CloseHandle(o->o.hEvent);
+               io_u->engine_data = NULL;
+               free(o);
+       }
+}
+
+static int fio_windowsaio_io_u_init(struct thread_data *td, struct io_u *io_u)
+{
+       struct fio_overlapped *o;
+
+       o = malloc(sizeof(*o));
+       o->io_complete = FALSE:
+       o->io_u = io_u;
+       o->o.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+       if (!o->o.hEvent) {
+               free(o);
+               return 1;
+       }
+
+       io_u->engine_data = o;
+       return 0;
+}
+
 static struct ioengine_ops ioengine = {
        .name           = "windowsaio",
        .version        = FIO_IOOPS_VERSION,
@@ -521,7 +504,9 @@ static struct ioengine_ops ioengine = {
        .cleanup        = fio_windowsaio_cleanup,
        .open_file      = fio_windowsaio_open_file,
        .close_file     = fio_windowsaio_close_file,
-       .get_file_size  = generic_get_file_size
+       .get_file_size  = generic_get_file_size,
+       .io_u_init      = fio_windowsaio_io_u_init,
+       .io_u_free      = fio_windowsaio_io_u_free,
 };
 
 static void fio_init fio_posixaio_register(void)
index 997f90afcfe605feee231da08822289364be20dc..0285b08c77567aefc1bdfed7a2bf481548a99ed5 100644 (file)
@@ -121,6 +121,8 @@ struct ioengine_ops {
        int (*close_file)(struct thread_data *, struct fio_file *);
        int (*get_file_size)(struct thread_data *, struct fio_file *);
        void (*terminate)(struct thread_data *);
+       int (*io_u_init)(struct thread_data *, struct io_u *);
+       void (*io_u_free)(struct thread_data *, struct io_u *);
        int option_struct_size;
        struct fio_option *options;
        void *data;