18 #include "crc/crc32c.h"
21 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
23 static char *get_opt_postfix(const char *str)
25 char *p = strstr(str, ":");
31 strip_blank_front(&p);
36 static int converthexchartoint(char a)
56 static int bs_cmp(const void *p1, const void *p2)
58 const struct bssplit *bsp1 = p1;
59 const struct bssplit *bsp2 = p2;
61 return bsp1->perc < bsp2->perc;
64 static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
66 struct bssplit *bssplit;
67 unsigned int i, perc, perc_missing;
68 unsigned int max_bs, min_bs;
72 td->o.bssplit_nr[ddir] = 4;
73 bssplit = malloc(4 * sizeof(struct bssplit));
78 while ((fname = strsep(&str, ":")) != NULL) {
85 * grow struct buffer, if needed
87 if (i == td->o.bssplit_nr[ddir]) {
88 td->o.bssplit_nr[ddir] <<= 1;
89 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
90 * sizeof(struct bssplit));
93 perc_str = strstr(fname, "/");
97 perc = atoi(perc_str);
105 if (str_to_decimal(fname, &val, 1, td)) {
106 log_err("fio: bssplit conversion failed\n");
117 bssplit[i].perc = perc;
121 td->o.bssplit_nr[ddir] = i;
124 * Now check if the percentages add up, and how much is missing
126 perc = perc_missing = 0;
127 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
128 struct bssplit *bsp = &bssplit[i];
130 if (bsp->perc == (unsigned char) -1)
137 log_err("fio: bssplit percentages add to more than 100%%\n");
142 * If values didn't have a percentage set, divide the remains between
146 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
147 struct bssplit *bsp = &bssplit[i];
149 if (bsp->perc == (unsigned char) -1)
150 bsp->perc = (100 - perc) / perc_missing;
154 td->o.min_bs[ddir] = min_bs;
155 td->o.max_bs[ddir] = max_bs;
158 * now sort based on percentages, for ease of lookup
160 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 td->o.bssplit[ddir] = bssplit;
166 static int str_bssplit_cb(void *data, const char *input)
168 struct thread_data *td = data;
169 char *str, *p, *odir;
172 p = str = strdup(input);
174 strip_blank_front(&str);
175 strip_blank_end(str);
177 odir = strchr(str, ',');
179 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
182 ret = bssplit_ddir(td, DDIR_READ, str);
189 ret = bssplit_ddir(td, DDIR_READ, str);
191 ret = bssplit_ddir(td, DDIR_WRITE, op);
200 static int str_rw_cb(void *data, const char *str)
202 struct thread_data *td = data;
203 char *nr = get_opt_postfix(str);
205 td->o.ddir_seq_nr = 1;
207 td->o.ddir_seq_nr = atoi(nr);
214 static int str_mem_cb(void *data, const char *mem)
216 struct thread_data *td = data;
218 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
219 td->mmapfile = get_opt_postfix(mem);
220 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
221 log_err("fio: mmaphuge:/path/to/file\n");
229 static int str_verify_cb(void *data, const char *mem)
231 struct thread_data *td = data;
233 if (td->o.verify != VERIFY_CRC32C_INTEL)
236 if (!crc32c_intel_works()) {
237 log_info("fio: System does not support hw accelerated crc32c. Falling back to sw crc32c.\n");
238 td->o.verify = VERIFY_CRC32C;
244 static int fio_clock_source_cb(void *data, const char *str)
246 struct thread_data *td = data;
248 fio_clock_source = td->o.clocksource;
253 static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
259 static int str_rwmix_read_cb(void *data, unsigned long long *val)
261 struct thread_data *td = data;
263 td->o.rwmix[DDIR_READ] = *val;
264 td->o.rwmix[DDIR_WRITE] = 100 - *val;
268 static int str_rwmix_write_cb(void *data, unsigned long long *val)
270 struct thread_data *td = data;
272 td->o.rwmix[DDIR_WRITE] = *val;
273 td->o.rwmix[DDIR_READ] = 100 - *val;
277 #ifdef FIO_HAVE_IOPRIO
278 static int str_prioclass_cb(void *data, unsigned long long *val)
280 struct thread_data *td = data;
284 * mask off old class bits, str_prio_cb() may have set a default class
286 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
289 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
294 static int str_prio_cb(void *data, unsigned long long *val)
296 struct thread_data *td = data;
301 * If no class is set, assume BE
303 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
304 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
311 static int str_exitall_cb(void)
313 exitall_on_terminate = 1;
317 #ifdef FIO_HAVE_CPU_AFFINITY
318 static int str_cpumask_cb(void *data, unsigned long long *val)
320 struct thread_data *td = data;
325 ret = fio_cpuset_init(&td->o.cpumask);
327 log_err("fio: cpuset_init failed\n");
328 td_verror(td, ret, "fio_cpuset_init");
332 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
334 for (i = 0; i < sizeof(int) * 8; i++) {
335 if ((1 << i) & *val) {
337 log_err("fio: CPU %d too large (max=%ld)\n", i,
341 dprint(FD_PARSE, "set cpu allowed %d\n", i);
342 fio_cpu_set(&td->o.cpumask, i);
346 td->o.cpumask_set = 1;
350 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
357 ret = fio_cpuset_init(mask);
359 log_err("fio: cpuset_init failed\n");
360 td_verror(td, ret, "fio_cpuset_init");
364 p = str = strdup(input);
366 strip_blank_front(&str);
367 strip_blank_end(str);
369 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
371 while ((cpu = strsep(&str, ",")) != NULL) {
380 while ((cpu2 = strsep(&str2, "-")) != NULL) {
390 while (icpu <= icpu2) {
391 if (icpu >= FIO_MAX_CPUS) {
392 log_err("fio: your OS only supports up to"
393 " %d CPUs\n", (int) FIO_MAX_CPUS);
397 if (icpu > max_cpu) {
398 log_err("fio: CPU %d too large (max=%ld)\n",
404 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
405 fio_cpu_set(mask, icpu);
414 td->o.cpumask_set = 1;
418 static int str_cpus_allowed_cb(void *data, const char *input)
420 struct thread_data *td = data;
423 ret = set_cpus_allowed(td, &td->o.cpumask, input);
425 td->o.cpumask_set = 1;
430 static int str_verify_cpus_allowed_cb(void *data, const char *input)
432 struct thread_data *td = data;
435 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
437 td->o.verify_cpumask_set = 1;
444 static int str_verify_trim_cb(void *data, unsigned long long *val)
446 struct thread_data *td = data;
448 td->o.trim_percentage = *val;
453 static int str_fst_cb(void *data, const char *str)
455 struct thread_data *td = data;
456 char *nr = get_opt_postfix(str);
458 td->file_service_nr = 1;
460 td->file_service_nr = atoi(nr);
467 #ifdef FIO_HAVE_SYNC_FILE_RANGE
468 static int str_sfr_cb(void *data, const char *str)
470 struct thread_data *td = data;
471 char *nr = get_opt_postfix(str);
473 td->sync_file_range_nr = 1;
475 td->sync_file_range_nr = atoi(nr);
483 static int check_dir(struct thread_data *td, char *fname)
485 char file[PATH_MAX], *dir;
488 if (td->o.directory) {
489 strcpy(file, td->o.directory);
494 sprintf(file + elen, "%s", fname);
501 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
502 * yet, so we can't do this check right here...
504 if (lstat(dir, &sb) < 0) {
507 log_err("fio: %s is not a directory\n", dir);
508 td_verror(td, ret, "lstat");
512 if (!S_ISDIR(sb.st_mode)) {
513 log_err("fio: %s is not a directory\n", dir);
523 * Return next file in the string. Files are separated with ':'. If the ':'
524 * is escaped with a '\', then that ':' is part of the filename and does not
525 * indicate a new file.
527 static char *get_next_file_name(char **ptr)
532 if (!str || !strlen(str))
538 * No colon, we are done
540 p = strchr(str, ':');
547 * We got a colon, but it's the first character. Skip and
555 if (*(p - 1) != '\\') {
561 memmove(p - 1, p, strlen(p) + 1);
568 static int str_filename_cb(void *data, const char *input)
570 struct thread_data *td = data;
571 char *fname, *str, *p;
573 p = str = strdup(input);
575 strip_blank_front(&str);
576 strip_blank_end(str);
578 if (!td->files_index)
581 while ((fname = get_next_file_name(&str)) != NULL) {
584 if (check_dir(td, fname)) {
596 static int str_directory_cb(void *data, const char fio_unused *str)
598 struct thread_data *td = data;
601 if (lstat(td->o.directory, &sb) < 0) {
604 log_err("fio: %s is not a directory\n", td->o.directory);
605 td_verror(td, ret, "lstat");
608 if (!S_ISDIR(sb.st_mode)) {
609 log_err("fio: %s is not a directory\n", td->o.directory);
616 static int str_opendir_cb(void *data, const char fio_unused *str)
618 struct thread_data *td = data;
620 if (!td->files_index)
623 return add_dir_files(td, td->o.opendir);
626 static int str_verify_offset_cb(void *data, unsigned long long *off)
628 struct thread_data *td = data;
630 if (*off && *off < sizeof(struct verify_header)) {
631 log_err("fio: verify_offset too small\n");
635 td->o.verify_offset = *off;
639 static int str_verify_pattern_cb(void *data, const char *input)
641 struct thread_data *td = data;
643 int i = 0, j = 0, len, k, base = 10;
646 loc1 = strstr(input, "0x");
647 loc2 = strstr(input, "0X");
650 off = strtol(input, NULL, base);
651 if (off != LONG_MAX || errno != ERANGE) {
653 td->o.verify_pattern[i] = off & 0xff;
662 j = loc1 - input + 2;
664 j = loc2 - input + 2;
667 if (len - j < MAX_PATTERN_SIZE * 2) {
669 off = converthexchartoint(input[k--]);
671 off += (converthexchartoint(input[k--])
673 td->o.verify_pattern[i++] = (char) off;
677 td->o.verify_pattern_bytes = i;
681 static int str_lockfile_cb(void *data, const char *str)
683 struct thread_data *td = data;
684 char *nr = get_opt_postfix(str);
686 td->o.lockfile_batch = 1;
688 td->o.lockfile_batch = atoi(nr);
695 static int str_write_bw_log_cb(void *data, const char *str)
697 struct thread_data *td = data;
700 td->o.bw_log_file = strdup(str);
702 td->o.write_bw_log = 1;
706 static int str_write_lat_log_cb(void *data, const char *str)
708 struct thread_data *td = data;
711 td->o.lat_log_file = strdup(str);
713 td->o.write_lat_log = 1;
717 static int str_gtod_reduce_cb(void *data, int *il)
719 struct thread_data *td = data;
722 td->o.disable_lat = !!val;
723 td->o.disable_clat = !!val;
724 td->o.disable_slat = !!val;
725 td->o.disable_bw = !!val;
727 td->tv_cache_mask = 63;
732 static int str_gtod_cpu_cb(void *data, long long *il)
734 struct thread_data *td = data;
737 td->o.gtod_cpu = val;
738 td->o.gtod_offload = 1;
742 static int rw_verify(struct fio_option *o, void *data)
744 struct thread_data *td = data;
746 if (read_only && td_write(td)) {
747 log_err("fio: job <%s> has write bit set, but fio is in"
748 " read-only mode\n", td->o.name);
755 static int gtod_cpu_verify(struct fio_option *o, void *data)
757 #ifndef FIO_HAVE_CPU_AFFINITY
758 struct thread_data *td = data;
760 if (td->o.gtod_cpu) {
761 log_err("fio: platform must support CPU affinity for"
762 "gettimeofday() offloading\n");
770 static int kb_base_verify(struct fio_option *o, void *data)
772 struct thread_data *td = data;
774 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
775 log_err("fio: kb_base set to nonsensical value: %u\n",
783 #define __stringify_1(x) #x
784 #define __stringify(x) __stringify_1(x)
787 * Map of job/command line options
789 static struct fio_option options[FIO_MAX_OPTS] = {
791 .name = "description",
792 .type = FIO_OPT_STR_STORE,
793 .off1 = td_var_offset(description),
794 .help = "Text job description",
798 .type = FIO_OPT_STR_STORE,
799 .off1 = td_var_offset(name),
800 .help = "Name of this job",
804 .type = FIO_OPT_STR_STORE,
805 .off1 = td_var_offset(directory),
806 .cb = str_directory_cb,
807 .help = "Directory to store files in",
811 .type = FIO_OPT_STR_STORE,
812 .off1 = td_var_offset(filename),
813 .cb = str_filename_cb,
814 .prio = -1, /* must come after "directory" */
815 .help = "File(s) to use for the workload",
820 .off1 = td_var_offset(kb_base),
821 .verify = kb_base_verify,
824 .help = "How many bytes per KB for reporting (1000 or 1024)",
829 .cb = str_lockfile_cb,
830 .off1 = td_var_offset(file_lock_mode),
831 .help = "Lock file when doing IO to it",
832 .parent = "filename",
836 .oval = FILE_LOCK_NONE,
837 .help = "No file locking",
839 { .ival = "exclusive",
840 .oval = FILE_LOCK_EXCLUSIVE,
841 .help = "Exclusive file lock",
845 .oval = FILE_LOCK_READWRITE,
846 .help = "Read vs write lock",
852 .type = FIO_OPT_STR_STORE,
853 .off1 = td_var_offset(opendir),
854 .cb = str_opendir_cb,
855 .help = "Recursively add files from this directory and down",
859 .alias = "readwrite",
862 .off1 = td_var_offset(td_ddir),
863 .help = "IO direction",
868 .oval = TD_DDIR_READ,
869 .help = "Sequential read",
872 .oval = TD_DDIR_WRITE,
873 .help = "Sequential write",
875 { .ival = "randread",
876 .oval = TD_DDIR_RANDREAD,
877 .help = "Random read",
879 { .ival = "randwrite",
880 .oval = TD_DDIR_RANDWRITE,
881 .help = "Random write",
885 .help = "Sequential read and write mix",
888 .oval = TD_DDIR_RANDRW,
889 .help = "Random read and write mix"
894 .name = "rw_sequencer",
896 .off1 = td_var_offset(rw_seq),
897 .help = "IO offset generator modifier",
900 { .ival = "sequential",
902 .help = "Generate sequential offsets",
904 { .ival = "identical",
905 .oval = RW_SEQ_IDENT,
906 .help = "Generate identical offsets",
913 .type = FIO_OPT_STR_STORE,
914 .off1 = td_var_offset(ioengine),
915 .help = "IO engine to use",
919 .help = "Use read/write",
922 .help = "Use pread/pwrite",
925 .help = "Use readv/writev",
927 #ifdef FIO_HAVE_LIBAIO
929 .help = "Linux native asynchronous IO",
932 #ifdef FIO_HAVE_POSIXAIO
933 { .ival = "posixaio",
934 .help = "POSIX asynchronous IO",
937 #ifdef FIO_HAVE_SOLARISAIO
938 { .ival = "solarisaio",
939 .help = "Solaris native asynchronous IO",
942 #ifdef FIO_HAVE_WINDOWSAIO
943 { .ival = "windowsaio",
944 .help = "Windows native asynchronous IO"
947 .help = "Memory mapped IO"
950 #ifdef FIO_HAVE_SPLICE
952 .help = "splice/vmsplice based IO",
954 { .ival = "netsplice",
955 .help = "splice/vmsplice to/from the network",
960 .help = "SCSI generic v3 IO",
964 .help = "Testing engine (no data transfer)",
967 .help = "Network IO",
969 #ifdef FIO_HAVE_SYSLET
970 { .ival = "syslet-rw",
971 .help = "syslet enabled async pread/pwrite IO",
975 .help = "CPU cycle burner engine",
977 #ifdef FIO_HAVE_GUASI
979 .help = "GUASI IO engine",
982 #ifdef FIO_HAVE_BINJECT
984 .help = "binject direct inject block engine",
987 { .ival = "external",
988 .help = "Load external engine (append name)",
995 .off1 = td_var_offset(iodepth),
996 .help = "Number of IO buffers to keep in flight",
1001 .name = "iodepth_batch",
1002 .alias = "iodepth_batch_submit",
1003 .type = FIO_OPT_INT,
1004 .off1 = td_var_offset(iodepth_batch),
1005 .help = "Number of IO buffers to submit in one go",
1006 .parent = "iodepth",
1011 .name = "iodepth_batch_complete",
1012 .type = FIO_OPT_INT,
1013 .off1 = td_var_offset(iodepth_batch_complete),
1014 .help = "Number of IO buffers to retrieve in one go",
1015 .parent = "iodepth",
1020 .name = "iodepth_low",
1021 .type = FIO_OPT_INT,
1022 .off1 = td_var_offset(iodepth_low),
1023 .help = "Low water mark for queuing depth",
1024 .parent = "iodepth",
1028 .type = FIO_OPT_STR_VAL,
1029 .off1 = td_var_offset(size),
1031 .help = "Total size of device or files",
1034 .name = "fill_device",
1035 .type = FIO_OPT_BOOL,
1036 .off1 = td_var_offset(fill_device),
1037 .help = "Write until an ENOSPC error occurs",
1042 .type = FIO_OPT_STR_VAL,
1043 .off1 = td_var_offset(file_size_low),
1044 .off2 = td_var_offset(file_size_high),
1046 .help = "Size of individual files",
1050 .alias = "fileoffset",
1051 .type = FIO_OPT_STR_VAL,
1052 .off1 = td_var_offset(start_offset),
1053 .help = "Start IO from this offset",
1058 .alias = "blocksize",
1059 .type = FIO_OPT_INT,
1060 .off1 = td_var_offset(bs[DDIR_READ]),
1061 .off2 = td_var_offset(bs[DDIR_WRITE]),
1063 .help = "Block size unit",
1069 .alias = "blockalign",
1070 .type = FIO_OPT_INT,
1071 .off1 = td_var_offset(ba[DDIR_READ]),
1072 .off2 = td_var_offset(ba[DDIR_WRITE]),
1074 .help = "IO block offset alignment",
1079 .alias = "blocksize_range",
1080 .type = FIO_OPT_RANGE,
1081 .off1 = td_var_offset(min_bs[DDIR_READ]),
1082 .off2 = td_var_offset(max_bs[DDIR_READ]),
1083 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1084 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1086 .help = "Set block size range (in more detail than bs)",
1091 .type = FIO_OPT_STR,
1092 .cb = str_bssplit_cb,
1093 .help = "Set a specific mix of block sizes",
1097 .name = "bs_unaligned",
1098 .alias = "blocksize_unaligned",
1099 .type = FIO_OPT_STR_SET,
1100 .off1 = td_var_offset(bs_unaligned),
1101 .help = "Don't sector align IO buffer sizes",
1105 .name = "randrepeat",
1106 .type = FIO_OPT_BOOL,
1107 .off1 = td_var_offset(rand_repeatable),
1108 .help = "Use repeatable random IO pattern",
1113 .name = "norandommap",
1114 .type = FIO_OPT_STR_SET,
1115 .off1 = td_var_offset(norandommap),
1116 .help = "Accept potential duplicate random blocks",
1120 .name = "softrandommap",
1121 .type = FIO_OPT_BOOL,
1122 .off1 = td_var_offset(softrandommap),
1123 .help = "Set norandommap if randommap allocation fails",
1124 .parent = "norandommap",
1129 .alias = "nr_files",
1130 .type = FIO_OPT_INT,
1131 .off1 = td_var_offset(nr_files),
1132 .help = "Split job workload between this number of files",
1136 .name = "openfiles",
1137 .type = FIO_OPT_INT,
1138 .off1 = td_var_offset(open_files),
1139 .help = "Number of files to keep open at the same time",
1142 .name = "file_service_type",
1143 .type = FIO_OPT_STR,
1145 .off1 = td_var_offset(file_service_type),
1146 .help = "How to select which file to service next",
1147 .def = "roundrobin",
1150 .oval = FIO_FSERVICE_RANDOM,
1151 .help = "Choose a file at random",
1153 { .ival = "roundrobin",
1154 .oval = FIO_FSERVICE_RR,
1155 .help = "Round robin select files",
1157 { .ival = "sequential",
1158 .oval = FIO_FSERVICE_SEQ,
1159 .help = "Finish one file before moving to the next",
1162 .parent = "nrfiles",
1164 #ifdef FIO_HAVE_FALLOCATE
1166 .name = "fallocate",
1167 .type = FIO_OPT_BOOL,
1168 .off1 = td_var_offset(fallocate),
1169 .help = "Use fallocate() when laying out files",
1174 .name = "fadvise_hint",
1175 .type = FIO_OPT_BOOL,
1176 .off1 = td_var_offset(fadvise_hint),
1177 .help = "Use fadvise() to advise the kernel on IO pattern",
1182 .type = FIO_OPT_INT,
1183 .off1 = td_var_offset(fsync_blocks),
1184 .help = "Issue fsync for writes every given number of blocks",
1188 .name = "fdatasync",
1189 .type = FIO_OPT_INT,
1190 .off1 = td_var_offset(fdatasync_blocks),
1191 .help = "Issue fdatasync for writes every given number of blocks",
1195 .name = "write_barrier",
1196 .type = FIO_OPT_INT,
1197 .off1 = td_var_offset(barrier_blocks),
1198 .help = "Make every Nth write a barrier write",
1201 #ifdef FIO_HAVE_SYNC_FILE_RANGE
1203 .name = "sync_file_range",
1205 { .ival = "wait_before",
1206 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1207 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1211 .oval = SYNC_FILE_RANGE_WRITE,
1212 .help = "SYNC_FILE_RANGE_WRITE",
1216 .ival = "wait_after",
1217 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1218 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1222 .type = FIO_OPT_STR_MULTI,
1224 .off1 = td_var_offset(sync_file_range),
1225 .help = "Use sync_file_range()",
1230 .type = FIO_OPT_BOOL,
1231 .off1 = td_var_offset(odirect),
1232 .help = "Use O_DIRECT IO (negates buffered)",
1237 .type = FIO_OPT_BOOL,
1238 .off1 = td_var_offset(odirect),
1240 .help = "Use buffered IO (negates direct)",
1244 .name = "overwrite",
1245 .type = FIO_OPT_BOOL,
1246 .off1 = td_var_offset(overwrite),
1247 .help = "When writing, set whether to overwrite current data",
1252 .type = FIO_OPT_INT,
1253 .off1 = td_var_offset(loops),
1254 .help = "Number of times to run the job",
1259 .type = FIO_OPT_INT,
1260 .off1 = td_var_offset(numjobs),
1261 .help = "Duplicate this job this many times",
1265 .name = "startdelay",
1266 .type = FIO_OPT_STR_VAL_TIME,
1267 .off1 = td_var_offset(start_delay),
1268 .help = "Only start job when this period has passed",
1274 .type = FIO_OPT_STR_VAL_TIME,
1275 .off1 = td_var_offset(timeout),
1276 .help = "Stop workload when this amount of time has passed",
1280 .name = "time_based",
1281 .type = FIO_OPT_STR_SET,
1282 .off1 = td_var_offset(time_based),
1283 .help = "Keep running until runtime/timeout is met",
1286 .name = "ramp_time",
1287 .type = FIO_OPT_STR_VAL_TIME,
1288 .off1 = td_var_offset(ramp_time),
1289 .help = "Ramp up time before measuring performance",
1292 .name = "clocksource",
1293 .type = FIO_OPT_STR,
1294 .cb = fio_clock_source_cb,
1295 .off1 = td_var_offset(clocksource),
1296 .help = "What type of timing source to use",
1298 { .ival = "gettimeofday",
1300 .help = "Use gettimeofday(2) for timing",
1302 { .ival = "clock_gettime",
1303 .oval = CS_CGETTIME,
1304 .help = "Use clock_gettime(2) for timing",
1306 #ifdef ARCH_HAVE_CPU_CLOCK
1308 .oval = CS_CPUCLOCK,
1309 .help = "Use CPU private clock",
1317 .type = FIO_OPT_STR,
1319 .off1 = td_var_offset(mem_type),
1320 .help = "Backing type for IO buffers",
1325 .help = "Use malloc(3) for IO buffers",
1329 .help = "Use shared memory segments for IO buffers",
1331 #ifdef FIO_HAVE_HUGETLB
1332 { .ival = "shmhuge",
1333 .oval = MEM_SHMHUGE,
1334 .help = "Like shm, but use huge pages",
1339 .help = "Use mmap(2) (file or anon) for IO buffers",
1341 #ifdef FIO_HAVE_HUGETLB
1342 { .ival = "mmaphuge",
1343 .oval = MEM_MMAPHUGE,
1344 .help = "Like mmap, but use huge pages",
1350 .name = "iomem_align",
1351 .alias = "mem_align",
1352 .type = FIO_OPT_INT,
1353 .off1 = td_var_offset(mem_align),
1355 .help = "IO memory buffer offset alignment",
1361 .type = FIO_OPT_STR,
1362 .off1 = td_var_offset(verify),
1363 .help = "Verify data written",
1364 .cb = str_verify_cb,
1368 .oval = VERIFY_NONE,
1369 .help = "Don't do IO verification",
1373 .help = "Use md5 checksums for verification",
1376 .oval = VERIFY_CRC64,
1377 .help = "Use crc64 checksums for verification",
1380 .oval = VERIFY_CRC32,
1381 .help = "Use crc32 checksums for verification",
1383 { .ival = "crc32c-intel",
1384 .oval = VERIFY_CRC32C_INTEL,
1385 .help = "Use hw crc32c checksums for verification",
1388 .oval = VERIFY_CRC32C,
1389 .help = "Use crc32c checksums for verification",
1392 .oval = VERIFY_CRC16,
1393 .help = "Use crc16 checksums for verification",
1396 .oval = VERIFY_CRC7,
1397 .help = "Use crc7 checksums for verification",
1400 .oval = VERIFY_SHA1,
1401 .help = "Use sha1 checksums for verification",
1404 .oval = VERIFY_SHA256,
1405 .help = "Use sha256 checksums for verification",
1408 .oval = VERIFY_SHA512,
1409 .help = "Use sha512 checksums for verification",
1412 .oval = VERIFY_META,
1413 .help = "Use io information",
1417 .oval = VERIFY_NULL,
1418 .help = "Pretend to verify",
1423 .name = "do_verify",
1424 .type = FIO_OPT_BOOL,
1425 .off1 = td_var_offset(do_verify),
1426 .help = "Run verification stage after write",
1431 .name = "verifysort",
1432 .type = FIO_OPT_BOOL,
1433 .off1 = td_var_offset(verifysort),
1434 .help = "Sort written verify blocks for read back",
1439 .name = "verify_interval",
1440 .type = FIO_OPT_INT,
1441 .off1 = td_var_offset(verify_interval),
1442 .minval = 2 * sizeof(struct verify_header),
1443 .help = "Store verify buffer header every N bytes",
1447 .name = "verify_offset",
1448 .type = FIO_OPT_INT,
1449 .help = "Offset verify header location by N bytes",
1451 .cb = str_verify_offset_cb,
1455 .name = "verify_pattern",
1456 .type = FIO_OPT_STR,
1457 .cb = str_verify_pattern_cb,
1458 .help = "Fill pattern for IO buffers",
1462 .name = "verify_fatal",
1463 .type = FIO_OPT_BOOL,
1464 .off1 = td_var_offset(verify_fatal),
1466 .help = "Exit on a single verify failure, don't continue",
1470 .name = "verify_async",
1471 .type = FIO_OPT_INT,
1472 .off1 = td_var_offset(verify_async),
1474 .help = "Number of async verifier threads to use",
1478 .name = "verify_backlog",
1479 .type = FIO_OPT_STR_VAL,
1480 .off1 = td_var_offset(verify_backlog),
1481 .help = "Verify after this number of blocks are written",
1485 .name = "verify_backlog_batch",
1486 .type = FIO_OPT_INT,
1487 .off1 = td_var_offset(verify_batch),
1488 .help = "Verify this number of IO blocks",
1491 #ifdef FIO_HAVE_CPU_AFFINITY
1493 .name = "verify_async_cpus",
1494 .type = FIO_OPT_STR,
1495 .cb = str_verify_cpus_allowed_cb,
1496 .help = "Set CPUs allowed for async verify threads",
1497 .parent = "verify_async",
1500 #ifdef FIO_HAVE_TRIM
1502 .name = "trim_percentage",
1503 .type = FIO_OPT_INT,
1504 .cb = str_verify_trim_cb,
1506 .help = "Number of verify blocks to discard/trim",
1511 .name = "trim_verify_zero",
1512 .type = FIO_OPT_INT,
1513 .help = "Verify that trim/discarded blocks are returned as zeroes",
1514 .off1 = td_var_offset(trim_zero),
1515 .parent = "trim_percentage",
1519 .name = "trim_backlog",
1520 .type = FIO_OPT_STR_VAL,
1521 .off1 = td_var_offset(trim_backlog),
1522 .help = "Trim after this number of blocks are written",
1523 .parent = "trim_percentage",
1526 .name = "trim_backlog_batch",
1527 .type = FIO_OPT_INT,
1528 .off1 = td_var_offset(trim_batch),
1529 .help = "Trim this number of IO blocks",
1530 .parent = "trim_percentage",
1534 .name = "write_iolog",
1535 .type = FIO_OPT_STR_STORE,
1536 .off1 = td_var_offset(write_iolog_file),
1537 .help = "Store IO pattern to file",
1540 .name = "read_iolog",
1541 .type = FIO_OPT_STR_STORE,
1542 .off1 = td_var_offset(read_iolog_file),
1543 .help = "Playback IO pattern from file",
1546 .name = "replay_no_stall",
1547 .type = FIO_OPT_INT,
1548 .off1 = td_var_offset(no_stall),
1550 .parent = "read_iolog",
1551 .help = "Playback IO pattern file as fast as possible without stalls",
1554 .name = "replay_redirect",
1555 .type = FIO_OPT_STR_STORE,
1556 .off1 = td_var_offset(replay_redirect),
1557 .parent = "read_iolog",
1558 .help = "Replay all I/O onto this device, regardless of trace device",
1561 .name = "exec_prerun",
1562 .type = FIO_OPT_STR_STORE,
1563 .off1 = td_var_offset(exec_prerun),
1564 .help = "Execute this file prior to running job",
1567 .name = "exec_postrun",
1568 .type = FIO_OPT_STR_STORE,
1569 .off1 = td_var_offset(exec_postrun),
1570 .help = "Execute this file after running job",
1572 #ifdef FIO_HAVE_IOSCHED_SWITCH
1574 .name = "ioscheduler",
1575 .type = FIO_OPT_STR_STORE,
1576 .off1 = td_var_offset(ioscheduler),
1577 .help = "Use this IO scheduler on the backing device",
1582 .type = FIO_OPT_STR_VAL,
1583 .off1 = td_var_offset(zone_size),
1584 .help = "Give size of an IO zone",
1589 .type = FIO_OPT_STR_VAL,
1590 .off1 = td_var_offset(zone_skip),
1591 .help = "Space between IO zones",
1596 .type = FIO_OPT_STR_VAL,
1597 .cb = str_lockmem_cb,
1598 .help = "Lock down this amount of memory",
1602 .name = "rwmixread",
1603 .type = FIO_OPT_INT,
1604 .cb = str_rwmix_read_cb,
1606 .help = "Percentage of mixed workload that is reads",
1610 .name = "rwmixwrite",
1611 .type = FIO_OPT_INT,
1612 .cb = str_rwmix_write_cb,
1614 .help = "Percentage of mixed workload that is writes",
1618 .name = "rwmixcycle",
1619 .type = FIO_OPT_DEPRECATED,
1623 .type = FIO_OPT_INT,
1624 .off1 = td_var_offset(nice),
1625 .help = "Set job CPU nice value",
1630 #ifdef FIO_HAVE_IOPRIO
1633 .type = FIO_OPT_INT,
1635 .help = "Set job IO priority value",
1640 .name = "prioclass",
1641 .type = FIO_OPT_INT,
1642 .cb = str_prioclass_cb,
1643 .help = "Set job IO priority class",
1649 .name = "thinktime",
1650 .type = FIO_OPT_INT,
1651 .off1 = td_var_offset(thinktime),
1652 .help = "Idle time between IO buffers (usec)",
1656 .name = "thinktime_spin",
1657 .type = FIO_OPT_INT,
1658 .off1 = td_var_offset(thinktime_spin),
1659 .help = "Start think time by spinning this amount (usec)",
1661 .parent = "thinktime",
1664 .name = "thinktime_blocks",
1665 .type = FIO_OPT_INT,
1666 .off1 = td_var_offset(thinktime_blocks),
1667 .help = "IO buffer period between 'thinktime'",
1669 .parent = "thinktime",
1673 .type = FIO_OPT_INT,
1674 .off1 = td_var_offset(rate[0]),
1675 .off2 = td_var_offset(rate[1]),
1676 .help = "Set bandwidth rate",
1680 .type = FIO_OPT_INT,
1681 .off1 = td_var_offset(ratemin[0]),
1682 .off2 = td_var_offset(ratemin[1]),
1683 .help = "Job must meet this rate or it will be shutdown",
1687 .name = "rate_iops",
1688 .type = FIO_OPT_INT,
1689 .off1 = td_var_offset(rate_iops[0]),
1690 .off2 = td_var_offset(rate_iops[1]),
1691 .help = "Limit IO used to this number of IO operations/sec",
1694 .name = "rate_iops_min",
1695 .type = FIO_OPT_INT,
1696 .off1 = td_var_offset(rate_iops_min[0]),
1697 .off2 = td_var_offset(rate_iops_min[1]),
1698 .help = "Job must meet this rate or it will be shut down",
1699 .parent = "rate_iops",
1702 .name = "ratecycle",
1703 .type = FIO_OPT_INT,
1704 .off1 = td_var_offset(ratecycle),
1705 .help = "Window average for rate limits (msec)",
1710 .name = "invalidate",
1711 .type = FIO_OPT_BOOL,
1712 .off1 = td_var_offset(invalidate_cache),
1713 .help = "Invalidate buffer/page cache prior to running job",
1718 .type = FIO_OPT_BOOL,
1719 .off1 = td_var_offset(sync_io),
1720 .help = "Use O_SYNC for buffered writes",
1722 .parent = "buffered",
1725 .name = "bwavgtime",
1726 .type = FIO_OPT_INT,
1727 .off1 = td_var_offset(bw_avg_time),
1728 .help = "Time window over which to calculate bandwidth"
1733 .name = "create_serialize",
1734 .type = FIO_OPT_BOOL,
1735 .off1 = td_var_offset(create_serialize),
1736 .help = "Serialize creating of job files",
1740 .name = "create_fsync",
1741 .type = FIO_OPT_BOOL,
1742 .off1 = td_var_offset(create_fsync),
1743 .help = "fsync file after creation",
1747 .name = "create_on_open",
1748 .type = FIO_OPT_BOOL,
1749 .off1 = td_var_offset(create_on_open),
1750 .help = "Create files when they are opened for IO",
1755 .type = FIO_OPT_BOOL,
1756 .off1 = td_var_offset(pre_read),
1757 .help = "Pre-read files before starting official testing",
1762 .type = FIO_OPT_INT,
1763 .off1 = td_var_offset(cpuload),
1764 .help = "Use this percentage of CPU",
1767 .name = "cpuchunks",
1768 .type = FIO_OPT_INT,
1769 .off1 = td_var_offset(cpucycle),
1770 .help = "Length of the CPU burn cycles (usecs)",
1772 .parent = "cpuload",
1774 #ifdef FIO_HAVE_CPU_AFFINITY
1777 .type = FIO_OPT_INT,
1778 .cb = str_cpumask_cb,
1779 .help = "CPU affinity mask",
1782 .name = "cpus_allowed",
1783 .type = FIO_OPT_STR,
1784 .cb = str_cpus_allowed_cb,
1785 .help = "Set CPUs allowed",
1789 .name = "end_fsync",
1790 .type = FIO_OPT_BOOL,
1791 .off1 = td_var_offset(end_fsync),
1792 .help = "Include fsync at the end of job",
1796 .name = "fsync_on_close",
1797 .type = FIO_OPT_BOOL,
1798 .off1 = td_var_offset(fsync_on_close),
1799 .help = "fsync files on close",
1804 .type = FIO_OPT_BOOL,
1805 .off1 = td_var_offset(unlink),
1806 .help = "Unlink created files after job has completed",
1811 .type = FIO_OPT_STR_SET,
1812 .cb = str_exitall_cb,
1813 .help = "Terminate all jobs when one exits",
1816 .name = "stonewall",
1817 .type = FIO_OPT_STR_SET,
1818 .off1 = td_var_offset(stonewall),
1819 .help = "Insert a hard barrier between this job and previous",
1822 .name = "new_group",
1823 .type = FIO_OPT_STR_SET,
1824 .off1 = td_var_offset(new_group),
1825 .help = "Mark the start of a new group (for reporting)",
1829 .type = FIO_OPT_STR_SET,
1830 .off1 = td_var_offset(use_thread),
1831 .help = "Use threads instead of forks",
1834 .name = "write_bw_log",
1835 .type = FIO_OPT_STR,
1836 .off1 = td_var_offset(write_bw_log),
1837 .cb = str_write_bw_log_cb,
1838 .help = "Write log of bandwidth during run",
1841 .name = "write_lat_log",
1842 .type = FIO_OPT_STR,
1843 .off1 = td_var_offset(write_lat_log),
1844 .cb = str_write_lat_log_cb,
1845 .help = "Write log of latency during run",
1848 .name = "hugepage-size",
1849 .type = FIO_OPT_INT,
1850 .off1 = td_var_offset(hugepage_size),
1851 .help = "When using hugepages, specify size of each page",
1852 .def = __stringify(FIO_HUGE_PAGE),
1855 .name = "group_reporting",
1856 .type = FIO_OPT_STR_SET,
1857 .off1 = td_var_offset(group_reporting),
1858 .help = "Do reporting on a per-group basis",
1861 .name = "zero_buffers",
1862 .type = FIO_OPT_STR_SET,
1863 .off1 = td_var_offset(zero_buffers),
1864 .help = "Init IO buffers to all zeroes",
1867 .name = "refill_buffers",
1868 .type = FIO_OPT_STR_SET,
1869 .off1 = td_var_offset(refill_buffers),
1870 .help = "Refill IO buffers on every IO submit",
1872 #ifdef FIO_HAVE_DISK_UTIL
1874 .name = "disk_util",
1875 .type = FIO_OPT_BOOL,
1876 .off1 = td_var_offset(do_disk_util),
1877 .help = "Log disk utilization statistics",
1882 .name = "gtod_reduce",
1883 .type = FIO_OPT_BOOL,
1884 .help = "Greatly reduce number of gettimeofday() calls",
1885 .cb = str_gtod_reduce_cb,
1889 .name = "disable_lat",
1890 .type = FIO_OPT_BOOL,
1891 .off1 = td_var_offset(disable_lat),
1892 .help = "Disable latency numbers",
1893 .parent = "gtod_reduce",
1897 .name = "disable_clat",
1898 .type = FIO_OPT_BOOL,
1899 .off1 = td_var_offset(disable_clat),
1900 .help = "Disable completion latency numbers",
1901 .parent = "gtod_reduce",
1905 .name = "disable_slat",
1906 .type = FIO_OPT_BOOL,
1907 .off1 = td_var_offset(disable_slat),
1908 .help = "Disable submission latency numbers",
1909 .parent = "gtod_reduce",
1913 .name = "disable_bw_measurement",
1914 .type = FIO_OPT_BOOL,
1915 .off1 = td_var_offset(disable_bw),
1916 .help = "Disable bandwidth logging",
1917 .parent = "gtod_reduce",
1922 .type = FIO_OPT_INT,
1923 .cb = str_gtod_cpu_cb,
1924 .help = "Set up dedicated gettimeofday() thread on this CPU",
1925 .verify = gtod_cpu_verify,
1928 .name = "continue_on_error",
1929 .type = FIO_OPT_BOOL,
1930 .off1 = td_var_offset(continue_on_error),
1931 .help = "Continue on non-fatal errors during IO",
1936 .type = FIO_OPT_STR_STORE,
1937 .off1 = td_var_offset(profile),
1938 .help = "Select a specific builtin performance test",
1942 .type = FIO_OPT_STR_STORE,
1943 .off1 = td_var_offset(cgroup),
1944 .help = "Add job to cgroup of this name",
1947 .name = "cgroup_weight",
1948 .type = FIO_OPT_INT,
1949 .off1 = td_var_offset(cgroup_weight),
1950 .help = "Use given weight for cgroup",
1955 .name = "cgroup_nodelete",
1956 .type = FIO_OPT_BOOL,
1957 .off1 = td_var_offset(cgroup_nodelete),
1958 .help = "Do not delete cgroups after job completion",
1963 .type = FIO_OPT_INT,
1964 .off1 = td_var_offset(uid),
1965 .help = "Run job with this user ID",
1969 .type = FIO_OPT_INT,
1970 .off1 = td_var_offset(gid),
1971 .help = "Run job with this group ID",
1978 static void add_to_lopt(struct option *lopt, struct fio_option *o,
1981 lopt->name = (char *) name;
1982 lopt->val = FIO_GETOPT_JOB;
1983 if (o->type == FIO_OPT_STR_SET)
1984 lopt->has_arg = no_argument;
1986 lopt->has_arg = required_argument;
1989 void fio_options_dup_and_init(struct option *long_options)
1991 struct fio_option *o;
1994 options_init(options);
1997 while (long_options[i].name)
2002 add_to_lopt(&long_options[i], o, o->name);
2005 add_to_lopt(&long_options[i], o, o->alias);
2010 assert(i < FIO_NR_OPTIONS);
2014 struct fio_keyword {
2020 static struct fio_keyword fio_keywords[] = {
2022 .word = "$pagesize",
2023 .desc = "Page size in the system",
2026 .word = "$mb_memory",
2027 .desc = "Megabytes of memory online",
2031 .desc = "Number of CPUs online in the system",
2038 void fio_keywords_init(void)
2040 unsigned long long mb_memory;
2044 sprintf(buf, "%lu", page_size);
2045 fio_keywords[0].replace = strdup(buf);
2047 mb_memory = os_phys_mem() / page_size;
2048 sprintf(buf, "%llu", mb_memory);
2049 fio_keywords[1].replace = strdup(buf);
2051 l = sysconf(_SC_NPROCESSORS_ONLN);
2052 sprintf(buf, "%lu", l);
2053 fio_keywords[2].replace = strdup(buf);
2058 static char *bc_calc(char *str)
2060 char *buf, *tmp, opt[80];
2065 * No math, just return string
2067 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2072 * Split option from value, we only need to calculate the value
2074 tmp = strchr(str, '=');
2079 memset(opt, 0, sizeof(opt));
2080 strncpy(opt, str, tmp - str);
2084 sprintf(buf, "which %s > /dev/null", BC_APP);
2086 log_err("fio: bc is needed for performing math\n");
2091 sprintf(buf, "echo %s | %s", tmp, BC_APP);
2092 f = popen(buf, "r");
2098 ret = fread(buf, 1, 128, f);
2104 buf[ret - 1] = '\0';
2113 * Look for reserved variable names and replace them with real values
2115 static char *fio_keyword_replace(char *opt)
2120 for (i = 0; fio_keywords[i].word != NULL; i++) {
2121 struct fio_keyword *kw = &fio_keywords[i];
2123 while ((s = strstr(opt, kw->word)) != NULL) {
2124 char *new = malloc(strlen(opt) + 1);
2130 * Copy part of the string before the keyword and
2131 * sprintf() the replacement after it.
2133 memcpy(new, opt, olen);
2134 len = sprintf(new + olen, "%s", kw->replace);
2137 * If there's more in the original string, copy that
2140 opt += strlen(kw->word) + olen;
2142 memcpy(new + olen + len, opt, opt - o_org - 1);
2145 * replace opt and free the old opt
2151 * Check for potential math and invoke bc, if possible
2160 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2164 sort_options(opts, options, num_opts);
2166 for (ret = 0, i = 0; i < num_opts; i++) {
2167 opts[i] = fio_keyword_replace(opts[i]);
2168 ret |= parse_option(opts[i], options, td);
2174 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2176 return parse_cmd_option(opt, val, options, td);
2179 void fio_fill_default_options(struct thread_data *td)
2181 fill_default_options(td, options);
2184 int fio_show_option_help(const char *opt)
2186 return show_cmd_help(options, opt);
2189 static void __options_mem(struct thread_data *td, int alloc)
2191 struct thread_options *o = &td->o;
2192 struct fio_option *opt;
2196 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2197 if (opt->type != FIO_OPT_STR_STORE)
2200 ptr = (void *) o + opt->off1;
2203 *ptr = strdup(*ptr);
2213 * dupe FIO_OPT_STR_STORE options
2215 void options_mem_dupe(struct thread_data *td)
2217 __options_mem(td, 1);
2220 void options_mem_free(struct thread_data fio_unused *td)
2223 __options_mem(td, 0);
2227 unsigned int fio_get_kb_base(void *data)
2229 struct thread_data *td = data;
2230 unsigned int kb_base = 0;
2233 kb_base = td->o.kb_base;
2240 int add_option(struct fio_option *o)
2242 struct fio_option *__o;
2251 memcpy(&options[opt_index], o, sizeof(*o));
2255 void invalidate_profile_options(const char *prof_name)
2257 struct fio_option *o;
2261 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2262 o->type = FIO_OPT_INVALID;
2263 o->prof_name = NULL;
2269 void add_opt_posval(const char *optname, const char *ival, const char *help)
2271 struct fio_option *o;
2274 o = find_option(options, optname);
2278 for (i = 0; i < PARSE_MAX_VP; i++) {
2279 if (o->posval[i].ival)
2282 o->posval[i].ival = ival;
2283 o->posval[i].help = help;
2288 void del_opt_posval(const char *optname, const char *ival)
2290 struct fio_option *o;
2293 o = find_option(options, optname);
2297 for (i = 0; i < PARSE_MAX_VP; i++) {
2298 if (!o->posval[i].ival)
2300 if (strcmp(o->posval[i].ival, ival))
2303 o->posval[i].ival = NULL;
2304 o->posval[i].help = NULL;