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;
81 static int str_prio_cb(void *data, unsigned int *val)
83 struct thread_data *td = data;
88 * If no class is set, assume BE
90 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
91 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
98 static int str_exitall_cb(void)
100 exitall_on_terminate = 1;
104 #ifdef FIO_HAVE_CPU_AFFINITY
105 static int str_cpumask_cb(void *data, unsigned int *val)
107 struct thread_data *td = data;
110 CPU_ZERO(&td->o.cpumask);
112 for (i = 0; i < sizeof(int) * 8; i++)
114 CPU_SET(*val, &td->o.cpumask);
116 td->o.cpumask_set = 1;
120 static int str_cpus_allowed_cb(void *data, const char *input)
122 struct thread_data *td = data;
125 CPU_ZERO(&td->o.cpumask);
127 p = str = strdup(input);
129 strip_blank_front(&str);
130 strip_blank_end(str);
132 while ((cpu = strsep(&str, ",")) != NULL) {
135 CPU_SET(atoi(cpu), &td->o.cpumask);
139 td->o.cpumask_set = 1;
145 static int str_fst_cb(void *data, const char *str)
147 struct thread_data *td = data;
148 char *nr = get_opt_postfix(str);
150 td->file_service_nr = 1;
152 td->file_service_nr = atoi(nr);
157 static int str_filename_cb(void *data, const char *input)
159 struct thread_data *td = data;
160 char *fname, *str, *p;
162 p = str = strdup(input);
164 strip_blank_front(&str);
165 strip_blank_end(str);
167 if (!td->files_index)
170 while ((fname = strsep(&str, ":")) != NULL) {
181 static int str_directory_cb(void *data, const char fio_unused *str)
183 struct thread_data *td = data;
186 if (lstat(td->o.directory, &sb) < 0) {
187 log_err("fio: %s is not a directory\n", td->o.directory);
188 td_verror(td, errno, "lstat");
191 if (!S_ISDIR(sb.st_mode)) {
192 log_err("fio: %s is not a directory\n", td->o.directory);
199 static int str_opendir_cb(void *data, const char fio_unused *str)
201 struct thread_data *td = data;
203 if (!td->files_index)
206 return add_dir_files(td, td->o.opendir);
209 static int str_verify_offset_cb(void *data, unsigned int *off)
211 struct thread_data *td = data;
213 if (*off && *off < sizeof(struct verify_header)) {
214 log_err("fio: verify_offset too small\n");
218 td->o.verify_offset = *off;
222 static int str_verify_cb(void *data, const char *mem)
224 struct thread_data *td = data;
225 unsigned int nr, msb;
228 if (td->o.verify != VERIFY_PATTERN)
231 pat = get_opt_postfix(mem);
233 log_err("fio: missing pattern\n");
237 if (strstr(pat, "0x") || strstr(pat, "0X"))
238 nr = strtol(pat, NULL, 16);
240 nr = strtol(pat, NULL, 16);
244 td->o.verify_pattern_bytes = 1;
246 td->o.verify_pattern_bytes = 2;
248 td->o.verify_pattern_bytes = 3;
250 td->o.verify_pattern_bytes = 4;
252 td->o.verify_pattern = nr;
256 #define __stringify_1(x) #x
257 #define __stringify(x) __stringify_1(x)
260 * Map of job/command line options
262 static struct fio_option options[] = {
264 .name = "description",
265 .type = FIO_OPT_STR_STORE,
266 .off1 = td_var_offset(description),
267 .help = "Text job description",
271 .type = FIO_OPT_STR_STORE,
272 .off1 = td_var_offset(name),
273 .help = "Name of this job",
277 .type = FIO_OPT_STR_STORE,
278 .off1 = td_var_offset(directory),
279 .cb = str_directory_cb,
280 .help = "Directory to store files in",
284 .type = FIO_OPT_STR_STORE,
285 .off1 = td_var_offset(filename),
286 .cb = str_filename_cb,
287 .help = "File(s) to use for the workload",
291 .type = FIO_OPT_STR_STORE,
292 .off1 = td_var_offset(opendir),
293 .cb = str_opendir_cb,
294 .help = "Recursively add files from this directory and down",
298 .alias = "readwrite",
301 .off1 = td_var_offset(td_ddir),
302 .help = "IO direction",
306 .oval = TD_DDIR_READ,
307 .help = "Sequential read",
310 .oval = TD_DDIR_WRITE,
311 .help = "Sequential write",
313 { .ival = "randread",
314 .oval = TD_DDIR_RANDREAD,
315 .help = "Random read",
317 { .ival = "randwrite",
318 .oval = TD_DDIR_RANDWRITE,
319 .help = "Random write",
323 .help = "Sequential read and write mix",
326 .oval = TD_DDIR_RANDRW,
327 .help = "Random read and write mix"
333 .type = FIO_OPT_STR_STORE,
334 .off1 = td_var_offset(ioengine),
335 .help = "IO engine to use",
339 .help = "Use read/write",
342 .help = "Use pread/pwrite",
344 #ifdef FIO_HAVE_LIBAIO
346 .help = "Linux native asynchronous IO",
349 #ifdef FIO_HAVE_POSIXAIO
350 { .ival = "posixaio",
351 .help = "POSIX asynchronous IO",
355 .help = "Memory mapped IO",
357 #ifdef FIO_HAVE_SPLICE
359 .help = "splice/vmsplice based IO",
361 { .ival = "netsplice",
362 .help = "splice/vmsplice to/from the network",
367 .help = "SCSI generic v3 IO",
371 .help = "Testing engine (no data transfer)",
374 .help = "Network IO",
376 #ifdef FIO_HAVE_SYSLET
377 { .ival = "syslet-rw",
378 .help = "syslet enabled async pread/pwrite IO",
382 .help = "CPU cycler burner engine",
384 #ifdef FIO_HAVE_GUASI
386 .help = "GUASI IO engine",
389 { .ival = "external",
390 .help = "Load external engine (append name)",
397 .off1 = td_var_offset(iodepth),
398 .help = "Amount of IO buffers to keep in flight",
402 .name = "iodepth_batch",
404 .off1 = td_var_offset(iodepth_batch),
405 .help = "Number of IO to submit in one go",
409 .name = "iodepth_low",
411 .off1 = td_var_offset(iodepth_low),
412 .help = "Low water mark for queuing depth",
417 .type = FIO_OPT_STR_VAL,
418 .off1 = td_var_offset(size),
420 .help = "Total size of device or files",
424 .type = FIO_OPT_STR_VAL,
425 .off1 = td_var_offset(file_size_low),
426 .off2 = td_var_offset(file_size_high),
428 .help = "Size of individual files",
432 .alias = "fileoffset",
433 .type = FIO_OPT_STR_VAL,
434 .off1 = td_var_offset(start_offset),
435 .help = "Start IO from this offset",
440 .alias = "blocksize",
441 .type = FIO_OPT_STR_VAL_INT,
442 .off1 = td_var_offset(bs[DDIR_READ]),
443 .off2 = td_var_offset(bs[DDIR_WRITE]),
445 .help = "Block size unit",
451 .alias = "blocksize_range",
452 .type = FIO_OPT_RANGE,
453 .off1 = td_var_offset(min_bs[DDIR_READ]),
454 .off2 = td_var_offset(max_bs[DDIR_READ]),
455 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
456 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
458 .help = "Set block size range (in more detail than bs)",
462 .name = "bs_unaligned",
463 .alias = "blocksize_unaligned",
464 .type = FIO_OPT_STR_SET,
465 .off1 = td_var_offset(bs_unaligned),
466 .help = "Don't sector align IO buffer sizes",
470 .name = "randrepeat",
471 .type = FIO_OPT_BOOL,
472 .off1 = td_var_offset(rand_repeatable),
473 .help = "Use repeatable random IO pattern",
478 .name = "norandommap",
479 .type = FIO_OPT_STR_SET,
480 .off1 = td_var_offset(norandommap),
481 .help = "Accept potential duplicate random blocks",
487 .off1 = td_var_offset(nr_files),
488 .help = "Split job workload between this number of files",
494 .off1 = td_var_offset(open_files),
495 .help = "Number of files to keep open at the same time",
498 .name = "file_service_type",
501 .off1 = td_var_offset(file_service_type),
502 .help = "How to select which file to service next",
506 .oval = FIO_FSERVICE_RANDOM,
507 .help = "Choose a file at random",
509 { .ival = "roundrobin",
510 .oval = FIO_FSERVICE_RR,
511 .help = "Round robin select files",
517 .name = "fadvise_hint",
518 .type = FIO_OPT_BOOL,
519 .off1 = td_var_offset(fadvise_hint),
520 .help = "Use fadvise() to advise the kernel on IO pattern",
526 .off1 = td_var_offset(fsync_blocks),
527 .help = "Issue fsync for writes every given number of blocks",
532 .type = FIO_OPT_BOOL,
533 .off1 = td_var_offset(odirect),
534 .help = "Use O_DIRECT IO (negates buffered)",
539 .type = FIO_OPT_BOOL,
540 .off1 = td_var_offset(odirect),
542 .help = "Use buffered IO (negates direct)",
547 .type = FIO_OPT_BOOL,
548 .off1 = td_var_offset(overwrite),
549 .help = "When writing, set whether to overwrite current data",
555 .off1 = td_var_offset(loops),
556 .help = "Number of times to run the job",
562 .off1 = td_var_offset(numjobs),
563 .help = "Duplicate this job this many times",
567 .name = "startdelay",
569 .off1 = td_var_offset(start_delay),
570 .help = "Only start job when this period has passed",
576 .type = FIO_OPT_STR_VAL_TIME,
577 .off1 = td_var_offset(timeout),
578 .help = "Stop workload when this amount of time has passed",
582 .name = "time_based",
583 .type = FIO_OPT_STR_SET,
584 .off1 = td_var_offset(time_based),
585 .help = "Keep running until runtime/timeout is met",
592 .off1 = td_var_offset(mem_type),
593 .help = "Backing type for IO buffers",
598 .help = "Use malloc(3) for IO buffers",
602 .help = "Use shared memory segments for IO buffers",
604 #ifdef FIO_HAVE_HUGETLB
607 .help = "Like shm, but use huge pages",
612 .help = "Use mmap(2) (file or anon) for IO buffers",
614 #ifdef FIO_HAVE_HUGETLB
615 { .ival = "mmaphuge",
616 .oval = MEM_MMAPHUGE,
617 .help = "Like mmap, but use huge pages",
625 .off1 = td_var_offset(verify),
627 .help = "Verify data written",
632 .help = "Don't do IO verification",
636 .help = "Use md5 checksums for verification",
639 .oval = VERIFY_CRC64,
640 .help = "Use crc64 checksums for verification",
643 .oval = VERIFY_CRC32,
644 .help = "Use crc32 checksums for verification",
647 .oval = VERIFY_CRC16,
648 .help = "Use crc16 checksums for verification",
652 .help = "Use crc7 checksums for verification",
655 .oval = VERIFY_SHA256,
656 .help = "Use sha256 checksums for verification",
659 .oval = VERIFY_SHA512,
660 .help = "Use sha512 checksums for verification",
664 .help = "Use io information",
667 .oval = VERIFY_PATTERN,
668 .help = "Verify a specific buffer pattern",
673 .help = "Pretend to verify",
679 .type = FIO_OPT_BOOL,
680 .off1 = td_var_offset(do_verify),
681 .help = "Run verification stage after write",
686 .name = "verifysort",
687 .type = FIO_OPT_BOOL,
688 .off1 = td_var_offset(verifysort),
689 .help = "Sort written verify blocks for read back",
694 .name = "verify_interval",
695 .type = FIO_OPT_STR_VAL_INT,
696 .off1 = td_var_offset(verify_interval),
697 .minval = 2 * sizeof(struct verify_header),
698 .help = "Store verify buffer header every N bytes",
702 .name = "verify_offset",
703 .type = FIO_OPT_STR_VAL_INT,
704 .help = "Offset verify header location by N bytes",
706 .cb = str_verify_offset_cb,
710 .name = "verify_fatal",
711 .type = FIO_OPT_BOOL,
712 .off1 = td_var_offset(verify_fatal),
714 .help = "Exit on a single verify failure, don't continue",
718 .name = "write_iolog",
719 .type = FIO_OPT_STR_STORE,
720 .off1 = td_var_offset(write_iolog_file),
721 .help = "Store IO pattern to file",
724 .name = "read_iolog",
725 .type = FIO_OPT_STR_STORE,
726 .off1 = td_var_offset(read_iolog_file),
727 .help = "Playback IO pattern from file",
730 .name = "exec_prerun",
731 .type = FIO_OPT_STR_STORE,
732 .off1 = td_var_offset(exec_prerun),
733 .help = "Execute this file prior to running job",
736 .name = "exec_postrun",
737 .type = FIO_OPT_STR_STORE,
738 .off1 = td_var_offset(exec_postrun),
739 .help = "Execute this file after running job",
741 #ifdef FIO_HAVE_IOSCHED_SWITCH
743 .name = "ioscheduler",
744 .type = FIO_OPT_STR_STORE,
745 .off1 = td_var_offset(ioscheduler),
746 .help = "Use this IO scheduler on the backing device",
751 .type = FIO_OPT_STR_VAL,
752 .off1 = td_var_offset(zone_size),
753 .help = "Give size of an IO zone",
758 .type = FIO_OPT_STR_VAL,
759 .off1 = td_var_offset(zone_skip),
760 .help = "Space between IO zones",
765 .type = FIO_OPT_STR_VAL,
766 .cb = str_lockmem_cb,
767 .help = "Lock down this amount of memory",
773 .off1 = td_var_offset(rwmix[DDIR_READ]),
775 .help = "Percentage of mixed workload that is reads",
779 .name = "rwmixwrite",
781 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
783 .help = "Percentage of mixed workload that is writes",
787 .name = "rwmixcycle",
789 .off1 = td_var_offset(rwmixcycle),
790 .help = "Cycle period for mixed read/write workloads (msec)",
792 .parent = "rwmixread",
797 .off1 = td_var_offset(nice),
798 .help = "Set job CPU nice value",
803 #ifdef FIO_HAVE_IOPRIO
808 .help = "Set job IO priority value",
815 .cb = str_prioclass_cb,
816 .help = "Set job IO priority class",
824 .off1 = td_var_offset(thinktime),
825 .help = "Idle time between IO buffers (usec)",
829 .name = "thinktime_spin",
831 .off1 = td_var_offset(thinktime_spin),
832 .help = "Start think time by spinning this amount (usec)",
834 .parent = "thinktime",
837 .name = "thinktime_blocks",
839 .off1 = td_var_offset(thinktime_blocks),
840 .help = "IO buffer period between 'thinktime'",
842 .parent = "thinktime",
847 .off1 = td_var_offset(rate),
848 .help = "Set bandwidth rate",
853 .off1 = td_var_offset(ratemin),
854 .help = "Job must meet this rate or it will be shutdown",
860 .off1 = td_var_offset(rate_iops),
861 .help = "Limit IO used to this number of IO operations/sec",
864 .name = "rate_iops_min",
866 .off1 = td_var_offset(rate_iops_min),
867 .help = "Job must meet this rate or it will be shutdown",
868 .parent = "rate_iops",
873 .off1 = td_var_offset(ratecycle),
874 .help = "Window average for rate limits (msec)",
879 .name = "invalidate",
880 .type = FIO_OPT_BOOL,
881 .off1 = td_var_offset(invalidate_cache),
882 .help = "Invalidate buffer/page cache prior to running job",
887 .type = FIO_OPT_BOOL,
888 .off1 = td_var_offset(sync_io),
889 .help = "Use O_SYNC for buffered writes",
891 .parent = "buffered",
896 .off1 = td_var_offset(bw_avg_time),
897 .help = "Time window over which to calculate bandwidth (msec)",
901 .name = "create_serialize",
902 .type = FIO_OPT_BOOL,
903 .off1 = td_var_offset(create_serialize),
904 .help = "Serialize creating of job files",
908 .name = "create_fsync",
909 .type = FIO_OPT_BOOL,
910 .off1 = td_var_offset(create_fsync),
911 .help = "Fsync file after creation",
917 .off1 = td_var_offset(cpuload),
918 .help = "Use this percentage of CPU",
923 .off1 = td_var_offset(cpucycle),
924 .help = "Length of the CPU burn cycles (usecs)",
928 #ifdef FIO_HAVE_CPU_AFFINITY
932 .cb = str_cpumask_cb,
933 .help = "CPU affinity mask",
936 .name = "cpus_allowed",
938 .cb = str_cpus_allowed_cb,
939 .help = "Set CPUs allowed",
944 .type = FIO_OPT_BOOL,
945 .off1 = td_var_offset(end_fsync),
946 .help = "Include fsync at the end of job",
950 .name = "fsync_on_close",
951 .type = FIO_OPT_BOOL,
952 .off1 = td_var_offset(fsync_on_close),
953 .help = "fsync files on close",
958 .type = FIO_OPT_BOOL,
959 .off1 = td_var_offset(unlink),
960 .help = "Unlink created files after job has completed",
965 .type = FIO_OPT_STR_SET,
966 .cb = str_exitall_cb,
967 .help = "Terminate all jobs when one exits",
971 .type = FIO_OPT_STR_SET,
972 .off1 = td_var_offset(stonewall),
973 .help = "Insert a hard barrier between this job and previous",
977 .type = FIO_OPT_STR_SET,
978 .off1 = td_var_offset(new_group),
979 .help = "Mark the start of a new group (for reporting)",
983 .type = FIO_OPT_STR_SET,
984 .off1 = td_var_offset(use_thread),
985 .help = "Use threads instead of forks",
988 .name = "write_bw_log",
989 .type = FIO_OPT_STR_SET,
990 .off1 = td_var_offset(write_bw_log),
991 .help = "Write log of bandwidth during run",
994 .name = "write_lat_log",
995 .type = FIO_OPT_STR_SET,
996 .off1 = td_var_offset(write_lat_log),
997 .help = "Write log of latency during run",
1000 .name = "hugepage-size",
1001 .type = FIO_OPT_STR_VAL,
1002 .off1 = td_var_offset(hugepage_size),
1003 .help = "When using hugepages, specify size of each page",
1004 .def = __stringify(FIO_HUGE_PAGE),
1007 .name = "group_reporting",
1008 .type = FIO_OPT_STR_SET,
1009 .off1 = td_var_offset(group_reporting),
1010 .help = "Do reporting on a per-group basis",
1013 .name = "zero_buffers",
1014 .type = FIO_OPT_STR_SET,
1015 .off1 = td_var_offset(zero_buffers),
1016 .help = "Init IO buffers to all zeroes",
1018 #ifdef FIO_HAVE_DISK_UTIL
1020 .name = "disk_util",
1021 .type = FIO_OPT_BOOL,
1022 .off1 = td_var_offset(do_disk_util),
1023 .help = "Log disk utilization stats",
1032 void fio_options_dup_and_init(struct option *long_options)
1034 struct fio_option *o;
1037 options_init(options);
1040 while (long_options[i].name)
1045 long_options[i].name = o->name;
1046 long_options[i].val = FIO_GETOPT_JOB;
1047 if (o->type == FIO_OPT_STR_SET)
1048 long_options[i].has_arg = no_argument;
1050 long_options[i].has_arg = required_argument;
1054 assert(i < FIO_NR_OPTIONS);
1058 int fio_option_parse(struct thread_data *td, const char *opt)
1060 return parse_option(opt, options, td);
1063 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1065 return parse_cmd_option(opt, val, options, td);
1068 void fio_fill_default_options(struct thread_data *td)
1070 fill_default_options(td, options);
1073 int fio_show_option_help(const char *opt)
1075 return show_cmd_help(options, opt);
1078 static void __options_mem(struct thread_data *td, int alloc)
1080 struct thread_options *o = &td->o;
1081 struct fio_option *opt;
1085 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1086 if (opt->type != FIO_OPT_STR_STORE)
1089 ptr = (void *) o + opt->off1;
1092 *ptr = strdup(*ptr);
1102 * dupe FIO_OPT_STR_STORE options
1104 void options_mem_dupe(struct thread_data *td)
1106 __options_mem(td, 1);
1109 void options_mem_free(struct thread_data fio_unused *td)
1112 __options_mem(td, 0);