Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1 | /* |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 2 | * This file contains job initialization and setup functions. |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 3 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <unistd.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <ctype.h> |
| 9 | #include <string.h> |
| 10 | #include <errno.h> |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 11 | #include <getopt.h> |
| 12 | #include <assert.h> |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 13 | #include <sys/ipc.h> |
| 14 | #include <sys/shm.h> |
| 15 | #include <sys/types.h> |
| 16 | #include <sys/stat.h> |
| 17 | |
| 18 | #include "fio.h" |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 19 | #include "parse.h" |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 20 | |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 21 | #define FIO_RANDSEED (0xb1899bedUL) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 22 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 23 | #define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var) |
| 24 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 25 | static int str_mem_cb(void *, const char *); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 26 | static int str_lockmem_cb(void *, unsigned long *); |
Jens Axboe | 34cfcda | 2006-11-03 14:00:45 +0100 | [diff] [blame] | 27 | #ifdef FIO_HAVE_IOPRIO |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 28 | static int str_prio_cb(void *, unsigned int *); |
| 29 | static int str_prioclass_cb(void *, unsigned int *); |
Jens Axboe | 34cfcda | 2006-11-03 14:00:45 +0100 | [diff] [blame] | 30 | #endif |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 31 | static int str_exitall_cb(void); |
| 32 | static int str_cpumask_cb(void *, unsigned int *); |
Jens Axboe | 1907dbc | 2007-03-12 11:44:28 +0100 | [diff] [blame] | 33 | static int str_fst_cb(void *, const char *); |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 34 | static int str_filename_cb(void *, const char *); |
| 35 | static int str_directory_cb(void *, const char *); |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 36 | static int str_opendir_cb(void *, const char *); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 37 | |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 38 | #define __stringify_1(x) #x |
| 39 | #define __stringify(x) __stringify_1(x) |
| 40 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 41 | /* |
| 42 | * Map of job/command line options |
| 43 | */ |
| 44 | static struct fio_option options[] = { |
| 45 | { |
Jens Axboe | 61697c3 | 2007-02-05 15:04:46 +0100 | [diff] [blame] | 46 | .name = "description", |
| 47 | .type = FIO_OPT_STR_STORE, |
| 48 | .off1 = td_var_offset(description), |
| 49 | .help = "Text job description", |
| 50 | }, |
| 51 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 52 | .name = "name", |
| 53 | .type = FIO_OPT_STR_STORE, |
| 54 | .off1 = td_var_offset(name), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 55 | .help = "Name of this job", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 56 | }, |
| 57 | { |
| 58 | .name = "directory", |
| 59 | .type = FIO_OPT_STR_STORE, |
| 60 | .off1 = td_var_offset(directory), |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 61 | .cb = str_directory_cb, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 62 | .help = "Directory to store files in", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 63 | }, |
| 64 | { |
| 65 | .name = "filename", |
| 66 | .type = FIO_OPT_STR_STORE, |
| 67 | .off1 = td_var_offset(filename), |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 68 | .cb = str_filename_cb, |
| 69 | .help = "File(s) to use for the workload", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 70 | }, |
| 71 | { |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 72 | .name = "opendir", |
| 73 | .type = FIO_OPT_STR_STORE, |
| 74 | .off1 = td_var_offset(opendir), |
| 75 | .cb = str_opendir_cb, |
| 76 | .help = "Recursively add files from this directory and down", |
| 77 | }, |
| 78 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 79 | .name = "rw", |
| 80 | .type = FIO_OPT_STR, |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 81 | .off1 = td_var_offset(td_ddir), |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 82 | .help = "IO direction", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 83 | .def = "read", |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 84 | .posval = { |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 85 | { .ival = "read", |
| 86 | .oval = TD_DDIR_READ, |
| 87 | .help = "Sequential read", |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 88 | }, |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 89 | { .ival = "write", |
| 90 | .oval = TD_DDIR_WRITE, |
| 91 | .help = "Sequential write", |
| 92 | }, |
| 93 | { .ival = "randread", |
| 94 | .oval = TD_DDIR_RANDREAD, |
| 95 | .help = "Random read", |
| 96 | }, |
| 97 | { .ival = "randwrite", |
| 98 | .oval = TD_DDIR_RANDWRITE, |
| 99 | .help = "Random write", |
Jens Axboe | 9d6d019 | 2007-03-14 13:28:31 +0100 | [diff] [blame] | 100 | }, |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 101 | { .ival = "rw", |
| 102 | .oval = TD_DDIR_RW, |
| 103 | .help = "Sequential read and write mix", |
| 104 | }, |
| 105 | { .ival = "randrw", |
| 106 | .oval = TD_DDIR_RANDRW, |
| 107 | .help = "Random read and write mix" |
| 108 | }, |
| 109 | }, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 110 | }, |
| 111 | { |
| 112 | .name = "ioengine", |
Jens Axboe | 09629a9 | 2007-03-09 09:00:06 +0100 | [diff] [blame] | 113 | .type = FIO_OPT_STR_STORE, |
| 114 | .off1 = td_var_offset(ioengine), |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 115 | .help = "IO engine to use", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 116 | .def = "sync", |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 117 | .posval = { |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 118 | { .ival = "sync", |
| 119 | .help = "Use read/write", |
| 120 | }, |
Jens Axboe | 10cad1a | 2007-02-23 11:23:03 +0100 | [diff] [blame] | 121 | #ifdef FIO_HAVE_LIBAIO |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 122 | { .ival = "libaio", |
| 123 | .help = "Linux native asynchronous IO", |
| 124 | }, |
Jens Axboe | 10cad1a | 2007-02-23 11:23:03 +0100 | [diff] [blame] | 125 | #endif |
| 126 | #ifdef FIO_HAVE_POSIXAIO |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 127 | { .ival = "posixaio", |
| 128 | .help = "POSIX asynchronous IO", |
| 129 | }, |
Jens Axboe | 10cad1a | 2007-02-23 11:23:03 +0100 | [diff] [blame] | 130 | #endif |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 131 | { .ival = "mmap", |
| 132 | .help = "Memory mapped IO", |
| 133 | }, |
Jens Axboe | 10cad1a | 2007-02-23 11:23:03 +0100 | [diff] [blame] | 134 | #ifdef FIO_HAVE_SPLICE |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 135 | { .ival = "splice", |
| 136 | .help = "splice/vmsplice based IO", |
| 137 | }, |
Jens Axboe | 10cad1a | 2007-02-23 11:23:03 +0100 | [diff] [blame] | 138 | #endif |
| 139 | #ifdef FIO_HAVE_SGIO |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 140 | { .ival = "sg", |
| 141 | .help = "SCSI generic v3 IO", |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 142 | }, |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 143 | #endif |
| 144 | { .ival = "null", |
| 145 | .help = "Testing engine (no data transfer)", |
| 146 | }, |
| 147 | { .ival = "net", |
| 148 | .help = "Network IO", |
| 149 | }, |
| 150 | #ifdef FIO_HAVE_SYSLET |
| 151 | { .ival = "syslet-rw", |
| 152 | .help = "syslet enabled async pread/pwrite IO", |
| 153 | }, |
| 154 | #endif |
| 155 | { .ival = "cpuio", |
| 156 | .help = "CPU cycler burner engine", |
| 157 | }, |
| 158 | { .ival = "external", |
| 159 | .help = "Load external engine (append name)", |
| 160 | }, |
| 161 | }, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 162 | }, |
| 163 | { |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 164 | .name = "iodepth", |
| 165 | .type = FIO_OPT_INT, |
| 166 | .off1 = td_var_offset(iodepth), |
| 167 | .help = "Amount of IO buffers to keep in flight", |
| 168 | .def = "1", |
| 169 | }, |
| 170 | { |
Jens Axboe | cb5ab51 | 2007-02-26 12:57:09 +0100 | [diff] [blame] | 171 | .name = "iodepth_batch", |
| 172 | .type = FIO_OPT_INT, |
| 173 | .off1 = td_var_offset(iodepth_batch), |
| 174 | .help = "Number of IO to submit in one go", |
| 175 | }, |
| 176 | { |
Jens Axboe | e916b39 | 2007-02-20 14:37:26 +0100 | [diff] [blame] | 177 | .name = "iodepth_low", |
| 178 | .type = FIO_OPT_INT, |
| 179 | .off1 = td_var_offset(iodepth_low), |
| 180 | .help = "Low water mark for queuing depth", |
| 181 | }, |
| 182 | { |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 183 | .name = "size", |
| 184 | .type = FIO_OPT_STR_VAL, |
| 185 | .off1 = td_var_offset(total_file_size), |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 186 | .help = "Total size of device or files", |
| 187 | }, |
| 188 | { |
| 189 | .name = "filesize", |
| 190 | .type = FIO_OPT_STR_VAL, |
| 191 | .off1 = td_var_offset(file_size_low), |
| 192 | .off2 = td_var_offset(file_size_high), |
| 193 | .help = "Size of individual files", |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 194 | }, |
| 195 | { |
| 196 | .name = "bs", |
| 197 | .type = FIO_OPT_STR_VAL_INT, |
| 198 | .off1 = td_var_offset(bs[DDIR_READ]), |
| 199 | .off2 = td_var_offset(bs[DDIR_WRITE]), |
| 200 | .help = "Block size unit", |
| 201 | .def = "4k", |
| 202 | }, |
| 203 | { |
| 204 | .name = "bsrange", |
| 205 | .type = FIO_OPT_RANGE, |
| 206 | .off1 = td_var_offset(min_bs[DDIR_READ]), |
| 207 | .off2 = td_var_offset(max_bs[DDIR_READ]), |
| 208 | .off3 = td_var_offset(min_bs[DDIR_WRITE]), |
| 209 | .off4 = td_var_offset(max_bs[DDIR_WRITE]), |
| 210 | .help = "Set block size range (in more detail than bs)", |
| 211 | }, |
| 212 | { |
| 213 | .name = "bs_unaligned", |
| 214 | .type = FIO_OPT_STR_SET, |
| 215 | .off1 = td_var_offset(bs_unaligned), |
| 216 | .help = "Don't sector align IO buffer sizes", |
| 217 | }, |
| 218 | { |
| 219 | .name = "offset", |
| 220 | .type = FIO_OPT_STR_VAL, |
| 221 | .off1 = td_var_offset(start_offset), |
| 222 | .help = "Start IO from this offset", |
| 223 | .def = "0", |
| 224 | }, |
| 225 | { |
| 226 | .name = "randrepeat", |
| 227 | .type = FIO_OPT_BOOL, |
| 228 | .off1 = td_var_offset(rand_repeatable), |
| 229 | .help = "Use repeatable random IO pattern", |
| 230 | .def = "1", |
| 231 | }, |
| 232 | { |
| 233 | .name = "norandommap", |
| 234 | .type = FIO_OPT_STR_SET, |
| 235 | .off1 = td_var_offset(norandommap), |
| 236 | .help = "Accept potential duplicate random blocks", |
| 237 | }, |
| 238 | { |
| 239 | .name = "nrfiles", |
| 240 | .type = FIO_OPT_INT, |
| 241 | .off1 = td_var_offset(nr_files), |
| 242 | .help = "Split job workload between this number of files", |
| 243 | .def = "1", |
| 244 | }, |
| 245 | { |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 246 | .name = "openfiles", |
| 247 | .type = FIO_OPT_INT, |
| 248 | .off1 = td_var_offset(open_files), |
| 249 | .help = "Number of files to keep open at the same time", |
| 250 | }, |
| 251 | { |
Jens Axboe | 0aabe16 | 2007-02-23 08:45:55 +0100 | [diff] [blame] | 252 | .name = "file_service_type", |
| 253 | .type = FIO_OPT_STR, |
Jens Axboe | 1907dbc | 2007-03-12 11:44:28 +0100 | [diff] [blame] | 254 | .cb = str_fst_cb, |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 255 | .off1 = td_var_offset(file_service_type), |
Jens Axboe | 0aabe16 | 2007-02-23 08:45:55 +0100 | [diff] [blame] | 256 | .help = "How to select which file to service next", |
| 257 | .def = "roundrobin", |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 258 | .posval = { |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 259 | { .ival = "random", |
| 260 | .oval = FIO_FSERVICE_RANDOM, |
| 261 | .help = "Choose a file at random", |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 262 | }, |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 263 | { .ival = "roundrobin", |
| 264 | .oval = FIO_FSERVICE_RR, |
| 265 | .help = "Round robin select files", |
| 266 | }, |
| 267 | }, |
Jens Axboe | 0aabe16 | 2007-02-23 08:45:55 +0100 | [diff] [blame] | 268 | }, |
| 269 | { |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 270 | .name = "fsync", |
| 271 | .type = FIO_OPT_INT, |
| 272 | .off1 = td_var_offset(fsync_blocks), |
| 273 | .help = "Issue fsync for writes every given number of blocks", |
| 274 | .def = "0", |
| 275 | }, |
| 276 | { |
| 277 | .name = "direct", |
| 278 | .type = FIO_OPT_BOOL, |
| 279 | .off1 = td_var_offset(odirect), |
Jens Axboe | 76a43db | 2007-01-11 13:24:44 +0100 | [diff] [blame] | 280 | .help = "Use O_DIRECT IO (negates buffered)", |
| 281 | .def = "0", |
| 282 | }, |
| 283 | { |
| 284 | .name = "buffered", |
| 285 | .type = FIO_OPT_BOOL, |
| 286 | .off1 = td_var_offset(odirect), |
| 287 | .neg = 1, |
| 288 | .help = "Use buffered IO (negates direct)", |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 289 | .def = "1", |
| 290 | }, |
| 291 | { |
| 292 | .name = "overwrite", |
| 293 | .type = FIO_OPT_BOOL, |
| 294 | .off1 = td_var_offset(overwrite), |
| 295 | .help = "When writing, set whether to overwrite current data", |
| 296 | .def = "0", |
| 297 | }, |
| 298 | { |
| 299 | .name = "loops", |
| 300 | .type = FIO_OPT_INT, |
| 301 | .off1 = td_var_offset(loops), |
| 302 | .help = "Number of times to run the job", |
| 303 | .def = "1", |
| 304 | }, |
| 305 | { |
| 306 | .name = "numjobs", |
| 307 | .type = FIO_OPT_INT, |
| 308 | .off1 = td_var_offset(numjobs), |
| 309 | .help = "Duplicate this job this many times", |
| 310 | .def = "1", |
| 311 | }, |
| 312 | { |
| 313 | .name = "startdelay", |
| 314 | .type = FIO_OPT_INT, |
| 315 | .off1 = td_var_offset(start_delay), |
| 316 | .help = "Only start job when this period has passed", |
| 317 | .def = "0", |
| 318 | }, |
| 319 | { |
| 320 | .name = "runtime", |
| 321 | .alias = "timeout", |
| 322 | .type = FIO_OPT_STR_VAL_TIME, |
| 323 | .off1 = td_var_offset(timeout), |
| 324 | .help = "Stop workload when this amount of time has passed", |
| 325 | .def = "0", |
| 326 | }, |
| 327 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 328 | .name = "mem", |
| 329 | .type = FIO_OPT_STR, |
| 330 | .cb = str_mem_cb, |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 331 | .off1 = td_var_offset(mem_type), |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 332 | .help = "Backing type for IO buffers", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 333 | .def = "malloc", |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 334 | .posval = { |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 335 | { .ival = "malloc", |
| 336 | .oval = MEM_MALLOC, |
| 337 | .help = "Use malloc(3) for IO buffers", |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 338 | }, |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 339 | { .ival = "shm", |
| 340 | .oval = MEM_SHM, |
| 341 | .help = "Use shared memory segments for IO buffers", |
| 342 | }, |
| 343 | #ifdef FIO_HAVE_HUGETLB |
| 344 | { .ival = "shmhuge", |
| 345 | .oval = MEM_SHMHUGE, |
| 346 | .help = "Like shm, but use huge pages", |
| 347 | }, |
| 348 | #endif |
| 349 | { .ival = "mmap", |
| 350 | .oval = MEM_MMAP, |
| 351 | .help = "Use mmap(2) (file or anon) for IO buffers", |
| 352 | }, |
| 353 | #ifdef FIO_HAVE_HUGETLB |
| 354 | { .ival = "mmaphuge", |
| 355 | .oval = MEM_MMAPHUGE, |
| 356 | .help = "Like mmap, but use huge pages", |
| 357 | }, |
| 358 | #endif |
| 359 | }, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 360 | }, |
| 361 | { |
| 362 | .name = "verify", |
| 363 | .type = FIO_OPT_STR, |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 364 | .off1 = td_var_offset(verify), |
Jens Axboe | 9d6d019 | 2007-03-14 13:28:31 +0100 | [diff] [blame] | 365 | .help = "Verify data written", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 366 | .def = "0", |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 367 | .posval = { |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 368 | { .ival = "0", |
| 369 | .oval = VERIFY_NONE, |
| 370 | .help = "Don't do IO verification", |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 371 | }, |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 372 | { .ival = "crc32", |
| 373 | .oval = VERIFY_CRC32, |
| 374 | .help = "Use crc32 checksums for verification", |
| 375 | }, |
| 376 | { .ival = "md5", |
| 377 | .oval = VERIFY_MD5, |
| 378 | .help = "Use md5 checksums for verification", |
| 379 | }, |
| 380 | }, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 381 | }, |
| 382 | { |
| 383 | .name = "write_iolog", |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 384 | .type = FIO_OPT_STR_STORE, |
| 385 | .off1 = td_var_offset(write_iolog_file), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 386 | .help = "Store IO pattern to file", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 387 | }, |
| 388 | { |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 389 | .name = "read_iolog", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 390 | .type = FIO_OPT_STR_STORE, |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 391 | .off1 = td_var_offset(read_iolog_file), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 392 | .help = "Playback IO pattern from file", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 393 | }, |
| 394 | { |
| 395 | .name = "exec_prerun", |
| 396 | .type = FIO_OPT_STR_STORE, |
| 397 | .off1 = td_var_offset(exec_prerun), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 398 | .help = "Execute this file prior to running job", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 399 | }, |
| 400 | { |
| 401 | .name = "exec_postrun", |
| 402 | .type = FIO_OPT_STR_STORE, |
| 403 | .off1 = td_var_offset(exec_postrun), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 404 | .help = "Execute this file after running job", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 405 | }, |
| 406 | #ifdef FIO_HAVE_IOSCHED_SWITCH |
| 407 | { |
| 408 | .name = "ioscheduler", |
| 409 | .type = FIO_OPT_STR_STORE, |
| 410 | .off1 = td_var_offset(ioscheduler), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 411 | .help = "Use this IO scheduler on the backing device", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 412 | }, |
| 413 | #endif |
| 414 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 415 | .name = "zonesize", |
| 416 | .type = FIO_OPT_STR_VAL, |
| 417 | .off1 = td_var_offset(zone_size), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 418 | .help = "Give size of an IO zone", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 419 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 420 | }, |
| 421 | { |
| 422 | .name = "zoneskip", |
| 423 | .type = FIO_OPT_STR_VAL, |
| 424 | .off1 = td_var_offset(zone_skip), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 425 | .help = "Space between IO zones", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 426 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 427 | }, |
| 428 | { |
| 429 | .name = "lockmem", |
| 430 | .type = FIO_OPT_STR_VAL, |
| 431 | .cb = str_lockmem_cb, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 432 | .help = "Lock down this amount of memory", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 433 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 434 | }, |
| 435 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 436 | .name = "rwmixcycle", |
| 437 | .type = FIO_OPT_INT, |
| 438 | .off1 = td_var_offset(rwmixcycle), |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 439 | .help = "Cycle period for mixed read/write workloads (msec)", |
| 440 | .def = "500", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 441 | }, |
| 442 | { |
| 443 | .name = "rwmixread", |
| 444 | .type = FIO_OPT_INT, |
| 445 | .off1 = td_var_offset(rwmixread), |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 446 | .maxval = 100, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 447 | .help = "Percentage of mixed workload that is reads", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 448 | .def = "50", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 449 | }, |
| 450 | { |
| 451 | .name = "rwmixwrite", |
| 452 | .type = FIO_OPT_INT, |
| 453 | .off1 = td_var_offset(rwmixwrite), |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 454 | .maxval = 100, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 455 | .help = "Percentage of mixed workload that is writes", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 456 | .def = "50", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 457 | }, |
| 458 | { |
| 459 | .name = "nice", |
| 460 | .type = FIO_OPT_INT, |
| 461 | .off1 = td_var_offset(nice), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 462 | .help = "Set job CPU nice value", |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 463 | .minval = -19, |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 464 | .maxval = 20, |
| 465 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 466 | }, |
| 467 | #ifdef FIO_HAVE_IOPRIO |
| 468 | { |
| 469 | .name = "prio", |
| 470 | .type = FIO_OPT_INT, |
| 471 | .cb = str_prio_cb, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 472 | .help = "Set job IO priority value", |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 473 | .minval = 0, |
| 474 | .maxval = 7, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 475 | }, |
| 476 | { |
| 477 | .name = "prioclass", |
| 478 | .type = FIO_OPT_INT, |
| 479 | .cb = str_prioclass_cb, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 480 | .help = "Set job IO priority class", |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 481 | .minval = 0, |
| 482 | .maxval = 3, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 483 | }, |
| 484 | #endif |
| 485 | { |
| 486 | .name = "thinktime", |
| 487 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 488 | .off1 = td_var_offset(thinktime), |
Jens Axboe | 5fa0f81 | 2007-01-11 14:06:35 +0100 | [diff] [blame] | 489 | .help = "Idle time between IO buffers (usec)", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 490 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 491 | }, |
| 492 | { |
Jens Axboe | 48097d5 | 2007-02-17 06:30:44 +0100 | [diff] [blame] | 493 | .name = "thinktime_spin", |
| 494 | .type = FIO_OPT_INT, |
| 495 | .off1 = td_var_offset(thinktime_spin), |
Jens Axboe | 34403fb | 2007-03-02 21:43:25 +0100 | [diff] [blame] | 496 | .help = "Start think time by spinning this amount (usec)", |
Jens Axboe | 48097d5 | 2007-02-17 06:30:44 +0100 | [diff] [blame] | 497 | .def = "0", |
| 498 | }, |
| 499 | { |
Jens Axboe | 9c1f743 | 2007-01-03 20:43:19 +0100 | [diff] [blame] | 500 | .name = "thinktime_blocks", |
| 501 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 502 | .off1 = td_var_offset(thinktime_blocks), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 503 | .help = "IO buffer period between 'thinktime'", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 504 | .def = "1", |
Jens Axboe | 9c1f743 | 2007-01-03 20:43:19 +0100 | [diff] [blame] | 505 | }, |
| 506 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 507 | .name = "rate", |
| 508 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 509 | .off1 = td_var_offset(rate), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 510 | .help = "Set bandwidth rate", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 511 | }, |
| 512 | { |
| 513 | .name = "ratemin", |
| 514 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 515 | .off1 = td_var_offset(ratemin), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 516 | .help = "The bottom limit accepted", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 517 | }, |
| 518 | { |
| 519 | .name = "ratecycle", |
| 520 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 521 | .off1 = td_var_offset(ratecycle), |
Jens Axboe | 6da1fa7 | 2007-01-10 11:27:48 +0100 | [diff] [blame] | 522 | .help = "Window average for rate limits (msec)", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 523 | .def = "1000", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 524 | }, |
| 525 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 526 | .name = "invalidate", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 527 | .type = FIO_OPT_BOOL, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 528 | .off1 = td_var_offset(invalidate_cache), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 529 | .help = "Invalidate buffer/page cache prior to running job", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 530 | .def = "1", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 531 | }, |
| 532 | { |
| 533 | .name = "sync", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 534 | .type = FIO_OPT_BOOL, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 535 | .off1 = td_var_offset(sync_io), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 536 | .help = "Use O_SYNC for buffered writes", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 537 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 538 | }, |
| 539 | { |
| 540 | .name = "bwavgtime", |
| 541 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 542 | .off1 = td_var_offset(bw_avg_time), |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 543 | .help = "Time window over which to calculate bandwidth (msec)", |
| 544 | .def = "500", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 545 | }, |
| 546 | { |
| 547 | .name = "create_serialize", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 548 | .type = FIO_OPT_BOOL, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 549 | .off1 = td_var_offset(create_serialize), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 550 | .help = "Serialize creating of job files", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 551 | .def = "1", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 552 | }, |
| 553 | { |
| 554 | .name = "create_fsync", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 555 | .type = FIO_OPT_BOOL, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 556 | .off1 = td_var_offset(create_fsync), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 557 | .help = "Fsync file after creation", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 558 | .def = "1", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 559 | }, |
| 560 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 561 | .name = "cpuload", |
| 562 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 563 | .off1 = td_var_offset(cpuload), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 564 | .help = "Use this percentage of CPU", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 565 | }, |
| 566 | { |
| 567 | .name = "cpuchunks", |
| 568 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 569 | .off1 = td_var_offset(cpucycle), |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 570 | .help = "Length of the CPU burn cycles (usecs)", |
| 571 | .def = "50000", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 572 | }, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 573 | #ifdef FIO_HAVE_CPU_AFFINITY |
| 574 | { |
| 575 | .name = "cpumask", |
| 576 | .type = FIO_OPT_INT, |
| 577 | .cb = str_cpumask_cb, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 578 | .help = "CPU affinity mask", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 579 | }, |
| 580 | #endif |
| 581 | { |
| 582 | .name = "end_fsync", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 583 | .type = FIO_OPT_BOOL, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 584 | .off1 = td_var_offset(end_fsync), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 585 | .help = "Include fsync at the end of job", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 586 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 587 | }, |
| 588 | { |
Jens Axboe | ebb1415 | 2007-03-13 14:42:15 +0100 | [diff] [blame] | 589 | .name = "fsync_on_close", |
| 590 | .type = FIO_OPT_BOOL, |
| 591 | .off1 = td_var_offset(fsync_on_close), |
| 592 | .help = "fsync files on close", |
| 593 | .def = "0", |
| 594 | }, |
| 595 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 596 | .name = "unlink", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 597 | .type = FIO_OPT_BOOL, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 598 | .off1 = td_var_offset(unlink), |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 599 | .help = "Unlink created files after job has completed", |
Jens Axboe | e545a6c | 2007-01-14 00:00:29 +0100 | [diff] [blame] | 600 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 601 | }, |
| 602 | { |
| 603 | .name = "exitall", |
| 604 | .type = FIO_OPT_STR_SET, |
| 605 | .cb = str_exitall_cb, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 606 | .help = "Terminate all jobs when one exits", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 607 | }, |
| 608 | { |
| 609 | .name = "stonewall", |
| 610 | .type = FIO_OPT_STR_SET, |
| 611 | .off1 = td_var_offset(stonewall), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 612 | .help = "Insert a hard barrier between this job and previous", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 613 | }, |
| 614 | { |
| 615 | .name = "thread", |
| 616 | .type = FIO_OPT_STR_SET, |
Jens Axboe | d9bb3b8 | 2007-01-10 20:30:53 +0100 | [diff] [blame] | 617 | .off1 = td_var_offset(use_thread), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 618 | .help = "Use threads instead of forks", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 619 | }, |
| 620 | { |
| 621 | .name = "write_bw_log", |
| 622 | .type = FIO_OPT_STR_SET, |
| 623 | .off1 = td_var_offset(write_bw_log), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 624 | .help = "Write log of bandwidth during run", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 625 | }, |
| 626 | { |
| 627 | .name = "write_lat_log", |
| 628 | .type = FIO_OPT_STR_SET, |
| 629 | .off1 = td_var_offset(write_lat_log), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 630 | .help = "Write log of latency during run", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 631 | }, |
| 632 | { |
Jens Axboe | 56bb17f | 2006-12-20 20:27:36 +0100 | [diff] [blame] | 633 | .name = "hugepage-size", |
| 634 | .type = FIO_OPT_STR_VAL, |
| 635 | .off1 = td_var_offset(hugepage_size), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 636 | .help = "When using hugepages, specify size of each page", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 637 | .def = __stringify(FIO_HUGE_PAGE), |
Jens Axboe | 56bb17f | 2006-12-20 20:27:36 +0100 | [diff] [blame] | 638 | }, |
| 639 | { |
Jens Axboe | b2560f3 | 2007-03-06 12:43:03 +0100 | [diff] [blame] | 640 | .name = "group_reporting", |
| 641 | .type = FIO_OPT_STR_SET, |
| 642 | .off1 = td_var_offset(group_reporting), |
| 643 | .help = "Do reporting on a per-group basis", |
| 644 | }, |
| 645 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 646 | .name = NULL, |
| 647 | }, |
| 648 | }; |
| 649 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 650 | #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option)) |
| 651 | #define FIO_CMD_OPTS (16) |
| 652 | #define FIO_GETOPT_JOB (0x89988998) |
| 653 | |
| 654 | /* |
| 655 | * Command line options. These will contain the above, plus a few |
| 656 | * extra that only pertain to fio itself and not jobs. |
| 657 | */ |
| 658 | static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = { |
| 659 | { |
| 660 | .name = "output", |
| 661 | .has_arg = required_argument, |
| 662 | .val = 'o', |
| 663 | }, |
| 664 | { |
| 665 | .name = "timeout", |
| 666 | .has_arg = required_argument, |
| 667 | .val = 't', |
| 668 | }, |
| 669 | { |
| 670 | .name = "latency-log", |
| 671 | .has_arg = required_argument, |
| 672 | .val = 'l', |
| 673 | }, |
| 674 | { |
| 675 | .name = "bandwidth-log", |
| 676 | .has_arg = required_argument, |
| 677 | .val = 'b', |
| 678 | }, |
| 679 | { |
| 680 | .name = "minimal", |
| 681 | .has_arg = optional_argument, |
| 682 | .val = 'm', |
| 683 | }, |
| 684 | { |
| 685 | .name = "version", |
| 686 | .has_arg = no_argument, |
| 687 | .val = 'v', |
| 688 | }, |
| 689 | { |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 690 | .name = "help", |
| 691 | .has_arg = no_argument, |
| 692 | .val = 'h', |
| 693 | }, |
| 694 | { |
| 695 | .name = "cmdhelp", |
Jens Axboe | 320beef | 2007-03-01 10:44:12 +0100 | [diff] [blame] | 696 | .has_arg = optional_argument, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 697 | .val = 'c', |
| 698 | }, |
| 699 | { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 700 | .name = NULL, |
| 701 | }, |
| 702 | }; |
| 703 | |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 704 | static int def_timeout = 0; |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 705 | |
Jens Axboe | 54592a3 | 2007-03-14 14:24:11 +0100 | [diff] [blame] | 706 | static char fio_version_string[] = "fio 1.14a"; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 707 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 708 | static char **ini_file; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 709 | static int max_jobs = MAX_JOBS; |
| 710 | |
| 711 | struct thread_data def_thread; |
| 712 | struct thread_data *threads = NULL; |
| 713 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 714 | int exitall_on_terminate = 0; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 715 | int terse_output = 0; |
Jens Axboe | c04f7ec | 2006-05-31 10:13:16 +0200 | [diff] [blame] | 716 | unsigned long long mlock_size = 0; |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 717 | FILE *f_out = NULL; |
| 718 | FILE *f_err = NULL; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 719 | |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 720 | static int write_lat_log = 0; |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 721 | int write_bw_log = 0; |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 722 | |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 723 | static int prev_group_jobs; |
| 724 | |
Joel Becker | 9728ce3 | 2007-03-01 08:24:39 +0100 | [diff] [blame] | 725 | FILE *get_f_out() |
| 726 | { |
| 727 | return f_out; |
| 728 | } |
| 729 | |
| 730 | FILE *get_f_err() |
| 731 | { |
| 732 | return f_err; |
| 733 | } |
| 734 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 735 | /* |
| 736 | * Return a free job structure. |
| 737 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 738 | static struct thread_data *get_new_job(int global, struct thread_data *parent) |
| 739 | { |
| 740 | struct thread_data *td; |
| 741 | |
| 742 | if (global) |
| 743 | return &def_thread; |
| 744 | if (thread_number >= max_jobs) |
| 745 | return NULL; |
| 746 | |
| 747 | td = &threads[thread_number++]; |
Jens Axboe | ddaeaa5 | 2006-06-08 11:00:58 +0200 | [diff] [blame] | 748 | *td = *parent; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 749 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 750 | td->thread_number = thread_number; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 751 | return td; |
| 752 | } |
| 753 | |
| 754 | static void put_job(struct thread_data *td) |
| 755 | { |
Jens Axboe | 549577a | 2006-10-30 12:23:41 +0100 | [diff] [blame] | 756 | if (td == &def_thread) |
| 757 | return; |
| 758 | |
Jens Axboe | 16edf25 | 2007-02-10 14:59:22 +0100 | [diff] [blame] | 759 | if (td->error) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame^] | 760 | log_info("fio: %s\n", td->verror); |
Jens Axboe | 16edf25 | 2007-02-10 14:59:22 +0100 | [diff] [blame] | 761 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 762 | memset(&threads[td->thread_number - 1], 0, sizeof(*td)); |
| 763 | thread_number--; |
| 764 | } |
| 765 | |
Jens Axboe | dad915e | 2006-10-27 11:10:18 +0200 | [diff] [blame] | 766 | /* |
| 767 | * Lazy way of fixing up options that depend on each other. We could also |
| 768 | * define option callback handlers, but this is easier. |
| 769 | */ |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 770 | static void fixup_options(struct thread_data *td) |
| 771 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 772 | if (!td->rwmixread && td->rwmixwrite) |
| 773 | td->rwmixread = 100 - td->rwmixwrite; |
Jens Axboe | dad915e | 2006-10-27 11:10:18 +0200 | [diff] [blame] | 774 | |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 775 | if (td->write_iolog_file && td->read_iolog_file) { |
| 776 | log_err("fio: read iolog overrides write_iolog\n"); |
| 777 | free(td->write_iolog_file); |
| 778 | td->write_iolog_file = NULL; |
| 779 | } |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 780 | |
| 781 | if (td->io_ops->flags & FIO_SYNCIO) |
| 782 | td->iodepth = 1; |
| 783 | else { |
| 784 | if (!td->iodepth) |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 785 | td->iodepth = td->open_files; |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | /* |
| 789 | * only really works for sequential io for now, and with 1 file |
| 790 | */ |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 791 | if (td->zone_size && td_random(td) && td->open_files == 1) |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 792 | td->zone_size = 0; |
| 793 | |
| 794 | /* |
| 795 | * Reads can do overwrites, we always need to pre-create the file |
| 796 | */ |
| 797 | if (td_read(td) || td_rw(td)) |
| 798 | td->overwrite = 1; |
| 799 | |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 800 | if (!td->min_bs[DDIR_READ]) |
| 801 | td->min_bs[DDIR_READ]= td->bs[DDIR_READ]; |
| 802 | if (!td->max_bs[DDIR_READ]) |
| 803 | td->max_bs[DDIR_READ] = td->bs[DDIR_READ]; |
| 804 | if (!td->min_bs[DDIR_WRITE]) |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 805 | td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE]; |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 806 | if (!td->max_bs[DDIR_WRITE]) |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 807 | td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE]; |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 808 | |
| 809 | td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]); |
| 810 | |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 811 | if (!td->file_size_high) |
| 812 | td->file_size_high = td->file_size_low; |
| 813 | |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 814 | if (td_read(td) && !td_rw(td)) |
| 815 | td->verify = 0; |
Jens Axboe | bb8895e | 2006-10-30 15:14:48 +0100 | [diff] [blame] | 816 | |
| 817 | if (td->norandommap && td->verify != VERIFY_NONE) { |
| 818 | log_err("fio: norandommap given, verify disabled\n"); |
| 819 | td->verify = VERIFY_NONE; |
| 820 | } |
Jens Axboe | 690adba | 2006-10-30 15:25:09 +0100 | [diff] [blame] | 821 | if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO)) |
| 822 | log_err("fio: bs_unaligned may not work with raw io\n"); |
Jens Axboe | e0a2233 | 2006-12-20 12:54:25 +0100 | [diff] [blame] | 823 | |
| 824 | /* |
Jens Axboe | 48097d5 | 2007-02-17 06:30:44 +0100 | [diff] [blame] | 825 | * thinktime_spin must be less than thinktime |
| 826 | */ |
| 827 | if (td->thinktime_spin > td->thinktime) |
| 828 | td->thinktime_spin = td->thinktime; |
Jens Axboe | e916b39 | 2007-02-20 14:37:26 +0100 | [diff] [blame] | 829 | |
| 830 | /* |
| 831 | * The low water mark cannot be bigger than the iodepth |
| 832 | */ |
Jens Axboe | 9467b77 | 2007-02-27 19:56:43 +0100 | [diff] [blame] | 833 | if (td->iodepth_low > td->iodepth || !td->iodepth_low) { |
| 834 | /* |
| 835 | * syslet work around - if the workload is sequential, |
| 836 | * we want to let the queue drain all the way down to |
| 837 | * avoid seeking between async threads |
| 838 | */ |
| 839 | if (!strcmp(td->io_ops->name, "syslet-rw") && !td_random(td)) |
| 840 | td->iodepth_low = 1; |
| 841 | else |
| 842 | td->iodepth_low = td->iodepth; |
| 843 | } |
Jens Axboe | cb5ab51 | 2007-02-26 12:57:09 +0100 | [diff] [blame] | 844 | |
| 845 | /* |
| 846 | * If batch number isn't set, default to the same as iodepth |
| 847 | */ |
| 848 | if (td->iodepth_batch > td->iodepth || !td->iodepth_batch) |
| 849 | td->iodepth_batch = td->iodepth; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 850 | |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 851 | if (td->nr_files > td->files_index) |
Jens Axboe | 9f9214f | 2007-03-13 14:02:16 +0100 | [diff] [blame] | 852 | td->nr_files = td->files_index; |
| 853 | |
| 854 | if (td->open_files > td->nr_files || !td->open_files) |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 855 | td->open_files = td->nr_files; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 856 | } |
| 857 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 858 | /* |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 859 | * This function leaks the buffer |
| 860 | */ |
| 861 | static char *to_kmg(unsigned int val) |
| 862 | { |
| 863 | char *buf = malloc(32); |
Jens Axboe | f3502ba | 2007-02-14 01:27:09 +0100 | [diff] [blame] | 864 | char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 }; |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 865 | char *p = post; |
| 866 | |
Jens Axboe | 245142f | 2006-11-08 12:49:21 +0100 | [diff] [blame] | 867 | do { |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 868 | if (val & 1023) |
| 869 | break; |
| 870 | |
| 871 | val >>= 10; |
| 872 | p++; |
Jens Axboe | 245142f | 2006-11-08 12:49:21 +0100 | [diff] [blame] | 873 | } while (*p); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 874 | |
| 875 | snprintf(buf, 31, "%u%c", val, *p); |
| 876 | return buf; |
| 877 | } |
| 878 | |
Jens Axboe | 09629a9 | 2007-03-09 09:00:06 +0100 | [diff] [blame] | 879 | /* External engines are specified by "external:name.o") */ |
| 880 | static const char *get_engine_name(const char *str) |
| 881 | { |
| 882 | char *p = strstr(str, ":"); |
| 883 | |
| 884 | if (!p) |
| 885 | return str; |
| 886 | |
| 887 | p++; |
| 888 | strip_blank_front(&p); |
| 889 | strip_blank_end(p); |
| 890 | return p; |
| 891 | } |
| 892 | |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 893 | static int exists_and_not_file(const char *filename) |
| 894 | { |
| 895 | struct stat sb; |
| 896 | |
| 897 | if (lstat(filename, &sb) == -1) |
| 898 | return 0; |
| 899 | |
| 900 | if (S_ISREG(sb.st_mode)) |
| 901 | return 0; |
| 902 | |
| 903 | return 1; |
| 904 | } |
| 905 | |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 906 | /* |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 907 | * Initialize the various random states we need (random io, block size ranges, |
| 908 | * read/write mix, etc). |
| 909 | */ |
| 910 | static int init_random_state(struct thread_data *td) |
| 911 | { |
| 912 | unsigned long seeds[6]; |
| 913 | int fd, num_maps, blocks; |
| 914 | struct fio_file *f; |
| 915 | unsigned int i; |
| 916 | |
| 917 | fd = open("/dev/urandom", O_RDONLY); |
| 918 | if (fd == -1) { |
| 919 | td_verror(td, errno, "open"); |
| 920 | return 1; |
| 921 | } |
| 922 | |
| 923 | if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) { |
| 924 | td_verror(td, EIO, "read"); |
| 925 | close(fd); |
| 926 | return 1; |
| 927 | } |
| 928 | |
| 929 | close(fd); |
| 930 | |
| 931 | os_random_seed(seeds[0], &td->bsrange_state); |
| 932 | os_random_seed(seeds[1], &td->verify_state); |
| 933 | os_random_seed(seeds[2], &td->rwmix_state); |
| 934 | |
| 935 | if (td->file_service_type == FIO_FSERVICE_RANDOM) |
| 936 | os_random_seed(seeds[3], &td->next_file_state); |
| 937 | |
| 938 | os_random_seed(seeds[5], &td->file_size_state); |
| 939 | |
| 940 | if (!td_random(td)) |
| 941 | return 0; |
| 942 | |
| 943 | if (td->rand_repeatable) |
| 944 | seeds[4] = FIO_RANDSEED * td->thread_number; |
| 945 | |
| 946 | if (!td->norandommap) { |
| 947 | for_each_file(td, f, i) { |
| 948 | blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs; |
| 949 | num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP; |
| 950 | f->file_map = malloc(num_maps * sizeof(long)); |
| 951 | if (!f->file_map) { |
| 952 | log_err("fio: failed allocating random map. If running a large number of jobs, try the 'norandommap' option\n"); |
| 953 | return 1; |
| 954 | } |
| 955 | f->num_maps = num_maps; |
| 956 | memset(f->file_map, 0, num_maps * sizeof(long)); |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | os_random_seed(seeds[4], &td->random_state); |
| 961 | return 0; |
| 962 | } |
| 963 | |
| 964 | |
| 965 | /* |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 966 | * Adds a job to the list of things todo. Sanitizes the various options |
| 967 | * to make sure we don't have conflicts, and initializes various |
| 968 | * members of td. |
| 969 | */ |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 970 | static int add_job(struct thread_data *td, const char *jobname, int job_add_num) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 971 | { |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame] | 972 | const char *ddir_str[] = { NULL, "read", "write", "rw", NULL, |
| 973 | "randread", "randwrite", "randrw" }; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 974 | unsigned int i; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 975 | struct fio_file *f; |
Jens Axboe | 09629a9 | 2007-03-09 09:00:06 +0100 | [diff] [blame] | 976 | const char *engine; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 977 | char fname[PATH_MAX]; |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 978 | int numjobs, file_alloced; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 979 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 980 | /* |
| 981 | * the def_thread is just for options, it's not a real job |
| 982 | */ |
| 983 | if (td == &def_thread) |
| 984 | return 0; |
| 985 | |
Jens Axboe | 09629a9 | 2007-03-09 09:00:06 +0100 | [diff] [blame] | 986 | engine = get_engine_name(td->ioengine); |
| 987 | td->io_ops = load_ioengine(td, engine); |
| 988 | if (!td->io_ops) { |
| 989 | log_err("fio: failed to load engine %s\n", engine); |
| 990 | return 1; |
| 991 | } |
Jens Axboe | df64119 | 2006-10-12 07:55:41 +0200 | [diff] [blame] | 992 | |
Jens Axboe | 9cedf16 | 2007-03-12 11:29:30 +0100 | [diff] [blame] | 993 | if (td->use_thread) |
| 994 | nr_thread++; |
| 995 | else |
| 996 | nr_process++; |
| 997 | |
Jens Axboe | 690adba | 2006-10-30 15:25:09 +0100 | [diff] [blame] | 998 | if (td->odirect) |
| 999 | td->io_ops->flags |= FIO_RAWIO; |
| 1000 | |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 1001 | file_alloced = 0; |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1002 | if (!td->filename && !td->files_index) { |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 1003 | file_alloced = 1; |
Jens Axboe | 80be24f | 2007-03-12 11:01:25 +0100 | [diff] [blame] | 1004 | |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 1005 | if (td->nr_files == 1 && exists_and_not_file(jobname)) |
| 1006 | add_file(td, jobname); |
Jens Axboe | 7b05a21 | 2007-03-13 11:17:07 +0100 | [diff] [blame] | 1007 | else { |
| 1008 | for (i = 0; i < td->nr_files; i++) { |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 1009 | sprintf(fname, "%s.%d.%d", jobname, td->thread_number, i); |
Jens Axboe | 7b05a21 | 2007-03-13 11:17:07 +0100 | [diff] [blame] | 1010 | add_file(td, fname); |
| 1011 | } |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 1012 | } |
Jens Axboe | 0af7b54 | 2006-02-17 10:10:12 +0100 | [diff] [blame] | 1013 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1014 | |
Jens Axboe | e0a2233 | 2006-12-20 12:54:25 +0100 | [diff] [blame] | 1015 | fixup_options(td); |
| 1016 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 1017 | for_each_file(td, f, i) { |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 1018 | if (td->directory && f->filetype == FIO_TYPE_FILE) { |
| 1019 | sprintf(fname, "%s/%s", td->directory, f->file_name); |
| 1020 | f->file_name = strdup(fname); |
| 1021 | } |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 1022 | } |
| 1023 | |
Jens Axboe | 07739b5 | 2007-03-08 20:25:46 +0100 | [diff] [blame] | 1024 | td->mutex = fio_sem_init(0); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1025 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1026 | td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX; |
| 1027 | td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX; |
| 1028 | td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1029 | |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 1030 | if ((td->stonewall || td->numjobs > 1) && prev_group_jobs) { |
| 1031 | prev_group_jobs = 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1032 | groupid++; |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 1033 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1034 | |
| 1035 | td->groupid = groupid; |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 1036 | prev_group_jobs++; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1037 | |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 1038 | if (init_random_state(td)) |
| 1039 | goto err; |
| 1040 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1041 | if (setup_rate(td)) |
| 1042 | goto err; |
| 1043 | |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 1044 | if (td->write_lat_log) { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1045 | setup_log(&td->ts.slat_log); |
| 1046 | setup_log(&td->ts.clat_log); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1047 | } |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 1048 | if (td->write_bw_log) |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1049 | setup_log(&td->ts.bw_log); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1050 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1051 | if (!td->name) |
| 1052 | td->name = strdup(jobname); |
Jens Axboe | 0145205 | 2006-06-07 10:29:47 +0200 | [diff] [blame] | 1053 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 1054 | if (!terse_output) { |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 1055 | if (!job_add_num) { |
Jens Axboe | ba0fbe1 | 2007-03-09 14:34:23 +0100 | [diff] [blame] | 1056 | if (!strcmp(td->io_ops->name, "cpuio")) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame^] | 1057 | log_info("%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 1058 | else { |
| 1059 | char *c1, *c2, *c3, *c4; |
| 1060 | |
| 1061 | c1 = to_kmg(td->min_bs[DDIR_READ]); |
| 1062 | c2 = to_kmg(td->max_bs[DDIR_READ]); |
| 1063 | c3 = to_kmg(td->min_bs[DDIR_WRITE]); |
| 1064 | c4 = to_kmg(td->max_bs[DDIR_WRITE]); |
| 1065 | |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame^] | 1066 | log_info("%s: (g=%d): rw=%s, bs=%s-%s/%s-%s, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[td->td_ddir], c1, c2, c3, c4, td->io_ops->name, td->iodepth); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 1067 | |
| 1068 | free(c1); |
| 1069 | free(c2); |
| 1070 | free(c3); |
| 1071 | free(c4); |
| 1072 | } |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 1073 | } else if (job_add_num == 1) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame^] | 1074 | log_info("...\n"); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 1075 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1076 | |
| 1077 | /* |
| 1078 | * recurse add identical jobs, clear numjobs and stonewall options |
| 1079 | * as they don't apply to sub-jobs |
| 1080 | */ |
| 1081 | numjobs = td->numjobs; |
| 1082 | while (--numjobs) { |
| 1083 | struct thread_data *td_new = get_new_job(0, td); |
| 1084 | |
| 1085 | if (!td_new) |
| 1086 | goto err; |
| 1087 | |
| 1088 | td_new->numjobs = 1; |
| 1089 | td_new->stonewall = 0; |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 1090 | |
| 1091 | if (file_alloced) { |
| 1092 | td_new->filename = NULL; |
| 1093 | td_new->files_index = 0; |
| 1094 | td_new->files = NULL; |
| 1095 | } |
| 1096 | |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 1097 | job_add_num = numjobs - 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1098 | |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 1099 | if (add_job(td_new, jobname, job_add_num)) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1100 | goto err; |
| 1101 | } |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 1102 | |
| 1103 | if (td->numjobs > 1) { |
| 1104 | groupid++; |
| 1105 | prev_group_jobs = 0; |
| 1106 | } |
| 1107 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1108 | return 0; |
| 1109 | err: |
| 1110 | put_job(td); |
| 1111 | return -1; |
| 1112 | } |
| 1113 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1114 | static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu) |
| 1115 | { |
| 1116 | #ifdef FIO_HAVE_CPU_AFFINITY |
| 1117 | unsigned int i; |
| 1118 | |
| 1119 | CPU_ZERO(&cpumask); |
| 1120 | |
| 1121 | for (i = 0; i < sizeof(int) * 8; i++) { |
| 1122 | if ((1 << i) & cpu) |
| 1123 | CPU_SET(i, &cpumask); |
| 1124 | } |
| 1125 | #endif |
| 1126 | } |
| 1127 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1128 | static int is_empty_or_comment(char *line) |
| 1129 | { |
| 1130 | unsigned int i; |
| 1131 | |
| 1132 | for (i = 0; i < strlen(line); i++) { |
| 1133 | if (line[i] == ';') |
| 1134 | return 1; |
Ingo Molnar | 5cc2da3 | 2007-02-20 10:19:44 +0100 | [diff] [blame] | 1135 | if (line[i] == '#') |
| 1136 | return 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1137 | if (!isspace(line[i]) && !iscntrl(line[i])) |
| 1138 | return 0; |
| 1139 | } |
| 1140 | |
| 1141 | return 1; |
| 1142 | } |
| 1143 | |
Jens Axboe | 313cb20 | 2006-12-21 09:50:00 +0100 | [diff] [blame] | 1144 | /* |
| 1145 | * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that. |
| 1146 | */ |
Jens Axboe | 1907dbc | 2007-03-12 11:44:28 +0100 | [diff] [blame] | 1147 | static char *get_opt_postfix(const char *str) |
Jens Axboe | 313cb20 | 2006-12-21 09:50:00 +0100 | [diff] [blame] | 1148 | { |
| 1149 | char *p = strstr(str, ":"); |
| 1150 | |
| 1151 | if (!p) |
| 1152 | return NULL; |
| 1153 | |
| 1154 | p++; |
| 1155 | strip_blank_front(&p); |
| 1156 | strip_blank_end(p); |
| 1157 | return strdup(p); |
| 1158 | } |
| 1159 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1160 | static int str_mem_cb(void *data, const char *mem) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1161 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 1162 | struct thread_data *td = data; |
| 1163 | |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 1164 | if (td->mem_type == MEM_MMAPHUGE || td->mem_type == MEM_MMAP) { |
Jens Axboe | 1907dbc | 2007-03-12 11:44:28 +0100 | [diff] [blame] | 1165 | td->mmapfile = get_opt_postfix(mem); |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 1166 | if (td->mem_type == MEM_MMAPHUGE && !td->mmapfile) { |
Jens Axboe | d0bdaf4 | 2006-12-20 14:40:44 +0100 | [diff] [blame] | 1167 | log_err("fio: mmaphuge:/path/to/file\n"); |
| 1168 | return 1; |
| 1169 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1170 | } |
| 1171 | |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 1172 | return 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1173 | } |
| 1174 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1175 | static int str_lockmem_cb(void fio_unused *data, unsigned long *val) |
| 1176 | { |
| 1177 | mlock_size = *val; |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
Jens Axboe | 34cfcda | 2006-11-03 14:00:45 +0100 | [diff] [blame] | 1181 | #ifdef FIO_HAVE_IOPRIO |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1182 | static int str_prioclass_cb(void *data, unsigned int *val) |
| 1183 | { |
| 1184 | struct thread_data *td = data; |
| 1185 | |
| 1186 | td->ioprio |= *val << IOPRIO_CLASS_SHIFT; |
| 1187 | return 0; |
| 1188 | } |
| 1189 | |
| 1190 | static int str_prio_cb(void *data, unsigned int *val) |
| 1191 | { |
| 1192 | struct thread_data *td = data; |
| 1193 | |
| 1194 | td->ioprio |= *val; |
| 1195 | return 0; |
| 1196 | } |
Jens Axboe | 34cfcda | 2006-11-03 14:00:45 +0100 | [diff] [blame] | 1197 | #endif |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1198 | |
| 1199 | static int str_exitall_cb(void) |
| 1200 | { |
| 1201 | exitall_on_terminate = 1; |
| 1202 | return 0; |
| 1203 | } |
| 1204 | |
| 1205 | static int str_cpumask_cb(void *data, unsigned int *val) |
| 1206 | { |
| 1207 | struct thread_data *td = data; |
| 1208 | |
| 1209 | fill_cpu_mask(td->cpumask, *val); |
| 1210 | return 0; |
| 1211 | } |
| 1212 | |
Jens Axboe | 1907dbc | 2007-03-12 11:44:28 +0100 | [diff] [blame] | 1213 | static int str_fst_cb(void *data, const char *str) |
| 1214 | { |
| 1215 | struct thread_data *td = data; |
| 1216 | char *nr = get_opt_postfix(str); |
| 1217 | |
| 1218 | td->file_service_nr = 1; |
| 1219 | if (nr) |
| 1220 | td->file_service_nr = atoi(nr); |
| 1221 | |
| 1222 | return 0; |
| 1223 | } |
| 1224 | |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 1225 | static int str_filename_cb(void *data, const char *input) |
| 1226 | { |
| 1227 | struct thread_data *td = data; |
Jens Axboe | cae6195 | 2007-03-13 11:12:14 +0100 | [diff] [blame] | 1228 | char *fname, *str, *p; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 1229 | |
Jens Axboe | cae6195 | 2007-03-13 11:12:14 +0100 | [diff] [blame] | 1230 | p = str = strdup(input); |
Jens Axboe | e13363e | 2007-03-13 11:18:57 +0100 | [diff] [blame] | 1231 | |
| 1232 | strip_blank_front(&str); |
| 1233 | strip_blank_end(str); |
| 1234 | |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1235 | if (!td->files_index) |
| 1236 | td->nr_files = 0; |
| 1237 | |
Jens Axboe | 0ad920e | 2007-03-13 11:06:45 +0100 | [diff] [blame] | 1238 | while ((fname = strsep(&str, ":")) != NULL) { |
Jens Axboe | e13363e | 2007-03-13 11:18:57 +0100 | [diff] [blame] | 1239 | if (!strlen(fname)) |
| 1240 | break; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 1241 | add_file(td, fname); |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1242 | td->nr_files++; |
Jens Axboe | 0ad920e | 2007-03-13 11:06:45 +0100 | [diff] [blame] | 1243 | } |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 1244 | |
Jens Axboe | cae6195 | 2007-03-13 11:12:14 +0100 | [diff] [blame] | 1245 | free(p); |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | static int str_directory_cb(void *data, const char fio_unused *str) |
| 1250 | { |
| 1251 | struct thread_data *td = data; |
| 1252 | struct stat sb; |
| 1253 | |
| 1254 | if (lstat(td->directory, &sb) < 0) { |
| 1255 | log_err("fio: %s is not a directory\n", td->directory); |
| 1256 | td_verror(td, errno, "lstat"); |
| 1257 | return 1; |
| 1258 | } |
| 1259 | if (!S_ISDIR(sb.st_mode)) { |
| 1260 | log_err("fio: %s is not a directory\n", td->directory); |
| 1261 | return 1; |
| 1262 | } |
| 1263 | |
| 1264 | return 0; |
| 1265 | } |
| 1266 | |
Jens Axboe | bbf6b54 | 2007-03-13 15:28:55 +0100 | [diff] [blame] | 1267 | static int str_opendir_cb(void *data, const char fio_unused *str) |
| 1268 | { |
| 1269 | struct thread_data *td = data; |
| 1270 | |
| 1271 | if (!td->files_index) |
| 1272 | td->nr_files = 0; |
| 1273 | |
| 1274 | return add_dir_files(td, td->opendir); |
| 1275 | } |
| 1276 | |
Jens Axboe | 0726198 | 2006-06-07 10:51:12 +0200 | [diff] [blame] | 1277 | /* |
| 1278 | * This is our [ini] type file parser. |
| 1279 | */ |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 1280 | static int parse_jobs_ini(char *file, int stonewall_flag) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1281 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1282 | unsigned int global; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1283 | struct thread_data *td; |
Jens Axboe | fee3bb4 | 2006-10-30 13:32:08 +0100 | [diff] [blame] | 1284 | char *string, *name; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1285 | fpos_t off; |
| 1286 | FILE *f; |
| 1287 | char *p; |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 1288 | int ret = 0, stonewall; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1289 | |
| 1290 | f = fopen(file, "r"); |
| 1291 | if (!f) { |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 1292 | perror("fopen job file"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1293 | return 1; |
| 1294 | } |
| 1295 | |
| 1296 | string = malloc(4096); |
| 1297 | name = malloc(256); |
Jens Axboe | fee3bb4 | 2006-10-30 13:32:08 +0100 | [diff] [blame] | 1298 | memset(name, 0, 256); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1299 | |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 1300 | stonewall = stonewall_flag; |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1301 | do { |
| 1302 | p = fgets(string, 4095, f); |
| 1303 | if (!p) |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1304 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1305 | if (is_empty_or_comment(p)) |
| 1306 | continue; |
Jens Axboe | fee3bb4 | 2006-10-30 13:32:08 +0100 | [diff] [blame] | 1307 | if (sscanf(p, "[%255s]", name) != 1) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1308 | continue; |
| 1309 | |
| 1310 | global = !strncmp(name, "global", 6); |
| 1311 | |
| 1312 | name[strlen(name) - 1] = '\0'; |
| 1313 | |
| 1314 | td = get_new_job(global, &def_thread); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1315 | if (!td) { |
| 1316 | ret = 1; |
| 1317 | break; |
| 1318 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1319 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1320 | /* |
| 1321 | * Seperate multiple job files by a stonewall |
| 1322 | */ |
Jens Axboe | f948191 | 2006-06-09 11:37:28 +0200 | [diff] [blame] | 1323 | if (!global && stonewall) { |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1324 | td->stonewall = stonewall; |
| 1325 | stonewall = 0; |
| 1326 | } |
| 1327 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1328 | fgetpos(f, &off); |
| 1329 | while ((p = fgets(string, 4096, f)) != NULL) { |
| 1330 | if (is_empty_or_comment(p)) |
| 1331 | continue; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1332 | |
Jens Axboe | b6754f9 | 2006-05-30 14:29:32 +0200 | [diff] [blame] | 1333 | strip_blank_front(&p); |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1334 | |
| 1335 | if (p[0] == '[') |
| 1336 | break; |
| 1337 | |
Jens Axboe | 4ae3f76 | 2006-05-30 13:35:14 +0200 | [diff] [blame] | 1338 | strip_blank_end(p); |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 1339 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1340 | fgetpos(f, &off); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1341 | |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1342 | /* |
| 1343 | * Don't break here, continue parsing options so we |
| 1344 | * dump all the bad ones. Makes trial/error fixups |
| 1345 | * easier on the user. |
| 1346 | */ |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1347 | ret |= parse_option(p, options, td); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1348 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1349 | |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1350 | if (!ret) { |
| 1351 | fsetpos(f, &off); |
| 1352 | ret = add_job(td, name, 0); |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 1353 | } else { |
| 1354 | log_err("fio: job %s dropped\n", name); |
| 1355 | put_job(td); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1356 | } |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1357 | } while (!ret); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1358 | |
| 1359 | free(string); |
| 1360 | free(name); |
| 1361 | fclose(f); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1362 | return ret; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | static int fill_def_thread(void) |
| 1366 | { |
| 1367 | memset(&def_thread, 0, sizeof(def_thread)); |
| 1368 | |
| 1369 | if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) { |
| 1370 | perror("sched_getaffinity"); |
| 1371 | return 1; |
| 1372 | } |
| 1373 | |
| 1374 | /* |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1375 | * fill default options |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1376 | */ |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1377 | fill_default_options(&def_thread, options); |
| 1378 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1379 | def_thread.timeout = def_timeout; |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 1380 | def_thread.write_bw_log = write_bw_log; |
| 1381 | def_thread.write_lat_log = write_lat_log; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1382 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1383 | #ifdef FIO_HAVE_DISK_UTIL |
| 1384 | def_thread.do_disk_util = 1; |
| 1385 | #endif |
| 1386 | |
| 1387 | return 0; |
| 1388 | } |
| 1389 | |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame] | 1390 | static void usage(void) |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 1391 | { |
| 1392 | printf("%s\n", fio_version_string); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1393 | printf("\t--output\tWrite output to file\n"); |
| 1394 | printf("\t--timeout\tRuntime in seconds\n"); |
| 1395 | printf("\t--latency-log\tGenerate per-job latency logs\n"); |
| 1396 | printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n"); |
| 1397 | printf("\t--minimal\tMinimal (terse) output\n"); |
| 1398 | printf("\t--version\tPrint version info and exit\n"); |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 1399 | printf("\t--help\t\tPrint this page\n"); |
| 1400 | printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n"); |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 1401 | } |
| 1402 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1403 | static int parse_cmd_line(int argc, char *argv[]) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1404 | { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1405 | struct thread_data *td = NULL; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 1406 | int c, ini_idx = 0, lidx, ret, dont_add_job = 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1407 | |
Jens Axboe | 0be06ea | 2007-03-01 14:23:28 +0100 | [diff] [blame] | 1408 | while ((c = getopt_long_only(argc, argv, "", long_options, &lidx)) != -1) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1409 | switch (c) { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1410 | case 't': |
| 1411 | def_timeout = atoi(optarg); |
| 1412 | break; |
| 1413 | case 'l': |
| 1414 | write_lat_log = 1; |
| 1415 | break; |
| 1416 | case 'w': |
| 1417 | write_bw_log = 1; |
| 1418 | break; |
| 1419 | case 'o': |
| 1420 | f_out = fopen(optarg, "w+"); |
| 1421 | if (!f_out) { |
| 1422 | perror("fopen output"); |
| 1423 | exit(1); |
| 1424 | } |
| 1425 | f_err = f_out; |
| 1426 | break; |
| 1427 | case 'm': |
| 1428 | terse_output = 1; |
| 1429 | break; |
| 1430 | case 'h': |
| 1431 | usage(); |
| 1432 | exit(0); |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 1433 | case 'c': |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 1434 | ret = show_cmd_help(options, optarg); |
| 1435 | exit(ret); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1436 | case 'v': |
| 1437 | printf("%s\n", fio_version_string); |
| 1438 | exit(0); |
| 1439 | case FIO_GETOPT_JOB: { |
| 1440 | const char *opt = long_options[lidx].name; |
| 1441 | char *val = optarg; |
| 1442 | |
Jens Axboe | c2b1e75 | 2006-10-30 09:03:13 +0100 | [diff] [blame] | 1443 | if (!strncmp(opt, "name", 4) && td) { |
| 1444 | ret = add_job(td, td->name ?: "fio", 0); |
| 1445 | if (ret) { |
| 1446 | put_job(td); |
| 1447 | return 0; |
| 1448 | } |
| 1449 | td = NULL; |
| 1450 | } |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1451 | if (!td) { |
Jens Axboe | 38d0adb | 2006-10-30 12:21:25 +0100 | [diff] [blame] | 1452 | int global = !strncmp(val, "global", 6); |
Jens Axboe | c2b1e75 | 2006-10-30 09:03:13 +0100 | [diff] [blame] | 1453 | |
| 1454 | td = get_new_job(global, &def_thread); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1455 | if (!td) |
| 1456 | return 0; |
| 1457 | } |
Jens Axboe | 38d0adb | 2006-10-30 12:21:25 +0100 | [diff] [blame] | 1458 | |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 1459 | ret = parse_cmd_option(opt, val, options, td); |
Jens Axboe | 78217df | 2007-02-23 11:18:30 +0100 | [diff] [blame] | 1460 | if (ret) |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 1461 | dont_add_job = 1; |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1462 | break; |
| 1463 | } |
| 1464 | default: |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1465 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1466 | } |
| 1467 | } |
Jens Axboe | c9fad89 | 2006-05-27 17:26:50 +0200 | [diff] [blame] | 1468 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1469 | if (td) { |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 1470 | if (dont_add_job) |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1471 | put_job(td); |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 1472 | else { |
| 1473 | ret = add_job(td, td->name ?: "fio", 0); |
| 1474 | if (ret) |
| 1475 | put_job(td); |
| 1476 | } |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1477 | } |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 1478 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1479 | while (optind < argc) { |
| 1480 | ini_idx++; |
| 1481 | ini_file = realloc(ini_file, ini_idx * sizeof(char *)); |
| 1482 | ini_file[ini_idx - 1] = strdup(argv[optind]); |
| 1483 | optind++; |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 1484 | } |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1485 | |
| 1486 | return ini_idx; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | static void free_shm(void) |
| 1490 | { |
| 1491 | struct shmid_ds sbuf; |
| 1492 | |
| 1493 | if (threads) { |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 1494 | shmdt((void *) threads); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1495 | threads = NULL; |
| 1496 | shmctl(shm_id, IPC_RMID, &sbuf); |
| 1497 | } |
| 1498 | } |
| 1499 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1500 | /* |
| 1501 | * The thread area is shared between the main process and the job |
| 1502 | * threads/processes. So setup a shared memory segment that will hold |
| 1503 | * all the job info. |
| 1504 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1505 | static int setup_thread_area(void) |
| 1506 | { |
| 1507 | /* |
| 1508 | * 1024 is too much on some machines, scale max_jobs if |
| 1509 | * we get a failure that looks like too large a shm segment |
| 1510 | */ |
| 1511 | do { |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1512 | size_t size = max_jobs * sizeof(struct thread_data); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1513 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1514 | shm_id = shmget(0, size, IPC_CREAT | 0600); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1515 | if (shm_id != -1) |
| 1516 | break; |
| 1517 | if (errno != EINVAL) { |
| 1518 | perror("shmget"); |
| 1519 | break; |
| 1520 | } |
| 1521 | |
| 1522 | max_jobs >>= 1; |
| 1523 | } while (max_jobs); |
| 1524 | |
| 1525 | if (shm_id == -1) |
| 1526 | return 1; |
| 1527 | |
| 1528 | threads = shmat(shm_id, NULL, 0); |
| 1529 | if (threads == (void *) -1) { |
| 1530 | perror("shmat"); |
| 1531 | return 1; |
| 1532 | } |
| 1533 | |
| 1534 | atexit(free_shm); |
| 1535 | return 0; |
| 1536 | } |
| 1537 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1538 | /* |
| 1539 | * Copy the fio options into the long options map, so we mirror |
| 1540 | * job and cmd line options. |
| 1541 | */ |
| 1542 | static void dupe_job_options(void) |
| 1543 | { |
| 1544 | struct fio_option *o; |
| 1545 | unsigned int i; |
| 1546 | |
| 1547 | i = 0; |
| 1548 | while (long_options[i].name) |
| 1549 | i++; |
| 1550 | |
| 1551 | o = &options[0]; |
| 1552 | while (o->name) { |
| 1553 | long_options[i].name = o->name; |
| 1554 | long_options[i].val = FIO_GETOPT_JOB; |
| 1555 | if (o->type == FIO_OPT_STR_SET) |
| 1556 | long_options[i].has_arg = no_argument; |
| 1557 | else |
| 1558 | long_options[i].has_arg = required_argument; |
| 1559 | |
| 1560 | i++; |
| 1561 | o++; |
| 1562 | assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS); |
| 1563 | } |
| 1564 | } |
| 1565 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1566 | int parse_options(int argc, char *argv[]) |
| 1567 | { |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1568 | int job_files, i; |
| 1569 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1570 | f_out = stdout; |
| 1571 | f_err = stderr; |
| 1572 | |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 1573 | options_init(options); |
| 1574 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1575 | dupe_job_options(); |
| 1576 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1577 | if (setup_thread_area()) |
| 1578 | return 1; |
| 1579 | if (fill_def_thread()) |
| 1580 | return 1; |
| 1581 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1582 | job_files = parse_cmd_line(argc, argv); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1583 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1584 | for (i = 0; i < job_files; i++) { |
| 1585 | if (fill_def_thread()) |
| 1586 | return 1; |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 1587 | if (parse_jobs_ini(ini_file[i], i)) |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1588 | return 1; |
Jens Axboe | 88c6ed8 | 2006-06-09 11:28:10 +0200 | [diff] [blame] | 1589 | free(ini_file[i]); |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1590 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1591 | |
Jens Axboe | 88c6ed8 | 2006-06-09 11:28:10 +0200 | [diff] [blame] | 1592 | free(ini_file); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1593 | |
| 1594 | if (!thread_number) { |
| 1595 | log_err("No jobs defined(s)\n"); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1596 | return 1; |
| 1597 | } |
| 1598 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1599 | return 0; |
| 1600 | } |