io_u: we don't need to set power_2 to false
[fio.git] / ioengine.h
... / ...
CommitLineData
1#ifndef FIO_IOENGINE_H
2#define FIO_IOENGINE_H
3
4#include "compiler/compiler.h"
5#include "os/os.h"
6#include "log.h"
7#include "io_ddir.h"
8#include "debug.h"
9#include "file.h"
10#include "workqueue.h"
11
12#ifdef CONFIG_LIBAIO
13#include <libaio.h>
14#endif
15#ifdef CONFIG_GUASI
16#include <guasi.h>
17#endif
18
19#define FIO_IOOPS_VERSION 23
20
21enum {
22 IO_U_F_FREE = 1 << 0,
23 IO_U_F_FLIGHT = 1 << 1,
24 IO_U_F_NO_FILE_PUT = 1 << 2,
25 IO_U_F_IN_CUR_DEPTH = 1 << 3,
26 IO_U_F_BUSY_OK = 1 << 4,
27 IO_U_F_TRIMMED = 1 << 5,
28 IO_U_F_BARRIER = 1 << 6,
29 IO_U_F_VER_LIST = 1 << 7,
30};
31
32/*
33 * The io unit
34 */
35struct io_u {
36 struct timeval start_time;
37 struct timeval issue_time;
38
39 struct fio_file *file;
40 unsigned int flags;
41 enum fio_ddir ddir;
42
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
49 /*
50 * Write generation
51 */
52 unsigned short numberio;
53
54 /*
55 * Allocated/set buffer and length
56 */
57 unsigned long buflen;
58 unsigned long long offset;
59 void *buf;
60
61 /*
62 * Initial seed for generating the buffer contents
63 */
64 uint64_t rand_seed;
65
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
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
79 struct io_piece *ipo;
80
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
93 union {
94 struct flist_head verify_list;
95 struct workqueue_work work;
96 };
97
98 /*
99 * Callback for io completion
100 */
101 int (*end_io)(struct thread_data *, struct io_u **);
102
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;
126 };
127};
128
129/*
130 * io_ops->queue() return values
131 */
132enum {
133 FIO_Q_COMPLETED = 0, /* completed sync */
134 FIO_Q_QUEUED = 1, /* queued, will complete async */
135 FIO_Q_BUSY = 2, /* no more room, call ->commit() */
136};
137
138struct ioengine_ops {
139 struct flist_head list;
140 const char *name;
141 int version;
142 int flags;
143 int (*setup)(struct thread_data *);
144 int (*init)(struct thread_data *);
145 int (*prep)(struct thread_data *, struct io_u *);
146 int (*queue)(struct thread_data *, struct io_u *);
147 int (*commit)(struct thread_data *);
148 int (*getevents)(struct thread_data *, unsigned int, unsigned int, const struct timespec *);
149 struct io_u *(*event)(struct thread_data *, int);
150 char *(*errdetails)(struct io_u *);
151 int (*cancel)(struct thread_data *, struct io_u *);
152 void (*cleanup)(struct thread_data *);
153 int (*open_file)(struct thread_data *, struct fio_file *);
154 int (*close_file)(struct thread_data *, struct fio_file *);
155 int (*invalidate)(struct thread_data *, struct fio_file *);
156 int (*unlink_file)(struct thread_data *, struct fio_file *);
157 int (*get_file_size)(struct thread_data *, struct fio_file *);
158 void (*terminate)(struct thread_data *);
159 int (*iomem_alloc)(struct thread_data *, size_t);
160 void (*iomem_free)(struct thread_data *);
161 int (*io_u_init)(struct thread_data *, struct io_u *);
162 void (*io_u_free)(struct thread_data *, struct io_u *);
163 int option_struct_size;
164 struct fio_option *options;
165};
166
167enum fio_ioengine_flags {
168 FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */
169 FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */
170 FIO_DISKLESSIO = 1 << 2, /* no disk involved */
171 FIO_NOEXTEND = 1 << 3, /* engine can't extend file */
172 FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */
173 FIO_UNIDIR = 1 << 5, /* engine is uni-directional */
174 FIO_NOIO = 1 << 6, /* thread does only pseudo IO */
175 FIO_PIPEIO = 1 << 7, /* input/output no seekable */
176 FIO_BARRIER = 1 << 8, /* engine supports barriers */
177 FIO_MEMALIGN = 1 << 9, /* engine wants aligned memory */
178 FIO_BIT_BASED = 1 << 10, /* engine uses a bit base (e.g. uses Kbit as opposed to KB) */
179 FIO_FAKEIO = 1 << 11, /* engine pretends to do IO */
180};
181
182/*
183 * External engine defined symbol to fill in the engine ops structure
184 */
185typedef void (*get_ioengine_t)(struct ioengine_ops **);
186
187/*
188 * io engine entry points
189 */
190extern int __must_check td_io_init(struct thread_data *);
191extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
192extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
193extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
194extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, const struct timespec *);
195extern int __must_check td_io_commit(struct thread_data *);
196extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
197extern int td_io_close_file(struct thread_data *, struct fio_file *);
198extern int td_io_unlink_file(struct thread_data *, struct fio_file *);
199extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
200
201extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
202extern void register_ioengine(struct ioengine_ops *);
203extern void unregister_ioengine(struct ioengine_ops *);
204extern void free_ioengine(struct thread_data *);
205extern void close_ioengine(struct thread_data *);
206
207extern int fio_show_ioengine_help(const char *engine);
208
209/*
210 * io unit handling
211 */
212extern struct io_u *__get_io_u(struct thread_data *);
213extern struct io_u *get_io_u(struct thread_data *);
214extern void put_io_u(struct thread_data *, struct io_u *);
215extern void clear_io_u(struct thread_data *, struct io_u *);
216extern void requeue_io_u(struct thread_data *, struct io_u **);
217extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *);
218extern int __must_check io_u_queued_complete(struct thread_data *, int);
219extern void io_u_queued(struct thread_data *, struct io_u *);
220extern int io_u_quiesce(struct thread_data *);
221extern void io_u_log_error(struct thread_data *, struct io_u *);
222extern void io_u_mark_depth(struct thread_data *, unsigned int);
223extern void fill_io_buffer(struct thread_data *, void *, unsigned int, unsigned int);
224extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
225void io_u_mark_complete(struct thread_data *, unsigned int);
226void io_u_mark_submit(struct thread_data *, unsigned int);
227bool queue_full(const struct thread_data *);
228
229int do_io_u_sync(const struct thread_data *, struct io_u *);
230int do_io_u_trim(const struct thread_data *, struct io_u *);
231
232#ifdef FIO_INC_DEBUG
233static inline void dprint_io_u(struct io_u *io_u, const char *p)
234{
235 struct fio_file *f = io_u->file;
236
237 dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
238 (unsigned long long) io_u->offset,
239 io_u->buflen, io_u->ddir);
240 if (f)
241 dprint(FD_IO, "/%s", f->file_name);
242 dprint(FD_IO, "\n");
243}
244#else
245#define dprint_io_u(io_u, p)
246#endif
247
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
256#define io_u_clear(td, io_u, val) \
257 td_flags_clear((td), &(io_u->flags), (val))
258#define io_u_set(td, io_u, val) \
259 td_flags_set((td), &(io_u)->flags, (val))
260
261#endif