Cleanup verify headers
[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>
214e1eca 14#include <getopt.h>
cd14cc10 15#include <inttypes.h>
7101d9c2 16#include <assert.h>
ebac4655 17
317b95d0 18#include "compiler/compiler.h"
01743ee1 19#include "flist.h"
e2887563 20#include "fifo.h"
4b87898e 21#include "rbtree.h"
317b95d0
JA
22#include "arch/arch.h"
23#include "os/os.h"
07739b57 24#include "mutex.h"
a3d741fa
JA
25#include "log.h"
26#include "debug.h"
d6aed795
JA
27#include "file.h"
28#include "io_ddir.h"
ebac4655 29
609342ff
DL
30#ifdef FIO_HAVE_GUASI
31#include <guasi.h>
32#endif
33
417f0068
JA
34#ifdef FIO_HAVE_SOLARISAIO
35#include <sys/asynch.h>
36#endif
37
1c9e06ee
JA
38/*
39 * Use for maintaining statistics
40 */
ebac4655 41struct io_stat {
ebac4655
JA
42 unsigned long max_val;
43 unsigned long min_val;
44 unsigned long samples;
68704084
JA
45
46 double mean;
47 double S;
ebac4655
JA
48};
49
1c9e06ee
JA
50/*
51 * A single data sample
52 */
ebac4655
JA
53struct io_sample {
54 unsigned long time;
55 unsigned long val;
1e97cce9 56 enum fio_ddir ddir;
306ddc97 57 unsigned int bs;
ebac4655
JA
58};
59
1c9e06ee
JA
60/*
61 * Dynamically growing data sample log
62 */
ebac4655
JA
63struct io_log {
64 unsigned long nr_samples;
65 unsigned long max_samples;
66 struct io_sample *log;
67};
68
1c9e06ee
JA
69/*
70 * When logging io actions, this matches a single sent io_u
71 */
ebac4655 72struct io_piece {
4b87898e
JA
73 union {
74 struct rb_node rb_node;
01743ee1 75 struct flist_head list;
4b87898e 76 };
f29b25a3
JA
77 union {
78 int fileno;
79 struct fio_file *file;
80 };
ebac4655 81 unsigned long long offset;
a4f4fdd7 82 unsigned long len;
1e97cce9 83 enum fio_ddir ddir;
f29b25a3
JA
84 union {
85 unsigned long delay;
86 unsigned int file_action;
87 };
ebac4655
JA
88};
89
0c6e7517
JA
90enum {
91 IO_U_F_FREE = 1 << 0,
92 IO_U_F_FLIGHT = 1 << 1,
93};
94
36690c9b
JA
95struct thread_data;
96
ebac4655
JA
97/*
98 * The io unit
99 */
100struct io_u {
101 union {
102#ifdef FIO_HAVE_LIBAIO
103 struct iocb iocb;
104#endif
105#ifdef FIO_HAVE_POSIXAIO
106 struct aiocb aiocb;
107#endif
108#ifdef FIO_HAVE_SGIO
109 struct sg_io_hdr hdr;
a4f4fdd7 110#endif
609342ff
DL
111#ifdef FIO_HAVE_GUASI
112 guasi_req_t greq;
417f0068
JA
113#endif
114#ifdef FIO_HAVE_SOLARISAIO
115 aio_result_t resultp;
ebac4655 116#endif
ac893112 117 void *mmap_data;
ebac4655
JA
118 };
119 struct timeval start_time;
120 struct timeval issue_time;
121
1c9e06ee
JA
122 /*
123 * Allocated/set buffer and length
124 */
6b9cea23 125 void *buf;
a4f4fdd7 126 unsigned long buflen;
ebac4655
JA
127 unsigned long long offset;
128
1c9e06ee
JA
129 /*
130 * IO engine state, may be different from above when we get
131 * partial transfers / residual data counts
132 */
cec6b55d 133 void *xfer_buf;
a4f4fdd7 134 unsigned long xfer_buflen;
cec6b55d 135
ebac4655
JA
136 unsigned int resid;
137 unsigned int error;
138
1e97cce9 139 enum fio_ddir ddir;
ebac4655 140
dfd7bc2c
JA
141 /*
142 * io engine private data
143 */
144 union {
145 unsigned int index;
146 unsigned int seen;
556e831d 147 void *engine_data;
dfd7bc2c
JA
148 };
149
0c6e7517
JA
150 unsigned int flags;
151
53cdc686
JA
152 struct fio_file *file;
153
01743ee1 154 struct flist_head list;
d7762cf8
JA
155
156 /*
157 * Callback for io completion
158 */
36690c9b 159 int (*end_io)(struct thread_data *, struct io_u *);
ebac4655
JA
160};
161
36167d82
JA
162/*
163 * io_ops->queue() return values
164 */
165enum {
166 FIO_Q_COMPLETED = 0, /* completed sync */
167 FIO_Q_QUEUED = 1, /* queued, will complete async */
755200a3 168 FIO_Q_BUSY = 2, /* no more room, call ->commit() */
36167d82
JA
169};
170
ebac4655 171struct group_run_stats {
9104f874
JA
172 unsigned long long max_run[2], min_run[2];
173 unsigned long long max_bw[2], min_bw[2];
e9b2a3fa 174 unsigned long long io_kb[2];
9104f874 175 unsigned long long agg[2];
ebac4655
JA
176};
177
e9c047a0
JA
178/*
179 * What type of allocation to use for io buffers
180 */
181enum fio_memtype {
182 MEM_MALLOC = 0, /* ordinary malloc */
183 MEM_SHM, /* use shared memory segments */
74b025b0 184 MEM_SHMHUGE, /* use shared memory segments with huge pages */
e9c047a0 185 MEM_MMAP, /* use anonynomous mmap */
d0bdaf49 186 MEM_MMAPHUGE, /* memory mapped huge file */
e9c047a0
JA
187};
188
2866c82d 189enum fio_ioengine_flags {
1c9e06ee 190 FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */
ba0fbe10
JA
191 FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */
192 FIO_DISKLESSIO = 1 << 2, /* no disk involved */
0263882a 193 FIO_NOEXTEND = 1 << 3, /* engine can't extend file */
62d984e2 194 FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */
b67740d3 195 FIO_UNIDIR = 1 << 5, /* engine is uni-directional */
1f809d15 196 FIO_NOIO = 1 << 6, /* thread does only pseudo IO */
ad830ed7 197 FIO_SIGQUIT = 1 << 7, /* needs SIGQUIT to exit */
e9c047a0
JA
198};
199
b2560f3c
JA
200/*
201 * How many depth levels to log
202 */
203#define FIO_IO_U_MAP_NR 8
a9a18a3f
JA
204#define FIO_IO_U_LAT_U_NR 10
205#define FIO_IO_U_LAT_M_NR 12
b2560f3c 206
079ad09b 207struct thread_stat {
756867bd
JA
208 char *name;
209 char *verror;
210 int error;
211 int groupid;
212 pid_t pid;
213 char *description;
6586ee89 214 int members;
756867bd 215
079ad09b
JA
216 struct io_log *slat_log;
217 struct io_log *clat_log;
218 struct io_log *bw_log;
219
220 /*
221 * bandwidth and latency stats
222 */
223 struct io_stat clat_stat[2]; /* completion latency */
224 struct io_stat slat_stat[2]; /* submission latency */
225 struct io_stat bw_stat[2]; /* bandwidth stats */
226
227 unsigned long long stat_io_bytes[2];
228 struct timeval stat_sample_time[2];
229
230 /*
231 * fio system usage accounting
232 */
233 struct rusage ru_start;
234 struct rusage ru_end;
235 unsigned long usr_time;
236 unsigned long sys_time;
237 unsigned long ctx;
81887d5d 238 unsigned long minf, majf;
079ad09b 239
b2560f3c
JA
240 /*
241 * IO depth and latency stats
242 */
243 unsigned int io_u_map[FIO_IO_U_MAP_NR];
838bc709
JA
244 unsigned int io_u_submit[FIO_IO_U_MAP_NR];
245 unsigned int io_u_complete[FIO_IO_U_MAP_NR];
04a0feae
JA
246 unsigned int io_u_lat_u[FIO_IO_U_LAT_U_NR];
247 unsigned int io_u_lat_m[FIO_IO_U_LAT_M_NR];
b3605062 248 unsigned long total_io_u[2];
30061b97 249 unsigned long short_io_u[2];
838bc709
JA
250 unsigned long total_submit;
251 unsigned long total_complete;
756867bd
JA
252
253 unsigned long long io_bytes[2];
254 unsigned long runtime[2];
255 unsigned long total_run_time;
b2560f3c 256};
71619dc2 257
564ca972
JA
258struct bssplit {
259 unsigned int bs;
260 unsigned char perc;
261};
262
2dc1bbeb 263struct thread_options {
b1ec1da6 264 int pad;
61697c37 265 char *description;
b4692828 266 char *name;
ef899b63 267 char *directory;
13f8e2d2 268 char *filename;
2dc1bbeb 269 char *opendir;
09629a90 270 char *ioengine;
413dd459 271 enum td_ddir td_ddir;
211097b2 272 unsigned int ddir_nr;
2dc1bbeb
JA
273 unsigned int iodepth;
274 unsigned int iodepth_low;
275 unsigned int iodepth_batch;
4950421a 276 unsigned int iodepth_batch_complete;
2dc1bbeb
JA
277
278 unsigned long long size;
aa31f1f1 279 unsigned int fill_device;
2dc1bbeb
JA
280 unsigned long long file_size_low;
281 unsigned long long file_size_high;
282 unsigned long long start_offset;
283
284 unsigned int bs[2];
2b7a01d0 285 unsigned int ba[2];
2dc1bbeb
JA
286 unsigned int min_bs[2];
287 unsigned int max_bs[2];
720e84ad
JA
288 struct bssplit *bssplit[2];
289 unsigned int bssplit_nr[2];
2dc1bbeb
JA
290
291 unsigned int nr_files;
292 unsigned int open_files;
4d4e80f2 293 enum file_lock_mode file_lock_mode;
29c1349f 294 unsigned int lockfile_batch;
e9c047a0 295
9158d2f7
JA
296 unsigned int odirect;
297 unsigned int invalidate_cache;
298 unsigned int create_serialize;
299 unsigned int create_fsync;
814452bd 300 unsigned int create_on_open;
9158d2f7 301 unsigned int end_fsync;
afad68f7 302 unsigned int pre_read;
9158d2f7
JA
303 unsigned int sync_io;
304 unsigned int verify;
e84c73a8 305 unsigned int do_verify;
160b966d 306 unsigned int verifysort;
a59e170d
JA
307 unsigned int verify_interval;
308 unsigned int verify_offset;
90059d65
JA
309 unsigned int verify_pattern;
310 unsigned int verify_pattern_bytes;
a12a3b4d 311 unsigned int verify_fatal;
9158d2f7
JA
312 unsigned int use_thread;
313 unsigned int unlink;
314 unsigned int do_disk_util;
315 unsigned int override_sync;
316 unsigned int rand_repeatable;
317 unsigned int write_lat_log;
318 unsigned int write_bw_log;
bb8895e0 319 unsigned int norandommap;
2b386d25 320 unsigned int softrandommap;
690adba3 321 unsigned int bs_unaligned;
ebb1415f 322 unsigned int fsync_on_close;
e9c047a0 323
56bb17f2 324 unsigned int hugepage_size;
a00735e6 325 unsigned int rw_min_bs;
ebac4655 326 unsigned int thinktime;
48097d5c 327 unsigned int thinktime_spin;
9c1f7434 328 unsigned int thinktime_blocks;
ebac4655
JA
329 unsigned int fsync_blocks;
330 unsigned int start_delay;
0db26797 331 unsigned long long timeout;
721938ae 332 unsigned long long ramp_time;
ebac4655 333 unsigned int overwrite;
ebac4655 334 unsigned int bw_avg_time;
ebac4655 335 unsigned int loops;
20dc95c4
JA
336 unsigned long long zone_size;
337 unsigned long long zone_skip;
e9c047a0 338 enum fio_memtype mem_type;
2dc1bbeb 339
ebac4655 340 unsigned int stonewall;
b3d62a75 341 unsigned int new_group;
ebac4655 342 unsigned int numjobs;
ebac4655 343 os_cpu_mask_t cpumask;
375b2695 344 unsigned int cpumask_set;
aea47d44 345 unsigned int iolog;
a6ccc7be 346 unsigned int rwmixcycle;
e47f799f 347 unsigned int rwmix[2];
b6f4d880 348 unsigned int nice;
0aabe160 349 unsigned int file_service_type;
b2560f3c 350 unsigned int group_reporting;
d2f3ac35 351 unsigned int fadvise_hint;
e9459e5a 352 unsigned int zero_buffers;
5973cafb 353 unsigned int refill_buffers;
cf4464ca 354 unsigned int time_based;
9520ebb9
JA
355 unsigned int disable_clat;
356 unsigned int disable_slat;
357 unsigned int disable_bw;
993bf48b 358 unsigned int gtod_reduce;
be4ecfdf
JA
359 unsigned int gtod_cpu;
360 unsigned int gtod_offload;
aea47d44 361
076efc7c
JA
362 char *read_iolog_file;
363 char *write_iolog_file;
e3cedca7
JA
364 char *bw_log_file;
365 char *lat_log_file;
2dc1bbeb
JA
366
367 /*
368 * Pre-run and post-run shell
369 */
370 char *exec_prerun;
371 char *exec_postrun;
372
373 unsigned int rate;
374 unsigned int ratemin;
375 unsigned int ratecycle;
376 unsigned int rate_iops;
377 unsigned int rate_iops_min;
378
379 char *ioscheduler;
380
381 /*
382 * CPU "io" cycle burner
383 */
384 unsigned int cpuload;
385 unsigned int cpucycle;
386};
387
e4e33258
JA
388#define FIO_VERROR_SIZE 128
389
2dc1bbeb
JA
390/*
391 * This describes a single thread/process executing a fio job.
392 */
393struct thread_data {
394 struct thread_options o;
e4e33258 395 char verror[FIO_VERROR_SIZE];
2dc1bbeb
JA
396 pthread_t thread;
397 int thread_number;
398 int groupid;
399 struct thread_stat ts;
126d65c6 400 struct fio_file **files;
dd87b2c9 401 unsigned int files_size;
2dc1bbeb
JA
402 unsigned int files_index;
403 unsigned int nr_open_files;
1020a139 404 unsigned int nr_done_files;
2dc1bbeb
JA
405 unsigned int nr_normal_files;
406 union {
407 unsigned int next_file;
408 os_random_state_t next_file_state;
409 };
410 int error;
20e354ef 411 int done;
2dc1bbeb
JA
412 pid_t pid;
413 char *orig_buffer;
414 size_t orig_buffer_size;
415 volatile int terminate;
416 volatile int runstate;
417 unsigned int ioprio;
ac684785 418 unsigned int ioprio_set;
2dc1bbeb
JA
419 unsigned int last_was_sync;
420
421 char *mmapfile;
422 int mmapfd;
423
843a7413
JA
424 void *iolog_buf;
425 FILE *iolog_f;
ebac4655 426
da86774e 427 char *sysfs_root;
da86774e 428
5bfc35d7
JA
429 unsigned long rand_seeds[6];
430
6dfd46b9
JA
431 os_random_state_t bsrange_state;
432 os_random_state_t verify_state;
ebac4655
JA
433
434 int shm_id;
435
e9c047a0
JA
436 /*
437 * IO engine hooks, contains everything needed to submit an io_u
438 * to any of the available IO engines.
439 */
2866c82d 440 struct ioengine_ops *io_ops;
ebac4655 441
e9c047a0
JA
442 /*
443 * Current IO depth and list of free and busy io_u's.
444 */
ebac4655 445 unsigned int cur_depth;
d8005759 446 unsigned int io_u_queued;
01743ee1
JA
447 struct flist_head io_u_freelist;
448 struct flist_head io_u_busylist;
449 struct flist_head io_u_requeues;
ebac4655 450
e9c047a0
JA
451 /*
452 * Rate state
453 */
ebac4655
JA
454 unsigned long rate_usec_cycle;
455 long rate_pending_usleep;
456 unsigned long rate_bytes;
4e991c23 457 unsigned long rate_blocks;
ebac4655
JA
458 struct timeval lastrate;
459
ebac4655
JA
460 unsigned long long total_io_size;
461
755200a3 462 unsigned long io_issues[2];
9104f874
JA
463 unsigned long long io_blocks[2];
464 unsigned long long io_bytes[2];
48f5abd3 465 unsigned long long io_skip_bytes;
9104f874 466 unsigned long long this_io_bytes[2];
079ad09b 467 unsigned long long zone_bytes;
cdd18ad8 468 struct fio_mutex *mutex;
ebac4655 469
e9c047a0
JA
470 /*
471 * State for random io, a bitmap of blocks done vs not done
472 */
6dfd46b9 473 os_random_state_t random_state;
ebac4655 474
ebac4655
JA
475 struct timeval start; /* start of this loop */
476 struct timeval epoch; /* time job was started */
38d77cae 477 struct timeval rw_end[2];
a61eddec 478 struct timeval last_issue;
993bf48b
JA
479 struct timeval tv_cache;
480 unsigned int tv_cache_nr;
481 unsigned int tv_cache_mask;
38d77cae 482 unsigned int rw_end_set[2];
721938ae 483 unsigned int ramp_time_over;
ebac4655 484
e9c047a0
JA
485 /*
486 * read/write mixed workload state
487 */
6dfd46b9 488 os_random_state_t rwmix_state;
e4928662 489 unsigned long rwmix_issues;
e9c047a0 490 enum fio_ddir rwmix_ddir;
211097b2 491 unsigned int ddir_nr;
a6ccc7be 492
e9c047a0 493 /*
8de8f047
JA
494 * IO history logs for verification. We use a tree for sorting,
495 * if we are overwriting. Otherwise just use a fifo.
e9c047a0 496 */
4b87898e 497 struct rb_root io_hist_tree;
01743ee1 498 struct flist_head io_hist_list;
8de8f047
JA
499
500 /*
501 * For IO replaying
502 */
01743ee1 503 struct flist_head io_log_list;
433afcb4 504
1907dbc6
JA
505 /*
506 * for fileservice, how often to switch to a new file
507 */
508 unsigned int file_service_nr;
509 unsigned int file_service_left;
510 struct fio_file *file_service_file;
9c60ce64
JA
511
512 /*
513 * For generating file sizes
514 */
515 os_random_state_t file_size_state;
ebac4655
JA
516};
517
0aabe160 518/*
a086c257
JA
519 * roundrobin available files, or choose one at random, or do each one
520 * serially.
0aabe160
JA
521 */
522enum {
523 FIO_FSERVICE_RANDOM = 1,
524 FIO_FSERVICE_RR = 2,
a086c257 525 FIO_FSERVICE_SEQ = 3,
0aabe160
JA
526};
527
e592a06b
AC
528/*
529 * when should interactive ETA output be generated
530 */
531enum {
532 FIO_ETA_AUTO,
533 FIO_ETA_ALWAYS,
534 FIO_ETA_NEVER,
535};
536
e1161c32 537#define __td_verror(td, err, msg, func) \
ebac4655 538 do { \
19abcd3d
JA
539 if ((td)->error) \
540 break; \
ebac4655
JA
541 int e = (err); \
542 (td)->error = e; \
e1161c32 543 snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, func=%s, error=%s", __FILE__, __LINE__, (func), (msg)); \
ebac4655
JA
544 } while (0)
545
b990b5c0 546
e1161c32
JA
547#define td_verror(td, err, func) \
548 __td_verror((td), (err), strerror((err)), (func))
549#define td_vmsg(td, err, msg, func) \
550 __td_verror((td), (err), (msg), (func))
b990b5c0 551
ebac4655
JA
552extern int exitall_on_terminate;
553extern int thread_number;
9cedf167 554extern int nr_process, nr_thread;
ebac4655
JA
555extern int shm_id;
556extern int groupid;
c6ae0a5b 557extern int terse_output;
53cdc686 558extern int temp_stall_ts;
1e97cce9 559extern unsigned long long mlock_size;
cfc99db7 560extern unsigned long page_mask, page_size;
4241ea8f 561extern int read_only;
e592a06b 562extern int eta_print;
d3eeeabc 563extern unsigned long done_secs;
01f06b63 564extern char *job_section;
be4ecfdf
JA
565extern int fio_gtod_offload;
566extern int fio_gtod_cpu;
ebac4655
JA
567
568extern struct thread_data *threads;
569
2dc1bbeb
JA
570#define td_read(td) ((td)->o.td_ddir & TD_DDIR_READ)
571#define td_write(td) ((td)->o.td_ddir & TD_DDIR_WRITE)
572#define td_rw(td) (((td)->o.td_ddir & TD_DDIR_RW) == TD_DDIR_RW)
573#define td_random(td) ((td)->o.td_ddir & TD_DDIR_RAND)
303032ae 574#define file_randommap(td, f) (!(td)->o.norandommap && (f)->file_map)
ebac4655 575
7101d9c2
JA
576static inline void fio_ro_check(struct thread_data *td, struct io_u *io_u)
577{
578 assert(!(io_u->ddir == DDIR_WRITE && !td_write(td)));
579}
580
de605666 581#define BLOCKS_PER_MAP (8 * sizeof(int))
aec2de20
JA
582#define TO_MAP_BLOCK(f, b) (b)
583#define RAND_MAP_IDX(f, b) (TO_MAP_BLOCK(f, b) / BLOCKS_PER_MAP)
584#define RAND_MAP_BIT(f, b) (TO_MAP_BLOCK(f, b) & (BLOCKS_PER_MAP - 1))
ebac4655
JA
585
586#define MAX_JOBS (1024)
587
87dc1ab1
JA
588static inline int should_fsync(struct thread_data *td)
589{
590 if (td->last_was_sync)
591 return 0;
2dc1bbeb 592 if (td->o.odirect)
87dc1ab1 593 return 0;
2dc1bbeb 594 if (td_write(td) || td_rw(td) || td->o.override_sync)
87dc1ab1
JA
595 return 1;
596
597 return 0;
598}
599
1c9e06ee
JA
600/*
601 * Disk utils as read in /sys/block/<dev>/stat
602 */
ebac4655
JA
603struct disk_util_stat {
604 unsigned ios[2];
605 unsigned merges[2];
606 unsigned long long sectors[2];
607 unsigned ticks[2];
608 unsigned io_ticks;
609 unsigned time_in_queue;
610};
611
1c9e06ee
JA
612/*
613 * Per-device disk util management
614 */
ebac4655 615struct disk_util {
01743ee1 616 struct flist_head list;
67423013
ST
617 /* If this disk is a slave, hook it into the master's
618 * list using this head.
619 */
620 struct flist_head slavelist;
ebac4655
JA
621
622 char *name;
e11c410c 623 char *sysfs_root;
ebac4655 624 char path[256];
07e5b264 625 int major, minor;
ebac4655
JA
626
627 struct disk_util_stat dus;
628 struct disk_util_stat last_dus;
629
67423013
ST
630 /* For software raids, this entry maintains pointers to the
631 * entries for the slave devices. The disk_util entries for
632 * the slaves devices should primarily be maintained through
633 * the disk_list list, i.e. for memory allocation and
634 * de-allocation, etc. Whereas this list should be used only
635 * for aggregating a software RAID's disk util figures.
636 */
637 struct flist_head slaves;
638
ebac4655
JA
639 unsigned long msec;
640 struct timeval time;
c97bd0fa
JA
641
642 struct fio_mutex *lock;
643 unsigned long users;
ebac4655
JA
644};
645
c97bd0fa
JA
646static inline void disk_util_inc(struct disk_util *du)
647{
648 if (du) {
649 fio_mutex_down(du->lock);
650 du->users++;
651 fio_mutex_up(du->lock);
652 }
653}
654
655static inline void disk_util_dec(struct disk_util *du)
656{
657 if (du) {
658 fio_mutex_down(du->lock);
659 du->users--;
660 fio_mutex_up(du->lock);
661 }
662}
663
ebac4655
JA
664#define DISK_UTIL_MSEC (250)
665
6796209a
JA
666/*
667 * Log exports
668 */
f29b25a3
JA
669enum file_log_act {
670 FIO_LOG_ADD_FILE,
671 FIO_LOG_OPEN_FILE,
672 FIO_LOG_CLOSE_FILE,
f718273e 673 FIO_LOG_UNLINK_FILE,
f29b25a3
JA
674};
675
72cb971b 676extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
f29b25a3
JA
677extern void log_io_u(struct thread_data *, struct io_u *);
678extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
72cb971b 679extern int __must_check init_iolog(struct thread_data *td);
6796209a 680extern void log_io_piece(struct thread_data *, struct io_u *);
691c8fb0 681extern void queue_io_piece(struct thread_data *, struct io_piece *);
6796209a
JA
682extern void prune_io_piece_log(struct thread_data *);
683extern void write_iolog_close(struct thread_data *);
684
685/*
686 * Logging
687 */
306ddc97
JA
688extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long,
689 unsigned int);
690extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long,
691 unsigned int);
692extern void add_bw_sample(struct thread_data *, enum fio_ddir, unsigned int,
693 struct timeval *);
6796209a
JA
694extern void show_run_stats(void);
695extern void init_disk_util(struct thread_data *);
696extern void update_rusage_stat(struct thread_data *);
697extern void update_io_ticks(void);
8914a9d8
JA
698extern void setup_log(struct io_log **);
699extern void finish_log(struct thread_data *, struct io_log *, const char *);
e3cedca7 700extern void finish_log_named(struct thread_data *, struct io_log *, const char *, const char *);
bb3884d8 701extern void __finish_log(struct io_log *, const char *);
bb3884d8
JA
702extern struct io_log *agg_io_log[2];
703extern int write_bw_log;
306ddc97 704extern void add_agg_sample(unsigned long, enum fio_ddir, unsigned int);
6796209a
JA
705
706/*
707 * Time functions
708 */
10927316
SL
709extern unsigned long long utime_since(struct timeval *, struct timeval *);
710extern unsigned long long utime_since_now(struct timeval *);
6796209a
JA
711extern unsigned long mtime_since(struct timeval *, struct timeval *);
712extern unsigned long mtime_since_now(struct timeval *);
713extern unsigned long time_since_now(struct timeval *);
263e529f 714extern unsigned long mtime_since_genesis(void);
6dd6f2cd 715extern void usec_spin(unsigned int);
6796209a 716extern void usec_sleep(struct thread_data *, unsigned long);
413dd459 717extern void rate_throttle(struct thread_data *, unsigned long, unsigned int);
6043c579 718extern void fill_start_time(struct timeval *);
02bcaa8c 719extern void fio_gettime(struct timeval *, void *);
be4ecfdf
JA
720extern void fio_gtod_init(void);
721extern void fio_gtod_update(void);
a2f77c9f 722extern void set_genesis_time(void);
721938ae 723extern int ramp_time_over(struct thread_data *);
b29ee5b3 724extern int in_ramp_time(struct thread_data *);
6796209a 725
8914a9d8 726/*
214e1eca 727 * Init/option functions
8914a9d8 728 */
72cb971b 729extern int __must_check parse_options(int, char **);
3b8b7135 730extern int fio_options_parse(struct thread_data *, char **, int);
214e1eca
JA
731extern int fio_cmd_option_parse(struct thread_data *, const char *, char *);
732extern void fio_fill_default_options(struct thread_data *);
733extern int fio_show_option_help(const char *);
734extern void fio_options_dup_and_init(struct option *);
d23bb327
JA
735extern void options_mem_dupe(struct thread_data *);
736extern void options_mem_free(struct thread_data *);
5bfc35d7 737extern void td_fill_rand_seeds(struct thread_data *);
214e1eca
JA
738#define FIO_GETOPT_JOB 0x89988998
739#define FIO_NR_OPTIONS 128
8914a9d8 740
53cdc686
JA
741/*
742 * File setup/shutdown
743 */
744extern void close_files(struct thread_data *);
24ffd2c2 745extern void close_and_free_files(struct thread_data *);
b2fdda43 746extern int __must_check setup_files(struct thread_data *);
b2fdda43 747extern int __must_check file_invalidate_cache(struct thread_data *, struct fio_file *);
b5af8293 748extern int __must_check generic_open_file(struct thread_data *, struct fio_file *);
6977bcd0 749extern int __must_check generic_close_file(struct thread_data *, struct fio_file *);
df9c26b1 750extern int __must_check generic_get_file_size(struct thread_data *, struct fio_file *);
afad68f7 751extern int __must_check pre_read_files(struct thread_data *);
f29b25a3 752extern int add_file(struct thread_data *, const char *);
0ad920e7 753extern void get_file(struct fio_file *);
6977bcd0 754extern int __must_check put_file(struct thread_data *, struct fio_file *);
4d4e80f2
JA
755extern void lock_file(struct thread_data *, struct fio_file *, enum fio_ddir);
756extern void unlock_file(struct thread_data *, struct fio_file *);
757extern void unlock_file_all(struct thread_data *, struct fio_file *);
bbf6b540 758extern int add_dir_files(struct thread_data *, const char *);
68727076 759extern int init_random_map(struct thread_data *);
cade3ef4 760extern void dup_files(struct thread_data *, struct thread_data *);
f29b25a3
JA
761extern int get_fileno(struct thread_data *, const char *);
762extern void free_release_files(struct thread_data *);
53cdc686 763
263e529f
JA
764/*
765 * ETA/status stuff
766 */
767extern void print_thread_status(void);
768extern void print_status_init(int);
769
9f8f2064
JA
770/*
771 * disk util stuff
772 */
773#ifdef FIO_HAVE_DISK_UTIL
774extern void show_disk_util(void);
9f8f2064
JA
775extern void init_disk_util(struct thread_data *);
776extern void update_io_ticks(void);
777#else
778#define show_disk_util()
9f8f2064
JA
779#define init_disk_util(td)
780#define update_io_ticks()
781#endif
782
263e529f
JA
783/*
784 * Thread life cycle. Once a thread has a runstate beyond TD_INITIALIZED, it
785 * will never back again. It may cycle between running/verififying/fsyncing.
786 * Once the thread reaches TD_EXITED, it is just waiting for the core to
787 * reap it.
788 */
789enum {
790 TD_NOT_CREATED = 0,
791 TD_CREATED,
792 TD_INITIALIZED,
b29ee5b3 793 TD_RAMP,
263e529f 794 TD_RUNNING,
b0f65863 795 TD_PRE_READING,
263e529f
JA
796 TD_VERIFYING,
797 TD_FSYNCING,
798 TD_EXITED,
799 TD_REAPED,
800};
801
b29ee5b3
JA
802extern void td_set_runstate(struct thread_data *, int);
803
2f9ade3c
JA
804/*
805 * Memory helpers
806 */
b2fdda43 807extern int __must_check fio_pin_memory(void);
2f9ade3c 808extern void fio_unpin_memory(void);
b2fdda43 809extern int __must_check allocate_io_mem(struct thread_data *);
2f9ade3c
JA
810extern void free_io_mem(struct thread_data *);
811
10ba535a
JA
812/*
813 * io unit handling
814 */
01743ee1 815#define queue_full(td) flist_empty(&(td)->io_u_freelist)
10ba535a 816extern struct io_u *__get_io_u(struct thread_data *);
3d7c391d 817extern struct io_u *get_io_u(struct thread_data *);
10ba535a 818extern void put_io_u(struct thread_data *, struct io_u *);
755200a3 819extern void requeue_io_u(struct thread_data *, struct io_u **);
d7762cf8
JA
820extern long __must_check io_u_sync_complete(struct thread_data *, struct io_u *);
821extern long __must_check io_u_queued_complete(struct thread_data *, int);
7e77dd02 822extern void io_u_queued(struct thread_data *, struct io_u *);
5451792e 823extern void io_u_log_error(struct thread_data *, struct io_u *);
d8005759 824extern void io_u_mark_depth(struct thread_data *, unsigned int);
5973cafb 825extern void io_u_fill_buffer(struct thread_data *td, struct io_u *, unsigned int);
838bc709
JA
826void io_u_mark_complete(struct thread_data *, unsigned int);
827void io_u_mark_submit(struct thread_data *, unsigned int);
10ba535a 828
b29ee5b3
JA
829/*
830 * Reset stats after ramp time completes
831 */
832extern void reset_all_stats(struct thread_data *);
833
10ba535a
JA
834/*
835 * io engine entry points
836 */
b2fdda43
JA
837extern int __must_check td_io_init(struct thread_data *);
838extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
839extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
840extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
e7d2e616 841extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *);
b2fdda43 842extern int __must_check td_io_commit(struct thread_data *);
b5af8293 843extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
6977bcd0 844extern int td_io_close_file(struct thread_data *, struct fio_file *);
df9c26b1 845extern int __must_check td_io_get_file_size(struct thread_data *, struct fio_file *);
10ba535a 846
fb7b71a3
JA
847/*
848 * blktrace support
849 */
5e62c22a 850#ifdef FIO_HAVE_BLKTRACE
fb7b71a3
JA
851extern int is_blktrace(const char *);
852extern int load_blktrace(struct thread_data *, const char *);
5e62c22a 853#endif
fb7b71a3 854
2866c82d 855struct ioengine_ops {
01743ee1 856 struct flist_head list;
2866c82d
JA
857 char name[16];
858 int version;
859 int flags;
ea2877a4 860 int (*setup)(struct thread_data *);
2866c82d
JA
861 int (*init)(struct thread_data *);
862 int (*prep)(struct thread_data *, struct io_u *);
863 int (*queue)(struct thread_data *, struct io_u *);
755200a3 864 int (*commit)(struct thread_data *);
e7d2e616 865 int (*getevents)(struct thread_data *, unsigned int, unsigned int, struct timespec *);
2866c82d
JA
866 struct io_u *(*event)(struct thread_data *, int);
867 int (*cancel)(struct thread_data *, struct io_u *);
868 void (*cleanup)(struct thread_data *);
b5af8293 869 int (*open_file)(struct thread_data *, struct fio_file *);
6977bcd0 870 int (*close_file)(struct thread_data *, struct fio_file *);
df9c26b1 871 int (*get_file_size)(struct thread_data *, struct fio_file *);
2866c82d
JA
872 void *data;
873 void *dlhandle;
874};
875
df9c26b1 876#define FIO_IOOPS_VERSION 10
2866c82d 877
b4692828 878extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
b2fdda43 879extern void register_ioengine(struct ioengine_ops *);
5f350952 880extern void unregister_ioengine(struct ioengine_ops *);
2866c82d
JA
881extern void close_ioengine(struct thread_data *);
882
883/*
884 * Mark unused variables passed to ops functions as unused, to silence gcc
885 */
886#define fio_unused __attribute((__unused__))
5f350952
JA
887#define fio_init __attribute__((constructor))
888#define fio_exit __attribute__((destructor))
2866c82d 889
34572e28
JA
890#define for_each_td(td, i) \
891 for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++)
53cdc686 892#define for_each_file(td, f, i) \
691c8fb0
JA
893 if ((td)->files_index) \
894 for ((i) = 0, (f) = (td)->files[0]; \
895 (i) < (td)->o.nr_files && ((f) = (td)->files[i]) != NULL; \
896 (i)++)
53cdc686 897
0032bf9f
JA
898#define fio_assert(td, cond) do { \
899 if (!(cond)) { \
340fd243 900 int *__foo = NULL; \
0032bf9f
JA
901 fprintf(stderr, "file:%s:%d, assert %s failed\n", __FILE__, __LINE__, #cond); \
902 (td)->runstate = TD_EXITED; \
437c9b71 903 (td)->error = EFAULT; \
340fd243 904 *__foo = 0; \
0032bf9f
JA
905 } \
906} while (0)
907
009bd847
JA
908static inline void fio_file_reset(struct fio_file *f)
909{
910 f->last_free_lookup = 0;
911 f->last_pos = f->file_offset;
eaf9b417
JA
912 if (f->file_map)
913 memset(f->file_map, 0, f->num_maps * sizeof(int));
009bd847
JA
914}
915
9bf27b45
JA
916static inline void clear_error(struct thread_data *td)
917{
918 td->error = 0;
919 td->verror[0] = '\0';
920}
921
79e48f72 922#ifdef FIO_INC_DEBUG
2ba1c290
JA
923static inline void dprint_io_u(struct io_u *io_u, const char *p)
924{
925 struct fio_file *f = io_u->file;
926
927 dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
5921e80c
JA
928 (unsigned long long) io_u->offset,
929 io_u->buflen, io_u->ddir);
8172fe97
JA
930 if (fio_debug & (1 << FD_IO)) {
931 if (f)
932 log_info("/%s", f->file_name);
933
934 log_info("\n");
935 }
2ba1c290 936}
79e48f72 937#else
79e48f72
JA
938#define dprint_io_u(io_u, p)
939#endif
2ba1c290 940
12d9d841
JA
941static inline int fio_fill_issue_time(struct thread_data *td)
942{
943 if (td->o.read_iolog_file ||
944 !td->o.disable_clat || !td->o.disable_slat || !td->o.disable_bw)
945 return 1;
946
947 return 0;
948}
949
ebac4655 950#endif