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;
25 * Inspect the ring to see if we have completed events
27 static void fio_syslet_complete(struct thread_data *td)
29 struct syslet_data *sd = td->io_ops->data;
32 struct syslet_uatom *atom;
36 atom = sd->ring[sd->ahu.user_ring_idx];
40 sd->ring[sd->ahu.user_ring_idx] = NULL;
41 if (++sd->ahu.user_ring_idx == td->iodepth)
42 sd->ahu.user_ring_idx = 0;
47 io_u->resid = io_u->xfer_buflen - ret;
51 sd->events[sd->nr_events++] = io_u;
55 static int fio_syslet_getevents(struct thread_data *td, int min,
57 struct timespec fio_unused *t)
59 struct syslet_data *sd = td->io_ops->data;
64 fio_syslet_complete(td);
67 * do we have enough immediate completions?
69 if (sd->nr_events >= (unsigned int) min)
73 * OK, we need to wait for some events...
75 get_events = min - sd->nr_events;
76 ret = async_wait(get_events, sd->ahu.user_ring_idx, &sd->ahu);
86 static struct io_u *fio_syslet_event(struct thread_data *td, int event)
88 struct syslet_data *sd = td->io_ops->data;
90 return sd->events[event];
93 static void init_atom(struct syslet_uatom *atom, int nr, void *arg0,
94 void *arg1, void *arg2, void *arg3, void *ret_ptr,
95 unsigned long flags, void *priv)
99 atom->ret_ptr = ret_ptr;
101 atom->arg_ptr[0] = arg0;
102 atom->arg_ptr[1] = arg1;
103 atom->arg_ptr[2] = arg2;
104 atom->arg_ptr[3] = arg3;
105 atom->arg_ptr[4] = atom->arg_ptr[5] = NULL;
106 atom->private = priv;
110 * Use seek atom for sync
112 static void fio_syslet_prep_sync(struct io_u *io_u, struct fio_file *f)
114 init_atom(&io_u->req.atom, __NR_fsync, &f->fd, NULL, NULL, NULL,
115 &io_u->req.ret, 0, io_u);
118 static void fio_syslet_prep_rw(struct io_u *io_u, struct fio_file *f)
125 if (io_u->ddir == DDIR_READ)
130 init_atom(&io_u->req.atom, nr, &f->fd, &io_u->xfer_buf,
131 &io_u->xfer_buflen, &io_u->offset, &io_u->req.ret, 0, io_u);
134 static int fio_syslet_prep(struct thread_data fio_unused *td, struct io_u *io_u)
136 struct fio_file *f = io_u->file;
138 if (io_u->ddir == DDIR_SYNC)
139 fio_syslet_prep_sync(io_u, f);
141 fio_syslet_prep_rw(io_u, f);
146 static void cachemiss_thread_start(void)
152 #define THREAD_STACK_SIZE (16384)
154 static unsigned long thread_stack_alloc()
156 return (unsigned long)malloc(THREAD_STACK_SIZE) + THREAD_STACK_SIZE;
159 static int fio_syslet_queue(struct thread_data *td, struct io_u *io_u)
161 struct syslet_data *sd = td->io_ops->data;
162 struct syslet_uatom *done;
165 if (!sd->ahu.new_thread_stack)
166 sd->ahu.new_thread_stack = thread_stack_alloc();
169 * On sync completion, the atom is returned. So on NULL return
170 * it's queued asynchronously.
172 done = async_exec(&io_u->req.atom, &sd->ahu);
181 if (ret != (long) io_u->xfer_buflen) {
183 io_u->resid = io_u->xfer_buflen - ret;
185 return FIO_Q_COMPLETED;
190 assert(sd->nr_events < td->iodepth);
193 td_verror(td, io_u->error, "xfer");
195 return FIO_Q_COMPLETED;
198 static int async_head_init(struct syslet_data *sd, unsigned int depth)
200 unsigned long ring_size;
202 memset(&sd->ahu, 0, sizeof(struct async_head_user));
204 ring_size = sizeof(struct syslet_uatom *) * depth;
205 sd->ring = malloc(ring_size);
206 memset(sd->ring, 0, ring_size);
208 sd->ahu.user_ring_idx = 0;
209 sd->ahu.completion_ring = sd->ring;
210 sd->ahu.ring_size_bytes = ring_size;
211 sd->ahu.head_stack = thread_stack_alloc();
212 sd->ahu.head_eip = (unsigned long)cachemiss_thread_start;
213 sd->ahu.new_thread_eip = (unsigned long)cachemiss_thread_start;
218 static void async_head_exit(struct syslet_data *sd)
223 static void fio_syslet_cleanup(struct thread_data *td)
225 struct syslet_data *sd = td->io_ops->data;
231 td->io_ops->data = NULL;
235 static int fio_syslet_init(struct thread_data *td)
237 struct syslet_data *sd;
240 sd = malloc(sizeof(*sd));
241 memset(sd, 0, sizeof(*sd));
242 sd->events = malloc(sizeof(struct io_u *) * td->iodepth);
243 memset(sd->events, 0, sizeof(struct io_u *) * td->iodepth);
246 * This will handily fail for kernels where syslet isn't available
248 if (async_head_init(sd, td->iodepth)) {
254 td->io_ops->data = sd;
258 static struct ioengine_ops ioengine = {
260 .version = FIO_IOOPS_VERSION,
261 .init = fio_syslet_init,
262 .prep = fio_syslet_prep,
263 .queue = fio_syslet_queue,
264 .getevents = fio_syslet_getevents,
265 .event = fio_syslet_event,
266 .cleanup = fio_syslet_cleanup,
269 #else /* FIO_HAVE_SYSLET */
272 * When we have a proper configure system in place, we simply wont build
273 * and install this io engine. For now install a crippled version that
274 * just complains and fails to load.
276 static int fio_syslet_init(struct thread_data fio_unused *td)
278 fprintf(stderr, "fio: syslet not available\n");
282 static struct ioengine_ops ioengine = {
284 .version = FIO_IOOPS_VERSION,
285 .init = fio_syslet_init,
288 #endif /* FIO_HAVE_SYSLET */
290 static void fio_init fio_syslet_register(void)
292 register_ioengine(&ioengine);
295 static void fio_exit fio_syslet_unregister(void)
297 unregister_ioengine(&ioengine);