Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 1 | /* |
Jens Axboe | da751ca | 2007-03-14 10:59:33 +0100 | [diff] [blame] | 2 | * syslet engine |
| 3 | * |
| 4 | * IO engine that does regular pread(2)/pwrite(2) to transfer data, but |
| 5 | * with syslets to make the execution async. |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 6 | * |
| 7 | */ |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <unistd.h> |
| 11 | #include <errno.h> |
| 12 | #include <assert.h> |
Jens Axboe | b884635 | 2007-03-14 14:29:16 +0100 | [diff] [blame] | 13 | #include <asm/unistd.h> |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 14 | |
| 15 | #include "../fio.h" |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 16 | |
| 17 | #ifdef FIO_HAVE_SYSLET |
| 18 | |
Jens Axboe | 1760e67 | 2007-03-14 20:41:42 +0100 | [diff] [blame] | 19 | #ifdef __NR_pread64 |
| 20 | #define __NR_fio_pread __NR_pread64 |
| 21 | #define __NR_fio_pwrite __NR_pwrite64 |
| 22 | #else |
| 23 | #define __NR_fio_pread __NR_pread |
| 24 | #define __NR_fio_pwrite __NR_pwrite |
| 25 | #endif |
| 26 | |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 27 | struct syslet_data { |
| 28 | struct io_u **events; |
| 29 | unsigned int nr_events; |
| 30 | |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 31 | struct async_head_user ahu; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 32 | struct syslet_uatom **ring; |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 33 | |
| 34 | struct syslet_uatom *head, *tail; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 35 | }; |
| 36 | |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 37 | static void fio_syslet_complete_atom(struct thread_data *td, |
| 38 | struct syslet_uatom *atom) |
| 39 | { |
| 40 | struct syslet_data *sd = td->io_ops->data; |
Jens Axboe | 5b38ee8 | 2007-02-26 10:44:22 +0100 | [diff] [blame] | 41 | struct syslet_uatom *last; |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 42 | struct io_u *io_u; |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 43 | |
| 44 | /* |
Jens Axboe | 5b38ee8 | 2007-02-26 10:44:22 +0100 | [diff] [blame] | 45 | * complete from the beginning of the sequence up to (and |
| 46 | * including) this atom |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 47 | */ |
Jens Axboe | 5b38ee8 | 2007-02-26 10:44:22 +0100 | [diff] [blame] | 48 | last = atom; |
| 49 | io_u = atom->private; |
| 50 | atom = io_u->req.head; |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * now complete in right order |
| 54 | */ |
Jens Axboe | 5b38ee8 | 2007-02-26 10:44:22 +0100 | [diff] [blame] | 55 | do { |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 56 | long ret; |
| 57 | |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 58 | io_u = atom->private; |
| 59 | ret = *atom->ret_ptr; |
Jens Axboe | e2e6791 | 2007-03-12 09:43:05 +0100 | [diff] [blame] | 60 | if (ret >= 0) |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 61 | io_u->resid = io_u->xfer_buflen - ret; |
| 62 | else if (ret < 0) |
| 63 | io_u->error = ret; |
| 64 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 65 | assert(sd->nr_events < td->o.iodepth); |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 66 | sd->events[sd->nr_events++] = io_u; |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 67 | |
Jens Axboe | 5b38ee8 | 2007-02-26 10:44:22 +0100 | [diff] [blame] | 68 | if (atom == last) |
| 69 | break; |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 70 | |
Jens Axboe | 5b38ee8 | 2007-02-26 10:44:22 +0100 | [diff] [blame] | 71 | atom = atom->next; |
| 72 | } while (1); |
| 73 | |
| 74 | assert(!last->next); |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 75 | } |
| 76 | |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 77 | /* |
| 78 | * Inspect the ring to see if we have completed events |
| 79 | */ |
| 80 | static void fio_syslet_complete(struct thread_data *td) |
| 81 | { |
| 82 | struct syslet_data *sd = td->io_ops->data; |
| 83 | |
| 84 | do { |
| 85 | struct syslet_uatom *atom; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 86 | |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 87 | atom = sd->ring[sd->ahu.user_ring_idx]; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 88 | if (!atom) |
| 89 | break; |
| 90 | |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 91 | sd->ring[sd->ahu.user_ring_idx] = NULL; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 92 | if (++sd->ahu.user_ring_idx == td->o.iodepth) |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 93 | sd->ahu.user_ring_idx = 0; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 94 | |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 95 | fio_syslet_complete_atom(td, atom); |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 96 | } while (1); |
| 97 | } |
| 98 | |
| 99 | static int fio_syslet_getevents(struct thread_data *td, int min, |
| 100 | int fio_unused max, |
| 101 | struct timespec fio_unused *t) |
| 102 | { |
| 103 | struct syslet_data *sd = td->io_ops->data; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 104 | long ret; |
| 105 | |
| 106 | do { |
| 107 | fio_syslet_complete(td); |
| 108 | |
| 109 | /* |
| 110 | * do we have enough immediate completions? |
| 111 | */ |
| 112 | if (sd->nr_events >= (unsigned int) min) |
| 113 | break; |
| 114 | |
| 115 | /* |
| 116 | * OK, we need to wait for some events... |
| 117 | */ |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 118 | ret = async_wait(1, sd->ahu.user_ring_idx, &sd->ahu); |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 119 | if (ret < 0) |
Jens Axboe | e49499f | 2007-02-22 11:08:52 +0100 | [diff] [blame] | 120 | return -errno; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 121 | } while (1); |
| 122 | |
| 123 | ret = sd->nr_events; |
| 124 | sd->nr_events = 0; |
| 125 | return ret; |
| 126 | } |
| 127 | |
| 128 | static struct io_u *fio_syslet_event(struct thread_data *td, int event) |
| 129 | { |
| 130 | struct syslet_data *sd = td->io_ops->data; |
| 131 | |
| 132 | return sd->events[event]; |
| 133 | } |
| 134 | |
| 135 | static void init_atom(struct syslet_uatom *atom, int nr, void *arg0, |
Jens Axboe | a2e1b08 | 2007-02-14 08:06:19 +0100 | [diff] [blame] | 136 | void *arg1, void *arg2, void *arg3, void *ret_ptr, |
| 137 | unsigned long flags, void *priv) |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 138 | { |
| 139 | atom->flags = flags; |
| 140 | atom->nr = nr; |
| 141 | atom->ret_ptr = ret_ptr; |
Jens Axboe | a2e1b08 | 2007-02-14 08:06:19 +0100 | [diff] [blame] | 142 | atom->next = NULL; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 143 | atom->arg_ptr[0] = arg0; |
| 144 | atom->arg_ptr[1] = arg1; |
| 145 | atom->arg_ptr[2] = arg2; |
Jens Axboe | a2e1b08 | 2007-02-14 08:06:19 +0100 | [diff] [blame] | 146 | atom->arg_ptr[3] = arg3; |
| 147 | atom->arg_ptr[4] = atom->arg_ptr[5] = NULL; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 148 | atom->private = priv; |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Use seek atom for sync |
| 153 | */ |
| 154 | static void fio_syslet_prep_sync(struct io_u *io_u, struct fio_file *f) |
| 155 | { |
Jens Axboe | a2e1b08 | 2007-02-14 08:06:19 +0100 | [diff] [blame] | 156 | init_atom(&io_u->req.atom, __NR_fsync, &f->fd, NULL, NULL, NULL, |
Jens Axboe | 7d44a74 | 2007-02-14 17:32:08 +0100 | [diff] [blame] | 157 | &io_u->req.ret, 0, io_u); |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static void fio_syslet_prep_rw(struct io_u *io_u, struct fio_file *f) |
| 161 | { |
| 162 | int nr; |
| 163 | |
| 164 | /* |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 165 | * prepare rw |
| 166 | */ |
| 167 | if (io_u->ddir == DDIR_READ) |
Jens Axboe | 1760e67 | 2007-03-14 20:41:42 +0100 | [diff] [blame] | 168 | nr = __NR_fio_pread; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 169 | else |
Jens Axboe | 1760e67 | 2007-03-14 20:41:42 +0100 | [diff] [blame] | 170 | nr = __NR_fio_pwrite; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 171 | |
Jens Axboe | a2e1b08 | 2007-02-14 08:06:19 +0100 | [diff] [blame] | 172 | init_atom(&io_u->req.atom, nr, &f->fd, &io_u->xfer_buf, |
Jens Axboe | 7d44a74 | 2007-02-14 17:32:08 +0100 | [diff] [blame] | 173 | &io_u->xfer_buflen, &io_u->offset, &io_u->req.ret, 0, io_u); |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static int fio_syslet_prep(struct thread_data fio_unused *td, struct io_u *io_u) |
| 177 | { |
| 178 | struct fio_file *f = io_u->file; |
| 179 | |
| 180 | if (io_u->ddir == DDIR_SYNC) |
| 181 | fio_syslet_prep_sync(io_u, f); |
| 182 | else |
| 183 | fio_syslet_prep_rw(io_u, f); |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 188 | static void cachemiss_thread_start(void) |
| 189 | { |
| 190 | while (1) |
Jens Axboe | 7756b0d | 2007-02-26 10:22:31 +0100 | [diff] [blame] | 191 | async_thread(NULL, NULL); |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | #define THREAD_STACK_SIZE (16384) |
| 195 | |
| 196 | static unsigned long thread_stack_alloc() |
| 197 | { |
Jens Axboe | 5b38ee8 | 2007-02-26 10:44:22 +0100 | [diff] [blame] | 198 | return (unsigned long) malloc(THREAD_STACK_SIZE) + THREAD_STACK_SIZE; |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 199 | } |
| 200 | |
Jens Axboe | a0a930e | 2007-02-27 19:47:13 +0100 | [diff] [blame] | 201 | static void fio_syslet_queued(struct thread_data *td, struct syslet_data *sd) |
| 202 | { |
| 203 | struct syslet_uatom *atom; |
| 204 | struct timeval now; |
| 205 | |
| 206 | fio_gettime(&now, NULL); |
| 207 | |
| 208 | atom = sd->head; |
| 209 | while (atom) { |
| 210 | struct io_u *io_u = atom->private; |
| 211 | |
| 212 | memcpy(&io_u->issue_time, &now, sizeof(now)); |
| 213 | io_u_queued(td, io_u); |
| 214 | atom = atom->next; |
| 215 | } |
| 216 | } |
| 217 | |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 218 | static int fio_syslet_commit(struct thread_data *td) |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 219 | { |
| 220 | struct syslet_data *sd = td->io_ops->data; |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 221 | struct syslet_uatom *done; |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 222 | |
| 223 | if (!sd->head) |
| 224 | return 0; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 225 | |
Jens Axboe | 5b38ee8 | 2007-02-26 10:44:22 +0100 | [diff] [blame] | 226 | assert(!sd->tail->next); |
| 227 | |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 228 | if (!sd->ahu.new_thread_stack) |
| 229 | sd->ahu.new_thread_stack = thread_stack_alloc(); |
| 230 | |
Jens Axboe | a0a930e | 2007-02-27 19:47:13 +0100 | [diff] [blame] | 231 | fio_syslet_queued(td, sd); |
| 232 | |
Jens Axboe | 7d44a74 | 2007-02-14 17:32:08 +0100 | [diff] [blame] | 233 | /* |
| 234 | * On sync completion, the atom is returned. So on NULL return |
| 235 | * it's queued asynchronously. |
| 236 | */ |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 237 | done = async_exec(sd->head, &sd->ahu); |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 238 | |
Jens Axboe | 76f58b9 | 2007-03-29 13:26:17 +0200 | [diff] [blame] | 239 | if (done == (void *) -1) { |
| 240 | log_err("fio: syslets don't appear to work\n"); |
| 241 | return -1; |
| 242 | } |
| 243 | |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 244 | sd->head = sd->tail = NULL; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 245 | |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 246 | if (done) |
| 247 | fio_syslet_complete_atom(td, done); |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 248 | |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 249 | return 0; |
| 250 | } |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 251 | |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 252 | static int fio_syslet_queue(struct thread_data *td, struct io_u *io_u) |
| 253 | { |
| 254 | struct syslet_data *sd = td->io_ops->data; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 255 | |
Jens Axboe | 7101d9c | 2007-09-12 13:12:39 +0200 | [diff] [blame^] | 256 | fio_ro_check(td, io_u); |
| 257 | |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 258 | if (sd->tail) { |
| 259 | sd->tail->next = &io_u->req.atom; |
| 260 | sd->tail = &io_u->req.atom; |
| 261 | } else |
| 262 | sd->head = sd->tail = &io_u->req.atom; |
| 263 | |
Jens Axboe | 5b38ee8 | 2007-02-26 10:44:22 +0100 | [diff] [blame] | 264 | io_u->req.head = sd->head; |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 265 | return FIO_Q_QUEUED; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 266 | } |
| 267 | |
Jens Axboe | db64e9b | 2007-02-14 02:10:59 +0100 | [diff] [blame] | 268 | static int async_head_init(struct syslet_data *sd, unsigned int depth) |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 269 | { |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 270 | unsigned long ring_size; |
| 271 | |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 272 | memset(&sd->ahu, 0, sizeof(struct async_head_user)); |
Jens Axboe | 2ca50be | 2007-02-14 08:31:15 +0100 | [diff] [blame] | 273 | |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 274 | ring_size = sizeof(struct syslet_uatom *) * depth; |
| 275 | sd->ring = malloc(ring_size); |
| 276 | memset(sd->ring, 0, ring_size); |
| 277 | |
Ingo Molnar | bf0dc8f | 2007-02-21 23:25:44 +0100 | [diff] [blame] | 278 | sd->ahu.user_ring_idx = 0; |
| 279 | sd->ahu.completion_ring = sd->ring; |
| 280 | sd->ahu.ring_size_bytes = ring_size; |
| 281 | sd->ahu.head_stack = thread_stack_alloc(); |
Jens Axboe | 5b38ee8 | 2007-02-26 10:44:22 +0100 | [diff] [blame] | 282 | sd->ahu.head_eip = (unsigned long) cachemiss_thread_start; |
| 283 | sd->ahu.new_thread_eip = (unsigned long) cachemiss_thread_start; |
Jens Axboe | db64e9b | 2007-02-14 02:10:59 +0100 | [diff] [blame] | 284 | |
| 285 | return 0; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 286 | } |
| 287 | |
Jens Axboe | 2ca50be | 2007-02-14 08:31:15 +0100 | [diff] [blame] | 288 | static void async_head_exit(struct syslet_data *sd) |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 289 | { |
Jens Axboe | 7f059a7 | 2007-02-14 08:53:11 +0100 | [diff] [blame] | 290 | free(sd->ring); |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 291 | } |
| 292 | |
Jens Axboe | 76f58b9 | 2007-03-29 13:26:17 +0200 | [diff] [blame] | 293 | static int check_syslet_support(struct syslet_data *sd) |
| 294 | { |
| 295 | struct syslet_uatom atom; |
| 296 | void *ret; |
| 297 | |
| 298 | init_atom(&atom, __NR_getpid, NULL, NULL, NULL, NULL, NULL, 0, NULL); |
| 299 | ret = async_exec(sd->head, &sd->ahu); |
| 300 | if (ret == (void *) -1) |
| 301 | return 1; |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 306 | static void fio_syslet_cleanup(struct thread_data *td) |
| 307 | { |
| 308 | struct syslet_data *sd = td->io_ops->data; |
| 309 | |
| 310 | if (sd) { |
Jens Axboe | 2ca50be | 2007-02-14 08:31:15 +0100 | [diff] [blame] | 311 | async_head_exit(sd); |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 312 | free(sd->events); |
| 313 | free(sd); |
| 314 | td->io_ops->data = NULL; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | static int fio_syslet_init(struct thread_data *td) |
| 319 | { |
| 320 | struct syslet_data *sd; |
| 321 | |
| 322 | sd = malloc(sizeof(*sd)); |
| 323 | memset(sd, 0, sizeof(*sd)); |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 324 | sd->events = malloc(sizeof(struct io_u *) * td->o.iodepth); |
| 325 | memset(sd->events, 0, sizeof(struct io_u *) * td->o.iodepth); |
Jens Axboe | db64e9b | 2007-02-14 02:10:59 +0100 | [diff] [blame] | 326 | |
| 327 | /* |
| 328 | * This will handily fail for kernels where syslet isn't available |
| 329 | */ |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 330 | if (async_head_init(sd, td->o.iodepth)) { |
Jens Axboe | db64e9b | 2007-02-14 02:10:59 +0100 | [diff] [blame] | 331 | free(sd->events); |
| 332 | free(sd); |
| 333 | return 1; |
| 334 | } |
| 335 | |
Jens Axboe | 76f58b9 | 2007-03-29 13:26:17 +0200 | [diff] [blame] | 336 | if (check_syslet_support(sd)) { |
| 337 | log_err("fio: syslets do not appear to work\n"); |
| 338 | free(sd->events); |
| 339 | free(sd); |
| 340 | return 1; |
| 341 | } |
| 342 | |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 343 | td->io_ops->data = sd; |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | static struct ioengine_ops ioengine = { |
| 348 | .name = "syslet-rw", |
| 349 | .version = FIO_IOOPS_VERSION, |
| 350 | .init = fio_syslet_init, |
| 351 | .prep = fio_syslet_prep, |
| 352 | .queue = fio_syslet_queue, |
Jens Axboe | 9ff9de6 | 2007-02-23 13:21:45 +0100 | [diff] [blame] | 353 | .commit = fio_syslet_commit, |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 354 | .getevents = fio_syslet_getevents, |
| 355 | .event = fio_syslet_event, |
| 356 | .cleanup = fio_syslet_cleanup, |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 357 | .open_file = generic_open_file, |
| 358 | .close_file = generic_close_file, |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 359 | }; |
| 360 | |
| 361 | #else /* FIO_HAVE_SYSLET */ |
| 362 | |
| 363 | /* |
| 364 | * When we have a proper configure system in place, we simply wont build |
| 365 | * and install this io engine. For now install a crippled version that |
| 366 | * just complains and fails to load. |
| 367 | */ |
| 368 | static int fio_syslet_init(struct thread_data fio_unused *td) |
| 369 | { |
| 370 | fprintf(stderr, "fio: syslet not available\n"); |
| 371 | return 1; |
| 372 | } |
| 373 | |
| 374 | static struct ioengine_ops ioengine = { |
| 375 | .name = "syslet-rw", |
| 376 | .version = FIO_IOOPS_VERSION, |
| 377 | .init = fio_syslet_init, |
| 378 | }; |
| 379 | |
| 380 | #endif /* FIO_HAVE_SYSLET */ |
| 381 | |
| 382 | static void fio_init fio_syslet_register(void) |
| 383 | { |
| 384 | register_ioengine(&ioengine); |
| 385 | } |
| 386 | |
| 387 | static void fio_exit fio_syslet_unregister(void) |
| 388 | { |
| 389 | unregister_ioengine(&ioengine); |
| 390 | } |