4 * IO engine that does regular pread(2)/pwrite(2) to transfer data, but
5 * with syslets to make the execution async.
17 #ifdef FIO_HAVE_SYSLET
21 unsigned int nr_events;
23 struct async_head_user ahu;
24 struct syslet_uatom **ring;
26 struct syslet_uatom *head, *tail;
29 static void fio_syslet_complete_atom(struct thread_data *td,
30 struct syslet_uatom *atom)
32 struct syslet_data *sd = td->io_ops->data;
33 struct syslet_uatom *last;
37 * complete from the beginning of the sequence up to (and
38 * including) this atom
42 atom = io_u->req.head;
45 * now complete in right order
53 io_u->resid = io_u->xfer_buflen - ret;
57 assert(sd->nr_events < td->iodepth);
58 sd->events[sd->nr_events++] = io_u;
70 * Inspect the ring to see if we have completed events
72 static void fio_syslet_complete(struct thread_data *td)
74 struct syslet_data *sd = td->io_ops->data;
77 struct syslet_uatom *atom;
79 atom = sd->ring[sd->ahu.user_ring_idx];
83 sd->ring[sd->ahu.user_ring_idx] = NULL;
84 if (++sd->ahu.user_ring_idx == td->iodepth)
85 sd->ahu.user_ring_idx = 0;
87 fio_syslet_complete_atom(td, atom);
91 static int fio_syslet_getevents(struct thread_data *td, int min,
93 struct timespec fio_unused *t)
95 struct syslet_data *sd = td->io_ops->data;
99 fio_syslet_complete(td);
102 * do we have enough immediate completions?
104 if (sd->nr_events >= (unsigned int) min)
108 * OK, we need to wait for some events...
110 ret = async_wait(1, sd->ahu.user_ring_idx, &sd->ahu);
120 static struct io_u *fio_syslet_event(struct thread_data *td, int event)
122 struct syslet_data *sd = td->io_ops->data;
124 return sd->events[event];
127 static void init_atom(struct syslet_uatom *atom, int nr, void *arg0,
128 void *arg1, void *arg2, void *arg3, void *ret_ptr,
129 unsigned long flags, void *priv)
133 atom->ret_ptr = ret_ptr;
135 atom->arg_ptr[0] = arg0;
136 atom->arg_ptr[1] = arg1;
137 atom->arg_ptr[2] = arg2;
138 atom->arg_ptr[3] = arg3;
139 atom->arg_ptr[4] = atom->arg_ptr[5] = NULL;
140 atom->private = priv;
144 * Use seek atom for sync
146 static void fio_syslet_prep_sync(struct io_u *io_u, struct fio_file *f)
148 init_atom(&io_u->req.atom, __NR_fsync, &f->fd, NULL, NULL, NULL,
149 &io_u->req.ret, 0, io_u);
152 static void fio_syslet_prep_rw(struct io_u *io_u, struct fio_file *f)
159 if (io_u->ddir == DDIR_READ)
164 init_atom(&io_u->req.atom, nr, &f->fd, &io_u->xfer_buf,
165 &io_u->xfer_buflen, &io_u->offset, &io_u->req.ret, 0, io_u);
168 static int fio_syslet_prep(struct thread_data fio_unused *td, struct io_u *io_u)
170 struct fio_file *f = io_u->file;
172 if (io_u->ddir == DDIR_SYNC)
173 fio_syslet_prep_sync(io_u, f);
175 fio_syslet_prep_rw(io_u, f);
180 static void cachemiss_thread_start(void)
183 async_thread(NULL, NULL);
186 #define THREAD_STACK_SIZE (16384)
188 static unsigned long thread_stack_alloc()
190 return (unsigned long) malloc(THREAD_STACK_SIZE) + THREAD_STACK_SIZE;
193 static void fio_syslet_queued(struct thread_data *td, struct syslet_data *sd)
195 struct syslet_uatom *atom;
198 fio_gettime(&now, NULL);
202 struct io_u *io_u = atom->private;
204 memcpy(&io_u->issue_time, &now, sizeof(now));
205 io_u_queued(td, io_u);
210 static int fio_syslet_commit(struct thread_data *td)
212 struct syslet_data *sd = td->io_ops->data;
213 struct syslet_uatom *done;
218 assert(!sd->tail->next);
220 if (!sd->ahu.new_thread_stack)
221 sd->ahu.new_thread_stack = thread_stack_alloc();
223 fio_syslet_queued(td, sd);
226 * On sync completion, the atom is returned. So on NULL return
227 * it's queued asynchronously.
229 done = async_exec(sd->head, &sd->ahu);
231 sd->head = sd->tail = NULL;
234 fio_syslet_complete_atom(td, done);
239 static int fio_syslet_queue(struct thread_data *td, struct io_u *io_u)
241 struct syslet_data *sd = td->io_ops->data;
244 sd->tail->next = &io_u->req.atom;
245 sd->tail = &io_u->req.atom;
247 sd->head = sd->tail = &io_u->req.atom;
249 io_u->req.head = sd->head;
253 static int async_head_init(struct syslet_data *sd, unsigned int depth)
255 unsigned long ring_size;
257 memset(&sd->ahu, 0, sizeof(struct async_head_user));
259 ring_size = sizeof(struct syslet_uatom *) * depth;
260 sd->ring = malloc(ring_size);
261 memset(sd->ring, 0, ring_size);
263 sd->ahu.user_ring_idx = 0;
264 sd->ahu.completion_ring = sd->ring;
265 sd->ahu.ring_size_bytes = ring_size;
266 sd->ahu.head_stack = thread_stack_alloc();
267 sd->ahu.head_eip = (unsigned long) cachemiss_thread_start;
268 sd->ahu.new_thread_eip = (unsigned long) cachemiss_thread_start;
273 static void async_head_exit(struct syslet_data *sd)
278 static void fio_syslet_cleanup(struct thread_data *td)
280 struct syslet_data *sd = td->io_ops->data;
286 td->io_ops->data = NULL;
290 static int fio_syslet_init(struct thread_data *td)
292 struct syslet_data *sd;
295 sd = malloc(sizeof(*sd));
296 memset(sd, 0, sizeof(*sd));
297 sd->events = malloc(sizeof(struct io_u *) * td->iodepth);
298 memset(sd->events, 0, sizeof(struct io_u *) * td->iodepth);
301 * This will handily fail for kernels where syslet isn't available
303 if (async_head_init(sd, td->iodepth)) {
309 td->io_ops->data = sd;
313 static struct ioengine_ops ioengine = {
315 .version = FIO_IOOPS_VERSION,
316 .init = fio_syslet_init,
317 .prep = fio_syslet_prep,
318 .queue = fio_syslet_queue,
319 .commit = fio_syslet_commit,
320 .getevents = fio_syslet_getevents,
321 .event = fio_syslet_event,
322 .cleanup = fio_syslet_cleanup,
323 .open_file = generic_open_file,
324 .close_file = generic_close_file,
327 #else /* FIO_HAVE_SYSLET */
330 * When we have a proper configure system in place, we simply wont build
331 * and install this io engine. For now install a crippled version that
332 * just complains and fails to load.
334 static int fio_syslet_init(struct thread_data fio_unused *td)
336 fprintf(stderr, "fio: syslet not available\n");
340 static struct ioengine_ops ioengine = {
342 .version = FIO_IOOPS_VERSION,
343 .init = fio_syslet_init,
346 #endif /* FIO_HAVE_SYSLET */
348 static void fio_init fio_syslet_register(void)
350 register_ioengine(&ioengine);
353 static void fio_exit fio_syslet_unregister(void)
355 unregister_ioengine(&ioengine);