gfio: add check for unnecessary g_thread_init() call
[fio.git] / ioengine.h
1 #ifndef FIO_IOENGINE_H
2 #define FIO_IOENGINE_H
3
4 #include "compiler/compiler.h"
5 #include "io_ddir.h"
6 #include "debug.h"
7 #include "file.h"
8
9 #define FIO_IOOPS_VERSION       14
10
11 enum {
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,
16         IO_U_F_BUSY_OK          = 1 << 4,
17         IO_U_F_TRIMMED          = 1 << 5,
18         IO_U_F_BARRIER          = 1 << 6,
19         IO_U_F_VER_LIST         = 1 << 7,
20 };
21
22 struct thread_data;
23
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
33                 os_aiocb_t aiocb;
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;
43 #endif
44 #ifdef FIO_HAVE_BINJECT
45                 struct b_user_cmd buc;
46 #endif
47 #ifdef FIO_HAVE_RDMA
48                 struct ibv_mr *mr;
49 #endif
50                 void *mmap_data;
51         };
52         struct timeval start_time;
53         struct timeval issue_time;
54
55         struct fio_file *file;
56         unsigned int flags;
57         enum fio_ddir ddir;
58
59         /*
60          * Allocated/set buffer and length
61          */
62         unsigned long buflen;
63         unsigned long long offset;
64         void *buf;
65
66         /*
67          * Initial seed for generating the buffer contents
68          */
69         unsigned long rand_seed;
70
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
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
84         unsigned int resid;
85         unsigned int error;
86
87         /*
88          * io engine private data
89          */
90         union {
91                 unsigned int index;
92                 unsigned int seen;
93                 void *engine_data;
94         };
95
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 *);
130         void (*terminate)(struct thread_data *);
131         int option_struct_size;
132         struct fio_option *options;
133         void *data;
134         void *dlhandle;
135 };
136
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 */
142         FIO_NODISKUTIL  = 1 << 4,       /* diskutil can't handle filename */
143         FIO_UNIDIR      = 1 << 5,       /* engine is uni-directional */
144         FIO_NOIO        = 1 << 6,       /* thread does only pseudo IO */
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 */
148 };
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 *);
166 extern void free_ioengine(struct thread_data *);
167 extern void close_ioengine(struct thread_data *);
168
169 extern int fio_show_ioengine_help(const char *engine);
170
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 *);
178 extern void clear_io_u(struct thread_data *, struct io_u *);
179 extern void requeue_io_u(struct thread_data *, struct io_u **);
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 *);
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);
185 extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
186 void io_u_mark_complete(struct thread_data *, unsigned int);
187 void io_u_mark_submit(struct thread_data *, unsigned int);
188
189 int do_io_u_sync(struct thread_data *, struct io_u *);
190 int do_io_u_trim(struct thread_data *, struct io_u *);
191
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
211 #endif