Base the rwmix switch algorithm on io issues
[fio.git] / fio.h
... / ...
CommitLineData
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 <getopt.h>
15#include <inttypes.h>
16#include <assert.h>
17
18#include "compiler/compiler.h"
19#include "list.h"
20#include "fifo.h"
21#include "rbtree.h"
22#include "arch/arch.h"
23#include "os/os.h"
24#include "mutex.h"
25#include "log.h"
26#include "debug.h"
27
28#ifdef FIO_HAVE_GUASI
29#include <guasi.h>
30#endif
31
32enum fio_ddir {
33 DDIR_READ = 0,
34 DDIR_WRITE,
35 DDIR_SYNC,
36 DDIR_INVAL = -1,
37};
38
39enum td_ddir {
40 TD_DDIR_READ = 1 << 0,
41 TD_DDIR_WRITE = 1 << 1,
42 TD_DDIR_RAND = 1 << 2,
43 TD_DDIR_RW = TD_DDIR_READ | TD_DDIR_WRITE,
44 TD_DDIR_RANDREAD = TD_DDIR_READ | TD_DDIR_RAND,
45 TD_DDIR_RANDWRITE = TD_DDIR_WRITE | TD_DDIR_RAND,
46 TD_DDIR_RANDRW = TD_DDIR_RW | TD_DDIR_RAND,
47};
48
49enum file_lock_mode {
50 FILE_LOCK_NONE,
51 FILE_LOCK_EXCLUSIVE,
52 FILE_LOCK_READWRITE,
53};
54
55/*
56 * Use for maintaining statistics
57 */
58struct io_stat {
59 unsigned long max_val;
60 unsigned long min_val;
61 unsigned long samples;
62
63 double mean;
64 double S;
65};
66
67/*
68 * A single data sample
69 */
70struct io_sample {
71 unsigned long time;
72 unsigned long val;
73 enum fio_ddir ddir;
74};
75
76/*
77 * Dynamically growing data sample log
78 */
79struct io_log {
80 unsigned long nr_samples;
81 unsigned long max_samples;
82 struct io_sample *log;
83};
84
85/*
86 * When logging io actions, this matches a single sent io_u
87 */
88struct io_piece {
89 union {
90 struct rb_node rb_node;
91 struct list_head list;
92 };
93 union {
94 int fileno;
95 struct fio_file *file;
96 };
97 unsigned long long offset;
98 unsigned long len;
99 enum fio_ddir ddir;
100 union {
101 unsigned long delay;
102 unsigned int file_action;
103 };
104};
105
106enum {
107 IO_U_F_FREE = 1 << 0,
108 IO_U_F_FLIGHT = 1 << 1,
109};
110
111struct thread_data;
112
113/*
114 * The io unit
115 */
116struct io_u {
117 union {
118#ifdef FIO_HAVE_LIBAIO
119 struct iocb iocb;
120#endif
121#ifdef FIO_HAVE_POSIXAIO
122 struct aiocb aiocb;
123#endif
124#ifdef FIO_HAVE_SGIO
125 struct sg_io_hdr hdr;
126#endif
127#ifdef FIO_HAVE_GUASI
128 guasi_req_t greq;
129#endif
130 };
131 struct timeval start_time;
132 struct timeval issue_time;
133
134 /*
135 * Allocated/set buffer and length
136 */
137 void *buf;
138 unsigned long buflen;
139 unsigned long long offset;
140 unsigned long long endpos;
141
142 /*
143 * IO engine state, may be different from above when we get
144 * partial transfers / residual data counts
145 */
146 void *xfer_buf;
147 unsigned long xfer_buflen;
148
149 unsigned int resid;
150 unsigned int error;
151
152 enum fio_ddir ddir;
153
154 /*
155 * io engine private data
156 */
157 union {
158 unsigned int index;
159 unsigned int seen;
160 };
161
162 unsigned int flags;
163
164 struct fio_file *file;
165
166 struct list_head list;
167
168 /*
169 * Callback for io completion
170 */
171 int (*end_io)(struct thread_data *, struct io_u *);
172};
173
174/*
175 * io_ops->queue() return values
176 */
177enum {
178 FIO_Q_COMPLETED = 0, /* completed sync */
179 FIO_Q_QUEUED = 1, /* queued, will complete async */
180 FIO_Q_BUSY = 2, /* no more room, call ->commit() */
181};
182
183#define FIO_HDR_MAGIC 0xf00baaef
184
185enum {
186 VERIFY_NONE = 0, /* no verification */
187 VERIFY_MD5, /* md5 sum data blocks */
188 VERIFY_CRC64, /* crc64 sum data blocks */
189 VERIFY_CRC32, /* crc32 sum data blocks */
190 VERIFY_CRC16, /* crc16 sum data blocks */
191 VERIFY_CRC7, /* crc7 sum data blocks */
192 VERIFY_SHA256, /* sha256 sum data blocks */
193 VERIFY_SHA512, /* sha512 sum data blocks */
194 VERIFY_META, /* block_num, timestamp etc. */
195 VERIFY_NULL, /* pretend to verify */
196};
197
198/*
199 * A header structure associated with each checksummed data block. It is
200 * followed by a checksum specific header that contains the verification
201 * data.
202 */
203struct verify_header {
204 unsigned int fio_magic;
205 unsigned int len;
206 unsigned int verify_type;
207};
208
209struct vhdr_md5 {
210 uint32_t md5_digest[16];
211};
212struct vhdr_sha512 {
213 uint8_t sha512[128];
214};
215struct vhdr_sha256 {
216 uint8_t sha256[128];
217};
218struct vhdr_crc64 {
219 uint64_t crc64;
220};
221struct vhdr_crc32 {
222 uint32_t crc32;
223};
224struct vhdr_crc16 {
225 uint16_t crc16;
226};
227struct vhdr_crc7 {
228 uint8_t crc7;
229};
230struct vhdr_meta {
231 uint64_t offset;
232 unsigned char thread;
233 unsigned short numberio;
234 unsigned long time_sec;
235 unsigned long time_usec;
236};
237
238struct group_run_stats {
239 unsigned long long max_run[2], min_run[2];
240 unsigned long long max_bw[2], min_bw[2];
241 unsigned long long io_kb[2];
242 unsigned long long agg[2];
243};
244
245/*
246 * What type of allocation to use for io buffers
247 */
248enum fio_memtype {
249 MEM_MALLOC = 0, /* ordinary malloc */
250 MEM_SHM, /* use shared memory segments */
251 MEM_SHMHUGE, /* use shared memory segments with huge pages */
252 MEM_MMAP, /* use anonynomous mmap */
253 MEM_MMAPHUGE, /* memory mapped huge file */
254};
255
256/*
257 * The type of object we are working on
258 */
259enum fio_filetype {
260 FIO_TYPE_FILE = 1, /* plain file */
261 FIO_TYPE_BD, /* block device */
262 FIO_TYPE_CHAR, /* character device */
263 FIO_TYPE_PIPE, /* pipe */
264};
265
266enum fio_ioengine_flags {
267 FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */
268 FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */
269 FIO_DISKLESSIO = 1 << 2, /* no disk involved */
270 FIO_NOEXTEND = 1 << 3, /* engine can't extend file */
271 FIO_NODISKUTIL = 1 << 4, /* diskutil can't handle filename */
272 FIO_UNIDIR = 1 << 5, /* engine is uni-directional */
273 FIO_NOIO = 1 << 6, /* thread does only pseudo IO */
274 FIO_SIGQUIT = 1 << 7, /* needs SIGQUIT to exit */
275};
276
277enum fio_file_flags {
278 FIO_FILE_OPEN = 1 << 0, /* file is open */
279 FIO_FILE_CLOSING = 1 << 1, /* file being closed */
280 FIO_FILE_EXTEND = 1 << 2, /* needs extend */
281 FIO_FILE_DONE = 1 << 3, /* io completed to this file */
282 FIO_SIZE_KNOWN = 1 << 4, /* size has been set */
283 FIO_FILE_HASHED = 1 << 5, /* file is on hash */
284};
285
286/*
287 * Each thread_data structure has a number of files associated with it,
288 * this structure holds state information for a single file.
289 */
290struct fio_file {
291 struct list_head hash_list;
292 enum fio_filetype filetype;
293
294 /*
295 * A file may not be a file descriptor, let the io engine decide
296 */
297 union {
298 unsigned long file_data;
299 int fd;
300 };
301
302 /*
303 * filename and possible memory mapping
304 */
305 char *file_name;
306 void *mmap;
307 unsigned int major, minor;
308
309 /*
310 * size of the file, offset into file, and io size from that offset
311 */
312 unsigned long long real_file_size;
313 unsigned long long file_offset;
314 unsigned long long io_size;
315
316 unsigned long long last_pos;
317
318 /*
319 * if io is protected by a semaphore, this is set
320 */
321 struct fio_mutex *lock;
322 void *lock_owner;
323 unsigned int lock_batch;
324 enum fio_ddir lock_ddir;
325
326 /*
327 * block map for random io
328 */
329 unsigned long *file_map;
330 unsigned int num_maps;
331 unsigned int last_free_lookup;
332
333 int references;
334 enum fio_file_flags flags;
335};
336
337/*
338 * How many depth levels to log
339 */
340#define FIO_IO_U_MAP_NR 8
341#define FIO_IO_U_LAT_U_NR 10
342#define FIO_IO_U_LAT_M_NR 12
343
344struct thread_stat {
345 char *name;
346 char *verror;
347 int error;
348 int groupid;
349 pid_t pid;
350 char *description;
351 int members;
352
353 struct io_log *slat_log;
354 struct io_log *clat_log;
355 struct io_log *bw_log;
356
357 /*
358 * bandwidth and latency stats
359 */
360 struct io_stat clat_stat[2]; /* completion latency */
361 struct io_stat slat_stat[2]; /* submission latency */
362 struct io_stat bw_stat[2]; /* bandwidth stats */
363
364 unsigned long long stat_io_bytes[2];
365 struct timeval stat_sample_time[2];
366
367 /*
368 * fio system usage accounting
369 */
370 struct rusage ru_start;
371 struct rusage ru_end;
372 unsigned long usr_time;
373 unsigned long sys_time;
374 unsigned long ctx;
375 unsigned long minf, majf;
376
377 /*
378 * IO depth and latency stats
379 */
380 unsigned int io_u_map[FIO_IO_U_MAP_NR];
381 unsigned int io_u_lat_u[FIO_IO_U_LAT_U_NR];
382 unsigned int io_u_lat_m[FIO_IO_U_LAT_M_NR];
383 unsigned long total_io_u[2];
384 unsigned long short_io_u[2];
385
386 unsigned long long io_bytes[2];
387 unsigned long runtime[2];
388 unsigned long total_run_time;
389};
390
391struct bssplit {
392 unsigned int bs;
393 unsigned char perc;
394};
395
396struct thread_options {
397 int pad;
398 char *description;
399 char *name;
400 char *directory;
401 char *filename;
402 char *opendir;
403 char *ioengine;
404 enum td_ddir td_ddir;
405 unsigned int ddir_nr;
406 unsigned int iodepth;
407 unsigned int iodepth_low;
408 unsigned int iodepth_batch;
409
410 unsigned long long size;
411 unsigned int fill_device;
412 unsigned long long file_size_low;
413 unsigned long long file_size_high;
414 unsigned long long start_offset;
415
416 unsigned int bs[2];
417 unsigned int min_bs[2];
418 unsigned int max_bs[2];
419 struct bssplit *bssplit;
420 unsigned int bssplit_nr;
421
422 unsigned int nr_files;
423 unsigned int open_files;
424 enum file_lock_mode file_lock_mode;
425 unsigned int lockfile_batch;
426
427 unsigned int odirect;
428 unsigned int invalidate_cache;
429 unsigned int create_serialize;
430 unsigned int create_fsync;
431 unsigned int end_fsync;
432 unsigned int sync_io;
433 unsigned int verify;
434 unsigned int do_verify;
435 unsigned int verifysort;
436 unsigned int verify_interval;
437 unsigned int verify_offset;
438 unsigned int verify_pattern;
439 unsigned int verify_pattern_bytes;
440 unsigned int verify_fatal;
441 unsigned int use_thread;
442 unsigned int unlink;
443 unsigned int do_disk_util;
444 unsigned int override_sync;
445 unsigned int rand_repeatable;
446 unsigned int write_lat_log;
447 unsigned int write_bw_log;
448 unsigned int norandommap;
449 unsigned int softrandommap;
450 unsigned int bs_unaligned;
451 unsigned int fsync_on_close;
452
453 unsigned int hugepage_size;
454 unsigned int rw_min_bs;
455 unsigned int thinktime;
456 unsigned int thinktime_spin;
457 unsigned int thinktime_blocks;
458 unsigned int fsync_blocks;
459 unsigned int start_delay;
460 unsigned long long timeout;
461 unsigned int overwrite;
462 unsigned int bw_avg_time;
463 unsigned int loops;
464 unsigned long long zone_size;
465 unsigned long long zone_skip;
466 enum fio_memtype mem_type;
467
468 unsigned int stonewall;
469 unsigned int new_group;
470 unsigned int numjobs;
471 os_cpu_mask_t cpumask;
472 unsigned int cpumask_set;
473 unsigned int iolog;
474 unsigned int rwmixcycle;
475 unsigned int rwmix[2];
476 unsigned int nice;
477 unsigned int file_service_type;
478 unsigned int group_reporting;
479 unsigned int fadvise_hint;
480 unsigned int zero_buffers;
481 unsigned int time_based;
482
483 char *read_iolog_file;
484 char *write_iolog_file;
485
486 /*
487 * Pre-run and post-run shell
488 */
489 char *exec_prerun;
490 char *exec_postrun;
491
492 unsigned int rate;
493 unsigned int ratemin;
494 unsigned int ratecycle;
495 unsigned int rate_iops;
496 unsigned int rate_iops_min;
497
498 char *ioscheduler;
499
500 /*
501 * CPU "io" cycle burner
502 */
503 unsigned int cpuload;
504 unsigned int cpucycle;
505};
506
507#define FIO_VERROR_SIZE 128
508
509/*
510 * This describes a single thread/process executing a fio job.
511 */
512struct thread_data {
513 struct thread_options o;
514 char verror[FIO_VERROR_SIZE];
515 pthread_t thread;
516 int thread_number;
517 int groupid;
518 struct thread_stat ts;
519 struct fio_file **files;
520 unsigned int files_index;
521 unsigned int nr_open_files;
522 unsigned int nr_done_files;
523 unsigned int nr_normal_files;
524 union {
525 unsigned int next_file;
526 os_random_state_t next_file_state;
527 };
528 int error;
529 int done;
530 pid_t pid;
531 char *orig_buffer;
532 size_t orig_buffer_size;
533 volatile int terminate;
534 volatile int runstate;
535 unsigned int ioprio;
536 unsigned int ioprio_set;
537 unsigned int last_was_sync;
538
539 char *mmapfile;
540 int mmapfd;
541
542 void *iolog_buf;
543 FILE *iolog_f;
544
545 char *sysfs_root;
546
547 os_random_state_t bsrange_state;
548 os_random_state_t verify_state;
549
550 int shm_id;
551
552 /*
553 * IO engine hooks, contains everything needed to submit an io_u
554 * to any of the available IO engines.
555 */
556 struct ioengine_ops *io_ops;
557
558 /*
559 * Current IO depth and list of free and busy io_u's.
560 */
561 unsigned int cur_depth;
562 struct list_head io_u_freelist;
563 struct list_head io_u_busylist;
564 struct list_head io_u_requeues;
565 unsigned int io_u_queued;
566
567 /*
568 * Rate state
569 */
570 unsigned long rate_usec_cycle;
571 long rate_pending_usleep;
572 unsigned long rate_bytes;
573 unsigned long rate_blocks;
574 struct timeval lastrate;
575
576 unsigned long long total_io_size;
577
578 unsigned long io_issues[2];
579 unsigned long long io_blocks[2];
580 unsigned long long io_bytes[2];
581 unsigned long long io_skip_bytes;
582 unsigned long long this_io_bytes[2];
583 unsigned long long zone_bytes;
584 struct fio_mutex *mutex;
585
586 /*
587 * State for random io, a bitmap of blocks done vs not done
588 */
589 os_random_state_t random_state;
590
591 struct timeval start; /* start of this loop */
592 struct timeval epoch; /* time job was started */
593 struct timeval rw_end[2];
594 struct timeval last_issue;
595 unsigned int rw_end_set[2];
596
597 /*
598 * read/write mixed workload state
599 */
600 os_random_state_t rwmix_state;
601 unsigned long rwmix_issues;
602 enum fio_ddir rwmix_ddir;
603 unsigned int ddir_nr;
604
605 /*
606 * IO history logs for verification. We use a tree for sorting,
607 * if we are overwriting. Otherwise just use a fifo.
608 */
609 struct rb_root io_hist_tree;
610 struct list_head io_hist_list;
611
612 /*
613 * For IO replaying
614 */
615 struct list_head io_log_list;
616
617 /*
618 * timeout handling
619 */
620 struct timeval timeout_end;
621 struct itimerval timer;
622
623 /*
624 * for fileservice, how often to switch to a new file
625 */
626 unsigned int file_service_nr;
627 unsigned int file_service_left;
628 struct fio_file *file_service_file;
629
630 /*
631 * For generating file sizes
632 */
633 os_random_state_t file_size_state;
634};
635
636/*
637 * roundrobin available files, or choose one at random.
638 */
639enum {
640 FIO_FSERVICE_RANDOM = 1,
641 FIO_FSERVICE_RR = 2,
642};
643
644/*
645 * when should interactive ETA output be generated
646 */
647enum {
648 FIO_ETA_AUTO,
649 FIO_ETA_ALWAYS,
650 FIO_ETA_NEVER,
651};
652
653/*
654 * 30 second per-io_u timeout, with 5 second intervals to avoid resetting
655 * the timer on each queue operation.
656 */
657#define IO_U_TIMEOUT_INC 5
658#define IO_U_TIMEOUT 30
659
660#define __td_verror(td, err, msg, func) \
661 do { \
662 if ((td)->error) \
663 break; \
664 int e = (err); \
665 (td)->error = e; \
666 snprintf(td->verror, sizeof(td->verror) - 1, "file:%s:%d, func=%s, error=%s", __FILE__, __LINE__, (func), (msg)); \
667 } while (0)
668
669
670#define td_verror(td, err, func) \
671 __td_verror((td), (err), strerror((err)), (func))
672#define td_vmsg(td, err, msg, func) \
673 __td_verror((td), (err), (msg), (func))
674
675extern int exitall_on_terminate;
676extern int thread_number;
677extern int nr_process, nr_thread;
678extern int shm_id;
679extern int groupid;
680extern int terse_output;
681extern int temp_stall_ts;
682extern unsigned long long mlock_size;
683extern unsigned long page_mask, page_size;
684extern int read_only;
685extern int eta_print;
686extern unsigned long done_secs;
687extern char *job_section;
688
689extern struct thread_data *threads;
690
691#define td_read(td) ((td)->o.td_ddir & TD_DDIR_READ)
692#define td_write(td) ((td)->o.td_ddir & TD_DDIR_WRITE)
693#define td_rw(td) (((td)->o.td_ddir & TD_DDIR_RW) == TD_DDIR_RW)
694#define td_random(td) ((td)->o.td_ddir & TD_DDIR_RAND)
695#define file_randommap(td, f) (!(td)->o.norandommap && (f)->file_map)
696
697static inline void fio_ro_check(struct thread_data *td, struct io_u *io_u)
698{
699 assert(!(io_u->ddir == DDIR_WRITE && !td_write(td)));
700}
701
702#define BLOCKS_PER_MAP (8 * sizeof(long))
703#define TO_MAP_BLOCK(td, f, b) (b)
704#define RAND_MAP_IDX(td, f, b) (TO_MAP_BLOCK(td, f, b) / BLOCKS_PER_MAP)
705#define RAND_MAP_BIT(td, f, b) (TO_MAP_BLOCK(td, f, b) & (BLOCKS_PER_MAP - 1))
706
707#define MAX_JOBS (1024)
708
709static inline int should_fsync(struct thread_data *td)
710{
711 if (td->last_was_sync)
712 return 0;
713 if (td->o.odirect)
714 return 0;
715 if (td_write(td) || td_rw(td) || td->o.override_sync)
716 return 1;
717
718 return 0;
719}
720
721/*
722 * Disk utils as read in /sys/block/<dev>/stat
723 */
724struct disk_util_stat {
725 unsigned ios[2];
726 unsigned merges[2];
727 unsigned long long sectors[2];
728 unsigned ticks[2];
729 unsigned io_ticks;
730 unsigned time_in_queue;
731};
732
733/*
734 * Per-device disk util management
735 */
736struct disk_util {
737 struct list_head list;
738
739 char *name;
740 char *sysfs_root;
741 char path[256];
742 int major, minor;
743
744 struct disk_util_stat dus;
745 struct disk_util_stat last_dus;
746
747 unsigned long msec;
748 struct timeval time;
749};
750
751#define DISK_UTIL_MSEC (250)
752
753/*
754 * Log exports
755 */
756enum file_log_act {
757 FIO_LOG_ADD_FILE,
758 FIO_LOG_OPEN_FILE,
759 FIO_LOG_CLOSE_FILE,
760 FIO_LOG_UNLINK_FILE,
761};
762
763extern int __must_check read_iolog_get(struct thread_data *, struct io_u *);
764extern void log_io_u(struct thread_data *, struct io_u *);
765extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act);
766extern int __must_check init_iolog(struct thread_data *td);
767extern void log_io_piece(struct thread_data *, struct io_u *);
768extern void queue_io_piece(struct thread_data *, struct io_piece *);
769extern void prune_io_piece_log(struct thread_data *);
770extern void write_iolog_close(struct thread_data *);
771
772/*
773 * Logging
774 */
775extern void add_clat_sample(struct thread_data *, enum fio_ddir, unsigned long);
776extern void add_slat_sample(struct thread_data *, enum fio_ddir, unsigned long);
777extern void add_bw_sample(struct thread_data *, enum fio_ddir, struct timeval *);
778extern void show_run_stats(void);
779extern void init_disk_util(struct thread_data *);
780extern void update_rusage_stat(struct thread_data *);
781extern void update_io_ticks(void);
782extern void disk_util_timer_arm(void);
783extern void setup_log(struct io_log **);
784extern void finish_log(struct thread_data *, struct io_log *, const char *);
785extern void __finish_log(struct io_log *, const char *);
786extern struct io_log *agg_io_log[2];
787extern int write_bw_log;
788extern void add_agg_sample(unsigned long, enum fio_ddir);
789
790/*
791 * Time functions
792 */
793extern unsigned long long utime_since(struct timeval *, struct timeval *);
794extern unsigned long long utime_since_now(struct timeval *);
795extern unsigned long mtime_since(struct timeval *, struct timeval *);
796extern unsigned long mtime_since_now(struct timeval *);
797extern unsigned long time_since_now(struct timeval *);
798extern unsigned long mtime_since_genesis(void);
799extern void __usec_sleep(unsigned int);
800extern void usec_sleep(struct thread_data *, unsigned long);
801extern void rate_throttle(struct thread_data *, unsigned long, unsigned int);
802extern void fill_start_time(struct timeval *);
803extern void fio_gettime(struct timeval *, void *);
804extern void set_genesis_time(void);
805
806/*
807 * Init/option functions
808 */
809extern int __must_check parse_options(int, char **);
810extern int fio_option_parse(struct thread_data *, const char *);
811extern int fio_cmd_option_parse(struct thread_data *, const char *, char *);
812extern void fio_fill_default_options(struct thread_data *);
813extern int fio_show_option_help(const char *);
814extern void fio_options_dup_and_init(struct option *);
815extern void options_mem_dupe(struct thread_data *);
816extern void options_mem_free(struct thread_data *);
817#define FIO_GETOPT_JOB 0x89988998
818#define FIO_NR_OPTIONS 128
819
820/*
821 * File setup/shutdown
822 */
823extern void close_files(struct thread_data *);
824extern void close_and_free_files(struct thread_data *);
825extern int __must_check setup_files(struct thread_data *);
826extern int __must_check open_files(struct thread_data *);
827extern int __must_check file_invalidate_cache(struct thread_data *, struct fio_file *);
828extern int __must_check generic_open_file(struct thread_data *, struct fio_file *);
829extern int __must_check generic_close_file(struct thread_data *, struct fio_file *);
830extern int add_file(struct thread_data *, const char *);
831extern void get_file(struct fio_file *);
832extern int __must_check put_file(struct thread_data *, struct fio_file *);
833extern void lock_file(struct thread_data *, struct fio_file *, enum fio_ddir);
834extern void unlock_file(struct thread_data *, struct fio_file *);
835extern void unlock_file_all(struct thread_data *, struct fio_file *);
836extern int add_dir_files(struct thread_data *, const char *);
837extern int init_random_map(struct thread_data *);
838extern void dup_files(struct thread_data *, struct thread_data *);
839extern int get_fileno(struct thread_data *, const char *);
840extern void free_release_files(struct thread_data *);
841
842/*
843 * ETA/status stuff
844 */
845extern void print_thread_status(void);
846extern void print_status_init(int);
847
848/*
849 * disk util stuff
850 */
851#ifdef FIO_HAVE_DISK_UTIL
852extern void show_disk_util(void);
853extern void disk_util_timer_arm(void);
854extern void init_disk_util(struct thread_data *);
855extern void update_io_ticks(void);
856#else
857#define show_disk_util()
858#define disk_util_timer_arm()
859#define init_disk_util(td)
860#define update_io_ticks()
861#endif
862
863/*
864 * Thread life cycle. Once a thread has a runstate beyond TD_INITIALIZED, it
865 * will never back again. It may cycle between running/verififying/fsyncing.
866 * Once the thread reaches TD_EXITED, it is just waiting for the core to
867 * reap it.
868 */
869enum {
870 TD_NOT_CREATED = 0,
871 TD_CREATED,
872 TD_INITIALIZED,
873 TD_RUNNING,
874 TD_VERIFYING,
875 TD_FSYNCING,
876 TD_EXITED,
877 TD_REAPED,
878};
879
880/*
881 * Verify helpers
882 */
883extern void populate_verify_io_u(struct thread_data *, struct io_u *);
884extern int __must_check get_next_verify(struct thread_data *td, struct io_u *);
885extern int __must_check verify_io_u(struct thread_data *, struct io_u *);
886
887/*
888 * Memory helpers
889 */
890extern int __must_check fio_pin_memory(void);
891extern void fio_unpin_memory(void);
892extern int __must_check allocate_io_mem(struct thread_data *);
893extern void free_io_mem(struct thread_data *);
894
895/*
896 * io unit handling
897 */
898#define queue_full(td) list_empty(&(td)->io_u_freelist)
899extern struct io_u *__get_io_u(struct thread_data *);
900extern struct io_u *get_io_u(struct thread_data *);
901extern void put_io_u(struct thread_data *, struct io_u *);
902extern void requeue_io_u(struct thread_data *, struct io_u **);
903extern long __must_check io_u_sync_complete(struct thread_data *, struct io_u *);
904extern long __must_check io_u_queued_complete(struct thread_data *, int);
905extern void io_u_queued(struct thread_data *, struct io_u *);
906extern void io_u_log_error(struct thread_data *, struct io_u *);
907extern void io_u_init_timeout(void);
908extern void io_u_set_timeout(struct thread_data *);
909extern void io_u_mark_depth(struct thread_data *, struct io_u *);
910
911/*
912 * io engine entry points
913 */
914extern int __must_check td_io_init(struct thread_data *);
915extern int __must_check td_io_prep(struct thread_data *, struct io_u *);
916extern int __must_check td_io_queue(struct thread_data *, struct io_u *);
917extern int __must_check td_io_sync(struct thread_data *, struct fio_file *);
918extern int __must_check td_io_getevents(struct thread_data *, unsigned int, unsigned int, struct timespec *);
919extern int __must_check td_io_commit(struct thread_data *);
920extern int __must_check td_io_open_file(struct thread_data *, struct fio_file *);
921extern int td_io_close_file(struct thread_data *, struct fio_file *);
922
923/*
924 * blktrace support
925 */
926#ifdef FIO_HAVE_BLKTRACE
927extern int is_blktrace(const char *);
928extern int load_blktrace(struct thread_data *, const char *);
929#endif
930
931struct ioengine_ops {
932 struct list_head list;
933 char name[16];
934 int version;
935 int flags;
936 int (*setup)(struct thread_data *);
937 int (*init)(struct thread_data *);
938 int (*prep)(struct thread_data *, struct io_u *);
939 int (*queue)(struct thread_data *, struct io_u *);
940 int (*commit)(struct thread_data *);
941 int (*getevents)(struct thread_data *, unsigned int, unsigned int, struct timespec *);
942 struct io_u *(*event)(struct thread_data *, int);
943 int (*cancel)(struct thread_data *, struct io_u *);
944 void (*cleanup)(struct thread_data *);
945 int (*open_file)(struct thread_data *, struct fio_file *);
946 int (*close_file)(struct thread_data *, struct fio_file *);
947 void *data;
948 void *dlhandle;
949};
950
951#define FIO_IOOPS_VERSION 9
952
953extern struct ioengine_ops *load_ioengine(struct thread_data *, const char *);
954extern void register_ioengine(struct ioengine_ops *);
955extern void unregister_ioengine(struct ioengine_ops *);
956extern void close_ioengine(struct thread_data *);
957
958/*
959 * Mark unused variables passed to ops functions as unused, to silence gcc
960 */
961#define fio_unused __attribute((__unused__))
962#define fio_init __attribute__((constructor))
963#define fio_exit __attribute__((destructor))
964
965#define for_each_td(td, i) \
966 for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++)
967#define for_each_file(td, f, i) \
968 if ((td)->files_index) \
969 for ((i) = 0, (f) = (td)->files[0]; \
970 (i) < (td)->o.nr_files && ((f) = (td)->files[i]) != NULL; \
971 (i)++)
972
973#define fio_assert(td, cond) do { \
974 if (!(cond)) { \
975 int *__foo = NULL; \
976 fprintf(stderr, "file:%s:%d, assert %s failed\n", __FILE__, __LINE__, #cond); \
977 (td)->runstate = TD_EXITED; \
978 (td)->error = EFAULT; \
979 *__foo = 0; \
980 } \
981} while (0)
982
983static inline void clear_error(struct thread_data *td)
984{
985 td->error = 0;
986 td->verror[0] = '\0';
987}
988
989#ifdef FIO_INC_DEBUG
990static inline void dprint_io_u(struct io_u *io_u, const char *p)
991{
992 struct fio_file *f = io_u->file;
993
994 dprint(FD_IO, "%s: io_u %p: off=%llu/len=%lu/ddir=%d", p, io_u,
995 io_u->offset, io_u->buflen, io_u->ddir);
996 if (fio_debug & (1 << FD_IO)) {
997 if (f)
998 log_info("/%s", f->file_name);
999
1000 log_info("\n");
1001 }
1002}
1003#else
1004#define dprint_io_u(io_u, p)
1005#endif
1006
1007#endif