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