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;
259 static int str_fst_cb(void *data, const char *str)
261 struct thread_data *td = data;
262 char *nr = get_opt_postfix(str);
264 td->file_service_nr = 1;
266 td->file_service_nr = atoi(nr);
271 static int str_filename_cb(void *data, const char *input)
273 struct thread_data *td = data;
274 char *fname, *str, *p;
276 p = str = strdup(input);
278 strip_blank_front(&str);
279 strip_blank_end(str);
281 if (!td->files_index)
284 while ((fname = strsep(&str, ":")) != NULL) {
295 static int str_directory_cb(void *data, const char fio_unused *str)
297 struct thread_data *td = data;
300 if (lstat(td->o.directory, &sb) < 0) {
301 log_err("fio: %s is not a directory\n", td->o.directory);
302 td_verror(td, errno, "lstat");
305 if (!S_ISDIR(sb.st_mode)) {
306 log_err("fio: %s is not a directory\n", td->o.directory);
313 static int str_opendir_cb(void *data, const char fio_unused *str)
315 struct thread_data *td = data;
317 if (!td->files_index)
320 return add_dir_files(td, td->o.opendir);
323 static int str_verify_offset_cb(void *data, unsigned int *off)
325 struct thread_data *td = data;
327 if (*off && *off < sizeof(struct verify_header)) {
328 log_err("fio: verify_offset too small\n");
332 td->o.verify_offset = *off;
336 static int str_verify_pattern_cb(void *data, unsigned int *off)
338 struct thread_data *td = data;
343 td->o.verify_pattern_bytes = 1;
345 td->o.verify_pattern_bytes = 2;
347 td->o.verify_pattern_bytes = 3;
349 td->o.verify_pattern_bytes = 4;
351 td->o.verify_pattern = *off;
355 #define __stringify_1(x) #x
356 #define __stringify(x) __stringify_1(x)
359 * Map of job/command line options
361 static struct fio_option options[] = {
363 .name = "description",
364 .type = FIO_OPT_STR_STORE,
365 .off1 = td_var_offset(description),
366 .help = "Text job description",
370 .type = FIO_OPT_STR_STORE,
371 .off1 = td_var_offset(name),
372 .help = "Name of this job",
376 .type = FIO_OPT_STR_STORE,
377 .off1 = td_var_offset(directory),
378 .cb = str_directory_cb,
379 .help = "Directory to store files in",
383 .type = FIO_OPT_STR_STORE,
384 .off1 = td_var_offset(filename),
385 .cb = str_filename_cb,
386 .help = "File(s) to use for the workload",
390 .type = FIO_OPT_STR_STORE,
391 .off1 = td_var_offset(opendir),
392 .cb = str_opendir_cb,
393 .help = "Recursively add files from this directory and down",
397 .alias = "readwrite",
400 .off1 = td_var_offset(td_ddir),
401 .help = "IO direction",
405 .oval = TD_DDIR_READ,
406 .help = "Sequential read",
409 .oval = TD_DDIR_WRITE,
410 .help = "Sequential write",
412 { .ival = "randread",
413 .oval = TD_DDIR_RANDREAD,
414 .help = "Random read",
416 { .ival = "randwrite",
417 .oval = TD_DDIR_RANDWRITE,
418 .help = "Random write",
422 .help = "Sequential read and write mix",
425 .oval = TD_DDIR_RANDRW,
426 .help = "Random read and write mix"
432 .type = FIO_OPT_STR_STORE,
433 .off1 = td_var_offset(ioengine),
434 .help = "IO engine to use",
438 .help = "Use read/write",
441 .help = "Use pread/pwrite",
444 .help = "Use readv/writev",
446 #ifdef FIO_HAVE_LIBAIO
448 .help = "Linux native asynchronous IO",
451 #ifdef FIO_HAVE_POSIXAIO
452 { .ival = "posixaio",
453 .help = "POSIX asynchronous IO",
457 .help = "Memory mapped IO",
459 #ifdef FIO_HAVE_SPLICE
461 .help = "splice/vmsplice based IO",
463 { .ival = "netsplice",
464 .help = "splice/vmsplice to/from the network",
469 .help = "SCSI generic v3 IO",
473 .help = "Testing engine (no data transfer)",
476 .help = "Network IO",
478 #ifdef FIO_HAVE_SYSLET
479 { .ival = "syslet-rw",
480 .help = "syslet enabled async pread/pwrite IO",
484 .help = "CPU cycler burner engine",
486 #ifdef FIO_HAVE_GUASI
488 .help = "GUASI IO engine",
491 { .ival = "external",
492 .help = "Load external engine (append name)",
499 .off1 = td_var_offset(iodepth),
500 .help = "Amount of IO buffers to keep in flight",
505 .name = "iodepth_batch",
507 .off1 = td_var_offset(iodepth_batch),
508 .help = "Number of IO to submit in one go",
514 .name = "iodepth_low",
516 .off1 = td_var_offset(iodepth_low),
517 .help = "Low water mark for queuing depth",
522 .type = FIO_OPT_STR_VAL,
523 .off1 = td_var_offset(size),
525 .help = "Total size of device or files",
528 .name = "fill_device",
529 .type = FIO_OPT_BOOL,
530 .off1 = td_var_offset(fill_device),
531 .help = "Write until an ENOSPC error occurs",
536 .type = FIO_OPT_STR_VAL,
537 .off1 = td_var_offset(file_size_low),
538 .off2 = td_var_offset(file_size_high),
540 .help = "Size of individual files",
544 .alias = "fileoffset",
545 .type = FIO_OPT_STR_VAL,
546 .off1 = td_var_offset(start_offset),
547 .help = "Start IO from this offset",
552 .alias = "blocksize",
553 .type = FIO_OPT_STR_VAL_INT,
554 .off1 = td_var_offset(bs[DDIR_READ]),
555 .off2 = td_var_offset(bs[DDIR_WRITE]),
557 .help = "Block size unit",
563 .alias = "blocksize_range",
564 .type = FIO_OPT_RANGE,
565 .off1 = td_var_offset(min_bs[DDIR_READ]),
566 .off2 = td_var_offset(max_bs[DDIR_READ]),
567 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
568 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
570 .help = "Set block size range (in more detail than bs)",
576 .cb = str_bssplit_cb,
577 .help = "Set a specific mix of block sizes",
581 .name = "bs_unaligned",
582 .alias = "blocksize_unaligned",
583 .type = FIO_OPT_STR_SET,
584 .off1 = td_var_offset(bs_unaligned),
585 .help = "Don't sector align IO buffer sizes",
589 .name = "randrepeat",
590 .type = FIO_OPT_BOOL,
591 .off1 = td_var_offset(rand_repeatable),
592 .help = "Use repeatable random IO pattern",
597 .name = "norandommap",
598 .type = FIO_OPT_STR_SET,
599 .off1 = td_var_offset(norandommap),
600 .help = "Accept potential duplicate random blocks",
606 .off1 = td_var_offset(nr_files),
607 .help = "Split job workload between this number of files",
613 .off1 = td_var_offset(open_files),
614 .help = "Number of files to keep open at the same time",
617 .name = "file_service_type",
620 .off1 = td_var_offset(file_service_type),
621 .help = "How to select which file to service next",
625 .oval = FIO_FSERVICE_RANDOM,
626 .help = "Choose a file at random",
628 { .ival = "roundrobin",
629 .oval = FIO_FSERVICE_RR,
630 .help = "Round robin select files",
636 .name = "fadvise_hint",
637 .type = FIO_OPT_BOOL,
638 .off1 = td_var_offset(fadvise_hint),
639 .help = "Use fadvise() to advise the kernel on IO pattern",
645 .off1 = td_var_offset(fsync_blocks),
646 .help = "Issue fsync for writes every given number of blocks",
651 .type = FIO_OPT_BOOL,
652 .off1 = td_var_offset(odirect),
653 .help = "Use O_DIRECT IO (negates buffered)",
658 .type = FIO_OPT_BOOL,
659 .off1 = td_var_offset(odirect),
661 .help = "Use buffered IO (negates direct)",
666 .type = FIO_OPT_BOOL,
667 .off1 = td_var_offset(overwrite),
668 .help = "When writing, set whether to overwrite current data",
674 .off1 = td_var_offset(loops),
675 .help = "Number of times to run the job",
681 .off1 = td_var_offset(numjobs),
682 .help = "Duplicate this job this many times",
686 .name = "startdelay",
688 .off1 = td_var_offset(start_delay),
689 .help = "Only start job when this period has passed",
695 .type = FIO_OPT_STR_VAL_TIME,
696 .off1 = td_var_offset(timeout),
697 .help = "Stop workload when this amount of time has passed",
701 .name = "time_based",
702 .type = FIO_OPT_STR_SET,
703 .off1 = td_var_offset(time_based),
704 .help = "Keep running until runtime/timeout is met",
711 .off1 = td_var_offset(mem_type),
712 .help = "Backing type for IO buffers",
717 .help = "Use malloc(3) for IO buffers",
721 .help = "Use shared memory segments for IO buffers",
723 #ifdef FIO_HAVE_HUGETLB
726 .help = "Like shm, but use huge pages",
731 .help = "Use mmap(2) (file or anon) for IO buffers",
733 #ifdef FIO_HAVE_HUGETLB
734 { .ival = "mmaphuge",
735 .oval = MEM_MMAPHUGE,
736 .help = "Like mmap, but use huge pages",
744 .off1 = td_var_offset(verify),
745 .help = "Verify data written",
750 .help = "Don't do IO verification",
754 .help = "Use md5 checksums for verification",
757 .oval = VERIFY_CRC64,
758 .help = "Use crc64 checksums for verification",
761 .oval = VERIFY_CRC32,
762 .help = "Use crc32 checksums for verification",
765 .oval = VERIFY_CRC16,
766 .help = "Use crc16 checksums for verification",
770 .help = "Use crc7 checksums for verification",
773 .oval = VERIFY_SHA256,
774 .help = "Use sha256 checksums for verification",
777 .oval = VERIFY_SHA512,
778 .help = "Use sha512 checksums for verification",
782 .help = "Use io information",
787 .help = "Pretend to verify",
793 .type = FIO_OPT_BOOL,
794 .off1 = td_var_offset(do_verify),
795 .help = "Run verification stage after write",
800 .name = "verifysort",
801 .type = FIO_OPT_BOOL,
802 .off1 = td_var_offset(verifysort),
803 .help = "Sort written verify blocks for read back",
808 .name = "verify_interval",
809 .type = FIO_OPT_STR_VAL_INT,
810 .off1 = td_var_offset(verify_interval),
811 .minval = 2 * sizeof(struct verify_header),
812 .help = "Store verify buffer header every N bytes",
816 .name = "verify_offset",
817 .type = FIO_OPT_STR_VAL_INT,
818 .help = "Offset verify header location by N bytes",
820 .cb = str_verify_offset_cb,
824 .name = "verify_pattern",
826 .cb = str_verify_pattern_cb,
827 .help = "Fill pattern for IO buffers",
831 .name = "verify_fatal",
832 .type = FIO_OPT_BOOL,
833 .off1 = td_var_offset(verify_fatal),
835 .help = "Exit on a single verify failure, don't continue",
839 .name = "write_iolog",
840 .type = FIO_OPT_STR_STORE,
841 .off1 = td_var_offset(write_iolog_file),
842 .help = "Store IO pattern to file",
845 .name = "read_iolog",
846 .type = FIO_OPT_STR_STORE,
847 .off1 = td_var_offset(read_iolog_file),
848 .help = "Playback IO pattern from file",
851 .name = "exec_prerun",
852 .type = FIO_OPT_STR_STORE,
853 .off1 = td_var_offset(exec_prerun),
854 .help = "Execute this file prior to running job",
857 .name = "exec_postrun",
858 .type = FIO_OPT_STR_STORE,
859 .off1 = td_var_offset(exec_postrun),
860 .help = "Execute this file after running job",
862 #ifdef FIO_HAVE_IOSCHED_SWITCH
864 .name = "ioscheduler",
865 .type = FIO_OPT_STR_STORE,
866 .off1 = td_var_offset(ioscheduler),
867 .help = "Use this IO scheduler on the backing device",
872 .type = FIO_OPT_STR_VAL,
873 .off1 = td_var_offset(zone_size),
874 .help = "Give size of an IO zone",
879 .type = FIO_OPT_STR_VAL,
880 .off1 = td_var_offset(zone_skip),
881 .help = "Space between IO zones",
886 .type = FIO_OPT_STR_VAL,
887 .cb = str_lockmem_cb,
888 .help = "Lock down this amount of memory",
894 .off1 = td_var_offset(rwmix[DDIR_READ]),
896 .help = "Percentage of mixed workload that is reads",
900 .name = "rwmixwrite",
902 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
904 .help = "Percentage of mixed workload that is writes",
908 .name = "rwmixcycle",
910 .off1 = td_var_offset(rwmixcycle),
911 .help = "Cycle period for mixed read/write workloads (msec)",
913 .parent = "rwmixread",
918 .off1 = td_var_offset(nice),
919 .help = "Set job CPU nice value",
924 #ifdef FIO_HAVE_IOPRIO
929 .help = "Set job IO priority value",
936 .cb = str_prioclass_cb,
937 .help = "Set job IO priority class",
945 .off1 = td_var_offset(thinktime),
946 .help = "Idle time between IO buffers (usec)",
950 .name = "thinktime_spin",
952 .off1 = td_var_offset(thinktime_spin),
953 .help = "Start think time by spinning this amount (usec)",
955 .parent = "thinktime",
958 .name = "thinktime_blocks",
960 .off1 = td_var_offset(thinktime_blocks),
961 .help = "IO buffer period between 'thinktime'",
963 .parent = "thinktime",
968 .off1 = td_var_offset(rate),
969 .help = "Set bandwidth rate",
974 .off1 = td_var_offset(ratemin),
975 .help = "Job must meet this rate or it will be shutdown",
981 .off1 = td_var_offset(rate_iops),
982 .help = "Limit IO used to this number of IO operations/sec",
985 .name = "rate_iops_min",
987 .off1 = td_var_offset(rate_iops_min),
988 .help = "Job must meet this rate or it will be shutdown",
989 .parent = "rate_iops",
994 .off1 = td_var_offset(ratecycle),
995 .help = "Window average for rate limits (msec)",
1000 .name = "invalidate",
1001 .type = FIO_OPT_BOOL,
1002 .off1 = td_var_offset(invalidate_cache),
1003 .help = "Invalidate buffer/page cache prior to running job",
1008 .type = FIO_OPT_BOOL,
1009 .off1 = td_var_offset(sync_io),
1010 .help = "Use O_SYNC for buffered writes",
1012 .parent = "buffered",
1015 .name = "bwavgtime",
1016 .type = FIO_OPT_INT,
1017 .off1 = td_var_offset(bw_avg_time),
1018 .help = "Time window over which to calculate bandwidth (msec)",
1022 .name = "create_serialize",
1023 .type = FIO_OPT_BOOL,
1024 .off1 = td_var_offset(create_serialize),
1025 .help = "Serialize creating of job files",
1029 .name = "create_fsync",
1030 .type = FIO_OPT_BOOL,
1031 .off1 = td_var_offset(create_fsync),
1032 .help = "Fsync file after creation",
1037 .type = FIO_OPT_INT,
1038 .off1 = td_var_offset(cpuload),
1039 .help = "Use this percentage of CPU",
1042 .name = "cpuchunks",
1043 .type = FIO_OPT_INT,
1044 .off1 = td_var_offset(cpucycle),
1045 .help = "Length of the CPU burn cycles (usecs)",
1047 .parent = "cpuload",
1049 #ifdef FIO_HAVE_CPU_AFFINITY
1052 .type = FIO_OPT_INT,
1053 .cb = str_cpumask_cb,
1054 .help = "CPU affinity mask",
1057 .name = "cpus_allowed",
1058 .type = FIO_OPT_STR,
1059 .cb = str_cpus_allowed_cb,
1060 .help = "Set CPUs allowed",
1064 .name = "end_fsync",
1065 .type = FIO_OPT_BOOL,
1066 .off1 = td_var_offset(end_fsync),
1067 .help = "Include fsync at the end of job",
1071 .name = "fsync_on_close",
1072 .type = FIO_OPT_BOOL,
1073 .off1 = td_var_offset(fsync_on_close),
1074 .help = "fsync files on close",
1079 .type = FIO_OPT_BOOL,
1080 .off1 = td_var_offset(unlink),
1081 .help = "Unlink created files after job has completed",
1086 .type = FIO_OPT_STR_SET,
1087 .cb = str_exitall_cb,
1088 .help = "Terminate all jobs when one exits",
1091 .name = "stonewall",
1092 .type = FIO_OPT_STR_SET,
1093 .off1 = td_var_offset(stonewall),
1094 .help = "Insert a hard barrier between this job and previous",
1097 .name = "new_group",
1098 .type = FIO_OPT_STR_SET,
1099 .off1 = td_var_offset(new_group),
1100 .help = "Mark the start of a new group (for reporting)",
1104 .type = FIO_OPT_STR_SET,
1105 .off1 = td_var_offset(use_thread),
1106 .help = "Use threads instead of forks",
1109 .name = "write_bw_log",
1110 .type = FIO_OPT_STR_SET,
1111 .off1 = td_var_offset(write_bw_log),
1112 .help = "Write log of bandwidth during run",
1115 .name = "write_lat_log",
1116 .type = FIO_OPT_STR_SET,
1117 .off1 = td_var_offset(write_lat_log),
1118 .help = "Write log of latency during run",
1121 .name = "hugepage-size",
1122 .type = FIO_OPT_STR_VAL,
1123 .off1 = td_var_offset(hugepage_size),
1124 .help = "When using hugepages, specify size of each page",
1125 .def = __stringify(FIO_HUGE_PAGE),
1128 .name = "group_reporting",
1129 .type = FIO_OPT_STR_SET,
1130 .off1 = td_var_offset(group_reporting),
1131 .help = "Do reporting on a per-group basis",
1134 .name = "zero_buffers",
1135 .type = FIO_OPT_STR_SET,
1136 .off1 = td_var_offset(zero_buffers),
1137 .help = "Init IO buffers to all zeroes",
1139 #ifdef FIO_HAVE_DISK_UTIL
1141 .name = "disk_util",
1142 .type = FIO_OPT_BOOL,
1143 .off1 = td_var_offset(do_disk_util),
1144 .help = "Log disk utilization stats",
1153 void fio_options_dup_and_init(struct option *long_options)
1155 struct fio_option *o;
1158 options_init(options);
1161 while (long_options[i].name)
1166 long_options[i].name = o->name;
1167 long_options[i].val = FIO_GETOPT_JOB;
1168 if (o->type == FIO_OPT_STR_SET)
1169 long_options[i].has_arg = no_argument;
1171 long_options[i].has_arg = required_argument;
1175 assert(i < FIO_NR_OPTIONS);
1179 int fio_option_parse(struct thread_data *td, const char *opt)
1181 return parse_option(opt, options, td);
1184 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1186 return parse_cmd_option(opt, val, options, td);
1189 void fio_fill_default_options(struct thread_data *td)
1191 fill_default_options(td, options);
1194 int fio_show_option_help(const char *opt)
1196 return show_cmd_help(options, opt);
1199 static void __options_mem(struct thread_data *td, int alloc)
1201 struct thread_options *o = &td->o;
1202 struct fio_option *opt;
1206 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1207 if (opt->type != FIO_OPT_STR_STORE)
1210 ptr = (void *) o + opt->off1;
1213 *ptr = strdup(*ptr);
1223 * dupe FIO_OPT_STR_STORE options
1225 void options_mem_dupe(struct thread_data *td)
1227 __options_mem(td, 1);
1230 void options_mem_free(struct thread_data fio_unused *td)
1233 __options_mem(td, 0);