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;
68 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
72 static int str_prio_cb(void *data, unsigned int *val)
74 struct thread_data *td = data;
81 static int str_exitall_cb(void)
83 exitall_on_terminate = 1;
87 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
89 #ifdef FIO_HAVE_CPU_AFFINITY
94 for (i = 0; i < sizeof(int) * 8; i++) {
101 static int str_cpumask_cb(void *data, unsigned int *val)
103 struct thread_data *td = data;
105 fill_cpu_mask(td->o.cpumask, *val);
109 static int str_fst_cb(void *data, const char *str)
111 struct thread_data *td = data;
112 char *nr = get_opt_postfix(str);
114 td->file_service_nr = 1;
116 td->file_service_nr = atoi(nr);
121 static int str_filename_cb(void *data, const char *input)
123 struct thread_data *td = data;
124 char *fname, *str, *p;
126 p = str = strdup(input);
128 strip_blank_front(&str);
129 strip_blank_end(str);
131 if (!td->files_index)
134 while ((fname = strsep(&str, ":")) != NULL) {
145 static int str_directory_cb(void *data, const char fio_unused *str)
147 struct thread_data *td = data;
150 if (lstat(td->o.directory, &sb) < 0) {
151 log_err("fio: %s is not a directory\n", td->o.directory);
152 td_verror(td, errno, "lstat");
155 if (!S_ISDIR(sb.st_mode)) {
156 log_err("fio: %s is not a directory\n", td->o.directory);
163 static int str_opendir_cb(void *data, const char fio_unused *str)
165 struct thread_data *td = data;
167 if (!td->files_index)
170 return add_dir_files(td, td->o.opendir);
174 #define __stringify_1(x) #x
175 #define __stringify(x) __stringify_1(x)
178 * Map of job/command line options
180 static struct fio_option options[] = {
182 .name = "description",
183 .type = FIO_OPT_STR_STORE,
184 .off1 = td_var_offset(description),
185 .help = "Text job description",
189 .type = FIO_OPT_STR_STORE,
190 .off1 = td_var_offset(name),
191 .help = "Name of this job",
195 .type = FIO_OPT_STR_STORE,
196 .off1 = td_var_offset(directory),
197 .cb = str_directory_cb,
198 .help = "Directory to store files in",
202 .type = FIO_OPT_STR_STORE,
203 .off1 = td_var_offset(filename),
204 .cb = str_filename_cb,
205 .help = "File(s) to use for the workload",
209 .type = FIO_OPT_STR_STORE,
210 .off1 = td_var_offset(opendir),
211 .cb = str_opendir_cb,
212 .help = "Recursively add files from this directory and down",
216 .alias = "readwrite",
219 .off1 = td_var_offset(td_ddir),
220 .help = "IO direction",
224 .oval = TD_DDIR_READ,
225 .help = "Sequential read",
228 .oval = TD_DDIR_WRITE,
229 .help = "Sequential write",
231 { .ival = "randread",
232 .oval = TD_DDIR_RANDREAD,
233 .help = "Random read",
235 { .ival = "randwrite",
236 .oval = TD_DDIR_RANDWRITE,
237 .help = "Random write",
241 .help = "Sequential read and write mix",
244 .oval = TD_DDIR_RANDRW,
245 .help = "Random read and write mix"
251 .type = FIO_OPT_STR_STORE,
252 .off1 = td_var_offset(ioengine),
253 .help = "IO engine to use",
257 .help = "Use read/write",
259 #ifdef FIO_HAVE_LIBAIO
261 .help = "Linux native asynchronous IO",
264 #ifdef FIO_HAVE_POSIXAIO
265 { .ival = "posixaio",
266 .help = "POSIX asynchronous IO",
270 .help = "Memory mapped IO",
272 #ifdef FIO_HAVE_SPLICE
274 .help = "splice/vmsplice based IO",
279 .help = "SCSI generic v3 IO",
283 .help = "Testing engine (no data transfer)",
286 .help = "Network IO",
288 #ifdef FIO_HAVE_SYSLET
289 { .ival = "syslet-rw",
290 .help = "syslet enabled async pread/pwrite IO",
294 .help = "CPU cycler burner engine",
296 #ifdef FIO_HAVE_GUASI
298 .help = "GUASI IO engine",
301 { .ival = "external",
302 .help = "Load external engine (append name)",
309 .off1 = td_var_offset(iodepth),
310 .help = "Amount of IO buffers to keep in flight",
314 .name = "iodepth_batch",
316 .off1 = td_var_offset(iodepth_batch),
317 .help = "Number of IO to submit in one go",
320 .name = "iodepth_low",
322 .off1 = td_var_offset(iodepth_low),
323 .help = "Low water mark for queuing depth",
327 .type = FIO_OPT_STR_VAL,
328 .off1 = td_var_offset(size),
329 .help = "Total size of device or files",
333 .type = FIO_OPT_STR_VAL,
334 .off1 = td_var_offset(file_size_low),
335 .off2 = td_var_offset(file_size_high),
336 .help = "Size of individual files",
340 .alias = "blocksize",
341 .type = FIO_OPT_STR_VAL_INT,
342 .off1 = td_var_offset(bs[DDIR_READ]),
343 .off2 = td_var_offset(bs[DDIR_WRITE]),
344 .help = "Block size unit",
349 .alias = "blocksize_range",
350 .type = FIO_OPT_RANGE,
351 .off1 = td_var_offset(min_bs[DDIR_READ]),
352 .off2 = td_var_offset(max_bs[DDIR_READ]),
353 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
354 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
355 .help = "Set block size range (in more detail than bs)",
358 .name = "bs_unaligned",
359 .alias = "blocksize_unaligned",
360 .type = FIO_OPT_STR_SET,
361 .off1 = td_var_offset(bs_unaligned),
362 .help = "Don't sector align IO buffer sizes",
366 .type = FIO_OPT_STR_VAL,
367 .off1 = td_var_offset(start_offset),
368 .help = "Start IO from this offset",
372 .name = "randrepeat",
373 .type = FIO_OPT_BOOL,
374 .off1 = td_var_offset(rand_repeatable),
375 .help = "Use repeatable random IO pattern",
379 .name = "norandommap",
380 .type = FIO_OPT_STR_SET,
381 .off1 = td_var_offset(norandommap),
382 .help = "Accept potential duplicate random blocks",
387 .off1 = td_var_offset(nr_files),
388 .help = "Split job workload between this number of files",
394 .off1 = td_var_offset(open_files),
395 .help = "Number of files to keep open at the same time",
398 .name = "file_service_type",
401 .off1 = td_var_offset(file_service_type),
402 .help = "How to select which file to service next",
406 .oval = FIO_FSERVICE_RANDOM,
407 .help = "Choose a file at random",
409 { .ival = "roundrobin",
410 .oval = FIO_FSERVICE_RR,
411 .help = "Round robin select files",
418 .off1 = td_var_offset(fsync_blocks),
419 .help = "Issue fsync for writes every given number of blocks",
424 .type = FIO_OPT_BOOL,
425 .off1 = td_var_offset(odirect),
426 .help = "Use O_DIRECT IO (negates buffered)",
431 .type = FIO_OPT_BOOL,
432 .off1 = td_var_offset(odirect),
434 .help = "Use buffered IO (negates direct)",
439 .type = FIO_OPT_BOOL,
440 .off1 = td_var_offset(overwrite),
441 .help = "When writing, set whether to overwrite current data",
447 .off1 = td_var_offset(loops),
448 .help = "Number of times to run the job",
454 .off1 = td_var_offset(numjobs),
455 .help = "Duplicate this job this many times",
459 .name = "startdelay",
461 .off1 = td_var_offset(start_delay),
462 .help = "Only start job when this period has passed",
468 .type = FIO_OPT_STR_VAL_TIME,
469 .off1 = td_var_offset(timeout),
470 .help = "Stop workload when this amount of time has passed",
478 .off1 = td_var_offset(mem_type),
479 .help = "Backing type for IO buffers",
484 .help = "Use malloc(3) for IO buffers",
488 .help = "Use shared memory segments for IO buffers",
490 #ifdef FIO_HAVE_HUGETLB
493 .help = "Like shm, but use huge pages",
498 .help = "Use mmap(2) (file or anon) for IO buffers",
500 #ifdef FIO_HAVE_HUGETLB
501 { .ival = "mmaphuge",
502 .oval = MEM_MMAPHUGE,
503 .help = "Like mmap, but use huge pages",
511 .off1 = td_var_offset(verify),
512 .help = "Verify data written",
517 .help = "Don't do IO verification",
520 .oval = VERIFY_CRC32,
521 .help = "Use crc32 checksums for verification",
525 .help = "Use md5 checksums for verification",
530 .name = "write_iolog",
531 .type = FIO_OPT_STR_STORE,
532 .off1 = td_var_offset(write_iolog_file),
533 .help = "Store IO pattern to file",
536 .name = "read_iolog",
537 .type = FIO_OPT_STR_STORE,
538 .off1 = td_var_offset(read_iolog_file),
539 .help = "Playback IO pattern from file",
542 .name = "exec_prerun",
543 .type = FIO_OPT_STR_STORE,
544 .off1 = td_var_offset(exec_prerun),
545 .help = "Execute this file prior to running job",
548 .name = "exec_postrun",
549 .type = FIO_OPT_STR_STORE,
550 .off1 = td_var_offset(exec_postrun),
551 .help = "Execute this file after running job",
553 #ifdef FIO_HAVE_IOSCHED_SWITCH
555 .name = "ioscheduler",
556 .type = FIO_OPT_STR_STORE,
557 .off1 = td_var_offset(ioscheduler),
558 .help = "Use this IO scheduler on the backing device",
563 .type = FIO_OPT_STR_VAL,
564 .off1 = td_var_offset(zone_size),
565 .help = "Give size of an IO zone",
570 .type = FIO_OPT_STR_VAL,
571 .off1 = td_var_offset(zone_skip),
572 .help = "Space between IO zones",
577 .type = FIO_OPT_STR_VAL,
578 .cb = str_lockmem_cb,
579 .help = "Lock down this amount of memory",
583 .name = "rwmixcycle",
585 .off1 = td_var_offset(rwmixcycle),
586 .help = "Cycle period for mixed read/write workloads (msec)",
592 .off1 = td_var_offset(rwmix[DDIR_READ]),
594 .help = "Percentage of mixed workload that is reads",
598 .name = "rwmixwrite",
600 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
602 .help = "Percentage of mixed workload that is writes",
608 .off1 = td_var_offset(nice),
609 .help = "Set job CPU nice value",
614 #ifdef FIO_HAVE_IOPRIO
619 .help = "Set job IO priority value",
626 .cb = str_prioclass_cb,
627 .help = "Set job IO priority class",
635 .off1 = td_var_offset(thinktime),
636 .help = "Idle time between IO buffers (usec)",
640 .name = "thinktime_spin",
642 .off1 = td_var_offset(thinktime_spin),
643 .help = "Start think time by spinning this amount (usec)",
647 .name = "thinktime_blocks",
649 .off1 = td_var_offset(thinktime_blocks),
650 .help = "IO buffer period between 'thinktime'",
656 .off1 = td_var_offset(rate),
657 .help = "Set bandwidth rate",
662 .off1 = td_var_offset(ratemin),
663 .help = "Job must meet this rate or it will be shutdown",
668 .off1 = td_var_offset(rate_iops),
669 .help = "Limit IO used to this number of IO operations/sec",
672 .name = "rate_iops_min",
674 .off1 = td_var_offset(rate_iops_min),
675 .help = "Job must meet this rate or it will be shutdown",
680 .off1 = td_var_offset(ratecycle),
681 .help = "Window average for rate limits (msec)",
685 .name = "invalidate",
686 .type = FIO_OPT_BOOL,
687 .off1 = td_var_offset(invalidate_cache),
688 .help = "Invalidate buffer/page cache prior to running job",
693 .type = FIO_OPT_BOOL,
694 .off1 = td_var_offset(sync_io),
695 .help = "Use O_SYNC for buffered writes",
701 .off1 = td_var_offset(bw_avg_time),
702 .help = "Time window over which to calculate bandwidth (msec)",
706 .name = "create_serialize",
707 .type = FIO_OPT_BOOL,
708 .off1 = td_var_offset(create_serialize),
709 .help = "Serialize creating of job files",
713 .name = "create_fsync",
714 .type = FIO_OPT_BOOL,
715 .off1 = td_var_offset(create_fsync),
716 .help = "Fsync file after creation",
722 .off1 = td_var_offset(cpuload),
723 .help = "Use this percentage of CPU",
728 .off1 = td_var_offset(cpucycle),
729 .help = "Length of the CPU burn cycles (usecs)",
732 #ifdef FIO_HAVE_CPU_AFFINITY
736 .cb = str_cpumask_cb,
737 .help = "CPU affinity mask",
742 .type = FIO_OPT_BOOL,
743 .off1 = td_var_offset(end_fsync),
744 .help = "Include fsync at the end of job",
748 .name = "fsync_on_close",
749 .type = FIO_OPT_BOOL,
750 .off1 = td_var_offset(fsync_on_close),
751 .help = "fsync files on close",
756 .type = FIO_OPT_BOOL,
757 .off1 = td_var_offset(unlink),
758 .help = "Unlink created files after job has completed",
763 .type = FIO_OPT_STR_SET,
764 .cb = str_exitall_cb,
765 .help = "Terminate all jobs when one exits",
769 .type = FIO_OPT_STR_SET,
770 .off1 = td_var_offset(stonewall),
771 .help = "Insert a hard barrier between this job and previous",
775 .type = FIO_OPT_STR_SET,
776 .off1 = td_var_offset(new_group),
777 .help = "Mark the start of a new group (for reporting)",
781 .type = FIO_OPT_STR_SET,
782 .off1 = td_var_offset(use_thread),
783 .help = "Use threads instead of forks",
786 .name = "write_bw_log",
787 .type = FIO_OPT_STR_SET,
788 .off1 = td_var_offset(write_bw_log),
789 .help = "Write log of bandwidth during run",
792 .name = "write_lat_log",
793 .type = FIO_OPT_STR_SET,
794 .off1 = td_var_offset(write_lat_log),
795 .help = "Write log of latency during run",
798 .name = "hugepage-size",
799 .type = FIO_OPT_STR_VAL,
800 .off1 = td_var_offset(hugepage_size),
801 .help = "When using hugepages, specify size of each page",
802 .def = __stringify(FIO_HUGE_PAGE),
805 .name = "group_reporting",
806 .type = FIO_OPT_STR_SET,
807 .off1 = td_var_offset(group_reporting),
808 .help = "Do reporting on a per-group basis",
815 void fio_options_dup_and_init(struct option *long_options)
817 struct fio_option *o;
820 options_init(options);
823 while (long_options[i].name)
828 long_options[i].name = o->name;
829 long_options[i].val = FIO_GETOPT_JOB;
830 if (o->type == FIO_OPT_STR_SET)
831 long_options[i].has_arg = no_argument;
833 long_options[i].has_arg = required_argument;
837 assert(i < FIO_NR_OPTIONS);
841 int fio_option_parse(struct thread_data *td, const char *opt)
843 return parse_option(opt, options, td);
846 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
848 return parse_cmd_option(opt, val, options, td);
851 void fio_fill_default_options(struct thread_data *td)
853 fill_default_options(td, options);
856 int fio_show_option_help(const char *opt)
858 return show_cmd_help(options, opt);