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);
39 printf("ddir_nr=%d\n", td->o.ddir_nr);
44 static int str_mem_cb(void *data, const char *mem)
46 struct thread_data *td = data;
48 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
49 td->mmapfile = get_opt_postfix(mem);
50 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
51 log_err("fio: mmaphuge:/path/to/file\n");
59 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
65 #ifdef FIO_HAVE_IOPRIO
66 static int str_prioclass_cb(void *data, unsigned int *val)
68 struct thread_data *td = data;
70 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
74 static int str_prio_cb(void *data, unsigned int *val)
76 struct thread_data *td = data;
83 static int str_exitall_cb(void)
85 exitall_on_terminate = 1;
89 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
91 #ifdef FIO_HAVE_CPU_AFFINITY
96 for (i = 0; i < sizeof(int) * 8; i++) {
103 static int str_cpumask_cb(void *data, unsigned int *val)
105 struct thread_data *td = data;
107 fill_cpu_mask(td->o.cpumask, *val);
111 static int str_fst_cb(void *data, const char *str)
113 struct thread_data *td = data;
114 char *nr = get_opt_postfix(str);
116 td->file_service_nr = 1;
118 td->file_service_nr = atoi(nr);
123 static int str_filename_cb(void *data, const char *input)
125 struct thread_data *td = data;
126 char *fname, *str, *p;
128 p = str = strdup(input);
130 strip_blank_front(&str);
131 strip_blank_end(str);
133 if (!td->files_index)
136 while ((fname = strsep(&str, ":")) != NULL) {
147 static int str_directory_cb(void *data, const char fio_unused *str)
149 struct thread_data *td = data;
152 if (lstat(td->o.directory, &sb) < 0) {
153 log_err("fio: %s is not a directory\n", td->o.directory);
154 td_verror(td, errno, "lstat");
157 if (!S_ISDIR(sb.st_mode)) {
158 log_err("fio: %s is not a directory\n", td->o.directory);
165 static int str_opendir_cb(void *data, const char fio_unused *str)
167 struct thread_data *td = data;
169 if (!td->files_index)
172 return add_dir_files(td, td->o.opendir);
176 #define __stringify_1(x) #x
177 #define __stringify(x) __stringify_1(x)
180 * Map of job/command line options
182 static struct fio_option options[] = {
184 .name = "description",
185 .type = FIO_OPT_STR_STORE,
186 .off1 = td_var_offset(description),
187 .help = "Text job description",
191 .type = FIO_OPT_STR_STORE,
192 .off1 = td_var_offset(name),
193 .help = "Name of this job",
197 .type = FIO_OPT_STR_STORE,
198 .off1 = td_var_offset(directory),
199 .cb = str_directory_cb,
200 .help = "Directory to store files in",
204 .type = FIO_OPT_STR_STORE,
205 .off1 = td_var_offset(filename),
206 .cb = str_filename_cb,
207 .help = "File(s) to use for the workload",
211 .type = FIO_OPT_STR_STORE,
212 .off1 = td_var_offset(opendir),
213 .cb = str_opendir_cb,
214 .help = "Recursively add files from this directory and down",
218 .alias = "readwrite",
221 .off1 = td_var_offset(td_ddir),
222 .help = "IO direction",
226 .oval = TD_DDIR_READ,
227 .help = "Sequential read",
230 .oval = TD_DDIR_WRITE,
231 .help = "Sequential write",
233 { .ival = "randread",
234 .oval = TD_DDIR_RANDREAD,
235 .help = "Random read",
237 { .ival = "randwrite",
238 .oval = TD_DDIR_RANDWRITE,
239 .help = "Random write",
243 .help = "Sequential read and write mix",
246 .oval = TD_DDIR_RANDRW,
247 .help = "Random read and write mix"
253 .type = FIO_OPT_STR_STORE,
254 .off1 = td_var_offset(ioengine),
255 .help = "IO engine to use",
259 .help = "Use read/write",
261 #ifdef FIO_HAVE_LIBAIO
263 .help = "Linux native asynchronous IO",
266 #ifdef FIO_HAVE_POSIXAIO
267 { .ival = "posixaio",
268 .help = "POSIX asynchronous IO",
272 .help = "Memory mapped IO",
274 #ifdef FIO_HAVE_SPLICE
276 .help = "splice/vmsplice based IO",
281 .help = "SCSI generic v3 IO",
285 .help = "Testing engine (no data transfer)",
288 .help = "Network IO",
290 #ifdef FIO_HAVE_SYSLET
291 { .ival = "syslet-rw",
292 .help = "syslet enabled async pread/pwrite IO",
296 .help = "CPU cycler burner engine",
298 #ifdef FIO_HAVE_GUASI
300 .help = "GUASI IO engine",
303 { .ival = "external",
304 .help = "Load external engine (append name)",
311 .off1 = td_var_offset(iodepth),
312 .help = "Amount of IO buffers to keep in flight",
316 .name = "iodepth_batch",
318 .off1 = td_var_offset(iodepth_batch),
319 .help = "Number of IO to submit in one go",
322 .name = "iodepth_low",
324 .off1 = td_var_offset(iodepth_low),
325 .help = "Low water mark for queuing depth",
329 .type = FIO_OPT_STR_VAL,
330 .off1 = td_var_offset(size),
331 .help = "Total size of device or files",
335 .type = FIO_OPT_STR_VAL,
336 .off1 = td_var_offset(file_size_low),
337 .off2 = td_var_offset(file_size_high),
338 .help = "Size of individual files",
342 .alias = "blocksize",
343 .type = FIO_OPT_STR_VAL_INT,
344 .off1 = td_var_offset(bs[DDIR_READ]),
345 .off2 = td_var_offset(bs[DDIR_WRITE]),
346 .help = "Block size unit",
351 .alias = "blocksize_range",
352 .type = FIO_OPT_RANGE,
353 .off1 = td_var_offset(min_bs[DDIR_READ]),
354 .off2 = td_var_offset(max_bs[DDIR_READ]),
355 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
356 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
357 .help = "Set block size range (in more detail than bs)",
360 .name = "bs_unaligned",
361 .alias = "blocksize_unaligned",
362 .type = FIO_OPT_STR_SET,
363 .off1 = td_var_offset(bs_unaligned),
364 .help = "Don't sector align IO buffer sizes",
368 .type = FIO_OPT_STR_VAL,
369 .off1 = td_var_offset(start_offset),
370 .help = "Start IO from this offset",
374 .name = "randrepeat",
375 .type = FIO_OPT_BOOL,
376 .off1 = td_var_offset(rand_repeatable),
377 .help = "Use repeatable random IO pattern",
381 .name = "norandommap",
382 .type = FIO_OPT_STR_SET,
383 .off1 = td_var_offset(norandommap),
384 .help = "Accept potential duplicate random blocks",
389 .off1 = td_var_offset(nr_files),
390 .help = "Split job workload between this number of files",
396 .off1 = td_var_offset(open_files),
397 .help = "Number of files to keep open at the same time",
400 .name = "file_service_type",
403 .off1 = td_var_offset(file_service_type),
404 .help = "How to select which file to service next",
408 .oval = FIO_FSERVICE_RANDOM,
409 .help = "Choose a file at random",
411 { .ival = "roundrobin",
412 .oval = FIO_FSERVICE_RR,
413 .help = "Round robin select files",
420 .off1 = td_var_offset(fsync_blocks),
421 .help = "Issue fsync for writes every given number of blocks",
426 .type = FIO_OPT_BOOL,
427 .off1 = td_var_offset(odirect),
428 .help = "Use O_DIRECT IO (negates buffered)",
433 .type = FIO_OPT_BOOL,
434 .off1 = td_var_offset(odirect),
436 .help = "Use buffered IO (negates direct)",
441 .type = FIO_OPT_BOOL,
442 .off1 = td_var_offset(overwrite),
443 .help = "When writing, set whether to overwrite current data",
449 .off1 = td_var_offset(loops),
450 .help = "Number of times to run the job",
456 .off1 = td_var_offset(numjobs),
457 .help = "Duplicate this job this many times",
461 .name = "startdelay",
463 .off1 = td_var_offset(start_delay),
464 .help = "Only start job when this period has passed",
470 .type = FIO_OPT_STR_VAL_TIME,
471 .off1 = td_var_offset(timeout),
472 .help = "Stop workload when this amount of time has passed",
480 .off1 = td_var_offset(mem_type),
481 .help = "Backing type for IO buffers",
486 .help = "Use malloc(3) for IO buffers",
490 .help = "Use shared memory segments for IO buffers",
492 #ifdef FIO_HAVE_HUGETLB
495 .help = "Like shm, but use huge pages",
500 .help = "Use mmap(2) (file or anon) for IO buffers",
502 #ifdef FIO_HAVE_HUGETLB
503 { .ival = "mmaphuge",
504 .oval = MEM_MMAPHUGE,
505 .help = "Like mmap, but use huge pages",
513 .off1 = td_var_offset(verify),
514 .help = "Verify data written",
519 .help = "Don't do IO verification",
522 .oval = VERIFY_CRC32,
523 .help = "Use crc32 checksums for verification",
527 .help = "Use md5 checksums for verification",
532 .name = "write_iolog",
533 .type = FIO_OPT_STR_STORE,
534 .off1 = td_var_offset(write_iolog_file),
535 .help = "Store IO pattern to file",
538 .name = "read_iolog",
539 .type = FIO_OPT_STR_STORE,
540 .off1 = td_var_offset(read_iolog_file),
541 .help = "Playback IO pattern from file",
544 .name = "exec_prerun",
545 .type = FIO_OPT_STR_STORE,
546 .off1 = td_var_offset(exec_prerun),
547 .help = "Execute this file prior to running job",
550 .name = "exec_postrun",
551 .type = FIO_OPT_STR_STORE,
552 .off1 = td_var_offset(exec_postrun),
553 .help = "Execute this file after running job",
555 #ifdef FIO_HAVE_IOSCHED_SWITCH
557 .name = "ioscheduler",
558 .type = FIO_OPT_STR_STORE,
559 .off1 = td_var_offset(ioscheduler),
560 .help = "Use this IO scheduler on the backing device",
565 .type = FIO_OPT_STR_VAL,
566 .off1 = td_var_offset(zone_size),
567 .help = "Give size of an IO zone",
572 .type = FIO_OPT_STR_VAL,
573 .off1 = td_var_offset(zone_skip),
574 .help = "Space between IO zones",
579 .type = FIO_OPT_STR_VAL,
580 .cb = str_lockmem_cb,
581 .help = "Lock down this amount of memory",
585 .name = "rwmixcycle",
587 .off1 = td_var_offset(rwmixcycle),
588 .help = "Cycle period for mixed read/write workloads (msec)",
594 .off1 = td_var_offset(rwmix[DDIR_READ]),
596 .help = "Percentage of mixed workload that is reads",
600 .name = "rwmixwrite",
602 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
604 .help = "Percentage of mixed workload that is writes",
610 .off1 = td_var_offset(nice),
611 .help = "Set job CPU nice value",
616 #ifdef FIO_HAVE_IOPRIO
621 .help = "Set job IO priority value",
628 .cb = str_prioclass_cb,
629 .help = "Set job IO priority class",
637 .off1 = td_var_offset(thinktime),
638 .help = "Idle time between IO buffers (usec)",
642 .name = "thinktime_spin",
644 .off1 = td_var_offset(thinktime_spin),
645 .help = "Start think time by spinning this amount (usec)",
649 .name = "thinktime_blocks",
651 .off1 = td_var_offset(thinktime_blocks),
652 .help = "IO buffer period between 'thinktime'",
658 .off1 = td_var_offset(rate),
659 .help = "Set bandwidth rate",
664 .off1 = td_var_offset(ratemin),
665 .help = "Job must meet this rate or it will be shutdown",
670 .off1 = td_var_offset(rate_iops),
671 .help = "Limit IO used to this number of IO operations/sec",
674 .name = "rate_iops_min",
676 .off1 = td_var_offset(rate_iops_min),
677 .help = "Job must meet this rate or it will be shutdown",
682 .off1 = td_var_offset(ratecycle),
683 .help = "Window average for rate limits (msec)",
687 .name = "invalidate",
688 .type = FIO_OPT_BOOL,
689 .off1 = td_var_offset(invalidate_cache),
690 .help = "Invalidate buffer/page cache prior to running job",
695 .type = FIO_OPT_BOOL,
696 .off1 = td_var_offset(sync_io),
697 .help = "Use O_SYNC for buffered writes",
703 .off1 = td_var_offset(bw_avg_time),
704 .help = "Time window over which to calculate bandwidth (msec)",
708 .name = "create_serialize",
709 .type = FIO_OPT_BOOL,
710 .off1 = td_var_offset(create_serialize),
711 .help = "Serialize creating of job files",
715 .name = "create_fsync",
716 .type = FIO_OPT_BOOL,
717 .off1 = td_var_offset(create_fsync),
718 .help = "Fsync file after creation",
724 .off1 = td_var_offset(cpuload),
725 .help = "Use this percentage of CPU",
730 .off1 = td_var_offset(cpucycle),
731 .help = "Length of the CPU burn cycles (usecs)",
734 #ifdef FIO_HAVE_CPU_AFFINITY
738 .cb = str_cpumask_cb,
739 .help = "CPU affinity mask",
744 .type = FIO_OPT_BOOL,
745 .off1 = td_var_offset(end_fsync),
746 .help = "Include fsync at the end of job",
750 .name = "fsync_on_close",
751 .type = FIO_OPT_BOOL,
752 .off1 = td_var_offset(fsync_on_close),
753 .help = "fsync files on close",
758 .type = FIO_OPT_BOOL,
759 .off1 = td_var_offset(unlink),
760 .help = "Unlink created files after job has completed",
765 .type = FIO_OPT_STR_SET,
766 .cb = str_exitall_cb,
767 .help = "Terminate all jobs when one exits",
771 .type = FIO_OPT_STR_SET,
772 .off1 = td_var_offset(stonewall),
773 .help = "Insert a hard barrier between this job and previous",
777 .type = FIO_OPT_STR_SET,
778 .off1 = td_var_offset(new_group),
779 .help = "Mark the start of a new group (for reporting)",
783 .type = FIO_OPT_STR_SET,
784 .off1 = td_var_offset(use_thread),
785 .help = "Use threads instead of forks",
788 .name = "write_bw_log",
789 .type = FIO_OPT_STR_SET,
790 .off1 = td_var_offset(write_bw_log),
791 .help = "Write log of bandwidth during run",
794 .name = "write_lat_log",
795 .type = FIO_OPT_STR_SET,
796 .off1 = td_var_offset(write_lat_log),
797 .help = "Write log of latency during run",
800 .name = "hugepage-size",
801 .type = FIO_OPT_STR_VAL,
802 .off1 = td_var_offset(hugepage_size),
803 .help = "When using hugepages, specify size of each page",
804 .def = __stringify(FIO_HUGE_PAGE),
807 .name = "group_reporting",
808 .type = FIO_OPT_STR_SET,
809 .off1 = td_var_offset(group_reporting),
810 .help = "Do reporting on a per-group basis",
817 void fio_options_dup_and_init(struct option *long_options)
819 struct fio_option *o;
822 options_init(options);
825 while (long_options[i].name)
830 long_options[i].name = o->name;
831 long_options[i].val = FIO_GETOPT_JOB;
832 if (o->type == FIO_OPT_STR_SET)
833 long_options[i].has_arg = no_argument;
835 long_options[i].has_arg = required_argument;
839 assert(i < FIO_NR_OPTIONS);
843 int fio_option_parse(struct thread_data *td, const char *opt)
845 return parse_option(opt, options, td);
848 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
850 return parse_cmd_option(opt, val, options, td);
853 void fio_fill_default_options(struct thread_data *td)
855 fill_default_options(td, options);
858 int fio_show_option_help(const char *opt)
860 return show_cmd_help(options, opt);