4 * IO engine using the GUASI library.
6 * Before running make. You'll need the GUASI lib as well:
8 * http://www.xmailserver.org/guasi-lib.html
19 #define GFIO_MIN_THREADS 32
20 #ifndef GFIO_MAX_THREADS
21 #define GFIO_MAX_THREADS 2000
25 #include <guasi_syscalls.h>
28 #define GDBG_PRINT(a) printf a
30 #define GDBG_PRINT(a) (void) 0
42 static int fio_guasi_prep(struct thread_data fio_unused *td, struct io_u *io_u)
45 GDBG_PRINT(("fio_guasi_prep(%p)\n", io_u));
51 static struct io_u *fio_guasi_event(struct thread_data *td, int event)
53 struct guasi_data *ld = td->io_ops_data;
55 struct guasi_reqinfo rinf;
57 GDBG_PRINT(("fio_guasi_event(%d)\n", event));
58 if (guasi_req_info(ld->reqs[event], &rinf) < 0) {
59 log_err("guasi_req_info(%d) FAILED!\n", event);
63 io_u->error = EINPROGRESS;
64 GDBG_PRINT(("fio_guasi_event(%d) -> %p\n", event, io_u));
65 if (rinf.status == GUASI_STATUS_COMPLETE) {
66 io_u->error = rinf.result;
67 if (io_u->ddir == DDIR_READ ||
68 io_u->ddir == DDIR_WRITE) {
70 if (rinf.result != (long) io_u->xfer_buflen) {
72 io_u->resid = io_u->xfer_buflen - rinf.result;
74 io_u->error = rinf.error;
82 static int fio_guasi_getevents(struct thread_data *td, unsigned int min,
83 unsigned int max, const struct timespec *t)
85 struct guasi_data *ld = td->io_ops_data;
89 GDBG_PRINT(("fio_guasi_getevents(%d, %d)\n", min, max));
90 if (min > ld->max_reqs)
92 if (max > ld->max_reqs)
95 timeo = t->tv_sec * 1000L + t->tv_nsec / 1000000L;
96 for (n = 0; n < ld->reqs_nr; n++)
97 guasi_req_free(ld->reqs[n]);
100 r = guasi_fetch(ld->hctx, ld->reqs + n, min - n,
103 log_err("guasi_fetch() FAILED! (%d)\n", r);
111 GDBG_PRINT(("fio_guasi_getevents() -> %d\n", n));
116 static enum fio_q_status fio_guasi_queue(struct thread_data *td,
119 struct guasi_data *ld = td->io_ops_data;
121 fio_ro_check(td, io_u);
123 GDBG_PRINT(("fio_guasi_queue(%p)\n", io_u));
124 if (ld->queued_nr == (int) td->o.iodepth)
127 ld->io_us[ld->queued_nr] = io_u;
132 static void fio_guasi_queued(struct thread_data *td, struct io_u **io_us, int nr)
138 if (!fio_fill_issue_time(td))
141 io_u_mark_submit(td, nr);
142 fio_gettime(&now, NULL);
143 for (i = 0; i < nr; i++) {
145 memcpy(&io_u->issue_time, &now, sizeof(now));
146 io_u_queued(td, io_u);
150 static int fio_guasi_commit(struct thread_data *td)
152 struct guasi_data *ld = td->io_ops_data;
157 GDBG_PRINT(("fio_guasi_commit(%d)\n", ld->queued_nr));
158 for (i = 0; i < ld->queued_nr; i++) {
160 GDBG_PRINT(("fio_guasi_commit(%d) --> %p\n", i, io_u));
163 if (io_u->ddir == DDIR_READ)
164 io_u->greq = guasi__pread(ld->hctx, ld, io_u, 0,
165 f->fd, io_u->xfer_buf, io_u->xfer_buflen,
167 else if (io_u->ddir == DDIR_WRITE)
168 io_u->greq = guasi__pwrite(ld->hctx, ld, io_u, 0,
169 f->fd, io_u->xfer_buf, io_u->xfer_buflen,
171 else if (ddir_sync(io_u->ddir))
172 io_u->greq = guasi__fsync(ld->hctx, ld, io_u, 0, f->fd);
174 log_err("fio_guasi_commit() FAILED: unknow request %d\n",
177 if (io_u->greq == NULL) {
178 log_err("fio_guasi_commit() FAILED: submit failed (%s)\n",
183 fio_guasi_queued(td, ld->io_us, i);
185 GDBG_PRINT(("fio_guasi_commit() -> %d\n", i));
190 static int fio_guasi_cancel(struct thread_data fio_unused *td,
193 GDBG_PRINT(("fio_guasi_cancel(%p) req=%p\n", io_u, io_u->greq));
194 if (io_u->greq != NULL)
195 guasi_req_cancel(io_u->greq);
200 static void fio_guasi_cleanup(struct thread_data *td)
202 struct guasi_data *ld = td->io_ops_data;
205 GDBG_PRINT(("fio_guasi_cleanup(%p)\n", ld));
207 for (n = 0; n < ld->reqs_nr; n++)
208 guasi_req_free(ld->reqs[n]);
209 guasi_free(ld->hctx);
214 GDBG_PRINT(("fio_guasi_cleanup(%p) DONE\n", ld));
217 static int fio_guasi_init(struct thread_data *td)
220 struct guasi_data *ld = malloc(sizeof(*ld));
222 GDBG_PRINT(("fio_guasi_init(): depth=%d\n", td->o.iodepth));
223 memset(ld, 0, sizeof(*ld));
224 maxthr = td->o.iodepth > GFIO_MIN_THREADS ? td->o.iodepth: GFIO_MIN_THREADS;
225 if (maxthr > GFIO_MAX_THREADS)
226 maxthr = GFIO_MAX_THREADS;
227 if ((ld->hctx = guasi_create(GFIO_MIN_THREADS, maxthr, 1)) == NULL) {
228 td_verror(td, errno, "guasi_create");
232 ld->max_reqs = td->o.iodepth;
233 ld->reqs = malloc(ld->max_reqs * sizeof(guasi_req_t));
234 ld->io_us = malloc(ld->max_reqs * sizeof(struct io_u *));
235 memset(ld->io_us, 0, ld->max_reqs * sizeof(struct io_u *));
239 td->io_ops_data = ld;
240 GDBG_PRINT(("fio_guasi_init(): depth=%d -> %p\n", td->o.iodepth, ld));
245 static struct ioengine_ops ioengine = {
247 .version = FIO_IOOPS_VERSION,
248 .init = fio_guasi_init,
249 .prep = fio_guasi_prep,
250 .queue = fio_guasi_queue,
251 .commit = fio_guasi_commit,
252 .cancel = fio_guasi_cancel,
253 .getevents = fio_guasi_getevents,
254 .event = fio_guasi_event,
255 .cleanup = fio_guasi_cleanup,
256 .open_file = generic_open_file,
257 .close_file = generic_close_file,
258 .get_file_size = generic_get_file_size,
261 static void fio_init fio_guasi_register(void)
263 register_ioengine(&ioengine);
266 static void fio_exit fio_guasi_unregister(void)
268 unregister_ioengine(&ioengine);