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