Fix ramp time for io_submit_mode=offload
[fio.git] / ioengine.h
CommitLineData
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"
88271841 10#include "workqueue.h"
ec41265e 11
67bf9823
JA
12#ifdef CONFIG_LIBAIO
13#include <libaio.h>
14#endif
15#ifdef CONFIG_GUASI
16#include <guasi.h>
17#endif
18
5ad7be56 19#define FIO_IOOPS_VERSION 22
dcefb588
JA
20
21enum {
0c41214f
RR
22 IO_U_F_FREE = 1 << 0,
23 IO_U_F_FLIGHT = 1 << 1,
f8b0bd10 24 IO_U_F_NO_FILE_PUT = 1 << 2,
0c41214f 25 IO_U_F_IN_CUR_DEPTH = 1 << 3,
38dad62d 26 IO_U_F_BUSY_OK = 1 << 4,
0d29de83 27 IO_U_F_TRIMMED = 1 << 5,
1ef2b6be 28 IO_U_F_BARRIER = 1 << 6,
82af2a7c 29 IO_U_F_VER_LIST = 1 << 7,
dcefb588
JA
30};
31
32/*
33 * The io unit
34 */
35struct io_u {
dcefb588
JA
36 struct timeval start_time;
37 struct timeval issue_time;
38
d72be545
JA
39 struct fio_file *file;
40 unsigned int flags;
41 enum fio_ddir ddir;
42
bcd5abfa
JA
43 /*
44 * For replay workloads, we may want to account as a different
45 * IO type than what is being submitted.
46 */
47 enum fio_ddir acct_ddir;
48
d8f1f7d4
JA
49 /*
50 * Write generation
51 */
52 unsigned short numberio;
53
dcefb588
JA
54 /*
55 * Allocated/set buffer and length
56 */
dcefb588
JA
57 unsigned long buflen;
58 unsigned long long offset;
d72be545 59 void *buf;
dcefb588 60
7d9fb455
JA
61 /*
62 * Initial seed for generating the buffer contents
63 */
363cffa7 64 uint64_t rand_seed;
7d9fb455 65
dcefb588
JA
66 /*
67 * IO engine state, may be different from above when we get
68 * partial transfers / residual data counts
69 */
70 void *xfer_buf;
71 unsigned long xfer_buflen;
72
95228507
JA
73 /*
74 * Parameter related to pre-filled buffers and
75 * their size to handle variable block sizes.
76 */
77 unsigned long buf_filled_len;
78
f9401285
JA
79 struct io_piece *ipo;
80
225ba9e3
JA
81 unsigned int resid;
82 unsigned int error;
83
84 /*
85 * io engine private data
86 */
87 union {
88 unsigned int index;
89 unsigned int seen;
90 void *engine_data;
91 };
92
88271841
JA
93 union {
94 struct flist_head verify_list;
95 struct workqueue_work work;
96 };
225ba9e3
JA
97
98 /*
99 * Callback for io completion
100 */
f8b0bd10 101 int (*end_io)(struct thread_data *, struct io_u **);
225ba9e3 102
2ae0b204
JA
103 union {
104#ifdef CONFIG_LIBAIO
105 struct iocb iocb;
106#endif
107#ifdef CONFIG_POSIXAIO
108 os_aiocb_t aiocb;
109#endif
110#ifdef FIO_HAVE_SGIO
111 struct sg_io_hdr hdr;
112#endif
113#ifdef CONFIG_GUASI
114 guasi_req_t greq;
115#endif
116#ifdef CONFIG_SOLARISAIO
117 aio_result_t resultp;
118#endif
119#ifdef FIO_HAVE_BINJECT
120 struct b_user_cmd buc;
121#endif
122#ifdef CONFIG_RDMA
123 struct ibv_mr *mr;
124#endif
125 void *mmap_data;
a9da8ab2 126 uint64_t null;
2ae0b204 127 };
dcefb588
JA
128};
129
130/*
131 * io_ops->queue() return values
132 */
133enum {
134 FIO_Q_COMPLETED = 0, /* completed sync */
135 FIO_Q_QUEUED = 1, /* queued, will complete async */
136 FIO_Q_BUSY = 2, /* no more room, call ->commit() */
137};
138
139struct ioengine_ops {
140 struct flist_head list;
141 char name[16];
142 int version;
143 int flags;
144 int (*setup)(struct thread_data *);
145 int (*init)(struct thread_data *);
146 int (*prep)(struct thread_data *, struct io_u *);
147 int (*queue)(struct thread_data *, struct io_u *);
148 int (*commit)(struct thread_data *);
1f440ece 149 int (*getevents)(struct thread_data *, unsigned int, unsigned int, const struct timespec *);
dcefb588 150 struct io_u *(*event)(struct thread_data *, int);
5ad7be56 151 char *(*errdetails)(struct io_u *);
dcefb588
JA
152 int (*cancel)(struct thread_data *, struct io_u *);
153 void (*cleanup)(struct thread_data *);
154 int (*open_file)(struct thread_data *, struct fio_file *);
155 int (*close_file)(struct thread_data *, struct fio_file *);
d9b100fc 156 int (*invalidate)(struct thread_data *, struct fio_file *);
38ef9c90 157 int (*unlink_file)(struct thread_data *, struct fio_file *);
dcefb588 158 int (*get_file_size)(struct thread_data *, struct fio_file *);
36d80bc7 159 void (*terminate)(struct thread_data *);
c73ed246
JA
160 int (*io_u_init)(struct thread_data *, struct io_u *);
161 void (*io_u_free)(struct thread_data *, struct io_u *);
de890a1e
SL
162 int option_struct_size;
163 struct fio_option *options;
dcefb588
JA
164 void *data;
165 void *dlhandle;
166};
167
2b4f4abe
JA
168enum fio_ioengine_flags {
169 FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */
170 FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */
171 FIO_DISKLESSIO = 1 << 2, /* no disk involved */
172 FIO_NOEXTEND = 1 << 3, /* engine can't extend file */
93bcfd20 173 FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */
2b4f4abe
JA
174 FIO_UNIDIR = 1 << 5, /* engine is uni-directional */
175 FIO_NOIO = 1 << 6, /* thread does only pseudo IO */
36d80bc7
JA
176 FIO_PIPEIO = 1 << 7, /* input/output no seekable */
177 FIO_BARRIER = 1 << 8, /* engine supports barriers */
178 FIO_MEMALIGN = 1 << 9, /* engine wants aligned memory */
ad705bcb 179 FIO_BIT_BASED = 1 << 10, /* engine uses a bit base (e.g. uses Kbit as opposed to KB) */
5c57c084 180 FIO_FAKEIO = 1 << 11, /* engine pretends to do IO */
2b4f4abe 181};
dcefb588 182
a8075704
DG
183/*
184 * External engine defined symbol to fill in the engine ops structure
185 */
186typedef void (*get_ioengine_t)(struct ioengine_ops **);
187
dcefb588
JA
188/*
189 * io engine entry points
190 */
191extern int __must_check td_io_init(struct thread_data *);
192extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
193extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
194extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
1f440ece 195extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, const struct timespec *);
dcefb588
JA
196extern int __must_check td_io_commit(struct thread_data *);
197extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
198extern int td_io_close_file(struct thread_data *, struct fio_file *);
38ef9c90 199extern int td_io_unlink_file(struct thread_data *, struct fio_file *);
dcefb588
JA
200extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
201
202extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
203extern void register_ioengine(struct ioengine_ops *);
204extern void unregister_ioengine(struct ioengine_ops *);
de890a1e 205extern void free_ioengine(struct thread_data *);
dcefb588
JA
206extern void close_ioengine(struct thread_data *);
207
de890a1e
SL
208extern int fio_show_ioengine_help(const char *engine);
209
dcefb588
JA
210/*
211 * io unit handling
212 */
dcefb588
JA
213extern struct io_u *__get_io_u(struct thread_data *);
214extern struct io_u *get_io_u(struct thread_data *);
215extern void put_io_u(struct thread_data *, struct io_u *);
f2bba182 216extern void clear_io_u(struct thread_data *, struct io_u *);
dcefb588 217extern void requeue_io_u(struct thread_data *, struct io_u **);
55312f9f
JA
218extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *);
219extern int __must_check io_u_queued_complete(struct thread_data *, int);
dcefb588 220extern void io_u_queued(struct thread_data *, struct io_u *);
0d593542 221extern int io_u_quiesce(struct thread_data *);
dcefb588
JA
222extern void io_u_log_error(struct thread_data *, struct io_u *);
223extern void io_u_mark_depth(struct thread_data *, unsigned int);
cc86c395 224extern void fill_io_buffer(struct thread_data *, void *, unsigned int, unsigned int);
9c42684e 225extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
dcefb588
JA
226void io_u_mark_complete(struct thread_data *, unsigned int);
227void io_u_mark_submit(struct thread_data *, unsigned int);
e39c0676 228bool queue_full(const struct thread_data *);
dcefb588 229
effd6ff0
JA
230int do_io_u_sync(const struct thread_data *, struct io_u *);
231int do_io_u_trim(const struct thread_data *, struct io_u *);
44f29692 232
c592b9fe
JA
233#ifdef FIO_INC_DEBUG
234static inline void dprint_io_u(struct io_u *io_u, const char *p)
235{
236 struct fio_file *f = io_u->file;
237
238 dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
239 (unsigned long long) io_u->offset,
240 io_u->buflen, io_u->ddir);
241 if (fio_debug & (1 << FD_IO)) {
242 if (f)
243 log_info("/%s", f->file_name);
244
245 log_info("\n");
246 }
247}
248#else
249#define dprint_io_u(io_u, p)
250#endif
251
bcd5abfa
JA
252static inline enum fio_ddir acct_ddir(struct io_u *io_u)
253{
254 if (io_u->acct_ddir != -1)
255 return io_u->acct_ddir;
256
257 return io_u->ddir;
258}
259
a9da8ab2
JA
260static inline void io_u_clear(struct io_u *io_u, unsigned int flags)
261{
262 __sync_fetch_and_and(&io_u->flags, ~flags);
263}
264
265static inline void io_u_set(struct io_u *io_u, unsigned int flags)
266{
267 __sync_fetch_and_or(&io_u->flags, flags);
268}
269
dcefb588 270#endif