12 #define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
15 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
17 static char *get_opt_postfix(const char *str)
19 char *p = strstr(str, ":");
25 strip_blank_front(&p);
30 static int str_rw_cb(void *data, const char *str)
32 struct thread_data *td = data;
33 char *nr = get_opt_postfix(str);
37 td->o.ddir_nr = atoi(nr);
42 static int str_mem_cb(void *data, const char *mem)
44 struct thread_data *td = data;
46 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
47 td->mmapfile = get_opt_postfix(mem);
48 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
49 log_err("fio: mmaphuge:/path/to/file\n");
57 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
63 #ifdef FIO_HAVE_IOPRIO
64 static int str_prioclass_cb(void *data, unsigned int *val)
66 struct thread_data *td = data;
70 * mask off old class bits, str_prio_cb() may have set a default class
72 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
75 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
79 static int str_prio_cb(void *data, unsigned int *val)
81 struct thread_data *td = data;
86 * If no class is set, assume BE
88 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
89 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
95 static int str_exitall_cb(void)
97 exitall_on_terminate = 1;
101 #ifdef FIO_HAVE_CPU_AFFINITY
102 static int str_cpumask_cb(void *data, unsigned int *val)
104 struct thread_data *td = data;
107 CPU_ZERO(&td->o.cpumask);
109 for (i = 0; i < sizeof(int) * 8; i++)
111 CPU_SET(*val, &td->o.cpumask);
113 td->o.cpumask_set = 1;
117 static int str_cpus_allowed_cb(void *data, const char *input)
119 struct thread_data *td = data;
122 CPU_ZERO(&td->o.cpumask);
124 p = str = strdup(input);
126 strip_blank_front(&str);
127 strip_blank_end(str);
129 while ((cpu = strsep(&str, ",")) != NULL) {
132 CPU_SET(atoi(cpu), &td->o.cpumask);
136 td->o.cpumask_set = 1;
142 static int str_fst_cb(void *data, const char *str)
144 struct thread_data *td = data;
145 char *nr = get_opt_postfix(str);
147 td->file_service_nr = 1;
149 td->file_service_nr = atoi(nr);
154 static int str_filename_cb(void *data, const char *input)
156 struct thread_data *td = data;
157 char *fname, *str, *p;
159 p = str = strdup(input);
161 strip_blank_front(&str);
162 strip_blank_end(str);
164 if (!td->files_index)
167 while ((fname = strsep(&str, ":")) != NULL) {
178 static int str_directory_cb(void *data, const char fio_unused *str)
180 struct thread_data *td = data;
183 if (lstat(td->o.directory, &sb) < 0) {
184 log_err("fio: %s is not a directory\n", td->o.directory);
185 td_verror(td, errno, "lstat");
188 if (!S_ISDIR(sb.st_mode)) {
189 log_err("fio: %s is not a directory\n", td->o.directory);
196 static int str_opendir_cb(void *data, const char fio_unused *str)
198 struct thread_data *td = data;
200 if (!td->files_index)
203 return add_dir_files(td, td->o.opendir);
207 #define __stringify_1(x) #x
208 #define __stringify(x) __stringify_1(x)
211 * Map of job/command line options
213 static struct fio_option options[] = {
215 .name = "description",
216 .type = FIO_OPT_STR_STORE,
217 .off1 = td_var_offset(description),
218 .help = "Text job description",
222 .type = FIO_OPT_STR_STORE,
223 .off1 = td_var_offset(name),
224 .help = "Name of this job",
228 .type = FIO_OPT_STR_STORE,
229 .off1 = td_var_offset(directory),
230 .cb = str_directory_cb,
231 .help = "Directory to store files in",
235 .type = FIO_OPT_STR_STORE,
236 .off1 = td_var_offset(filename),
237 .cb = str_filename_cb,
238 .help = "File(s) to use for the workload",
242 .type = FIO_OPT_STR_STORE,
243 .off1 = td_var_offset(opendir),
244 .cb = str_opendir_cb,
245 .help = "Recursively add files from this directory and down",
249 .alias = "readwrite",
252 .off1 = td_var_offset(td_ddir),
253 .help = "IO direction",
257 .oval = TD_DDIR_READ,
258 .help = "Sequential read",
261 .oval = TD_DDIR_WRITE,
262 .help = "Sequential write",
264 { .ival = "randread",
265 .oval = TD_DDIR_RANDREAD,
266 .help = "Random read",
268 { .ival = "randwrite",
269 .oval = TD_DDIR_RANDWRITE,
270 .help = "Random write",
274 .help = "Sequential read and write mix",
277 .oval = TD_DDIR_RANDRW,
278 .help = "Random read and write mix"
283 .name = "fadvise_hint",
284 .type = FIO_OPT_BOOL,
285 .off1 = td_var_offset(fadvise_hint),
286 .help = "Use fadvise() to advise the kernel on IO pattern",
291 .type = FIO_OPT_STR_STORE,
292 .off1 = td_var_offset(ioengine),
293 .help = "IO engine to use",
297 .help = "Use read/write",
299 #ifdef FIO_HAVE_LIBAIO
301 .help = "Linux native asynchronous IO",
304 #ifdef FIO_HAVE_POSIXAIO
305 { .ival = "posixaio",
306 .help = "POSIX asynchronous IO",
310 .help = "Memory mapped IO",
312 #ifdef FIO_HAVE_SPLICE
314 .help = "splice/vmsplice based IO",
316 { .ival = "netsplice",
317 .help = "splice/vmsplice to/from the network",
322 .help = "SCSI generic v3 IO",
326 .help = "Testing engine (no data transfer)",
329 .help = "Network IO",
331 #ifdef FIO_HAVE_SYSLET
332 { .ival = "syslet-rw",
333 .help = "syslet enabled async pread/pwrite IO",
337 .help = "CPU cycler burner engine",
339 #ifdef FIO_HAVE_GUASI
341 .help = "GUASI IO engine",
344 { .ival = "external",
345 .help = "Load external engine (append name)",
352 .off1 = td_var_offset(iodepth),
353 .help = "Amount of IO buffers to keep in flight",
357 .name = "iodepth_batch",
359 .off1 = td_var_offset(iodepth_batch),
360 .help = "Number of IO to submit in one go",
363 .name = "iodepth_low",
365 .off1 = td_var_offset(iodepth_low),
366 .help = "Low water mark for queuing depth",
370 .type = FIO_OPT_STR_VAL,
371 .off1 = td_var_offset(size),
373 .help = "Total size of device or files",
377 .type = FIO_OPT_STR_VAL,
378 .off1 = td_var_offset(file_size_low),
379 .off2 = td_var_offset(file_size_high),
381 .help = "Size of individual files",
385 .alias = "blocksize",
386 .type = FIO_OPT_STR_VAL_INT,
387 .off1 = td_var_offset(bs[DDIR_READ]),
388 .off2 = td_var_offset(bs[DDIR_WRITE]),
390 .help = "Block size unit",
395 .alias = "blocksize_range",
396 .type = FIO_OPT_RANGE,
397 .off1 = td_var_offset(min_bs[DDIR_READ]),
398 .off2 = td_var_offset(max_bs[DDIR_READ]),
399 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
400 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
402 .help = "Set block size range (in more detail than bs)",
405 .name = "bs_unaligned",
406 .alias = "blocksize_unaligned",
407 .type = FIO_OPT_STR_SET,
408 .off1 = td_var_offset(bs_unaligned),
409 .help = "Don't sector align IO buffer sizes",
413 .type = FIO_OPT_STR_VAL,
414 .off1 = td_var_offset(start_offset),
415 .help = "Start IO from this offset",
419 .name = "randrepeat",
420 .type = FIO_OPT_BOOL,
421 .off1 = td_var_offset(rand_repeatable),
422 .help = "Use repeatable random IO pattern",
426 .name = "norandommap",
427 .type = FIO_OPT_STR_SET,
428 .off1 = td_var_offset(norandommap),
429 .help = "Accept potential duplicate random blocks",
434 .off1 = td_var_offset(nr_files),
435 .help = "Split job workload between this number of files",
441 .off1 = td_var_offset(open_files),
442 .help = "Number of files to keep open at the same time",
445 .name = "file_service_type",
448 .off1 = td_var_offset(file_service_type),
449 .help = "How to select which file to service next",
453 .oval = FIO_FSERVICE_RANDOM,
454 .help = "Choose a file at random",
456 { .ival = "roundrobin",
457 .oval = FIO_FSERVICE_RR,
458 .help = "Round robin select files",
465 .off1 = td_var_offset(fsync_blocks),
466 .help = "Issue fsync for writes every given number of blocks",
471 .type = FIO_OPT_BOOL,
472 .off1 = td_var_offset(odirect),
473 .help = "Use O_DIRECT IO (negates buffered)",
478 .type = FIO_OPT_BOOL,
479 .off1 = td_var_offset(odirect),
481 .help = "Use buffered IO (negates direct)",
486 .type = FIO_OPT_BOOL,
487 .off1 = td_var_offset(overwrite),
488 .help = "When writing, set whether to overwrite current data",
494 .off1 = td_var_offset(loops),
495 .help = "Number of times to run the job",
501 .off1 = td_var_offset(numjobs),
502 .help = "Duplicate this job this many times",
506 .name = "startdelay",
508 .off1 = td_var_offset(start_delay),
509 .help = "Only start job when this period has passed",
515 .type = FIO_OPT_STR_VAL_TIME,
516 .off1 = td_var_offset(timeout),
517 .help = "Stop workload when this amount of time has passed",
521 .name = "time_based",
522 .type = FIO_OPT_STR_SET,
523 .off1 = td_var_offset(time_based),
524 .help = "Keep running until runtime/timeout is met",
531 .off1 = td_var_offset(mem_type),
532 .help = "Backing type for IO buffers",
537 .help = "Use malloc(3) for IO buffers",
541 .help = "Use shared memory segments for IO buffers",
543 #ifdef FIO_HAVE_HUGETLB
546 .help = "Like shm, but use huge pages",
551 .help = "Use mmap(2) (file or anon) for IO buffers",
553 #ifdef FIO_HAVE_HUGETLB
554 { .ival = "mmaphuge",
555 .oval = MEM_MMAPHUGE,
556 .help = "Like mmap, but use huge pages",
564 .off1 = td_var_offset(verify),
565 .help = "Verify data written",
570 .help = "Don't do IO verification",
573 .oval = VERIFY_CRC32,
574 .help = "Use crc32 checksums for verification",
577 .oval = VERIFY_CRC16,
578 .help = "Use crc16 checksums for verification",
582 .help = "Use crc7 checksums for verification",
586 .help = "Use md5 checksums for verification",
591 .help = "Pretend to verify",
596 .name = "verifysort",
597 .type = FIO_OPT_BOOL,
598 .off1 = td_var_offset(verifysort),
599 .help = "Sort written verify blocks for read back",
603 .name = "write_iolog",
604 .type = FIO_OPT_STR_STORE,
605 .off1 = td_var_offset(write_iolog_file),
606 .help = "Store IO pattern to file",
609 .name = "read_iolog",
610 .type = FIO_OPT_STR_STORE,
611 .off1 = td_var_offset(read_iolog_file),
612 .help = "Playback IO pattern from file",
615 .name = "exec_prerun",
616 .type = FIO_OPT_STR_STORE,
617 .off1 = td_var_offset(exec_prerun),
618 .help = "Execute this file prior to running job",
621 .name = "exec_postrun",
622 .type = FIO_OPT_STR_STORE,
623 .off1 = td_var_offset(exec_postrun),
624 .help = "Execute this file after running job",
626 #ifdef FIO_HAVE_IOSCHED_SWITCH
628 .name = "ioscheduler",
629 .type = FIO_OPT_STR_STORE,
630 .off1 = td_var_offset(ioscheduler),
631 .help = "Use this IO scheduler on the backing device",
636 .type = FIO_OPT_STR_VAL,
637 .off1 = td_var_offset(zone_size),
638 .help = "Give size of an IO zone",
643 .type = FIO_OPT_STR_VAL,
644 .off1 = td_var_offset(zone_skip),
645 .help = "Space between IO zones",
650 .type = FIO_OPT_STR_VAL,
651 .cb = str_lockmem_cb,
652 .help = "Lock down this amount of memory",
656 .name = "rwmixcycle",
658 .off1 = td_var_offset(rwmixcycle),
659 .help = "Cycle period for mixed read/write workloads (msec)",
665 .off1 = td_var_offset(rwmix[DDIR_READ]),
667 .help = "Percentage of mixed workload that is reads",
671 .name = "rwmixwrite",
673 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
675 .help = "Percentage of mixed workload that is writes",
681 .off1 = td_var_offset(nice),
682 .help = "Set job CPU nice value",
687 #ifdef FIO_HAVE_IOPRIO
692 .help = "Set job IO priority value",
699 .cb = str_prioclass_cb,
700 .help = "Set job IO priority class",
708 .off1 = td_var_offset(thinktime),
709 .help = "Idle time between IO buffers (usec)",
713 .name = "thinktime_spin",
715 .off1 = td_var_offset(thinktime_spin),
716 .help = "Start think time by spinning this amount (usec)",
720 .name = "thinktime_blocks",
722 .off1 = td_var_offset(thinktime_blocks),
723 .help = "IO buffer period between 'thinktime'",
729 .off1 = td_var_offset(rate),
730 .help = "Set bandwidth rate",
735 .off1 = td_var_offset(ratemin),
736 .help = "Job must meet this rate or it will be shutdown",
741 .off1 = td_var_offset(rate_iops),
742 .help = "Limit IO used to this number of IO operations/sec",
745 .name = "rate_iops_min",
747 .off1 = td_var_offset(rate_iops_min),
748 .help = "Job must meet this rate or it will be shutdown",
753 .off1 = td_var_offset(ratecycle),
754 .help = "Window average for rate limits (msec)",
758 .name = "invalidate",
759 .type = FIO_OPT_BOOL,
760 .off1 = td_var_offset(invalidate_cache),
761 .help = "Invalidate buffer/page cache prior to running job",
766 .type = FIO_OPT_BOOL,
767 .off1 = td_var_offset(sync_io),
768 .help = "Use O_SYNC for buffered writes",
774 .off1 = td_var_offset(bw_avg_time),
775 .help = "Time window over which to calculate bandwidth (msec)",
779 .name = "create_serialize",
780 .type = FIO_OPT_BOOL,
781 .off1 = td_var_offset(create_serialize),
782 .help = "Serialize creating of job files",
786 .name = "create_fsync",
787 .type = FIO_OPT_BOOL,
788 .off1 = td_var_offset(create_fsync),
789 .help = "Fsync file after creation",
795 .off1 = td_var_offset(cpuload),
796 .help = "Use this percentage of CPU",
801 .off1 = td_var_offset(cpucycle),
802 .help = "Length of the CPU burn cycles (usecs)",
805 #ifdef FIO_HAVE_CPU_AFFINITY
809 .cb = str_cpumask_cb,
810 .help = "CPU affinity mask",
813 .name = "cpus_allowed",
815 .cb = str_cpus_allowed_cb,
816 .help = "Set CPUs allowed",
821 .type = FIO_OPT_BOOL,
822 .off1 = td_var_offset(end_fsync),
823 .help = "Include fsync at the end of job",
827 .name = "fsync_on_close",
828 .type = FIO_OPT_BOOL,
829 .off1 = td_var_offset(fsync_on_close),
830 .help = "fsync files on close",
835 .type = FIO_OPT_BOOL,
836 .off1 = td_var_offset(unlink),
837 .help = "Unlink created files after job has completed",
842 .type = FIO_OPT_STR_SET,
843 .cb = str_exitall_cb,
844 .help = "Terminate all jobs when one exits",
848 .type = FIO_OPT_STR_SET,
849 .off1 = td_var_offset(stonewall),
850 .help = "Insert a hard barrier between this job and previous",
854 .type = FIO_OPT_STR_SET,
855 .off1 = td_var_offset(new_group),
856 .help = "Mark the start of a new group (for reporting)",
860 .type = FIO_OPT_STR_SET,
861 .off1 = td_var_offset(use_thread),
862 .help = "Use threads instead of forks",
865 .name = "write_bw_log",
866 .type = FIO_OPT_STR_SET,
867 .off1 = td_var_offset(write_bw_log),
868 .help = "Write log of bandwidth during run",
871 .name = "write_lat_log",
872 .type = FIO_OPT_STR_SET,
873 .off1 = td_var_offset(write_lat_log),
874 .help = "Write log of latency during run",
877 .name = "hugepage-size",
878 .type = FIO_OPT_STR_VAL,
879 .off1 = td_var_offset(hugepage_size),
880 .help = "When using hugepages, specify size of each page",
881 .def = __stringify(FIO_HUGE_PAGE),
884 .name = "group_reporting",
885 .type = FIO_OPT_STR_SET,
886 .off1 = td_var_offset(group_reporting),
887 .help = "Do reporting on a per-group basis",
890 .name = "zero_buffers",
891 .type = FIO_OPT_STR_SET,
892 .off1 = td_var_offset(zero_buffers),
893 .help = "Init IO buffers to all zeroes",
895 #ifdef FIO_HAVE_DISK_UTIL
898 .type = FIO_OPT_BOOL,
899 .off1 = td_var_offset(do_disk_util),
900 .help = "Log disk utilization stats",
909 void fio_options_dup_and_init(struct option *long_options)
911 struct fio_option *o;
914 options_init(options);
917 while (long_options[i].name)
922 long_options[i].name = o->name;
923 long_options[i].val = FIO_GETOPT_JOB;
924 if (o->type == FIO_OPT_STR_SET)
925 long_options[i].has_arg = no_argument;
927 long_options[i].has_arg = required_argument;
931 assert(i < FIO_NR_OPTIONS);
935 int fio_option_parse(struct thread_data *td, const char *opt)
937 return parse_option(opt, options, td);
940 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
942 return parse_cmd_option(opt, val, options, td);
945 void fio_fill_default_options(struct thread_data *td)
947 fill_default_options(td, options);
950 int fio_show_option_help(const char *opt)
952 return show_cmd_help(options, opt);
955 static void __options_mem(struct thread_data *td, int alloc)
957 struct thread_options *o = &td->o;
958 struct fio_option *opt;
962 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
963 if (opt->type != FIO_OPT_STR_STORE)
966 ptr = (void *) o + opt->off1;
979 * dupe FIO_OPT_STR_STORE options
981 void options_mem_dupe(struct thread_data *td)
983 __options_mem(td, 1);
986 void options_mem_free(struct thread_data fio_unused *td)
989 __options_mem(td, 0);