t/nvmept_trim: increase transfer size for some tests
[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
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          * number of trim ranges for this IO.
57          */
58         unsigned int number_trim;
59
60         /*
61          * Allocated/set buffer and length
62          */
63         unsigned long long buflen;
64         unsigned long long offset;      /* is really ->xfer_offset... */
65         unsigned long long verify_offset;       /* is really ->offset */
66         void *buf;
67
68         /*
69          * Initial seed for generating the buffer contents
70          */
71         uint64_t rand_seed;
72
73         /*
74          * IO engine state, may be different from above when we get
75          * partial transfers / residual data counts
76          */
77         void *xfer_buf;
78         unsigned long long xfer_buflen;
79
80         /*
81          * Parameter related to pre-filled buffers and
82          * their size to handle variable block sizes.
83          */
84         unsigned long long buf_filled_len;
85
86         struct io_piece *ipo;
87
88         unsigned long long resid;
89         unsigned int error;
90
91         /*
92          * io engine private data
93          */
94         union {
95                 unsigned int index;
96                 unsigned int seen;
97         };
98         void *engine_data;
99
100         union {
101                 struct flist_head verify_list;
102                 struct workqueue_work work;
103         };
104
105         /*
106          * ZBD mode zbd_queue_io callback: called after engine->queue operation
107          * to advance a zone write pointer and eventually unlock the I/O zone.
108          * @q indicates the I/O queue status (busy, queued or completed).
109          * @success == true means that the I/O operation has been queued or
110          * completed successfully.
111          */
112         void (*zbd_queue_io)(struct thread_data *td, struct io_u *, int q,
113                              bool success);
114
115         /*
116          * ZBD mode zbd_put_io callback: called in after completion of an I/O
117          * or commit of an async I/O to unlock the I/O target zone.
118          */
119         void (*zbd_put_io)(struct thread_data *td, const struct io_u *);
120
121         /*
122          * Callback for io completion
123          */
124         int (*end_io)(struct thread_data *, struct io_u **);
125
126         uint32_t dtype;
127         uint32_t dspec;
128
129         union {
130 #ifdef CONFIG_LIBAIO
131                 struct iocb iocb;
132 #endif
133 #ifdef CONFIG_POSIXAIO
134                 os_aiocb_t aiocb;
135 #endif
136 #ifdef FIO_HAVE_SGIO
137                 struct sg_io_hdr hdr;
138 #endif
139 #ifdef CONFIG_SOLARISAIO
140                 aio_result_t resultp;
141 #endif
142 #ifdef CONFIG_RDMA
143                 struct ibv_mr *mr;
144 #endif
145                 void *mmap_data;
146         };
147 };
148
149 /*
150  * io unit handling
151  */
152 extern struct io_u *__get_io_u(struct thread_data *);
153 extern struct io_u *get_io_u(struct thread_data *);
154 extern void put_io_u(struct thread_data *, struct io_u *);
155 extern void clear_io_u(struct thread_data *, struct io_u *);
156 extern void requeue_io_u(struct thread_data *, struct io_u **);
157 extern int __must_check io_u_sync_complete(struct thread_data *, struct io_u *);
158 extern int __must_check io_u_queued_complete(struct thread_data *, int);
159 extern void io_u_queued(struct thread_data *, struct io_u *);
160 extern int io_u_quiesce(struct thread_data *);
161 extern void io_u_log_error(struct thread_data *, struct io_u *);
162 extern void io_u_mark_depth(struct thread_data *, unsigned int);
163 extern void fill_io_buffer(struct thread_data *, void *, unsigned long long, unsigned long long);
164 extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned long long, unsigned long long);
165 void io_u_mark_complete(struct thread_data *, unsigned int);
166 void io_u_mark_submit(struct thread_data *, unsigned int);
167 bool queue_full(const struct thread_data *);
168
169 int do_io_u_sync(const struct thread_data *, struct io_u *);
170 int do_io_u_trim(struct thread_data *, struct io_u *);
171
172 #ifdef FIO_INC_DEBUG
173 static inline void dprint_io_u(struct io_u *io_u, const char *p)
174 {
175         struct fio_file *f = io_u->file;
176
177         if (f)
178                 dprint(FD_IO, "%s: io_u %p: off=0x%llx,len=0x%llx,ddir=%d,file=%s\n",
179                                 p, io_u,
180                                 (unsigned long long) io_u->offset,
181                                 io_u->buflen, io_u->ddir,
182                                 f->file_name);
183         else
184                 dprint(FD_IO, "%s: io_u %p: off=0x%llx,len=0x%llx,ddir=%d\n",
185                                 p, io_u,
186                                 (unsigned long long) io_u->offset,
187                                 io_u->buflen, io_u->ddir);
188 }
189 #else
190 #define dprint_io_u(io_u, p)
191 #endif
192
193 static inline enum fio_ddir acct_ddir(struct io_u *io_u)
194 {
195         if (io_u->acct_ddir != -1)
196                 return io_u->acct_ddir;
197
198         return io_u->ddir;
199 }
200
201 #define io_u_clear(td, io_u, val)       \
202         td_flags_clear((td), &(io_u->flags), (val))
203 #define io_u_set(td, io_u, val)         \
204         td_flags_set((td), &(io_u)->flags, (val))
205
206 #endif