Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include <ctype.h> |
| 5 | #include <string.h> |
| 6 | #include <getopt.h> |
| 7 | #include <assert.h> |
| 8 | |
| 9 | #include "fio.h" |
| 10 | #include "parse.h" |
| 11 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 12 | #define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var) |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 13 | |
| 14 | /* |
| 15 | * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that. |
| 16 | */ |
| 17 | static char *get_opt_postfix(const char *str) |
| 18 | { |
| 19 | char *p = strstr(str, ":"); |
| 20 | |
| 21 | if (!p) |
| 22 | return NULL; |
| 23 | |
| 24 | p++; |
| 25 | strip_blank_front(&p); |
| 26 | strip_blank_end(p); |
| 27 | return strdup(p); |
| 28 | } |
| 29 | |
Jens Axboe | 211097b | 2007-03-22 18:56:45 +0100 | [diff] [blame] | 30 | static int str_rw_cb(void *data, const char *str) |
| 31 | { |
| 32 | struct thread_data *td = data; |
| 33 | char *nr = get_opt_postfix(str); |
| 34 | |
Jens Axboe | fafdba3 | 2007-03-26 10:09:12 +0200 | [diff] [blame] | 35 | td->o.ddir_nr = 1; |
Jens Axboe | 211097b | 2007-03-22 18:56:45 +0100 | [diff] [blame] | 36 | if (nr) |
| 37 | td->o.ddir_nr = atoi(nr); |
| 38 | |
Jens Axboe | 211097b | 2007-03-22 18:56:45 +0100 | [diff] [blame] | 39 | return 0; |
| 40 | } |
| 41 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 42 | static int str_mem_cb(void *data, const char *mem) |
| 43 | { |
| 44 | struct thread_data *td = data; |
| 45 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 46 | if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) { |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 47 | td->mmapfile = get_opt_postfix(mem); |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 48 | if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) { |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 49 | log_err("fio: mmaphuge:/path/to/file\n"); |
| 50 | return 1; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static int str_lockmem_cb(void fio_unused *data, unsigned long *val) |
| 58 | { |
| 59 | mlock_size = *val; |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | #ifdef FIO_HAVE_IOPRIO |
| 64 | static int str_prioclass_cb(void *data, unsigned int *val) |
| 65 | { |
| 66 | struct thread_data *td = data; |
| 67 | |
| 68 | td->ioprio |= *val << IOPRIO_CLASS_SHIFT; |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static int str_prio_cb(void *data, unsigned int *val) |
| 73 | { |
| 74 | struct thread_data *td = data; |
| 75 | |
| 76 | td->ioprio |= *val; |
| 77 | return 0; |
| 78 | } |
| 79 | #endif |
| 80 | |
| 81 | static int str_exitall_cb(void) |
| 82 | { |
| 83 | exitall_on_terminate = 1; |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu) |
| 88 | { |
| 89 | #ifdef FIO_HAVE_CPU_AFFINITY |
| 90 | unsigned int i; |
| 91 | |
| 92 | CPU_ZERO(&cpumask); |
| 93 | |
| 94 | for (i = 0; i < sizeof(int) * 8; i++) { |
| 95 | if ((1 << i) & cpu) |
| 96 | CPU_SET(i, &cpumask); |
| 97 | } |
| 98 | #endif |
| 99 | } |
| 100 | |
| 101 | static int str_cpumask_cb(void *data, unsigned int *val) |
| 102 | { |
| 103 | struct thread_data *td = data; |
| 104 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 105 | fill_cpu_mask(td->o.cpumask, *val); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static int str_fst_cb(void *data, const char *str) |
| 110 | { |
| 111 | struct thread_data *td = data; |
| 112 | char *nr = get_opt_postfix(str); |
| 113 | |
| 114 | td->file_service_nr = 1; |
| 115 | if (nr) |
| 116 | td->file_service_nr = atoi(nr); |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | static int str_filename_cb(void *data, const char *input) |
| 122 | { |
| 123 | struct thread_data *td = data; |
| 124 | char *fname, *str, *p; |
| 125 | |
| 126 | p = str = strdup(input); |
| 127 | |
| 128 | strip_blank_front(&str); |
| 129 | strip_blank_end(str); |
| 130 | |
| 131 | if (!td->files_index) |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 132 | td->o.nr_files = 0; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 133 | |
| 134 | while ((fname = strsep(&str, ":")) != NULL) { |
| 135 | if (!strlen(fname)) |
| 136 | break; |
| 137 | add_file(td, fname); |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 138 | td->o.nr_files++; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | free(p); |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static int str_directory_cb(void *data, const char fio_unused *str) |
| 146 | { |
| 147 | struct thread_data *td = data; |
| 148 | struct stat sb; |
| 149 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 150 | if (lstat(td->o.directory, &sb) < 0) { |
| 151 | log_err("fio: %s is not a directory\n", td->o.directory); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 152 | td_verror(td, errno, "lstat"); |
| 153 | return 1; |
| 154 | } |
| 155 | if (!S_ISDIR(sb.st_mode)) { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 156 | log_err("fio: %s is not a directory\n", td->o.directory); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static int str_opendir_cb(void *data, const char fio_unused *str) |
| 164 | { |
| 165 | struct thread_data *td = data; |
| 166 | |
| 167 | if (!td->files_index) |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 168 | td->o.nr_files = 0; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 169 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 170 | return add_dir_files(td, td->o.opendir); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | |
| 174 | #define __stringify_1(x) #x |
| 175 | #define __stringify(x) __stringify_1(x) |
| 176 | |
| 177 | /* |
| 178 | * Map of job/command line options |
| 179 | */ |
| 180 | static struct fio_option options[] = { |
| 181 | { |
| 182 | .name = "description", |
| 183 | .type = FIO_OPT_STR_STORE, |
| 184 | .off1 = td_var_offset(description), |
| 185 | .help = "Text job description", |
| 186 | }, |
| 187 | { |
| 188 | .name = "name", |
| 189 | .type = FIO_OPT_STR_STORE, |
| 190 | .off1 = td_var_offset(name), |
| 191 | .help = "Name of this job", |
| 192 | }, |
| 193 | { |
| 194 | .name = "directory", |
| 195 | .type = FIO_OPT_STR_STORE, |
| 196 | .off1 = td_var_offset(directory), |
| 197 | .cb = str_directory_cb, |
| 198 | .help = "Directory to store files in", |
| 199 | }, |
| 200 | { |
| 201 | .name = "filename", |
| 202 | .type = FIO_OPT_STR_STORE, |
| 203 | .off1 = td_var_offset(filename), |
| 204 | .cb = str_filename_cb, |
| 205 | .help = "File(s) to use for the workload", |
| 206 | }, |
| 207 | { |
| 208 | .name = "opendir", |
| 209 | .type = FIO_OPT_STR_STORE, |
| 210 | .off1 = td_var_offset(opendir), |
| 211 | .cb = str_opendir_cb, |
| 212 | .help = "Recursively add files from this directory and down", |
| 213 | }, |
| 214 | { |
| 215 | .name = "rw", |
Jens Axboe | d3aad8f | 2007-03-15 14:12:05 +0100 | [diff] [blame] | 216 | .alias = "readwrite", |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 217 | .type = FIO_OPT_STR, |
Jens Axboe | 211097b | 2007-03-22 18:56:45 +0100 | [diff] [blame] | 218 | .cb = str_rw_cb, |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 219 | .off1 = td_var_offset(td_ddir), |
| 220 | .help = "IO direction", |
| 221 | .def = "read", |
| 222 | .posval = { |
| 223 | { .ival = "read", |
| 224 | .oval = TD_DDIR_READ, |
| 225 | .help = "Sequential read", |
| 226 | }, |
| 227 | { .ival = "write", |
| 228 | .oval = TD_DDIR_WRITE, |
| 229 | .help = "Sequential write", |
| 230 | }, |
| 231 | { .ival = "randread", |
| 232 | .oval = TD_DDIR_RANDREAD, |
| 233 | .help = "Random read", |
| 234 | }, |
| 235 | { .ival = "randwrite", |
| 236 | .oval = TD_DDIR_RANDWRITE, |
| 237 | .help = "Random write", |
| 238 | }, |
| 239 | { .ival = "rw", |
| 240 | .oval = TD_DDIR_RW, |
| 241 | .help = "Sequential read and write mix", |
| 242 | }, |
| 243 | { .ival = "randrw", |
| 244 | .oval = TD_DDIR_RANDRW, |
| 245 | .help = "Random read and write mix" |
| 246 | }, |
| 247 | }, |
| 248 | }, |
| 249 | { |
Jens Axboe | d2f3ac3 | 2007-03-22 19:24:09 +0100 | [diff] [blame] | 250 | .name = "fadvise_hint", |
| 251 | .type = FIO_OPT_BOOL, |
| 252 | .off1 = td_var_offset(fadvise_hint), |
| 253 | .help = "Use fadvise() to advise the kernel on IO pattern", |
| 254 | .def = "1", |
| 255 | }, |
| 256 | { |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 257 | .name = "ioengine", |
| 258 | .type = FIO_OPT_STR_STORE, |
| 259 | .off1 = td_var_offset(ioengine), |
| 260 | .help = "IO engine to use", |
| 261 | .def = "sync", |
| 262 | .posval = { |
| 263 | { .ival = "sync", |
| 264 | .help = "Use read/write", |
| 265 | }, |
| 266 | #ifdef FIO_HAVE_LIBAIO |
| 267 | { .ival = "libaio", |
| 268 | .help = "Linux native asynchronous IO", |
| 269 | }, |
| 270 | #endif |
| 271 | #ifdef FIO_HAVE_POSIXAIO |
| 272 | { .ival = "posixaio", |
| 273 | .help = "POSIX asynchronous IO", |
| 274 | }, |
| 275 | #endif |
| 276 | { .ival = "mmap", |
| 277 | .help = "Memory mapped IO", |
| 278 | }, |
| 279 | #ifdef FIO_HAVE_SPLICE |
| 280 | { .ival = "splice", |
| 281 | .help = "splice/vmsplice based IO", |
| 282 | }, |
| 283 | #endif |
| 284 | #ifdef FIO_HAVE_SGIO |
| 285 | { .ival = "sg", |
| 286 | .help = "SCSI generic v3 IO", |
| 287 | }, |
| 288 | #endif |
| 289 | { .ival = "null", |
| 290 | .help = "Testing engine (no data transfer)", |
| 291 | }, |
| 292 | { .ival = "net", |
| 293 | .help = "Network IO", |
| 294 | }, |
| 295 | #ifdef FIO_HAVE_SYSLET |
| 296 | { .ival = "syslet-rw", |
| 297 | .help = "syslet enabled async pread/pwrite IO", |
| 298 | }, |
| 299 | #endif |
| 300 | { .ival = "cpuio", |
| 301 | .help = "CPU cycler burner engine", |
| 302 | }, |
Jens Axboe | b8c82a4 | 2007-03-21 08:48:26 +0100 | [diff] [blame] | 303 | #ifdef FIO_HAVE_GUASI |
| 304 | { .ival = "guasi", |
| 305 | .help = "GUASI IO engine", |
| 306 | }, |
| 307 | #endif |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 308 | { .ival = "external", |
| 309 | .help = "Load external engine (append name)", |
| 310 | }, |
| 311 | }, |
| 312 | }, |
| 313 | { |
| 314 | .name = "iodepth", |
| 315 | .type = FIO_OPT_INT, |
| 316 | .off1 = td_var_offset(iodepth), |
| 317 | .help = "Amount of IO buffers to keep in flight", |
| 318 | .def = "1", |
| 319 | }, |
| 320 | { |
| 321 | .name = "iodepth_batch", |
| 322 | .type = FIO_OPT_INT, |
| 323 | .off1 = td_var_offset(iodepth_batch), |
| 324 | .help = "Number of IO to submit in one go", |
| 325 | }, |
| 326 | { |
| 327 | .name = "iodepth_low", |
| 328 | .type = FIO_OPT_INT, |
| 329 | .off1 = td_var_offset(iodepth_low), |
| 330 | .help = "Low water mark for queuing depth", |
| 331 | }, |
| 332 | { |
| 333 | .name = "size", |
| 334 | .type = FIO_OPT_STR_VAL, |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 335 | .off1 = td_var_offset(size), |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 336 | .help = "Total size of device or files", |
| 337 | }, |
| 338 | { |
| 339 | .name = "filesize", |
| 340 | .type = FIO_OPT_STR_VAL, |
| 341 | .off1 = td_var_offset(file_size_low), |
| 342 | .off2 = td_var_offset(file_size_high), |
| 343 | .help = "Size of individual files", |
| 344 | }, |
| 345 | { |
| 346 | .name = "bs", |
Jens Axboe | d3aad8f | 2007-03-15 14:12:05 +0100 | [diff] [blame] | 347 | .alias = "blocksize", |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 348 | .type = FIO_OPT_STR_VAL_INT, |
| 349 | .off1 = td_var_offset(bs[DDIR_READ]), |
| 350 | .off2 = td_var_offset(bs[DDIR_WRITE]), |
| 351 | .help = "Block size unit", |
| 352 | .def = "4k", |
| 353 | }, |
| 354 | { |
| 355 | .name = "bsrange", |
Jens Axboe | d3aad8f | 2007-03-15 14:12:05 +0100 | [diff] [blame] | 356 | .alias = "blocksize_range", |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 357 | .type = FIO_OPT_RANGE, |
| 358 | .off1 = td_var_offset(min_bs[DDIR_READ]), |
| 359 | .off2 = td_var_offset(max_bs[DDIR_READ]), |
| 360 | .off3 = td_var_offset(min_bs[DDIR_WRITE]), |
| 361 | .off4 = td_var_offset(max_bs[DDIR_WRITE]), |
| 362 | .help = "Set block size range (in more detail than bs)", |
| 363 | }, |
| 364 | { |
| 365 | .name = "bs_unaligned", |
Jens Axboe | d3aad8f | 2007-03-15 14:12:05 +0100 | [diff] [blame] | 366 | .alias = "blocksize_unaligned", |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 367 | .type = FIO_OPT_STR_SET, |
| 368 | .off1 = td_var_offset(bs_unaligned), |
| 369 | .help = "Don't sector align IO buffer sizes", |
| 370 | }, |
| 371 | { |
| 372 | .name = "offset", |
| 373 | .type = FIO_OPT_STR_VAL, |
| 374 | .off1 = td_var_offset(start_offset), |
| 375 | .help = "Start IO from this offset", |
| 376 | .def = "0", |
| 377 | }, |
| 378 | { |
| 379 | .name = "randrepeat", |
| 380 | .type = FIO_OPT_BOOL, |
| 381 | .off1 = td_var_offset(rand_repeatable), |
| 382 | .help = "Use repeatable random IO pattern", |
| 383 | .def = "1", |
| 384 | }, |
| 385 | { |
| 386 | .name = "norandommap", |
| 387 | .type = FIO_OPT_STR_SET, |
| 388 | .off1 = td_var_offset(norandommap), |
| 389 | .help = "Accept potential duplicate random blocks", |
| 390 | }, |
| 391 | { |
| 392 | .name = "nrfiles", |
| 393 | .type = FIO_OPT_INT, |
| 394 | .off1 = td_var_offset(nr_files), |
| 395 | .help = "Split job workload between this number of files", |
| 396 | .def = "1", |
| 397 | }, |
| 398 | { |
| 399 | .name = "openfiles", |
| 400 | .type = FIO_OPT_INT, |
| 401 | .off1 = td_var_offset(open_files), |
| 402 | .help = "Number of files to keep open at the same time", |
| 403 | }, |
| 404 | { |
| 405 | .name = "file_service_type", |
| 406 | .type = FIO_OPT_STR, |
| 407 | .cb = str_fst_cb, |
| 408 | .off1 = td_var_offset(file_service_type), |
| 409 | .help = "How to select which file to service next", |
| 410 | .def = "roundrobin", |
| 411 | .posval = { |
| 412 | { .ival = "random", |
| 413 | .oval = FIO_FSERVICE_RANDOM, |
| 414 | .help = "Choose a file at random", |
| 415 | }, |
| 416 | { .ival = "roundrobin", |
| 417 | .oval = FIO_FSERVICE_RR, |
| 418 | .help = "Round robin select files", |
| 419 | }, |
| 420 | }, |
| 421 | }, |
| 422 | { |
| 423 | .name = "fsync", |
| 424 | .type = FIO_OPT_INT, |
| 425 | .off1 = td_var_offset(fsync_blocks), |
| 426 | .help = "Issue fsync for writes every given number of blocks", |
| 427 | .def = "0", |
| 428 | }, |
| 429 | { |
| 430 | .name = "direct", |
| 431 | .type = FIO_OPT_BOOL, |
| 432 | .off1 = td_var_offset(odirect), |
| 433 | .help = "Use O_DIRECT IO (negates buffered)", |
| 434 | .def = "0", |
| 435 | }, |
| 436 | { |
| 437 | .name = "buffered", |
| 438 | .type = FIO_OPT_BOOL, |
| 439 | .off1 = td_var_offset(odirect), |
| 440 | .neg = 1, |
| 441 | .help = "Use buffered IO (negates direct)", |
| 442 | .def = "1", |
| 443 | }, |
| 444 | { |
| 445 | .name = "overwrite", |
| 446 | .type = FIO_OPT_BOOL, |
| 447 | .off1 = td_var_offset(overwrite), |
| 448 | .help = "When writing, set whether to overwrite current data", |
| 449 | .def = "0", |
| 450 | }, |
| 451 | { |
| 452 | .name = "loops", |
| 453 | .type = FIO_OPT_INT, |
| 454 | .off1 = td_var_offset(loops), |
| 455 | .help = "Number of times to run the job", |
| 456 | .def = "1", |
| 457 | }, |
| 458 | { |
| 459 | .name = "numjobs", |
| 460 | .type = FIO_OPT_INT, |
| 461 | .off1 = td_var_offset(numjobs), |
| 462 | .help = "Duplicate this job this many times", |
| 463 | .def = "1", |
| 464 | }, |
| 465 | { |
| 466 | .name = "startdelay", |
| 467 | .type = FIO_OPT_INT, |
| 468 | .off1 = td_var_offset(start_delay), |
| 469 | .help = "Only start job when this period has passed", |
| 470 | .def = "0", |
| 471 | }, |
| 472 | { |
| 473 | .name = "runtime", |
| 474 | .alias = "timeout", |
| 475 | .type = FIO_OPT_STR_VAL_TIME, |
| 476 | .off1 = td_var_offset(timeout), |
| 477 | .help = "Stop workload when this amount of time has passed", |
| 478 | .def = "0", |
| 479 | }, |
| 480 | { |
| 481 | .name = "mem", |
Jens Axboe | d3aad8f | 2007-03-15 14:12:05 +0100 | [diff] [blame] | 482 | .alias = "iomem", |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 483 | .type = FIO_OPT_STR, |
| 484 | .cb = str_mem_cb, |
| 485 | .off1 = td_var_offset(mem_type), |
| 486 | .help = "Backing type for IO buffers", |
| 487 | .def = "malloc", |
| 488 | .posval = { |
| 489 | { .ival = "malloc", |
| 490 | .oval = MEM_MALLOC, |
| 491 | .help = "Use malloc(3) for IO buffers", |
| 492 | }, |
Jens Axboe | b370e46 | 2007-03-19 10:51:49 +0100 | [diff] [blame] | 493 | { .ival = "shm", |
| 494 | .oval = MEM_SHM, |
| 495 | .help = "Use shared memory segments for IO buffers", |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 496 | }, |
| 497 | #ifdef FIO_HAVE_HUGETLB |
Jens Axboe | 37c8cdf | 2007-03-19 13:14:03 +0100 | [diff] [blame] | 498 | { .ival = "shmhuge", |
| 499 | .oval = MEM_SHMHUGE, |
| 500 | .help = "Like shm, but use huge pages", |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 501 | }, |
| 502 | #endif |
Jens Axboe | b370e46 | 2007-03-19 10:51:49 +0100 | [diff] [blame] | 503 | { .ival = "mmap", |
| 504 | .oval = MEM_MMAP, |
| 505 | .help = "Use mmap(2) (file or anon) for IO buffers", |
| 506 | }, |
Jens Axboe | 37c8cdf | 2007-03-19 13:14:03 +0100 | [diff] [blame] | 507 | #ifdef FIO_HAVE_HUGETLB |
| 508 | { .ival = "mmaphuge", |
| 509 | .oval = MEM_MMAPHUGE, |
| 510 | .help = "Like mmap, but use huge pages", |
| 511 | }, |
| 512 | #endif |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 513 | }, |
| 514 | }, |
| 515 | { |
| 516 | .name = "verify", |
| 517 | .type = FIO_OPT_STR, |
| 518 | .off1 = td_var_offset(verify), |
| 519 | .help = "Verify data written", |
| 520 | .def = "0", |
| 521 | .posval = { |
| 522 | { .ival = "0", |
| 523 | .oval = VERIFY_NONE, |
| 524 | .help = "Don't do IO verification", |
| 525 | }, |
| 526 | { .ival = "crc32", |
| 527 | .oval = VERIFY_CRC32, |
| 528 | .help = "Use crc32 checksums for verification", |
| 529 | }, |
| 530 | { .ival = "md5", |
| 531 | .oval = VERIFY_MD5, |
| 532 | .help = "Use md5 checksums for verification", |
| 533 | }, |
Jens Axboe | 36690c9 | 2007-03-26 10:23:34 +0200 | [diff] [blame] | 534 | { |
| 535 | .ival = "null", |
| 536 | .oval = VERIFY_NULL, |
| 537 | .help = "Pretend to verify", |
| 538 | }, |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 539 | }, |
| 540 | }, |
| 541 | { |
Jens Axboe | 160b966 | 2007-03-27 10:59:49 +0200 | [diff] [blame] | 542 | .name = "verifysort", |
| 543 | .type = FIO_OPT_BOOL, |
| 544 | .off1 = td_var_offset(verifysort), |
| 545 | .help = "Sort written verify blocks for read back", |
| 546 | .def = "1", |
| 547 | }, |
| 548 | { |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 549 | .name = "write_iolog", |
| 550 | .type = FIO_OPT_STR_STORE, |
| 551 | .off1 = td_var_offset(write_iolog_file), |
| 552 | .help = "Store IO pattern to file", |
| 553 | }, |
| 554 | { |
| 555 | .name = "read_iolog", |
| 556 | .type = FIO_OPT_STR_STORE, |
| 557 | .off1 = td_var_offset(read_iolog_file), |
| 558 | .help = "Playback IO pattern from file", |
| 559 | }, |
| 560 | { |
| 561 | .name = "exec_prerun", |
| 562 | .type = FIO_OPT_STR_STORE, |
| 563 | .off1 = td_var_offset(exec_prerun), |
| 564 | .help = "Execute this file prior to running job", |
| 565 | }, |
| 566 | { |
| 567 | .name = "exec_postrun", |
| 568 | .type = FIO_OPT_STR_STORE, |
| 569 | .off1 = td_var_offset(exec_postrun), |
| 570 | .help = "Execute this file after running job", |
| 571 | }, |
| 572 | #ifdef FIO_HAVE_IOSCHED_SWITCH |
| 573 | { |
| 574 | .name = "ioscheduler", |
| 575 | .type = FIO_OPT_STR_STORE, |
| 576 | .off1 = td_var_offset(ioscheduler), |
| 577 | .help = "Use this IO scheduler on the backing device", |
| 578 | }, |
| 579 | #endif |
| 580 | { |
| 581 | .name = "zonesize", |
| 582 | .type = FIO_OPT_STR_VAL, |
| 583 | .off1 = td_var_offset(zone_size), |
| 584 | .help = "Give size of an IO zone", |
| 585 | .def = "0", |
| 586 | }, |
| 587 | { |
| 588 | .name = "zoneskip", |
| 589 | .type = FIO_OPT_STR_VAL, |
| 590 | .off1 = td_var_offset(zone_skip), |
| 591 | .help = "Space between IO zones", |
| 592 | .def = "0", |
| 593 | }, |
| 594 | { |
| 595 | .name = "lockmem", |
| 596 | .type = FIO_OPT_STR_VAL, |
| 597 | .cb = str_lockmem_cb, |
| 598 | .help = "Lock down this amount of memory", |
| 599 | .def = "0", |
| 600 | }, |
| 601 | { |
| 602 | .name = "rwmixcycle", |
| 603 | .type = FIO_OPT_INT, |
| 604 | .off1 = td_var_offset(rwmixcycle), |
| 605 | .help = "Cycle period for mixed read/write workloads (msec)", |
| 606 | .def = "500", |
| 607 | }, |
| 608 | { |
| 609 | .name = "rwmixread", |
| 610 | .type = FIO_OPT_INT, |
Jens Axboe | e47f799 | 2007-03-21 14:05:39 +0100 | [diff] [blame] | 611 | .off1 = td_var_offset(rwmix[DDIR_READ]), |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 612 | .maxval = 100, |
| 613 | .help = "Percentage of mixed workload that is reads", |
| 614 | .def = "50", |
| 615 | }, |
| 616 | { |
| 617 | .name = "rwmixwrite", |
| 618 | .type = FIO_OPT_INT, |
Jens Axboe | e47f799 | 2007-03-21 14:05:39 +0100 | [diff] [blame] | 619 | .off1 = td_var_offset(rwmix[DDIR_WRITE]), |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 620 | .maxval = 100, |
| 621 | .help = "Percentage of mixed workload that is writes", |
| 622 | .def = "50", |
| 623 | }, |
| 624 | { |
| 625 | .name = "nice", |
| 626 | .type = FIO_OPT_INT, |
| 627 | .off1 = td_var_offset(nice), |
| 628 | .help = "Set job CPU nice value", |
| 629 | .minval = -19, |
| 630 | .maxval = 20, |
| 631 | .def = "0", |
| 632 | }, |
| 633 | #ifdef FIO_HAVE_IOPRIO |
| 634 | { |
| 635 | .name = "prio", |
| 636 | .type = FIO_OPT_INT, |
| 637 | .cb = str_prio_cb, |
| 638 | .help = "Set job IO priority value", |
| 639 | .minval = 0, |
| 640 | .maxval = 7, |
| 641 | }, |
| 642 | { |
| 643 | .name = "prioclass", |
| 644 | .type = FIO_OPT_INT, |
| 645 | .cb = str_prioclass_cb, |
| 646 | .help = "Set job IO priority class", |
| 647 | .minval = 0, |
| 648 | .maxval = 3, |
| 649 | }, |
| 650 | #endif |
| 651 | { |
| 652 | .name = "thinktime", |
| 653 | .type = FIO_OPT_INT, |
| 654 | .off1 = td_var_offset(thinktime), |
| 655 | .help = "Idle time between IO buffers (usec)", |
| 656 | .def = "0", |
| 657 | }, |
| 658 | { |
| 659 | .name = "thinktime_spin", |
| 660 | .type = FIO_OPT_INT, |
| 661 | .off1 = td_var_offset(thinktime_spin), |
| 662 | .help = "Start think time by spinning this amount (usec)", |
| 663 | .def = "0", |
| 664 | }, |
| 665 | { |
| 666 | .name = "thinktime_blocks", |
| 667 | .type = FIO_OPT_INT, |
| 668 | .off1 = td_var_offset(thinktime_blocks), |
| 669 | .help = "IO buffer period between 'thinktime'", |
| 670 | .def = "1", |
| 671 | }, |
| 672 | { |
| 673 | .name = "rate", |
| 674 | .type = FIO_OPT_INT, |
| 675 | .off1 = td_var_offset(rate), |
| 676 | .help = "Set bandwidth rate", |
| 677 | }, |
| 678 | { |
| 679 | .name = "ratemin", |
| 680 | .type = FIO_OPT_INT, |
| 681 | .off1 = td_var_offset(ratemin), |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 682 | .help = "Job must meet this rate or it will be shutdown", |
| 683 | }, |
| 684 | { |
| 685 | .name = "rate_iops", |
| 686 | .type = FIO_OPT_INT, |
| 687 | .off1 = td_var_offset(rate_iops), |
| 688 | .help = "Limit IO used to this number of IO operations/sec", |
| 689 | }, |
| 690 | { |
| 691 | .name = "rate_iops_min", |
| 692 | .type = FIO_OPT_INT, |
| 693 | .off1 = td_var_offset(rate_iops_min), |
| 694 | .help = "Job must meet this rate or it will be shutdown", |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 695 | }, |
| 696 | { |
| 697 | .name = "ratecycle", |
| 698 | .type = FIO_OPT_INT, |
| 699 | .off1 = td_var_offset(ratecycle), |
| 700 | .help = "Window average for rate limits (msec)", |
| 701 | .def = "1000", |
| 702 | }, |
| 703 | { |
| 704 | .name = "invalidate", |
| 705 | .type = FIO_OPT_BOOL, |
| 706 | .off1 = td_var_offset(invalidate_cache), |
| 707 | .help = "Invalidate buffer/page cache prior to running job", |
| 708 | .def = "1", |
| 709 | }, |
| 710 | { |
| 711 | .name = "sync", |
| 712 | .type = FIO_OPT_BOOL, |
| 713 | .off1 = td_var_offset(sync_io), |
| 714 | .help = "Use O_SYNC for buffered writes", |
| 715 | .def = "0", |
| 716 | }, |
| 717 | { |
| 718 | .name = "bwavgtime", |
| 719 | .type = FIO_OPT_INT, |
| 720 | .off1 = td_var_offset(bw_avg_time), |
| 721 | .help = "Time window over which to calculate bandwidth (msec)", |
| 722 | .def = "500", |
| 723 | }, |
| 724 | { |
| 725 | .name = "create_serialize", |
| 726 | .type = FIO_OPT_BOOL, |
| 727 | .off1 = td_var_offset(create_serialize), |
| 728 | .help = "Serialize creating of job files", |
| 729 | .def = "1", |
| 730 | }, |
| 731 | { |
| 732 | .name = "create_fsync", |
| 733 | .type = FIO_OPT_BOOL, |
| 734 | .off1 = td_var_offset(create_fsync), |
| 735 | .help = "Fsync file after creation", |
| 736 | .def = "1", |
| 737 | }, |
| 738 | { |
| 739 | .name = "cpuload", |
| 740 | .type = FIO_OPT_INT, |
| 741 | .off1 = td_var_offset(cpuload), |
| 742 | .help = "Use this percentage of CPU", |
| 743 | }, |
| 744 | { |
| 745 | .name = "cpuchunks", |
| 746 | .type = FIO_OPT_INT, |
| 747 | .off1 = td_var_offset(cpucycle), |
| 748 | .help = "Length of the CPU burn cycles (usecs)", |
| 749 | .def = "50000", |
| 750 | }, |
| 751 | #ifdef FIO_HAVE_CPU_AFFINITY |
| 752 | { |
| 753 | .name = "cpumask", |
| 754 | .type = FIO_OPT_INT, |
| 755 | .cb = str_cpumask_cb, |
| 756 | .help = "CPU affinity mask", |
| 757 | }, |
| 758 | #endif |
| 759 | { |
| 760 | .name = "end_fsync", |
| 761 | .type = FIO_OPT_BOOL, |
| 762 | .off1 = td_var_offset(end_fsync), |
| 763 | .help = "Include fsync at the end of job", |
| 764 | .def = "0", |
| 765 | }, |
| 766 | { |
| 767 | .name = "fsync_on_close", |
| 768 | .type = FIO_OPT_BOOL, |
| 769 | .off1 = td_var_offset(fsync_on_close), |
| 770 | .help = "fsync files on close", |
| 771 | .def = "0", |
| 772 | }, |
| 773 | { |
| 774 | .name = "unlink", |
| 775 | .type = FIO_OPT_BOOL, |
| 776 | .off1 = td_var_offset(unlink), |
| 777 | .help = "Unlink created files after job has completed", |
| 778 | .def = "0", |
| 779 | }, |
| 780 | { |
| 781 | .name = "exitall", |
| 782 | .type = FIO_OPT_STR_SET, |
| 783 | .cb = str_exitall_cb, |
| 784 | .help = "Terminate all jobs when one exits", |
| 785 | }, |
| 786 | { |
| 787 | .name = "stonewall", |
| 788 | .type = FIO_OPT_STR_SET, |
| 789 | .off1 = td_var_offset(stonewall), |
| 790 | .help = "Insert a hard barrier between this job and previous", |
| 791 | }, |
| 792 | { |
Jens Axboe | b3d62a7 | 2007-03-20 14:23:26 +0100 | [diff] [blame] | 793 | .name = "new_group", |
| 794 | .type = FIO_OPT_STR_SET, |
| 795 | .off1 = td_var_offset(new_group), |
| 796 | .help = "Mark the start of a new group (for reporting)", |
| 797 | }, |
| 798 | { |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 799 | .name = "thread", |
| 800 | .type = FIO_OPT_STR_SET, |
| 801 | .off1 = td_var_offset(use_thread), |
| 802 | .help = "Use threads instead of forks", |
| 803 | }, |
| 804 | { |
| 805 | .name = "write_bw_log", |
| 806 | .type = FIO_OPT_STR_SET, |
| 807 | .off1 = td_var_offset(write_bw_log), |
| 808 | .help = "Write log of bandwidth during run", |
| 809 | }, |
| 810 | { |
| 811 | .name = "write_lat_log", |
| 812 | .type = FIO_OPT_STR_SET, |
| 813 | .off1 = td_var_offset(write_lat_log), |
| 814 | .help = "Write log of latency during run", |
| 815 | }, |
| 816 | { |
| 817 | .name = "hugepage-size", |
| 818 | .type = FIO_OPT_STR_VAL, |
| 819 | .off1 = td_var_offset(hugepage_size), |
| 820 | .help = "When using hugepages, specify size of each page", |
| 821 | .def = __stringify(FIO_HUGE_PAGE), |
| 822 | }, |
| 823 | { |
| 824 | .name = "group_reporting", |
| 825 | .type = FIO_OPT_STR_SET, |
| 826 | .off1 = td_var_offset(group_reporting), |
| 827 | .help = "Do reporting on a per-group basis", |
| 828 | }, |
| 829 | { |
Jens Axboe | e9459e5 | 2007-04-17 15:46:32 +0200 | [diff] [blame^] | 830 | .name = "zero_buffers", |
| 831 | .type = FIO_OPT_STR_SET, |
| 832 | .off1 = td_var_offset(zero_buffers), |
| 833 | .help = "Init IO buffers to all zeroes", |
| 834 | }, |
| 835 | { |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 836 | .name = NULL, |
| 837 | }, |
| 838 | }; |
| 839 | |
| 840 | void fio_options_dup_and_init(struct option *long_options) |
| 841 | { |
| 842 | struct fio_option *o; |
| 843 | unsigned int i; |
| 844 | |
| 845 | options_init(options); |
| 846 | |
| 847 | i = 0; |
| 848 | while (long_options[i].name) |
| 849 | i++; |
| 850 | |
| 851 | o = &options[0]; |
| 852 | while (o->name) { |
| 853 | long_options[i].name = o->name; |
| 854 | long_options[i].val = FIO_GETOPT_JOB; |
| 855 | if (o->type == FIO_OPT_STR_SET) |
| 856 | long_options[i].has_arg = no_argument; |
| 857 | else |
| 858 | long_options[i].has_arg = required_argument; |
| 859 | |
| 860 | i++; |
| 861 | o++; |
| 862 | assert(i < FIO_NR_OPTIONS); |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | int fio_option_parse(struct thread_data *td, const char *opt) |
| 867 | { |
| 868 | return parse_option(opt, options, td); |
| 869 | } |
| 870 | |
| 871 | int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val) |
| 872 | { |
| 873 | return parse_cmd_option(opt, val, options, td); |
| 874 | } |
| 875 | |
| 876 | void fio_fill_default_options(struct thread_data *td) |
| 877 | { |
| 878 | fill_default_options(td, options); |
| 879 | } |
| 880 | |
| 881 | int fio_show_option_help(const char *opt) |
| 882 | { |
| 883 | return show_cmd_help(options, opt); |
| 884 | } |
Jens Axboe | d23bb32 | 2007-03-23 15:57:56 +0100 | [diff] [blame] | 885 | |
| 886 | static void __options_mem(struct thread_data *td, int alloc) |
| 887 | { |
| 888 | struct thread_options *o = &td->o; |
| 889 | struct fio_option *opt; |
| 890 | char **ptr; |
| 891 | int i; |
| 892 | |
| 893 | for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) { |
| 894 | if (opt->type != FIO_OPT_STR_STORE) |
| 895 | continue; |
| 896 | |
| 897 | ptr = (void *) o + opt->off1; |
| 898 | if (*ptr) { |
| 899 | if (alloc) |
| 900 | *ptr = strdup(*ptr); |
| 901 | else { |
| 902 | free(*ptr); |
| 903 | *ptr = NULL; |
| 904 | } |
| 905 | } |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | /* |
| 910 | * dupe FIO_OPT_STR_STORE options |
| 911 | */ |
| 912 | void options_mem_dupe(struct thread_data *td) |
| 913 | { |
| 914 | __options_mem(td, 1); |
| 915 | } |
| 916 | |
Jens Axboe | 22d6621 | 2007-03-27 20:06:25 +0200 | [diff] [blame] | 917 | void options_mem_free(struct thread_data fio_unused *td) |
Jens Axboe | d23bb32 | 2007-03-23 15:57:56 +0100 | [diff] [blame] | 918 | { |
Jens Axboe | 22d6621 | 2007-03-27 20:06:25 +0200 | [diff] [blame] | 919 | #if 0 |
Jens Axboe | d23bb32 | 2007-03-23 15:57:56 +0100 | [diff] [blame] | 920 | __options_mem(td, 0); |
Jens Axboe | 22d6621 | 2007-03-27 20:06:25 +0200 | [diff] [blame] | 921 | #endif |
Jens Axboe | d23bb32 | 2007-03-23 15:57:56 +0100 | [diff] [blame] | 922 | } |