12 #define td_var_offset(var) ((size_t) &((struct thread_data *)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->mem_type == MEM_MMAPHUGE || td->mem_type == MEM_MMAP) {
35 td->mmapfile = get_opt_postfix(mem);
36 if (td->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->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->directory, &sb) < 0) {
139 log_err("fio: %s is not a directory\n", td->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->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->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",
205 .off1 = td_var_offset(td_ddir),
206 .help = "IO direction",
210 .oval = TD_DDIR_READ,
211 .help = "Sequential read",
214 .oval = TD_DDIR_WRITE,
215 .help = "Sequential write",
217 { .ival = "randread",
218 .oval = TD_DDIR_RANDREAD,
219 .help = "Random read",
221 { .ival = "randwrite",
222 .oval = TD_DDIR_RANDWRITE,
223 .help = "Random write",
227 .help = "Sequential read and write mix",
230 .oval = TD_DDIR_RANDRW,
231 .help = "Random read and write mix"
237 .type = FIO_OPT_STR_STORE,
238 .off1 = td_var_offset(ioengine),
239 .help = "IO engine to use",
243 .help = "Use read/write",
245 #ifdef FIO_HAVE_LIBAIO
247 .help = "Linux native asynchronous IO",
250 #ifdef FIO_HAVE_POSIXAIO
251 { .ival = "posixaio",
252 .help = "POSIX asynchronous IO",
256 .help = "Memory mapped IO",
258 #ifdef FIO_HAVE_SPLICE
260 .help = "splice/vmsplice based IO",
265 .help = "SCSI generic v3 IO",
269 .help = "Testing engine (no data transfer)",
272 .help = "Network IO",
274 #ifdef FIO_HAVE_SYSLET
275 { .ival = "syslet-rw",
276 .help = "syslet enabled async pread/pwrite IO",
280 .help = "CPU cycler burner engine",
282 { .ival = "external",
283 .help = "Load external engine (append name)",
290 .off1 = td_var_offset(iodepth),
291 .help = "Amount of IO buffers to keep in flight",
295 .name = "iodepth_batch",
297 .off1 = td_var_offset(iodepth_batch),
298 .help = "Number of IO to submit in one go",
301 .name = "iodepth_low",
303 .off1 = td_var_offset(iodepth_low),
304 .help = "Low water mark for queuing depth",
308 .type = FIO_OPT_STR_VAL,
309 .off1 = td_var_offset(total_file_size),
310 .help = "Total size of device or files",
314 .type = FIO_OPT_STR_VAL,
315 .off1 = td_var_offset(file_size_low),
316 .off2 = td_var_offset(file_size_high),
317 .help = "Size of individual files",
321 .type = FIO_OPT_STR_VAL_INT,
322 .off1 = td_var_offset(bs[DDIR_READ]),
323 .off2 = td_var_offset(bs[DDIR_WRITE]),
324 .help = "Block size unit",
329 .type = FIO_OPT_RANGE,
330 .off1 = td_var_offset(min_bs[DDIR_READ]),
331 .off2 = td_var_offset(max_bs[DDIR_READ]),
332 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
333 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
334 .help = "Set block size range (in more detail than bs)",
337 .name = "bs_unaligned",
338 .type = FIO_OPT_STR_SET,
339 .off1 = td_var_offset(bs_unaligned),
340 .help = "Don't sector align IO buffer sizes",
344 .type = FIO_OPT_STR_VAL,
345 .off1 = td_var_offset(start_offset),
346 .help = "Start IO from this offset",
350 .name = "randrepeat",
351 .type = FIO_OPT_BOOL,
352 .off1 = td_var_offset(rand_repeatable),
353 .help = "Use repeatable random IO pattern",
357 .name = "norandommap",
358 .type = FIO_OPT_STR_SET,
359 .off1 = td_var_offset(norandommap),
360 .help = "Accept potential duplicate random blocks",
365 .off1 = td_var_offset(nr_files),
366 .help = "Split job workload between this number of files",
372 .off1 = td_var_offset(open_files),
373 .help = "Number of files to keep open at the same time",
376 .name = "file_service_type",
379 .off1 = td_var_offset(file_service_type),
380 .help = "How to select which file to service next",
384 .oval = FIO_FSERVICE_RANDOM,
385 .help = "Choose a file at random",
387 { .ival = "roundrobin",
388 .oval = FIO_FSERVICE_RR,
389 .help = "Round robin select files",
396 .off1 = td_var_offset(fsync_blocks),
397 .help = "Issue fsync for writes every given number of blocks",
402 .type = FIO_OPT_BOOL,
403 .off1 = td_var_offset(odirect),
404 .help = "Use O_DIRECT IO (negates buffered)",
409 .type = FIO_OPT_BOOL,
410 .off1 = td_var_offset(odirect),
412 .help = "Use buffered IO (negates direct)",
417 .type = FIO_OPT_BOOL,
418 .off1 = td_var_offset(overwrite),
419 .help = "When writing, set whether to overwrite current data",
425 .off1 = td_var_offset(loops),
426 .help = "Number of times to run the job",
432 .off1 = td_var_offset(numjobs),
433 .help = "Duplicate this job this many times",
437 .name = "startdelay",
439 .off1 = td_var_offset(start_delay),
440 .help = "Only start job when this period has passed",
446 .type = FIO_OPT_STR_VAL_TIME,
447 .off1 = td_var_offset(timeout),
448 .help = "Stop workload when this amount of time has passed",
455 .off1 = td_var_offset(mem_type),
456 .help = "Backing type for IO buffers",
461 .help = "Use malloc(3) for IO buffers",
465 .help = "Use shared memory segments for IO buffers",
467 #ifdef FIO_HAVE_HUGETLB
470 .help = "Like shm, but use huge pages",
475 .help = "Use mmap(2) (file or anon) for IO buffers",
477 #ifdef FIO_HAVE_HUGETLB
478 { .ival = "mmaphuge",
479 .oval = MEM_MMAPHUGE,
480 .help = "Like mmap, but use huge pages",
488 .off1 = td_var_offset(verify),
489 .help = "Verify data written",
494 .help = "Don't do IO verification",
497 .oval = VERIFY_CRC32,
498 .help = "Use crc32 checksums for verification",
502 .help = "Use md5 checksums for verification",
507 .name = "write_iolog",
508 .type = FIO_OPT_STR_STORE,
509 .off1 = td_var_offset(write_iolog_file),
510 .help = "Store IO pattern to file",
513 .name = "read_iolog",
514 .type = FIO_OPT_STR_STORE,
515 .off1 = td_var_offset(read_iolog_file),
516 .help = "Playback IO pattern from file",
519 .name = "exec_prerun",
520 .type = FIO_OPT_STR_STORE,
521 .off1 = td_var_offset(exec_prerun),
522 .help = "Execute this file prior to running job",
525 .name = "exec_postrun",
526 .type = FIO_OPT_STR_STORE,
527 .off1 = td_var_offset(exec_postrun),
528 .help = "Execute this file after running job",
530 #ifdef FIO_HAVE_IOSCHED_SWITCH
532 .name = "ioscheduler",
533 .type = FIO_OPT_STR_STORE,
534 .off1 = td_var_offset(ioscheduler),
535 .help = "Use this IO scheduler on the backing device",
540 .type = FIO_OPT_STR_VAL,
541 .off1 = td_var_offset(zone_size),
542 .help = "Give size of an IO zone",
547 .type = FIO_OPT_STR_VAL,
548 .off1 = td_var_offset(zone_skip),
549 .help = "Space between IO zones",
554 .type = FIO_OPT_STR_VAL,
555 .cb = str_lockmem_cb,
556 .help = "Lock down this amount of memory",
560 .name = "rwmixcycle",
562 .off1 = td_var_offset(rwmixcycle),
563 .help = "Cycle period for mixed read/write workloads (msec)",
569 .off1 = td_var_offset(rwmixread),
571 .help = "Percentage of mixed workload that is reads",
575 .name = "rwmixwrite",
577 .off1 = td_var_offset(rwmixwrite),
579 .help = "Percentage of mixed workload that is writes",
585 .off1 = td_var_offset(nice),
586 .help = "Set job CPU nice value",
591 #ifdef FIO_HAVE_IOPRIO
596 .help = "Set job IO priority value",
603 .cb = str_prioclass_cb,
604 .help = "Set job IO priority class",
612 .off1 = td_var_offset(thinktime),
613 .help = "Idle time between IO buffers (usec)",
617 .name = "thinktime_spin",
619 .off1 = td_var_offset(thinktime_spin),
620 .help = "Start think time by spinning this amount (usec)",
624 .name = "thinktime_blocks",
626 .off1 = td_var_offset(thinktime_blocks),
627 .help = "IO buffer period between 'thinktime'",
633 .off1 = td_var_offset(rate),
634 .help = "Set bandwidth rate",
639 .off1 = td_var_offset(ratemin),
640 .help = "Job must meet this rate or it will be shutdown",
645 .off1 = td_var_offset(rate_iops),
646 .help = "Limit IO used to this number of IO operations/sec",
649 .name = "rate_iops_min",
651 .off1 = td_var_offset(rate_iops_min),
652 .help = "Job must meet this rate or it will be shutdown",
657 .off1 = td_var_offset(ratecycle),
658 .help = "Window average for rate limits (msec)",
662 .name = "invalidate",
663 .type = FIO_OPT_BOOL,
664 .off1 = td_var_offset(invalidate_cache),
665 .help = "Invalidate buffer/page cache prior to running job",
670 .type = FIO_OPT_BOOL,
671 .off1 = td_var_offset(sync_io),
672 .help = "Use O_SYNC for buffered writes",
678 .off1 = td_var_offset(bw_avg_time),
679 .help = "Time window over which to calculate bandwidth (msec)",
683 .name = "create_serialize",
684 .type = FIO_OPT_BOOL,
685 .off1 = td_var_offset(create_serialize),
686 .help = "Serialize creating of job files",
690 .name = "create_fsync",
691 .type = FIO_OPT_BOOL,
692 .off1 = td_var_offset(create_fsync),
693 .help = "Fsync file after creation",
699 .off1 = td_var_offset(cpuload),
700 .help = "Use this percentage of CPU",
705 .off1 = td_var_offset(cpucycle),
706 .help = "Length of the CPU burn cycles (usecs)",
709 #ifdef FIO_HAVE_CPU_AFFINITY
713 .cb = str_cpumask_cb,
714 .help = "CPU affinity mask",
719 .type = FIO_OPT_BOOL,
720 .off1 = td_var_offset(end_fsync),
721 .help = "Include fsync at the end of job",
725 .name = "fsync_on_close",
726 .type = FIO_OPT_BOOL,
727 .off1 = td_var_offset(fsync_on_close),
728 .help = "fsync files on close",
733 .type = FIO_OPT_BOOL,
734 .off1 = td_var_offset(unlink),
735 .help = "Unlink created files after job has completed",
740 .type = FIO_OPT_STR_SET,
741 .cb = str_exitall_cb,
742 .help = "Terminate all jobs when one exits",
746 .type = FIO_OPT_STR_SET,
747 .off1 = td_var_offset(stonewall),
748 .help = "Insert a hard barrier between this job and previous",
752 .type = FIO_OPT_STR_SET,
753 .off1 = td_var_offset(use_thread),
754 .help = "Use threads instead of forks",
757 .name = "write_bw_log",
758 .type = FIO_OPT_STR_SET,
759 .off1 = td_var_offset(write_bw_log),
760 .help = "Write log of bandwidth during run",
763 .name = "write_lat_log",
764 .type = FIO_OPT_STR_SET,
765 .off1 = td_var_offset(write_lat_log),
766 .help = "Write log of latency during run",
769 .name = "hugepage-size",
770 .type = FIO_OPT_STR_VAL,
771 .off1 = td_var_offset(hugepage_size),
772 .help = "When using hugepages, specify size of each page",
773 .def = __stringify(FIO_HUGE_PAGE),
776 .name = "group_reporting",
777 .type = FIO_OPT_STR_SET,
778 .off1 = td_var_offset(group_reporting),
779 .help = "Do reporting on a per-group basis",
786 void fio_options_dup_and_init(struct option *long_options)
788 struct fio_option *o;
791 options_init(options);
794 while (long_options[i].name)
799 long_options[i].name = o->name;
800 long_options[i].val = FIO_GETOPT_JOB;
801 if (o->type == FIO_OPT_STR_SET)
802 long_options[i].has_arg = no_argument;
804 long_options[i].has_arg = required_argument;
808 assert(i < FIO_NR_OPTIONS);
812 int fio_option_parse(struct thread_data *td, const char *opt)
814 return parse_option(opt, options, td);
817 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
819 return parse_cmd_option(opt, val, options, td);
822 void fio_fill_default_options(struct thread_data *td)
824 fill_default_options(td, options);
827 int fio_show_option_help(const char *opt)
829 return show_cmd_help(options, opt);