Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 1 | /* |
| 2 | * guasi engine |
| 3 | * |
| 4 | * IO engine using the GUASI library. |
| 5 | * |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 6 | * This is currently disabled. To enable it, execute: |
| 7 | * |
| 8 | * $ export EXTFLAGS="-DFIO_HAVE_GUASI" |
| 9 | * $ export EXTLIBS="-lguasi" |
| 10 | * |
| 11 | * before running make. You'll need the GUASI lib as well: |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 12 | * |
| 13 | * http://www.xmailserver.org/guasi-lib.html |
| 14 | * |
| 15 | */ |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <unistd.h> |
| 19 | #include <errno.h> |
| 20 | #include <assert.h> |
| 21 | |
| 22 | #include "../fio.h" |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 23 | |
| 24 | #ifdef FIO_HAVE_GUASI |
| 25 | |
| 26 | #define GFIO_MIN_THREADS 32 |
Davide Libenzi | d6c6810 | 2007-03-22 07:43:55 +0100 | [diff] [blame] | 27 | #ifndef GFIO_MAX_THREADS |
Davide Libenzi | 97c26cb | 2007-03-26 12:20:49 +0200 | [diff] [blame] | 28 | #define GFIO_MAX_THREADS 2000 |
Davide Libenzi | d6c6810 | 2007-03-22 07:43:55 +0100 | [diff] [blame] | 29 | #endif |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 30 | |
| 31 | #include <guasi.h> |
| 32 | #include <guasi_syscalls.h> |
| 33 | |
| 34 | #ifdef GFIO_DEBUG |
| 35 | #define GDBG_PRINT(a) printf a |
| 36 | #else |
| 37 | #define GDBG_PRINT(a) (void) 0 |
| 38 | #endif |
| 39 | |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 40 | struct guasi_data { |
| 41 | guasi_t hctx; |
| 42 | int max_reqs; |
| 43 | guasi_req_t *reqs; |
| 44 | struct io_u **io_us; |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 45 | int queued_nr; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 46 | int reqs_nr; |
| 47 | }; |
| 48 | |
| 49 | static int fio_guasi_prep(struct thread_data fio_unused *td, struct io_u *io_u) |
| 50 | { |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 51 | |
| 52 | GDBG_PRINT(("fio_guasi_prep(%p)\n", io_u)); |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 53 | io_u->greq = NULL; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | static struct io_u *fio_guasi_event(struct thread_data *td, int event) |
| 59 | { |
| 60 | struct guasi_data *ld = td->io_ops->data; |
| 61 | struct io_u *io_u; |
| 62 | struct guasi_reqinfo rinf; |
| 63 | |
| 64 | GDBG_PRINT(("fio_guasi_event(%d)\n", event)); |
| 65 | if (guasi_req_info(ld->reqs[event], &rinf) < 0) { |
Jens Axboe | 0725726 | 2007-03-27 11:04:59 +0200 | [diff] [blame] | 66 | log_err("guasi_req_info(%d) FAILED!\n", event); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 67 | return NULL; |
| 68 | } |
| 69 | io_u = rinf.asid; |
Davide Libenzi | 66b83d9 | 2007-03-21 09:15:13 +0100 | [diff] [blame] | 70 | io_u->error = EINPROGRESS; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 71 | GDBG_PRINT(("fio_guasi_event(%d) -> %p\n", event, io_u)); |
Davide Libenzi | 66b83d9 | 2007-03-21 09:15:13 +0100 | [diff] [blame] | 72 | if (rinf.status == GUASI_STATUS_COMPLETE) { |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 73 | io_u->error = rinf.result; |
Davide Libenzi | 66b83d9 | 2007-03-21 09:15:13 +0100 | [diff] [blame] | 74 | if (io_u->ddir == DDIR_READ || |
| 75 | io_u->ddir == DDIR_WRITE) { |
| 76 | io_u->error = 0; |
| 77 | if (rinf.result != (long) io_u->xfer_buflen) { |
| 78 | if (rinf.result >= 0) |
| 79 | io_u->resid = io_u->xfer_buflen - rinf.result; |
| 80 | else |
| 81 | io_u->error = rinf.error; |
| 82 | } |
| 83 | } |
| 84 | } |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 85 | |
| 86 | return io_u; |
| 87 | } |
| 88 | |
Jens Axboe | e7d2e61 | 2007-12-11 10:49:39 +0100 | [diff] [blame] | 89 | static int fio_guasi_getevents(struct thread_data *td, unsigned int min, |
| 90 | unsigned int max, struct timespec *t) |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 91 | { |
| 92 | struct guasi_data *ld = td->io_ops->data; |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 93 | int n, r; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 94 | long timeo = -1; |
| 95 | |
| 96 | GDBG_PRINT(("fio_guasi_getevents(%d, %d)\n", min, max)); |
| 97 | if (min > ld->max_reqs) |
| 98 | min = ld->max_reqs; |
| 99 | if (max > ld->max_reqs) |
| 100 | max = ld->max_reqs; |
| 101 | if (t) |
| 102 | timeo = t->tv_sec * 1000L + t->tv_nsec / 1000000L; |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 103 | for (n = 0; n < ld->reqs_nr; n++) |
| 104 | guasi_req_free(ld->reqs[n]); |
| 105 | n = 0; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 106 | do { |
Davide Libenzi | 97c26cb | 2007-03-26 12:20:49 +0200 | [diff] [blame] | 107 | r = guasi_fetch(ld->hctx, ld->reqs + n, min - n, |
| 108 | max - n, timeo); |
| 109 | if (r < 0) { |
Jens Axboe | 0725726 | 2007-03-27 11:04:59 +0200 | [diff] [blame] | 110 | log_err("guasi_fetch() FAILED! (%d)\n", r); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 111 | break; |
Davide Libenzi | 97c26cb | 2007-03-26 12:20:49 +0200 | [diff] [blame] | 112 | } |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 113 | n += r; |
| 114 | if (n >= min) |
| 115 | break; |
| 116 | } while (1); |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 117 | ld->reqs_nr = n; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 118 | GDBG_PRINT(("fio_guasi_getevents() -> %d\n", n)); |
| 119 | |
| 120 | return n; |
| 121 | } |
| 122 | |
| 123 | static int fio_guasi_queue(struct thread_data *td, struct io_u *io_u) |
| 124 | { |
| 125 | struct guasi_data *ld = td->io_ops->data; |
| 126 | |
Jens Axboe | 7101d9c | 2007-09-12 13:12:39 +0200 | [diff] [blame] | 127 | fio_ro_check(td, io_u); |
| 128 | |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 129 | GDBG_PRINT(("fio_guasi_queue(%p)\n", io_u)); |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 130 | if (ld->queued_nr == (int) td->o.iodepth) |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 131 | return FIO_Q_BUSY; |
| 132 | |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 133 | ld->io_us[ld->queued_nr] = io_u; |
| 134 | ld->queued_nr++; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 135 | return FIO_Q_QUEUED; |
| 136 | } |
| 137 | |
Davide Libenzi | 97c26cb | 2007-03-26 12:20:49 +0200 | [diff] [blame] | 138 | static void fio_guasi_queued(struct thread_data *td, struct io_u **io_us, int nr) |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 139 | { |
Davide Libenzi | 97c26cb | 2007-03-26 12:20:49 +0200 | [diff] [blame] | 140 | int i; |
| 141 | struct io_u *io_u; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 142 | struct timeval now; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 143 | |
Jens Axboe | 12d9d84 | 2008-10-16 21:26:10 +0200 | [diff] [blame] | 144 | if (!fio_fill_issue_time(td)) |
| 145 | return; |
| 146 | |
Jens Axboe | 838bc70 | 2008-05-22 13:08:23 +0200 | [diff] [blame] | 147 | io_u_mark_submit(td, nr); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 148 | fio_gettime(&now, NULL); |
Davide Libenzi | 97c26cb | 2007-03-26 12:20:49 +0200 | [diff] [blame] | 149 | for (i = 0; i < nr; i++) { |
| 150 | io_u = io_us[i]; |
| 151 | memcpy(&io_u->issue_time, &now, sizeof(now)); |
| 152 | io_u_queued(td, io_u); |
| 153 | } |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static int fio_guasi_commit(struct thread_data *td) |
| 157 | { |
| 158 | struct guasi_data *ld = td->io_ops->data; |
| 159 | int i; |
| 160 | struct io_u *io_u; |
| 161 | struct fio_file *f; |
| 162 | |
Davide Libenzi | d6c6810 | 2007-03-22 07:43:55 +0100 | [diff] [blame] | 163 | GDBG_PRINT(("fio_guasi_commit(%d)\n", ld->queued_nr)); |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 164 | for (i = 0; i < ld->queued_nr; i++) { |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 165 | io_u = ld->io_us[i]; |
Davide Libenzi | d6c6810 | 2007-03-22 07:43:55 +0100 | [diff] [blame] | 166 | GDBG_PRINT(("fio_guasi_commit(%d) --> %p\n", i, io_u)); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 167 | f = io_u->file; |
| 168 | io_u->greq = NULL; |
| 169 | if (io_u->ddir == DDIR_READ) |
| 170 | io_u->greq = guasi__pread(ld->hctx, ld, io_u, 0, |
| 171 | f->fd, io_u->xfer_buf, io_u->xfer_buflen, |
| 172 | io_u->offset); |
| 173 | else if (io_u->ddir == DDIR_WRITE) |
| 174 | io_u->greq = guasi__pwrite(ld->hctx, ld, io_u, 0, |
| 175 | f->fd, io_u->xfer_buf, io_u->xfer_buflen, |
| 176 | io_u->offset); |
Jens Axboe | 5f9099e | 2009-06-16 22:40:26 +0200 | [diff] [blame] | 177 | else if (ddir_sync(io_u->ddir)) |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 178 | io_u->greq = guasi__fsync(ld->hctx, ld, io_u, 0, f->fd); |
| 179 | else { |
Jens Axboe | 0725726 | 2007-03-27 11:04:59 +0200 | [diff] [blame] | 180 | log_err("fio_guasi_commit() FAILED: unknow request %d\n", |
Davide Libenzi | 66b83d9 | 2007-03-21 09:15:13 +0100 | [diff] [blame] | 181 | io_u->ddir); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 182 | } |
Davide Libenzi | 97c26cb | 2007-03-26 12:20:49 +0200 | [diff] [blame] | 183 | if (io_u->greq == NULL) { |
Jens Axboe | 0725726 | 2007-03-27 11:04:59 +0200 | [diff] [blame] | 184 | log_err("fio_guasi_commit() FAILED: submit failed (%s)\n", |
Davide Libenzi | d6c6810 | 2007-03-22 07:43:55 +0100 | [diff] [blame] | 185 | strerror(errno)); |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 186 | return -1; |
| 187 | } |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 188 | } |
Davide Libenzi | 97c26cb | 2007-03-26 12:20:49 +0200 | [diff] [blame] | 189 | fio_guasi_queued(td, ld->io_us, i); |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 190 | ld->queued_nr = 0; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 191 | GDBG_PRINT(("fio_guasi_commit() -> %d\n", i)); |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
Jens Axboe | ffa59ce | 2007-06-19 14:25:46 +0200 | [diff] [blame] | 196 | static int fio_guasi_cancel(struct thread_data fio_unused *td, |
| 197 | struct io_u *io_u) |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 198 | { |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 199 | GDBG_PRINT(("fio_guasi_cancel(%p) req=%p\n", io_u, io_u->greq)); |
| 200 | if (io_u->greq != NULL) |
| 201 | guasi_req_cancel(io_u->greq); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 202 | |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 203 | return 0; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static void fio_guasi_cleanup(struct thread_data *td) |
| 207 | { |
| 208 | struct guasi_data *ld = td->io_ops->data; |
Davide Libenzi | 8999fe9 | 2007-03-27 08:14:13 +0200 | [diff] [blame] | 209 | int n; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 210 | |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 211 | GDBG_PRINT(("fio_guasi_cleanup(%p)\n", ld)); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 212 | if (ld) { |
Davide Libenzi | 8999fe9 | 2007-03-27 08:14:13 +0200 | [diff] [blame] | 213 | for (n = 0; n < ld->reqs_nr; n++) |
| 214 | guasi_req_free(ld->reqs[n]); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 215 | guasi_free(ld->hctx); |
| 216 | free(ld->reqs); |
| 217 | free(ld->io_us); |
| 218 | free(ld); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 219 | } |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 220 | GDBG_PRINT(("fio_guasi_cleanup(%p) DONE\n", ld)); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static int fio_guasi_init(struct thread_data *td) |
| 224 | { |
| 225 | int maxthr; |
| 226 | struct guasi_data *ld = malloc(sizeof(*ld)); |
| 227 | |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 228 | GDBG_PRINT(("fio_guasi_init(): depth=%d\n", td->o.iodepth)); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 229 | memset(ld, 0, sizeof(*ld)); |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 230 | maxthr = td->o.iodepth > GFIO_MIN_THREADS ? td->o.iodepth: GFIO_MIN_THREADS; |
Davide Libenzi | d6c6810 | 2007-03-22 07:43:55 +0100 | [diff] [blame] | 231 | if (maxthr > GFIO_MAX_THREADS) |
| 232 | maxthr = GFIO_MAX_THREADS; |
Davide Libenzi | 0798ba3 | 2007-04-10 22:29:29 +0200 | [diff] [blame] | 233 | if ((ld->hctx = guasi_create(GFIO_MIN_THREADS, maxthr, 1)) == NULL) { |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 234 | td_verror(td, errno, "guasi_create"); |
| 235 | free(ld); |
| 236 | return 1; |
| 237 | } |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 238 | ld->max_reqs = td->o.iodepth; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 239 | ld->reqs = malloc(ld->max_reqs * sizeof(guasi_req_t)); |
| 240 | ld->io_us = malloc(ld->max_reqs * sizeof(struct io_u *)); |
| 241 | memset(ld->io_us, 0, ld->max_reqs * sizeof(struct io_u *)); |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 242 | ld->queued_nr = 0; |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 243 | ld->reqs_nr = 0; |
| 244 | |
| 245 | td->io_ops->data = ld; |
Davide Libenzi | 46eaa15 | 2007-03-22 07:43:07 +0100 | [diff] [blame] | 246 | GDBG_PRINT(("fio_guasi_init(): depth=%d -> %p\n", td->o.iodepth, ld)); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | static struct ioengine_ops ioengine = { |
| 252 | .name = "guasi", |
| 253 | .version = FIO_IOOPS_VERSION, |
| 254 | .init = fio_guasi_init, |
| 255 | .prep = fio_guasi_prep, |
| 256 | .queue = fio_guasi_queue, |
| 257 | .commit = fio_guasi_commit, |
| 258 | .cancel = fio_guasi_cancel, |
| 259 | .getevents = fio_guasi_getevents, |
| 260 | .event = fio_guasi_event, |
| 261 | .cleanup = fio_guasi_cleanup, |
| 262 | .open_file = generic_open_file, |
| 263 | .close_file = generic_close_file, |
Jens Axboe | df9c26b | 2009-03-05 10:13:58 +0100 | [diff] [blame] | 264 | .get_file_size = generic_get_file_size, |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 265 | }; |
| 266 | |
| 267 | #else /* FIO_HAVE_GUASI */ |
| 268 | |
| 269 | /* |
| 270 | * When we have a proper configure system in place, we simply wont build |
| 271 | * and install this io engine. For now install a crippled version that |
| 272 | * just complains and fails to load. |
| 273 | */ |
| 274 | static int fio_guasi_init(struct thread_data fio_unused *td) |
| 275 | { |
Jens Axboe | a3edaf7 | 2010-09-26 10:53:40 +0900 | [diff] [blame] | 276 | log_err("fio: guasi not available\n"); |
Davide Libenzi | 609342f | 2007-03-21 08:46:18 +0100 | [diff] [blame] | 277 | return 1; |
| 278 | } |
| 279 | |
| 280 | static struct ioengine_ops ioengine = { |
| 281 | .name = "guasi", |
| 282 | .version = FIO_IOOPS_VERSION, |
| 283 | .init = fio_guasi_init, |
| 284 | }; |
| 285 | |
| 286 | #endif |
| 287 | |
| 288 | static void fio_init fio_guasi_register(void) |
| 289 | { |
| 290 | register_ioengine(&ioengine); |
| 291 | } |
| 292 | |
| 293 | static void fio_exit fio_guasi_unregister(void) |
| 294 | { |
| 295 | unregister_ioengine(&ioengine); |
| 296 | } |
| 297 | |