blob: 6809501ffa795fa46e59419d91345bfc3904a0a6 [file] [log] [blame]
Jens Axboedcefb582009-06-03 08:49:39 +02001#ifndef FIO_IOENGINE_H
2#define FIO_IOENGINE_H
3
Jens Axboe67bf9822013-01-10 11:23:19 +01004#ifdef CONFIG_LIBAIO
5#include <libaio.h>
6#endif
7#ifdef CONFIG_GUASI
8#include <guasi.h>
9#endif
10
Jens Axboe36d80bc2012-11-30 21:46:06 +010011#define FIO_IOOPS_VERSION 14
Jens Axboedcefb582009-06-03 08:49:39 +020012
13enum {
Radha Ramachandran0c412142009-11-03 21:45:31 +010014 IO_U_F_FREE = 1 << 0,
15 IO_U_F_FLIGHT = 1 << 1,
16 IO_U_F_FREE_DEF = 1 << 2,
17 IO_U_F_IN_CUR_DEPTH = 1 << 3,
Jens Axboe38dad622010-07-20 14:46:00 -060018 IO_U_F_BUSY_OK = 1 << 4,
Jens Axboe0d29de82010-09-01 13:54:15 +020019 IO_U_F_TRIMMED = 1 << 5,
Jens Axboe1ef2b6b2010-10-08 15:07:01 +020020 IO_U_F_BARRIER = 1 << 6,
Jens Axboe82af2a72012-03-13 13:45:58 +010021 IO_U_F_VER_LIST = 1 << 7,
Jens Axboedcefb582009-06-03 08:49:39 +020022};
23
24/*
25 * The io unit
26 */
27struct io_u {
28 union {
Jens Axboe67bf9822013-01-10 11:23:19 +010029#ifdef CONFIG_LIBAIO
Jens Axboedcefb582009-06-03 08:49:39 +020030 struct iocb iocb;
31#endif
Jens Axboe67bf9822013-01-10 11:23:19 +010032#ifdef CONFIG_POSIXAIO
Jens Axboee97c1442011-09-21 09:38:01 +020033 os_aiocb_t aiocb;
Jens Axboedcefb582009-06-03 08:49:39 +020034#endif
35#ifdef FIO_HAVE_SGIO
36 struct sg_io_hdr hdr;
37#endif
Jens Axboe67bf9822013-01-10 11:23:19 +010038#ifdef CONFIG_GUASI
Jens Axboedcefb582009-06-03 08:49:39 +020039 guasi_req_t greq;
40#endif
Jens Axboe67bf9822013-01-10 11:23:19 +010041#ifdef CONFIG_SOLARISAIO
Jens Axboedcefb582009-06-03 08:49:39 +020042 aio_result_t resultp;
43#endif
Jens Axboe79a43182010-09-07 13:28:58 +020044#ifdef FIO_HAVE_BINJECT
45 struct b_user_cmd buc;
46#endif
Jens Axboe67bf9822013-01-10 11:23:19 +010047#ifdef CONFIG_RDMA
ren yufei21b8aee2011-08-01 10:01:57 +020048 struct ibv_mr *mr;
49#endif
Jens Axboedcefb582009-06-03 08:49:39 +020050 void *mmap_data;
51 };
52 struct timeval start_time;
53 struct timeval issue_time;
54
Jens Axboed72be542012-11-30 19:37:46 +010055 struct fio_file *file;
56 unsigned int flags;
57 enum fio_ddir ddir;
58
Jens Axboedcefb582009-06-03 08:49:39 +020059 /*
60 * Allocated/set buffer and length
61 */
Jens Axboedcefb582009-06-03 08:49:39 +020062 unsigned long buflen;
63 unsigned long long offset;
Jens Axboed72be542012-11-30 19:37:46 +010064 void *buf;
Jens Axboedcefb582009-06-03 08:49:39 +020065
66 /*
Jens Axboe7d9fb452011-01-11 22:16:49 +010067 * Initial seed for generating the buffer contents
68 */
69 unsigned long rand_seed;
70
71 /*
Jens Axboedcefb582009-06-03 08:49:39 +020072 * 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
Jens Axboe95228502010-07-14 08:42:03 +020078 /*
79 * Parameter related to pre-filled buffers and
80 * their size to handle variable block sizes.
81 */
82 unsigned long buf_filled_len;
83
Jens Axboedcefb582009-06-03 08:49:39 +020084 unsigned int resid;
85 unsigned int error;
86
Jens Axboedcefb582009-06-03 08:49:39 +020087 /*
88 * io engine private data
89 */
90 union {
91 unsigned int index;
92 unsigned int seen;
93 void *engine_data;
94 };
95
Jens Axboedcefb582009-06-03 08:49:39 +020096 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 */
107enum {
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
113struct 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 *);
Jens Axboe36d80bc2012-11-30 21:46:06 +0100130 void (*terminate)(struct thread_data *);
Jens Axboec73ed242012-12-06 20:30:38 +0100131 int (*io_u_init)(struct thread_data *, struct io_u *);
132 void (*io_u_free)(struct thread_data *, struct io_u *);
Steven Langde890a12011-11-09 14:03:34 +0100133 int option_struct_size;
134 struct fio_option *options;
Jens Axboedcefb582009-06-03 08:49:39 +0200135 void *data;
136 void *dlhandle;
137};
138
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200139enum fio_ioengine_flags {
140 FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */
141 FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */
142 FIO_DISKLESSIO = 1 << 2, /* no disk involved */
143 FIO_NOEXTEND = 1 << 3, /* engine can't extend file */
Bruce Cran93bcfd22012-02-20 20:18:19 +0100144 FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200145 FIO_UNIDIR = 1 << 5, /* engine is uni-directional */
146 FIO_NOIO = 1 << 6, /* thread does only pseudo IO */
Jens Axboe36d80bc2012-11-30 21:46:06 +0100147 FIO_PIPEIO = 1 << 7, /* input/output no seekable */
148 FIO_BARRIER = 1 << 8, /* engine supports barriers */
149 FIO_MEMALIGN = 1 << 9, /* engine wants aligned memory */
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200150};
Jens Axboedcefb582009-06-03 08:49:39 +0200151
152/*
153 * io engine entry points
154 */
155extern int __must_check td_io_init(struct thread_data *);
156extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
157extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
158extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
159extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *);
160extern int __must_check td_io_commit(struct thread_data *);
161extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
162extern int td_io_close_file(struct thread_data *, struct fio_file *);
163extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
164
165extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
166extern void register_ioengine(struct ioengine_ops *);
167extern void unregister_ioengine(struct ioengine_ops *);
Steven Langde890a12011-11-09 14:03:34 +0100168extern void free_ioengine(struct thread_data *);
Jens Axboedcefb582009-06-03 08:49:39 +0200169extern void close_ioengine(struct thread_data *);
170
Steven Langde890a12011-11-09 14:03:34 +0100171extern int fio_show_ioengine_help(const char *engine);
172
Jens Axboedcefb582009-06-03 08:49:39 +0200173/*
174 * io unit handling
175 */
176#define queue_full(td) flist_empty(&(td)->io_u_freelist)
177extern struct io_u *__get_io_u(struct thread_data *);
178extern struct io_u *get_io_u(struct thread_data *);
179extern void put_io_u(struct thread_data *, struct io_u *);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200180extern void clear_io_u(struct thread_data *, struct io_u *);
Jens Axboedcefb582009-06-03 08:49:39 +0200181extern void requeue_io_u(struct thread_data *, struct io_u **);
Jens Axboe581e7142009-06-09 12:47:16 +0200182extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, unsigned long *);
183extern int __must_check io_u_queued_complete(struct thread_data *, int, unsigned long *);
Jens Axboedcefb582009-06-03 08:49:39 +0200184extern void io_u_queued(struct thread_data *, struct io_u *);
185extern void io_u_log_error(struct thread_data *, struct io_u *);
186extern void io_u_mark_depth(struct thread_data *, unsigned int);
Jens Axboe9c426842012-03-02 21:02:12 +0100187extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
Jens Axboedcefb582009-06-03 08:49:39 +0200188void io_u_mark_complete(struct thread_data *, unsigned int);
189void io_u_mark_submit(struct thread_data *, unsigned int);
190
Jens Axboe0a28ecd2010-03-09 21:40:38 +0100191int do_io_u_sync(struct thread_data *, struct io_u *);
Jens Axboea5f30272010-07-19 16:19:55 -0600192int do_io_u_trim(struct thread_data *, struct io_u *);
Jens Axboe44f29692010-03-09 20:09:44 +0100193
Jens Axboec592b9f2009-06-03 09:29:28 +0200194#ifdef FIO_INC_DEBUG
195static inline void dprint_io_u(struct io_u *io_u, const char *p)
196{
197 struct fio_file *f = io_u->file;
198
199 dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
200 (unsigned long long) io_u->offset,
201 io_u->buflen, io_u->ddir);
202 if (fio_debug & (1 << FD_IO)) {
203 if (f)
204 log_info("/%s", f->file_name);
205
206 log_info("\n");
207 }
208}
209#else
210#define dprint_io_u(io_u, p)
211#endif
212
Jens Axboedcefb582009-06-03 08:49:39 +0200213#endif