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