blob: 4839019fc49c3ec88facc04eda4e5c812b3a68f9 [file] [log] [blame]
Davide Libenzi609342f2007-03-21 08:46:18 +01001/*
2 * guasi engine
3 *
4 * IO engine using the GUASI library.
5 *
Davide Libenzi46eaa152007-03-22 07:43:07 +01006 * 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 Libenzi609342f2007-03-21 08:46:18 +010012 *
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 Libenzi609342f2007-03-21 08:46:18 +010023
24#ifdef FIO_HAVE_GUASI
25
26#define GFIO_MIN_THREADS 32
Davide Libenzid6c68102007-03-22 07:43:55 +010027#ifndef GFIO_MAX_THREADS
Davide Libenzi97c26cb2007-03-26 12:20:49 +020028#define GFIO_MAX_THREADS 2000
Davide Libenzid6c68102007-03-22 07:43:55 +010029#endif
Davide Libenzi609342f2007-03-21 08:46:18 +010030
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 Libenzi609342f2007-03-21 08:46:18 +010040struct guasi_data {
41 guasi_t hctx;
42 int max_reqs;
43 guasi_req_t *reqs;
44 struct io_u **io_us;
Davide Libenzi46eaa152007-03-22 07:43:07 +010045 int queued_nr;
Davide Libenzi609342f2007-03-21 08:46:18 +010046 int reqs_nr;
47};
48
49static int fio_guasi_prep(struct thread_data fio_unused *td, struct io_u *io_u)
50{
Davide Libenzi609342f2007-03-21 08:46:18 +010051
52 GDBG_PRINT(("fio_guasi_prep(%p)\n", io_u));
Davide Libenzi46eaa152007-03-22 07:43:07 +010053 io_u->greq = NULL;
Davide Libenzi609342f2007-03-21 08:46:18 +010054
55 return 0;
56}
57
58static 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 Axboe07257262007-03-27 11:04:59 +020066 log_err("guasi_req_info(%d) FAILED!\n", event);
Davide Libenzi609342f2007-03-21 08:46:18 +010067 return NULL;
68 }
69 io_u = rinf.asid;
Davide Libenzi66b83d92007-03-21 09:15:13 +010070 io_u->error = EINPROGRESS;
Davide Libenzi609342f2007-03-21 08:46:18 +010071 GDBG_PRINT(("fio_guasi_event(%d) -> %p\n", event, io_u));
Davide Libenzi66b83d92007-03-21 09:15:13 +010072 if (rinf.status == GUASI_STATUS_COMPLETE) {
Davide Libenzi609342f2007-03-21 08:46:18 +010073 io_u->error = rinf.result;
Davide Libenzi66b83d92007-03-21 09:15:13 +010074 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 Libenzi609342f2007-03-21 08:46:18 +010085
86 return io_u;
87}
88
Jens Axboee7d2e612007-12-11 10:49:39 +010089static int fio_guasi_getevents(struct thread_data *td, unsigned int min,
90 unsigned int max, struct timespec *t)
Davide Libenzi609342f2007-03-21 08:46:18 +010091{
92 struct guasi_data *ld = td->io_ops->data;
Davide Libenzi46eaa152007-03-22 07:43:07 +010093 int n, r;
Davide Libenzi609342f2007-03-21 08:46:18 +010094 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 Libenzi46eaa152007-03-22 07:43:07 +0100103 for (n = 0; n < ld->reqs_nr; n++)
104 guasi_req_free(ld->reqs[n]);
105 n = 0;
Davide Libenzi609342f2007-03-21 08:46:18 +0100106 do {
Davide Libenzi97c26cb2007-03-26 12:20:49 +0200107 r = guasi_fetch(ld->hctx, ld->reqs + n, min - n,
108 max - n, timeo);
109 if (r < 0) {
Jens Axboe07257262007-03-27 11:04:59 +0200110 log_err("guasi_fetch() FAILED! (%d)\n", r);
Davide Libenzi609342f2007-03-21 08:46:18 +0100111 break;
Davide Libenzi97c26cb2007-03-26 12:20:49 +0200112 }
Davide Libenzi609342f2007-03-21 08:46:18 +0100113 n += r;
114 if (n >= min)
115 break;
116 } while (1);
Davide Libenzi46eaa152007-03-22 07:43:07 +0100117 ld->reqs_nr = n;
Davide Libenzi609342f2007-03-21 08:46:18 +0100118 GDBG_PRINT(("fio_guasi_getevents() -> %d\n", n));
119
120 return n;
121}
122
123static 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 Axboe7101d9c2007-09-12 13:12:39 +0200127 fio_ro_check(td, io_u);
128
Davide Libenzi609342f2007-03-21 08:46:18 +0100129 GDBG_PRINT(("fio_guasi_queue(%p)\n", io_u));
Davide Libenzi46eaa152007-03-22 07:43:07 +0100130 if (ld->queued_nr == (int) td->o.iodepth)
Davide Libenzi609342f2007-03-21 08:46:18 +0100131 return FIO_Q_BUSY;
132
Davide Libenzi46eaa152007-03-22 07:43:07 +0100133 ld->io_us[ld->queued_nr] = io_u;
134 ld->queued_nr++;
Davide Libenzi609342f2007-03-21 08:46:18 +0100135 return FIO_Q_QUEUED;
136}
137
Davide Libenzi97c26cb2007-03-26 12:20:49 +0200138static void fio_guasi_queued(struct thread_data *td, struct io_u **io_us, int nr)
Davide Libenzi609342f2007-03-21 08:46:18 +0100139{
Davide Libenzi97c26cb2007-03-26 12:20:49 +0200140 int i;
141 struct io_u *io_u;
Davide Libenzi609342f2007-03-21 08:46:18 +0100142 struct timeval now;
Davide Libenzi609342f2007-03-21 08:46:18 +0100143
Jens Axboe12d9d842008-10-16 21:26:10 +0200144 if (!fio_fill_issue_time(td))
145 return;
146
Jens Axboe838bc702008-05-22 13:08:23 +0200147 io_u_mark_submit(td, nr);
Davide Libenzi609342f2007-03-21 08:46:18 +0100148 fio_gettime(&now, NULL);
Davide Libenzi97c26cb2007-03-26 12:20:49 +0200149 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 Libenzi609342f2007-03-21 08:46:18 +0100154}
155
156static 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 Libenzid6c68102007-03-22 07:43:55 +0100163 GDBG_PRINT(("fio_guasi_commit(%d)\n", ld->queued_nr));
Davide Libenzi46eaa152007-03-22 07:43:07 +0100164 for (i = 0; i < ld->queued_nr; i++) {
Davide Libenzi609342f2007-03-21 08:46:18 +0100165 io_u = ld->io_us[i];
Davide Libenzid6c68102007-03-22 07:43:55 +0100166 GDBG_PRINT(("fio_guasi_commit(%d) --> %p\n", i, io_u));
Davide Libenzi609342f2007-03-21 08:46:18 +0100167 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 Axboe5f9099e2009-06-16 22:40:26 +0200177 else if (ddir_sync(io_u->ddir))
Davide Libenzi609342f2007-03-21 08:46:18 +0100178 io_u->greq = guasi__fsync(ld->hctx, ld, io_u, 0, f->fd);
179 else {
Jens Axboe07257262007-03-27 11:04:59 +0200180 log_err("fio_guasi_commit() FAILED: unknow request %d\n",
Davide Libenzi66b83d92007-03-21 09:15:13 +0100181 io_u->ddir);
Davide Libenzi609342f2007-03-21 08:46:18 +0100182 }
Davide Libenzi97c26cb2007-03-26 12:20:49 +0200183 if (io_u->greq == NULL) {
Jens Axboe07257262007-03-27 11:04:59 +0200184 log_err("fio_guasi_commit() FAILED: submit failed (%s)\n",
Davide Libenzid6c68102007-03-22 07:43:55 +0100185 strerror(errno));
Davide Libenzi46eaa152007-03-22 07:43:07 +0100186 return -1;
187 }
Davide Libenzi609342f2007-03-21 08:46:18 +0100188 }
Davide Libenzi97c26cb2007-03-26 12:20:49 +0200189 fio_guasi_queued(td, ld->io_us, i);
Davide Libenzi46eaa152007-03-22 07:43:07 +0100190 ld->queued_nr = 0;
Davide Libenzi609342f2007-03-21 08:46:18 +0100191 GDBG_PRINT(("fio_guasi_commit() -> %d\n", i));
192
193 return 0;
194}
195
Jens Axboeffa59ce2007-06-19 14:25:46 +0200196static int fio_guasi_cancel(struct thread_data fio_unused *td,
197 struct io_u *io_u)
Davide Libenzi609342f2007-03-21 08:46:18 +0100198{
Davide Libenzi46eaa152007-03-22 07:43:07 +0100199 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 Libenzi609342f2007-03-21 08:46:18 +0100202
Davide Libenzi46eaa152007-03-22 07:43:07 +0100203 return 0;
Davide Libenzi609342f2007-03-21 08:46:18 +0100204}
205
206static void fio_guasi_cleanup(struct thread_data *td)
207{
208 struct guasi_data *ld = td->io_ops->data;
Davide Libenzi8999fe92007-03-27 08:14:13 +0200209 int n;
Davide Libenzi609342f2007-03-21 08:46:18 +0100210
Davide Libenzi46eaa152007-03-22 07:43:07 +0100211 GDBG_PRINT(("fio_guasi_cleanup(%p)\n", ld));
Davide Libenzi609342f2007-03-21 08:46:18 +0100212 if (ld) {
Davide Libenzi8999fe92007-03-27 08:14:13 +0200213 for (n = 0; n < ld->reqs_nr; n++)
214 guasi_req_free(ld->reqs[n]);
Davide Libenzi609342f2007-03-21 08:46:18 +0100215 guasi_free(ld->hctx);
216 free(ld->reqs);
217 free(ld->io_us);
218 free(ld);
Davide Libenzi609342f2007-03-21 08:46:18 +0100219 }
Davide Libenzi46eaa152007-03-22 07:43:07 +0100220 GDBG_PRINT(("fio_guasi_cleanup(%p) DONE\n", ld));
Davide Libenzi609342f2007-03-21 08:46:18 +0100221}
222
223static int fio_guasi_init(struct thread_data *td)
224{
225 int maxthr;
226 struct guasi_data *ld = malloc(sizeof(*ld));
227
Davide Libenzi46eaa152007-03-22 07:43:07 +0100228 GDBG_PRINT(("fio_guasi_init(): depth=%d\n", td->o.iodepth));
Davide Libenzi609342f2007-03-21 08:46:18 +0100229 memset(ld, 0, sizeof(*ld));
Davide Libenzi46eaa152007-03-22 07:43:07 +0100230 maxthr = td->o.iodepth > GFIO_MIN_THREADS ? td->o.iodepth: GFIO_MIN_THREADS;
Davide Libenzid6c68102007-03-22 07:43:55 +0100231 if (maxthr > GFIO_MAX_THREADS)
232 maxthr = GFIO_MAX_THREADS;
Davide Libenzi0798ba32007-04-10 22:29:29 +0200233 if ((ld->hctx = guasi_create(GFIO_MIN_THREADS, maxthr, 1)) == NULL) {
Davide Libenzi609342f2007-03-21 08:46:18 +0100234 td_verror(td, errno, "guasi_create");
235 free(ld);
236 return 1;
237 }
Davide Libenzi46eaa152007-03-22 07:43:07 +0100238 ld->max_reqs = td->o.iodepth;
Davide Libenzi609342f2007-03-21 08:46:18 +0100239 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 Libenzi46eaa152007-03-22 07:43:07 +0100242 ld->queued_nr = 0;
Davide Libenzi609342f2007-03-21 08:46:18 +0100243 ld->reqs_nr = 0;
244
245 td->io_ops->data = ld;
Davide Libenzi46eaa152007-03-22 07:43:07 +0100246 GDBG_PRINT(("fio_guasi_init(): depth=%d -> %p\n", td->o.iodepth, ld));
Davide Libenzi609342f2007-03-21 08:46:18 +0100247
248 return 0;
249}
250
251static 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 Axboedf9c26b2009-03-05 10:13:58 +0100264 .get_file_size = generic_get_file_size,
Davide Libenzi609342f2007-03-21 08:46:18 +0100265};
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 */
274static int fio_guasi_init(struct thread_data fio_unused *td)
275{
Jens Axboea3edaf72010-09-26 10:53:40 +0900276 log_err("fio: guasi not available\n");
Davide Libenzi609342f2007-03-21 08:46:18 +0100277 return 1;
278}
279
280static struct ioengine_ops ioengine = {
281 .name = "guasi",
282 .version = FIO_IOOPS_VERSION,
283 .init = fio_guasi_init,
284};
285
286#endif
287
288static void fio_init fio_guasi_register(void)
289{
290 register_ioengine(&ioengine);
291}
292
293static void fio_exit fio_guasi_unregister(void)
294{
295 unregister_ioengine(&ioengine);
296}
297