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);
120 td->o.cpumask_set = 1;
124 static int str_fst_cb(void *data, const char *str)
126 struct thread_data *td = data;
127 char *nr = get_opt_postfix(str);
129 td->file_service_nr = 1;
131 td->file_service_nr = atoi(nr);
136 static int str_filename_cb(void *data, const char *input)
138 struct thread_data *td = data;
139 char *fname, *str, *p;
141 p = str = strdup(input);
143 strip_blank_front(&str);
144 strip_blank_end(str);
146 if (!td->files_index)
149 while ((fname = strsep(&str, ":")) != NULL) {
160 static int str_directory_cb(void *data, const char fio_unused *str)
162 struct thread_data *td = data;
165 if (lstat(td->o.directory, &sb) < 0) {
166 log_err("fio: %s is not a directory\n", td->o.directory);
167 td_verror(td, errno, "lstat");
170 if (!S_ISDIR(sb.st_mode)) {
171 log_err("fio: %s is not a directory\n", td->o.directory);
178 static int str_opendir_cb(void *data, const char fio_unused *str)
180 struct thread_data *td = data;
182 if (!td->files_index)
185 return add_dir_files(td, td->o.opendir);
189 #define __stringify_1(x) #x
190 #define __stringify(x) __stringify_1(x)
193 * Map of job/command line options
195 static struct fio_option options[] = {
197 .name = "description",
198 .type = FIO_OPT_STR_STORE,
199 .off1 = td_var_offset(description),
200 .help = "Text job description",
204 .type = FIO_OPT_STR_STORE,
205 .off1 = td_var_offset(name),
206 .help = "Name of this job",
210 .type = FIO_OPT_STR_STORE,
211 .off1 = td_var_offset(directory),
212 .cb = str_directory_cb,
213 .help = "Directory to store files in",
217 .type = FIO_OPT_STR_STORE,
218 .off1 = td_var_offset(filename),
219 .cb = str_filename_cb,
220 .help = "File(s) to use for the workload",
224 .type = FIO_OPT_STR_STORE,
225 .off1 = td_var_offset(opendir),
226 .cb = str_opendir_cb,
227 .help = "Recursively add files from this directory and down",
231 .alias = "readwrite",
234 .off1 = td_var_offset(td_ddir),
235 .help = "IO direction",
239 .oval = TD_DDIR_READ,
240 .help = "Sequential read",
243 .oval = TD_DDIR_WRITE,
244 .help = "Sequential write",
246 { .ival = "randread",
247 .oval = TD_DDIR_RANDREAD,
248 .help = "Random read",
250 { .ival = "randwrite",
251 .oval = TD_DDIR_RANDWRITE,
252 .help = "Random write",
256 .help = "Sequential read and write mix",
259 .oval = TD_DDIR_RANDRW,
260 .help = "Random read and write mix"
265 .name = "fadvise_hint",
266 .type = FIO_OPT_BOOL,
267 .off1 = td_var_offset(fadvise_hint),
268 .help = "Use fadvise() to advise the kernel on IO pattern",
273 .type = FIO_OPT_STR_STORE,
274 .off1 = td_var_offset(ioengine),
275 .help = "IO engine to use",
279 .help = "Use read/write",
281 #ifdef FIO_HAVE_LIBAIO
283 .help = "Linux native asynchronous IO",
286 #ifdef FIO_HAVE_POSIXAIO
287 { .ival = "posixaio",
288 .help = "POSIX asynchronous IO",
292 .help = "Memory mapped IO",
294 #ifdef FIO_HAVE_SPLICE
296 .help = "splice/vmsplice based IO",
301 .help = "SCSI generic v3 IO",
305 .help = "Testing engine (no data transfer)",
308 .help = "Network IO",
310 #ifdef FIO_HAVE_SYSLET
311 { .ival = "syslet-rw",
312 .help = "syslet enabled async pread/pwrite IO",
316 .help = "CPU cycler burner engine",
318 #ifdef FIO_HAVE_GUASI
320 .help = "GUASI IO engine",
323 { .ival = "external",
324 .help = "Load external engine (append name)",
331 .off1 = td_var_offset(iodepth),
332 .help = "Amount of IO buffers to keep in flight",
336 .name = "iodepth_batch",
338 .off1 = td_var_offset(iodepth_batch),
339 .help = "Number of IO to submit in one go",
342 .name = "iodepth_low",
344 .off1 = td_var_offset(iodepth_low),
345 .help = "Low water mark for queuing depth",
349 .type = FIO_OPT_STR_VAL,
350 .off1 = td_var_offset(size),
351 .help = "Total size of device or files",
355 .type = FIO_OPT_STR_VAL,
356 .off1 = td_var_offset(file_size_low),
357 .off2 = td_var_offset(file_size_high),
358 .help = "Size of individual files",
362 .alias = "blocksize",
363 .type = FIO_OPT_STR_VAL_INT,
364 .off1 = td_var_offset(bs[DDIR_READ]),
365 .off2 = td_var_offset(bs[DDIR_WRITE]),
366 .help = "Block size unit",
371 .alias = "blocksize_range",
372 .type = FIO_OPT_RANGE,
373 .off1 = td_var_offset(min_bs[DDIR_READ]),
374 .off2 = td_var_offset(max_bs[DDIR_READ]),
375 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
376 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
377 .help = "Set block size range (in more detail than bs)",
380 .name = "bs_unaligned",
381 .alias = "blocksize_unaligned",
382 .type = FIO_OPT_STR_SET,
383 .off1 = td_var_offset(bs_unaligned),
384 .help = "Don't sector align IO buffer sizes",
388 .type = FIO_OPT_STR_VAL,
389 .off1 = td_var_offset(start_offset),
390 .help = "Start IO from this offset",
394 .name = "randrepeat",
395 .type = FIO_OPT_BOOL,
396 .off1 = td_var_offset(rand_repeatable),
397 .help = "Use repeatable random IO pattern",
401 .name = "norandommap",
402 .type = FIO_OPT_STR_SET,
403 .off1 = td_var_offset(norandommap),
404 .help = "Accept potential duplicate random blocks",
409 .off1 = td_var_offset(nr_files),
410 .help = "Split job workload between this number of files",
416 .off1 = td_var_offset(open_files),
417 .help = "Number of files to keep open at the same time",
420 .name = "file_service_type",
423 .off1 = td_var_offset(file_service_type),
424 .help = "How to select which file to service next",
428 .oval = FIO_FSERVICE_RANDOM,
429 .help = "Choose a file at random",
431 { .ival = "roundrobin",
432 .oval = FIO_FSERVICE_RR,
433 .help = "Round robin select files",
440 .off1 = td_var_offset(fsync_blocks),
441 .help = "Issue fsync for writes every given number of blocks",
446 .type = FIO_OPT_BOOL,
447 .off1 = td_var_offset(odirect),
448 .help = "Use O_DIRECT IO (negates buffered)",
453 .type = FIO_OPT_BOOL,
454 .off1 = td_var_offset(odirect),
456 .help = "Use buffered IO (negates direct)",
461 .type = FIO_OPT_BOOL,
462 .off1 = td_var_offset(overwrite),
463 .help = "When writing, set whether to overwrite current data",
469 .off1 = td_var_offset(loops),
470 .help = "Number of times to run the job",
476 .off1 = td_var_offset(numjobs),
477 .help = "Duplicate this job this many times",
481 .name = "startdelay",
483 .off1 = td_var_offset(start_delay),
484 .help = "Only start job when this period has passed",
490 .type = FIO_OPT_STR_VAL_TIME,
491 .off1 = td_var_offset(timeout),
492 .help = "Stop workload when this amount of time has passed",
496 .name = "time_based",
497 .type = FIO_OPT_STR_SET,
498 .off1 = td_var_offset(time_based),
499 .help = "Keep running until runtime/timeout is met",
506 .off1 = td_var_offset(mem_type),
507 .help = "Backing type for IO buffers",
512 .help = "Use malloc(3) for IO buffers",
516 .help = "Use shared memory segments for IO buffers",
518 #ifdef FIO_HAVE_HUGETLB
521 .help = "Like shm, but use huge pages",
526 .help = "Use mmap(2) (file or anon) for IO buffers",
528 #ifdef FIO_HAVE_HUGETLB
529 { .ival = "mmaphuge",
530 .oval = MEM_MMAPHUGE,
531 .help = "Like mmap, but use huge pages",
539 .off1 = td_var_offset(verify),
540 .help = "Verify data written",
545 .help = "Don't do IO verification",
548 .oval = VERIFY_CRC32,
549 .help = "Use crc32 checksums for verification",
553 .help = "Use md5 checksums for verification",
558 .help = "Pretend to verify",
563 .name = "verifysort",
564 .type = FIO_OPT_BOOL,
565 .off1 = td_var_offset(verifysort),
566 .help = "Sort written verify blocks for read back",
570 .name = "write_iolog",
571 .type = FIO_OPT_STR_STORE,
572 .off1 = td_var_offset(write_iolog_file),
573 .help = "Store IO pattern to file",
576 .name = "read_iolog",
577 .type = FIO_OPT_STR_STORE,
578 .off1 = td_var_offset(read_iolog_file),
579 .help = "Playback IO pattern from file",
582 .name = "exec_prerun",
583 .type = FIO_OPT_STR_STORE,
584 .off1 = td_var_offset(exec_prerun),
585 .help = "Execute this file prior to running job",
588 .name = "exec_postrun",
589 .type = FIO_OPT_STR_STORE,
590 .off1 = td_var_offset(exec_postrun),
591 .help = "Execute this file after running job",
593 #ifdef FIO_HAVE_IOSCHED_SWITCH
595 .name = "ioscheduler",
596 .type = FIO_OPT_STR_STORE,
597 .off1 = td_var_offset(ioscheduler),
598 .help = "Use this IO scheduler on the backing device",
603 .type = FIO_OPT_STR_VAL,
604 .off1 = td_var_offset(zone_size),
605 .help = "Give size of an IO zone",
610 .type = FIO_OPT_STR_VAL,
611 .off1 = td_var_offset(zone_skip),
612 .help = "Space between IO zones",
617 .type = FIO_OPT_STR_VAL,
618 .cb = str_lockmem_cb,
619 .help = "Lock down this amount of memory",
623 .name = "rwmixcycle",
625 .off1 = td_var_offset(rwmixcycle),
626 .help = "Cycle period for mixed read/write workloads (msec)",
632 .off1 = td_var_offset(rwmix[DDIR_READ]),
634 .help = "Percentage of mixed workload that is reads",
638 .name = "rwmixwrite",
640 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
642 .help = "Percentage of mixed workload that is writes",
648 .off1 = td_var_offset(nice),
649 .help = "Set job CPU nice value",
654 #ifdef FIO_HAVE_IOPRIO
659 .help = "Set job IO priority value",
666 .cb = str_prioclass_cb,
667 .help = "Set job IO priority class",
675 .off1 = td_var_offset(thinktime),
676 .help = "Idle time between IO buffers (usec)",
680 .name = "thinktime_spin",
682 .off1 = td_var_offset(thinktime_spin),
683 .help = "Start think time by spinning this amount (usec)",
687 .name = "thinktime_blocks",
689 .off1 = td_var_offset(thinktime_blocks),
690 .help = "IO buffer period between 'thinktime'",
696 .off1 = td_var_offset(rate),
697 .help = "Set bandwidth rate",
702 .off1 = td_var_offset(ratemin),
703 .help = "Job must meet this rate or it will be shutdown",
708 .off1 = td_var_offset(rate_iops),
709 .help = "Limit IO used to this number of IO operations/sec",
712 .name = "rate_iops_min",
714 .off1 = td_var_offset(rate_iops_min),
715 .help = "Job must meet this rate or it will be shutdown",
720 .off1 = td_var_offset(ratecycle),
721 .help = "Window average for rate limits (msec)",
725 .name = "invalidate",
726 .type = FIO_OPT_BOOL,
727 .off1 = td_var_offset(invalidate_cache),
728 .help = "Invalidate buffer/page cache prior to running job",
733 .type = FIO_OPT_BOOL,
734 .off1 = td_var_offset(sync_io),
735 .help = "Use O_SYNC for buffered writes",
741 .off1 = td_var_offset(bw_avg_time),
742 .help = "Time window over which to calculate bandwidth (msec)",
746 .name = "create_serialize",
747 .type = FIO_OPT_BOOL,
748 .off1 = td_var_offset(create_serialize),
749 .help = "Serialize creating of job files",
753 .name = "create_fsync",
754 .type = FIO_OPT_BOOL,
755 .off1 = td_var_offset(create_fsync),
756 .help = "Fsync file after creation",
762 .off1 = td_var_offset(cpuload),
763 .help = "Use this percentage of CPU",
768 .off1 = td_var_offset(cpucycle),
769 .help = "Length of the CPU burn cycles (usecs)",
772 #ifdef FIO_HAVE_CPU_AFFINITY
776 .cb = str_cpumask_cb,
777 .help = "CPU affinity mask",
782 .type = FIO_OPT_BOOL,
783 .off1 = td_var_offset(end_fsync),
784 .help = "Include fsync at the end of job",
788 .name = "fsync_on_close",
789 .type = FIO_OPT_BOOL,
790 .off1 = td_var_offset(fsync_on_close),
791 .help = "fsync files on close",
796 .type = FIO_OPT_BOOL,
797 .off1 = td_var_offset(unlink),
798 .help = "Unlink created files after job has completed",
803 .type = FIO_OPT_STR_SET,
804 .cb = str_exitall_cb,
805 .help = "Terminate all jobs when one exits",
809 .type = FIO_OPT_STR_SET,
810 .off1 = td_var_offset(stonewall),
811 .help = "Insert a hard barrier between this job and previous",
815 .type = FIO_OPT_STR_SET,
816 .off1 = td_var_offset(new_group),
817 .help = "Mark the start of a new group (for reporting)",
821 .type = FIO_OPT_STR_SET,
822 .off1 = td_var_offset(use_thread),
823 .help = "Use threads instead of forks",
826 .name = "write_bw_log",
827 .type = FIO_OPT_STR_SET,
828 .off1 = td_var_offset(write_bw_log),
829 .help = "Write log of bandwidth during run",
832 .name = "write_lat_log",
833 .type = FIO_OPT_STR_SET,
834 .off1 = td_var_offset(write_lat_log),
835 .help = "Write log of latency during run",
838 .name = "hugepage-size",
839 .type = FIO_OPT_STR_VAL,
840 .off1 = td_var_offset(hugepage_size),
841 .help = "When using hugepages, specify size of each page",
842 .def = __stringify(FIO_HUGE_PAGE),
845 .name = "group_reporting",
846 .type = FIO_OPT_STR_SET,
847 .off1 = td_var_offset(group_reporting),
848 .help = "Do reporting on a per-group basis",
851 .name = "zero_buffers",
852 .type = FIO_OPT_STR_SET,
853 .off1 = td_var_offset(zero_buffers),
854 .help = "Init IO buffers to all zeroes",
856 #ifdef FIO_HAVE_DISK_UTIL
859 .type = FIO_OPT_BOOL,
860 .off1 = td_var_offset(do_disk_util),
861 .help = "Log disk utilization stats",
870 void fio_options_dup_and_init(struct option *long_options)
872 struct fio_option *o;
875 options_init(options);
878 while (long_options[i].name)
883 long_options[i].name = o->name;
884 long_options[i].val = FIO_GETOPT_JOB;
885 if (o->type == FIO_OPT_STR_SET)
886 long_options[i].has_arg = no_argument;
888 long_options[i].has_arg = required_argument;
892 assert(i < FIO_NR_OPTIONS);
896 int fio_option_parse(struct thread_data *td, const char *opt)
898 return parse_option(opt, options, td);
901 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
903 return parse_cmd_option(opt, val, options, td);
906 void fio_fill_default_options(struct thread_data *td)
908 fill_default_options(td, options);
911 int fio_show_option_help(const char *opt)
913 return show_cmd_help(options, opt);
916 static void __options_mem(struct thread_data *td, int alloc)
918 struct thread_options *o = &td->o;
919 struct fio_option *opt;
923 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
924 if (opt->type != FIO_OPT_STR_STORE)
927 ptr = (void *) o + opt->off1;
940 * dupe FIO_OPT_STR_STORE options
942 void options_mem_dupe(struct thread_data *td)
944 __options_mem(td, 1);
947 void options_mem_free(struct thread_data fio_unused *td)
950 __options_mem(td, 0);