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