Commit | Line | Data |
---|---|---|
dcefb588 JA |
1 | #ifndef FIO_IOENGINE_H |
2 | #define FIO_IOENGINE_H | |
3 | ||
41666588 JA |
4 | #include "compiler/compiler.h" |
5 | #include "io_ddir.h" | |
ec41265e | 6 | #include "debug.h" |
41666588 | 7 | #include "file.h" |
ec41265e | 8 | |
36d80bc7 | 9 | #define FIO_IOOPS_VERSION 14 |
dcefb588 JA |
10 | |
11 | enum { | |
0c41214f RR |
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, | |
38dad62d | 16 | IO_U_F_BUSY_OK = 1 << 4, |
0d29de83 | 17 | IO_U_F_TRIMMED = 1 << 5, |
1ef2b6be | 18 | IO_U_F_BARRIER = 1 << 6, |
82af2a7c | 19 | IO_U_F_VER_LIST = 1 << 7, |
dcefb588 JA |
20 | }; |
21 | ||
41666588 JA |
22 | struct thread_data; |
23 | ||
dcefb588 JA |
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 | |
e97c1442 | 33 | os_aiocb_t aiocb; |
dcefb588 JA |
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; | |
79a43187 JA |
43 | #endif |
44 | #ifdef FIO_HAVE_BINJECT | |
45 | struct b_user_cmd buc; | |
21b8aee8 | 46 | #endif |
47 | #ifdef FIO_HAVE_RDMA | |
48 | struct ibv_mr *mr; | |
dcefb588 JA |
49 | #endif |
50 | void *mmap_data; | |
51 | }; | |
52 | struct timeval start_time; | |
53 | struct timeval issue_time; | |
54 | ||
d72be545 JA |
55 | struct fio_file *file; |
56 | unsigned int flags; | |
57 | enum fio_ddir ddir; | |
58 | ||
dcefb588 JA |
59 | /* |
60 | * Allocated/set buffer and length | |
61 | */ | |
dcefb588 JA |
62 | unsigned long buflen; |
63 | unsigned long long offset; | |
d72be545 | 64 | void *buf; |
dcefb588 | 65 | |
7d9fb455 JA |
66 | /* |
67 | * Initial seed for generating the buffer contents | |
68 | */ | |
69 | unsigned long rand_seed; | |
70 | ||
dcefb588 JA |
71 | /* |
72 | * IO engine state, may be different from above when we get | |
73 | * partial transfers / residual data counts | |
74 | */ | |
75 | void *xfer_buf; | |
76 | unsigned long xfer_buflen; | |
77 | ||
95228507 JA |
78 | /* |
79 | * Parameter related to pre-filled buffers and | |
80 | * their size to handle variable block sizes. | |
81 | */ | |
82 | unsigned long buf_filled_len; | |
83 | ||
dcefb588 JA |
84 | unsigned int resid; |
85 | unsigned int error; | |
86 | ||
dcefb588 JA |
87 | /* |
88 | * io engine private data | |
89 | */ | |
90 | union { | |
91 | unsigned int index; | |
92 | unsigned int seen; | |
93 | void *engine_data; | |
94 | }; | |
95 | ||
dcefb588 JA |
96 | struct flist_head list; |
97 | ||
98 | /* | |
99 | * Callback for io completion | |
100 | */ | |
101 | int (*end_io)(struct thread_data *, struct io_u *); | |
102 | }; | |
103 | ||
104 | /* | |
105 | * io_ops->queue() return values | |
106 | */ | |
107 | enum { | |
108 | FIO_Q_COMPLETED = 0, /* completed sync */ | |
109 | FIO_Q_QUEUED = 1, /* queued, will complete async */ | |
110 | FIO_Q_BUSY = 2, /* no more room, call ->commit() */ | |
111 | }; | |
112 | ||
113 | struct ioengine_ops { | |
114 | struct flist_head list; | |
115 | char name[16]; | |
116 | int version; | |
117 | int flags; | |
118 | int (*setup)(struct thread_data *); | |
119 | int (*init)(struct thread_data *); | |
120 | int (*prep)(struct thread_data *, struct io_u *); | |
121 | int (*queue)(struct thread_data *, struct io_u *); | |
122 | int (*commit)(struct thread_data *); | |
123 | int (*getevents)(struct thread_data *, unsigned int, unsigned int, struct timespec *); | |
124 | struct io_u *(*event)(struct thread_data *, int); | |
125 | int (*cancel)(struct thread_data *, struct io_u *); | |
126 | void (*cleanup)(struct thread_data *); | |
127 | int (*open_file)(struct thread_data *, struct fio_file *); | |
128 | int (*close_file)(struct thread_data *, struct fio_file *); | |
129 | int (*get_file_size)(struct thread_data *, struct fio_file *); | |
36d80bc7 | 130 | void (*terminate)(struct thread_data *); |
de890a1e SL |
131 | int option_struct_size; |
132 | struct fio_option *options; | |
dcefb588 JA |
133 | void *data; |
134 | void *dlhandle; | |
135 | }; | |
136 | ||
2b4f4abe JA |
137 | enum fio_ioengine_flags { |
138 | FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */ | |
139 | FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */ | |
140 | FIO_DISKLESSIO = 1 << 2, /* no disk involved */ | |
141 | FIO_NOEXTEND = 1 << 3, /* engine can't extend file */ | |
93bcfd20 | 142 | FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */ |
2b4f4abe JA |
143 | FIO_UNIDIR = 1 << 5, /* engine is uni-directional */ |
144 | FIO_NOIO = 1 << 6, /* thread does only pseudo IO */ | |
36d80bc7 JA |
145 | FIO_PIPEIO = 1 << 7, /* input/output no seekable */ |
146 | FIO_BARRIER = 1 << 8, /* engine supports barriers */ | |
147 | FIO_MEMALIGN = 1 << 9, /* engine wants aligned memory */ | |
2b4f4abe | 148 | }; |
dcefb588 JA |
149 | |
150 | /* | |
151 | * io engine entry points | |
152 | */ | |
153 | extern int __must_check td_io_init(struct thread_data *); | |
154 | extern int __must_check td_io_prep(struct thread_data *, struct io_u *); | |
155 | extern int __must_check td_io_queue(struct thread_data *, struct io_u *); | |
156 | extern int __must_check td_io_sync(struct thread_data *, struct fio_file *); | |
157 | extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *); | |
158 | extern int __must_check td_io_commit(struct thread_data *); | |
159 | extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *); | |
160 | extern int td_io_close_file(struct thread_data *, struct fio_file *); | |
161 | extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *); | |
162 | ||
163 | extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *); | |
164 | extern void register_ioengine(struct ioengine_ops *); | |
165 | extern void unregister_ioengine(struct ioengine_ops *); | |
de890a1e | 166 | extern void free_ioengine(struct thread_data *); |
dcefb588 JA |
167 | extern void close_ioengine(struct thread_data *); |
168 | ||
de890a1e SL |
169 | extern int fio_show_ioengine_help(const char *engine); |
170 | ||
dcefb588 JA |
171 | /* |
172 | * io unit handling | |
173 | */ | |
174 | #define queue_full(td) flist_empty(&(td)->io_u_freelist) | |
175 | extern struct io_u *__get_io_u(struct thread_data *); | |
176 | extern struct io_u *get_io_u(struct thread_data *); | |
177 | extern void put_io_u(struct thread_data *, struct io_u *); | |
f2bba182 | 178 | extern void clear_io_u(struct thread_data *, struct io_u *); |
dcefb588 | 179 | extern void requeue_io_u(struct thread_data *, struct io_u **); |
581e7141 JA |
180 | extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, unsigned long *); |
181 | extern int __must_check io_u_queued_complete(struct thread_data *, int, unsigned long *); | |
dcefb588 JA |
182 | extern void io_u_queued(struct thread_data *, struct io_u *); |
183 | extern void io_u_log_error(struct thread_data *, struct io_u *); | |
184 | extern void io_u_mark_depth(struct thread_data *, unsigned int); | |
9c42684e | 185 | extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int); |
dcefb588 JA |
186 | void io_u_mark_complete(struct thread_data *, unsigned int); |
187 | void io_u_mark_submit(struct thread_data *, unsigned int); | |
188 | ||
0a28ecda | 189 | int do_io_u_sync(struct thread_data *, struct io_u *); |
a5f3027c | 190 | int do_io_u_trim(struct thread_data *, struct io_u *); |
44f29692 | 191 | |
c592b9fe JA |
192 | #ifdef FIO_INC_DEBUG |
193 | static inline void dprint_io_u(struct io_u *io_u, const char *p) | |
194 | { | |
195 | struct fio_file *f = io_u->file; | |
196 | ||
197 | dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u, | |
198 | (unsigned long long) io_u->offset, | |
199 | io_u->buflen, io_u->ddir); | |
200 | if (fio_debug & (1 << FD_IO)) { | |
201 | if (f) | |
202 | log_info("/%s", f->file_name); | |
203 | ||
204 | log_info("\n"); | |
205 | } | |
206 | } | |
207 | #else | |
208 | #define dprint_io_u(io_u, p) | |
209 | #endif | |
210 | ||
dcefb588 | 211 | #endif |