18 #include "crc/crc32c.h"
21 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
23 static char *get_opt_postfix(const char *str)
25 char *p = strstr(str, ":");
31 strip_blank_front(&p);
36 static int converthexchartoint(char a)
56 static int bs_cmp(const void *p1, const void *p2)
58 const struct bssplit *bsp1 = p1;
59 const struct bssplit *bsp2 = p2;
61 return bsp1->perc < bsp2->perc;
64 static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
66 struct bssplit *bssplit;
67 unsigned int i, perc, perc_missing;
68 unsigned int max_bs, min_bs;
72 td->o.bssplit_nr[ddir] = 4;
73 bssplit = malloc(4 * sizeof(struct bssplit));
78 while ((fname = strsep(&str, ":")) != NULL) {
85 * grow struct buffer, if needed
87 if (i == td->o.bssplit_nr[ddir]) {
88 td->o.bssplit_nr[ddir] <<= 1;
89 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
90 * sizeof(struct bssplit));
93 perc_str = strstr(fname, "/");
97 perc = atoi(perc_str);
105 if (str_to_decimal(fname, &val, 1, td)) {
106 log_err("fio: bssplit conversion failed\n");
117 bssplit[i].perc = perc;
121 td->o.bssplit_nr[ddir] = i;
124 * Now check if the percentages add up, and how much is missing
126 perc = perc_missing = 0;
127 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
128 struct bssplit *bsp = &bssplit[i];
130 if (bsp->perc == (unsigned char) -1)
137 log_err("fio: bssplit percentages add to more than 100%%\n");
142 * If values didn't have a percentage set, divide the remains between
146 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
147 struct bssplit *bsp = &bssplit[i];
149 if (bsp->perc == (unsigned char) -1)
150 bsp->perc = (100 - perc) / perc_missing;
154 td->o.min_bs[ddir] = min_bs;
155 td->o.max_bs[ddir] = max_bs;
158 * now sort based on percentages, for ease of lookup
160 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 td->o.bssplit[ddir] = bssplit;
166 static int str_bssplit_cb(void *data, const char *input)
168 struct thread_data *td = data;
169 char *str, *p, *odir, *ddir;
172 p = str = strdup(input);
174 strip_blank_front(&str);
175 strip_blank_end(str);
177 odir = strchr(str, ',');
179 ddir = strchr(odir + 1, ',');
181 ret = bssplit_ddir(td, DDIR_TRIM, ddir + 1);
187 op = strdup(odir + 1);
188 ret = bssplit_ddir(td, DDIR_TRIM, op);
193 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
196 ret = bssplit_ddir(td, DDIR_READ, str);
202 ret = bssplit_ddir(td, DDIR_WRITE, op);
207 ret = bssplit_ddir(td, DDIR_TRIM, op);
210 ret = bssplit_ddir(td, DDIR_READ, str);
217 static int str_rw_cb(void *data, const char *str)
219 struct thread_data *td = data;
220 char *nr = get_opt_postfix(str);
222 td->o.ddir_seq_nr = 1;
223 td->o.ddir_seq_add = 0;
229 td->o.ddir_seq_nr = atoi(nr);
233 if (str_to_decimal(nr, &val, 1, td)) {
234 log_err("fio: rw postfix parsing failed\n");
239 td->o.ddir_seq_add = val;
246 static int str_mem_cb(void *data, const char *mem)
248 struct thread_data *td = data;
250 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
251 td->mmapfile = get_opt_postfix(mem);
252 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
253 log_err("fio: mmaphuge:/path/to/file\n");
261 static int str_verify_cb(void *data, const char *mem)
263 struct thread_data *td = data;
265 if (td->o.verify == VERIFY_CRC32C_INTEL ||
266 td->o.verify == VERIFY_CRC32C) {
267 crc32c_intel_probe();
273 static int fio_clock_source_cb(void *data, const char *str)
275 struct thread_data *td = data;
277 fio_clock_source = td->o.clocksource;
282 static int str_lockmem_cb(void fio_unused *data, unsigned long long *val)
288 static int str_rwmix_read_cb(void *data, unsigned long long *val)
290 struct thread_data *td = data;
292 td->o.rwmix[DDIR_READ] = *val;
293 td->o.rwmix[DDIR_WRITE] = 100 - *val;
297 static int str_rwmix_write_cb(void *data, unsigned long long *val)
299 struct thread_data *td = data;
301 td->o.rwmix[DDIR_WRITE] = *val;
302 td->o.rwmix[DDIR_READ] = 100 - *val;
306 #ifdef FIO_HAVE_IOPRIO
307 static int str_prioclass_cb(void *data, unsigned long long *val)
309 struct thread_data *td = data;
313 * mask off old class bits, str_prio_cb() may have set a default class
315 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
318 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
323 static int str_prio_cb(void *data, unsigned long long *val)
325 struct thread_data *td = data;
330 * If no class is set, assume BE
332 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
333 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
340 static int str_exitall_cb(void)
342 exitall_on_terminate = 1;
346 #ifdef FIO_HAVE_CPU_AFFINITY
347 static int str_cpumask_cb(void *data, unsigned long long *val)
349 struct thread_data *td = data;
354 ret = fio_cpuset_init(&td->o.cpumask);
356 log_err("fio: cpuset_init failed\n");
357 td_verror(td, ret, "fio_cpuset_init");
361 max_cpu = cpus_online();
363 for (i = 0; i < sizeof(int) * 8; i++) {
364 if ((1 << i) & *val) {
366 log_err("fio: CPU %d too large (max=%ld)\n", i,
370 dprint(FD_PARSE, "set cpu allowed %d\n", i);
371 fio_cpu_set(&td->o.cpumask, i);
375 td->o.cpumask_set = 1;
379 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
386 ret = fio_cpuset_init(mask);
388 log_err("fio: cpuset_init failed\n");
389 td_verror(td, ret, "fio_cpuset_init");
393 p = str = strdup(input);
395 strip_blank_front(&str);
396 strip_blank_end(str);
398 max_cpu = cpus_online();
400 while ((cpu = strsep(&str, ",")) != NULL) {
409 while ((cpu2 = strsep(&str2, "-")) != NULL) {
419 while (icpu <= icpu2) {
420 if (icpu >= FIO_MAX_CPUS) {
421 log_err("fio: your OS only supports up to"
422 " %d CPUs\n", (int) FIO_MAX_CPUS);
426 if (icpu > max_cpu) {
427 log_err("fio: CPU %d too large (max=%ld)\n",
433 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
434 fio_cpu_set(mask, icpu);
443 td->o.cpumask_set = 1;
447 static int str_cpus_allowed_cb(void *data, const char *input)
449 struct thread_data *td = data;
452 ret = set_cpus_allowed(td, &td->o.cpumask, input);
454 td->o.cpumask_set = 1;
459 static int str_verify_cpus_allowed_cb(void *data, const char *input)
461 struct thread_data *td = data;
464 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
466 td->o.verify_cpumask_set = 1;
473 static int str_verify_trim_cb(void *data, unsigned long long *val)
475 struct thread_data *td = data;
477 td->o.trim_percentage = *val;
482 static int str_fst_cb(void *data, const char *str)
484 struct thread_data *td = data;
485 char *nr = get_opt_postfix(str);
487 td->file_service_nr = 1;
489 td->file_service_nr = atoi(nr);
496 #ifdef FIO_HAVE_SYNC_FILE_RANGE
497 static int str_sfr_cb(void *data, const char *str)
499 struct thread_data *td = data;
500 char *nr = get_opt_postfix(str);
502 td->sync_file_range_nr = 1;
504 td->sync_file_range_nr = atoi(nr);
512 static int check_dir(struct thread_data *td, char *fname)
515 char file[PATH_MAX], *dir;
518 if (td->o.directory) {
519 strcpy(file, td->o.directory);
524 sprintf(file + elen, "%s", fname);
530 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
531 * yet, so we can't do this check right here...
533 if (lstat(dir, &sb) < 0) {
536 log_err("fio: %s is not a directory\n", dir);
537 td_verror(td, ret, "lstat");
541 if (!S_ISDIR(sb.st_mode)) {
542 log_err("fio: %s is not a directory\n", dir);
552 * Return next file in the string. Files are separated with ':'. If the ':'
553 * is escaped with a '\', then that ':' is part of the filename and does not
554 * indicate a new file.
556 static char *get_next_file_name(char **ptr)
561 if (!str || !strlen(str))
567 * No colon, we are done
569 p = strchr(str, ':');
576 * We got a colon, but it's the first character. Skip and
584 if (*(p - 1) != '\\') {
590 memmove(p - 1, p, strlen(p) + 1);
597 static int str_filename_cb(void *data, const char *input)
599 struct thread_data *td = data;
600 char *fname, *str, *p;
602 p = str = strdup(input);
604 strip_blank_front(&str);
605 strip_blank_end(str);
607 if (!td->files_index)
610 while ((fname = get_next_file_name(&str)) != NULL) {
613 if (check_dir(td, fname)) {
625 static int str_directory_cb(void *data, const char fio_unused *str)
627 struct thread_data *td = data;
630 if (lstat(td->o.directory, &sb) < 0) {
633 log_err("fio: %s is not a directory\n", td->o.directory);
634 td_verror(td, ret, "lstat");
637 if (!S_ISDIR(sb.st_mode)) {
638 log_err("fio: %s is not a directory\n", td->o.directory);
645 static int str_opendir_cb(void *data, const char fio_unused *str)
647 struct thread_data *td = data;
649 if (!td->files_index)
652 return add_dir_files(td, td->o.opendir);
655 static int str_verify_offset_cb(void *data, unsigned long long *off)
657 struct thread_data *td = data;
659 if (*off && *off < sizeof(struct verify_header)) {
660 log_err("fio: verify_offset too small\n");
664 td->o.verify_offset = *off;
668 static int str_verify_pattern_cb(void *data, const char *input)
670 struct thread_data *td = data;
672 int i = 0, j = 0, len, k, base = 10;
675 loc1 = strstr(input, "0x");
676 loc2 = strstr(input, "0X");
679 off = strtol(input, NULL, base);
680 if (off != LONG_MAX || errno != ERANGE) {
682 td->o.verify_pattern[i] = off & 0xff;
691 j = loc1 - input + 2;
693 j = loc2 - input + 2;
696 if (len - j < MAX_PATTERN_SIZE * 2) {
698 off = converthexchartoint(input[k--]);
700 off += (converthexchartoint(input[k--])
702 td->o.verify_pattern[i++] = (char) off;
708 * Fill the pattern all the way to the end. This greatly reduces
709 * the number of memcpy's we have to do when verifying the IO.
711 while (i > 1 && i * 2 <= MAX_PATTERN_SIZE) {
712 memcpy(&td->o.verify_pattern[i], &td->o.verify_pattern[0], i);
717 * The code in verify_io_u_pattern assumes a single byte pattern
718 * fills the whole verify pattern buffer.
720 memset(td->o.verify_pattern, td->o.verify_pattern[0],
724 td->o.verify_pattern_bytes = i;
727 * VERIFY_META could already be set
729 if (td->o.verify == VERIFY_NONE)
730 td->o.verify = VERIFY_PATTERN;
735 static int str_lockfile_cb(void *data, const char *str)
737 struct thread_data *td = data;
738 char *nr = get_opt_postfix(str);
740 td->o.lockfile_batch = 1;
742 td->o.lockfile_batch = atoi(nr);
749 static int str_write_bw_log_cb(void *data, const char *str)
751 struct thread_data *td = data;
754 td->o.bw_log_file = strdup(str);
756 td->o.write_bw_log = 1;
760 static int str_write_lat_log_cb(void *data, const char *str)
762 struct thread_data *td = data;
765 td->o.lat_log_file = strdup(str);
767 td->o.write_lat_log = 1;
771 static int str_write_iops_log_cb(void *data, const char *str)
773 struct thread_data *td = data;
776 td->o.iops_log_file = strdup(str);
778 td->o.write_iops_log = 1;
782 static int str_gtod_reduce_cb(void *data, int *il)
784 struct thread_data *td = data;
787 td->o.disable_lat = !!val;
788 td->o.disable_clat = !!val;
789 td->o.disable_slat = !!val;
790 td->o.disable_bw = !!val;
791 td->o.clat_percentiles = !val;
793 td->tv_cache_mask = 63;
798 static int str_gtod_cpu_cb(void *data, long long *il)
800 struct thread_data *td = data;
803 td->o.gtod_cpu = val;
804 td->o.gtod_offload = 1;
808 static int str_size_cb(void *data, unsigned long long *__val)
810 struct thread_data *td = data;
811 unsigned long long v = *__val;
813 if (parse_is_percent(v)) {
815 td->o.size_percent = -1ULL - v;
822 static int rw_verify(struct fio_option *o, void *data)
824 struct thread_data *td = data;
826 if (read_only && td_write(td)) {
827 log_err("fio: job <%s> has write bit set, but fio is in"
828 " read-only mode\n", td->o.name);
835 static int gtod_cpu_verify(struct fio_option *o, void *data)
837 #ifndef FIO_HAVE_CPU_AFFINITY
838 struct thread_data *td = data;
840 if (td->o.gtod_cpu) {
841 log_err("fio: platform must support CPU affinity for"
842 "gettimeofday() offloading\n");
850 static int kb_base_verify(struct fio_option *o, void *data)
852 struct thread_data *td = data;
854 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
855 log_err("fio: kb_base set to nonsensical value: %u\n",
864 * Map of job/command line options
866 static struct fio_option options[FIO_MAX_OPTS] = {
868 .name = "description",
869 .type = FIO_OPT_STR_STORE,
870 .off1 = td_var_offset(description),
871 .help = "Text job description",
875 .type = FIO_OPT_STR_STORE,
876 .off1 = td_var_offset(name),
877 .help = "Name of this job",
881 .type = FIO_OPT_STR_STORE,
882 .off1 = td_var_offset(directory),
883 .cb = str_directory_cb,
884 .help = "Directory to store files in",
888 .type = FIO_OPT_STR_STORE,
889 .off1 = td_var_offset(filename),
890 .cb = str_filename_cb,
891 .prio = -1, /* must come after "directory" */
892 .help = "File(s) to use for the workload",
897 .off1 = td_var_offset(kb_base),
898 .verify = kb_base_verify,
901 .help = "How many bytes per KB for reporting (1000 or 1024)",
906 .cb = str_lockfile_cb,
907 .off1 = td_var_offset(file_lock_mode),
908 .help = "Lock file when doing IO to it",
909 .parent = "filename",
913 .oval = FILE_LOCK_NONE,
914 .help = "No file locking",
916 { .ival = "exclusive",
917 .oval = FILE_LOCK_EXCLUSIVE,
918 .help = "Exclusive file lock",
922 .oval = FILE_LOCK_READWRITE,
923 .help = "Read vs write lock",
929 .type = FIO_OPT_STR_STORE,
930 .off1 = td_var_offset(opendir),
931 .cb = str_opendir_cb,
932 .help = "Recursively add files from this directory and down",
936 .alias = "readwrite",
939 .off1 = td_var_offset(td_ddir),
940 .help = "IO direction",
945 .oval = TD_DDIR_READ,
946 .help = "Sequential read",
949 .oval = TD_DDIR_WRITE,
950 .help = "Sequential write",
953 .oval = TD_DDIR_TRIM,
954 .help = "Sequential trim",
956 { .ival = "randread",
957 .oval = TD_DDIR_RANDREAD,
958 .help = "Random read",
960 { .ival = "randwrite",
961 .oval = TD_DDIR_RANDWRITE,
962 .help = "Random write",
964 { .ival = "randtrim",
965 .oval = TD_DDIR_RANDTRIM,
966 .help = "Random trim",
970 .help = "Sequential read and write mix",
972 { .ival = "readwrite",
974 .help = "Sequential read and write mix",
977 .oval = TD_DDIR_RANDRW,
978 .help = "Random read and write mix"
983 .name = "rw_sequencer",
985 .off1 = td_var_offset(rw_seq),
986 .help = "IO offset generator modifier",
989 { .ival = "sequential",
991 .help = "Generate sequential offsets",
993 { .ival = "identical",
994 .oval = RW_SEQ_IDENT,
995 .help = "Generate identical offsets",
1002 .type = FIO_OPT_STR_STORE,
1003 .off1 = td_var_offset(ioengine),
1004 .help = "IO engine to use",
1005 .def = FIO_PREFERRED_ENGINE,
1008 .help = "Use read/write",
1011 .help = "Use pread/pwrite",
1014 .help = "Use readv/writev",
1016 #ifdef FIO_HAVE_LIBAIO
1018 .help = "Linux native asynchronous IO",
1021 #ifdef FIO_HAVE_POSIXAIO
1022 { .ival = "posixaio",
1023 .help = "POSIX asynchronous IO",
1026 #ifdef FIO_HAVE_SOLARISAIO
1027 { .ival = "solarisaio",
1028 .help = "Solaris native asynchronous IO",
1031 #ifdef FIO_HAVE_WINDOWSAIO
1032 { .ival = "windowsaio",
1033 .help = "Windows native asynchronous IO"
1037 .help = "Memory mapped IO"
1039 #ifdef FIO_HAVE_SPLICE
1041 .help = "splice/vmsplice based IO",
1043 { .ival = "netsplice",
1044 .help = "splice/vmsplice to/from the network",
1047 #ifdef FIO_HAVE_SGIO
1049 .help = "SCSI generic v3 IO",
1053 .help = "Testing engine (no data transfer)",
1056 .help = "Network IO",
1058 #ifdef FIO_HAVE_SYSLET
1059 { .ival = "syslet-rw",
1060 .help = "syslet enabled async pread/pwrite IO",
1064 .help = "CPU cycle burner engine",
1066 #ifdef FIO_HAVE_GUASI
1068 .help = "GUASI IO engine",
1071 #ifdef FIO_HAVE_BINJECT
1072 { .ival = "binject",
1073 .help = "binject direct inject block engine",
1076 #ifdef FIO_HAVE_RDMA
1078 .help = "RDMA IO engine",
1081 #ifdef FIO_HAVE_FUSION_AW
1082 { .ival = "fusion-aw-sync",
1083 .help = "Fusion-io atomic write engine",
1086 #ifdef FIO_HAVE_E4_ENG
1087 { .ival = "e4defrag",
1088 .help = "ext4 defrag engine",
1091 #ifdef FIO_HAVE_FALLOC_ENG
1093 .help = "fallocate() file based engine",
1096 { .ival = "external",
1097 .help = "Load external engine (append name)",
1103 .type = FIO_OPT_INT,
1104 .off1 = td_var_offset(iodepth),
1105 .help = "Number of IO buffers to keep in flight",
1110 .name = "iodepth_batch",
1111 .alias = "iodepth_batch_submit",
1112 .type = FIO_OPT_INT,
1113 .off1 = td_var_offset(iodepth_batch),
1114 .help = "Number of IO buffers to submit in one go",
1115 .parent = "iodepth",
1120 .name = "iodepth_batch_complete",
1121 .type = FIO_OPT_INT,
1122 .off1 = td_var_offset(iodepth_batch_complete),
1123 .help = "Number of IO buffers to retrieve in one go",
1124 .parent = "iodepth",
1129 .name = "iodepth_low",
1130 .type = FIO_OPT_INT,
1131 .off1 = td_var_offset(iodepth_low),
1132 .help = "Low water mark for queuing depth",
1133 .parent = "iodepth",
1137 .type = FIO_OPT_STR_VAL,
1139 .help = "Total size of device or files",
1142 .name = "fill_device",
1144 .type = FIO_OPT_BOOL,
1145 .off1 = td_var_offset(fill_device),
1146 .help = "Write until an ENOSPC error occurs",
1151 .type = FIO_OPT_STR_VAL,
1152 .off1 = td_var_offset(file_size_low),
1153 .off2 = td_var_offset(file_size_high),
1155 .help = "Size of individual files",
1159 .alias = "fileoffset",
1160 .type = FIO_OPT_STR_VAL,
1161 .off1 = td_var_offset(start_offset),
1162 .help = "Start IO from this offset",
1166 .name = "offset_increment",
1167 .type = FIO_OPT_STR_VAL,
1168 .off1 = td_var_offset(offset_increment),
1169 .help = "What is the increment from one offset to the next",
1175 .alias = "blocksize",
1176 .type = FIO_OPT_INT,
1177 .off1 = td_var_offset(bs[DDIR_READ]),
1178 .off2 = td_var_offset(bs[DDIR_WRITE]),
1179 .off3 = td_var_offset(bs[DDIR_TRIM]),
1181 .help = "Block size unit",
1187 .alias = "blockalign",
1188 .type = FIO_OPT_INT,
1189 .off1 = td_var_offset(ba[DDIR_READ]),
1190 .off2 = td_var_offset(ba[DDIR_WRITE]),
1191 .off3 = td_var_offset(ba[DDIR_TRIM]),
1193 .help = "IO block offset alignment",
1198 .alias = "blocksize_range",
1199 .type = FIO_OPT_RANGE,
1200 .off1 = td_var_offset(min_bs[DDIR_READ]),
1201 .off2 = td_var_offset(max_bs[DDIR_READ]),
1202 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1203 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1204 .off5 = td_var_offset(min_bs[DDIR_TRIM]),
1205 .off6 = td_var_offset(max_bs[DDIR_TRIM]),
1207 .help = "Set block size range (in more detail than bs)",
1212 .type = FIO_OPT_STR,
1213 .cb = str_bssplit_cb,
1214 .help = "Set a specific mix of block sizes",
1218 .name = "bs_unaligned",
1219 .alias = "blocksize_unaligned",
1220 .type = FIO_OPT_STR_SET,
1221 .off1 = td_var_offset(bs_unaligned),
1222 .help = "Don't sector align IO buffer sizes",
1226 .name = "randrepeat",
1227 .type = FIO_OPT_BOOL,
1228 .off1 = td_var_offset(rand_repeatable),
1229 .help = "Use repeatable random IO pattern",
1234 .name = "use_os_rand",
1235 .type = FIO_OPT_BOOL,
1236 .off1 = td_var_offset(use_os_rand),
1237 .help = "Set to use OS random generator",
1242 .name = "norandommap",
1243 .type = FIO_OPT_STR_SET,
1244 .off1 = td_var_offset(norandommap),
1245 .help = "Accept potential duplicate random blocks",
1249 .name = "softrandommap",
1250 .type = FIO_OPT_BOOL,
1251 .off1 = td_var_offset(softrandommap),
1252 .help = "Set norandommap if randommap allocation fails",
1253 .parent = "norandommap",
1258 .alias = "nr_files",
1259 .type = FIO_OPT_INT,
1260 .off1 = td_var_offset(nr_files),
1261 .help = "Split job workload between this number of files",
1265 .name = "openfiles",
1266 .type = FIO_OPT_INT,
1267 .off1 = td_var_offset(open_files),
1268 .help = "Number of files to keep open at the same time",
1271 .name = "file_service_type",
1272 .type = FIO_OPT_STR,
1274 .off1 = td_var_offset(file_service_type),
1275 .help = "How to select which file to service next",
1276 .def = "roundrobin",
1279 .oval = FIO_FSERVICE_RANDOM,
1280 .help = "Choose a file at random",
1282 { .ival = "roundrobin",
1283 .oval = FIO_FSERVICE_RR,
1284 .help = "Round robin select files",
1286 { .ival = "sequential",
1287 .oval = FIO_FSERVICE_SEQ,
1288 .help = "Finish one file before moving to the next",
1291 .parent = "nrfiles",
1293 #ifdef FIO_HAVE_FALLOCATE
1295 .name = "fallocate",
1296 .type = FIO_OPT_STR,
1297 .off1 = td_var_offset(fallocate_mode),
1298 .help = "Whether pre-allocation is performed when laying out files",
1302 .oval = FIO_FALLOCATE_NONE,
1303 .help = "Do not pre-allocate space",
1306 .oval = FIO_FALLOCATE_POSIX,
1307 .help = "Use posix_fallocate()",
1309 #ifdef FIO_HAVE_LINUX_FALLOCATE
1311 .oval = FIO_FALLOCATE_KEEP_SIZE,
1312 .help = "Use fallocate(..., FALLOC_FL_KEEP_SIZE, ...)",
1315 /* Compatibility with former boolean values */
1317 .oval = FIO_FALLOCATE_NONE,
1318 .help = "Alias for 'none'",
1321 .oval = FIO_FALLOCATE_POSIX,
1322 .help = "Alias for 'posix'",
1326 #endif /* FIO_HAVE_FALLOCATE */
1328 .name = "fadvise_hint",
1329 .type = FIO_OPT_BOOL,
1330 .off1 = td_var_offset(fadvise_hint),
1331 .help = "Use fadvise() to advise the kernel on IO pattern",
1336 .type = FIO_OPT_INT,
1337 .off1 = td_var_offset(fsync_blocks),
1338 .help = "Issue fsync for writes every given number of blocks",
1342 .name = "fdatasync",
1343 .type = FIO_OPT_INT,
1344 .off1 = td_var_offset(fdatasync_blocks),
1345 .help = "Issue fdatasync for writes every given number of blocks",
1349 .name = "write_barrier",
1350 .type = FIO_OPT_INT,
1351 .off1 = td_var_offset(barrier_blocks),
1352 .help = "Make every Nth write a barrier write",
1355 #ifdef FIO_HAVE_SYNC_FILE_RANGE
1357 .name = "sync_file_range",
1359 { .ival = "wait_before",
1360 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1361 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
1365 .oval = SYNC_FILE_RANGE_WRITE,
1366 .help = "SYNC_FILE_RANGE_WRITE",
1370 .ival = "wait_after",
1371 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1372 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
1376 .type = FIO_OPT_STR_MULTI,
1378 .off1 = td_var_offset(sync_file_range),
1379 .help = "Use sync_file_range()",
1384 .type = FIO_OPT_BOOL,
1385 .off1 = td_var_offset(odirect),
1386 .help = "Use O_DIRECT IO (negates buffered)",
1391 .type = FIO_OPT_BOOL,
1392 .off1 = td_var_offset(odirect),
1394 .help = "Use buffered IO (negates direct)",
1398 .name = "overwrite",
1399 .type = FIO_OPT_BOOL,
1400 .off1 = td_var_offset(overwrite),
1401 .help = "When writing, set whether to overwrite current data",
1406 .type = FIO_OPT_INT,
1407 .off1 = td_var_offset(loops),
1408 .help = "Number of times to run the job",
1413 .type = FIO_OPT_INT,
1414 .off1 = td_var_offset(numjobs),
1415 .help = "Duplicate this job this many times",
1419 .name = "startdelay",
1420 .type = FIO_OPT_STR_VAL_TIME,
1421 .off1 = td_var_offset(start_delay),
1422 .help = "Only start job when this period has passed",
1428 .type = FIO_OPT_STR_VAL_TIME,
1429 .off1 = td_var_offset(timeout),
1430 .help = "Stop workload when this amount of time has passed",
1434 .name = "time_based",
1435 .type = FIO_OPT_STR_SET,
1436 .off1 = td_var_offset(time_based),
1437 .help = "Keep running until runtime/timeout is met",
1440 .name = "ramp_time",
1441 .type = FIO_OPT_STR_VAL_TIME,
1442 .off1 = td_var_offset(ramp_time),
1443 .help = "Ramp up time before measuring performance",
1446 .name = "clocksource",
1447 .type = FIO_OPT_STR,
1448 .cb = fio_clock_source_cb,
1449 .off1 = td_var_offset(clocksource),
1450 .help = "What type of timing source to use",
1452 { .ival = "gettimeofday",
1454 .help = "Use gettimeofday(2) for timing",
1456 { .ival = "clock_gettime",
1457 .oval = CS_CGETTIME,
1458 .help = "Use clock_gettime(2) for timing",
1460 #ifdef ARCH_HAVE_CPU_CLOCK
1462 .oval = CS_CPUCLOCK,
1463 .help = "Use CPU private clock",
1471 .type = FIO_OPT_STR,
1473 .off1 = td_var_offset(mem_type),
1474 .help = "Backing type for IO buffers",
1479 .help = "Use malloc(3) for IO buffers",
1483 .help = "Use shared memory segments for IO buffers",
1485 #ifdef FIO_HAVE_HUGETLB
1486 { .ival = "shmhuge",
1487 .oval = MEM_SHMHUGE,
1488 .help = "Like shm, but use huge pages",
1493 .help = "Use mmap(2) (file or anon) for IO buffers",
1495 #ifdef FIO_HAVE_HUGETLB
1496 { .ival = "mmaphuge",
1497 .oval = MEM_MMAPHUGE,
1498 .help = "Like mmap, but use huge pages",
1504 .name = "iomem_align",
1505 .alias = "mem_align",
1506 .type = FIO_OPT_INT,
1507 .off1 = td_var_offset(mem_align),
1509 .help = "IO memory buffer offset alignment",
1515 .type = FIO_OPT_STR,
1516 .off1 = td_var_offset(verify),
1517 .help = "Verify data written",
1518 .cb = str_verify_cb,
1522 .oval = VERIFY_NONE,
1523 .help = "Don't do IO verification",
1527 .help = "Use md5 checksums for verification",
1530 .oval = VERIFY_CRC64,
1531 .help = "Use crc64 checksums for verification",
1534 .oval = VERIFY_CRC32,
1535 .help = "Use crc32 checksums for verification",
1537 { .ival = "crc32c-intel",
1538 .oval = VERIFY_CRC32C,
1539 .help = "Use crc32c checksums for verification (hw assisted, if available)",
1542 .oval = VERIFY_CRC32C,
1543 .help = "Use crc32c checksums for verification (hw assisted, if available)",
1546 .oval = VERIFY_CRC16,
1547 .help = "Use crc16 checksums for verification",
1550 .oval = VERIFY_CRC7,
1551 .help = "Use crc7 checksums for verification",
1554 .oval = VERIFY_SHA1,
1555 .help = "Use sha1 checksums for verification",
1558 .oval = VERIFY_SHA256,
1559 .help = "Use sha256 checksums for verification",
1562 .oval = VERIFY_SHA512,
1563 .help = "Use sha512 checksums for verification",
1566 .oval = VERIFY_META,
1567 .help = "Use io information",
1571 .oval = VERIFY_NULL,
1572 .help = "Pretend to verify",
1577 .name = "do_verify",
1578 .type = FIO_OPT_BOOL,
1579 .off1 = td_var_offset(do_verify),
1580 .help = "Run verification stage after write",
1585 .name = "verifysort",
1586 .type = FIO_OPT_BOOL,
1587 .off1 = td_var_offset(verifysort),
1588 .help = "Sort written verify blocks for read back",
1593 .name = "verify_interval",
1594 .type = FIO_OPT_INT,
1595 .off1 = td_var_offset(verify_interval),
1596 .minval = 2 * sizeof(struct verify_header),
1597 .help = "Store verify buffer header every N bytes",
1601 .name = "verify_offset",
1602 .type = FIO_OPT_INT,
1603 .help = "Offset verify header location by N bytes",
1605 .cb = str_verify_offset_cb,
1609 .name = "verify_pattern",
1610 .type = FIO_OPT_STR,
1611 .cb = str_verify_pattern_cb,
1612 .help = "Fill pattern for IO buffers",
1616 .name = "verify_fatal",
1617 .type = FIO_OPT_BOOL,
1618 .off1 = td_var_offset(verify_fatal),
1620 .help = "Exit on a single verify failure, don't continue",
1624 .name = "verify_dump",
1625 .type = FIO_OPT_BOOL,
1626 .off1 = td_var_offset(verify_dump),
1628 .help = "Dump contents of good and bad blocks on failure",
1632 .name = "verify_async",
1633 .type = FIO_OPT_INT,
1634 .off1 = td_var_offset(verify_async),
1636 .help = "Number of async verifier threads to use",
1640 .name = "verify_backlog",
1641 .type = FIO_OPT_STR_VAL,
1642 .off1 = td_var_offset(verify_backlog),
1643 .help = "Verify after this number of blocks are written",
1647 .name = "verify_backlog_batch",
1648 .type = FIO_OPT_INT,
1649 .off1 = td_var_offset(verify_batch),
1650 .help = "Verify this number of IO blocks",
1653 #ifdef FIO_HAVE_CPU_AFFINITY
1655 .name = "verify_async_cpus",
1656 .type = FIO_OPT_STR,
1657 .cb = str_verify_cpus_allowed_cb,
1658 .help = "Set CPUs allowed for async verify threads",
1659 .parent = "verify_async",
1662 #ifdef FIO_HAVE_TRIM
1664 .name = "trim_percentage",
1665 .type = FIO_OPT_INT,
1666 .cb = str_verify_trim_cb,
1668 .help = "Number of verify blocks to discard/trim",
1673 .name = "trim_verify_zero",
1674 .type = FIO_OPT_INT,
1675 .help = "Verify that trim/discarded blocks are returned as zeroes",
1676 .off1 = td_var_offset(trim_zero),
1677 .parent = "trim_percentage",
1681 .name = "trim_backlog",
1682 .type = FIO_OPT_STR_VAL,
1683 .off1 = td_var_offset(trim_backlog),
1684 .help = "Trim after this number of blocks are written",
1685 .parent = "trim_percentage",
1688 .name = "trim_backlog_batch",
1689 .type = FIO_OPT_INT,
1690 .off1 = td_var_offset(trim_batch),
1691 .help = "Trim this number of IO blocks",
1692 .parent = "trim_percentage",
1696 .name = "write_iolog",
1697 .type = FIO_OPT_STR_STORE,
1698 .off1 = td_var_offset(write_iolog_file),
1699 .help = "Store IO pattern to file",
1702 .name = "read_iolog",
1703 .type = FIO_OPT_STR_STORE,
1704 .off1 = td_var_offset(read_iolog_file),
1705 .help = "Playback IO pattern from file",
1708 .name = "replay_no_stall",
1709 .type = FIO_OPT_INT,
1710 .off1 = td_var_offset(no_stall),
1712 .parent = "read_iolog",
1713 .help = "Playback IO pattern file as fast as possible without stalls",
1716 .name = "replay_redirect",
1717 .type = FIO_OPT_STR_STORE,
1718 .off1 = td_var_offset(replay_redirect),
1719 .parent = "read_iolog",
1720 .help = "Replay all I/O onto this device, regardless of trace device",
1723 .name = "exec_prerun",
1724 .type = FIO_OPT_STR_STORE,
1725 .off1 = td_var_offset(exec_prerun),
1726 .help = "Execute this file prior to running job",
1729 .name = "exec_postrun",
1730 .type = FIO_OPT_STR_STORE,
1731 .off1 = td_var_offset(exec_postrun),
1732 .help = "Execute this file after running job",
1734 #ifdef FIO_HAVE_IOSCHED_SWITCH
1736 .name = "ioscheduler",
1737 .type = FIO_OPT_STR_STORE,
1738 .off1 = td_var_offset(ioscheduler),
1739 .help = "Use this IO scheduler on the backing device",
1744 .type = FIO_OPT_STR_VAL,
1745 .off1 = td_var_offset(zone_size),
1746 .help = "Amount of data to read per zone",
1750 .name = "zonerange",
1751 .type = FIO_OPT_STR_VAL,
1752 .off1 = td_var_offset(zone_range),
1753 .help = "Give size of an IO zone",
1758 .type = FIO_OPT_STR_VAL,
1759 .off1 = td_var_offset(zone_skip),
1760 .help = "Space between IO zones",
1765 .type = FIO_OPT_STR_VAL,
1766 .cb = str_lockmem_cb,
1767 .help = "Lock down this amount of memory",
1771 .name = "rwmixread",
1772 .type = FIO_OPT_INT,
1773 .cb = str_rwmix_read_cb,
1775 .help = "Percentage of mixed workload that is reads",
1779 .name = "rwmixwrite",
1780 .type = FIO_OPT_INT,
1781 .cb = str_rwmix_write_cb,
1783 .help = "Percentage of mixed workload that is writes",
1787 .name = "rwmixcycle",
1788 .type = FIO_OPT_DEPRECATED,
1792 .type = FIO_OPT_INT,
1793 .off1 = td_var_offset(nice),
1794 .help = "Set job CPU nice value",
1799 #ifdef FIO_HAVE_IOPRIO
1802 .type = FIO_OPT_INT,
1804 .help = "Set job IO priority value",
1809 .name = "prioclass",
1810 .type = FIO_OPT_INT,
1811 .cb = str_prioclass_cb,
1812 .help = "Set job IO priority class",
1818 .name = "thinktime",
1819 .type = FIO_OPT_INT,
1820 .off1 = td_var_offset(thinktime),
1821 .help = "Idle time between IO buffers (usec)",
1825 .name = "thinktime_spin",
1826 .type = FIO_OPT_INT,
1827 .off1 = td_var_offset(thinktime_spin),
1828 .help = "Start think time by spinning this amount (usec)",
1830 .parent = "thinktime",
1833 .name = "thinktime_blocks",
1834 .type = FIO_OPT_INT,
1835 .off1 = td_var_offset(thinktime_blocks),
1836 .help = "IO buffer period between 'thinktime'",
1838 .parent = "thinktime",
1842 .type = FIO_OPT_INT,
1843 .off1 = td_var_offset(rate[DDIR_READ]),
1844 .off2 = td_var_offset(rate[DDIR_WRITE]),
1845 .off3 = td_var_offset(rate[DDIR_TRIM]),
1846 .help = "Set bandwidth rate",
1850 .type = FIO_OPT_INT,
1851 .off1 = td_var_offset(ratemin[DDIR_READ]),
1852 .off2 = td_var_offset(ratemin[DDIR_WRITE]),
1853 .off3 = td_var_offset(ratemin[DDIR_TRIM]),
1854 .help = "Job must meet this rate or it will be shutdown",
1858 .name = "rate_iops",
1859 .type = FIO_OPT_INT,
1860 .off1 = td_var_offset(rate_iops[DDIR_READ]),
1861 .off2 = td_var_offset(rate_iops[DDIR_WRITE]),
1862 .off3 = td_var_offset(rate_iops[DDIR_TRIM]),
1863 .help = "Limit IO used to this number of IO operations/sec",
1866 .name = "rate_iops_min",
1867 .type = FIO_OPT_INT,
1868 .off1 = td_var_offset(rate_iops_min[DDIR_READ]),
1869 .off2 = td_var_offset(rate_iops_min[DDIR_WRITE]),
1870 .off3 = td_var_offset(rate_iops_min[DDIR_TRIM]),
1871 .help = "Job must meet this rate or it will be shut down",
1872 .parent = "rate_iops",
1875 .name = "ratecycle",
1876 .type = FIO_OPT_INT,
1877 .off1 = td_var_offset(ratecycle),
1878 .help = "Window average for rate limits (msec)",
1883 .name = "invalidate",
1884 .type = FIO_OPT_BOOL,
1885 .off1 = td_var_offset(invalidate_cache),
1886 .help = "Invalidate buffer/page cache prior to running job",
1891 .type = FIO_OPT_BOOL,
1892 .off1 = td_var_offset(sync_io),
1893 .help = "Use O_SYNC for buffered writes",
1895 .parent = "buffered",
1898 .name = "bwavgtime",
1899 .type = FIO_OPT_INT,
1900 .off1 = td_var_offset(bw_avg_time),
1901 .help = "Time window over which to calculate bandwidth"
1904 .parent = "write_bw_log",
1907 .name = "iopsavgtime",
1908 .type = FIO_OPT_INT,
1909 .off1 = td_var_offset(iops_avg_time),
1910 .help = "Time window over which to calculate IOPS (msec)",
1912 .parent = "write_iops_log",
1915 .name = "create_serialize",
1916 .type = FIO_OPT_BOOL,
1917 .off1 = td_var_offset(create_serialize),
1918 .help = "Serialize creating of job files",
1922 .name = "create_fsync",
1923 .type = FIO_OPT_BOOL,
1924 .off1 = td_var_offset(create_fsync),
1925 .help = "fsync file after creation",
1929 .name = "create_on_open",
1930 .type = FIO_OPT_BOOL,
1931 .off1 = td_var_offset(create_on_open),
1932 .help = "Create files when they are opened for IO",
1936 .name = "create_only",
1937 .type = FIO_OPT_BOOL,
1938 .off1 = td_var_offset(create_only),
1939 .help = "Only perform file creation phase",
1944 .type = FIO_OPT_BOOL,
1945 .off1 = td_var_offset(pre_read),
1946 .help = "Pre-read files before starting official testing",
1951 .type = FIO_OPT_INT,
1952 .off1 = td_var_offset(cpuload),
1953 .help = "Use this percentage of CPU",
1956 .name = "cpuchunks",
1957 .type = FIO_OPT_INT,
1958 .off1 = td_var_offset(cpucycle),
1959 .help = "Length of the CPU burn cycles (usecs)",
1961 .parent = "cpuload",
1963 #ifdef FIO_HAVE_CPU_AFFINITY
1966 .type = FIO_OPT_INT,
1967 .cb = str_cpumask_cb,
1968 .help = "CPU affinity mask",
1971 .name = "cpus_allowed",
1972 .type = FIO_OPT_STR,
1973 .cb = str_cpus_allowed_cb,
1974 .help = "Set CPUs allowed",
1978 .name = "end_fsync",
1979 .type = FIO_OPT_BOOL,
1980 .off1 = td_var_offset(end_fsync),
1981 .help = "Include fsync at the end of job",
1985 .name = "fsync_on_close",
1986 .type = FIO_OPT_BOOL,
1987 .off1 = td_var_offset(fsync_on_close),
1988 .help = "fsync files on close",
1993 .type = FIO_OPT_BOOL,
1994 .off1 = td_var_offset(unlink),
1995 .help = "Unlink created files after job has completed",
2000 .type = FIO_OPT_STR_SET,
2001 .cb = str_exitall_cb,
2002 .help = "Terminate all jobs when one exits",
2005 .name = "stonewall",
2006 .alias = "wait_for_previous",
2007 .type = FIO_OPT_STR_SET,
2008 .off1 = td_var_offset(stonewall),
2009 .help = "Insert a hard barrier between this job and previous",
2012 .name = "new_group",
2013 .type = FIO_OPT_STR_SET,
2014 .off1 = td_var_offset(new_group),
2015 .help = "Mark the start of a new group (for reporting)",
2019 .type = FIO_OPT_STR_SET,
2020 .off1 = td_var_offset(use_thread),
2021 .help = "Use threads instead of forks",
2024 .name = "write_bw_log",
2025 .type = FIO_OPT_STR,
2026 .off1 = td_var_offset(write_bw_log),
2027 .cb = str_write_bw_log_cb,
2028 .help = "Write log of bandwidth during run",
2031 .name = "write_lat_log",
2032 .type = FIO_OPT_STR,
2033 .off1 = td_var_offset(write_lat_log),
2034 .cb = str_write_lat_log_cb,
2035 .help = "Write log of latency during run",
2038 .name = "write_iops_log",
2039 .type = FIO_OPT_STR,
2040 .off1 = td_var_offset(write_iops_log),
2041 .cb = str_write_iops_log_cb,
2042 .help = "Write log of IOPS during run",
2045 .name = "log_avg_msec",
2046 .type = FIO_OPT_INT,
2047 .off1 = td_var_offset(log_avg_msec),
2048 .help = "Average bw/iops/lat logs over this period of time",
2052 .name = "hugepage-size",
2053 .type = FIO_OPT_INT,
2054 .off1 = td_var_offset(hugepage_size),
2055 .help = "When using hugepages, specify size of each page",
2056 .def = __fio_stringify(FIO_HUGE_PAGE),
2059 .name = "group_reporting",
2060 .type = FIO_OPT_STR_SET,
2061 .off1 = td_var_offset(group_reporting),
2062 .help = "Do reporting on a per-group basis",
2065 .name = "zero_buffers",
2066 .type = FIO_OPT_STR_SET,
2067 .off1 = td_var_offset(zero_buffers),
2068 .help = "Init IO buffers to all zeroes",
2071 .name = "refill_buffers",
2072 .type = FIO_OPT_STR_SET,
2073 .off1 = td_var_offset(refill_buffers),
2074 .help = "Refill IO buffers on every IO submit",
2077 .name = "scramble_buffers",
2078 .type = FIO_OPT_BOOL,
2079 .off1 = td_var_offset(scramble_buffers),
2080 .help = "Slightly scramble buffers on every IO submit",
2084 .name = "buffer_compress_percentage",
2085 .type = FIO_OPT_INT,
2086 .off1 = td_var_offset(compress_percentage),
2089 .help = "How compressible the buffer is (approximately)",
2092 .name = "buffer_compress_chunk",
2093 .type = FIO_OPT_INT,
2094 .off1 = td_var_offset(compress_chunk),
2095 .parent = "buffer_compress_percentage",
2096 .help = "Size of compressible region in buffer",
2099 .name = "clat_percentiles",
2100 .type = FIO_OPT_BOOL,
2101 .off1 = td_var_offset(clat_percentiles),
2102 .help = "Enable the reporting of completion latency percentiles",
2106 .name = "percentile_list",
2107 .type = FIO_OPT_FLOAT_LIST,
2108 .off1 = td_var_offset(percentile_list),
2109 .off2 = td_var_offset(overwrite_plist),
2110 .help = "Specify a custom list of percentiles to report",
2111 .maxlen = FIO_IO_U_LIST_MAX_LEN,
2116 #ifdef FIO_HAVE_DISK_UTIL
2118 .name = "disk_util",
2119 .type = FIO_OPT_BOOL,
2120 .off1 = td_var_offset(do_disk_util),
2121 .help = "Log disk utilization statistics",
2126 .name = "gtod_reduce",
2127 .type = FIO_OPT_BOOL,
2128 .help = "Greatly reduce number of gettimeofday() calls",
2129 .cb = str_gtod_reduce_cb,
2133 .name = "disable_lat",
2134 .type = FIO_OPT_BOOL,
2135 .off1 = td_var_offset(disable_lat),
2136 .help = "Disable latency numbers",
2137 .parent = "gtod_reduce",
2141 .name = "disable_clat",
2142 .type = FIO_OPT_BOOL,
2143 .off1 = td_var_offset(disable_clat),
2144 .help = "Disable completion latency numbers",
2145 .parent = "gtod_reduce",
2149 .name = "disable_slat",
2150 .type = FIO_OPT_BOOL,
2151 .off1 = td_var_offset(disable_slat),
2152 .help = "Disable submission latency numbers",
2153 .parent = "gtod_reduce",
2157 .name = "disable_bw_measurement",
2158 .type = FIO_OPT_BOOL,
2159 .off1 = td_var_offset(disable_bw),
2160 .help = "Disable bandwidth logging",
2161 .parent = "gtod_reduce",
2166 .type = FIO_OPT_INT,
2167 .cb = str_gtod_cpu_cb,
2168 .help = "Set up dedicated gettimeofday() thread on this CPU",
2169 .verify = gtod_cpu_verify,
2172 .name = "continue_on_error",
2173 .type = FIO_OPT_STR,
2174 .off1 = td_var_offset(continue_on_error),
2175 .help = "Continue on non-fatal errors during IO",
2179 .oval = ERROR_TYPE_NONE,
2180 .help = "Exit when an error is encountered",
2183 .oval = ERROR_TYPE_READ,
2184 .help = "Continue on read errors only",
2187 .oval = ERROR_TYPE_WRITE,
2188 .help = "Continue on write errors only",
2191 .oval = ERROR_TYPE_READ | ERROR_TYPE_WRITE,
2192 .help = "Continue on any IO errors",
2195 .oval = ERROR_TYPE_VERIFY,
2196 .help = "Continue on verify errors only",
2199 .oval = ERROR_TYPE_ANY,
2200 .help = "Continue on all io and verify errors",
2203 .oval = ERROR_TYPE_NONE,
2204 .help = "Alias for 'none'",
2207 .oval = ERROR_TYPE_ANY,
2208 .help = "Alias for 'all'",
2214 .type = FIO_OPT_STR_STORE,
2215 .off1 = td_var_offset(profile),
2216 .help = "Select a specific builtin performance test",
2220 .type = FIO_OPT_STR_STORE,
2221 .off1 = td_var_offset(cgroup),
2222 .help = "Add job to cgroup of this name",
2225 .name = "cgroup_weight",
2226 .type = FIO_OPT_INT,
2227 .off1 = td_var_offset(cgroup_weight),
2228 .help = "Use given weight for cgroup",
2233 .name = "cgroup_nodelete",
2234 .type = FIO_OPT_BOOL,
2235 .off1 = td_var_offset(cgroup_nodelete),
2236 .help = "Do not delete cgroups after job completion",
2241 .type = FIO_OPT_INT,
2242 .off1 = td_var_offset(uid),
2243 .help = "Run job with this user ID",
2247 .type = FIO_OPT_INT,
2248 .off1 = td_var_offset(gid),
2249 .help = "Run job with this group ID",
2253 .type = FIO_OPT_INT,
2254 .off1 = td_var_offset(flow_id),
2255 .help = "The flow index ID to use",
2260 .type = FIO_OPT_INT,
2261 .off1 = td_var_offset(flow),
2262 .help = "Weight for flow control of this job",
2263 .parent = "flow_id",
2267 .name = "flow_watermark",
2268 .type = FIO_OPT_INT,
2269 .off1 = td_var_offset(flow_watermark),
2270 .help = "High watermark for flow control. This option"
2271 " should be set to the same value for all threads"
2272 " with non-zero flow.",
2273 .parent = "flow_id",
2277 .name = "flow_sleep",
2278 .type = FIO_OPT_INT,
2279 .off1 = td_var_offset(flow_sleep),
2280 .help = "How many microseconds to sleep after being held"
2281 " back by the flow control mechanism",
2282 .parent = "flow_id",
2290 static void add_to_lopt(struct option *lopt, struct fio_option *o,
2291 const char *name, int val)
2293 lopt->name = (char *) name;
2295 if (o->type == FIO_OPT_STR_SET)
2296 lopt->has_arg = no_argument;
2298 lopt->has_arg = required_argument;
2301 static void options_to_lopts(struct fio_option *opts,
2302 struct option *long_options,
2303 int i, int option_type)
2305 struct fio_option *o = &opts[0];
2307 add_to_lopt(&long_options[i], o, o->name, option_type);
2310 add_to_lopt(&long_options[i], o, o->alias, option_type);
2315 assert(i < FIO_NR_OPTIONS);
2319 void fio_options_set_ioengine_opts(struct option *long_options,
2320 struct thread_data *td)
2325 while (long_options[i].name) {
2326 if (long_options[i].val == FIO_GETOPT_IOENGINE) {
2327 memset(&long_options[i], 0, sizeof(*long_options));
2334 * Just clear out the prior ioengine options.
2339 options_to_lopts(td->io_ops->options, long_options, i,
2340 FIO_GETOPT_IOENGINE);
2343 void fio_options_dup_and_init(struct option *long_options)
2347 options_init(options);
2350 while (long_options[i].name)
2353 options_to_lopts(options, long_options, i, FIO_GETOPT_JOB);
2356 struct fio_keyword {
2362 static struct fio_keyword fio_keywords[] = {
2364 .word = "$pagesize",
2365 .desc = "Page size in the system",
2368 .word = "$mb_memory",
2369 .desc = "Megabytes of memory online",
2373 .desc = "Number of CPUs online in the system",
2380 void fio_keywords_init(void)
2382 unsigned long long mb_memory;
2386 sprintf(buf, "%lu", page_size);
2387 fio_keywords[0].replace = strdup(buf);
2389 mb_memory = os_phys_mem() / (1024 * 1024);
2390 sprintf(buf, "%llu", mb_memory);
2391 fio_keywords[1].replace = strdup(buf);
2394 sprintf(buf, "%lu", l);
2395 fio_keywords[2].replace = strdup(buf);
2400 static char *bc_calc(char *str)
2402 char buf[128], *tmp;
2407 * No math, just return string
2409 if ((!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
2410 !strchr(str, '/')) || strchr(str, '\''))
2414 * Split option from value, we only need to calculate the value
2416 tmp = strchr(str, '=');
2423 * Prevent buffer overflows; such a case isn't reasonable anyway
2425 if (strlen(str) >= 128 || strlen(tmp) > 100)
2428 sprintf(buf, "which %s > /dev/null", BC_APP);
2430 log_err("fio: bc is needed for performing math\n");
2434 sprintf(buf, "echo '%s' | %s", tmp, BC_APP);
2435 f = popen(buf, "r");
2440 ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f);
2446 buf[(tmp - str) + ret - 1] = '\0';
2447 memcpy(buf, str, tmp - str);
2453 * Return a copy of the input string with substrings of the form ${VARNAME}
2454 * substituted with the value of the environment variable VARNAME. The
2455 * substitution always occurs, even if VARNAME is empty or the corresponding
2456 * environment variable undefined.
2458 static char *option_dup_subs(const char *opt)
2460 char out[OPT_LEN_MAX+1];
2461 char in[OPT_LEN_MAX+1];
2464 char *ch1, *ch2, *env;
2465 ssize_t nchr = OPT_LEN_MAX;
2468 if (strlen(opt) + 1 > OPT_LEN_MAX) {
2469 log_err("OPT_LEN_MAX (%d) is too small\n", OPT_LEN_MAX);
2473 in[OPT_LEN_MAX] = '\0';
2474 strncpy(in, opt, OPT_LEN_MAX);
2476 while (*inptr && nchr > 0) {
2477 if (inptr[0] == '$' && inptr[1] == '{') {
2478 ch2 = strchr(inptr, '}');
2479 if (ch2 && inptr+1 < ch2) {
2486 envlen = strlen(env);
2487 if (envlen <= nchr) {
2488 memcpy(outptr, env, envlen);
2498 *outptr++ = *inptr++;
2507 * Look for reserved variable names and replace them with real values
2509 static char *fio_keyword_replace(char *opt)
2515 for (i = 0; fio_keywords[i].word != NULL; i++) {
2516 struct fio_keyword *kw = &fio_keywords[i];
2518 while ((s = strstr(opt, kw->word)) != NULL) {
2519 char *new = malloc(strlen(opt) + 1);
2525 * Copy part of the string before the keyword and
2526 * sprintf() the replacement after it.
2528 memcpy(new, opt, olen);
2529 len = sprintf(new + olen, "%s", kw->replace);
2532 * If there's more in the original string, copy that
2535 opt += strlen(kw->word) + olen;
2537 memcpy(new + olen + len, opt, opt - o_org - 1);
2540 * replace opt and free the old opt
2550 * Check for potential math and invoke bc, if possible
2558 static char **dup_and_sub_options(char **opts, int num_opts)
2561 char **opts_copy = malloc(num_opts * sizeof(*opts));
2562 for (i = 0; i < num_opts; i++) {
2563 opts_copy[i] = option_dup_subs(opts[i]);
2566 opts_copy[i] = fio_keyword_replace(opts_copy[i]);
2571 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
2573 int i, ret, unknown;
2576 sort_options(opts, options, num_opts);
2577 opts_copy = dup_and_sub_options(opts, num_opts);
2579 for (ret = 0, i = 0, unknown = 0; i < num_opts; i++) {
2580 struct fio_option *o;
2581 int newret = parse_option(opts_copy[i], opts[i], options, &o,
2590 opts_copy[i] = NULL;
2597 ret |= ioengine_load(td);
2599 sort_options(opts_copy, td->io_ops->options, num_opts);
2602 for (i = 0; i < num_opts; i++) {
2603 struct fio_option *o = NULL;
2609 newret = parse_option(opts_copy[i], opts[i],
2610 td->io_ops->options, &o,
2615 log_err("Bad option <%s>\n", opts[i]);
2618 opts_copy[i] = NULL;
2626 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2628 return parse_cmd_option(opt, val, options, td);
2631 int fio_cmd_ioengine_option_parse(struct thread_data *td, const char *opt,
2634 return parse_cmd_option(opt, val, td->io_ops->options, td);
2637 void fio_fill_default_options(struct thread_data *td)
2639 fill_default_options(td, options);
2642 int fio_show_option_help(const char *opt)
2644 return show_cmd_help(options, opt);
2647 void options_mem_dupe(void *data, struct fio_option *options)
2649 struct fio_option *o;
2652 for (o = &options[0]; o->name; o++) {
2653 if (o->type != FIO_OPT_STR_STORE)
2656 ptr = td_var(data, o->off1);
2658 *ptr = strdup(*ptr);
2663 * dupe FIO_OPT_STR_STORE options
2665 void fio_options_mem_dupe(struct thread_data *td)
2667 options_mem_dupe(&td->o, options);
2669 if (td->eo && td->io_ops) {
2670 void *oldeo = td->eo;
2672 td->eo = malloc(td->io_ops->option_struct_size);
2673 memcpy(td->eo, oldeo, td->io_ops->option_struct_size);
2674 options_mem_dupe(td->eo, td->io_ops->options);
2678 unsigned int fio_get_kb_base(void *data)
2680 struct thread_data *td = data;
2681 unsigned int kb_base = 0;
2684 kb_base = td->o.kb_base;
2691 int add_option(struct fio_option *o)
2693 struct fio_option *__o;
2702 memcpy(&options[opt_index], o, sizeof(*o));
2706 void invalidate_profile_options(const char *prof_name)
2708 struct fio_option *o;
2712 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2713 o->type = FIO_OPT_INVALID;
2714 o->prof_name = NULL;
2720 void add_opt_posval(const char *optname, const char *ival, const char *help)
2722 struct fio_option *o;
2725 o = find_option(options, optname);
2729 for (i = 0; i < PARSE_MAX_VP; i++) {
2730 if (o->posval[i].ival)
2733 o->posval[i].ival = ival;
2734 o->posval[i].help = help;
2739 void del_opt_posval(const char *optname, const char *ival)
2741 struct fio_option *o;
2744 o = find_option(options, optname);
2748 for (i = 0; i < PARSE_MAX_VP; i++) {
2749 if (!o->posval[i].ival)
2751 if (strcmp(o->posval[i].ival, ival))
2754 o->posval[i].ival = NULL;
2755 o->posval[i].help = NULL;
2759 void fio_options_free(struct thread_data *td)
2761 options_free(options, td);
2762 if (td->eo && td->io_ops && td->io_ops->options) {
2763 options_free(td->io_ops->options, td->eo);