Add basic write/read-and-verify example job file
[fio.git] / iolog.h
CommitLineData
5995a6a4
JA
1#ifndef FIO_IOLOG_H
2#define FIO_IOLOG_H
3
05775438 4#include "lib/rbtree.h"
c7c6cb4c 5#include "lib/ieee754.h"
836fcc0f 6#include "flist.h"
ec41265e 7#include "ioengine.h"
802ad4a8 8
5995a6a4
JA
9/*
10 * Use for maintaining statistics
11 */
12struct io_stat {
7b9f733a
JA
13 uint64_t max_val;
14 uint64_t min_val;
15 uint64_t samples;
5995a6a4 16
802ad4a8
JA
17 fio_fp64_t mean;
18 fio_fp64_t S;
5995a6a4
JA
19};
20
1e613c9c
KC
21struct io_hist {
22 uint64_t samples;
23 unsigned long hist_last;
d730bc58 24 struct flist_head list;
1e613c9c
KC
25};
26
5995a6a4
JA
27/*
28 * A single data sample
29 */
30struct io_sample {
1b42725f
JA
31 uint64_t time;
32 uint64_t val;
b26317c9 33 uint32_t __ddir;
1b42725f 34 uint32_t bs;
5995a6a4
JA
35};
36
ae588852
JA
37struct io_sample_offset {
38 struct io_sample s;
39 uint64_t offset;
40};
41
ea51b956
JA
42enum {
43 IO_LOG_TYPE_LAT = 1,
44 IO_LOG_TYPE_CLAT,
45 IO_LOG_TYPE_SLAT,
46 IO_LOG_TYPE_BW,
47 IO_LOG_TYPE_IOPS,
1e613c9c 48 IO_LOG_TYPE_HIST,
ea51b956
JA
49};
50
6d37f67f 51#define DEF_LOG_ENTRIES 1024
7e419452
JA
52#define MAX_LOG_ENTRIES (1024 * DEF_LOG_ENTRIES)
53
7e419452
JA
54struct io_logs {
55 struct flist_head list;
56 uint64_t nr_samples;
57 uint64_t max_samples;
58 void *log;
59};
6d37f67f 60
5995a6a4
JA
61/*
62 * Dynamically growing data sample log
63 */
64struct io_log {
b8bc8cba
JA
65 /*
66 * Entries already logged
67 */
7e419452
JA
68 struct flist_head io_logs;
69 uint32_t cur_log_max;
b8bc8cba 70
1fed2080
JA
71 /*
72 * When the current log runs out of space, store events here until
73 * we have a chance to regrow
74 */
75 struct io_logs *pending;
76
b26317c9
JA
77 unsigned int log_ddir_mask;
78
cb7e0ace
JA
79 char *filename;
80
aee2ab67
JA
81 struct thread_data *td;
82
1b42725f 83 unsigned int log_type;
ea51b956 84
3c568239
JA
85 /*
86 * If we fail extending the log, stop collecting more entries.
87 */
7e419452 88 bool disabled;
3c568239 89
ae588852
JA
90 /*
91 * Log offsets
92 */
93 unsigned int log_offset;
94
aee2ab67
JA
95 /*
96 * Max size of log entries before a chunk is compressed
97 */
98 unsigned int log_gz;
99
b26317c9
JA
100 /*
101 * Don't deflate for storing, just store the compressed bits
102 */
103 unsigned int log_gz_store;
104
b8bc8cba
JA
105 /*
106 * Windowed average, for logging single entries average over some
107 * period of time.
108 */
6eaf09d6 109 struct io_stat avg_window[DDIR_RWDIR_CNT];
b8bc8cba
JA
110 unsigned long avg_msec;
111 unsigned long avg_last;
aee2ab67 112
8aa89d70
JA
113 /*
114 * Windowed latency histograms, for keeping track of when we need to
115 * save a copy of the histogram every approximately hist_msec
116 * milliseconds.
117 */
1e613c9c
KC
118 struct io_hist hist_window[DDIR_RWDIR_CNT];
119 unsigned long hist_msec;
120 int hist_coarseness;
121
aee2ab67
JA
122 pthread_mutex_t chunk_lock;
123 unsigned int chunk_seq;
124 struct flist_head chunk_list;
5995a6a4
JA
125};
126
49e98daa
JA
127/*
128 * If the upper bit is set, then we have the offset as well
129 */
130#define LOG_OFFSET_SAMPLE_BIT 0x80000000U
131#define io_sample_ddir(io) ((io)->__ddir & ~LOG_OFFSET_SAMPLE_BIT)
b26317c9
JA
132
133static inline void io_sample_set_ddir(struct io_log *log,
134 struct io_sample *io,
135 enum fio_ddir ddir)
136{
137 io->__ddir = ddir | log->log_ddir_mask;
138}
139
ae588852
JA
140static inline size_t __log_entry_sz(int log_offset)
141{
142 if (log_offset)
143 return sizeof(struct io_sample_offset);
144 else
145 return sizeof(struct io_sample);
146}
147
148static inline size_t log_entry_sz(struct io_log *log)
149{
150 return __log_entry_sz(log->log_offset);
151}
152
153static inline struct io_sample *__get_sample(void *samples, int log_offset,
154 uint64_t sample)
155{
6f9bbb55
CB
156 uint64_t sample_offset = sample * __log_entry_sz(log_offset);
157 return (struct io_sample *) ((char *) samples + sample_offset);
ae588852
JA
158}
159
7e419452
JA
160struct io_logs *iolog_cur_log(struct io_log *);
161uint64_t iolog_nr_samples(struct io_log *);
1fed2080 162void regrow_logs(struct thread_data *);
7e419452 163
ae588852 164static inline struct io_sample *get_sample(struct io_log *iolog,
7e419452 165 struct io_logs *cur_log,
ae588852
JA
166 uint64_t sample)
167{
7e419452 168 return __get_sample(cur_log->log, iolog->log_offset, sample);
ae588852
JA
169}
170
0d29de83
JA
171enum {
172 IP_F_ONRB = 1,
173 IP_F_ONLIST = 2,
174 IP_F_TRIMMED = 4,
f9401285 175 IP_F_IN_FLIGHT = 8,
0d29de83
JA
176};
177
5995a6a4
JA
178/*
179 * When logging io actions, this matches a single sent io_u
180 */
181struct io_piece {
182 union {
183 struct rb_node rb_node;
184 struct flist_head list;
185 };
0d29de83 186 struct flist_head trim_list;
5995a6a4
JA
187 union {
188 int fileno;
189 struct fio_file *file;
190 };
191 unsigned long long offset;
da0a7bd2 192 unsigned short numberio;
5995a6a4 193 unsigned long len;
a917a8b3 194 unsigned int flags;
5995a6a4
JA
195 enum fio_ddir ddir;
196 union {
197 unsigned long delay;
198 unsigned int file_action;
199 };
200};
201
202/*
203 * Log exports
204 */
205enum file_log_act {
206 FIO_LOG_ADD_FILE,
207 FIO_LOG_OPEN_FILE,
208 FIO_LOG_CLOSE_FILE,
209 FIO_LOG_UNLINK_FILE,
210};
211
8062f527 212struct io_u;
5995a6a4 213extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
1f440ece 214extern void log_io_u(const struct thread_data *, const struct io_u *);
5995a6a4
JA
215extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
216extern int __must_check init_iolog(struct thread_data *td);
217extern void log_io_piece(struct thread_data *, struct io_u *);
890b6656 218extern void unlog_io_piece(struct thread_data *, struct io_u *);
1f440ece 219extern void trim_io_piece(struct thread_data *, const struct io_u *);
5995a6a4
JA
220extern void queue_io_piece(struct thread_data *, struct io_piece *);
221extern void prune_io_piece_log(struct thread_data *);
222extern void write_iolog_close(struct thread_data *);
24660963 223extern int iolog_compress_init(struct thread_data *, struct sk_out *);
155f2f02 224extern void iolog_compress_exit(struct thread_data *);
0cba0f91 225extern size_t log_chunk_sizes(struct io_log *);
5995a6a4 226
b26317c9
JA
227#ifdef CONFIG_ZLIB
228extern int iolog_file_inflate(const char *);
229#endif
230
5995a6a4
JA
231/*
232 * Logging
233 */
aee2ab67
JA
234struct log_params {
235 struct thread_data *td;
236 unsigned long avg_msec;
1e613c9c
KC
237 unsigned long hist_msec;
238 int hist_coarseness;
aee2ab67
JA
239 int log_type;
240 int log_offset;
241 int log_gz;
b26317c9 242 int log_gz_store;
aee2ab67
JA
243 int log_compress;
244};
245
a47591e4
JA
246static inline bool per_unit_log(struct io_log *log)
247{
248 return log && !log->avg_msec;
249}
250
b392f36d
JA
251static inline bool inline_log(struct io_log *log)
252{
253 return log->log_type == IO_LOG_TYPE_LAT ||
254 log->log_type == IO_LOG_TYPE_CLAT ||
255 log->log_type == IO_LOG_TYPE_SLAT;
256}
257
a47591e4 258extern void finalize_logs(struct thread_data *td, bool);
aee2ab67 259extern void setup_log(struct io_log **, struct log_params *, const char *);
60a25727 260extern void flush_log(struct io_log *, bool);
bead01d7 261extern void flush_samples(FILE *, void *, uint64_t);
518dac09 262extern void free_log(struct io_log *);
a47591e4
JA
263extern void fio_writeout_logs(bool);
264extern void td_writeout_logs(struct thread_data *, bool);
7e419452 265extern int iolog_cur_flush(struct io_log *, struct io_logs *);
5995a6a4 266
0d29de83
JA
267static inline void init_ipo(struct io_piece *ipo)
268{
269 memset(ipo, 0, sizeof(*ipo));
270 INIT_FLIST_HEAD(&ipo->trim_list);
271}
272
0cba0f91
JA
273struct iolog_compress {
274 struct flist_head list;
275 void *buf;
276 size_t len;
277 unsigned int seq;
278};
279
5995a6a4 280#endif