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