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> |
cd14cc10 | 14 | #include <inttypes.h> |
7101d9c2 | 15 | #include <assert.h> |
ebac4655 | 16 | |
ecc314ba BC |
17 | struct thread_data; |
18 | ||
317b95d0 | 19 | #include "compiler/compiler.h" |
01743ee1 | 20 | #include "flist.h" |
e2887563 | 21 | #include "fifo.h" |
4b87898e | 22 | #include "rbtree.h" |
317b95d0 JA |
23 | #include "arch/arch.h" |
24 | #include "os/os.h" | |
07739b57 | 25 | #include "mutex.h" |
a3d741fa JA |
26 | #include "log.h" |
27 | #include "debug.h" | |
d6aed795 JA |
28 | #include "file.h" |
29 | #include "io_ddir.h" | |
dcefb588 | 30 | #include "ioengine.h" |
5995a6a4 | 31 | #include "iolog.h" |
c5c8bd5c | 32 | #include "helpers.h" |
07b3232d | 33 | #include "options.h" |
7eb36574 | 34 | #include "profile.h" |
c223da83 | 35 | #include "time.h" |
bf2e821a | 36 | #include "lib/getopt.h" |
2615cc4b | 37 | #include "lib/rand.h" |
ebac4655 | 38 | |
609342ff DL |
39 | #ifdef FIO_HAVE_GUASI |
40 | #include <guasi.h> | |
41 | #endif | |
42 | ||
417f0068 JA |
43 | #ifdef FIO_HAVE_SOLARISAIO |
44 | #include <sys/asynch.h> | |
45 | #endif | |
46 | ||
ebac4655 | 47 | struct group_run_stats { |
9104f874 JA |
48 | unsigned long long max_run[2], min_run[2]; |
49 | unsigned long long max_bw[2], min_bw[2]; | |
e9b2a3fa | 50 | unsigned long long io_kb[2]; |
9104f874 | 51 | unsigned long long agg[2]; |
90fef2d1 | 52 | unsigned int kb_base; |
ebac4655 JA |
53 | }; |
54 | ||
e9c047a0 JA |
55 | /* |
56 | * What type of allocation to use for io buffers | |
57 | */ | |
58 | enum fio_memtype { | |
59 | MEM_MALLOC = 0, /* ordinary malloc */ | |
60 | MEM_SHM, /* use shared memory segments */ | |
74b025b0 | 61 | MEM_SHMHUGE, /* use shared memory segments with huge pages */ |
e9c047a0 | 62 | MEM_MMAP, /* use anonynomous mmap */ |
d0bdaf49 | 63 | MEM_MMAPHUGE, /* memory mapped huge file */ |
e9c047a0 JA |
64 | }; |
65 | ||
38dad62d JA |
66 | /* |
67 | * offset generator types | |
68 | */ | |
69 | enum { | |
70 | RW_SEQ_SEQ = 0, | |
71 | RW_SEQ_IDENT, | |
72 | }; | |
73 | ||
b2560f3c JA |
74 | /* |
75 | * How many depth levels to log | |
76 | */ | |
bb067558 | 77 | #define FIO_IO_U_MAP_NR 7 |
a9a18a3f JA |
78 | #define FIO_IO_U_LAT_U_NR 10 |
79 | #define FIO_IO_U_LAT_M_NR 12 | |
b2560f3c | 80 | |
0e92f873 RR |
81 | #define MAX_PATTERN_SIZE 512 |
82 | ||
079ad09b | 83 | struct thread_stat { |
756867bd JA |
84 | char *name; |
85 | char *verror; | |
86 | int error; | |
87 | int groupid; | |
88 | pid_t pid; | |
89 | char *description; | |
6586ee89 | 90 | int members; |
756867bd | 91 | |
079ad09b JA |
92 | struct io_log *slat_log; |
93 | struct io_log *clat_log; | |
02af0988 | 94 | struct io_log *lat_log; |
079ad09b JA |
95 | struct io_log *bw_log; |
96 | ||
97 | /* | |
98 | * bandwidth and latency stats | |
99 | */ | |
100 | struct io_stat clat_stat[2]; /* completion latency */ | |
101 | struct io_stat slat_stat[2]; /* submission latency */ | |
02af0988 | 102 | struct io_stat lat_stat[2]; /* total latency */ |
079ad09b JA |
103 | struct io_stat bw_stat[2]; /* bandwidth stats */ |
104 | ||
105 | unsigned long long stat_io_bytes[2]; | |
106 | struct timeval stat_sample_time[2]; | |
107 | ||
108 | /* | |
109 | * fio system usage accounting | |
110 | */ | |
111 | struct rusage ru_start; | |
112 | struct rusage ru_end; | |
113 | unsigned long usr_time; | |
114 | unsigned long sys_time; | |
115 | unsigned long ctx; | |
81887d5d | 116 | unsigned long minf, majf; |
079ad09b | 117 | |
b2560f3c JA |
118 | /* |
119 | * IO depth and latency stats | |
120 | */ | |
121 | unsigned int io_u_map[FIO_IO_U_MAP_NR]; | |
838bc709 JA |
122 | unsigned int io_u_submit[FIO_IO_U_MAP_NR]; |
123 | unsigned int io_u_complete[FIO_IO_U_MAP_NR]; | |
04a0feae JA |
124 | unsigned int io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
125 | unsigned int io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
0d29de83 JA |
126 | unsigned long total_io_u[3]; |
127 | unsigned long short_io_u[3]; | |
838bc709 JA |
128 | unsigned long total_submit; |
129 | unsigned long total_complete; | |
756867bd JA |
130 | |
131 | unsigned long long io_bytes[2]; | |
cda99fa0 | 132 | unsigned long long runtime[2]; |
756867bd | 133 | unsigned long total_run_time; |
f2bba182 RR |
134 | |
135 | /* | |
136 | * IO Error related stats | |
137 | */ | |
138 | unsigned continue_on_error; | |
139 | unsigned long total_err_count; | |
140 | int first_error; | |
90fef2d1 JA |
141 | |
142 | unsigned int kb_base; | |
b2560f3c | 143 | }; |
71619dc2 | 144 | |
564ca972 JA |
145 | struct bssplit { |
146 | unsigned int bs; | |
147 | unsigned char perc; | |
148 | }; | |
149 | ||
2dc1bbeb | 150 | struct thread_options { |
b1ec1da6 | 151 | int pad; |
61697c37 | 152 | char *description; |
b4692828 | 153 | char *name; |
ef899b63 | 154 | char *directory; |
13f8e2d2 | 155 | char *filename; |
2dc1bbeb | 156 | char *opendir; |
09629a90 | 157 | char *ioengine; |
413dd459 | 158 | enum td_ddir td_ddir; |
38dad62d | 159 | unsigned int rw_seq; |
90fef2d1 | 160 | unsigned int kb_base; |
5736c10d | 161 | unsigned int ddir_seq_nr; |
2dc1bbeb JA |
162 | unsigned int iodepth; |
163 | unsigned int iodepth_low; | |
164 | unsigned int iodepth_batch; | |
4950421a | 165 | unsigned int iodepth_batch_complete; |
2dc1bbeb JA |
166 | |
167 | unsigned long long size; | |
7bb59102 | 168 | unsigned int size_percent; |
aa31f1f1 | 169 | unsigned int fill_device; |
2dc1bbeb JA |
170 | unsigned long long file_size_low; |
171 | unsigned long long file_size_high; | |
172 | unsigned long long start_offset; | |
173 | ||
174 | unsigned int bs[2]; | |
2b7a01d0 | 175 | unsigned int ba[2]; |
2dc1bbeb JA |
176 | unsigned int min_bs[2]; |
177 | unsigned int max_bs[2]; | |
720e84ad JA |
178 | struct bssplit *bssplit[2]; |
179 | unsigned int bssplit_nr[2]; | |
2dc1bbeb JA |
180 | |
181 | unsigned int nr_files; | |
182 | unsigned int open_files; | |
4d4e80f2 | 183 | enum file_lock_mode file_lock_mode; |
29c1349f | 184 | unsigned int lockfile_batch; |
e9c047a0 | 185 | |
9158d2f7 JA |
186 | unsigned int odirect; |
187 | unsigned int invalidate_cache; | |
188 | unsigned int create_serialize; | |
189 | unsigned int create_fsync; | |
814452bd | 190 | unsigned int create_on_open; |
9158d2f7 | 191 | unsigned int end_fsync; |
afad68f7 | 192 | unsigned int pre_read; |
9158d2f7 JA |
193 | unsigned int sync_io; |
194 | unsigned int verify; | |
e84c73a8 | 195 | unsigned int do_verify; |
160b966d | 196 | unsigned int verifysort; |
a59e170d JA |
197 | unsigned int verify_interval; |
198 | unsigned int verify_offset; | |
0e92f873 | 199 | char verify_pattern[MAX_PATTERN_SIZE]; |
90059d65 | 200 | unsigned int verify_pattern_bytes; |
a12a3b4d | 201 | unsigned int verify_fatal; |
b463e936 | 202 | unsigned int verify_dump; |
e8462bd8 | 203 | unsigned int verify_async; |
9e144189 JA |
204 | unsigned long long verify_backlog; |
205 | unsigned int verify_batch; | |
9158d2f7 JA |
206 | unsigned int use_thread; |
207 | unsigned int unlink; | |
208 | unsigned int do_disk_util; | |
209 | unsigned int override_sync; | |
210 | unsigned int rand_repeatable; | |
2615cc4b | 211 | unsigned int use_os_rand; |
9158d2f7 JA |
212 | unsigned int write_lat_log; |
213 | unsigned int write_bw_log; | |
bb8895e0 | 214 | unsigned int norandommap; |
2b386d25 | 215 | unsigned int softrandommap; |
690adba3 | 216 | unsigned int bs_unaligned; |
ebb1415f | 217 | unsigned int fsync_on_close; |
e9c047a0 | 218 | |
56bb17f2 | 219 | unsigned int hugepage_size; |
a00735e6 | 220 | unsigned int rw_min_bs; |
ebac4655 | 221 | unsigned int thinktime; |
48097d5c | 222 | unsigned int thinktime_spin; |
9c1f7434 | 223 | unsigned int thinktime_blocks; |
ebac4655 | 224 | unsigned int fsync_blocks; |
5f9099ea | 225 | unsigned int fdatasync_blocks; |
1ef2b6be | 226 | unsigned int barrier_blocks; |
dce8b847 | 227 | unsigned long long start_delay; |
0db26797 | 228 | unsigned long long timeout; |
721938ae | 229 | unsigned long long ramp_time; |
ebac4655 | 230 | unsigned int overwrite; |
ebac4655 | 231 | unsigned int bw_avg_time; |
ebac4655 | 232 | unsigned int loops; |
20dc95c4 JA |
233 | unsigned long long zone_size; |
234 | unsigned long long zone_skip; | |
e9c047a0 | 235 | enum fio_memtype mem_type; |
d529ee19 | 236 | unsigned int mem_align; |
2dc1bbeb | 237 | |
ebac4655 | 238 | unsigned int stonewall; |
b3d62a75 | 239 | unsigned int new_group; |
ebac4655 | 240 | unsigned int numjobs; |
ebac4655 | 241 | os_cpu_mask_t cpumask; |
375b2695 | 242 | unsigned int cpumask_set; |
e8462bd8 JA |
243 | os_cpu_mask_t verify_cpumask; |
244 | unsigned int verify_cpumask_set; | |
aea47d44 | 245 | unsigned int iolog; |
a6ccc7be | 246 | unsigned int rwmixcycle; |
e47f799f | 247 | unsigned int rwmix[2]; |
b6f4d880 | 248 | unsigned int nice; |
0aabe160 | 249 | unsigned int file_service_type; |
b2560f3c | 250 | unsigned int group_reporting; |
d2f3ac35 | 251 | unsigned int fadvise_hint; |
a596f047 | 252 | enum fio_fallocate_mode fallocate_mode; |
e9459e5a | 253 | unsigned int zero_buffers; |
5973cafb | 254 | unsigned int refill_buffers; |
cf4464ca | 255 | unsigned int time_based; |
02af0988 | 256 | unsigned int disable_lat; |
9520ebb9 JA |
257 | unsigned int disable_clat; |
258 | unsigned int disable_slat; | |
259 | unsigned int disable_bw; | |
993bf48b | 260 | unsigned int gtod_reduce; |
be4ecfdf JA |
261 | unsigned int gtod_cpu; |
262 | unsigned int gtod_offload; | |
c223da83 | 263 | enum fio_cs clocksource; |
64bbb865 | 264 | unsigned int no_stall; |
0d29de83 JA |
265 | unsigned int trim_percentage; |
266 | unsigned int trim_batch; | |
267 | unsigned int trim_zero; | |
268 | unsigned long long trim_backlog; | |
aea47d44 | 269 | |
076efc7c JA |
270 | char *read_iolog_file; |
271 | char *write_iolog_file; | |
e3cedca7 JA |
272 | char *bw_log_file; |
273 | char *lat_log_file; | |
d1c46c04 | 274 | char *replay_redirect; |
2dc1bbeb JA |
275 | |
276 | /* | |
277 | * Pre-run and post-run shell | |
278 | */ | |
279 | char *exec_prerun; | |
280 | char *exec_postrun; | |
281 | ||
581e7141 JA |
282 | unsigned int rate[2]; |
283 | unsigned int ratemin[2]; | |
2dc1bbeb | 284 | unsigned int ratecycle; |
581e7141 JA |
285 | unsigned int rate_iops[2]; |
286 | unsigned int rate_iops_min[2]; | |
2dc1bbeb JA |
287 | |
288 | char *ioscheduler; | |
289 | ||
290 | /* | |
291 | * CPU "io" cycle burner | |
292 | */ | |
293 | unsigned int cpuload; | |
294 | unsigned int cpucycle; | |
f2bba182 RR |
295 | |
296 | /* | |
297 | * I/O Error handling | |
298 | */ | |
299 | unsigned int continue_on_error; | |
9ac8a797 JA |
300 | |
301 | /* | |
302 | * Benchmark profile type | |
303 | */ | |
79d16311 | 304 | char *profile; |
a696fa2a JA |
305 | |
306 | /* | |
307 | * blkio cgroup support | |
308 | */ | |
a696fa2a JA |
309 | char *cgroup; |
310 | unsigned int cgroup_weight; | |
7de87099 | 311 | unsigned int cgroup_nodelete; |
e0b0d892 JA |
312 | |
313 | unsigned int uid; | |
314 | unsigned int gid; | |
44f29692 JA |
315 | |
316 | unsigned int sync_file_range; | |
2dc1bbeb JA |
317 | }; |
318 | ||
e4e33258 JA |
319 | #define FIO_VERROR_SIZE 128 |
320 | ||
2dc1bbeb JA |
321 | /* |
322 | * This describes a single thread/process executing a fio job. | |
323 | */ | |
324 | struct thread_data { | |
325 | struct thread_options o; | |
e4e33258 | 326 | char verror[FIO_VERROR_SIZE]; |
2dc1bbeb JA |
327 | pthread_t thread; |
328 | int thread_number; | |
329 | int groupid; | |
330 | struct thread_stat ts; | |
126d65c6 | 331 | struct fio_file **files; |
dd87b2c9 | 332 | unsigned int files_size; |
2dc1bbeb JA |
333 | unsigned int files_index; |
334 | unsigned int nr_open_files; | |
1020a139 | 335 | unsigned int nr_done_files; |
2dc1bbeb JA |
336 | unsigned int nr_normal_files; |
337 | union { | |
338 | unsigned int next_file; | |
339 | os_random_state_t next_file_state; | |
4c07ad86 | 340 | struct frand_state __next_file_state; |
2dc1bbeb JA |
341 | }; |
342 | int error; | |
20e354ef | 343 | int done; |
2dc1bbeb JA |
344 | pid_t pid; |
345 | char *orig_buffer; | |
346 | size_t orig_buffer_size; | |
347 | volatile int terminate; | |
348 | volatile int runstate; | |
349 | unsigned int ioprio; | |
ac684785 | 350 | unsigned int ioprio_set; |
2dc1bbeb | 351 | unsigned int last_was_sync; |
9e144189 | 352 | enum fio_ddir last_ddir; |
2dc1bbeb JA |
353 | |
354 | char *mmapfile; | |
355 | int mmapfd; | |
356 | ||
843a7413 JA |
357 | void *iolog_buf; |
358 | FILE *iolog_f; | |
ebac4655 | 359 | |
da86774e | 360 | char *sysfs_root; |
da86774e | 361 | |
0d29de83 | 362 | unsigned long rand_seeds[7]; |
5bfc35d7 | 363 | |
4c07ad86 JA |
364 | union { |
365 | os_random_state_t bsrange_state; | |
366 | struct frand_state __bsrange_state; | |
367 | }; | |
368 | union { | |
369 | os_random_state_t verify_state; | |
370 | struct frand_state __verify_state; | |
371 | }; | |
372 | union { | |
373 | os_random_state_t trim_state; | |
374 | struct frand_state __trim_state; | |
375 | }; | |
ebac4655 | 376 | |
9e144189 | 377 | unsigned int verify_batch; |
0d29de83 | 378 | unsigned int trim_batch; |
9e144189 | 379 | |
ebac4655 JA |
380 | int shm_id; |
381 | ||
e9c047a0 JA |
382 | /* |
383 | * IO engine hooks, contains everything needed to submit an io_u | |
384 | * to any of the available IO engines. | |
385 | */ | |
2866c82d | 386 | struct ioengine_ops *io_ops; |
ebac4655 | 387 | |
e9c047a0 JA |
388 | /* |
389 | * Current IO depth and list of free and busy io_u's. | |
390 | */ | |
ebac4655 | 391 | unsigned int cur_depth; |
d8005759 | 392 | unsigned int io_u_queued; |
01743ee1 JA |
393 | struct flist_head io_u_freelist; |
394 | struct flist_head io_u_busylist; | |
395 | struct flist_head io_u_requeues; | |
e8462bd8 JA |
396 | pthread_mutex_t io_u_lock; |
397 | pthread_cond_t free_cond; | |
398 | ||
399 | /* | |
400 | * async verify offload | |
401 | */ | |
402 | struct flist_head verify_list; | |
403 | pthread_t *verify_threads; | |
404 | unsigned int nr_verify_threads; | |
405 | pthread_cond_t verify_cond; | |
406 | int verify_thread_exit; | |
ebac4655 | 407 | |
e9c047a0 JA |
408 | /* |
409 | * Rate state | |
410 | */ | |
ba3e4e0c | 411 | unsigned long rate_nsec_cycle[2]; |
581e7141 JA |
412 | long rate_pending_usleep[2]; |
413 | unsigned long rate_bytes[2]; | |
414 | unsigned long rate_blocks[2]; | |
415 | struct timeval lastrate[2]; | |
ebac4655 | 416 | |
ebac4655 | 417 | unsigned long long total_io_size; |
2e3bd4c2 | 418 | unsigned long long fill_device_size; |
ebac4655 | 419 | |
755200a3 | 420 | unsigned long io_issues[2]; |
9104f874 JA |
421 | unsigned long long io_blocks[2]; |
422 | unsigned long long io_bytes[2]; | |
48f5abd3 | 423 | unsigned long long io_skip_bytes; |
9104f874 | 424 | unsigned long long this_io_bytes[2]; |
079ad09b | 425 | unsigned long long zone_bytes; |
cdd18ad8 | 426 | struct fio_mutex *mutex; |
ebac4655 | 427 | |
e9c047a0 JA |
428 | /* |
429 | * State for random io, a bitmap of blocks done vs not done | |
430 | */ | |
4c07ad86 JA |
431 | union { |
432 | os_random_state_t random_state; | |
433 | struct frand_state __random_state; | |
434 | }; | |
ebac4655 | 435 | |
ebac4655 JA |
436 | struct timeval start; /* start of this loop */ |
437 | struct timeval epoch; /* time job was started */ | |
a61eddec | 438 | struct timeval last_issue; |
993bf48b JA |
439 | struct timeval tv_cache; |
440 | unsigned int tv_cache_nr; | |
441 | unsigned int tv_cache_mask; | |
721938ae | 442 | unsigned int ramp_time_over; |
ebac4655 | 443 | |
e9c047a0 JA |
444 | /* |
445 | * read/write mixed workload state | |
446 | */ | |
4c07ad86 JA |
447 | union { |
448 | os_random_state_t rwmix_state; | |
449 | struct frand_state __rwmix_state; | |
450 | }; | |
e4928662 | 451 | unsigned long rwmix_issues; |
e9c047a0 | 452 | enum fio_ddir rwmix_ddir; |
5736c10d | 453 | unsigned int ddir_seq_nr; |
a6ccc7be | 454 | |
e9c047a0 | 455 | /* |
8de8f047 JA |
456 | * IO history logs for verification. We use a tree for sorting, |
457 | * if we are overwriting. Otherwise just use a fifo. | |
e9c047a0 | 458 | */ |
4b87898e | 459 | struct rb_root io_hist_tree; |
01743ee1 | 460 | struct flist_head io_hist_list; |
9e144189 | 461 | unsigned long io_hist_len; |
8de8f047 JA |
462 | |
463 | /* | |
464 | * For IO replaying | |
465 | */ | |
01743ee1 | 466 | struct flist_head io_log_list; |
433afcb4 | 467 | |
0d29de83 JA |
468 | /* |
469 | * For tracking/handling discards | |
470 | */ | |
471 | struct flist_head trim_list; | |
472 | unsigned long trim_entries; | |
473 | ||
1907dbc6 JA |
474 | /* |
475 | * for fileservice, how often to switch to a new file | |
476 | */ | |
477 | unsigned int file_service_nr; | |
478 | unsigned int file_service_left; | |
479 | struct fio_file *file_service_file; | |
9c60ce64 | 480 | |
44f29692 JA |
481 | unsigned int sync_file_range_nr; |
482 | ||
9c60ce64 JA |
483 | /* |
484 | * For generating file sizes | |
485 | */ | |
4c07ad86 JA |
486 | union { |
487 | os_random_state_t file_size_state; | |
488 | struct frand_state __file_size_state; | |
489 | }; | |
f2bba182 RR |
490 | |
491 | /* | |
492 | * Error counts | |
493 | */ | |
494 | unsigned int total_err_count; | |
495 | int first_error; | |
15dc1934 JA |
496 | |
497 | /* | |
498 | * Can be overloaded by profiles | |
499 | */ | |
7eb36574 | 500 | struct prof_io_ops prof_io_ops; |
58c55ba0 | 501 | void *prof_data; |
ebac4655 JA |
502 | }; |
503 | ||
e592a06b AC |
504 | /* |
505 | * when should interactive ETA output be generated | |
506 | */ | |
507 | enum { | |
508 | FIO_ETA_AUTO, | |
509 | FIO_ETA_ALWAYS, | |
510 | FIO_ETA_NEVER, | |
511 | }; | |
512 | ||
e1161c32 | 513 | #define __td_verror(td, err, msg, func) \ |
ebac4655 | 514 | do { \ |
19abcd3d JA |
515 | if ((td)->error) \ |
516 | break; \ | |
ebac4655 JA |
517 | int e = (err); \ |
518 | (td)->error = e; \ | |
f2bba182 RR |
519 | if (!(td)->first_error) \ |
520 | snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, func=%s, error=%s", __FILE__, __LINE__, (func), (msg)); \ | |
ebac4655 JA |
521 | } while (0) |
522 | ||
b990b5c0 | 523 | |
f2bba182 RR |
524 | #define td_clear_error(td) \ |
525 | (td)->error = 0; | |
e1161c32 JA |
526 | #define td_verror(td, err, func) \ |
527 | __td_verror((td), (err), strerror((err)), (func)) | |
528 | #define td_vmsg(td, err, msg, func) \ | |
529 | __td_verror((td), (err), (msg), (func)) | |
b990b5c0 | 530 | |
ebac4655 JA |
531 | extern int exitall_on_terminate; |
532 | extern int thread_number; | |
9cedf167 | 533 | extern int nr_process, nr_thread; |
ebac4655 JA |
534 | extern int shm_id; |
535 | extern int groupid; | |
c6ae0a5b | 536 | extern int terse_output; |
53cdc686 | 537 | extern int temp_stall_ts; |
1e97cce9 | 538 | extern unsigned long long mlock_size; |
cfc99db7 | 539 | extern unsigned long page_mask, page_size; |
4241ea8f | 540 | extern int read_only; |
e592a06b | 541 | extern int eta_print; |
d3eeeabc | 542 | extern unsigned long done_secs; |
01f06b63 | 543 | extern char *job_section; |
be4ecfdf JA |
544 | extern int fio_gtod_offload; |
545 | extern int fio_gtod_cpu; | |
c223da83 | 546 | extern enum fio_cs fio_clock_source; |
a9523c6f | 547 | extern int warnings_fatal; |
ebac4655 JA |
548 | |
549 | extern struct thread_data *threads; | |
550 | ||
7101d9c2 JA |
551 | static inline void fio_ro_check(struct thread_data *td, struct io_u *io_u) |
552 | { | |
553 | assert(!(io_u->ddir == DDIR_WRITE && !td_write(td))); | |
554 | } | |
555 | ||
0ce8b119 | 556 | #define BLOCKS_PER_MAP (8 * sizeof(unsigned long)) |
aec2de20 JA |
557 | #define TO_MAP_BLOCK(f, b) (b) |
558 | #define RAND_MAP_IDX(f, b) (TO_MAP_BLOCK(f, b) / BLOCKS_PER_MAP) | |
559 | #define RAND_MAP_BIT(f, b) (TO_MAP_BLOCK(f, b) & (BLOCKS_PER_MAP - 1)) | |
ebac4655 | 560 | |
fca70358 | 561 | #define REAL_MAX_JOBS 2048 |
ebac4655 | 562 | |
1ec99eea | 563 | #define td_non_fatal_error(e) ((e) == EIO || (e) == EILSEQ) |
f2bba182 RR |
564 | |
565 | static inline void update_error_count(struct thread_data *td, int err) | |
566 | { | |
567 | td->total_err_count++; | |
568 | if (td->total_err_count == 1) | |
569 | td->first_error = err; | |
570 | } | |
571 | ||
87dc1ab1 JA |
572 | static inline int should_fsync(struct thread_data *td) |
573 | { | |
574 | if (td->last_was_sync) | |
575 | return 0; | |
2dc1bbeb | 576 | if (td->o.odirect) |
87dc1ab1 | 577 | return 0; |
2dc1bbeb | 578 | if (td_write(td) || td_rw(td) || td->o.override_sync) |
87dc1ab1 JA |
579 | return 1; |
580 | ||
581 | return 0; | |
582 | } | |
583 | ||
8914a9d8 | 584 | /* |
214e1eca | 585 | * Init/option functions |
8914a9d8 | 586 | */ |
72cb971b | 587 | extern int __must_check parse_options(int, char **); |
3b8b7135 | 588 | extern int fio_options_parse(struct thread_data *, char **, int); |
74929ac2 | 589 | extern void fio_keywords_init(void); |
214e1eca JA |
590 | extern int fio_cmd_option_parse(struct thread_data *, const char *, char *); |
591 | extern void fio_fill_default_options(struct thread_data *); | |
592 | extern int fio_show_option_help(const char *); | |
593 | extern void fio_options_dup_and_init(struct option *); | |
d23bb327 JA |
594 | extern void options_mem_dupe(struct thread_data *); |
595 | extern void options_mem_free(struct thread_data *); | |
5bfc35d7 | 596 | extern void td_fill_rand_seeds(struct thread_data *); |
79d16311 | 597 | extern void add_job_opts(const char **); |
1ec3d69b JA |
598 | extern char *num2str(unsigned long, int, int, int); |
599 | ||
214e1eca | 600 | #define FIO_GETOPT_JOB 0x89988998 |
07b3232d | 601 | #define FIO_NR_OPTIONS (FIO_MAX_OPTS + 128) |
8914a9d8 | 602 | |
263e529f JA |
603 | /* |
604 | * ETA/status stuff | |
605 | */ | |
606 | extern void print_thread_status(void); | |
607 | extern void print_status_init(int); | |
608 | ||
609 | /* | |
610 | * Thread life cycle. Once a thread has a runstate beyond TD_INITIALIZED, it | |
611 | * will never back again. It may cycle between running/verififying/fsyncing. | |
612 | * Once the thread reaches TD_EXITED, it is just waiting for the core to | |
613 | * reap it. | |
614 | */ | |
615 | enum { | |
616 | TD_NOT_CREATED = 0, | |
617 | TD_CREATED, | |
618 | TD_INITIALIZED, | |
b29ee5b3 | 619 | TD_RAMP, |
263e529f | 620 | TD_RUNNING, |
b0f65863 | 621 | TD_PRE_READING, |
263e529f JA |
622 | TD_VERIFYING, |
623 | TD_FSYNCING, | |
624 | TD_EXITED, | |
625 | TD_REAPED, | |
626 | }; | |
627 | ||
b29ee5b3 JA |
628 | extern void td_set_runstate(struct thread_data *, int); |
629 | ||
2f9ade3c JA |
630 | /* |
631 | * Memory helpers | |
632 | */ | |
b2fdda43 | 633 | extern int __must_check fio_pin_memory(void); |
2f9ade3c | 634 | extern void fio_unpin_memory(void); |
b2fdda43 | 635 | extern int __must_check allocate_io_mem(struct thread_data *); |
2f9ade3c JA |
636 | extern void free_io_mem(struct thread_data *); |
637 | ||
b29ee5b3 JA |
638 | /* |
639 | * Reset stats after ramp time completes | |
640 | */ | |
641 | extern void reset_all_stats(struct thread_data *); | |
642 | ||
fb7b71a3 JA |
643 | /* |
644 | * blktrace support | |
645 | */ | |
5e62c22a | 646 | #ifdef FIO_HAVE_BLKTRACE |
fb7b71a3 JA |
647 | extern int is_blktrace(const char *); |
648 | extern int load_blktrace(struct thread_data *, const char *); | |
5e62c22a | 649 | #endif |
fb7b71a3 | 650 | |
2866c82d JA |
651 | /* |
652 | * Mark unused variables passed to ops functions as unused, to silence gcc | |
653 | */ | |
654 | #define fio_unused __attribute((__unused__)) | |
5f350952 JA |
655 | #define fio_init __attribute__((constructor)) |
656 | #define fio_exit __attribute__((destructor)) | |
2866c82d | 657 | |
34572e28 JA |
658 | #define for_each_td(td, i) \ |
659 | for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++) | |
53cdc686 | 660 | #define for_each_file(td, f, i) \ |
691c8fb0 JA |
661 | if ((td)->files_index) \ |
662 | for ((i) = 0, (f) = (td)->files[0]; \ | |
663 | (i) < (td)->o.nr_files && ((f) = (td)->files[i]) != NULL; \ | |
664 | (i)++) | |
53cdc686 | 665 | |
0032bf9f JA |
666 | #define fio_assert(td, cond) do { \ |
667 | if (!(cond)) { \ | |
340fd243 | 668 | int *__foo = NULL; \ |
0032bf9f | 669 | fprintf(stderr, "file:%s:%d, assert %s failed\n", __FILE__, __LINE__, #cond); \ |
ac18ea38 | 670 | td_set_runstate((td), TD_EXITED); \ |
437c9b71 | 671 | (td)->error = EFAULT; \ |
340fd243 | 672 | *__foo = 0; \ |
0032bf9f JA |
673 | } \ |
674 | } while (0) | |
675 | ||
12d9d841 JA |
676 | static inline int fio_fill_issue_time(struct thread_data *td) |
677 | { | |
678 | if (td->o.read_iolog_file || | |
679 | !td->o.disable_clat || !td->o.disable_slat || !td->o.disable_bw) | |
680 | return 1; | |
681 | ||
682 | return 0; | |
683 | } | |
684 | ||
581e7141 JA |
685 | static inline int __should_check_rate(struct thread_data *td, |
686 | enum fio_ddir ddir) | |
687 | { | |
688 | struct thread_options *o = &td->o; | |
689 | ||
690 | /* | |
691 | * If some rate setting was given, we need to check it | |
692 | */ | |
693 | if (o->rate[ddir] || o->ratemin[ddir] || o->rate_iops[ddir] || | |
694 | o->rate_iops_min[ddir]) | |
695 | return 1; | |
696 | ||
697 | return 0; | |
698 | } | |
699 | ||
700 | static inline int should_check_rate(struct thread_data *td, | |
701 | unsigned long *bytes_done) | |
702 | { | |
703 | int ret = 0; | |
704 | ||
705 | if (bytes_done[0]) | |
706 | ret |= __should_check_rate(td, 0); | |
707 | if (bytes_done[1]) | |
708 | ret |= __should_check_rate(td, 1); | |
709 | ||
710 | return ret; | |
711 | } | |
712 | ||
d529ee19 JA |
713 | static inline int is_power_of_2(unsigned int val) |
714 | { | |
715 | return (val != 0 && ((val & (val - 1)) == 0)); | |
716 | } | |
717 | ||
e8462bd8 JA |
718 | /* |
719 | * We currently only need to do locking if we have verifier threads | |
720 | * accessing our internal structures too | |
721 | */ | |
722 | static inline void td_io_u_lock(struct thread_data *td) | |
723 | { | |
724 | if (td->o.verify_async) | |
725 | pthread_mutex_lock(&td->io_u_lock); | |
726 | } | |
727 | ||
728 | static inline void td_io_u_unlock(struct thread_data *td) | |
729 | { | |
730 | if (td->o.verify_async) | |
731 | pthread_mutex_unlock(&td->io_u_lock); | |
732 | } | |
733 | ||
734 | static inline void td_io_u_free_notify(struct thread_data *td) | |
735 | { | |
736 | if (td->o.verify_async) | |
737 | pthread_cond_signal(&td->free_cond); | |
738 | } | |
739 | ||
ebac4655 | 740 | #endif |