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