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