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