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