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 IO_LOG_SAMPLE_AVG = 0,
35 struct io_sample_value {
40 union io_sample_data {
41 struct io_sample_value val;
42 struct io_u_plat_entry *plat_entry;
45 #define sample_val(value) ((union io_sample_data) { .val.val0 = value })
46 #define sample_plat(plat) ((union io_sample_data) { .plat_entry = plat })
49 * A single data sample
53 union io_sample_data data;
61 * Enumerate indexes of auxiliary log data in struct io_sample aux[] array
65 IOS_AUX_ISSUE_TIME_INDEX,
77 #define DEF_LOG_ENTRIES 1024
78 #define MAX_LOG_ENTRIES (1024 * DEF_LOG_ENTRIES)
81 struct flist_head list;
88 * Dynamically growing data sample log
92 * Entries already logged
94 struct flist_head io_logs;
98 * When the current log runs out of space, store events here until
99 * we have a chance to regrow
101 struct io_logs *pending;
103 unsigned int log_ddir_mask;
107 struct thread_data *td;
109 unsigned int log_type;
112 * If we fail extending the log, stop collecting more entries.
119 unsigned int log_offset;
124 unsigned int log_prio;
127 * Log I/O issuing time
129 unsigned int log_issue_time;
132 * Max size of log entries before a chunk is compressed
137 * Don't deflate for storing, just store the compressed bits
139 unsigned int log_gz_store;
142 * Windowed average, for logging single entries average over some
145 struct io_stat avg_window[DDIR_RWDIR_CNT];
146 unsigned long avg_msec;
147 unsigned long avg_last[DDIR_RWDIR_CNT];
150 * Windowed latency histograms, for keeping track of when we need to
151 * save a copy of the histogram every approximately hist_msec
154 struct io_hist hist_window[DDIR_RWDIR_CNT];
155 unsigned long hist_msec;
156 unsigned int hist_coarseness;
158 pthread_mutex_t chunk_lock;
159 unsigned int chunk_seq;
160 struct flist_head chunk_list;
162 pthread_mutex_t deferred_free_lock;
163 #define IOLOG_MAX_DEFER 8
164 void *deferred_items[IOLOG_MAX_DEFER];
165 unsigned int deferred;
169 * If the upper bit is set, then we have the offset as well
171 #define LOG_OFFSET_SAMPLE_BIT 0x80000000U
173 * If the bit following the upper bit is set, then we have the priority
175 #define LOG_PRIO_SAMPLE_BIT 0x40000000U
177 * If the bit following prioity sample vit is set, we report both avg and max
179 #define LOG_AVG_MAX_SAMPLE_BIT 0x20000000U
181 * If the bit following AVG_MAX_SAMPLE_BIT is set, we report the issue time also
183 #define LOG_ISSUE_TIME_SAMPLE_BIT 0x10000000U
185 #define LOG_SAMPLE_BITS (LOG_OFFSET_SAMPLE_BIT | LOG_PRIO_SAMPLE_BIT |\
186 LOG_AVG_MAX_SAMPLE_BIT |\
187 LOG_ISSUE_TIME_SAMPLE_BIT)
188 #define io_sample_ddir(io) ((io)->__ddir & ~LOG_SAMPLE_BITS)
190 static inline void io_sample_set_ddir(struct io_log *log,
191 struct io_sample *io,
194 io->__ddir = ddir | log->log_ddir_mask;
197 static inline size_t __log_entry_sz(bool log_offset, bool log_issue_time)
199 size_t ret = sizeof(struct io_sample);
202 ret += sizeof(uint64_t);
205 ret += sizeof(uint64_t);
210 static inline size_t log_entry_sz(struct io_log *log)
212 return __log_entry_sz(log->log_offset, log->log_issue_time);
215 static inline size_t log_sample_sz(struct io_log *log, struct io_logs *cur_log)
217 return cur_log->nr_samples * log_entry_sz(log);
220 static inline struct io_sample *__get_sample(void *samples, bool log_offset,
224 uint64_t sample_offset = sample *
225 __log_entry_sz(log_offset, log_issue_time);
226 return (struct io_sample *) ((char *) samples + sample_offset);
229 struct io_logs *iolog_cur_log(struct io_log *);
230 uint64_t iolog_nr_samples(struct io_log *);
231 void regrow_logs(struct thread_data *);
232 void regrow_agg_logs(void);
234 static inline struct io_sample *get_sample(struct io_log *iolog,
235 struct io_logs *cur_log,
238 return __get_sample(cur_log->log,
239 iolog->log_offset, iolog->log_issue_time, sample);
250 * When logging io actions, this matches a single sent io_u
254 struct fio_rb_node rb_node;
255 struct flist_head list;
257 struct flist_head trim_list;
260 struct fio_file *file;
262 unsigned long long offset;
263 unsigned short numberio;
268 unsigned int file_action;
282 extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
283 extern void log_io_u(const struct thread_data *, const struct io_u *);
284 extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
285 extern bool __must_check init_iolog(struct thread_data *td);
286 extern void log_io_piece(struct thread_data *, struct io_u *);
287 extern void unlog_io_piece(struct thread_data *, struct io_u *);
288 extern void trim_io_piece(const struct io_u *);
289 extern void queue_io_piece(struct thread_data *, struct io_piece *);
290 extern void prune_io_piece_log(struct thread_data *);
291 extern void write_iolog_close(struct thread_data *);
292 int64_t iolog_items_to_fetch(struct thread_data *td);
293 extern int iolog_compress_init(struct thread_data *, struct sk_out *);
294 extern void iolog_compress_exit(struct thread_data *);
295 extern size_t log_chunk_sizes(struct io_log *);
296 extern int init_io_u_buffers(struct thread_data *);
297 extern unsigned long long delay_since_ttime(const struct thread_data *,
301 extern int iolog_file_inflate(const char *);
308 struct thread_data *td;
309 unsigned long avg_msec;
310 unsigned long hist_msec;
321 static inline bool per_unit_log(struct io_log *log)
323 return log && (!log->avg_msec || log->log_gz || log->log_gz_store);
326 static inline bool inline_log(struct io_log *log)
328 return log->log_type == IO_LOG_TYPE_LAT ||
329 log->log_type == IO_LOG_TYPE_CLAT ||
330 log->log_type == IO_LOG_TYPE_SLAT;
333 static inline void ipo_bytes_align(unsigned int replay_align, struct io_piece *ipo)
338 ipo->offset &= ~(replay_align - (uint64_t)1);
341 extern void finalize_logs(struct thread_data *td, bool);
342 extern void setup_log(struct io_log **, struct log_params *, const char *);
343 extern void flush_log(struct io_log *, bool);
344 extern void flush_samples(FILE *, void *, uint64_t);
345 extern uint64_t hist_sum(int, int, uint64_t *, uint64_t *);
346 extern void free_log(struct io_log *);
347 extern void fio_writeout_logs(bool);
348 extern void td_writeout_logs(struct thread_data *, bool);
349 extern int iolog_cur_flush(struct io_log *, struct io_logs *);
351 static inline void init_ipo(struct io_piece *ipo)
353 INIT_FLIST_HEAD(&ipo->list);
354 INIT_FLIST_HEAD(&ipo->trim_list);
357 struct iolog_compress {
358 struct flist_head list;