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