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_clat = !!val;
714 td->o.disable_slat = !!val;
715 td->o.disable_bw = !!val;
717 td->tv_cache_mask = 63;
722 static int str_gtod_cpu_cb(void *data, int *il)
724 struct thread_data *td = data;
727 td->o.gtod_cpu = val;
728 td->o.gtod_offload = 1;
732 static int rw_verify(struct fio_option *o, void *data)
734 struct thread_data *td = data;
736 if (read_only && td_write(td)) {
737 log_err("fio: job <%s> has write bit set, but fio is in"
738 " read-only mode\n", td->o.name);
745 static int gtod_cpu_verify(struct fio_option *o, void *data)
747 #ifndef FIO_HAVE_CPU_AFFINITY
748 struct thread_data *td = data;
750 if (td->o.gtod_cpu) {
751 log_err("fio: platform must support CPU affinity for"
752 "gettimeofday() offloading\n");
760 static int kb_base_verify(struct fio_option *o, void *data)
762 struct thread_data *td = data;
764 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
765 log_err("fio: kb_base set to nonsensical value: %u\n",
773 #define __stringify_1(x) #x
774 #define __stringify(x) __stringify_1(x)
777 * Map of job/command line options
779 static struct fio_option options[FIO_MAX_OPTS] = {
781 .name = "description",
782 .type = FIO_OPT_STR_STORE,
783 .off1 = td_var_offset(description),
784 .help = "Text job description",
788 .type = FIO_OPT_STR_STORE,
789 .off1 = td_var_offset(name),
790 .help = "Name of this job",
794 .type = FIO_OPT_STR_STORE,
795 .off1 = td_var_offset(directory),
796 .cb = str_directory_cb,
797 .help = "Directory to store files in",
801 .type = FIO_OPT_STR_STORE,
802 .off1 = td_var_offset(filename),
803 .cb = str_filename_cb,
804 .prio = -1, /* must come after "directory" */
805 .help = "File(s) to use for the workload",
810 .off1 = td_var_offset(kb_base),
811 .verify = kb_base_verify,
814 .help = "How many bytes per KB for reporting (1000 or 1024)",
819 .cb = str_lockfile_cb,
820 .off1 = td_var_offset(file_lock_mode),
821 .help = "Lock file when doing IO to it",
822 .parent = "filename",
826 .oval = FILE_LOCK_NONE,
827 .help = "No file locking",
829 { .ival = "exclusive",
830 .oval = FILE_LOCK_EXCLUSIVE,
831 .help = "Exclusive file lock",
835 .oval = FILE_LOCK_READWRITE,
836 .help = "Read vs write lock",
842 .type = FIO_OPT_STR_STORE,
843 .off1 = td_var_offset(opendir),
844 .cb = str_opendir_cb,
845 .help = "Recursively add files from this directory and down",
849 .alias = "readwrite",
852 .off1 = td_var_offset(td_ddir),
853 .help = "IO direction",
858 .oval = TD_DDIR_READ,
859 .help = "Sequential read",
862 .oval = TD_DDIR_WRITE,
863 .help = "Sequential write",
865 { .ival = "randread",
866 .oval = TD_DDIR_RANDREAD,
867 .help = "Random read",
869 { .ival = "randwrite",
870 .oval = TD_DDIR_RANDWRITE,
871 .help = "Random write",
875 .help = "Sequential read and write mix",
878 .oval = TD_DDIR_RANDRW,
879 .help = "Random read and write mix"
885 .type = FIO_OPT_STR_STORE,
886 .off1 = td_var_offset(ioengine),
887 .help = "IO engine to use",
891 .help = "Use read/write",
894 .help = "Use pread/pwrite",
897 .help = "Use readv/writev",
899 #ifdef FIO_HAVE_LIBAIO
901 .help = "Linux native asynchronous IO",
904 #ifdef FIO_HAVE_POSIXAIO
905 { .ival = "posixaio",
906 .help = "POSIX asynchronous IO",
909 #ifdef FIO_HAVE_SOLARISAIO
910 { .ival = "solarisaio",
911 .help = "Solaris native asynchronous IO",
915 .help = "Memory mapped IO",
917 #ifdef FIO_HAVE_SPLICE
919 .help = "splice/vmsplice based IO",
921 { .ival = "netsplice",
922 .help = "splice/vmsplice to/from the network",
927 .help = "SCSI generic v3 IO",
931 .help = "Testing engine (no data transfer)",
934 .help = "Network IO",
936 #ifdef FIO_HAVE_SYSLET
937 { .ival = "syslet-rw",
938 .help = "syslet enabled async pread/pwrite IO",
942 .help = "CPU cycler burner engine",
944 #ifdef FIO_HAVE_GUASI
946 .help = "GUASI IO engine",
949 { .ival = "external",
950 .help = "Load external engine (append name)",
957 .off1 = td_var_offset(iodepth),
958 .help = "Amount of IO buffers to keep in flight",
963 .name = "iodepth_batch",
964 .alias = "iodepth_batch_submit",
966 .off1 = td_var_offset(iodepth_batch),
967 .help = "Number of IO buffers to submit in one go",
973 .name = "iodepth_batch_complete",
975 .off1 = td_var_offset(iodepth_batch_complete),
976 .help = "Number of IO buffers to retrieve in one go",
982 .name = "iodepth_low",
984 .off1 = td_var_offset(iodepth_low),
985 .help = "Low water mark for queuing depth",
990 .type = FIO_OPT_STR_VAL,
991 .off1 = td_var_offset(size),
993 .help = "Total size of device or files",
996 .name = "fill_device",
997 .type = FIO_OPT_BOOL,
998 .off1 = td_var_offset(fill_device),
999 .help = "Write until an ENOSPC error occurs",
1004 .type = FIO_OPT_STR_VAL,
1005 .off1 = td_var_offset(file_size_low),
1006 .off2 = td_var_offset(file_size_high),
1008 .help = "Size of individual files",
1012 .alias = "fileoffset",
1013 .type = FIO_OPT_STR_VAL,
1014 .off1 = td_var_offset(start_offset),
1015 .help = "Start IO from this offset",
1020 .alias = "blocksize",
1021 .type = FIO_OPT_INT,
1022 .off1 = td_var_offset(bs[DDIR_READ]),
1023 .off2 = td_var_offset(bs[DDIR_WRITE]),
1025 .help = "Block size unit",
1031 .alias = "blockalign",
1032 .type = FIO_OPT_INT,
1033 .off1 = td_var_offset(ba[DDIR_READ]),
1034 .off2 = td_var_offset(ba[DDIR_WRITE]),
1036 .help = "IO block offset alignment",
1041 .alias = "blocksize_range",
1042 .type = FIO_OPT_RANGE,
1043 .off1 = td_var_offset(min_bs[DDIR_READ]),
1044 .off2 = td_var_offset(max_bs[DDIR_READ]),
1045 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1046 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1048 .help = "Set block size range (in more detail than bs)",
1053 .type = FIO_OPT_STR,
1054 .cb = str_bssplit_cb,
1055 .help = "Set a specific mix of block sizes",
1059 .name = "bs_unaligned",
1060 .alias = "blocksize_unaligned",
1061 .type = FIO_OPT_STR_SET,
1062 .off1 = td_var_offset(bs_unaligned),
1063 .help = "Don't sector align IO buffer sizes",
1067 .name = "randrepeat",
1068 .type = FIO_OPT_BOOL,
1069 .off1 = td_var_offset(rand_repeatable),
1070 .help = "Use repeatable random IO pattern",
1075 .name = "norandommap",
1076 .type = FIO_OPT_STR_SET,
1077 .off1 = td_var_offset(norandommap),
1078 .help = "Accept potential duplicate random blocks",
1082 .name = "softrandommap",
1083 .type = FIO_OPT_BOOL,
1084 .off1 = td_var_offset(softrandommap),
1085 .help = "Set norandommap if randommap allocation fails",
1086 .parent = "norandommap",
1091 .type = FIO_OPT_INT,
1092 .off1 = td_var_offset(nr_files),
1093 .help = "Split job workload between this number of files",
1097 .name = "openfiles",
1098 .type = FIO_OPT_INT,
1099 .off1 = td_var_offset(open_files),
1100 .help = "Number of files to keep open at the same time",
1103 .name = "file_service_type",
1104 .type = FIO_OPT_STR,
1106 .off1 = td_var_offset(file_service_type),
1107 .help = "How to select which file to service next",
1108 .def = "roundrobin",
1111 .oval = FIO_FSERVICE_RANDOM,
1112 .help = "Choose a file at random",
1114 { .ival = "roundrobin",
1115 .oval = FIO_FSERVICE_RR,
1116 .help = "Round robin select files",
1118 { .ival = "sequential",
1119 .oval = FIO_FSERVICE_SEQ,
1120 .help = "Finish one file before moving to the next",
1123 .parent = "nrfiles",
1125 #ifdef FIO_HAVE_FALLOCATE
1127 .name = "fallocate",
1128 .type = FIO_OPT_BOOL,
1129 .off1 = td_var_offset(fallocate),
1130 .help = "Use fallocate() when laying out files",
1135 .name = "fadvise_hint",
1136 .type = FIO_OPT_BOOL,
1137 .off1 = td_var_offset(fadvise_hint),
1138 .help = "Use fadvise() to advise the kernel on IO pattern",
1143 .type = FIO_OPT_INT,
1144 .off1 = td_var_offset(fsync_blocks),
1145 .help = "Issue fsync for writes every given number of blocks",
1149 .name = "fdatasync",
1150 .type = FIO_OPT_INT,
1151 .off1 = td_var_offset(fdatasync_blocks),
1152 .help = "Issue fdatasync for writes every given number of blocks",
1155 #ifdef FIO_HAVE_SYNC_FILE_RANGE
1157 .name = "sync_file_range",
1159 { .ival = "wait_before",
1160 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1161 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1165 .oval = SYNC_FILE_RANGE_WRITE,
1166 .help = "SYNC_FILE_RANGE_WRITE",
1170 .ival = "wait_after",
1171 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1172 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1176 .type = FIO_OPT_STR_MULTI,
1178 .off1 = td_var_offset(sync_file_range),
1179 .help = "Use sync_file_range()",
1184 .type = FIO_OPT_BOOL,
1185 .off1 = td_var_offset(odirect),
1186 .help = "Use O_DIRECT IO (negates buffered)",
1191 .type = FIO_OPT_BOOL,
1192 .off1 = td_var_offset(odirect),
1194 .help = "Use buffered IO (negates direct)",
1198 .name = "overwrite",
1199 .type = FIO_OPT_BOOL,
1200 .off1 = td_var_offset(overwrite),
1201 .help = "When writing, set whether to overwrite current data",
1206 .type = FIO_OPT_INT,
1207 .off1 = td_var_offset(loops),
1208 .help = "Number of times to run the job",
1213 .type = FIO_OPT_INT,
1214 .off1 = td_var_offset(numjobs),
1215 .help = "Duplicate this job this many times",
1219 .name = "startdelay",
1220 .type = FIO_OPT_INT,
1221 .off1 = td_var_offset(start_delay),
1222 .help = "Only start job when this period has passed",
1228 .type = FIO_OPT_STR_VAL_TIME,
1229 .off1 = td_var_offset(timeout),
1230 .help = "Stop workload when this amount of time has passed",
1234 .name = "time_based",
1235 .type = FIO_OPT_STR_SET,
1236 .off1 = td_var_offset(time_based),
1237 .help = "Keep running until runtime/timeout is met",
1240 .name = "ramp_time",
1241 .type = FIO_OPT_STR_VAL_TIME,
1242 .off1 = td_var_offset(ramp_time),
1243 .help = "Ramp up time before measuring performance",
1246 .name = "clocksource",
1247 .type = FIO_OPT_STR,
1248 .cb = fio_clock_source_cb,
1249 .off1 = td_var_offset(clocksource),
1250 .help = "What type of timing source to use",
1252 { .ival = "gettimeofday",
1254 .help = "Use gettimeofday(2) for timing",
1256 { .ival = "clock_gettime",
1257 .oval = CS_CGETTIME,
1258 .help = "Use clock_gettime(2) for timing",
1260 #ifdef ARCH_HAVE_CPU_CLOCK
1262 .oval = CS_CPUCLOCK,
1263 .help = "Use CPU private clock",
1271 .type = FIO_OPT_STR,
1273 .off1 = td_var_offset(mem_type),
1274 .help = "Backing type for IO buffers",
1279 .help = "Use malloc(3) for IO buffers",
1283 .help = "Use shared memory segments for IO buffers",
1285 #ifdef FIO_HAVE_HUGETLB
1286 { .ival = "shmhuge",
1287 .oval = MEM_SHMHUGE,
1288 .help = "Like shm, but use huge pages",
1293 .help = "Use mmap(2) (file or anon) for IO buffers",
1295 #ifdef FIO_HAVE_HUGETLB
1296 { .ival = "mmaphuge",
1297 .oval = MEM_MMAPHUGE,
1298 .help = "Like mmap, but use huge pages",
1304 .name = "iomem_align",
1305 .alias = "mem_align",
1306 .type = FIO_OPT_INT,
1307 .off1 = td_var_offset(mem_align),
1309 .help = "IO memory buffer offset alignment",
1315 .type = FIO_OPT_STR,
1316 .off1 = td_var_offset(verify),
1317 .help = "Verify data written",
1318 .cb = str_verify_cb,
1322 .oval = VERIFY_NONE,
1323 .help = "Don't do IO verification",
1327 .help = "Use md5 checksums for verification",
1330 .oval = VERIFY_CRC64,
1331 .help = "Use crc64 checksums for verification",
1334 .oval = VERIFY_CRC32,
1335 .help = "Use crc32 checksums for verification",
1337 { .ival = "crc32c-intel",
1338 .oval = VERIFY_CRC32C_INTEL,
1339 .help = "Use hw crc32c checksums for verification",
1342 .oval = VERIFY_CRC32C,
1343 .help = "Use crc32c checksums for verification",
1346 .oval = VERIFY_CRC16,
1347 .help = "Use crc16 checksums for verification",
1350 .oval = VERIFY_CRC7,
1351 .help = "Use crc7 checksums for verification",
1354 .oval = VERIFY_SHA1,
1355 .help = "Use sha1 checksums for verification",
1358 .oval = VERIFY_SHA256,
1359 .help = "Use sha256 checksums for verification",
1362 .oval = VERIFY_SHA512,
1363 .help = "Use sha512 checksums for verification",
1366 .oval = VERIFY_META,
1367 .help = "Use io information",
1371 .oval = VERIFY_NULL,
1372 .help = "Pretend to verify",
1377 .name = "do_verify",
1378 .type = FIO_OPT_BOOL,
1379 .off1 = td_var_offset(do_verify),
1380 .help = "Run verification stage after write",
1385 .name = "verifysort",
1386 .type = FIO_OPT_BOOL,
1387 .off1 = td_var_offset(verifysort),
1388 .help = "Sort written verify blocks for read back",
1393 .name = "verify_interval",
1394 .type = FIO_OPT_INT,
1395 .off1 = td_var_offset(verify_interval),
1396 .minval = 2 * sizeof(struct verify_header),
1397 .help = "Store verify buffer header every N bytes",
1401 .name = "verify_offset",
1402 .type = FIO_OPT_INT,
1403 .help = "Offset verify header location by N bytes",
1405 .cb = str_verify_offset_cb,
1409 .name = "verify_pattern",
1410 .type = FIO_OPT_STR,
1411 .cb = str_verify_pattern_cb,
1412 .help = "Fill pattern for IO buffers",
1416 .name = "verify_fatal",
1417 .type = FIO_OPT_BOOL,
1418 .off1 = td_var_offset(verify_fatal),
1420 .help = "Exit on a single verify failure, don't continue",
1424 .name = "verify_async",
1425 .type = FIO_OPT_INT,
1426 .off1 = td_var_offset(verify_async),
1428 .help = "Number of async verifier threads to use",
1432 .name = "verify_backlog",
1433 .type = FIO_OPT_STR_VAL,
1434 .off1 = td_var_offset(verify_backlog),
1435 .help = "Verify after this number of blocks are written",
1439 .name = "verify_backlog_batch",
1440 .type = FIO_OPT_INT,
1441 .off1 = td_var_offset(verify_batch),
1442 .help = "Verify this number of IO blocks",
1443 .parent = "verify_backlog",
1445 #ifdef FIO_HAVE_CPU_AFFINITY
1447 .name = "verify_async_cpus",
1448 .type = FIO_OPT_STR,
1449 .cb = str_verify_cpus_allowed_cb,
1450 .help = "Set CPUs allowed for async verify threads",
1451 .parent = "verify_async",
1455 .name = "write_iolog",
1456 .type = FIO_OPT_STR_STORE,
1457 .off1 = td_var_offset(write_iolog_file),
1458 .help = "Store IO pattern to file",
1461 .name = "read_iolog",
1462 .type = FIO_OPT_STR_STORE,
1463 .off1 = td_var_offset(read_iolog_file),
1464 .help = "Playback IO pattern from file",
1467 .name = "exec_prerun",
1468 .type = FIO_OPT_STR_STORE,
1469 .off1 = td_var_offset(exec_prerun),
1470 .help = "Execute this file prior to running job",
1473 .name = "exec_postrun",
1474 .type = FIO_OPT_STR_STORE,
1475 .off1 = td_var_offset(exec_postrun),
1476 .help = "Execute this file after running job",
1478 #ifdef FIO_HAVE_IOSCHED_SWITCH
1480 .name = "ioscheduler",
1481 .type = FIO_OPT_STR_STORE,
1482 .off1 = td_var_offset(ioscheduler),
1483 .help = "Use this IO scheduler on the backing device",
1488 .type = FIO_OPT_STR_VAL,
1489 .off1 = td_var_offset(zone_size),
1490 .help = "Give size of an IO zone",
1495 .type = FIO_OPT_STR_VAL,
1496 .off1 = td_var_offset(zone_skip),
1497 .help = "Space between IO zones",
1502 .type = FIO_OPT_STR_VAL,
1503 .cb = str_lockmem_cb,
1504 .help = "Lock down this amount of memory",
1508 .name = "rwmixread",
1509 .type = FIO_OPT_INT,
1510 .cb = str_rwmix_read_cb,
1512 .help = "Percentage of mixed workload that is reads",
1516 .name = "rwmixwrite",
1517 .type = FIO_OPT_INT,
1518 .cb = str_rwmix_write_cb,
1520 .help = "Percentage of mixed workload that is writes",
1524 .name = "rwmixcycle",
1525 .type = FIO_OPT_DEPRECATED,
1529 .type = FIO_OPT_INT,
1530 .off1 = td_var_offset(nice),
1531 .help = "Set job CPU nice value",
1536 #ifdef FIO_HAVE_IOPRIO
1539 .type = FIO_OPT_INT,
1541 .help = "Set job IO priority value",
1546 .name = "prioclass",
1547 .type = FIO_OPT_INT,
1548 .cb = str_prioclass_cb,
1549 .help = "Set job IO priority class",
1555 .name = "thinktime",
1556 .type = FIO_OPT_INT,
1557 .off1 = td_var_offset(thinktime),
1558 .help = "Idle time between IO buffers (usec)",
1562 .name = "thinktime_spin",
1563 .type = FIO_OPT_INT,
1564 .off1 = td_var_offset(thinktime_spin),
1565 .help = "Start think time by spinning this amount (usec)",
1567 .parent = "thinktime",
1570 .name = "thinktime_blocks",
1571 .type = FIO_OPT_INT,
1572 .off1 = td_var_offset(thinktime_blocks),
1573 .help = "IO buffer period between 'thinktime'",
1575 .parent = "thinktime",
1579 .type = FIO_OPT_INT,
1580 .off1 = td_var_offset(rate[0]),
1581 .off2 = td_var_offset(rate[1]),
1582 .help = "Set bandwidth rate",
1586 .type = FIO_OPT_INT,
1587 .off1 = td_var_offset(ratemin[0]),
1588 .off2 = td_var_offset(ratemin[1]),
1589 .help = "Job must meet this rate or it will be shutdown",
1593 .name = "rate_iops",
1594 .type = FIO_OPT_INT,
1595 .off1 = td_var_offset(rate_iops[0]),
1596 .off2 = td_var_offset(rate_iops[1]),
1597 .help = "Limit IO used to this number of IO operations/sec",
1600 .name = "rate_iops_min",
1601 .type = FIO_OPT_INT,
1602 .off1 = td_var_offset(rate_iops_min[0]),
1603 .off2 = td_var_offset(rate_iops_min[1]),
1604 .help = "Job must meet this rate or it will be shutdown",
1605 .parent = "rate_iops",
1608 .name = "ratecycle",
1609 .type = FIO_OPT_INT,
1610 .off1 = td_var_offset(ratecycle),
1611 .help = "Window average for rate limits (msec)",
1616 .name = "invalidate",
1617 .type = FIO_OPT_BOOL,
1618 .off1 = td_var_offset(invalidate_cache),
1619 .help = "Invalidate buffer/page cache prior to running job",
1624 .type = FIO_OPT_BOOL,
1625 .off1 = td_var_offset(sync_io),
1626 .help = "Use O_SYNC for buffered writes",
1628 .parent = "buffered",
1631 .name = "bwavgtime",
1632 .type = FIO_OPT_INT,
1633 .off1 = td_var_offset(bw_avg_time),
1634 .help = "Time window over which to calculate bandwidth"
1639 .name = "create_serialize",
1640 .type = FIO_OPT_BOOL,
1641 .off1 = td_var_offset(create_serialize),
1642 .help = "Serialize creating of job files",
1646 .name = "create_fsync",
1647 .type = FIO_OPT_BOOL,
1648 .off1 = td_var_offset(create_fsync),
1649 .help = "Fsync file after creation",
1653 .name = "create_on_open",
1654 .type = FIO_OPT_BOOL,
1655 .off1 = td_var_offset(create_on_open),
1656 .help = "Create files when they are opened for IO",
1661 .type = FIO_OPT_BOOL,
1662 .off1 = td_var_offset(pre_read),
1663 .help = "Preread files before starting official testing",
1668 .type = FIO_OPT_INT,
1669 .off1 = td_var_offset(cpuload),
1670 .help = "Use this percentage of CPU",
1673 .name = "cpuchunks",
1674 .type = FIO_OPT_INT,
1675 .off1 = td_var_offset(cpucycle),
1676 .help = "Length of the CPU burn cycles (usecs)",
1678 .parent = "cpuload",
1680 #ifdef FIO_HAVE_CPU_AFFINITY
1683 .type = FIO_OPT_INT,
1684 .cb = str_cpumask_cb,
1685 .help = "CPU affinity mask",
1688 .name = "cpus_allowed",
1689 .type = FIO_OPT_STR,
1690 .cb = str_cpus_allowed_cb,
1691 .help = "Set CPUs allowed",
1695 .name = "end_fsync",
1696 .type = FIO_OPT_BOOL,
1697 .off1 = td_var_offset(end_fsync),
1698 .help = "Include fsync at the end of job",
1702 .name = "fsync_on_close",
1703 .type = FIO_OPT_BOOL,
1704 .off1 = td_var_offset(fsync_on_close),
1705 .help = "fsync files on close",
1710 .type = FIO_OPT_BOOL,
1711 .off1 = td_var_offset(unlink),
1712 .help = "Unlink created files after job has completed",
1717 .type = FIO_OPT_STR_SET,
1718 .cb = str_exitall_cb,
1719 .help = "Terminate all jobs when one exits",
1722 .name = "stonewall",
1723 .type = FIO_OPT_STR_SET,
1724 .off1 = td_var_offset(stonewall),
1725 .help = "Insert a hard barrier between this job and previous",
1728 .name = "new_group",
1729 .type = FIO_OPT_STR_SET,
1730 .off1 = td_var_offset(new_group),
1731 .help = "Mark the start of a new group (for reporting)",
1735 .type = FIO_OPT_STR_SET,
1736 .off1 = td_var_offset(use_thread),
1737 .help = "Use threads instead of forks",
1740 .name = "write_bw_log",
1741 .type = FIO_OPT_STR,
1742 .off1 = td_var_offset(write_bw_log),
1743 .cb = str_write_bw_log_cb,
1744 .help = "Write log of bandwidth during run",
1747 .name = "write_lat_log",
1748 .type = FIO_OPT_STR,
1749 .off1 = td_var_offset(write_lat_log),
1750 .cb = str_write_lat_log_cb,
1751 .help = "Write log of latency during run",
1754 .name = "hugepage-size",
1755 .type = FIO_OPT_INT,
1756 .off1 = td_var_offset(hugepage_size),
1757 .help = "When using hugepages, specify size of each page",
1758 .def = __stringify(FIO_HUGE_PAGE),
1761 .name = "group_reporting",
1762 .type = FIO_OPT_STR_SET,
1763 .off1 = td_var_offset(group_reporting),
1764 .help = "Do reporting on a per-group basis",
1767 .name = "zero_buffers",
1768 .type = FIO_OPT_STR_SET,
1769 .off1 = td_var_offset(zero_buffers),
1770 .help = "Init IO buffers to all zeroes",
1773 .name = "refill_buffers",
1774 .type = FIO_OPT_STR_SET,
1775 .off1 = td_var_offset(refill_buffers),
1776 .help = "Refill IO buffers on every IO submit",
1778 #ifdef FIO_HAVE_DISK_UTIL
1780 .name = "disk_util",
1781 .type = FIO_OPT_BOOL,
1782 .off1 = td_var_offset(do_disk_util),
1783 .help = "Log disk utilization statistics",
1788 .name = "gtod_reduce",
1789 .type = FIO_OPT_BOOL,
1790 .help = "Greatly reduce number of gettimeofday() calls",
1791 .cb = str_gtod_reduce_cb,
1795 .name = "disable_clat",
1796 .type = FIO_OPT_BOOL,
1797 .off1 = td_var_offset(disable_clat),
1798 .help = "Disable completion latency numbers",
1799 .parent = "gtod_reduce",
1803 .name = "disable_slat",
1804 .type = FIO_OPT_BOOL,
1805 .off1 = td_var_offset(disable_slat),
1806 .help = "Disable submissionn latency numbers",
1807 .parent = "gtod_reduce",
1811 .name = "disable_bw_measurement",
1812 .type = FIO_OPT_BOOL,
1813 .off1 = td_var_offset(disable_bw),
1814 .help = "Disable bandwidth logging",
1815 .parent = "gtod_reduce",
1820 .type = FIO_OPT_INT,
1821 .cb = str_gtod_cpu_cb,
1822 .help = "Setup dedicated gettimeofday() thread on this CPU",
1823 .verify = gtod_cpu_verify,
1826 .name = "continue_on_error",
1827 .type = FIO_OPT_BOOL,
1828 .off1 = td_var_offset(continue_on_error),
1829 .help = "Continue on non-fatal errors during I/O",
1834 .type = FIO_OPT_STR_STORE,
1835 .off1 = td_var_offset(profile),
1836 .help = "Select a specific builtin performance test",
1840 .type = FIO_OPT_STR_STORE,
1841 .off1 = td_var_offset(cgroup),
1842 .help = "Add job to cgroup of this name",
1845 .name = "cgroup_weight",
1846 .type = FIO_OPT_INT,
1847 .off1 = td_var_offset(cgroup_weight),
1848 .help = "Use given weight for cgroup",
1853 .name = "cgroup_nodelete",
1854 .type = FIO_OPT_BOOL,
1855 .off1 = td_var_offset(cgroup_nodelete),
1856 .help = "Do not delete cgroups after job completion",
1861 .type = FIO_OPT_INT,
1862 .off1 = td_var_offset(uid),
1863 .help = "Run job with this user ID",
1867 .type = FIO_OPT_INT,
1868 .off1 = td_var_offset(gid),
1869 .help = "Run job with this group ID",
1876 static void add_to_lopt(struct option *lopt, struct fio_option *o,
1879 lopt->name = (char *) name;
1880 lopt->val = FIO_GETOPT_JOB;
1881 if (o->type == FIO_OPT_STR_SET)
1882 lopt->has_arg = no_argument;
1884 lopt->has_arg = required_argument;
1887 void fio_options_dup_and_init(struct option *long_options)
1889 struct fio_option *o;
1892 options_init(options);
1895 while (long_options[i].name)
1900 add_to_lopt(&long_options[i], o, o->name);
1903 add_to_lopt(&long_options[i], o, o->alias);
1908 assert(i < FIO_NR_OPTIONS);
1912 struct fio_keyword {
1918 static struct fio_keyword fio_keywords[] = {
1920 .word = "$pagesize",
1921 .desc = "Page size in the system",
1924 .word = "$mb_memory",
1925 .desc = "Megabytes of memory online",
1929 .desc = "Number of CPUs online in the system",
1936 void fio_keywords_init(void)
1938 unsigned long long mb_memory;
1942 sprintf(buf, "%lu", page_size);
1943 fio_keywords[0].replace = strdup(buf);
1945 mb_memory = os_phys_mem() / page_size;
1946 sprintf(buf, "%llu", mb_memory);
1947 fio_keywords[1].replace = strdup(buf);
1949 l = sysconf(_SC_NPROCESSORS_ONLN);
1950 sprintf(buf, "%lu", l);
1951 fio_keywords[2].replace = strdup(buf);
1956 static char *bc_calc(char *str)
1958 char *buf, *tmp, opt[80];
1963 * No math, just return string
1965 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1970 * Split option from value, we only need to calculate the value
1972 tmp = strchr(str, '=');
1977 memset(opt, 0, sizeof(opt));
1978 strncpy(opt, str, tmp - str);
1982 sprintf(buf, "which %s > /dev/null", BC_APP);
1984 log_err("fio: bc is needed for performing math\n");
1989 sprintf(buf, "echo %s | %s", tmp, BC_APP);
1990 f = popen(buf, "r");
1996 ret = fread(buf, 1, 128, f);
2002 buf[ret - 1] = '\0';
2011 * Look for reserved variable names and replace them with real values
2013 static char *fio_keyword_replace(char *opt)
2018 for (i = 0; fio_keywords[i].word != NULL; i++) {
2019 struct fio_keyword *kw = &fio_keywords[i];
2021 while ((s = strstr(opt, kw->word)) != NULL) {
2022 char *new = malloc(strlen(opt) + 1);
2028 * Copy part of the string before the keyword and
2029 * sprintf() the replacement after it.
2031 memcpy(new, opt, olen);
2032 len = sprintf(new + olen, "%s", kw->replace);
2035 * If there's more in the original string, copy that
2038 opt += strlen(kw->word) + olen;
2040 memcpy(new + olen + len, opt, opt - o_org - 1);
2043 * replace opt and free the old opt
2049 * Check for potential math and invoke bc, if possible
2058 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2062 sort_options(opts, options, num_opts);
2064 for (ret = 0, i = 0; i < num_opts; i++) {
2065 opts[i] = fio_keyword_replace(opts[i]);
2066 ret |= parse_option(opts[i], options, td);
2072 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2074 return parse_cmd_option(opt, val, options, td);
2077 void fio_fill_default_options(struct thread_data *td)
2079 fill_default_options(td, options);
2082 int fio_show_option_help(const char *opt)
2084 return show_cmd_help(options, opt);
2087 static void __options_mem(struct thread_data *td, int alloc)
2089 struct thread_options *o = &td->o;
2090 struct fio_option *opt;
2094 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2095 if (opt->type != FIO_OPT_STR_STORE)
2098 ptr = (void *) o + opt->off1;
2101 *ptr = strdup(*ptr);
2111 * dupe FIO_OPT_STR_STORE options
2113 void options_mem_dupe(struct thread_data *td)
2115 __options_mem(td, 1);
2118 void options_mem_free(struct thread_data fio_unused *td)
2121 __options_mem(td, 0);
2125 unsigned int fio_get_kb_base(void *data)
2127 struct thread_data *td = data;
2128 unsigned int kb_base = 0;
2131 kb_base = td->o.kb_base;
2138 int add_option(struct fio_option *o)
2140 struct fio_option *__o;
2149 memcpy(&options[opt_index], o, sizeof(*o));
2153 void invalidate_profile_options(const char *prof_name)
2155 struct fio_option *o;
2159 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2160 o->type = FIO_OPT_INVALID;
2161 o->prof_name = NULL;
2167 void add_opt_posval(const char *optname, const char *ival, const char *help)
2169 struct fio_option *o;
2172 o = find_option(options, optname);
2176 for (i = 0; i < PARSE_MAX_VP; i++) {
2177 if (o->posval[i].ival)
2180 o->posval[i].ival = ival;
2181 o->posval[i].help = help;
2186 void del_opt_posval(const char *optname, const char *ival)
2188 struct fio_option *o;
2191 o = find_option(options, optname);
2195 for (i = 0; i < PARSE_MAX_VP; i++) {
2196 if (!o->posval[i].ival)
2198 if (strcmp(o->posval[i].ival, ival))
2201 o->posval[i].ival = NULL;
2202 o->posval[i].help = NULL;