Allow fio to terminate jobs when steady state is attained
[fio.git] / fio.h
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>
9 #include <errno.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <string.h>
14 #include <inttypes.h>
15 #include <assert.h>
16
17 #include "compiler/compiler.h"
18 #include "thread_options.h"
19 #include "flist.h"
20 #include "fifo.h"
21 #include "arch/arch.h"
22 #include "os/os.h"
23 #include "mutex.h"
24 #include "log.h"
25 #include "debug.h"
26 #include "file.h"
27 #include "io_ddir.h"
28 #include "ioengine.h"
29 #include "iolog.h"
30 #include "helpers.h"
31 #include "options.h"
32 #include "profile.h"
33 #include "fio_time.h"
34 #include "gettime.h"
35 #include "oslib/getopt.h"
36 #include "lib/rand.h"
37 #include "lib/rbtree.h"
38 #include "client.h"
39 #include "server.h"
40 #include "stat.h"
41 #include "flow.h"
42 #include "io_u_queue.h"
43 #include "workqueue.h"
44
45 #ifdef CONFIG_SOLARISAIO
46 #include <sys/asynch.h>
47 #endif
48
49 #ifdef CONFIG_LIBNUMA
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
59 /*
60  * offset generator types
61  */
62 enum {
63         RW_SEQ_SEQ      = 0,
64         RW_SEQ_IDENT,
65 };
66
67 enum {
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,
81         TD_F_NO_PROGRESS        = 1U << 13,
82         TD_F_REGROW_LOGS        = 1U << 14,
83 };
84
85 enum {
86         FIO_RAND_BS_OFF         = 0,
87         FIO_RAND_VER_OFF,
88         FIO_RAND_MIX_OFF,
89         FIO_RAND_FILE_OFF,
90         FIO_RAND_BLOCK_OFF,
91         FIO_RAND_FILE_SIZE_OFF,
92         FIO_RAND_TRIM_OFF,
93         FIO_RAND_BUF_OFF,
94         FIO_RAND_SEQ_RAND_READ_OFF,
95         FIO_RAND_SEQ_RAND_WRITE_OFF,
96         FIO_RAND_SEQ_RAND_TRIM_OFF,
97         FIO_RAND_START_DELAY,
98         FIO_DEDUPE_OFF,
99         FIO_RAND_POISSON_OFF,
100         FIO_RAND_ZONE_OFF,
101         FIO_RAND_NR_OFFS,
102 };
103
104 enum {
105         IO_MODE_INLINE = 0,
106         IO_MODE_OFFLOAD = 1,
107
108         RATE_PROCESS_LINEAR = 0,
109         RATE_PROCESS_POISSON = 1,
110 };
111
112 /*
113  * Per-thread/process specific data. Only used for the network client
114  * for now.
115  */
116 struct sk_out;
117 void sk_out_assign(struct sk_out *);
118 void sk_out_drop(void);
119
120 struct zone_split_index {
121         uint8_t size_perc;
122         uint8_t size_perc_prev;
123 };
124
125 /*
126  * For steady state detection
127  */
128 struct steadystate_data {
129         double limit;
130         unsigned long long dur;
131         unsigned long long ramp_time;
132         bool (*evaluate)(unsigned long, unsigned long, struct thread_data *);
133         bool check_iops;
134         bool check_slope;
135         bool pct;
136
137         int attained;
138         int last_in_group;
139         int ramp_time_over;
140
141         unsigned int head;
142         unsigned int tail;
143         unsigned long *cache;
144
145         double criterion;
146
147         unsigned long long sum_y;
148         unsigned long long sum_x;
149         unsigned long long sum_x_sq;
150         unsigned long long sum_xy;
151         unsigned long long oldest_y;
152
153         struct timeval prev_time;
154         unsigned long long prev_iops;
155         unsigned long long prev_bytes;
156 };
157
158
159 /*
160  * This describes a single thread/process executing a fio job.
161  */
162 struct thread_data {
163         struct flist_head opt_list;
164         unsigned long flags;
165         struct thread_options o;
166         void *eo;
167         pthread_t thread;
168         unsigned int thread_number;
169         unsigned int subjob_number;
170         unsigned int groupid;
171         struct thread_stat ts;
172
173         int client_type;
174
175         struct io_log *slat_log;
176         struct io_log *clat_log;
177         struct io_log *clat_hist_log;
178         struct io_log *lat_log;
179         struct io_log *bw_log;
180         struct io_log *iops_log;
181
182         struct workqueue log_compress_wq;
183
184         struct thread_data *parent;
185
186         uint64_t stat_io_bytes[DDIR_RWDIR_CNT];
187         struct timeval bw_sample_time;
188
189         uint64_t stat_io_blocks[DDIR_RWDIR_CNT];
190         struct timeval iops_sample_time;
191
192         volatile int update_rusage;
193         struct fio_mutex *rusage_sem;
194         struct rusage ru_start;
195         struct rusage ru_end;
196
197         struct fio_file **files;
198         unsigned char *file_locks;
199         unsigned int files_size;
200         unsigned int files_index;
201         unsigned int nr_open_files;
202         unsigned int nr_done_files;
203         unsigned int nr_normal_files;
204         union {
205                 unsigned int next_file;
206                 struct frand_state next_file_state;
207         };
208         union {
209                 struct zipf_state next_file_zipf;
210                 struct gauss_state next_file_gauss;
211         };
212         union {
213                 double zipf_theta;
214                 double pareto_h;
215                 double gauss_dev;
216         };
217         int error;
218         int sig;
219         int done;
220         int stop_io;
221         pid_t pid;
222         char *orig_buffer;
223         size_t orig_buffer_size;
224         volatile int terminate;
225         volatile int runstate;
226         unsigned int last_was_sync;
227         enum fio_ddir last_ddir;
228
229         int mmapfd;
230
231         void *iolog_buf;
232         FILE *iolog_f;
233
234         char *sysfs_root;
235
236         unsigned long rand_seeds[FIO_RAND_NR_OFFS];
237
238         struct frand_state bsrange_state;
239         struct frand_state verify_state;
240         struct frand_state trim_state;
241         struct frand_state delay_state;
242
243         struct frand_state buf_state;
244         struct frand_state buf_state_prev;
245         struct frand_state dedupe_state;
246         struct frand_state zone_state;
247
248         struct zone_split_index **zone_state_index;
249
250         unsigned int verify_batch;
251         unsigned int trim_batch;
252
253         struct thread_io_list *vstate;
254
255         int shm_id;
256
257         /*
258          * IO engine hooks, contains everything needed to submit an io_u
259          * to any of the available IO engines.
260          */
261         struct ioengine_ops *io_ops;
262
263         /*
264          * IO engine private data and dlhandle.
265          */
266         void *io_ops_data;
267         void *io_ops_dlhandle;
268
269         /*
270          * Queue depth of io_u's that fio MIGHT do
271          */
272         unsigned int cur_depth;
273
274         /*
275          * io_u's about to be committed
276          */
277         unsigned int io_u_queued;
278
279         /*
280          * io_u's submitted but not completed yet
281          */
282         unsigned int io_u_in_flight;
283
284         /*
285          * List of free and busy io_u's
286          */
287         struct io_u_ring io_u_requeues;
288         struct io_u_queue io_u_freelist;
289         struct io_u_queue io_u_all;
290         pthread_mutex_t io_u_lock;
291         pthread_cond_t free_cond;
292
293         /*
294          * async verify offload
295          */
296         struct flist_head verify_list;
297         pthread_t *verify_threads;
298         unsigned int nr_verify_threads;
299         pthread_cond_t verify_cond;
300         int verify_thread_exit;
301
302         /*
303          * Rate state
304          */
305         uint64_t rate_bps[DDIR_RWDIR_CNT];
306         unsigned long rate_next_io_time[DDIR_RWDIR_CNT];
307         unsigned long rate_bytes[DDIR_RWDIR_CNT];
308         unsigned long rate_blocks[DDIR_RWDIR_CNT];
309         unsigned long rate_io_issue_bytes[DDIR_RWDIR_CNT];
310         struct timeval lastrate[DDIR_RWDIR_CNT];
311         int64_t last_usec;
312         struct frand_state poisson_state;
313
314         /*
315          * Enforced rate submission/completion workqueue
316          */
317         struct workqueue io_wq;
318
319         uint64_t total_io_size;
320         uint64_t fill_device_size;
321
322         /*
323          * Issue side
324          */
325         uint64_t io_issues[DDIR_RWDIR_CNT];
326         uint64_t io_issue_bytes[DDIR_RWDIR_CNT];
327         uint64_t loops;
328
329         /*
330          * Completions
331          */
332         uint64_t io_blocks[DDIR_RWDIR_CNT];
333         uint64_t this_io_blocks[DDIR_RWDIR_CNT];
334         uint64_t io_bytes[DDIR_RWDIR_CNT];
335         uint64_t this_io_bytes[DDIR_RWDIR_CNT];
336         uint64_t io_skip_bytes;
337         uint64_t zone_bytes;
338         struct fio_mutex *mutex;
339         uint64_t bytes_done[DDIR_RWDIR_CNT];
340
341         /*
342          * State for random io, a bitmap of blocks done vs not done
343          */
344         struct frand_state random_state;
345
346         struct timeval start;   /* start of this loop */
347         struct timeval epoch;   /* time job was started */
348         struct timeval last_issue;
349         long time_offset;
350         struct timeval tv_cache;
351         struct timeval terminate_time;
352         unsigned int tv_cache_nr;
353         unsigned int tv_cache_mask;
354         unsigned int ramp_time_over;
355
356         /*
357          * Time since last latency_window was started
358          */
359         struct timeval latency_ts;
360         unsigned int latency_qd;
361         unsigned int latency_qd_high;
362         unsigned int latency_qd_low;
363         unsigned int latency_failed;
364         uint64_t latency_ios;
365         int latency_end_run;
366
367         /*
368          * read/write mixed workload state
369          */
370         struct frand_state rwmix_state;
371         unsigned long rwmix_issues;
372         enum fio_ddir rwmix_ddir;
373         unsigned int ddir_seq_nr;
374
375         /*
376          * rand/seq mixed workload state
377          */
378         struct frand_state seq_rand_state[DDIR_RWDIR_CNT];
379
380         /*
381          * IO history logs for verification. We use a tree for sorting,
382          * if we are overwriting. Otherwise just use a fifo.
383          */
384         struct rb_root io_hist_tree;
385         struct flist_head io_hist_list;
386         unsigned long io_hist_len;
387
388         /*
389          * For IO replaying
390          */
391         struct flist_head io_log_list;
392
393         /*
394          * For tracking/handling discards
395          */
396         struct flist_head trim_list;
397         unsigned long trim_entries;
398
399         struct flist_head next_rand_list;
400
401         /*
402          * for fileservice, how often to switch to a new file
403          */
404         unsigned int file_service_nr;
405         unsigned int file_service_left;
406         struct fio_file *file_service_file;
407
408         unsigned int sync_file_range_nr;
409
410         /*
411          * For generating file sizes
412          */
413         struct frand_state file_size_state;
414
415         /*
416          * Error counts
417          */
418         unsigned int total_err_count;
419         int first_error;
420
421         struct fio_flow *flow;
422
423         /*
424          * Can be overloaded by profiles
425          */
426         struct prof_io_ops prof_io_ops;
427         void *prof_data;
428
429         void *pinned_mem;
430
431         struct steadystate_data ss;
432
433         char verror[FIO_VERROR_SIZE];
434 };
435
436 /*
437  * when should interactive ETA output be generated
438  */
439 enum {
440         FIO_ETA_AUTO,
441         FIO_ETA_ALWAYS,
442         FIO_ETA_NEVER,
443 };
444
445 #define __td_verror(td, err, msg, func)                                 \
446         do {                                                            \
447                 unsigned int ____e = (err);                             \
448                 if ((td)->error)                                        \
449                         break;                                          \
450                 (td)->error = ____e;                                    \
451                 if (!(td)->first_error)                                 \
452                         snprintf(td->verror, sizeof(td->verror), "file:%s:%d, func=%s, error=%s", __FILE__, __LINE__, (func), (msg));           \
453         } while (0)
454
455
456 #define td_clear_error(td)              do {            \
457         (td)->error = 0;                                \
458         if ((td)->parent)                               \
459                 (td)->parent->error = 0;                \
460 } while (0)
461
462 #define td_verror(td, err, func)        do {                    \
463         __td_verror((td), (err), strerror((err)), (func));      \
464         if ((td)->parent)                                       \
465                 __td_verror((td)->parent, (err), strerror((err)), (func)); \
466 } while (0)
467
468 #define td_vmsg(td, err, msg, func)     do {                    \
469         __td_verror((td), (err), (msg), (func));                \
470         if ((td)->parent)                                       \
471                 __td_verror((td)->parent, (err), (msg), (func));        \
472 } while (0)
473
474 #define __fio_stringify_1(x)    #x
475 #define __fio_stringify(x)      __fio_stringify_1(x)
476
477 extern int exitall_on_terminate;
478 extern unsigned int thread_number;
479 extern unsigned int stat_number;
480 extern int shm_id;
481 extern int groupid;
482 extern int output_format;
483 extern int append_terse_output;
484 extern int temp_stall_ts;
485 extern uintptr_t page_mask, page_size;
486 extern int read_only;
487 extern int eta_print;
488 extern int eta_new_line;
489 extern unsigned long done_secs;
490 extern char *job_section;
491 extern int fio_gtod_offload;
492 extern int fio_gtod_cpu;
493 extern enum fio_cs fio_clock_source;
494 extern int fio_clock_source_set;
495 extern int warnings_fatal;
496 extern int terse_version;
497 extern int is_backend;
498 extern int nr_clients;
499 extern int log_syslog;
500 extern int status_interval;
501 extern const char fio_version_string[];
502 extern char *trigger_file;
503 extern char *trigger_cmd;
504 extern char *trigger_remote_cmd;
505 extern long long trigger_timeout;
506 extern char *aux_path;
507
508 extern bool steadystate;
509 #define STEADYSTATE_MSEC (1000)
510
511 extern struct thread_data *threads;
512
513 static inline void fio_ro_check(const struct thread_data *td, struct io_u *io_u)
514 {
515         assert(!(io_u->ddir == DDIR_WRITE && !td_write(td)));
516 }
517
518 #define REAL_MAX_JOBS           2048
519
520 static inline int should_fsync(struct thread_data *td)
521 {
522         if (td->last_was_sync)
523                 return 0;
524         if (td_write(td) || td_rw(td) || td->o.override_sync)
525                 return 1;
526
527         return 0;
528 }
529
530 /*
531  * Init/option functions
532  */
533 extern int __must_check fio_init_options(void);
534 extern int __must_check parse_options(int, char **);
535 extern int parse_jobs_ini(char *, int, int, int);
536 extern int parse_cmd_line(int, char **, int);
537 extern int fio_backend(struct sk_out *);
538 extern void reset_fio_state(void);
539 extern void clear_io_state(struct thread_data *, int);
540 extern int fio_options_parse(struct thread_data *, char **, int);
541 extern void fio_keywords_init(void);
542 extern void fio_keywords_exit(void);
543 extern int fio_cmd_option_parse(struct thread_data *, const char *, char *);
544 extern int fio_cmd_ioengine_option_parse(struct thread_data *, const char *, char *);
545 extern void fio_fill_default_options(struct thread_data *);
546 extern int fio_show_option_help(const char *);
547 extern void fio_options_set_ioengine_opts(struct option *long_options, struct thread_data *td);
548 extern void fio_options_dup_and_init(struct option *);
549 extern void fio_options_mem_dupe(struct thread_data *);
550 extern void options_mem_dupe(void *data, struct fio_option *options);
551 extern void td_fill_rand_seeds(struct thread_data *);
552 extern void td_fill_verify_state_seed(struct thread_data *);
553 extern void add_job_opts(const char **, int);
554 extern char *num2str(uint64_t, int, int, int, int);
555 extern int ioengine_load(struct thread_data *);
556 extern int parse_dryrun(void);
557 extern int fio_running_or_pending_io_threads(void);
558 extern int fio_set_fd_nonblocking(int, const char *);
559 extern void sig_show_status(int sig);
560 extern struct thread_data *get_global_options(void);
561
562 extern uintptr_t page_mask;
563 extern uintptr_t page_size;
564 extern int initialize_fio(char *envp[]);
565 extern void deinitialize_fio(void);
566
567 #define FIO_GETOPT_JOB          0x89000000
568 #define FIO_GETOPT_IOENGINE     0x98000000
569 #define FIO_NR_OPTIONS          (FIO_MAX_OPTS + 128)
570
571 /*
572  * ETA/status stuff
573  */
574 extern void print_thread_status(void);
575 extern void print_status_init(int);
576 extern char *fio_uint_to_kmg(unsigned int val);
577
578 /*
579  * Thread life cycle. Once a thread has a runstate beyond TD_INITIALIZED, it
580  * will never back again. It may cycle between running/verififying/fsyncing.
581  * Once the thread reaches TD_EXITED, it is just waiting for the core to
582  * reap it.
583  */
584 enum {
585         TD_NOT_CREATED = 0,
586         TD_CREATED,
587         TD_INITIALIZED,
588         TD_RAMP,
589         TD_SETTING_UP,
590         TD_RUNNING,
591         TD_PRE_READING,
592         TD_VERIFYING,
593         TD_FSYNCING,
594         TD_FINISHING,
595         TD_EXITED,
596         TD_REAPED,
597         TD_LAST,
598         TD_NR,
599 };
600
601 #define TD_ENG_FLAG_SHIFT       16
602 #define TD_ENG_FLAG_MASK        ((1U << 16) - 1)
603
604 static inline enum fio_ioengine_flags td_ioengine_flags(struct thread_data *td)
605 {
606         return (td->flags >> TD_ENG_FLAG_SHIFT) & TD_ENG_FLAG_MASK;
607 }
608
609 static inline void td_set_ioengine_flags(struct thread_data *td)
610 {
611         td->flags |= (td->io_ops->flags << TD_ENG_FLAG_SHIFT);
612 }
613
614 static inline bool td_ioengine_flagged(struct thread_data *td, unsigned int val)
615 {
616         return ((td->flags >> TD_ENG_FLAG_SHIFT) & val) != 0;
617 }
618
619 extern void td_set_runstate(struct thread_data *, int);
620 extern int td_bump_runstate(struct thread_data *, int);
621 extern void td_restore_runstate(struct thread_data *, int);
622 extern const char *runstate_to_name(int runstate);
623
624 /*
625  * Allow 60 seconds for a job to quit on its own, otherwise reap with
626  * a vengeance.
627  */
628 #define FIO_REAP_TIMEOUT        60
629
630 #define TERMINATE_ALL           (-1U)
631 extern void fio_terminate_threads(unsigned int);
632 extern void fio_mark_td_terminate(struct thread_data *);
633
634 /*
635  * Memory helpers
636  */
637 extern int __must_check fio_pin_memory(struct thread_data *);
638 extern void fio_unpin_memory(struct thread_data *);
639 extern int __must_check allocate_io_mem(struct thread_data *);
640 extern void free_io_mem(struct thread_data *);
641 extern void free_threads_shm(void);
642
643 /*
644  * Reset stats after ramp time completes
645  */
646 extern void reset_all_stats(struct thread_data *);
647
648 /*
649  * blktrace support
650  */
651 #ifdef FIO_HAVE_BLKTRACE
652 extern int is_blktrace(const char *, int *);
653 extern int load_blktrace(struct thread_data *, const char *, int);
654 #endif
655
656 extern int io_queue_event(struct thread_data *td, struct io_u *io_u, int *ret,
657                    enum fio_ddir ddir, uint64_t *bytes_issued, int from_verify,
658                    struct timeval *comp_time);
659
660 /*
661  * Latency target helpers
662  */
663 extern void lat_target_check(struct thread_data *);
664 extern void lat_target_init(struct thread_data *);
665 extern void lat_target_reset(struct thread_data *);
666
667 #define for_each_td(td, i)      \
668         for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++)
669 #define for_each_file(td, f, i) \
670         if ((td)->files_index)                                          \
671                 for ((i) = 0, (f) = (td)->files[0];                     \
672                  (i) < (td)->o.nr_files && ((f) = (td)->files[i]) != NULL; \
673                  (i)++)
674
675 #define fio_assert(td, cond)    do {    \
676         if (!(cond)) {                  \
677                 int *__foo = NULL;      \
678                 fprintf(stderr, "file:%s:%d, assert %s failed\n", __FILE__, __LINE__, #cond);   \
679                 td_set_runstate((td), TD_EXITED);       \
680                 (td)->error = EFAULT;           \
681                 *__foo = 0;                     \
682         }       \
683 } while (0)
684
685 static inline int fio_fill_issue_time(struct thread_data *td)
686 {
687         if (td->o.read_iolog_file ||
688             !td->o.disable_clat || !td->o.disable_slat || !td->o.disable_bw)
689                 return 1;
690
691         return 0;
692 }
693
694 static inline int __should_check_rate(struct thread_data *td,
695                                       enum fio_ddir ddir)
696 {
697         struct thread_options *o = &td->o;
698
699         /*
700          * If some rate setting was given, we need to check it
701          */
702         if (o->rate[ddir] || o->ratemin[ddir] || o->rate_iops[ddir] ||
703             o->rate_iops_min[ddir])
704                 return 1;
705
706         return 0;
707 }
708
709 static inline int should_check_rate(struct thread_data *td)
710 {
711         int ret = 0;
712
713         if (td->bytes_done[DDIR_READ])
714                 ret |= __should_check_rate(td, DDIR_READ);
715         if (td->bytes_done[DDIR_WRITE])
716                 ret |= __should_check_rate(td, DDIR_WRITE);
717         if (td->bytes_done[DDIR_TRIM])
718                 ret |= __should_check_rate(td, DDIR_TRIM);
719
720         return ret;
721 }
722
723 static inline unsigned int td_max_bs(struct thread_data *td)
724 {
725         unsigned int max_bs;
726
727         max_bs = max(td->o.max_bs[DDIR_READ], td->o.max_bs[DDIR_WRITE]);
728         return max(td->o.max_bs[DDIR_TRIM], max_bs);
729 }
730
731 static inline unsigned int td_min_bs(struct thread_data *td)
732 {
733         unsigned int min_bs;
734
735         min_bs = min(td->o.min_bs[DDIR_READ], td->o.min_bs[DDIR_WRITE]);
736         return min(td->o.min_bs[DDIR_TRIM], min_bs);
737 }
738
739 static inline bool td_async_processing(struct thread_data *td)
740 {
741         return (td->flags & TD_F_NEED_LOCK) != 0;
742 }
743
744 /*
745  * We currently only need to do locking if we have verifier threads
746  * accessing our internal structures too
747  */
748 static inline void td_io_u_lock(struct thread_data *td)
749 {
750         if (td_async_processing(td))
751                 pthread_mutex_lock(&td->io_u_lock);
752 }
753
754 static inline void td_io_u_unlock(struct thread_data *td)
755 {
756         if (td_async_processing(td))
757                 pthread_mutex_unlock(&td->io_u_lock);
758 }
759
760 static inline void td_io_u_free_notify(struct thread_data *td)
761 {
762         if (td_async_processing(td))
763                 pthread_cond_signal(&td->free_cond);
764 }
765
766 static inline void td_flags_clear(struct thread_data *td, unsigned int *flags,
767                                   unsigned int value)
768 {
769         if (!td_async_processing(td))
770                 *flags &= ~value;
771         else
772                 __sync_fetch_and_and(flags, ~value);
773 }
774
775 static inline void td_flags_set(struct thread_data *td, unsigned int *flags,
776                                 unsigned int value)
777 {
778         if (!td_async_processing(td))
779                 *flags |= value;
780         else
781                 __sync_fetch_and_or(flags, value);
782 }
783
784 extern const char *fio_get_arch_string(int);
785 extern const char *fio_get_os_string(int);
786
787 #ifdef FIO_INTERNAL
788 #define ARRAY_SIZE(x)    (sizeof((x)) / (sizeof((x)[0])))
789 #define FIELD_SIZE(s, f) (sizeof(((typeof(s))0)->f))
790 #endif
791
792 enum {
793         __FIO_OUTPUT_TERSE      = 0,
794         __FIO_OUTPUT_JSON       = 1,
795         __FIO_OUTPUT_NORMAL     = 2,
796         __FIO_OUTPUT_JSON_PLUS  = 3,
797         FIO_OUTPUT_NR           = 4,
798
799         FIO_OUTPUT_TERSE        = 1U << __FIO_OUTPUT_TERSE,
800         FIO_OUTPUT_JSON         = 1U << __FIO_OUTPUT_JSON,
801         FIO_OUTPUT_NORMAL       = 1U << __FIO_OUTPUT_NORMAL,
802         FIO_OUTPUT_JSON_PLUS    = 1U << __FIO_OUTPUT_JSON_PLUS,
803 };
804
805 enum {
806         FIO_RAND_DIST_RANDOM    = 0,
807         FIO_RAND_DIST_ZIPF,
808         FIO_RAND_DIST_PARETO,
809         FIO_RAND_DIST_GAUSS,
810         FIO_RAND_DIST_ZONED,
811 };
812
813 #define FIO_DEF_ZIPF            1.1
814 #define FIO_DEF_PARETO          0.2
815
816 enum {
817         FIO_RAND_GEN_TAUSWORTHE = 0,
818         FIO_RAND_GEN_LFSR,
819         FIO_RAND_GEN_TAUSWORTHE64,
820 };
821
822 enum {
823         FIO_CPUS_SHARED         = 0,
824         FIO_CPUS_SPLIT,
825 };
826
827 enum {
828         FIO_STEADYSTATE_IOPS    = 0,
829         FIO_STEADYSTATE_IOPS_SLOPE,
830         FIO_STEADYSTATE_BW,
831         FIO_STEADYSTATE_BW_SLOPE,
832 };
833
834
835 extern void exec_trigger(const char *);
836 extern void check_trigger_file(void);
837
838 #endif