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 fio_clock_source_cb(void *data, const char *str)
230 struct thread_data *td = data;
232 fio_clock_source = td->o.clocksource;
237 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
243 static int str_rwmix_read_cb(void *data, unsigned int *val)
245 struct thread_data *td = data;
247 td->o.rwmix[DDIR_READ] = *val;
248 td->o.rwmix[DDIR_WRITE] = 100 - *val;
252 static int str_rwmix_write_cb(void *data, unsigned int *val)
254 struct thread_data *td = data;
256 td->o.rwmix[DDIR_WRITE] = *val;
257 td->o.rwmix[DDIR_READ] = 100 - *val;
261 #ifdef FIO_HAVE_IOPRIO
262 static int str_prioclass_cb(void *data, unsigned int *val)
264 struct thread_data *td = data;
268 * mask off old class bits, str_prio_cb() may have set a default class
270 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
273 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
278 static int str_prio_cb(void *data, unsigned int *val)
280 struct thread_data *td = data;
285 * If no class is set, assume BE
287 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
288 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
295 static int str_exitall_cb(void)
297 exitall_on_terminate = 1;
301 #ifdef FIO_HAVE_CPU_AFFINITY
302 static int str_cpumask_cb(void *data, unsigned int *val)
304 struct thread_data *td = data;
309 ret = fio_cpuset_init(&td->o.cpumask);
311 log_err("fio: cpuset_init failed\n");
312 td_verror(td, ret, "fio_cpuset_init");
316 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
318 for (i = 0; i < sizeof(int) * 8; i++) {
319 if ((1 << i) & *val) {
321 log_err("fio: CPU %d too large (max=%ld)\n", i,
325 dprint(FD_PARSE, "set cpu allowed %d\n", i);
326 fio_cpu_set(&td->o.cpumask, i);
330 td->o.cpumask_set = 1;
334 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
341 ret = fio_cpuset_init(mask);
343 log_err("fio: cpuset_init failed\n");
344 td_verror(td, ret, "fio_cpuset_init");
348 p = str = strdup(input);
350 strip_blank_front(&str);
351 strip_blank_end(str);
353 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
355 while ((cpu = strsep(&str, ",")) != NULL) {
364 while ((cpu2 = strsep(&str2, "-")) != NULL) {
374 while (icpu <= icpu2) {
375 if (icpu >= FIO_MAX_CPUS) {
376 log_err("fio: your OS only supports up to"
377 " %d CPUs\n", (int) FIO_MAX_CPUS);
381 if (icpu > max_cpu) {
382 log_err("fio: CPU %d too large (max=%ld)\n",
388 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
389 fio_cpu_set(mask, icpu);
398 td->o.cpumask_set = 1;
402 static int str_cpus_allowed_cb(void *data, const char *input)
404 struct thread_data *td = data;
407 ret = set_cpus_allowed(td, &td->o.cpumask, input);
409 td->o.cpumask_set = 1;
414 static int str_verify_cpus_allowed_cb(void *data, const char *input)
416 struct thread_data *td = data;
419 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
421 td->o.verify_cpumask_set = 1;
427 static int str_fst_cb(void *data, const char *str)
429 struct thread_data *td = data;
430 char *nr = get_opt_postfix(str);
432 td->file_service_nr = 1;
434 td->file_service_nr = atoi(nr);
441 #ifdef FIO_HAVE_SYNC_FILE_RANGE
442 static int str_sfr_cb(void *data, const char *str)
444 struct thread_data *td = data;
445 char *nr = get_opt_postfix(str);
447 td->sync_file_range_nr = 1;
449 td->sync_file_range_nr = atoi(nr);
457 static int check_dir(struct thread_data *td, char *fname)
459 char file[PATH_MAX], *dir;
462 if (td->o.directory) {
463 strcpy(file, td->o.directory);
468 sprintf(file + elen, "%s", fname);
475 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
476 * yet, so we can't do this check right here...
478 if (lstat(dir, &sb) < 0) {
481 log_err("fio: %s is not a directory\n", dir);
482 td_verror(td, ret, "lstat");
486 if (!S_ISDIR(sb.st_mode)) {
487 log_err("fio: %s is not a directory\n", dir);
497 * Return next file in the string. Files are separated with ':'. If the ':'
498 * is escaped with a '\', then that ':' is part of the filename and does not
499 * indicate a new file.
501 static char *get_next_file_name(char **ptr)
506 if (!str || !strlen(str))
512 * No colon, we are done
514 p = strchr(str, ':');
521 * We got a colon, but it's the first character. Skip and
529 if (*(p - 1) != '\\') {
535 memmove(p - 1, p, strlen(p) + 1);
542 static int str_filename_cb(void *data, const char *input)
544 struct thread_data *td = data;
545 char *fname, *str, *p;
547 p = str = strdup(input);
549 strip_blank_front(&str);
550 strip_blank_end(str);
552 if (!td->files_index)
555 while ((fname = get_next_file_name(&str)) != NULL) {
558 if (check_dir(td, fname)) {
570 static int str_directory_cb(void *data, const char fio_unused *str)
572 struct thread_data *td = data;
575 if (lstat(td->o.directory, &sb) < 0) {
578 log_err("fio: %s is not a directory\n", td->o.directory);
579 td_verror(td, ret, "lstat");
582 if (!S_ISDIR(sb.st_mode)) {
583 log_err("fio: %s is not a directory\n", td->o.directory);
590 static int str_opendir_cb(void *data, const char fio_unused *str)
592 struct thread_data *td = data;
594 if (!td->files_index)
597 return add_dir_files(td, td->o.opendir);
600 static int str_verify_offset_cb(void *data, unsigned int *off)
602 struct thread_data *td = data;
604 if (*off && *off < sizeof(struct verify_header)) {
605 log_err("fio: verify_offset too small\n");
609 td->o.verify_offset = *off;
613 static int str_verify_pattern_cb(void *data, const char *input)
615 struct thread_data *td = data;
617 int i = 0, j = 0, len, k, base = 10;
620 loc1 = strstr(input, "0x");
621 loc2 = strstr(input, "0X");
624 off = strtol(input, NULL, base);
625 if (off != LONG_MAX || errno != ERANGE) {
627 td->o.verify_pattern[i] = off & 0xff;
636 j = loc1 - input + 2;
638 j = loc2 - input + 2;
641 if (len - j < MAX_PATTERN_SIZE * 2) {
643 off = converthexchartoint(input[k--]);
645 off += (converthexchartoint(input[k--])
647 td->o.verify_pattern[i++] = (char) off;
651 td->o.verify_pattern_bytes = i;
655 static int str_lockfile_cb(void *data, const char *str)
657 struct thread_data *td = data;
658 char *nr = get_opt_postfix(str);
660 td->o.lockfile_batch = 1;
662 td->o.lockfile_batch = atoi(nr);
669 static int str_write_bw_log_cb(void *data, const char *str)
671 struct thread_data *td = data;
674 td->o.bw_log_file = strdup(str);
676 td->o.write_bw_log = 1;
680 static int str_write_lat_log_cb(void *data, const char *str)
682 struct thread_data *td = data;
685 td->o.lat_log_file = strdup(str);
687 td->o.write_lat_log = 1;
691 static int str_gtod_reduce_cb(void *data, int *il)
693 struct thread_data *td = data;
696 td->o.disable_clat = !!val;
697 td->o.disable_slat = !!val;
698 td->o.disable_bw = !!val;
700 td->tv_cache_mask = 63;
705 static int str_gtod_cpu_cb(void *data, int *il)
707 struct thread_data *td = data;
710 td->o.gtod_cpu = val;
711 td->o.gtod_offload = 1;
715 static int rw_verify(struct fio_option *o, void *data)
717 struct thread_data *td = data;
719 if (read_only && td_write(td)) {
720 log_err("fio: job <%s> has write bit set, but fio is in"
721 " read-only mode\n", td->o.name);
728 static int gtod_cpu_verify(struct fio_option *o, void *data)
730 #ifndef FIO_HAVE_CPU_AFFINITY
731 struct thread_data *td = data;
733 if (td->o.gtod_cpu) {
734 log_err("fio: platform must support CPU affinity for"
735 "gettimeofday() offloading\n");
743 static int kb_base_verify(struct fio_option *o, void *data)
745 struct thread_data *td = data;
747 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
748 log_err("fio: kb_base set to nonsensical value: %u\n",
756 #define __stringify_1(x) #x
757 #define __stringify(x) __stringify_1(x)
760 * Map of job/command line options
762 static struct fio_option options[FIO_MAX_OPTS] = {
764 .name = "description",
765 .type = FIO_OPT_STR_STORE,
766 .off1 = td_var_offset(description),
767 .help = "Text job description",
771 .type = FIO_OPT_STR_STORE,
772 .off1 = td_var_offset(name),
773 .help = "Name of this job",
777 .type = FIO_OPT_STR_STORE,
778 .off1 = td_var_offset(directory),
779 .cb = str_directory_cb,
780 .help = "Directory to store files in",
784 .type = FIO_OPT_STR_STORE,
785 .off1 = td_var_offset(filename),
786 .cb = str_filename_cb,
787 .prio = -1, /* must come after "directory" */
788 .help = "File(s) to use for the workload",
793 .off1 = td_var_offset(kb_base),
794 .verify = kb_base_verify,
797 .help = "How many bytes per KB for reporting (1000 or 1024)",
802 .cb = str_lockfile_cb,
803 .off1 = td_var_offset(file_lock_mode),
804 .help = "Lock file when doing IO to it",
805 .parent = "filename",
809 .oval = FILE_LOCK_NONE,
810 .help = "No file locking",
812 { .ival = "exclusive",
813 .oval = FILE_LOCK_EXCLUSIVE,
814 .help = "Exclusive file lock",
818 .oval = FILE_LOCK_READWRITE,
819 .help = "Read vs write lock",
825 .type = FIO_OPT_STR_STORE,
826 .off1 = td_var_offset(opendir),
827 .cb = str_opendir_cb,
828 .help = "Recursively add files from this directory and down",
832 .alias = "readwrite",
835 .off1 = td_var_offset(td_ddir),
836 .help = "IO direction",
841 .oval = TD_DDIR_READ,
842 .help = "Sequential read",
845 .oval = TD_DDIR_WRITE,
846 .help = "Sequential write",
848 { .ival = "randread",
849 .oval = TD_DDIR_RANDREAD,
850 .help = "Random read",
852 { .ival = "randwrite",
853 .oval = TD_DDIR_RANDWRITE,
854 .help = "Random write",
858 .help = "Sequential read and write mix",
861 .oval = TD_DDIR_RANDRW,
862 .help = "Random read and write mix"
868 .type = FIO_OPT_STR_STORE,
869 .off1 = td_var_offset(ioengine),
870 .help = "IO engine to use",
874 .help = "Use read/write",
877 .help = "Use pread/pwrite",
880 .help = "Use readv/writev",
882 #ifdef FIO_HAVE_LIBAIO
884 .help = "Linux native asynchronous IO",
887 #ifdef FIO_HAVE_POSIXAIO
888 { .ival = "posixaio",
889 .help = "POSIX asynchronous IO",
892 #ifdef FIO_HAVE_SOLARISAIO
893 { .ival = "solarisaio",
894 .help = "Solaris native asynchronous IO",
898 .help = "Memory mapped IO",
900 #ifdef FIO_HAVE_SPLICE
902 .help = "splice/vmsplice based IO",
904 { .ival = "netsplice",
905 .help = "splice/vmsplice to/from the network",
910 .help = "SCSI generic v3 IO",
914 .help = "Testing engine (no data transfer)",
917 .help = "Network IO",
919 #ifdef FIO_HAVE_SYSLET
920 { .ival = "syslet-rw",
921 .help = "syslet enabled async pread/pwrite IO",
925 .help = "CPU cycler burner engine",
927 #ifdef FIO_HAVE_GUASI
929 .help = "GUASI IO engine",
932 { .ival = "external",
933 .help = "Load external engine (append name)",
940 .off1 = td_var_offset(iodepth),
941 .help = "Amount of IO buffers to keep in flight",
946 .name = "iodepth_batch",
947 .alias = "iodepth_batch_submit",
949 .off1 = td_var_offset(iodepth_batch),
950 .help = "Number of IO buffers to submit in one go",
956 .name = "iodepth_batch_complete",
958 .off1 = td_var_offset(iodepth_batch_complete),
959 .help = "Number of IO buffers to retrieve in one go",
965 .name = "iodepth_low",
967 .off1 = td_var_offset(iodepth_low),
968 .help = "Low water mark for queuing depth",
973 .type = FIO_OPT_STR_VAL,
974 .off1 = td_var_offset(size),
976 .help = "Total size of device or files",
979 .name = "fill_device",
980 .type = FIO_OPT_BOOL,
981 .off1 = td_var_offset(fill_device),
982 .help = "Write until an ENOSPC error occurs",
987 .type = FIO_OPT_STR_VAL,
988 .off1 = td_var_offset(file_size_low),
989 .off2 = td_var_offset(file_size_high),
991 .help = "Size of individual files",
995 .alias = "fileoffset",
996 .type = FIO_OPT_STR_VAL,
997 .off1 = td_var_offset(start_offset),
998 .help = "Start IO from this offset",
1003 .alias = "blocksize",
1004 .type = FIO_OPT_INT,
1005 .off1 = td_var_offset(bs[DDIR_READ]),
1006 .off2 = td_var_offset(bs[DDIR_WRITE]),
1008 .help = "Block size unit",
1014 .alias = "blockalign",
1015 .type = FIO_OPT_INT,
1016 .off1 = td_var_offset(ba[DDIR_READ]),
1017 .off2 = td_var_offset(ba[DDIR_WRITE]),
1019 .help = "IO block offset alignment",
1024 .alias = "blocksize_range",
1025 .type = FIO_OPT_RANGE,
1026 .off1 = td_var_offset(min_bs[DDIR_READ]),
1027 .off2 = td_var_offset(max_bs[DDIR_READ]),
1028 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1029 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1031 .help = "Set block size range (in more detail than bs)",
1036 .type = FIO_OPT_STR,
1037 .cb = str_bssplit_cb,
1038 .help = "Set a specific mix of block sizes",
1042 .name = "bs_unaligned",
1043 .alias = "blocksize_unaligned",
1044 .type = FIO_OPT_STR_SET,
1045 .off1 = td_var_offset(bs_unaligned),
1046 .help = "Don't sector align IO buffer sizes",
1050 .name = "randrepeat",
1051 .type = FIO_OPT_BOOL,
1052 .off1 = td_var_offset(rand_repeatable),
1053 .help = "Use repeatable random IO pattern",
1058 .name = "norandommap",
1059 .type = FIO_OPT_STR_SET,
1060 .off1 = td_var_offset(norandommap),
1061 .help = "Accept potential duplicate random blocks",
1065 .name = "softrandommap",
1066 .type = FIO_OPT_BOOL,
1067 .off1 = td_var_offset(softrandommap),
1068 .help = "Set norandommap if randommap allocation fails",
1069 .parent = "norandommap",
1074 .type = FIO_OPT_INT,
1075 .off1 = td_var_offset(nr_files),
1076 .help = "Split job workload between this number of files",
1080 .name = "openfiles",
1081 .type = FIO_OPT_INT,
1082 .off1 = td_var_offset(open_files),
1083 .help = "Number of files to keep open at the same time",
1086 .name = "file_service_type",
1087 .type = FIO_OPT_STR,
1089 .off1 = td_var_offset(file_service_type),
1090 .help = "How to select which file to service next",
1091 .def = "roundrobin",
1094 .oval = FIO_FSERVICE_RANDOM,
1095 .help = "Choose a file at random",
1097 { .ival = "roundrobin",
1098 .oval = FIO_FSERVICE_RR,
1099 .help = "Round robin select files",
1101 { .ival = "sequential",
1102 .oval = FIO_FSERVICE_SEQ,
1103 .help = "Finish one file before moving to the next",
1106 .parent = "nrfiles",
1108 #ifdef FIO_HAVE_FALLOCATE
1110 .name = "fallocate",
1111 .type = FIO_OPT_BOOL,
1112 .off1 = td_var_offset(fallocate),
1113 .help = "Use fallocate() when laying out files",
1118 .name = "fadvise_hint",
1119 .type = FIO_OPT_BOOL,
1120 .off1 = td_var_offset(fadvise_hint),
1121 .help = "Use fadvise() to advise the kernel on IO pattern",
1126 .type = FIO_OPT_INT,
1127 .off1 = td_var_offset(fsync_blocks),
1128 .help = "Issue fsync for writes every given number of blocks",
1132 .name = "fdatasync",
1133 .type = FIO_OPT_INT,
1134 .off1 = td_var_offset(fdatasync_blocks),
1135 .help = "Issue fdatasync for writes every given number of blocks",
1138 #ifdef FIO_HAVE_SYNC_FILE_RANGE
1140 .name = "sync_file_range",
1142 { .ival = "wait_before",
1143 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1144 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1148 .oval = SYNC_FILE_RANGE_WRITE,
1149 .help = "SYNC_FILE_RANGE_WRITE",
1153 .ival = "wait_after",
1154 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1155 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1159 .type = FIO_OPT_STR_MULTI,
1161 .off1 = td_var_offset(sync_file_range),
1162 .help = "Use sync_file_range()",
1167 .type = FIO_OPT_BOOL,
1168 .off1 = td_var_offset(odirect),
1169 .help = "Use O_DIRECT IO (negates buffered)",
1174 .type = FIO_OPT_BOOL,
1175 .off1 = td_var_offset(odirect),
1177 .help = "Use buffered IO (negates direct)",
1181 .name = "overwrite",
1182 .type = FIO_OPT_BOOL,
1183 .off1 = td_var_offset(overwrite),
1184 .help = "When writing, set whether to overwrite current data",
1189 .type = FIO_OPT_INT,
1190 .off1 = td_var_offset(loops),
1191 .help = "Number of times to run the job",
1196 .type = FIO_OPT_INT,
1197 .off1 = td_var_offset(numjobs),
1198 .help = "Duplicate this job this many times",
1202 .name = "startdelay",
1203 .type = FIO_OPT_INT,
1204 .off1 = td_var_offset(start_delay),
1205 .help = "Only start job when this period has passed",
1211 .type = FIO_OPT_STR_VAL_TIME,
1212 .off1 = td_var_offset(timeout),
1213 .help = "Stop workload when this amount of time has passed",
1217 .name = "time_based",
1218 .type = FIO_OPT_STR_SET,
1219 .off1 = td_var_offset(time_based),
1220 .help = "Keep running until runtime/timeout is met",
1223 .name = "ramp_time",
1224 .type = FIO_OPT_STR_VAL_TIME,
1225 .off1 = td_var_offset(ramp_time),
1226 .help = "Ramp up time before measuring performance",
1229 .name = "clocksource",
1230 .type = FIO_OPT_STR,
1231 .cb = fio_clock_source_cb,
1232 .off1 = td_var_offset(clocksource),
1233 .help = "What type of timing source to use",
1235 { .ival = "gettimeofday",
1237 .help = "Use gettimeofday(2) for timing",
1239 { .ival = "clock_gettime",
1240 .oval = CS_CGETTIME,
1241 .help = "Use clock_gettime(2) for timing",
1243 #ifdef ARCH_HAVE_CPU_CLOCK
1245 .oval = CS_CPUCLOCK,
1246 .help = "Use CPU private clock",
1254 .type = FIO_OPT_STR,
1256 .off1 = td_var_offset(mem_type),
1257 .help = "Backing type for IO buffers",
1262 .help = "Use malloc(3) for IO buffers",
1266 .help = "Use shared memory segments for IO buffers",
1268 #ifdef FIO_HAVE_HUGETLB
1269 { .ival = "shmhuge",
1270 .oval = MEM_SHMHUGE,
1271 .help = "Like shm, but use huge pages",
1276 .help = "Use mmap(2) (file or anon) for IO buffers",
1278 #ifdef FIO_HAVE_HUGETLB
1279 { .ival = "mmaphuge",
1280 .oval = MEM_MMAPHUGE,
1281 .help = "Like mmap, but use huge pages",
1287 .name = "iomem_align",
1288 .alias = "mem_align",
1289 .type = FIO_OPT_INT,
1290 .off1 = td_var_offset(mem_align),
1292 .help = "IO memory buffer offset alignment",
1298 .type = FIO_OPT_STR,
1299 .off1 = td_var_offset(verify),
1300 .help = "Verify data written",
1304 .oval = VERIFY_NONE,
1305 .help = "Don't do IO verification",
1309 .help = "Use md5 checksums for verification",
1312 .oval = VERIFY_CRC64,
1313 .help = "Use crc64 checksums for verification",
1316 .oval = VERIFY_CRC32,
1317 .help = "Use crc32 checksums for verification",
1319 { .ival = "crc32c-intel",
1320 .oval = VERIFY_CRC32C_INTEL,
1321 .help = "Use hw crc32c checksums for verification",
1324 .oval = VERIFY_CRC32C,
1325 .help = "Use crc32c checksums for verification",
1328 .oval = VERIFY_CRC16,
1329 .help = "Use crc16 checksums for verification",
1332 .oval = VERIFY_CRC7,
1333 .help = "Use crc7 checksums for verification",
1336 .oval = VERIFY_SHA1,
1337 .help = "Use sha1 checksums for verification",
1340 .oval = VERIFY_SHA256,
1341 .help = "Use sha256 checksums for verification",
1344 .oval = VERIFY_SHA512,
1345 .help = "Use sha512 checksums for verification",
1348 .oval = VERIFY_META,
1349 .help = "Use io information",
1353 .oval = VERIFY_NULL,
1354 .help = "Pretend to verify",
1359 .name = "do_verify",
1360 .type = FIO_OPT_BOOL,
1361 .off1 = td_var_offset(do_verify),
1362 .help = "Run verification stage after write",
1367 .name = "verifysort",
1368 .type = FIO_OPT_BOOL,
1369 .off1 = td_var_offset(verifysort),
1370 .help = "Sort written verify blocks for read back",
1375 .name = "verify_interval",
1376 .type = FIO_OPT_INT,
1377 .off1 = td_var_offset(verify_interval),
1378 .minval = 2 * sizeof(struct verify_header),
1379 .help = "Store verify buffer header every N bytes",
1383 .name = "verify_offset",
1384 .type = FIO_OPT_INT,
1385 .help = "Offset verify header location by N bytes",
1387 .cb = str_verify_offset_cb,
1391 .name = "verify_pattern",
1392 .type = FIO_OPT_STR,
1393 .cb = str_verify_pattern_cb,
1394 .help = "Fill pattern for IO buffers",
1398 .name = "verify_fatal",
1399 .type = FIO_OPT_BOOL,
1400 .off1 = td_var_offset(verify_fatal),
1402 .help = "Exit on a single verify failure, don't continue",
1406 .name = "verify_async",
1407 .type = FIO_OPT_INT,
1408 .off1 = td_var_offset(verify_async),
1410 .help = "Number of async verifier threads to use",
1413 #ifdef FIO_HAVE_CPU_AFFINITY
1415 .name = "verify_async_cpus",
1416 .type = FIO_OPT_STR,
1417 .cb = str_verify_cpus_allowed_cb,
1418 .help = "Set CPUs allowed for async verify threads",
1419 .parent = "verify_async",
1423 .name = "write_iolog",
1424 .type = FIO_OPT_STR_STORE,
1425 .off1 = td_var_offset(write_iolog_file),
1426 .help = "Store IO pattern to file",
1429 .name = "read_iolog",
1430 .type = FIO_OPT_STR_STORE,
1431 .off1 = td_var_offset(read_iolog_file),
1432 .help = "Playback IO pattern from file",
1435 .name = "exec_prerun",
1436 .type = FIO_OPT_STR_STORE,
1437 .off1 = td_var_offset(exec_prerun),
1438 .help = "Execute this file prior to running job",
1441 .name = "exec_postrun",
1442 .type = FIO_OPT_STR_STORE,
1443 .off1 = td_var_offset(exec_postrun),
1444 .help = "Execute this file after running job",
1446 #ifdef FIO_HAVE_IOSCHED_SWITCH
1448 .name = "ioscheduler",
1449 .type = FIO_OPT_STR_STORE,
1450 .off1 = td_var_offset(ioscheduler),
1451 .help = "Use this IO scheduler on the backing device",
1456 .type = FIO_OPT_STR_VAL,
1457 .off1 = td_var_offset(zone_size),
1458 .help = "Give size of an IO zone",
1463 .type = FIO_OPT_STR_VAL,
1464 .off1 = td_var_offset(zone_skip),
1465 .help = "Space between IO zones",
1470 .type = FIO_OPT_STR_VAL,
1471 .cb = str_lockmem_cb,
1472 .help = "Lock down this amount of memory",
1476 .name = "rwmixread",
1477 .type = FIO_OPT_INT,
1478 .cb = str_rwmix_read_cb,
1480 .help = "Percentage of mixed workload that is reads",
1484 .name = "rwmixwrite",
1485 .type = FIO_OPT_INT,
1486 .cb = str_rwmix_write_cb,
1488 .help = "Percentage of mixed workload that is writes",
1492 .name = "rwmixcycle",
1493 .type = FIO_OPT_DEPRECATED,
1497 .type = FIO_OPT_INT,
1498 .off1 = td_var_offset(nice),
1499 .help = "Set job CPU nice value",
1504 #ifdef FIO_HAVE_IOPRIO
1507 .type = FIO_OPT_INT,
1509 .help = "Set job IO priority value",
1514 .name = "prioclass",
1515 .type = FIO_OPT_INT,
1516 .cb = str_prioclass_cb,
1517 .help = "Set job IO priority class",
1523 .name = "thinktime",
1524 .type = FIO_OPT_INT,
1525 .off1 = td_var_offset(thinktime),
1526 .help = "Idle time between IO buffers (usec)",
1530 .name = "thinktime_spin",
1531 .type = FIO_OPT_INT,
1532 .off1 = td_var_offset(thinktime_spin),
1533 .help = "Start think time by spinning this amount (usec)",
1535 .parent = "thinktime",
1538 .name = "thinktime_blocks",
1539 .type = FIO_OPT_INT,
1540 .off1 = td_var_offset(thinktime_blocks),
1541 .help = "IO buffer period between 'thinktime'",
1543 .parent = "thinktime",
1547 .type = FIO_OPT_INT,
1548 .off1 = td_var_offset(rate[0]),
1549 .off2 = td_var_offset(rate[1]),
1550 .help = "Set bandwidth rate",
1554 .type = FIO_OPT_INT,
1555 .off1 = td_var_offset(ratemin[0]),
1556 .off2 = td_var_offset(ratemin[1]),
1557 .help = "Job must meet this rate or it will be shutdown",
1561 .name = "rate_iops",
1562 .type = FIO_OPT_INT,
1563 .off1 = td_var_offset(rate_iops[0]),
1564 .off2 = td_var_offset(rate_iops[1]),
1565 .help = "Limit IO used to this number of IO operations/sec",
1568 .name = "rate_iops_min",
1569 .type = FIO_OPT_INT,
1570 .off1 = td_var_offset(rate_iops_min[0]),
1571 .off2 = td_var_offset(rate_iops_min[1]),
1572 .help = "Job must meet this rate or it will be shutdown",
1573 .parent = "rate_iops",
1576 .name = "ratecycle",
1577 .type = FIO_OPT_INT,
1578 .off1 = td_var_offset(ratecycle),
1579 .help = "Window average for rate limits (msec)",
1584 .name = "invalidate",
1585 .type = FIO_OPT_BOOL,
1586 .off1 = td_var_offset(invalidate_cache),
1587 .help = "Invalidate buffer/page cache prior to running job",
1592 .type = FIO_OPT_BOOL,
1593 .off1 = td_var_offset(sync_io),
1594 .help = "Use O_SYNC for buffered writes",
1596 .parent = "buffered",
1599 .name = "bwavgtime",
1600 .type = FIO_OPT_INT,
1601 .off1 = td_var_offset(bw_avg_time),
1602 .help = "Time window over which to calculate bandwidth"
1607 .name = "create_serialize",
1608 .type = FIO_OPT_BOOL,
1609 .off1 = td_var_offset(create_serialize),
1610 .help = "Serialize creating of job files",
1614 .name = "create_fsync",
1615 .type = FIO_OPT_BOOL,
1616 .off1 = td_var_offset(create_fsync),
1617 .help = "Fsync file after creation",
1621 .name = "create_on_open",
1622 .type = FIO_OPT_BOOL,
1623 .off1 = td_var_offset(create_on_open),
1624 .help = "Create files when they are opened for IO",
1629 .type = FIO_OPT_BOOL,
1630 .off1 = td_var_offset(pre_read),
1631 .help = "Preread files before starting official testing",
1636 .type = FIO_OPT_INT,
1637 .off1 = td_var_offset(cpuload),
1638 .help = "Use this percentage of CPU",
1641 .name = "cpuchunks",
1642 .type = FIO_OPT_INT,
1643 .off1 = td_var_offset(cpucycle),
1644 .help = "Length of the CPU burn cycles (usecs)",
1646 .parent = "cpuload",
1648 #ifdef FIO_HAVE_CPU_AFFINITY
1651 .type = FIO_OPT_INT,
1652 .cb = str_cpumask_cb,
1653 .help = "CPU affinity mask",
1656 .name = "cpus_allowed",
1657 .type = FIO_OPT_STR,
1658 .cb = str_cpus_allowed_cb,
1659 .help = "Set CPUs allowed",
1663 .name = "end_fsync",
1664 .type = FIO_OPT_BOOL,
1665 .off1 = td_var_offset(end_fsync),
1666 .help = "Include fsync at the end of job",
1670 .name = "fsync_on_close",
1671 .type = FIO_OPT_BOOL,
1672 .off1 = td_var_offset(fsync_on_close),
1673 .help = "fsync files on close",
1678 .type = FIO_OPT_BOOL,
1679 .off1 = td_var_offset(unlink),
1680 .help = "Unlink created files after job has completed",
1685 .type = FIO_OPT_STR_SET,
1686 .cb = str_exitall_cb,
1687 .help = "Terminate all jobs when one exits",
1690 .name = "stonewall",
1691 .type = FIO_OPT_STR_SET,
1692 .off1 = td_var_offset(stonewall),
1693 .help = "Insert a hard barrier between this job and previous",
1696 .name = "new_group",
1697 .type = FIO_OPT_STR_SET,
1698 .off1 = td_var_offset(new_group),
1699 .help = "Mark the start of a new group (for reporting)",
1703 .type = FIO_OPT_STR_SET,
1704 .off1 = td_var_offset(use_thread),
1705 .help = "Use threads instead of forks",
1708 .name = "write_bw_log",
1709 .type = FIO_OPT_STR,
1710 .off1 = td_var_offset(write_bw_log),
1711 .cb = str_write_bw_log_cb,
1712 .help = "Write log of bandwidth during run",
1715 .name = "write_lat_log",
1716 .type = FIO_OPT_STR,
1717 .off1 = td_var_offset(write_lat_log),
1718 .cb = str_write_lat_log_cb,
1719 .help = "Write log of latency during run",
1722 .name = "hugepage-size",
1723 .type = FIO_OPT_INT,
1724 .off1 = td_var_offset(hugepage_size),
1725 .help = "When using hugepages, specify size of each page",
1726 .def = __stringify(FIO_HUGE_PAGE),
1729 .name = "group_reporting",
1730 .type = FIO_OPT_STR_SET,
1731 .off1 = td_var_offset(group_reporting),
1732 .help = "Do reporting on a per-group basis",
1735 .name = "zero_buffers",
1736 .type = FIO_OPT_STR_SET,
1737 .off1 = td_var_offset(zero_buffers),
1738 .help = "Init IO buffers to all zeroes",
1741 .name = "refill_buffers",
1742 .type = FIO_OPT_STR_SET,
1743 .off1 = td_var_offset(refill_buffers),
1744 .help = "Refill IO buffers on every IO submit",
1746 #ifdef FIO_HAVE_DISK_UTIL
1748 .name = "disk_util",
1749 .type = FIO_OPT_BOOL,
1750 .off1 = td_var_offset(do_disk_util),
1751 .help = "Log disk utilization statistics",
1756 .name = "gtod_reduce",
1757 .type = FIO_OPT_BOOL,
1758 .help = "Greatly reduce number of gettimeofday() calls",
1759 .cb = str_gtod_reduce_cb,
1763 .name = "disable_clat",
1764 .type = FIO_OPT_BOOL,
1765 .off1 = td_var_offset(disable_clat),
1766 .help = "Disable completion latency numbers",
1767 .parent = "gtod_reduce",
1771 .name = "disable_slat",
1772 .type = FIO_OPT_BOOL,
1773 .off1 = td_var_offset(disable_slat),
1774 .help = "Disable submissionn latency numbers",
1775 .parent = "gtod_reduce",
1779 .name = "disable_bw_measurement",
1780 .type = FIO_OPT_BOOL,
1781 .off1 = td_var_offset(disable_bw),
1782 .help = "Disable bandwidth logging",
1783 .parent = "gtod_reduce",
1788 .type = FIO_OPT_INT,
1789 .cb = str_gtod_cpu_cb,
1790 .help = "Setup dedicated gettimeofday() thread on this CPU",
1791 .verify = gtod_cpu_verify,
1794 .name = "continue_on_error",
1795 .type = FIO_OPT_BOOL,
1796 .off1 = td_var_offset(continue_on_error),
1797 .help = "Continue on non-fatal errors during I/O",
1802 .type = FIO_OPT_STR_STORE,
1803 .off1 = td_var_offset(profile),
1804 .help = "Select a specific builtin performance test",
1808 .type = FIO_OPT_STR_STORE,
1809 .off1 = td_var_offset(cgroup),
1810 .help = "Add job to cgroup of this name",
1813 .name = "cgroup_weight",
1814 .type = FIO_OPT_INT,
1815 .off1 = td_var_offset(cgroup_weight),
1816 .help = "Use given weight for cgroup",
1822 .type = FIO_OPT_INT,
1823 .off1 = td_var_offset(uid),
1824 .help = "Run job with this user ID",
1828 .type = FIO_OPT_INT,
1829 .off1 = td_var_offset(gid),
1830 .help = "Run job with this group ID",
1837 static void add_to_lopt(struct option *lopt, struct fio_option *o)
1839 lopt->name = (char *) o->name;
1840 lopt->val = FIO_GETOPT_JOB;
1841 if (o->type == FIO_OPT_STR_SET)
1842 lopt->has_arg = no_argument;
1844 lopt->has_arg = required_argument;
1847 void fio_options_dup_and_init(struct option *long_options)
1849 struct fio_option *o;
1852 options_init(options);
1855 while (long_options[i].name)
1860 add_to_lopt(&long_options[i], o);
1864 assert(i < FIO_NR_OPTIONS);
1868 struct fio_keyword {
1874 static struct fio_keyword fio_keywords[] = {
1876 .word = "$pagesize",
1877 .desc = "Page size in the system",
1880 .word = "$mb_memory",
1881 .desc = "Megabytes of memory online",
1885 .desc = "Number of CPUs online in the system",
1892 void fio_keywords_init(void)
1894 unsigned long long mb_memory;
1898 sprintf(buf, "%lu", page_size);
1899 fio_keywords[0].replace = strdup(buf);
1901 mb_memory = os_phys_mem() / page_size;
1902 sprintf(buf, "%llu", mb_memory);
1903 fio_keywords[1].replace = strdup(buf);
1905 l = sysconf(_SC_NPROCESSORS_ONLN);
1906 sprintf(buf, "%lu", l);
1907 fio_keywords[2].replace = strdup(buf);
1912 static char *bc_calc(char *str)
1914 char *buf, *tmp, opt[80];
1919 * No math, just return string
1921 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1926 * Split option from value, we only need to calculate the value
1928 tmp = strchr(str, '=');
1933 memset(opt, 0, sizeof(opt));
1934 strncpy(opt, str, tmp - str);
1938 sprintf(buf, "which %s > /dev/null", BC_APP);
1940 log_err("fio: bc is needed for performing math\n");
1945 sprintf(buf, "echo %s | %s", tmp, BC_APP);
1946 f = popen(buf, "r");
1952 ret = fread(buf, 1, 128, f);
1958 buf[ret - 1] = '\0';
1967 * Look for reserved variable names and replace them with real values
1969 static char *fio_keyword_replace(char *opt)
1974 for (i = 0; fio_keywords[i].word != NULL; i++) {
1975 struct fio_keyword *kw = &fio_keywords[i];
1977 while ((s = strstr(opt, kw->word)) != NULL) {
1978 char *new = malloc(strlen(opt) + 1);
1984 * Copy part of the string before the keyword and
1985 * sprintf() the replacement after it.
1987 memcpy(new, opt, olen);
1988 len = sprintf(new + olen, "%s", kw->replace);
1991 * If there's more in the original string, copy that
1994 opt += strlen(kw->word) + olen;
1996 memcpy(new + olen + len, opt, opt - o_org - 1);
1999 * replace opt and free the old opt
2005 * Check for potential math and invoke bc, if possible
2014 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2018 sort_options(opts, options, num_opts);
2020 for (ret = 0, i = 0; i < num_opts; i++) {
2021 opts[i] = fio_keyword_replace(opts[i]);
2022 ret |= parse_option(opts[i], options, td);
2028 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2030 return parse_cmd_option(opt, val, options, td);
2033 void fio_fill_default_options(struct thread_data *td)
2035 fill_default_options(td, options);
2038 int fio_show_option_help(const char *opt)
2040 return show_cmd_help(options, opt);
2043 static void __options_mem(struct thread_data *td, int alloc)
2045 struct thread_options *o = &td->o;
2046 struct fio_option *opt;
2050 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2051 if (opt->type != FIO_OPT_STR_STORE)
2054 ptr = (void *) o + opt->off1;
2057 *ptr = strdup(*ptr);
2067 * dupe FIO_OPT_STR_STORE options
2069 void options_mem_dupe(struct thread_data *td)
2071 __options_mem(td, 1);
2074 void options_mem_free(struct thread_data fio_unused *td)
2077 __options_mem(td, 0);
2081 unsigned int fio_get_kb_base(void *data)
2083 struct thread_data *td = data;
2084 unsigned int kb_base = 0;
2087 kb_base = td->o.kb_base;
2094 int add_option(struct fio_option *o)
2096 struct fio_option *__o;
2105 memcpy(&options[opt_index], o, sizeof(*o));
2109 void invalidate_profile_options(const char *prof_name)
2111 struct fio_option *o;
2115 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2116 o->type = FIO_OPT_INVALID;
2117 o->prof_name = NULL;
2123 void add_opt_posval(const char *optname, const char *ival, const char *help)
2125 struct fio_option *o;
2128 o = find_option(options, optname);
2132 for (i = 0; i < PARSE_MAX_VP; i++) {
2133 if (o->posval[i].ival)
2136 o->posval[i].ival = ival;
2137 o->posval[i].help = help;
2142 void del_opt_posval(const char *optname, const char *ival)
2144 struct fio_option *o;
2147 o = find_option(options, optname);
2151 for (i = 0; i < PARSE_MAX_VP; i++) {
2152 if (!o->posval[i].ival)
2154 if (strcmp(o->posval[i].ival, ival))
2157 o->posval[i].ival = NULL;
2158 o->posval[i].help = NULL;