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
26 #define GFIO_MIN_THREADS 32
27 #ifndef GFIO_MAX_THREADS
28 #define GFIO_MAX_THREADS 2000
32 #include <guasi_syscalls.h>
35 #define GDBG_PRINT(a) printf a
37 #define GDBG_PRINT(a) (void) 0
49 static int fio_guasi_prep(struct thread_data fio_unused *td, struct io_u *io_u)
52 GDBG_PRINT(("fio_guasi_prep(%p)\n", io_u));
58 static struct io_u *fio_guasi_event(struct thread_data *td, int event)
60 struct guasi_data *ld = td->io_ops->data;
62 struct guasi_reqinfo rinf;
64 GDBG_PRINT(("fio_guasi_event(%d)\n", event));
65 if (guasi_req_info(ld->reqs[event], &rinf) < 0) {
66 log_err("guasi_req_info(%d) FAILED!\n", event);
70 io_u->error = EINPROGRESS;
71 GDBG_PRINT(("fio_guasi_event(%d) -> %p\n", event, io_u));
72 if (rinf.status == GUASI_STATUS_COMPLETE) {
73 io_u->error = rinf.result;
74 if (io_u->ddir == DDIR_READ ||
75 io_u->ddir == DDIR_WRITE) {
77 if (rinf.result != (long) io_u->xfer_buflen) {
79 io_u->resid = io_u->xfer_buflen - rinf.result;
81 io_u->error = rinf.error;
89 static int fio_guasi_getevents(struct thread_data *td, unsigned int min,
90 unsigned int max, struct timespec *t)
92 struct guasi_data *ld = td->io_ops->data;
96 GDBG_PRINT(("fio_guasi_getevents(%d, %d)\n", min, max));
97 if (min > ld->max_reqs)
99 if (max > ld->max_reqs)
102 timeo = t->tv_sec * 1000L + t->tv_nsec / 1000000L;
103 for (n = 0; n < ld->reqs_nr; n++)
104 guasi_req_free(ld->reqs[n]);
107 r = guasi_fetch(ld->hctx, ld->reqs + n, min - n,
110 log_err("guasi_fetch() FAILED! (%d)\n", r);
118 GDBG_PRINT(("fio_guasi_getevents() -> %d\n", n));
123 static int fio_guasi_queue(struct thread_data *td, struct io_u *io_u)
125 struct guasi_data *ld = td->io_ops->data;
127 fio_ro_check(td, io_u);
129 GDBG_PRINT(("fio_guasi_queue(%p)\n", io_u));
130 if (ld->queued_nr == (int) td->o.iodepth)
133 ld->io_us[ld->queued_nr] = io_u;
138 static void fio_guasi_queued(struct thread_data *td, struct io_u **io_us, int nr)
144 fio_gettime(&now, NULL);
145 for (i = 0; i < nr; i++) {
147 memcpy(&io_u->issue_time, &now, sizeof(now));
148 io_u_queued(td, io_u);
152 static int fio_guasi_commit(struct thread_data *td)
154 struct guasi_data *ld = td->io_ops->data;
159 GDBG_PRINT(("fio_guasi_commit(%d)\n", ld->queued_nr));
160 for (i = 0; i < ld->queued_nr; i++) {
162 GDBG_PRINT(("fio_guasi_commit(%d) --> %p\n", i, io_u));
165 if (io_u->ddir == DDIR_READ)
166 io_u->greq = guasi__pread(ld->hctx, ld, io_u, 0,
167 f->fd, io_u->xfer_buf, io_u->xfer_buflen,
169 else if (io_u->ddir == DDIR_WRITE)
170 io_u->greq = guasi__pwrite(ld->hctx, ld, io_u, 0,
171 f->fd, io_u->xfer_buf, io_u->xfer_buflen,
173 else if (io_u->ddir == DDIR_SYNC)
174 io_u->greq = guasi__fsync(ld->hctx, ld, io_u, 0, f->fd);
176 log_err("fio_guasi_commit() FAILED: unknow request %d\n",
179 if (io_u->greq == NULL) {
180 log_err("fio_guasi_commit() FAILED: submit failed (%s)\n",
185 fio_guasi_queued(td, ld->io_us, i);
187 GDBG_PRINT(("fio_guasi_commit() -> %d\n", i));
192 static int fio_guasi_cancel(struct thread_data fio_unused *td,
195 GDBG_PRINT(("fio_guasi_cancel(%p) req=%p\n", io_u, io_u->greq));
196 if (io_u->greq != NULL)
197 guasi_req_cancel(io_u->greq);
202 static void fio_guasi_cleanup(struct thread_data *td)
204 struct guasi_data *ld = td->io_ops->data;
207 GDBG_PRINT(("fio_guasi_cleanup(%p)\n", ld));
209 for (n = 0; n < ld->reqs_nr; n++)
210 guasi_req_free(ld->reqs[n]);
211 guasi_free(ld->hctx);
215 td->io_ops->data = NULL;
217 GDBG_PRINT(("fio_guasi_cleanup(%p) DONE\n", ld));
220 static int fio_guasi_init(struct thread_data *td)
223 struct guasi_data *ld = malloc(sizeof(*ld));
225 GDBG_PRINT(("fio_guasi_init(): depth=%d\n", td->o.iodepth));
226 memset(ld, 0, sizeof(*ld));
227 maxthr = td->o.iodepth > GFIO_MIN_THREADS ? td->o.iodepth: GFIO_MIN_THREADS;
228 if (maxthr > GFIO_MAX_THREADS)
229 maxthr = GFIO_MAX_THREADS;
230 if ((ld->hctx = guasi_create(GFIO_MIN_THREADS, maxthr, 1)) == NULL) {
231 td_verror(td, errno, "guasi_create");
235 ld->max_reqs = td->o.iodepth;
236 ld->reqs = malloc(ld->max_reqs * sizeof(guasi_req_t));
237 ld->io_us = malloc(ld->max_reqs * sizeof(struct io_u *));
238 memset(ld->io_us, 0, ld->max_reqs * sizeof(struct io_u *));
242 td->io_ops->data = ld;
243 GDBG_PRINT(("fio_guasi_init(): depth=%d -> %p\n", td->o.iodepth, ld));
248 static struct ioengine_ops ioengine = {
250 .version = FIO_IOOPS_VERSION,
251 .init = fio_guasi_init,
252 .prep = fio_guasi_prep,
253 .queue = fio_guasi_queue,
254 .commit = fio_guasi_commit,
255 .cancel = fio_guasi_cancel,
256 .getevents = fio_guasi_getevents,
257 .event = fio_guasi_event,
258 .cleanup = fio_guasi_cleanup,
259 .open_file = generic_open_file,
260 .close_file = generic_close_file,
263 #else /* FIO_HAVE_GUASI */
266 * When we have a proper configure system in place, we simply wont build
267 * and install this io engine. For now install a crippled version that
268 * just complains and fails to load.
270 static int fio_guasi_init(struct thread_data fio_unused *td)
272 fprintf(stderr, "fio: guasi not available\n");
276 static struct ioengine_ops ioengine = {
278 .version = FIO_IOOPS_VERSION,
279 .init = fio_guasi_init,
284 static void fio_init fio_guasi_register(void)
286 register_ioengine(&ioengine);
289 static void fio_exit fio_guasi_unregister(void)
291 unregister_ioengine(&ioengine);