__dprint() fixup
[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#include "options.h"
18
19/*
20 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
21 */
22static char *get_opt_postfix(const char *str)
23{
24 char *p = strstr(str, ":");
25
26 if (!p)
27 return NULL;
28
29 p++;
30 strip_blank_front(&p);
31 strip_blank_end(p);
32 return strdup(p);
33}
34
35static int converthexchartoint(char a)
36{
37 int base;
38
39 switch(a) {
40 case '0'...'9':
41 base = '0';
42 break;
43 case 'A'...'F':
44 base = 'A' - 10;
45 break;
46 case 'a'...'f':
47 base = 'a' - 10;
48 break;
49 default:
50 base = 0;
51 }
52 return (a - base);
53}
54
55static int bs_cmp(const void *p1, const void *p2)
56{
57 const struct bssplit *bsp1 = p1;
58 const struct bssplit *bsp2 = p2;
59
60 return bsp1->perc < bsp2->perc;
61}
62
63static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
64{
65 struct bssplit *bssplit;
66 unsigned int i, perc, perc_missing;
67 unsigned int max_bs, min_bs;
68 long long val;
69 char *fname;
70
71 td->o.bssplit_nr[ddir] = 4;
72 bssplit = malloc(4 * sizeof(struct bssplit));
73
74 i = 0;
75 max_bs = 0;
76 min_bs = -1;
77 while ((fname = strsep(&str, ":")) != NULL) {
78 char *perc_str;
79
80 if (!strlen(fname))
81 break;
82
83 /*
84 * grow struct buffer, if needed
85 */
86 if (i == td->o.bssplit_nr[ddir]) {
87 td->o.bssplit_nr[ddir] <<= 1;
88 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
89 * sizeof(struct bssplit));
90 }
91
92 perc_str = strstr(fname, "/");
93 if (perc_str) {
94 *perc_str = '\0';
95 perc_str++;
96 perc = atoi(perc_str);
97 if (perc > 100)
98 perc = 100;
99 else if (!perc)
100 perc = -1;
101 } else
102 perc = -1;
103
104 if (str_to_decimal(fname, &val, 1, td)) {
105 log_err("fio: bssplit conversion failed\n");
106 free(td->o.bssplit);
107 return 1;
108 }
109
110 if (val > max_bs)
111 max_bs = val;
112 if (val < min_bs)
113 min_bs = val;
114
115 bssplit[i].bs = val;
116 bssplit[i].perc = perc;
117 i++;
118 }
119
120 td->o.bssplit_nr[ddir] = i;
121
122 /*
123 * Now check if the percentages add up, and how much is missing
124 */
125 perc = perc_missing = 0;
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 perc_missing++;
131 else
132 perc += bsp->perc;
133 }
134
135 if (perc > 100) {
136 log_err("fio: bssplit percentages add to more than 100%%\n");
137 free(bssplit);
138 return 1;
139 }
140 /*
141 * If values didn't have a percentage set, divide the remains between
142 * them.
143 */
144 if (perc_missing) {
145 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
146 struct bssplit *bsp = &bssplit[i];
147
148 if (bsp->perc == (unsigned char) -1)
149 bsp->perc = (100 - perc) / perc_missing;
150 }
151 }
152
153 td->o.min_bs[ddir] = min_bs;
154 td->o.max_bs[ddir] = max_bs;
155
156 /*
157 * now sort based on percentages, for ease of lookup
158 */
159 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
160 td->o.bssplit[ddir] = bssplit;
161 return 0;
162
163}
164
165static int str_bssplit_cb(void *data, const char *input)
166{
167 struct thread_data *td = data;
168 char *str, *p, *odir;
169 int ret = 0;
170
171 p = str = strdup(input);
172
173 strip_blank_front(&str);
174 strip_blank_end(str);
175
176 odir = strchr(str, ',');
177 if (odir) {
178 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
179 if (!ret) {
180 *odir = '\0';
181 ret = bssplit_ddir(td, DDIR_READ, str);
182 }
183 } else {
184 char *op;
185
186 op = strdup(str);
187
188 ret = bssplit_ddir(td, DDIR_READ, str);
189 if (!ret)
190 ret = bssplit_ddir(td, DDIR_WRITE, op);
191
192 free(op);
193 }
194
195 free(p);
196 return ret;
197}
198
199static int str_rw_cb(void *data, const char *str)
200{
201 struct thread_data *td = data;
202 char *nr = get_opt_postfix(str);
203
204 td->o.ddir_nr = 1;
205 if (nr) {
206 td->o.ddir_nr = atoi(nr);
207 free(nr);
208 }
209
210 return 0;
211}
212
213static int str_mem_cb(void *data, const char *mem)
214{
215 struct thread_data *td = data;
216
217 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
218 td->mmapfile = get_opt_postfix(mem);
219 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
220 log_err("fio: mmaphuge:/path/to/file\n");
221 return 1;
222 }
223 }
224
225 return 0;
226}
227
228static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
229{
230 mlock_size = *val;
231 return 0;
232}
233
234static int str_rwmix_read_cb(void *data, unsigned int *val)
235{
236 struct thread_data *td = data;
237
238 td->o.rwmix[DDIR_READ] = *val;
239 td->o.rwmix[DDIR_WRITE] = 100 - *val;
240 return 0;
241}
242
243static int str_rwmix_write_cb(void *data, unsigned int *val)
244{
245 struct thread_data *td = data;
246
247 td->o.rwmix[DDIR_WRITE] = *val;
248 td->o.rwmix[DDIR_READ] = 100 - *val;
249 return 0;
250}
251
252#ifdef FIO_HAVE_IOPRIO
253static int str_prioclass_cb(void *data, unsigned int *val)
254{
255 struct thread_data *td = data;
256 unsigned short mask;
257
258 /*
259 * mask off old class bits, str_prio_cb() may have set a default class
260 */
261 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
262 td->ioprio &= mask;
263
264 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
265 td->ioprio_set = 1;
266 return 0;
267}
268
269static int str_prio_cb(void *data, unsigned int *val)
270{
271 struct thread_data *td = data;
272
273 td->ioprio |= *val;
274
275 /*
276 * If no class is set, assume BE
277 */
278 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
279 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
280
281 td->ioprio_set = 1;
282 return 0;
283}
284#endif
285
286static int str_exitall_cb(void)
287{
288 exitall_on_terminate = 1;
289 return 0;
290}
291
292#ifdef FIO_HAVE_CPU_AFFINITY
293static int str_cpumask_cb(void *data, unsigned int *val)
294{
295 struct thread_data *td = data;
296 unsigned int i;
297 long max_cpu;
298 int ret;
299
300 ret = fio_cpuset_init(&td->o.cpumask);
301 if (ret < 0) {
302 log_err("fio: cpuset_init failed\n");
303 td_verror(td, ret, "fio_cpuset_init");
304 return 1;
305 }
306
307 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
308
309 for (i = 0; i < sizeof(int) * 8; i++) {
310 if ((1 << i) & *val) {
311 if (i > max_cpu) {
312 log_err("fio: CPU %d too large (max=%ld)\n", i,
313 max_cpu);
314 return 1;
315 }
316 dprint(FD_PARSE, "set cpu allowed %d\n", i);
317 fio_cpu_set(&td->o.cpumask, i);
318 }
319 }
320
321 td->o.cpumask_set = 1;
322 return 0;
323}
324
325static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
326 const char *input)
327{
328 char *cpu, *str, *p;
329 long max_cpu;
330 int ret = 0;
331
332 ret = fio_cpuset_init(mask);
333 if (ret < 0) {
334 log_err("fio: cpuset_init failed\n");
335 td_verror(td, ret, "fio_cpuset_init");
336 return 1;
337 }
338
339 p = str = strdup(input);
340
341 strip_blank_front(&str);
342 strip_blank_end(str);
343
344 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
345
346 while ((cpu = strsep(&str, ",")) != NULL) {
347 char *str2, *cpu2;
348 int icpu, icpu2;
349
350 if (!strlen(cpu))
351 break;
352
353 str2 = cpu;
354 icpu2 = -1;
355 while ((cpu2 = strsep(&str2, "-")) != NULL) {
356 if (!strlen(cpu2))
357 break;
358
359 icpu2 = atoi(cpu2);
360 }
361
362 icpu = atoi(cpu);
363 if (icpu2 == -1)
364 icpu2 = icpu;
365 while (icpu <= icpu2) {
366 if (icpu >= FIO_MAX_CPUS) {
367 log_err("fio: your OS only supports up to"
368 " %d CPUs\n", (int) FIO_MAX_CPUS);
369 ret = 1;
370 break;
371 }
372 if (icpu > max_cpu) {
373 log_err("fio: CPU %d too large (max=%ld)\n",
374 icpu, max_cpu);
375 ret = 1;
376 break;
377 }
378
379 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
380 fio_cpu_set(mask, icpu);
381 icpu++;
382 }
383 if (ret)
384 break;
385 }
386
387 free(p);
388 if (!ret)
389 td->o.cpumask_set = 1;
390 return ret;
391}
392
393static int str_cpus_allowed_cb(void *data, const char *input)
394{
395 struct thread_data *td = data;
396 int ret;
397
398 ret = set_cpus_allowed(td, &td->o.cpumask, input);
399 if (!ret)
400 td->o.cpumask_set = 1;
401
402 return ret;
403}
404
405static int str_verify_cpus_allowed_cb(void *data, const char *input)
406{
407 struct thread_data *td = data;
408 int ret;
409
410 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
411 if (!ret)
412 td->o.verify_cpumask_set = 1;
413
414 return ret;
415}
416#endif
417
418static int str_fst_cb(void *data, const char *str)
419{
420 struct thread_data *td = data;
421 char *nr = get_opt_postfix(str);
422
423 td->file_service_nr = 1;
424 if (nr) {
425 td->file_service_nr = atoi(nr);
426 free(nr);
427 }
428
429 return 0;
430}
431
432static int str_sfr_cb(void *data, const char *str)
433{
434 struct thread_data *td = data;
435 char *nr = get_opt_postfix(str);
436
437 td->sync_file_range_nr = 1;
438 if (nr) {
439 td->sync_file_range_nr = atoi(nr);
440 free(nr);
441 }
442
443 return 0;
444}
445
446static int check_dir(struct thread_data *td, char *fname)
447{
448 char file[PATH_MAX], *dir;
449 int elen = 0;
450
451 if (td->o.directory) {
452 strcpy(file, td->o.directory);
453 strcat(file, "/");
454 elen = strlen(file);
455 }
456
457 sprintf(file + elen, "%s", fname);
458 dir = dirname(file);
459
460#if 0
461 {
462 struct stat sb;
463 /*
464 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
465 * yet, so we can't do this check right here...
466 */
467 if (lstat(dir, &sb) < 0) {
468 int ret = errno;
469
470 log_err("fio: %s is not a directory\n", dir);
471 td_verror(td, ret, "lstat");
472 return 1;
473 }
474
475 if (!S_ISDIR(sb.st_mode)) {
476 log_err("fio: %s is not a directory\n", dir);
477 return 1;
478 }
479 }
480#endif
481
482 return 0;
483}
484
485/*
486 * Return next file in the string. Files are separated with ':'. If the ':'
487 * is escaped with a '\', then that ':' is part of the filename and does not
488 * indicate a new file.
489 */
490static char *get_next_file_name(char **ptr)
491{
492 char *str = *ptr;
493 char *p, *start;
494
495 if (!str || !strlen(str))
496 return NULL;
497
498 start = str;
499 do {
500 /*
501 * No colon, we are done
502 */
503 p = strchr(str, ':');
504 if (!p) {
505 *ptr = NULL;
506 break;
507 }
508
509 /*
510 * We got a colon, but it's the first character. Skip and
511 * continue
512 */
513 if (p == start) {
514 str = ++start;
515 continue;
516 }
517
518 if (*(p - 1) != '\\') {
519 *p = '\0';
520 *ptr = p + 1;
521 break;
522 }
523
524 memmove(p - 1, p, strlen(p) + 1);
525 str = p;
526 } while (1);
527
528 return start;
529}
530
531static int str_filename_cb(void *data, const char *input)
532{
533 struct thread_data *td = data;
534 char *fname, *str, *p;
535
536 p = str = strdup(input);
537
538 strip_blank_front(&str);
539 strip_blank_end(str);
540
541 if (!td->files_index)
542 td->o.nr_files = 0;
543
544 while ((fname = get_next_file_name(&str)) != NULL) {
545 if (!strlen(fname))
546 break;
547 if (check_dir(td, fname)) {
548 free(p);
549 return 1;
550 }
551 add_file(td, fname);
552 td->o.nr_files++;
553 }
554
555 free(p);
556 return 0;
557}
558
559static int str_directory_cb(void *data, const char fio_unused *str)
560{
561 struct thread_data *td = data;
562 struct stat sb;
563
564 if (lstat(td->o.directory, &sb) < 0) {
565 int ret = errno;
566
567 log_err("fio: %s is not a directory\n", td->o.directory);
568 td_verror(td, ret, "lstat");
569 return 1;
570 }
571 if (!S_ISDIR(sb.st_mode)) {
572 log_err("fio: %s is not a directory\n", td->o.directory);
573 return 1;
574 }
575
576 return 0;
577}
578
579static int str_opendir_cb(void *data, const char fio_unused *str)
580{
581 struct thread_data *td = data;
582
583 if (!td->files_index)
584 td->o.nr_files = 0;
585
586 return add_dir_files(td, td->o.opendir);
587}
588
589static int str_verify_offset_cb(void *data, unsigned int *off)
590{
591 struct thread_data *td = data;
592
593 if (*off && *off < sizeof(struct verify_header)) {
594 log_err("fio: verify_offset too small\n");
595 return 1;
596 }
597
598 td->o.verify_offset = *off;
599 return 0;
600}
601
602static int str_verify_pattern_cb(void *data, const char *input)
603{
604 struct thread_data *td = data;
605 long off;
606 int i = 0, j = 0, len, k, base = 10;
607 char* loc1, * loc2;
608
609 loc1 = strstr(input, "0x");
610 loc2 = strstr(input, "0X");
611 if (loc1 || loc2)
612 base = 16;
613 off = strtol(input, NULL, base);
614 if (off != LONG_MAX || errno != ERANGE) {
615 while (off) {
616 td->o.verify_pattern[i] = off & 0xff;
617 off >>= 8;
618 i++;
619 }
620 } else {
621 len = strlen(input);
622 k = len - 1;
623 if (base == 16) {
624 if (loc1)
625 j = loc1 - input + 2;
626 else
627 j = loc2 - input + 2;
628 } else
629 return 1;
630 if (len - j < MAX_PATTERN_SIZE * 2) {
631 while (k >= j) {
632 off = converthexchartoint(input[k--]);
633 if (k >= j)
634 off += (converthexchartoint(input[k--])
635 * 16);
636 td->o.verify_pattern[i++] = (char) off;
637 }
638 }
639 }
640 td->o.verify_pattern_bytes = i;
641 return 0;
642}
643
644static int str_lockfile_cb(void *data, const char *str)
645{
646 struct thread_data *td = data;
647 char *nr = get_opt_postfix(str);
648
649 td->o.lockfile_batch = 1;
650 if (nr) {
651 td->o.lockfile_batch = atoi(nr);
652 free(nr);
653 }
654
655 return 0;
656}
657
658static int str_write_bw_log_cb(void *data, const char *str)
659{
660 struct thread_data *td = data;
661
662 if (str)
663 td->o.bw_log_file = strdup(str);
664
665 td->o.write_bw_log = 1;
666 return 0;
667}
668
669static int str_write_lat_log_cb(void *data, const char *str)
670{
671 struct thread_data *td = data;
672
673 if (str)
674 td->o.lat_log_file = strdup(str);
675
676 td->o.write_lat_log = 1;
677 return 0;
678}
679
680static int str_gtod_reduce_cb(void *data, int *il)
681{
682 struct thread_data *td = data;
683 int val = *il;
684
685 td->o.disable_clat = !!val;
686 td->o.disable_slat = !!val;
687 td->o.disable_bw = !!val;
688 if (val)
689 td->tv_cache_mask = 63;
690
691 return 0;
692}
693
694static int str_gtod_cpu_cb(void *data, int *il)
695{
696 struct thread_data *td = data;
697 int val = *il;
698
699 td->o.gtod_cpu = val;
700 td->o.gtod_offload = 1;
701 return 0;
702}
703
704static int rw_verify(struct fio_option *o, void *data)
705{
706 struct thread_data *td = data;
707
708 if (read_only && td_write(td)) {
709 log_err("fio: job <%s> has write bit set, but fio is in"
710 " read-only mode\n", td->o.name);
711 return 1;
712 }
713
714 return 0;
715}
716
717static int gtod_cpu_verify(struct fio_option *o, void *data)
718{
719#ifndef FIO_HAVE_CPU_AFFINITY
720 struct thread_data *td = data;
721
722 if (td->o.gtod_cpu) {
723 log_err("fio: platform must support CPU affinity for"
724 "gettimeofday() offloading\n");
725 return 1;
726 }
727#endif
728
729 return 0;
730}
731
732static int kb_base_verify(struct fio_option *o, void *data)
733{
734 struct thread_data *td = data;
735
736 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
737 log_err("fio: kb_base set to nonsensical value: %u\n",
738 td->o.kb_base);
739 return 1;
740 }
741
742 return 0;
743}
744
745#define __stringify_1(x) #x
746#define __stringify(x) __stringify_1(x)
747
748/*
749 * Map of job/command line options
750 */
751static struct fio_option options[FIO_MAX_OPTS] = {
752 {
753 .name = "description",
754 .type = FIO_OPT_STR_STORE,
755 .off1 = td_var_offset(description),
756 .help = "Text job description",
757 },
758 {
759 .name = "name",
760 .type = FIO_OPT_STR_STORE,
761 .off1 = td_var_offset(name),
762 .help = "Name of this job",
763 },
764 {
765 .name = "directory",
766 .type = FIO_OPT_STR_STORE,
767 .off1 = td_var_offset(directory),
768 .cb = str_directory_cb,
769 .help = "Directory to store files in",
770 },
771 {
772 .name = "filename",
773 .type = FIO_OPT_STR_STORE,
774 .off1 = td_var_offset(filename),
775 .cb = str_filename_cb,
776 .prio = -1, /* must come after "directory" */
777 .help = "File(s) to use for the workload",
778 },
779 {
780 .name = "kb_base",
781 .type = FIO_OPT_INT,
782 .off1 = td_var_offset(kb_base),
783 .verify = kb_base_verify,
784 .prio = 1,
785 .def = "1024",
786 .help = "How many bytes per KB for reporting (1000 or 1024)",
787 },
788 {
789 .name = "lockfile",
790 .type = FIO_OPT_STR,
791 .cb = str_lockfile_cb,
792 .off1 = td_var_offset(file_lock_mode),
793 .help = "Lock file when doing IO to it",
794 .parent = "filename",
795 .def = "none",
796 .posval = {
797 { .ival = "none",
798 .oval = FILE_LOCK_NONE,
799 .help = "No file locking",
800 },
801 { .ival = "exclusive",
802 .oval = FILE_LOCK_EXCLUSIVE,
803 .help = "Exclusive file lock",
804 },
805 {
806 .ival = "readwrite",
807 .oval = FILE_LOCK_READWRITE,
808 .help = "Read vs write lock",
809 },
810 },
811 },
812 {
813 .name = "opendir",
814 .type = FIO_OPT_STR_STORE,
815 .off1 = td_var_offset(opendir),
816 .cb = str_opendir_cb,
817 .help = "Recursively add files from this directory and down",
818 },
819 {
820 .name = "rw",
821 .alias = "readwrite",
822 .type = FIO_OPT_STR,
823 .cb = str_rw_cb,
824 .off1 = td_var_offset(td_ddir),
825 .help = "IO direction",
826 .def = "read",
827 .verify = rw_verify,
828 .posval = {
829 { .ival = "read",
830 .oval = TD_DDIR_READ,
831 .help = "Sequential read",
832 },
833 { .ival = "write",
834 .oval = TD_DDIR_WRITE,
835 .help = "Sequential write",
836 },
837 { .ival = "randread",
838 .oval = TD_DDIR_RANDREAD,
839 .help = "Random read",
840 },
841 { .ival = "randwrite",
842 .oval = TD_DDIR_RANDWRITE,
843 .help = "Random write",
844 },
845 { .ival = "rw",
846 .oval = TD_DDIR_RW,
847 .help = "Sequential read and write mix",
848 },
849 { .ival = "randrw",
850 .oval = TD_DDIR_RANDRW,
851 .help = "Random read and write mix"
852 },
853 },
854 },
855 {
856 .name = "ioengine",
857 .type = FIO_OPT_STR_STORE,
858 .off1 = td_var_offset(ioengine),
859 .help = "IO engine to use",
860 .def = "sync",
861 .posval = {
862 { .ival = "sync",
863 .help = "Use read/write",
864 },
865 { .ival = "psync",
866 .help = "Use pread/pwrite",
867 },
868 { .ival = "vsync",
869 .help = "Use readv/writev",
870 },
871#ifdef FIO_HAVE_LIBAIO
872 { .ival = "libaio",
873 .help = "Linux native asynchronous IO",
874 },
875#endif
876#ifdef FIO_HAVE_POSIXAIO
877 { .ival = "posixaio",
878 .help = "POSIX asynchronous IO",
879 },
880#endif
881#ifdef FIO_HAVE_SOLARISAIO
882 { .ival = "solarisaio",
883 .help = "Solaris native asynchronous IO",
884 },
885#endif
886 { .ival = "mmap",
887 .help = "Memory mapped IO",
888 },
889#ifdef FIO_HAVE_SPLICE
890 { .ival = "splice",
891 .help = "splice/vmsplice based IO",
892 },
893 { .ival = "netsplice",
894 .help = "splice/vmsplice to/from the network",
895 },
896#endif
897#ifdef FIO_HAVE_SGIO
898 { .ival = "sg",
899 .help = "SCSI generic v3 IO",
900 },
901#endif
902 { .ival = "null",
903 .help = "Testing engine (no data transfer)",
904 },
905 { .ival = "net",
906 .help = "Network IO",
907 },
908#ifdef FIO_HAVE_SYSLET
909 { .ival = "syslet-rw",
910 .help = "syslet enabled async pread/pwrite IO",
911 },
912#endif
913 { .ival = "cpuio",
914 .help = "CPU cycler burner engine",
915 },
916#ifdef FIO_HAVE_GUASI
917 { .ival = "guasi",
918 .help = "GUASI IO engine",
919 },
920#endif
921 { .ival = "external",
922 .help = "Load external engine (append name)",
923 },
924 },
925 },
926 {
927 .name = "iodepth",
928 .type = FIO_OPT_INT,
929 .off1 = td_var_offset(iodepth),
930 .help = "Amount of IO buffers to keep in flight",
931 .minval = 1,
932 .def = "1",
933 },
934 {
935 .name = "iodepth_batch",
936 .alias = "iodepth_batch_submit",
937 .type = FIO_OPT_INT,
938 .off1 = td_var_offset(iodepth_batch),
939 .help = "Number of IO buffers to submit in one go",
940 .parent = "iodepth",
941 .minval = 1,
942 .def = "1",
943 },
944 {
945 .name = "iodepth_batch_complete",
946 .type = FIO_OPT_INT,
947 .off1 = td_var_offset(iodepth_batch_complete),
948 .help = "Number of IO buffers to retrieve in one go",
949 .parent = "iodepth",
950 .minval = 0,
951 .def = "1",
952 },
953 {
954 .name = "iodepth_low",
955 .type = FIO_OPT_INT,
956 .off1 = td_var_offset(iodepth_low),
957 .help = "Low water mark for queuing depth",
958 .parent = "iodepth",
959 },
960 {
961 .name = "size",
962 .type = FIO_OPT_STR_VAL,
963 .off1 = td_var_offset(size),
964 .minval = 1,
965 .help = "Total size of device or files",
966 },
967 {
968 .name = "fill_device",
969 .type = FIO_OPT_BOOL,
970 .off1 = td_var_offset(fill_device),
971 .help = "Write until an ENOSPC error occurs",
972 .def = "0",
973 },
974 {
975 .name = "filesize",
976 .type = FIO_OPT_STR_VAL,
977 .off1 = td_var_offset(file_size_low),
978 .off2 = td_var_offset(file_size_high),
979 .minval = 1,
980 .help = "Size of individual files",
981 },
982 {
983 .name = "offset",
984 .alias = "fileoffset",
985 .type = FIO_OPT_STR_VAL,
986 .off1 = td_var_offset(start_offset),
987 .help = "Start IO from this offset",
988 .def = "0",
989 },
990 {
991 .name = "bs",
992 .alias = "blocksize",
993 .type = FIO_OPT_INT,
994 .off1 = td_var_offset(bs[DDIR_READ]),
995 .off2 = td_var_offset(bs[DDIR_WRITE]),
996 .minval = 1,
997 .help = "Block size unit",
998 .def = "4k",
999 .parent = "rw",
1000 },
1001 {
1002 .name = "ba",
1003 .alias = "blockalign",
1004 .type = FIO_OPT_INT,
1005 .off1 = td_var_offset(ba[DDIR_READ]),
1006 .off2 = td_var_offset(ba[DDIR_WRITE]),
1007 .minval = 1,
1008 .help = "IO block offset alignment",
1009 .parent = "rw",
1010 },
1011 {
1012 .name = "bsrange",
1013 .alias = "blocksize_range",
1014 .type = FIO_OPT_RANGE,
1015 .off1 = td_var_offset(min_bs[DDIR_READ]),
1016 .off2 = td_var_offset(max_bs[DDIR_READ]),
1017 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1018 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1019 .minval = 1,
1020 .help = "Set block size range (in more detail than bs)",
1021 .parent = "rw",
1022 },
1023 {
1024 .name = "bssplit",
1025 .type = FIO_OPT_STR,
1026 .cb = str_bssplit_cb,
1027 .help = "Set a specific mix of block sizes",
1028 .parent = "rw",
1029 },
1030 {
1031 .name = "bs_unaligned",
1032 .alias = "blocksize_unaligned",
1033 .type = FIO_OPT_STR_SET,
1034 .off1 = td_var_offset(bs_unaligned),
1035 .help = "Don't sector align IO buffer sizes",
1036 .parent = "rw",
1037 },
1038 {
1039 .name = "randrepeat",
1040 .type = FIO_OPT_BOOL,
1041 .off1 = td_var_offset(rand_repeatable),
1042 .help = "Use repeatable random IO pattern",
1043 .def = "1",
1044 .parent = "rw",
1045 },
1046 {
1047 .name = "norandommap",
1048 .type = FIO_OPT_STR_SET,
1049 .off1 = td_var_offset(norandommap),
1050 .help = "Accept potential duplicate random blocks",
1051 .parent = "rw",
1052 },
1053 {
1054 .name = "softrandommap",
1055 .type = FIO_OPT_BOOL,
1056 .off1 = td_var_offset(softrandommap),
1057 .help = "Set norandommap if randommap allocation fails",
1058 .parent = "norandommap",
1059 .def = "0",
1060 },
1061 {
1062 .name = "nrfiles",
1063 .type = FIO_OPT_INT,
1064 .off1 = td_var_offset(nr_files),
1065 .help = "Split job workload between this number of files",
1066 .def = "1",
1067 },
1068 {
1069 .name = "openfiles",
1070 .type = FIO_OPT_INT,
1071 .off1 = td_var_offset(open_files),
1072 .help = "Number of files to keep open at the same time",
1073 },
1074 {
1075 .name = "file_service_type",
1076 .type = FIO_OPT_STR,
1077 .cb = str_fst_cb,
1078 .off1 = td_var_offset(file_service_type),
1079 .help = "How to select which file to service next",
1080 .def = "roundrobin",
1081 .posval = {
1082 { .ival = "random",
1083 .oval = FIO_FSERVICE_RANDOM,
1084 .help = "Choose a file at random",
1085 },
1086 { .ival = "roundrobin",
1087 .oval = FIO_FSERVICE_RR,
1088 .help = "Round robin select files",
1089 },
1090 { .ival = "sequential",
1091 .oval = FIO_FSERVICE_SEQ,
1092 .help = "Finish one file before moving to the next",
1093 },
1094 },
1095 .parent = "nrfiles",
1096 },
1097#ifdef FIO_HAVE_FALLOCATE
1098 {
1099 .name = "fallocate",
1100 .type = FIO_OPT_BOOL,
1101 .off1 = td_var_offset(fallocate),
1102 .help = "Use fallocate() when laying out files",
1103 .def = "1",
1104 },
1105#endif
1106 {
1107 .name = "fadvise_hint",
1108 .type = FIO_OPT_BOOL,
1109 .off1 = td_var_offset(fadvise_hint),
1110 .help = "Use fadvise() to advise the kernel on IO pattern",
1111 .def = "1",
1112 },
1113 {
1114 .name = "fsync",
1115 .type = FIO_OPT_INT,
1116 .off1 = td_var_offset(fsync_blocks),
1117 .help = "Issue fsync for writes every given number of blocks",
1118 .def = "0",
1119 },
1120 {
1121 .name = "fdatasync",
1122 .type = FIO_OPT_INT,
1123 .off1 = td_var_offset(fdatasync_blocks),
1124 .help = "Issue fdatasync for writes every given number of blocks",
1125 .def = "0",
1126 },
1127#ifdef FIO_HAVE_SYNC_FILE_RANGE
1128 {
1129 .name = "sync_file_range",
1130 .posval = {
1131 { .ival = "wait_before",
1132 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1133 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1134 .or = 1,
1135 },
1136 { .ival = "write",
1137 .oval = SYNC_FILE_RANGE_WRITE,
1138 .help = "SYNC_FILE_RANGE_WRITE",
1139 .or = 1,
1140 },
1141 {
1142 .ival = "wait_after",
1143 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1144 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1145 .or = 1,
1146 },
1147 },
1148 .type = FIO_OPT_STR_MULTI,
1149 .cb = str_sfr_cb,
1150 .off1 = td_var_offset(sync_file_range),
1151 .help = "Use sync_file_range()",
1152 },
1153#endif
1154 {
1155 .name = "direct",
1156 .type = FIO_OPT_BOOL,
1157 .off1 = td_var_offset(odirect),
1158 .help = "Use O_DIRECT IO (negates buffered)",
1159 .def = "0",
1160 },
1161 {
1162 .name = "buffered",
1163 .type = FIO_OPT_BOOL,
1164 .off1 = td_var_offset(odirect),
1165 .neg = 1,
1166 .help = "Use buffered IO (negates direct)",
1167 .def = "1",
1168 },
1169 {
1170 .name = "overwrite",
1171 .type = FIO_OPT_BOOL,
1172 .off1 = td_var_offset(overwrite),
1173 .help = "When writing, set whether to overwrite current data",
1174 .def = "0",
1175 },
1176 {
1177 .name = "loops",
1178 .type = FIO_OPT_INT,
1179 .off1 = td_var_offset(loops),
1180 .help = "Number of times to run the job",
1181 .def = "1",
1182 },
1183 {
1184 .name = "numjobs",
1185 .type = FIO_OPT_INT,
1186 .off1 = td_var_offset(numjobs),
1187 .help = "Duplicate this job this many times",
1188 .def = "1",
1189 },
1190 {
1191 .name = "startdelay",
1192 .type = FIO_OPT_INT,
1193 .off1 = td_var_offset(start_delay),
1194 .help = "Only start job when this period has passed",
1195 .def = "0",
1196 },
1197 {
1198 .name = "runtime",
1199 .alias = "timeout",
1200 .type = FIO_OPT_STR_VAL_TIME,
1201 .off1 = td_var_offset(timeout),
1202 .help = "Stop workload when this amount of time has passed",
1203 .def = "0",
1204 },
1205 {
1206 .name = "time_based",
1207 .type = FIO_OPT_STR_SET,
1208 .off1 = td_var_offset(time_based),
1209 .help = "Keep running until runtime/timeout is met",
1210 },
1211 {
1212 .name = "ramp_time",
1213 .type = FIO_OPT_STR_VAL_TIME,
1214 .off1 = td_var_offset(ramp_time),
1215 .help = "Ramp up time before measuring performance",
1216 },
1217 {
1218 .name = "mem",
1219 .alias = "iomem",
1220 .type = FIO_OPT_STR,
1221 .cb = str_mem_cb,
1222 .off1 = td_var_offset(mem_type),
1223 .help = "Backing type for IO buffers",
1224 .def = "malloc",
1225 .posval = {
1226 { .ival = "malloc",
1227 .oval = MEM_MALLOC,
1228 .help = "Use malloc(3) for IO buffers",
1229 },
1230 { .ival = "shm",
1231 .oval = MEM_SHM,
1232 .help = "Use shared memory segments for IO buffers",
1233 },
1234#ifdef FIO_HAVE_HUGETLB
1235 { .ival = "shmhuge",
1236 .oval = MEM_SHMHUGE,
1237 .help = "Like shm, but use huge pages",
1238 },
1239#endif
1240 { .ival = "mmap",
1241 .oval = MEM_MMAP,
1242 .help = "Use mmap(2) (file or anon) for IO buffers",
1243 },
1244#ifdef FIO_HAVE_HUGETLB
1245 { .ival = "mmaphuge",
1246 .oval = MEM_MMAPHUGE,
1247 .help = "Like mmap, but use huge pages",
1248 },
1249#endif
1250 },
1251 },
1252 {
1253 .name = "iomem_align",
1254 .alias = "mem_align",
1255 .type = FIO_OPT_INT,
1256 .off1 = td_var_offset(mem_align),
1257 .minval = 0,
1258 .help = "IO memory buffer offset alignment",
1259 .def = "0",
1260 .parent = "iomem",
1261 },
1262 {
1263 .name = "verify",
1264 .type = FIO_OPT_STR,
1265 .off1 = td_var_offset(verify),
1266 .help = "Verify data written",
1267 .def = "0",
1268 .posval = {
1269 { .ival = "0",
1270 .oval = VERIFY_NONE,
1271 .help = "Don't do IO verification",
1272 },
1273 { .ival = "md5",
1274 .oval = VERIFY_MD5,
1275 .help = "Use md5 checksums for verification",
1276 },
1277 { .ival = "crc64",
1278 .oval = VERIFY_CRC64,
1279 .help = "Use crc64 checksums for verification",
1280 },
1281 { .ival = "crc32",
1282 .oval = VERIFY_CRC32,
1283 .help = "Use crc32 checksums for verification",
1284 },
1285 { .ival = "crc32c-intel",
1286 .oval = VERIFY_CRC32C_INTEL,
1287 .help = "Use hw crc32c checksums for verification",
1288 },
1289 { .ival = "crc32c",
1290 .oval = VERIFY_CRC32C,
1291 .help = "Use crc32c checksums for verification",
1292 },
1293 { .ival = "crc16",
1294 .oval = VERIFY_CRC16,
1295 .help = "Use crc16 checksums for verification",
1296 },
1297 { .ival = "crc7",
1298 .oval = VERIFY_CRC7,
1299 .help = "Use crc7 checksums for verification",
1300 },
1301 { .ival = "sha1",
1302 .oval = VERIFY_SHA1,
1303 .help = "Use sha1 checksums for verification",
1304 },
1305 { .ival = "sha256",
1306 .oval = VERIFY_SHA256,
1307 .help = "Use sha256 checksums for verification",
1308 },
1309 { .ival = "sha512",
1310 .oval = VERIFY_SHA512,
1311 .help = "Use sha512 checksums for verification",
1312 },
1313 { .ival = "meta",
1314 .oval = VERIFY_META,
1315 .help = "Use io information",
1316 },
1317 {
1318 .ival = "null",
1319 .oval = VERIFY_NULL,
1320 .help = "Pretend to verify",
1321 },
1322 },
1323 },
1324 {
1325 .name = "do_verify",
1326 .type = FIO_OPT_BOOL,
1327 .off1 = td_var_offset(do_verify),
1328 .help = "Run verification stage after write",
1329 .def = "1",
1330 .parent = "verify",
1331 },
1332 {
1333 .name = "verifysort",
1334 .type = FIO_OPT_BOOL,
1335 .off1 = td_var_offset(verifysort),
1336 .help = "Sort written verify blocks for read back",
1337 .def = "1",
1338 .parent = "verify",
1339 },
1340 {
1341 .name = "verify_interval",
1342 .type = FIO_OPT_INT,
1343 .off1 = td_var_offset(verify_interval),
1344 .minval = 2 * sizeof(struct verify_header),
1345 .help = "Store verify buffer header every N bytes",
1346 .parent = "verify",
1347 },
1348 {
1349 .name = "verify_offset",
1350 .type = FIO_OPT_INT,
1351 .help = "Offset verify header location by N bytes",
1352 .def = "0",
1353 .cb = str_verify_offset_cb,
1354 .parent = "verify",
1355 },
1356 {
1357 .name = "verify_pattern",
1358 .type = FIO_OPT_STR,
1359 .cb = str_verify_pattern_cb,
1360 .help = "Fill pattern for IO buffers",
1361 .parent = "verify",
1362 },
1363 {
1364 .name = "verify_fatal",
1365 .type = FIO_OPT_BOOL,
1366 .off1 = td_var_offset(verify_fatal),
1367 .def = "0",
1368 .help = "Exit on a single verify failure, don't continue",
1369 .parent = "verify",
1370 },
1371 {
1372 .name = "verify_async",
1373 .type = FIO_OPT_INT,
1374 .off1 = td_var_offset(verify_async),
1375 .def = "0",
1376 .help = "Number of async verifier threads to use",
1377 .parent = "verify",
1378 },
1379#ifdef FIO_HAVE_CPU_AFFINITY
1380 {
1381 .name = "verify_async_cpus",
1382 .type = FIO_OPT_STR,
1383 .cb = str_verify_cpus_allowed_cb,
1384 .help = "Set CPUs allowed for async verify threads",
1385 .parent = "verify_async",
1386 },
1387#endif
1388 {
1389 .name = "write_iolog",
1390 .type = FIO_OPT_STR_STORE,
1391 .off1 = td_var_offset(write_iolog_file),
1392 .help = "Store IO pattern to file",
1393 },
1394 {
1395 .name = "read_iolog",
1396 .type = FIO_OPT_STR_STORE,
1397 .off1 = td_var_offset(read_iolog_file),
1398 .help = "Playback IO pattern from file",
1399 },
1400 {
1401 .name = "exec_prerun",
1402 .type = FIO_OPT_STR_STORE,
1403 .off1 = td_var_offset(exec_prerun),
1404 .help = "Execute this file prior to running job",
1405 },
1406 {
1407 .name = "exec_postrun",
1408 .type = FIO_OPT_STR_STORE,
1409 .off1 = td_var_offset(exec_postrun),
1410 .help = "Execute this file after running job",
1411 },
1412#ifdef FIO_HAVE_IOSCHED_SWITCH
1413 {
1414 .name = "ioscheduler",
1415 .type = FIO_OPT_STR_STORE,
1416 .off1 = td_var_offset(ioscheduler),
1417 .help = "Use this IO scheduler on the backing device",
1418 },
1419#endif
1420 {
1421 .name = "zonesize",
1422 .type = FIO_OPT_STR_VAL,
1423 .off1 = td_var_offset(zone_size),
1424 .help = "Give size of an IO zone",
1425 .def = "0",
1426 },
1427 {
1428 .name = "zoneskip",
1429 .type = FIO_OPT_STR_VAL,
1430 .off1 = td_var_offset(zone_skip),
1431 .help = "Space between IO zones",
1432 .def = "0",
1433 },
1434 {
1435 .name = "lockmem",
1436 .type = FIO_OPT_STR_VAL,
1437 .cb = str_lockmem_cb,
1438 .help = "Lock down this amount of memory",
1439 .def = "0",
1440 },
1441 {
1442 .name = "rwmixread",
1443 .type = FIO_OPT_INT,
1444 .cb = str_rwmix_read_cb,
1445 .maxval = 100,
1446 .help = "Percentage of mixed workload that is reads",
1447 .def = "50",
1448 },
1449 {
1450 .name = "rwmixwrite",
1451 .type = FIO_OPT_INT,
1452 .cb = str_rwmix_write_cb,
1453 .maxval = 100,
1454 .help = "Percentage of mixed workload that is writes",
1455 .def = "50",
1456 },
1457 {
1458 .name = "rwmixcycle",
1459 .type = FIO_OPT_DEPRECATED,
1460 },
1461 {
1462 .name = "nice",
1463 .type = FIO_OPT_INT,
1464 .off1 = td_var_offset(nice),
1465 .help = "Set job CPU nice value",
1466 .minval = -19,
1467 .maxval = 20,
1468 .def = "0",
1469 },
1470#ifdef FIO_HAVE_IOPRIO
1471 {
1472 .name = "prio",
1473 .type = FIO_OPT_INT,
1474 .cb = str_prio_cb,
1475 .help = "Set job IO priority value",
1476 .minval = 0,
1477 .maxval = 7,
1478 },
1479 {
1480 .name = "prioclass",
1481 .type = FIO_OPT_INT,
1482 .cb = str_prioclass_cb,
1483 .help = "Set job IO priority class",
1484 .minval = 0,
1485 .maxval = 3,
1486 },
1487#endif
1488 {
1489 .name = "thinktime",
1490 .type = FIO_OPT_INT,
1491 .off1 = td_var_offset(thinktime),
1492 .help = "Idle time between IO buffers (usec)",
1493 .def = "0",
1494 },
1495 {
1496 .name = "thinktime_spin",
1497 .type = FIO_OPT_INT,
1498 .off1 = td_var_offset(thinktime_spin),
1499 .help = "Start think time by spinning this amount (usec)",
1500 .def = "0",
1501 .parent = "thinktime",
1502 },
1503 {
1504 .name = "thinktime_blocks",
1505 .type = FIO_OPT_INT,
1506 .off1 = td_var_offset(thinktime_blocks),
1507 .help = "IO buffer period between 'thinktime'",
1508 .def = "1",
1509 .parent = "thinktime",
1510 },
1511 {
1512 .name = "rate",
1513 .type = FIO_OPT_INT,
1514 .off1 = td_var_offset(rate[0]),
1515 .off2 = td_var_offset(rate[1]),
1516 .help = "Set bandwidth rate",
1517 },
1518 {
1519 .name = "ratemin",
1520 .type = FIO_OPT_INT,
1521 .off1 = td_var_offset(ratemin[0]),
1522 .off2 = td_var_offset(ratemin[1]),
1523 .help = "Job must meet this rate or it will be shutdown",
1524 .parent = "rate",
1525 },
1526 {
1527 .name = "rate_iops",
1528 .type = FIO_OPT_INT,
1529 .off1 = td_var_offset(rate_iops[0]),
1530 .off2 = td_var_offset(rate_iops[1]),
1531 .help = "Limit IO used to this number of IO operations/sec",
1532 },
1533 {
1534 .name = "rate_iops_min",
1535 .type = FIO_OPT_INT,
1536 .off1 = td_var_offset(rate_iops_min[0]),
1537 .off2 = td_var_offset(rate_iops_min[1]),
1538 .help = "Job must meet this rate or it will be shutdown",
1539 .parent = "rate_iops",
1540 },
1541 {
1542 .name = "ratecycle",
1543 .type = FIO_OPT_INT,
1544 .off1 = td_var_offset(ratecycle),
1545 .help = "Window average for rate limits (msec)",
1546 .def = "1000",
1547 .parent = "rate",
1548 },
1549 {
1550 .name = "invalidate",
1551 .type = FIO_OPT_BOOL,
1552 .off1 = td_var_offset(invalidate_cache),
1553 .help = "Invalidate buffer/page cache prior to running job",
1554 .def = "1",
1555 },
1556 {
1557 .name = "sync",
1558 .type = FIO_OPT_BOOL,
1559 .off1 = td_var_offset(sync_io),
1560 .help = "Use O_SYNC for buffered writes",
1561 .def = "0",
1562 .parent = "buffered",
1563 },
1564 {
1565 .name = "bwavgtime",
1566 .type = FIO_OPT_INT,
1567 .off1 = td_var_offset(bw_avg_time),
1568 .help = "Time window over which to calculate bandwidth"
1569 " (msec)",
1570 .def = "500",
1571 },
1572 {
1573 .name = "create_serialize",
1574 .type = FIO_OPT_BOOL,
1575 .off1 = td_var_offset(create_serialize),
1576 .help = "Serialize creating of job files",
1577 .def = "1",
1578 },
1579 {
1580 .name = "create_fsync",
1581 .type = FIO_OPT_BOOL,
1582 .off1 = td_var_offset(create_fsync),
1583 .help = "Fsync file after creation",
1584 .def = "1",
1585 },
1586 {
1587 .name = "create_on_open",
1588 .type = FIO_OPT_BOOL,
1589 .off1 = td_var_offset(create_on_open),
1590 .help = "Create files when they are opened for IO",
1591 .def = "0",
1592 },
1593 {
1594 .name = "pre_read",
1595 .type = FIO_OPT_BOOL,
1596 .off1 = td_var_offset(pre_read),
1597 .help = "Preread files before starting official testing",
1598 .def = "0",
1599 },
1600 {
1601 .name = "cpuload",
1602 .type = FIO_OPT_INT,
1603 .off1 = td_var_offset(cpuload),
1604 .help = "Use this percentage of CPU",
1605 },
1606 {
1607 .name = "cpuchunks",
1608 .type = FIO_OPT_INT,
1609 .off1 = td_var_offset(cpucycle),
1610 .help = "Length of the CPU burn cycles (usecs)",
1611 .def = "50000",
1612 .parent = "cpuload",
1613 },
1614#ifdef FIO_HAVE_CPU_AFFINITY
1615 {
1616 .name = "cpumask",
1617 .type = FIO_OPT_INT,
1618 .cb = str_cpumask_cb,
1619 .help = "CPU affinity mask",
1620 },
1621 {
1622 .name = "cpus_allowed",
1623 .type = FIO_OPT_STR,
1624 .cb = str_cpus_allowed_cb,
1625 .help = "Set CPUs allowed",
1626 },
1627#endif
1628 {
1629 .name = "end_fsync",
1630 .type = FIO_OPT_BOOL,
1631 .off1 = td_var_offset(end_fsync),
1632 .help = "Include fsync at the end of job",
1633 .def = "0",
1634 },
1635 {
1636 .name = "fsync_on_close",
1637 .type = FIO_OPT_BOOL,
1638 .off1 = td_var_offset(fsync_on_close),
1639 .help = "fsync files on close",
1640 .def = "0",
1641 },
1642 {
1643 .name = "unlink",
1644 .type = FIO_OPT_BOOL,
1645 .off1 = td_var_offset(unlink),
1646 .help = "Unlink created files after job has completed",
1647 .def = "0",
1648 },
1649 {
1650 .name = "exitall",
1651 .type = FIO_OPT_STR_SET,
1652 .cb = str_exitall_cb,
1653 .help = "Terminate all jobs when one exits",
1654 },
1655 {
1656 .name = "stonewall",
1657 .type = FIO_OPT_STR_SET,
1658 .off1 = td_var_offset(stonewall),
1659 .help = "Insert a hard barrier between this job and previous",
1660 },
1661 {
1662 .name = "new_group",
1663 .type = FIO_OPT_STR_SET,
1664 .off1 = td_var_offset(new_group),
1665 .help = "Mark the start of a new group (for reporting)",
1666 },
1667 {
1668 .name = "thread",
1669 .type = FIO_OPT_STR_SET,
1670 .off1 = td_var_offset(use_thread),
1671 .help = "Use threads instead of forks",
1672 },
1673 {
1674 .name = "write_bw_log",
1675 .type = FIO_OPT_STR,
1676 .off1 = td_var_offset(write_bw_log),
1677 .cb = str_write_bw_log_cb,
1678 .help = "Write log of bandwidth during run",
1679 },
1680 {
1681 .name = "write_lat_log",
1682 .type = FIO_OPT_STR,
1683 .off1 = td_var_offset(write_lat_log),
1684 .cb = str_write_lat_log_cb,
1685 .help = "Write log of latency during run",
1686 },
1687 {
1688 .name = "hugepage-size",
1689 .type = FIO_OPT_INT,
1690 .off1 = td_var_offset(hugepage_size),
1691 .help = "When using hugepages, specify size of each page",
1692 .def = __stringify(FIO_HUGE_PAGE),
1693 },
1694 {
1695 .name = "group_reporting",
1696 .type = FIO_OPT_STR_SET,
1697 .off1 = td_var_offset(group_reporting),
1698 .help = "Do reporting on a per-group basis",
1699 },
1700 {
1701 .name = "zero_buffers",
1702 .type = FIO_OPT_STR_SET,
1703 .off1 = td_var_offset(zero_buffers),
1704 .help = "Init IO buffers to all zeroes",
1705 },
1706 {
1707 .name = "refill_buffers",
1708 .type = FIO_OPT_STR_SET,
1709 .off1 = td_var_offset(refill_buffers),
1710 .help = "Refill IO buffers on every IO submit",
1711 },
1712#ifdef FIO_HAVE_DISK_UTIL
1713 {
1714 .name = "disk_util",
1715 .type = FIO_OPT_BOOL,
1716 .off1 = td_var_offset(do_disk_util),
1717 .help = "Log disk utilization statistics",
1718 .def = "1",
1719 },
1720#endif
1721 {
1722 .name = "gtod_reduce",
1723 .type = FIO_OPT_BOOL,
1724 .help = "Greatly reduce number of gettimeofday() calls",
1725 .cb = str_gtod_reduce_cb,
1726 .def = "0",
1727 },
1728 {
1729 .name = "disable_clat",
1730 .type = FIO_OPT_BOOL,
1731 .off1 = td_var_offset(disable_clat),
1732 .help = "Disable completion latency numbers",
1733 .parent = "gtod_reduce",
1734 .def = "0",
1735 },
1736 {
1737 .name = "disable_slat",
1738 .type = FIO_OPT_BOOL,
1739 .off1 = td_var_offset(disable_slat),
1740 .help = "Disable submissionn latency numbers",
1741 .parent = "gtod_reduce",
1742 .def = "0",
1743 },
1744 {
1745 .name = "disable_bw_measurement",
1746 .type = FIO_OPT_BOOL,
1747 .off1 = td_var_offset(disable_bw),
1748 .help = "Disable bandwidth logging",
1749 .parent = "gtod_reduce",
1750 .def = "0",
1751 },
1752 {
1753 .name = "gtod_cpu",
1754 .type = FIO_OPT_INT,
1755 .cb = str_gtod_cpu_cb,
1756 .help = "Setup dedicated gettimeofday() thread on this CPU",
1757 .verify = gtod_cpu_verify,
1758 },
1759 {
1760 .name = "continue_on_error",
1761 .type = FIO_OPT_BOOL,
1762 .off1 = td_var_offset(continue_on_error),
1763 .help = "Continue on non-fatal errors during I/O",
1764 .def = "0",
1765 },
1766 {
1767 .name = "profile",
1768 .type = FIO_OPT_STR_STORE,
1769 .off1 = td_var_offset(profile),
1770 .help = "Select a specific builtin performance test",
1771 },
1772 {
1773 .name = "cgroup",
1774 .type = FIO_OPT_STR_STORE,
1775 .off1 = td_var_offset(cgroup),
1776 .help = "Add job to cgroup of this name",
1777 },
1778 {
1779 .name = "cgroup_weight",
1780 .type = FIO_OPT_INT,
1781 .off1 = td_var_offset(cgroup_weight),
1782 .help = "Use given weight for cgroup",
1783 .minval = 100,
1784 .maxval = 1000,
1785 },
1786 {
1787 .name = "uid",
1788 .type = FIO_OPT_INT,
1789 .off1 = td_var_offset(uid),
1790 .help = "Run job with this user ID",
1791 },
1792 {
1793 .name = "gid",
1794 .type = FIO_OPT_INT,
1795 .off1 = td_var_offset(gid),
1796 .help = "Run job with this group ID",
1797 },
1798 {
1799 .name = NULL,
1800 },
1801};
1802
1803static void add_to_lopt(struct option *lopt, struct fio_option *o)
1804{
1805 lopt->name = (char *) o->name;
1806 lopt->val = FIO_GETOPT_JOB;
1807 if (o->type == FIO_OPT_STR_SET)
1808 lopt->has_arg = no_argument;
1809 else
1810 lopt->has_arg = required_argument;
1811}
1812
1813void fio_options_dup_and_init(struct option *long_options)
1814{
1815 struct fio_option *o;
1816 unsigned int i;
1817
1818 options_init(options);
1819
1820 i = 0;
1821 while (long_options[i].name)
1822 i++;
1823
1824 o = &options[0];
1825 while (o->name) {
1826 add_to_lopt(&long_options[i], o);
1827
1828 i++;
1829 o++;
1830 assert(i < FIO_NR_OPTIONS);
1831 }
1832}
1833
1834struct fio_keyword {
1835 const char *word;
1836 const char *desc;
1837 char *replace;
1838};
1839
1840static struct fio_keyword fio_keywords[] = {
1841 {
1842 .word = "$pagesize",
1843 .desc = "Page size in the system",
1844 },
1845 {
1846 .word = "$mb_memory",
1847 .desc = "Megabytes of memory online",
1848 },
1849 {
1850 .word = "$ncpus",
1851 .desc = "Number of CPUs online in the system",
1852 },
1853 {
1854 .word = NULL,
1855 },
1856};
1857
1858void fio_keywords_init(void)
1859{
1860 unsigned long long mb_memory;
1861 char buf[128];
1862 long l;
1863
1864 sprintf(buf, "%lu", page_size);
1865 fio_keywords[0].replace = strdup(buf);
1866
1867 mb_memory = os_phys_mem() / page_size;
1868 sprintf(buf, "%llu", mb_memory);
1869 fio_keywords[1].replace = strdup(buf);
1870
1871 l = sysconf(_SC_NPROCESSORS_ONLN);
1872 sprintf(buf, "%lu", l);
1873 fio_keywords[2].replace = strdup(buf);
1874}
1875
1876#define BC_APP "bc"
1877
1878static char *bc_calc(char *str)
1879{
1880 char *buf, *tmp, opt[80];
1881 FILE *f;
1882 int ret;
1883
1884 /*
1885 * No math, just return string
1886 */
1887 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1888 !strchr(str, '/'))
1889 return str;
1890
1891 /*
1892 * Split option from value, we only need to calculate the value
1893 */
1894 tmp = strchr(str, '=');
1895 if (!tmp)
1896 return str;
1897
1898 tmp++;
1899 memset(opt, 0, sizeof(opt));
1900 strncpy(opt, str, tmp - str);
1901
1902 buf = malloc(128);
1903
1904 sprintf(buf, "which %s > /dev/null", BC_APP);
1905 if (system(buf)) {
1906 log_err("fio: bc is needed for performing math\n");
1907 free(buf);
1908 return NULL;
1909 }
1910
1911 sprintf(buf, "echo %s | %s", tmp, BC_APP);
1912 f = popen(buf, "r");
1913 if (!f) {
1914 free(buf);
1915 return NULL;
1916 }
1917
1918 ret = fread(buf, 1, 128, f);
1919 if (ret <= 0) {
1920 free(buf);
1921 return NULL;
1922 }
1923
1924 buf[ret - 1] = '\0';
1925 strcat(opt, buf);
1926 strcpy(buf, opt);
1927 pclose(f);
1928 free(str);
1929 return buf;
1930}
1931
1932/*
1933 * Look for reserved variable names and replace them with real values
1934 */
1935static char *fio_keyword_replace(char *opt)
1936{
1937 char *s;
1938 int i;
1939
1940 for (i = 0; fio_keywords[i].word != NULL; i++) {
1941 struct fio_keyword *kw = &fio_keywords[i];
1942
1943 while ((s = strstr(opt, kw->word)) != NULL) {
1944 char *new = malloc(strlen(opt) + 1);
1945 char *o_org = opt;
1946 int olen = s - opt;
1947 int len;
1948
1949 /*
1950 * Copy part of the string before the keyword and
1951 * sprintf() the replacement after it.
1952 */
1953 memcpy(new, opt, olen);
1954 len = sprintf(new + olen, "%s", kw->replace);
1955
1956 /*
1957 * If there's more in the original string, copy that
1958 * in too
1959 */
1960 opt += strlen(kw->word) + olen;
1961 if (strlen(opt))
1962 memcpy(new + olen + len, opt, opt - o_org - 1);
1963
1964 /*
1965 * replace opt and free the old opt
1966 */
1967 opt = new;
1968 //free(o_org);
1969
1970 /*
1971 * Check for potential math and invoke bc, if possible
1972 */
1973 opt = bc_calc(opt);
1974 }
1975 }
1976
1977 return opt;
1978}
1979
1980int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
1981{
1982 int i, ret;
1983
1984 sort_options(opts, options, num_opts);
1985
1986 for (ret = 0, i = 0; i < num_opts; i++) {
1987 opts[i] = fio_keyword_replace(opts[i]);
1988 ret |= parse_option(opts[i], options, td);
1989 }
1990
1991 return ret;
1992}
1993
1994int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1995{
1996 return parse_cmd_option(opt, val, options, td);
1997}
1998
1999void fio_fill_default_options(struct thread_data *td)
2000{
2001 fill_default_options(td, options);
2002}
2003
2004int fio_show_option_help(const char *opt)
2005{
2006 return show_cmd_help(options, opt);
2007}
2008
2009static void __options_mem(struct thread_data *td, int alloc)
2010{
2011 struct thread_options *o = &td->o;
2012 struct fio_option *opt;
2013 char **ptr;
2014 int i;
2015
2016 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2017 if (opt->type != FIO_OPT_STR_STORE)
2018 continue;
2019
2020 ptr = (void *) o + opt->off1;
2021 if (*ptr) {
2022 if (alloc)
2023 *ptr = strdup(*ptr);
2024 else {
2025 free(*ptr);
2026 *ptr = NULL;
2027 }
2028 }
2029 }
2030}
2031
2032/*
2033 * dupe FIO_OPT_STR_STORE options
2034 */
2035void options_mem_dupe(struct thread_data *td)
2036{
2037 __options_mem(td, 1);
2038}
2039
2040void options_mem_free(struct thread_data fio_unused *td)
2041{
2042#if 0
2043 __options_mem(td, 0);
2044#endif
2045}
2046
2047unsigned int fio_get_kb_base(void *data)
2048{
2049 struct thread_data *td = data;
2050 unsigned int kb_base = 0;
2051
2052 if (td)
2053 kb_base = td->o.kb_base;
2054 if (!kb_base)
2055 kb_base = 1024;
2056
2057 return kb_base;
2058}
2059
2060int add_option(struct fio_option *o)
2061{
2062 struct fio_option *__o;
2063 int opt_index = 0;
2064
2065 __o = options;
2066 while (__o->name) {
2067 opt_index++;
2068 __o++;
2069 }
2070
2071 memcpy(&options[opt_index], o, sizeof(*o));
2072 return 0;
2073}
2074
2075void invalidate_profile_options(const char *prof_name)
2076{
2077 struct fio_option *o;
2078
2079 o = options;
2080 while (o->name) {
2081 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2082 o->type = FIO_OPT_INVALID;
2083 o->prof_name = NULL;
2084 }
2085 o++;
2086 }
2087}
2088
2089void add_opt_posval(const char *optname, const char *ival, const char *help)
2090{
2091 struct fio_option *o;
2092 unsigned int i;
2093
2094 o = find_option(options, optname);
2095 if (!o)
2096 return;
2097
2098 for (i = 0; i < PARSE_MAX_VP; i++) {
2099 if (o->posval[i].ival)
2100 continue;
2101
2102 o->posval[i].ival = ival;
2103 o->posval[i].help = help;
2104 break;
2105 }
2106}
2107
2108void del_opt_posval(const char *optname, const char *ival)
2109{
2110 struct fio_option *o;
2111 unsigned int i;
2112
2113 o = find_option(options, optname);
2114 if (!o)
2115 return;
2116
2117 for (i = 0; i < PARSE_MAX_VP; i++) {
2118 if (!o->posval[i].ival)
2119 continue;
2120 if (strcmp(o->posval[i].ival, ival))
2121 continue;
2122
2123 o->posval[i].ival = NULL;
2124 o->posval[i].help = NULL;
2125 }
2126}