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 | |
317b95d0 | 17 | #include "compiler/compiler.h" |
8062f527 | 18 | #include "thread_options.h" |
01743ee1 | 19 | #include "flist.h" |
e2887563 | 20 | #include "fifo.h" |
317b95d0 JA |
21 | #include "arch/arch.h" |
22 | #include "os/os.h" | |
07739b57 | 23 | #include "mutex.h" |
a3d741fa JA |
24 | #include "log.h" |
25 | #include "debug.h" | |
d6aed795 JA |
26 | #include "file.h" |
27 | #include "io_ddir.h" | |
dcefb588 | 28 | #include "ioengine.h" |
5995a6a4 | 29 | #include "iolog.h" |
c5c8bd5c | 30 | #include "helpers.h" |
07b3232d | 31 | #include "options.h" |
7eb36574 | 32 | #include "profile.h" |
ef3c94b6 | 33 | #include "fio_time.h" |
a7346816 | 34 | #include "gettime.h" |
bf2e821a | 35 | #include "lib/getopt.h" |
2615cc4b | 36 | #include "lib/rand.h" |
7fb6d453 | 37 | #include "lib/rbtree.h" |
dd366728 | 38 | #include "client.h" |
37db14fe | 39 | #include "server.h" |
a64e88da | 40 | #include "stat.h" |
9e684a49 | 41 | #include "flow.h" |
2ae0b204 | 42 | #include "io_u_queue.h" |
a9da8ab2 | 43 | #include "workqueue.h" |
ebac4655 | 44 | |
4700b234 | 45 | #ifdef CONFIG_SOLARISAIO |
417f0068 JA |
46 | #include <sys/asynch.h> |
47 | #endif | |
48 | ||
67bf9823 | 49 | #ifdef CONFIG_LIBNUMA |
d0b937ed YR |
50 | #include <linux/mempolicy.h> |
51 | #include <numa.h> | |
52 | ||
53 | /* | |
54 | * "local" is pseudo-policy | |
55 | */ | |
56 | #define MPOL_LOCAL MPOL_MAX | |
57 | #endif | |
58 | ||
38dad62d JA |
59 | /* |
60 | * offset generator types | |
61 | */ | |
62 | enum { | |
63 | RW_SEQ_SEQ = 0, | |
64 | RW_SEQ_IDENT, | |
65 | }; | |
66 | ||
d72be545 JA |
67 | enum { |
68 | TD_F_VER_BACKLOG = 1, | |
69 | TD_F_TRIM_BACKLOG = 2, | |
70 | TD_F_READ_IOLOG = 4, | |
71 | TD_F_REFILL_BUFFERS = 8, | |
72 | TD_F_SCRAMBLE_BUFFERS = 16, | |
73 | TD_F_VER_NONE = 32, | |
74 | TD_F_PROFILE_OPS = 64, | |
bedc9dc2 | 75 | TD_F_COMPRESS = 128, |
046395d7 | 76 | TD_F_NOIO = 256, |
aee2ab67 | 77 | TD_F_COMPRESS_LOG = 512, |
ca09be4b | 78 | TD_F_VSTATE_SAVED = 1024, |
a9da8ab2 JA |
79 | TD_F_NEED_LOCK = 2048, |
80 | TD_F_CHILD = 4096, | |
d72be545 JA |
81 | }; |
82 | ||
d24945f0 JA |
83 | enum { |
84 | FIO_RAND_BS_OFF = 0, | |
85 | FIO_RAND_VER_OFF, | |
86 | FIO_RAND_MIX_OFF, | |
87 | FIO_RAND_FILE_OFF, | |
88 | FIO_RAND_BLOCK_OFF, | |
89 | FIO_RAND_FILE_SIZE_OFF, | |
90 | FIO_RAND_TRIM_OFF, | |
91 | FIO_RAND_BUF_OFF, | |
d9472271 JA |
92 | FIO_RAND_SEQ_RAND_READ_OFF, |
93 | FIO_RAND_SEQ_RAND_WRITE_OFF, | |
94 | FIO_RAND_SEQ_RAND_TRIM_OFF, | |
23ed19b0 | 95 | FIO_RAND_START_DELAY, |
5c94b008 | 96 | FIO_DEDUPE_OFF, |
d24945f0 JA |
97 | FIO_RAND_NR_OFFS, |
98 | }; | |
99 | ||
a9da8ab2 JA |
100 | enum { |
101 | IO_MODE_INLINE = 0, | |
102 | IO_MODE_OFFLOAD, | |
103 | }; | |
104 | ||
2dc1bbeb JA |
105 | /* |
106 | * This describes a single thread/process executing a fio job. | |
107 | */ | |
108 | struct thread_data { | |
109 | struct thread_options o; | |
d72be545 | 110 | unsigned long flags; |
de890a1e | 111 | void *eo; |
e4e33258 | 112 | char verror[FIO_VERROR_SIZE]; |
2dc1bbeb | 113 | pthread_t thread; |
2f122b13 | 114 | unsigned int thread_number; |
69bdd6ba | 115 | unsigned int subjob_number; |
2f122b13 | 116 | unsigned int groupid; |
2dc1bbeb | 117 | struct thread_stat ts; |
7b9f733a | 118 | |
46bcd498 JA |
119 | int client_type; |
120 | ||
7b9f733a JA |
121 | struct io_log *slat_log; |
122 | struct io_log *clat_log; | |
123 | struct io_log *lat_log; | |
124 | struct io_log *bw_log; | |
c8eeb9df | 125 | struct io_log *iops_log; |
7b9f733a | 126 | |
aee2ab67 JA |
127 | struct tp_data *tp_data; |
128 | ||
a9da8ab2 JA |
129 | struct thread_data *parent; |
130 | ||
6eaf09d6 | 131 | uint64_t stat_io_bytes[DDIR_RWDIR_CNT]; |
c8eeb9df JA |
132 | struct timeval bw_sample_time; |
133 | ||
6eaf09d6 | 134 | uint64_t stat_io_blocks[DDIR_RWDIR_CNT]; |
c8eeb9df | 135 | struct timeval iops_sample_time; |
f0505a14 | 136 | |
ca09be4b JA |
137 | /* |
138 | * Tracks the last iodepth number of completed writes, if data | |
139 | * verification is enabled | |
140 | */ | |
141 | uint64_t *last_write_comp; | |
142 | unsigned int last_write_idx; | |
143 | ||
c97f1ad6 JA |
144 | volatile int update_rusage; |
145 | struct fio_mutex *rusage_sem; | |
c8aaba19 JA |
146 | struct rusage ru_start; |
147 | struct rusage ru_end; | |
148 | ||
126d65c6 | 149 | struct fio_file **files; |
d7df1d13 | 150 | unsigned char *file_locks; |
dd87b2c9 | 151 | unsigned int files_size; |
2dc1bbeb JA |
152 | unsigned int files_index; |
153 | unsigned int nr_open_files; | |
1020a139 | 154 | unsigned int nr_done_files; |
2dc1bbeb JA |
155 | unsigned int nr_normal_files; |
156 | union { | |
157 | unsigned int next_file; | |
d6b72507 | 158 | struct frand_state next_file_state; |
2dc1bbeb JA |
159 | }; |
160 | int error; | |
a5e371a6 | 161 | int sig; |
20e354ef | 162 | int done; |
ca09be4b | 163 | int stop_io; |
2dc1bbeb JA |
164 | pid_t pid; |
165 | char *orig_buffer; | |
166 | size_t orig_buffer_size; | |
167 | volatile int terminate; | |
168 | volatile int runstate; | |
2dc1bbeb | 169 | unsigned int last_was_sync; |
9e144189 | 170 | enum fio_ddir last_ddir; |
2dc1bbeb | 171 | |
2dc1bbeb JA |
172 | int mmapfd; |
173 | ||
843a7413 JA |
174 | void *iolog_buf; |
175 | FILE *iolog_f; | |
ebac4655 | 176 | |
da86774e | 177 | char *sysfs_root; |
da86774e | 178 | |
d24945f0 | 179 | unsigned long rand_seeds[FIO_RAND_NR_OFFS]; |
5bfc35d7 | 180 | |
d6b72507 JA |
181 | struct frand_state bsrange_state; |
182 | struct frand_state verify_state; | |
183 | struct frand_state trim_state; | |
184 | struct frand_state delay_state; | |
ebac4655 | 185 | |
3545a109 | 186 | struct frand_state buf_state; |
5c94b008 JA |
187 | struct frand_state buf_state_prev; |
188 | struct frand_state dedupe_state; | |
3545a109 | 189 | |
9e144189 | 190 | unsigned int verify_batch; |
0d29de83 | 191 | unsigned int trim_batch; |
9e144189 | 192 | |
ca09be4b JA |
193 | struct thread_io_list *vstate; |
194 | ||
ebac4655 JA |
195 | int shm_id; |
196 | ||
e9c047a0 JA |
197 | /* |
198 | * IO engine hooks, contains everything needed to submit an io_u | |
199 | * to any of the available IO engines. | |
200 | */ | |
2866c82d | 201 | struct ioengine_ops *io_ops; |
ebac4655 | 202 | |
e9c047a0 | 203 | /* |
422f9e4b | 204 | * Queue depth of io_u's that fio MIGHT do |
e9c047a0 | 205 | */ |
ebac4655 | 206 | unsigned int cur_depth; |
422f9e4b RM |
207 | |
208 | /* | |
209 | * io_u's about to be committed | |
210 | */ | |
d8005759 | 211 | unsigned int io_u_queued; |
422f9e4b RM |
212 | |
213 | /* | |
214 | * io_u's submitted but not completed yet | |
215 | */ | |
216 | unsigned int io_u_in_flight; | |
217 | ||
218 | /* | |
219 | * List of free and busy io_u's | |
220 | */ | |
2ae0b204 JA |
221 | struct io_u_ring io_u_requeues; |
222 | struct io_u_queue io_u_freelist; | |
223 | struct io_u_queue io_u_all; | |
e8462bd8 JA |
224 | pthread_mutex_t io_u_lock; |
225 | pthread_cond_t free_cond; | |
226 | ||
227 | /* | |
228 | * async verify offload | |
229 | */ | |
230 | struct flist_head verify_list; | |
231 | pthread_t *verify_threads; | |
232 | unsigned int nr_verify_threads; | |
233 | pthread_cond_t verify_cond; | |
234 | int verify_thread_exit; | |
ebac4655 | 235 | |
e9c047a0 JA |
236 | /* |
237 | * Rate state | |
238 | */ | |
bdb6d20a | 239 | uint64_t rate_bps[DDIR_RWDIR_CNT]; |
6eaf09d6 SL |
240 | long rate_pending_usleep[DDIR_RWDIR_CNT]; |
241 | unsigned long rate_bytes[DDIR_RWDIR_CNT]; | |
242 | unsigned long rate_blocks[DDIR_RWDIR_CNT]; | |
243 | struct timeval lastrate[DDIR_RWDIR_CNT]; | |
ebac4655 | 244 | |
a9da8ab2 JA |
245 | /* |
246 | * Enforced rate submission/completion workqueue | |
247 | */ | |
248 | struct workqueue io_wq; | |
249 | ||
bdb6d20a JA |
250 | uint64_t total_io_size; |
251 | uint64_t fill_device_size; | |
ebac4655 | 252 | |
74d6277f JA |
253 | /* |
254 | * Issue side | |
255 | */ | |
ca09be4b | 256 | uint64_t io_issues[DDIR_RWDIR_CNT]; |
74d6277f | 257 | uint64_t io_issue_bytes[DDIR_RWDIR_CNT]; |
cf8a46a7 | 258 | uint64_t loops; |
74d6277f JA |
259 | |
260 | /* | |
261 | * Completions | |
262 | */ | |
bdb6d20a JA |
263 | uint64_t io_blocks[DDIR_RWDIR_CNT]; |
264 | uint64_t this_io_blocks[DDIR_RWDIR_CNT]; | |
265 | uint64_t io_bytes[DDIR_RWDIR_CNT]; | |
bdb6d20a | 266 | uint64_t this_io_bytes[DDIR_RWDIR_CNT]; |
55312f9f | 267 | uint64_t io_skip_bytes; |
bdb6d20a | 268 | uint64_t zone_bytes; |
cdd18ad8 | 269 | struct fio_mutex *mutex; |
55312f9f | 270 | uint64_t bytes_done[DDIR_RWDIR_CNT]; |
ebac4655 | 271 | |
e9c047a0 JA |
272 | /* |
273 | * State for random io, a bitmap of blocks done vs not done | |
274 | */ | |
d6b72507 | 275 | struct frand_state random_state; |
ebac4655 | 276 | |
ebac4655 JA |
277 | struct timeval start; /* start of this loop */ |
278 | struct timeval epoch; /* time job was started */ | |
a61eddec | 279 | struct timeval last_issue; |
df8fb609 | 280 | long time_offset; |
993bf48b | 281 | struct timeval tv_cache; |
cba5460c | 282 | struct timeval terminate_time; |
993bf48b JA |
283 | unsigned int tv_cache_nr; |
284 | unsigned int tv_cache_mask; | |
721938ae | 285 | unsigned int ramp_time_over; |
ebac4655 | 286 | |
3e260a46 JA |
287 | /* |
288 | * Time since last latency_window was started | |
289 | */ | |
290 | struct timeval latency_ts; | |
291 | unsigned int latency_qd; | |
292 | unsigned int latency_qd_high; | |
293 | unsigned int latency_qd_low; | |
294 | unsigned int latency_failed; | |
295 | uint64_t latency_ios; | |
6bb58215 | 296 | int latency_end_run; |
3e260a46 | 297 | |
e9c047a0 JA |
298 | /* |
299 | * read/write mixed workload state | |
300 | */ | |
d6b72507 | 301 | struct frand_state rwmix_state; |
e4928662 | 302 | unsigned long rwmix_issues; |
e9c047a0 | 303 | enum fio_ddir rwmix_ddir; |
5736c10d | 304 | unsigned int ddir_seq_nr; |
a6ccc7be | 305 | |
211c9b89 JA |
306 | /* |
307 | * rand/seq mixed workload state | |
308 | */ | |
d6b72507 | 309 | struct frand_state seq_rand_state[DDIR_RWDIR_CNT]; |
211c9b89 | 310 | |
e9c047a0 | 311 | /* |
8de8f047 JA |
312 | * IO history logs for verification. We use a tree for sorting, |
313 | * if we are overwriting. Otherwise just use a fifo. | |
e9c047a0 | 314 | */ |
4b87898e | 315 | struct rb_root io_hist_tree; |
01743ee1 | 316 | struct flist_head io_hist_list; |
9e144189 | 317 | unsigned long io_hist_len; |
8de8f047 JA |
318 | |
319 | /* | |
320 | * For IO replaying | |
321 | */ | |
01743ee1 | 322 | struct flist_head io_log_list; |
433afcb4 | 323 | |
0d29de83 JA |
324 | /* |
325 | * For tracking/handling discards | |
326 | */ | |
327 | struct flist_head trim_list; | |
328 | unsigned long trim_entries; | |
329 | ||
1ae83d45 JA |
330 | struct flist_head next_rand_list; |
331 | ||
1907dbc6 JA |
332 | /* |
333 | * for fileservice, how often to switch to a new file | |
334 | */ | |
335 | unsigned int file_service_nr; | |
336 | unsigned int file_service_left; | |
337 | struct fio_file *file_service_file; | |
9c60ce64 | 338 | |
44f29692 JA |
339 | unsigned int sync_file_range_nr; |
340 | ||
9c60ce64 JA |
341 | /* |
342 | * For generating file sizes | |
343 | */ | |
d6b72507 | 344 | struct frand_state file_size_state; |
f2bba182 RR |
345 | |
346 | /* | |
347 | * Error counts | |
348 | */ | |
349 | unsigned int total_err_count; | |
350 | int first_error; | |
15dc1934 | 351 | |
9e684a49 DE |
352 | struct fio_flow *flow; |
353 | ||
15dc1934 JA |
354 | /* |
355 | * Can be overloaded by profiles | |
356 | */ | |
7eb36574 | 357 | struct prof_io_ops prof_io_ops; |
58c55ba0 | 358 | void *prof_data; |
9a3f1100 JA |
359 | |
360 | void *pinned_mem; | |
ebac4655 JA |
361 | }; |
362 | ||
e592a06b AC |
363 | /* |
364 | * when should interactive ETA output be generated | |
365 | */ | |
366 | enum { | |
367 | FIO_ETA_AUTO, | |
368 | FIO_ETA_ALWAYS, | |
369 | FIO_ETA_NEVER, | |
370 | }; | |
371 | ||
e1161c32 | 372 | #define __td_verror(td, err, msg, func) \ |
ebac4655 | 373 | do { \ |
21beb609 | 374 | unsigned int ____e = (err); \ |
19abcd3d JA |
375 | if ((td)->error) \ |
376 | break; \ | |
8271963e | 377 | (td)->error = ____e; \ |
f2bba182 | 378 | if (!(td)->first_error) \ |
98ffb8f3 | 379 | snprintf(td->verror, sizeof(td->verror), "file:%s:%d, func=%s, error=%s", __FILE__, __LINE__, (func), (msg)); \ |
ebac4655 JA |
380 | } while (0) |
381 | ||
b990b5c0 | 382 | |
a9da8ab2 JA |
383 | #define td_clear_error(td) do { \ |
384 | (td)->error = 0; \ | |
385 | if ((td)->parent) \ | |
386 | (td)->parent->error = 0; \ | |
387 | } while (0) | |
388 | ||
389 | #define td_verror(td, err, func) do { \ | |
390 | __td_verror((td), (err), strerror((err)), (func)); \ | |
391 | if ((td)->parent) \ | |
392 | __td_verror((td)->parent, (err), strerror((err)), (func)); \ | |
393 | } while (0) | |
394 | ||
395 | #define td_vmsg(td, err, msg, func) do { \ | |
396 | __td_verror((td), (err), (msg), (func)); \ | |
397 | if ((td)->parent) \ | |
398 | __td_verror((td)->parent, (err), (msg), (func)); \ | |
399 | } while (0) | |
b990b5c0 | 400 | |
81179eec JA |
401 | #define __fio_stringify_1(x) #x |
402 | #define __fio_stringify(x) __fio_stringify_1(x) | |
403 | ||
ebac4655 | 404 | extern int exitall_on_terminate; |
11e950bd | 405 | extern unsigned int thread_number; |
108fea77 | 406 | extern unsigned int stat_number; |
ebac4655 JA |
407 | extern int shm_id; |
408 | extern int groupid; | |
f3afa57e | 409 | extern int output_format; |
2b8c71b0 | 410 | extern int append_terse_output; |
53cdc686 | 411 | extern int temp_stall_ts; |
7078106d | 412 | extern uintptr_t page_mask, page_size; |
4241ea8f | 413 | extern int read_only; |
e592a06b | 414 | extern int eta_print; |
e382e661 | 415 | extern int eta_new_line; |
d3eeeabc | 416 | extern unsigned long done_secs; |
01f06b63 | 417 | extern char *job_section; |
be4ecfdf JA |
418 | extern int fio_gtod_offload; |
419 | extern int fio_gtod_cpu; | |
c223da83 | 420 | extern enum fio_cs fio_clock_source; |
fa80feae | 421 | extern int fio_clock_source_set; |
a9523c6f | 422 | extern int warnings_fatal; |
f57a9c59 | 423 | extern int terse_version; |
5c341e9a | 424 | extern int is_backend; |
a37f69b7 | 425 | extern int nr_clients; |
e46d8091 | 426 | extern int log_syslog; |
06464907 | 427 | extern int status_interval; |
5e726d0a | 428 | extern const char fio_version_string[]; |
5ddc6707 JA |
429 | extern int helper_do_stat; |
430 | extern pthread_cond_t helper_cond; | |
ca09be4b JA |
431 | extern char *trigger_file; |
432 | extern char *trigger_cmd; | |
b63efd30 | 433 | extern char *trigger_remote_cmd; |
ca09be4b | 434 | extern long long trigger_timeout; |
ebac4655 JA |
435 | |
436 | extern struct thread_data *threads; | |
437 | ||
effd6ff0 | 438 | static inline void fio_ro_check(const struct thread_data *td, struct io_u *io_u) |
7101d9c2 JA |
439 | { |
440 | assert(!(io_u->ddir == DDIR_WRITE && !td_write(td))); | |
441 | } | |
442 | ||
fca70358 | 443 | #define REAL_MAX_JOBS 2048 |
ebac4655 | 444 | |
87dc1ab1 JA |
445 | static inline int should_fsync(struct thread_data *td) |
446 | { | |
447 | if (td->last_was_sync) | |
448 | return 0; | |
2dc1bbeb | 449 | if (td_write(td) || td_rw(td) || td->o.override_sync) |
87dc1ab1 JA |
450 | return 1; |
451 | ||
452 | return 0; | |
453 | } | |
454 | ||
8914a9d8 | 455 | /* |
214e1eca | 456 | * Init/option functions |
8914a9d8 | 457 | */ |
0420ba6a | 458 | extern int __must_check fio_init_options(void); |
72cb971b | 459 | extern int __must_check parse_options(int, char **); |
46bcd498 JA |
460 | extern int parse_jobs_ini(char *, int, int, int); |
461 | extern int parse_cmd_line(int, char **, int); | |
2e1df07d | 462 | extern int fio_backend(void); |
50d16976 | 463 | extern void reset_fio_state(void); |
2e1df07d | 464 | extern void clear_io_state(struct thread_data *); |
292cc475 | 465 | extern int fio_options_parse(struct thread_data *, char **, int, int); |
74929ac2 | 466 | extern void fio_keywords_init(void); |
214e1eca | 467 | extern int fio_cmd_option_parse(struct thread_data *, const char *, char *); |
de890a1e | 468 | extern int fio_cmd_ioengine_option_parse(struct thread_data *, const char *, char *); |
214e1eca JA |
469 | extern void fio_fill_default_options(struct thread_data *); |
470 | extern int fio_show_option_help(const char *); | |
de890a1e | 471 | extern void fio_options_set_ioengine_opts(struct option *long_options, struct thread_data *td); |
214e1eca | 472 | extern void fio_options_dup_and_init(struct option *); |
de890a1e SL |
473 | extern void fio_options_mem_dupe(struct thread_data *); |
474 | extern void options_mem_dupe(void *data, struct fio_option *options); | |
5bfc35d7 | 475 | extern void td_fill_rand_seeds(struct thread_data *); |
46bcd498 | 476 | extern void add_job_opts(const char **, int); |
ca09be4b | 477 | extern char *num2str(uint64_t, int, int, int, int); |
de890a1e | 478 | extern int ioengine_load(struct thread_data *); |
f9633d72 | 479 | extern int parse_dryrun(void); |
046395d7 | 480 | extern int fio_running_or_pending_io_threads(void); |
3a35845f | 481 | extern int fio_set_fd_nonblocking(int, const char *); |
1ec3d69b | 482 | |
a569b45f JA |
483 | extern uintptr_t page_mask; |
484 | extern uintptr_t page_size; | |
485 | extern int initialize_fio(char *envp[]); | |
486 | ||
de890a1e SL |
487 | #define FIO_GETOPT_JOB 0x89000000 |
488 | #define FIO_GETOPT_IOENGINE 0x98000000 | |
07b3232d | 489 | #define FIO_NR_OPTIONS (FIO_MAX_OPTS + 128) |
8914a9d8 | 490 | |
263e529f JA |
491 | /* |
492 | * ETA/status stuff | |
493 | */ | |
494 | extern void print_thread_status(void); | |
495 | extern void print_status_init(int); | |
0a428b23 | 496 | extern char *fio_uint_to_kmg(unsigned int val); |
263e529f JA |
497 | |
498 | /* | |
499 | * Thread life cycle. Once a thread has a runstate beyond TD_INITIALIZED, it | |
500 | * will never back again. It may cycle between running/verififying/fsyncing. | |
501 | * Once the thread reaches TD_EXITED, it is just waiting for the core to | |
502 | * reap it. | |
503 | */ | |
504 | enum { | |
505 | TD_NOT_CREATED = 0, | |
506 | TD_CREATED, | |
507 | TD_INITIALIZED, | |
b29ee5b3 | 508 | TD_RAMP, |
36d80bc7 | 509 | TD_SETTING_UP, |
263e529f | 510 | TD_RUNNING, |
b0f65863 | 511 | TD_PRE_READING, |
263e529f JA |
512 | TD_VERIFYING, |
513 | TD_FSYNCING, | |
3d434057 | 514 | TD_FINISHING, |
263e529f JA |
515 | TD_EXITED, |
516 | TD_REAPED, | |
517 | }; | |
518 | ||
b29ee5b3 | 519 | extern void td_set_runstate(struct thread_data *, int); |
8edd973d JA |
520 | extern int td_bump_runstate(struct thread_data *, int); |
521 | extern void td_restore_runstate(struct thread_data *, int); | |
522 | ||
cba5460c JA |
523 | /* |
524 | * Allow 60 seconds for a job to quit on its own, otherwise reap with | |
525 | * a vengeance. | |
526 | */ | |
527 | #define FIO_REAP_TIMEOUT 60 | |
528 | ||
cc0df00a JA |
529 | #define TERMINATE_ALL (-1) |
530 | extern void fio_terminate_threads(int); | |
ebea2133 | 531 | extern void fio_mark_td_terminate(struct thread_data *); |
b29ee5b3 | 532 | |
2f9ade3c JA |
533 | /* |
534 | * Memory helpers | |
535 | */ | |
9a3f1100 JA |
536 | extern int __must_check fio_pin_memory(struct thread_data *); |
537 | extern void fio_unpin_memory(struct thread_data *); | |
b2fdda43 | 538 | extern int __must_check allocate_io_mem(struct thread_data *); |
2f9ade3c | 539 | extern void free_io_mem(struct thread_data *); |
2bb3f0a7 | 540 | extern void free_threads_shm(void); |
2f9ade3c | 541 | |
b29ee5b3 JA |
542 | /* |
543 | * Reset stats after ramp time completes | |
544 | */ | |
545 | extern void reset_all_stats(struct thread_data *); | |
546 | ||
fb7b71a3 JA |
547 | /* |
548 | * blktrace support | |
549 | */ | |
5e62c22a | 550 | #ifdef FIO_HAVE_BLKTRACE |
d95b34a6 JA |
551 | extern int is_blktrace(const char *, int *); |
552 | extern int load_blktrace(struct thread_data *, const char *, int); | |
5e62c22a | 553 | #endif |
fb7b71a3 | 554 | |
3e260a46 JA |
555 | /* |
556 | * Latency target helpers | |
557 | */ | |
558 | extern void lat_target_check(struct thread_data *); | |
559 | extern void lat_target_init(struct thread_data *); | |
6bb58215 | 560 | extern void lat_target_reset(struct thread_data *); |
3e260a46 | 561 | |
34572e28 JA |
562 | #define for_each_td(td, i) \ |
563 | for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++) | |
53cdc686 | 564 | #define for_each_file(td, f, i) \ |
691c8fb0 JA |
565 | if ((td)->files_index) \ |
566 | for ((i) = 0, (f) = (td)->files[0]; \ | |
567 | (i) < (td)->o.nr_files && ((f) = (td)->files[i]) != NULL; \ | |
568 | (i)++) | |
53cdc686 | 569 | |
0032bf9f JA |
570 | #define fio_assert(td, cond) do { \ |
571 | if (!(cond)) { \ | |
340fd243 | 572 | int *__foo = NULL; \ |
0032bf9f | 573 | fprintf(stderr, "file:%s:%d, assert %s failed\n", __FILE__, __LINE__, #cond); \ |
ac18ea38 | 574 | td_set_runstate((td), TD_EXITED); \ |
437c9b71 | 575 | (td)->error = EFAULT; \ |
340fd243 | 576 | *__foo = 0; \ |
0032bf9f JA |
577 | } \ |
578 | } while (0) | |
579 | ||
12d9d841 JA |
580 | static inline int fio_fill_issue_time(struct thread_data *td) |
581 | { | |
582 | if (td->o.read_iolog_file || | |
583 | !td->o.disable_clat || !td->o.disable_slat || !td->o.disable_bw) | |
584 | return 1; | |
585 | ||
586 | return 0; | |
587 | } | |
588 | ||
581e7141 JA |
589 | static inline int __should_check_rate(struct thread_data *td, |
590 | enum fio_ddir ddir) | |
591 | { | |
592 | struct thread_options *o = &td->o; | |
593 | ||
594 | /* | |
595 | * If some rate setting was given, we need to check it | |
596 | */ | |
597 | if (o->rate[ddir] || o->ratemin[ddir] || o->rate_iops[ddir] || | |
598 | o->rate_iops_min[ddir]) | |
599 | return 1; | |
600 | ||
601 | return 0; | |
602 | } | |
603 | ||
55312f9f | 604 | static inline int should_check_rate(struct thread_data *td) |
581e7141 JA |
605 | { |
606 | int ret = 0; | |
607 | ||
55312f9f | 608 | if (td->bytes_done[DDIR_READ]) |
6eaf09d6 | 609 | ret |= __should_check_rate(td, DDIR_READ); |
55312f9f | 610 | if (td->bytes_done[DDIR_WRITE]) |
6eaf09d6 | 611 | ret |= __should_check_rate(td, DDIR_WRITE); |
55312f9f | 612 | if (td->bytes_done[DDIR_TRIM]) |
6eaf09d6 | 613 | ret |= __should_check_rate(td, DDIR_TRIM); |
581e7141 JA |
614 | |
615 | return ret; | |
616 | } | |
617 | ||
74f4b020 JA |
618 | static inline unsigned int td_max_bs(struct thread_data *td) |
619 | { | |
620 | unsigned int max_bs; | |
621 | ||
622 | max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]); | |
623 | return max(td->o.max_bs[DDIR_TRIM], max_bs); | |
624 | } | |
625 | ||
8d916c94 JA |
626 | static inline unsigned int td_min_bs(struct thread_data *td) |
627 | { | |
628 | unsigned int min_bs; | |
629 | ||
630 | min_bs = min(td->o.min_bs[DDIR_READ], td->o.min_bs[DDIR_WRITE]); | |
631 | return min(td->o.min_bs[DDIR_TRIM], min_bs); | |
632 | } | |
633 | ||
ca09be4b | 634 | static inline int is_power_of_2(uint64_t val) |
d529ee19 JA |
635 | { |
636 | return (val != 0 && ((val & (val - 1)) == 0)); | |
637 | } | |
638 | ||
a9da8ab2 JA |
639 | static inline int td_async_processing(struct thread_data *td) |
640 | { | |
641 | return (td->flags & TD_F_NEED_LOCK) != 0; | |
642 | } | |
643 | ||
e8462bd8 JA |
644 | /* |
645 | * We currently only need to do locking if we have verifier threads | |
646 | * accessing our internal structures too | |
647 | */ | |
648 | static inline void td_io_u_lock(struct thread_data *td) | |
649 | { | |
a9da8ab2 | 650 | if (td_async_processing(td)) |
e8462bd8 JA |
651 | pthread_mutex_lock(&td->io_u_lock); |
652 | } | |
653 | ||
654 | static inline void td_io_u_unlock(struct thread_data *td) | |
655 | { | |
a9da8ab2 | 656 | if (td_async_processing(td)) |
e8462bd8 JA |
657 | pthread_mutex_unlock(&td->io_u_lock); |
658 | } | |
659 | ||
660 | static inline void td_io_u_free_notify(struct thread_data *td) | |
661 | { | |
a9da8ab2 | 662 | if (td_async_processing(td)) |
e8462bd8 JA |
663 | pthread_cond_signal(&td->free_cond); |
664 | } | |
665 | ||
cca84643 JA |
666 | extern const char *fio_get_arch_string(int); |
667 | extern const char *fio_get_os_string(int); | |
668 | ||
e2c81040 | 669 | #ifdef FIO_INTERNAL |
05775438 | 670 | #define ARRAY_SIZE(x) (sizeof((x)) / (sizeof((x)[0]))) |
e2c81040 | 671 | #endif |
05775438 | 672 | |
f3afa57e JA |
673 | enum { |
674 | FIO_OUTPUT_TERSE = 0, | |
675 | FIO_OUTPUT_JSON, | |
676 | FIO_OUTPUT_NORMAL, | |
677 | }; | |
678 | ||
e25839d4 JA |
679 | enum { |
680 | FIO_RAND_DIST_RANDOM = 0, | |
681 | FIO_RAND_DIST_ZIPF, | |
925fee33 | 682 | FIO_RAND_DIST_PARETO, |
56d9fa4b | 683 | FIO_RAND_DIST_GAUSS, |
e25839d4 JA |
684 | }; |
685 | ||
c95f9404 JA |
686 | #define FIO_DEF_ZIPF 1.1 |
687 | #define FIO_DEF_PARETO 0.2 | |
688 | ||
8055e41d JA |
689 | enum { |
690 | FIO_RAND_GEN_TAUSWORTHE = 0, | |
691 | FIO_RAND_GEN_LFSR, | |
692 | }; | |
693 | ||
c2acfbac JA |
694 | enum { |
695 | FIO_CPUS_SHARED = 0, | |
696 | FIO_CPUS_SPLIT, | |
697 | }; | |
698 | ||
ca09be4b JA |
699 | extern void exec_trigger(const char *); |
700 | extern void check_trigger_file(void); | |
701 | ||
ebac4655 | 702 | #endif |