Commit | Line | Data |
---|---|---|
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" | |
609342ff DL |
23 | |
24 | #ifdef FIO_HAVE_GUASI | |
25 | ||
26 | #define GFIO_MIN_THREADS 32 | |
d6c6810f | 27 | #ifndef GFIO_MAX_THREADS |
97c26cbe | 28 | #define GFIO_MAX_THREADS 2000 |
d6c6810f | 29 | #endif |
609342ff DL |
30 | |
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 | ||
609342ff DL |
40 | struct guasi_data { |
41 | guasi_t hctx; | |
42 | int max_reqs; | |
43 | guasi_req_t *reqs; | |
44 | struct io_u **io_us; | |
46eaa157 | 45 | int queued_nr; |
609342ff DL |
46 | int reqs_nr; |
47 | }; | |
48 | ||
49 | static int fio_guasi_prep(struct thread_data fio_unused *td, struct io_u *io_u) | |
50 | { | |
609342ff DL |
51 | |
52 | GDBG_PRINT(("fio_guasi_prep(%p)\n", io_u)); | |
46eaa157 | 53 | io_u->greq = NULL; |
609342ff DL |
54 | |
55 | return 0; | |
56 | } | |
57 | ||
58 | static 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) { | |
07257263 | 66 | log_err("guasi_req_info(%d) FAILED!\n", event); |
609342ff DL |
67 | return NULL; |
68 | } | |
69 | io_u = rinf.asid; | |
66b83d9a | 70 | io_u->error = EINPROGRESS; |
609342ff | 71 | GDBG_PRINT(("fio_guasi_event(%d) -> %p\n", event, io_u)); |
66b83d9a | 72 | if (rinf.status == GUASI_STATUS_COMPLETE) { |
609342ff | 73 | io_u->error = rinf.result; |
66b83d9a DL |
74 | 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 | } | |
609342ff DL |
85 | |
86 | return io_u; | |
87 | } | |
88 | ||
89 | static int fio_guasi_getevents(struct thread_data *td, int min, int max, | |
90 | struct timespec *t) | |
91 | { | |
92 | struct guasi_data *ld = td->io_ops->data; | |
46eaa157 | 93 | int n, r; |
609342ff DL |
94 | 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; | |
46eaa157 DL |
103 | for (n = 0; n < ld->reqs_nr; n++) |
104 | guasi_req_free(ld->reqs[n]); | |
105 | n = 0; | |
609342ff | 106 | do { |
97c26cbe DL |
107 | r = guasi_fetch(ld->hctx, ld->reqs + n, min - n, |
108 | max - n, timeo); | |
109 | if (r < 0) { | |
07257263 | 110 | log_err("guasi_fetch() FAILED! (%d)\n", r); |
609342ff | 111 | break; |
97c26cbe | 112 | } |
609342ff DL |
113 | n += r; |
114 | if (n >= min) | |
115 | break; | |
116 | } while (1); | |
46eaa157 | 117 | ld->reqs_nr = n; |
609342ff DL |
118 | GDBG_PRINT(("fio_guasi_getevents() -> %d\n", n)); |
119 | ||
120 | return n; | |
121 | } | |
122 | ||
123 | static int fio_guasi_queue(struct thread_data *td, struct io_u *io_u) | |
124 | { | |
125 | struct guasi_data *ld = td->io_ops->data; | |
126 | ||
7101d9c2 JA |
127 | fio_ro_check(td, io_u); |
128 | ||
609342ff | 129 | GDBG_PRINT(("fio_guasi_queue(%p)\n", io_u)); |
46eaa157 | 130 | if (ld->queued_nr == (int) td->o.iodepth) |
609342ff DL |
131 | return FIO_Q_BUSY; |
132 | ||
46eaa157 DL |
133 | ld->io_us[ld->queued_nr] = io_u; |
134 | ld->queued_nr++; | |
609342ff DL |
135 | return FIO_Q_QUEUED; |
136 | } | |
137 | ||
97c26cbe | 138 | static void fio_guasi_queued(struct thread_data *td, struct io_u **io_us, int nr) |
609342ff | 139 | { |
97c26cbe DL |
140 | int i; |
141 | struct io_u *io_u; | |
609342ff | 142 | struct timeval now; |
609342ff DL |
143 | |
144 | fio_gettime(&now, NULL); | |
97c26cbe DL |
145 | for (i = 0; i < nr; i++) { |
146 | io_u = io_us[i]; | |
147 | memcpy(&io_u->issue_time, &now, sizeof(now)); | |
148 | io_u_queued(td, io_u); | |
149 | } | |
609342ff DL |
150 | } |
151 | ||
152 | static int fio_guasi_commit(struct thread_data *td) | |
153 | { | |
154 | struct guasi_data *ld = td->io_ops->data; | |
155 | int i; | |
156 | struct io_u *io_u; | |
157 | struct fio_file *f; | |
158 | ||
d6c6810f | 159 | GDBG_PRINT(("fio_guasi_commit(%d)\n", ld->queued_nr)); |
46eaa157 | 160 | for (i = 0; i < ld->queued_nr; i++) { |
609342ff | 161 | io_u = ld->io_us[i]; |
d6c6810f | 162 | GDBG_PRINT(("fio_guasi_commit(%d) --> %p\n", i, io_u)); |
609342ff DL |
163 | f = io_u->file; |
164 | io_u->greq = NULL; | |
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, | |
168 | io_u->offset); | |
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, | |
172 | io_u->offset); | |
173 | else if (io_u->ddir == DDIR_SYNC) | |
174 | io_u->greq = guasi__fsync(ld->hctx, ld, io_u, 0, f->fd); | |
175 | else { | |
07257263 | 176 | log_err("fio_guasi_commit() FAILED: unknow request %d\n", |
66b83d9a | 177 | io_u->ddir); |
609342ff | 178 | } |
97c26cbe | 179 | if (io_u->greq == NULL) { |
07257263 | 180 | log_err("fio_guasi_commit() FAILED: submit failed (%s)\n", |
d6c6810f | 181 | strerror(errno)); |
46eaa157 DL |
182 | return -1; |
183 | } | |
609342ff | 184 | } |
97c26cbe | 185 | fio_guasi_queued(td, ld->io_us, i); |
46eaa157 | 186 | ld->queued_nr = 0; |
609342ff DL |
187 | GDBG_PRINT(("fio_guasi_commit() -> %d\n", i)); |
188 | ||
189 | return 0; | |
190 | } | |
191 | ||
ffa59cea JA |
192 | static int fio_guasi_cancel(struct thread_data fio_unused *td, |
193 | struct io_u *io_u) | |
609342ff | 194 | { |
46eaa157 DL |
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); | |
609342ff | 198 | |
46eaa157 | 199 | return 0; |
609342ff DL |
200 | } |
201 | ||
202 | static void fio_guasi_cleanup(struct thread_data *td) | |
203 | { | |
204 | struct guasi_data *ld = td->io_ops->data; | |
8999fe9a | 205 | int n; |
609342ff | 206 | |
46eaa157 | 207 | GDBG_PRINT(("fio_guasi_cleanup(%p)\n", ld)); |
609342ff | 208 | if (ld) { |
8999fe9a DL |
209 | for (n = 0; n < ld->reqs_nr; n++) |
210 | guasi_req_free(ld->reqs[n]); | |
609342ff DL |
211 | guasi_free(ld->hctx); |
212 | free(ld->reqs); | |
213 | free(ld->io_us); | |
214 | free(ld); | |
215 | td->io_ops->data = NULL; | |
216 | } | |
46eaa157 | 217 | GDBG_PRINT(("fio_guasi_cleanup(%p) DONE\n", ld)); |
609342ff DL |
218 | } |
219 | ||
220 | static int fio_guasi_init(struct thread_data *td) | |
221 | { | |
222 | int maxthr; | |
223 | struct guasi_data *ld = malloc(sizeof(*ld)); | |
224 | ||
46eaa157 | 225 | GDBG_PRINT(("fio_guasi_init(): depth=%d\n", td->o.iodepth)); |
609342ff | 226 | memset(ld, 0, sizeof(*ld)); |
46eaa157 | 227 | maxthr = td->o.iodepth > GFIO_MIN_THREADS ? td->o.iodepth: GFIO_MIN_THREADS; |
d6c6810f DL |
228 | if (maxthr > GFIO_MAX_THREADS) |
229 | maxthr = GFIO_MAX_THREADS; | |
0798ba36 | 230 | if ((ld->hctx = guasi_create(GFIO_MIN_THREADS, maxthr, 1)) == NULL) { |
609342ff DL |
231 | td_verror(td, errno, "guasi_create"); |
232 | free(ld); | |
233 | return 1; | |
234 | } | |
46eaa157 | 235 | ld->max_reqs = td->o.iodepth; |
609342ff DL |
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 *)); | |
46eaa157 | 239 | ld->queued_nr = 0; |
609342ff DL |
240 | ld->reqs_nr = 0; |
241 | ||
242 | td->io_ops->data = ld; | |
46eaa157 | 243 | GDBG_PRINT(("fio_guasi_init(): depth=%d -> %p\n", td->o.iodepth, ld)); |
609342ff DL |
244 | |
245 | return 0; | |
246 | } | |
247 | ||
248 | static struct ioengine_ops ioengine = { | |
249 | .name = "guasi", | |
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, | |
261 | }; | |
262 | ||
263 | #else /* FIO_HAVE_GUASI */ | |
264 | ||
265 | /* | |
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. | |
269 | */ | |
270 | static int fio_guasi_init(struct thread_data fio_unused *td) | |
271 | { | |
272 | fprintf(stderr, "fio: guasi not available\n"); | |
273 | return 1; | |
274 | } | |
275 | ||
276 | static struct ioengine_ops ioengine = { | |
277 | .name = "guasi", | |
278 | .version = FIO_IOOPS_VERSION, | |
279 | .init = fio_guasi_init, | |
280 | }; | |
281 | ||
282 | #endif | |
283 | ||
284 | static void fio_init fio_guasi_register(void) | |
285 | { | |
286 | register_ioengine(&ioengine); | |
287 | } | |
288 | ||
289 | static void fio_exit fio_guasi_unregister(void) | |
290 | { | |
291 | unregister_ioengine(&ioengine); | |
292 | } | |
293 |