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