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 bs_cmp(const void *p1, const void *p2)
38 const struct bssplit *bsp1 = p1;
39 const struct bssplit *bsp2 = p2;
41 return bsp1->perc < bsp2->perc;
44 static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
46 struct bssplit *bssplit;
47 unsigned int i, perc, perc_missing;
48 unsigned int max_bs, min_bs;
52 td->o.bssplit_nr[ddir] = 4;
53 bssplit = malloc(4 * sizeof(struct bssplit));
58 while ((fname = strsep(&str, ":")) != NULL) {
65 * grow struct buffer, if needed
67 if (i == td->o.bssplit_nr[ddir]) {
68 td->o.bssplit_nr[ddir] <<= 1;
69 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
70 * sizeof(struct bssplit));
73 perc_str = strstr(fname, "/");
77 perc = atoi(perc_str);
85 if (str_to_decimal(fname, &val, 1, &td)) {
86 log_err("fio: bssplit conversion failed\n");
97 bssplit[i].perc = perc;
101 td->o.bssplit_nr[ddir] = i;
104 * Now check if the percentages add up, and how much is missing
106 perc = perc_missing = 0;
107 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
108 struct bssplit *bsp = &bssplit[i];
110 if (bsp->perc == (unsigned char) -1)
117 log_err("fio: bssplit percentages add to more than 100%%\n");
122 * If values didn't have a percentage set, divide the remains between
126 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
127 struct bssplit *bsp = &bssplit[i];
129 if (bsp->perc == (unsigned char) -1)
130 bsp->perc = (100 - perc) / perc_missing;
134 td->o.min_bs[ddir] = min_bs;
135 td->o.max_bs[ddir] = max_bs;
138 * now sort based on percentages, for ease of lookup
140 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
141 td->o.bssplit[ddir] = bssplit;
146 static int str_bssplit_cb(void *data, const char *input)
148 struct thread_data *td = data;
149 char *str, *p, *odir;
152 p = str = strdup(input);
154 strip_blank_front(&str);
155 strip_blank_end(str);
157 odir = strchr(str, ',');
159 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
162 ret = bssplit_ddir(td, DDIR_READ, str);
169 ret = bssplit_ddir(td, DDIR_READ, str);
171 ret = bssplit_ddir(td, DDIR_WRITE, op);
180 static int str_rw_cb(void *data, const char *str)
182 struct thread_data *td = data;
183 char *nr = get_opt_postfix(str);
187 td->o.ddir_nr = atoi(nr);
194 static int str_mem_cb(void *data, const char *mem)
196 struct thread_data *td = data;
198 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
199 td->mmapfile = get_opt_postfix(mem);
200 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
201 log_err("fio: mmaphuge:/path/to/file\n");
209 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
215 static int str_rwmix_read_cb(void *data, unsigned int *val)
217 struct thread_data *td = data;
219 td->o.rwmix[DDIR_READ] = *val;
220 td->o.rwmix[DDIR_WRITE] = 100 - *val;
224 static int str_rwmix_write_cb(void *data, unsigned int *val)
226 struct thread_data *td = data;
228 td->o.rwmix[DDIR_WRITE] = *val;
229 td->o.rwmix[DDIR_READ] = 100 - *val;
233 #ifdef FIO_HAVE_IOPRIO
234 static int str_prioclass_cb(void *data, unsigned int *val)
236 struct thread_data *td = data;
240 * mask off old class bits, str_prio_cb() may have set a default class
242 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
245 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
250 static int str_prio_cb(void *data, unsigned int *val)
252 struct thread_data *td = data;
257 * If no class is set, assume BE
259 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
260 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
267 static int str_exitall_cb(void)
269 exitall_on_terminate = 1;
273 #ifdef FIO_HAVE_CPU_AFFINITY
274 static int str_cpumask_cb(void *data, unsigned int *val)
276 struct thread_data *td = data;
281 ret = fio_cpuset_init(&td->o.cpumask);
283 log_err("fio: cpuset_init failed\n");
284 td_verror(td, ret, "fio_cpuset_init");
288 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
290 for (i = 0; i < sizeof(int) * 8; i++) {
291 if ((1 << i) & *val) {
293 log_err("fio: CPU %d too large (max=%ld)\n", i,
297 dprint(FD_PARSE, "set cpu allowed %d\n", i);
298 fio_cpu_set(&td->o.cpumask, i);
302 td->o.cpumask_set = 1;
306 static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
313 ret = fio_cpuset_init(mask);
315 log_err("fio: cpuset_init failed\n");
316 td_verror(td, ret, "fio_cpuset_init");
320 p = str = strdup(input);
322 strip_blank_front(&str);
323 strip_blank_end(str);
325 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
327 while ((cpu = strsep(&str, ",")) != NULL) {
336 while ((cpu2 = strsep(&str2, "-")) != NULL) {
346 while (icpu <= icpu2) {
347 if (icpu >= FIO_MAX_CPUS) {
348 log_err("fio: your OS only supports up to"
349 " %d CPUs\n", (int) FIO_MAX_CPUS);
353 if (icpu > max_cpu) {
354 log_err("fio: CPU %d too large (max=%ld)\n",
360 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
361 fio_cpu_set(mask, icpu);
370 td->o.cpumask_set = 1;
374 static int str_cpus_allowed_cb(void *data, const char *input)
376 struct thread_data *td = data;
379 ret = set_cpus_allowed(td, &td->o.cpumask, input);
381 td->o.cpumask_set = 1;
386 static int str_verify_cpus_allowed_cb(void *data, const char *input)
388 struct thread_data *td = data;
391 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
393 td->o.verify_cpumask_set = 1;
399 static int str_fst_cb(void *data, const char *str)
401 struct thread_data *td = data;
402 char *nr = get_opt_postfix(str);
404 td->file_service_nr = 1;
406 td->file_service_nr = atoi(nr);
413 static int check_dir(struct thread_data *td, char *fname)
415 char file[PATH_MAX], *dir;
418 if (td->o.directory) {
419 strcpy(file, td->o.directory);
424 sprintf(file + elen, "%s", fname);
431 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
432 * yet, so we can't do this check right here...
434 if (lstat(dir, &sb) < 0) {
437 log_err("fio: %s is not a directory\n", dir);
438 td_verror(td, ret, "lstat");
442 if (!S_ISDIR(sb.st_mode)) {
443 log_err("fio: %s is not a directory\n", dir);
453 * Return next file in the string. Files are separated with ':'. If the ':'
454 * is escaped with a '\', then that ':' is part of the filename and does not
455 * indicate a new file.
457 static char *get_next_file_name(char **ptr)
462 if (!str || !strlen(str))
468 * No colon, we are done
470 p = strchr(str, ':');
477 * We got a colon, but it's the first character. Skip and
485 if (*(p - 1) != '\\') {
491 memmove(p - 1, p, strlen(p) + 1);
498 static int str_filename_cb(void *data, const char *input)
500 struct thread_data *td = data;
501 char *fname, *str, *p;
503 p = str = strdup(input);
505 strip_blank_front(&str);
506 strip_blank_end(str);
508 if (!td->files_index)
511 while ((fname = get_next_file_name(&str)) != NULL) {
514 if (check_dir(td, fname)) {
526 static int str_directory_cb(void *data, const char fio_unused *str)
528 struct thread_data *td = data;
531 if (lstat(td->o.directory, &sb) < 0) {
534 log_err("fio: %s is not a directory\n", td->o.directory);
535 td_verror(td, ret, "lstat");
538 if (!S_ISDIR(sb.st_mode)) {
539 log_err("fio: %s is not a directory\n", td->o.directory);
546 static int str_opendir_cb(void *data, const char fio_unused *str)
548 struct thread_data *td = data;
550 if (!td->files_index)
553 return add_dir_files(td, td->o.opendir);
556 static int str_verify_offset_cb(void *data, unsigned int *off)
558 struct thread_data *td = data;
560 if (*off && *off < sizeof(struct verify_header)) {
561 log_err("fio: verify_offset too small\n");
565 td->o.verify_offset = *off;
569 static int str_verify_pattern_cb(void *data, unsigned int *off)
571 struct thread_data *td = data;
576 td->o.verify_pattern_bytes = 1;
578 td->o.verify_pattern_bytes = 2;
580 td->o.verify_pattern_bytes = 3;
582 td->o.verify_pattern_bytes = 4;
584 td->o.verify_pattern = *off;
588 static int str_lockfile_cb(void *data, const char *str)
590 struct thread_data *td = data;
591 char *nr = get_opt_postfix(str);
593 td->o.lockfile_batch = 1;
595 td->o.lockfile_batch = atoi(nr);
602 static int str_write_bw_log_cb(void *data, const char *str)
604 struct thread_data *td = data;
607 td->o.bw_log_file = strdup(str);
609 td->o.write_bw_log = 1;
613 static int str_write_lat_log_cb(void *data, const char *str)
615 struct thread_data *td = data;
618 td->o.lat_log_file = strdup(str);
620 td->o.write_lat_log = 1;
624 static int str_gtod_reduce_cb(void *data, int *il)
626 struct thread_data *td = data;
629 td->o.disable_clat = !!val;
630 td->o.disable_slat = !!val;
631 td->o.disable_bw = !!val;
633 td->tv_cache_mask = 63;
638 static int str_gtod_cpu_cb(void *data, int *il)
640 struct thread_data *td = data;
643 td->o.gtod_cpu = val;
644 td->o.gtod_offload = 1;
648 static int rw_verify(struct fio_option *o, void *data)
650 struct thread_data *td = data;
652 if (read_only && td_write(td)) {
653 log_err("fio: job <%s> has write bit set, but fio is in"
654 " read-only mode\n", td->o.name);
661 static int gtod_cpu_verify(struct fio_option *o, void *data)
663 #ifndef FIO_HAVE_CPU_AFFINITY
664 struct thread_data *td = data;
666 if (td->o.gtod_cpu) {
667 log_err("fio: platform must support CPU affinity for"
668 "gettimeofday() offloading\n");
676 static int kb_base_verify(struct fio_option *o, void *data)
678 struct thread_data *td = data;
680 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
681 log_err("fio: kb_base set to nonsensical value: %u\n",
689 #define __stringify_1(x) #x
690 #define __stringify(x) __stringify_1(x)
693 * Map of job/command line options
695 static struct fio_option options[] = {
697 .name = "description",
698 .type = FIO_OPT_STR_STORE,
699 .off1 = td_var_offset(description),
700 .help = "Text job description",
704 .type = FIO_OPT_STR_STORE,
705 .off1 = td_var_offset(name),
706 .help = "Name of this job",
710 .type = FIO_OPT_STR_STORE,
711 .off1 = td_var_offset(directory),
712 .cb = str_directory_cb,
713 .help = "Directory to store files in",
717 .type = FIO_OPT_STR_STORE,
718 .off1 = td_var_offset(filename),
719 .cb = str_filename_cb,
720 .prio = -1, /* must come after "directory" */
721 .help = "File(s) to use for the workload",
726 .off1 = td_var_offset(kb_base),
727 .verify = kb_base_verify,
730 .help = "How many bytes per KB for reporting (1000 or 1024)",
735 .cb = str_lockfile_cb,
736 .off1 = td_var_offset(file_lock_mode),
737 .help = "Lock file when doing IO to it",
738 .parent = "filename",
742 .oval = FILE_LOCK_NONE,
743 .help = "No file locking",
745 { .ival = "exclusive",
746 .oval = FILE_LOCK_EXCLUSIVE,
747 .help = "Exclusive file lock",
751 .oval = FILE_LOCK_READWRITE,
752 .help = "Read vs write lock",
758 .type = FIO_OPT_STR_STORE,
759 .off1 = td_var_offset(opendir),
760 .cb = str_opendir_cb,
761 .help = "Recursively add files from this directory and down",
765 .alias = "readwrite",
768 .off1 = td_var_offset(td_ddir),
769 .help = "IO direction",
774 .oval = TD_DDIR_READ,
775 .help = "Sequential read",
778 .oval = TD_DDIR_WRITE,
779 .help = "Sequential write",
781 { .ival = "randread",
782 .oval = TD_DDIR_RANDREAD,
783 .help = "Random read",
785 { .ival = "randwrite",
786 .oval = TD_DDIR_RANDWRITE,
787 .help = "Random write",
791 .help = "Sequential read and write mix",
794 .oval = TD_DDIR_RANDRW,
795 .help = "Random read and write mix"
801 .type = FIO_OPT_STR_STORE,
802 .off1 = td_var_offset(ioengine),
803 .help = "IO engine to use",
807 .help = "Use read/write",
810 .help = "Use pread/pwrite",
813 .help = "Use readv/writev",
815 #ifdef FIO_HAVE_LIBAIO
817 .help = "Linux native asynchronous IO",
820 #ifdef FIO_HAVE_POSIXAIO
821 { .ival = "posixaio",
822 .help = "POSIX asynchronous IO",
825 #ifdef FIO_HAVE_SOLARISAIO
826 { .ival = "solarisaio",
827 .help = "Solaris native asynchronous IO",
831 .help = "Memory mapped IO",
833 #ifdef FIO_HAVE_SPLICE
835 .help = "splice/vmsplice based IO",
837 { .ival = "netsplice",
838 .help = "splice/vmsplice to/from the network",
843 .help = "SCSI generic v3 IO",
847 .help = "Testing engine (no data transfer)",
850 .help = "Network IO",
852 #ifdef FIO_HAVE_SYSLET
853 { .ival = "syslet-rw",
854 .help = "syslet enabled async pread/pwrite IO",
858 .help = "CPU cycler burner engine",
860 #ifdef FIO_HAVE_GUASI
862 .help = "GUASI IO engine",
865 { .ival = "external",
866 .help = "Load external engine (append name)",
873 .off1 = td_var_offset(iodepth),
874 .help = "Amount of IO buffers to keep in flight",
879 .name = "iodepth_batch",
880 .alias = "iodepth_batch_submit",
882 .off1 = td_var_offset(iodepth_batch),
883 .help = "Number of IO buffers to submit in one go",
889 .name = "iodepth_batch_complete",
891 .off1 = td_var_offset(iodepth_batch_complete),
892 .help = "Number of IO buffers to retrieve in one go",
898 .name = "iodepth_low",
900 .off1 = td_var_offset(iodepth_low),
901 .help = "Low water mark for queuing depth",
906 .type = FIO_OPT_STR_VAL,
907 .off1 = td_var_offset(size),
909 .help = "Total size of device or files",
912 .name = "fill_device",
913 .type = FIO_OPT_BOOL,
914 .off1 = td_var_offset(fill_device),
915 .help = "Write until an ENOSPC error occurs",
920 .type = FIO_OPT_STR_VAL,
921 .off1 = td_var_offset(file_size_low),
922 .off2 = td_var_offset(file_size_high),
924 .help = "Size of individual files",
928 .alias = "fileoffset",
929 .type = FIO_OPT_STR_VAL,
930 .off1 = td_var_offset(start_offset),
931 .help = "Start IO from this offset",
936 .alias = "blocksize",
938 .off1 = td_var_offset(bs[DDIR_READ]),
939 .off2 = td_var_offset(bs[DDIR_WRITE]),
941 .help = "Block size unit",
947 .alias = "blockalign",
949 .off1 = td_var_offset(ba[DDIR_READ]),
950 .off2 = td_var_offset(ba[DDIR_WRITE]),
952 .help = "IO block offset alignment",
957 .alias = "blocksize_range",
958 .type = FIO_OPT_RANGE,
959 .off1 = td_var_offset(min_bs[DDIR_READ]),
960 .off2 = td_var_offset(max_bs[DDIR_READ]),
961 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
962 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
964 .help = "Set block size range (in more detail than bs)",
970 .cb = str_bssplit_cb,
971 .help = "Set a specific mix of block sizes",
975 .name = "bs_unaligned",
976 .alias = "blocksize_unaligned",
977 .type = FIO_OPT_STR_SET,
978 .off1 = td_var_offset(bs_unaligned),
979 .help = "Don't sector align IO buffer sizes",
983 .name = "randrepeat",
984 .type = FIO_OPT_BOOL,
985 .off1 = td_var_offset(rand_repeatable),
986 .help = "Use repeatable random IO pattern",
991 .name = "norandommap",
992 .type = FIO_OPT_STR_SET,
993 .off1 = td_var_offset(norandommap),
994 .help = "Accept potential duplicate random blocks",
998 .name = "softrandommap",
999 .type = FIO_OPT_BOOL,
1000 .off1 = td_var_offset(softrandommap),
1001 .help = "Set norandommap if randommap allocation fails",
1002 .parent = "norandommap",
1007 .type = FIO_OPT_INT,
1008 .off1 = td_var_offset(nr_files),
1009 .help = "Split job workload between this number of files",
1013 .name = "openfiles",
1014 .type = FIO_OPT_INT,
1015 .off1 = td_var_offset(open_files),
1016 .help = "Number of files to keep open at the same time",
1019 .name = "file_service_type",
1020 .type = FIO_OPT_STR,
1022 .off1 = td_var_offset(file_service_type),
1023 .help = "How to select which file to service next",
1024 .def = "roundrobin",
1027 .oval = FIO_FSERVICE_RANDOM,
1028 .help = "Choose a file at random",
1030 { .ival = "roundrobin",
1031 .oval = FIO_FSERVICE_RR,
1032 .help = "Round robin select files",
1034 { .ival = "sequential",
1035 .oval = FIO_FSERVICE_SEQ,
1036 .help = "Finish one file before moving to the next",
1039 .parent = "nrfiles",
1042 .name = "fadvise_hint",
1043 .type = FIO_OPT_BOOL,
1044 .off1 = td_var_offset(fadvise_hint),
1045 .help = "Use fadvise() to advise the kernel on IO pattern",
1050 .type = FIO_OPT_INT,
1051 .off1 = td_var_offset(fsync_blocks),
1052 .help = "Issue fsync for writes every given number of blocks",
1056 .name = "fdatasync",
1057 .type = FIO_OPT_INT,
1058 .off1 = td_var_offset(fdatasync_blocks),
1059 .help = "Issue fdatasync for writes every given number of blocks",
1064 .type = FIO_OPT_BOOL,
1065 .off1 = td_var_offset(odirect),
1066 .help = "Use O_DIRECT IO (negates buffered)",
1071 .type = FIO_OPT_BOOL,
1072 .off1 = td_var_offset(odirect),
1074 .help = "Use buffered IO (negates direct)",
1078 .name = "overwrite",
1079 .type = FIO_OPT_BOOL,
1080 .off1 = td_var_offset(overwrite),
1081 .help = "When writing, set whether to overwrite current data",
1086 .type = FIO_OPT_INT,
1087 .off1 = td_var_offset(loops),
1088 .help = "Number of times to run the job",
1093 .type = FIO_OPT_INT,
1094 .off1 = td_var_offset(numjobs),
1095 .help = "Duplicate this job this many times",
1099 .name = "startdelay",
1100 .type = FIO_OPT_INT,
1101 .off1 = td_var_offset(start_delay),
1102 .help = "Only start job when this period has passed",
1108 .type = FIO_OPT_STR_VAL_TIME,
1109 .off1 = td_var_offset(timeout),
1110 .help = "Stop workload when this amount of time has passed",
1114 .name = "time_based",
1115 .type = FIO_OPT_STR_SET,
1116 .off1 = td_var_offset(time_based),
1117 .help = "Keep running until runtime/timeout is met",
1120 .name = "ramp_time",
1121 .type = FIO_OPT_STR_VAL_TIME,
1122 .off1 = td_var_offset(ramp_time),
1123 .help = "Ramp up time before measuring performance",
1128 .type = FIO_OPT_STR,
1130 .off1 = td_var_offset(mem_type),
1131 .help = "Backing type for IO buffers",
1136 .help = "Use malloc(3) for IO buffers",
1140 .help = "Use shared memory segments for IO buffers",
1142 #ifdef FIO_HAVE_HUGETLB
1143 { .ival = "shmhuge",
1144 .oval = MEM_SHMHUGE,
1145 .help = "Like shm, but use huge pages",
1150 .help = "Use mmap(2) (file or anon) for IO buffers",
1152 #ifdef FIO_HAVE_HUGETLB
1153 { .ival = "mmaphuge",
1154 .oval = MEM_MMAPHUGE,
1155 .help = "Like mmap, but use huge pages",
1161 .name = "iomem_align",
1162 .alias = "mem_align",
1163 .type = FIO_OPT_INT,
1164 .off1 = td_var_offset(mem_align),
1166 .help = "IO memory buffer offset alignment",
1172 .type = FIO_OPT_STR,
1173 .off1 = td_var_offset(verify),
1174 .help = "Verify data written",
1178 .oval = VERIFY_NONE,
1179 .help = "Don't do IO verification",
1183 .help = "Use md5 checksums for verification",
1186 .oval = VERIFY_CRC64,
1187 .help = "Use crc64 checksums for verification",
1190 .oval = VERIFY_CRC32,
1191 .help = "Use crc32 checksums for verification",
1193 { .ival = "crc32c-intel",
1194 .oval = VERIFY_CRC32C_INTEL,
1195 .help = "Use hw crc32c checksums for verification",
1198 .oval = VERIFY_CRC32C,
1199 .help = "Use crc32c checksums for verification",
1202 .oval = VERIFY_CRC16,
1203 .help = "Use crc16 checksums for verification",
1206 .oval = VERIFY_CRC7,
1207 .help = "Use crc7 checksums for verification",
1210 .oval = VERIFY_SHA1,
1211 .help = "Use sha1 checksums for verification",
1214 .oval = VERIFY_SHA256,
1215 .help = "Use sha256 checksums for verification",
1218 .oval = VERIFY_SHA512,
1219 .help = "Use sha512 checksums for verification",
1222 .oval = VERIFY_META,
1223 .help = "Use io information",
1227 .oval = VERIFY_NULL,
1228 .help = "Pretend to verify",
1233 .name = "do_verify",
1234 .type = FIO_OPT_BOOL,
1235 .off1 = td_var_offset(do_verify),
1236 .help = "Run verification stage after write",
1241 .name = "verifysort",
1242 .type = FIO_OPT_BOOL,
1243 .off1 = td_var_offset(verifysort),
1244 .help = "Sort written verify blocks for read back",
1249 .name = "verify_interval",
1250 .type = FIO_OPT_INT,
1251 .off1 = td_var_offset(verify_interval),
1252 .minval = 2 * sizeof(struct verify_header),
1253 .help = "Store verify buffer header every N bytes",
1257 .name = "verify_offset",
1258 .type = FIO_OPT_INT,
1259 .help = "Offset verify header location by N bytes",
1261 .cb = str_verify_offset_cb,
1265 .name = "verify_pattern",
1266 .type = FIO_OPT_INT,
1267 .cb = str_verify_pattern_cb,
1268 .help = "Fill pattern for IO buffers",
1272 .name = "verify_fatal",
1273 .type = FIO_OPT_BOOL,
1274 .off1 = td_var_offset(verify_fatal),
1276 .help = "Exit on a single verify failure, don't continue",
1280 .name = "verify_async",
1281 .type = FIO_OPT_INT,
1282 .off1 = td_var_offset(verify_async),
1284 .help = "Number of async verifier threads to use",
1287 #ifdef FIO_HAVE_CPU_AFFINITY
1289 .name = "verify_async_cpus",
1290 .type = FIO_OPT_STR,
1291 .cb = str_verify_cpus_allowed_cb,
1292 .help = "Set CPUs allowed for async verify threads",
1293 .parent = "verify_async",
1297 .name = "write_iolog",
1298 .type = FIO_OPT_STR_STORE,
1299 .off1 = td_var_offset(write_iolog_file),
1300 .help = "Store IO pattern to file",
1303 .name = "read_iolog",
1304 .type = FIO_OPT_STR_STORE,
1305 .off1 = td_var_offset(read_iolog_file),
1306 .help = "Playback IO pattern from file",
1309 .name = "exec_prerun",
1310 .type = FIO_OPT_STR_STORE,
1311 .off1 = td_var_offset(exec_prerun),
1312 .help = "Execute this file prior to running job",
1315 .name = "exec_postrun",
1316 .type = FIO_OPT_STR_STORE,
1317 .off1 = td_var_offset(exec_postrun),
1318 .help = "Execute this file after running job",
1320 #ifdef FIO_HAVE_IOSCHED_SWITCH
1322 .name = "ioscheduler",
1323 .type = FIO_OPT_STR_STORE,
1324 .off1 = td_var_offset(ioscheduler),
1325 .help = "Use this IO scheduler on the backing device",
1330 .type = FIO_OPT_STR_VAL,
1331 .off1 = td_var_offset(zone_size),
1332 .help = "Give size of an IO zone",
1337 .type = FIO_OPT_STR_VAL,
1338 .off1 = td_var_offset(zone_skip),
1339 .help = "Space between IO zones",
1344 .type = FIO_OPT_STR_VAL,
1345 .cb = str_lockmem_cb,
1346 .help = "Lock down this amount of memory",
1350 .name = "rwmixread",
1351 .type = FIO_OPT_INT,
1352 .cb = str_rwmix_read_cb,
1354 .help = "Percentage of mixed workload that is reads",
1358 .name = "rwmixwrite",
1359 .type = FIO_OPT_INT,
1360 .cb = str_rwmix_write_cb,
1362 .help = "Percentage of mixed workload that is writes",
1366 .name = "rwmixcycle",
1367 .type = FIO_OPT_DEPRECATED,
1371 .type = FIO_OPT_INT,
1372 .off1 = td_var_offset(nice),
1373 .help = "Set job CPU nice value",
1378 #ifdef FIO_HAVE_IOPRIO
1381 .type = FIO_OPT_INT,
1383 .help = "Set job IO priority value",
1388 .name = "prioclass",
1389 .type = FIO_OPT_INT,
1390 .cb = str_prioclass_cb,
1391 .help = "Set job IO priority class",
1397 .name = "thinktime",
1398 .type = FIO_OPT_INT,
1399 .off1 = td_var_offset(thinktime),
1400 .help = "Idle time between IO buffers (usec)",
1404 .name = "thinktime_spin",
1405 .type = FIO_OPT_INT,
1406 .off1 = td_var_offset(thinktime_spin),
1407 .help = "Start think time by spinning this amount (usec)",
1409 .parent = "thinktime",
1412 .name = "thinktime_blocks",
1413 .type = FIO_OPT_INT,
1414 .off1 = td_var_offset(thinktime_blocks),
1415 .help = "IO buffer period between 'thinktime'",
1417 .parent = "thinktime",
1421 .type = FIO_OPT_INT,
1422 .off1 = td_var_offset(rate[0]),
1423 .off2 = td_var_offset(rate[1]),
1424 .help = "Set bandwidth rate",
1428 .type = FIO_OPT_INT,
1429 .off1 = td_var_offset(ratemin[0]),
1430 .off2 = td_var_offset(ratemin[1]),
1431 .help = "Job must meet this rate or it will be shutdown",
1435 .name = "rate_iops",
1436 .type = FIO_OPT_INT,
1437 .off1 = td_var_offset(rate_iops[0]),
1438 .off2 = td_var_offset(rate_iops[1]),
1439 .help = "Limit IO used to this number of IO operations/sec",
1442 .name = "rate_iops_min",
1443 .type = FIO_OPT_INT,
1444 .off1 = td_var_offset(rate_iops_min[0]),
1445 .off2 = td_var_offset(rate_iops_min[1]),
1446 .help = "Job must meet this rate or it will be shutdown",
1447 .parent = "rate_iops",
1450 .name = "ratecycle",
1451 .type = FIO_OPT_INT,
1452 .off1 = td_var_offset(ratecycle),
1453 .help = "Window average for rate limits (msec)",
1458 .name = "invalidate",
1459 .type = FIO_OPT_BOOL,
1460 .off1 = td_var_offset(invalidate_cache),
1461 .help = "Invalidate buffer/page cache prior to running job",
1466 .type = FIO_OPT_BOOL,
1467 .off1 = td_var_offset(sync_io),
1468 .help = "Use O_SYNC for buffered writes",
1470 .parent = "buffered",
1473 .name = "bwavgtime",
1474 .type = FIO_OPT_INT,
1475 .off1 = td_var_offset(bw_avg_time),
1476 .help = "Time window over which to calculate bandwidth"
1481 .name = "create_serialize",
1482 .type = FIO_OPT_BOOL,
1483 .off1 = td_var_offset(create_serialize),
1484 .help = "Serialize creating of job files",
1488 .name = "create_fsync",
1489 .type = FIO_OPT_BOOL,
1490 .off1 = td_var_offset(create_fsync),
1491 .help = "Fsync file after creation",
1495 .name = "create_on_open",
1496 .type = FIO_OPT_BOOL,
1497 .off1 = td_var_offset(create_on_open),
1498 .help = "Create files when they are opened for IO",
1503 .type = FIO_OPT_BOOL,
1504 .off1 = td_var_offset(pre_read),
1505 .help = "Preread files before starting official testing",
1510 .type = FIO_OPT_INT,
1511 .off1 = td_var_offset(cpuload),
1512 .help = "Use this percentage of CPU",
1515 .name = "cpuchunks",
1516 .type = FIO_OPT_INT,
1517 .off1 = td_var_offset(cpucycle),
1518 .help = "Length of the CPU burn cycles (usecs)",
1520 .parent = "cpuload",
1522 #ifdef FIO_HAVE_CPU_AFFINITY
1525 .type = FIO_OPT_INT,
1526 .cb = str_cpumask_cb,
1527 .help = "CPU affinity mask",
1530 .name = "cpus_allowed",
1531 .type = FIO_OPT_STR,
1532 .cb = str_cpus_allowed_cb,
1533 .help = "Set CPUs allowed",
1537 .name = "end_fsync",
1538 .type = FIO_OPT_BOOL,
1539 .off1 = td_var_offset(end_fsync),
1540 .help = "Include fsync at the end of job",
1544 .name = "fsync_on_close",
1545 .type = FIO_OPT_BOOL,
1546 .off1 = td_var_offset(fsync_on_close),
1547 .help = "fsync files on close",
1552 .type = FIO_OPT_BOOL,
1553 .off1 = td_var_offset(unlink),
1554 .help = "Unlink created files after job has completed",
1559 .type = FIO_OPT_STR_SET,
1560 .cb = str_exitall_cb,
1561 .help = "Terminate all jobs when one exits",
1564 .name = "stonewall",
1565 .type = FIO_OPT_STR_SET,
1566 .off1 = td_var_offset(stonewall),
1567 .help = "Insert a hard barrier between this job and previous",
1570 .name = "new_group",
1571 .type = FIO_OPT_STR_SET,
1572 .off1 = td_var_offset(new_group),
1573 .help = "Mark the start of a new group (for reporting)",
1577 .type = FIO_OPT_STR_SET,
1578 .off1 = td_var_offset(use_thread),
1579 .help = "Use threads instead of forks",
1582 .name = "write_bw_log",
1583 .type = FIO_OPT_STR,
1584 .off1 = td_var_offset(write_bw_log),
1585 .cb = str_write_bw_log_cb,
1586 .help = "Write log of bandwidth during run",
1589 .name = "write_lat_log",
1590 .type = FIO_OPT_STR,
1591 .off1 = td_var_offset(write_lat_log),
1592 .cb = str_write_lat_log_cb,
1593 .help = "Write log of latency during run",
1596 .name = "hugepage-size",
1597 .type = FIO_OPT_INT,
1598 .off1 = td_var_offset(hugepage_size),
1599 .help = "When using hugepages, specify size of each page",
1600 .def = __stringify(FIO_HUGE_PAGE),
1603 .name = "group_reporting",
1604 .type = FIO_OPT_STR_SET,
1605 .off1 = td_var_offset(group_reporting),
1606 .help = "Do reporting on a per-group basis",
1609 .name = "zero_buffers",
1610 .type = FIO_OPT_STR_SET,
1611 .off1 = td_var_offset(zero_buffers),
1612 .help = "Init IO buffers to all zeroes",
1615 .name = "refill_buffers",
1616 .type = FIO_OPT_STR_SET,
1617 .off1 = td_var_offset(refill_buffers),
1618 .help = "Refill IO buffers on every IO submit",
1620 #ifdef FIO_HAVE_DISK_UTIL
1622 .name = "disk_util",
1623 .type = FIO_OPT_BOOL,
1624 .off1 = td_var_offset(do_disk_util),
1625 .help = "Log disk utilization statistics",
1630 .name = "gtod_reduce",
1631 .type = FIO_OPT_BOOL,
1632 .help = "Greatly reduce number of gettimeofday() calls",
1633 .cb = str_gtod_reduce_cb,
1637 .name = "disable_clat",
1638 .type = FIO_OPT_BOOL,
1639 .off1 = td_var_offset(disable_clat),
1640 .help = "Disable completion latency numbers",
1641 .parent = "gtod_reduce",
1645 .name = "disable_slat",
1646 .type = FIO_OPT_BOOL,
1647 .off1 = td_var_offset(disable_slat),
1648 .help = "Disable submissionn latency numbers",
1649 .parent = "gtod_reduce",
1653 .name = "disable_bw_measurement",
1654 .type = FIO_OPT_BOOL,
1655 .off1 = td_var_offset(disable_bw),
1656 .help = "Disable bandwidth logging",
1657 .parent = "gtod_reduce",
1662 .type = FIO_OPT_INT,
1663 .cb = str_gtod_cpu_cb,
1664 .help = "Setup dedicated gettimeofday() thread on this CPU",
1665 .verify = gtod_cpu_verify,
1668 .name = "continue_on_error",
1669 .type = FIO_OPT_BOOL,
1670 .off1 = td_var_offset(continue_on_error),
1671 .help = "Continue on non-fatal errors during I/O",
1679 void fio_options_dup_and_init(struct option *long_options)
1681 struct fio_option *o;
1684 options_init(options);
1687 while (long_options[i].name)
1692 long_options[i].name = (char *) o->name;
1693 long_options[i].val = FIO_GETOPT_JOB;
1694 if (o->type == FIO_OPT_STR_SET)
1695 long_options[i].has_arg = no_argument;
1697 long_options[i].has_arg = required_argument;
1701 assert(i < FIO_NR_OPTIONS);
1705 struct fio_keyword {
1711 static struct fio_keyword fio_keywords[] = {
1713 .word = "$pagesize",
1714 .desc = "Page size in the system",
1717 .word = "$mb_memory",
1718 .desc = "Megabytes of memory online",
1722 .desc = "Number of CPUs online in the system",
1729 void fio_keywords_init(void)
1731 unsigned long mb_memory;
1735 sprintf(buf, "%lu", page_size);
1736 fio_keywords[0].replace = strdup(buf);
1738 l = sysconf(_SC_PHYS_PAGES);
1739 mb_memory = l * (page_size / 1024UL);
1740 sprintf(buf, "%lu", mb_memory);
1741 fio_keywords[1].replace = strdup(buf);
1743 l = sysconf(_SC_NPROCESSORS_ONLN);
1744 sprintf(buf, "%lu", l);
1745 fio_keywords[2].replace = strdup(buf);
1749 * Look for reserved variable names and replace them with real values
1751 static char *fio_keyword_replace(char *opt)
1756 for (i = 0; fio_keywords[i].word != NULL; i++) {
1757 struct fio_keyword *kw = &fio_keywords[i];
1759 while ((s = strstr(opt, kw->word)) != NULL) {
1760 char *new = malloc(strlen(opt) + 1);
1766 * Copy part of the string before the keyword and
1767 * sprintf() the replacement after it.
1769 memcpy(new, opt, olen);
1770 len = sprintf(new + olen, "%s", kw->replace);
1773 * If there's more in the original string, copy that
1776 opt += strlen(kw->word) + olen;
1778 memcpy(new + olen + len, opt, opt - o_org - 1);
1781 * replace opt and free the old opt
1791 int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
1795 sort_options(opts, options, num_opts);
1797 for (ret = 0, i = 0; i < num_opts; i++) {
1798 opts[i] = fio_keyword_replace(opts[i]);
1799 ret |= parse_option(opts[i], options, td);
1805 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1807 return parse_cmd_option(opt, val, options, td);
1810 void fio_fill_default_options(struct thread_data *td)
1812 fill_default_options(td, options);
1815 int fio_show_option_help(const char *opt)
1817 return show_cmd_help(options, opt);
1820 static void __options_mem(struct thread_data *td, int alloc)
1822 struct thread_options *o = &td->o;
1823 struct fio_option *opt;
1827 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1828 if (opt->type != FIO_OPT_STR_STORE)
1831 ptr = (void *) o + opt->off1;
1834 *ptr = strdup(*ptr);
1844 * dupe FIO_OPT_STR_STORE options
1846 void options_mem_dupe(struct thread_data *td)
1848 __options_mem(td, 1);
1851 void options_mem_free(struct thread_data fio_unused *td)
1854 __options_mem(td, 0);
1858 unsigned int fio_get_kb_base(void *data)
1860 struct thread_data *td = data;
1861 unsigned int kb_base = 0;
1864 kb_base = td->o.kb_base;