sg engine: fix old comment
[fio.git] / engines / guasi.c
CommitLineData
609342ff
DL
1/*
2 * guasi engine
3 *
4 * IO engine using the GUASI library.
5 *
46eaa157
DL
6 * 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:
609342ff
DL
12 *
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"
23#include "../os.h"
24
25#ifdef FIO_HAVE_GUASI
26
27#define GFIO_MIN_THREADS 32
d6c6810f 28#ifndef GFIO_MAX_THREADS
97c26cbe 29#define GFIO_MAX_THREADS 2000
d6c6810f 30#endif
609342ff
DL
31
32#include <guasi.h>
33#include <guasi_syscalls.h>
34
35#ifdef GFIO_DEBUG
36#define GDBG_PRINT(a) printf a
37#else
38#define GDBG_PRINT(a) (void) 0
39#endif
40
41#define STFU_GCC(a) a = a
42
43
44struct guasi_data {
45 guasi_t hctx;
46 int max_reqs;
47 guasi_req_t *reqs;
48 struct io_u **io_us;
46eaa157 49 int queued_nr;
609342ff
DL
50 int reqs_nr;
51};
52
53static int fio_guasi_prep(struct thread_data fio_unused *td, struct io_u *io_u)
54{
609342ff
DL
55
56 GDBG_PRINT(("fio_guasi_prep(%p)\n", io_u));
46eaa157 57 io_u->greq = NULL;
609342ff
DL
58
59 return 0;
60}
61
62static struct io_u *fio_guasi_event(struct thread_data *td, int event)
63{
64 struct guasi_data *ld = td->io_ops->data;
65 struct io_u *io_u;
66 struct guasi_reqinfo rinf;
67
68 GDBG_PRINT(("fio_guasi_event(%d)\n", event));
69 if (guasi_req_info(ld->reqs[event], &rinf) < 0) {
07257263 70 log_err("guasi_req_info(%d) FAILED!\n", event);
609342ff
DL
71 return NULL;
72 }
73 io_u = rinf.asid;
66b83d9a 74 io_u->error = EINPROGRESS;
609342ff 75 GDBG_PRINT(("fio_guasi_event(%d) -> %p\n", event, io_u));
66b83d9a 76 if (rinf.status == GUASI_STATUS_COMPLETE) {
609342ff 77 io_u->error = rinf.result;
66b83d9a
DL
78 if (io_u->ddir == DDIR_READ ||
79 io_u->ddir == DDIR_WRITE) {
80 io_u->error = 0;
81 if (rinf.result != (long) io_u->xfer_buflen) {
82 if (rinf.result >= 0)
83 io_u->resid = io_u->xfer_buflen - rinf.result;
84 else
85 io_u->error = rinf.error;
86 }
87 }
88 }
609342ff
DL
89
90 return io_u;
91}
92
93static int fio_guasi_getevents(struct thread_data *td, int min, int max,
94 struct timespec *t)
95{
96 struct guasi_data *ld = td->io_ops->data;
46eaa157 97 int n, r;
609342ff
DL
98 long timeo = -1;
99
100 GDBG_PRINT(("fio_guasi_getevents(%d, %d)\n", min, max));
101 if (min > ld->max_reqs)
102 min = ld->max_reqs;
103 if (max > ld->max_reqs)
104 max = ld->max_reqs;
105 if (t)
106 timeo = t->tv_sec * 1000L + t->tv_nsec / 1000000L;
46eaa157
DL
107 for (n = 0; n < ld->reqs_nr; n++)
108 guasi_req_free(ld->reqs[n]);
109 n = 0;
609342ff 110 do {
97c26cbe
DL
111 r = guasi_fetch(ld->hctx, ld->reqs + n, min - n,
112 max - n, timeo);
113 if (r < 0) {
07257263 114 log_err("guasi_fetch() FAILED! (%d)\n", r);
609342ff 115 break;
97c26cbe 116 }
609342ff
DL
117 n += r;
118 if (n >= min)
119 break;
120 } while (1);
46eaa157 121 ld->reqs_nr = n;
609342ff
DL
122 GDBG_PRINT(("fio_guasi_getevents() -> %d\n", n));
123
124 return n;
125}
126
127static int fio_guasi_queue(struct thread_data *td, struct io_u *io_u)
128{
129 struct guasi_data *ld = td->io_ops->data;
130
131 GDBG_PRINT(("fio_guasi_queue(%p)\n", io_u));
46eaa157 132 if (ld->queued_nr == (int) td->o.iodepth)
609342ff
DL
133 return FIO_Q_BUSY;
134
46eaa157
DL
135 ld->io_us[ld->queued_nr] = io_u;
136 ld->queued_nr++;
609342ff
DL
137 return FIO_Q_QUEUED;
138}
139
97c26cbe 140static void fio_guasi_queued(struct thread_data *td, struct io_u **io_us, int nr)
609342ff 141{
97c26cbe
DL
142 int i;
143 struct io_u *io_u;
609342ff 144 struct timeval now;
609342ff
DL
145
146 fio_gettime(&now, NULL);
97c26cbe
DL
147 for (i = 0; i < nr; i++) {
148 io_u = io_us[i];
149 memcpy(&io_u->issue_time, &now, sizeof(now));
150 io_u_queued(td, io_u);
151 }
609342ff
DL
152}
153
154static int fio_guasi_commit(struct thread_data *td)
155{
156 struct guasi_data *ld = td->io_ops->data;
157 int i;
158 struct io_u *io_u;
159 struct fio_file *f;
160
d6c6810f 161 GDBG_PRINT(("fio_guasi_commit(%d)\n", ld->queued_nr));
46eaa157 162 for (i = 0; i < ld->queued_nr; i++) {
609342ff 163 io_u = ld->io_us[i];
d6c6810f 164 GDBG_PRINT(("fio_guasi_commit(%d) --> %p\n", i, io_u));
609342ff
DL
165 f = io_u->file;
166 io_u->greq = NULL;
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,
170 io_u->offset);
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,
174 io_u->offset);
175 else if (io_u->ddir == DDIR_SYNC)
176 io_u->greq = guasi__fsync(ld->hctx, ld, io_u, 0, f->fd);
177 else {
07257263 178 log_err("fio_guasi_commit() FAILED: unknow request %d\n",
66b83d9a 179 io_u->ddir);
609342ff 180 }
97c26cbe 181 if (io_u->greq == NULL) {
07257263 182 log_err("fio_guasi_commit() FAILED: submit failed (%s)\n",
d6c6810f 183 strerror(errno));
46eaa157
DL
184 return -1;
185 }
609342ff 186 }
97c26cbe 187 fio_guasi_queued(td, ld->io_us, i);
46eaa157 188 ld->queued_nr = 0;
609342ff
DL
189 GDBG_PRINT(("fio_guasi_commit() -> %d\n", i));
190
191 return 0;
192}
193
194static int fio_guasi_cancel(struct thread_data *td, struct io_u *io_u)
195{
196 struct guasi_data *ld = td->io_ops->data;
197
198 STFU_GCC(ld);
46eaa157
DL
199 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);
609342ff 202
46eaa157 203 return 0;
609342ff
DL
204}
205
206static void fio_guasi_cleanup(struct thread_data *td)
207{
208 struct guasi_data *ld = td->io_ops->data;
8999fe9a 209 int n;
609342ff 210
46eaa157 211 GDBG_PRINT(("fio_guasi_cleanup(%p)\n", ld));
609342ff 212 if (ld) {
8999fe9a
DL
213 for (n = 0; n < ld->reqs_nr; n++)
214 guasi_req_free(ld->reqs[n]);
609342ff
DL
215 guasi_free(ld->hctx);
216 free(ld->reqs);
217 free(ld->io_us);
218 free(ld);
219 td->io_ops->data = NULL;
220 }
46eaa157 221 GDBG_PRINT(("fio_guasi_cleanup(%p) DONE\n", ld));
609342ff
DL
222}
223
224static int fio_guasi_init(struct thread_data *td)
225{
226 int maxthr;
227 struct guasi_data *ld = malloc(sizeof(*ld));
228
46eaa157 229 GDBG_PRINT(("fio_guasi_init(): depth=%d\n", td->o.iodepth));
609342ff 230 memset(ld, 0, sizeof(*ld));
46eaa157 231 maxthr = td->o.iodepth > GFIO_MIN_THREADS ? td->o.iodepth: GFIO_MIN_THREADS;
d6c6810f
DL
232 if (maxthr > GFIO_MAX_THREADS)
233 maxthr = GFIO_MAX_THREADS;
97c26cbe 234 if ((ld->hctx = guasi_create(GFIO_MIN_THREADS, maxthr, 1, 0)) == NULL) {
609342ff
DL
235 td_verror(td, errno, "guasi_create");
236 free(ld);
237 return 1;
238 }
46eaa157 239 ld->max_reqs = td->o.iodepth;
609342ff
DL
240 ld->reqs = malloc(ld->max_reqs * sizeof(guasi_req_t));
241 ld->io_us = malloc(ld->max_reqs * sizeof(struct io_u *));
242 memset(ld->io_us, 0, ld->max_reqs * sizeof(struct io_u *));
46eaa157 243 ld->queued_nr = 0;
609342ff
DL
244 ld->reqs_nr = 0;
245
246 td->io_ops->data = ld;
46eaa157 247 GDBG_PRINT(("fio_guasi_init(): depth=%d -> %p\n", td->o.iodepth, ld));
609342ff
DL
248
249 return 0;
250}
251
252static struct ioengine_ops ioengine = {
253 .name = "guasi",
254 .version = FIO_IOOPS_VERSION,
255 .init = fio_guasi_init,
256 .prep = fio_guasi_prep,
257 .queue = fio_guasi_queue,
258 .commit = fio_guasi_commit,
259 .cancel = fio_guasi_cancel,
260 .getevents = fio_guasi_getevents,
261 .event = fio_guasi_event,
262 .cleanup = fio_guasi_cleanup,
263 .open_file = generic_open_file,
264 .close_file = generic_close_file,
265};
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{
276 fprintf(stderr, "fio: guasi not available\n");
277 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