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",
443 #ifdef FIO_HAVE_LIBAIO
445 .help = "Linux native asynchronous IO",
448 #ifdef FIO_HAVE_POSIXAIO
449 { .ival = "posixaio",
450 .help = "POSIX asynchronous IO",
454 .help = "Memory mapped IO",
456 #ifdef FIO_HAVE_SPLICE
458 .help = "splice/vmsplice based IO",
460 { .ival = "netsplice",
461 .help = "splice/vmsplice to/from the network",
466 .help = "SCSI generic v3 IO",
470 .help = "Testing engine (no data transfer)",
473 .help = "Network IO",
475 #ifdef FIO_HAVE_SYSLET
476 { .ival = "syslet-rw",
477 .help = "syslet enabled async pread/pwrite IO",
481 .help = "CPU cycler burner engine",
483 #ifdef FIO_HAVE_GUASI
485 .help = "GUASI IO engine",
488 { .ival = "external",
489 .help = "Load external engine (append name)",
496 .off1 = td_var_offset(iodepth),
497 .help = "Amount of IO buffers to keep in flight",
502 .name = "iodepth_batch",
504 .off1 = td_var_offset(iodepth_batch),
505 .help = "Number of IO to submit in one go",
509 .name = "iodepth_low",
511 .off1 = td_var_offset(iodepth_low),
512 .help = "Low water mark for queuing depth",
517 .type = FIO_OPT_STR_VAL,
518 .off1 = td_var_offset(size),
520 .help = "Total size of device or files",
523 .name = "fill_device",
524 .type = FIO_OPT_BOOL,
525 .off1 = td_var_offset(fill_device),
526 .help = "Write until an ENOSPC error occurs",
531 .type = FIO_OPT_STR_VAL,
532 .off1 = td_var_offset(file_size_low),
533 .off2 = td_var_offset(file_size_high),
535 .help = "Size of individual files",
539 .alias = "fileoffset",
540 .type = FIO_OPT_STR_VAL,
541 .off1 = td_var_offset(start_offset),
542 .help = "Start IO from this offset",
547 .alias = "blocksize",
548 .type = FIO_OPT_STR_VAL_INT,
549 .off1 = td_var_offset(bs[DDIR_READ]),
550 .off2 = td_var_offset(bs[DDIR_WRITE]),
552 .help = "Block size unit",
558 .alias = "blocksize_range",
559 .type = FIO_OPT_RANGE,
560 .off1 = td_var_offset(min_bs[DDIR_READ]),
561 .off2 = td_var_offset(max_bs[DDIR_READ]),
562 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
563 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
565 .help = "Set block size range (in more detail than bs)",
571 .cb = str_bssplit_cb,
572 .help = "Set a specific mix of block sizes",
576 .name = "bs_unaligned",
577 .alias = "blocksize_unaligned",
578 .type = FIO_OPT_STR_SET,
579 .off1 = td_var_offset(bs_unaligned),
580 .help = "Don't sector align IO buffer sizes",
584 .name = "randrepeat",
585 .type = FIO_OPT_BOOL,
586 .off1 = td_var_offset(rand_repeatable),
587 .help = "Use repeatable random IO pattern",
592 .name = "norandommap",
593 .type = FIO_OPT_STR_SET,
594 .off1 = td_var_offset(norandommap),
595 .help = "Accept potential duplicate random blocks",
601 .off1 = td_var_offset(nr_files),
602 .help = "Split job workload between this number of files",
608 .off1 = td_var_offset(open_files),
609 .help = "Number of files to keep open at the same time",
612 .name = "file_service_type",
615 .off1 = td_var_offset(file_service_type),
616 .help = "How to select which file to service next",
620 .oval = FIO_FSERVICE_RANDOM,
621 .help = "Choose a file at random",
623 { .ival = "roundrobin",
624 .oval = FIO_FSERVICE_RR,
625 .help = "Round robin select files",
631 .name = "fadvise_hint",
632 .type = FIO_OPT_BOOL,
633 .off1 = td_var_offset(fadvise_hint),
634 .help = "Use fadvise() to advise the kernel on IO pattern",
640 .off1 = td_var_offset(fsync_blocks),
641 .help = "Issue fsync for writes every given number of blocks",
646 .type = FIO_OPT_BOOL,
647 .off1 = td_var_offset(odirect),
648 .help = "Use O_DIRECT IO (negates buffered)",
653 .type = FIO_OPT_BOOL,
654 .off1 = td_var_offset(odirect),
656 .help = "Use buffered IO (negates direct)",
661 .type = FIO_OPT_BOOL,
662 .off1 = td_var_offset(overwrite),
663 .help = "When writing, set whether to overwrite current data",
669 .off1 = td_var_offset(loops),
670 .help = "Number of times to run the job",
676 .off1 = td_var_offset(numjobs),
677 .help = "Duplicate this job this many times",
681 .name = "startdelay",
683 .off1 = td_var_offset(start_delay),
684 .help = "Only start job when this period has passed",
690 .type = FIO_OPT_STR_VAL_TIME,
691 .off1 = td_var_offset(timeout),
692 .help = "Stop workload when this amount of time has passed",
696 .name = "time_based",
697 .type = FIO_OPT_STR_SET,
698 .off1 = td_var_offset(time_based),
699 .help = "Keep running until runtime/timeout is met",
706 .off1 = td_var_offset(mem_type),
707 .help = "Backing type for IO buffers",
712 .help = "Use malloc(3) for IO buffers",
716 .help = "Use shared memory segments for IO buffers",
718 #ifdef FIO_HAVE_HUGETLB
721 .help = "Like shm, but use huge pages",
726 .help = "Use mmap(2) (file or anon) for IO buffers",
728 #ifdef FIO_HAVE_HUGETLB
729 { .ival = "mmaphuge",
730 .oval = MEM_MMAPHUGE,
731 .help = "Like mmap, but use huge pages",
739 .off1 = td_var_offset(verify),
740 .help = "Verify data written",
745 .help = "Don't do IO verification",
749 .help = "Use md5 checksums for verification",
752 .oval = VERIFY_CRC64,
753 .help = "Use crc64 checksums for verification",
756 .oval = VERIFY_CRC32,
757 .help = "Use crc32 checksums for verification",
760 .oval = VERIFY_CRC16,
761 .help = "Use crc16 checksums for verification",
765 .help = "Use crc7 checksums for verification",
768 .oval = VERIFY_SHA256,
769 .help = "Use sha256 checksums for verification",
772 .oval = VERIFY_SHA512,
773 .help = "Use sha512 checksums for verification",
777 .help = "Use io information",
782 .help = "Pretend to verify",
788 .type = FIO_OPT_BOOL,
789 .off1 = td_var_offset(do_verify),
790 .help = "Run verification stage after write",
795 .name = "verifysort",
796 .type = FIO_OPT_BOOL,
797 .off1 = td_var_offset(verifysort),
798 .help = "Sort written verify blocks for read back",
803 .name = "verify_interval",
804 .type = FIO_OPT_STR_VAL_INT,
805 .off1 = td_var_offset(verify_interval),
806 .minval = 2 * sizeof(struct verify_header),
807 .help = "Store verify buffer header every N bytes",
811 .name = "verify_offset",
812 .type = FIO_OPT_STR_VAL_INT,
813 .help = "Offset verify header location by N bytes",
815 .cb = str_verify_offset_cb,
819 .name = "verify_pattern",
821 .cb = str_verify_pattern_cb,
822 .help = "Fill pattern for IO buffers",
826 .name = "verify_fatal",
827 .type = FIO_OPT_BOOL,
828 .off1 = td_var_offset(verify_fatal),
830 .help = "Exit on a single verify failure, don't continue",
834 .name = "write_iolog",
835 .type = FIO_OPT_STR_STORE,
836 .off1 = td_var_offset(write_iolog_file),
837 .help = "Store IO pattern to file",
840 .name = "read_iolog",
841 .type = FIO_OPT_STR_STORE,
842 .off1 = td_var_offset(read_iolog_file),
843 .help = "Playback IO pattern from file",
846 .name = "exec_prerun",
847 .type = FIO_OPT_STR_STORE,
848 .off1 = td_var_offset(exec_prerun),
849 .help = "Execute this file prior to running job",
852 .name = "exec_postrun",
853 .type = FIO_OPT_STR_STORE,
854 .off1 = td_var_offset(exec_postrun),
855 .help = "Execute this file after running job",
857 #ifdef FIO_HAVE_IOSCHED_SWITCH
859 .name = "ioscheduler",
860 .type = FIO_OPT_STR_STORE,
861 .off1 = td_var_offset(ioscheduler),
862 .help = "Use this IO scheduler on the backing device",
867 .type = FIO_OPT_STR_VAL,
868 .off1 = td_var_offset(zone_size),
869 .help = "Give size of an IO zone",
874 .type = FIO_OPT_STR_VAL,
875 .off1 = td_var_offset(zone_skip),
876 .help = "Space between IO zones",
881 .type = FIO_OPT_STR_VAL,
882 .cb = str_lockmem_cb,
883 .help = "Lock down this amount of memory",
889 .off1 = td_var_offset(rwmix[DDIR_READ]),
891 .help = "Percentage of mixed workload that is reads",
895 .name = "rwmixwrite",
897 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
899 .help = "Percentage of mixed workload that is writes",
903 .name = "rwmixcycle",
905 .off1 = td_var_offset(rwmixcycle),
906 .help = "Cycle period for mixed read/write workloads (msec)",
908 .parent = "rwmixread",
913 .off1 = td_var_offset(nice),
914 .help = "Set job CPU nice value",
919 #ifdef FIO_HAVE_IOPRIO
924 .help = "Set job IO priority value",
931 .cb = str_prioclass_cb,
932 .help = "Set job IO priority class",
940 .off1 = td_var_offset(thinktime),
941 .help = "Idle time between IO buffers (usec)",
945 .name = "thinktime_spin",
947 .off1 = td_var_offset(thinktime_spin),
948 .help = "Start think time by spinning this amount (usec)",
950 .parent = "thinktime",
953 .name = "thinktime_blocks",
955 .off1 = td_var_offset(thinktime_blocks),
956 .help = "IO buffer period between 'thinktime'",
958 .parent = "thinktime",
963 .off1 = td_var_offset(rate),
964 .help = "Set bandwidth rate",
969 .off1 = td_var_offset(ratemin),
970 .help = "Job must meet this rate or it will be shutdown",
976 .off1 = td_var_offset(rate_iops),
977 .help = "Limit IO used to this number of IO operations/sec",
980 .name = "rate_iops_min",
982 .off1 = td_var_offset(rate_iops_min),
983 .help = "Job must meet this rate or it will be shutdown",
984 .parent = "rate_iops",
989 .off1 = td_var_offset(ratecycle),
990 .help = "Window average for rate limits (msec)",
995 .name = "invalidate",
996 .type = FIO_OPT_BOOL,
997 .off1 = td_var_offset(invalidate_cache),
998 .help = "Invalidate buffer/page cache prior to running job",
1003 .type = FIO_OPT_BOOL,
1004 .off1 = td_var_offset(sync_io),
1005 .help = "Use O_SYNC for buffered writes",
1007 .parent = "buffered",
1010 .name = "bwavgtime",
1011 .type = FIO_OPT_INT,
1012 .off1 = td_var_offset(bw_avg_time),
1013 .help = "Time window over which to calculate bandwidth (msec)",
1017 .name = "create_serialize",
1018 .type = FIO_OPT_BOOL,
1019 .off1 = td_var_offset(create_serialize),
1020 .help = "Serialize creating of job files",
1024 .name = "create_fsync",
1025 .type = FIO_OPT_BOOL,
1026 .off1 = td_var_offset(create_fsync),
1027 .help = "Fsync file after creation",
1032 .type = FIO_OPT_INT,
1033 .off1 = td_var_offset(cpuload),
1034 .help = "Use this percentage of CPU",
1037 .name = "cpuchunks",
1038 .type = FIO_OPT_INT,
1039 .off1 = td_var_offset(cpucycle),
1040 .help = "Length of the CPU burn cycles (usecs)",
1042 .parent = "cpuload",
1044 #ifdef FIO_HAVE_CPU_AFFINITY
1047 .type = FIO_OPT_INT,
1048 .cb = str_cpumask_cb,
1049 .help = "CPU affinity mask",
1052 .name = "cpus_allowed",
1053 .type = FIO_OPT_STR,
1054 .cb = str_cpus_allowed_cb,
1055 .help = "Set CPUs allowed",
1059 .name = "end_fsync",
1060 .type = FIO_OPT_BOOL,
1061 .off1 = td_var_offset(end_fsync),
1062 .help = "Include fsync at the end of job",
1066 .name = "fsync_on_close",
1067 .type = FIO_OPT_BOOL,
1068 .off1 = td_var_offset(fsync_on_close),
1069 .help = "fsync files on close",
1074 .type = FIO_OPT_BOOL,
1075 .off1 = td_var_offset(unlink),
1076 .help = "Unlink created files after job has completed",
1081 .type = FIO_OPT_STR_SET,
1082 .cb = str_exitall_cb,
1083 .help = "Terminate all jobs when one exits",
1086 .name = "stonewall",
1087 .type = FIO_OPT_STR_SET,
1088 .off1 = td_var_offset(stonewall),
1089 .help = "Insert a hard barrier between this job and previous",
1092 .name = "new_group",
1093 .type = FIO_OPT_STR_SET,
1094 .off1 = td_var_offset(new_group),
1095 .help = "Mark the start of a new group (for reporting)",
1099 .type = FIO_OPT_STR_SET,
1100 .off1 = td_var_offset(use_thread),
1101 .help = "Use threads instead of forks",
1104 .name = "write_bw_log",
1105 .type = FIO_OPT_STR_SET,
1106 .off1 = td_var_offset(write_bw_log),
1107 .help = "Write log of bandwidth during run",
1110 .name = "write_lat_log",
1111 .type = FIO_OPT_STR_SET,
1112 .off1 = td_var_offset(write_lat_log),
1113 .help = "Write log of latency during run",
1116 .name = "hugepage-size",
1117 .type = FIO_OPT_STR_VAL,
1118 .off1 = td_var_offset(hugepage_size),
1119 .help = "When using hugepages, specify size of each page",
1120 .def = __stringify(FIO_HUGE_PAGE),
1123 .name = "group_reporting",
1124 .type = FIO_OPT_STR_SET,
1125 .off1 = td_var_offset(group_reporting),
1126 .help = "Do reporting on a per-group basis",
1129 .name = "zero_buffers",
1130 .type = FIO_OPT_STR_SET,
1131 .off1 = td_var_offset(zero_buffers),
1132 .help = "Init IO buffers to all zeroes",
1134 #ifdef FIO_HAVE_DISK_UTIL
1136 .name = "disk_util",
1137 .type = FIO_OPT_BOOL,
1138 .off1 = td_var_offset(do_disk_util),
1139 .help = "Log disk utilization stats",
1148 void fio_options_dup_and_init(struct option *long_options)
1150 struct fio_option *o;
1153 options_init(options);
1156 while (long_options[i].name)
1161 long_options[i].name = o->name;
1162 long_options[i].val = FIO_GETOPT_JOB;
1163 if (o->type == FIO_OPT_STR_SET)
1164 long_options[i].has_arg = no_argument;
1166 long_options[i].has_arg = required_argument;
1170 assert(i < FIO_NR_OPTIONS);
1174 int fio_option_parse(struct thread_data *td, const char *opt)
1176 return parse_option(opt, options, td);
1179 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1181 return parse_cmd_option(opt, val, options, td);
1184 void fio_fill_default_options(struct thread_data *td)
1186 fill_default_options(td, options);
1189 int fio_show_option_help(const char *opt)
1191 return show_cmd_help(options, opt);
1194 static void __options_mem(struct thread_data *td, int alloc)
1196 struct thread_options *o = &td->o;
1197 struct fio_option *opt;
1201 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1202 if (opt->type != FIO_OPT_STR_STORE)
1205 ptr = (void *) o + opt->off1;
1208 *ptr = strdup(*ptr);
1218 * dupe FIO_OPT_STR_STORE options
1220 void options_mem_dupe(struct thread_data *td)
1222 __options_mem(td, 1);
1225 void options_mem_free(struct thread_data fio_unused *td)
1228 __options_mem(td, 0);