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