10 #include <sys/types.h>
20 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
22 static char *get_opt_postfix(const char *str)
24 char *p = strstr(str, ":");
30 strip_blank_front(&p);
35 static int converthexchartoint(char a)
55 static int bs_cmp(const void *p1, const void *p2)
57 const struct bssplit *bsp1 = p1;
58 const struct bssplit *bsp2 = p2;
60 return bsp1->perc < bsp2->perc;
63 static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
65 struct bssplit *bssplit;
66 unsigned int i, perc, perc_missing;
67 unsigned int max_bs, min_bs;
71 td->o.bssplit_nr[ddir] = 4;
72 bssplit = malloc(4 * sizeof(struct bssplit));
77 while ((fname = strsep(&str, ":")) != NULL) {
84 * grow struct buffer, if needed
86 if (i == td->o.bssplit_nr[ddir]) {
87 td->o.bssplit_nr[ddir] <<= 1;
88 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
89 * sizeof(struct bssplit));
92 perc_str = strstr(fname, "/");
96 perc = atoi(perc_str);
104 if (str_to_decimal(fname, &val, 1, td)) {
105 log_err("fio: bssplit conversion failed\n");
116 bssplit[i].perc = perc;
120 td->o.bssplit_nr[ddir] = i;
123 * Now check if the percentages add up, and how much is missing
125 perc = perc_missing = 0;
126 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
127 struct bssplit *bsp = &bssplit[i];
129 if (bsp->perc == (unsigned char) -1)
136 log_err("fio: bssplit percentages add to more than 100%%\n");
141 * If values didn't have a percentage set, divide the remains between
145 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
146 struct bssplit *bsp = &bssplit[i];
148 if (bsp->perc == (unsigned char) -1)
149 bsp->perc = (100 - perc) / perc_missing;
153 td->o.min_bs[ddir] = min_bs;
154 td->o.max_bs[ddir] = max_bs;
157 * now sort based on percentages, for ease of lookup
159 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
160 td->o.bssplit[ddir] = bssplit;
165 static int str_bssplit_cb(void *data, const char *input)
167 struct thread_data *td = data;
168 char *str, *p, *odir;
171 p = str = strdup(input);
173 strip_blank_front(&str);
174 strip_blank_end(str);
176 odir = strchr(str, ',');
178 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
181 ret = bssplit_ddir(td, DDIR_READ, str);
188 ret = bssplit_ddir(td, DDIR_READ, str);
190 ret = bssplit_ddir(td, DDIR_WRITE, op);
199 static int str_rw_cb(void *data, const char *str)
201 struct thread_data *td = data;
202 char *nr = get_opt_postfix(str);
206 td->o.ddir_nr = atoi(nr);
213 static int str_mem_cb(void *data, const char *mem)
215 struct thread_data *td = data;
217 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
218 td->mmapfile = get_opt_postfix(mem);
219 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
220 log_err("fio: mmaphuge:/path/to/file\n");
228 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
234 static int str_rwmix_read_cb(void *data, unsigned int *val)
236 struct thread_data *td = data;
238 td->o.rwmix[DDIR_READ] = *val;
239 td->o.rwmix[DDIR_WRITE] = 100 - *val;
243 static int str_rwmix_write_cb(void *data, unsigned int *val)
245 struct thread_data *td = data;
247 td->o.rwmix[DDIR_WRITE] = *val;
248 td->o.rwmix[DDIR_READ] = 100 - *val;
252 #ifdef FIO_HAVE_IOPRIO
253 static int str_prioclass_cb(void *data, unsigned int *val)
255 struct thread_data *td = data;
259 * mask off old class bits, str_prio_cb() may have set a default class
261 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
264 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
269 static int str_prio_cb(void *data, unsigned int *val)
271 struct thread_data *td = data;
276 * If no class is set, assume BE
278 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
279 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
286 static int str_exitall_cb(void)
288 exitall_on_terminate = 1;
292 #ifdef FIO_HAVE_CPU_AFFINITY
293 static int str_cpumask_cb(void *data, unsigned int *val)
295 struct thread_data *td = data;
300 ret = fio_cpuset_init(&td->o.cpumask);
302 log_err("fio: cpuset_init failed\n");
303 td_verror(td, ret, "fio_cpuset_init");
307 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
309 for (i = 0; i < sizeof(int) * 8; i++) {
310 if ((1 << i) & *val) {
312 log_err("fio: CPU %d too large (max=%ld)\n", i,
316 dprint(FD_PARSE, "set cpu allowed %d\n", i);
317 fio_cpu_set(&td->o.cpumask, i);
321 td->o.cpumask_set = 1;
325 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
332 ret = fio_cpuset_init(mask);
334 log_err("fio: cpuset_init failed\n");
335 td_verror(td, ret, "fio_cpuset_init");
339 p = str = strdup(input);
341 strip_blank_front(&str);
342 strip_blank_end(str);
344 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
346 while ((cpu = strsep(&str, ",")) != NULL) {
355 while ((cpu2 = strsep(&str2, "-")) != NULL) {
365 while (icpu <= icpu2) {
366 if (icpu >= FIO_MAX_CPUS) {
367 log_err("fio: your OS only supports up to"
368 " %d CPUs\n", (int) FIO_MAX_CPUS);
372 if (icpu > max_cpu) {
373 log_err("fio: CPU %d too large (max=%ld)\n",
379 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
380 fio_cpu_set(mask, icpu);
389 td->o.cpumask_set = 1;
393 static int str_cpus_allowed_cb(void *data, const char *input)
395 struct thread_data *td = data;
398 ret = set_cpus_allowed(td, &td->o.cpumask, input);
400 td->o.cpumask_set = 1;
405 static int str_verify_cpus_allowed_cb(void *data, const char *input)
407 struct thread_data *td = data;
410 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
412 td->o.verify_cpumask_set = 1;
418 static int str_fst_cb(void *data, const char *str)
420 struct thread_data *td = data;
421 char *nr = get_opt_postfix(str);
423 td->file_service_nr = 1;
425 td->file_service_nr = atoi(nr);
432 static int check_dir(struct thread_data *td, char *fname)
434 char file[PATH_MAX], *dir;
437 if (td->o.directory) {
438 strcpy(file, td->o.directory);
443 sprintf(file + elen, "%s", fname);
450 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
451 * yet, so we can't do this check right here...
453 if (lstat(dir, &sb) < 0) {
456 log_err("fio: %s is not a directory\n", dir);
457 td_verror(td, ret, "lstat");
461 if (!S_ISDIR(sb.st_mode)) {
462 log_err("fio: %s is not a directory\n", dir);
472 * Return next file in the string. Files are separated with ':'. If the ':'
473 * is escaped with a '\', then that ':' is part of the filename and does not
474 * indicate a new file.
476 static char *get_next_file_name(char **ptr)
481 if (!str || !strlen(str))
487 * No colon, we are done
489 p = strchr(str, ':');
496 * We got a colon, but it's the first character. Skip and
504 if (*(p - 1) != '\\') {
510 memmove(p - 1, p, strlen(p) + 1);
517 static int str_filename_cb(void *data, const char *input)
519 struct thread_data *td = data;
520 char *fname, *str, *p;
522 p = str = strdup(input);
524 strip_blank_front(&str);
525 strip_blank_end(str);
527 if (!td->files_index)
530 while ((fname = get_next_file_name(&str)) != NULL) {
533 if (check_dir(td, fname)) {
545 static int str_directory_cb(void *data, const char fio_unused *str)
547 struct thread_data *td = data;
550 if (lstat(td->o.directory, &sb) < 0) {
553 log_err("fio: %s is not a directory\n", td->o.directory);
554 td_verror(td, ret, "lstat");
557 if (!S_ISDIR(sb.st_mode)) {
558 log_err("fio: %s is not a directory\n", td->o.directory);
565 static int str_opendir_cb(void *data, const char fio_unused *str)
567 struct thread_data *td = data;
569 if (!td->files_index)
572 return add_dir_files(td, td->o.opendir);
575 static int str_verify_offset_cb(void *data, unsigned int *off)
577 struct thread_data *td = data;
579 if (*off && *off < sizeof(struct verify_header)) {
580 log_err("fio: verify_offset too small\n");
584 td->o.verify_offset = *off;
588 static int str_verify_pattern_cb(void *data, const char *input)
590 struct thread_data *td = data;
592 int i = 0, j = 0, len, k, base = 10;
595 loc1 = strstr(input, "0x");
596 loc2 = strstr(input, "0X");
599 off = strtol(input, NULL, base);
600 if (off != LONG_MAX || errno != ERANGE) {
602 td->o.verify_pattern[i] = off & 0xff;
611 j = loc1 - input + 2;
613 j = loc2 - input + 2;
616 if (len - j < MAX_PATTERN_SIZE * 2) {
618 off = converthexchartoint(input[k--]);
620 off += (converthexchartoint(input[k--])
622 td->o.verify_pattern[i++] = (char) off;
626 td->o.verify_pattern_bytes = i;
630 static int str_lockfile_cb(void *data, const char *str)
632 struct thread_data *td = data;
633 char *nr = get_opt_postfix(str);
635 td->o.lockfile_batch = 1;
637 td->o.lockfile_batch = atoi(nr);
644 static int str_write_bw_log_cb(void *data, const char *str)
646 struct thread_data *td = data;
649 td->o.bw_log_file = strdup(str);
651 td->o.write_bw_log = 1;
655 static int str_write_lat_log_cb(void *data, const char *str)
657 struct thread_data *td = data;
660 td->o.lat_log_file = strdup(str);
662 td->o.write_lat_log = 1;
666 static int str_gtod_reduce_cb(void *data, int *il)
668 struct thread_data *td = data;
671 td->o.disable_clat = !!val;
672 td->o.disable_slat = !!val;
673 td->o.disable_bw = !!val;
675 td->tv_cache_mask = 63;
680 static int str_gtod_cpu_cb(void *data, int *il)
682 struct thread_data *td = data;
685 td->o.gtod_cpu = val;
686 td->o.gtod_offload = 1;
690 static int rw_verify(struct fio_option *o, void *data)
692 struct thread_data *td = data;
694 if (read_only && td_write(td)) {
695 log_err("fio: job <%s> has write bit set, but fio is in"
696 " read-only mode\n", td->o.name);
703 static int gtod_cpu_verify(struct fio_option *o, void *data)
705 #ifndef FIO_HAVE_CPU_AFFINITY
706 struct thread_data *td = data;
708 if (td->o.gtod_cpu) {
709 log_err("fio: platform must support CPU affinity for"
710 "gettimeofday() offloading\n");
718 static int kb_base_verify(struct fio_option *o, void *data)
720 struct thread_data *td = data;
722 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
723 log_err("fio: kb_base set to nonsensical value: %u\n",
731 #define __stringify_1(x) #x
732 #define __stringify(x) __stringify_1(x)
735 * Map of job/command line options
737 static struct fio_option options[FIO_MAX_OPTS] = {
739 .name = "description",
740 .type = FIO_OPT_STR_STORE,
741 .off1 = td_var_offset(description),
742 .help = "Text job description",
746 .type = FIO_OPT_STR_STORE,
747 .off1 = td_var_offset(name),
748 .help = "Name of this job",
752 .type = FIO_OPT_STR_STORE,
753 .off1 = td_var_offset(directory),
754 .cb = str_directory_cb,
755 .help = "Directory to store files in",
759 .type = FIO_OPT_STR_STORE,
760 .off1 = td_var_offset(filename),
761 .cb = str_filename_cb,
762 .prio = -1, /* must come after "directory" */
763 .help = "File(s) to use for the workload",
768 .off1 = td_var_offset(kb_base),
769 .verify = kb_base_verify,
772 .help = "How many bytes per KB for reporting (1000 or 1024)",
777 .cb = str_lockfile_cb,
778 .off1 = td_var_offset(file_lock_mode),
779 .help = "Lock file when doing IO to it",
780 .parent = "filename",
784 .oval = FILE_LOCK_NONE,
785 .help = "No file locking",
787 { .ival = "exclusive",
788 .oval = FILE_LOCK_EXCLUSIVE,
789 .help = "Exclusive file lock",
793 .oval = FILE_LOCK_READWRITE,
794 .help = "Read vs write lock",
800 .type = FIO_OPT_STR_STORE,
801 .off1 = td_var_offset(opendir),
802 .cb = str_opendir_cb,
803 .help = "Recursively add files from this directory and down",
807 .alias = "readwrite",
810 .off1 = td_var_offset(td_ddir),
811 .help = "IO direction",
816 .oval = TD_DDIR_READ,
817 .help = "Sequential read",
820 .oval = TD_DDIR_WRITE,
821 .help = "Sequential write",
823 { .ival = "randread",
824 .oval = TD_DDIR_RANDREAD,
825 .help = "Random read",
827 { .ival = "randwrite",
828 .oval = TD_DDIR_RANDWRITE,
829 .help = "Random write",
833 .help = "Sequential read and write mix",
836 .oval = TD_DDIR_RANDRW,
837 .help = "Random read and write mix"
843 .type = FIO_OPT_STR_STORE,
844 .off1 = td_var_offset(ioengine),
845 .help = "IO engine to use",
849 .help = "Use read/write",
852 .help = "Use pread/pwrite",
855 .help = "Use readv/writev",
857 #ifdef FIO_HAVE_LIBAIO
859 .help = "Linux native asynchronous IO",
862 #ifdef FIO_HAVE_POSIXAIO
863 { .ival = "posixaio",
864 .help = "POSIX asynchronous IO",
867 #ifdef FIO_HAVE_SOLARISAIO
868 { .ival = "solarisaio",
869 .help = "Solaris native asynchronous IO",
873 .help = "Memory mapped IO",
875 #ifdef FIO_HAVE_SPLICE
877 .help = "splice/vmsplice based IO",
879 { .ival = "netsplice",
880 .help = "splice/vmsplice to/from the network",
885 .help = "SCSI generic v3 IO",
889 .help = "Testing engine (no data transfer)",
892 .help = "Network IO",
894 #ifdef FIO_HAVE_SYSLET
895 { .ival = "syslet-rw",
896 .help = "syslet enabled async pread/pwrite IO",
900 .help = "CPU cycler burner engine",
902 #ifdef FIO_HAVE_GUASI
904 .help = "GUASI IO engine",
907 { .ival = "external",
908 .help = "Load external engine (append name)",
915 .off1 = td_var_offset(iodepth),
916 .help = "Amount of IO buffers to keep in flight",
921 .name = "iodepth_batch",
922 .alias = "iodepth_batch_submit",
924 .off1 = td_var_offset(iodepth_batch),
925 .help = "Number of IO buffers to submit in one go",
931 .name = "iodepth_batch_complete",
933 .off1 = td_var_offset(iodepth_batch_complete),
934 .help = "Number of IO buffers to retrieve in one go",
940 .name = "iodepth_low",
942 .off1 = td_var_offset(iodepth_low),
943 .help = "Low water mark for queuing depth",
948 .type = FIO_OPT_STR_VAL,
949 .off1 = td_var_offset(size),
951 .help = "Total size of device or files",
954 .name = "fill_device",
955 .type = FIO_OPT_BOOL,
956 .off1 = td_var_offset(fill_device),
957 .help = "Write until an ENOSPC error occurs",
962 .type = FIO_OPT_STR_VAL,
963 .off1 = td_var_offset(file_size_low),
964 .off2 = td_var_offset(file_size_high),
966 .help = "Size of individual files",
970 .alias = "fileoffset",
971 .type = FIO_OPT_STR_VAL,
972 .off1 = td_var_offset(start_offset),
973 .help = "Start IO from this offset",
978 .alias = "blocksize",
980 .off1 = td_var_offset(bs[DDIR_READ]),
981 .off2 = td_var_offset(bs[DDIR_WRITE]),
983 .help = "Block size unit",
989 .alias = "blockalign",
991 .off1 = td_var_offset(ba[DDIR_READ]),
992 .off2 = td_var_offset(ba[DDIR_WRITE]),
994 .help = "IO block offset alignment",
999 .alias = "blocksize_range",
1000 .type = FIO_OPT_RANGE,
1001 .off1 = td_var_offset(min_bs[DDIR_READ]),
1002 .off2 = td_var_offset(max_bs[DDIR_READ]),
1003 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1004 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1006 .help = "Set block size range (in more detail than bs)",
1011 .type = FIO_OPT_STR,
1012 .cb = str_bssplit_cb,
1013 .help = "Set a specific mix of block sizes",
1017 .name = "bs_unaligned",
1018 .alias = "blocksize_unaligned",
1019 .type = FIO_OPT_STR_SET,
1020 .off1 = td_var_offset(bs_unaligned),
1021 .help = "Don't sector align IO buffer sizes",
1025 .name = "randrepeat",
1026 .type = FIO_OPT_BOOL,
1027 .off1 = td_var_offset(rand_repeatable),
1028 .help = "Use repeatable random IO pattern",
1033 .name = "norandommap",
1034 .type = FIO_OPT_STR_SET,
1035 .off1 = td_var_offset(norandommap),
1036 .help = "Accept potential duplicate random blocks",
1040 .name = "softrandommap",
1041 .type = FIO_OPT_BOOL,
1042 .off1 = td_var_offset(softrandommap),
1043 .help = "Set norandommap if randommap allocation fails",
1044 .parent = "norandommap",
1049 .type = FIO_OPT_INT,
1050 .off1 = td_var_offset(nr_files),
1051 .help = "Split job workload between this number of files",
1055 .name = "openfiles",
1056 .type = FIO_OPT_INT,
1057 .off1 = td_var_offset(open_files),
1058 .help = "Number of files to keep open at the same time",
1061 .name = "file_service_type",
1062 .type = FIO_OPT_STR,
1064 .off1 = td_var_offset(file_service_type),
1065 .help = "How to select which file to service next",
1066 .def = "roundrobin",
1069 .oval = FIO_FSERVICE_RANDOM,
1070 .help = "Choose a file at random",
1072 { .ival = "roundrobin",
1073 .oval = FIO_FSERVICE_RR,
1074 .help = "Round robin select files",
1076 { .ival = "sequential",
1077 .oval = FIO_FSERVICE_SEQ,
1078 .help = "Finish one file before moving to the next",
1081 .parent = "nrfiles",
1083 #ifdef FIO_HAVE_FALLOCATE
1085 .name = "fallocate",
1086 .type = FIO_OPT_BOOL,
1087 .off1 = td_var_offset(fallocate),
1088 .help = "Use fallocate() when laying out files",
1093 .name = "fadvise_hint",
1094 .type = FIO_OPT_BOOL,
1095 .off1 = td_var_offset(fadvise_hint),
1096 .help = "Use fadvise() to advise the kernel on IO pattern",
1101 .type = FIO_OPT_INT,
1102 .off1 = td_var_offset(fsync_blocks),
1103 .help = "Issue fsync for writes every given number of blocks",
1107 .name = "fdatasync",
1108 .type = FIO_OPT_INT,
1109 .off1 = td_var_offset(fdatasync_blocks),
1110 .help = "Issue fdatasync for writes every given number of blocks",
1115 .type = FIO_OPT_BOOL,
1116 .off1 = td_var_offset(odirect),
1117 .help = "Use O_DIRECT IO (negates buffered)",
1122 .type = FIO_OPT_BOOL,
1123 .off1 = td_var_offset(odirect),
1125 .help = "Use buffered IO (negates direct)",
1129 .name = "overwrite",
1130 .type = FIO_OPT_BOOL,
1131 .off1 = td_var_offset(overwrite),
1132 .help = "When writing, set whether to overwrite current data",
1137 .type = FIO_OPT_INT,
1138 .off1 = td_var_offset(loops),
1139 .help = "Number of times to run the job",
1144 .type = FIO_OPT_INT,
1145 .off1 = td_var_offset(numjobs),
1146 .help = "Duplicate this job this many times",
1150 .name = "startdelay",
1151 .type = FIO_OPT_INT,
1152 .off1 = td_var_offset(start_delay),
1153 .help = "Only start job when this period has passed",
1159 .type = FIO_OPT_STR_VAL_TIME,
1160 .off1 = td_var_offset(timeout),
1161 .help = "Stop workload when this amount of time has passed",
1165 .name = "time_based",
1166 .type = FIO_OPT_STR_SET,
1167 .off1 = td_var_offset(time_based),
1168 .help = "Keep running until runtime/timeout is met",
1171 .name = "ramp_time",
1172 .type = FIO_OPT_STR_VAL_TIME,
1173 .off1 = td_var_offset(ramp_time),
1174 .help = "Ramp up time before measuring performance",
1179 .type = FIO_OPT_STR,
1181 .off1 = td_var_offset(mem_type),
1182 .help = "Backing type for IO buffers",
1187 .help = "Use malloc(3) for IO buffers",
1191 .help = "Use shared memory segments for IO buffers",
1193 #ifdef FIO_HAVE_HUGETLB
1194 { .ival = "shmhuge",
1195 .oval = MEM_SHMHUGE,
1196 .help = "Like shm, but use huge pages",
1201 .help = "Use mmap(2) (file or anon) for IO buffers",
1203 #ifdef FIO_HAVE_HUGETLB
1204 { .ival = "mmaphuge",
1205 .oval = MEM_MMAPHUGE,
1206 .help = "Like mmap, but use huge pages",
1212 .name = "iomem_align",
1213 .alias = "mem_align",
1214 .type = FIO_OPT_INT,
1215 .off1 = td_var_offset(mem_align),
1217 .help = "IO memory buffer offset alignment",
1223 .type = FIO_OPT_STR,
1224 .off1 = td_var_offset(verify),
1225 .help = "Verify data written",
1229 .oval = VERIFY_NONE,
1230 .help = "Don't do IO verification",
1234 .help = "Use md5 checksums for verification",
1237 .oval = VERIFY_CRC64,
1238 .help = "Use crc64 checksums for verification",
1241 .oval = VERIFY_CRC32,
1242 .help = "Use crc32 checksums for verification",
1244 { .ival = "crc32c-intel",
1245 .oval = VERIFY_CRC32C_INTEL,
1246 .help = "Use hw crc32c checksums for verification",
1249 .oval = VERIFY_CRC32C,
1250 .help = "Use crc32c checksums for verification",
1253 .oval = VERIFY_CRC16,
1254 .help = "Use crc16 checksums for verification",
1257 .oval = VERIFY_CRC7,
1258 .help = "Use crc7 checksums for verification",
1261 .oval = VERIFY_SHA1,
1262 .help = "Use sha1 checksums for verification",
1265 .oval = VERIFY_SHA256,
1266 .help = "Use sha256 checksums for verification",
1269 .oval = VERIFY_SHA512,
1270 .help = "Use sha512 checksums for verification",
1273 .oval = VERIFY_META,
1274 .help = "Use io information",
1278 .oval = VERIFY_NULL,
1279 .help = "Pretend to verify",
1284 .name = "do_verify",
1285 .type = FIO_OPT_BOOL,
1286 .off1 = td_var_offset(do_verify),
1287 .help = "Run verification stage after write",
1292 .name = "verifysort",
1293 .type = FIO_OPT_BOOL,
1294 .off1 = td_var_offset(verifysort),
1295 .help = "Sort written verify blocks for read back",
1300 .name = "verify_interval",
1301 .type = FIO_OPT_INT,
1302 .off1 = td_var_offset(verify_interval),
1303 .minval = 2 * sizeof(struct verify_header),
1304 .help = "Store verify buffer header every N bytes",
1308 .name = "verify_offset",
1309 .type = FIO_OPT_INT,
1310 .help = "Offset verify header location by N bytes",
1312 .cb = str_verify_offset_cb,
1316 .name = "verify_pattern",
1317 .type = FIO_OPT_STR,
1318 .cb = str_verify_pattern_cb,
1319 .help = "Fill pattern for IO buffers",
1323 .name = "verify_fatal",
1324 .type = FIO_OPT_BOOL,
1325 .off1 = td_var_offset(verify_fatal),
1327 .help = "Exit on a single verify failure, don't continue",
1331 .name = "verify_async",
1332 .type = FIO_OPT_INT,
1333 .off1 = td_var_offset(verify_async),
1335 .help = "Number of async verifier threads to use",
1338 #ifdef FIO_HAVE_CPU_AFFINITY
1340 .name = "verify_async_cpus",
1341 .type = FIO_OPT_STR,
1342 .cb = str_verify_cpus_allowed_cb,
1343 .help = "Set CPUs allowed for async verify threads",
1344 .parent = "verify_async",
1348 .name = "write_iolog",
1349 .type = FIO_OPT_STR_STORE,
1350 .off1 = td_var_offset(write_iolog_file),
1351 .help = "Store IO pattern to file",
1354 .name = "read_iolog",
1355 .type = FIO_OPT_STR_STORE,
1356 .off1 = td_var_offset(read_iolog_file),
1357 .help = "Playback IO pattern from file",
1360 .name = "exec_prerun",
1361 .type = FIO_OPT_STR_STORE,
1362 .off1 = td_var_offset(exec_prerun),
1363 .help = "Execute this file prior to running job",
1366 .name = "exec_postrun",
1367 .type = FIO_OPT_STR_STORE,
1368 .off1 = td_var_offset(exec_postrun),
1369 .help = "Execute this file after running job",
1371 #ifdef FIO_HAVE_IOSCHED_SWITCH
1373 .name = "ioscheduler",
1374 .type = FIO_OPT_STR_STORE,
1375 .off1 = td_var_offset(ioscheduler),
1376 .help = "Use this IO scheduler on the backing device",
1381 .type = FIO_OPT_STR_VAL,
1382 .off1 = td_var_offset(zone_size),
1383 .help = "Give size of an IO zone",
1388 .type = FIO_OPT_STR_VAL,
1389 .off1 = td_var_offset(zone_skip),
1390 .help = "Space between IO zones",
1395 .type = FIO_OPT_STR_VAL,
1396 .cb = str_lockmem_cb,
1397 .help = "Lock down this amount of memory",
1401 .name = "rwmixread",
1402 .type = FIO_OPT_INT,
1403 .cb = str_rwmix_read_cb,
1405 .help = "Percentage of mixed workload that is reads",
1409 .name = "rwmixwrite",
1410 .type = FIO_OPT_INT,
1411 .cb = str_rwmix_write_cb,
1413 .help = "Percentage of mixed workload that is writes",
1417 .name = "rwmixcycle",
1418 .type = FIO_OPT_DEPRECATED,
1422 .type = FIO_OPT_INT,
1423 .off1 = td_var_offset(nice),
1424 .help = "Set job CPU nice value",
1429 #ifdef FIO_HAVE_IOPRIO
1432 .type = FIO_OPT_INT,
1434 .help = "Set job IO priority value",
1439 .name = "prioclass",
1440 .type = FIO_OPT_INT,
1441 .cb = str_prioclass_cb,
1442 .help = "Set job IO priority class",
1448 .name = "thinktime",
1449 .type = FIO_OPT_INT,
1450 .off1 = td_var_offset(thinktime),
1451 .help = "Idle time between IO buffers (usec)",
1455 .name = "thinktime_spin",
1456 .type = FIO_OPT_INT,
1457 .off1 = td_var_offset(thinktime_spin),
1458 .help = "Start think time by spinning this amount (usec)",
1460 .parent = "thinktime",
1463 .name = "thinktime_blocks",
1464 .type = FIO_OPT_INT,
1465 .off1 = td_var_offset(thinktime_blocks),
1466 .help = "IO buffer period between 'thinktime'",
1468 .parent = "thinktime",
1472 .type = FIO_OPT_INT,
1473 .off1 = td_var_offset(rate[0]),
1474 .off2 = td_var_offset(rate[1]),
1475 .help = "Set bandwidth rate",
1479 .type = FIO_OPT_INT,
1480 .off1 = td_var_offset(ratemin[0]),
1481 .off2 = td_var_offset(ratemin[1]),
1482 .help = "Job must meet this rate or it will be shutdown",
1486 .name = "rate_iops",
1487 .type = FIO_OPT_INT,
1488 .off1 = td_var_offset(rate_iops[0]),
1489 .off2 = td_var_offset(rate_iops[1]),
1490 .help = "Limit IO used to this number of IO operations/sec",
1493 .name = "rate_iops_min",
1494 .type = FIO_OPT_INT,
1495 .off1 = td_var_offset(rate_iops_min[0]),
1496 .off2 = td_var_offset(rate_iops_min[1]),
1497 .help = "Job must meet this rate or it will be shutdown",
1498 .parent = "rate_iops",
1501 .name = "ratecycle",
1502 .type = FIO_OPT_INT,
1503 .off1 = td_var_offset(ratecycle),
1504 .help = "Window average for rate limits (msec)",
1509 .name = "invalidate",
1510 .type = FIO_OPT_BOOL,
1511 .off1 = td_var_offset(invalidate_cache),
1512 .help = "Invalidate buffer/page cache prior to running job",
1517 .type = FIO_OPT_BOOL,
1518 .off1 = td_var_offset(sync_io),
1519 .help = "Use O_SYNC for buffered writes",
1521 .parent = "buffered",
1524 .name = "bwavgtime",
1525 .type = FIO_OPT_INT,
1526 .off1 = td_var_offset(bw_avg_time),
1527 .help = "Time window over which to calculate bandwidth"
1532 .name = "create_serialize",
1533 .type = FIO_OPT_BOOL,
1534 .off1 = td_var_offset(create_serialize),
1535 .help = "Serialize creating of job files",
1539 .name = "create_fsync",
1540 .type = FIO_OPT_BOOL,
1541 .off1 = td_var_offset(create_fsync),
1542 .help = "Fsync file after creation",
1546 .name = "create_on_open",
1547 .type = FIO_OPT_BOOL,
1548 .off1 = td_var_offset(create_on_open),
1549 .help = "Create files when they are opened for IO",
1554 .type = FIO_OPT_BOOL,
1555 .off1 = td_var_offset(pre_read),
1556 .help = "Preread files before starting official testing",
1561 .type = FIO_OPT_INT,
1562 .off1 = td_var_offset(cpuload),
1563 .help = "Use this percentage of CPU",
1566 .name = "cpuchunks",
1567 .type = FIO_OPT_INT,
1568 .off1 = td_var_offset(cpucycle),
1569 .help = "Length of the CPU burn cycles (usecs)",
1571 .parent = "cpuload",
1573 #ifdef FIO_HAVE_CPU_AFFINITY
1576 .type = FIO_OPT_INT,
1577 .cb = str_cpumask_cb,
1578 .help = "CPU affinity mask",
1581 .name = "cpus_allowed",
1582 .type = FIO_OPT_STR,
1583 .cb = str_cpus_allowed_cb,
1584 .help = "Set CPUs allowed",
1588 .name = "end_fsync",
1589 .type = FIO_OPT_BOOL,
1590 .off1 = td_var_offset(end_fsync),
1591 .help = "Include fsync at the end of job",
1595 .name = "fsync_on_close",
1596 .type = FIO_OPT_BOOL,
1597 .off1 = td_var_offset(fsync_on_close),
1598 .help = "fsync files on close",
1603 .type = FIO_OPT_BOOL,
1604 .off1 = td_var_offset(unlink),
1605 .help = "Unlink created files after job has completed",
1610 .type = FIO_OPT_STR_SET,
1611 .cb = str_exitall_cb,
1612 .help = "Terminate all jobs when one exits",
1615 .name = "stonewall",
1616 .type = FIO_OPT_STR_SET,
1617 .off1 = td_var_offset(stonewall),
1618 .help = "Insert a hard barrier between this job and previous",
1621 .name = "new_group",
1622 .type = FIO_OPT_STR_SET,
1623 .off1 = td_var_offset(new_group),
1624 .help = "Mark the start of a new group (for reporting)",
1628 .type = FIO_OPT_STR_SET,
1629 .off1 = td_var_offset(use_thread),
1630 .help = "Use threads instead of forks",
1633 .name = "write_bw_log",
1634 .type = FIO_OPT_STR,
1635 .off1 = td_var_offset(write_bw_log),
1636 .cb = str_write_bw_log_cb,
1637 .help = "Write log of bandwidth during run",
1640 .name = "write_lat_log",
1641 .type = FIO_OPT_STR,
1642 .off1 = td_var_offset(write_lat_log),
1643 .cb = str_write_lat_log_cb,
1644 .help = "Write log of latency during run",
1647 .name = "hugepage-size",
1648 .type = FIO_OPT_INT,
1649 .off1 = td_var_offset(hugepage_size),
1650 .help = "When using hugepages, specify size of each page",
1651 .def = __stringify(FIO_HUGE_PAGE),
1654 .name = "group_reporting",
1655 .type = FIO_OPT_STR_SET,
1656 .off1 = td_var_offset(group_reporting),
1657 .help = "Do reporting on a per-group basis",
1660 .name = "zero_buffers",
1661 .type = FIO_OPT_STR_SET,
1662 .off1 = td_var_offset(zero_buffers),
1663 .help = "Init IO buffers to all zeroes",
1666 .name = "refill_buffers",
1667 .type = FIO_OPT_STR_SET,
1668 .off1 = td_var_offset(refill_buffers),
1669 .help = "Refill IO buffers on every IO submit",
1671 #ifdef FIO_HAVE_DISK_UTIL
1673 .name = "disk_util",
1674 .type = FIO_OPT_BOOL,
1675 .off1 = td_var_offset(do_disk_util),
1676 .help = "Log disk utilization statistics",
1681 .name = "gtod_reduce",
1682 .type = FIO_OPT_BOOL,
1683 .help = "Greatly reduce number of gettimeofday() calls",
1684 .cb = str_gtod_reduce_cb,
1688 .name = "disable_clat",
1689 .type = FIO_OPT_BOOL,
1690 .off1 = td_var_offset(disable_clat),
1691 .help = "Disable completion latency numbers",
1692 .parent = "gtod_reduce",
1696 .name = "disable_slat",
1697 .type = FIO_OPT_BOOL,
1698 .off1 = td_var_offset(disable_slat),
1699 .help = "Disable submissionn latency numbers",
1700 .parent = "gtod_reduce",
1704 .name = "disable_bw_measurement",
1705 .type = FIO_OPT_BOOL,
1706 .off1 = td_var_offset(disable_bw),
1707 .help = "Disable bandwidth logging",
1708 .parent = "gtod_reduce",
1713 .type = FIO_OPT_INT,
1714 .cb = str_gtod_cpu_cb,
1715 .help = "Setup dedicated gettimeofday() thread on this CPU",
1716 .verify = gtod_cpu_verify,
1719 .name = "continue_on_error",
1720 .type = FIO_OPT_BOOL,
1721 .off1 = td_var_offset(continue_on_error),
1722 .help = "Continue on non-fatal errors during I/O",
1727 .type = FIO_OPT_STR_STORE,
1728 .off1 = td_var_offset(profile),
1729 .help = "Select a specific builtin performance test",
1733 .type = FIO_OPT_STR_STORE,
1734 .off1 = td_var_offset(cgroup),
1735 .help = "Add job to cgroup of this name",
1738 .name = "cgroup_weight",
1739 .type = FIO_OPT_INT,
1740 .off1 = td_var_offset(cgroup_weight),
1741 .help = "Use given weight for cgroup",
1747 .type = FIO_OPT_INT,
1748 .off1 = td_var_offset(uid),
1749 .help = "Run job with this user ID",
1753 .type = FIO_OPT_INT,
1754 .off1 = td_var_offset(gid),
1755 .help = "Run job with this group ID",
1762 static void add_to_lopt(struct option *lopt, struct fio_option *o)
1764 lopt->name = (char *) o->name;
1765 lopt->val = FIO_GETOPT_JOB;
1766 if (o->type == FIO_OPT_STR_SET)
1767 lopt->has_arg = no_argument;
1769 lopt->has_arg = required_argument;
1772 void fio_options_dup_and_init(struct option *long_options)
1774 struct fio_option *o;
1777 options_init(options);
1780 while (long_options[i].name)
1785 add_to_lopt(&long_options[i], o);
1789 assert(i < FIO_NR_OPTIONS);
1793 struct fio_keyword {
1799 static struct fio_keyword fio_keywords[] = {
1801 .word = "$pagesize",
1802 .desc = "Page size in the system",
1805 .word = "$mb_memory",
1806 .desc = "Megabytes of memory online",
1810 .desc = "Number of CPUs online in the system",
1817 void fio_keywords_init(void)
1819 unsigned long long mb_memory;
1823 sprintf(buf, "%lu", page_size);
1824 fio_keywords[0].replace = strdup(buf);
1826 mb_memory = os_phys_mem() / page_size;
1827 sprintf(buf, "%llu", mb_memory);
1828 fio_keywords[1].replace = strdup(buf);
1830 l = sysconf(_SC_NPROCESSORS_ONLN);
1831 sprintf(buf, "%lu", l);
1832 fio_keywords[2].replace = strdup(buf);
1837 static char *bc_calc(char *str)
1839 char *buf, *tmp, opt[80];
1844 * No math, just return string
1846 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1851 * Split option from value, we only need to calculate the value
1853 tmp = strchr(str, '=');
1858 memset(opt, 0, sizeof(opt));
1859 strncpy(opt, str, tmp - str);
1863 sprintf(buf, "which %s > /dev/null", BC_APP);
1865 log_err("fio: bc is needed for performing math\n");
1870 sprintf(buf, "echo %s | %s", tmp, BC_APP);
1871 f = popen(buf, "r");
1877 ret = fread(buf, 1, 128, f);
1883 buf[ret - 1] = '\0';
1892 * Look for reserved variable names and replace them with real values
1894 static char *fio_keyword_replace(char *opt)
1899 for (i = 0; fio_keywords[i].word != NULL; i++) {
1900 struct fio_keyword *kw = &fio_keywords[i];
1902 while ((s = strstr(opt, kw->word)) != NULL) {
1903 char *new = malloc(strlen(opt) + 1);
1909 * Copy part of the string before the keyword and
1910 * sprintf() the replacement after it.
1912 memcpy(new, opt, olen);
1913 len = sprintf(new + olen, "%s", kw->replace);
1916 * If there's more in the original string, copy that
1919 opt += strlen(kw->word) + olen;
1921 memcpy(new + olen + len, opt, opt - o_org - 1);
1924 * replace opt and free the old opt
1930 * Check for potential math and invoke bc, if possible
1939 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
1943 sort_options(opts, options, num_opts);
1945 for (ret = 0, i = 0; i < num_opts; i++) {
1946 opts[i] = fio_keyword_replace(opts[i]);
1947 ret |= parse_option(opts[i], options, td);
1953 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1955 return parse_cmd_option(opt, val, options, td);
1958 void fio_fill_default_options(struct thread_data *td)
1960 fill_default_options(td, options);
1963 int fio_show_option_help(const char *opt)
1965 return show_cmd_help(options, opt);
1968 static void __options_mem(struct thread_data *td, int alloc)
1970 struct thread_options *o = &td->o;
1971 struct fio_option *opt;
1975 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1976 if (opt->type != FIO_OPT_STR_STORE)
1979 ptr = (void *) o + opt->off1;
1982 *ptr = strdup(*ptr);
1992 * dupe FIO_OPT_STR_STORE options
1994 void options_mem_dupe(struct thread_data *td)
1996 __options_mem(td, 1);
1999 void options_mem_free(struct thread_data fio_unused *td)
2002 __options_mem(td, 0);
2006 unsigned int fio_get_kb_base(void *data)
2008 struct thread_data *td = data;
2009 unsigned int kb_base = 0;
2012 kb_base = td->o.kb_base;
2019 int add_option(struct fio_option *o)
2021 struct fio_option *__o;
2030 memcpy(&options[opt_index], o, sizeof(*o));
2034 void invalidate_profile_options(const char *prof_name)
2036 struct fio_option *o;
2040 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2041 o->type = FIO_OPT_INVALID;
2042 o->prof_name = NULL;