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