Commit | Line | Data |
---|---|---|
dcefb588 JA |
1 | #ifndef FIO_IOENGINE_H |
2 | #define FIO_IOENGINE_H | |
3 | ||
41666588 | 4 | #include "compiler/compiler.h" |
836fcc0f JA |
5 | #include "os/os.h" |
6 | #include "log.h" | |
41666588 | 7 | #include "io_ddir.h" |
ec41265e | 8 | #include "debug.h" |
41666588 | 9 | #include "file.h" |
ec41265e | 10 | |
67bf9823 JA |
11 | #ifdef CONFIG_LIBAIO |
12 | #include <libaio.h> | |
13 | #endif | |
14 | #ifdef CONFIG_GUASI | |
15 | #include <guasi.h> | |
16 | #endif | |
17 | ||
d179fe19 | 18 | #define FIO_IOOPS_VERSION 16 |
dcefb588 JA |
19 | |
20 | enum { | |
0c41214f RR |
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, | |
38dad62d | 25 | IO_U_F_BUSY_OK = 1 << 4, |
0d29de83 | 26 | IO_U_F_TRIMMED = 1 << 5, |
1ef2b6be | 27 | IO_U_F_BARRIER = 1 << 6, |
82af2a7c | 28 | IO_U_F_VER_LIST = 1 << 7, |
dcefb588 JA |
29 | }; |
30 | ||
31 | /* | |
32 | * The io unit | |
33 | */ | |
34 | struct io_u { | |
dcefb588 JA |
35 | struct timeval start_time; |
36 | struct timeval issue_time; | |
37 | ||
d72be545 JA |
38 | struct fio_file *file; |
39 | unsigned int flags; | |
40 | enum fio_ddir ddir; | |
41 | ||
bcd5abfa JA |
42 | /* |
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 | ||
dcefb588 JA |
48 | /* |
49 | * Allocated/set buffer and length | |
50 | */ | |
dcefb588 JA |
51 | unsigned long buflen; |
52 | unsigned long long offset; | |
da0a7bd2 | 53 | unsigned short numberio; |
d72be545 | 54 | void *buf; |
dcefb588 | 55 | |
7d9fb455 JA |
56 | /* |
57 | * Initial seed for generating the buffer contents | |
58 | */ | |
363cffa7 | 59 | uint64_t rand_seed; |
7d9fb455 | 60 | |
dcefb588 JA |
61 | /* |
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 | ||
95228507 JA |
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 | ||
2ae0b204 JA |
74 | union { |
75 | #ifdef CONFIG_LIBAIO | |
76 | struct iocb iocb; | |
77 | #endif | |
78 | #ifdef CONFIG_POSIXAIO | |
79 | os_aiocb_t aiocb; | |
80 | #endif | |
81 | #ifdef FIO_HAVE_SGIO | |
82 | struct sg_io_hdr hdr; | |
83 | #endif | |
84 | #ifdef CONFIG_GUASI | |
85 | guasi_req_t greq; | |
86 | #endif | |
87 | #ifdef CONFIG_SOLARISAIO | |
88 | aio_result_t resultp; | |
89 | #endif | |
90 | #ifdef FIO_HAVE_BINJECT | |
91 | struct b_user_cmd buc; | |
92 | #endif | |
93 | #ifdef CONFIG_RDMA | |
94 | struct ibv_mr *mr; | |
95 | #endif | |
96 | void *mmap_data; | |
97 | }; | |
98 | ||
dcefb588 JA |
99 | unsigned int resid; |
100 | unsigned int error; | |
101 | ||
dcefb588 JA |
102 | /* |
103 | * io engine private data | |
104 | */ | |
105 | union { | |
106 | unsigned int index; | |
107 | unsigned int seen; | |
108 | void *engine_data; | |
109 | }; | |
110 | ||
2ae0b204 | 111 | struct flist_head verify_list; |
dcefb588 JA |
112 | |
113 | /* | |
114 | * Callback for io completion | |
115 | */ | |
116 | int (*end_io)(struct thread_data *, struct io_u *); | |
117 | }; | |
118 | ||
119 | /* | |
120 | * io_ops->queue() return values | |
121 | */ | |
122 | enum { | |
123 | FIO_Q_COMPLETED = 0, /* completed sync */ | |
124 | FIO_Q_QUEUED = 1, /* queued, will complete async */ | |
125 | FIO_Q_BUSY = 2, /* no more room, call ->commit() */ | |
126 | }; | |
127 | ||
128 | struct ioengine_ops { | |
129 | struct flist_head list; | |
130 | char name[16]; | |
131 | int version; | |
132 | int flags; | |
133 | int (*setup)(struct thread_data *); | |
134 | int (*init)(struct thread_data *); | |
135 | int (*prep)(struct thread_data *, struct io_u *); | |
136 | int (*queue)(struct thread_data *, struct io_u *); | |
137 | int (*commit)(struct thread_data *); | |
138 | int (*getevents)(struct thread_data *, unsigned int, unsigned int, struct timespec *); | |
139 | struct io_u *(*event)(struct thread_data *, int); | |
140 | int (*cancel)(struct thread_data *, struct io_u *); | |
141 | void (*cleanup)(struct thread_data *); | |
142 | int (*open_file)(struct thread_data *, struct fio_file *); | |
143 | int (*close_file)(struct thread_data *, struct fio_file *); | |
144 | int (*get_file_size)(struct thread_data *, struct fio_file *); | |
36d80bc7 | 145 | void (*terminate)(struct thread_data *); |
c73ed246 JA |
146 | int (*io_u_init)(struct thread_data *, struct io_u *); |
147 | void (*io_u_free)(struct thread_data *, struct io_u *); | |
de890a1e SL |
148 | int option_struct_size; |
149 | struct fio_option *options; | |
dcefb588 JA |
150 | void *data; |
151 | void *dlhandle; | |
152 | }; | |
153 | ||
2b4f4abe JA |
154 | enum fio_ioengine_flags { |
155 | FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */ | |
156 | FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */ | |
157 | FIO_DISKLESSIO = 1 << 2, /* no disk involved */ | |
158 | FIO_NOEXTEND = 1 << 3, /* engine can't extend file */ | |
93bcfd20 | 159 | FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */ |
2b4f4abe JA |
160 | FIO_UNIDIR = 1 << 5, /* engine is uni-directional */ |
161 | FIO_NOIO = 1 << 6, /* thread does only pseudo IO */ | |
36d80bc7 JA |
162 | FIO_PIPEIO = 1 << 7, /* input/output no seekable */ |
163 | FIO_BARRIER = 1 << 8, /* engine supports barriers */ | |
164 | FIO_MEMALIGN = 1 << 9, /* engine wants aligned memory */ | |
ad705bcb | 165 | FIO_BIT_BASED = 1 << 10, /* engine uses a bit base (e.g. uses Kbit as opposed to KB) */ |
2b4f4abe | 166 | }; |
dcefb588 JA |
167 | |
168 | /* | |
169 | * io engine entry points | |
170 | */ | |
171 | extern int __must_check td_io_init(struct thread_data *); | |
172 | extern int __must_check td_io_prep(struct thread_data *, struct io_u *); | |
173 | extern int __must_check td_io_queue(struct thread_data *, struct io_u *); | |
174 | extern int __must_check td_io_sync(struct thread_data *, struct fio_file *); | |
175 | extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *); | |
176 | extern int __must_check td_io_commit(struct thread_data *); | |
177 | extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *); | |
178 | extern int td_io_close_file(struct thread_data *, struct fio_file *); | |
179 | extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *); | |
180 | ||
181 | extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *); | |
182 | extern void register_ioengine(struct ioengine_ops *); | |
183 | extern void unregister_ioengine(struct ioengine_ops *); | |
de890a1e | 184 | extern void free_ioengine(struct thread_data *); |
dcefb588 JA |
185 | extern void close_ioengine(struct thread_data *); |
186 | ||
de890a1e SL |
187 | extern int fio_show_ioengine_help(const char *engine); |
188 | ||
dcefb588 JA |
189 | /* |
190 | * io unit handling | |
191 | */ | |
dcefb588 JA |
192 | extern struct io_u *__get_io_u(struct thread_data *); |
193 | extern struct io_u *get_io_u(struct thread_data *); | |
194 | extern void put_io_u(struct thread_data *, struct io_u *); | |
f2bba182 | 195 | extern void clear_io_u(struct thread_data *, struct io_u *); |
dcefb588 | 196 | extern void requeue_io_u(struct thread_data *, struct io_u **); |
100f49f1 JA |
197 | extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, uint64_t *); |
198 | extern int __must_check io_u_queued_complete(struct thread_data *, int, uint64_t *); | |
dcefb588 | 199 | extern void io_u_queued(struct thread_data *, struct io_u *); |
002e7183 | 200 | extern void io_u_quiesce(struct thread_data *); |
dcefb588 JA |
201 | extern void io_u_log_error(struct thread_data *, struct io_u *); |
202 | extern void io_u_mark_depth(struct thread_data *, unsigned int); | |
cc86c395 | 203 | extern void fill_io_buffer(struct thread_data *, void *, unsigned int, unsigned int); |
9c42684e | 204 | extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int); |
dcefb588 JA |
205 | void io_u_mark_complete(struct thread_data *, unsigned int); |
206 | void io_u_mark_submit(struct thread_data *, unsigned int); | |
3e260a46 | 207 | int queue_full(struct thread_data *); |
dcefb588 | 208 | |
0a28ecda | 209 | int do_io_u_sync(struct thread_data *, struct io_u *); |
a5f3027c | 210 | int do_io_u_trim(struct thread_data *, struct io_u *); |
44f29692 | 211 | |
c592b9fe JA |
212 | #ifdef FIO_INC_DEBUG |
213 | static inline void dprint_io_u(struct io_u *io_u, const char *p) | |
214 | { | |
215 | struct fio_file *f = io_u->file; | |
216 | ||
217 | dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u, | |
218 | (unsigned long long) io_u->offset, | |
219 | io_u->buflen, io_u->ddir); | |
220 | if (fio_debug & (1 << FD_IO)) { | |
221 | if (f) | |
222 | log_info("/%s", f->file_name); | |
223 | ||
224 | log_info("\n"); | |
225 | } | |
226 | } | |
227 | #else | |
228 | #define dprint_io_u(io_u, p) | |
229 | #endif | |
230 | ||
bcd5abfa JA |
231 | static inline enum fio_ddir acct_ddir(struct io_u *io_u) |
232 | { | |
233 | if (io_u->acct_ddir != -1) | |
234 | return io_u->acct_ddir; | |
235 | ||
236 | return io_u->ddir; | |
237 | } | |
238 | ||
dcefb588 | 239 | #endif |