Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 1 | #ifndef FIO_IOENGINE_H |
| 2 | #define FIO_IOENGINE_H |
| 3 | |
Jens Axboe | 4166658 | 2012-03-21 10:25:29 +0100 | [diff] [blame] | 4 | #include "compiler/compiler.h" |
| 5 | #include "io_ddir.h" |
Jens Axboe | ec41265 | 2012-03-08 12:37:31 +0100 | [diff] [blame] | 6 | #include "debug.h" |
Jens Axboe | 4166658 | 2012-03-21 10:25:29 +0100 | [diff] [blame] | 7 | #include "file.h" |
Jens Axboe | ec41265 | 2012-03-08 12:37:31 +0100 | [diff] [blame] | 8 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 9 | #define FIO_IOOPS_VERSION 13 |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 10 | |
| 11 | enum { |
Radha Ramachandran | 0c41214 | 2009-11-03 21:45:31 +0100 | [diff] [blame] | 12 | IO_U_F_FREE = 1 << 0, |
| 13 | IO_U_F_FLIGHT = 1 << 1, |
| 14 | IO_U_F_FREE_DEF = 1 << 2, |
| 15 | IO_U_F_IN_CUR_DEPTH = 1 << 3, |
Jens Axboe | 38dad62 | 2010-07-20 14:46:00 -0600 | [diff] [blame] | 16 | IO_U_F_BUSY_OK = 1 << 4, |
Jens Axboe | 0d29de8 | 2010-09-01 13:54:15 +0200 | [diff] [blame] | 17 | IO_U_F_TRIMMED = 1 << 5, |
Jens Axboe | 1ef2b6b | 2010-10-08 15:07:01 +0200 | [diff] [blame] | 18 | IO_U_F_BARRIER = 1 << 6, |
Jens Axboe | 82af2a7 | 2012-03-13 13:45:58 +0100 | [diff] [blame] | 19 | IO_U_F_VER_LIST = 1 << 7, |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 20 | }; |
| 21 | |
Jens Axboe | 4166658 | 2012-03-21 10:25:29 +0100 | [diff] [blame] | 22 | struct thread_data; |
| 23 | |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 24 | /* |
| 25 | * The io unit |
| 26 | */ |
| 27 | struct io_u { |
| 28 | union { |
| 29 | #ifdef FIO_HAVE_LIBAIO |
| 30 | struct iocb iocb; |
| 31 | #endif |
| 32 | #ifdef FIO_HAVE_POSIXAIO |
Jens Axboe | e97c144 | 2011-09-21 09:38:01 +0200 | [diff] [blame] | 33 | os_aiocb_t aiocb; |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 34 | #endif |
| 35 | #ifdef FIO_HAVE_SGIO |
| 36 | struct sg_io_hdr hdr; |
| 37 | #endif |
| 38 | #ifdef FIO_HAVE_GUASI |
| 39 | guasi_req_t greq; |
| 40 | #endif |
| 41 | #ifdef FIO_HAVE_SOLARISAIO |
| 42 | aio_result_t resultp; |
| 43 | #endif |
Jens Axboe | 79a4318 | 2010-09-07 13:28:58 +0200 | [diff] [blame] | 44 | #ifdef FIO_HAVE_BINJECT |
| 45 | struct b_user_cmd buc; |
| 46 | #endif |
ren yufei | 21b8aee | 2011-08-01 10:01:57 +0200 | [diff] [blame] | 47 | #ifdef FIO_HAVE_RDMA |
| 48 | struct ibv_mr *mr; |
| 49 | #endif |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 50 | void *mmap_data; |
| 51 | }; |
| 52 | struct timeval start_time; |
| 53 | struct timeval issue_time; |
| 54 | |
| 55 | /* |
| 56 | * Allocated/set buffer and length |
| 57 | */ |
| 58 | void *buf; |
| 59 | unsigned long buflen; |
| 60 | unsigned long long offset; |
| 61 | |
| 62 | /* |
Jens Axboe | 7d9fb45 | 2011-01-11 22:16:49 +0100 | [diff] [blame] | 63 | * Initial seed for generating the buffer contents |
| 64 | */ |
| 65 | unsigned long rand_seed; |
| 66 | |
| 67 | /* |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 68 | * IO engine state, may be different from above when we get |
| 69 | * partial transfers / residual data counts |
| 70 | */ |
| 71 | void *xfer_buf; |
| 72 | unsigned long xfer_buflen; |
| 73 | |
Jens Axboe | 9522850 | 2010-07-14 08:42:03 +0200 | [diff] [blame] | 74 | /* |
| 75 | * Parameter related to pre-filled buffers and |
| 76 | * their size to handle variable block sizes. |
| 77 | */ |
| 78 | unsigned long buf_filled_len; |
| 79 | |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 80 | unsigned int resid; |
| 81 | unsigned int error; |
| 82 | |
| 83 | enum fio_ddir ddir; |
| 84 | |
| 85 | /* |
| 86 | * io engine private data |
| 87 | */ |
| 88 | union { |
| 89 | unsigned int index; |
| 90 | unsigned int seen; |
| 91 | void *engine_data; |
| 92 | }; |
| 93 | |
| 94 | unsigned int flags; |
| 95 | |
| 96 | struct fio_file *file; |
| 97 | |
| 98 | struct flist_head list; |
| 99 | |
| 100 | /* |
| 101 | * Callback for io completion |
| 102 | */ |
| 103 | int (*end_io)(struct thread_data *, struct io_u *); |
| 104 | }; |
| 105 | |
| 106 | /* |
| 107 | * io_ops->queue() return values |
| 108 | */ |
| 109 | enum { |
| 110 | FIO_Q_COMPLETED = 0, /* completed sync */ |
| 111 | FIO_Q_QUEUED = 1, /* queued, will complete async */ |
| 112 | FIO_Q_BUSY = 2, /* no more room, call ->commit() */ |
| 113 | }; |
| 114 | |
| 115 | struct ioengine_ops { |
| 116 | struct flist_head list; |
| 117 | char name[16]; |
| 118 | int version; |
| 119 | int flags; |
| 120 | int (*setup)(struct thread_data *); |
| 121 | int (*init)(struct thread_data *); |
| 122 | int (*prep)(struct thread_data *, struct io_u *); |
| 123 | int (*queue)(struct thread_data *, struct io_u *); |
| 124 | int (*commit)(struct thread_data *); |
| 125 | int (*getevents)(struct thread_data *, unsigned int, unsigned int, struct timespec *); |
| 126 | struct io_u *(*event)(struct thread_data *, int); |
| 127 | int (*cancel)(struct thread_data *, struct io_u *); |
| 128 | void (*cleanup)(struct thread_data *); |
| 129 | int (*open_file)(struct thread_data *, struct fio_file *); |
| 130 | int (*close_file)(struct thread_data *, struct fio_file *); |
| 131 | int (*get_file_size)(struct thread_data *, struct fio_file *); |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 132 | int option_struct_size; |
| 133 | struct fio_option *options; |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 134 | void *data; |
| 135 | void *dlhandle; |
| 136 | }; |
| 137 | |
Jens Axboe | 2b4f4ab | 2009-06-03 08:50:36 +0200 | [diff] [blame] | 138 | enum fio_ioengine_flags { |
| 139 | FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */ |
| 140 | FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */ |
| 141 | FIO_DISKLESSIO = 1 << 2, /* no disk involved */ |
| 142 | FIO_NOEXTEND = 1 << 3, /* engine can't extend file */ |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 143 | FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */ |
Jens Axboe | 2b4f4ab | 2009-06-03 08:50:36 +0200 | [diff] [blame] | 144 | FIO_UNIDIR = 1 << 5, /* engine is uni-directional */ |
| 145 | FIO_NOIO = 1 << 6, /* thread does only pseudo IO */ |
Bruce Cran | 03e20d6 | 2011-01-02 20:14:54 +0100 | [diff] [blame] | 146 | FIO_SIGTERM = 1 << 7, /* needs SIGTERM to exit */ |
Jens Axboe | 9c0d224 | 2009-07-01 12:26:28 +0200 | [diff] [blame] | 147 | FIO_PIPEIO = 1 << 8, /* input/output no seekable */ |
Jens Axboe | 1ef2b6b | 2010-10-08 15:07:01 +0200 | [diff] [blame] | 148 | FIO_BARRIER = 1 << 9, /* engine supports barriers */ |
Jens Axboe | ca7e0dd | 2010-10-28 08:52:13 -0600 | [diff] [blame] | 149 | FIO_MEMALIGN = 1 << 10, /* engine wants aligned memory */ |
Jens Axboe | 2b4f4ab | 2009-06-03 08:50:36 +0200 | [diff] [blame] | 150 | }; |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * io engine entry points |
| 154 | */ |
| 155 | extern int __must_check td_io_init(struct thread_data *); |
| 156 | extern int __must_check td_io_prep(struct thread_data *, struct io_u *); |
| 157 | extern int __must_check td_io_queue(struct thread_data *, struct io_u *); |
| 158 | extern int __must_check td_io_sync(struct thread_data *, struct fio_file *); |
| 159 | extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *); |
| 160 | extern int __must_check td_io_commit(struct thread_data *); |
| 161 | extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *); |
| 162 | extern int td_io_close_file(struct thread_data *, struct fio_file *); |
| 163 | extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *); |
| 164 | |
| 165 | extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *); |
| 166 | extern void register_ioengine(struct ioengine_ops *); |
| 167 | extern void unregister_ioengine(struct ioengine_ops *); |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 168 | extern void free_ioengine(struct thread_data *); |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 169 | extern void close_ioengine(struct thread_data *); |
| 170 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 171 | extern int fio_show_ioengine_help(const char *engine); |
| 172 | |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 173 | /* |
| 174 | * io unit handling |
| 175 | */ |
| 176 | #define queue_full(td) flist_empty(&(td)->io_u_freelist) |
| 177 | extern struct io_u *__get_io_u(struct thread_data *); |
| 178 | extern struct io_u *get_io_u(struct thread_data *); |
| 179 | extern void put_io_u(struct thread_data *, struct io_u *); |
Radha Ramachandran | f2bba18 | 2009-06-15 08:40:16 +0200 | [diff] [blame] | 180 | extern void clear_io_u(struct thread_data *, struct io_u *); |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 181 | extern void requeue_io_u(struct thread_data *, struct io_u **); |
Jens Axboe | 581e714 | 2009-06-09 12:47:16 +0200 | [diff] [blame] | 182 | extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, unsigned long *); |
| 183 | extern int __must_check io_u_queued_complete(struct thread_data *, int, unsigned long *); |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 184 | extern void io_u_queued(struct thread_data *, struct io_u *); |
| 185 | extern void io_u_log_error(struct thread_data *, struct io_u *); |
| 186 | extern void io_u_mark_depth(struct thread_data *, unsigned int); |
Jens Axboe | 9c42684 | 2012-03-02 21:02:12 +0100 | [diff] [blame] | 187 | extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int); |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 188 | void io_u_mark_complete(struct thread_data *, unsigned int); |
| 189 | void io_u_mark_submit(struct thread_data *, unsigned int); |
| 190 | |
Jens Axboe | 0a28ecd | 2010-03-09 21:40:38 +0100 | [diff] [blame] | 191 | int do_io_u_sync(struct thread_data *, struct io_u *); |
Jens Axboe | a5f3027 | 2010-07-19 16:19:55 -0600 | [diff] [blame] | 192 | int do_io_u_trim(struct thread_data *, struct io_u *); |
Jens Axboe | 44f2969 | 2010-03-09 20:09:44 +0100 | [diff] [blame] | 193 | |
Jens Axboe | c592b9f | 2009-06-03 09:29:28 +0200 | [diff] [blame] | 194 | #ifdef FIO_INC_DEBUG |
| 195 | static inline void dprint_io_u(struct io_u *io_u, const char *p) |
| 196 | { |
| 197 | struct fio_file *f = io_u->file; |
| 198 | |
| 199 | dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u, |
| 200 | (unsigned long long) io_u->offset, |
| 201 | io_u->buflen, io_u->ddir); |
| 202 | if (fio_debug & (1 << FD_IO)) { |
| 203 | if (f) |
| 204 | log_info("/%s", f->file_name); |
| 205 | |
| 206 | log_info("\n"); |
| 207 | } |
| 208 | } |
| 209 | #else |
| 210 | #define dprint_io_u(io_u, p) |
| 211 | #endif |
| 212 | |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 213 | #endif |