blob: e27dab1c1785ea1ac7af9b4f84361efe331082d8 [file] [log] [blame]
Jens Axboedcefb582009-06-03 08:49:39 +02001#ifndef FIO_IOENGINE_H
2#define FIO_IOENGINE_H
3
Steven Langde890a12011-11-09 14:03:34 +01004#define FIO_IOOPS_VERSION 13
Jens Axboedcefb582009-06-03 08:49:39 +02005
6enum {
Radha Ramachandran0c412142009-11-03 21:45:31 +01007 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,
Jens Axboe38dad622010-07-20 14:46:00 -060011 IO_U_F_BUSY_OK = 1 << 4,
Jens Axboe0d29de82010-09-01 13:54:15 +020012 IO_U_F_TRIMMED = 1 << 5,
Jens Axboe1ef2b6b2010-10-08 15:07:01 +020013 IO_U_F_BARRIER = 1 << 6,
Jens Axboe82af2a72012-03-13 13:45:58 +010014 IO_U_F_VER_LIST = 1 << 7,
Jens Axboedcefb582009-06-03 08:49:39 +020015};
16
17/*
18 * The io unit
19 */
20struct io_u {
21 union {
22#ifdef FIO_HAVE_LIBAIO
23 struct iocb iocb;
24#endif
25#ifdef FIO_HAVE_POSIXAIO
Jens Axboee97c1442011-09-21 09:38:01 +020026 os_aiocb_t aiocb;
Jens Axboedcefb582009-06-03 08:49:39 +020027#endif
28#ifdef FIO_HAVE_SGIO
29 struct sg_io_hdr hdr;
30#endif
31#ifdef FIO_HAVE_GUASI
32 guasi_req_t greq;
33#endif
34#ifdef FIO_HAVE_SOLARISAIO
35 aio_result_t resultp;
36#endif
Jens Axboe79a43182010-09-07 13:28:58 +020037#ifdef FIO_HAVE_BINJECT
38 struct b_user_cmd buc;
39#endif
ren yufei21b8aee2011-08-01 10:01:57 +020040#ifdef FIO_HAVE_RDMA
41 struct ibv_mr *mr;
42#endif
Jens Axboedcefb582009-06-03 08:49:39 +020043 void *mmap_data;
44 };
45 struct timeval start_time;
46 struct timeval issue_time;
47
Jens Axboed72be542012-11-30 19:37:46 +010048 struct fio_file *file;
49 unsigned int flags;
50 enum fio_ddir ddir;
51
Jens Axboedcefb582009-06-03 08:49:39 +020052 /*
53 * Allocated/set buffer and length
54 */
Jens Axboedcefb582009-06-03 08:49:39 +020055 unsigned long buflen;
56 unsigned long long offset;
Jens Axboed72be542012-11-30 19:37:46 +010057 void *buf;
Jens Axboedcefb582009-06-03 08:49:39 +020058
59 /*
Jens Axboe7d9fb452011-01-11 22:16:49 +010060 * Initial seed for generating the buffer contents
61 */
62 unsigned long rand_seed;
63
64 /*
Jens Axboedcefb582009-06-03 08:49:39 +020065 * IO engine state, may be different from above when we get
66 * partial transfers / residual data counts
67 */
68 void *xfer_buf;
69 unsigned long xfer_buflen;
70
Jens Axboe95228502010-07-14 08:42:03 +020071 /*
72 * Parameter related to pre-filled buffers and
73 * their size to handle variable block sizes.
74 */
75 unsigned long buf_filled_len;
76
Jens Axboedcefb582009-06-03 08:49:39 +020077 unsigned int resid;
78 unsigned int error;
79
Jens Axboedcefb582009-06-03 08:49:39 +020080 /*
81 * io engine private data
82 */
83 union {
84 unsigned int index;
85 unsigned int seen;
86 void *engine_data;
87 };
88
Jens Axboedcefb582009-06-03 08:49:39 +020089 struct flist_head list;
90
91 /*
92 * Callback for io completion
93 */
94 int (*end_io)(struct thread_data *, struct io_u *);
95};
96
97/*
98 * io_ops->queue() return values
99 */
100enum {
101 FIO_Q_COMPLETED = 0, /* completed sync */
102 FIO_Q_QUEUED = 1, /* queued, will complete async */
103 FIO_Q_BUSY = 2, /* no more room, call ->commit() */
104};
105
106struct ioengine_ops {
107 struct flist_head list;
108 char name[16];
109 int version;
110 int flags;
111 int (*setup)(struct thread_data *);
112 int (*init)(struct thread_data *);
113 int (*prep)(struct thread_data *, struct io_u *);
114 int (*queue)(struct thread_data *, struct io_u *);
115 int (*commit)(struct thread_data *);
116 int (*getevents)(struct thread_data *, unsigned int, unsigned int, struct timespec *);
117 struct io_u *(*event)(struct thread_data *, int);
118 int (*cancel)(struct thread_data *, struct io_u *);
119 void (*cleanup)(struct thread_data *);
120 int (*open_file)(struct thread_data *, struct fio_file *);
121 int (*close_file)(struct thread_data *, struct fio_file *);
122 int (*get_file_size)(struct thread_data *, struct fio_file *);
Steven Langde890a12011-11-09 14:03:34 +0100123 int option_struct_size;
124 struct fio_option *options;
Jens Axboedcefb582009-06-03 08:49:39 +0200125 void *data;
126 void *dlhandle;
127};
128
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200129enum fio_ioengine_flags {
130 FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */
131 FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */
132 FIO_DISKLESSIO = 1 << 2, /* no disk involved */
133 FIO_NOEXTEND = 1 << 3, /* engine can't extend file */
Bruce Cran93bcfd22012-02-20 20:18:19 +0100134 FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200135 FIO_UNIDIR = 1 << 5, /* engine is uni-directional */
136 FIO_NOIO = 1 << 6, /* thread does only pseudo IO */
Bruce Cran03e20d62011-01-02 20:14:54 +0100137 FIO_SIGTERM = 1 << 7, /* needs SIGTERM to exit */
Jens Axboe9c0d2242009-07-01 12:26:28 +0200138 FIO_PIPEIO = 1 << 8, /* input/output no seekable */
Jens Axboe1ef2b6b2010-10-08 15:07:01 +0200139 FIO_BARRIER = 1 << 9, /* engine supports barriers */
Jens Axboeca7e0dd2010-10-28 08:52:13 -0600140 FIO_MEMALIGN = 1 << 10, /* engine wants aligned memory */
Jens Axboe2b4f4ab2009-06-03 08:50:36 +0200141};
Jens Axboedcefb582009-06-03 08:49:39 +0200142
143/*
144 * io engine entry points
145 */
146extern int __must_check td_io_init(struct thread_data *);
147extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
148extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
149extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
150extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *);
151extern int __must_check td_io_commit(struct thread_data *);
152extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
153extern int td_io_close_file(struct thread_data *, struct fio_file *);
154extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
155
156extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
157extern void register_ioengine(struct ioengine_ops *);
158extern void unregister_ioengine(struct ioengine_ops *);
Steven Langde890a12011-11-09 14:03:34 +0100159extern void free_ioengine(struct thread_data *);
Jens Axboedcefb582009-06-03 08:49:39 +0200160extern void close_ioengine(struct thread_data *);
161
Steven Langde890a12011-11-09 14:03:34 +0100162extern int fio_show_ioengine_help(const char *engine);
163
Jens Axboedcefb582009-06-03 08:49:39 +0200164/*
165 * io unit handling
166 */
167#define queue_full(td) flist_empty(&(td)->io_u_freelist)
168extern struct io_u *__get_io_u(struct thread_data *);
169extern struct io_u *get_io_u(struct thread_data *);
170extern void put_io_u(struct thread_data *, struct io_u *);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200171extern void clear_io_u(struct thread_data *, struct io_u *);
Jens Axboedcefb582009-06-03 08:49:39 +0200172extern void requeue_io_u(struct thread_data *, struct io_u **);
Jens Axboe581e7142009-06-09 12:47:16 +0200173extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *, unsigned long *);
174extern int __must_check io_u_queued_complete(struct thread_data *, int, unsigned long *);
Jens Axboedcefb582009-06-03 08:49:39 +0200175extern void io_u_queued(struct thread_data *, struct io_u *);
176extern void io_u_log_error(struct thread_data *, struct io_u *);
177extern void io_u_mark_depth(struct thread_data *, unsigned int);
Jens Axboe9c426842012-03-02 21:02:12 +0100178extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int, unsigned int);
Jens Axboedcefb582009-06-03 08:49:39 +0200179void io_u_mark_complete(struct thread_data *, unsigned int);
180void io_u_mark_submit(struct thread_data *, unsigned int);
181
Jens Axboe0a28ecd2010-03-09 21:40:38 +0100182int do_io_u_sync(struct thread_data *, struct io_u *);
Jens Axboea5f30272010-07-19 16:19:55 -0600183int do_io_u_trim(struct thread_data *, struct io_u *);
Jens Axboe44f29692010-03-09 20:09:44 +0100184
Jens Axboec592b9f2009-06-03 09:29:28 +0200185#ifdef FIO_INC_DEBUG
186static inline void dprint_io_u(struct io_u *io_u, const char *p)
187{
188 struct fio_file *f = io_u->file;
189
190 dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
191 (unsigned long long) io_u->offset,
192 io_u->buflen, io_u->ddir);
193 if (fio_debug & (1 << FD_IO)) {
194 if (f)
195 log_info("/%s", f->file_name);
196
197 log_info("\n");
198 }
199}
200#else
201#define dprint_io_u(io_u, p)
202#endif
203
Jens Axboedcefb582009-06-03 08:49:39 +0200204#endif