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"
316 .type = FIO_OPT_STR_STORE,
317 .off1 = td_var_offset(ioengine),
318 .help = "IO engine to use",
322 .help = "Use read/write",
324 #ifdef FIO_HAVE_LIBAIO
326 .help = "Linux native asynchronous IO",
329 #ifdef FIO_HAVE_POSIXAIO
330 { .ival = "posixaio",
331 .help = "POSIX asynchronous IO",
335 .help = "Memory mapped IO",
337 #ifdef FIO_HAVE_SPLICE
339 .help = "splice/vmsplice based IO",
341 { .ival = "netsplice",
342 .help = "splice/vmsplice to/from the network",
347 .help = "SCSI generic v3 IO",
351 .help = "Testing engine (no data transfer)",
354 .help = "Network IO",
356 #ifdef FIO_HAVE_SYSLET
357 { .ival = "syslet-rw",
358 .help = "syslet enabled async pread/pwrite IO",
362 .help = "CPU cycler burner engine",
364 #ifdef FIO_HAVE_GUASI
366 .help = "GUASI IO engine",
369 { .ival = "external",
370 .help = "Load external engine (append name)",
377 .off1 = td_var_offset(iodepth),
378 .help = "Amount of IO buffers to keep in flight",
382 .name = "iodepth_batch",
384 .off1 = td_var_offset(iodepth_batch),
385 .help = "Number of IO to submit in one go",
389 .name = "iodepth_low",
391 .off1 = td_var_offset(iodepth_low),
392 .help = "Low water mark for queuing depth",
397 .type = FIO_OPT_STR_VAL,
398 .off1 = td_var_offset(size),
400 .help = "Total size of device or files",
404 .type = FIO_OPT_STR_VAL,
405 .off1 = td_var_offset(file_size_low),
406 .off2 = td_var_offset(file_size_high),
408 .help = "Size of individual files",
412 .alias = "fileoffset",
413 .type = FIO_OPT_STR_VAL,
414 .off1 = td_var_offset(start_offset),
415 .help = "Start IO from this offset",
420 .alias = "blocksize",
421 .type = FIO_OPT_STR_VAL_INT,
422 .off1 = td_var_offset(bs[DDIR_READ]),
423 .off2 = td_var_offset(bs[DDIR_WRITE]),
425 .help = "Block size unit",
431 .alias = "blocksize_range",
432 .type = FIO_OPT_RANGE,
433 .off1 = td_var_offset(min_bs[DDIR_READ]),
434 .off2 = td_var_offset(max_bs[DDIR_READ]),
435 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
436 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
438 .help = "Set block size range (in more detail than bs)",
442 .name = "bs_unaligned",
443 .alias = "blocksize_unaligned",
444 .type = FIO_OPT_STR_SET,
445 .off1 = td_var_offset(bs_unaligned),
446 .help = "Don't sector align IO buffer sizes",
450 .name = "randrepeat",
451 .type = FIO_OPT_BOOL,
452 .off1 = td_var_offset(rand_repeatable),
453 .help = "Use repeatable random IO pattern",
458 .name = "norandommap",
459 .type = FIO_OPT_STR_SET,
460 .off1 = td_var_offset(norandommap),
461 .help = "Accept potential duplicate random blocks",
467 .off1 = td_var_offset(nr_files),
468 .help = "Split job workload between this number of files",
474 .off1 = td_var_offset(open_files),
475 .help = "Number of files to keep open at the same time",
478 .name = "file_service_type",
481 .off1 = td_var_offset(file_service_type),
482 .help = "How to select which file to service next",
486 .oval = FIO_FSERVICE_RANDOM,
487 .help = "Choose a file at random",
489 { .ival = "roundrobin",
490 .oval = FIO_FSERVICE_RR,
491 .help = "Round robin select files",
497 .name = "fadvise_hint",
498 .type = FIO_OPT_BOOL,
499 .off1 = td_var_offset(fadvise_hint),
500 .help = "Use fadvise() to advise the kernel on IO pattern",
506 .off1 = td_var_offset(fsync_blocks),
507 .help = "Issue fsync for writes every given number of blocks",
512 .type = FIO_OPT_BOOL,
513 .off1 = td_var_offset(odirect),
514 .help = "Use O_DIRECT IO (negates buffered)",
519 .type = FIO_OPT_BOOL,
520 .off1 = td_var_offset(odirect),
522 .help = "Use buffered IO (negates direct)",
527 .type = FIO_OPT_BOOL,
528 .off1 = td_var_offset(overwrite),
529 .help = "When writing, set whether to overwrite current data",
535 .off1 = td_var_offset(loops),
536 .help = "Number of times to run the job",
542 .off1 = td_var_offset(numjobs),
543 .help = "Duplicate this job this many times",
547 .name = "startdelay",
549 .off1 = td_var_offset(start_delay),
550 .help = "Only start job when this period has passed",
556 .type = FIO_OPT_STR_VAL_TIME,
557 .off1 = td_var_offset(timeout),
558 .help = "Stop workload when this amount of time has passed",
562 .name = "time_based",
563 .type = FIO_OPT_STR_SET,
564 .off1 = td_var_offset(time_based),
565 .help = "Keep running until runtime/timeout is met",
572 .off1 = td_var_offset(mem_type),
573 .help = "Backing type for IO buffers",
578 .help = "Use malloc(3) for IO buffers",
582 .help = "Use shared memory segments for IO buffers",
584 #ifdef FIO_HAVE_HUGETLB
587 .help = "Like shm, but use huge pages",
592 .help = "Use mmap(2) (file or anon) for IO buffers",
594 #ifdef FIO_HAVE_HUGETLB
595 { .ival = "mmaphuge",
596 .oval = MEM_MMAPHUGE,
597 .help = "Like mmap, but use huge pages",
605 .off1 = td_var_offset(verify),
606 .help = "Verify data written",
611 .help = "Don't do IO verification",
615 .help = "Use md5 checksums for verification",
618 .oval = VERIFY_CRC64,
619 .help = "Use crc64 checksums for verification",
622 .oval = VERIFY_CRC32,
623 .help = "Use crc32 checksums for verification",
626 .oval = VERIFY_CRC16,
627 .help = "Use crc16 checksums for verification",
631 .help = "Use crc7 checksums for verification",
634 .oval = VERIFY_SHA256,
635 .help = "Use sha256 checksums for verification",
638 .oval = VERIFY_SHA512,
639 .help = "Use sha512 checksums for verification",
643 .help = "Use io information",
648 .help = "Pretend to verify",
653 .name = "verifysort",
654 .type = FIO_OPT_BOOL,
655 .off1 = td_var_offset(verifysort),
656 .help = "Sort written verify blocks for read back",
661 .name = "verify_interval",
662 .type = FIO_OPT_STR_VAL_INT,
663 .off1 = td_var_offset(verify_interval),
664 .minval = 2 * sizeof(struct verify_header),
665 .help = "Store verify buffer header every N bytes",
669 .name = "verify_offset",
670 .type = FIO_OPT_STR_VAL_INT,
671 .help = "Offset verify header location by N bytes",
673 .cb = str_verify_offset_cb,
677 .name = "verify_pattern",
679 .cb = str_verify_pattern_cb,
680 .help = "Fill pattern for IO buffers",
684 .name = "write_iolog",
685 .type = FIO_OPT_STR_STORE,
686 .off1 = td_var_offset(write_iolog_file),
687 .help = "Store IO pattern to file",
690 .name = "read_iolog",
691 .type = FIO_OPT_STR_STORE,
692 .off1 = td_var_offset(read_iolog_file),
693 .help = "Playback IO pattern from file",
696 .name = "exec_prerun",
697 .type = FIO_OPT_STR_STORE,
698 .off1 = td_var_offset(exec_prerun),
699 .help = "Execute this file prior to running job",
702 .name = "exec_postrun",
703 .type = FIO_OPT_STR_STORE,
704 .off1 = td_var_offset(exec_postrun),
705 .help = "Execute this file after running job",
707 #ifdef FIO_HAVE_IOSCHED_SWITCH
709 .name = "ioscheduler",
710 .type = FIO_OPT_STR_STORE,
711 .off1 = td_var_offset(ioscheduler),
712 .help = "Use this IO scheduler on the backing device",
717 .type = FIO_OPT_STR_VAL,
718 .off1 = td_var_offset(zone_size),
719 .help = "Give size of an IO zone",
724 .type = FIO_OPT_STR_VAL,
725 .off1 = td_var_offset(zone_skip),
726 .help = "Space between IO zones",
731 .type = FIO_OPT_STR_VAL,
732 .cb = str_lockmem_cb,
733 .help = "Lock down this amount of memory",
739 .off1 = td_var_offset(rwmix[DDIR_READ]),
741 .help = "Percentage of mixed workload that is reads",
745 .name = "rwmixwrite",
747 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
749 .help = "Percentage of mixed workload that is writes",
753 .name = "rwmixcycle",
755 .off1 = td_var_offset(rwmixcycle),
756 .help = "Cycle period for mixed read/write workloads (msec)",
758 .parent = "rwmixread",
763 .off1 = td_var_offset(nice),
764 .help = "Set job CPU nice value",
769 #ifdef FIO_HAVE_IOPRIO
774 .help = "Set job IO priority value",
781 .cb = str_prioclass_cb,
782 .help = "Set job IO priority class",
790 .off1 = td_var_offset(thinktime),
791 .help = "Idle time between IO buffers (usec)",
795 .name = "thinktime_spin",
797 .off1 = td_var_offset(thinktime_spin),
798 .help = "Start think time by spinning this amount (usec)",
800 .parent = "thinktime",
803 .name = "thinktime_blocks",
805 .off1 = td_var_offset(thinktime_blocks),
806 .help = "IO buffer period between 'thinktime'",
808 .parent = "thinktime",
813 .off1 = td_var_offset(rate),
814 .help = "Set bandwidth rate",
819 .off1 = td_var_offset(ratemin),
820 .help = "Job must meet this rate or it will be shutdown",
826 .off1 = td_var_offset(rate_iops),
827 .help = "Limit IO used to this number of IO operations/sec",
830 .name = "rate_iops_min",
832 .off1 = td_var_offset(rate_iops_min),
833 .help = "Job must meet this rate or it will be shutdown",
834 .parent = "rate_iops",
839 .off1 = td_var_offset(ratecycle),
840 .help = "Window average for rate limits (msec)",
845 .name = "invalidate",
846 .type = FIO_OPT_BOOL,
847 .off1 = td_var_offset(invalidate_cache),
848 .help = "Invalidate buffer/page cache prior to running job",
853 .type = FIO_OPT_BOOL,
854 .off1 = td_var_offset(sync_io),
855 .help = "Use O_SYNC for buffered writes",
857 .parent = "buffered",
862 .off1 = td_var_offset(bw_avg_time),
863 .help = "Time window over which to calculate bandwidth (msec)",
867 .name = "create_serialize",
868 .type = FIO_OPT_BOOL,
869 .off1 = td_var_offset(create_serialize),
870 .help = "Serialize creating of job files",
874 .name = "create_fsync",
875 .type = FIO_OPT_BOOL,
876 .off1 = td_var_offset(create_fsync),
877 .help = "Fsync file after creation",
883 .off1 = td_var_offset(cpuload),
884 .help = "Use this percentage of CPU",
889 .off1 = td_var_offset(cpucycle),
890 .help = "Length of the CPU burn cycles (usecs)",
894 #ifdef FIO_HAVE_CPU_AFFINITY
898 .cb = str_cpumask_cb,
899 .help = "CPU affinity mask",
902 .name = "cpus_allowed",
904 .cb = str_cpus_allowed_cb,
905 .help = "Set CPUs allowed",
910 .type = FIO_OPT_BOOL,
911 .off1 = td_var_offset(end_fsync),
912 .help = "Include fsync at the end of job",
916 .name = "fsync_on_close",
917 .type = FIO_OPT_BOOL,
918 .off1 = td_var_offset(fsync_on_close),
919 .help = "fsync files on close",
924 .type = FIO_OPT_BOOL,
925 .off1 = td_var_offset(unlink),
926 .help = "Unlink created files after job has completed",
931 .type = FIO_OPT_STR_SET,
932 .cb = str_exitall_cb,
933 .help = "Terminate all jobs when one exits",
937 .type = FIO_OPT_STR_SET,
938 .off1 = td_var_offset(stonewall),
939 .help = "Insert a hard barrier between this job and previous",
943 .type = FIO_OPT_STR_SET,
944 .off1 = td_var_offset(new_group),
945 .help = "Mark the start of a new group (for reporting)",
949 .type = FIO_OPT_STR_SET,
950 .off1 = td_var_offset(use_thread),
951 .help = "Use threads instead of forks",
954 .name = "write_bw_log",
955 .type = FIO_OPT_STR_SET,
956 .off1 = td_var_offset(write_bw_log),
957 .help = "Write log of bandwidth during run",
960 .name = "write_lat_log",
961 .type = FIO_OPT_STR_SET,
962 .off1 = td_var_offset(write_lat_log),
963 .help = "Write log of latency during run",
966 .name = "hugepage-size",
967 .type = FIO_OPT_STR_VAL,
968 .off1 = td_var_offset(hugepage_size),
969 .help = "When using hugepages, specify size of each page",
970 .def = __stringify(FIO_HUGE_PAGE),
973 .name = "group_reporting",
974 .type = FIO_OPT_STR_SET,
975 .off1 = td_var_offset(group_reporting),
976 .help = "Do reporting on a per-group basis",
979 .name = "zero_buffers",
980 .type = FIO_OPT_STR_SET,
981 .off1 = td_var_offset(zero_buffers),
982 .help = "Init IO buffers to all zeroes",
984 #ifdef FIO_HAVE_DISK_UTIL
987 .type = FIO_OPT_BOOL,
988 .off1 = td_var_offset(do_disk_util),
989 .help = "Log disk utilization stats",
998 void fio_options_dup_and_init(struct option *long_options)
1000 struct fio_option *o;
1003 options_init(options);
1006 while (long_options[i].name)
1011 long_options[i].name = o->name;
1012 long_options[i].val = FIO_GETOPT_JOB;
1013 if (o->type == FIO_OPT_STR_SET)
1014 long_options[i].has_arg = no_argument;
1016 long_options[i].has_arg = required_argument;
1020 assert(i < FIO_NR_OPTIONS);
1024 int fio_option_parse(struct thread_data *td, const char *opt)
1026 return parse_option(opt, options, td);
1029 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1031 return parse_cmd_option(opt, val, options, td);
1034 void fio_fill_default_options(struct thread_data *td)
1036 fill_default_options(td, options);
1039 int fio_show_option_help(const char *opt)
1041 return show_cmd_help(options, opt);
1044 static void __options_mem(struct thread_data *td, int alloc)
1046 struct thread_options *o = &td->o;
1047 struct fio_option *opt;
1051 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1052 if (opt->type != FIO_OPT_STR_STORE)
1055 ptr = (void *) o + opt->off1;
1058 *ptr = strdup(*ptr);
1068 * dupe FIO_OPT_STR_STORE options
1070 void options_mem_dupe(struct thread_data *td)
1072 __options_mem(td, 1);
1075 void options_mem_free(struct thread_data fio_unused *td)
1078 __options_mem(td, 0);