Add the 'zbd' debug level
[fio.git] / engines / guasi.c
CommitLineData
609342ff
DL
1/*
2 * guasi engine
3 *
4 * IO engine using the GUASI library.
5 *
0ac5d398 6 * Before running make. You'll need the GUASI lib as well:
609342ff
DL
7 *
8 * http://www.xmailserver.org/guasi-lib.html
9 *
10 */
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14#include <errno.h>
15#include <assert.h>
16
17#include "../fio.h"
609342ff 18
609342ff 19#define GFIO_MIN_THREADS 32
d6c6810f 20#ifndef GFIO_MAX_THREADS
97c26cbe 21#define GFIO_MAX_THREADS 2000
d6c6810f 22#endif
609342ff
DL
23
24#include <guasi.h>
25#include <guasi_syscalls.h>
26
27#ifdef GFIO_DEBUG
28#define GDBG_PRINT(a) printf a
29#else
30#define GDBG_PRINT(a) (void) 0
31#endif
32
609342ff
DL
33struct guasi_data {
34 guasi_t hctx;
35 int max_reqs;
36 guasi_req_t *reqs;
37 struct io_u **io_us;
46eaa157 38 int queued_nr;
609342ff
DL
39 int reqs_nr;
40};
41
42static int fio_guasi_prep(struct thread_data fio_unused *td, struct io_u *io_u)
43{
609342ff
DL
44
45 GDBG_PRINT(("fio_guasi_prep(%p)\n", io_u));
46eaa157 46 io_u->greq = NULL;
609342ff
DL
47
48 return 0;
49}
50
51static struct io_u *fio_guasi_event(struct thread_data *td, int event)
52{
565e784d 53 struct guasi_data *ld = td->io_ops_data;
609342ff
DL
54 struct io_u *io_u;
55 struct guasi_reqinfo rinf;
56
57 GDBG_PRINT(("fio_guasi_event(%d)\n", event));
58 if (guasi_req_info(ld->reqs[event], &rinf) < 0) {
07257263 59 log_err("guasi_req_info(%d) FAILED!\n", event);
609342ff
DL
60 return NULL;
61 }
62 io_u = rinf.asid;
66b83d9a 63 io_u->error = EINPROGRESS;
609342ff 64 GDBG_PRINT(("fio_guasi_event(%d) -> %p\n", event, io_u));
66b83d9a 65 if (rinf.status == GUASI_STATUS_COMPLETE) {
609342ff 66 io_u->error = rinf.result;
66b83d9a
DL
67 if (io_u->ddir == DDIR_READ ||
68 io_u->ddir == DDIR_WRITE) {
69 io_u->error = 0;
70 if (rinf.result != (long) io_u->xfer_buflen) {
71 if (rinf.result >= 0)
72 io_u->resid = io_u->xfer_buflen - rinf.result;
73 else
74 io_u->error = rinf.error;
75 }
76 }
77 }
609342ff
DL
78
79 return io_u;
80}
81
e7d2e616 82static int fio_guasi_getevents(struct thread_data *td, unsigned int min,
1f440ece 83 unsigned int max, const struct timespec *t)
609342ff 84{
565e784d 85 struct guasi_data *ld = td->io_ops_data;
46eaa157 86 int n, r;
609342ff
DL
87 long timeo = -1;
88
89 GDBG_PRINT(("fio_guasi_getevents(%d, %d)\n", min, max));
90 if (min > ld->max_reqs)
91 min = ld->max_reqs;
92 if (max > ld->max_reqs)
93 max = ld->max_reqs;
94 if (t)
95 timeo = t->tv_sec * 1000L + t->tv_nsec / 1000000L;
46eaa157
DL
96 for (n = 0; n < ld->reqs_nr; n++)
97 guasi_req_free(ld->reqs[n]);
98 n = 0;
609342ff 99 do {
97c26cbe
DL
100 r = guasi_fetch(ld->hctx, ld->reqs + n, min - n,
101 max - n, timeo);
102 if (r < 0) {
07257263 103 log_err("guasi_fetch() FAILED! (%d)\n", r);
609342ff 104 break;
97c26cbe 105 }
609342ff
DL
106 n += r;
107 if (n >= min)
108 break;
109 } while (1);
46eaa157 110 ld->reqs_nr = n;
609342ff
DL
111 GDBG_PRINT(("fio_guasi_getevents() -> %d\n", n));
112
113 return n;
114}
115
2e4ef4fb
JA
116static enum fio_q_status fio_guasi_queue(struct thread_data *td,
117 struct io_u *io_u)
609342ff 118{
565e784d 119 struct guasi_data *ld = td->io_ops_data;
609342ff 120
7101d9c2
JA
121 fio_ro_check(td, io_u);
122
609342ff 123 GDBG_PRINT(("fio_guasi_queue(%p)\n", io_u));
46eaa157 124 if (ld->queued_nr == (int) td->o.iodepth)
609342ff
DL
125 return FIO_Q_BUSY;
126
46eaa157
DL
127 ld->io_us[ld->queued_nr] = io_u;
128 ld->queued_nr++;
609342ff
DL
129 return FIO_Q_QUEUED;
130}
131
97c26cbe 132static void fio_guasi_queued(struct thread_data *td, struct io_u **io_us, int nr)
609342ff 133{
97c26cbe
DL
134 int i;
135 struct io_u *io_u;
8b6a404c 136 struct timespec now;
609342ff 137
12d9d841
JA
138 if (!fio_fill_issue_time(td))
139 return;
140
838bc709 141 io_u_mark_submit(td, nr);
609342ff 142 fio_gettime(&now, NULL);
97c26cbe
DL
143 for (i = 0; i < nr; i++) {
144 io_u = io_us[i];
145 memcpy(&io_u->issue_time, &now, sizeof(now));
146 io_u_queued(td, io_u);
147 }
609342ff
DL
148}
149
150static int fio_guasi_commit(struct thread_data *td)
151{
565e784d 152 struct guasi_data *ld = td->io_ops_data;
609342ff
DL
153 int i;
154 struct io_u *io_u;
155 struct fio_file *f;
156
d6c6810f 157 GDBG_PRINT(("fio_guasi_commit(%d)\n", ld->queued_nr));
46eaa157 158 for (i = 0; i < ld->queued_nr; i++) {
609342ff 159 io_u = ld->io_us[i];
d6c6810f 160 GDBG_PRINT(("fio_guasi_commit(%d) --> %p\n", i, io_u));
609342ff
DL
161 f = io_u->file;
162 io_u->greq = NULL;
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,
166 io_u->offset);
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,
170 io_u->offset);
5f9099ea 171 else if (ddir_sync(io_u->ddir))
609342ff
DL
172 io_u->greq = guasi__fsync(ld->hctx, ld, io_u, 0, f->fd);
173 else {
07257263 174 log_err("fio_guasi_commit() FAILED: unknow request %d\n",
66b83d9a 175 io_u->ddir);
609342ff 176 }
97c26cbe 177 if (io_u->greq == NULL) {
07257263 178 log_err("fio_guasi_commit() FAILED: submit failed (%s)\n",
d6c6810f 179 strerror(errno));
46eaa157
DL
180 return -1;
181 }
609342ff 182 }
97c26cbe 183 fio_guasi_queued(td, ld->io_us, i);
46eaa157 184 ld->queued_nr = 0;
609342ff
DL
185 GDBG_PRINT(("fio_guasi_commit() -> %d\n", i));
186
187 return 0;
188}
189
ffa59cea
JA
190static int fio_guasi_cancel(struct thread_data fio_unused *td,
191 struct io_u *io_u)
609342ff 192{
46eaa157
DL
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);
609342ff 196
46eaa157 197 return 0;
609342ff
DL
198}
199
200static void fio_guasi_cleanup(struct thread_data *td)
201{
565e784d 202 struct guasi_data *ld = td->io_ops_data;
8999fe9a 203 int n;
609342ff 204
46eaa157 205 GDBG_PRINT(("fio_guasi_cleanup(%p)\n", ld));
609342ff 206 if (ld) {
8999fe9a
DL
207 for (n = 0; n < ld->reqs_nr; n++)
208 guasi_req_free(ld->reqs[n]);
609342ff
DL
209 guasi_free(ld->hctx);
210 free(ld->reqs);
211 free(ld->io_us);
212 free(ld);
609342ff 213 }
46eaa157 214 GDBG_PRINT(("fio_guasi_cleanup(%p) DONE\n", ld));
609342ff
DL
215}
216
217static int fio_guasi_init(struct thread_data *td)
218{
219 int maxthr;
220 struct guasi_data *ld = malloc(sizeof(*ld));
221
46eaa157 222 GDBG_PRINT(("fio_guasi_init(): depth=%d\n", td->o.iodepth));
609342ff 223 memset(ld, 0, sizeof(*ld));
46eaa157 224 maxthr = td->o.iodepth > GFIO_MIN_THREADS ? td->o.iodepth: GFIO_MIN_THREADS;
d6c6810f
DL
225 if (maxthr > GFIO_MAX_THREADS)
226 maxthr = GFIO_MAX_THREADS;
0798ba36 227 if ((ld->hctx = guasi_create(GFIO_MIN_THREADS, maxthr, 1)) == NULL) {
609342ff
DL
228 td_verror(td, errno, "guasi_create");
229 free(ld);
230 return 1;
231 }
46eaa157 232 ld->max_reqs = td->o.iodepth;
609342ff
DL
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 *));
46eaa157 236 ld->queued_nr = 0;
609342ff
DL
237 ld->reqs_nr = 0;
238
565e784d 239 td->io_ops_data = ld;
46eaa157 240 GDBG_PRINT(("fio_guasi_init(): depth=%d -> %p\n", td->o.iodepth, ld));
609342ff
DL
241
242 return 0;
243}
244
245static struct ioengine_ops ioengine = {
246 .name = "guasi",
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,
df9c26b1 258 .get_file_size = generic_get_file_size,
609342ff
DL
259};
260
609342ff
DL
261static void fio_init fio_guasi_register(void)
262{
263 register_ioengine(&ioengine);
264}
265
266static void fio_exit fio_guasi_unregister(void)
267{
268 unregister_ioengine(&ioengine);
269}
270