10 #include <sys/types.h>
19 #include "crc/crc32c.h"
22 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
24 static char *get_opt_postfix(const char *str)
26 char *p = strstr(str, ":");
32 strip_blank_front(&p);
37 static int converthexchartoint(char a)
57 static int bs_cmp(const void *p1, const void *p2)
59 const struct bssplit *bsp1 = p1;
60 const struct bssplit *bsp2 = p2;
62 return bsp1->perc < bsp2->perc;
65 static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
67 struct bssplit *bssplit;
68 unsigned int i, perc, perc_missing;
69 unsigned int max_bs, min_bs;
73 td->o.bssplit_nr[ddir] = 4;
74 bssplit = malloc(4 * sizeof(struct bssplit));
79 while ((fname = strsep(&str, ":")) != NULL) {
86 * grow struct buffer, if needed
88 if (i == td->o.bssplit_nr[ddir]) {
89 td->o.bssplit_nr[ddir] <<= 1;
90 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
91 * sizeof(struct bssplit));
94 perc_str = strstr(fname, "/");
98 perc = atoi(perc_str);
106 if (str_to_decimal(fname, &val, 1, td)) {
107 log_err("fio: bssplit conversion failed\n");
118 bssplit[i].perc = perc;
122 td->o.bssplit_nr[ddir] = i;
125 * Now check if the percentages add up, and how much is missing
127 perc = perc_missing = 0;
128 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
129 struct bssplit *bsp = &bssplit[i];
131 if (bsp->perc == (unsigned char) -1)
138 log_err("fio: bssplit percentages add to more than 100%%\n");
143 * If values didn't have a percentage set, divide the remains between
147 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
148 struct bssplit *bsp = &bssplit[i];
150 if (bsp->perc == (unsigned char) -1)
151 bsp->perc = (100 - perc) / perc_missing;
155 td->o.min_bs[ddir] = min_bs;
156 td->o.max_bs[ddir] = max_bs;
159 * now sort based on percentages, for ease of lookup
161 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
162 td->o.bssplit[ddir] = bssplit;
167 static int str_bssplit_cb(void *data, const char *input)
169 struct thread_data *td = data;
170 char *str, *p, *odir;
173 p = str = strdup(input);
175 strip_blank_front(&str);
176 strip_blank_end(str);
178 odir = strchr(str, ',');
180 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
183 ret = bssplit_ddir(td, DDIR_READ, str);
190 ret = bssplit_ddir(td, DDIR_READ, str);
192 ret = bssplit_ddir(td, DDIR_WRITE, op);
201 static int str_rw_cb(void *data, const char *str)
203 struct thread_data *td = data;
204 char *nr = get_opt_postfix(str);
208 td->o.ddir_nr = atoi(nr);
215 static int str_mem_cb(void *data, const char *mem)
217 struct thread_data *td = data;
219 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
220 td->mmapfile = get_opt_postfix(mem);
221 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
222 log_err("fio: mmaphuge:/path/to/file\n");
230 static int str_verify_cb(void *data, const char *mem)
232 struct thread_data *td = data;
234 if (td->o.verify != VERIFY_CRC32C_INTEL)
237 if (!crc32c_intel_works()) {
238 log_info("fio: System does not support hw accelerated crc32c. Falling back to sw crc32c.\n");
239 td->o.verify = VERIFY_CRC32C;
245 static int fio_clock_source_cb(void *data, const char *str)
247 struct thread_data *td = data;
249 fio_clock_source = td->o.clocksource;
254 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
260 static int str_rwmix_read_cb(void *data, unsigned int *val)
262 struct thread_data *td = data;
264 td->o.rwmix[DDIR_READ] = *val;
265 td->o.rwmix[DDIR_WRITE] = 100 - *val;
269 static int str_rwmix_write_cb(void *data, unsigned int *val)
271 struct thread_data *td = data;
273 td->o.rwmix[DDIR_WRITE] = *val;
274 td->o.rwmix[DDIR_READ] = 100 - *val;
278 #ifdef FIO_HAVE_IOPRIO
279 static int str_prioclass_cb(void *data, unsigned int *val)
281 struct thread_data *td = data;
285 * mask off old class bits, str_prio_cb() may have set a default class
287 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
290 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
295 static int str_prio_cb(void *data, unsigned int *val)
297 struct thread_data *td = data;
302 * If no class is set, assume BE
304 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
305 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
312 static int str_exitall_cb(void)
314 exitall_on_terminate = 1;
318 #ifdef FIO_HAVE_CPU_AFFINITY
319 static int str_cpumask_cb(void *data, unsigned int *val)
321 struct thread_data *td = data;
326 ret = fio_cpuset_init(&td->o.cpumask);
328 log_err("fio: cpuset_init failed\n");
329 td_verror(td, ret, "fio_cpuset_init");
333 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
335 for (i = 0; i < sizeof(int) * 8; i++) {
336 if ((1 << i) & *val) {
338 log_err("fio: CPU %d too large (max=%ld)\n", i,
342 dprint(FD_PARSE, "set cpu allowed %d\n", i);
343 fio_cpu_set(&td->o.cpumask, i);
347 td->o.cpumask_set = 1;
351 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
358 ret = fio_cpuset_init(mask);
360 log_err("fio: cpuset_init failed\n");
361 td_verror(td, ret, "fio_cpuset_init");
365 p = str = strdup(input);
367 strip_blank_front(&str);
368 strip_blank_end(str);
370 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
372 while ((cpu = strsep(&str, ",")) != NULL) {
381 while ((cpu2 = strsep(&str2, "-")) != NULL) {
391 while (icpu <= icpu2) {
392 if (icpu >= FIO_MAX_CPUS) {
393 log_err("fio: your OS only supports up to"
394 " %d CPUs\n", (int) FIO_MAX_CPUS);
398 if (icpu > max_cpu) {
399 log_err("fio: CPU %d too large (max=%ld)\n",
405 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
406 fio_cpu_set(mask, icpu);
415 td->o.cpumask_set = 1;
419 static int str_cpus_allowed_cb(void *data, const char *input)
421 struct thread_data *td = data;
424 ret = set_cpus_allowed(td, &td->o.cpumask, input);
426 td->o.cpumask_set = 1;
431 static int str_verify_cpus_allowed_cb(void *data, const char *input)
433 struct thread_data *td = data;
436 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
438 td->o.verify_cpumask_set = 1;
444 static int str_fst_cb(void *data, const char *str)
446 struct thread_data *td = data;
447 char *nr = get_opt_postfix(str);
449 td->file_service_nr = 1;
451 td->file_service_nr = atoi(nr);
458 #ifdef FIO_HAVE_SYNC_FILE_RANGE
459 static int str_sfr_cb(void *data, const char *str)
461 struct thread_data *td = data;
462 char *nr = get_opt_postfix(str);
464 td->sync_file_range_nr = 1;
466 td->sync_file_range_nr = atoi(nr);
474 static int check_dir(struct thread_data *td, char *fname)
476 char file[PATH_MAX], *dir;
479 if (td->o.directory) {
480 strcpy(file, td->o.directory);
485 sprintf(file + elen, "%s", fname);
492 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
493 * yet, so we can't do this check right here...
495 if (lstat(dir, &sb) < 0) {
498 log_err("fio: %s is not a directory\n", dir);
499 td_verror(td, ret, "lstat");
503 if (!S_ISDIR(sb.st_mode)) {
504 log_err("fio: %s is not a directory\n", dir);
514 * Return next file in the string. Files are separated with ':'. If the ':'
515 * is escaped with a '\', then that ':' is part of the filename and does not
516 * indicate a new file.
518 static char *get_next_file_name(char **ptr)
523 if (!str || !strlen(str))
529 * No colon, we are done
531 p = strchr(str, ':');
538 * We got a colon, but it's the first character. Skip and
546 if (*(p - 1) != '\\') {
552 memmove(p - 1, p, strlen(p) + 1);
559 static int str_filename_cb(void *data, const char *input)
561 struct thread_data *td = data;
562 char *fname, *str, *p;
564 p = str = strdup(input);
566 strip_blank_front(&str);
567 strip_blank_end(str);
569 if (!td->files_index)
572 while ((fname = get_next_file_name(&str)) != NULL) {
575 if (check_dir(td, fname)) {
587 static int str_directory_cb(void *data, const char fio_unused *str)
589 struct thread_data *td = data;
592 if (lstat(td->o.directory, &sb) < 0) {
595 log_err("fio: %s is not a directory\n", td->o.directory);
596 td_verror(td, ret, "lstat");
599 if (!S_ISDIR(sb.st_mode)) {
600 log_err("fio: %s is not a directory\n", td->o.directory);
607 static int str_opendir_cb(void *data, const char fio_unused *str)
609 struct thread_data *td = data;
611 if (!td->files_index)
614 return add_dir_files(td, td->o.opendir);
617 static int str_verify_offset_cb(void *data, unsigned int *off)
619 struct thread_data *td = data;
621 if (*off && *off < sizeof(struct verify_header)) {
622 log_err("fio: verify_offset too small\n");
626 td->o.verify_offset = *off;
630 static int str_verify_pattern_cb(void *data, const char *input)
632 struct thread_data *td = data;
634 int i = 0, j = 0, len, k, base = 10;
637 loc1 = strstr(input, "0x");
638 loc2 = strstr(input, "0X");
641 off = strtol(input, NULL, base);
642 if (off != LONG_MAX || errno != ERANGE) {
644 td->o.verify_pattern[i] = off & 0xff;
653 j = loc1 - input + 2;
655 j = loc2 - input + 2;
658 if (len - j < MAX_PATTERN_SIZE * 2) {
660 off = converthexchartoint(input[k--]);
662 off += (converthexchartoint(input[k--])
664 td->o.verify_pattern[i++] = (char) off;
668 td->o.verify_pattern_bytes = i;
672 static int str_lockfile_cb(void *data, const char *str)
674 struct thread_data *td = data;
675 char *nr = get_opt_postfix(str);
677 td->o.lockfile_batch = 1;
679 td->o.lockfile_batch = atoi(nr);
686 static int str_write_bw_log_cb(void *data, const char *str)
688 struct thread_data *td = data;
691 td->o.bw_log_file = strdup(str);
693 td->o.write_bw_log = 1;
697 static int str_write_lat_log_cb(void *data, const char *str)
699 struct thread_data *td = data;
702 td->o.lat_log_file = strdup(str);
704 td->o.write_lat_log = 1;
708 static int str_gtod_reduce_cb(void *data, int *il)
710 struct thread_data *td = data;
713 td->o.disable_lat = !!val;
714 td->o.disable_clat = !!val;
715 td->o.disable_slat = !!val;
716 td->o.disable_bw = !!val;
718 td->tv_cache_mask = 63;
723 static int str_gtod_cpu_cb(void *data, int *il)
725 struct thread_data *td = data;
728 td->o.gtod_cpu = val;
729 td->o.gtod_offload = 1;
733 static int rw_verify(struct fio_option *o, void *data)
735 struct thread_data *td = data;
737 if (read_only && td_write(td)) {
738 log_err("fio: job <%s> has write bit set, but fio is in"
739 " read-only mode\n", td->o.name);
746 static int gtod_cpu_verify(struct fio_option *o, void *data)
748 #ifndef FIO_HAVE_CPU_AFFINITY
749 struct thread_data *td = data;
751 if (td->o.gtod_cpu) {
752 log_err("fio: platform must support CPU affinity for"
753 "gettimeofday() offloading\n");
761 static int kb_base_verify(struct fio_option *o, void *data)
763 struct thread_data *td = data;
765 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
766 log_err("fio: kb_base set to nonsensical value: %u\n",
774 #define __stringify_1(x) #x
775 #define __stringify(x) __stringify_1(x)
778 * Map of job/command line options
780 static struct fio_option options[FIO_MAX_OPTS] = {
782 .name = "description",
783 .type = FIO_OPT_STR_STORE,
784 .off1 = td_var_offset(description),
785 .help = "Text job description",
789 .type = FIO_OPT_STR_STORE,
790 .off1 = td_var_offset(name),
791 .help = "Name of this job",
795 .type = FIO_OPT_STR_STORE,
796 .off1 = td_var_offset(directory),
797 .cb = str_directory_cb,
798 .help = "Directory to store files in",
802 .type = FIO_OPT_STR_STORE,
803 .off1 = td_var_offset(filename),
804 .cb = str_filename_cb,
805 .prio = -1, /* must come after "directory" */
806 .help = "File(s) to use for the workload",
811 .off1 = td_var_offset(kb_base),
812 .verify = kb_base_verify,
815 .help = "How many bytes per KB for reporting (1000 or 1024)",
820 .cb = str_lockfile_cb,
821 .off1 = td_var_offset(file_lock_mode),
822 .help = "Lock file when doing IO to it",
823 .parent = "filename",
827 .oval = FILE_LOCK_NONE,
828 .help = "No file locking",
830 { .ival = "exclusive",
831 .oval = FILE_LOCK_EXCLUSIVE,
832 .help = "Exclusive file lock",
836 .oval = FILE_LOCK_READWRITE,
837 .help = "Read vs write lock",
843 .type = FIO_OPT_STR_STORE,
844 .off1 = td_var_offset(opendir),
845 .cb = str_opendir_cb,
846 .help = "Recursively add files from this directory and down",
850 .alias = "readwrite",
853 .off1 = td_var_offset(td_ddir),
854 .help = "IO direction",
859 .oval = TD_DDIR_READ,
860 .help = "Sequential read",
863 .oval = TD_DDIR_WRITE,
864 .help = "Sequential write",
866 { .ival = "randread",
867 .oval = TD_DDIR_RANDREAD,
868 .help = "Random read",
870 { .ival = "randwrite",
871 .oval = TD_DDIR_RANDWRITE,
872 .help = "Random write",
876 .help = "Sequential read and write mix",
879 .oval = TD_DDIR_RANDRW,
880 .help = "Random read and write mix"
886 .type = FIO_OPT_STR_STORE,
887 .off1 = td_var_offset(ioengine),
888 .help = "IO engine to use",
892 .help = "Use read/write",
895 .help = "Use pread/pwrite",
898 .help = "Use readv/writev",
900 #ifdef FIO_HAVE_LIBAIO
902 .help = "Linux native asynchronous IO",
905 #ifdef FIO_HAVE_POSIXAIO
906 { .ival = "posixaio",
907 .help = "POSIX asynchronous IO",
910 #ifdef FIO_HAVE_SOLARISAIO
911 { .ival = "solarisaio",
912 .help = "Solaris native asynchronous IO",
916 .help = "Memory mapped IO",
918 #ifdef FIO_HAVE_SPLICE
920 .help = "splice/vmsplice based IO",
922 { .ival = "netsplice",
923 .help = "splice/vmsplice to/from the network",
928 .help = "SCSI generic v3 IO",
932 .help = "Testing engine (no data transfer)",
935 .help = "Network IO",
937 #ifdef FIO_HAVE_SYSLET
938 { .ival = "syslet-rw",
939 .help = "syslet enabled async pread/pwrite IO",
943 .help = "CPU cycler burner engine",
945 #ifdef FIO_HAVE_GUASI
947 .help = "GUASI IO engine",
950 { .ival = "external",
951 .help = "Load external engine (append name)",
958 .off1 = td_var_offset(iodepth),
959 .help = "Amount of IO buffers to keep in flight",
964 .name = "iodepth_batch",
965 .alias = "iodepth_batch_submit",
967 .off1 = td_var_offset(iodepth_batch),
968 .help = "Number of IO buffers to submit in one go",
974 .name = "iodepth_batch_complete",
976 .off1 = td_var_offset(iodepth_batch_complete),
977 .help = "Number of IO buffers to retrieve in one go",
983 .name = "iodepth_low",
985 .off1 = td_var_offset(iodepth_low),
986 .help = "Low water mark for queuing depth",
991 .type = FIO_OPT_STR_VAL,
992 .off1 = td_var_offset(size),
994 .help = "Total size of device or files",
997 .name = "fill_device",
998 .type = FIO_OPT_BOOL,
999 .off1 = td_var_offset(fill_device),
1000 .help = "Write until an ENOSPC error occurs",
1005 .type = FIO_OPT_STR_VAL,
1006 .off1 = td_var_offset(file_size_low),
1007 .off2 = td_var_offset(file_size_high),
1009 .help = "Size of individual files",
1013 .alias = "fileoffset",
1014 .type = FIO_OPT_STR_VAL,
1015 .off1 = td_var_offset(start_offset),
1016 .help = "Start IO from this offset",
1021 .alias = "blocksize",
1022 .type = FIO_OPT_INT,
1023 .off1 = td_var_offset(bs[DDIR_READ]),
1024 .off2 = td_var_offset(bs[DDIR_WRITE]),
1026 .help = "Block size unit",
1032 .alias = "blockalign",
1033 .type = FIO_OPT_INT,
1034 .off1 = td_var_offset(ba[DDIR_READ]),
1035 .off2 = td_var_offset(ba[DDIR_WRITE]),
1037 .help = "IO block offset alignment",
1042 .alias = "blocksize_range",
1043 .type = FIO_OPT_RANGE,
1044 .off1 = td_var_offset(min_bs[DDIR_READ]),
1045 .off2 = td_var_offset(max_bs[DDIR_READ]),
1046 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1047 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1049 .help = "Set block size range (in more detail than bs)",
1054 .type = FIO_OPT_STR,
1055 .cb = str_bssplit_cb,
1056 .help = "Set a specific mix of block sizes",
1060 .name = "bs_unaligned",
1061 .alias = "blocksize_unaligned",
1062 .type = FIO_OPT_STR_SET,
1063 .off1 = td_var_offset(bs_unaligned),
1064 .help = "Don't sector align IO buffer sizes",
1068 .name = "randrepeat",
1069 .type = FIO_OPT_BOOL,
1070 .off1 = td_var_offset(rand_repeatable),
1071 .help = "Use repeatable random IO pattern",
1076 .name = "norandommap",
1077 .type = FIO_OPT_STR_SET,
1078 .off1 = td_var_offset(norandommap),
1079 .help = "Accept potential duplicate random blocks",
1083 .name = "softrandommap",
1084 .type = FIO_OPT_BOOL,
1085 .off1 = td_var_offset(softrandommap),
1086 .help = "Set norandommap if randommap allocation fails",
1087 .parent = "norandommap",
1092 .type = FIO_OPT_INT,
1093 .off1 = td_var_offset(nr_files),
1094 .help = "Split job workload between this number of files",
1098 .name = "openfiles",
1099 .type = FIO_OPT_INT,
1100 .off1 = td_var_offset(open_files),
1101 .help = "Number of files to keep open at the same time",
1104 .name = "file_service_type",
1105 .type = FIO_OPT_STR,
1107 .off1 = td_var_offset(file_service_type),
1108 .help = "How to select which file to service next",
1109 .def = "roundrobin",
1112 .oval = FIO_FSERVICE_RANDOM,
1113 .help = "Choose a file at random",
1115 { .ival = "roundrobin",
1116 .oval = FIO_FSERVICE_RR,
1117 .help = "Round robin select files",
1119 { .ival = "sequential",
1120 .oval = FIO_FSERVICE_SEQ,
1121 .help = "Finish one file before moving to the next",
1124 .parent = "nrfiles",
1126 #ifdef FIO_HAVE_FALLOCATE
1128 .name = "fallocate",
1129 .type = FIO_OPT_BOOL,
1130 .off1 = td_var_offset(fallocate),
1131 .help = "Use fallocate() when laying out files",
1136 .name = "fadvise_hint",
1137 .type = FIO_OPT_BOOL,
1138 .off1 = td_var_offset(fadvise_hint),
1139 .help = "Use fadvise() to advise the kernel on IO pattern",
1144 .type = FIO_OPT_INT,
1145 .off1 = td_var_offset(fsync_blocks),
1146 .help = "Issue fsync for writes every given number of blocks",
1150 .name = "fdatasync",
1151 .type = FIO_OPT_INT,
1152 .off1 = td_var_offset(fdatasync_blocks),
1153 .help = "Issue fdatasync for writes every given number of blocks",
1156 #ifdef FIO_HAVE_SYNC_FILE_RANGE
1158 .name = "sync_file_range",
1160 { .ival = "wait_before",
1161 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1162 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1166 .oval = SYNC_FILE_RANGE_WRITE,
1167 .help = "SYNC_FILE_RANGE_WRITE",
1171 .ival = "wait_after",
1172 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1173 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1177 .type = FIO_OPT_STR_MULTI,
1179 .off1 = td_var_offset(sync_file_range),
1180 .help = "Use sync_file_range()",
1185 .type = FIO_OPT_BOOL,
1186 .off1 = td_var_offset(odirect),
1187 .help = "Use O_DIRECT IO (negates buffered)",
1192 .type = FIO_OPT_BOOL,
1193 .off1 = td_var_offset(odirect),
1195 .help = "Use buffered IO (negates direct)",
1199 .name = "overwrite",
1200 .type = FIO_OPT_BOOL,
1201 .off1 = td_var_offset(overwrite),
1202 .help = "When writing, set whether to overwrite current data",
1207 .type = FIO_OPT_INT,
1208 .off1 = td_var_offset(loops),
1209 .help = "Number of times to run the job",
1214 .type = FIO_OPT_INT,
1215 .off1 = td_var_offset(numjobs),
1216 .help = "Duplicate this job this many times",
1220 .name = "startdelay",
1221 .type = FIO_OPT_INT,
1222 .off1 = td_var_offset(start_delay),
1223 .help = "Only start job when this period has passed",
1229 .type = FIO_OPT_STR_VAL_TIME,
1230 .off1 = td_var_offset(timeout),
1231 .help = "Stop workload when this amount of time has passed",
1235 .name = "time_based",
1236 .type = FIO_OPT_STR_SET,
1237 .off1 = td_var_offset(time_based),
1238 .help = "Keep running until runtime/timeout is met",
1241 .name = "ramp_time",
1242 .type = FIO_OPT_STR_VAL_TIME,
1243 .off1 = td_var_offset(ramp_time),
1244 .help = "Ramp up time before measuring performance",
1247 .name = "clocksource",
1248 .type = FIO_OPT_STR,
1249 .cb = fio_clock_source_cb,
1250 .off1 = td_var_offset(clocksource),
1251 .help = "What type of timing source to use",
1253 { .ival = "gettimeofday",
1255 .help = "Use gettimeofday(2) for timing",
1257 { .ival = "clock_gettime",
1258 .oval = CS_CGETTIME,
1259 .help = "Use clock_gettime(2) for timing",
1261 #ifdef ARCH_HAVE_CPU_CLOCK
1263 .oval = CS_CPUCLOCK,
1264 .help = "Use CPU private clock",
1272 .type = FIO_OPT_STR,
1274 .off1 = td_var_offset(mem_type),
1275 .help = "Backing type for IO buffers",
1280 .help = "Use malloc(3) for IO buffers",
1284 .help = "Use shared memory segments for IO buffers",
1286 #ifdef FIO_HAVE_HUGETLB
1287 { .ival = "shmhuge",
1288 .oval = MEM_SHMHUGE,
1289 .help = "Like shm, but use huge pages",
1294 .help = "Use mmap(2) (file or anon) for IO buffers",
1296 #ifdef FIO_HAVE_HUGETLB
1297 { .ival = "mmaphuge",
1298 .oval = MEM_MMAPHUGE,
1299 .help = "Like mmap, but use huge pages",
1305 .name = "iomem_align",
1306 .alias = "mem_align",
1307 .type = FIO_OPT_INT,
1308 .off1 = td_var_offset(mem_align),
1310 .help = "IO memory buffer offset alignment",
1316 .type = FIO_OPT_STR,
1317 .off1 = td_var_offset(verify),
1318 .help = "Verify data written",
1319 .cb = str_verify_cb,
1323 .oval = VERIFY_NONE,
1324 .help = "Don't do IO verification",
1328 .help = "Use md5 checksums for verification",
1331 .oval = VERIFY_CRC64,
1332 .help = "Use crc64 checksums for verification",
1335 .oval = VERIFY_CRC32,
1336 .help = "Use crc32 checksums for verification",
1338 { .ival = "crc32c-intel",
1339 .oval = VERIFY_CRC32C_INTEL,
1340 .help = "Use hw crc32c checksums for verification",
1343 .oval = VERIFY_CRC32C,
1344 .help = "Use crc32c checksums for verification",
1347 .oval = VERIFY_CRC16,
1348 .help = "Use crc16 checksums for verification",
1351 .oval = VERIFY_CRC7,
1352 .help = "Use crc7 checksums for verification",
1355 .oval = VERIFY_SHA1,
1356 .help = "Use sha1 checksums for verification",
1359 .oval = VERIFY_SHA256,
1360 .help = "Use sha256 checksums for verification",
1363 .oval = VERIFY_SHA512,
1364 .help = "Use sha512 checksums for verification",
1367 .oval = VERIFY_META,
1368 .help = "Use io information",
1372 .oval = VERIFY_NULL,
1373 .help = "Pretend to verify",
1378 .name = "do_verify",
1379 .type = FIO_OPT_BOOL,
1380 .off1 = td_var_offset(do_verify),
1381 .help = "Run verification stage after write",
1386 .name = "verifysort",
1387 .type = FIO_OPT_BOOL,
1388 .off1 = td_var_offset(verifysort),
1389 .help = "Sort written verify blocks for read back",
1394 .name = "verify_interval",
1395 .type = FIO_OPT_INT,
1396 .off1 = td_var_offset(verify_interval),
1397 .minval = 2 * sizeof(struct verify_header),
1398 .help = "Store verify buffer header every N bytes",
1402 .name = "verify_offset",
1403 .type = FIO_OPT_INT,
1404 .help = "Offset verify header location by N bytes",
1406 .cb = str_verify_offset_cb,
1410 .name = "verify_pattern",
1411 .type = FIO_OPT_STR,
1412 .cb = str_verify_pattern_cb,
1413 .help = "Fill pattern for IO buffers",
1417 .name = "verify_fatal",
1418 .type = FIO_OPT_BOOL,
1419 .off1 = td_var_offset(verify_fatal),
1421 .help = "Exit on a single verify failure, don't continue",
1425 .name = "verify_async",
1426 .type = FIO_OPT_INT,
1427 .off1 = td_var_offset(verify_async),
1429 .help = "Number of async verifier threads to use",
1433 .name = "verify_backlog",
1434 .type = FIO_OPT_STR_VAL,
1435 .off1 = td_var_offset(verify_backlog),
1436 .help = "Verify after this number of blocks are written",
1440 .name = "verify_backlog_batch",
1441 .type = FIO_OPT_INT,
1442 .off1 = td_var_offset(verify_batch),
1443 .help = "Verify this number of IO blocks",
1444 .parent = "verify_backlog",
1446 #ifdef FIO_HAVE_CPU_AFFINITY
1448 .name = "verify_async_cpus",
1449 .type = FIO_OPT_STR,
1450 .cb = str_verify_cpus_allowed_cb,
1451 .help = "Set CPUs allowed for async verify threads",
1452 .parent = "verify_async",
1456 .name = "write_iolog",
1457 .type = FIO_OPT_STR_STORE,
1458 .off1 = td_var_offset(write_iolog_file),
1459 .help = "Store IO pattern to file",
1462 .name = "read_iolog",
1463 .type = FIO_OPT_STR_STORE,
1464 .off1 = td_var_offset(read_iolog_file),
1465 .help = "Playback IO pattern from file",
1468 .name = "exec_prerun",
1469 .type = FIO_OPT_STR_STORE,
1470 .off1 = td_var_offset(exec_prerun),
1471 .help = "Execute this file prior to running job",
1474 .name = "exec_postrun",
1475 .type = FIO_OPT_STR_STORE,
1476 .off1 = td_var_offset(exec_postrun),
1477 .help = "Execute this file after running job",
1479 #ifdef FIO_HAVE_IOSCHED_SWITCH
1481 .name = "ioscheduler",
1482 .type = FIO_OPT_STR_STORE,
1483 .off1 = td_var_offset(ioscheduler),
1484 .help = "Use this IO scheduler on the backing device",
1489 .type = FIO_OPT_STR_VAL,
1490 .off1 = td_var_offset(zone_size),
1491 .help = "Give size of an IO zone",
1496 .type = FIO_OPT_STR_VAL,
1497 .off1 = td_var_offset(zone_skip),
1498 .help = "Space between IO zones",
1503 .type = FIO_OPT_STR_VAL,
1504 .cb = str_lockmem_cb,
1505 .help = "Lock down this amount of memory",
1509 .name = "rwmixread",
1510 .type = FIO_OPT_INT,
1511 .cb = str_rwmix_read_cb,
1513 .help = "Percentage of mixed workload that is reads",
1517 .name = "rwmixwrite",
1518 .type = FIO_OPT_INT,
1519 .cb = str_rwmix_write_cb,
1521 .help = "Percentage of mixed workload that is writes",
1525 .name = "rwmixcycle",
1526 .type = FIO_OPT_DEPRECATED,
1530 .type = FIO_OPT_INT,
1531 .off1 = td_var_offset(nice),
1532 .help = "Set job CPU nice value",
1537 #ifdef FIO_HAVE_IOPRIO
1540 .type = FIO_OPT_INT,
1542 .help = "Set job IO priority value",
1547 .name = "prioclass",
1548 .type = FIO_OPT_INT,
1549 .cb = str_prioclass_cb,
1550 .help = "Set job IO priority class",
1556 .name = "thinktime",
1557 .type = FIO_OPT_INT,
1558 .off1 = td_var_offset(thinktime),
1559 .help = "Idle time between IO buffers (usec)",
1563 .name = "thinktime_spin",
1564 .type = FIO_OPT_INT,
1565 .off1 = td_var_offset(thinktime_spin),
1566 .help = "Start think time by spinning this amount (usec)",
1568 .parent = "thinktime",
1571 .name = "thinktime_blocks",
1572 .type = FIO_OPT_INT,
1573 .off1 = td_var_offset(thinktime_blocks),
1574 .help = "IO buffer period between 'thinktime'",
1576 .parent = "thinktime",
1580 .type = FIO_OPT_INT,
1581 .off1 = td_var_offset(rate[0]),
1582 .off2 = td_var_offset(rate[1]),
1583 .help = "Set bandwidth rate",
1587 .type = FIO_OPT_INT,
1588 .off1 = td_var_offset(ratemin[0]),
1589 .off2 = td_var_offset(ratemin[1]),
1590 .help = "Job must meet this rate or it will be shutdown",
1594 .name = "rate_iops",
1595 .type = FIO_OPT_INT,
1596 .off1 = td_var_offset(rate_iops[0]),
1597 .off2 = td_var_offset(rate_iops[1]),
1598 .help = "Limit IO used to this number of IO operations/sec",
1601 .name = "rate_iops_min",
1602 .type = FIO_OPT_INT,
1603 .off1 = td_var_offset(rate_iops_min[0]),
1604 .off2 = td_var_offset(rate_iops_min[1]),
1605 .help = "Job must meet this rate or it will be shutdown",
1606 .parent = "rate_iops",
1609 .name = "ratecycle",
1610 .type = FIO_OPT_INT,
1611 .off1 = td_var_offset(ratecycle),
1612 .help = "Window average for rate limits (msec)",
1617 .name = "invalidate",
1618 .type = FIO_OPT_BOOL,
1619 .off1 = td_var_offset(invalidate_cache),
1620 .help = "Invalidate buffer/page cache prior to running job",
1625 .type = FIO_OPT_BOOL,
1626 .off1 = td_var_offset(sync_io),
1627 .help = "Use O_SYNC for buffered writes",
1629 .parent = "buffered",
1632 .name = "bwavgtime",
1633 .type = FIO_OPT_INT,
1634 .off1 = td_var_offset(bw_avg_time),
1635 .help = "Time window over which to calculate bandwidth"
1640 .name = "create_serialize",
1641 .type = FIO_OPT_BOOL,
1642 .off1 = td_var_offset(create_serialize),
1643 .help = "Serialize creating of job files",
1647 .name = "create_fsync",
1648 .type = FIO_OPT_BOOL,
1649 .off1 = td_var_offset(create_fsync),
1650 .help = "Fsync file after creation",
1654 .name = "create_on_open",
1655 .type = FIO_OPT_BOOL,
1656 .off1 = td_var_offset(create_on_open),
1657 .help = "Create files when they are opened for IO",
1662 .type = FIO_OPT_BOOL,
1663 .off1 = td_var_offset(pre_read),
1664 .help = "Preread files before starting official testing",
1669 .type = FIO_OPT_INT,
1670 .off1 = td_var_offset(cpuload),
1671 .help = "Use this percentage of CPU",
1674 .name = "cpuchunks",
1675 .type = FIO_OPT_INT,
1676 .off1 = td_var_offset(cpucycle),
1677 .help = "Length of the CPU burn cycles (usecs)",
1679 .parent = "cpuload",
1681 #ifdef FIO_HAVE_CPU_AFFINITY
1684 .type = FIO_OPT_INT,
1685 .cb = str_cpumask_cb,
1686 .help = "CPU affinity mask",
1689 .name = "cpus_allowed",
1690 .type = FIO_OPT_STR,
1691 .cb = str_cpus_allowed_cb,
1692 .help = "Set CPUs allowed",
1696 .name = "end_fsync",
1697 .type = FIO_OPT_BOOL,
1698 .off1 = td_var_offset(end_fsync),
1699 .help = "Include fsync at the end of job",
1703 .name = "fsync_on_close",
1704 .type = FIO_OPT_BOOL,
1705 .off1 = td_var_offset(fsync_on_close),
1706 .help = "fsync files on close",
1711 .type = FIO_OPT_BOOL,
1712 .off1 = td_var_offset(unlink),
1713 .help = "Unlink created files after job has completed",
1718 .type = FIO_OPT_STR_SET,
1719 .cb = str_exitall_cb,
1720 .help = "Terminate all jobs when one exits",
1723 .name = "stonewall",
1724 .type = FIO_OPT_STR_SET,
1725 .off1 = td_var_offset(stonewall),
1726 .help = "Insert a hard barrier between this job and previous",
1729 .name = "new_group",
1730 .type = FIO_OPT_STR_SET,
1731 .off1 = td_var_offset(new_group),
1732 .help = "Mark the start of a new group (for reporting)",
1736 .type = FIO_OPT_STR_SET,
1737 .off1 = td_var_offset(use_thread),
1738 .help = "Use threads instead of forks",
1741 .name = "write_bw_log",
1742 .type = FIO_OPT_STR,
1743 .off1 = td_var_offset(write_bw_log),
1744 .cb = str_write_bw_log_cb,
1745 .help = "Write log of bandwidth during run",
1748 .name = "write_lat_log",
1749 .type = FIO_OPT_STR,
1750 .off1 = td_var_offset(write_lat_log),
1751 .cb = str_write_lat_log_cb,
1752 .help = "Write log of latency during run",
1755 .name = "hugepage-size",
1756 .type = FIO_OPT_INT,
1757 .off1 = td_var_offset(hugepage_size),
1758 .help = "When using hugepages, specify size of each page",
1759 .def = __stringify(FIO_HUGE_PAGE),
1762 .name = "group_reporting",
1763 .type = FIO_OPT_STR_SET,
1764 .off1 = td_var_offset(group_reporting),
1765 .help = "Do reporting on a per-group basis",
1768 .name = "zero_buffers",
1769 .type = FIO_OPT_STR_SET,
1770 .off1 = td_var_offset(zero_buffers),
1771 .help = "Init IO buffers to all zeroes",
1774 .name = "refill_buffers",
1775 .type = FIO_OPT_STR_SET,
1776 .off1 = td_var_offset(refill_buffers),
1777 .help = "Refill IO buffers on every IO submit",
1779 #ifdef FIO_HAVE_DISK_UTIL
1781 .name = "disk_util",
1782 .type = FIO_OPT_BOOL,
1783 .off1 = td_var_offset(do_disk_util),
1784 .help = "Log disk utilization statistics",
1789 .name = "gtod_reduce",
1790 .type = FIO_OPT_BOOL,
1791 .help = "Greatly reduce number of gettimeofday() calls",
1792 .cb = str_gtod_reduce_cb,
1796 .name = "disable_lat",
1797 .type = FIO_OPT_BOOL,
1798 .off1 = td_var_offset(disable_lat),
1799 .help = "Disable latency numbers",
1800 .parent = "gtod_reduce",
1804 .name = "disable_clat",
1805 .type = FIO_OPT_BOOL,
1806 .off1 = td_var_offset(disable_clat),
1807 .help = "Disable completion latency numbers",
1808 .parent = "gtod_reduce",
1812 .name = "disable_slat",
1813 .type = FIO_OPT_BOOL,
1814 .off1 = td_var_offset(disable_slat),
1815 .help = "Disable submissionn latency numbers",
1816 .parent = "gtod_reduce",
1820 .name = "disable_bw_measurement",
1821 .type = FIO_OPT_BOOL,
1822 .off1 = td_var_offset(disable_bw),
1823 .help = "Disable bandwidth logging",
1824 .parent = "gtod_reduce",
1829 .type = FIO_OPT_INT,
1830 .cb = str_gtod_cpu_cb,
1831 .help = "Setup dedicated gettimeofday() thread on this CPU",
1832 .verify = gtod_cpu_verify,
1835 .name = "continue_on_error",
1836 .type = FIO_OPT_BOOL,
1837 .off1 = td_var_offset(continue_on_error),
1838 .help = "Continue on non-fatal errors during I/O",
1843 .type = FIO_OPT_STR_STORE,
1844 .off1 = td_var_offset(profile),
1845 .help = "Select a specific builtin performance test",
1849 .type = FIO_OPT_STR_STORE,
1850 .off1 = td_var_offset(cgroup),
1851 .help = "Add job to cgroup of this name",
1854 .name = "cgroup_weight",
1855 .type = FIO_OPT_INT,
1856 .off1 = td_var_offset(cgroup_weight),
1857 .help = "Use given weight for cgroup",
1862 .name = "cgroup_nodelete",
1863 .type = FIO_OPT_BOOL,
1864 .off1 = td_var_offset(cgroup_nodelete),
1865 .help = "Do not delete cgroups after job completion",
1870 .type = FIO_OPT_INT,
1871 .off1 = td_var_offset(uid),
1872 .help = "Run job with this user ID",
1876 .type = FIO_OPT_INT,
1877 .off1 = td_var_offset(gid),
1878 .help = "Run job with this group ID",
1885 static void add_to_lopt(struct option *lopt, struct fio_option *o,
1888 lopt->name = (char *) name;
1889 lopt->val = FIO_GETOPT_JOB;
1890 if (o->type == FIO_OPT_STR_SET)
1891 lopt->has_arg = no_argument;
1893 lopt->has_arg = required_argument;
1896 void fio_options_dup_and_init(struct option *long_options)
1898 struct fio_option *o;
1901 options_init(options);
1904 while (long_options[i].name)
1909 add_to_lopt(&long_options[i], o, o->name);
1912 add_to_lopt(&long_options[i], o, o->alias);
1917 assert(i < FIO_NR_OPTIONS);
1921 struct fio_keyword {
1927 static struct fio_keyword fio_keywords[] = {
1929 .word = "$pagesize",
1930 .desc = "Page size in the system",
1933 .word = "$mb_memory",
1934 .desc = "Megabytes of memory online",
1938 .desc = "Number of CPUs online in the system",
1945 void fio_keywords_init(void)
1947 unsigned long long mb_memory;
1951 sprintf(buf, "%lu", page_size);
1952 fio_keywords[0].replace = strdup(buf);
1954 mb_memory = os_phys_mem() / page_size;
1955 sprintf(buf, "%llu", mb_memory);
1956 fio_keywords[1].replace = strdup(buf);
1958 l = sysconf(_SC_NPROCESSORS_ONLN);
1959 sprintf(buf, "%lu", l);
1960 fio_keywords[2].replace = strdup(buf);
1965 static char *bc_calc(char *str)
1967 char *buf, *tmp, opt[80];
1972 * No math, just return string
1974 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1979 * Split option from value, we only need to calculate the value
1981 tmp = strchr(str, '=');
1986 memset(opt, 0, sizeof(opt));
1987 strncpy(opt, str, tmp - str);
1991 sprintf(buf, "which %s > /dev/null", BC_APP);
1993 log_err("fio: bc is needed for performing math\n");
1998 sprintf(buf, "echo %s | %s", tmp, BC_APP);
1999 f = popen(buf, "r");
2005 ret = fread(buf, 1, 128, f);
2011 buf[ret - 1] = '\0';
2020 * Look for reserved variable names and replace them with real values
2022 static char *fio_keyword_replace(char *opt)
2027 for (i = 0; fio_keywords[i].word != NULL; i++) {
2028 struct fio_keyword *kw = &fio_keywords[i];
2030 while ((s = strstr(opt, kw->word)) != NULL) {
2031 char *new = malloc(strlen(opt) + 1);
2037 * Copy part of the string before the keyword and
2038 * sprintf() the replacement after it.
2040 memcpy(new, opt, olen);
2041 len = sprintf(new + olen, "%s", kw->replace);
2044 * If there's more in the original string, copy that
2047 opt += strlen(kw->word) + olen;
2049 memcpy(new + olen + len, opt, opt - o_org - 1);
2052 * replace opt and free the old opt
2058 * Check for potential math and invoke bc, if possible
2067 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2071 sort_options(opts, options, num_opts);
2073 for (ret = 0, i = 0; i < num_opts; i++) {
2074 opts[i] = fio_keyword_replace(opts[i]);
2075 ret |= parse_option(opts[i], options, td);
2081 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2083 return parse_cmd_option(opt, val, options, td);
2086 void fio_fill_default_options(struct thread_data *td)
2088 fill_default_options(td, options);
2091 int fio_show_option_help(const char *opt)
2093 return show_cmd_help(options, opt);
2096 static void __options_mem(struct thread_data *td, int alloc)
2098 struct thread_options *o = &td->o;
2099 struct fio_option *opt;
2103 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2104 if (opt->type != FIO_OPT_STR_STORE)
2107 ptr = (void *) o + opt->off1;
2110 *ptr = strdup(*ptr);
2120 * dupe FIO_OPT_STR_STORE options
2122 void options_mem_dupe(struct thread_data *td)
2124 __options_mem(td, 1);
2127 void options_mem_free(struct thread_data fio_unused *td)
2130 __options_mem(td, 0);
2134 unsigned int fio_get_kb_base(void *data)
2136 struct thread_data *td = data;
2137 unsigned int kb_base = 0;
2140 kb_base = td->o.kb_base;
2147 int add_option(struct fio_option *o)
2149 struct fio_option *__o;
2158 memcpy(&options[opt_index], o, sizeof(*o));
2162 void invalidate_profile_options(const char *prof_name)
2164 struct fio_option *o;
2168 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2169 o->type = FIO_OPT_INVALID;
2170 o->prof_name = NULL;
2176 void add_opt_posval(const char *optname, const char *ival, const char *help)
2178 struct fio_option *o;
2181 o = find_option(options, optname);
2185 for (i = 0; i < PARSE_MAX_VP; i++) {
2186 if (o->posval[i].ival)
2189 o->posval[i].ival = ival;
2190 o->posval[i].help = help;
2195 void del_opt_posval(const char *optname, const char *ival)
2197 struct fio_option *o;
2200 o = find_option(options, optname);
2204 for (i = 0; i < PARSE_MAX_VP; i++) {
2205 if (!o->posval[i].ival)
2207 if (strcmp(o->posval[i].ival, ival))
2210 o->posval[i].ival = NULL;
2211 o->posval[i].help = NULL;