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);
206 static int str_header_offset_cb(void *data, unsigned int *off)
208 struct thread_data *td = data;
209 if (*off && *off < sizeof(struct verify_header)) {
210 log_err("fio: header_offset too small\n");
213 td->o.header_offset = *off;
218 #define __stringify_1(x) #x
219 #define __stringify(x) __stringify_1(x)
222 * Map of job/command line options
224 static struct fio_option options[] = {
226 .name = "description",
227 .type = FIO_OPT_STR_STORE,
228 .off1 = td_var_offset(description),
229 .help = "Text job description",
233 .type = FIO_OPT_STR_STORE,
234 .off1 = td_var_offset(name),
235 .help = "Name of this job",
239 .type = FIO_OPT_STR_STORE,
240 .off1 = td_var_offset(directory),
241 .cb = str_directory_cb,
242 .help = "Directory to store files in",
246 .type = FIO_OPT_STR_STORE,
247 .off1 = td_var_offset(filename),
248 .cb = str_filename_cb,
249 .help = "File(s) to use for the workload",
253 .type = FIO_OPT_STR_STORE,
254 .off1 = td_var_offset(opendir),
255 .cb = str_opendir_cb,
256 .help = "Recursively add files from this directory and down",
260 .alias = "readwrite",
263 .off1 = td_var_offset(td_ddir),
264 .help = "IO direction",
268 .oval = TD_DDIR_READ,
269 .help = "Sequential read",
272 .oval = TD_DDIR_WRITE,
273 .help = "Sequential write",
275 { .ival = "randread",
276 .oval = TD_DDIR_RANDREAD,
277 .help = "Random read",
279 { .ival = "randwrite",
280 .oval = TD_DDIR_RANDWRITE,
281 .help = "Random write",
285 .help = "Sequential read and write mix",
288 .oval = TD_DDIR_RANDRW,
289 .help = "Random read and write mix"
294 .name = "fadvise_hint",
295 .type = FIO_OPT_BOOL,
296 .off1 = td_var_offset(fadvise_hint),
297 .help = "Use fadvise() to advise the kernel on IO pattern",
302 .type = FIO_OPT_STR_STORE,
303 .off1 = td_var_offset(ioengine),
304 .help = "IO engine to use",
308 .help = "Use read/write",
310 #ifdef FIO_HAVE_LIBAIO
312 .help = "Linux native asynchronous IO",
315 #ifdef FIO_HAVE_POSIXAIO
316 { .ival = "posixaio",
317 .help = "POSIX asynchronous IO",
321 .help = "Memory mapped IO",
323 #ifdef FIO_HAVE_SPLICE
325 .help = "splice/vmsplice based IO",
327 { .ival = "netsplice",
328 .help = "splice/vmsplice to/from the network",
333 .help = "SCSI generic v3 IO",
337 .help = "Testing engine (no data transfer)",
340 .help = "Network IO",
342 #ifdef FIO_HAVE_SYSLET
343 { .ival = "syslet-rw",
344 .help = "syslet enabled async pread/pwrite IO",
348 .help = "CPU cycler burner engine",
350 #ifdef FIO_HAVE_GUASI
352 .help = "GUASI IO engine",
355 { .ival = "external",
356 .help = "Load external engine (append name)",
363 .off1 = td_var_offset(iodepth),
364 .help = "Amount of IO buffers to keep in flight",
368 .name = "iodepth_batch",
370 .off1 = td_var_offset(iodepth_batch),
371 .help = "Number of IO to submit in one go",
374 .name = "iodepth_low",
376 .off1 = td_var_offset(iodepth_low),
377 .help = "Low water mark for queuing depth",
381 .type = FIO_OPT_STR_VAL,
382 .off1 = td_var_offset(size),
384 .help = "Total size of device or files",
388 .type = FIO_OPT_STR_VAL,
389 .off1 = td_var_offset(file_size_low),
390 .off2 = td_var_offset(file_size_high),
392 .help = "Size of individual files",
396 .alias = "blocksize",
397 .type = FIO_OPT_STR_VAL_INT,
398 .off1 = td_var_offset(bs[DDIR_READ]),
399 .off2 = td_var_offset(bs[DDIR_WRITE]),
401 .help = "Block size unit",
406 .alias = "blocksize_range",
407 .type = FIO_OPT_RANGE,
408 .off1 = td_var_offset(min_bs[DDIR_READ]),
409 .off2 = td_var_offset(max_bs[DDIR_READ]),
410 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
411 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
413 .help = "Set block size range (in more detail than bs)",
416 .name = "bs_unaligned",
417 .alias = "blocksize_unaligned",
418 .type = FIO_OPT_STR_SET,
419 .off1 = td_var_offset(bs_unaligned),
420 .help = "Don't sector align IO buffer sizes",
424 .type = FIO_OPT_STR_VAL,
425 .off1 = td_var_offset(start_offset),
426 .help = "Start IO from this offset",
430 .name = "randrepeat",
431 .type = FIO_OPT_BOOL,
432 .off1 = td_var_offset(rand_repeatable),
433 .help = "Use repeatable random IO pattern",
437 .name = "norandommap",
438 .type = FIO_OPT_STR_SET,
439 .off1 = td_var_offset(norandommap),
440 .help = "Accept potential duplicate random blocks",
445 .off1 = td_var_offset(nr_files),
446 .help = "Split job workload between this number of files",
452 .off1 = td_var_offset(open_files),
453 .help = "Number of files to keep open at the same time",
456 .name = "file_service_type",
459 .off1 = td_var_offset(file_service_type),
460 .help = "How to select which file to service next",
464 .oval = FIO_FSERVICE_RANDOM,
465 .help = "Choose a file at random",
467 { .ival = "roundrobin",
468 .oval = FIO_FSERVICE_RR,
469 .help = "Round robin select files",
476 .off1 = td_var_offset(fsync_blocks),
477 .help = "Issue fsync for writes every given number of blocks",
482 .type = FIO_OPT_BOOL,
483 .off1 = td_var_offset(odirect),
484 .help = "Use O_DIRECT IO (negates buffered)",
489 .type = FIO_OPT_BOOL,
490 .off1 = td_var_offset(odirect),
492 .help = "Use buffered IO (negates direct)",
497 .type = FIO_OPT_BOOL,
498 .off1 = td_var_offset(overwrite),
499 .help = "When writing, set whether to overwrite current data",
505 .off1 = td_var_offset(loops),
506 .help = "Number of times to run the job",
512 .off1 = td_var_offset(numjobs),
513 .help = "Duplicate this job this many times",
517 .name = "startdelay",
519 .off1 = td_var_offset(start_delay),
520 .help = "Only start job when this period has passed",
526 .type = FIO_OPT_STR_VAL_TIME,
527 .off1 = td_var_offset(timeout),
528 .help = "Stop workload when this amount of time has passed",
532 .name = "time_based",
533 .type = FIO_OPT_STR_SET,
534 .off1 = td_var_offset(time_based),
535 .help = "Keep running until runtime/timeout is met",
542 .off1 = td_var_offset(mem_type),
543 .help = "Backing type for IO buffers",
548 .help = "Use malloc(3) for IO buffers",
552 .help = "Use shared memory segments for IO buffers",
554 #ifdef FIO_HAVE_HUGETLB
557 .help = "Like shm, but use huge pages",
562 .help = "Use mmap(2) (file or anon) for IO buffers",
564 #ifdef FIO_HAVE_HUGETLB
565 { .ival = "mmaphuge",
566 .oval = MEM_MMAPHUGE,
567 .help = "Like mmap, but use huge pages",
575 .off1 = td_var_offset(verify),
576 .help = "Verify data written",
581 .help = "Don't do IO verification",
585 .help = "Use md5 checksums for verification",
588 .oval = VERIFY_CRC64,
589 .help = "Use crc64 checksums for verification",
592 .oval = VERIFY_CRC32,
593 .help = "Use crc32 checksums for verification",
596 .oval = VERIFY_CRC16,
597 .help = "Use crc16 checksums for verification",
601 .help = "Use crc7 checksums for verification",
606 .help = "Pretend to verify",
611 .name = "verifysort",
612 .type = FIO_OPT_BOOL,
613 .off1 = td_var_offset(verifysort),
614 .help = "Sort written verify blocks for read back",
618 .name = "header_interval",
619 .type = FIO_OPT_STR_VAL_INT,
620 .off1 = td_var_offset(header_interval),
621 .help = "Store buffer header every N bytes",
625 .name = "header_offset",
626 .type = FIO_OPT_STR_VAL_INT,
627 .help = "Offset header location by N bytes",
629 .cb = str_header_offset_cb,
632 .name = "write_iolog",
633 .type = FIO_OPT_STR_STORE,
634 .off1 = td_var_offset(write_iolog_file),
635 .help = "Store IO pattern to file",
638 .name = "read_iolog",
639 .type = FIO_OPT_STR_STORE,
640 .off1 = td_var_offset(read_iolog_file),
641 .help = "Playback IO pattern from file",
644 .name = "exec_prerun",
645 .type = FIO_OPT_STR_STORE,
646 .off1 = td_var_offset(exec_prerun),
647 .help = "Execute this file prior to running job",
650 .name = "exec_postrun",
651 .type = FIO_OPT_STR_STORE,
652 .off1 = td_var_offset(exec_postrun),
653 .help = "Execute this file after running job",
655 #ifdef FIO_HAVE_IOSCHED_SWITCH
657 .name = "ioscheduler",
658 .type = FIO_OPT_STR_STORE,
659 .off1 = td_var_offset(ioscheduler),
660 .help = "Use this IO scheduler on the backing device",
665 .type = FIO_OPT_STR_VAL,
666 .off1 = td_var_offset(zone_size),
667 .help = "Give size of an IO zone",
672 .type = FIO_OPT_STR_VAL,
673 .off1 = td_var_offset(zone_skip),
674 .help = "Space between IO zones",
679 .type = FIO_OPT_STR_VAL,
680 .cb = str_lockmem_cb,
681 .help = "Lock down this amount of memory",
685 .name = "rwmixcycle",
687 .off1 = td_var_offset(rwmixcycle),
688 .help = "Cycle period for mixed read/write workloads (msec)",
694 .off1 = td_var_offset(rwmix[DDIR_READ]),
696 .help = "Percentage of mixed workload that is reads",
700 .name = "rwmixwrite",
702 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
704 .help = "Percentage of mixed workload that is writes",
710 .off1 = td_var_offset(nice),
711 .help = "Set job CPU nice value",
716 #ifdef FIO_HAVE_IOPRIO
721 .help = "Set job IO priority value",
728 .cb = str_prioclass_cb,
729 .help = "Set job IO priority class",
737 .off1 = td_var_offset(thinktime),
738 .help = "Idle time between IO buffers (usec)",
742 .name = "thinktime_spin",
744 .off1 = td_var_offset(thinktime_spin),
745 .help = "Start think time by spinning this amount (usec)",
749 .name = "thinktime_blocks",
751 .off1 = td_var_offset(thinktime_blocks),
752 .help = "IO buffer period between 'thinktime'",
758 .off1 = td_var_offset(rate),
759 .help = "Set bandwidth rate",
764 .off1 = td_var_offset(ratemin),
765 .help = "Job must meet this rate or it will be shutdown",
770 .off1 = td_var_offset(rate_iops),
771 .help = "Limit IO used to this number of IO operations/sec",
774 .name = "rate_iops_min",
776 .off1 = td_var_offset(rate_iops_min),
777 .help = "Job must meet this rate or it will be shutdown",
782 .off1 = td_var_offset(ratecycle),
783 .help = "Window average for rate limits (msec)",
787 .name = "invalidate",
788 .type = FIO_OPT_BOOL,
789 .off1 = td_var_offset(invalidate_cache),
790 .help = "Invalidate buffer/page cache prior to running job",
795 .type = FIO_OPT_BOOL,
796 .off1 = td_var_offset(sync_io),
797 .help = "Use O_SYNC for buffered writes",
803 .off1 = td_var_offset(bw_avg_time),
804 .help = "Time window over which to calculate bandwidth (msec)",
808 .name = "create_serialize",
809 .type = FIO_OPT_BOOL,
810 .off1 = td_var_offset(create_serialize),
811 .help = "Serialize creating of job files",
815 .name = "create_fsync",
816 .type = FIO_OPT_BOOL,
817 .off1 = td_var_offset(create_fsync),
818 .help = "Fsync file after creation",
824 .off1 = td_var_offset(cpuload),
825 .help = "Use this percentage of CPU",
830 .off1 = td_var_offset(cpucycle),
831 .help = "Length of the CPU burn cycles (usecs)",
834 #ifdef FIO_HAVE_CPU_AFFINITY
838 .cb = str_cpumask_cb,
839 .help = "CPU affinity mask",
842 .name = "cpus_allowed",
844 .cb = str_cpus_allowed_cb,
845 .help = "Set CPUs allowed",
850 .type = FIO_OPT_BOOL,
851 .off1 = td_var_offset(end_fsync),
852 .help = "Include fsync at the end of job",
856 .name = "fsync_on_close",
857 .type = FIO_OPT_BOOL,
858 .off1 = td_var_offset(fsync_on_close),
859 .help = "fsync files on close",
864 .type = FIO_OPT_BOOL,
865 .off1 = td_var_offset(unlink),
866 .help = "Unlink created files after job has completed",
871 .type = FIO_OPT_STR_SET,
872 .cb = str_exitall_cb,
873 .help = "Terminate all jobs when one exits",
877 .type = FIO_OPT_STR_SET,
878 .off1 = td_var_offset(stonewall),
879 .help = "Insert a hard barrier between this job and previous",
883 .type = FIO_OPT_STR_SET,
884 .off1 = td_var_offset(new_group),
885 .help = "Mark the start of a new group (for reporting)",
889 .type = FIO_OPT_STR_SET,
890 .off1 = td_var_offset(use_thread),
891 .help = "Use threads instead of forks",
894 .name = "write_bw_log",
895 .type = FIO_OPT_STR_SET,
896 .off1 = td_var_offset(write_bw_log),
897 .help = "Write log of bandwidth during run",
900 .name = "write_lat_log",
901 .type = FIO_OPT_STR_SET,
902 .off1 = td_var_offset(write_lat_log),
903 .help = "Write log of latency during run",
906 .name = "hugepage-size",
907 .type = FIO_OPT_STR_VAL,
908 .off1 = td_var_offset(hugepage_size),
909 .help = "When using hugepages, specify size of each page",
910 .def = __stringify(FIO_HUGE_PAGE),
913 .name = "group_reporting",
914 .type = FIO_OPT_STR_SET,
915 .off1 = td_var_offset(group_reporting),
916 .help = "Do reporting on a per-group basis",
919 .name = "zero_buffers",
920 .type = FIO_OPT_STR_SET,
921 .off1 = td_var_offset(zero_buffers),
922 .help = "Init IO buffers to all zeroes",
924 #ifdef FIO_HAVE_DISK_UTIL
927 .type = FIO_OPT_BOOL,
928 .off1 = td_var_offset(do_disk_util),
929 .help = "Log disk utilization stats",
938 void fio_options_dup_and_init(struct option *long_options)
940 struct fio_option *o;
943 options_init(options);
946 while (long_options[i].name)
951 long_options[i].name = o->name;
952 long_options[i].val = FIO_GETOPT_JOB;
953 if (o->type == FIO_OPT_STR_SET)
954 long_options[i].has_arg = no_argument;
956 long_options[i].has_arg = required_argument;
960 assert(i < FIO_NR_OPTIONS);
964 int fio_option_parse(struct thread_data *td, const char *opt)
966 return parse_option(opt, options, td);
969 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
971 return parse_cmd_option(opt, val, options, td);
974 void fio_fill_default_options(struct thread_data *td)
976 fill_default_options(td, options);
979 int fio_show_option_help(const char *opt)
981 return show_cmd_help(options, opt);
984 static void __options_mem(struct thread_data *td, int alloc)
986 struct thread_options *o = &td->o;
987 struct fio_option *opt;
991 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
992 if (opt->type != FIO_OPT_STR_STORE)
995 ptr = (void *) o + opt->off1;
1008 * dupe FIO_OPT_STR_STORE options
1010 void options_mem_dupe(struct thread_data *td)
1012 __options_mem(td, 1);
1015 void options_mem_free(struct thread_data fio_unused *td)
1018 __options_mem(td, 0);