| 1 | #ifndef FIO_IO_U |
| 2 | #define FIO_IO_U |
| 3 | |
| 4 | #include "compiler/compiler.h" |
| 5 | #include "os/os.h" |
| 6 | #include "io_ddir.h" |
| 7 | #include "debug.h" |
| 8 | #include "file.h" |
| 9 | #include "workqueue.h" |
| 10 | |
| 11 | #ifdef CONFIG_LIBAIO |
| 12 | #include <libaio.h> |
| 13 | #endif |
| 14 | |
| 15 | enum { |
| 16 | IO_U_F_FREE = 1 << 0, |
| 17 | IO_U_F_FLIGHT = 1 << 1, |
| 18 | IO_U_F_NO_FILE_PUT = 1 << 2, |
| 19 | IO_U_F_IN_CUR_DEPTH = 1 << 3, |
| 20 | IO_U_F_BUSY_OK = 1 << 4, |
| 21 | IO_U_F_TRIMMED = 1 << 5, |
| 22 | IO_U_F_BARRIER = 1 << 6, |
| 23 | IO_U_F_VER_LIST = 1 << 7, |
| 24 | IO_U_F_PATTERN_DONE = 1 << 8, |
| 25 | }; |
| 26 | |
| 27 | /* |
| 28 | * The io unit |
| 29 | */ |
| 30 | struct io_u { |
| 31 | struct timespec start_time; |
| 32 | struct timespec issue_time; |
| 33 | |
| 34 | struct fio_file *file; |
| 35 | unsigned int flags; |
| 36 | enum fio_ddir ddir; |
| 37 | |
| 38 | /* |
| 39 | * For replay workloads, we may want to account as a different |
| 40 | * IO type than what is being submitted. |
| 41 | */ |
| 42 | enum fio_ddir acct_ddir; |
| 43 | |
| 44 | /* |
| 45 | * Write generation |
| 46 | */ |
| 47 | unsigned short numberio; |
| 48 | |
| 49 | /* |
| 50 | * IO priority. |
| 51 | */ |
| 52 | unsigned short ioprio; |
| 53 | unsigned short clat_prio_index; |
| 54 | |
| 55 | /* |
| 56 | * Allocated/set buffer and length |
| 57 | */ |
| 58 | unsigned long long buflen; |
| 59 | unsigned long long offset; /* is really ->xfer_offset... */ |
| 60 | unsigned long long verify_offset; /* is really ->offset */ |
| 61 | void *buf; |
| 62 | |
| 63 | /* |
| 64 | * Initial seed for generating the buffer contents |
| 65 | */ |
| 66 | uint64_t rand_seed; |
| 67 | |
| 68 | /* |
| 69 | * IO engine state, may be different from above when we get |
| 70 | * partial transfers / residual data counts |
| 71 | */ |
| 72 | void *xfer_buf; |
| 73 | unsigned long long xfer_buflen; |
| 74 | |
| 75 | /* |
| 76 | * Parameter related to pre-filled buffers and |
| 77 | * their size to handle variable block sizes. |
| 78 | */ |
| 79 | unsigned long long buf_filled_len; |
| 80 | |
| 81 | struct io_piece *ipo; |
| 82 | |
| 83 | unsigned long long resid; |
| 84 | unsigned int error; |
| 85 | |
| 86 | /* |
| 87 | * io engine private data |
| 88 | */ |
| 89 | union { |
| 90 | unsigned int index; |
| 91 | unsigned int seen; |
| 92 | }; |
| 93 | void *engine_data; |
| 94 | |
| 95 | union { |
| 96 | struct flist_head verify_list; |
| 97 | struct workqueue_work work; |
| 98 | }; |
| 99 | |
| 100 | /* |
| 101 | * ZBD mode zbd_queue_io callback: called after engine->queue operation |
| 102 | * to advance a zone write pointer and eventually unlock the I/O zone. |
| 103 | * @q indicates the I/O queue status (busy, queued or completed). |
| 104 | * @success == true means that the I/O operation has been queued or |
| 105 | * completed successfully. |
| 106 | */ |
| 107 | void (*zbd_queue_io)(struct thread_data *td, struct io_u *, int q, |
| 108 | bool success); |
| 109 | |
| 110 | /* |
| 111 | * ZBD mode zbd_put_io callback: called in after completion of an I/O |
| 112 | * or commit of an async I/O to unlock the I/O target zone. |
| 113 | */ |
| 114 | void (*zbd_put_io)(struct thread_data *td, const struct io_u *); |
| 115 | |
| 116 | /* |
| 117 | * Callback for io completion |
| 118 | */ |
| 119 | int (*end_io)(struct thread_data *, struct io_u **); |
| 120 | |
| 121 | uint32_t dtype; |
| 122 | uint32_t dspec; |
| 123 | |
| 124 | union { |
| 125 | #ifdef CONFIG_LIBAIO |
| 126 | struct iocb iocb; |
| 127 | #endif |
| 128 | #ifdef CONFIG_POSIXAIO |
| 129 | os_aiocb_t aiocb; |
| 130 | #endif |
| 131 | #ifdef FIO_HAVE_SGIO |
| 132 | struct sg_io_hdr hdr; |
| 133 | #endif |
| 134 | #ifdef CONFIG_SOLARISAIO |
| 135 | aio_result_t resultp; |
| 136 | #endif |
| 137 | #ifdef CONFIG_RDMA |
| 138 | struct ibv_mr *mr; |
| 139 | #endif |
| 140 | void *mmap_data; |
| 141 | }; |
| 142 | }; |
| 143 | |
| 144 | /* |
| 145 | * io unit handling |
| 146 | */ |
| 147 | extern struct io_u *__get_io_u(struct thread_data *); |
| 148 | extern struct io_u *get_io_u(struct thread_data *); |
| 149 | extern void put_io_u(struct thread_data *, struct io_u *); |
| 150 | extern void clear_io_u(struct thread_data *, struct io_u *); |
| 151 | extern void requeue_io_u(struct thread_data *, struct io_u **); |
| 152 | extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *); |
| 153 | extern int __must_check io_u_queued_complete(struct thread_data *, int); |
| 154 | extern void io_u_queued(struct thread_data *, struct io_u *); |
| 155 | extern int io_u_quiesce(struct thread_data *); |
| 156 | extern void io_u_log_error(struct thread_data *, struct io_u *); |
| 157 | extern void io_u_mark_depth(struct thread_data *, unsigned int); |
| 158 | extern void fill_io_buffer(struct thread_data *, void *, unsigned long long, unsigned long long); |
| 159 | extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned long long, unsigned long long); |
| 160 | void io_u_mark_complete(struct thread_data *, unsigned int); |
| 161 | void io_u_mark_submit(struct thread_data *, unsigned int); |
| 162 | bool queue_full(const struct thread_data *); |
| 163 | |
| 164 | int do_io_u_sync(const struct thread_data *, struct io_u *); |
| 165 | int do_io_u_trim(struct thread_data *, struct io_u *); |
| 166 | |
| 167 | #ifdef FIO_INC_DEBUG |
| 168 | static inline void dprint_io_u(struct io_u *io_u, const char *p) |
| 169 | { |
| 170 | struct fio_file *f = io_u->file; |
| 171 | |
| 172 | if (f) |
| 173 | dprint(FD_IO, "%s: io_u %p: off=0x%llx,len=0x%llx,ddir=%d,file=%s\n", |
| 174 | p, io_u, |
| 175 | (unsigned long long) io_u->offset, |
| 176 | io_u->buflen, io_u->ddir, |
| 177 | f->file_name); |
| 178 | else |
| 179 | dprint(FD_IO, "%s: io_u %p: off=0x%llx,len=0x%llx,ddir=%d\n", |
| 180 | p, io_u, |
| 181 | (unsigned long long) io_u->offset, |
| 182 | io_u->buflen, io_u->ddir); |
| 183 | } |
| 184 | #else |
| 185 | #define dprint_io_u(io_u, p) |
| 186 | #endif |
| 187 | |
| 188 | static inline enum fio_ddir acct_ddir(struct io_u *io_u) |
| 189 | { |
| 190 | if (io_u->acct_ddir != -1) |
| 191 | return io_u->acct_ddir; |
| 192 | |
| 193 | return io_u->ddir; |
| 194 | } |
| 195 | |
| 196 | #define io_u_clear(td, io_u, val) \ |
| 197 | td_flags_clear((td), &(io_u->flags), (val)) |
| 198 | #define io_u_set(td, io_u, val) \ |
| 199 | td_flags_set((td), &(io_u)->flags, (val)) |
| 200 | |
| 201 | #endif |