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 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
103 #ifdef FIO_HAVE_CPU_AFFINITY
108 for (i = 0; i < sizeof(int) * 8; i++) {
110 CPU_SET(i, &cpumask);
115 static int str_cpumask_cb(void *data, unsigned int *val)
117 struct thread_data *td = data;
119 fill_cpu_mask(td->o.cpumask, *val);
123 static int str_fst_cb(void *data, const char *str)
125 struct thread_data *td = data;
126 char *nr = get_opt_postfix(str);
128 td->file_service_nr = 1;
130 td->file_service_nr = atoi(nr);
135 static int str_filename_cb(void *data, const char *input)
137 struct thread_data *td = data;
138 char *fname, *str, *p;
140 p = str = strdup(input);
142 strip_blank_front(&str);
143 strip_blank_end(str);
145 if (!td->files_index)
148 while ((fname = strsep(&str, ":")) != NULL) {
159 static int str_directory_cb(void *data, const char fio_unused *str)
161 struct thread_data *td = data;
164 if (lstat(td->o.directory, &sb) < 0) {
165 log_err("fio: %s is not a directory\n", td->o.directory);
166 td_verror(td, errno, "lstat");
169 if (!S_ISDIR(sb.st_mode)) {
170 log_err("fio: %s is not a directory\n", td->o.directory);
177 static int str_opendir_cb(void *data, const char fio_unused *str)
179 struct thread_data *td = data;
181 if (!td->files_index)
184 return add_dir_files(td, td->o.opendir);
188 #define __stringify_1(x) #x
189 #define __stringify(x) __stringify_1(x)
192 * Map of job/command line options
194 static struct fio_option options[] = {
196 .name = "description",
197 .type = FIO_OPT_STR_STORE,
198 .off1 = td_var_offset(description),
199 .help = "Text job description",
203 .type = FIO_OPT_STR_STORE,
204 .off1 = td_var_offset(name),
205 .help = "Name of this job",
209 .type = FIO_OPT_STR_STORE,
210 .off1 = td_var_offset(directory),
211 .cb = str_directory_cb,
212 .help = "Directory to store files in",
216 .type = FIO_OPT_STR_STORE,
217 .off1 = td_var_offset(filename),
218 .cb = str_filename_cb,
219 .help = "File(s) to use for the workload",
223 .type = FIO_OPT_STR_STORE,
224 .off1 = td_var_offset(opendir),
225 .cb = str_opendir_cb,
226 .help = "Recursively add files from this directory and down",
230 .alias = "readwrite",
233 .off1 = td_var_offset(td_ddir),
234 .help = "IO direction",
238 .oval = TD_DDIR_READ,
239 .help = "Sequential read",
242 .oval = TD_DDIR_WRITE,
243 .help = "Sequential write",
245 { .ival = "randread",
246 .oval = TD_DDIR_RANDREAD,
247 .help = "Random read",
249 { .ival = "randwrite",
250 .oval = TD_DDIR_RANDWRITE,
251 .help = "Random write",
255 .help = "Sequential read and write mix",
258 .oval = TD_DDIR_RANDRW,
259 .help = "Random read and write mix"
264 .name = "fadvise_hint",
265 .type = FIO_OPT_BOOL,
266 .off1 = td_var_offset(fadvise_hint),
267 .help = "Use fadvise() to advise the kernel on IO pattern",
272 .type = FIO_OPT_STR_STORE,
273 .off1 = td_var_offset(ioengine),
274 .help = "IO engine to use",
278 .help = "Use read/write",
280 #ifdef FIO_HAVE_LIBAIO
282 .help = "Linux native asynchronous IO",
285 #ifdef FIO_HAVE_POSIXAIO
286 { .ival = "posixaio",
287 .help = "POSIX asynchronous IO",
291 .help = "Memory mapped IO",
293 #ifdef FIO_HAVE_SPLICE
295 .help = "splice/vmsplice based IO",
300 .help = "SCSI generic v3 IO",
304 .help = "Testing engine (no data transfer)",
307 .help = "Network IO",
309 #ifdef FIO_HAVE_SYSLET
310 { .ival = "syslet-rw",
311 .help = "syslet enabled async pread/pwrite IO",
315 .help = "CPU cycler burner engine",
317 #ifdef FIO_HAVE_GUASI
319 .help = "GUASI IO engine",
322 { .ival = "external",
323 .help = "Load external engine (append name)",
330 .off1 = td_var_offset(iodepth),
331 .help = "Amount of IO buffers to keep in flight",
335 .name = "iodepth_batch",
337 .off1 = td_var_offset(iodepth_batch),
338 .help = "Number of IO to submit in one go",
341 .name = "iodepth_low",
343 .off1 = td_var_offset(iodepth_low),
344 .help = "Low water mark for queuing depth",
348 .type = FIO_OPT_STR_VAL,
349 .off1 = td_var_offset(size),
350 .help = "Total size of device or files",
354 .type = FIO_OPT_STR_VAL,
355 .off1 = td_var_offset(file_size_low),
356 .off2 = td_var_offset(file_size_high),
357 .help = "Size of individual files",
361 .alias = "blocksize",
362 .type = FIO_OPT_STR_VAL_INT,
363 .off1 = td_var_offset(bs[DDIR_READ]),
364 .off2 = td_var_offset(bs[DDIR_WRITE]),
365 .help = "Block size unit",
370 .alias = "blocksize_range",
371 .type = FIO_OPT_RANGE,
372 .off1 = td_var_offset(min_bs[DDIR_READ]),
373 .off2 = td_var_offset(max_bs[DDIR_READ]),
374 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
375 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
376 .help = "Set block size range (in more detail than bs)",
379 .name = "bs_unaligned",
380 .alias = "blocksize_unaligned",
381 .type = FIO_OPT_STR_SET,
382 .off1 = td_var_offset(bs_unaligned),
383 .help = "Don't sector align IO buffer sizes",
387 .type = FIO_OPT_STR_VAL,
388 .off1 = td_var_offset(start_offset),
389 .help = "Start IO from this offset",
393 .name = "randrepeat",
394 .type = FIO_OPT_BOOL,
395 .off1 = td_var_offset(rand_repeatable),
396 .help = "Use repeatable random IO pattern",
400 .name = "norandommap",
401 .type = FIO_OPT_STR_SET,
402 .off1 = td_var_offset(norandommap),
403 .help = "Accept potential duplicate random blocks",
408 .off1 = td_var_offset(nr_files),
409 .help = "Split job workload between this number of files",
415 .off1 = td_var_offset(open_files),
416 .help = "Number of files to keep open at the same time",
419 .name = "file_service_type",
422 .off1 = td_var_offset(file_service_type),
423 .help = "How to select which file to service next",
427 .oval = FIO_FSERVICE_RANDOM,
428 .help = "Choose a file at random",
430 { .ival = "roundrobin",
431 .oval = FIO_FSERVICE_RR,
432 .help = "Round robin select files",
439 .off1 = td_var_offset(fsync_blocks),
440 .help = "Issue fsync for writes every given number of blocks",
445 .type = FIO_OPT_BOOL,
446 .off1 = td_var_offset(odirect),
447 .help = "Use O_DIRECT IO (negates buffered)",
452 .type = FIO_OPT_BOOL,
453 .off1 = td_var_offset(odirect),
455 .help = "Use buffered IO (negates direct)",
460 .type = FIO_OPT_BOOL,
461 .off1 = td_var_offset(overwrite),
462 .help = "When writing, set whether to overwrite current data",
468 .off1 = td_var_offset(loops),
469 .help = "Number of times to run the job",
475 .off1 = td_var_offset(numjobs),
476 .help = "Duplicate this job this many times",
480 .name = "startdelay",
482 .off1 = td_var_offset(start_delay),
483 .help = "Only start job when this period has passed",
489 .type = FIO_OPT_STR_VAL_TIME,
490 .off1 = td_var_offset(timeout),
491 .help = "Stop workload when this amount of time has passed",
495 .name = "time_based",
496 .type = FIO_OPT_STR_SET,
497 .off1 = td_var_offset(time_based),
498 .help = "Keep running until runtime/timeout is met",
505 .off1 = td_var_offset(mem_type),
506 .help = "Backing type for IO buffers",
511 .help = "Use malloc(3) for IO buffers",
515 .help = "Use shared memory segments for IO buffers",
517 #ifdef FIO_HAVE_HUGETLB
520 .help = "Like shm, but use huge pages",
525 .help = "Use mmap(2) (file or anon) for IO buffers",
527 #ifdef FIO_HAVE_HUGETLB
528 { .ival = "mmaphuge",
529 .oval = MEM_MMAPHUGE,
530 .help = "Like mmap, but use huge pages",
538 .off1 = td_var_offset(verify),
539 .help = "Verify data written",
544 .help = "Don't do IO verification",
547 .oval = VERIFY_CRC32,
548 .help = "Use crc32 checksums for verification",
552 .help = "Use md5 checksums for verification",
557 .help = "Pretend to verify",
562 .name = "verifysort",
563 .type = FIO_OPT_BOOL,
564 .off1 = td_var_offset(verifysort),
565 .help = "Sort written verify blocks for read back",
569 .name = "write_iolog",
570 .type = FIO_OPT_STR_STORE,
571 .off1 = td_var_offset(write_iolog_file),
572 .help = "Store IO pattern to file",
575 .name = "read_iolog",
576 .type = FIO_OPT_STR_STORE,
577 .off1 = td_var_offset(read_iolog_file),
578 .help = "Playback IO pattern from file",
581 .name = "exec_prerun",
582 .type = FIO_OPT_STR_STORE,
583 .off1 = td_var_offset(exec_prerun),
584 .help = "Execute this file prior to running job",
587 .name = "exec_postrun",
588 .type = FIO_OPT_STR_STORE,
589 .off1 = td_var_offset(exec_postrun),
590 .help = "Execute this file after running job",
592 #ifdef FIO_HAVE_IOSCHED_SWITCH
594 .name = "ioscheduler",
595 .type = FIO_OPT_STR_STORE,
596 .off1 = td_var_offset(ioscheduler),
597 .help = "Use this IO scheduler on the backing device",
602 .type = FIO_OPT_STR_VAL,
603 .off1 = td_var_offset(zone_size),
604 .help = "Give size of an IO zone",
609 .type = FIO_OPT_STR_VAL,
610 .off1 = td_var_offset(zone_skip),
611 .help = "Space between IO zones",
616 .type = FIO_OPT_STR_VAL,
617 .cb = str_lockmem_cb,
618 .help = "Lock down this amount of memory",
622 .name = "rwmixcycle",
624 .off1 = td_var_offset(rwmixcycle),
625 .help = "Cycle period for mixed read/write workloads (msec)",
631 .off1 = td_var_offset(rwmix[DDIR_READ]),
633 .help = "Percentage of mixed workload that is reads",
637 .name = "rwmixwrite",
639 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
641 .help = "Percentage of mixed workload that is writes",
647 .off1 = td_var_offset(nice),
648 .help = "Set job CPU nice value",
653 #ifdef FIO_HAVE_IOPRIO
658 .help = "Set job IO priority value",
665 .cb = str_prioclass_cb,
666 .help = "Set job IO priority class",
674 .off1 = td_var_offset(thinktime),
675 .help = "Idle time between IO buffers (usec)",
679 .name = "thinktime_spin",
681 .off1 = td_var_offset(thinktime_spin),
682 .help = "Start think time by spinning this amount (usec)",
686 .name = "thinktime_blocks",
688 .off1 = td_var_offset(thinktime_blocks),
689 .help = "IO buffer period between 'thinktime'",
695 .off1 = td_var_offset(rate),
696 .help = "Set bandwidth rate",
701 .off1 = td_var_offset(ratemin),
702 .help = "Job must meet this rate or it will be shutdown",
707 .off1 = td_var_offset(rate_iops),
708 .help = "Limit IO used to this number of IO operations/sec",
711 .name = "rate_iops_min",
713 .off1 = td_var_offset(rate_iops_min),
714 .help = "Job must meet this rate or it will be shutdown",
719 .off1 = td_var_offset(ratecycle),
720 .help = "Window average for rate limits (msec)",
724 .name = "invalidate",
725 .type = FIO_OPT_BOOL,
726 .off1 = td_var_offset(invalidate_cache),
727 .help = "Invalidate buffer/page cache prior to running job",
732 .type = FIO_OPT_BOOL,
733 .off1 = td_var_offset(sync_io),
734 .help = "Use O_SYNC for buffered writes",
740 .off1 = td_var_offset(bw_avg_time),
741 .help = "Time window over which to calculate bandwidth (msec)",
745 .name = "create_serialize",
746 .type = FIO_OPT_BOOL,
747 .off1 = td_var_offset(create_serialize),
748 .help = "Serialize creating of job files",
752 .name = "create_fsync",
753 .type = FIO_OPT_BOOL,
754 .off1 = td_var_offset(create_fsync),
755 .help = "Fsync file after creation",
761 .off1 = td_var_offset(cpuload),
762 .help = "Use this percentage of CPU",
767 .off1 = td_var_offset(cpucycle),
768 .help = "Length of the CPU burn cycles (usecs)",
771 #ifdef FIO_HAVE_CPU_AFFINITY
775 .cb = str_cpumask_cb,
776 .help = "CPU affinity mask",
781 .type = FIO_OPT_BOOL,
782 .off1 = td_var_offset(end_fsync),
783 .help = "Include fsync at the end of job",
787 .name = "fsync_on_close",
788 .type = FIO_OPT_BOOL,
789 .off1 = td_var_offset(fsync_on_close),
790 .help = "fsync files on close",
795 .type = FIO_OPT_BOOL,
796 .off1 = td_var_offset(unlink),
797 .help = "Unlink created files after job has completed",
802 .type = FIO_OPT_STR_SET,
803 .cb = str_exitall_cb,
804 .help = "Terminate all jobs when one exits",
808 .type = FIO_OPT_STR_SET,
809 .off1 = td_var_offset(stonewall),
810 .help = "Insert a hard barrier between this job and previous",
814 .type = FIO_OPT_STR_SET,
815 .off1 = td_var_offset(new_group),
816 .help = "Mark the start of a new group (for reporting)",
820 .type = FIO_OPT_STR_SET,
821 .off1 = td_var_offset(use_thread),
822 .help = "Use threads instead of forks",
825 .name = "write_bw_log",
826 .type = FIO_OPT_STR_SET,
827 .off1 = td_var_offset(write_bw_log),
828 .help = "Write log of bandwidth during run",
831 .name = "write_lat_log",
832 .type = FIO_OPT_STR_SET,
833 .off1 = td_var_offset(write_lat_log),
834 .help = "Write log of latency during run",
837 .name = "hugepage-size",
838 .type = FIO_OPT_STR_VAL,
839 .off1 = td_var_offset(hugepage_size),
840 .help = "When using hugepages, specify size of each page",
841 .def = __stringify(FIO_HUGE_PAGE),
844 .name = "group_reporting",
845 .type = FIO_OPT_STR_SET,
846 .off1 = td_var_offset(group_reporting),
847 .help = "Do reporting on a per-group basis",
850 .name = "zero_buffers",
851 .type = FIO_OPT_STR_SET,
852 .off1 = td_var_offset(zero_buffers),
853 .help = "Init IO buffers to all zeroes",
855 #ifdef FIO_HAVE_DISK_UTIL
858 .type = FIO_OPT_BOOL,
859 .off1 = td_var_offset(do_disk_util),
860 .help = "Log disk utilization stats",
869 void fio_options_dup_and_init(struct option *long_options)
871 struct fio_option *o;
874 options_init(options);
877 while (long_options[i].name)
882 long_options[i].name = o->name;
883 long_options[i].val = FIO_GETOPT_JOB;
884 if (o->type == FIO_OPT_STR_SET)
885 long_options[i].has_arg = no_argument;
887 long_options[i].has_arg = required_argument;
891 assert(i < FIO_NR_OPTIONS);
895 int fio_option_parse(struct thread_data *td, const char *opt)
897 return parse_option(opt, options, td);
900 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
902 return parse_cmd_option(opt, val, options, td);
905 void fio_fill_default_options(struct thread_data *td)
907 fill_default_options(td, options);
910 int fio_show_option_help(const char *opt)
912 return show_cmd_help(options, opt);
915 static void __options_mem(struct thread_data *td, int alloc)
917 struct thread_options *o = &td->o;
918 struct fio_option *opt;
922 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
923 if (opt->type != FIO_OPT_STR_STORE)
926 ptr = (void *) o + opt->off1;
939 * dupe FIO_OPT_STR_STORE options
941 void options_mem_dupe(struct thread_data *td)
943 __options_mem(td, 1);
946 void options_mem_free(struct thread_data fio_unused *td)
949 __options_mem(td, 0);