13 #define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
16 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
18 static char *get_opt_postfix(const char *str)
20 char *p = strstr(str, ":");
26 strip_blank_front(&p);
31 static int bs_cmp(const void *p1, const void *p2)
33 const struct bssplit *bsp1 = p1;
34 const struct bssplit *bsp2 = p2;
36 return bsp1->perc < bsp2->perc;
39 static int str_bssplit_cb(void *data, const char *input)
41 struct thread_data *td = data;
42 char *fname, *str, *p;
43 unsigned int i, perc, perc_missing;
44 unsigned int max_bs, min_bs;
47 p = str = strdup(input);
49 strip_blank_front(&str);
53 td->o.bssplit = malloc(4 * sizeof(struct bssplit));
58 while ((fname = strsep(&str, ":")) != NULL) {
65 * grow struct buffer, if needed
67 if (i == td->o.bssplit_nr) {
68 td->o.bssplit_nr <<= 1;
69 td->o.bssplit = realloc(td->o.bssplit, td->o.bssplit_nr * sizeof(struct bssplit));
72 perc_str = strstr(fname, "/");
76 perc = atoi(perc_str);
84 if (str_to_decimal(fname, &val, 1)) {
85 log_err("fio: bssplit conversion failed\n");
95 td->o.bssplit[i].bs = val;
96 td->o.bssplit[i].perc = perc;
100 td->o.bssplit_nr = i;
103 * Now check if the percentages add up, and how much is missing
105 perc = perc_missing = 0;
106 for (i = 0; i < td->o.bssplit_nr; i++) {
107 struct bssplit *bsp = &td->o.bssplit[i];
109 if (bsp->perc == (unsigned char) -1)
116 log_err("fio: bssplit percentages add to more than 100%%\n");
121 * If values didn't have a percentage set, divide the remains between
125 for (i = 0; i < td->o.bssplit_nr; i++) {
126 struct bssplit *bsp = &td->o.bssplit[i];
128 if (bsp->perc == (unsigned char) -1)
129 bsp->perc = (100 - perc) / perc_missing;
133 td->o.min_bs[DDIR_READ] = td->o.min_bs[DDIR_WRITE] = min_bs;
134 td->o.max_bs[DDIR_READ] = td->o.max_bs[DDIR_WRITE] = max_bs;
137 * now sort based on percentages, for ease of lookup
139 qsort(td->o.bssplit, td->o.bssplit_nr, sizeof(struct bssplit), bs_cmp);
145 static int str_rw_cb(void *data, const char *str)
147 struct thread_data *td = data;
148 char *nr = get_opt_postfix(str);
152 td->o.ddir_nr = atoi(nr);
157 static int str_mem_cb(void *data, const char *mem)
159 struct thread_data *td = data;
161 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
162 td->mmapfile = get_opt_postfix(mem);
163 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
164 log_err("fio: mmaphuge:/path/to/file\n");
172 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
178 #ifdef FIO_HAVE_IOPRIO
179 static int str_prioclass_cb(void *data, unsigned int *val)
181 struct thread_data *td = data;
185 * mask off old class bits, str_prio_cb() may have set a default class
187 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
190 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
195 static int str_prio_cb(void *data, unsigned int *val)
197 struct thread_data *td = data;
202 * If no class is set, assume BE
204 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
205 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
212 static int str_exitall_cb(void)
214 exitall_on_terminate = 1;
218 #ifdef FIO_HAVE_CPU_AFFINITY
219 static int str_cpumask_cb(void *data, unsigned int *val)
221 struct thread_data *td = data;
224 CPU_ZERO(&td->o.cpumask);
226 for (i = 0; i < sizeof(int) * 8; i++)
228 CPU_SET(*val, &td->o.cpumask);
230 td->o.cpumask_set = 1;
234 static int str_cpus_allowed_cb(void *data, const char *input)
236 struct thread_data *td = data;
239 CPU_ZERO(&td->o.cpumask);
241 p = str = strdup(input);
243 strip_blank_front(&str);
244 strip_blank_end(str);
246 while ((cpu = strsep(&str, ",")) != NULL) {
249 CPU_SET(atoi(cpu), &td->o.cpumask);
253 td->o.cpumask_set = 1;
258 static int str_fst_cb(void *data, const char *str)
260 struct thread_data *td = data;
261 char *nr = get_opt_postfix(str);
263 td->file_service_nr = 1;
265 td->file_service_nr = atoi(nr);
270 static int str_filename_cb(void *data, const char *input)
272 struct thread_data *td = data;
273 char *fname, *str, *p;
275 p = str = strdup(input);
277 strip_blank_front(&str);
278 strip_blank_end(str);
280 if (!td->files_index)
283 while ((fname = strsep(&str, ":")) != NULL) {
294 static int str_directory_cb(void *data, const char fio_unused *str)
296 struct thread_data *td = data;
299 if (lstat(td->o.directory, &sb) < 0) {
300 log_err("fio: %s is not a directory\n", td->o.directory);
301 td_verror(td, errno, "lstat");
304 if (!S_ISDIR(sb.st_mode)) {
305 log_err("fio: %s is not a directory\n", td->o.directory);
312 static int str_opendir_cb(void *data, const char fio_unused *str)
314 struct thread_data *td = data;
316 if (!td->files_index)
319 return add_dir_files(td, td->o.opendir);
322 static int str_verify_offset_cb(void *data, unsigned int *off)
324 struct thread_data *td = data;
326 if (*off && *off < sizeof(struct verify_header)) {
327 log_err("fio: verify_offset too small\n");
331 td->o.verify_offset = *off;
335 static int str_verify_pattern_cb(void *data, unsigned int *off)
337 struct thread_data *td = data;
342 td->o.verify_pattern_bytes = 1;
344 td->o.verify_pattern_bytes = 2;
346 td->o.verify_pattern_bytes = 3;
348 td->o.verify_pattern_bytes = 4;
350 td->o.verify_pattern = *off;
354 #define __stringify_1(x) #x
355 #define __stringify(x) __stringify_1(x)
358 * Map of job/command line options
360 static struct fio_option options[] = {
362 .name = "description",
363 .type = FIO_OPT_STR_STORE,
364 .off1 = td_var_offset(description),
365 .help = "Text job description",
369 .type = FIO_OPT_STR_STORE,
370 .off1 = td_var_offset(name),
371 .help = "Name of this job",
375 .type = FIO_OPT_STR_STORE,
376 .off1 = td_var_offset(directory),
377 .cb = str_directory_cb,
378 .help = "Directory to store files in",
382 .type = FIO_OPT_STR_STORE,
383 .off1 = td_var_offset(filename),
384 .cb = str_filename_cb,
385 .help = "File(s) to use for the workload",
389 .type = FIO_OPT_STR_STORE,
390 .off1 = td_var_offset(opendir),
391 .cb = str_opendir_cb,
392 .help = "Recursively add files from this directory and down",
396 .alias = "readwrite",
399 .off1 = td_var_offset(td_ddir),
400 .help = "IO direction",
404 .oval = TD_DDIR_READ,
405 .help = "Sequential read",
408 .oval = TD_DDIR_WRITE,
409 .help = "Sequential write",
411 { .ival = "randread",
412 .oval = TD_DDIR_RANDREAD,
413 .help = "Random read",
415 { .ival = "randwrite",
416 .oval = TD_DDIR_RANDWRITE,
417 .help = "Random write",
421 .help = "Sequential read and write mix",
424 .oval = TD_DDIR_RANDRW,
425 .help = "Random read and write mix"
431 .type = FIO_OPT_STR_STORE,
432 .off1 = td_var_offset(ioengine),
433 .help = "IO engine to use",
437 .help = "Use read/write",
440 .help = "Use pread/pwrite",
443 .help = "Use readv/writev",
445 #ifdef FIO_HAVE_LIBAIO
447 .help = "Linux native asynchronous IO",
450 #ifdef FIO_HAVE_POSIXAIO
451 { .ival = "posixaio",
452 .help = "POSIX asynchronous IO",
456 .help = "Memory mapped IO",
458 #ifdef FIO_HAVE_SPLICE
460 .help = "splice/vmsplice based IO",
462 { .ival = "netsplice",
463 .help = "splice/vmsplice to/from the network",
468 .help = "SCSI generic v3 IO",
472 .help = "Testing engine (no data transfer)",
475 .help = "Network IO",
477 #ifdef FIO_HAVE_SYSLET
478 { .ival = "syslet-rw",
479 .help = "syslet enabled async pread/pwrite IO",
483 .help = "CPU cycler burner engine",
485 #ifdef FIO_HAVE_GUASI
487 .help = "GUASI IO engine",
490 { .ival = "external",
491 .help = "Load external engine (append name)",
498 .off1 = td_var_offset(iodepth),
499 .help = "Amount of IO buffers to keep in flight",
504 .name = "iodepth_batch",
506 .off1 = td_var_offset(iodepth_batch),
507 .help = "Number of IO to submit in one go",
513 .name = "iodepth_low",
515 .off1 = td_var_offset(iodepth_low),
516 .help = "Low water mark for queuing depth",
521 .type = FIO_OPT_STR_VAL,
522 .off1 = td_var_offset(size),
524 .help = "Total size of device or files",
527 .name = "fill_device",
528 .type = FIO_OPT_BOOL,
529 .off1 = td_var_offset(fill_device),
530 .help = "Write until an ENOSPC error occurs",
535 .type = FIO_OPT_STR_VAL,
536 .off1 = td_var_offset(file_size_low),
537 .off2 = td_var_offset(file_size_high),
539 .help = "Size of individual files",
543 .alias = "fileoffset",
544 .type = FIO_OPT_STR_VAL,
545 .off1 = td_var_offset(start_offset),
546 .help = "Start IO from this offset",
551 .alias = "blocksize",
552 .type = FIO_OPT_STR_VAL_INT,
553 .off1 = td_var_offset(bs[DDIR_READ]),
554 .off2 = td_var_offset(bs[DDIR_WRITE]),
556 .help = "Block size unit",
562 .alias = "blocksize_range",
563 .type = FIO_OPT_RANGE,
564 .off1 = td_var_offset(min_bs[DDIR_READ]),
565 .off2 = td_var_offset(max_bs[DDIR_READ]),
566 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
567 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
569 .help = "Set block size range (in more detail than bs)",
575 .cb = str_bssplit_cb,
576 .help = "Set a specific mix of block sizes",
580 .name = "bs_unaligned",
581 .alias = "blocksize_unaligned",
582 .type = FIO_OPT_STR_SET,
583 .off1 = td_var_offset(bs_unaligned),
584 .help = "Don't sector align IO buffer sizes",
588 .name = "randrepeat",
589 .type = FIO_OPT_BOOL,
590 .off1 = td_var_offset(rand_repeatable),
591 .help = "Use repeatable random IO pattern",
596 .name = "norandommap",
597 .type = FIO_OPT_STR_SET,
598 .off1 = td_var_offset(norandommap),
599 .help = "Accept potential duplicate random blocks",
605 .off1 = td_var_offset(nr_files),
606 .help = "Split job workload between this number of files",
612 .off1 = td_var_offset(open_files),
613 .help = "Number of files to keep open at the same time",
616 .name = "file_service_type",
619 .off1 = td_var_offset(file_service_type),
620 .help = "How to select which file to service next",
624 .oval = FIO_FSERVICE_RANDOM,
625 .help = "Choose a file at random",
627 { .ival = "roundrobin",
628 .oval = FIO_FSERVICE_RR,
629 .help = "Round robin select files",
635 .name = "fadvise_hint",
636 .type = FIO_OPT_BOOL,
637 .off1 = td_var_offset(fadvise_hint),
638 .help = "Use fadvise() to advise the kernel on IO pattern",
644 .off1 = td_var_offset(fsync_blocks),
645 .help = "Issue fsync for writes every given number of blocks",
650 .type = FIO_OPT_BOOL,
651 .off1 = td_var_offset(odirect),
652 .help = "Use O_DIRECT IO (negates buffered)",
657 .type = FIO_OPT_BOOL,
658 .off1 = td_var_offset(odirect),
660 .help = "Use buffered IO (negates direct)",
665 .type = FIO_OPT_BOOL,
666 .off1 = td_var_offset(overwrite),
667 .help = "When writing, set whether to overwrite current data",
673 .off1 = td_var_offset(loops),
674 .help = "Number of times to run the job",
680 .off1 = td_var_offset(numjobs),
681 .help = "Duplicate this job this many times",
685 .name = "startdelay",
687 .off1 = td_var_offset(start_delay),
688 .help = "Only start job when this period has passed",
694 .type = FIO_OPT_STR_VAL_TIME,
695 .off1 = td_var_offset(timeout),
696 .help = "Stop workload when this amount of time has passed",
700 .name = "time_based",
701 .type = FIO_OPT_STR_SET,
702 .off1 = td_var_offset(time_based),
703 .help = "Keep running until runtime/timeout is met",
710 .off1 = td_var_offset(mem_type),
711 .help = "Backing type for IO buffers",
716 .help = "Use malloc(3) for IO buffers",
720 .help = "Use shared memory segments for IO buffers",
722 #ifdef FIO_HAVE_HUGETLB
725 .help = "Like shm, but use huge pages",
730 .help = "Use mmap(2) (file or anon) for IO buffers",
732 #ifdef FIO_HAVE_HUGETLB
733 { .ival = "mmaphuge",
734 .oval = MEM_MMAPHUGE,
735 .help = "Like mmap, but use huge pages",
743 .off1 = td_var_offset(verify),
744 .help = "Verify data written",
749 .help = "Don't do IO verification",
753 .help = "Use md5 checksums for verification",
756 .oval = VERIFY_CRC64,
757 .help = "Use crc64 checksums for verification",
760 .oval = VERIFY_CRC32,
761 .help = "Use crc32 checksums for verification",
764 .oval = VERIFY_CRC16,
765 .help = "Use crc16 checksums for verification",
769 .help = "Use crc7 checksums for verification",
772 .oval = VERIFY_SHA256,
773 .help = "Use sha256 checksums for verification",
776 .oval = VERIFY_SHA512,
777 .help = "Use sha512 checksums for verification",
781 .help = "Use io information",
786 .help = "Pretend to verify",
792 .type = FIO_OPT_BOOL,
793 .off1 = td_var_offset(do_verify),
794 .help = "Run verification stage after write",
799 .name = "verifysort",
800 .type = FIO_OPT_BOOL,
801 .off1 = td_var_offset(verifysort),
802 .help = "Sort written verify blocks for read back",
807 .name = "verify_interval",
808 .type = FIO_OPT_STR_VAL_INT,
809 .off1 = td_var_offset(verify_interval),
810 .minval = 2 * sizeof(struct verify_header),
811 .help = "Store verify buffer header every N bytes",
815 .name = "verify_offset",
816 .type = FIO_OPT_STR_VAL_INT,
817 .help = "Offset verify header location by N bytes",
819 .cb = str_verify_offset_cb,
823 .name = "verify_pattern",
825 .cb = str_verify_pattern_cb,
826 .help = "Fill pattern for IO buffers",
830 .name = "verify_fatal",
831 .type = FIO_OPT_BOOL,
832 .off1 = td_var_offset(verify_fatal),
834 .help = "Exit on a single verify failure, don't continue",
838 .name = "write_iolog",
839 .type = FIO_OPT_STR_STORE,
840 .off1 = td_var_offset(write_iolog_file),
841 .help = "Store IO pattern to file",
844 .name = "read_iolog",
845 .type = FIO_OPT_STR_STORE,
846 .off1 = td_var_offset(read_iolog_file),
847 .help = "Playback IO pattern from file",
850 .name = "exec_prerun",
851 .type = FIO_OPT_STR_STORE,
852 .off1 = td_var_offset(exec_prerun),
853 .help = "Execute this file prior to running job",
856 .name = "exec_postrun",
857 .type = FIO_OPT_STR_STORE,
858 .off1 = td_var_offset(exec_postrun),
859 .help = "Execute this file after running job",
861 #ifdef FIO_HAVE_IOSCHED_SWITCH
863 .name = "ioscheduler",
864 .type = FIO_OPT_STR_STORE,
865 .off1 = td_var_offset(ioscheduler),
866 .help = "Use this IO scheduler on the backing device",
871 .type = FIO_OPT_STR_VAL,
872 .off1 = td_var_offset(zone_size),
873 .help = "Give size of an IO zone",
878 .type = FIO_OPT_STR_VAL,
879 .off1 = td_var_offset(zone_skip),
880 .help = "Space between IO zones",
885 .type = FIO_OPT_STR_VAL,
886 .cb = str_lockmem_cb,
887 .help = "Lock down this amount of memory",
893 .off1 = td_var_offset(rwmix[DDIR_READ]),
895 .help = "Percentage of mixed workload that is reads",
899 .name = "rwmixwrite",
901 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
903 .help = "Percentage of mixed workload that is writes",
907 .name = "rwmixcycle",
909 .off1 = td_var_offset(rwmixcycle),
910 .help = "Cycle period for mixed read/write workloads (msec)",
912 .parent = "rwmixread",
917 .off1 = td_var_offset(nice),
918 .help = "Set job CPU nice value",
923 #ifdef FIO_HAVE_IOPRIO
928 .help = "Set job IO priority value",
935 .cb = str_prioclass_cb,
936 .help = "Set job IO priority class",
944 .off1 = td_var_offset(thinktime),
945 .help = "Idle time between IO buffers (usec)",
949 .name = "thinktime_spin",
951 .off1 = td_var_offset(thinktime_spin),
952 .help = "Start think time by spinning this amount (usec)",
954 .parent = "thinktime",
957 .name = "thinktime_blocks",
959 .off1 = td_var_offset(thinktime_blocks),
960 .help = "IO buffer period between 'thinktime'",
962 .parent = "thinktime",
967 .off1 = td_var_offset(rate),
968 .help = "Set bandwidth rate",
973 .off1 = td_var_offset(ratemin),
974 .help = "Job must meet this rate or it will be shutdown",
980 .off1 = td_var_offset(rate_iops),
981 .help = "Limit IO used to this number of IO operations/sec",
984 .name = "rate_iops_min",
986 .off1 = td_var_offset(rate_iops_min),
987 .help = "Job must meet this rate or it will be shutdown",
988 .parent = "rate_iops",
993 .off1 = td_var_offset(ratecycle),
994 .help = "Window average for rate limits (msec)",
999 .name = "invalidate",
1000 .type = FIO_OPT_BOOL,
1001 .off1 = td_var_offset(invalidate_cache),
1002 .help = "Invalidate buffer/page cache prior to running job",
1007 .type = FIO_OPT_BOOL,
1008 .off1 = td_var_offset(sync_io),
1009 .help = "Use O_SYNC for buffered writes",
1011 .parent = "buffered",
1014 .name = "bwavgtime",
1015 .type = FIO_OPT_INT,
1016 .off1 = td_var_offset(bw_avg_time),
1017 .help = "Time window over which to calculate bandwidth (msec)",
1021 .name = "create_serialize",
1022 .type = FIO_OPT_BOOL,
1023 .off1 = td_var_offset(create_serialize),
1024 .help = "Serialize creating of job files",
1028 .name = "create_fsync",
1029 .type = FIO_OPT_BOOL,
1030 .off1 = td_var_offset(create_fsync),
1031 .help = "Fsync file after creation",
1036 .type = FIO_OPT_INT,
1037 .off1 = td_var_offset(cpuload),
1038 .help = "Use this percentage of CPU",
1041 .name = "cpuchunks",
1042 .type = FIO_OPT_INT,
1043 .off1 = td_var_offset(cpucycle),
1044 .help = "Length of the CPU burn cycles (usecs)",
1046 .parent = "cpuload",
1048 #ifdef FIO_HAVE_CPU_AFFINITY
1051 .type = FIO_OPT_INT,
1052 .cb = str_cpumask_cb,
1053 .help = "CPU affinity mask",
1056 .name = "cpus_allowed",
1057 .type = FIO_OPT_STR,
1058 .cb = str_cpus_allowed_cb,
1059 .help = "Set CPUs allowed",
1063 .name = "end_fsync",
1064 .type = FIO_OPT_BOOL,
1065 .off1 = td_var_offset(end_fsync),
1066 .help = "Include fsync at the end of job",
1070 .name = "fsync_on_close",
1071 .type = FIO_OPT_BOOL,
1072 .off1 = td_var_offset(fsync_on_close),
1073 .help = "fsync files on close",
1078 .type = FIO_OPT_BOOL,
1079 .off1 = td_var_offset(unlink),
1080 .help = "Unlink created files after job has completed",
1085 .type = FIO_OPT_STR_SET,
1086 .cb = str_exitall_cb,
1087 .help = "Terminate all jobs when one exits",
1090 .name = "stonewall",
1091 .type = FIO_OPT_STR_SET,
1092 .off1 = td_var_offset(stonewall),
1093 .help = "Insert a hard barrier between this job and previous",
1096 .name = "new_group",
1097 .type = FIO_OPT_STR_SET,
1098 .off1 = td_var_offset(new_group),
1099 .help = "Mark the start of a new group (for reporting)",
1103 .type = FIO_OPT_STR_SET,
1104 .off1 = td_var_offset(use_thread),
1105 .help = "Use threads instead of forks",
1108 .name = "write_bw_log",
1109 .type = FIO_OPT_STR_SET,
1110 .off1 = td_var_offset(write_bw_log),
1111 .help = "Write log of bandwidth during run",
1114 .name = "write_lat_log",
1115 .type = FIO_OPT_STR_SET,
1116 .off1 = td_var_offset(write_lat_log),
1117 .help = "Write log of latency during run",
1120 .name = "hugepage-size",
1121 .type = FIO_OPT_STR_VAL,
1122 .off1 = td_var_offset(hugepage_size),
1123 .help = "When using hugepages, specify size of each page",
1124 .def = __stringify(FIO_HUGE_PAGE),
1127 .name = "group_reporting",
1128 .type = FIO_OPT_STR_SET,
1129 .off1 = td_var_offset(group_reporting),
1130 .help = "Do reporting on a per-group basis",
1133 .name = "zero_buffers",
1134 .type = FIO_OPT_STR_SET,
1135 .off1 = td_var_offset(zero_buffers),
1136 .help = "Init IO buffers to all zeroes",
1138 #ifdef FIO_HAVE_DISK_UTIL
1140 .name = "disk_util",
1141 .type = FIO_OPT_BOOL,
1142 .off1 = td_var_offset(do_disk_util),
1143 .help = "Log disk utilization stats",
1152 void fio_options_dup_and_init(struct option *long_options)
1154 struct fio_option *o;
1157 options_init(options);
1160 while (long_options[i].name)
1165 long_options[i].name = o->name;
1166 long_options[i].val = FIO_GETOPT_JOB;
1167 if (o->type == FIO_OPT_STR_SET)
1168 long_options[i].has_arg = no_argument;
1170 long_options[i].has_arg = required_argument;
1174 assert(i < FIO_NR_OPTIONS);
1178 int fio_option_parse(struct thread_data *td, const char *opt)
1180 return parse_option(opt, options, td);
1183 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1185 return parse_cmd_option(opt, val, options, td);
1188 void fio_fill_default_options(struct thread_data *td)
1190 fill_default_options(td, options);
1193 int fio_show_option_help(const char *opt)
1195 return show_cmd_help(options, opt);
1198 static void __options_mem(struct thread_data *td, int alloc)
1200 struct thread_options *o = &td->o;
1201 struct fio_option *opt;
1205 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1206 if (opt->type != FIO_OPT_STR_STORE)
1209 ptr = (void *) o + opt->off1;
1212 *ptr = strdup(*ptr);
1222 * dupe FIO_OPT_STR_STORE options
1224 void options_mem_dupe(struct thread_data *td)
1226 __options_mem(td, 1);
1229 void options_mem_free(struct thread_data fio_unused *td)
1232 __options_mem(td, 0);