13 #define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
16 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
18 static char *get_opt_postfix(const char *str)
20 char *p = strstr(str, ":");
26 strip_blank_front(&p);
31 static int str_rw_cb(void *data, const char *str)
33 struct thread_data *td = data;
34 char *nr = get_opt_postfix(str);
38 td->o.ddir_nr = atoi(nr);
43 static int str_mem_cb(void *data, const char *mem)
45 struct thread_data *td = data;
47 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
48 td->mmapfile = get_opt_postfix(mem);
49 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
50 log_err("fio: mmaphuge:/path/to/file\n");
58 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
64 #ifdef FIO_HAVE_IOPRIO
65 static int str_prioclass_cb(void *data, unsigned int *val)
67 struct thread_data *td = data;
71 * mask off old class bits, str_prio_cb() may have set a default class
73 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
76 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
80 static int str_prio_cb(void *data, unsigned int *val)
82 struct thread_data *td = data;
87 * If no class is set, assume BE
89 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
90 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
96 static int str_exitall_cb(void)
98 exitall_on_terminate = 1;
102 #ifdef FIO_HAVE_CPU_AFFINITY
103 static int str_cpumask_cb(void *data, unsigned int *val)
105 struct thread_data *td = data;
108 CPU_ZERO(&td->o.cpumask);
110 for (i = 0; i < sizeof(int) * 8; i++)
112 CPU_SET(*val, &td->o.cpumask);
114 td->o.cpumask_set = 1;
118 static int str_cpus_allowed_cb(void *data, const char *input)
120 struct thread_data *td = data;
123 CPU_ZERO(&td->o.cpumask);
125 p = str = strdup(input);
127 strip_blank_front(&str);
128 strip_blank_end(str);
130 while ((cpu = strsep(&str, ",")) != NULL) {
133 CPU_SET(atoi(cpu), &td->o.cpumask);
137 td->o.cpumask_set = 1;
143 static int str_fst_cb(void *data, const char *str)
145 struct thread_data *td = data;
146 char *nr = get_opt_postfix(str);
148 td->file_service_nr = 1;
150 td->file_service_nr = atoi(nr);
155 static int str_filename_cb(void *data, const char *input)
157 struct thread_data *td = data;
158 char *fname, *str, *p;
160 p = str = strdup(input);
162 strip_blank_front(&str);
163 strip_blank_end(str);
165 if (!td->files_index)
168 while ((fname = strsep(&str, ":")) != NULL) {
179 static int str_directory_cb(void *data, const char fio_unused *str)
181 struct thread_data *td = data;
184 if (lstat(td->o.directory, &sb) < 0) {
185 log_err("fio: %s is not a directory\n", td->o.directory);
186 td_verror(td, errno, "lstat");
189 if (!S_ISDIR(sb.st_mode)) {
190 log_err("fio: %s is not a directory\n", td->o.directory);
197 static int str_opendir_cb(void *data, const char fio_unused *str)
199 struct thread_data *td = data;
201 if (!td->files_index)
204 return add_dir_files(td, td->o.opendir);
207 static int str_verify_offset_cb(void *data, unsigned int *off)
209 struct thread_data *td = data;
211 if (*off && *off < sizeof(struct verify_header)) {
212 log_err("fio: verify_offset too small\n");
216 td->o.verify_offset = *off;
220 static int str_verify_cb(void *data, const char *mem)
222 struct thread_data *td = data;
223 unsigned int nr, msb;
226 if (td->o.verify != VERIFY_PATTERN)
229 pat = get_opt_postfix(mem);
231 log_err("fio: missing pattern\n");
235 if (strstr(pat, "0x") || strstr(pat, "0X"))
236 nr = strtol(pat, NULL, 16);
238 nr = strtol(pat, NULL, 16);
242 td->o.verify_pattern_bytes = 1;
244 td->o.verify_pattern_bytes = 2;
246 td->o.verify_pattern_bytes = 3;
248 td->o.verify_pattern_bytes = 4;
250 td->o.verify_pattern = nr;
254 #define __stringify_1(x) #x
255 #define __stringify(x) __stringify_1(x)
258 * Map of job/command line options
260 static struct fio_option options[] = {
262 .name = "description",
263 .type = FIO_OPT_STR_STORE,
264 .off1 = td_var_offset(description),
265 .help = "Text job description",
269 .type = FIO_OPT_STR_STORE,
270 .off1 = td_var_offset(name),
271 .help = "Name of this job",
275 .type = FIO_OPT_STR_STORE,
276 .off1 = td_var_offset(directory),
277 .cb = str_directory_cb,
278 .help = "Directory to store files in",
282 .type = FIO_OPT_STR_STORE,
283 .off1 = td_var_offset(filename),
284 .cb = str_filename_cb,
285 .help = "File(s) to use for the workload",
289 .type = FIO_OPT_STR_STORE,
290 .off1 = td_var_offset(opendir),
291 .cb = str_opendir_cb,
292 .help = "Recursively add files from this directory and down",
296 .alias = "readwrite",
299 .off1 = td_var_offset(td_ddir),
300 .help = "IO direction",
304 .oval = TD_DDIR_READ,
305 .help = "Sequential read",
308 .oval = TD_DDIR_WRITE,
309 .help = "Sequential write",
311 { .ival = "randread",
312 .oval = TD_DDIR_RANDREAD,
313 .help = "Random read",
315 { .ival = "randwrite",
316 .oval = TD_DDIR_RANDWRITE,
317 .help = "Random write",
321 .help = "Sequential read and write mix",
324 .oval = TD_DDIR_RANDRW,
325 .help = "Random read and write mix"
331 .type = FIO_OPT_STR_STORE,
332 .off1 = td_var_offset(ioengine),
333 .help = "IO engine to use",
337 .help = "Use read/write",
340 .help = "Use pread/pwrite",
342 #ifdef FIO_HAVE_LIBAIO
344 .help = "Linux native asynchronous IO",
347 #ifdef FIO_HAVE_POSIXAIO
348 { .ival = "posixaio",
349 .help = "POSIX asynchronous IO",
353 .help = "Memory mapped IO",
355 #ifdef FIO_HAVE_SPLICE
357 .help = "splice/vmsplice based IO",
359 { .ival = "netsplice",
360 .help = "splice/vmsplice to/from the network",
365 .help = "SCSI generic v3 IO",
369 .help = "Testing engine (no data transfer)",
372 .help = "Network IO",
374 #ifdef FIO_HAVE_SYSLET
375 { .ival = "syslet-rw",
376 .help = "syslet enabled async pread/pwrite IO",
380 .help = "CPU cycler burner engine",
382 #ifdef FIO_HAVE_GUASI
384 .help = "GUASI IO engine",
387 { .ival = "external",
388 .help = "Load external engine (append name)",
395 .off1 = td_var_offset(iodepth),
396 .help = "Amount of IO buffers to keep in flight",
400 .name = "iodepth_batch",
402 .off1 = td_var_offset(iodepth_batch),
403 .help = "Number of IO to submit in one go",
407 .name = "iodepth_low",
409 .off1 = td_var_offset(iodepth_low),
410 .help = "Low water mark for queuing depth",
415 .type = FIO_OPT_STR_VAL,
416 .off1 = td_var_offset(size),
418 .help = "Total size of device or files",
422 .type = FIO_OPT_STR_VAL,
423 .off1 = td_var_offset(file_size_low),
424 .off2 = td_var_offset(file_size_high),
426 .help = "Size of individual files",
430 .alias = "fileoffset",
431 .type = FIO_OPT_STR_VAL,
432 .off1 = td_var_offset(start_offset),
433 .help = "Start IO from this offset",
438 .alias = "blocksize",
439 .type = FIO_OPT_STR_VAL_INT,
440 .off1 = td_var_offset(bs[DDIR_READ]),
441 .off2 = td_var_offset(bs[DDIR_WRITE]),
443 .help = "Block size unit",
449 .alias = "blocksize_range",
450 .type = FIO_OPT_RANGE,
451 .off1 = td_var_offset(min_bs[DDIR_READ]),
452 .off2 = td_var_offset(max_bs[DDIR_READ]),
453 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
454 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
456 .help = "Set block size range (in more detail than bs)",
460 .name = "bs_unaligned",
461 .alias = "blocksize_unaligned",
462 .type = FIO_OPT_STR_SET,
463 .off1 = td_var_offset(bs_unaligned),
464 .help = "Don't sector align IO buffer sizes",
468 .name = "randrepeat",
469 .type = FIO_OPT_BOOL,
470 .off1 = td_var_offset(rand_repeatable),
471 .help = "Use repeatable random IO pattern",
476 .name = "norandommap",
477 .type = FIO_OPT_STR_SET,
478 .off1 = td_var_offset(norandommap),
479 .help = "Accept potential duplicate random blocks",
485 .off1 = td_var_offset(nr_files),
486 .help = "Split job workload between this number of files",
492 .off1 = td_var_offset(open_files),
493 .help = "Number of files to keep open at the same time",
496 .name = "file_service_type",
499 .off1 = td_var_offset(file_service_type),
500 .help = "How to select which file to service next",
504 .oval = FIO_FSERVICE_RANDOM,
505 .help = "Choose a file at random",
507 { .ival = "roundrobin",
508 .oval = FIO_FSERVICE_RR,
509 .help = "Round robin select files",
515 .name = "fadvise_hint",
516 .type = FIO_OPT_BOOL,
517 .off1 = td_var_offset(fadvise_hint),
518 .help = "Use fadvise() to advise the kernel on IO pattern",
524 .off1 = td_var_offset(fsync_blocks),
525 .help = "Issue fsync for writes every given number of blocks",
530 .type = FIO_OPT_BOOL,
531 .off1 = td_var_offset(odirect),
532 .help = "Use O_DIRECT IO (negates buffered)",
537 .type = FIO_OPT_BOOL,
538 .off1 = td_var_offset(odirect),
540 .help = "Use buffered IO (negates direct)",
545 .type = FIO_OPT_BOOL,
546 .off1 = td_var_offset(overwrite),
547 .help = "When writing, set whether to overwrite current data",
553 .off1 = td_var_offset(loops),
554 .help = "Number of times to run the job",
560 .off1 = td_var_offset(numjobs),
561 .help = "Duplicate this job this many times",
565 .name = "startdelay",
567 .off1 = td_var_offset(start_delay),
568 .help = "Only start job when this period has passed",
574 .type = FIO_OPT_STR_VAL_TIME,
575 .off1 = td_var_offset(timeout),
576 .help = "Stop workload when this amount of time has passed",
580 .name = "time_based",
581 .type = FIO_OPT_STR_SET,
582 .off1 = td_var_offset(time_based),
583 .help = "Keep running until runtime/timeout is met",
590 .off1 = td_var_offset(mem_type),
591 .help = "Backing type for IO buffers",
596 .help = "Use malloc(3) for IO buffers",
600 .help = "Use shared memory segments for IO buffers",
602 #ifdef FIO_HAVE_HUGETLB
605 .help = "Like shm, but use huge pages",
610 .help = "Use mmap(2) (file or anon) for IO buffers",
612 #ifdef FIO_HAVE_HUGETLB
613 { .ival = "mmaphuge",
614 .oval = MEM_MMAPHUGE,
615 .help = "Like mmap, but use huge pages",
623 .off1 = td_var_offset(verify),
625 .help = "Verify data written",
630 .help = "Don't do IO verification",
634 .help = "Use md5 checksums for verification",
637 .oval = VERIFY_CRC64,
638 .help = "Use crc64 checksums for verification",
641 .oval = VERIFY_CRC32,
642 .help = "Use crc32 checksums for verification",
645 .oval = VERIFY_CRC16,
646 .help = "Use crc16 checksums for verification",
650 .help = "Use crc7 checksums for verification",
653 .oval = VERIFY_SHA256,
654 .help = "Use sha256 checksums for verification",
657 .oval = VERIFY_SHA512,
658 .help = "Use sha512 checksums for verification",
662 .help = "Use io information",
665 .oval = VERIFY_PATTERN,
666 .help = "Verify a specific buffer pattern",
671 .help = "Pretend to verify",
677 .type = FIO_OPT_BOOL,
678 .off1 = td_var_offset(do_verify),
679 .help = "Run verification stage after write",
684 .name = "verifysort",
685 .type = FIO_OPT_BOOL,
686 .off1 = td_var_offset(verifysort),
687 .help = "Sort written verify blocks for read back",
692 .name = "verify_interval",
693 .type = FIO_OPT_STR_VAL_INT,
694 .off1 = td_var_offset(verify_interval),
695 .minval = 2 * sizeof(struct verify_header),
696 .help = "Store verify buffer header every N bytes",
700 .name = "verify_offset",
701 .type = FIO_OPT_STR_VAL_INT,
702 .help = "Offset verify header location by N bytes",
704 .cb = str_verify_offset_cb,
708 .name = "verify_fatal",
709 .type = FIO_OPT_BOOL,
710 .off1 = td_var_offset(verify_fatal),
712 .help = "Exit on a single verify failure, don't continue",
716 .name = "write_iolog",
717 .type = FIO_OPT_STR_STORE,
718 .off1 = td_var_offset(write_iolog_file),
719 .help = "Store IO pattern to file",
722 .name = "read_iolog",
723 .type = FIO_OPT_STR_STORE,
724 .off1 = td_var_offset(read_iolog_file),
725 .help = "Playback IO pattern from file",
728 .name = "exec_prerun",
729 .type = FIO_OPT_STR_STORE,
730 .off1 = td_var_offset(exec_prerun),
731 .help = "Execute this file prior to running job",
734 .name = "exec_postrun",
735 .type = FIO_OPT_STR_STORE,
736 .off1 = td_var_offset(exec_postrun),
737 .help = "Execute this file after running job",
739 #ifdef FIO_HAVE_IOSCHED_SWITCH
741 .name = "ioscheduler",
742 .type = FIO_OPT_STR_STORE,
743 .off1 = td_var_offset(ioscheduler),
744 .help = "Use this IO scheduler on the backing device",
749 .type = FIO_OPT_STR_VAL,
750 .off1 = td_var_offset(zone_size),
751 .help = "Give size of an IO zone",
756 .type = FIO_OPT_STR_VAL,
757 .off1 = td_var_offset(zone_skip),
758 .help = "Space between IO zones",
763 .type = FIO_OPT_STR_VAL,
764 .cb = str_lockmem_cb,
765 .help = "Lock down this amount of memory",
771 .off1 = td_var_offset(rwmix[DDIR_READ]),
773 .help = "Percentage of mixed workload that is reads",
777 .name = "rwmixwrite",
779 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
781 .help = "Percentage of mixed workload that is writes",
785 .name = "rwmixcycle",
787 .off1 = td_var_offset(rwmixcycle),
788 .help = "Cycle period for mixed read/write workloads (msec)",
790 .parent = "rwmixread",
795 .off1 = td_var_offset(nice),
796 .help = "Set job CPU nice value",
801 #ifdef FIO_HAVE_IOPRIO
806 .help = "Set job IO priority value",
813 .cb = str_prioclass_cb,
814 .help = "Set job IO priority class",
822 .off1 = td_var_offset(thinktime),
823 .help = "Idle time between IO buffers (usec)",
827 .name = "thinktime_spin",
829 .off1 = td_var_offset(thinktime_spin),
830 .help = "Start think time by spinning this amount (usec)",
832 .parent = "thinktime",
835 .name = "thinktime_blocks",
837 .off1 = td_var_offset(thinktime_blocks),
838 .help = "IO buffer period between 'thinktime'",
840 .parent = "thinktime",
845 .off1 = td_var_offset(rate),
846 .help = "Set bandwidth rate",
851 .off1 = td_var_offset(ratemin),
852 .help = "Job must meet this rate or it will be shutdown",
858 .off1 = td_var_offset(rate_iops),
859 .help = "Limit IO used to this number of IO operations/sec",
862 .name = "rate_iops_min",
864 .off1 = td_var_offset(rate_iops_min),
865 .help = "Job must meet this rate or it will be shutdown",
866 .parent = "rate_iops",
871 .off1 = td_var_offset(ratecycle),
872 .help = "Window average for rate limits (msec)",
877 .name = "invalidate",
878 .type = FIO_OPT_BOOL,
879 .off1 = td_var_offset(invalidate_cache),
880 .help = "Invalidate buffer/page cache prior to running job",
885 .type = FIO_OPT_BOOL,
886 .off1 = td_var_offset(sync_io),
887 .help = "Use O_SYNC for buffered writes",
889 .parent = "buffered",
894 .off1 = td_var_offset(bw_avg_time),
895 .help = "Time window over which to calculate bandwidth (msec)",
899 .name = "create_serialize",
900 .type = FIO_OPT_BOOL,
901 .off1 = td_var_offset(create_serialize),
902 .help = "Serialize creating of job files",
906 .name = "create_fsync",
907 .type = FIO_OPT_BOOL,
908 .off1 = td_var_offset(create_fsync),
909 .help = "Fsync file after creation",
915 .off1 = td_var_offset(cpuload),
916 .help = "Use this percentage of CPU",
921 .off1 = td_var_offset(cpucycle),
922 .help = "Length of the CPU burn cycles (usecs)",
926 #ifdef FIO_HAVE_CPU_AFFINITY
930 .cb = str_cpumask_cb,
931 .help = "CPU affinity mask",
934 .name = "cpus_allowed",
936 .cb = str_cpus_allowed_cb,
937 .help = "Set CPUs allowed",
942 .type = FIO_OPT_BOOL,
943 .off1 = td_var_offset(end_fsync),
944 .help = "Include fsync at the end of job",
948 .name = "fsync_on_close",
949 .type = FIO_OPT_BOOL,
950 .off1 = td_var_offset(fsync_on_close),
951 .help = "fsync files on close",
956 .type = FIO_OPT_BOOL,
957 .off1 = td_var_offset(unlink),
958 .help = "Unlink created files after job has completed",
963 .type = FIO_OPT_STR_SET,
964 .cb = str_exitall_cb,
965 .help = "Terminate all jobs when one exits",
969 .type = FIO_OPT_STR_SET,
970 .off1 = td_var_offset(stonewall),
971 .help = "Insert a hard barrier between this job and previous",
975 .type = FIO_OPT_STR_SET,
976 .off1 = td_var_offset(new_group),
977 .help = "Mark the start of a new group (for reporting)",
981 .type = FIO_OPT_STR_SET,
982 .off1 = td_var_offset(use_thread),
983 .help = "Use threads instead of forks",
986 .name = "write_bw_log",
987 .type = FIO_OPT_STR_SET,
988 .off1 = td_var_offset(write_bw_log),
989 .help = "Write log of bandwidth during run",
992 .name = "write_lat_log",
993 .type = FIO_OPT_STR_SET,
994 .off1 = td_var_offset(write_lat_log),
995 .help = "Write log of latency during run",
998 .name = "hugepage-size",
999 .type = FIO_OPT_STR_VAL,
1000 .off1 = td_var_offset(hugepage_size),
1001 .help = "When using hugepages, specify size of each page",
1002 .def = __stringify(FIO_HUGE_PAGE),
1005 .name = "group_reporting",
1006 .type = FIO_OPT_STR_SET,
1007 .off1 = td_var_offset(group_reporting),
1008 .help = "Do reporting on a per-group basis",
1011 .name = "zero_buffers",
1012 .type = FIO_OPT_STR_SET,
1013 .off1 = td_var_offset(zero_buffers),
1014 .help = "Init IO buffers to all zeroes",
1016 #ifdef FIO_HAVE_DISK_UTIL
1018 .name = "disk_util",
1019 .type = FIO_OPT_BOOL,
1020 .off1 = td_var_offset(do_disk_util),
1021 .help = "Log disk utilization stats",
1030 void fio_options_dup_and_init(struct option *long_options)
1032 struct fio_option *o;
1035 options_init(options);
1038 while (long_options[i].name)
1043 long_options[i].name = o->name;
1044 long_options[i].val = FIO_GETOPT_JOB;
1045 if (o->type == FIO_OPT_STR_SET)
1046 long_options[i].has_arg = no_argument;
1048 long_options[i].has_arg = required_argument;
1052 assert(i < FIO_NR_OPTIONS);
1056 int fio_option_parse(struct thread_data *td, const char *opt)
1058 return parse_option(opt, options, td);
1061 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1063 return parse_cmd_option(opt, val, options, td);
1066 void fio_fill_default_options(struct thread_data *td)
1068 fill_default_options(td, options);
1071 int fio_show_option_help(const char *opt)
1073 return show_cmd_help(options, opt);
1076 static void __options_mem(struct thread_data *td, int alloc)
1078 struct thread_options *o = &td->o;
1079 struct fio_option *opt;
1083 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1084 if (opt->type != FIO_OPT_STR_STORE)
1087 ptr = (void *) o + opt->off1;
1090 *ptr = strdup(*ptr);
1100 * dupe FIO_OPT_STR_STORE options
1102 void options_mem_dupe(struct thread_data *td)
1104 __options_mem(td, 1);
1107 void options_mem_free(struct thread_data fio_unused *td)
1110 __options_mem(td, 0);