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