2 * Native Solaris async IO engine
13 #ifdef FIO_HAVE_SOLARISAIO
15 #include <sys/asynch.h>
17 struct solarisaio_data {
18 struct io_u **aio_events;
19 unsigned int aio_pending;
21 unsigned int max_depth;
24 static int fio_solarisaio_cancel(struct thread_data fio_unused *td,
27 return aiocancel(&io_u->resultp);
30 static int fio_solarisaio_prep(struct thread_data fio_unused *td,
33 struct solarisaio_data *sd = td->io_ops->data;
35 io_u->resultp.aio_return = AIO_INPROGRESS;
36 io_u->engine_data = sd;
40 static void wait_for_event(struct timeval *tv)
42 struct solarisaio_data *sd;
47 if (res == (aio_result_t *) -1) {
51 log_err("fio: solarisaio got %d in aiowait\n", err);
58 io_u = container_of(res, struct io_u, resultp);
59 sd = io_u->engine_data;
61 if (io_u->resultp.aio_return >= 0) {
62 io_u->resid = io_u->xfer_buflen - io_u->resultp.aio_return;
65 io_u->error = io_u->resultp.aio_errno;
68 * For SIGIO, we need a write barrier between the two, so that
69 * the ->aio_pending store is seen after the ->aio_events store
71 sd->aio_events[sd->aio_pending] = io_u;
77 static int fio_solarisaio_getevents(struct thread_data *td, unsigned int min,
78 unsigned int max, struct timespec *t)
80 struct solarisaio_data *sd = td->io_ops->data;
88 tv.tv_sec = t->tv_sec;
89 tv.tv_usec = t->tv_nsec / 1000;
92 while (sd->aio_pending < min)
96 * should be OK without locking, as int operations should be atomic
98 ret = sd->aio_pending;
99 sd->aio_pending -= ret;
103 static struct io_u *fio_solarisaio_event(struct thread_data *td, int event)
105 struct solarisaio_data *sd = td->io_ops->data;
107 return sd->aio_events[event];
110 static int fio_solarisaio_queue(struct thread_data fio_unused *td,
113 struct solarisaio_data *sd = td->io_ops->data;
114 struct fio_file *f = io_u->file;
118 fio_ro_check(td, io_u);
120 if (io_u->ddir == DDIR_SYNC) {
123 if (fsync(f->fd) < 0)
126 return FIO_Q_COMPLETED;
129 if (io_u->ddir == DDIR_DATASYNC) {
132 if (fdatasync(f->fd) < 0)
135 return FIO_Q_COMPLETED;
138 if (sd->nr == sd->max_depth)
142 if (io_u->ddir == DDIR_READ)
143 ret = aioread(f->fd, io_u->xfer_buf, io_u->xfer_buflen, off,
144 SEEK_SET, &io_u->resultp);
146 ret = aiowrite(f->fd, io_u->xfer_buf, io_u->xfer_buflen, off,
147 SEEK_SET, &io_u->resultp);
150 td_verror(td, io_u->error, "xfer");
151 return FIO_Q_COMPLETED;
158 static void fio_solarisaio_cleanup(struct thread_data *td)
160 struct solarisaio_data *sd = td->io_ops->data;
163 free(sd->aio_events);
169 * Set USE_SIGNAL_COMPLETIONS to use SIGIO as completion events.
171 #ifdef USE_SIGNAL_COMPLETIONS
172 static void fio_solarisaio_sigio(int sig)
174 wait_for_event(NULL);
177 static void fio_solarisaio_init_sigio(void)
179 struct sigaction act;
181 memset(&act, 0, sizeof(act));
182 act.sa_handler = fio_solarisaio_sigio;
183 act.sa_flags = SA_RESTART;
184 sigaction(SIGIO, &act, NULL);
188 static int fio_solarisaio_init(struct thread_data *td)
190 struct solarisaio_data *sd = malloc(sizeof(*sd));
191 unsigned int max_depth;
193 max_depth = td->o.iodepth;
194 if (max_depth > MAXASYNCHIO) {
195 max_depth = MAXASYNCHIO;
196 log_info("fio: lower depth to %d due to OS constraints\n",
200 memset(sd, 0, sizeof(*sd));
201 sd->aio_events = malloc(max_depth * sizeof(struct io_u *));
202 memset(sd->aio_events, 0, max_depth * sizeof(struct io_u *));
203 sd->max_depth = max_depth;
205 #ifdef USE_SIGNAL_COMPLETIONS
206 fio_solarisaio_init_sigio();
209 td->io_ops->data = sd;
213 static struct ioengine_ops ioengine = {
214 .name = "solarisaio",
215 .version = FIO_IOOPS_VERSION,
216 .init = fio_solarisaio_init,
217 .prep = fio_solarisaio_prep,
218 .queue = fio_solarisaio_queue,
219 .cancel = fio_solarisaio_cancel,
220 .getevents = fio_solarisaio_getevents,
221 .event = fio_solarisaio_event,
222 .cleanup = fio_solarisaio_cleanup,
223 .open_file = generic_open_file,
224 .close_file = generic_close_file,
225 .get_file_size = generic_get_file_size,
228 #else /* FIO_HAVE_SOLARISAIO */
231 * When we have a proper configure system in place, we simply wont build
232 * and install this io engine. For now install a crippled version that
233 * just complains and fails to load.
235 static int fio_solarisaio_init(struct thread_data fio_unused *td)
237 log_err("fio: solarisaio not available\n");
241 static struct ioengine_ops ioengine = {
242 .name = "solarisaio",
243 .version = FIO_IOOPS_VERSION,
244 .init = fio_solarisaio_init,
249 static void fio_init fio_solarisaio_register(void)
251 register_ioengine(&ioengine);
254 static void fio_exit fio_solarisaio_unregister(void)
256 unregister_ioengine(&ioengine);