Add support for the iomem_align option
[fio.git] / options.c
... / ...
CommitLineData
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#include <libgen.h>
9#include <fcntl.h>
10#include <sys/types.h>
11#include <sys/stat.h>
12
13#include "fio.h"
14#include "verify.h"
15#include "parse.h"
16#include "lib/fls.h"
17
18#define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
19
20/*
21 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
22 */
23static char *get_opt_postfix(const char *str)
24{
25 char *p = strstr(str, ":");
26
27 if (!p)
28 return NULL;
29
30 p++;
31 strip_blank_front(&p);
32 strip_blank_end(p);
33 return strdup(p);
34}
35
36static int bs_cmp(const void *p1, const void *p2)
37{
38 const struct bssplit *bsp1 = p1;
39 const struct bssplit *bsp2 = p2;
40
41 return bsp1->perc < bsp2->perc;
42}
43
44static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
45{
46 struct bssplit *bssplit;
47 unsigned int i, perc, perc_missing;
48 unsigned int max_bs, min_bs;
49 long long val;
50 char *fname;
51
52 td->o.bssplit_nr[ddir] = 4;
53 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[ddir]) {
68 td->o.bssplit_nr[ddir] <<= 1;
69 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
70 * sizeof(struct bssplit));
71 }
72
73 perc_str = strstr(fname, "/");
74 if (perc_str) {
75 *perc_str = '\0';
76 perc_str++;
77 perc = atoi(perc_str);
78 if (perc > 100)
79 perc = 100;
80 else if (!perc)
81 perc = -1;
82 } else
83 perc = -1;
84
85 if (str_to_decimal(fname, &val, 1)) {
86 log_err("fio: bssplit conversion failed\n");
87 free(td->o.bssplit);
88 return 1;
89 }
90
91 if (val > max_bs)
92 max_bs = val;
93 if (val < min_bs)
94 min_bs = val;
95
96 bssplit[i].bs = val;
97 bssplit[i].perc = perc;
98 i++;
99 }
100
101 td->o.bssplit_nr[ddir] = i;
102
103 /*
104 * Now check if the percentages add up, and how much is missing
105 */
106 perc = perc_missing = 0;
107 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
108 struct bssplit *bsp = &bssplit[i];
109
110 if (bsp->perc == (unsigned char) -1)
111 perc_missing++;
112 else
113 perc += bsp->perc;
114 }
115
116 if (perc > 100) {
117 log_err("fio: bssplit percentages add to more than 100%%\n");
118 free(bssplit);
119 return 1;
120 }
121 /*
122 * If values didn't have a percentage set, divide the remains between
123 * them.
124 */
125 if (perc_missing) {
126 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
127 struct bssplit *bsp = &bssplit[i];
128
129 if (bsp->perc == (unsigned char) -1)
130 bsp->perc = (100 - perc) / perc_missing;
131 }
132 }
133
134 td->o.min_bs[ddir] = min_bs;
135 td->o.max_bs[ddir] = max_bs;
136
137 /*
138 * now sort based on percentages, for ease of lookup
139 */
140 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
141 td->o.bssplit[ddir] = bssplit;
142 return 0;
143
144}
145
146static int str_bssplit_cb(void *data, const char *input)
147{
148 struct thread_data *td = data;
149 char *str, *p, *odir;
150 int ret = 0;
151
152 p = str = strdup(input);
153
154 strip_blank_front(&str);
155 strip_blank_end(str);
156
157 odir = strchr(str, ',');
158 if (odir) {
159 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
160 if (!ret) {
161 *odir = '\0';
162 ret = bssplit_ddir(td, DDIR_READ, str);
163 }
164 } else {
165 char *op;
166
167 op = strdup(str);
168
169 ret = bssplit_ddir(td, DDIR_READ, str);
170 if (!ret)
171 ret = bssplit_ddir(td, DDIR_WRITE, op);
172
173 free(op);
174 }
175
176 free(p);
177 return ret;
178}
179
180static int str_rw_cb(void *data, const char *str)
181{
182 struct thread_data *td = data;
183 char *nr = get_opt_postfix(str);
184
185 td->o.ddir_nr = 1;
186 if (nr) {
187 td->o.ddir_nr = atoi(nr);
188 free(nr);
189 }
190
191 return 0;
192}
193
194static int str_mem_cb(void *data, const char *mem)
195{
196 struct thread_data *td = data;
197
198 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
199 td->mmapfile = get_opt_postfix(mem);
200 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
201 log_err("fio: mmaphuge:/path/to/file\n");
202 return 1;
203 }
204 }
205
206 return 0;
207}
208
209static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
210{
211 mlock_size = *val;
212 return 0;
213}
214
215static int str_rwmix_read_cb(void *data, unsigned int *val)
216{
217 struct thread_data *td = data;
218
219 td->o.rwmix[DDIR_READ] = *val;
220 td->o.rwmix[DDIR_WRITE] = 100 - *val;
221 return 0;
222}
223
224static int str_rwmix_write_cb(void *data, unsigned int *val)
225{
226 struct thread_data *td = data;
227
228 td->o.rwmix[DDIR_WRITE] = *val;
229 td->o.rwmix[DDIR_READ] = 100 - *val;
230 return 0;
231}
232
233#ifdef FIO_HAVE_IOPRIO
234static int str_prioclass_cb(void *data, unsigned int *val)
235{
236 struct thread_data *td = data;
237 unsigned short mask;
238
239 /*
240 * mask off old class bits, str_prio_cb() may have set a default class
241 */
242 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
243 td->ioprio &= mask;
244
245 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
246 td->ioprio_set = 1;
247 return 0;
248}
249
250static int str_prio_cb(void *data, unsigned int *val)
251{
252 struct thread_data *td = data;
253
254 td->ioprio |= *val;
255
256 /*
257 * If no class is set, assume BE
258 */
259 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
260 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
261
262 td->ioprio_set = 1;
263 return 0;
264}
265#endif
266
267static int str_exitall_cb(void)
268{
269 exitall_on_terminate = 1;
270 return 0;
271}
272
273#ifdef FIO_HAVE_CPU_AFFINITY
274static int str_cpumask_cb(void *data, unsigned int *val)
275{
276 struct thread_data *td = data;
277 unsigned int i;
278 long max_cpu;
279 int ret;
280
281 ret = fio_cpuset_init(&td->o.cpumask);
282 if (ret < 0) {
283 log_err("fio: cpuset_init failed\n");
284 td_verror(td, ret, "fio_cpuset_init");
285 return 1;
286 }
287
288 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
289
290 for (i = 0; i < sizeof(int) * 8; i++) {
291 if ((1 << i) & *val) {
292 if (i > max_cpu) {
293 log_err("fio: CPU %d too large (max=%ld)\n", i,
294 max_cpu);
295 return 1;
296 }
297 dprint(FD_PARSE, "set cpu allowed %d\n", i);
298 fio_cpu_set(&td->o.cpumask, i);
299 }
300 }
301
302 td->o.cpumask_set = 1;
303 return 0;
304}
305
306static int str_cpus_allowed_cb(void *data, const char *input)
307{
308 struct thread_data *td = data;
309 char *cpu, *str, *p;
310 long max_cpu;
311 int ret = 0;
312
313 ret = fio_cpuset_init(&td->o.cpumask);
314 if (ret < 0) {
315 log_err("fio: cpuset_init failed\n");
316 td_verror(td, ret, "fio_cpuset_init");
317 return 1;
318 }
319
320 p = str = strdup(input);
321
322 strip_blank_front(&str);
323 strip_blank_end(str);
324
325 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
326
327 while ((cpu = strsep(&str, ",")) != NULL) {
328 char *str2, *cpu2;
329 int icpu, icpu2;
330
331 if (!strlen(cpu))
332 break;
333
334 str2 = cpu;
335 icpu2 = -1;
336 while ((cpu2 = strsep(&str2, "-")) != NULL) {
337 if (!strlen(cpu2))
338 break;
339
340 icpu2 = atoi(cpu2);
341 }
342
343 icpu = atoi(cpu);
344 if (icpu2 == -1)
345 icpu2 = icpu;
346 while (icpu <= icpu2) {
347 if (icpu >= FIO_MAX_CPUS) {
348 log_err("fio: your OS only supports up to"
349 " %d CPUs\n", (int) FIO_MAX_CPUS);
350 ret = 1;
351 break;
352 }
353 if (icpu > max_cpu) {
354 log_err("fio: CPU %d too large (max=%ld)\n",
355 icpu, max_cpu);
356 ret = 1;
357 break;
358 }
359
360 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
361 fio_cpu_set(&td->o.cpumask, icpu);
362 icpu++;
363 }
364 if (ret)
365 break;
366 }
367
368 free(p);
369 if (!ret)
370 td->o.cpumask_set = 1;
371 return ret;
372}
373#endif
374
375static int str_fst_cb(void *data, const char *str)
376{
377 struct thread_data *td = data;
378 char *nr = get_opt_postfix(str);
379
380 td->file_service_nr = 1;
381 if (nr) {
382 td->file_service_nr = atoi(nr);
383 free(nr);
384 }
385
386 return 0;
387}
388
389static int check_dir(struct thread_data *td, char *fname)
390{
391 char file[PATH_MAX], *dir;
392 int elen = 0;
393
394 if (td->o.directory) {
395 strcpy(file, td->o.directory);
396 strcat(file, "/");
397 elen = strlen(file);
398 }
399
400 sprintf(file + elen, "%s", fname);
401 dir = dirname(file);
402
403#if 0
404 {
405 struct stat sb;
406 /*
407 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
408 * yet, so we can't do this check right here...
409 */
410 if (lstat(dir, &sb) < 0) {
411 int ret = errno;
412
413 log_err("fio: %s is not a directory\n", dir);
414 td_verror(td, ret, "lstat");
415 return 1;
416 }
417
418 if (!S_ISDIR(sb.st_mode)) {
419 log_err("fio: %s is not a directory\n", dir);
420 return 1;
421 }
422 }
423#endif
424
425 return 0;
426}
427
428static int str_filename_cb(void *data, const char *input)
429{
430 struct thread_data *td = data;
431 char *fname, *str, *p;
432
433 p = str = strdup(input);
434
435 strip_blank_front(&str);
436 strip_blank_end(str);
437
438 if (!td->files_index)
439 td->o.nr_files = 0;
440
441 while ((fname = strsep(&str, ":")) != NULL) {
442 if (!strlen(fname))
443 break;
444 if (check_dir(td, fname)) {
445 free(p);
446 return 1;
447 }
448 add_file(td, fname);
449 td->o.nr_files++;
450 }
451
452 free(p);
453 return 0;
454}
455
456static int str_directory_cb(void *data, const char fio_unused *str)
457{
458 struct thread_data *td = data;
459 struct stat sb;
460
461 if (lstat(td->o.directory, &sb) < 0) {
462 int ret = errno;
463
464 log_err("fio: %s is not a directory\n", td->o.directory);
465 td_verror(td, ret, "lstat");
466 return 1;
467 }
468 if (!S_ISDIR(sb.st_mode)) {
469 log_err("fio: %s is not a directory\n", td->o.directory);
470 return 1;
471 }
472
473 return 0;
474}
475
476static int str_opendir_cb(void *data, const char fio_unused *str)
477{
478 struct thread_data *td = data;
479
480 if (!td->files_index)
481 td->o.nr_files = 0;
482
483 return add_dir_files(td, td->o.opendir);
484}
485
486static int str_verify_offset_cb(void *data, unsigned int *off)
487{
488 struct thread_data *td = data;
489
490 if (*off && *off < sizeof(struct verify_header)) {
491 log_err("fio: verify_offset too small\n");
492 return 1;
493 }
494
495 td->o.verify_offset = *off;
496 return 0;
497}
498
499static int str_verify_pattern_cb(void *data, unsigned int *off)
500{
501 struct thread_data *td = data;
502 unsigned int msb;
503
504 msb = __fls(*off);
505 if (msb <= 8)
506 td->o.verify_pattern_bytes = 1;
507 else if (msb <= 16)
508 td->o.verify_pattern_bytes = 2;
509 else if (msb <= 24)
510 td->o.verify_pattern_bytes = 3;
511 else
512 td->o.verify_pattern_bytes = 4;
513
514 td->o.verify_pattern = *off;
515 return 0;
516}
517
518static int str_lockfile_cb(void *data, const char *str)
519{
520 struct thread_data *td = data;
521 char *nr = get_opt_postfix(str);
522
523 td->o.lockfile_batch = 1;
524 if (nr) {
525 td->o.lockfile_batch = atoi(nr);
526 free(nr);
527 }
528
529 return 0;
530}
531
532static int str_write_bw_log_cb(void *data, const char *str)
533{
534 struct thread_data *td = data;
535
536 if (str)
537 td->o.bw_log_file = strdup(str);
538
539 td->o.write_bw_log = 1;
540 return 0;
541}
542
543static int str_write_lat_log_cb(void *data, const char *str)
544{
545 struct thread_data *td = data;
546
547 if (str)
548 td->o.lat_log_file = strdup(str);
549
550 td->o.write_lat_log = 1;
551 return 0;
552}
553
554static int str_gtod_reduce_cb(void *data, int *il)
555{
556 struct thread_data *td = data;
557 int val = *il;
558
559 td->o.disable_clat = !!val;
560 td->o.disable_slat = !!val;
561 td->o.disable_bw = !!val;
562 if (val)
563 td->tv_cache_mask = 63;
564
565 return 0;
566}
567
568static int str_gtod_cpu_cb(void *data, int *il)
569{
570 struct thread_data *td = data;
571 int val = *il;
572
573 td->o.gtod_cpu = val;
574 td->o.gtod_offload = 1;
575 return 0;
576}
577
578#define __stringify_1(x) #x
579#define __stringify(x) __stringify_1(x)
580
581/*
582 * Map of job/command line options
583 */
584static struct fio_option options[] = {
585 {
586 .name = "description",
587 .type = FIO_OPT_STR_STORE,
588 .off1 = td_var_offset(description),
589 .help = "Text job description",
590 },
591 {
592 .name = "name",
593 .type = FIO_OPT_STR_STORE,
594 .off1 = td_var_offset(name),
595 .help = "Name of this job",
596 },
597 {
598 .name = "directory",
599 .type = FIO_OPT_STR_STORE,
600 .off1 = td_var_offset(directory),
601 .cb = str_directory_cb,
602 .help = "Directory to store files in",
603 },
604 {
605 .name = "filename",
606 .type = FIO_OPT_STR_STORE,
607 .off1 = td_var_offset(filename),
608 .cb = str_filename_cb,
609 .prio = -1, /* must come after "directory" */
610 .help = "File(s) to use for the workload",
611 },
612 {
613 .name = "lockfile",
614 .type = FIO_OPT_STR,
615 .cb = str_lockfile_cb,
616 .off1 = td_var_offset(file_lock_mode),
617 .help = "Lock file when doing IO to it",
618 .parent = "filename",
619 .def = "none",
620 .posval = {
621 { .ival = "none",
622 .oval = FILE_LOCK_NONE,
623 .help = "No file locking",
624 },
625 { .ival = "exclusive",
626 .oval = FILE_LOCK_EXCLUSIVE,
627 .help = "Exclusive file lock",
628 },
629 {
630 .ival = "readwrite",
631 .oval = FILE_LOCK_READWRITE,
632 .help = "Read vs write lock",
633 },
634 },
635 },
636 {
637 .name = "opendir",
638 .type = FIO_OPT_STR_STORE,
639 .off1 = td_var_offset(opendir),
640 .cb = str_opendir_cb,
641 .help = "Recursively add files from this directory and down",
642 },
643 {
644 .name = "rw",
645 .alias = "readwrite",
646 .type = FIO_OPT_STR,
647 .cb = str_rw_cb,
648 .off1 = td_var_offset(td_ddir),
649 .help = "IO direction",
650 .def = "read",
651 .posval = {
652 { .ival = "read",
653 .oval = TD_DDIR_READ,
654 .help = "Sequential read",
655 },
656 { .ival = "write",
657 .oval = TD_DDIR_WRITE,
658 .help = "Sequential write",
659 },
660 { .ival = "randread",
661 .oval = TD_DDIR_RANDREAD,
662 .help = "Random read",
663 },
664 { .ival = "randwrite",
665 .oval = TD_DDIR_RANDWRITE,
666 .help = "Random write",
667 },
668 { .ival = "rw",
669 .oval = TD_DDIR_RW,
670 .help = "Sequential read and write mix",
671 },
672 { .ival = "randrw",
673 .oval = TD_DDIR_RANDRW,
674 .help = "Random read and write mix"
675 },
676 },
677 },
678 {
679 .name = "ioengine",
680 .type = FIO_OPT_STR_STORE,
681 .off1 = td_var_offset(ioengine),
682 .help = "IO engine to use",
683 .def = "sync",
684 .posval = {
685 { .ival = "sync",
686 .help = "Use read/write",
687 },
688 { .ival = "psync",
689 .help = "Use pread/pwrite",
690 },
691 { .ival = "vsync",
692 .help = "Use readv/writev",
693 },
694#ifdef FIO_HAVE_LIBAIO
695 { .ival = "libaio",
696 .help = "Linux native asynchronous IO",
697 },
698#endif
699#ifdef FIO_HAVE_POSIXAIO
700 { .ival = "posixaio",
701 .help = "POSIX asynchronous IO",
702 },
703#endif
704#ifdef FIO_HAVE_SOLARISAIO
705 { .ival = "solarisaio",
706 .help = "Solaris native asynchronous IO",
707 },
708#endif
709 { .ival = "mmap",
710 .help = "Memory mapped IO",
711 },
712#ifdef FIO_HAVE_SPLICE
713 { .ival = "splice",
714 .help = "splice/vmsplice based IO",
715 },
716 { .ival = "netsplice",
717 .help = "splice/vmsplice to/from the network",
718 },
719#endif
720#ifdef FIO_HAVE_SGIO
721 { .ival = "sg",
722 .help = "SCSI generic v3 IO",
723 },
724#endif
725 { .ival = "null",
726 .help = "Testing engine (no data transfer)",
727 },
728 { .ival = "net",
729 .help = "Network IO",
730 },
731#ifdef FIO_HAVE_SYSLET
732 { .ival = "syslet-rw",
733 .help = "syslet enabled async pread/pwrite IO",
734 },
735#endif
736 { .ival = "cpuio",
737 .help = "CPU cycler burner engine",
738 },
739#ifdef FIO_HAVE_GUASI
740 { .ival = "guasi",
741 .help = "GUASI IO engine",
742 },
743#endif
744 { .ival = "external",
745 .help = "Load external engine (append name)",
746 },
747 },
748 },
749 {
750 .name = "iodepth",
751 .type = FIO_OPT_INT,
752 .off1 = td_var_offset(iodepth),
753 .help = "Amount of IO buffers to keep in flight",
754 .minval = 1,
755 .def = "1",
756 },
757 {
758 .name = "iodepth_batch",
759 .alias = "iodepth_batch_submit",
760 .type = FIO_OPT_INT,
761 .off1 = td_var_offset(iodepth_batch),
762 .help = "Number of IO buffers to submit in one go",
763 .parent = "iodepth",
764 .minval = 1,
765 .def = "1",
766 },
767 {
768 .name = "iodepth_batch_complete",
769 .type = FIO_OPT_INT,
770 .off1 = td_var_offset(iodepth_batch_complete),
771 .help = "Number of IO buffers to retrieve in one go",
772 .parent = "iodepth",
773 .minval = 0,
774 .def = "1",
775 },
776 {
777 .name = "iodepth_low",
778 .type = FIO_OPT_INT,
779 .off1 = td_var_offset(iodepth_low),
780 .help = "Low water mark for queuing depth",
781 .parent = "iodepth",
782 },
783 {
784 .name = "size",
785 .type = FIO_OPT_STR_VAL,
786 .off1 = td_var_offset(size),
787 .minval = 1,
788 .help = "Total size of device or files",
789 },
790 {
791 .name = "fill_device",
792 .type = FIO_OPT_BOOL,
793 .off1 = td_var_offset(fill_device),
794 .help = "Write until an ENOSPC error occurs",
795 .def = "0",
796 },
797 {
798 .name = "filesize",
799 .type = FIO_OPT_STR_VAL,
800 .off1 = td_var_offset(file_size_low),
801 .off2 = td_var_offset(file_size_high),
802 .minval = 1,
803 .help = "Size of individual files",
804 },
805 {
806 .name = "offset",
807 .alias = "fileoffset",
808 .type = FIO_OPT_STR_VAL,
809 .off1 = td_var_offset(start_offset),
810 .help = "Start IO from this offset",
811 .def = "0",
812 },
813 {
814 .name = "bs",
815 .alias = "blocksize",
816 .type = FIO_OPT_INT,
817 .off1 = td_var_offset(bs[DDIR_READ]),
818 .off2 = td_var_offset(bs[DDIR_WRITE]),
819 .minval = 1,
820 .help = "Block size unit",
821 .def = "4k",
822 .parent = "rw",
823 },
824 {
825 .name = "ba",
826 .alias = "blockalign",
827 .type = FIO_OPT_INT,
828 .off1 = td_var_offset(ba[DDIR_READ]),
829 .off2 = td_var_offset(ba[DDIR_WRITE]),
830 .minval = 1,
831 .help = "IO block offset alignment",
832 .parent = "rw",
833 },
834 {
835 .name = "bsrange",
836 .alias = "blocksize_range",
837 .type = FIO_OPT_RANGE,
838 .off1 = td_var_offset(min_bs[DDIR_READ]),
839 .off2 = td_var_offset(max_bs[DDIR_READ]),
840 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
841 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
842 .minval = 1,
843 .help = "Set block size range (in more detail than bs)",
844 .parent = "rw",
845 },
846 {
847 .name = "bssplit",
848 .type = FIO_OPT_STR,
849 .cb = str_bssplit_cb,
850 .help = "Set a specific mix of block sizes",
851 .parent = "rw",
852 },
853 {
854 .name = "bs_unaligned",
855 .alias = "blocksize_unaligned",
856 .type = FIO_OPT_STR_SET,
857 .off1 = td_var_offset(bs_unaligned),
858 .help = "Don't sector align IO buffer sizes",
859 .parent = "rw",
860 },
861 {
862 .name = "randrepeat",
863 .type = FIO_OPT_BOOL,
864 .off1 = td_var_offset(rand_repeatable),
865 .help = "Use repeatable random IO pattern",
866 .def = "1",
867 .parent = "rw",
868 },
869 {
870 .name = "norandommap",
871 .type = FIO_OPT_STR_SET,
872 .off1 = td_var_offset(norandommap),
873 .help = "Accept potential duplicate random blocks",
874 .parent = "rw",
875 },
876 {
877 .name = "softrandommap",
878 .type = FIO_OPT_BOOL,
879 .off1 = td_var_offset(softrandommap),
880 .help = "Set norandommap if randommap allocation fails",
881 .parent = "norandommap",
882 .def = "0",
883 },
884 {
885 .name = "nrfiles",
886 .type = FIO_OPT_INT,
887 .off1 = td_var_offset(nr_files),
888 .help = "Split job workload between this number of files",
889 .def = "1",
890 },
891 {
892 .name = "openfiles",
893 .type = FIO_OPT_INT,
894 .off1 = td_var_offset(open_files),
895 .help = "Number of files to keep open at the same time",
896 },
897 {
898 .name = "file_service_type",
899 .type = FIO_OPT_STR,
900 .cb = str_fst_cb,
901 .off1 = td_var_offset(file_service_type),
902 .help = "How to select which file to service next",
903 .def = "roundrobin",
904 .posval = {
905 { .ival = "random",
906 .oval = FIO_FSERVICE_RANDOM,
907 .help = "Choose a file at random",
908 },
909 { .ival = "roundrobin",
910 .oval = FIO_FSERVICE_RR,
911 .help = "Round robin select files",
912 },
913 { .ival = "sequential",
914 .oval = FIO_FSERVICE_SEQ,
915 .help = "Finish one file before moving to the next",
916 },
917 },
918 .parent = "nrfiles",
919 },
920 {
921 .name = "fadvise_hint",
922 .type = FIO_OPT_BOOL,
923 .off1 = td_var_offset(fadvise_hint),
924 .help = "Use fadvise() to advise the kernel on IO pattern",
925 .def = "1",
926 },
927 {
928 .name = "fsync",
929 .type = FIO_OPT_INT,
930 .off1 = td_var_offset(fsync_blocks),
931 .help = "Issue fsync for writes every given number of blocks",
932 .def = "0",
933 },
934 {
935 .name = "fdatasync",
936 .type = FIO_OPT_INT,
937 .off1 = td_var_offset(fdatasync_blocks),
938 .help = "Issue fdatasync for writes every given number of blocks",
939 .def = "0",
940 },
941 {
942 .name = "direct",
943 .type = FIO_OPT_BOOL,
944 .off1 = td_var_offset(odirect),
945 .help = "Use O_DIRECT IO (negates buffered)",
946 .def = "0",
947 },
948 {
949 .name = "buffered",
950 .type = FIO_OPT_BOOL,
951 .off1 = td_var_offset(odirect),
952 .neg = 1,
953 .help = "Use buffered IO (negates direct)",
954 .def = "1",
955 },
956 {
957 .name = "overwrite",
958 .type = FIO_OPT_BOOL,
959 .off1 = td_var_offset(overwrite),
960 .help = "When writing, set whether to overwrite current data",
961 .def = "0",
962 },
963 {
964 .name = "loops",
965 .type = FIO_OPT_INT,
966 .off1 = td_var_offset(loops),
967 .help = "Number of times to run the job",
968 .def = "1",
969 },
970 {
971 .name = "numjobs",
972 .type = FIO_OPT_INT,
973 .off1 = td_var_offset(numjobs),
974 .help = "Duplicate this job this many times",
975 .def = "1",
976 },
977 {
978 .name = "startdelay",
979 .type = FIO_OPT_INT,
980 .off1 = td_var_offset(start_delay),
981 .help = "Only start job when this period has passed",
982 .def = "0",
983 },
984 {
985 .name = "runtime",
986 .alias = "timeout",
987 .type = FIO_OPT_STR_VAL_TIME,
988 .off1 = td_var_offset(timeout),
989 .help = "Stop workload when this amount of time has passed",
990 .def = "0",
991 },
992 {
993 .name = "time_based",
994 .type = FIO_OPT_STR_SET,
995 .off1 = td_var_offset(time_based),
996 .help = "Keep running until runtime/timeout is met",
997 },
998 {
999 .name = "ramp_time",
1000 .type = FIO_OPT_STR_VAL_TIME,
1001 .off1 = td_var_offset(ramp_time),
1002 .help = "Ramp up time before measuring performance",
1003 },
1004 {
1005 .name = "mem",
1006 .alias = "iomem",
1007 .type = FIO_OPT_STR,
1008 .cb = str_mem_cb,
1009 .off1 = td_var_offset(mem_type),
1010 .help = "Backing type for IO buffers",
1011 .def = "malloc",
1012 .posval = {
1013 { .ival = "malloc",
1014 .oval = MEM_MALLOC,
1015 .help = "Use malloc(3) for IO buffers",
1016 },
1017 { .ival = "shm",
1018 .oval = MEM_SHM,
1019 .help = "Use shared memory segments for IO buffers",
1020 },
1021#ifdef FIO_HAVE_HUGETLB
1022 { .ival = "shmhuge",
1023 .oval = MEM_SHMHUGE,
1024 .help = "Like shm, but use huge pages",
1025 },
1026#endif
1027 { .ival = "mmap",
1028 .oval = MEM_MMAP,
1029 .help = "Use mmap(2) (file or anon) for IO buffers",
1030 },
1031#ifdef FIO_HAVE_HUGETLB
1032 { .ival = "mmaphuge",
1033 .oval = MEM_MMAPHUGE,
1034 .help = "Like mmap, but use huge pages",
1035 },
1036#endif
1037 },
1038 },
1039 {
1040 .name = "iomem_align",
1041 .alias = "mem_align",
1042 .type = FIO_OPT_INT,
1043 .off1 = td_var_offset(mem_align),
1044 .minval = 0,
1045 .help = "IO memory buffer offset alignment",
1046 .def = "0",
1047 .parent = "iomem",
1048 },
1049 {
1050 .name = "verify",
1051 .type = FIO_OPT_STR,
1052 .off1 = td_var_offset(verify),
1053 .help = "Verify data written",
1054 .def = "0",
1055 .posval = {
1056 { .ival = "0",
1057 .oval = VERIFY_NONE,
1058 .help = "Don't do IO verification",
1059 },
1060 { .ival = "md5",
1061 .oval = VERIFY_MD5,
1062 .help = "Use md5 checksums for verification",
1063 },
1064 { .ival = "crc64",
1065 .oval = VERIFY_CRC64,
1066 .help = "Use crc64 checksums for verification",
1067 },
1068 { .ival = "crc32",
1069 .oval = VERIFY_CRC32,
1070 .help = "Use crc32 checksums for verification",
1071 },
1072 { .ival = "crc32c-intel",
1073 .oval = VERIFY_CRC32C_INTEL,
1074 .help = "Use hw crc32c checksums for verification",
1075 },
1076 { .ival = "crc32c",
1077 .oval = VERIFY_CRC32C,
1078 .help = "Use crc32c checksums for verification",
1079 },
1080 { .ival = "crc16",
1081 .oval = VERIFY_CRC16,
1082 .help = "Use crc16 checksums for verification",
1083 },
1084 { .ival = "crc7",
1085 .oval = VERIFY_CRC7,
1086 .help = "Use crc7 checksums for verification",
1087 },
1088 { .ival = "sha256",
1089 .oval = VERIFY_SHA256,
1090 .help = "Use sha256 checksums for verification",
1091 },
1092 { .ival = "sha512",
1093 .oval = VERIFY_SHA512,
1094 .help = "Use sha512 checksums for verification",
1095 },
1096 { .ival = "meta",
1097 .oval = VERIFY_META,
1098 .help = "Use io information",
1099 },
1100 {
1101 .ival = "null",
1102 .oval = VERIFY_NULL,
1103 .help = "Pretend to verify",
1104 },
1105 },
1106 },
1107 {
1108 .name = "do_verify",
1109 .type = FIO_OPT_BOOL,
1110 .off1 = td_var_offset(do_verify),
1111 .help = "Run verification stage after write",
1112 .def = "1",
1113 .parent = "verify",
1114 },
1115 {
1116 .name = "verifysort",
1117 .type = FIO_OPT_BOOL,
1118 .off1 = td_var_offset(verifysort),
1119 .help = "Sort written verify blocks for read back",
1120 .def = "1",
1121 .parent = "verify",
1122 },
1123 {
1124 .name = "verify_interval",
1125 .type = FIO_OPT_INT,
1126 .off1 = td_var_offset(verify_interval),
1127 .minval = 2 * sizeof(struct verify_header),
1128 .help = "Store verify buffer header every N bytes",
1129 .parent = "verify",
1130 },
1131 {
1132 .name = "verify_offset",
1133 .type = FIO_OPT_INT,
1134 .help = "Offset verify header location by N bytes",
1135 .def = "0",
1136 .cb = str_verify_offset_cb,
1137 .parent = "verify",
1138 },
1139 {
1140 .name = "verify_pattern",
1141 .type = FIO_OPT_INT,
1142 .cb = str_verify_pattern_cb,
1143 .help = "Fill pattern for IO buffers",
1144 .parent = "verify",
1145 },
1146 {
1147 .name = "verify_fatal",
1148 .type = FIO_OPT_BOOL,
1149 .off1 = td_var_offset(verify_fatal),
1150 .def = "0",
1151 .help = "Exit on a single verify failure, don't continue",
1152 .parent = "verify",
1153 },
1154 {
1155 .name = "write_iolog",
1156 .type = FIO_OPT_STR_STORE,
1157 .off1 = td_var_offset(write_iolog_file),
1158 .help = "Store IO pattern to file",
1159 },
1160 {
1161 .name = "read_iolog",
1162 .type = FIO_OPT_STR_STORE,
1163 .off1 = td_var_offset(read_iolog_file),
1164 .help = "Playback IO pattern from file",
1165 },
1166 {
1167 .name = "exec_prerun",
1168 .type = FIO_OPT_STR_STORE,
1169 .off1 = td_var_offset(exec_prerun),
1170 .help = "Execute this file prior to running job",
1171 },
1172 {
1173 .name = "exec_postrun",
1174 .type = FIO_OPT_STR_STORE,
1175 .off1 = td_var_offset(exec_postrun),
1176 .help = "Execute this file after running job",
1177 },
1178#ifdef FIO_HAVE_IOSCHED_SWITCH
1179 {
1180 .name = "ioscheduler",
1181 .type = FIO_OPT_STR_STORE,
1182 .off1 = td_var_offset(ioscheduler),
1183 .help = "Use this IO scheduler on the backing device",
1184 },
1185#endif
1186 {
1187 .name = "zonesize",
1188 .type = FIO_OPT_STR_VAL,
1189 .off1 = td_var_offset(zone_size),
1190 .help = "Give size of an IO zone",
1191 .def = "0",
1192 },
1193 {
1194 .name = "zoneskip",
1195 .type = FIO_OPT_STR_VAL,
1196 .off1 = td_var_offset(zone_skip),
1197 .help = "Space between IO zones",
1198 .def = "0",
1199 },
1200 {
1201 .name = "lockmem",
1202 .type = FIO_OPT_STR_VAL,
1203 .cb = str_lockmem_cb,
1204 .help = "Lock down this amount of memory",
1205 .def = "0",
1206 },
1207 {
1208 .name = "rwmixread",
1209 .type = FIO_OPT_INT,
1210 .cb = str_rwmix_read_cb,
1211 .maxval = 100,
1212 .help = "Percentage of mixed workload that is reads",
1213 .def = "50",
1214 },
1215 {
1216 .name = "rwmixwrite",
1217 .type = FIO_OPT_INT,
1218 .cb = str_rwmix_write_cb,
1219 .maxval = 100,
1220 .help = "Percentage of mixed workload that is writes",
1221 .def = "50",
1222 },
1223 {
1224 .name = "rwmixcycle",
1225 .type = FIO_OPT_DEPRECATED,
1226 },
1227 {
1228 .name = "nice",
1229 .type = FIO_OPT_INT,
1230 .off1 = td_var_offset(nice),
1231 .help = "Set job CPU nice value",
1232 .minval = -19,
1233 .maxval = 20,
1234 .def = "0",
1235 },
1236#ifdef FIO_HAVE_IOPRIO
1237 {
1238 .name = "prio",
1239 .type = FIO_OPT_INT,
1240 .cb = str_prio_cb,
1241 .help = "Set job IO priority value",
1242 .minval = 0,
1243 .maxval = 7,
1244 },
1245 {
1246 .name = "prioclass",
1247 .type = FIO_OPT_INT,
1248 .cb = str_prioclass_cb,
1249 .help = "Set job IO priority class",
1250 .minval = 0,
1251 .maxval = 3,
1252 },
1253#endif
1254 {
1255 .name = "thinktime",
1256 .type = FIO_OPT_INT,
1257 .off1 = td_var_offset(thinktime),
1258 .help = "Idle time between IO buffers (usec)",
1259 .def = "0",
1260 },
1261 {
1262 .name = "thinktime_spin",
1263 .type = FIO_OPT_INT,
1264 .off1 = td_var_offset(thinktime_spin),
1265 .help = "Start think time by spinning this amount (usec)",
1266 .def = "0",
1267 .parent = "thinktime",
1268 },
1269 {
1270 .name = "thinktime_blocks",
1271 .type = FIO_OPT_INT,
1272 .off1 = td_var_offset(thinktime_blocks),
1273 .help = "IO buffer period between 'thinktime'",
1274 .def = "1",
1275 .parent = "thinktime",
1276 },
1277 {
1278 .name = "rate",
1279 .type = FIO_OPT_INT,
1280 .off1 = td_var_offset(rate[0]),
1281 .off2 = td_var_offset(rate[1]),
1282 .help = "Set bandwidth rate",
1283 },
1284 {
1285 .name = "ratemin",
1286 .type = FIO_OPT_INT,
1287 .off1 = td_var_offset(ratemin[0]),
1288 .off2 = td_var_offset(ratemin[1]),
1289 .help = "Job must meet this rate or it will be shutdown",
1290 .parent = "rate",
1291 },
1292 {
1293 .name = "rate_iops",
1294 .type = FIO_OPT_INT,
1295 .off1 = td_var_offset(rate_iops[0]),
1296 .off2 = td_var_offset(rate_iops[1]),
1297 .help = "Limit IO used to this number of IO operations/sec",
1298 },
1299 {
1300 .name = "rate_iops_min",
1301 .type = FIO_OPT_INT,
1302 .off1 = td_var_offset(rate_iops_min[0]),
1303 .off2 = td_var_offset(rate_iops_min[1]),
1304 .help = "Job must meet this rate or it will be shutdown",
1305 .parent = "rate_iops",
1306 },
1307 {
1308 .name = "ratecycle",
1309 .type = FIO_OPT_INT,
1310 .off1 = td_var_offset(ratecycle),
1311 .help = "Window average for rate limits (msec)",
1312 .def = "1000",
1313 .parent = "rate",
1314 },
1315 {
1316 .name = "invalidate",
1317 .type = FIO_OPT_BOOL,
1318 .off1 = td_var_offset(invalidate_cache),
1319 .help = "Invalidate buffer/page cache prior to running job",
1320 .def = "1",
1321 },
1322 {
1323 .name = "sync",
1324 .type = FIO_OPT_BOOL,
1325 .off1 = td_var_offset(sync_io),
1326 .help = "Use O_SYNC for buffered writes",
1327 .def = "0",
1328 .parent = "buffered",
1329 },
1330 {
1331 .name = "bwavgtime",
1332 .type = FIO_OPT_INT,
1333 .off1 = td_var_offset(bw_avg_time),
1334 .help = "Time window over which to calculate bandwidth"
1335 " (msec)",
1336 .def = "500",
1337 },
1338 {
1339 .name = "create_serialize",
1340 .type = FIO_OPT_BOOL,
1341 .off1 = td_var_offset(create_serialize),
1342 .help = "Serialize creating of job files",
1343 .def = "1",
1344 },
1345 {
1346 .name = "create_fsync",
1347 .type = FIO_OPT_BOOL,
1348 .off1 = td_var_offset(create_fsync),
1349 .help = "Fsync file after creation",
1350 .def = "1",
1351 },
1352 {
1353 .name = "create_on_open",
1354 .type = FIO_OPT_BOOL,
1355 .off1 = td_var_offset(create_on_open),
1356 .help = "Create files when they are opened for IO",
1357 .def = "0",
1358 },
1359 {
1360 .name = "pre_read",
1361 .type = FIO_OPT_BOOL,
1362 .off1 = td_var_offset(pre_read),
1363 .help = "Preread files before starting official testing",
1364 .def = "0",
1365 },
1366 {
1367 .name = "cpuload",
1368 .type = FIO_OPT_INT,
1369 .off1 = td_var_offset(cpuload),
1370 .help = "Use this percentage of CPU",
1371 },
1372 {
1373 .name = "cpuchunks",
1374 .type = FIO_OPT_INT,
1375 .off1 = td_var_offset(cpucycle),
1376 .help = "Length of the CPU burn cycles (usecs)",
1377 .def = "50000",
1378 .parent = "cpuload",
1379 },
1380#ifdef FIO_HAVE_CPU_AFFINITY
1381 {
1382 .name = "cpumask",
1383 .type = FIO_OPT_INT,
1384 .cb = str_cpumask_cb,
1385 .help = "CPU affinity mask",
1386 },
1387 {
1388 .name = "cpus_allowed",
1389 .type = FIO_OPT_STR,
1390 .cb = str_cpus_allowed_cb,
1391 .help = "Set CPUs allowed",
1392 },
1393#endif
1394 {
1395 .name = "end_fsync",
1396 .type = FIO_OPT_BOOL,
1397 .off1 = td_var_offset(end_fsync),
1398 .help = "Include fsync at the end of job",
1399 .def = "0",
1400 },
1401 {
1402 .name = "fsync_on_close",
1403 .type = FIO_OPT_BOOL,
1404 .off1 = td_var_offset(fsync_on_close),
1405 .help = "fsync files on close",
1406 .def = "0",
1407 },
1408 {
1409 .name = "unlink",
1410 .type = FIO_OPT_BOOL,
1411 .off1 = td_var_offset(unlink),
1412 .help = "Unlink created files after job has completed",
1413 .def = "0",
1414 },
1415 {
1416 .name = "exitall",
1417 .type = FIO_OPT_STR_SET,
1418 .cb = str_exitall_cb,
1419 .help = "Terminate all jobs when one exits",
1420 },
1421 {
1422 .name = "stonewall",
1423 .type = FIO_OPT_STR_SET,
1424 .off1 = td_var_offset(stonewall),
1425 .help = "Insert a hard barrier between this job and previous",
1426 },
1427 {
1428 .name = "new_group",
1429 .type = FIO_OPT_STR_SET,
1430 .off1 = td_var_offset(new_group),
1431 .help = "Mark the start of a new group (for reporting)",
1432 },
1433 {
1434 .name = "thread",
1435 .type = FIO_OPT_STR_SET,
1436 .off1 = td_var_offset(use_thread),
1437 .help = "Use threads instead of forks",
1438 },
1439 {
1440 .name = "write_bw_log",
1441 .type = FIO_OPT_STR,
1442 .off1 = td_var_offset(write_bw_log),
1443 .cb = str_write_bw_log_cb,
1444 .help = "Write log of bandwidth during run",
1445 },
1446 {
1447 .name = "write_lat_log",
1448 .type = FIO_OPT_STR,
1449 .off1 = td_var_offset(write_lat_log),
1450 .cb = str_write_lat_log_cb,
1451 .help = "Write log of latency during run",
1452 },
1453 {
1454 .name = "hugepage-size",
1455 .type = FIO_OPT_INT,
1456 .off1 = td_var_offset(hugepage_size),
1457 .help = "When using hugepages, specify size of each page",
1458 .def = __stringify(FIO_HUGE_PAGE),
1459 },
1460 {
1461 .name = "group_reporting",
1462 .type = FIO_OPT_STR_SET,
1463 .off1 = td_var_offset(group_reporting),
1464 .help = "Do reporting on a per-group basis",
1465 },
1466 {
1467 .name = "zero_buffers",
1468 .type = FIO_OPT_STR_SET,
1469 .off1 = td_var_offset(zero_buffers),
1470 .help = "Init IO buffers to all zeroes",
1471 },
1472 {
1473 .name = "refill_buffers",
1474 .type = FIO_OPT_STR_SET,
1475 .off1 = td_var_offset(refill_buffers),
1476 .help = "Refill IO buffers on every IO submit",
1477 },
1478#ifdef FIO_HAVE_DISK_UTIL
1479 {
1480 .name = "disk_util",
1481 .type = FIO_OPT_BOOL,
1482 .off1 = td_var_offset(do_disk_util),
1483 .help = "Log disk utilization statistics",
1484 .def = "1",
1485 },
1486#endif
1487 {
1488 .name = "gtod_reduce",
1489 .type = FIO_OPT_BOOL,
1490 .help = "Greatly reduce number of gettimeofday() calls",
1491 .cb = str_gtod_reduce_cb,
1492 .def = "0",
1493 },
1494 {
1495 .name = "disable_clat",
1496 .type = FIO_OPT_BOOL,
1497 .off1 = td_var_offset(disable_clat),
1498 .help = "Disable completion latency numbers",
1499 .parent = "gtod_reduce",
1500 .def = "0",
1501 },
1502 {
1503 .name = "disable_slat",
1504 .type = FIO_OPT_BOOL,
1505 .off1 = td_var_offset(disable_slat),
1506 .help = "Disable submissionn latency numbers",
1507 .parent = "gtod_reduce",
1508 .def = "0",
1509 },
1510 {
1511 .name = "disable_bw_measurement",
1512 .type = FIO_OPT_BOOL,
1513 .off1 = td_var_offset(disable_bw),
1514 .help = "Disable bandwidth logging",
1515 .parent = "gtod_reduce",
1516 .def = "0",
1517 },
1518 {
1519 .name = "gtod_cpu",
1520 .type = FIO_OPT_INT,
1521 .cb = str_gtod_cpu_cb,
1522 .help = "Setup dedicated gettimeofday() thread on this CPU",
1523 },
1524 {
1525 .name = "continue_on_error",
1526 .type = FIO_OPT_BOOL,
1527 .off1 = td_var_offset(continue_on_error),
1528 .help = "Continue on non-fatal errors during I/O",
1529 .def = "0",
1530 },
1531 {
1532 .name = NULL,
1533 },
1534};
1535
1536void fio_options_dup_and_init(struct option *long_options)
1537{
1538 struct fio_option *o;
1539 unsigned int i;
1540
1541 options_init(options);
1542
1543 i = 0;
1544 while (long_options[i].name)
1545 i++;
1546
1547 o = &options[0];
1548 while (o->name) {
1549 long_options[i].name = (char *) o->name;
1550 long_options[i].val = FIO_GETOPT_JOB;
1551 if (o->type == FIO_OPT_STR_SET)
1552 long_options[i].has_arg = no_argument;
1553 else
1554 long_options[i].has_arg = required_argument;
1555
1556 i++;
1557 o++;
1558 assert(i < FIO_NR_OPTIONS);
1559 }
1560}
1561
1562int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
1563{
1564 int i, ret;
1565
1566 sort_options(opts, options, num_opts);
1567
1568 for (ret = 0, i = 0; i < num_opts; i++)
1569 ret |= parse_option(opts[i], options, td);
1570
1571 return ret;
1572}
1573
1574int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1575{
1576 return parse_cmd_option(opt, val, options, td);
1577}
1578
1579void fio_fill_default_options(struct thread_data *td)
1580{
1581 fill_default_options(td, options);
1582}
1583
1584int fio_show_option_help(const char *opt)
1585{
1586 return show_cmd_help(options, opt);
1587}
1588
1589static void __options_mem(struct thread_data *td, int alloc)
1590{
1591 struct thread_options *o = &td->o;
1592 struct fio_option *opt;
1593 char **ptr;
1594 int i;
1595
1596 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1597 if (opt->type != FIO_OPT_STR_STORE)
1598 continue;
1599
1600 ptr = (void *) o + opt->off1;
1601 if (*ptr) {
1602 if (alloc)
1603 *ptr = strdup(*ptr);
1604 else {
1605 free(*ptr);
1606 *ptr = NULL;
1607 }
1608 }
1609 }
1610}
1611
1612/*
1613 * dupe FIO_OPT_STR_STORE options
1614 */
1615void options_mem_dupe(struct thread_data *td)
1616{
1617 __options_mem(td, 1);
1618}
1619
1620void options_mem_free(struct thread_data fio_unused *td)
1621{
1622#if 0
1623 __options_mem(td, 0);
1624#endif
1625}