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