4 * IO engine that does regular pread(2)/pwrite(2) to transfer data, but
5 * with syslets to make the execution async.
13 #include <asm/unistd.h>
18 #ifdef FIO_HAVE_SYSLET
22 unsigned int nr_events;
24 struct async_head_user ahu;
25 struct syslet_uatom **ring;
27 struct syslet_uatom *head, *tail;
30 static void fio_syslet_complete_atom(struct thread_data *td,
31 struct syslet_uatom *atom)
33 struct syslet_data *sd = td->io_ops->data;
34 struct syslet_uatom *last;
38 * complete from the beginning of the sequence up to (and
39 * including) this atom
43 atom = io_u->req.head;
46 * now complete in right order
54 io_u->resid = io_u->xfer_buflen - ret;
58 assert(sd->nr_events < td->iodepth);
59 sd->events[sd->nr_events++] = io_u;
71 * Inspect the ring to see if we have completed events
73 static void fio_syslet_complete(struct thread_data *td)
75 struct syslet_data *sd = td->io_ops->data;
78 struct syslet_uatom *atom;
80 atom = sd->ring[sd->ahu.user_ring_idx];
84 sd->ring[sd->ahu.user_ring_idx] = NULL;
85 if (++sd->ahu.user_ring_idx == td->iodepth)
86 sd->ahu.user_ring_idx = 0;
88 fio_syslet_complete_atom(td, atom);
92 static int fio_syslet_getevents(struct thread_data *td, int min,
94 struct timespec fio_unused *t)
96 struct syslet_data *sd = td->io_ops->data;
100 fio_syslet_complete(td);
103 * do we have enough immediate completions?
105 if (sd->nr_events >= (unsigned int) min)
109 * OK, we need to wait for some events...
111 ret = async_wait(1, sd->ahu.user_ring_idx, &sd->ahu);
121 static struct io_u *fio_syslet_event(struct thread_data *td, int event)
123 struct syslet_data *sd = td->io_ops->data;
125 return sd->events[event];
128 static void init_atom(struct syslet_uatom *atom, int nr, void *arg0,
129 void *arg1, void *arg2, void *arg3, void *ret_ptr,
130 unsigned long flags, void *priv)
134 atom->ret_ptr = ret_ptr;
136 atom->arg_ptr[0] = arg0;
137 atom->arg_ptr[1] = arg1;
138 atom->arg_ptr[2] = arg2;
139 atom->arg_ptr[3] = arg3;
140 atom->arg_ptr[4] = atom->arg_ptr[5] = NULL;
141 atom->private = priv;
145 * Use seek atom for sync
147 static void fio_syslet_prep_sync(struct io_u *io_u, struct fio_file *f)
149 init_atom(&io_u->req.atom, __NR_fsync, &f->fd, NULL, NULL, NULL,
150 &io_u->req.ret, 0, io_u);
153 static void fio_syslet_prep_rw(struct io_u *io_u, struct fio_file *f)
160 if (io_u->ddir == DDIR_READ)
165 init_atom(&io_u->req.atom, nr, &f->fd, &io_u->xfer_buf,
166 &io_u->xfer_buflen, &io_u->offset, &io_u->req.ret, 0, io_u);
169 static int fio_syslet_prep(struct thread_data fio_unused *td, struct io_u *io_u)
171 struct fio_file *f = io_u->file;
173 if (io_u->ddir == DDIR_SYNC)
174 fio_syslet_prep_sync(io_u, f);
176 fio_syslet_prep_rw(io_u, f);
181 static void cachemiss_thread_start(void)
184 async_thread(NULL, NULL);
187 #define THREAD_STACK_SIZE (16384)
189 static unsigned long thread_stack_alloc()
191 return (unsigned long) malloc(THREAD_STACK_SIZE) + THREAD_STACK_SIZE;
194 static void fio_syslet_queued(struct thread_data *td, struct syslet_data *sd)
196 struct syslet_uatom *atom;
199 fio_gettime(&now, NULL);
203 struct io_u *io_u = atom->private;
205 memcpy(&io_u->issue_time, &now, sizeof(now));
206 io_u_queued(td, io_u);
211 static int fio_syslet_commit(struct thread_data *td)
213 struct syslet_data *sd = td->io_ops->data;
214 struct syslet_uatom *done;
219 assert(!sd->tail->next);
221 if (!sd->ahu.new_thread_stack)
222 sd->ahu.new_thread_stack = thread_stack_alloc();
224 fio_syslet_queued(td, sd);
227 * On sync completion, the atom is returned. So on NULL return
228 * it's queued asynchronously.
230 done = async_exec(sd->head, &sd->ahu);
232 sd->head = sd->tail = NULL;
235 fio_syslet_complete_atom(td, done);
240 static int fio_syslet_queue(struct thread_data *td, struct io_u *io_u)
242 struct syslet_data *sd = td->io_ops->data;
245 sd->tail->next = &io_u->req.atom;
246 sd->tail = &io_u->req.atom;
248 sd->head = sd->tail = &io_u->req.atom;
250 io_u->req.head = sd->head;
254 static int async_head_init(struct syslet_data *sd, unsigned int depth)
256 unsigned long ring_size;
258 memset(&sd->ahu, 0, sizeof(struct async_head_user));
260 ring_size = sizeof(struct syslet_uatom *) * depth;
261 sd->ring = malloc(ring_size);
262 memset(sd->ring, 0, ring_size);
264 sd->ahu.user_ring_idx = 0;
265 sd->ahu.completion_ring = sd->ring;
266 sd->ahu.ring_size_bytes = ring_size;
267 sd->ahu.head_stack = thread_stack_alloc();
268 sd->ahu.head_eip = (unsigned long) cachemiss_thread_start;
269 sd->ahu.new_thread_eip = (unsigned long) cachemiss_thread_start;
274 static void async_head_exit(struct syslet_data *sd)
279 static void fio_syslet_cleanup(struct thread_data *td)
281 struct syslet_data *sd = td->io_ops->data;
287 td->io_ops->data = NULL;
291 static int fio_syslet_init(struct thread_data *td)
293 struct syslet_data *sd;
296 sd = malloc(sizeof(*sd));
297 memset(sd, 0, sizeof(*sd));
298 sd->events = malloc(sizeof(struct io_u *) * td->iodepth);
299 memset(sd->events, 0, sizeof(struct io_u *) * td->iodepth);
302 * This will handily fail for kernels where syslet isn't available
304 if (async_head_init(sd, td->iodepth)) {
310 td->io_ops->data = sd;
314 static struct ioengine_ops ioengine = {
316 .version = FIO_IOOPS_VERSION,
317 .init = fio_syslet_init,
318 .prep = fio_syslet_prep,
319 .queue = fio_syslet_queue,
320 .commit = fio_syslet_commit,
321 .getevents = fio_syslet_getevents,
322 .event = fio_syslet_event,
323 .cleanup = fio_syslet_cleanup,
324 .open_file = generic_open_file,
325 .close_file = generic_close_file,
328 #else /* FIO_HAVE_SYSLET */
331 * When we have a proper configure system in place, we simply wont build
332 * and install this io engine. For now install a crippled version that
333 * just complains and fails to load.
335 static int fio_syslet_init(struct thread_data fio_unused *td)
337 fprintf(stderr, "fio: syslet not available\n");
341 static struct ioengine_ops ioengine = {
343 .version = FIO_IOOPS_VERSION,
344 .init = fio_syslet_init,
347 #endif /* FIO_HAVE_SYSLET */
349 static void fio_init fio_syslet_register(void)
351 register_ioengine(&ioengine);
354 static void fio_exit fio_syslet_unregister(void)
356 unregister_ioengine(&ioengine);