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
24 #define GFIO_MIN_THREADS 32
25 #ifndef GFIO_MAX_THREADS
26 #define GFIO_MAX_THREADS 2000
30 #include <guasi_syscalls.h>
33 #define GDBG_PRINT(a) printf a
35 #define GDBG_PRINT(a) (void) 0
47 static int fio_guasi_prep(struct thread_data fio_unused *td, struct io_u *io_u)
50 GDBG_PRINT(("fio_guasi_prep(%p)\n", io_u));
56 static struct io_u *fio_guasi_event(struct thread_data *td, int event)
58 struct guasi_data *ld = td->io_ops->data;
60 struct guasi_reqinfo rinf;
62 GDBG_PRINT(("fio_guasi_event(%d)\n", event));
63 if (guasi_req_info(ld->reqs[event], &rinf) < 0) {
64 log_err("guasi_req_info(%d) FAILED!\n", event);
68 io_u->error = EINPROGRESS;
69 GDBG_PRINT(("fio_guasi_event(%d) -> %p\n", event, io_u));
70 if (rinf.status == GUASI_STATUS_COMPLETE) {
71 io_u->error = rinf.result;
72 if (io_u->ddir == DDIR_READ ||
73 io_u->ddir == DDIR_WRITE) {
75 if (rinf.result != (long) io_u->xfer_buflen) {
77 io_u->resid = io_u->xfer_buflen - rinf.result;
79 io_u->error = rinf.error;
87 static int fio_guasi_getevents(struct thread_data *td, unsigned int min,
88 unsigned int max, struct timespec *t)
90 struct guasi_data *ld = td->io_ops->data;
94 GDBG_PRINT(("fio_guasi_getevents(%d, %d)\n", min, max));
95 if (min > ld->max_reqs)
97 if (max > ld->max_reqs)
100 timeo = t->tv_sec * 1000L + t->tv_nsec / 1000000L;
101 for (n = 0; n < ld->reqs_nr; n++)
102 guasi_req_free(ld->reqs[n]);
105 r = guasi_fetch(ld->hctx, ld->reqs + n, min - n,
108 log_err("guasi_fetch() FAILED! (%d)\n", r);
116 GDBG_PRINT(("fio_guasi_getevents() -> %d\n", n));
121 static int fio_guasi_queue(struct thread_data *td, struct io_u *io_u)
123 struct guasi_data *ld = td->io_ops->data;
125 fio_ro_check(td, io_u);
127 GDBG_PRINT(("fio_guasi_queue(%p)\n", io_u));
128 if (ld->queued_nr == (int) td->o.iodepth)
131 ld->io_us[ld->queued_nr] = io_u;
136 static void fio_guasi_queued(struct thread_data *td, struct io_u **io_us, int nr)
142 if (!fio_fill_issue_time(td))
145 io_u_mark_submit(td, nr);
146 fio_gettime(&now, NULL);
147 for (i = 0; i < nr; i++) {
149 memcpy(&io_u->issue_time, &now, sizeof(now));
150 io_u_queued(td, io_u);
154 static int fio_guasi_commit(struct thread_data *td)
156 struct guasi_data *ld = td->io_ops->data;
161 GDBG_PRINT(("fio_guasi_commit(%d)\n", ld->queued_nr));
162 for (i = 0; i < ld->queued_nr; i++) {
164 GDBG_PRINT(("fio_guasi_commit(%d) --> %p\n", i, io_u));
167 if (io_u->ddir == DDIR_READ)
168 io_u->greq = guasi__pread(ld->hctx, ld, io_u, 0,
169 f->fd, io_u->xfer_buf, io_u->xfer_buflen,
171 else if (io_u->ddir == DDIR_WRITE)
172 io_u->greq = guasi__pwrite(ld->hctx, ld, io_u, 0,
173 f->fd, io_u->xfer_buf, io_u->xfer_buflen,
175 else if (ddir_sync(io_u->ddir))
176 io_u->greq = guasi__fsync(ld->hctx, ld, io_u, 0, f->fd);
178 log_err("fio_guasi_commit() FAILED: unknow request %d\n",
181 if (io_u->greq == NULL) {
182 log_err("fio_guasi_commit() FAILED: submit failed (%s)\n",
187 fio_guasi_queued(td, ld->io_us, i);
189 GDBG_PRINT(("fio_guasi_commit() -> %d\n", i));
194 static int fio_guasi_cancel(struct thread_data fio_unused *td,
197 GDBG_PRINT(("fio_guasi_cancel(%p) req=%p\n", io_u, io_u->greq));
198 if (io_u->greq != NULL)
199 guasi_req_cancel(io_u->greq);
204 static void fio_guasi_cleanup(struct thread_data *td)
206 struct guasi_data *ld = td->io_ops->data;
209 GDBG_PRINT(("fio_guasi_cleanup(%p)\n", ld));
211 for (n = 0; n < ld->reqs_nr; n++)
212 guasi_req_free(ld->reqs[n]);
213 guasi_free(ld->hctx);
218 GDBG_PRINT(("fio_guasi_cleanup(%p) DONE\n", ld));
221 static int fio_guasi_init(struct thread_data *td)
224 struct guasi_data *ld = malloc(sizeof(*ld));
226 GDBG_PRINT(("fio_guasi_init(): depth=%d\n", td->o.iodepth));
227 memset(ld, 0, sizeof(*ld));
228 maxthr = td->o.iodepth > GFIO_MIN_THREADS ? td->o.iodepth: GFIO_MIN_THREADS;
229 if (maxthr > GFIO_MAX_THREADS)
230 maxthr = GFIO_MAX_THREADS;
231 if ((ld->hctx = guasi_create(GFIO_MIN_THREADS, maxthr, 1)) == NULL) {
232 td_verror(td, errno, "guasi_create");
236 ld->max_reqs = td->o.iodepth;
237 ld->reqs = malloc(ld->max_reqs * sizeof(guasi_req_t));
238 ld->io_us = malloc(ld->max_reqs * sizeof(struct io_u *));
239 memset(ld->io_us, 0, ld->max_reqs * sizeof(struct io_u *));
243 td->io_ops->data = ld;
244 GDBG_PRINT(("fio_guasi_init(): depth=%d -> %p\n", td->o.iodepth, ld));
249 static struct ioengine_ops ioengine = {
251 .version = FIO_IOOPS_VERSION,
252 .init = fio_guasi_init,
253 .prep = fio_guasi_prep,
254 .queue = fio_guasi_queue,
255 .commit = fio_guasi_commit,
256 .cancel = fio_guasi_cancel,
257 .getevents = fio_guasi_getevents,
258 .event = fio_guasi_event,
259 .cleanup = fio_guasi_cleanup,
260 .open_file = generic_open_file,
261 .close_file = generic_close_file,
262 .get_file_size = generic_get_file_size,
265 static void fio_init fio_guasi_register(void)
267 register_ioengine(&ioengine);
270 static void fio_exit fio_guasi_unregister(void)
272 unregister_ioengine(&ioengine);