Add vsync io engine
[fio.git] / options.c
CommitLineData
214e1eca
JA
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"
90059d65 11#include "fls.h"
214e1eca 12
2dc1bbeb 13#define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
214e1eca
JA
14
15/*
16 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
17 */
18static char *get_opt_postfix(const char *str)
19{
20 char *p = strstr(str, ":");
21
22 if (!p)
23 return NULL;
24
25 p++;
26 strip_blank_front(&p);
27 strip_blank_end(p);
28 return strdup(p);
29}
30
564ca972
JA
31static int bs_cmp(const void *p1, const void *p2)
32{
33 const struct bssplit *bsp1 = p1;
34 const struct bssplit *bsp2 = p2;
35
36 return bsp1->perc < bsp2->perc;
37}
38
39static int str_bssplit_cb(void *data, const char *input)
40{
41 struct thread_data *td = data;
42 char *fname, *str, *p;
43 unsigned int i, perc, perc_missing;
44 unsigned int max_bs, min_bs;
45 long long val;
46
47 p = str = strdup(input);
48
49 strip_blank_front(&str);
50 strip_blank_end(str);
51
52 td->o.bssplit_nr = 4;
53 td->o.bssplit = malloc(4 * sizeof(struct bssplit));
54
55 i = 0;
56 max_bs = 0;
57 min_bs = -1;
58 while ((fname = strsep(&str, ":")) != NULL) {
59 char *perc_str;
60
61 if (!strlen(fname))
62 break;
63
64 /*
65 * grow struct buffer, if needed
66 */
67 if (i == td->o.bssplit_nr) {
68 td->o.bssplit_nr <<= 1;
69 td->o.bssplit = realloc(td->o.bssplit, td->o.bssplit_nr * sizeof(struct bssplit));
70 }
71
72 perc_str = strstr(fname, "/");
73 if (perc_str) {
74 *perc_str = '\0';
75 perc_str++;
76 perc = atoi(perc_str);
77 if (perc > 100)
78 perc = 100;
79 else if (!perc)
80 perc = -1;
81 } else
82 perc = -1;
83
84 if (str_to_decimal(fname, &val, 1)) {
85 log_err("fio: bssplit conversion failed\n");
86 free(td->o.bssplit);
87 return 1;
88 }
89
90 if (val > max_bs)
91 max_bs = val;
92 if (val < min_bs)
93 min_bs = val;
94
95 td->o.bssplit[i].bs = val;
96 td->o.bssplit[i].perc = perc;
97 i++;
98 }
99
100 td->o.bssplit_nr = i;
101
102 /*
103 * Now check if the percentages add up, and how much is missing
104 */
105 perc = perc_missing = 0;
106 for (i = 0; i < td->o.bssplit_nr; i++) {
107 struct bssplit *bsp = &td->o.bssplit[i];
108
109 if (bsp->perc == (unsigned char) -1)
110 perc_missing++;
111 else
112 perc += bsp->perc;
113 }
114
115 if (perc > 100) {
116 log_err("fio: bssplit percentages add to more than 100%%\n");
117 free(td->o.bssplit);
118 return 1;
119 }
120 /*
121 * If values didn't have a percentage set, divide the remains between
122 * them.
123 */
124 if (perc_missing) {
125 for (i = 0; i < td->o.bssplit_nr; i++) {
126 struct bssplit *bsp = &td->o.bssplit[i];
127
128 if (bsp->perc == (unsigned char) -1)
129 bsp->perc = (100 - perc) / perc_missing;
130 }
131 }
132
133 td->o.min_bs[DDIR_READ] = td->o.min_bs[DDIR_WRITE] = min_bs;
134 td->o.max_bs[DDIR_READ] = td->o.max_bs[DDIR_WRITE] = max_bs;
135
136 /*
137 * now sort based on percentages, for ease of lookup
138 */
139 qsort(td->o.bssplit, td->o.bssplit_nr, sizeof(struct bssplit), bs_cmp);
140
141 free(p);
142 return 0;
143}
144
211097b2
JA
145static int str_rw_cb(void *data, const char *str)
146{
147 struct thread_data *td = data;
148 char *nr = get_opt_postfix(str);
149
fafdba3c 150 td->o.ddir_nr = 1;
211097b2
JA
151 if (nr)
152 td->o.ddir_nr = atoi(nr);
153
211097b2
JA
154 return 0;
155}
156
214e1eca
JA
157static int str_mem_cb(void *data, const char *mem)
158{
159 struct thread_data *td = data;
160
2dc1bbeb 161 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
214e1eca 162 td->mmapfile = get_opt_postfix(mem);
2dc1bbeb 163 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
214e1eca
JA
164 log_err("fio: mmaphuge:/path/to/file\n");
165 return 1;
166 }
167 }
168
169 return 0;
170}
171
172static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
173{
174 mlock_size = *val;
175 return 0;
176}
177
178#ifdef FIO_HAVE_IOPRIO
179static int str_prioclass_cb(void *data, unsigned int *val)
180{
181 struct thread_data *td = data;
6cefbe33
JA
182 unsigned short mask;
183
184 /*
185 * mask off old class bits, str_prio_cb() may have set a default class
186 */
187 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
188 td->ioprio &= mask;
214e1eca
JA
189
190 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
ac684785 191 td->ioprio_set = 1;
214e1eca
JA
192 return 0;
193}
194
195static int str_prio_cb(void *data, unsigned int *val)
196{
197 struct thread_data *td = data;
198
199 td->ioprio |= *val;
6cefbe33
JA
200
201 /*
202 * If no class is set, assume BE
203 */
204 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
205 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
206
ac684785 207 td->ioprio_set = 1;
214e1eca
JA
208 return 0;
209}
210#endif
211
212static int str_exitall_cb(void)
213{
214 exitall_on_terminate = 1;
215 return 0;
216}
217
214e1eca 218#ifdef FIO_HAVE_CPU_AFFINITY
d2e268b0
JA
219static int str_cpumask_cb(void *data, unsigned int *val)
220{
221 struct thread_data *td = data;
214e1eca
JA
222 unsigned int i;
223
d2e268b0 224 CPU_ZERO(&td->o.cpumask);
214e1eca 225
e600f7f1 226 for (i = 0; i < sizeof(int) * 8; i++)
d2e268b0
JA
227 if ((1 << i) & *val)
228 CPU_SET(*val, &td->o.cpumask);
229
230 td->o.cpumask_set = 1;
231 return 0;
214e1eca
JA
232}
233
d2e268b0 234static int str_cpus_allowed_cb(void *data, const char *input)
214e1eca
JA
235{
236 struct thread_data *td = data;
d2e268b0
JA
237 char *cpu, *str, *p;
238
239 CPU_ZERO(&td->o.cpumask);
240
241 p = str = strdup(input);
214e1eca 242
d2e268b0
JA
243 strip_blank_front(&str);
244 strip_blank_end(str);
245
246 while ((cpu = strsep(&str, ",")) != NULL) {
247 if (!strlen(cpu))
248 break;
249 CPU_SET(atoi(cpu), &td->o.cpumask);
250 }
251
252 free(p);
375b2695 253 td->o.cpumask_set = 1;
d2e268b0 254 exit(0);
214e1eca
JA
255 return 0;
256}
d2e268b0 257#endif
214e1eca
JA
258
259static int str_fst_cb(void *data, const char *str)
260{
261 struct thread_data *td = data;
262 char *nr = get_opt_postfix(str);
263
264 td->file_service_nr = 1;
265 if (nr)
266 td->file_service_nr = atoi(nr);
267
268 return 0;
269}
270
271static int str_filename_cb(void *data, const char *input)
272{
273 struct thread_data *td = data;
274 char *fname, *str, *p;
275
276 p = str = strdup(input);
277
278 strip_blank_front(&str);
279 strip_blank_end(str);
280
281 if (!td->files_index)
2dc1bbeb 282 td->o.nr_files = 0;
214e1eca
JA
283
284 while ((fname = strsep(&str, ":")) != NULL) {
285 if (!strlen(fname))
286 break;
287 add_file(td, fname);
2dc1bbeb 288 td->o.nr_files++;
214e1eca
JA
289 }
290
291 free(p);
292 return 0;
293}
294
295static int str_directory_cb(void *data, const char fio_unused *str)
296{
297 struct thread_data *td = data;
298 struct stat sb;
299
2dc1bbeb
JA
300 if (lstat(td->o.directory, &sb) < 0) {
301 log_err("fio: %s is not a directory\n", td->o.directory);
214e1eca
JA
302 td_verror(td, errno, "lstat");
303 return 1;
304 }
305 if (!S_ISDIR(sb.st_mode)) {
2dc1bbeb 306 log_err("fio: %s is not a directory\n", td->o.directory);
214e1eca
JA
307 return 1;
308 }
309
310 return 0;
311}
312
313static int str_opendir_cb(void *data, const char fio_unused *str)
314{
315 struct thread_data *td = data;
316
317 if (!td->files_index)
2dc1bbeb 318 td->o.nr_files = 0;
214e1eca 319
2dc1bbeb 320 return add_dir_files(td, td->o.opendir);
214e1eca
JA
321}
322
a59e170d 323static int str_verify_offset_cb(void *data, unsigned int *off)
546a9142
SL
324{
325 struct thread_data *td = data;
a59e170d 326
546a9142 327 if (*off && *off < sizeof(struct verify_header)) {
a59e170d 328 log_err("fio: verify_offset too small\n");
546a9142
SL
329 return 1;
330 }
a59e170d
JA
331
332 td->o.verify_offset = *off;
546a9142
SL
333 return 0;
334}
335
e28218f3 336static int str_verify_pattern_cb(void *data, unsigned int *off)
90059d65
JA
337{
338 struct thread_data *td = data;
e28218f3 339 unsigned int msb;
90059d65 340
e28218f3 341 msb = fls(*off);
90059d65
JA
342 if (msb <= 8)
343 td->o.verify_pattern_bytes = 1;
344 else if (msb <= 16)
345 td->o.verify_pattern_bytes = 2;
346 else if (msb <= 24)
347 td->o.verify_pattern_bytes = 3;
348 else
349 td->o.verify_pattern_bytes = 4;
350
e28218f3 351 td->o.verify_pattern = *off;
90059d65
JA
352 return 0;
353}
214e1eca
JA
354
355#define __stringify_1(x) #x
356#define __stringify(x) __stringify_1(x)
357
358/*
359 * Map of job/command line options
360 */
361static struct fio_option options[] = {
362 {
363 .name = "description",
364 .type = FIO_OPT_STR_STORE,
365 .off1 = td_var_offset(description),
366 .help = "Text job description",
367 },
368 {
369 .name = "name",
370 .type = FIO_OPT_STR_STORE,
371 .off1 = td_var_offset(name),
372 .help = "Name of this job",
373 },
374 {
375 .name = "directory",
376 .type = FIO_OPT_STR_STORE,
377 .off1 = td_var_offset(directory),
378 .cb = str_directory_cb,
379 .help = "Directory to store files in",
380 },
381 {
382 .name = "filename",
383 .type = FIO_OPT_STR_STORE,
384 .off1 = td_var_offset(filename),
385 .cb = str_filename_cb,
386 .help = "File(s) to use for the workload",
387 },
388 {
389 .name = "opendir",
390 .type = FIO_OPT_STR_STORE,
391 .off1 = td_var_offset(opendir),
392 .cb = str_opendir_cb,
393 .help = "Recursively add files from this directory and down",
394 },
395 {
396 .name = "rw",
d3aad8f2 397 .alias = "readwrite",
214e1eca 398 .type = FIO_OPT_STR,
211097b2 399 .cb = str_rw_cb,
214e1eca
JA
400 .off1 = td_var_offset(td_ddir),
401 .help = "IO direction",
402 .def = "read",
403 .posval = {
404 { .ival = "read",
405 .oval = TD_DDIR_READ,
406 .help = "Sequential read",
407 },
408 { .ival = "write",
409 .oval = TD_DDIR_WRITE,
410 .help = "Sequential write",
411 },
412 { .ival = "randread",
413 .oval = TD_DDIR_RANDREAD,
414 .help = "Random read",
415 },
416 { .ival = "randwrite",
417 .oval = TD_DDIR_RANDWRITE,
418 .help = "Random write",
419 },
420 { .ival = "rw",
421 .oval = TD_DDIR_RW,
422 .help = "Sequential read and write mix",
423 },
424 { .ival = "randrw",
425 .oval = TD_DDIR_RANDRW,
426 .help = "Random read and write mix"
427 },
428 },
429 },
430 {
431 .name = "ioengine",
432 .type = FIO_OPT_STR_STORE,
433 .off1 = td_var_offset(ioengine),
434 .help = "IO engine to use",
435 .def = "sync",
436 .posval = {
437 { .ival = "sync",
438 .help = "Use read/write",
439 },
a31041ea 440 { .ival = "psync",
441 .help = "Use pread/pwrite",
442 },
1d2af02a
JA
443 { .ival = "vsync",
444 .help = "Use readv/writev",
445 },
214e1eca
JA
446#ifdef FIO_HAVE_LIBAIO
447 { .ival = "libaio",
448 .help = "Linux native asynchronous IO",
449 },
450#endif
451#ifdef FIO_HAVE_POSIXAIO
452 { .ival = "posixaio",
453 .help = "POSIX asynchronous IO",
454 },
455#endif
456 { .ival = "mmap",
457 .help = "Memory mapped IO",
458 },
459#ifdef FIO_HAVE_SPLICE
460 { .ival = "splice",
461 .help = "splice/vmsplice based IO",
462 },
9cce02e8
JA
463 { .ival = "netsplice",
464 .help = "splice/vmsplice to/from the network",
465 },
214e1eca
JA
466#endif
467#ifdef FIO_HAVE_SGIO
468 { .ival = "sg",
469 .help = "SCSI generic v3 IO",
470 },
471#endif
472 { .ival = "null",
473 .help = "Testing engine (no data transfer)",
474 },
475 { .ival = "net",
476 .help = "Network IO",
477 },
478#ifdef FIO_HAVE_SYSLET
479 { .ival = "syslet-rw",
480 .help = "syslet enabled async pread/pwrite IO",
481 },
482#endif
483 { .ival = "cpuio",
484 .help = "CPU cycler burner engine",
485 },
b8c82a46
JA
486#ifdef FIO_HAVE_GUASI
487 { .ival = "guasi",
488 .help = "GUASI IO engine",
489 },
490#endif
214e1eca
JA
491 { .ival = "external",
492 .help = "Load external engine (append name)",
493 },
494 },
495 },
496 {
497 .name = "iodepth",
498 .type = FIO_OPT_INT,
499 .off1 = td_var_offset(iodepth),
500 .help = "Amount of IO buffers to keep in flight",
757aff4f 501 .minval = 1,
214e1eca
JA
502 .def = "1",
503 },
504 {
505 .name = "iodepth_batch",
506 .type = FIO_OPT_INT,
507 .off1 = td_var_offset(iodepth_batch),
508 .help = "Number of IO to submit in one go",
afdf9352 509 .parent = "iodepth",
a2e6f8ac
JA
510 .minval = 1,
511 .def = "1",
214e1eca
JA
512 },
513 {
514 .name = "iodepth_low",
515 .type = FIO_OPT_INT,
516 .off1 = td_var_offset(iodepth_low),
517 .help = "Low water mark for queuing depth",
afdf9352 518 .parent = "iodepth",
214e1eca
JA
519 },
520 {
521 .name = "size",
522 .type = FIO_OPT_STR_VAL,
2dc1bbeb 523 .off1 = td_var_offset(size),
c3edbdba 524 .minval = 1,
214e1eca
JA
525 .help = "Total size of device or files",
526 },
aa31f1f1
SL
527 {
528 .name = "fill_device",
529 .type = FIO_OPT_BOOL,
530 .off1 = td_var_offset(fill_device),
531 .help = "Write until an ENOSPC error occurs",
532 .def = "0",
533 },
214e1eca
JA
534 {
535 .name = "filesize",
536 .type = FIO_OPT_STR_VAL,
537 .off1 = td_var_offset(file_size_low),
538 .off2 = td_var_offset(file_size_high),
c3edbdba 539 .minval = 1,
214e1eca
JA
540 .help = "Size of individual files",
541 },
67a1000f
JA
542 {
543 .name = "offset",
544 .alias = "fileoffset",
545 .type = FIO_OPT_STR_VAL,
546 .off1 = td_var_offset(start_offset),
547 .help = "Start IO from this offset",
548 .def = "0",
549 },
214e1eca
JA
550 {
551 .name = "bs",
d3aad8f2 552 .alias = "blocksize",
214e1eca
JA
553 .type = FIO_OPT_STR_VAL_INT,
554 .off1 = td_var_offset(bs[DDIR_READ]),
555 .off2 = td_var_offset(bs[DDIR_WRITE]),
c3edbdba 556 .minval = 1,
214e1eca
JA
557 .help = "Block size unit",
558 .def = "4k",
67a1000f 559 .parent = "rw",
214e1eca
JA
560 },
561 {
562 .name = "bsrange",
d3aad8f2 563 .alias = "blocksize_range",
214e1eca
JA
564 .type = FIO_OPT_RANGE,
565 .off1 = td_var_offset(min_bs[DDIR_READ]),
566 .off2 = td_var_offset(max_bs[DDIR_READ]),
567 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
568 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
c3edbdba 569 .minval = 1,
214e1eca 570 .help = "Set block size range (in more detail than bs)",
67a1000f 571 .parent = "rw",
214e1eca 572 },
564ca972
JA
573 {
574 .name = "bssplit",
575 .type = FIO_OPT_STR,
576 .cb = str_bssplit_cb,
577 .help = "Set a specific mix of block sizes",
578 .parent = "rw",
579 },
214e1eca
JA
580 {
581 .name = "bs_unaligned",
d3aad8f2 582 .alias = "blocksize_unaligned",
214e1eca
JA
583 .type = FIO_OPT_STR_SET,
584 .off1 = td_var_offset(bs_unaligned),
585 .help = "Don't sector align IO buffer sizes",
67a1000f 586 .parent = "rw",
214e1eca
JA
587 },
588 {
589 .name = "randrepeat",
590 .type = FIO_OPT_BOOL,
591 .off1 = td_var_offset(rand_repeatable),
592 .help = "Use repeatable random IO pattern",
593 .def = "1",
67a1000f 594 .parent = "rw",
214e1eca
JA
595 },
596 {
597 .name = "norandommap",
598 .type = FIO_OPT_STR_SET,
599 .off1 = td_var_offset(norandommap),
600 .help = "Accept potential duplicate random blocks",
67a1000f 601 .parent = "rw",
214e1eca
JA
602 },
603 {
604 .name = "nrfiles",
605 .type = FIO_OPT_INT,
606 .off1 = td_var_offset(nr_files),
607 .help = "Split job workload between this number of files",
608 .def = "1",
609 },
610 {
611 .name = "openfiles",
612 .type = FIO_OPT_INT,
613 .off1 = td_var_offset(open_files),
614 .help = "Number of files to keep open at the same time",
615 },
616 {
617 .name = "file_service_type",
618 .type = FIO_OPT_STR,
619 .cb = str_fst_cb,
620 .off1 = td_var_offset(file_service_type),
621 .help = "How to select which file to service next",
622 .def = "roundrobin",
623 .posval = {
624 { .ival = "random",
625 .oval = FIO_FSERVICE_RANDOM,
626 .help = "Choose a file at random",
627 },
628 { .ival = "roundrobin",
629 .oval = FIO_FSERVICE_RR,
630 .help = "Round robin select files",
631 },
632 },
67a1000f
JA
633 .parent = "nrfiles",
634 },
635 {
636 .name = "fadvise_hint",
637 .type = FIO_OPT_BOOL,
638 .off1 = td_var_offset(fadvise_hint),
639 .help = "Use fadvise() to advise the kernel on IO pattern",
640 .def = "1",
214e1eca
JA
641 },
642 {
643 .name = "fsync",
644 .type = FIO_OPT_INT,
645 .off1 = td_var_offset(fsync_blocks),
646 .help = "Issue fsync for writes every given number of blocks",
647 .def = "0",
648 },
649 {
650 .name = "direct",
651 .type = FIO_OPT_BOOL,
652 .off1 = td_var_offset(odirect),
653 .help = "Use O_DIRECT IO (negates buffered)",
654 .def = "0",
655 },
656 {
657 .name = "buffered",
658 .type = FIO_OPT_BOOL,
659 .off1 = td_var_offset(odirect),
660 .neg = 1,
661 .help = "Use buffered IO (negates direct)",
662 .def = "1",
663 },
664 {
665 .name = "overwrite",
666 .type = FIO_OPT_BOOL,
667 .off1 = td_var_offset(overwrite),
668 .help = "When writing, set whether to overwrite current data",
669 .def = "0",
670 },
671 {
672 .name = "loops",
673 .type = FIO_OPT_INT,
674 .off1 = td_var_offset(loops),
675 .help = "Number of times to run the job",
676 .def = "1",
677 },
678 {
679 .name = "numjobs",
680 .type = FIO_OPT_INT,
681 .off1 = td_var_offset(numjobs),
682 .help = "Duplicate this job this many times",
683 .def = "1",
684 },
685 {
686 .name = "startdelay",
687 .type = FIO_OPT_INT,
688 .off1 = td_var_offset(start_delay),
689 .help = "Only start job when this period has passed",
690 .def = "0",
691 },
692 {
693 .name = "runtime",
694 .alias = "timeout",
695 .type = FIO_OPT_STR_VAL_TIME,
696 .off1 = td_var_offset(timeout),
697 .help = "Stop workload when this amount of time has passed",
698 .def = "0",
699 },
cf4464ca
JA
700 {
701 .name = "time_based",
702 .type = FIO_OPT_STR_SET,
703 .off1 = td_var_offset(time_based),
704 .help = "Keep running until runtime/timeout is met",
705 },
214e1eca
JA
706 {
707 .name = "mem",
d3aad8f2 708 .alias = "iomem",
214e1eca
JA
709 .type = FIO_OPT_STR,
710 .cb = str_mem_cb,
711 .off1 = td_var_offset(mem_type),
712 .help = "Backing type for IO buffers",
713 .def = "malloc",
714 .posval = {
715 { .ival = "malloc",
716 .oval = MEM_MALLOC,
717 .help = "Use malloc(3) for IO buffers",
718 },
37c8cdfe
JA
719 { .ival = "shm",
720 .oval = MEM_SHM,
721 .help = "Use shared memory segments for IO buffers",
722 },
214e1eca
JA
723#ifdef FIO_HAVE_HUGETLB
724 { .ival = "shmhuge",
725 .oval = MEM_SHMHUGE,
726 .help = "Like shm, but use huge pages",
727 },
b370e46a 728#endif
37c8cdfe
JA
729 { .ival = "mmap",
730 .oval = MEM_MMAP,
731 .help = "Use mmap(2) (file or anon) for IO buffers",
732 },
214e1eca
JA
733#ifdef FIO_HAVE_HUGETLB
734 { .ival = "mmaphuge",
735 .oval = MEM_MMAPHUGE,
736 .help = "Like mmap, but use huge pages",
737 },
738#endif
739 },
740 },
741 {
742 .name = "verify",
743 .type = FIO_OPT_STR,
744 .off1 = td_var_offset(verify),
745 .help = "Verify data written",
746 .def = "0",
747 .posval = {
748 { .ival = "0",
749 .oval = VERIFY_NONE,
750 .help = "Don't do IO verification",
751 },
fcca4b58
JA
752 { .ival = "md5",
753 .oval = VERIFY_MD5,
754 .help = "Use md5 checksums for verification",
755 },
d77a7af3
JA
756 { .ival = "crc64",
757 .oval = VERIFY_CRC64,
758 .help = "Use crc64 checksums for verification",
759 },
214e1eca
JA
760 { .ival = "crc32",
761 .oval = VERIFY_CRC32,
762 .help = "Use crc32 checksums for verification",
763 },
969f7ed3
JA
764 { .ival = "crc16",
765 .oval = VERIFY_CRC16,
766 .help = "Use crc16 checksums for verification",
767 },
1e154bdb
JA
768 { .ival = "crc7",
769 .oval = VERIFY_CRC7,
770 .help = "Use crc7 checksums for verification",
771 },
cd14cc10
JA
772 { .ival = "sha256",
773 .oval = VERIFY_SHA256,
774 .help = "Use sha256 checksums for verification",
775 },
776 { .ival = "sha512",
777 .oval = VERIFY_SHA512,
778 .help = "Use sha512 checksums for verification",
779 },
7437ee87
SL
780 { .ival = "meta",
781 .oval = VERIFY_META,
782 .help = "Use io information",
783 },
36690c9b
JA
784 {
785 .ival = "null",
786 .oval = VERIFY_NULL,
787 .help = "Pretend to verify",
788 },
214e1eca
JA
789 },
790 },
005c565a
JA
791 {
792 .name = "do_verify",
68e1f29a 793 .type = FIO_OPT_BOOL,
005c565a
JA
794 .off1 = td_var_offset(do_verify),
795 .help = "Run verification stage after write",
796 .def = "1",
797 .parent = "verify",
798 },
160b966d
JA
799 {
800 .name = "verifysort",
801 .type = FIO_OPT_BOOL,
802 .off1 = td_var_offset(verifysort),
803 .help = "Sort written verify blocks for read back",
804 .def = "1",
c83f2df1 805 .parent = "verify",
160b966d 806 },
3f9f4e26 807 {
a59e170d 808 .name = "verify_interval",
3f9f4e26 809 .type = FIO_OPT_STR_VAL_INT,
a59e170d 810 .off1 = td_var_offset(verify_interval),
819a9680 811 .minval = 2 * sizeof(struct verify_header),
a59e170d 812 .help = "Store verify buffer header every N bytes",
afdf9352 813 .parent = "verify",
3f9f4e26 814 },
546a9142 815 {
a59e170d 816 .name = "verify_offset",
546a9142 817 .type = FIO_OPT_STR_VAL_INT,
a59e170d 818 .help = "Offset verify header location by N bytes",
546a9142 819 .def = "0",
a59e170d 820 .cb = str_verify_offset_cb,
afdf9352 821 .parent = "verify",
546a9142 822 },
e28218f3
SL
823 {
824 .name = "verify_pattern",
825 .type = FIO_OPT_INT,
826 .cb = str_verify_pattern_cb,
827 .help = "Fill pattern for IO buffers",
828 .parent = "verify",
829 },
a12a3b4d
JA
830 {
831 .name = "verify_fatal",
68e1f29a 832 .type = FIO_OPT_BOOL,
a12a3b4d
JA
833 .off1 = td_var_offset(verify_fatal),
834 .def = "0",
835 .help = "Exit on a single verify failure, don't continue",
836 .parent = "verify",
837 },
214e1eca
JA
838 {
839 .name = "write_iolog",
840 .type = FIO_OPT_STR_STORE,
841 .off1 = td_var_offset(write_iolog_file),
842 .help = "Store IO pattern to file",
843 },
844 {
845 .name = "read_iolog",
846 .type = FIO_OPT_STR_STORE,
847 .off1 = td_var_offset(read_iolog_file),
848 .help = "Playback IO pattern from file",
849 },
850 {
851 .name = "exec_prerun",
852 .type = FIO_OPT_STR_STORE,
853 .off1 = td_var_offset(exec_prerun),
854 .help = "Execute this file prior to running job",
855 },
856 {
857 .name = "exec_postrun",
858 .type = FIO_OPT_STR_STORE,
859 .off1 = td_var_offset(exec_postrun),
860 .help = "Execute this file after running job",
861 },
862#ifdef FIO_HAVE_IOSCHED_SWITCH
863 {
864 .name = "ioscheduler",
865 .type = FIO_OPT_STR_STORE,
866 .off1 = td_var_offset(ioscheduler),
867 .help = "Use this IO scheduler on the backing device",
868 },
869#endif
870 {
871 .name = "zonesize",
872 .type = FIO_OPT_STR_VAL,
873 .off1 = td_var_offset(zone_size),
874 .help = "Give size of an IO zone",
875 .def = "0",
876 },
877 {
878 .name = "zoneskip",
879 .type = FIO_OPT_STR_VAL,
880 .off1 = td_var_offset(zone_skip),
881 .help = "Space between IO zones",
882 .def = "0",
883 },
884 {
885 .name = "lockmem",
886 .type = FIO_OPT_STR_VAL,
887 .cb = str_lockmem_cb,
888 .help = "Lock down this amount of memory",
889 .def = "0",
890 },
214e1eca
JA
891 {
892 .name = "rwmixread",
893 .type = FIO_OPT_INT,
e47f799f 894 .off1 = td_var_offset(rwmix[DDIR_READ]),
214e1eca
JA
895 .maxval = 100,
896 .help = "Percentage of mixed workload that is reads",
897 .def = "50",
898 },
899 {
900 .name = "rwmixwrite",
901 .type = FIO_OPT_INT,
e47f799f 902 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
214e1eca
JA
903 .maxval = 100,
904 .help = "Percentage of mixed workload that is writes",
905 .def = "50",
906 },
afdf9352
JA
907 {
908 .name = "rwmixcycle",
909 .type = FIO_OPT_INT,
910 .off1 = td_var_offset(rwmixcycle),
911 .help = "Cycle period for mixed read/write workloads (msec)",
912 .def = "500",
913 .parent = "rwmixread",
914 },
214e1eca
JA
915 {
916 .name = "nice",
917 .type = FIO_OPT_INT,
918 .off1 = td_var_offset(nice),
919 .help = "Set job CPU nice value",
920 .minval = -19,
921 .maxval = 20,
922 .def = "0",
923 },
924#ifdef FIO_HAVE_IOPRIO
925 {
926 .name = "prio",
927 .type = FIO_OPT_INT,
928 .cb = str_prio_cb,
929 .help = "Set job IO priority value",
930 .minval = 0,
931 .maxval = 7,
932 },
933 {
934 .name = "prioclass",
935 .type = FIO_OPT_INT,
936 .cb = str_prioclass_cb,
937 .help = "Set job IO priority class",
938 .minval = 0,
939 .maxval = 3,
940 },
941#endif
942 {
943 .name = "thinktime",
944 .type = FIO_OPT_INT,
945 .off1 = td_var_offset(thinktime),
946 .help = "Idle time between IO buffers (usec)",
947 .def = "0",
948 },
949 {
950 .name = "thinktime_spin",
951 .type = FIO_OPT_INT,
952 .off1 = td_var_offset(thinktime_spin),
953 .help = "Start think time by spinning this amount (usec)",
954 .def = "0",
afdf9352 955 .parent = "thinktime",
214e1eca
JA
956 },
957 {
958 .name = "thinktime_blocks",
959 .type = FIO_OPT_INT,
960 .off1 = td_var_offset(thinktime_blocks),
961 .help = "IO buffer period between 'thinktime'",
962 .def = "1",
afdf9352 963 .parent = "thinktime",
214e1eca
JA
964 },
965 {
966 .name = "rate",
967 .type = FIO_OPT_INT,
968 .off1 = td_var_offset(rate),
969 .help = "Set bandwidth rate",
970 },
971 {
972 .name = "ratemin",
973 .type = FIO_OPT_INT,
974 .off1 = td_var_offset(ratemin),
4e991c23 975 .help = "Job must meet this rate or it will be shutdown",
afdf9352 976 .parent = "rate",
4e991c23
JA
977 },
978 {
979 .name = "rate_iops",
980 .type = FIO_OPT_INT,
981 .off1 = td_var_offset(rate_iops),
982 .help = "Limit IO used to this number of IO operations/sec",
983 },
984 {
985 .name = "rate_iops_min",
986 .type = FIO_OPT_INT,
987 .off1 = td_var_offset(rate_iops_min),
988 .help = "Job must meet this rate or it will be shutdown",
afdf9352 989 .parent = "rate_iops",
214e1eca
JA
990 },
991 {
992 .name = "ratecycle",
993 .type = FIO_OPT_INT,
994 .off1 = td_var_offset(ratecycle),
995 .help = "Window average for rate limits (msec)",
996 .def = "1000",
afdf9352 997 .parent = "rate",
214e1eca
JA
998 },
999 {
1000 .name = "invalidate",
1001 .type = FIO_OPT_BOOL,
1002 .off1 = td_var_offset(invalidate_cache),
1003 .help = "Invalidate buffer/page cache prior to running job",
1004 .def = "1",
1005 },
1006 {
1007 .name = "sync",
1008 .type = FIO_OPT_BOOL,
1009 .off1 = td_var_offset(sync_io),
1010 .help = "Use O_SYNC for buffered writes",
1011 .def = "0",
67a1000f 1012 .parent = "buffered",
214e1eca
JA
1013 },
1014 {
1015 .name = "bwavgtime",
1016 .type = FIO_OPT_INT,
1017 .off1 = td_var_offset(bw_avg_time),
1018 .help = "Time window over which to calculate bandwidth (msec)",
1019 .def = "500",
1020 },
1021 {
1022 .name = "create_serialize",
1023 .type = FIO_OPT_BOOL,
1024 .off1 = td_var_offset(create_serialize),
1025 .help = "Serialize creating of job files",
1026 .def = "1",
1027 },
1028 {
1029 .name = "create_fsync",
1030 .type = FIO_OPT_BOOL,
1031 .off1 = td_var_offset(create_fsync),
1032 .help = "Fsync file after creation",
1033 .def = "1",
1034 },
1035 {
1036 .name = "cpuload",
1037 .type = FIO_OPT_INT,
1038 .off1 = td_var_offset(cpuload),
1039 .help = "Use this percentage of CPU",
1040 },
1041 {
1042 .name = "cpuchunks",
1043 .type = FIO_OPT_INT,
1044 .off1 = td_var_offset(cpucycle),
1045 .help = "Length of the CPU burn cycles (usecs)",
1046 .def = "50000",
67a1000f 1047 .parent = "cpuload",
214e1eca
JA
1048 },
1049#ifdef FIO_HAVE_CPU_AFFINITY
1050 {
1051 .name = "cpumask",
1052 .type = FIO_OPT_INT,
1053 .cb = str_cpumask_cb,
1054 .help = "CPU affinity mask",
1055 },
d2e268b0
JA
1056 {
1057 .name = "cpus_allowed",
1058 .type = FIO_OPT_STR,
1059 .cb = str_cpus_allowed_cb,
1060 .help = "Set CPUs allowed",
1061 },
214e1eca
JA
1062#endif
1063 {
1064 .name = "end_fsync",
1065 .type = FIO_OPT_BOOL,
1066 .off1 = td_var_offset(end_fsync),
1067 .help = "Include fsync at the end of job",
1068 .def = "0",
1069 },
1070 {
1071 .name = "fsync_on_close",
1072 .type = FIO_OPT_BOOL,
1073 .off1 = td_var_offset(fsync_on_close),
1074 .help = "fsync files on close",
1075 .def = "0",
1076 },
1077 {
1078 .name = "unlink",
1079 .type = FIO_OPT_BOOL,
1080 .off1 = td_var_offset(unlink),
1081 .help = "Unlink created files after job has completed",
1082 .def = "0",
1083 },
1084 {
1085 .name = "exitall",
1086 .type = FIO_OPT_STR_SET,
1087 .cb = str_exitall_cb,
1088 .help = "Terminate all jobs when one exits",
1089 },
1090 {
1091 .name = "stonewall",
1092 .type = FIO_OPT_STR_SET,
1093 .off1 = td_var_offset(stonewall),
1094 .help = "Insert a hard barrier between this job and previous",
1095 },
b3d62a75
JA
1096 {
1097 .name = "new_group",
1098 .type = FIO_OPT_STR_SET,
1099 .off1 = td_var_offset(new_group),
1100 .help = "Mark the start of a new group (for reporting)",
1101 },
214e1eca
JA
1102 {
1103 .name = "thread",
1104 .type = FIO_OPT_STR_SET,
1105 .off1 = td_var_offset(use_thread),
1106 .help = "Use threads instead of forks",
1107 },
1108 {
1109 .name = "write_bw_log",
1110 .type = FIO_OPT_STR_SET,
1111 .off1 = td_var_offset(write_bw_log),
1112 .help = "Write log of bandwidth during run",
1113 },
1114 {
1115 .name = "write_lat_log",
1116 .type = FIO_OPT_STR_SET,
1117 .off1 = td_var_offset(write_lat_log),
1118 .help = "Write log of latency during run",
1119 },
1120 {
1121 .name = "hugepage-size",
1122 .type = FIO_OPT_STR_VAL,
1123 .off1 = td_var_offset(hugepage_size),
1124 .help = "When using hugepages, specify size of each page",
1125 .def = __stringify(FIO_HUGE_PAGE),
1126 },
1127 {
1128 .name = "group_reporting",
1129 .type = FIO_OPT_STR_SET,
1130 .off1 = td_var_offset(group_reporting),
1131 .help = "Do reporting on a per-group basis",
1132 },
e9459e5a
JA
1133 {
1134 .name = "zero_buffers",
1135 .type = FIO_OPT_STR_SET,
1136 .off1 = td_var_offset(zero_buffers),
1137 .help = "Init IO buffers to all zeroes",
1138 },
0a839f30
JA
1139#ifdef FIO_HAVE_DISK_UTIL
1140 {
1141 .name = "disk_util",
1142 .type = FIO_OPT_BOOL,
1143 .off1 = td_var_offset(do_disk_util),
1144 .help = "Log disk utilization stats",
1145 .def = "1",
1146 },
1147#endif
214e1eca
JA
1148 {
1149 .name = NULL,
1150 },
1151};
1152
1153void fio_options_dup_and_init(struct option *long_options)
1154{
1155 struct fio_option *o;
1156 unsigned int i;
1157
1158 options_init(options);
1159
1160 i = 0;
1161 while (long_options[i].name)
1162 i++;
1163
1164 o = &options[0];
1165 while (o->name) {
1166 long_options[i].name = o->name;
1167 long_options[i].val = FIO_GETOPT_JOB;
1168 if (o->type == FIO_OPT_STR_SET)
1169 long_options[i].has_arg = no_argument;
1170 else
1171 long_options[i].has_arg = required_argument;
1172
1173 i++;
1174 o++;
1175 assert(i < FIO_NR_OPTIONS);
1176 }
1177}
1178
1179int fio_option_parse(struct thread_data *td, const char *opt)
1180{
1181 return parse_option(opt, options, td);
1182}
1183
1184int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1185{
1186 return parse_cmd_option(opt, val, options, td);
1187}
1188
1189void fio_fill_default_options(struct thread_data *td)
1190{
1191 fill_default_options(td, options);
1192}
1193
1194int fio_show_option_help(const char *opt)
1195{
1196 return show_cmd_help(options, opt);
1197}
d23bb327
JA
1198
1199static void __options_mem(struct thread_data *td, int alloc)
1200{
1201 struct thread_options *o = &td->o;
1202 struct fio_option *opt;
1203 char **ptr;
1204 int i;
1205
1206 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1207 if (opt->type != FIO_OPT_STR_STORE)
1208 continue;
1209
1210 ptr = (void *) o + opt->off1;
1211 if (*ptr) {
1212 if (alloc)
1213 *ptr = strdup(*ptr);
1214 else {
1215 free(*ptr);
1216 *ptr = NULL;
1217 }
1218 }
1219 }
1220}
1221
1222/*
1223 * dupe FIO_OPT_STR_STORE options
1224 */
1225void options_mem_dupe(struct thread_data *td)
1226{
1227 __options_mem(td, 1);
1228}
1229
22d66213 1230void options_mem_free(struct thread_data fio_unused *td)
d23bb327 1231{
22d66213 1232#if 0
d23bb327 1233 __options_mem(td, 0);
22d66213 1234#endif
d23bb327 1235}