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