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