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