4 * IO engine using the GUASI library.
6 * This is currently disabled. To enable it, execute:
8 * $ export EXTFLAGS="-DFIO_HAVE_GUASI"
9 * $ export EXTLIBS="-lguasi"
11 * before running make. You'll need the GUASI lib as well:
13 * http://www.xmailserver.org/guasi-lib.html
27 #define GFIO_MIN_THREADS 32
28 #ifndef GFIO_MAX_THREADS
29 #define GFIO_MAX_THREADS 280
33 #include <guasi_syscalls.h>
36 #define GDBG_PRINT(a) printf a
38 #define GDBG_PRINT(a) (void) 0
41 #define STFU_GCC(a) a = a
53 static int fio_guasi_prep(struct thread_data fio_unused *td, struct io_u *io_u)
56 GDBG_PRINT(("fio_guasi_prep(%p)\n", io_u));
62 static struct io_u *fio_guasi_event(struct thread_data *td, int event)
64 struct guasi_data *ld = td->io_ops->data;
66 struct guasi_reqinfo rinf;
68 GDBG_PRINT(("fio_guasi_event(%d)\n", event));
69 if (guasi_req_info(ld->reqs[event], &rinf) < 0) {
70 fprintf(stderr, "guasi_req_info(%d) FAILED!\n", event);
74 io_u->error = EINPROGRESS;
75 GDBG_PRINT(("fio_guasi_event(%d) -> %p\n", event, io_u));
76 if (rinf.status == GUASI_STATUS_COMPLETE) {
77 io_u->error = rinf.result;
78 if (io_u->ddir == DDIR_READ ||
79 io_u->ddir == DDIR_WRITE) {
81 if (rinf.result != (long) io_u->xfer_buflen) {
83 io_u->resid = io_u->xfer_buflen - rinf.result;
85 io_u->error = rinf.error;
93 static int fio_guasi_getevents(struct thread_data *td, int min, int max,
96 struct guasi_data *ld = td->io_ops->data;
100 GDBG_PRINT(("fio_guasi_getevents(%d, %d)\n", min, max));
101 if (min > ld->max_reqs)
103 if (max > ld->max_reqs)
106 timeo = t->tv_sec * 1000L + t->tv_nsec / 1000000L;
107 for (n = 0; n < ld->reqs_nr; n++)
108 guasi_req_free(ld->reqs[n]);
111 r = guasi_fetch(ld->hctx, ld->reqs + n, max - n, timeo);
119 GDBG_PRINT(("fio_guasi_getevents() -> %d\n", n));
124 static int fio_guasi_queue(struct thread_data *td, struct io_u *io_u)
126 struct guasi_data *ld = td->io_ops->data;
128 GDBG_PRINT(("fio_guasi_queue(%p)\n", io_u));
129 if (ld->queued_nr == (int) td->o.iodepth)
132 ld->io_us[ld->queued_nr] = io_u;
137 static void fio_guasi_queued(struct thread_data *td, struct io_u **io_us,
141 struct io_u *io_u = io_us[nr];
143 fio_gettime(&now, NULL);
144 memcpy(&io_u->issue_time, &now, sizeof(now));
145 io_u_queued(td, io_u);
148 static int fio_guasi_commit(struct thread_data *td)
150 struct guasi_data *ld = td->io_ops->data;
155 GDBG_PRINT(("fio_guasi_commit(%d)\n", ld->queued_nr));
156 for (i = 0; i < ld->queued_nr; i++) {
158 GDBG_PRINT(("fio_guasi_commit(%d) --> %p\n", i, io_u));
161 if (io_u->ddir == DDIR_READ)
162 io_u->greq = guasi__pread(ld->hctx, ld, io_u, 0,
163 f->fd, io_u->xfer_buf, io_u->xfer_buflen,
165 else if (io_u->ddir == DDIR_WRITE)
166 io_u->greq = guasi__pwrite(ld->hctx, ld, io_u, 0,
167 f->fd, io_u->xfer_buf, io_u->xfer_buflen,
169 else if (io_u->ddir == DDIR_SYNC)
170 io_u->greq = guasi__fsync(ld->hctx, ld, io_u, 0, f->fd);
172 fprintf(stderr, "fio_guasi_commit() FAILED: unknow request %d\n",
175 if (io_u->greq != NULL)
176 fio_guasi_queued(td, ld->io_us, i);
178 fprintf(stderr, "fio_guasi_commit() FAILED: submit failed (%s)\n",
184 GDBG_PRINT(("fio_guasi_commit() -> %d\n", i));
189 static int fio_guasi_cancel(struct thread_data *td, struct io_u *io_u)
191 struct guasi_data *ld = td->io_ops->data;
194 GDBG_PRINT(("fio_guasi_cancel(%p) req=%p\n", io_u, io_u->greq));
195 if (io_u->greq != NULL)
196 guasi_req_cancel(io_u->greq);
201 static void fio_guasi_cleanup(struct thread_data *td)
203 struct guasi_data *ld = td->io_ops->data;
205 GDBG_PRINT(("fio_guasi_cleanup(%p)\n", ld));
207 guasi_free(ld->hctx);
211 td->io_ops->data = NULL;
213 GDBG_PRINT(("fio_guasi_cleanup(%p) DONE\n", ld));
216 static int fio_guasi_init(struct thread_data *td)
219 struct guasi_data *ld = malloc(sizeof(*ld));
221 GDBG_PRINT(("fio_guasi_init(): depth=%d\n", td->o.iodepth));
222 memset(ld, 0, sizeof(*ld));
223 maxthr = td->o.iodepth > GFIO_MIN_THREADS ? td->o.iodepth: GFIO_MIN_THREADS;
224 if (maxthr > GFIO_MAX_THREADS)
225 maxthr = GFIO_MAX_THREADS;
226 if ((ld->hctx = guasi_create(GFIO_MIN_THREADS, maxthr, 1)) == NULL) {
227 td_verror(td, errno, "guasi_create");
231 ld->max_reqs = td->o.iodepth;
232 ld->reqs = malloc(ld->max_reqs * sizeof(guasi_req_t));
233 ld->io_us = malloc(ld->max_reqs * sizeof(struct io_u *));
234 memset(ld->io_us, 0, ld->max_reqs * sizeof(struct io_u *));
238 td->io_ops->data = ld;
239 GDBG_PRINT(("fio_guasi_init(): depth=%d -> %p\n", td->o.iodepth, ld));
244 static struct ioengine_ops ioengine = {
246 .version = FIO_IOOPS_VERSION,
247 .init = fio_guasi_init,
248 .prep = fio_guasi_prep,
249 .queue = fio_guasi_queue,
250 .commit = fio_guasi_commit,
251 .cancel = fio_guasi_cancel,
252 .getevents = fio_guasi_getevents,
253 .event = fio_guasi_event,
254 .cleanup = fio_guasi_cleanup,
255 .open_file = generic_open_file,
256 .close_file = generic_close_file,
259 #else /* FIO_HAVE_GUASI */
262 * When we have a proper configure system in place, we simply wont build
263 * and install this io engine. For now install a crippled version that
264 * just complains and fails to load.
266 static int fio_guasi_init(struct thread_data fio_unused *td)
268 fprintf(stderr, "fio: guasi not available\n");
272 static struct ioengine_ops ioengine = {
274 .version = FIO_IOOPS_VERSION,
275 .init = fio_guasi_init,
280 static void fio_init fio_guasi_register(void)
282 register_ioengine(&ioengine);
285 static void fio_exit fio_guasi_unregister(void)
287 unregister_ioengine(&ioengine);