10 #include <sys/types.h>
19 static FLIST_HEAD(ext_opt_list);
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_lockmem_cb(void fio_unused *data, unsigned long *val)
236 static int str_rwmix_read_cb(void *data, unsigned int *val)
238 struct thread_data *td = data;
240 td->o.rwmix[DDIR_READ] = *val;
241 td->o.rwmix[DDIR_WRITE] = 100 - *val;
245 static int str_rwmix_write_cb(void *data, unsigned int *val)
247 struct thread_data *td = data;
249 td->o.rwmix[DDIR_WRITE] = *val;
250 td->o.rwmix[DDIR_READ] = 100 - *val;
254 #ifdef FIO_HAVE_IOPRIO
255 static int str_prioclass_cb(void *data, unsigned int *val)
257 struct thread_data *td = data;
261 * mask off old class bits, str_prio_cb() may have set a default class
263 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
266 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
271 static int str_prio_cb(void *data, unsigned int *val)
273 struct thread_data *td = data;
278 * If no class is set, assume BE
280 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
281 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
288 static int str_exitall_cb(void)
290 exitall_on_terminate = 1;
294 #ifdef FIO_HAVE_CPU_AFFINITY
295 static int str_cpumask_cb(void *data, unsigned int *val)
297 struct thread_data *td = data;
302 ret = fio_cpuset_init(&td->o.cpumask);
304 log_err("fio: cpuset_init failed\n");
305 td_verror(td, ret, "fio_cpuset_init");
309 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
311 for (i = 0; i < sizeof(int) * 8; i++) {
312 if ((1 << i) & *val) {
314 log_err("fio: CPU %d too large (max=%ld)\n", i,
318 dprint(FD_PARSE, "set cpu allowed %d\n", i);
319 fio_cpu_set(&td->o.cpumask, i);
323 td->o.cpumask_set = 1;
327 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
334 ret = fio_cpuset_init(mask);
336 log_err("fio: cpuset_init failed\n");
337 td_verror(td, ret, "fio_cpuset_init");
341 p = str = strdup(input);
343 strip_blank_front(&str);
344 strip_blank_end(str);
346 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
348 while ((cpu = strsep(&str, ",")) != NULL) {
357 while ((cpu2 = strsep(&str2, "-")) != NULL) {
367 while (icpu <= icpu2) {
368 if (icpu >= FIO_MAX_CPUS) {
369 log_err("fio: your OS only supports up to"
370 " %d CPUs\n", (int) FIO_MAX_CPUS);
374 if (icpu > max_cpu) {
375 log_err("fio: CPU %d too large (max=%ld)\n",
381 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
382 fio_cpu_set(mask, icpu);
391 td->o.cpumask_set = 1;
395 static int str_cpus_allowed_cb(void *data, const char *input)
397 struct thread_data *td = data;
400 ret = set_cpus_allowed(td, &td->o.cpumask, input);
402 td->o.cpumask_set = 1;
407 static int str_verify_cpus_allowed_cb(void *data, const char *input)
409 struct thread_data *td = data;
412 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
414 td->o.verify_cpumask_set = 1;
420 static int str_fst_cb(void *data, const char *str)
422 struct thread_data *td = data;
423 char *nr = get_opt_postfix(str);
425 td->file_service_nr = 1;
427 td->file_service_nr = atoi(nr);
434 static int check_dir(struct thread_data *td, char *fname)
436 char file[PATH_MAX], *dir;
439 if (td->o.directory) {
440 strcpy(file, td->o.directory);
445 sprintf(file + elen, "%s", fname);
452 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
453 * yet, so we can't do this check right here...
455 if (lstat(dir, &sb) < 0) {
458 log_err("fio: %s is not a directory\n", dir);
459 td_verror(td, ret, "lstat");
463 if (!S_ISDIR(sb.st_mode)) {
464 log_err("fio: %s is not a directory\n", dir);
474 * Return next file in the string. Files are separated with ':'. If the ':'
475 * is escaped with a '\', then that ':' is part of the filename and does not
476 * indicate a new file.
478 static char *get_next_file_name(char **ptr)
483 if (!str || !strlen(str))
489 * No colon, we are done
491 p = strchr(str, ':');
498 * We got a colon, but it's the first character. Skip and
506 if (*(p - 1) != '\\') {
512 memmove(p - 1, p, strlen(p) + 1);
519 static int str_filename_cb(void *data, const char *input)
521 struct thread_data *td = data;
522 char *fname, *str, *p;
524 p = str = strdup(input);
526 strip_blank_front(&str);
527 strip_blank_end(str);
529 if (!td->files_index)
532 while ((fname = get_next_file_name(&str)) != NULL) {
535 if (check_dir(td, fname)) {
547 static int str_directory_cb(void *data, const char fio_unused *str)
549 struct thread_data *td = data;
552 if (lstat(td->o.directory, &sb) < 0) {
555 log_err("fio: %s is not a directory\n", td->o.directory);
556 td_verror(td, ret, "lstat");
559 if (!S_ISDIR(sb.st_mode)) {
560 log_err("fio: %s is not a directory\n", td->o.directory);
567 static int str_opendir_cb(void *data, const char fio_unused *str)
569 struct thread_data *td = data;
571 if (!td->files_index)
574 return add_dir_files(td, td->o.opendir);
577 static int str_verify_offset_cb(void *data, unsigned int *off)
579 struct thread_data *td = data;
581 if (*off && *off < sizeof(struct verify_header)) {
582 log_err("fio: verify_offset too small\n");
586 td->o.verify_offset = *off;
590 static int str_verify_pattern_cb(void *data, const char *input)
592 struct thread_data *td = data;
594 int i = 0, j = 0, len, k, base = 10;
597 loc1 = strstr(input, "0x");
598 loc2 = strstr(input, "0X");
601 off = strtol(input, NULL, base);
602 if (off != LONG_MAX || errno != ERANGE) {
604 td->o.verify_pattern[i] = off & 0xff;
613 j = loc1 - input + 2;
615 j = loc2 - input + 2;
618 if (len - j < MAX_PATTERN_SIZE * 2) {
620 off = converthexchartoint(input[k--]);
622 off += (converthexchartoint(input[k--])
624 td->o.verify_pattern[i++] = (char) off;
628 td->o.verify_pattern_bytes = i;
632 static int str_lockfile_cb(void *data, const char *str)
634 struct thread_data *td = data;
635 char *nr = get_opt_postfix(str);
637 td->o.lockfile_batch = 1;
639 td->o.lockfile_batch = atoi(nr);
646 static int str_write_bw_log_cb(void *data, const char *str)
648 struct thread_data *td = data;
651 td->o.bw_log_file = strdup(str);
653 td->o.write_bw_log = 1;
657 static int str_write_lat_log_cb(void *data, const char *str)
659 struct thread_data *td = data;
662 td->o.lat_log_file = strdup(str);
664 td->o.write_lat_log = 1;
668 static int str_gtod_reduce_cb(void *data, int *il)
670 struct thread_data *td = data;
673 td->o.disable_clat = !!val;
674 td->o.disable_slat = !!val;
675 td->o.disable_bw = !!val;
677 td->tv_cache_mask = 63;
682 static int str_gtod_cpu_cb(void *data, int *il)
684 struct thread_data *td = data;
687 td->o.gtod_cpu = val;
688 td->o.gtod_offload = 1;
692 static int rw_verify(struct fio_option *o, void *data)
694 struct thread_data *td = data;
696 if (read_only && td_write(td)) {
697 log_err("fio: job <%s> has write bit set, but fio is in"
698 " read-only mode\n", td->o.name);
705 static int gtod_cpu_verify(struct fio_option *o, void *data)
707 #ifndef FIO_HAVE_CPU_AFFINITY
708 struct thread_data *td = data;
710 if (td->o.gtod_cpu) {
711 log_err("fio: platform must support CPU affinity for"
712 "gettimeofday() offloading\n");
720 static int kb_base_verify(struct fio_option *o, void *data)
722 struct thread_data *td = data;
724 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
725 log_err("fio: kb_base set to nonsensical value: %u\n",
733 #define __stringify_1(x) #x
734 #define __stringify(x) __stringify_1(x)
737 * Map of job/command line options
739 static struct fio_option options[] = {
741 .name = "description",
742 .type = FIO_OPT_STR_STORE,
743 .off1 = td_var_offset(description),
744 .help = "Text job description",
748 .type = FIO_OPT_STR_STORE,
749 .off1 = td_var_offset(name),
750 .help = "Name of this job",
754 .type = FIO_OPT_STR_STORE,
755 .off1 = td_var_offset(directory),
756 .cb = str_directory_cb,
757 .help = "Directory to store files in",
761 .type = FIO_OPT_STR_STORE,
762 .off1 = td_var_offset(filename),
763 .cb = str_filename_cb,
764 .prio = -1, /* must come after "directory" */
765 .help = "File(s) to use for the workload",
770 .off1 = td_var_offset(kb_base),
771 .verify = kb_base_verify,
774 .help = "How many bytes per KB for reporting (1000 or 1024)",
779 .cb = str_lockfile_cb,
780 .off1 = td_var_offset(file_lock_mode),
781 .help = "Lock file when doing IO to it",
782 .parent = "filename",
786 .oval = FILE_LOCK_NONE,
787 .help = "No file locking",
789 { .ival = "exclusive",
790 .oval = FILE_LOCK_EXCLUSIVE,
791 .help = "Exclusive file lock",
795 .oval = FILE_LOCK_READWRITE,
796 .help = "Read vs write lock",
802 .type = FIO_OPT_STR_STORE,
803 .off1 = td_var_offset(opendir),
804 .cb = str_opendir_cb,
805 .help = "Recursively add files from this directory and down",
809 .alias = "readwrite",
812 .off1 = td_var_offset(td_ddir),
813 .help = "IO direction",
818 .oval = TD_DDIR_READ,
819 .help = "Sequential read",
822 .oval = TD_DDIR_WRITE,
823 .help = "Sequential write",
825 { .ival = "randread",
826 .oval = TD_DDIR_RANDREAD,
827 .help = "Random read",
829 { .ival = "randwrite",
830 .oval = TD_DDIR_RANDWRITE,
831 .help = "Random write",
835 .help = "Sequential read and write mix",
838 .oval = TD_DDIR_RANDRW,
839 .help = "Random read and write mix"
845 .type = FIO_OPT_STR_STORE,
846 .off1 = td_var_offset(ioengine),
847 .help = "IO engine to use",
851 .help = "Use read/write",
854 .help = "Use pread/pwrite",
857 .help = "Use readv/writev",
859 #ifdef FIO_HAVE_LIBAIO
861 .help = "Linux native asynchronous IO",
864 #ifdef FIO_HAVE_POSIXAIO
865 { .ival = "posixaio",
866 .help = "POSIX asynchronous IO",
869 #ifdef FIO_HAVE_SOLARISAIO
870 { .ival = "solarisaio",
871 .help = "Solaris native asynchronous IO",
875 .help = "Memory mapped IO",
877 #ifdef FIO_HAVE_SPLICE
879 .help = "splice/vmsplice based IO",
881 { .ival = "netsplice",
882 .help = "splice/vmsplice to/from the network",
887 .help = "SCSI generic v3 IO",
891 .help = "Testing engine (no data transfer)",
894 .help = "Network IO",
896 #ifdef FIO_HAVE_SYSLET
897 { .ival = "syslet-rw",
898 .help = "syslet enabled async pread/pwrite IO",
902 .help = "CPU cycler burner engine",
904 #ifdef FIO_HAVE_GUASI
906 .help = "GUASI IO engine",
909 { .ival = "external",
910 .help = "Load external engine (append name)",
917 .off1 = td_var_offset(iodepth),
918 .help = "Amount of IO buffers to keep in flight",
923 .name = "iodepth_batch",
924 .alias = "iodepth_batch_submit",
926 .off1 = td_var_offset(iodepth_batch),
927 .help = "Number of IO buffers to submit in one go",
933 .name = "iodepth_batch_complete",
935 .off1 = td_var_offset(iodepth_batch_complete),
936 .help = "Number of IO buffers to retrieve in one go",
942 .name = "iodepth_low",
944 .off1 = td_var_offset(iodepth_low),
945 .help = "Low water mark for queuing depth",
950 .type = FIO_OPT_STR_VAL,
951 .off1 = td_var_offset(size),
953 .help = "Total size of device or files",
956 .name = "fill_device",
957 .type = FIO_OPT_BOOL,
958 .off1 = td_var_offset(fill_device),
959 .help = "Write until an ENOSPC error occurs",
964 .type = FIO_OPT_STR_VAL,
965 .off1 = td_var_offset(file_size_low),
966 .off2 = td_var_offset(file_size_high),
968 .help = "Size of individual files",
972 .alias = "fileoffset",
973 .type = FIO_OPT_STR_VAL,
974 .off1 = td_var_offset(start_offset),
975 .help = "Start IO from this offset",
980 .alias = "blocksize",
982 .off1 = td_var_offset(bs[DDIR_READ]),
983 .off2 = td_var_offset(bs[DDIR_WRITE]),
985 .help = "Block size unit",
991 .alias = "blockalign",
993 .off1 = td_var_offset(ba[DDIR_READ]),
994 .off2 = td_var_offset(ba[DDIR_WRITE]),
996 .help = "IO block offset alignment",
1001 .alias = "blocksize_range",
1002 .type = FIO_OPT_RANGE,
1003 .off1 = td_var_offset(min_bs[DDIR_READ]),
1004 .off2 = td_var_offset(max_bs[DDIR_READ]),
1005 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1006 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1008 .help = "Set block size range (in more detail than bs)",
1013 .type = FIO_OPT_STR,
1014 .cb = str_bssplit_cb,
1015 .help = "Set a specific mix of block sizes",
1019 .name = "bs_unaligned",
1020 .alias = "blocksize_unaligned",
1021 .type = FIO_OPT_STR_SET,
1022 .off1 = td_var_offset(bs_unaligned),
1023 .help = "Don't sector align IO buffer sizes",
1027 .name = "randrepeat",
1028 .type = FIO_OPT_BOOL,
1029 .off1 = td_var_offset(rand_repeatable),
1030 .help = "Use repeatable random IO pattern",
1035 .name = "norandommap",
1036 .type = FIO_OPT_STR_SET,
1037 .off1 = td_var_offset(norandommap),
1038 .help = "Accept potential duplicate random blocks",
1042 .name = "softrandommap",
1043 .type = FIO_OPT_BOOL,
1044 .off1 = td_var_offset(softrandommap),
1045 .help = "Set norandommap if randommap allocation fails",
1046 .parent = "norandommap",
1051 .type = FIO_OPT_INT,
1052 .off1 = td_var_offset(nr_files),
1053 .help = "Split job workload between this number of files",
1057 .name = "openfiles",
1058 .type = FIO_OPT_INT,
1059 .off1 = td_var_offset(open_files),
1060 .help = "Number of files to keep open at the same time",
1063 .name = "file_service_type",
1064 .type = FIO_OPT_STR,
1066 .off1 = td_var_offset(file_service_type),
1067 .help = "How to select which file to service next",
1068 .def = "roundrobin",
1071 .oval = FIO_FSERVICE_RANDOM,
1072 .help = "Choose a file at random",
1074 { .ival = "roundrobin",
1075 .oval = FIO_FSERVICE_RR,
1076 .help = "Round robin select files",
1078 { .ival = "sequential",
1079 .oval = FIO_FSERVICE_SEQ,
1080 .help = "Finish one file before moving to the next",
1083 .parent = "nrfiles",
1085 #ifdef FIO_HAVE_FALLOCATE
1087 .name = "fallocate",
1088 .type = FIO_OPT_BOOL,
1089 .off1 = td_var_offset(fallocate),
1090 .help = "Use fallocate() when laying out files",
1095 .name = "fadvise_hint",
1096 .type = FIO_OPT_BOOL,
1097 .off1 = td_var_offset(fadvise_hint),
1098 .help = "Use fadvise() to advise the kernel on IO pattern",
1103 .type = FIO_OPT_INT,
1104 .off1 = td_var_offset(fsync_blocks),
1105 .help = "Issue fsync for writes every given number of blocks",
1109 .name = "fdatasync",
1110 .type = FIO_OPT_INT,
1111 .off1 = td_var_offset(fdatasync_blocks),
1112 .help = "Issue fdatasync for writes every given number of blocks",
1117 .type = FIO_OPT_BOOL,
1118 .off1 = td_var_offset(odirect),
1119 .help = "Use O_DIRECT IO (negates buffered)",
1124 .type = FIO_OPT_BOOL,
1125 .off1 = td_var_offset(odirect),
1127 .help = "Use buffered IO (negates direct)",
1131 .name = "overwrite",
1132 .type = FIO_OPT_BOOL,
1133 .off1 = td_var_offset(overwrite),
1134 .help = "When writing, set whether to overwrite current data",
1139 .type = FIO_OPT_INT,
1140 .off1 = td_var_offset(loops),
1141 .help = "Number of times to run the job",
1146 .type = FIO_OPT_INT,
1147 .off1 = td_var_offset(numjobs),
1148 .help = "Duplicate this job this many times",
1152 .name = "startdelay",
1153 .type = FIO_OPT_INT,
1154 .off1 = td_var_offset(start_delay),
1155 .help = "Only start job when this period has passed",
1161 .type = FIO_OPT_STR_VAL_TIME,
1162 .off1 = td_var_offset(timeout),
1163 .help = "Stop workload when this amount of time has passed",
1167 .name = "time_based",
1168 .type = FIO_OPT_STR_SET,
1169 .off1 = td_var_offset(time_based),
1170 .help = "Keep running until runtime/timeout is met",
1173 .name = "ramp_time",
1174 .type = FIO_OPT_STR_VAL_TIME,
1175 .off1 = td_var_offset(ramp_time),
1176 .help = "Ramp up time before measuring performance",
1181 .type = FIO_OPT_STR,
1183 .off1 = td_var_offset(mem_type),
1184 .help = "Backing type for IO buffers",
1189 .help = "Use malloc(3) for IO buffers",
1193 .help = "Use shared memory segments for IO buffers",
1195 #ifdef FIO_HAVE_HUGETLB
1196 { .ival = "shmhuge",
1197 .oval = MEM_SHMHUGE,
1198 .help = "Like shm, but use huge pages",
1203 .help = "Use mmap(2) (file or anon) for IO buffers",
1205 #ifdef FIO_HAVE_HUGETLB
1206 { .ival = "mmaphuge",
1207 .oval = MEM_MMAPHUGE,
1208 .help = "Like mmap, but use huge pages",
1214 .name = "iomem_align",
1215 .alias = "mem_align",
1216 .type = FIO_OPT_INT,
1217 .off1 = td_var_offset(mem_align),
1219 .help = "IO memory buffer offset alignment",
1225 .type = FIO_OPT_STR,
1226 .off1 = td_var_offset(verify),
1227 .help = "Verify data written",
1231 .oval = VERIFY_NONE,
1232 .help = "Don't do IO verification",
1236 .help = "Use md5 checksums for verification",
1239 .oval = VERIFY_CRC64,
1240 .help = "Use crc64 checksums for verification",
1243 .oval = VERIFY_CRC32,
1244 .help = "Use crc32 checksums for verification",
1246 { .ival = "crc32c-intel",
1247 .oval = VERIFY_CRC32C_INTEL,
1248 .help = "Use hw crc32c checksums for verification",
1251 .oval = VERIFY_CRC32C,
1252 .help = "Use crc32c checksums for verification",
1255 .oval = VERIFY_CRC16,
1256 .help = "Use crc16 checksums for verification",
1259 .oval = VERIFY_CRC7,
1260 .help = "Use crc7 checksums for verification",
1263 .oval = VERIFY_SHA1,
1264 .help = "Use sha1 checksums for verification",
1267 .oval = VERIFY_SHA256,
1268 .help = "Use sha256 checksums for verification",
1271 .oval = VERIFY_SHA512,
1272 .help = "Use sha512 checksums for verification",
1275 .oval = VERIFY_META,
1276 .help = "Use io information",
1280 .oval = VERIFY_NULL,
1281 .help = "Pretend to verify",
1286 .name = "do_verify",
1287 .type = FIO_OPT_BOOL,
1288 .off1 = td_var_offset(do_verify),
1289 .help = "Run verification stage after write",
1294 .name = "verifysort",
1295 .type = FIO_OPT_BOOL,
1296 .off1 = td_var_offset(verifysort),
1297 .help = "Sort written verify blocks for read back",
1302 .name = "verify_interval",
1303 .type = FIO_OPT_INT,
1304 .off1 = td_var_offset(verify_interval),
1305 .minval = 2 * sizeof(struct verify_header),
1306 .help = "Store verify buffer header every N bytes",
1310 .name = "verify_offset",
1311 .type = FIO_OPT_INT,
1312 .help = "Offset verify header location by N bytes",
1314 .cb = str_verify_offset_cb,
1318 .name = "verify_pattern",
1319 .type = FIO_OPT_STR,
1320 .cb = str_verify_pattern_cb,
1321 .help = "Fill pattern for IO buffers",
1325 .name = "verify_fatal",
1326 .type = FIO_OPT_BOOL,
1327 .off1 = td_var_offset(verify_fatal),
1329 .help = "Exit on a single verify failure, don't continue",
1333 .name = "verify_async",
1334 .type = FIO_OPT_INT,
1335 .off1 = td_var_offset(verify_async),
1337 .help = "Number of async verifier threads to use",
1340 #ifdef FIO_HAVE_CPU_AFFINITY
1342 .name = "verify_async_cpus",
1343 .type = FIO_OPT_STR,
1344 .cb = str_verify_cpus_allowed_cb,
1345 .help = "Set CPUs allowed for async verify threads",
1346 .parent = "verify_async",
1350 .name = "write_iolog",
1351 .type = FIO_OPT_STR_STORE,
1352 .off1 = td_var_offset(write_iolog_file),
1353 .help = "Store IO pattern to file",
1356 .name = "read_iolog",
1357 .type = FIO_OPT_STR_STORE,
1358 .off1 = td_var_offset(read_iolog_file),
1359 .help = "Playback IO pattern from file",
1362 .name = "exec_prerun",
1363 .type = FIO_OPT_STR_STORE,
1364 .off1 = td_var_offset(exec_prerun),
1365 .help = "Execute this file prior to running job",
1368 .name = "exec_postrun",
1369 .type = FIO_OPT_STR_STORE,
1370 .off1 = td_var_offset(exec_postrun),
1371 .help = "Execute this file after running job",
1373 #ifdef FIO_HAVE_IOSCHED_SWITCH
1375 .name = "ioscheduler",
1376 .type = FIO_OPT_STR_STORE,
1377 .off1 = td_var_offset(ioscheduler),
1378 .help = "Use this IO scheduler on the backing device",
1383 .type = FIO_OPT_STR_VAL,
1384 .off1 = td_var_offset(zone_size),
1385 .help = "Give size of an IO zone",
1390 .type = FIO_OPT_STR_VAL,
1391 .off1 = td_var_offset(zone_skip),
1392 .help = "Space between IO zones",
1397 .type = FIO_OPT_STR_VAL,
1398 .cb = str_lockmem_cb,
1399 .help = "Lock down this amount of memory",
1403 .name = "rwmixread",
1404 .type = FIO_OPT_INT,
1405 .cb = str_rwmix_read_cb,
1407 .help = "Percentage of mixed workload that is reads",
1411 .name = "rwmixwrite",
1412 .type = FIO_OPT_INT,
1413 .cb = str_rwmix_write_cb,
1415 .help = "Percentage of mixed workload that is writes",
1419 .name = "rwmixcycle",
1420 .type = FIO_OPT_DEPRECATED,
1424 .type = FIO_OPT_INT,
1425 .off1 = td_var_offset(nice),
1426 .help = "Set job CPU nice value",
1431 #ifdef FIO_HAVE_IOPRIO
1434 .type = FIO_OPT_INT,
1436 .help = "Set job IO priority value",
1441 .name = "prioclass",
1442 .type = FIO_OPT_INT,
1443 .cb = str_prioclass_cb,
1444 .help = "Set job IO priority class",
1450 .name = "thinktime",
1451 .type = FIO_OPT_INT,
1452 .off1 = td_var_offset(thinktime),
1453 .help = "Idle time between IO buffers (usec)",
1457 .name = "thinktime_spin",
1458 .type = FIO_OPT_INT,
1459 .off1 = td_var_offset(thinktime_spin),
1460 .help = "Start think time by spinning this amount (usec)",
1462 .parent = "thinktime",
1465 .name = "thinktime_blocks",
1466 .type = FIO_OPT_INT,
1467 .off1 = td_var_offset(thinktime_blocks),
1468 .help = "IO buffer period between 'thinktime'",
1470 .parent = "thinktime",
1474 .type = FIO_OPT_INT,
1475 .off1 = td_var_offset(rate[0]),
1476 .off2 = td_var_offset(rate[1]),
1477 .help = "Set bandwidth rate",
1481 .type = FIO_OPT_INT,
1482 .off1 = td_var_offset(ratemin[0]),
1483 .off2 = td_var_offset(ratemin[1]),
1484 .help = "Job must meet this rate or it will be shutdown",
1488 .name = "rate_iops",
1489 .type = FIO_OPT_INT,
1490 .off1 = td_var_offset(rate_iops[0]),
1491 .off2 = td_var_offset(rate_iops[1]),
1492 .help = "Limit IO used to this number of IO operations/sec",
1495 .name = "rate_iops_min",
1496 .type = FIO_OPT_INT,
1497 .off1 = td_var_offset(rate_iops_min[0]),
1498 .off2 = td_var_offset(rate_iops_min[1]),
1499 .help = "Job must meet this rate or it will be shutdown",
1500 .parent = "rate_iops",
1503 .name = "ratecycle",
1504 .type = FIO_OPT_INT,
1505 .off1 = td_var_offset(ratecycle),
1506 .help = "Window average for rate limits (msec)",
1511 .name = "invalidate",
1512 .type = FIO_OPT_BOOL,
1513 .off1 = td_var_offset(invalidate_cache),
1514 .help = "Invalidate buffer/page cache prior to running job",
1519 .type = FIO_OPT_BOOL,
1520 .off1 = td_var_offset(sync_io),
1521 .help = "Use O_SYNC for buffered writes",
1523 .parent = "buffered",
1526 .name = "bwavgtime",
1527 .type = FIO_OPT_INT,
1528 .off1 = td_var_offset(bw_avg_time),
1529 .help = "Time window over which to calculate bandwidth"
1534 .name = "create_serialize",
1535 .type = FIO_OPT_BOOL,
1536 .off1 = td_var_offset(create_serialize),
1537 .help = "Serialize creating of job files",
1541 .name = "create_fsync",
1542 .type = FIO_OPT_BOOL,
1543 .off1 = td_var_offset(create_fsync),
1544 .help = "Fsync file after creation",
1548 .name = "create_on_open",
1549 .type = FIO_OPT_BOOL,
1550 .off1 = td_var_offset(create_on_open),
1551 .help = "Create files when they are opened for IO",
1556 .type = FIO_OPT_BOOL,
1557 .off1 = td_var_offset(pre_read),
1558 .help = "Preread files before starting official testing",
1563 .type = FIO_OPT_INT,
1564 .off1 = td_var_offset(cpuload),
1565 .help = "Use this percentage of CPU",
1568 .name = "cpuchunks",
1569 .type = FIO_OPT_INT,
1570 .off1 = td_var_offset(cpucycle),
1571 .help = "Length of the CPU burn cycles (usecs)",
1573 .parent = "cpuload",
1575 #ifdef FIO_HAVE_CPU_AFFINITY
1578 .type = FIO_OPT_INT,
1579 .cb = str_cpumask_cb,
1580 .help = "CPU affinity mask",
1583 .name = "cpus_allowed",
1584 .type = FIO_OPT_STR,
1585 .cb = str_cpus_allowed_cb,
1586 .help = "Set CPUs allowed",
1590 .name = "end_fsync",
1591 .type = FIO_OPT_BOOL,
1592 .off1 = td_var_offset(end_fsync),
1593 .help = "Include fsync at the end of job",
1597 .name = "fsync_on_close",
1598 .type = FIO_OPT_BOOL,
1599 .off1 = td_var_offset(fsync_on_close),
1600 .help = "fsync files on close",
1605 .type = FIO_OPT_BOOL,
1606 .off1 = td_var_offset(unlink),
1607 .help = "Unlink created files after job has completed",
1612 .type = FIO_OPT_STR_SET,
1613 .cb = str_exitall_cb,
1614 .help = "Terminate all jobs when one exits",
1617 .name = "stonewall",
1618 .type = FIO_OPT_STR_SET,
1619 .off1 = td_var_offset(stonewall),
1620 .help = "Insert a hard barrier between this job and previous",
1623 .name = "new_group",
1624 .type = FIO_OPT_STR_SET,
1625 .off1 = td_var_offset(new_group),
1626 .help = "Mark the start of a new group (for reporting)",
1630 .type = FIO_OPT_STR_SET,
1631 .off1 = td_var_offset(use_thread),
1632 .help = "Use threads instead of forks",
1635 .name = "write_bw_log",
1636 .type = FIO_OPT_STR,
1637 .off1 = td_var_offset(write_bw_log),
1638 .cb = str_write_bw_log_cb,
1639 .help = "Write log of bandwidth during run",
1642 .name = "write_lat_log",
1643 .type = FIO_OPT_STR,
1644 .off1 = td_var_offset(write_lat_log),
1645 .cb = str_write_lat_log_cb,
1646 .help = "Write log of latency during run",
1649 .name = "hugepage-size",
1650 .type = FIO_OPT_INT,
1651 .off1 = td_var_offset(hugepage_size),
1652 .help = "When using hugepages, specify size of each page",
1653 .def = __stringify(FIO_HUGE_PAGE),
1656 .name = "group_reporting",
1657 .type = FIO_OPT_STR_SET,
1658 .off1 = td_var_offset(group_reporting),
1659 .help = "Do reporting on a per-group basis",
1662 .name = "zero_buffers",
1663 .type = FIO_OPT_STR_SET,
1664 .off1 = td_var_offset(zero_buffers),
1665 .help = "Init IO buffers to all zeroes",
1668 .name = "refill_buffers",
1669 .type = FIO_OPT_STR_SET,
1670 .off1 = td_var_offset(refill_buffers),
1671 .help = "Refill IO buffers on every IO submit",
1673 #ifdef FIO_HAVE_DISK_UTIL
1675 .name = "disk_util",
1676 .type = FIO_OPT_BOOL,
1677 .off1 = td_var_offset(do_disk_util),
1678 .help = "Log disk utilization statistics",
1683 .name = "gtod_reduce",
1684 .type = FIO_OPT_BOOL,
1685 .help = "Greatly reduce number of gettimeofday() calls",
1686 .cb = str_gtod_reduce_cb,
1690 .name = "disable_clat",
1691 .type = FIO_OPT_BOOL,
1692 .off1 = td_var_offset(disable_clat),
1693 .help = "Disable completion latency numbers",
1694 .parent = "gtod_reduce",
1698 .name = "disable_slat",
1699 .type = FIO_OPT_BOOL,
1700 .off1 = td_var_offset(disable_slat),
1701 .help = "Disable submissionn latency numbers",
1702 .parent = "gtod_reduce",
1706 .name = "disable_bw_measurement",
1707 .type = FIO_OPT_BOOL,
1708 .off1 = td_var_offset(disable_bw),
1709 .help = "Disable bandwidth logging",
1710 .parent = "gtod_reduce",
1715 .type = FIO_OPT_INT,
1716 .cb = str_gtod_cpu_cb,
1717 .help = "Setup dedicated gettimeofday() thread on this CPU",
1718 .verify = gtod_cpu_verify,
1721 .name = "continue_on_error",
1722 .type = FIO_OPT_BOOL,
1723 .off1 = td_var_offset(continue_on_error),
1724 .help = "Continue on non-fatal errors during I/O",
1729 .type = FIO_OPT_STR,
1730 .off1 = td_var_offset(profile),
1732 { .ival = "tiobench",
1733 .oval = PROFILE_TIOBENCH,
1734 .help = "Perform tiobench like test",
1737 .help = "Select a specific builtin performance test",
1741 .type = FIO_OPT_STR_STORE,
1742 .off1 = td_var_offset(cgroup),
1743 .help = "Add job to cgroup of this name",
1746 .name = "cgroup_weight",
1747 .type = FIO_OPT_INT,
1748 .off1 = td_var_offset(cgroup_weight),
1749 .help = "Use given weight for cgroup",
1755 .type = FIO_OPT_INT,
1756 .off1 = td_var_offset(uid),
1757 .help = "Run job with this user ID",
1761 .type = FIO_OPT_INT,
1762 .off1 = td_var_offset(gid),
1763 .help = "Run job with this group ID",
1770 void fio_options_dup_and_init(struct option *long_options)
1772 struct fio_option *o;
1775 options_init(options);
1778 while (long_options[i].name)
1783 long_options[i].name = (char *) o->name;
1784 long_options[i].val = FIO_GETOPT_JOB;
1785 if (o->type == FIO_OPT_STR_SET)
1786 long_options[i].has_arg = no_argument;
1788 long_options[i].has_arg = required_argument;
1792 assert(i < FIO_NR_OPTIONS);
1796 struct fio_keyword {
1802 static struct fio_keyword fio_keywords[] = {
1804 .word = "$pagesize",
1805 .desc = "Page size in the system",
1808 .word = "$mb_memory",
1809 .desc = "Megabytes of memory online",
1813 .desc = "Number of CPUs online in the system",
1820 void fio_keywords_init(void)
1822 unsigned long long mb_memory;
1826 sprintf(buf, "%lu", page_size);
1827 fio_keywords[0].replace = strdup(buf);
1829 mb_memory = os_phys_mem() / page_size;
1830 sprintf(buf, "%llu", mb_memory);
1831 fio_keywords[1].replace = strdup(buf);
1833 l = sysconf(_SC_NPROCESSORS_ONLN);
1834 sprintf(buf, "%lu", l);
1835 fio_keywords[2].replace = strdup(buf);
1840 static char *bc_calc(char *str)
1842 char *buf, *tmp, opt[80];
1847 * No math, just return string
1849 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1854 * Split option from value, we only need to calculate the value
1856 tmp = strchr(str, '=');
1861 memset(opt, 0, sizeof(opt));
1862 strncpy(opt, str, tmp - str);
1866 sprintf(buf, "which %s > /dev/null", BC_APP);
1868 log_err("fio: bc is needed for performing math\n");
1873 sprintf(buf, "echo %s | %s", tmp, BC_APP);
1874 f = popen(buf, "r");
1880 ret = fread(buf, 1, 128, f);
1886 buf[ret - 1] = '\0';
1895 * Look for reserved variable names and replace them with real values
1897 static char *fio_keyword_replace(char *opt)
1902 for (i = 0; fio_keywords[i].word != NULL; i++) {
1903 struct fio_keyword *kw = &fio_keywords[i];
1905 while ((s = strstr(opt, kw->word)) != NULL) {
1906 char *new = malloc(strlen(opt) + 1);
1912 * Copy part of the string before the keyword and
1913 * sprintf() the replacement after it.
1915 memcpy(new, opt, olen);
1916 len = sprintf(new + olen, "%s", kw->replace);
1919 * If there's more in the original string, copy that
1922 opt += strlen(kw->word) + olen;
1924 memcpy(new + olen + len, opt, opt - o_org - 1);
1927 * replace opt and free the old opt
1933 * Check for potential math and invoke bc, if possible
1942 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
1946 sort_options(opts, options, num_opts);
1948 for (ret = 0, i = 0; i < num_opts; i++) {
1949 opts[i] = fio_keyword_replace(opts[i]);
1950 ret |= parse_option(opts[i], options, &ext_opt_list, td);
1956 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1958 return parse_cmd_option(opt, val, options, &ext_opt_list, td);
1961 void fio_fill_default_options(struct thread_data *td)
1963 fill_default_options(td, options);
1966 int fio_show_option_help(const char *opt)
1968 return show_cmd_help(options, opt);
1971 static void __options_mem(struct thread_data *td, int alloc)
1973 struct thread_options *o = &td->o;
1974 struct fio_option *opt;
1978 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1979 if (opt->type != FIO_OPT_STR_STORE)
1982 ptr = (void *) o + opt->off1;
1985 *ptr = strdup(*ptr);
1995 * dupe FIO_OPT_STR_STORE options
1997 void options_mem_dupe(struct thread_data *td)
1999 __options_mem(td, 1);
2002 void options_mem_free(struct thread_data fio_unused *td)
2005 __options_mem(td, 0);
2009 unsigned int fio_get_kb_base(void *data)
2011 struct thread_data *td = data;
2012 unsigned int kb_base = 0;
2015 kb_base = td->o.kb_base;
2022 void register_ext_option(struct ext_option *eopt)
2024 dprint(FD_PARSE, "register option '%s'\n", eopt->o.name);
2025 option_init(&eopt->o);
2026 flist_add_tail(&eopt->list, &ext_opt_list);