10 #include <sys/types.h>
18 #define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
21 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
23 static char *get_opt_postfix(const char *str)
25 char *p = strstr(str, ":");
31 strip_blank_front(&p);
36 static int converthexchartoint(char a)
56 static int bs_cmp(const void *p1, const void *p2)
58 const struct bssplit *bsp1 = p1;
59 const struct bssplit *bsp2 = p2;
61 return bsp1->perc < bsp2->perc;
64 static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
66 struct bssplit *bssplit;
67 unsigned int i, perc, perc_missing;
68 unsigned int max_bs, min_bs;
72 td->o.bssplit_nr[ddir] = 4;
73 bssplit = malloc(4 * sizeof(struct bssplit));
78 while ((fname = strsep(&str, ":")) != NULL) {
85 * grow struct buffer, if needed
87 if (i == td->o.bssplit_nr[ddir]) {
88 td->o.bssplit_nr[ddir] <<= 1;
89 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
90 * sizeof(struct bssplit));
93 perc_str = strstr(fname, "/");
97 perc = atoi(perc_str);
105 if (str_to_decimal(fname, &val, 1, td)) {
106 log_err("fio: bssplit conversion failed\n");
117 bssplit[i].perc = perc;
121 td->o.bssplit_nr[ddir] = i;
124 * Now check if the percentages add up, and how much is missing
126 perc = perc_missing = 0;
127 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
128 struct bssplit *bsp = &bssplit[i];
130 if (bsp->perc == (unsigned char) -1)
137 log_err("fio: bssplit percentages add to more than 100%%\n");
142 * If values didn't have a percentage set, divide the remains between
146 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
147 struct bssplit *bsp = &bssplit[i];
149 if (bsp->perc == (unsigned char) -1)
150 bsp->perc = (100 - perc) / perc_missing;
154 td->o.min_bs[ddir] = min_bs;
155 td->o.max_bs[ddir] = max_bs;
158 * now sort based on percentages, for ease of lookup
160 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 td->o.bssplit[ddir] = bssplit;
166 static int str_bssplit_cb(void *data, const char *input)
168 struct thread_data *td = data;
169 char *str, *p, *odir;
172 p = str = strdup(input);
174 strip_blank_front(&str);
175 strip_blank_end(str);
177 odir = strchr(str, ',');
179 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
182 ret = bssplit_ddir(td, DDIR_READ, str);
189 ret = bssplit_ddir(td, DDIR_READ, str);
191 ret = bssplit_ddir(td, DDIR_WRITE, op);
200 static int str_rw_cb(void *data, const char *str)
202 struct thread_data *td = data;
203 char *nr = get_opt_postfix(str);
207 td->o.ddir_nr = atoi(nr);
214 static int str_mem_cb(void *data, const char *mem)
216 struct thread_data *td = data;
218 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
219 td->mmapfile = get_opt_postfix(mem);
220 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
221 log_err("fio: mmaphuge:/path/to/file\n");
229 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
235 static int str_rwmix_read_cb(void *data, unsigned int *val)
237 struct thread_data *td = data;
239 td->o.rwmix[DDIR_READ] = *val;
240 td->o.rwmix[DDIR_WRITE] = 100 - *val;
244 static int str_rwmix_write_cb(void *data, unsigned int *val)
246 struct thread_data *td = data;
248 td->o.rwmix[DDIR_WRITE] = *val;
249 td->o.rwmix[DDIR_READ] = 100 - *val;
253 #ifdef FIO_HAVE_IOPRIO
254 static int str_prioclass_cb(void *data, unsigned int *val)
256 struct thread_data *td = data;
260 * mask off old class bits, str_prio_cb() may have set a default class
262 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
265 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
270 static int str_prio_cb(void *data, unsigned int *val)
272 struct thread_data *td = data;
277 * If no class is set, assume BE
279 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
280 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
287 static int str_exitall_cb(void)
289 exitall_on_terminate = 1;
293 #ifdef FIO_HAVE_CPU_AFFINITY
294 static int str_cpumask_cb(void *data, unsigned int *val)
296 struct thread_data *td = data;
301 ret = fio_cpuset_init(&td->o.cpumask);
303 log_err("fio: cpuset_init failed\n");
304 td_verror(td, ret, "fio_cpuset_init");
308 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
310 for (i = 0; i < sizeof(int) * 8; i++) {
311 if ((1 << i) & *val) {
313 log_err("fio: CPU %d too large (max=%ld)\n", i,
317 dprint(FD_PARSE, "set cpu allowed %d\n", i);
318 fio_cpu_set(&td->o.cpumask, i);
322 td->o.cpumask_set = 1;
326 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
333 ret = fio_cpuset_init(mask);
335 log_err("fio: cpuset_init failed\n");
336 td_verror(td, ret, "fio_cpuset_init");
340 p = str = strdup(input);
342 strip_blank_front(&str);
343 strip_blank_end(str);
345 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
347 while ((cpu = strsep(&str, ",")) != NULL) {
356 while ((cpu2 = strsep(&str2, "-")) != NULL) {
366 while (icpu <= icpu2) {
367 if (icpu >= FIO_MAX_CPUS) {
368 log_err("fio: your OS only supports up to"
369 " %d CPUs\n", (int) FIO_MAX_CPUS);
373 if (icpu > max_cpu) {
374 log_err("fio: CPU %d too large (max=%ld)\n",
380 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
381 fio_cpu_set(mask, icpu);
390 td->o.cpumask_set = 1;
394 static int str_cpus_allowed_cb(void *data, const char *input)
396 struct thread_data *td = data;
399 ret = set_cpus_allowed(td, &td->o.cpumask, input);
401 td->o.cpumask_set = 1;
406 static int str_verify_cpus_allowed_cb(void *data, const char *input)
408 struct thread_data *td = data;
411 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
413 td->o.verify_cpumask_set = 1;
419 static int str_fst_cb(void *data, const char *str)
421 struct thread_data *td = data;
422 char *nr = get_opt_postfix(str);
424 td->file_service_nr = 1;
426 td->file_service_nr = atoi(nr);
433 static int check_dir(struct thread_data *td, char *fname)
435 char file[PATH_MAX], *dir;
438 if (td->o.directory) {
439 strcpy(file, td->o.directory);
444 sprintf(file + elen, "%s", fname);
451 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
452 * yet, so we can't do this check right here...
454 if (lstat(dir, &sb) < 0) {
457 log_err("fio: %s is not a directory\n", dir);
458 td_verror(td, ret, "lstat");
462 if (!S_ISDIR(sb.st_mode)) {
463 log_err("fio: %s is not a directory\n", dir);
473 * Return next file in the string. Files are separated with ':'. If the ':'
474 * is escaped with a '\', then that ':' is part of the filename and does not
475 * indicate a new file.
477 static char *get_next_file_name(char **ptr)
482 if (!str || !strlen(str))
488 * No colon, we are done
490 p = strchr(str, ':');
497 * We got a colon, but it's the first character. Skip and
505 if (*(p - 1) != '\\') {
511 memmove(p - 1, p, strlen(p) + 1);
518 static int str_filename_cb(void *data, const char *input)
520 struct thread_data *td = data;
521 char *fname, *str, *p;
523 p = str = strdup(input);
525 strip_blank_front(&str);
526 strip_blank_end(str);
528 if (!td->files_index)
531 while ((fname = get_next_file_name(&str)) != NULL) {
534 if (check_dir(td, fname)) {
546 static int str_directory_cb(void *data, const char fio_unused *str)
548 struct thread_data *td = data;
551 if (lstat(td->o.directory, &sb) < 0) {
554 log_err("fio: %s is not a directory\n", td->o.directory);
555 td_verror(td, ret, "lstat");
558 if (!S_ISDIR(sb.st_mode)) {
559 log_err("fio: %s is not a directory\n", td->o.directory);
566 static int str_opendir_cb(void *data, const char fio_unused *str)
568 struct thread_data *td = data;
570 if (!td->files_index)
573 return add_dir_files(td, td->o.opendir);
576 static int str_verify_offset_cb(void *data, unsigned int *off)
578 struct thread_data *td = data;
580 if (*off && *off < sizeof(struct verify_header)) {
581 log_err("fio: verify_offset too small\n");
585 td->o.verify_offset = *off;
589 static int str_verify_pattern_cb(void *data, const char *input)
591 struct thread_data *td = data;
593 int i = 0, j = 0, len, k, base = 10;
596 loc1 = strstr(input, "0x");
597 loc2 = strstr(input, "0X");
600 off = strtol(input, NULL, base);
601 if (off != LONG_MAX || errno != ERANGE) {
603 td->o.verify_pattern[i] = off & 0xff;
612 j = loc1 - input + 2;
614 j = loc2 - input + 2;
617 if (len - j < MAX_PATTERN_SIZE * 2) {
619 off = converthexchartoint(input[k--]);
621 off += (converthexchartoint(input[k--])
623 td->o.verify_pattern[i++] = (char) off;
627 td->o.verify_pattern_bytes = i;
631 static int str_lockfile_cb(void *data, const char *str)
633 struct thread_data *td = data;
634 char *nr = get_opt_postfix(str);
636 td->o.lockfile_batch = 1;
638 td->o.lockfile_batch = atoi(nr);
645 static int str_write_bw_log_cb(void *data, const char *str)
647 struct thread_data *td = data;
650 td->o.bw_log_file = strdup(str);
652 td->o.write_bw_log = 1;
656 static int str_write_lat_log_cb(void *data, const char *str)
658 struct thread_data *td = data;
661 td->o.lat_log_file = strdup(str);
663 td->o.write_lat_log = 1;
667 static int str_gtod_reduce_cb(void *data, int *il)
669 struct thread_data *td = data;
672 td->o.disable_clat = !!val;
673 td->o.disable_slat = !!val;
674 td->o.disable_bw = !!val;
676 td->tv_cache_mask = 63;
681 static int str_gtod_cpu_cb(void *data, int *il)
683 struct thread_data *td = data;
686 td->o.gtod_cpu = val;
687 td->o.gtod_offload = 1;
691 static int rw_verify(struct fio_option *o, void *data)
693 struct thread_data *td = data;
695 if (read_only && td_write(td)) {
696 log_err("fio: job <%s> has write bit set, but fio is in"
697 " read-only mode\n", td->o.name);
704 static int gtod_cpu_verify(struct fio_option *o, void *data)
706 #ifndef FIO_HAVE_CPU_AFFINITY
707 struct thread_data *td = data;
709 if (td->o.gtod_cpu) {
710 log_err("fio: platform must support CPU affinity for"
711 "gettimeofday() offloading\n");
719 static int kb_base_verify(struct fio_option *o, void *data)
721 struct thread_data *td = data;
723 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
724 log_err("fio: kb_base set to nonsensical value: %u\n",
732 #define __stringify_1(x) #x
733 #define __stringify(x) __stringify_1(x)
736 * Map of job/command line options
738 static struct fio_option options[] = {
740 .name = "description",
741 .type = FIO_OPT_STR_STORE,
742 .off1 = td_var_offset(description),
743 .help = "Text job description",
747 .type = FIO_OPT_STR_STORE,
748 .off1 = td_var_offset(name),
749 .help = "Name of this job",
753 .type = FIO_OPT_STR_STORE,
754 .off1 = td_var_offset(directory),
755 .cb = str_directory_cb,
756 .help = "Directory to store files in",
760 .type = FIO_OPT_STR_STORE,
761 .off1 = td_var_offset(filename),
762 .cb = str_filename_cb,
763 .prio = -1, /* must come after "directory" */
764 .help = "File(s) to use for the workload",
769 .off1 = td_var_offset(kb_base),
770 .verify = kb_base_verify,
773 .help = "How many bytes per KB for reporting (1000 or 1024)",
778 .cb = str_lockfile_cb,
779 .off1 = td_var_offset(file_lock_mode),
780 .help = "Lock file when doing IO to it",
781 .parent = "filename",
785 .oval = FILE_LOCK_NONE,
786 .help = "No file locking",
788 { .ival = "exclusive",
789 .oval = FILE_LOCK_EXCLUSIVE,
790 .help = "Exclusive file lock",
794 .oval = FILE_LOCK_READWRITE,
795 .help = "Read vs write lock",
801 .type = FIO_OPT_STR_STORE,
802 .off1 = td_var_offset(opendir),
803 .cb = str_opendir_cb,
804 .help = "Recursively add files from this directory and down",
808 .alias = "readwrite",
811 .off1 = td_var_offset(td_ddir),
812 .help = "IO direction",
817 .oval = TD_DDIR_READ,
818 .help = "Sequential read",
821 .oval = TD_DDIR_WRITE,
822 .help = "Sequential write",
824 { .ival = "randread",
825 .oval = TD_DDIR_RANDREAD,
826 .help = "Random read",
828 { .ival = "randwrite",
829 .oval = TD_DDIR_RANDWRITE,
830 .help = "Random write",
834 .help = "Sequential read and write mix",
837 .oval = TD_DDIR_RANDRW,
838 .help = "Random read and write mix"
844 .type = FIO_OPT_STR_STORE,
845 .off1 = td_var_offset(ioengine),
846 .help = "IO engine to use",
850 .help = "Use read/write",
853 .help = "Use pread/pwrite",
856 .help = "Use readv/writev",
858 #ifdef FIO_HAVE_LIBAIO
860 .help = "Linux native asynchronous IO",
863 #ifdef FIO_HAVE_POSIXAIO
864 { .ival = "posixaio",
865 .help = "POSIX asynchronous IO",
868 #ifdef FIO_HAVE_SOLARISAIO
869 { .ival = "solarisaio",
870 .help = "Solaris native asynchronous IO",
874 .help = "Memory mapped IO",
876 #ifdef FIO_HAVE_SPLICE
878 .help = "splice/vmsplice based IO",
880 { .ival = "netsplice",
881 .help = "splice/vmsplice to/from the network",
886 .help = "SCSI generic v3 IO",
890 .help = "Testing engine (no data transfer)",
893 .help = "Network IO",
895 #ifdef FIO_HAVE_SYSLET
896 { .ival = "syslet-rw",
897 .help = "syslet enabled async pread/pwrite IO",
901 .help = "CPU cycler burner engine",
903 #ifdef FIO_HAVE_GUASI
905 .help = "GUASI IO engine",
908 { .ival = "external",
909 .help = "Load external engine (append name)",
916 .off1 = td_var_offset(iodepth),
917 .help = "Amount of IO buffers to keep in flight",
922 .name = "iodepth_batch",
923 .alias = "iodepth_batch_submit",
925 .off1 = td_var_offset(iodepth_batch),
926 .help = "Number of IO buffers to submit in one go",
932 .name = "iodepth_batch_complete",
934 .off1 = td_var_offset(iodepth_batch_complete),
935 .help = "Number of IO buffers to retrieve in one go",
941 .name = "iodepth_low",
943 .off1 = td_var_offset(iodepth_low),
944 .help = "Low water mark for queuing depth",
949 .type = FIO_OPT_STR_VAL,
950 .off1 = td_var_offset(size),
952 .help = "Total size of device or files",
955 .name = "fill_device",
956 .type = FIO_OPT_BOOL,
957 .off1 = td_var_offset(fill_device),
958 .help = "Write until an ENOSPC error occurs",
963 .type = FIO_OPT_STR_VAL,
964 .off1 = td_var_offset(file_size_low),
965 .off2 = td_var_offset(file_size_high),
967 .help = "Size of individual files",
971 .alias = "fileoffset",
972 .type = FIO_OPT_STR_VAL,
973 .off1 = td_var_offset(start_offset),
974 .help = "Start IO from this offset",
979 .alias = "blocksize",
981 .off1 = td_var_offset(bs[DDIR_READ]),
982 .off2 = td_var_offset(bs[DDIR_WRITE]),
984 .help = "Block size unit",
990 .alias = "blockalign",
992 .off1 = td_var_offset(ba[DDIR_READ]),
993 .off2 = td_var_offset(ba[DDIR_WRITE]),
995 .help = "IO block offset alignment",
1000 .alias = "blocksize_range",
1001 .type = FIO_OPT_RANGE,
1002 .off1 = td_var_offset(min_bs[DDIR_READ]),
1003 .off2 = td_var_offset(max_bs[DDIR_READ]),
1004 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1005 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
1007 .help = "Set block size range (in more detail than bs)",
1012 .type = FIO_OPT_STR,
1013 .cb = str_bssplit_cb,
1014 .help = "Set a specific mix of block sizes",
1018 .name = "bs_unaligned",
1019 .alias = "blocksize_unaligned",
1020 .type = FIO_OPT_STR_SET,
1021 .off1 = td_var_offset(bs_unaligned),
1022 .help = "Don't sector align IO buffer sizes",
1026 .name = "randrepeat",
1027 .type = FIO_OPT_BOOL,
1028 .off1 = td_var_offset(rand_repeatable),
1029 .help = "Use repeatable random IO pattern",
1034 .name = "norandommap",
1035 .type = FIO_OPT_STR_SET,
1036 .off1 = td_var_offset(norandommap),
1037 .help = "Accept potential duplicate random blocks",
1041 .name = "softrandommap",
1042 .type = FIO_OPT_BOOL,
1043 .off1 = td_var_offset(softrandommap),
1044 .help = "Set norandommap if randommap allocation fails",
1045 .parent = "norandommap",
1050 .type = FIO_OPT_INT,
1051 .off1 = td_var_offset(nr_files),
1052 .help = "Split job workload between this number of files",
1056 .name = "openfiles",
1057 .type = FIO_OPT_INT,
1058 .off1 = td_var_offset(open_files),
1059 .help = "Number of files to keep open at the same time",
1062 .name = "file_service_type",
1063 .type = FIO_OPT_STR,
1065 .off1 = td_var_offset(file_service_type),
1066 .help = "How to select which file to service next",
1067 .def = "roundrobin",
1070 .oval = FIO_FSERVICE_RANDOM,
1071 .help = "Choose a file at random",
1073 { .ival = "roundrobin",
1074 .oval = FIO_FSERVICE_RR,
1075 .help = "Round robin select files",
1077 { .ival = "sequential",
1078 .oval = FIO_FSERVICE_SEQ,
1079 .help = "Finish one file before moving to the next",
1082 .parent = "nrfiles",
1085 .name = "fadvise_hint",
1086 .type = FIO_OPT_BOOL,
1087 .off1 = td_var_offset(fadvise_hint),
1088 .help = "Use fadvise() to advise the kernel on IO pattern",
1093 .type = FIO_OPT_INT,
1094 .off1 = td_var_offset(fsync_blocks),
1095 .help = "Issue fsync for writes every given number of blocks",
1099 .name = "fdatasync",
1100 .type = FIO_OPT_INT,
1101 .off1 = td_var_offset(fdatasync_blocks),
1102 .help = "Issue fdatasync for writes every given number of blocks",
1107 .type = FIO_OPT_BOOL,
1108 .off1 = td_var_offset(odirect),
1109 .help = "Use O_DIRECT IO (negates buffered)",
1114 .type = FIO_OPT_BOOL,
1115 .off1 = td_var_offset(odirect),
1117 .help = "Use buffered IO (negates direct)",
1121 .name = "overwrite",
1122 .type = FIO_OPT_BOOL,
1123 .off1 = td_var_offset(overwrite),
1124 .help = "When writing, set whether to overwrite current data",
1129 .type = FIO_OPT_INT,
1130 .off1 = td_var_offset(loops),
1131 .help = "Number of times to run the job",
1136 .type = FIO_OPT_INT,
1137 .off1 = td_var_offset(numjobs),
1138 .help = "Duplicate this job this many times",
1142 .name = "startdelay",
1143 .type = FIO_OPT_INT,
1144 .off1 = td_var_offset(start_delay),
1145 .help = "Only start job when this period has passed",
1151 .type = FIO_OPT_STR_VAL_TIME,
1152 .off1 = td_var_offset(timeout),
1153 .help = "Stop workload when this amount of time has passed",
1157 .name = "time_based",
1158 .type = FIO_OPT_STR_SET,
1159 .off1 = td_var_offset(time_based),
1160 .help = "Keep running until runtime/timeout is met",
1163 .name = "ramp_time",
1164 .type = FIO_OPT_STR_VAL_TIME,
1165 .off1 = td_var_offset(ramp_time),
1166 .help = "Ramp up time before measuring performance",
1171 .type = FIO_OPT_STR,
1173 .off1 = td_var_offset(mem_type),
1174 .help = "Backing type for IO buffers",
1179 .help = "Use malloc(3) for IO buffers",
1183 .help = "Use shared memory segments for IO buffers",
1185 #ifdef FIO_HAVE_HUGETLB
1186 { .ival = "shmhuge",
1187 .oval = MEM_SHMHUGE,
1188 .help = "Like shm, but use huge pages",
1193 .help = "Use mmap(2) (file or anon) for IO buffers",
1195 #ifdef FIO_HAVE_HUGETLB
1196 { .ival = "mmaphuge",
1197 .oval = MEM_MMAPHUGE,
1198 .help = "Like mmap, but use huge pages",
1204 .name = "iomem_align",
1205 .alias = "mem_align",
1206 .type = FIO_OPT_INT,
1207 .off1 = td_var_offset(mem_align),
1209 .help = "IO memory buffer offset alignment",
1215 .type = FIO_OPT_STR,
1216 .off1 = td_var_offset(verify),
1217 .help = "Verify data written",
1221 .oval = VERIFY_NONE,
1222 .help = "Don't do IO verification",
1226 .help = "Use md5 checksums for verification",
1229 .oval = VERIFY_CRC64,
1230 .help = "Use crc64 checksums for verification",
1233 .oval = VERIFY_CRC32,
1234 .help = "Use crc32 checksums for verification",
1236 { .ival = "crc32c-intel",
1237 .oval = VERIFY_CRC32C_INTEL,
1238 .help = "Use hw crc32c checksums for verification",
1241 .oval = VERIFY_CRC32C,
1242 .help = "Use crc32c checksums for verification",
1245 .oval = VERIFY_CRC16,
1246 .help = "Use crc16 checksums for verification",
1249 .oval = VERIFY_CRC7,
1250 .help = "Use crc7 checksums for verification",
1253 .oval = VERIFY_SHA1,
1254 .help = "Use sha1 checksums for verification",
1257 .oval = VERIFY_SHA256,
1258 .help = "Use sha256 checksums for verification",
1261 .oval = VERIFY_SHA512,
1262 .help = "Use sha512 checksums for verification",
1265 .oval = VERIFY_META,
1266 .help = "Use io information",
1270 .oval = VERIFY_NULL,
1271 .help = "Pretend to verify",
1276 .name = "do_verify",
1277 .type = FIO_OPT_BOOL,
1278 .off1 = td_var_offset(do_verify),
1279 .help = "Run verification stage after write",
1284 .name = "verifysort",
1285 .type = FIO_OPT_BOOL,
1286 .off1 = td_var_offset(verifysort),
1287 .help = "Sort written verify blocks for read back",
1292 .name = "verify_interval",
1293 .type = FIO_OPT_INT,
1294 .off1 = td_var_offset(verify_interval),
1295 .minval = 2 * sizeof(struct verify_header),
1296 .help = "Store verify buffer header every N bytes",
1300 .name = "verify_offset",
1301 .type = FIO_OPT_INT,
1302 .help = "Offset verify header location by N bytes",
1304 .cb = str_verify_offset_cb,
1308 .name = "verify_pattern",
1309 .type = FIO_OPT_STR,
1310 .cb = str_verify_pattern_cb,
1311 .help = "Fill pattern for IO buffers",
1315 .name = "verify_fatal",
1316 .type = FIO_OPT_BOOL,
1317 .off1 = td_var_offset(verify_fatal),
1319 .help = "Exit on a single verify failure, don't continue",
1323 .name = "verify_async",
1324 .type = FIO_OPT_INT,
1325 .off1 = td_var_offset(verify_async),
1327 .help = "Number of async verifier threads to use",
1330 #ifdef FIO_HAVE_CPU_AFFINITY
1332 .name = "verify_async_cpus",
1333 .type = FIO_OPT_STR,
1334 .cb = str_verify_cpus_allowed_cb,
1335 .help = "Set CPUs allowed for async verify threads",
1336 .parent = "verify_async",
1340 .name = "write_iolog",
1341 .type = FIO_OPT_STR_STORE,
1342 .off1 = td_var_offset(write_iolog_file),
1343 .help = "Store IO pattern to file",
1346 .name = "read_iolog",
1347 .type = FIO_OPT_STR_STORE,
1348 .off1 = td_var_offset(read_iolog_file),
1349 .help = "Playback IO pattern from file",
1352 .name = "exec_prerun",
1353 .type = FIO_OPT_STR_STORE,
1354 .off1 = td_var_offset(exec_prerun),
1355 .help = "Execute this file prior to running job",
1358 .name = "exec_postrun",
1359 .type = FIO_OPT_STR_STORE,
1360 .off1 = td_var_offset(exec_postrun),
1361 .help = "Execute this file after running job",
1363 #ifdef FIO_HAVE_IOSCHED_SWITCH
1365 .name = "ioscheduler",
1366 .type = FIO_OPT_STR_STORE,
1367 .off1 = td_var_offset(ioscheduler),
1368 .help = "Use this IO scheduler on the backing device",
1373 .type = FIO_OPT_STR_VAL,
1374 .off1 = td_var_offset(zone_size),
1375 .help = "Give size of an IO zone",
1380 .type = FIO_OPT_STR_VAL,
1381 .off1 = td_var_offset(zone_skip),
1382 .help = "Space between IO zones",
1387 .type = FIO_OPT_STR_VAL,
1388 .cb = str_lockmem_cb,
1389 .help = "Lock down this amount of memory",
1393 .name = "rwmixread",
1394 .type = FIO_OPT_INT,
1395 .cb = str_rwmix_read_cb,
1397 .help = "Percentage of mixed workload that is reads",
1401 .name = "rwmixwrite",
1402 .type = FIO_OPT_INT,
1403 .cb = str_rwmix_write_cb,
1405 .help = "Percentage of mixed workload that is writes",
1409 .name = "rwmixcycle",
1410 .type = FIO_OPT_DEPRECATED,
1414 .type = FIO_OPT_INT,
1415 .off1 = td_var_offset(nice),
1416 .help = "Set job CPU nice value",
1421 #ifdef FIO_HAVE_IOPRIO
1424 .type = FIO_OPT_INT,
1426 .help = "Set job IO priority value",
1431 .name = "prioclass",
1432 .type = FIO_OPT_INT,
1433 .cb = str_prioclass_cb,
1434 .help = "Set job IO priority class",
1440 .name = "thinktime",
1441 .type = FIO_OPT_INT,
1442 .off1 = td_var_offset(thinktime),
1443 .help = "Idle time between IO buffers (usec)",
1447 .name = "thinktime_spin",
1448 .type = FIO_OPT_INT,
1449 .off1 = td_var_offset(thinktime_spin),
1450 .help = "Start think time by spinning this amount (usec)",
1452 .parent = "thinktime",
1455 .name = "thinktime_blocks",
1456 .type = FIO_OPT_INT,
1457 .off1 = td_var_offset(thinktime_blocks),
1458 .help = "IO buffer period between 'thinktime'",
1460 .parent = "thinktime",
1464 .type = FIO_OPT_INT,
1465 .off1 = td_var_offset(rate[0]),
1466 .off2 = td_var_offset(rate[1]),
1467 .help = "Set bandwidth rate",
1471 .type = FIO_OPT_INT,
1472 .off1 = td_var_offset(ratemin[0]),
1473 .off2 = td_var_offset(ratemin[1]),
1474 .help = "Job must meet this rate or it will be shutdown",
1478 .name = "rate_iops",
1479 .type = FIO_OPT_INT,
1480 .off1 = td_var_offset(rate_iops[0]),
1481 .off2 = td_var_offset(rate_iops[1]),
1482 .help = "Limit IO used to this number of IO operations/sec",
1485 .name = "rate_iops_min",
1486 .type = FIO_OPT_INT,
1487 .off1 = td_var_offset(rate_iops_min[0]),
1488 .off2 = td_var_offset(rate_iops_min[1]),
1489 .help = "Job must meet this rate or it will be shutdown",
1490 .parent = "rate_iops",
1493 .name = "ratecycle",
1494 .type = FIO_OPT_INT,
1495 .off1 = td_var_offset(ratecycle),
1496 .help = "Window average for rate limits (msec)",
1501 .name = "invalidate",
1502 .type = FIO_OPT_BOOL,
1503 .off1 = td_var_offset(invalidate_cache),
1504 .help = "Invalidate buffer/page cache prior to running job",
1509 .type = FIO_OPT_BOOL,
1510 .off1 = td_var_offset(sync_io),
1511 .help = "Use O_SYNC for buffered writes",
1513 .parent = "buffered",
1516 .name = "bwavgtime",
1517 .type = FIO_OPT_INT,
1518 .off1 = td_var_offset(bw_avg_time),
1519 .help = "Time window over which to calculate bandwidth"
1524 .name = "create_serialize",
1525 .type = FIO_OPT_BOOL,
1526 .off1 = td_var_offset(create_serialize),
1527 .help = "Serialize creating of job files",
1531 .name = "create_fsync",
1532 .type = FIO_OPT_BOOL,
1533 .off1 = td_var_offset(create_fsync),
1534 .help = "Fsync file after creation",
1538 .name = "create_on_open",
1539 .type = FIO_OPT_BOOL,
1540 .off1 = td_var_offset(create_on_open),
1541 .help = "Create files when they are opened for IO",
1546 .type = FIO_OPT_BOOL,
1547 .off1 = td_var_offset(pre_read),
1548 .help = "Preread files before starting official testing",
1553 .type = FIO_OPT_INT,
1554 .off1 = td_var_offset(cpuload),
1555 .help = "Use this percentage of CPU",
1558 .name = "cpuchunks",
1559 .type = FIO_OPT_INT,
1560 .off1 = td_var_offset(cpucycle),
1561 .help = "Length of the CPU burn cycles (usecs)",
1563 .parent = "cpuload",
1565 #ifdef FIO_HAVE_CPU_AFFINITY
1568 .type = FIO_OPT_INT,
1569 .cb = str_cpumask_cb,
1570 .help = "CPU affinity mask",
1573 .name = "cpus_allowed",
1574 .type = FIO_OPT_STR,
1575 .cb = str_cpus_allowed_cb,
1576 .help = "Set CPUs allowed",
1580 .name = "end_fsync",
1581 .type = FIO_OPT_BOOL,
1582 .off1 = td_var_offset(end_fsync),
1583 .help = "Include fsync at the end of job",
1587 .name = "fsync_on_close",
1588 .type = FIO_OPT_BOOL,
1589 .off1 = td_var_offset(fsync_on_close),
1590 .help = "fsync files on close",
1595 .type = FIO_OPT_BOOL,
1596 .off1 = td_var_offset(unlink),
1597 .help = "Unlink created files after job has completed",
1602 .type = FIO_OPT_STR_SET,
1603 .cb = str_exitall_cb,
1604 .help = "Terminate all jobs when one exits",
1607 .name = "stonewall",
1608 .type = FIO_OPT_STR_SET,
1609 .off1 = td_var_offset(stonewall),
1610 .help = "Insert a hard barrier between this job and previous",
1613 .name = "new_group",
1614 .type = FIO_OPT_STR_SET,
1615 .off1 = td_var_offset(new_group),
1616 .help = "Mark the start of a new group (for reporting)",
1620 .type = FIO_OPT_STR_SET,
1621 .off1 = td_var_offset(use_thread),
1622 .help = "Use threads instead of forks",
1625 .name = "write_bw_log",
1626 .type = FIO_OPT_STR,
1627 .off1 = td_var_offset(write_bw_log),
1628 .cb = str_write_bw_log_cb,
1629 .help = "Write log of bandwidth during run",
1632 .name = "write_lat_log",
1633 .type = FIO_OPT_STR,
1634 .off1 = td_var_offset(write_lat_log),
1635 .cb = str_write_lat_log_cb,
1636 .help = "Write log of latency during run",
1639 .name = "hugepage-size",
1640 .type = FIO_OPT_INT,
1641 .off1 = td_var_offset(hugepage_size),
1642 .help = "When using hugepages, specify size of each page",
1643 .def = __stringify(FIO_HUGE_PAGE),
1646 .name = "group_reporting",
1647 .type = FIO_OPT_STR_SET,
1648 .off1 = td_var_offset(group_reporting),
1649 .help = "Do reporting on a per-group basis",
1652 .name = "zero_buffers",
1653 .type = FIO_OPT_STR_SET,
1654 .off1 = td_var_offset(zero_buffers),
1655 .help = "Init IO buffers to all zeroes",
1658 .name = "refill_buffers",
1659 .type = FIO_OPT_STR_SET,
1660 .off1 = td_var_offset(refill_buffers),
1661 .help = "Refill IO buffers on every IO submit",
1663 #ifdef FIO_HAVE_DISK_UTIL
1665 .name = "disk_util",
1666 .type = FIO_OPT_BOOL,
1667 .off1 = td_var_offset(do_disk_util),
1668 .help = "Log disk utilization statistics",
1673 .name = "gtod_reduce",
1674 .type = FIO_OPT_BOOL,
1675 .help = "Greatly reduce number of gettimeofday() calls",
1676 .cb = str_gtod_reduce_cb,
1680 .name = "disable_clat",
1681 .type = FIO_OPT_BOOL,
1682 .off1 = td_var_offset(disable_clat),
1683 .help = "Disable completion latency numbers",
1684 .parent = "gtod_reduce",
1688 .name = "disable_slat",
1689 .type = FIO_OPT_BOOL,
1690 .off1 = td_var_offset(disable_slat),
1691 .help = "Disable submissionn latency numbers",
1692 .parent = "gtod_reduce",
1696 .name = "disable_bw_measurement",
1697 .type = FIO_OPT_BOOL,
1698 .off1 = td_var_offset(disable_bw),
1699 .help = "Disable bandwidth logging",
1700 .parent = "gtod_reduce",
1705 .type = FIO_OPT_INT,
1706 .cb = str_gtod_cpu_cb,
1707 .help = "Setup dedicated gettimeofday() thread on this CPU",
1708 .verify = gtod_cpu_verify,
1711 .name = "continue_on_error",
1712 .type = FIO_OPT_BOOL,
1713 .off1 = td_var_offset(continue_on_error),
1714 .help = "Continue on non-fatal errors during I/O",
1719 .type = FIO_OPT_STR,
1720 .off1 = td_var_offset(profile),
1722 { .ival = "tiobench",
1723 .oval = PROFILE_TIOBENCH,
1724 .help = "Perform tiobench like test",
1727 .help = "Select a specific builtin performance test",
1731 .type = FIO_OPT_STR_STORE,
1732 .off1 = td_var_offset(cgroup),
1733 .help = "Add job to cgroup of this name",
1736 .name = "cgroup_weight",
1737 .type = FIO_OPT_INT,
1738 .off1 = td_var_offset(cgroup_weight),
1739 .help = "Use given weight for cgroup",
1745 .type = FIO_OPT_INT,
1746 .off1 = td_var_offset(uid),
1747 .help = "Run job with this user ID",
1751 .type = FIO_OPT_INT,
1752 .off1 = td_var_offset(gid),
1753 .help = "Run job with this group ID",
1760 void fio_options_dup_and_init(struct option *long_options)
1762 struct fio_option *o;
1765 options_init(options);
1768 while (long_options[i].name)
1773 long_options[i].name = (char *) o->name;
1774 long_options[i].val = FIO_GETOPT_JOB;
1775 if (o->type == FIO_OPT_STR_SET)
1776 long_options[i].has_arg = no_argument;
1778 long_options[i].has_arg = required_argument;
1782 assert(i < FIO_NR_OPTIONS);
1786 struct fio_keyword {
1792 static struct fio_keyword fio_keywords[] = {
1794 .word = "$pagesize",
1795 .desc = "Page size in the system",
1798 .word = "$mb_memory",
1799 .desc = "Megabytes of memory online",
1803 .desc = "Number of CPUs online in the system",
1810 void fio_keywords_init(void)
1812 unsigned long long mb_memory;
1816 sprintf(buf, "%lu", page_size);
1817 fio_keywords[0].replace = strdup(buf);
1819 mb_memory = os_phys_mem() / page_size;
1820 sprintf(buf, "%llu", mb_memory);
1821 fio_keywords[1].replace = strdup(buf);
1823 l = sysconf(_SC_NPROCESSORS_ONLN);
1824 sprintf(buf, "%lu", l);
1825 fio_keywords[2].replace = strdup(buf);
1830 static char *bc_calc(char *str)
1832 char *buf, *tmp, opt[80];
1837 * No math, just return string
1839 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1844 * Split option from value, we only need to calculate the value
1846 tmp = strchr(str, '=');
1851 memset(opt, 0, sizeof(opt));
1852 strncpy(opt, str, tmp - str);
1856 sprintf(buf, "which %s > /dev/null", BC_APP);
1858 log_err("fio: bc is needed for performing math\n");
1863 sprintf(buf, "echo %s | %s", tmp, BC_APP);
1864 f = popen(buf, "r");
1870 ret = fread(buf, 1, 128, f);
1876 buf[ret - 1] = '\0';
1885 * Look for reserved variable names and replace them with real values
1887 static char *fio_keyword_replace(char *opt)
1892 for (i = 0; fio_keywords[i].word != NULL; i++) {
1893 struct fio_keyword *kw = &fio_keywords[i];
1895 while ((s = strstr(opt, kw->word)) != NULL) {
1896 char *new = malloc(strlen(opt) + 1);
1902 * Copy part of the string before the keyword and
1903 * sprintf() the replacement after it.
1905 memcpy(new, opt, olen);
1906 len = sprintf(new + olen, "%s", kw->replace);
1909 * If there's more in the original string, copy that
1912 opt += strlen(kw->word) + olen;
1914 memcpy(new + olen + len, opt, opt - o_org - 1);
1917 * replace opt and free the old opt
1923 * Check for potential math and invoke bc, if possible
1932 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
1936 sort_options(opts, options, num_opts);
1938 for (ret = 0, i = 0; i < num_opts; i++) {
1939 opts[i] = fio_keyword_replace(opts[i]);
1940 ret |= parse_option(opts[i], options, td);
1946 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1948 return parse_cmd_option(opt, val, options, td);
1951 void fio_fill_default_options(struct thread_data *td)
1953 fill_default_options(td, options);
1956 int fio_show_option_help(const char *opt)
1958 return show_cmd_help(options, opt);
1961 static void __options_mem(struct thread_data *td, int alloc)
1963 struct thread_options *o = &td->o;
1964 struct fio_option *opt;
1968 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1969 if (opt->type != FIO_OPT_STR_STORE)
1972 ptr = (void *) o + opt->off1;
1975 *ptr = strdup(*ptr);
1985 * dupe FIO_OPT_STR_STORE options
1987 void options_mem_dupe(struct thread_data *td)
1989 __options_mem(td, 1);
1992 void options_mem_free(struct thread_data fio_unused *td)
1995 __options_mem(td, 0);
1999 unsigned int fio_get_kb_base(void *data)
2001 struct thread_data *td = data;
2002 unsigned int kb_base = 0;
2005 kb_base = td->o.kb_base;