blob: 85923fcee3fdc1ff2f75be2bdec79048fac00c26 [file] [log] [blame]
Jens Axboedcefb582009-06-03 08:49:39 +02001#ifndef FIO_IOENGINE_H
2#define FIO_IOENGINE_H
3
Jens Axboe41666582012-03-21 10:25:29 +01004#include "compiler/compiler.h"
Jens Axboe836fcc02013-01-24 09:08:45 -07005#include "os/os.h"
6#include "log.h"
Jens Axboe41666582012-03-21 10:25:29 +01007#include "io_ddir.h"
Jens Axboeec412652012-03-08 12:37:31 +01008#include "debug.h"
Jens Axboe41666582012-03-21 10:25:29 +01009#include "file.h"
Jens Axboeec412652012-03-08 12:37:31 +010010
Jens Axboe67bf9822013-01-10 11:23:19 +010011#ifdef CONFIG_LIBAIO
12#include <libaio.h>
13#endif
14#ifdef CONFIG_GUASI
15#include <guasi.h>
16#endif
17
Jens Axboe89c4eb62014-10-01 08:43:58 -060018#define FIO_IOOPS_VERSION 21
Jens Axboedcefb582009-06-03 08:49:39 +020019
20enum {
Radha Ramachandran0c412142009-11-03 21:45:31 +010021 IO_U_F_FREE = 1 << 0,
22 IO_U_F_FLIGHT = 1 << 1,
Jens Axboee69fdf72014-07-23 16:11:43 +020023 IO_U_F_NO_FILE_PUT = 1 << 2,
Radha Ramachandran0c412142009-11-03 21:45:31 +010024 IO_U_F_IN_CUR_DEPTH = 1 << 3,
Jens Axboe38dad622010-07-20 14:46:00 -060025 IO_U_F_BUSY_OK = 1 << 4,
Jens Axboe0d29de82010-09-01 13:54:15 +020026 IO_U_F_TRIMMED = 1 << 5,
Jens Axboe1ef2b6b2010-10-08 15:07:01 +020027 IO_U_F_BARRIER = 1 << 6,
Jens Axboe82af2a72012-03-13 13:45:58 +010028 IO_U_F_VER_LIST = 1 << 7,
Jens Axboedcefb582009-06-03 08:49:39 +020029};
30
31/*
32 * The io unit
33 */
34struct io_u {
Jens Axboedcefb582009-06-03 08:49:39 +020035 struct timeval start_time;
36 struct timeval issue_time;
37
Jens Axboed72be542012-11-30 19:37:46 +010038 struct fio_file *file;
39 unsigned int flags;
40 enum fio_ddir ddir;
41
Jens Axboedcefb582009-06-03 08:49:39 +020042 /*
Jens Axboebcd5abf2013-01-23 09:27:25 -070043 * 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 /*
Jens Axboedcefb582009-06-03 08:49:39 +020049 * Allocated/set buffer and length
50 */
Jens Axboedcefb582009-06-03 08:49:39 +020051 unsigned long buflen;
52 unsigned long long offset;
Juan Casseda0a7bd2013-09-17 14:06:12 -070053 unsigned short numberio;
Jens Axboed72be542012-11-30 19:37:46 +010054 void *buf;
Jens Axboedcefb582009-06-03 08:49:39 +020055
56 /*
Jens Axboe7d9fb452011-01-11 22:16:49 +010057 * Initial seed for generating the buffer contents
58 */
Grant Grundler363cffa2014-01-28 15:11:23 -070059 uint64_t rand_seed;
Jens Axboe7d9fb452011-01-11 22:16:49 +010060
61 /*
Jens Axboedcefb582009-06-03 08:49:39 +020062 * IO engine state, may be different from above when we get
63 * partial transfers / residual data counts
64 */
65 void *xfer_buf;
66 unsigned long xfer_buflen;
67
Jens Axboe95228502010-07-14 08:42:03 +020068 /*
69 * Parameter related to pre-filled buffers and
70 * their size to handle variable block sizes.
71 */
72 unsigned long buf_filled_len;
73
Jens Axboef9401282014-02-06 12:17:37 -070074 struct io_piece *ipo;
75
Jens Axboe225ba9e2014-02-26 14:31:15 -080076 unsigned int resid;
77 unsigned int error;
78
79 /*
80 * io engine private data
81 */
82 union {
83 unsigned int index;
84 unsigned int seen;
85 void *engine_data;
86 };
87
88 struct flist_head verify_list;
89
90 /*
91 * Callback for io completion
92 */
Jens Axboee69fdf72014-07-23 16:11:43 +020093 int (*end_io)(struct thread_data *, struct io_u **);
Jens Axboe225ba9e2014-02-26 14:31:15 -080094
Jens Axboe2ae0b202013-05-28 14:16:55 +020095 union {
96#ifdef CONFIG_LIBAIO
97 struct iocb iocb;
98#endif
99#ifdef CONFIG_POSIXAIO
100 os_aiocb_t aiocb;
101#endif
102#ifdef FIO_HAVE_SGIO
103 struct sg_io_hdr hdr;
104#endif
105#ifdef CONFIG_GUASI
106 guasi_req_t greq;
107#endif
108#ifdef CONFIG_SOLARISAIO
109 aio_result_t resultp;
110#endif
111#ifdef FIO_HAVE_BINJECT
112 struct b_user_cmd buc;
113#endif
114#ifdef CONFIG_RDMA
115 struct ibv_mr *mr;
116#endif
117 void *mmap_data;
118 };
Jens Axboedcefb582009-06-03 08:49:39 +0200119};
120
121/*
122 * io_ops->queue() return values
123 */
124enum {
125 FIO_Q_COMPLETED = 0, /* completed sync */
126 FIO_Q_QUEUED = 1, /* queued, will complete async */
127 FIO_Q_BUSY = 2, /* no more room, call ->commit() */
128};
129
130struct ioengine_ops {
131 struct flist_head list;
132 char name[16];
133 int version;
134 int flags;
135 int (*setup)(struct thread_data *);
136 int (*init)(struct thread_data *);
137 int (*prep)(struct thread_data *, struct io_u *);
138 int (*queue)(struct thread_data *, struct io_u *);
139 int (*commit)(struct thread_data *);
Jens Axboe0cbbc392014-09-30 16:04:12 -0600140 int (*getevents)(struct thread_data *, unsigned int, unsigned int, const struct timespec *);
Jens Axboedcefb582009-06-03 08:49:39 +0200141 struct io_u *(*event)(struct thread_data *, int);
142 int (*cancel)(struct thread_data *, struct io_u *);
143 void (*cleanup)(struct thread_data *);
144 int (*open_file)(struct thread_data *, struct fio_file *);
145 int (*close_file)(struct thread_data *, struct fio_file *);
Jens Axboe1be9f212014-05-19 19:57:05 -0600146 int (*invalidate)(struct thread_data *, struct fio_file *);
Castor Fu9187a262014-08-19 09:28:53 -0700147 int (*unlink_file)(struct thread_data *, struct fio_file *);
Jens Axboedcefb582009-06-03 08:49:39 +0200148 int (*get_file_size)(struct thread_data *, struct fio_file *);
Jens Axboe36d80bc2012-11-30 21:46:06 +0100149 void (*terminate)(struct thread_data *);
Jens Axboec73ed242012-12-06 20:30:38 +0100150 int (*io_u_init)(struct thread_data *, struct io_u *);
151 void (*io_u_free)(struct thread_data *, struct io_u *);
Steven Langde890a12011-11-09 14:03:34 +0100152 int option_struct_size;
153 struct fio_option *options;
Jens Axboedcefb582009-06-03 08:49:39 +0200154 void *data;
155 void *dlhandle;
156};
157
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200158enum fio_ioengine_flags {
159 FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */
160 FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */
161 FIO_DISKLESSIO = 1 << 2, /* no disk involved */
162 FIO_NOEXTEND = 1 << 3, /* engine can't extend file */
Bruce Cran93bcfd22012-02-20 20:18:19 +0100163 FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200164 FIO_UNIDIR = 1 << 5, /* engine is uni-directional */
165 FIO_NOIO = 1 << 6, /* thread does only pseudo IO */
Jens Axboe36d80bc2012-11-30 21:46:06 +0100166 FIO_PIPEIO = 1 << 7, /* input/output no seekable */
167 FIO_BARRIER = 1 << 8, /* engine supports barriers */
168 FIO_MEMALIGN = 1 << 9, /* engine wants aligned memory */
Steven Noonanad705bc2013-04-08 15:05:25 -0700169 FIO_BIT_BASED = 1 << 10, /* engine uses a bit base (e.g. uses Kbit as opposed to KB) */
Jens Axboed9570702014-07-23 16:19:48 +0200170 FIO_FAKEIO = 1 << 11, /* engine pretends to do IO */
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200171};
Jens Axboedcefb582009-06-03 08:49:39 +0200172
173/*
Daniel Golluba8075702014-02-12 21:23:31 -0700174 * External engine defined symbol to fill in the engine ops structure
175 */
176typedef void (*get_ioengine_t)(struct ioengine_ops **);
177
178/*
Jens Axboedcefb582009-06-03 08:49:39 +0200179 * io engine entry points
180 */
181extern int __must_check td_io_init(struct thread_data *);
182extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
183extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
184extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
Jens Axboe0cbbc392014-09-30 16:04:12 -0600185extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, const struct timespec *);
Jens Axboedcefb582009-06-03 08:49:39 +0200186extern int __must_check td_io_commit(struct thread_data *);
187extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
188extern int td_io_close_file(struct thread_data *, struct fio_file *);
Castor Fu9187a262014-08-19 09:28:53 -0700189extern int td_io_unlink_file(struct thread_data *, struct fio_file *);
Jens Axboedcefb582009-06-03 08:49:39 +0200190extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
191
192extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
193extern void register_ioengine(struct ioengine_ops *);
194extern void unregister_ioengine(struct ioengine_ops *);
Steven Langde890a12011-11-09 14:03:34 +0100195extern void free_ioengine(struct thread_data *);
Jens Axboedcefb582009-06-03 08:49:39 +0200196extern void close_ioengine(struct thread_data *);
197
Steven Langde890a12011-11-09 14:03:34 +0100198extern int fio_show_ioengine_help(const char *engine);
199
Jens Axboedcefb582009-06-03 08:49:39 +0200200/*
201 * io unit handling
202 */
Jens Axboedcefb582009-06-03 08:49:39 +0200203extern struct io_u *__get_io_u(struct thread_data *);
204extern struct io_u *get_io_u(struct thread_data *);
205extern void put_io_u(struct thread_data *, struct io_u *);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200206extern void clear_io_u(struct thread_data *, struct io_u *);
Jens Axboedcefb582009-06-03 08:49:39 +0200207extern void requeue_io_u(struct thread_data *, struct io_u **);
Jens Axboe100f49f2013-01-23 10:15:57 -0700208extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, uint64_t *);
209extern int __must_check io_u_queued_complete(struct thread_data *, int, uint64_t *);
Jens Axboedcefb582009-06-03 08:49:39 +0200210extern void io_u_queued(struct thread_data *, struct io_u *);
Jens Axboe002e7182013-05-17 12:39:53 +0200211extern void io_u_quiesce(struct thread_data *);
Jens Axboedcefb582009-06-03 08:49:39 +0200212extern void io_u_log_error(struct thread_data *, struct io_u *);
213extern void io_u_mark_depth(struct thread_data *, unsigned int);
Jens Axboecc86c392013-05-03 15:12:33 +0200214extern void fill_io_buffer(struct thread_data *, void *, unsigned int, unsigned int);
Jens Axboe9c426842012-03-02 21:02:12 +0100215extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
Jens Axboedcefb582009-06-03 08:49:39 +0200216void io_u_mark_complete(struct thread_data *, unsigned int);
217void io_u_mark_submit(struct thread_data *, unsigned int);
Jens Axboe5a48d302014-09-30 13:29:57 -0600218int queue_full(const struct thread_data *);
Jens Axboedcefb582009-06-03 08:49:39 +0200219
Jens Axboe5a48d302014-09-30 13:29:57 -0600220int do_io_u_sync(const struct thread_data *, struct io_u *);
221int do_io_u_trim(const struct thread_data *, struct io_u *);
Jens Axboe44f29692010-03-09 20:09:44 +0100222
Jens Axboec592b9f2009-06-03 09:29:28 +0200223#ifdef FIO_INC_DEBUG
224static inline void dprint_io_u(struct io_u *io_u, const char *p)
225{
226 struct fio_file *f = io_u->file;
227
228 dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
229 (unsigned long long) io_u->offset,
230 io_u->buflen, io_u->ddir);
231 if (fio_debug & (1 << FD_IO)) {
232 if (f)
233 log_info("/%s", f->file_name);
234
235 log_info("\n");
236 }
237}
238#else
239#define dprint_io_u(io_u, p)
240#endif
241
Jens Axboebcd5abf2013-01-23 09:27:25 -0700242static inline enum fio_ddir acct_ddir(struct io_u *io_u)
243{
244 if (io_u->acct_ddir != -1)
245 return io_u->acct_ddir;
246
247 return io_u->ddir;
248}
249
Jens Axboedcefb582009-06-03 08:49:39 +0200250#endif