Switch mutex to using anonymous mmap
[fio.git] / ioengine.h
1 #ifndef FIO_IOENGINE_H
2 #define FIO_IOENGINE_H
3
4 #define FIO_IOOPS_VERSION       12
5
6 enum {
7         IO_U_F_FREE             = 1 << 0,
8         IO_U_F_FLIGHT           = 1 << 1,
9         IO_U_F_FREE_DEF         = 1 << 2,
10         IO_U_F_IN_CUR_DEPTH     = 1 << 3,
11         IO_U_F_BUSY_OK          = 1 << 4,
12         IO_U_F_TRIMMED          = 1 << 5,
13         IO_U_F_BARRIER          = 1 << 6,
14 };
15
16 /*
17  * The io unit
18  */
19 struct io_u {
20         union {
21 #ifdef FIO_HAVE_LIBAIO
22                 struct iocb iocb;
23 #endif
24 #ifdef FIO_HAVE_POSIXAIO
25                 struct aiocb aiocb;
26 #endif
27 #ifdef FIO_HAVE_SGIO
28                 struct sg_io_hdr hdr;
29 #endif
30 #ifdef FIO_HAVE_GUASI
31                 guasi_req_t greq;
32 #endif
33 #ifdef FIO_HAVE_SOLARISAIO
34                 aio_result_t resultp;
35 #endif
36 #ifdef FIO_HAVE_BINJECT
37                 struct b_user_cmd buc;
38 #endif
39                 void *mmap_data;
40         };
41         struct timeval start_time;
42         struct timeval issue_time;
43
44         /*
45          * Allocated/set buffer and length
46          */
47         void *buf;
48         unsigned long buflen;
49         unsigned long long offset;
50
51         /*
52          * Initial seed for generating the buffer contents
53          */
54         unsigned long rand_seed;
55
56         /*
57          * IO engine state, may be different from above when we get
58          * partial transfers / residual data counts
59          */
60         void *xfer_buf;
61         unsigned long xfer_buflen;
62
63         /*
64          * Parameter related to pre-filled buffers and
65          * their size to handle variable block sizes.
66          */
67         unsigned long buf_filled_len;
68
69         unsigned int resid;
70         unsigned int error;
71
72         enum fio_ddir ddir;
73
74         /*
75          * io engine private data
76          */
77         union {
78                 unsigned int index;
79                 unsigned int seen;
80                 void *engine_data;
81         };
82
83         unsigned int flags;
84
85         struct fio_file *file;
86
87         struct flist_head list;
88
89         /*
90          * Callback for io completion
91          */
92         int (*end_io)(struct thread_data *, struct io_u *);
93 };
94
95 /*
96  * io_ops->queue() return values
97  */
98 enum {
99         FIO_Q_COMPLETED = 0,            /* completed sync */
100         FIO_Q_QUEUED    = 1,            /* queued, will complete async */
101         FIO_Q_BUSY      = 2,            /* no more room, call ->commit() */
102 };
103
104 struct ioengine_ops {
105         struct flist_head list;
106         char name[16];
107         int version;
108         int flags;
109         int (*setup)(struct thread_data *);
110         int (*init)(struct thread_data *);
111         int (*prep)(struct thread_data *, struct io_u *);
112         int (*queue)(struct thread_data *, struct io_u *);
113         int (*commit)(struct thread_data *);
114         int (*getevents)(struct thread_data *, unsigned int, unsigned int, struct timespec *);
115         struct io_u *(*event)(struct thread_data *, int);
116         int (*cancel)(struct thread_data *, struct io_u *);
117         void (*cleanup)(struct thread_data *);
118         int (*open_file)(struct thread_data *, struct fio_file *);
119         int (*close_file)(struct thread_data *, struct fio_file *);
120         int (*get_file_size)(struct thread_data *, struct fio_file *);
121         void *data;
122         void *dlhandle;
123 };
124
125 enum fio_ioengine_flags {
126         FIO_SYNCIO      = 1 << 0,       /* io engine has synchronous ->queue */
127         FIO_RAWIO       = 1 << 1,       /* some sort of direct/raw io */
128         FIO_DISKLESSIO  = 1 << 2,       /* no disk involved */
129         FIO_NOEXTEND    = 1 << 3,       /* engine can't extend file */
130         FIO_NODISKUTIL  = 1 << 4,       /* diskutil can't handle filename */
131         FIO_UNIDIR      = 1 << 5,       /* engine is uni-directional */
132         FIO_NOIO        = 1 << 6,       /* thread does only pseudo IO */
133         FIO_SIGTERM     = 1 << 7,       /* needs SIGTERM to exit */
134         FIO_PIPEIO      = 1 << 8,       /* input/output no seekable */
135         FIO_BARRIER     = 1 << 9,       /* engine supports barriers */
136         FIO_MEMALIGN    = 1 << 10,      /* engine wants aligned memory */
137 };
138
139 /*
140  * io engine entry points
141  */
142 extern int __must_check td_io_init(struct thread_data *);
143 extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
144 extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
145 extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
146 extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *);
147 extern int __must_check td_io_commit(struct thread_data *);
148 extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
149 extern int td_io_close_file(struct thread_data *, struct fio_file *);
150 extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
151
152 extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
153 extern void register_ioengine(struct ioengine_ops *);
154 extern void unregister_ioengine(struct ioengine_ops *);
155 extern void close_ioengine(struct thread_data *);
156
157 /*
158  * io unit handling
159  */
160 #define queue_full(td)  flist_empty(&(td)->io_u_freelist)
161 extern struct io_u *__get_io_u(struct thread_data *);
162 extern struct io_u *get_io_u(struct thread_data *);
163 extern void put_io_u(struct thread_data *, struct io_u *);
164 extern void clear_io_u(struct thread_data *, struct io_u *);
165 extern void requeue_io_u(struct thread_data *, struct io_u **);
166 extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, unsigned long *);
167 extern int __must_check io_u_queued_complete(struct thread_data *, int, unsigned long *);
168 extern void io_u_queued(struct thread_data *, struct io_u *);
169 extern void io_u_log_error(struct thread_data *, struct io_u *);
170 extern void io_u_mark_depth(struct thread_data *, unsigned int);
171 extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int);
172 void io_u_mark_complete(struct thread_data *, unsigned int);
173 void io_u_mark_submit(struct thread_data *, unsigned int);
174
175 int do_io_u_sync(struct thread_data *, struct io_u *);
176 int do_io_u_trim(struct thread_data *, struct io_u *);
177
178 #ifdef FIO_INC_DEBUG
179 static inline void dprint_io_u(struct io_u *io_u, const char *p)
180 {
181         struct fio_file *f = io_u->file;
182
183         dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
184                                         (unsigned long long) io_u->offset,
185                                         io_u->buflen, io_u->ddir);
186         if (fio_debug & (1 << FD_IO)) {
187                 if (f)
188                         log_info("/%s", f->file_name);
189
190                 log_info("\n");
191         }
192 }
193 #else
194 #define dprint_io_u(io_u, p)
195 #endif
196
197 #endif