2 * read/write() engine that uses syslet to be async
14 #ifdef FIO_HAVE_SYSLET
18 unsigned int nr_events;
20 struct async_head_user ahu;
21 struct syslet_uatom **ring;
23 struct syslet_uatom *head, *tail;
26 static void fio_syslet_complete_atom(struct thread_data *td,
27 struct syslet_uatom *atom)
29 struct syslet_data *sd = td->io_ops->data;
30 struct syslet_uatom *last;
34 * complete from the beginning of the sequence up to (and
35 * including) this atom
39 atom = io_u->req.head;
42 * now complete in right order
50 io_u->resid = io_u->xfer_buflen - ret;
54 assert(sd->nr_events < td->iodepth);
55 sd->events[sd->nr_events++] = io_u;
67 * Inspect the ring to see if we have completed events
69 static void fio_syslet_complete(struct thread_data *td)
71 struct syslet_data *sd = td->io_ops->data;
74 struct syslet_uatom *atom;
76 atom = sd->ring[sd->ahu.user_ring_idx];
80 sd->ring[sd->ahu.user_ring_idx] = NULL;
81 if (++sd->ahu.user_ring_idx == td->iodepth)
82 sd->ahu.user_ring_idx = 0;
84 fio_syslet_complete_atom(td, atom);
88 static int fio_syslet_getevents(struct thread_data *td, int min,
90 struct timespec fio_unused *t)
92 struct syslet_data *sd = td->io_ops->data;
96 fio_syslet_complete(td);
99 * do we have enough immediate completions?
101 if (sd->nr_events >= (unsigned int) min)
105 * OK, we need to wait for some events...
107 ret = async_wait(1, sd->ahu.user_ring_idx, &sd->ahu);
117 static struct io_u *fio_syslet_event(struct thread_data *td, int event)
119 struct syslet_data *sd = td->io_ops->data;
121 return sd->events[event];
124 static void init_atom(struct syslet_uatom *atom, int nr, void *arg0,
125 void *arg1, void *arg2, void *arg3, void *ret_ptr,
126 unsigned long flags, void *priv)
130 atom->ret_ptr = ret_ptr;
132 atom->arg_ptr[0] = arg0;
133 atom->arg_ptr[1] = arg1;
134 atom->arg_ptr[2] = arg2;
135 atom->arg_ptr[3] = arg3;
136 atom->arg_ptr[4] = atom->arg_ptr[5] = NULL;
137 atom->private = priv;
141 * Use seek atom for sync
143 static void fio_syslet_prep_sync(struct io_u *io_u, struct fio_file *f)
145 init_atom(&io_u->req.atom, __NR_fsync, &f->fd, NULL, NULL, NULL,
146 &io_u->req.ret, 0, io_u);
149 static void fio_syslet_prep_rw(struct io_u *io_u, struct fio_file *f)
156 if (io_u->ddir == DDIR_READ)
161 init_atom(&io_u->req.atom, nr, &f->fd, &io_u->xfer_buf,
162 &io_u->xfer_buflen, &io_u->offset, &io_u->req.ret, 0, io_u);
165 static int fio_syslet_prep(struct thread_data fio_unused *td, struct io_u *io_u)
167 struct fio_file *f = io_u->file;
169 if (io_u->ddir == DDIR_SYNC)
170 fio_syslet_prep_sync(io_u, f);
172 fio_syslet_prep_rw(io_u, f);
177 static void cachemiss_thread_start(void)
180 async_thread(NULL, NULL);
183 #define THREAD_STACK_SIZE (16384)
185 static unsigned long thread_stack_alloc()
187 return (unsigned long) malloc(THREAD_STACK_SIZE) + THREAD_STACK_SIZE;
190 static int fio_syslet_commit(struct thread_data *td)
192 struct syslet_data *sd = td->io_ops->data;
193 struct syslet_uatom *done;
198 assert(!sd->tail->next);
200 if (!sd->ahu.new_thread_stack)
201 sd->ahu.new_thread_stack = thread_stack_alloc();
204 * On sync completion, the atom is returned. So on NULL return
205 * it's queued asynchronously.
207 done = async_exec(sd->head, &sd->ahu);
209 sd->head = sd->tail = NULL;
212 fio_syslet_complete_atom(td, done);
217 static int fio_syslet_queue(struct thread_data *td, struct io_u *io_u)
219 struct syslet_data *sd = td->io_ops->data;
222 sd->tail->next = &io_u->req.atom;
223 sd->tail = &io_u->req.atom;
225 sd->head = sd->tail = &io_u->req.atom;
227 io_u->req.head = sd->head;
231 static int async_head_init(struct syslet_data *sd, unsigned int depth)
233 unsigned long ring_size;
235 memset(&sd->ahu, 0, sizeof(struct async_head_user));
237 ring_size = sizeof(struct syslet_uatom *) * depth;
238 sd->ring = malloc(ring_size);
239 memset(sd->ring, 0, ring_size);
241 sd->ahu.user_ring_idx = 0;
242 sd->ahu.completion_ring = sd->ring;
243 sd->ahu.ring_size_bytes = ring_size;
244 sd->ahu.head_stack = thread_stack_alloc();
245 sd->ahu.head_eip = (unsigned long) cachemiss_thread_start;
246 sd->ahu.new_thread_eip = (unsigned long) cachemiss_thread_start;
251 static void async_head_exit(struct syslet_data *sd)
256 static void fio_syslet_cleanup(struct thread_data *td)
258 struct syslet_data *sd = td->io_ops->data;
264 td->io_ops->data = NULL;
268 static int fio_syslet_init(struct thread_data *td)
270 struct syslet_data *sd;
273 sd = malloc(sizeof(*sd));
274 memset(sd, 0, sizeof(*sd));
275 sd->events = malloc(sizeof(struct io_u *) * td->iodepth);
276 memset(sd->events, 0, sizeof(struct io_u *) * td->iodepth);
279 * This will handily fail for kernels where syslet isn't available
281 if (async_head_init(sd, td->iodepth)) {
287 td->io_ops->data = sd;
291 static struct ioengine_ops ioengine = {
293 .version = FIO_IOOPS_VERSION,
294 .init = fio_syslet_init,
295 .prep = fio_syslet_prep,
296 .queue = fio_syslet_queue,
297 .commit = fio_syslet_commit,
298 .getevents = fio_syslet_getevents,
299 .event = fio_syslet_event,
300 .cleanup = fio_syslet_cleanup,
303 #else /* FIO_HAVE_SYSLET */
306 * When we have a proper configure system in place, we simply wont build
307 * and install this io engine. For now install a crippled version that
308 * just complains and fails to load.
310 static int fio_syslet_init(struct thread_data fio_unused *td)
312 fprintf(stderr, "fio: syslet not available\n");
316 static struct ioengine_ops ioengine = {
318 .version = FIO_IOOPS_VERSION,
319 .init = fio_syslet_init,
322 #endif /* FIO_HAVE_SYSLET */
324 static void fio_init fio_syslet_register(void)
326 register_ioengine(&ioengine);
329 static void fio_exit fio_syslet_unregister(void)
331 unregister_ioengine(&ioengine);