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_pattern_cb(void *data, unsigned int *off)
222 struct thread_data *td = data;
227 td->o.verify_pattern_bytes = 1;
229 td->o.verify_pattern_bytes = 2;
231 td->o.verify_pattern_bytes = 3;
233 td->o.verify_pattern_bytes = 4;
235 td->o.verify_pattern = *off;
239 #define __stringify_1(x) #x
240 #define __stringify(x) __stringify_1(x)
243 * Map of job/command line options
245 static struct fio_option options[] = {
247 .name = "description",
248 .type = FIO_OPT_STR_STORE,
249 .off1 = td_var_offset(description),
250 .help = "Text job description",
254 .type = FIO_OPT_STR_STORE,
255 .off1 = td_var_offset(name),
256 .help = "Name of this job",
260 .type = FIO_OPT_STR_STORE,
261 .off1 = td_var_offset(directory),
262 .cb = str_directory_cb,
263 .help = "Directory to store files in",
267 .type = FIO_OPT_STR_STORE,
268 .off1 = td_var_offset(filename),
269 .cb = str_filename_cb,
270 .help = "File(s) to use for the workload",
274 .type = FIO_OPT_STR_STORE,
275 .off1 = td_var_offset(opendir),
276 .cb = str_opendir_cb,
277 .help = "Recursively add files from this directory and down",
281 .alias = "readwrite",
284 .off1 = td_var_offset(td_ddir),
285 .help = "IO direction",
289 .oval = TD_DDIR_READ,
290 .help = "Sequential read",
293 .oval = TD_DDIR_WRITE,
294 .help = "Sequential write",
296 { .ival = "randread",
297 .oval = TD_DDIR_RANDREAD,
298 .help = "Random read",
300 { .ival = "randwrite",
301 .oval = TD_DDIR_RANDWRITE,
302 .help = "Random write",
306 .help = "Sequential read and write mix",
309 .oval = TD_DDIR_RANDRW,
310 .help = "Random read and write mix"
315 .name = "fadvise_hint",
316 .type = FIO_OPT_BOOL,
317 .off1 = td_var_offset(fadvise_hint),
318 .help = "Use fadvise() to advise the kernel on IO pattern",
323 .type = FIO_OPT_STR_STORE,
324 .off1 = td_var_offset(ioengine),
325 .help = "IO engine to use",
329 .help = "Use read/write",
331 #ifdef FIO_HAVE_LIBAIO
333 .help = "Linux native asynchronous IO",
336 #ifdef FIO_HAVE_POSIXAIO
337 { .ival = "posixaio",
338 .help = "POSIX asynchronous IO",
342 .help = "Memory mapped IO",
344 #ifdef FIO_HAVE_SPLICE
346 .help = "splice/vmsplice based IO",
348 { .ival = "netsplice",
349 .help = "splice/vmsplice to/from the network",
354 .help = "SCSI generic v3 IO",
358 .help = "Testing engine (no data transfer)",
361 .help = "Network IO",
363 #ifdef FIO_HAVE_SYSLET
364 { .ival = "syslet-rw",
365 .help = "syslet enabled async pread/pwrite IO",
369 .help = "CPU cycler burner engine",
371 #ifdef FIO_HAVE_GUASI
373 .help = "GUASI IO engine",
376 { .ival = "external",
377 .help = "Load external engine (append name)",
384 .off1 = td_var_offset(iodepth),
385 .help = "Amount of IO buffers to keep in flight",
389 .name = "iodepth_batch",
391 .off1 = td_var_offset(iodepth_batch),
392 .help = "Number of IO to submit in one go",
396 .name = "iodepth_low",
398 .off1 = td_var_offset(iodepth_low),
399 .help = "Low water mark for queuing depth",
404 .type = FIO_OPT_STR_VAL,
405 .off1 = td_var_offset(size),
407 .help = "Total size of device or files",
411 .type = FIO_OPT_STR_VAL,
412 .off1 = td_var_offset(file_size_low),
413 .off2 = td_var_offset(file_size_high),
415 .help = "Size of individual files",
419 .alias = "blocksize",
420 .type = FIO_OPT_STR_VAL_INT,
421 .off1 = td_var_offset(bs[DDIR_READ]),
422 .off2 = td_var_offset(bs[DDIR_WRITE]),
424 .help = "Block size unit",
429 .alias = "blocksize_range",
430 .type = FIO_OPT_RANGE,
431 .off1 = td_var_offset(min_bs[DDIR_READ]),
432 .off2 = td_var_offset(max_bs[DDIR_READ]),
433 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
434 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
436 .help = "Set block size range (in more detail than bs)",
439 .name = "bs_unaligned",
440 .alias = "blocksize_unaligned",
441 .type = FIO_OPT_STR_SET,
442 .off1 = td_var_offset(bs_unaligned),
443 .help = "Don't sector align IO buffer sizes",
447 .type = FIO_OPT_STR_VAL,
448 .off1 = td_var_offset(start_offset),
449 .help = "Start IO from this offset",
453 .name = "randrepeat",
454 .type = FIO_OPT_BOOL,
455 .off1 = td_var_offset(rand_repeatable),
456 .help = "Use repeatable random IO pattern",
460 .name = "norandommap",
461 .type = FIO_OPT_STR_SET,
462 .off1 = td_var_offset(norandommap),
463 .help = "Accept potential duplicate random blocks",
468 .off1 = td_var_offset(nr_files),
469 .help = "Split job workload between this number of files",
475 .off1 = td_var_offset(open_files),
476 .help = "Number of files to keep open at the same time",
479 .name = "file_service_type",
482 .off1 = td_var_offset(file_service_type),
483 .help = "How to select which file to service next",
487 .oval = FIO_FSERVICE_RANDOM,
488 .help = "Choose a file at random",
490 { .ival = "roundrobin",
491 .oval = FIO_FSERVICE_RR,
492 .help = "Round robin select files",
499 .off1 = td_var_offset(fsync_blocks),
500 .help = "Issue fsync for writes every given number of blocks",
505 .type = FIO_OPT_BOOL,
506 .off1 = td_var_offset(odirect),
507 .help = "Use O_DIRECT IO (negates buffered)",
512 .type = FIO_OPT_BOOL,
513 .off1 = td_var_offset(odirect),
515 .help = "Use buffered IO (negates direct)",
520 .type = FIO_OPT_BOOL,
521 .off1 = td_var_offset(overwrite),
522 .help = "When writing, set whether to overwrite current data",
528 .off1 = td_var_offset(loops),
529 .help = "Number of times to run the job",
535 .off1 = td_var_offset(numjobs),
536 .help = "Duplicate this job this many times",
540 .name = "startdelay",
542 .off1 = td_var_offset(start_delay),
543 .help = "Only start job when this period has passed",
549 .type = FIO_OPT_STR_VAL_TIME,
550 .off1 = td_var_offset(timeout),
551 .help = "Stop workload when this amount of time has passed",
555 .name = "time_based",
556 .type = FIO_OPT_STR_SET,
557 .off1 = td_var_offset(time_based),
558 .help = "Keep running until runtime/timeout is met",
565 .off1 = td_var_offset(mem_type),
566 .help = "Backing type for IO buffers",
571 .help = "Use malloc(3) for IO buffers",
575 .help = "Use shared memory segments for IO buffers",
577 #ifdef FIO_HAVE_HUGETLB
580 .help = "Like shm, but use huge pages",
585 .help = "Use mmap(2) (file or anon) for IO buffers",
587 #ifdef FIO_HAVE_HUGETLB
588 { .ival = "mmaphuge",
589 .oval = MEM_MMAPHUGE,
590 .help = "Like mmap, but use huge pages",
598 .off1 = td_var_offset(verify),
599 .help = "Verify data written",
604 .help = "Don't do IO verification",
608 .help = "Use md5 checksums for verification",
611 .oval = VERIFY_CRC64,
612 .help = "Use crc64 checksums for verification",
615 .oval = VERIFY_CRC32,
616 .help = "Use crc32 checksums for verification",
619 .oval = VERIFY_CRC16,
620 .help = "Use crc16 checksums for verification",
624 .help = "Use crc7 checksums for verification",
627 .oval = VERIFY_SHA256,
628 .help = "Use sha256 checksums for verification",
631 .oval = VERIFY_SHA512,
632 .help = "Use sha512 checksums for verification",
637 .help = "Pretend to verify",
642 .name = "verifysort",
643 .type = FIO_OPT_BOOL,
644 .off1 = td_var_offset(verifysort),
645 .help = "Sort written verify blocks for read back",
650 .name = "verify_interval",
651 .type = FIO_OPT_STR_VAL_INT,
652 .off1 = td_var_offset(verify_interval),
653 .minval = 2 * sizeof(struct verify_header),
654 .help = "Store verify buffer header every N bytes",
658 .name = "verify_offset",
659 .type = FIO_OPT_STR_VAL_INT,
660 .help = "Offset verify header location by N bytes",
662 .cb = str_verify_offset_cb,
666 .name = "verify_pattern",
668 .cb = str_verify_pattern_cb,
669 .help = "Fill pattern for IO buffers",
673 .name = "write_iolog",
674 .type = FIO_OPT_STR_STORE,
675 .off1 = td_var_offset(write_iolog_file),
676 .help = "Store IO pattern to file",
679 .name = "read_iolog",
680 .type = FIO_OPT_STR_STORE,
681 .off1 = td_var_offset(read_iolog_file),
682 .help = "Playback IO pattern from file",
685 .name = "exec_prerun",
686 .type = FIO_OPT_STR_STORE,
687 .off1 = td_var_offset(exec_prerun),
688 .help = "Execute this file prior to running job",
691 .name = "exec_postrun",
692 .type = FIO_OPT_STR_STORE,
693 .off1 = td_var_offset(exec_postrun),
694 .help = "Execute this file after running job",
696 #ifdef FIO_HAVE_IOSCHED_SWITCH
698 .name = "ioscheduler",
699 .type = FIO_OPT_STR_STORE,
700 .off1 = td_var_offset(ioscheduler),
701 .help = "Use this IO scheduler on the backing device",
706 .type = FIO_OPT_STR_VAL,
707 .off1 = td_var_offset(zone_size),
708 .help = "Give size of an IO zone",
713 .type = FIO_OPT_STR_VAL,
714 .off1 = td_var_offset(zone_skip),
715 .help = "Space between IO zones",
720 .type = FIO_OPT_STR_VAL,
721 .cb = str_lockmem_cb,
722 .help = "Lock down this amount of memory",
728 .off1 = td_var_offset(rwmix[DDIR_READ]),
730 .help = "Percentage of mixed workload that is reads",
734 .name = "rwmixwrite",
736 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
738 .help = "Percentage of mixed workload that is writes",
742 .name = "rwmixcycle",
744 .off1 = td_var_offset(rwmixcycle),
745 .help = "Cycle period for mixed read/write workloads (msec)",
747 .parent = "rwmixread",
752 .off1 = td_var_offset(nice),
753 .help = "Set job CPU nice value",
758 #ifdef FIO_HAVE_IOPRIO
763 .help = "Set job IO priority value",
770 .cb = str_prioclass_cb,
771 .help = "Set job IO priority class",
779 .off1 = td_var_offset(thinktime),
780 .help = "Idle time between IO buffers (usec)",
784 .name = "thinktime_spin",
786 .off1 = td_var_offset(thinktime_spin),
787 .help = "Start think time by spinning this amount (usec)",
789 .parent = "thinktime",
792 .name = "thinktime_blocks",
794 .off1 = td_var_offset(thinktime_blocks),
795 .help = "IO buffer period between 'thinktime'",
797 .parent = "thinktime",
802 .off1 = td_var_offset(rate),
803 .help = "Set bandwidth rate",
808 .off1 = td_var_offset(ratemin),
809 .help = "Job must meet this rate or it will be shutdown",
815 .off1 = td_var_offset(rate_iops),
816 .help = "Limit IO used to this number of IO operations/sec",
819 .name = "rate_iops_min",
821 .off1 = td_var_offset(rate_iops_min),
822 .help = "Job must meet this rate or it will be shutdown",
823 .parent = "rate_iops",
828 .off1 = td_var_offset(ratecycle),
829 .help = "Window average for rate limits (msec)",
834 .name = "invalidate",
835 .type = FIO_OPT_BOOL,
836 .off1 = td_var_offset(invalidate_cache),
837 .help = "Invalidate buffer/page cache prior to running job",
842 .type = FIO_OPT_BOOL,
843 .off1 = td_var_offset(sync_io),
844 .help = "Use O_SYNC for buffered writes",
850 .off1 = td_var_offset(bw_avg_time),
851 .help = "Time window over which to calculate bandwidth (msec)",
855 .name = "create_serialize",
856 .type = FIO_OPT_BOOL,
857 .off1 = td_var_offset(create_serialize),
858 .help = "Serialize creating of job files",
862 .name = "create_fsync",
863 .type = FIO_OPT_BOOL,
864 .off1 = td_var_offset(create_fsync),
865 .help = "Fsync file after creation",
871 .off1 = td_var_offset(cpuload),
872 .help = "Use this percentage of CPU",
877 .off1 = td_var_offset(cpucycle),
878 .help = "Length of the CPU burn cycles (usecs)",
881 #ifdef FIO_HAVE_CPU_AFFINITY
885 .cb = str_cpumask_cb,
886 .help = "CPU affinity mask",
889 .name = "cpus_allowed",
891 .cb = str_cpus_allowed_cb,
892 .help = "Set CPUs allowed",
897 .type = FIO_OPT_BOOL,
898 .off1 = td_var_offset(end_fsync),
899 .help = "Include fsync at the end of job",
903 .name = "fsync_on_close",
904 .type = FIO_OPT_BOOL,
905 .off1 = td_var_offset(fsync_on_close),
906 .help = "fsync files on close",
911 .type = FIO_OPT_BOOL,
912 .off1 = td_var_offset(unlink),
913 .help = "Unlink created files after job has completed",
918 .type = FIO_OPT_STR_SET,
919 .cb = str_exitall_cb,
920 .help = "Terminate all jobs when one exits",
924 .type = FIO_OPT_STR_SET,
925 .off1 = td_var_offset(stonewall),
926 .help = "Insert a hard barrier between this job and previous",
930 .type = FIO_OPT_STR_SET,
931 .off1 = td_var_offset(new_group),
932 .help = "Mark the start of a new group (for reporting)",
936 .type = FIO_OPT_STR_SET,
937 .off1 = td_var_offset(use_thread),
938 .help = "Use threads instead of forks",
941 .name = "write_bw_log",
942 .type = FIO_OPT_STR_SET,
943 .off1 = td_var_offset(write_bw_log),
944 .help = "Write log of bandwidth during run",
947 .name = "write_lat_log",
948 .type = FIO_OPT_STR_SET,
949 .off1 = td_var_offset(write_lat_log),
950 .help = "Write log of latency during run",
953 .name = "hugepage-size",
954 .type = FIO_OPT_STR_VAL,
955 .off1 = td_var_offset(hugepage_size),
956 .help = "When using hugepages, specify size of each page",
957 .def = __stringify(FIO_HUGE_PAGE),
960 .name = "group_reporting",
961 .type = FIO_OPT_STR_SET,
962 .off1 = td_var_offset(group_reporting),
963 .help = "Do reporting on a per-group basis",
966 .name = "zero_buffers",
967 .type = FIO_OPT_STR_SET,
968 .off1 = td_var_offset(zero_buffers),
969 .help = "Init IO buffers to all zeroes",
971 #ifdef FIO_HAVE_DISK_UTIL
974 .type = FIO_OPT_BOOL,
975 .off1 = td_var_offset(do_disk_util),
976 .help = "Log disk utilization stats",
985 void fio_options_dup_and_init(struct option *long_options)
987 struct fio_option *o;
990 options_init(options);
993 while (long_options[i].name)
998 long_options[i].name = o->name;
999 long_options[i].val = FIO_GETOPT_JOB;
1000 if (o->type == FIO_OPT_STR_SET)
1001 long_options[i].has_arg = no_argument;
1003 long_options[i].has_arg = required_argument;
1007 assert(i < FIO_NR_OPTIONS);
1011 int fio_option_parse(struct thread_data *td, const char *opt)
1013 return parse_option(opt, options, td);
1016 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1018 return parse_cmd_option(opt, val, options, td);
1021 void fio_fill_default_options(struct thread_data *td)
1023 fill_default_options(td, options);
1026 int fio_show_option_help(const char *opt)
1028 return show_cmd_help(options, opt);
1031 static void __options_mem(struct thread_data *td, int alloc)
1033 struct thread_options *o = &td->o;
1034 struct fio_option *opt;
1038 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1039 if (opt->type != FIO_OPT_STR_STORE)
1042 ptr = (void *) o + opt->off1;
1045 *ptr = strdup(*ptr);
1055 * dupe FIO_OPT_STR_STORE options
1057 void options_mem_dupe(struct thread_data *td)
1059 __options_mem(td, 1);
1062 void options_mem_free(struct thread_data fio_unused *td)
1065 __options_mem(td, 0);