Commit | Line | Data |
---|---|---|
ebac4655 JA |
1 | #ifndef FIO_H |
2 | #define FIO_H | |
3 | ||
4 | #include <sched.h> | |
5 | #include <limits.h> | |
6 | #include <pthread.h> | |
7 | #include <sys/time.h> | |
8 | #include <sys/resource.h> | |
3c39a379 JA |
9 | #include <errno.h> |
10 | #include <stdlib.h> | |
11 | #include <stdio.h> | |
6d6f031f | 12 | #include <unistd.h> |
34cfcdaf | 13 | #include <string.h> |
214e1eca | 14 | #include <getopt.h> |
cd14cc10 | 15 | #include <inttypes.h> |
7101d9c2 | 16 | #include <assert.h> |
ebac4655 | 17 | |
317b95d0 | 18 | #include "compiler/compiler.h" |
01743ee1 | 19 | #include "flist.h" |
e2887563 | 20 | #include "fifo.h" |
4b87898e | 21 | #include "rbtree.h" |
317b95d0 JA |
22 | #include "arch/arch.h" |
23 | #include "os/os.h" | |
07739b57 | 24 | #include "mutex.h" |
a3d741fa JA |
25 | #include "log.h" |
26 | #include "debug.h" | |
d6aed795 JA |
27 | #include "file.h" |
28 | #include "io_ddir.h" | |
dcefb588 | 29 | #include "ioengine.h" |
ebac4655 | 30 | |
609342ff DL |
31 | #ifdef FIO_HAVE_GUASI |
32 | #include <guasi.h> | |
33 | #endif | |
34 | ||
417f0068 JA |
35 | #ifdef FIO_HAVE_SOLARISAIO |
36 | #include <sys/asynch.h> | |
37 | #endif | |
38 | ||
1c9e06ee JA |
39 | /* |
40 | * Use for maintaining statistics | |
41 | */ | |
ebac4655 | 42 | struct io_stat { |
ebac4655 JA |
43 | unsigned long max_val; |
44 | unsigned long min_val; | |
45 | unsigned long samples; | |
68704084 JA |
46 | |
47 | double mean; | |
48 | double S; | |
ebac4655 JA |
49 | }; |
50 | ||
1c9e06ee JA |
51 | /* |
52 | * A single data sample | |
53 | */ | |
ebac4655 JA |
54 | struct io_sample { |
55 | unsigned long time; | |
56 | unsigned long val; | |
1e97cce9 | 57 | enum fio_ddir ddir; |
306ddc97 | 58 | unsigned int bs; |
ebac4655 JA |
59 | }; |
60 | ||
1c9e06ee JA |
61 | /* |
62 | * Dynamically growing data sample log | |
63 | */ | |
ebac4655 JA |
64 | struct io_log { |
65 | unsigned long nr_samples; | |
66 | unsigned long max_samples; | |
67 | struct io_sample *log; | |
68 | }; | |
69 | ||
1c9e06ee JA |
70 | /* |
71 | * When logging io actions, this matches a single sent io_u | |
72 | */ | |
ebac4655 | 73 | struct io_piece { |
4b87898e JA |
74 | union { |
75 | struct rb_node rb_node; | |
01743ee1 | 76 | struct flist_head list; |
4b87898e | 77 | }; |
f29b25a3 JA |
78 | union { |
79 | int fileno; | |
80 | struct fio_file *file; | |
81 | }; | |
ebac4655 | 82 | unsigned long long offset; |
a4f4fdd7 | 83 | unsigned long len; |
1e97cce9 | 84 | enum fio_ddir ddir; |
f29b25a3 JA |
85 | union { |
86 | unsigned long delay; | |
87 | unsigned int file_action; | |
88 | }; | |
ebac4655 JA |
89 | }; |
90 | ||
ebac4655 | 91 | struct group_run_stats { |
9104f874 JA |
92 | unsigned long long max_run[2], min_run[2]; |
93 | unsigned long long max_bw[2], min_bw[2]; | |
e9b2a3fa | 94 | unsigned long long io_kb[2]; |
9104f874 | 95 | unsigned long long agg[2]; |
ebac4655 JA |
96 | }; |
97 | ||
e9c047a0 JA |
98 | /* |
99 | * What type of allocation to use for io buffers | |
100 | */ | |
101 | enum fio_memtype { | |
102 | MEM_MALLOC = 0, /* ordinary malloc */ | |
103 | MEM_SHM, /* use shared memory segments */ | |
74b025b0 | 104 | MEM_SHMHUGE, /* use shared memory segments with huge pages */ |
e9c047a0 | 105 | MEM_MMAP, /* use anonynomous mmap */ |
d0bdaf49 | 106 | MEM_MMAPHUGE, /* memory mapped huge file */ |
e9c047a0 JA |
107 | }; |
108 | ||
2866c82d | 109 | enum fio_ioengine_flags { |
1c9e06ee | 110 | FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */ |
ba0fbe10 JA |
111 | FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */ |
112 | FIO_DISKLESSIO = 1 << 2, /* no disk involved */ | |
0263882a | 113 | FIO_NOEXTEND = 1 << 3, /* engine can't extend file */ |
62d984e2 | 114 | FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */ |
b67740d3 | 115 | FIO_UNIDIR = 1 << 5, /* engine is uni-directional */ |
1f809d15 | 116 | FIO_NOIO = 1 << 6, /* thread does only pseudo IO */ |
ad830ed7 | 117 | FIO_SIGQUIT = 1 << 7, /* needs SIGQUIT to exit */ |
e9c047a0 JA |
118 | }; |
119 | ||
b2560f3c JA |
120 | /* |
121 | * How many depth levels to log | |
122 | */ | |
123 | #define FIO_IO_U_MAP_NR 8 | |
a9a18a3f JA |
124 | #define FIO_IO_U_LAT_U_NR 10 |
125 | #define FIO_IO_U_LAT_M_NR 12 | |
b2560f3c | 126 | |
079ad09b | 127 | struct thread_stat { |
756867bd JA |
128 | char *name; |
129 | char *verror; | |
130 | int error; | |
131 | int groupid; | |
132 | pid_t pid; | |
133 | char *description; | |
6586ee89 | 134 | int members; |
756867bd | 135 | |
079ad09b JA |
136 | struct io_log *slat_log; |
137 | struct io_log *clat_log; | |
138 | struct io_log *bw_log; | |
139 | ||
140 | /* | |
141 | * bandwidth and latency stats | |
142 | */ | |
143 | struct io_stat clat_stat[2]; /* completion latency */ | |
144 | struct io_stat slat_stat[2]; /* submission latency */ | |
145 | struct io_stat bw_stat[2]; /* bandwidth stats */ | |
146 | ||
147 | unsigned long long stat_io_bytes[2]; | |
148 | struct timeval stat_sample_time[2]; | |
149 | ||
150 | /* | |
151 | * fio system usage accounting | |
152 | */ | |
153 | struct rusage ru_start; | |
154 | struct rusage ru_end; | |
155 | unsigned long usr_time; | |
156 | unsigned long sys_time; | |
157 | unsigned long ctx; | |
81887d5d | 158 | unsigned long minf, majf; |
079ad09b | 159 | |
b2560f3c JA |
160 | /* |
161 | * IO depth and latency stats | |
162 | */ | |
163 | unsigned int io_u_map[FIO_IO_U_MAP_NR]; | |
838bc709 JA |
164 | unsigned int io_u_submit[FIO_IO_U_MAP_NR]; |
165 | unsigned int io_u_complete[FIO_IO_U_MAP_NR]; | |
04a0feae JA |
166 | unsigned int io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
167 | unsigned int io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
b3605062 | 168 | unsigned long total_io_u[2]; |
30061b97 | 169 | unsigned long short_io_u[2]; |
838bc709 JA |
170 | unsigned long total_submit; |
171 | unsigned long total_complete; | |
756867bd JA |
172 | |
173 | unsigned long long io_bytes[2]; | |
174 | unsigned long runtime[2]; | |
175 | unsigned long total_run_time; | |
b2560f3c | 176 | }; |
71619dc2 | 177 | |
564ca972 JA |
178 | struct bssplit { |
179 | unsigned int bs; | |
180 | unsigned char perc; | |
181 | }; | |
182 | ||
2dc1bbeb | 183 | struct thread_options { |
b1ec1da6 | 184 | int pad; |
61697c37 | 185 | char *description; |
b4692828 | 186 | char *name; |
ef899b63 | 187 | char *directory; |
13f8e2d2 | 188 | char *filename; |
2dc1bbeb | 189 | char *opendir; |
09629a90 | 190 | char *ioengine; |
413dd459 | 191 | enum td_ddir td_ddir; |
211097b2 | 192 | unsigned int ddir_nr; |
2dc1bbeb JA |
193 | unsigned int iodepth; |
194 | unsigned int iodepth_low; | |
195 | unsigned int iodepth_batch; | |
4950421a | 196 | unsigned int iodepth_batch_complete; |
2dc1bbeb JA |
197 | |
198 | unsigned long long size; | |
aa31f1f1 | 199 | unsigned int fill_device; |
2dc1bbeb JA |
200 | unsigned long long file_size_low; |
201 | unsigned long long file_size_high; | |
202 | unsigned long long start_offset; | |
203 | ||
204 | unsigned int bs[2]; | |
2b7a01d0 | 205 | unsigned int ba[2]; |
2dc1bbeb JA |
206 | unsigned int min_bs[2]; |
207 | unsigned int max_bs[2]; | |
720e84ad JA |
208 | struct bssplit *bssplit[2]; |
209 | unsigned int bssplit_nr[2]; | |
2dc1bbeb JA |
210 | |
211 | unsigned int nr_files; | |
212 | unsigned int open_files; | |
4d4e80f2 | 213 | enum file_lock_mode file_lock_mode; |
29c1349f | 214 | unsigned int lockfile_batch; |
e9c047a0 | 215 | |
9158d2f7 JA |
216 | unsigned int odirect; |
217 | unsigned int invalidate_cache; | |
218 | unsigned int create_serialize; | |
219 | unsigned int create_fsync; | |
814452bd | 220 | unsigned int create_on_open; |
9158d2f7 | 221 | unsigned int end_fsync; |
afad68f7 | 222 | unsigned int pre_read; |
9158d2f7 JA |
223 | unsigned int sync_io; |
224 | unsigned int verify; | |
e84c73a8 | 225 | unsigned int do_verify; |
160b966d | 226 | unsigned int verifysort; |
a59e170d JA |
227 | unsigned int verify_interval; |
228 | unsigned int verify_offset; | |
90059d65 JA |
229 | unsigned int verify_pattern; |
230 | unsigned int verify_pattern_bytes; | |
a12a3b4d | 231 | unsigned int verify_fatal; |
9158d2f7 JA |
232 | unsigned int use_thread; |
233 | unsigned int unlink; | |
234 | unsigned int do_disk_util; | |
235 | unsigned int override_sync; | |
236 | unsigned int rand_repeatable; | |
237 | unsigned int write_lat_log; | |
238 | unsigned int write_bw_log; | |
bb8895e0 | 239 | unsigned int norandommap; |
2b386d25 | 240 | unsigned int softrandommap; |
690adba3 | 241 | unsigned int bs_unaligned; |
ebb1415f | 242 | unsigned int fsync_on_close; |
e9c047a0 | 243 | |
56bb17f2 | 244 | unsigned int hugepage_size; |
a00735e6 | 245 | unsigned int rw_min_bs; |
ebac4655 | 246 | unsigned int thinktime; |
48097d5c | 247 | unsigned int thinktime_spin; |
9c1f7434 | 248 | unsigned int thinktime_blocks; |
ebac4655 JA |
249 | unsigned int fsync_blocks; |
250 | unsigned int start_delay; | |
0db26797 | 251 | unsigned long long timeout; |
721938ae | 252 | unsigned long long ramp_time; |
ebac4655 | 253 | unsigned int overwrite; |
ebac4655 | 254 | unsigned int bw_avg_time; |
ebac4655 | 255 | unsigned int loops; |
20dc95c4 JA |
256 | unsigned long long zone_size; |
257 | unsigned long long zone_skip; | |
e9c047a0 | 258 | enum fio_memtype mem_type; |
2dc1bbeb | 259 | |
ebac4655 | 260 | unsigned int stonewall; |
b3d62a75 | 261 | unsigned int new_group; |
ebac4655 | 262 | unsigned int numjobs; |
ebac4655 | 263 | os_cpu_mask_t cpumask; |
375b2695 | 264 | unsigned int cpumask_set; |
aea47d44 | 265 | unsigned int iolog; |
a6ccc7be | 266 | unsigned int rwmixcycle; |
e47f799f | 267 | unsigned int rwmix[2]; |
b6f4d880 | 268 | unsigned int nice; |
0aabe160 | 269 | unsigned int file_service_type; |
b2560f3c | 270 | unsigned int group_reporting; |
d2f3ac35 | 271 | unsigned int fadvise_hint; |
e9459e5a | 272 | unsigned int zero_buffers; |
5973cafb | 273 | unsigned int refill_buffers; |
cf4464ca | 274 | unsigned int time_based; |
9520ebb9 JA |
275 | unsigned int disable_clat; |
276 | unsigned int disable_slat; | |
277 | unsigned int disable_bw; | |
993bf48b | 278 | unsigned int gtod_reduce; |
be4ecfdf JA |
279 | unsigned int gtod_cpu; |
280 | unsigned int gtod_offload; | |
aea47d44 | 281 | |
076efc7c JA |
282 | char *read_iolog_file; |
283 | char *write_iolog_file; | |
e3cedca7 JA |
284 | char *bw_log_file; |
285 | char *lat_log_file; | |
2dc1bbeb JA |
286 | |
287 | /* | |
288 | * Pre-run and post-run shell | |
289 | */ | |
290 | char *exec_prerun; | |
291 | char *exec_postrun; | |
292 | ||
293 | unsigned int rate; | |
294 | unsigned int ratemin; | |
295 | unsigned int ratecycle; | |
296 | unsigned int rate_iops; | |
297 | unsigned int rate_iops_min; | |
298 | ||
299 | char *ioscheduler; | |
300 | ||
301 | /* | |
302 | * CPU "io" cycle burner | |
303 | */ | |
304 | unsigned int cpuload; | |
305 | unsigned int cpucycle; | |
306 | }; | |
307 | ||
e4e33258 JA |
308 | #define FIO_VERROR_SIZE 128 |
309 | ||
2dc1bbeb JA |
310 | /* |
311 | * This describes a single thread/process executing a fio job. | |
312 | */ | |
313 | struct thread_data { | |
314 | struct thread_options o; | |
e4e33258 | 315 | char verror[FIO_VERROR_SIZE]; |
2dc1bbeb JA |
316 | pthread_t thread; |
317 | int thread_number; | |
318 | int groupid; | |
319 | struct thread_stat ts; | |
126d65c6 | 320 | struct fio_file **files; |
dd87b2c9 | 321 | unsigned int files_size; |
2dc1bbeb JA |
322 | unsigned int files_index; |
323 | unsigned int nr_open_files; | |
1020a139 | 324 | unsigned int nr_done_files; |
2dc1bbeb JA |
325 | unsigned int nr_normal_files; |
326 | union { | |
327 | unsigned int next_file; | |
328 | os_random_state_t next_file_state; | |
329 | }; | |
330 | int error; | |
20e354ef | 331 | int done; |
2dc1bbeb JA |
332 | pid_t pid; |
333 | char *orig_buffer; | |
334 | size_t orig_buffer_size; | |
335 | volatile int terminate; | |
336 | volatile int runstate; | |
337 | unsigned int ioprio; | |
ac684785 | 338 | unsigned int ioprio_set; |
2dc1bbeb JA |
339 | unsigned int last_was_sync; |
340 | ||
341 | char *mmapfile; | |
342 | int mmapfd; | |
343 | ||
843a7413 JA |
344 | void *iolog_buf; |
345 | FILE *iolog_f; | |
ebac4655 | 346 | |
da86774e | 347 | char *sysfs_root; |
da86774e | 348 | |
5bfc35d7 JA |
349 | unsigned long rand_seeds[6]; |
350 | ||
6dfd46b9 JA |
351 | os_random_state_t bsrange_state; |
352 | os_random_state_t verify_state; | |
ebac4655 JA |
353 | |
354 | int shm_id; | |
355 | ||
e9c047a0 JA |
356 | /* |
357 | * IO engine hooks, contains everything needed to submit an io_u | |
358 | * to any of the available IO engines. | |
359 | */ | |
2866c82d | 360 | struct ioengine_ops *io_ops; |
ebac4655 | 361 | |
e9c047a0 JA |
362 | /* |
363 | * Current IO depth and list of free and busy io_u's. | |
364 | */ | |
ebac4655 | 365 | unsigned int cur_depth; |
d8005759 | 366 | unsigned int io_u_queued; |
01743ee1 JA |
367 | struct flist_head io_u_freelist; |
368 | struct flist_head io_u_busylist; | |
369 | struct flist_head io_u_requeues; | |
ebac4655 | 370 | |
e9c047a0 JA |
371 | /* |
372 | * Rate state | |
373 | */ | |
ebac4655 JA |
374 | unsigned long rate_usec_cycle; |
375 | long rate_pending_usleep; | |
376 | unsigned long rate_bytes; | |
4e991c23 | 377 | unsigned long rate_blocks; |
ebac4655 JA |
378 | struct timeval lastrate; |
379 | ||
ebac4655 JA |
380 | unsigned long long total_io_size; |
381 | ||
755200a3 | 382 | unsigned long io_issues[2]; |
9104f874 JA |
383 | unsigned long long io_blocks[2]; |
384 | unsigned long long io_bytes[2]; | |
48f5abd3 | 385 | unsigned long long io_skip_bytes; |
9104f874 | 386 | unsigned long long this_io_bytes[2]; |
079ad09b | 387 | unsigned long long zone_bytes; |
cdd18ad8 | 388 | struct fio_mutex *mutex; |
ebac4655 | 389 | |
e9c047a0 JA |
390 | /* |
391 | * State for random io, a bitmap of blocks done vs not done | |
392 | */ | |
6dfd46b9 | 393 | os_random_state_t random_state; |
ebac4655 | 394 | |
ebac4655 JA |
395 | struct timeval start; /* start of this loop */ |
396 | struct timeval epoch; /* time job was started */ | |
38d77cae | 397 | struct timeval rw_end[2]; |
a61eddec | 398 | struct timeval last_issue; |
993bf48b JA |
399 | struct timeval tv_cache; |
400 | unsigned int tv_cache_nr; | |
401 | unsigned int tv_cache_mask; | |
38d77cae | 402 | unsigned int rw_end_set[2]; |
721938ae | 403 | unsigned int ramp_time_over; |
ebac4655 | 404 | |
e9c047a0 JA |
405 | /* |
406 | * read/write mixed workload state | |
407 | */ | |
6dfd46b9 | 408 | os_random_state_t rwmix_state; |
e4928662 | 409 | unsigned long rwmix_issues; |
e9c047a0 | 410 | enum fio_ddir rwmix_ddir; |
211097b2 | 411 | unsigned int ddir_nr; |
a6ccc7be | 412 | |
e9c047a0 | 413 | /* |
8de8f047 JA |
414 | * IO history logs for verification. We use a tree for sorting, |
415 | * if we are overwriting. Otherwise just use a fifo. | |
e9c047a0 | 416 | */ |
4b87898e | 417 | struct rb_root io_hist_tree; |
01743ee1 | 418 | struct flist_head io_hist_list; |
8de8f047 JA |
419 | |
420 | /* | |
421 | * For IO replaying | |
422 | */ | |
01743ee1 | 423 | struct flist_head io_log_list; |
433afcb4 | 424 | |
1907dbc6 JA |
425 | /* |
426 | * for fileservice, how often to switch to a new file | |
427 | */ | |
428 | unsigned int file_service_nr; | |
429 | unsigned int file_service_left; | |
430 | struct fio_file *file_service_file; | |
9c60ce64 JA |
431 | |
432 | /* | |
433 | * For generating file sizes | |
434 | */ | |
435 | os_random_state_t file_size_state; | |
ebac4655 JA |
436 | }; |
437 | ||
0aabe160 | 438 | /* |
a086c257 JA |
439 | * roundrobin available files, or choose one at random, or do each one |
440 | * serially. | |
0aabe160 JA |
441 | */ |
442 | enum { | |
443 | FIO_FSERVICE_RANDOM = 1, | |
444 | FIO_FSERVICE_RR = 2, | |
a086c257 | 445 | FIO_FSERVICE_SEQ = 3, |
0aabe160 JA |
446 | }; |
447 | ||
e592a06b AC |
448 | /* |
449 | * when should interactive ETA output be generated | |
450 | */ | |
451 | enum { | |
452 | FIO_ETA_AUTO, | |
453 | FIO_ETA_ALWAYS, | |
454 | FIO_ETA_NEVER, | |
455 | }; | |
456 | ||
e1161c32 | 457 | #define __td_verror(td, err, msg, func) \ |
ebac4655 | 458 | do { \ |
19abcd3d JA |
459 | if ((td)->error) \ |
460 | break; \ | |
ebac4655 JA |
461 | int e = (err); \ |
462 | (td)->error = e; \ | |
e1161c32 | 463 | snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, func=%s, error=%s", __FILE__, __LINE__, (func), (msg)); \ |
ebac4655 JA |
464 | } while (0) |
465 | ||
b990b5c0 | 466 | |
e1161c32 JA |
467 | #define td_verror(td, err, func) \ |
468 | __td_verror((td), (err), strerror((err)), (func)) | |
469 | #define td_vmsg(td, err, msg, func) \ | |
470 | __td_verror((td), (err), (msg), (func)) | |
b990b5c0 | 471 | |
ebac4655 JA |
472 | extern int exitall_on_terminate; |
473 | extern int thread_number; | |
9cedf167 | 474 | extern int nr_process, nr_thread; |
ebac4655 JA |
475 | extern int shm_id; |
476 | extern int groupid; | |
c6ae0a5b | 477 | extern int terse_output; |
53cdc686 | 478 | extern int temp_stall_ts; |
1e97cce9 | 479 | extern unsigned long long mlock_size; |
cfc99db7 | 480 | extern unsigned long page_mask, page_size; |
4241ea8f | 481 | extern int read_only; |
e592a06b | 482 | extern int eta_print; |
d3eeeabc | 483 | extern unsigned long done_secs; |
01f06b63 | 484 | extern char *job_section; |
be4ecfdf JA |
485 | extern int fio_gtod_offload; |
486 | extern int fio_gtod_cpu; | |
ebac4655 JA |
487 | |
488 | extern struct thread_data *threads; | |
489 | ||
2dc1bbeb JA |
490 | #define td_read(td) ((td)->o.td_ddir & TD_DDIR_READ) |
491 | #define td_write(td) ((td)->o.td_ddir & TD_DDIR_WRITE) | |
492 | #define td_rw(td) (((td)->o.td_ddir & TD_DDIR_RW) == TD_DDIR_RW) | |
493 | #define td_random(td) ((td)->o.td_ddir & TD_DDIR_RAND) | |
303032ae | 494 | #define file_randommap(td, f) (!(td)->o.norandommap && (f)->file_map) |
ebac4655 | 495 | |
7101d9c2 JA |
496 | static inline void fio_ro_check(struct thread_data *td, struct io_u *io_u) |
497 | { | |
498 | assert(!(io_u->ddir == DDIR_WRITE && !td_write(td))); | |
499 | } | |
500 | ||
de605666 | 501 | #define BLOCKS_PER_MAP (8 * sizeof(int)) |
aec2de20 JA |
502 | #define TO_MAP_BLOCK(f, b) (b) |
503 | #define RAND_MAP_IDX(f, b) (TO_MAP_BLOCK(f, b) / BLOCKS_PER_MAP) | |
504 | #define RAND_MAP_BIT(f, b) (TO_MAP_BLOCK(f, b) & (BLOCKS_PER_MAP - 1)) | |
ebac4655 JA |
505 | |
506 | #define MAX_JOBS (1024) | |
507 | ||
87dc1ab1 JA |
508 | static inline int should_fsync(struct thread_data *td) |
509 | { | |
510 | if (td->last_was_sync) | |
511 | return 0; | |
2dc1bbeb | 512 | if (td->o.odirect) |
87dc1ab1 | 513 | return 0; |
2dc1bbeb | 514 | if (td_write(td) || td_rw(td) || td->o.override_sync) |
87dc1ab1 JA |
515 | return 1; |
516 | ||
517 | return 0; | |
518 | } | |
519 | ||
1c9e06ee JA |
520 | /* |
521 | * Disk utils as read in /sys/block/<dev>/stat | |
522 | */ | |
ebac4655 JA |
523 | struct disk_util_stat { |
524 | unsigned ios[2]; | |
525 | unsigned merges[2]; | |
526 | unsigned long long sectors[2]; | |
527 | unsigned ticks[2]; | |
528 | unsigned io_ticks; | |
529 | unsigned time_in_queue; | |
530 | }; | |
531 | ||
1c9e06ee JA |
532 | /* |
533 | * Per-device disk util management | |
534 | */ | |
ebac4655 | 535 | struct disk_util { |
01743ee1 | 536 | struct flist_head list; |
67423013 ST |
537 | /* If this disk is a slave, hook it into the master's |
538 | * list using this head. | |
539 | */ | |
540 | struct flist_head slavelist; | |
ebac4655 JA |
541 | |
542 | char *name; | |
e11c410c | 543 | char *sysfs_root; |
ebac4655 | 544 | char path[256]; |
07e5b264 | 545 | int major, minor; |
ebac4655 JA |
546 | |
547 | struct disk_util_stat dus; | |
548 | struct disk_util_stat last_dus; | |
549 | ||
67423013 ST |
550 | /* For software raids, this entry maintains pointers to the |
551 | * entries for the slave devices. The disk_util entries for | |
552 | * the slaves devices should primarily be maintained through | |
553 | * the disk_list list, i.e. for memory allocation and | |
554 | * de-allocation, etc. Whereas this list should be used only | |
555 | * for aggregating a software RAID's disk util figures. | |
556 | */ | |
557 | struct flist_head slaves; | |
558 | ||
ebac4655 JA |
559 | unsigned long msec; |
560 | struct timeval time; | |
c97bd0fa JA |
561 | |
562 | struct fio_mutex *lock; | |
563 | unsigned long users; | |
ebac4655 JA |
564 | }; |
565 | ||
c97bd0fa JA |
566 | static inline void disk_util_inc(struct disk_util *du) |
567 | { | |
568 | if (du) { | |
569 | fio_mutex_down(du->lock); | |
570 | du->users++; | |
571 | fio_mutex_up(du->lock); | |
572 | } | |
573 | } | |
574 | ||
575 | static inline void disk_util_dec(struct disk_util *du) | |
576 | { | |
577 | if (du) { | |
578 | fio_mutex_down(du->lock); | |
579 | du->users--; | |
580 | fio_mutex_up(du->lock); | |
581 | } | |
582 | } | |
583 | ||
ebac4655 JA |
584 | #define DISK_UTIL_MSEC (250) |
585 | ||
6796209a JA |
586 | /* |
587 | * Log exports | |
588 | */ | |
f29b25a3 JA |
589 | enum file_log_act { |
590 | FIO_LOG_ADD_FILE, | |
591 | FIO_LOG_OPEN_FILE, | |
592 | FIO_LOG_CLOSE_FILE, | |
f718273e | 593 | FIO_LOG_UNLINK_FILE, |
f29b25a3 JA |
594 | }; |
595 | ||
72cb971b | 596 | extern int __must_check read_iolog_get(struct thread_data *, struct io_u *); |
f29b25a3 JA |
597 | extern void log_io_u(struct thread_data *, struct io_u *); |
598 | extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act); | |
72cb971b | 599 | extern int __must_check init_iolog(struct thread_data *td); |
6796209a | 600 | extern void log_io_piece(struct thread_data *, struct io_u *); |
691c8fb0 | 601 | extern void queue_io_piece(struct thread_data *, struct io_piece *); |
6796209a JA |
602 | extern void prune_io_piece_log(struct thread_data *); |
603 | extern void write_iolog_close(struct thread_data *); | |
604 | ||
605 | /* | |
606 | * Logging | |
607 | */ | |
306ddc97 JA |
608 | extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long, |
609 | unsigned int); | |
610 | extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long, | |
611 | unsigned int); | |
612 | extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int, | |
613 | struct timeval *); | |
6796209a JA |
614 | extern void show_run_stats(void); |
615 | extern void init_disk_util(struct thread_data *); | |
616 | extern void update_rusage_stat(struct thread_data *); | |
617 | extern void update_io_ticks(void); | |
8914a9d8 JA |
618 | extern void setup_log(struct io_log **); |
619 | extern void finish_log(struct thread_data *, struct io_log *, const char *); | |
e3cedca7 | 620 | extern void finish_log_named(struct thread_data *, struct io_log *, const char *, const char *); |
bb3884d8 | 621 | extern void __finish_log(struct io_log *, const char *); |
bb3884d8 JA |
622 | extern struct io_log *agg_io_log[2]; |
623 | extern int write_bw_log; | |
306ddc97 | 624 | extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int); |
6796209a JA |
625 | |
626 | /* | |
627 | * Time functions | |
628 | */ | |
10927316 SL |
629 | extern unsigned long long utime_since(struct timeval *, struct timeval *); |
630 | extern unsigned long long utime_since_now(struct timeval *); | |
6796209a JA |
631 | extern unsigned long mtime_since(struct timeval *, struct timeval *); |
632 | extern unsigned long mtime_since_now(struct timeval *); | |
633 | extern unsigned long time_since_now(struct timeval *); | |
263e529f | 634 | extern unsigned long mtime_since_genesis(void); |
6dd6f2cd | 635 | extern void usec_spin(unsigned int); |
6796209a | 636 | extern void usec_sleep(struct thread_data *, unsigned long); |
413dd459 | 637 | extern void rate_throttle(struct thread_data *, unsigned long, unsigned int); |
6043c579 | 638 | extern void fill_start_time(struct timeval *); |
02bcaa8c | 639 | extern void fio_gettime(struct timeval *, void *); |
be4ecfdf JA |
640 | extern void fio_gtod_init(void); |
641 | extern void fio_gtod_update(void); | |
a2f77c9f | 642 | extern void set_genesis_time(void); |
721938ae | 643 | extern int ramp_time_over(struct thread_data *); |
b29ee5b3 | 644 | extern int in_ramp_time(struct thread_data *); |
6796209a | 645 | |
8914a9d8 | 646 | /* |
214e1eca | 647 | * Init/option functions |
8914a9d8 | 648 | */ |
72cb971b | 649 | extern int __must_check parse_options(int, char **); |
3b8b7135 | 650 | extern int fio_options_parse(struct thread_data *, char **, int); |
214e1eca JA |
651 | extern int fio_cmd_option_parse(struct thread_data *, const char *, char *); |
652 | extern void fio_fill_default_options(struct thread_data *); | |
653 | extern int fio_show_option_help(const char *); | |
654 | extern void fio_options_dup_and_init(struct option *); | |
d23bb327 JA |
655 | extern void options_mem_dupe(struct thread_data *); |
656 | extern void options_mem_free(struct thread_data *); | |
5bfc35d7 | 657 | extern void td_fill_rand_seeds(struct thread_data *); |
214e1eca JA |
658 | #define FIO_GETOPT_JOB 0x89988998 |
659 | #define FIO_NR_OPTIONS 128 | |
8914a9d8 | 660 | |
263e529f JA |
661 | /* |
662 | * ETA/status stuff | |
663 | */ | |
664 | extern void print_thread_status(void); | |
665 | extern void print_status_init(int); | |
666 | ||
9f8f2064 JA |
667 | /* |
668 | * disk util stuff | |
669 | */ | |
670 | #ifdef FIO_HAVE_DISK_UTIL | |
671 | extern void show_disk_util(void); | |
9f8f2064 JA |
672 | extern void init_disk_util(struct thread_data *); |
673 | extern void update_io_ticks(void); | |
674 | #else | |
675 | #define show_disk_util() | |
9f8f2064 JA |
676 | #define init_disk_util(td) |
677 | #define update_io_ticks() | |
678 | #endif | |
679 | ||
263e529f JA |
680 | /* |
681 | * Thread life cycle. Once a thread has a runstate beyond TD_INITIALIZED, it | |
682 | * will never back again. It may cycle between running/verififying/fsyncing. | |
683 | * Once the thread reaches TD_EXITED, it is just waiting for the core to | |
684 | * reap it. | |
685 | */ | |
686 | enum { | |
687 | TD_NOT_CREATED = 0, | |
688 | TD_CREATED, | |
689 | TD_INITIALIZED, | |
b29ee5b3 | 690 | TD_RAMP, |
263e529f | 691 | TD_RUNNING, |
b0f65863 | 692 | TD_PRE_READING, |
263e529f JA |
693 | TD_VERIFYING, |
694 | TD_FSYNCING, | |
695 | TD_EXITED, | |
696 | TD_REAPED, | |
697 | }; | |
698 | ||
b29ee5b3 JA |
699 | extern void td_set_runstate(struct thread_data *, int); |
700 | ||
2f9ade3c JA |
701 | /* |
702 | * Memory helpers | |
703 | */ | |
b2fdda43 | 704 | extern int __must_check fio_pin_memory(void); |
2f9ade3c | 705 | extern void fio_unpin_memory(void); |
b2fdda43 | 706 | extern int __must_check allocate_io_mem(struct thread_data *); |
2f9ade3c JA |
707 | extern void free_io_mem(struct thread_data *); |
708 | ||
b29ee5b3 JA |
709 | /* |
710 | * Reset stats after ramp time completes | |
711 | */ | |
712 | extern void reset_all_stats(struct thread_data *); | |
713 | ||
fb7b71a3 JA |
714 | /* |
715 | * blktrace support | |
716 | */ | |
5e62c22a | 717 | #ifdef FIO_HAVE_BLKTRACE |
fb7b71a3 JA |
718 | extern int is_blktrace(const char *); |
719 | extern int load_blktrace(struct thread_data *, const char *); | |
5e62c22a | 720 | #endif |
fb7b71a3 | 721 | |
2866c82d JA |
722 | /* |
723 | * Mark unused variables passed to ops functions as unused, to silence gcc | |
724 | */ | |
725 | #define fio_unused __attribute((__unused__)) | |
5f350952 JA |
726 | #define fio_init __attribute__((constructor)) |
727 | #define fio_exit __attribute__((destructor)) | |
2866c82d | 728 | |
34572e28 JA |
729 | #define for_each_td(td, i) \ |
730 | for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++) | |
53cdc686 | 731 | #define for_each_file(td, f, i) \ |
691c8fb0 JA |
732 | if ((td)->files_index) \ |
733 | for ((i) = 0, (f) = (td)->files[0]; \ | |
734 | (i) < (td)->o.nr_files && ((f) = (td)->files[i]) != NULL; \ | |
735 | (i)++) | |
53cdc686 | 736 | |
0032bf9f JA |
737 | #define fio_assert(td, cond) do { \ |
738 | if (!(cond)) { \ | |
340fd243 | 739 | int *__foo = NULL; \ |
0032bf9f JA |
740 | fprintf(stderr, "file:%s:%d, assert %s failed\n", __FILE__, __LINE__, #cond); \ |
741 | (td)->runstate = TD_EXITED; \ | |
437c9b71 | 742 | (td)->error = EFAULT; \ |
340fd243 | 743 | *__foo = 0; \ |
0032bf9f JA |
744 | } \ |
745 | } while (0) | |
746 | ||
009bd847 JA |
747 | static inline void fio_file_reset(struct fio_file *f) |
748 | { | |
749 | f->last_free_lookup = 0; | |
750 | f->last_pos = f->file_offset; | |
eaf9b417 JA |
751 | if (f->file_map) |
752 | memset(f->file_map, 0, f->num_maps * sizeof(int)); | |
009bd847 JA |
753 | } |
754 | ||
9bf27b45 JA |
755 | static inline void clear_error(struct thread_data *td) |
756 | { | |
757 | td->error = 0; | |
758 | td->verror[0] = '\0'; | |
759 | } | |
760 | ||
79e48f72 | 761 | #ifdef FIO_INC_DEBUG |
2ba1c290 JA |
762 | static inline void dprint_io_u(struct io_u *io_u, const char *p) |
763 | { | |
764 | struct fio_file *f = io_u->file; | |
765 | ||
766 | dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u, | |
5921e80c JA |
767 | (unsigned long long) io_u->offset, |
768 | io_u->buflen, io_u->ddir); | |
8172fe97 JA |
769 | if (fio_debug & (1 << FD_IO)) { |
770 | if (f) | |
771 | log_info("/%s", f->file_name); | |
772 | ||
773 | log_info("\n"); | |
774 | } | |
2ba1c290 | 775 | } |
79e48f72 | 776 | #else |
79e48f72 JA |
777 | #define dprint_io_u(io_u, p) |
778 | #endif | |
2ba1c290 | 779 | |
12d9d841 JA |
780 | static inline int fio_fill_issue_time(struct thread_data *td) |
781 | { | |
782 | if (td->o.read_iolog_file || | |
783 | !td->o.disable_clat || !td->o.disable_slat || !td->o.disable_bw) | |
784 | return 1; | |
785 | ||
786 | return 0; | |
787 | } | |
788 | ||
ebac4655 | 789 | #endif |