blob: 55039578d9edad878519cde64b665ea81c5e2b0f [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 Axboebcd5abf2013-01-23 09:27:25 -070018#define FIO_IOOPS_VERSION 15
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,
23 IO_U_F_FREE_DEF = 1 << 2,
24 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
Jens Axboe41666582012-03-21 10:25:29 +010031struct thread_data;
32
Jens Axboedcefb582009-06-03 08:49:39 +020033/*
34 * The io unit
35 */
36struct io_u {
37 union {
Jens Axboe67bf9822013-01-10 11:23:19 +010038#ifdef CONFIG_LIBAIO
Jens Axboedcefb582009-06-03 08:49:39 +020039 struct iocb iocb;
40#endif
Jens Axboe67bf9822013-01-10 11:23:19 +010041#ifdef CONFIG_POSIXAIO
Jens Axboee97c1442011-09-21 09:38:01 +020042 os_aiocb_t aiocb;
Jens Axboedcefb582009-06-03 08:49:39 +020043#endif
44#ifdef FIO_HAVE_SGIO
45 struct sg_io_hdr hdr;
46#endif
Jens Axboe67bf9822013-01-10 11:23:19 +010047#ifdef CONFIG_GUASI
Jens Axboedcefb582009-06-03 08:49:39 +020048 guasi_req_t greq;
49#endif
Jens Axboe67bf9822013-01-10 11:23:19 +010050#ifdef CONFIG_SOLARISAIO
Jens Axboedcefb582009-06-03 08:49:39 +020051 aio_result_t resultp;
52#endif
Jens Axboe79a43182010-09-07 13:28:58 +020053#ifdef FIO_HAVE_BINJECT
54 struct b_user_cmd buc;
55#endif
Jens Axboe67bf9822013-01-10 11:23:19 +010056#ifdef CONFIG_RDMA
ren yufei21b8aee2011-08-01 10:01:57 +020057 struct ibv_mr *mr;
58#endif
Jens Axboedcefb582009-06-03 08:49:39 +020059 void *mmap_data;
60 };
61 struct timeval start_time;
62 struct timeval issue_time;
63
Jens Axboed72be542012-11-30 19:37:46 +010064 struct fio_file *file;
65 unsigned int flags;
66 enum fio_ddir ddir;
67
Jens Axboedcefb582009-06-03 08:49:39 +020068 /*
Jens Axboebcd5abf2013-01-23 09:27:25 -070069 * For replay workloads, we may want to account as a different
70 * IO type than what is being submitted.
71 */
72 enum fio_ddir acct_ddir;
73
74 /*
Jens Axboedcefb582009-06-03 08:49:39 +020075 * Allocated/set buffer and length
76 */
Jens Axboedcefb582009-06-03 08:49:39 +020077 unsigned long buflen;
78 unsigned long long offset;
Jens Axboed72be542012-11-30 19:37:46 +010079 void *buf;
Jens Axboedcefb582009-06-03 08:49:39 +020080
81 /*
Jens Axboe7d9fb452011-01-11 22:16:49 +010082 * Initial seed for generating the buffer contents
83 */
84 unsigned long rand_seed;
85
86 /*
Jens Axboedcefb582009-06-03 08:49:39 +020087 * IO engine state, may be different from above when we get
88 * partial transfers / residual data counts
89 */
90 void *xfer_buf;
91 unsigned long xfer_buflen;
92
Jens Axboe95228502010-07-14 08:42:03 +020093 /*
94 * Parameter related to pre-filled buffers and
95 * their size to handle variable block sizes.
96 */
97 unsigned long buf_filled_len;
98
Jens Axboedcefb582009-06-03 08:49:39 +020099 unsigned int resid;
100 unsigned int error;
101
Jens Axboedcefb582009-06-03 08:49:39 +0200102 /*
103 * io engine private data
104 */
105 union {
106 unsigned int index;
107 unsigned int seen;
108 void *engine_data;
109 };
110
Jens Axboedcefb582009-06-03 08:49:39 +0200111 struct flist_head list;
112
113 /*
114 * Callback for io completion
115 */
116 int (*end_io)(struct thread_data *, struct io_u *);
117};
118
119/*
120 * io_ops->queue() return values
121 */
122enum {
123 FIO_Q_COMPLETED = 0, /* completed sync */
124 FIO_Q_QUEUED = 1, /* queued, will complete async */
125 FIO_Q_BUSY = 2, /* no more room, call ->commit() */
126};
127
128struct ioengine_ops {
129 struct flist_head list;
130 char name[16];
131 int version;
132 int flags;
133 int (*setup)(struct thread_data *);
134 int (*init)(struct thread_data *);
135 int (*prep)(struct thread_data *, struct io_u *);
136 int (*queue)(struct thread_data *, struct io_u *);
137 int (*commit)(struct thread_data *);
138 int (*getevents)(struct thread_data *, unsigned int, unsigned int, struct timespec *);
139 struct io_u *(*event)(struct thread_data *, int);
140 int (*cancel)(struct thread_data *, struct io_u *);
141 void (*cleanup)(struct thread_data *);
142 int (*open_file)(struct thread_data *, struct fio_file *);
143 int (*close_file)(struct thread_data *, struct fio_file *);
144 int (*get_file_size)(struct thread_data *, struct fio_file *);
Jens Axboe36d80bc2012-11-30 21:46:06 +0100145 void (*terminate)(struct thread_data *);
Jens Axboec73ed242012-12-06 20:30:38 +0100146 int (*io_u_init)(struct thread_data *, struct io_u *);
147 void (*io_u_free)(struct thread_data *, struct io_u *);
Steven Langde890a12011-11-09 14:03:34 +0100148 int option_struct_size;
149 struct fio_option *options;
Jens Axboedcefb582009-06-03 08:49:39 +0200150 void *data;
151 void *dlhandle;
152};
153
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200154enum fio_ioengine_flags {
155 FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */
156 FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */
157 FIO_DISKLESSIO = 1 << 2, /* no disk involved */
158 FIO_NOEXTEND = 1 << 3, /* engine can't extend file */
Bruce Cran93bcfd22012-02-20 20:18:19 +0100159 FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200160 FIO_UNIDIR = 1 << 5, /* engine is uni-directional */
161 FIO_NOIO = 1 << 6, /* thread does only pseudo IO */
Jens Axboe36d80bc2012-11-30 21:46:06 +0100162 FIO_PIPEIO = 1 << 7, /* input/output no seekable */
163 FIO_BARRIER = 1 << 8, /* engine supports barriers */
164 FIO_MEMALIGN = 1 << 9, /* engine wants aligned memory */
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200165};
Jens Axboedcefb582009-06-03 08:49:39 +0200166
167/*
168 * io engine entry points
169 */
170extern int __must_check td_io_init(struct thread_data *);
171extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
172extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
173extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
174extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *);
175extern int __must_check td_io_commit(struct thread_data *);
176extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
177extern int td_io_close_file(struct thread_data *, struct fio_file *);
178extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
179
180extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
181extern void register_ioengine(struct ioengine_ops *);
182extern void unregister_ioengine(struct ioengine_ops *);
Steven Langde890a12011-11-09 14:03:34 +0100183extern void free_ioengine(struct thread_data *);
Jens Axboedcefb582009-06-03 08:49:39 +0200184extern void close_ioengine(struct thread_data *);
185
Steven Langde890a12011-11-09 14:03:34 +0100186extern int fio_show_ioengine_help(const char *engine);
187
Jens Axboedcefb582009-06-03 08:49:39 +0200188/*
189 * io unit handling
190 */
191#define queue_full(td) flist_empty(&(td)->io_u_freelist)
192extern struct io_u *__get_io_u(struct thread_data *);
193extern struct io_u *get_io_u(struct thread_data *);
194extern void put_io_u(struct thread_data *, struct io_u *);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200195extern void clear_io_u(struct thread_data *, struct io_u *);
Jens Axboedcefb582009-06-03 08:49:39 +0200196extern void requeue_io_u(struct thread_data *, struct io_u **);
Jens Axboe100f49f2013-01-23 10:15:57 -0700197extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, uint64_t *);
198extern int __must_check io_u_queued_complete(struct thread_data *, int, uint64_t *);
Jens Axboedcefb582009-06-03 08:49:39 +0200199extern void io_u_queued(struct thread_data *, struct io_u *);
200extern void io_u_log_error(struct thread_data *, struct io_u *);
201extern void io_u_mark_depth(struct thread_data *, unsigned int);
Jens Axboe9c426842012-03-02 21:02:12 +0100202extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
Jens Axboedcefb582009-06-03 08:49:39 +0200203void io_u_mark_complete(struct thread_data *, unsigned int);
204void io_u_mark_submit(struct thread_data *, unsigned int);
205
Jens Axboe0a28ecd2010-03-09 21:40:38 +0100206int do_io_u_sync(struct thread_data *, struct io_u *);
Jens Axboea5f30272010-07-19 16:19:55 -0600207int do_io_u_trim(struct thread_data *, struct io_u *);
Jens Axboe44f29692010-03-09 20:09:44 +0100208
Jens Axboec592b9f2009-06-03 09:29:28 +0200209#ifdef FIO_INC_DEBUG
210static inline void dprint_io_u(struct io_u *io_u, const char *p)
211{
212 struct fio_file *f = io_u->file;
213
214 dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
215 (unsigned long long) io_u->offset,
216 io_u->buflen, io_u->ddir);
217 if (fio_debug & (1 << FD_IO)) {
218 if (f)
219 log_info("/%s", f->file_name);
220
221 log_info("\n");
222 }
223}
224#else
225#define dprint_io_u(io_u, p)
226#endif
227
Jens Axboebcd5abf2013-01-23 09:27:25 -0700228static inline enum fio_ddir acct_ddir(struct io_u *io_u)
229{
230 if (io_u->acct_ddir != -1)
231 return io_u->acct_ddir;
232
233 return io_u->ddir;
234}
235
Jens Axboedcefb582009-06-03 08:49:39 +0200236#endif