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_mem_cb(void *data, const char *mem)
32 struct thread_data *td = data;
34 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
35 td->mmapfile = get_opt_postfix(mem);
36 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
37 log_err("fio: mmaphuge:/path/to/file\n");
45 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
51 #ifdef FIO_HAVE_IOPRIO
52 static int str_prioclass_cb(void *data, unsigned int *val)
54 struct thread_data *td = data;
56 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
60 static int str_prio_cb(void *data, unsigned int *val)
62 struct thread_data *td = data;
69 static int str_exitall_cb(void)
71 exitall_on_terminate = 1;
75 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
77 #ifdef FIO_HAVE_CPU_AFFINITY
82 for (i = 0; i < sizeof(int) * 8; i++) {
89 static int str_cpumask_cb(void *data, unsigned int *val)
91 struct thread_data *td = data;
93 fill_cpu_mask(td->o.cpumask, *val);
97 static int str_fst_cb(void *data, const char *str)
99 struct thread_data *td = data;
100 char *nr = get_opt_postfix(str);
102 td->file_service_nr = 1;
104 td->file_service_nr = atoi(nr);
109 static int str_filename_cb(void *data, const char *input)
111 struct thread_data *td = data;
112 char *fname, *str, *p;
114 p = str = strdup(input);
116 strip_blank_front(&str);
117 strip_blank_end(str);
119 if (!td->files_index)
122 while ((fname = strsep(&str, ":")) != NULL) {
133 static int str_directory_cb(void *data, const char fio_unused *str)
135 struct thread_data *td = data;
138 if (lstat(td->o.directory, &sb) < 0) {
139 log_err("fio: %s is not a directory\n", td->o.directory);
140 td_verror(td, errno, "lstat");
143 if (!S_ISDIR(sb.st_mode)) {
144 log_err("fio: %s is not a directory\n", td->o.directory);
151 static int str_opendir_cb(void *data, const char fio_unused *str)
153 struct thread_data *td = data;
155 if (!td->files_index)
158 return add_dir_files(td, td->o.opendir);
162 #define __stringify_1(x) #x
163 #define __stringify(x) __stringify_1(x)
166 * Map of job/command line options
168 static struct fio_option options[] = {
170 .name = "description",
171 .type = FIO_OPT_STR_STORE,
172 .off1 = td_var_offset(description),
173 .help = "Text job description",
177 .type = FIO_OPT_STR_STORE,
178 .off1 = td_var_offset(name),
179 .help = "Name of this job",
183 .type = FIO_OPT_STR_STORE,
184 .off1 = td_var_offset(directory),
185 .cb = str_directory_cb,
186 .help = "Directory to store files in",
190 .type = FIO_OPT_STR_STORE,
191 .off1 = td_var_offset(filename),
192 .cb = str_filename_cb,
193 .help = "File(s) to use for the workload",
197 .type = FIO_OPT_STR_STORE,
198 .off1 = td_var_offset(opendir),
199 .cb = str_opendir_cb,
200 .help = "Recursively add files from this directory and down",
204 .alias = "readwrite",
206 .off1 = td_var_offset(td_ddir),
207 .help = "IO direction",
211 .oval = TD_DDIR_READ,
212 .help = "Sequential read",
215 .oval = TD_DDIR_WRITE,
216 .help = "Sequential write",
218 { .ival = "randread",
219 .oval = TD_DDIR_RANDREAD,
220 .help = "Random read",
222 { .ival = "randwrite",
223 .oval = TD_DDIR_RANDWRITE,
224 .help = "Random write",
228 .help = "Sequential read and write mix",
231 .oval = TD_DDIR_RANDRW,
232 .help = "Random read and write mix"
238 .type = FIO_OPT_STR_STORE,
239 .off1 = td_var_offset(ioengine),
240 .help = "IO engine to use",
244 .help = "Use read/write",
246 #ifdef FIO_HAVE_LIBAIO
248 .help = "Linux native asynchronous IO",
251 #ifdef FIO_HAVE_POSIXAIO
252 { .ival = "posixaio",
253 .help = "POSIX asynchronous IO",
257 .help = "Memory mapped IO",
259 #ifdef FIO_HAVE_SPLICE
261 .help = "splice/vmsplice based IO",
266 .help = "SCSI generic v3 IO",
270 .help = "Testing engine (no data transfer)",
273 .help = "Network IO",
275 #ifdef FIO_HAVE_SYSLET
276 { .ival = "syslet-rw",
277 .help = "syslet enabled async pread/pwrite IO",
281 .help = "CPU cycler burner engine",
283 { .ival = "external",
284 .help = "Load external engine (append name)",
291 .off1 = td_var_offset(iodepth),
292 .help = "Amount of IO buffers to keep in flight",
296 .name = "iodepth_batch",
298 .off1 = td_var_offset(iodepth_batch),
299 .help = "Number of IO to submit in one go",
302 .name = "iodepth_low",
304 .off1 = td_var_offset(iodepth_low),
305 .help = "Low water mark for queuing depth",
309 .type = FIO_OPT_STR_VAL,
310 .off1 = td_var_offset(size),
311 .help = "Total size of device or files",
315 .type = FIO_OPT_STR_VAL,
316 .off1 = td_var_offset(file_size_low),
317 .off2 = td_var_offset(file_size_high),
318 .help = "Size of individual files",
322 .alias = "blocksize",
323 .type = FIO_OPT_STR_VAL_INT,
324 .off1 = td_var_offset(bs[DDIR_READ]),
325 .off2 = td_var_offset(bs[DDIR_WRITE]),
326 .help = "Block size unit",
331 .alias = "blocksize_range",
332 .type = FIO_OPT_RANGE,
333 .off1 = td_var_offset(min_bs[DDIR_READ]),
334 .off2 = td_var_offset(max_bs[DDIR_READ]),
335 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
336 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
337 .help = "Set block size range (in more detail than bs)",
340 .name = "bs_unaligned",
341 .alias = "blocksize_unaligned",
342 .type = FIO_OPT_STR_SET,
343 .off1 = td_var_offset(bs_unaligned),
344 .help = "Don't sector align IO buffer sizes",
348 .type = FIO_OPT_STR_VAL,
349 .off1 = td_var_offset(start_offset),
350 .help = "Start IO from this offset",
354 .name = "randrepeat",
355 .type = FIO_OPT_BOOL,
356 .off1 = td_var_offset(rand_repeatable),
357 .help = "Use repeatable random IO pattern",
361 .name = "norandommap",
362 .type = FIO_OPT_STR_SET,
363 .off1 = td_var_offset(norandommap),
364 .help = "Accept potential duplicate random blocks",
369 .off1 = td_var_offset(nr_files),
370 .help = "Split job workload between this number of files",
376 .off1 = td_var_offset(open_files),
377 .help = "Number of files to keep open at the same time",
380 .name = "file_service_type",
383 .off1 = td_var_offset(file_service_type),
384 .help = "How to select which file to service next",
388 .oval = FIO_FSERVICE_RANDOM,
389 .help = "Choose a file at random",
391 { .ival = "roundrobin",
392 .oval = FIO_FSERVICE_RR,
393 .help = "Round robin select files",
400 .off1 = td_var_offset(fsync_blocks),
401 .help = "Issue fsync for writes every given number of blocks",
406 .type = FIO_OPT_BOOL,
407 .off1 = td_var_offset(odirect),
408 .help = "Use O_DIRECT IO (negates buffered)",
413 .type = FIO_OPT_BOOL,
414 .off1 = td_var_offset(odirect),
416 .help = "Use buffered IO (negates direct)",
421 .type = FIO_OPT_BOOL,
422 .off1 = td_var_offset(overwrite),
423 .help = "When writing, set whether to overwrite current data",
429 .off1 = td_var_offset(loops),
430 .help = "Number of times to run the job",
436 .off1 = td_var_offset(numjobs),
437 .help = "Duplicate this job this many times",
441 .name = "startdelay",
443 .off1 = td_var_offset(start_delay),
444 .help = "Only start job when this period has passed",
450 .type = FIO_OPT_STR_VAL_TIME,
451 .off1 = td_var_offset(timeout),
452 .help = "Stop workload when this amount of time has passed",
460 .off1 = td_var_offset(mem_type),
461 .help = "Backing type for IO buffers",
466 .help = "Use malloc(3) for IO buffers",
468 #ifdef FIO_HAVE_HUGETLB
471 .help = "Like shm, but use huge pages",
475 .help = "Use shared memory segments for IO buffers",
478 #ifdef FIO_HAVE_HUGETLB
479 { .ival = "mmaphuge",
480 .oval = MEM_MMAPHUGE,
481 .help = "Like mmap, but use huge pages",
486 .help = "Use mmap(2) (file or anon) for IO buffers",
493 .off1 = td_var_offset(verify),
494 .help = "Verify data written",
499 .help = "Don't do IO verification",
502 .oval = VERIFY_CRC32,
503 .help = "Use crc32 checksums for verification",
507 .help = "Use md5 checksums for verification",
512 .name = "write_iolog",
513 .type = FIO_OPT_STR_STORE,
514 .off1 = td_var_offset(write_iolog_file),
515 .help = "Store IO pattern to file",
518 .name = "read_iolog",
519 .type = FIO_OPT_STR_STORE,
520 .off1 = td_var_offset(read_iolog_file),
521 .help = "Playback IO pattern from file",
524 .name = "exec_prerun",
525 .type = FIO_OPT_STR_STORE,
526 .off1 = td_var_offset(exec_prerun),
527 .help = "Execute this file prior to running job",
530 .name = "exec_postrun",
531 .type = FIO_OPT_STR_STORE,
532 .off1 = td_var_offset(exec_postrun),
533 .help = "Execute this file after running job",
535 #ifdef FIO_HAVE_IOSCHED_SWITCH
537 .name = "ioscheduler",
538 .type = FIO_OPT_STR_STORE,
539 .off1 = td_var_offset(ioscheduler),
540 .help = "Use this IO scheduler on the backing device",
545 .type = FIO_OPT_STR_VAL,
546 .off1 = td_var_offset(zone_size),
547 .help = "Give size of an IO zone",
552 .type = FIO_OPT_STR_VAL,
553 .off1 = td_var_offset(zone_skip),
554 .help = "Space between IO zones",
559 .type = FIO_OPT_STR_VAL,
560 .cb = str_lockmem_cb,
561 .help = "Lock down this amount of memory",
565 .name = "rwmixcycle",
567 .off1 = td_var_offset(rwmixcycle),
568 .help = "Cycle period for mixed read/write workloads (msec)",
574 .off1 = td_var_offset(rwmixread),
576 .help = "Percentage of mixed workload that is reads",
580 .name = "rwmixwrite",
582 .off1 = td_var_offset(rwmixwrite),
584 .help = "Percentage of mixed workload that is writes",
590 .off1 = td_var_offset(nice),
591 .help = "Set job CPU nice value",
596 #ifdef FIO_HAVE_IOPRIO
601 .help = "Set job IO priority value",
608 .cb = str_prioclass_cb,
609 .help = "Set job IO priority class",
617 .off1 = td_var_offset(thinktime),
618 .help = "Idle time between IO buffers (usec)",
622 .name = "thinktime_spin",
624 .off1 = td_var_offset(thinktime_spin),
625 .help = "Start think time by spinning this amount (usec)",
629 .name = "thinktime_blocks",
631 .off1 = td_var_offset(thinktime_blocks),
632 .help = "IO buffer period between 'thinktime'",
638 .off1 = td_var_offset(rate),
639 .help = "Set bandwidth rate",
644 .off1 = td_var_offset(ratemin),
645 .help = "Job must meet this rate or it will be shutdown",
650 .off1 = td_var_offset(rate_iops),
651 .help = "Limit IO used to this number of IO operations/sec",
654 .name = "rate_iops_min",
656 .off1 = td_var_offset(rate_iops_min),
657 .help = "Job must meet this rate or it will be shutdown",
662 .off1 = td_var_offset(ratecycle),
663 .help = "Window average for rate limits (msec)",
667 .name = "invalidate",
668 .type = FIO_OPT_BOOL,
669 .off1 = td_var_offset(invalidate_cache),
670 .help = "Invalidate buffer/page cache prior to running job",
675 .type = FIO_OPT_BOOL,
676 .off1 = td_var_offset(sync_io),
677 .help = "Use O_SYNC for buffered writes",
683 .off1 = td_var_offset(bw_avg_time),
684 .help = "Time window over which to calculate bandwidth (msec)",
688 .name = "create_serialize",
689 .type = FIO_OPT_BOOL,
690 .off1 = td_var_offset(create_serialize),
691 .help = "Serialize creating of job files",
695 .name = "create_fsync",
696 .type = FIO_OPT_BOOL,
697 .off1 = td_var_offset(create_fsync),
698 .help = "Fsync file after creation",
704 .off1 = td_var_offset(cpuload),
705 .help = "Use this percentage of CPU",
710 .off1 = td_var_offset(cpucycle),
711 .help = "Length of the CPU burn cycles (usecs)",
714 #ifdef FIO_HAVE_CPU_AFFINITY
718 .cb = str_cpumask_cb,
719 .help = "CPU affinity mask",
724 .type = FIO_OPT_BOOL,
725 .off1 = td_var_offset(end_fsync),
726 .help = "Include fsync at the end of job",
730 .name = "fsync_on_close",
731 .type = FIO_OPT_BOOL,
732 .off1 = td_var_offset(fsync_on_close),
733 .help = "fsync files on close",
738 .type = FIO_OPT_BOOL,
739 .off1 = td_var_offset(unlink),
740 .help = "Unlink created files after job has completed",
745 .type = FIO_OPT_STR_SET,
746 .cb = str_exitall_cb,
747 .help = "Terminate all jobs when one exits",
751 .type = FIO_OPT_STR_SET,
752 .off1 = td_var_offset(stonewall),
753 .help = "Insert a hard barrier between this job and previous",
757 .type = FIO_OPT_STR_SET,
758 .off1 = td_var_offset(use_thread),
759 .help = "Use threads instead of forks",
762 .name = "write_bw_log",
763 .type = FIO_OPT_STR_SET,
764 .off1 = td_var_offset(write_bw_log),
765 .help = "Write log of bandwidth during run",
768 .name = "write_lat_log",
769 .type = FIO_OPT_STR_SET,
770 .off1 = td_var_offset(write_lat_log),
771 .help = "Write log of latency during run",
774 .name = "hugepage-size",
775 .type = FIO_OPT_STR_VAL,
776 .off1 = td_var_offset(hugepage_size),
777 .help = "When using hugepages, specify size of each page",
778 .def = __stringify(FIO_HUGE_PAGE),
781 .name = "group_reporting",
782 .type = FIO_OPT_STR_SET,
783 .off1 = td_var_offset(group_reporting),
784 .help = "Do reporting on a per-group basis",
791 void fio_options_dup_and_init(struct option *long_options)
793 struct fio_option *o;
796 options_init(options);
799 while (long_options[i].name)
804 long_options[i].name = o->name;
805 long_options[i].val = FIO_GETOPT_JOB;
806 if (o->type == FIO_OPT_STR_SET)
807 long_options[i].has_arg = no_argument;
809 long_options[i].has_arg = required_argument;
813 assert(i < FIO_NR_OPTIONS);
817 int fio_option_parse(struct thread_data *td, const char *opt)
819 return parse_option(opt, options, td);
822 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
824 return parse_cmd_option(opt, val, options, td);
827 void fio_fill_default_options(struct thread_data *td)
829 fill_default_options(td, options);
832 int fio_show_option_help(const char *opt)
834 return show_cmd_help(options, opt);