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" |
Jens Axboe | 836fcc0 | 2013-01-24 09:08:45 -0700 | [diff] [blame] | 5 | #include "os/os.h" |
| 6 | #include "log.h" |
Jens Axboe | 4166658 | 2012-03-21 10:25:29 +0100 | [diff] [blame] | 7 | #include "io_ddir.h" |
Jens Axboe | ec41265 | 2012-03-08 12:37:31 +0100 | [diff] [blame] | 8 | #include "debug.h" |
Jens Axboe | 4166658 | 2012-03-21 10:25:29 +0100 | [diff] [blame] | 9 | #include "file.h" |
Jens Axboe | ec41265 | 2012-03-08 12:37:31 +0100 | [diff] [blame] | 10 | |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 11 | #ifdef CONFIG_LIBAIO |
| 12 | #include <libaio.h> |
| 13 | #endif |
| 14 | #ifdef CONFIG_GUASI |
| 15 | #include <guasi.h> |
| 16 | #endif |
| 17 | |
Jens Axboe | 5678538 | 2014-02-27 16:10:43 -0800 | [diff] [blame] | 18 | #define FIO_IOOPS_VERSION 18 |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 19 | |
| 20 | enum { |
Radha Ramachandran | 0c41214 | 2009-11-03 21:45:31 +0100 | [diff] [blame] | 21 | IO_U_F_FREE = 1 << 0, |
| 22 | IO_U_F_FLIGHT = 1 << 1, |
| 23 | IO_U_F_FREE_DEF = 1 << 2, |
| 24 | IO_U_F_IN_CUR_DEPTH = 1 << 3, |
Jens Axboe | 38dad62 | 2010-07-20 14:46:00 -0600 | [diff] [blame] | 25 | IO_U_F_BUSY_OK = 1 << 4, |
Jens Axboe | 0d29de8 | 2010-09-01 13:54:15 +0200 | [diff] [blame] | 26 | IO_U_F_TRIMMED = 1 << 5, |
Jens Axboe | 1ef2b6b | 2010-10-08 15:07:01 +0200 | [diff] [blame] | 27 | IO_U_F_BARRIER = 1 << 6, |
Jens Axboe | 82af2a7 | 2012-03-13 13:45:58 +0100 | [diff] [blame] | 28 | IO_U_F_VER_LIST = 1 << 7, |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | /* |
| 32 | * The io unit |
| 33 | */ |
| 34 | struct io_u { |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 35 | struct timeval start_time; |
| 36 | struct timeval issue_time; |
| 37 | |
Jens Axboe | d72be54 | 2012-11-30 19:37:46 +0100 | [diff] [blame] | 38 | struct fio_file *file; |
| 39 | unsigned int flags; |
| 40 | enum fio_ddir ddir; |
| 41 | |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 42 | /* |
Jens Axboe | bcd5abf | 2013-01-23 09:27:25 -0700 | [diff] [blame] | 43 | * For replay workloads, we may want to account as a different |
| 44 | * IO type than what is being submitted. |
| 45 | */ |
| 46 | enum fio_ddir acct_ddir; |
| 47 | |
| 48 | /* |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 49 | * Allocated/set buffer and length |
| 50 | */ |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 51 | unsigned long buflen; |
| 52 | unsigned long long offset; |
Juan Casse | da0a7bd | 2013-09-17 14:06:12 -0700 | [diff] [blame] | 53 | unsigned short numberio; |
Jens Axboe | d72be54 | 2012-11-30 19:37:46 +0100 | [diff] [blame] | 54 | void *buf; |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 55 | |
| 56 | /* |
Jens Axboe | 7d9fb45 | 2011-01-11 22:16:49 +0100 | [diff] [blame] | 57 | * Initial seed for generating the buffer contents |
| 58 | */ |
Grant Grundler | 363cffa | 2014-01-28 15:11:23 -0700 | [diff] [blame] | 59 | uint64_t rand_seed; |
Jens Axboe | 7d9fb45 | 2011-01-11 22:16:49 +0100 | [diff] [blame] | 60 | |
| 61 | /* |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 62 | * IO engine state, may be different from above when we get |
| 63 | * partial transfers / residual data counts |
| 64 | */ |
| 65 | void *xfer_buf; |
| 66 | unsigned long xfer_buflen; |
| 67 | |
Jens Axboe | 9522850 | 2010-07-14 08:42:03 +0200 | [diff] [blame] | 68 | /* |
| 69 | * Parameter related to pre-filled buffers and |
| 70 | * their size to handle variable block sizes. |
| 71 | */ |
| 72 | unsigned long buf_filled_len; |
| 73 | |
Jens Axboe | f940128 | 2014-02-06 12:17:37 -0700 | [diff] [blame] | 74 | struct io_piece *ipo; |
| 75 | |
Jens Axboe | 225ba9e | 2014-02-26 14:31:15 -0800 | [diff] [blame] | 76 | unsigned int resid; |
| 77 | unsigned int error; |
| 78 | |
| 79 | /* |
| 80 | * io engine private data |
| 81 | */ |
| 82 | union { |
| 83 | unsigned int index; |
| 84 | unsigned int seen; |
| 85 | void *engine_data; |
| 86 | }; |
| 87 | |
| 88 | struct flist_head verify_list; |
| 89 | |
| 90 | /* |
| 91 | * Callback for io completion |
| 92 | */ |
| 93 | int (*end_io)(struct thread_data *, struct io_u *); |
| 94 | |
Jens Axboe | 2ae0b20 | 2013-05-28 14:16:55 +0200 | [diff] [blame] | 95 | union { |
| 96 | #ifdef CONFIG_LIBAIO |
| 97 | struct iocb iocb; |
| 98 | #endif |
| 99 | #ifdef CONFIG_POSIXAIO |
| 100 | os_aiocb_t aiocb; |
| 101 | #endif |
| 102 | #ifdef FIO_HAVE_SGIO |
| 103 | struct sg_io_hdr hdr; |
| 104 | #endif |
| 105 | #ifdef CONFIG_GUASI |
| 106 | guasi_req_t greq; |
| 107 | #endif |
| 108 | #ifdef CONFIG_SOLARISAIO |
| 109 | aio_result_t resultp; |
| 110 | #endif |
| 111 | #ifdef FIO_HAVE_BINJECT |
| 112 | struct b_user_cmd buc; |
| 113 | #endif |
| 114 | #ifdef CONFIG_RDMA |
| 115 | struct ibv_mr *mr; |
| 116 | #endif |
| 117 | void *mmap_data; |
| 118 | }; |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | /* |
| 122 | * io_ops->queue() return values |
| 123 | */ |
| 124 | enum { |
| 125 | FIO_Q_COMPLETED = 0, /* completed sync */ |
| 126 | FIO_Q_QUEUED = 1, /* queued, will complete async */ |
| 127 | FIO_Q_BUSY = 2, /* no more room, call ->commit() */ |
| 128 | }; |
| 129 | |
| 130 | struct ioengine_ops { |
| 131 | struct flist_head list; |
| 132 | char name[16]; |
| 133 | int version; |
| 134 | int flags; |
| 135 | int (*setup)(struct thread_data *); |
| 136 | int (*init)(struct thread_data *); |
| 137 | int (*prep)(struct thread_data *, struct io_u *); |
| 138 | int (*queue)(struct thread_data *, struct io_u *); |
| 139 | int (*commit)(struct thread_data *); |
| 140 | int (*getevents)(struct thread_data *, unsigned int, unsigned int, struct timespec *); |
| 141 | struct io_u *(*event)(struct thread_data *, int); |
| 142 | int (*cancel)(struct thread_data *, struct io_u *); |
| 143 | void (*cleanup)(struct thread_data *); |
| 144 | int (*open_file)(struct thread_data *, struct fio_file *); |
| 145 | int (*close_file)(struct thread_data *, struct fio_file *); |
| 146 | int (*get_file_size)(struct thread_data *, struct fio_file *); |
Jens Axboe | 36d80bc | 2012-11-30 21:46:06 +0100 | [diff] [blame] | 147 | void (*terminate)(struct thread_data *); |
Jens Axboe | c73ed24 | 2012-12-06 20:30:38 +0100 | [diff] [blame] | 148 | int (*io_u_init)(struct thread_data *, struct io_u *); |
| 149 | void (*io_u_free)(struct thread_data *, struct io_u *); |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 150 | int option_struct_size; |
| 151 | struct fio_option *options; |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 152 | void *data; |
| 153 | void *dlhandle; |
| 154 | }; |
| 155 | |
Jens Axboe | 2b4f4ab | 2009-06-03 08:50:36 +0200 | [diff] [blame] | 156 | enum fio_ioengine_flags { |
| 157 | FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */ |
| 158 | FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */ |
| 159 | FIO_DISKLESSIO = 1 << 2, /* no disk involved */ |
| 160 | FIO_NOEXTEND = 1 << 3, /* engine can't extend file */ |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 161 | FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */ |
Jens Axboe | 2b4f4ab | 2009-06-03 08:50:36 +0200 | [diff] [blame] | 162 | FIO_UNIDIR = 1 << 5, /* engine is uni-directional */ |
| 163 | FIO_NOIO = 1 << 6, /* thread does only pseudo IO */ |
Jens Axboe | 36d80bc | 2012-11-30 21:46:06 +0100 | [diff] [blame] | 164 | FIO_PIPEIO = 1 << 7, /* input/output no seekable */ |
| 165 | FIO_BARRIER = 1 << 8, /* engine supports barriers */ |
| 166 | FIO_MEMALIGN = 1 << 9, /* engine wants aligned memory */ |
Steven Noonan | ad705bc | 2013-04-08 15:05:25 -0700 | [diff] [blame] | 167 | FIO_BIT_BASED = 1 << 10, /* engine uses a bit base (e.g. uses Kbit as opposed to KB) */ |
Jens Axboe | 2b4f4ab | 2009-06-03 08:50:36 +0200 | [diff] [blame] | 168 | }; |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 169 | |
| 170 | /* |
Daniel Gollub | a807570 | 2014-02-12 21:23:31 -0700 | [diff] [blame] | 171 | * External engine defined symbol to fill in the engine ops structure |
| 172 | */ |
| 173 | typedef void (*get_ioengine_t)(struct ioengine_ops **); |
| 174 | |
| 175 | /* |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 176 | * io engine entry points |
| 177 | */ |
| 178 | extern int __must_check td_io_init(struct thread_data *); |
| 179 | extern int __must_check td_io_prep(struct thread_data *, struct io_u *); |
| 180 | extern int __must_check td_io_queue(struct thread_data *, struct io_u *); |
| 181 | extern int __must_check td_io_sync(struct thread_data *, struct fio_file *); |
| 182 | extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *); |
| 183 | extern int __must_check td_io_commit(struct thread_data *); |
| 184 | extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *); |
| 185 | extern int td_io_close_file(struct thread_data *, struct fio_file *); |
| 186 | extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *); |
| 187 | |
| 188 | extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *); |
| 189 | extern void register_ioengine(struct ioengine_ops *); |
| 190 | extern void unregister_ioengine(struct ioengine_ops *); |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 191 | extern void free_ioengine(struct thread_data *); |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 192 | extern void close_ioengine(struct thread_data *); |
| 193 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 194 | extern int fio_show_ioengine_help(const char *engine); |
| 195 | |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 196 | /* |
| 197 | * io unit handling |
| 198 | */ |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 199 | extern struct io_u *__get_io_u(struct thread_data *); |
| 200 | extern struct io_u *get_io_u(struct thread_data *); |
| 201 | extern void put_io_u(struct thread_data *, struct io_u *); |
Radha Ramachandran | f2bba18 | 2009-06-15 08:40:16 +0200 | [diff] [blame] | 202 | extern void clear_io_u(struct thread_data *, struct io_u *); |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 203 | extern void requeue_io_u(struct thread_data *, struct io_u **); |
Jens Axboe | 100f49f | 2013-01-23 10:15:57 -0700 | [diff] [blame] | 204 | extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, uint64_t *); |
| 205 | extern int __must_check io_u_queued_complete(struct thread_data *, int, uint64_t *); |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 206 | extern void io_u_queued(struct thread_data *, struct io_u *); |
Jens Axboe | 002e718 | 2013-05-17 12:39:53 +0200 | [diff] [blame] | 207 | extern void io_u_quiesce(struct thread_data *); |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 208 | extern void io_u_log_error(struct thread_data *, struct io_u *); |
| 209 | extern void io_u_mark_depth(struct thread_data *, unsigned int); |
Jens Axboe | cc86c39 | 2013-05-03 15:12:33 +0200 | [diff] [blame] | 210 | extern void fill_io_buffer(struct thread_data *, void *, unsigned int, unsigned int); |
Jens Axboe | 9c42684 | 2012-03-02 21:02:12 +0100 | [diff] [blame] | 211 | 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] | 212 | void io_u_mark_complete(struct thread_data *, unsigned int); |
| 213 | void io_u_mark_submit(struct thread_data *, unsigned int); |
Jens Axboe | 3e260a4 | 2013-12-09 12:38:53 -0700 | [diff] [blame] | 214 | int queue_full(struct thread_data *); |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 215 | |
Jens Axboe | 0a28ecd | 2010-03-09 21:40:38 +0100 | [diff] [blame] | 216 | int do_io_u_sync(struct thread_data *, struct io_u *); |
Jens Axboe | a5f3027 | 2010-07-19 16:19:55 -0600 | [diff] [blame] | 217 | int do_io_u_trim(struct thread_data *, struct io_u *); |
Jens Axboe | 44f2969 | 2010-03-09 20:09:44 +0100 | [diff] [blame] | 218 | |
Jens Axboe | c592b9f | 2009-06-03 09:29:28 +0200 | [diff] [blame] | 219 | #ifdef FIO_INC_DEBUG |
| 220 | static inline void dprint_io_u(struct io_u *io_u, const char *p) |
| 221 | { |
| 222 | struct fio_file *f = io_u->file; |
| 223 | |
| 224 | dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u, |
| 225 | (unsigned long long) io_u->offset, |
| 226 | io_u->buflen, io_u->ddir); |
| 227 | if (fio_debug & (1 << FD_IO)) { |
| 228 | if (f) |
| 229 | log_info("/%s", f->file_name); |
| 230 | |
| 231 | log_info("\n"); |
| 232 | } |
| 233 | } |
| 234 | #else |
| 235 | #define dprint_io_u(io_u, p) |
| 236 | #endif |
| 237 | |
Jens Axboe | bcd5abf | 2013-01-23 09:27:25 -0700 | [diff] [blame] | 238 | static inline enum fio_ddir acct_ddir(struct io_u *io_u) |
| 239 | { |
| 240 | if (io_u->acct_ddir != -1) |
| 241 | return io_u->acct_ddir; |
| 242 | |
| 243 | return io_u->ddir; |
| 244 | } |
| 245 | |
Jens Axboe | dcefb58 | 2009-06-03 08:49:39 +0200 | [diff] [blame] | 246 | #endif |