Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 1 | #ifndef FIO_IOLOG_H |
| 2 | #define FIO_IOLOG_H |
| 3 | |
Jens Axboe | 0577543 | 2012-03-21 14:07:11 +0100 | [diff] [blame] | 4 | #include "lib/rbtree.h" |
Jens Axboe | c7c6cb4 | 2011-10-13 14:12:40 +0200 | [diff] [blame] | 5 | #include "lib/ieee754.h" |
Jens Axboe | 836fcc0 | 2013-01-24 09:08:45 -0700 | [diff] [blame] | 6 | #include "flist.h" |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 7 | #include "ioengines.h" |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 8 | |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 9 | /* |
| 10 | * Use for maintaining statistics |
| 11 | */ |
| 12 | struct io_stat { |
Jens Axboe | 7b9f733 | 2011-10-03 10:06:44 +0200 | [diff] [blame] | 13 | uint64_t max_val; |
| 14 | uint64_t min_val; |
| 15 | uint64_t samples; |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 16 | |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 17 | fio_fp64_t mean; |
| 18 | fio_fp64_t S; |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 19 | }; |
| 20 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 21 | struct io_hist { |
| 22 | uint64_t samples; |
| 23 | unsigned long hist_last; |
| 24 | struct flist_head list; |
| 25 | }; |
| 26 | |
| 27 | |
| 28 | union 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 | |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 36 | /* |
| 37 | * A single data sample |
| 38 | */ |
| 39 | struct io_sample { |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 40 | uint64_t time; |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 41 | union io_sample_data data; |
Jens Axboe | bac4af1 | 2014-07-03 13:42:28 -0600 | [diff] [blame] | 42 | uint32_t __ddir; |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 43 | uint32_t bs; |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 44 | }; |
| 45 | |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 46 | struct io_sample_offset { |
| 47 | struct io_sample s; |
| 48 | uint64_t offset; |
| 49 | }; |
| 50 | |
Jens Axboe | ea51b95 | 2012-03-14 11:39:13 +0100 | [diff] [blame] | 51 | enum { |
| 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, |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 57 | IO_LOG_TYPE_HIST, |
| 58 | }; |
| 59 | |
| 60 | #define DEF_LOG_ENTRIES 1024 |
| 61 | #define MAX_LOG_ENTRIES (1024 * DEF_LOG_ENTRIES) |
| 62 | |
| 63 | struct io_logs { |
| 64 | struct flist_head list; |
| 65 | uint64_t nr_samples; |
| 66 | uint64_t max_samples; |
| 67 | void *log; |
Jens Axboe | ea51b95 | 2012-03-14 11:39:13 +0100 | [diff] [blame] | 68 | }; |
| 69 | |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 70 | /* |
| 71 | * Dynamically growing data sample log |
| 72 | */ |
| 73 | struct io_log { |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 74 | /* |
| 75 | * Entries already logged |
| 76 | */ |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 77 | struct flist_head io_logs; |
| 78 | uint32_t cur_log_max; |
| 79 | |
| 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; |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 85 | |
Jens Axboe | bac4af1 | 2014-07-03 13:42:28 -0600 | [diff] [blame] | 86 | unsigned int log_ddir_mask; |
| 87 | |
Jens Axboe | 987c4f4 | 2014-07-01 16:29:12 -0600 | [diff] [blame] | 88 | char *filename; |
| 89 | |
Jens Axboe | 38a812d | 2014-07-03 09:10:39 -0600 | [diff] [blame] | 90 | struct thread_data *td; |
| 91 | |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 92 | unsigned int log_type; |
Jens Axboe | ea51b95 | 2012-03-14 11:39:13 +0100 | [diff] [blame] | 93 | |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 94 | /* |
Jens Axboe | 3c56823 | 2013-09-30 12:17:34 -0600 | [diff] [blame] | 95 | * If we fail extending the log, stop collecting more entries. |
| 96 | */ |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 97 | bool disabled; |
Jens Axboe | 3c56823 | 2013-09-30 12:17:34 -0600 | [diff] [blame] | 98 | |
| 99 | /* |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 100 | * Log offsets |
| 101 | */ |
| 102 | unsigned int log_offset; |
| 103 | |
| 104 | /* |
Jens Axboe | 38a812d | 2014-07-03 09:10:39 -0600 | [diff] [blame] | 105 | * Max size of log entries before a chunk is compressed |
| 106 | */ |
| 107 | unsigned int log_gz; |
| 108 | |
| 109 | /* |
Jens Axboe | bac4af1 | 2014-07-03 13:42:28 -0600 | [diff] [blame] | 110 | * Don't deflate for storing, just store the compressed bits |
| 111 | */ |
| 112 | unsigned int log_gz_store; |
| 113 | |
| 114 | /* |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 115 | * Windowed average, for logging single entries average over some |
| 116 | * period of time. |
| 117 | */ |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 118 | struct io_stat avg_window[DDIR_RWDIR_CNT]; |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 119 | unsigned long avg_msec; |
| 120 | unsigned long avg_last; |
Jens Axboe | 38a812d | 2014-07-03 09:10:39 -0600 | [diff] [blame] | 121 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 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 | */ |
| 127 | struct io_hist hist_window[DDIR_RWDIR_CNT]; |
| 128 | unsigned long hist_msec; |
| 129 | unsigned int hist_coarseness; |
| 130 | |
Jens Axboe | 38a812d | 2014-07-03 09:10:39 -0600 | [diff] [blame] | 131 | pthread_mutex_t chunk_lock; |
| 132 | unsigned int chunk_seq; |
| 133 | struct flist_head chunk_list; |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 134 | }; |
| 135 | |
Jens Axboe | 238934c | 2014-07-03 18:01:11 -0600 | [diff] [blame] | 136 | /* |
| 137 | * If the upper bit is set, then we have the offset as well |
| 138 | */ |
| 139 | #define LOG_OFFSET_SAMPLE_BIT 0x80000000U |
| 140 | #define io_sample_ddir(io) ((io)->__ddir & ~LOG_OFFSET_SAMPLE_BIT) |
Jens Axboe | bac4af1 | 2014-07-03 13:42:28 -0600 | [diff] [blame] | 141 | |
| 142 | static inline void io_sample_set_ddir(struct io_log *log, |
| 143 | struct io_sample *io, |
| 144 | enum fio_ddir ddir) |
| 145 | { |
| 146 | io->__ddir = ddir | log->log_ddir_mask; |
| 147 | } |
| 148 | |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 149 | static inline size_t __log_entry_sz(int log_offset) |
| 150 | { |
| 151 | if (log_offset) |
| 152 | return sizeof(struct io_sample_offset); |
| 153 | else |
| 154 | return sizeof(struct io_sample); |
| 155 | } |
| 156 | |
| 157 | static inline size_t log_entry_sz(struct io_log *log) |
| 158 | { |
| 159 | return __log_entry_sz(log->log_offset); |
| 160 | } |
| 161 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 162 | static inline size_t log_sample_sz(struct io_log *log, struct io_logs *cur_log) |
| 163 | { |
| 164 | return cur_log->nr_samples * log_entry_sz(log); |
| 165 | } |
| 166 | |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 167 | static inline struct io_sample *__get_sample(void *samples, int log_offset, |
| 168 | uint64_t sample) |
| 169 | { |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 170 | uint64_t sample_offset = sample * __log_entry_sz(log_offset); |
| 171 | return (struct io_sample *) ((char *) samples + sample_offset); |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 172 | } |
| 173 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 174 | struct io_logs *iolog_cur_log(struct io_log *); |
| 175 | uint64_t iolog_nr_samples(struct io_log *); |
| 176 | void regrow_logs(struct thread_data *); |
| 177 | |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 178 | static inline struct io_sample *get_sample(struct io_log *iolog, |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 179 | struct io_logs *cur_log, |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 180 | uint64_t sample) |
| 181 | { |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 182 | return __get_sample(cur_log->log, iolog->log_offset, sample); |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 183 | } |
| 184 | |
Jens Axboe | 0d29de8 | 2010-09-01 13:54:15 +0200 | [diff] [blame] | 185 | enum { |
| 186 | IP_F_ONRB = 1, |
| 187 | IP_F_ONLIST = 2, |
| 188 | IP_F_TRIMMED = 4, |
Jens Axboe | f940128 | 2014-02-06 12:17:37 -0700 | [diff] [blame] | 189 | IP_F_IN_FLIGHT = 8, |
Jens Axboe | 0d29de8 | 2010-09-01 13:54:15 +0200 | [diff] [blame] | 190 | }; |
| 191 | |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 192 | /* |
| 193 | * When logging io actions, this matches a single sent io_u |
| 194 | */ |
| 195 | struct io_piece { |
| 196 | union { |
| 197 | struct rb_node rb_node; |
| 198 | struct flist_head list; |
| 199 | }; |
Jens Axboe | 0d29de8 | 2010-09-01 13:54:15 +0200 | [diff] [blame] | 200 | struct flist_head trim_list; |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 201 | union { |
| 202 | int fileno; |
| 203 | struct fio_file *file; |
| 204 | }; |
| 205 | unsigned long long offset; |
Juan Casse | da0a7bd | 2013-09-17 14:06:12 -0700 | [diff] [blame] | 206 | unsigned short numberio; |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 207 | unsigned long len; |
Jens Axboe | a917a8b | 2010-09-02 13:23:20 +0200 | [diff] [blame] | 208 | unsigned int flags; |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 209 | enum fio_ddir ddir; |
| 210 | union { |
| 211 | unsigned long delay; |
| 212 | unsigned int file_action; |
| 213 | }; |
| 214 | }; |
| 215 | |
| 216 | /* |
| 217 | * Log exports |
| 218 | */ |
| 219 | enum file_log_act { |
| 220 | FIO_LOG_ADD_FILE, |
| 221 | FIO_LOG_OPEN_FILE, |
| 222 | FIO_LOG_CLOSE_FILE, |
| 223 | FIO_LOG_UNLINK_FILE, |
| 224 | }; |
| 225 | |
Jens Axboe | 8062f52 | 2013-04-10 15:01:42 +0200 | [diff] [blame] | 226 | struct io_u; |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 227 | extern int __must_check read_iolog_get(struct thread_data *, struct io_u *); |
Jens Axboe | 0cbbc39 | 2014-09-30 16:04:12 -0600 | [diff] [blame] | 228 | extern void log_io_u(const struct thread_data *, const struct io_u *); |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 229 | extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act); |
| 230 | extern int __must_check init_iolog(struct thread_data *td); |
| 231 | extern void log_io_piece(struct thread_data *, struct io_u *); |
Jens Axboe | 890b665 | 2014-05-06 19:06:51 -0600 | [diff] [blame] | 232 | extern void unlog_io_piece(struct thread_data *, struct io_u *); |
Jens Axboe | 0cbbc39 | 2014-09-30 16:04:12 -0600 | [diff] [blame] | 233 | extern void trim_io_piece(struct thread_data *, const struct io_u *); |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 234 | extern void queue_io_piece(struct thread_data *, struct io_piece *); |
| 235 | extern void prune_io_piece_log(struct thread_data *); |
| 236 | extern void write_iolog_close(struct thread_data *); |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 237 | extern int iolog_compress_init(struct thread_data *, struct sk_out *); |
| 238 | extern void iolog_compress_exit(struct thread_data *); |
| 239 | extern size_t log_chunk_sizes(struct io_log *); |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 240 | |
Jens Axboe | bac4af1 | 2014-07-03 13:42:28 -0600 | [diff] [blame] | 241 | #ifdef CONFIG_ZLIB |
| 242 | extern int iolog_file_inflate(const char *); |
| 243 | #endif |
| 244 | |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 245 | /* |
| 246 | * Logging |
| 247 | */ |
Jens Axboe | 38a812d | 2014-07-03 09:10:39 -0600 | [diff] [blame] | 248 | struct log_params { |
| 249 | struct thread_data *td; |
| 250 | unsigned long avg_msec; |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 251 | unsigned long hist_msec; |
| 252 | int hist_coarseness; |
Jens Axboe | 38a812d | 2014-07-03 09:10:39 -0600 | [diff] [blame] | 253 | int log_type; |
| 254 | int log_offset; |
| 255 | int log_gz; |
Jens Axboe | bac4af1 | 2014-07-03 13:42:28 -0600 | [diff] [blame] | 256 | int log_gz_store; |
Jens Axboe | 38a812d | 2014-07-03 09:10:39 -0600 | [diff] [blame] | 257 | int log_compress; |
| 258 | }; |
| 259 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 260 | static inline bool per_unit_log(struct io_log *log) |
| 261 | { |
| 262 | return log && !log->avg_msec; |
| 263 | } |
| 264 | |
| 265 | static inline bool inline_log(struct io_log *log) |
| 266 | { |
| 267 | return log->log_type == IO_LOG_TYPE_LAT || |
| 268 | log->log_type == IO_LOG_TYPE_CLAT || |
| 269 | log->log_type == IO_LOG_TYPE_SLAT; |
| 270 | } |
| 271 | |
| 272 | static inline void ipo_bytes_align(unsigned int replay_align, struct io_piece *ipo) |
| 273 | { |
| 274 | if (!replay_align) |
| 275 | return; |
| 276 | |
| 277 | ipo->offset &= ~(replay_align - (uint64_t)1); |
| 278 | } |
| 279 | |
| 280 | extern void finalize_logs(struct thread_data *td, bool); |
Jens Axboe | 38a812d | 2014-07-03 09:10:39 -0600 | [diff] [blame] | 281 | extern void setup_log(struct io_log **, struct log_params *, const char *); |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 282 | extern void flush_log(struct io_log *, bool); |
| 283 | extern void flush_samples(FILE *, void *, uint64_t); |
| 284 | extern unsigned long hist_sum(int, int, unsigned int *, unsigned int *); |
Jens Axboe | 633d825 | 2014-07-02 13:36:34 -0600 | [diff] [blame] | 285 | extern void free_log(struct io_log *); |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 286 | extern void fio_writeout_logs(bool); |
| 287 | extern void td_writeout_logs(struct thread_data *, bool); |
| 288 | extern int iolog_cur_flush(struct io_log *, struct io_logs *); |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 289 | |
Jens Axboe | 0d29de8 | 2010-09-01 13:54:15 +0200 | [diff] [blame] | 290 | static inline void init_ipo(struct io_piece *ipo) |
| 291 | { |
| 292 | memset(ipo, 0, sizeof(*ipo)); |
| 293 | INIT_FLIST_HEAD(&ipo->trim_list); |
| 294 | } |
| 295 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 296 | struct iolog_compress { |
| 297 | struct flist_head list; |
| 298 | void *buf; |
| 299 | size_t len; |
| 300 | unsigned int seq; |
| 301 | }; |
| 302 | |
Jens Axboe | 5995a6a | 2009-06-03 08:53:28 +0200 | [diff] [blame] | 303 | #endif |