13 #define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
16 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
18 static char *get_opt_postfix(const char *str)
20 char *p = strstr(str, ":");
26 strip_blank_front(&p);
31 static int bs_cmp(const void *p1, const void *p2)
33 const struct bssplit *bsp1 = p1;
34 const struct bssplit *bsp2 = p2;
36 return bsp1->perc < bsp2->perc;
39 static int str_bssplit_cb(void *data, const char *input)
41 struct thread_data *td = data;
42 char *fname, *str, *p;
43 unsigned int i, perc, perc_missing;
44 unsigned int max_bs, min_bs;
47 p = str = strdup(input);
49 strip_blank_front(&str);
53 td->o.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) {
68 td->o.bssplit_nr <<= 1;
69 td->o.bssplit = realloc(td->o.bssplit, td->o.bssplit_nr * sizeof(struct bssplit));
72 perc_str = strstr(fname, "/");
76 perc = atoi(perc_str);
84 if (str_to_decimal(fname, &val, 1)) {
85 log_err("fio: bssplit conversion failed\n");
95 td->o.bssplit[i].bs = val;
96 td->o.bssplit[i].perc = perc;
100 td->o.bssplit_nr = i;
103 * Now check if the percentages add up, and how much is missing
105 perc = perc_missing = 0;
106 for (i = 0; i < td->o.bssplit_nr; i++) {
107 struct bssplit *bsp = &td->o.bssplit[i];
109 if (bsp->perc == (unsigned char) -1)
116 log_err("fio: bssplit percentages add to more than 100%%\n");
121 * If values didn't have a percentage set, divide the remains between
125 for (i = 0; i < td->o.bssplit_nr; i++) {
126 struct bssplit *bsp = &td->o.bssplit[i];
128 if (bsp->perc == (unsigned char) -1)
129 bsp->perc = (100 - perc) / perc_missing;
133 td->o.min_bs[DDIR_READ] = td->o.min_bs[DDIR_WRITE] = min_bs;
134 td->o.max_bs[DDIR_READ] = td->o.max_bs[DDIR_WRITE] = max_bs;
137 * now sort based on percentages, for ease of lookup
139 qsort(td->o.bssplit, td->o.bssplit_nr, sizeof(struct bssplit), bs_cmp);
145 static int str_rw_cb(void *data, const char *str)
147 struct thread_data *td = data;
148 char *nr = get_opt_postfix(str);
152 td->o.ddir_nr = atoi(nr);
157 static int str_mem_cb(void *data, const char *mem)
159 struct thread_data *td = data;
161 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
162 td->mmapfile = get_opt_postfix(mem);
163 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
164 log_err("fio: mmaphuge:/path/to/file\n");
172 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
178 #ifdef FIO_HAVE_IOPRIO
179 static int str_prioclass_cb(void *data, unsigned int *val)
181 struct thread_data *td = data;
185 * mask off old class bits, str_prio_cb() may have set a default class
187 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
190 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
195 static int str_prio_cb(void *data, unsigned int *val)
197 struct thread_data *td = data;
202 * If no class is set, assume BE
204 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
205 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
212 static int str_exitall_cb(void)
214 exitall_on_terminate = 1;
218 #ifdef FIO_HAVE_CPU_AFFINITY
219 static int str_cpumask_cb(void *data, unsigned int *val)
221 struct thread_data *td = data;
224 CPU_ZERO(&td->o.cpumask);
226 for (i = 0; i < sizeof(int) * 8; i++)
228 CPU_SET(*val, &td->o.cpumask);
230 td->o.cpumask_set = 1;
234 static int str_cpus_allowed_cb(void *data, const char *input)
236 struct thread_data *td = data;
239 CPU_ZERO(&td->o.cpumask);
241 p = str = strdup(input);
243 strip_blank_front(&str);
244 strip_blank_end(str);
246 while ((cpu = strsep(&str, ",")) != NULL) {
249 CPU_SET(atoi(cpu), &td->o.cpumask);
253 td->o.cpumask_set = 1;
259 static int str_fst_cb(void *data, const char *str)
261 struct thread_data *td = data;
262 char *nr = get_opt_postfix(str);
264 td->file_service_nr = 1;
266 td->file_service_nr = atoi(nr);
271 static int str_filename_cb(void *data, const char *input)
273 struct thread_data *td = data;
274 char *fname, *str, *p;
276 p = str = strdup(input);
278 strip_blank_front(&str);
279 strip_blank_end(str);
281 if (!td->files_index)
284 while ((fname = strsep(&str, ":")) != NULL) {
295 static int str_directory_cb(void *data, const char fio_unused *str)
297 struct thread_data *td = data;
300 if (lstat(td->o.directory, &sb) < 0) {
301 log_err("fio: %s is not a directory\n", td->o.directory);
302 td_verror(td, errno, "lstat");
305 if (!S_ISDIR(sb.st_mode)) {
306 log_err("fio: %s is not a directory\n", td->o.directory);
313 static int str_opendir_cb(void *data, const char fio_unused *str)
315 struct thread_data *td = data;
317 if (!td->files_index)
320 return add_dir_files(td, td->o.opendir);
323 static int str_verify_offset_cb(void *data, unsigned int *off)
325 struct thread_data *td = data;
327 if (*off && *off < sizeof(struct verify_header)) {
328 log_err("fio: verify_offset too small\n");
332 td->o.verify_offset = *off;
336 static int str_verify_pattern_cb(void *data, unsigned int *off)
338 struct thread_data *td = data;
343 td->o.verify_pattern_bytes = 1;
345 td->o.verify_pattern_bytes = 2;
347 td->o.verify_pattern_bytes = 3;
349 td->o.verify_pattern_bytes = 4;
351 td->o.verify_pattern = *off;
355 #define __stringify_1(x) #x
356 #define __stringify(x) __stringify_1(x)
359 * Map of job/command line options
361 static struct fio_option options[] = {
363 .name = "description",
364 .type = FIO_OPT_STR_STORE,
365 .off1 = td_var_offset(description),
366 .help = "Text job description",
370 .type = FIO_OPT_STR_STORE,
371 .off1 = td_var_offset(name),
372 .help = "Name of this job",
376 .type = FIO_OPT_STR_STORE,
377 .off1 = td_var_offset(directory),
378 .cb = str_directory_cb,
379 .help = "Directory to store files in",
383 .type = FIO_OPT_STR_STORE,
384 .off1 = td_var_offset(filename),
385 .cb = str_filename_cb,
386 .help = "File(s) to use for the workload",
390 .type = FIO_OPT_STR_STORE,
391 .off1 = td_var_offset(opendir),
392 .cb = str_opendir_cb,
393 .help = "Recursively add files from this directory and down",
397 .alias = "readwrite",
400 .off1 = td_var_offset(td_ddir),
401 .help = "IO direction",
405 .oval = TD_DDIR_READ,
406 .help = "Sequential read",
409 .oval = TD_DDIR_WRITE,
410 .help = "Sequential write",
412 { .ival = "randread",
413 .oval = TD_DDIR_RANDREAD,
414 .help = "Random read",
416 { .ival = "randwrite",
417 .oval = TD_DDIR_RANDWRITE,
418 .help = "Random write",
422 .help = "Sequential read and write mix",
425 .oval = TD_DDIR_RANDRW,
426 .help = "Random read and write mix"
432 .type = FIO_OPT_STR_STORE,
433 .off1 = td_var_offset(ioengine),
434 .help = "IO engine to use",
438 .help = "Use read/write",
441 .help = "Use pread/pwrite",
443 #ifdef FIO_HAVE_LIBAIO
445 .help = "Linux native asynchronous IO",
448 #ifdef FIO_HAVE_POSIXAIO
449 { .ival = "posixaio",
450 .help = "POSIX asynchronous IO",
454 .help = "Memory mapped IO",
456 #ifdef FIO_HAVE_SPLICE
458 .help = "splice/vmsplice based IO",
460 { .ival = "netsplice",
461 .help = "splice/vmsplice to/from the network",
466 .help = "SCSI generic v3 IO",
470 .help = "Testing engine (no data transfer)",
473 .help = "Network IO",
475 #ifdef FIO_HAVE_SYSLET
476 { .ival = "syslet-rw",
477 .help = "syslet enabled async pread/pwrite IO",
481 .help = "CPU cycler burner engine",
483 #ifdef FIO_HAVE_GUASI
485 .help = "GUASI IO engine",
488 { .ival = "external",
489 .help = "Load external engine (append name)",
496 .off1 = td_var_offset(iodepth),
497 .help = "Amount of IO buffers to keep in flight",
502 .name = "iodepth_batch",
504 .off1 = td_var_offset(iodepth_batch),
505 .help = "Number of IO to submit in one go",
511 .name = "iodepth_low",
513 .off1 = td_var_offset(iodepth_low),
514 .help = "Low water mark for queuing depth",
519 .type = FIO_OPT_STR_VAL,
520 .off1 = td_var_offset(size),
522 .help = "Total size of device or files",
525 .name = "fill_device",
526 .type = FIO_OPT_BOOL,
527 .off1 = td_var_offset(fill_device),
528 .help = "Write until an ENOSPC error occurs",
533 .type = FIO_OPT_STR_VAL,
534 .off1 = td_var_offset(file_size_low),
535 .off2 = td_var_offset(file_size_high),
537 .help = "Size of individual files",
541 .alias = "fileoffset",
542 .type = FIO_OPT_STR_VAL,
543 .off1 = td_var_offset(start_offset),
544 .help = "Start IO from this offset",
549 .alias = "blocksize",
550 .type = FIO_OPT_STR_VAL_INT,
551 .off1 = td_var_offset(bs[DDIR_READ]),
552 .off2 = td_var_offset(bs[DDIR_WRITE]),
554 .help = "Block size unit",
560 .alias = "blocksize_range",
561 .type = FIO_OPT_RANGE,
562 .off1 = td_var_offset(min_bs[DDIR_READ]),
563 .off2 = td_var_offset(max_bs[DDIR_READ]),
564 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
565 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
567 .help = "Set block size range (in more detail than bs)",
573 .cb = str_bssplit_cb,
574 .help = "Set a specific mix of block sizes",
578 .name = "bs_unaligned",
579 .alias = "blocksize_unaligned",
580 .type = FIO_OPT_STR_SET,
581 .off1 = td_var_offset(bs_unaligned),
582 .help = "Don't sector align IO buffer sizes",
586 .name = "randrepeat",
587 .type = FIO_OPT_BOOL,
588 .off1 = td_var_offset(rand_repeatable),
589 .help = "Use repeatable random IO pattern",
594 .name = "norandommap",
595 .type = FIO_OPT_STR_SET,
596 .off1 = td_var_offset(norandommap),
597 .help = "Accept potential duplicate random blocks",
603 .off1 = td_var_offset(nr_files),
604 .help = "Split job workload between this number of files",
610 .off1 = td_var_offset(open_files),
611 .help = "Number of files to keep open at the same time",
614 .name = "file_service_type",
617 .off1 = td_var_offset(file_service_type),
618 .help = "How to select which file to service next",
622 .oval = FIO_FSERVICE_RANDOM,
623 .help = "Choose a file at random",
625 { .ival = "roundrobin",
626 .oval = FIO_FSERVICE_RR,
627 .help = "Round robin select files",
633 .name = "fadvise_hint",
634 .type = FIO_OPT_BOOL,
635 .off1 = td_var_offset(fadvise_hint),
636 .help = "Use fadvise() to advise the kernel on IO pattern",
642 .off1 = td_var_offset(fsync_blocks),
643 .help = "Issue fsync for writes every given number of blocks",
648 .type = FIO_OPT_BOOL,
649 .off1 = td_var_offset(odirect),
650 .help = "Use O_DIRECT IO (negates buffered)",
655 .type = FIO_OPT_BOOL,
656 .off1 = td_var_offset(odirect),
658 .help = "Use buffered IO (negates direct)",
663 .type = FIO_OPT_BOOL,
664 .off1 = td_var_offset(overwrite),
665 .help = "When writing, set whether to overwrite current data",
671 .off1 = td_var_offset(loops),
672 .help = "Number of times to run the job",
678 .off1 = td_var_offset(numjobs),
679 .help = "Duplicate this job this many times",
683 .name = "startdelay",
685 .off1 = td_var_offset(start_delay),
686 .help = "Only start job when this period has passed",
692 .type = FIO_OPT_STR_VAL_TIME,
693 .off1 = td_var_offset(timeout),
694 .help = "Stop workload when this amount of time has passed",
698 .name = "time_based",
699 .type = FIO_OPT_STR_SET,
700 .off1 = td_var_offset(time_based),
701 .help = "Keep running until runtime/timeout is met",
708 .off1 = td_var_offset(mem_type),
709 .help = "Backing type for IO buffers",
714 .help = "Use malloc(3) for IO buffers",
718 .help = "Use shared memory segments for IO buffers",
720 #ifdef FIO_HAVE_HUGETLB
723 .help = "Like shm, but use huge pages",
728 .help = "Use mmap(2) (file or anon) for IO buffers",
730 #ifdef FIO_HAVE_HUGETLB
731 { .ival = "mmaphuge",
732 .oval = MEM_MMAPHUGE,
733 .help = "Like mmap, but use huge pages",
741 .off1 = td_var_offset(verify),
742 .help = "Verify data written",
747 .help = "Don't do IO verification",
751 .help = "Use md5 checksums for verification",
754 .oval = VERIFY_CRC64,
755 .help = "Use crc64 checksums for verification",
758 .oval = VERIFY_CRC32,
759 .help = "Use crc32 checksums for verification",
762 .oval = VERIFY_CRC16,
763 .help = "Use crc16 checksums for verification",
767 .help = "Use crc7 checksums for verification",
770 .oval = VERIFY_SHA256,
771 .help = "Use sha256 checksums for verification",
774 .oval = VERIFY_SHA512,
775 .help = "Use sha512 checksums for verification",
779 .help = "Use io information",
784 .help = "Pretend to verify",
790 .type = FIO_OPT_BOOL,
791 .off1 = td_var_offset(do_verify),
792 .help = "Run verification stage after write",
797 .name = "verifysort",
798 .type = FIO_OPT_BOOL,
799 .off1 = td_var_offset(verifysort),
800 .help = "Sort written verify blocks for read back",
805 .name = "verify_interval",
806 .type = FIO_OPT_STR_VAL_INT,
807 .off1 = td_var_offset(verify_interval),
808 .minval = 2 * sizeof(struct verify_header),
809 .help = "Store verify buffer header every N bytes",
813 .name = "verify_offset",
814 .type = FIO_OPT_STR_VAL_INT,
815 .help = "Offset verify header location by N bytes",
817 .cb = str_verify_offset_cb,
821 .name = "verify_pattern",
823 .cb = str_verify_pattern_cb,
824 .help = "Fill pattern for IO buffers",
828 .name = "verify_fatal",
829 .type = FIO_OPT_BOOL,
830 .off1 = td_var_offset(verify_fatal),
832 .help = "Exit on a single verify failure, don't continue",
836 .name = "write_iolog",
837 .type = FIO_OPT_STR_STORE,
838 .off1 = td_var_offset(write_iolog_file),
839 .help = "Store IO pattern to file",
842 .name = "read_iolog",
843 .type = FIO_OPT_STR_STORE,
844 .off1 = td_var_offset(read_iolog_file),
845 .help = "Playback IO pattern from file",
848 .name = "exec_prerun",
849 .type = FIO_OPT_STR_STORE,
850 .off1 = td_var_offset(exec_prerun),
851 .help = "Execute this file prior to running job",
854 .name = "exec_postrun",
855 .type = FIO_OPT_STR_STORE,
856 .off1 = td_var_offset(exec_postrun),
857 .help = "Execute this file after running job",
859 #ifdef FIO_HAVE_IOSCHED_SWITCH
861 .name = "ioscheduler",
862 .type = FIO_OPT_STR_STORE,
863 .off1 = td_var_offset(ioscheduler),
864 .help = "Use this IO scheduler on the backing device",
869 .type = FIO_OPT_STR_VAL,
870 .off1 = td_var_offset(zone_size),
871 .help = "Give size of an IO zone",
876 .type = FIO_OPT_STR_VAL,
877 .off1 = td_var_offset(zone_skip),
878 .help = "Space between IO zones",
883 .type = FIO_OPT_STR_VAL,
884 .cb = str_lockmem_cb,
885 .help = "Lock down this amount of memory",
891 .off1 = td_var_offset(rwmix[DDIR_READ]),
893 .help = "Percentage of mixed workload that is reads",
897 .name = "rwmixwrite",
899 .off1 = td_var_offset(rwmix[DDIR_WRITE]),
901 .help = "Percentage of mixed workload that is writes",
905 .name = "rwmixcycle",
907 .off1 = td_var_offset(rwmixcycle),
908 .help = "Cycle period for mixed read/write workloads (msec)",
910 .parent = "rwmixread",
915 .off1 = td_var_offset(nice),
916 .help = "Set job CPU nice value",
921 #ifdef FIO_HAVE_IOPRIO
926 .help = "Set job IO priority value",
933 .cb = str_prioclass_cb,
934 .help = "Set job IO priority class",
942 .off1 = td_var_offset(thinktime),
943 .help = "Idle time between IO buffers (usec)",
947 .name = "thinktime_spin",
949 .off1 = td_var_offset(thinktime_spin),
950 .help = "Start think time by spinning this amount (usec)",
952 .parent = "thinktime",
955 .name = "thinktime_blocks",
957 .off1 = td_var_offset(thinktime_blocks),
958 .help = "IO buffer period between 'thinktime'",
960 .parent = "thinktime",
965 .off1 = td_var_offset(rate),
966 .help = "Set bandwidth rate",
971 .off1 = td_var_offset(ratemin),
972 .help = "Job must meet this rate or it will be shutdown",
978 .off1 = td_var_offset(rate_iops),
979 .help = "Limit IO used to this number of IO operations/sec",
982 .name = "rate_iops_min",
984 .off1 = td_var_offset(rate_iops_min),
985 .help = "Job must meet this rate or it will be shutdown",
986 .parent = "rate_iops",
991 .off1 = td_var_offset(ratecycle),
992 .help = "Window average for rate limits (msec)",
997 .name = "invalidate",
998 .type = FIO_OPT_BOOL,
999 .off1 = td_var_offset(invalidate_cache),
1000 .help = "Invalidate buffer/page cache prior to running job",
1005 .type = FIO_OPT_BOOL,
1006 .off1 = td_var_offset(sync_io),
1007 .help = "Use O_SYNC for buffered writes",
1009 .parent = "buffered",
1012 .name = "bwavgtime",
1013 .type = FIO_OPT_INT,
1014 .off1 = td_var_offset(bw_avg_time),
1015 .help = "Time window over which to calculate bandwidth (msec)",
1019 .name = "create_serialize",
1020 .type = FIO_OPT_BOOL,
1021 .off1 = td_var_offset(create_serialize),
1022 .help = "Serialize creating of job files",
1026 .name = "create_fsync",
1027 .type = FIO_OPT_BOOL,
1028 .off1 = td_var_offset(create_fsync),
1029 .help = "Fsync file after creation",
1034 .type = FIO_OPT_INT,
1035 .off1 = td_var_offset(cpuload),
1036 .help = "Use this percentage of CPU",
1039 .name = "cpuchunks",
1040 .type = FIO_OPT_INT,
1041 .off1 = td_var_offset(cpucycle),
1042 .help = "Length of the CPU burn cycles (usecs)",
1044 .parent = "cpuload",
1046 #ifdef FIO_HAVE_CPU_AFFINITY
1049 .type = FIO_OPT_INT,
1050 .cb = str_cpumask_cb,
1051 .help = "CPU affinity mask",
1054 .name = "cpus_allowed",
1055 .type = FIO_OPT_STR,
1056 .cb = str_cpus_allowed_cb,
1057 .help = "Set CPUs allowed",
1061 .name = "end_fsync",
1062 .type = FIO_OPT_BOOL,
1063 .off1 = td_var_offset(end_fsync),
1064 .help = "Include fsync at the end of job",
1068 .name = "fsync_on_close",
1069 .type = FIO_OPT_BOOL,
1070 .off1 = td_var_offset(fsync_on_close),
1071 .help = "fsync files on close",
1076 .type = FIO_OPT_BOOL,
1077 .off1 = td_var_offset(unlink),
1078 .help = "Unlink created files after job has completed",
1083 .type = FIO_OPT_STR_SET,
1084 .cb = str_exitall_cb,
1085 .help = "Terminate all jobs when one exits",
1088 .name = "stonewall",
1089 .type = FIO_OPT_STR_SET,
1090 .off1 = td_var_offset(stonewall),
1091 .help = "Insert a hard barrier between this job and previous",
1094 .name = "new_group",
1095 .type = FIO_OPT_STR_SET,
1096 .off1 = td_var_offset(new_group),
1097 .help = "Mark the start of a new group (for reporting)",
1101 .type = FIO_OPT_STR_SET,
1102 .off1 = td_var_offset(use_thread),
1103 .help = "Use threads instead of forks",
1106 .name = "write_bw_log",
1107 .type = FIO_OPT_STR_SET,
1108 .off1 = td_var_offset(write_bw_log),
1109 .help = "Write log of bandwidth during run",
1112 .name = "write_lat_log",
1113 .type = FIO_OPT_STR_SET,
1114 .off1 = td_var_offset(write_lat_log),
1115 .help = "Write log of latency during run",
1118 .name = "hugepage-size",
1119 .type = FIO_OPT_STR_VAL,
1120 .off1 = td_var_offset(hugepage_size),
1121 .help = "When using hugepages, specify size of each page",
1122 .def = __stringify(FIO_HUGE_PAGE),
1125 .name = "group_reporting",
1126 .type = FIO_OPT_STR_SET,
1127 .off1 = td_var_offset(group_reporting),
1128 .help = "Do reporting on a per-group basis",
1131 .name = "zero_buffers",
1132 .type = FIO_OPT_STR_SET,
1133 .off1 = td_var_offset(zero_buffers),
1134 .help = "Init IO buffers to all zeroes",
1136 #ifdef FIO_HAVE_DISK_UTIL
1138 .name = "disk_util",
1139 .type = FIO_OPT_BOOL,
1140 .off1 = td_var_offset(do_disk_util),
1141 .help = "Log disk utilization stats",
1150 void fio_options_dup_and_init(struct option *long_options)
1152 struct fio_option *o;
1155 options_init(options);
1158 while (long_options[i].name)
1163 long_options[i].name = o->name;
1164 long_options[i].val = FIO_GETOPT_JOB;
1165 if (o->type == FIO_OPT_STR_SET)
1166 long_options[i].has_arg = no_argument;
1168 long_options[i].has_arg = required_argument;
1172 assert(i < FIO_NR_OPTIONS);
1176 int fio_option_parse(struct thread_data *td, const char *opt)
1178 return parse_option(opt, options, td);
1181 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1183 return parse_cmd_option(opt, val, options, td);
1186 void fio_fill_default_options(struct thread_data *td)
1188 fill_default_options(td, options);
1191 int fio_show_option_help(const char *opt)
1193 return show_cmd_help(options, opt);
1196 static void __options_mem(struct thread_data *td, int alloc)
1198 struct thread_options *o = &td->o;
1199 struct fio_option *opt;
1203 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1204 if (opt->type != FIO_OPT_STR_STORE)
1207 ptr = (void *) o + opt->off1;
1210 *ptr = strdup(*ptr);
1220 * dupe FIO_OPT_STR_STORE options
1222 void options_mem_dupe(struct thread_data *td)
1224 __options_mem(td, 1);
1227 void options_mem_free(struct thread_data fio_unused *td)
1230 __options_mem(td, 0);