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