6 #include "lib/rbtree.h"
7 #include "lib/ieee754.h"
12 * Use for maintaining statistics
25 unsigned long hist_last;
26 struct flist_head list;
30 union io_sample_data {
32 struct io_u_plat_entry *plat_entry;
35 #define sample_val(value) ((union io_sample_data) { .val = value })
36 #define sample_plat(plat) ((union io_sample_data) { .plat_entry = plat })
39 * A single data sample
43 union io_sample_data data;
49 struct io_sample_offset {
63 #define DEF_LOG_ENTRIES 1024
64 #define MAX_LOG_ENTRIES (1024 * DEF_LOG_ENTRIES)
67 struct flist_head list;
74 * Dynamically growing data sample log
78 * Entries already logged
80 struct flist_head io_logs;
84 * When the current log runs out of space, store events here until
85 * we have a chance to regrow
87 struct io_logs *pending;
89 unsigned int log_ddir_mask;
93 struct thread_data *td;
95 unsigned int log_type;
98 * If we fail extending the log, stop collecting more entries.
105 unsigned int log_offset;
110 unsigned int log_prio;
113 * Max size of log entries before a chunk is compressed
118 * Don't deflate for storing, just store the compressed bits
120 unsigned int log_gz_store;
123 * Windowed average, for logging single entries average over some
126 struct io_stat avg_window[DDIR_RWDIR_CNT];
127 unsigned long avg_msec;
128 unsigned long avg_last[DDIR_RWDIR_CNT];
131 * Windowed latency histograms, for keeping track of when we need to
132 * save a copy of the histogram every approximately hist_msec
135 struct io_hist hist_window[DDIR_RWDIR_CNT];
136 unsigned long hist_msec;
137 unsigned int hist_coarseness;
139 pthread_mutex_t chunk_lock;
140 unsigned int chunk_seq;
141 struct flist_head chunk_list;
143 pthread_mutex_t deferred_free_lock;
144 #define IOLOG_MAX_DEFER 8
145 void *deferred_items[IOLOG_MAX_DEFER];
146 unsigned int deferred;
150 * If the upper bit is set, then we have the offset as well
152 #define LOG_OFFSET_SAMPLE_BIT 0x80000000U
154 * If the bit following the upper bit is set, then we have the priority
156 #define LOG_PRIO_SAMPLE_BIT 0x40000000U
158 #define LOG_SAMPLE_BITS (LOG_OFFSET_SAMPLE_BIT | LOG_PRIO_SAMPLE_BIT)
159 #define io_sample_ddir(io) ((io)->__ddir & ~LOG_SAMPLE_BITS)
161 static inline void io_sample_set_ddir(struct io_log *log,
162 struct io_sample *io,
165 io->__ddir = ddir | log->log_ddir_mask;
168 static inline size_t __log_entry_sz(int log_offset)
171 return sizeof(struct io_sample_offset);
173 return sizeof(struct io_sample);
176 static inline size_t log_entry_sz(struct io_log *log)
178 return __log_entry_sz(log->log_offset);
181 static inline size_t log_sample_sz(struct io_log *log, struct io_logs *cur_log)
183 return cur_log->nr_samples * log_entry_sz(log);
186 static inline struct io_sample *__get_sample(void *samples, int log_offset,
189 uint64_t sample_offset = sample * __log_entry_sz(log_offset);
190 return (struct io_sample *) ((char *) samples + sample_offset);
193 struct io_logs *iolog_cur_log(struct io_log *);
194 uint64_t iolog_nr_samples(struct io_log *);
195 void regrow_logs(struct thread_data *);
196 void regrow_agg_logs(void);
198 static inline struct io_sample *get_sample(struct io_log *iolog,
199 struct io_logs *cur_log,
202 return __get_sample(cur_log->log, iolog->log_offset, sample);
213 * When logging io actions, this matches a single sent io_u
217 struct fio_rb_node rb_node;
218 struct flist_head list;
220 struct flist_head trim_list;
223 struct fio_file *file;
225 unsigned long long offset;
226 unsigned short numberio;
232 unsigned int file_action;
247 extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
248 extern void log_io_u(const struct thread_data *, const struct io_u *);
249 extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
250 extern bool __must_check init_iolog(struct thread_data *td);
251 extern void log_io_piece(struct thread_data *, struct io_u *);
252 extern void unlog_io_piece(struct thread_data *, struct io_u *);
253 extern void trim_io_piece(const struct io_u *);
254 extern void queue_io_piece(struct thread_data *, struct io_piece *);
255 extern void prune_io_piece_log(struct thread_data *);
256 extern void write_iolog_close(struct thread_data *);
257 extern int iolog_compress_init(struct thread_data *, struct sk_out *);
258 extern void iolog_compress_exit(struct thread_data *);
259 extern size_t log_chunk_sizes(struct io_log *);
260 extern int init_io_u_buffers(struct thread_data *);
263 extern int iolog_file_inflate(const char *);
270 struct thread_data *td;
271 unsigned long avg_msec;
272 unsigned long hist_msec;
282 static inline bool per_unit_log(struct io_log *log)
284 return log && (!log->avg_msec || log->log_gz || log->log_gz_store);
287 static inline bool inline_log(struct io_log *log)
289 return log->log_type == IO_LOG_TYPE_LAT ||
290 log->log_type == IO_LOG_TYPE_CLAT ||
291 log->log_type == IO_LOG_TYPE_SLAT;
294 static inline void ipo_bytes_align(unsigned int replay_align, struct io_piece *ipo)
299 ipo->offset &= ~(replay_align - (uint64_t)1);
302 extern void finalize_logs(struct thread_data *td, bool);
303 extern void setup_log(struct io_log **, struct log_params *, const char *);
304 extern void flush_log(struct io_log *, bool);
305 extern void flush_samples(FILE *, void *, uint64_t);
306 extern uint64_t hist_sum(int, int, uint64_t *, uint64_t *);
307 extern void free_log(struct io_log *);
308 extern void fio_writeout_logs(bool);
309 extern void td_writeout_logs(struct thread_data *, bool);
310 extern int iolog_cur_flush(struct io_log *, struct io_logs *);
312 static inline void init_ipo(struct io_piece *ipo)
314 INIT_FLIST_HEAD(&ipo->list);
315 INIT_FLIST_HEAD(&ipo->trim_list);
318 struct iolog_compress {
319 struct flist_head list;