2 * This file contains job initialization and setup functions.
15 #include <sys/types.h>
21 #define FIO_RANDSEED (0xb1899bedUL)
23 #define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var)
25 static int str_ioengine_cb(void *, const char *);
26 static int str_mem_cb(void *, const char *);
27 static int str_lockmem_cb(void *, unsigned long *);
28 #ifdef FIO_HAVE_IOPRIO
29 static int str_prio_cb(void *, unsigned int *);
30 static int str_prioclass_cb(void *, unsigned int *);
32 static int str_exitall_cb(void);
33 static int str_cpumask_cb(void *, unsigned int *);
35 #define __stringify_1(x) #x
36 #define __stringify(x) __stringify_1(x)
39 * Map of job/command line options
41 static struct fio_option options[] = {
43 .name = "description",
44 .type = FIO_OPT_STR_STORE,
45 .off1 = td_var_offset(description),
46 .help = "Text job description",
50 .type = FIO_OPT_STR_STORE,
51 .off1 = td_var_offset(name),
52 .help = "Name of this job",
56 .type = FIO_OPT_STR_STORE,
57 .off1 = td_var_offset(directory),
58 .help = "Directory to store files in",
62 .type = FIO_OPT_STR_STORE,
63 .off1 = td_var_offset(filename),
64 .help = "Force the use of a specific file",
69 .off1 = td_var_offset(td_ddir),
70 .help = "IO direction",
73 { .ival = "read", .oval = TD_DDIR_READ },
74 { .ival = "write", .oval = TD_DDIR_WRITE },
75 { .ival = "randread", .oval = TD_DDIR_RANDREAD },
76 { .ival = "randwrite", .oval = TD_DDIR_RANDWRITE },
77 { .ival = "rw", .oval = TD_DDIR_RW },
78 { .ival = "randrw", .oval = TD_DDIR_RANDRW },
84 .cb = str_ioengine_cb,
85 .help = "IO engine to use",
89 #ifdef FIO_HAVE_LIBAIO
90 { .ival = "libaio", },
92 #ifdef FIO_HAVE_POSIXAIO
93 { .ival = "posixaio", },
96 #ifdef FIO_HAVE_SPLICE
97 { .ival = "splice", },
102 { .ival = "null", }, { .ival = "net", },
103 #ifdef FIO_HAVE_SYSLET
104 { .ival = "syslet-rw", },
111 .off1 = td_var_offset(iodepth),
112 .help = "Amount of IO buffers to keep in flight",
116 .name = "iodepth_batch",
118 .off1 = td_var_offset(iodepth_batch),
119 .help = "Number of IO to submit in one go",
122 .name = "iodepth_low",
124 .off1 = td_var_offset(iodepth_low),
125 .help = "Low water mark for queuing depth",
129 .type = FIO_OPT_STR_VAL,
130 .off1 = td_var_offset(total_file_size),
131 .help = "Size of device or file",
135 .type = FIO_OPT_STR_VAL_INT,
136 .off1 = td_var_offset(bs[DDIR_READ]),
137 .off2 = td_var_offset(bs[DDIR_WRITE]),
138 .help = "Block size unit",
143 .type = FIO_OPT_RANGE,
144 .off1 = td_var_offset(min_bs[DDIR_READ]),
145 .off2 = td_var_offset(max_bs[DDIR_READ]),
146 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
147 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
148 .help = "Set block size range (in more detail than bs)",
151 .name = "bs_unaligned",
152 .type = FIO_OPT_STR_SET,
153 .off1 = td_var_offset(bs_unaligned),
154 .help = "Don't sector align IO buffer sizes",
158 .type = FIO_OPT_STR_VAL,
159 .off1 = td_var_offset(start_offset),
160 .help = "Start IO from this offset",
164 .name = "randrepeat",
165 .type = FIO_OPT_BOOL,
166 .off1 = td_var_offset(rand_repeatable),
167 .help = "Use repeatable random IO pattern",
171 .name = "norandommap",
172 .type = FIO_OPT_STR_SET,
173 .off1 = td_var_offset(norandommap),
174 .help = "Accept potential duplicate random blocks",
179 .off1 = td_var_offset(nr_files),
180 .help = "Split job workload between this number of files",
184 .name = "file_service_type",
186 .off1 = td_var_offset(file_service_type),
187 .help = "How to select which file to service next",
190 { .ival = "random", .oval = FIO_FSERVICE_RANDOM },
191 { .ival = "roundrobin", .oval = FIO_FSERVICE_RR },
197 .off1 = td_var_offset(fsync_blocks),
198 .help = "Issue fsync for writes every given number of blocks",
203 .type = FIO_OPT_BOOL,
204 .off1 = td_var_offset(odirect),
205 .help = "Use O_DIRECT IO (negates buffered)",
210 .type = FIO_OPT_BOOL,
211 .off1 = td_var_offset(odirect),
213 .help = "Use buffered IO (negates direct)",
218 .type = FIO_OPT_BOOL,
219 .off1 = td_var_offset(overwrite),
220 .help = "When writing, set whether to overwrite current data",
226 .off1 = td_var_offset(loops),
227 .help = "Number of times to run the job",
233 .off1 = td_var_offset(numjobs),
234 .help = "Duplicate this job this many times",
238 .name = "startdelay",
240 .off1 = td_var_offset(start_delay),
241 .help = "Only start job when this period has passed",
247 .type = FIO_OPT_STR_VAL_TIME,
248 .off1 = td_var_offset(timeout),
249 .help = "Stop workload when this amount of time has passed",
256 .off1 = td_var_offset(mem_type),
257 .help = "Backing type for IO buffers",
260 { .ival = "malloc", .oval = MEM_MALLOC },
261 { .ival = "shm", .oval = MEM_SHM },
262 #ifdef FIO_HAVE_HUGETLB
263 { .ival = "shmhuge", .oval = MEM_SHMHUGE },
265 { .ival = "mmap", .oval = MEM_MMAP },
266 #ifdef FIO_HAVE_HUGETLB
267 { .ival = "mmaphuge", .oval = MEM_MMAPHUGE },
274 .off1 = td_var_offset(verify),
275 .help = "Verify sum function",
278 { .ival = "0", .oval = VERIFY_NONE },
279 { .ival = "crc32", .oval = VERIFY_CRC32 },
280 { .ival = "md5", .oval = VERIFY_MD5 },
284 .name = "write_iolog",
285 .type = FIO_OPT_STR_STORE,
286 .off1 = td_var_offset(write_iolog_file),
287 .help = "Store IO pattern to file",
290 .name = "read_iolog",
291 .type = FIO_OPT_STR_STORE,
292 .off1 = td_var_offset(read_iolog_file),
293 .help = "Playback IO pattern from file",
296 .name = "exec_prerun",
297 .type = FIO_OPT_STR_STORE,
298 .off1 = td_var_offset(exec_prerun),
299 .help = "Execute this file prior to running job",
302 .name = "exec_postrun",
303 .type = FIO_OPT_STR_STORE,
304 .off1 = td_var_offset(exec_postrun),
305 .help = "Execute this file after running job",
307 #ifdef FIO_HAVE_IOSCHED_SWITCH
309 .name = "ioscheduler",
310 .type = FIO_OPT_STR_STORE,
311 .off1 = td_var_offset(ioscheduler),
312 .help = "Use this IO scheduler on the backing device",
317 .type = FIO_OPT_STR_VAL,
318 .off1 = td_var_offset(zone_size),
319 .help = "Give size of an IO zone",
324 .type = FIO_OPT_STR_VAL,
325 .off1 = td_var_offset(zone_skip),
326 .help = "Space between IO zones",
331 .type = FIO_OPT_STR_VAL,
332 .cb = str_lockmem_cb,
333 .help = "Lock down this amount of memory",
337 .name = "rwmixcycle",
339 .off1 = td_var_offset(rwmixcycle),
340 .help = "Cycle period for mixed read/write workloads (msec)",
346 .off1 = td_var_offset(rwmixread),
348 .help = "Percentage of mixed workload that is reads",
352 .name = "rwmixwrite",
354 .off1 = td_var_offset(rwmixwrite),
356 .help = "Percentage of mixed workload that is writes",
362 .off1 = td_var_offset(nice),
363 .help = "Set job CPU nice value",
368 #ifdef FIO_HAVE_IOPRIO
373 .help = "Set job IO priority value",
380 .cb = str_prioclass_cb,
381 .help = "Set job IO priority class",
389 .off1 = td_var_offset(thinktime),
390 .help = "Idle time between IO buffers (usec)",
394 .name = "thinktime_spin",
396 .off1 = td_var_offset(thinktime_spin),
397 .help = "Start thinktime by spinning this amount (usec)",
401 .name = "thinktime_blocks",
403 .off1 = td_var_offset(thinktime_blocks),
404 .help = "IO buffer period between 'thinktime'",
410 .off1 = td_var_offset(rate),
411 .help = "Set bandwidth rate",
416 .off1 = td_var_offset(ratemin),
417 .help = "The bottom limit accepted",
422 .off1 = td_var_offset(ratecycle),
423 .help = "Window average for rate limits (msec)",
427 .name = "invalidate",
428 .type = FIO_OPT_BOOL,
429 .off1 = td_var_offset(invalidate_cache),
430 .help = "Invalidate buffer/page cache prior to running job",
435 .type = FIO_OPT_BOOL,
436 .off1 = td_var_offset(sync_io),
437 .help = "Use O_SYNC for buffered writes",
443 .off1 = td_var_offset(bw_avg_time),
444 .help = "Time window over which to calculate bandwidth (msec)",
448 .name = "create_serialize",
449 .type = FIO_OPT_BOOL,
450 .off1 = td_var_offset(create_serialize),
451 .help = "Serialize creating of job files",
455 .name = "create_fsync",
456 .type = FIO_OPT_BOOL,
457 .off1 = td_var_offset(create_fsync),
458 .help = "Fsync file after creation",
464 .off1 = td_var_offset(cpuload),
465 .help = "Use this percentage of CPU",
470 .off1 = td_var_offset(cpucycle),
471 .help = "Length of the CPU burn cycles",
473 #ifdef FIO_HAVE_CPU_AFFINITY
477 .cb = str_cpumask_cb,
478 .help = "CPU affinity mask",
483 .type = FIO_OPT_BOOL,
484 .off1 = td_var_offset(end_fsync),
485 .help = "Include fsync at the end of job",
490 .type = FIO_OPT_BOOL,
491 .off1 = td_var_offset(unlink),
492 .help = "Unlink created files after job has completed",
497 .type = FIO_OPT_STR_SET,
498 .cb = str_exitall_cb,
499 .help = "Terminate all jobs when one exits",
503 .type = FIO_OPT_STR_SET,
504 .off1 = td_var_offset(stonewall),
505 .help = "Insert a hard barrier between this job and previous",
509 .type = FIO_OPT_STR_SET,
510 .off1 = td_var_offset(use_thread),
511 .help = "Use threads instead of forks",
514 .name = "write_bw_log",
515 .type = FIO_OPT_STR_SET,
516 .off1 = td_var_offset(write_bw_log),
517 .help = "Write log of bandwidth during run",
520 .name = "write_lat_log",
521 .type = FIO_OPT_STR_SET,
522 .off1 = td_var_offset(write_lat_log),
523 .help = "Write log of latency during run",
526 .name = "hugepage-size",
527 .type = FIO_OPT_STR_VAL,
528 .off1 = td_var_offset(hugepage_size),
529 .help = "When using hugepages, specify size of each page",
530 .def = __stringify(FIO_HUGE_PAGE),
537 #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
538 #define FIO_CMD_OPTS (16)
539 #define FIO_GETOPT_JOB (0x89988998)
542 * Command line options. These will contain the above, plus a few
543 * extra that only pertain to fio itself and not jobs.
545 static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
548 .has_arg = required_argument,
553 .has_arg = required_argument,
557 .name = "latency-log",
558 .has_arg = required_argument,
562 .name = "bandwidth-log",
563 .has_arg = required_argument,
568 .has_arg = optional_argument,
573 .has_arg = no_argument,
578 .has_arg = no_argument,
583 .has_arg = required_argument,
591 static int def_timeout = 0;
593 static char fio_version_string[] = "fio 1.11";
595 static char **ini_file;
596 static int max_jobs = MAX_JOBS;
598 struct thread_data def_thread;
599 struct thread_data *threads = NULL;
601 int exitall_on_terminate = 0;
602 int terse_output = 0;
603 unsigned long long mlock_size = 0;
607 static int write_lat_log = 0;
608 int write_bw_log = 0;
611 * Return a free job structure.
613 static struct thread_data *get_new_job(int global, struct thread_data *parent)
615 struct thread_data *td;
619 if (thread_number >= max_jobs)
622 td = &threads[thread_number++];
625 td->thread_number = thread_number;
629 static void put_job(struct thread_data *td)
631 if (td == &def_thread)
635 fprintf(f_out, "fio: %s\n", td->verror);
637 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
642 * Lazy way of fixing up options that depend on each other. We could also
643 * define option callback handlers, but this is easier.
645 static void fixup_options(struct thread_data *td)
647 if (!td->rwmixread && td->rwmixwrite)
648 td->rwmixread = 100 - td->rwmixwrite;
650 if (td->write_iolog_file && td->read_iolog_file) {
651 log_err("fio: read iolog overrides write_iolog\n");
652 free(td->write_iolog_file);
653 td->write_iolog_file = NULL;
656 if (td->io_ops->flags & FIO_SYNCIO)
660 td->iodepth = td->nr_files;
664 * only really works for sequential io for now, and with 1 file
666 if (td->zone_size && td_random(td) && td->nr_files == 1)
670 * Reads can do overwrites, we always need to pre-create the file
672 if (td_read(td) || td_rw(td))
675 if (!td->min_bs[DDIR_READ])
676 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
677 if (!td->max_bs[DDIR_READ])
678 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
679 if (!td->min_bs[DDIR_WRITE])
680 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
681 if (!td->max_bs[DDIR_WRITE])
682 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
684 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
686 if (td_read(td) && !td_rw(td))
689 if (td->norandommap && td->verify != VERIFY_NONE) {
690 log_err("fio: norandommap given, verify disabled\n");
691 td->verify = VERIFY_NONE;
693 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
694 log_err("fio: bs_unaligned may not work with raw io\n");
697 * O_DIRECT and char doesn't mix, clear that flag if necessary.
699 if (td->filetype == FIO_TYPE_CHAR && td->odirect)
703 * thinktime_spin must be less than thinktime
705 if (td->thinktime_spin > td->thinktime)
706 td->thinktime_spin = td->thinktime;
709 * The low water mark cannot be bigger than the iodepth
711 if (td->iodepth_low > td->iodepth || !td->iodepth_low)
712 td->iodepth_low = td->iodepth;
715 * If batch number isn't set, default to the same as iodepth
717 if (td->iodepth_batch > td->iodepth || !td->iodepth_batch)
718 td->iodepth_batch = td->iodepth;
722 * This function leaks the buffer
724 static char *to_kmg(unsigned int val)
726 char *buf = malloc(32);
727 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
738 snprintf(buf, 31, "%u%c", val, *p);
743 * Adds a job to the list of things todo. Sanitizes the various options
744 * to make sure we don't have conflicts, and initializes various
747 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
749 const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
750 "randread", "randwrite", "randrw" };
756 * the def_thread is just for options, it's not a real job
758 if (td == &def_thread)
764 td->io_ops->flags |= FIO_RAWIO;
766 td->filetype = FIO_TYPE_FILE;
767 if (td->filename && !lstat(td->filename, &sb)) {
768 if (S_ISBLK(sb.st_mode))
769 td->filetype = FIO_TYPE_BD;
770 else if (S_ISCHR(sb.st_mode))
771 td->filetype = FIO_TYPE_CHAR;
777 td->nr_uniq_files = 1;
779 td->nr_uniq_files = td->nr_files;
781 if (td->filetype == FIO_TYPE_FILE || td->filename) {
785 if (td->directory && td->directory[0] != '\0') {
786 if (lstat(td->directory, &sb) < 0) {
787 log_err("fio: %s is not a directory\n", td->directory);
788 td_verror(td, errno, "lstat");
791 if (!S_ISDIR(sb.st_mode)) {
792 log_err("fio: %s is not a directory\n", td->directory);
795 len = sprintf(tmp, "%s/", td->directory);
798 td->files = malloc(sizeof(struct fio_file) * td->nr_files);
800 for_each_file(td, f, i) {
801 memset(f, 0, sizeof(*f));
805 sprintf(tmp + len, "%s", td->filename);
807 sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
808 f->file_name = strdup(tmp);
812 td->files = malloc(sizeof(struct fio_file));
815 memset(f, 0, sizeof(*f));
817 f->file_name = strdup(jobname);
820 for_each_file(td, f, i) {
821 f->file_size = td->total_file_size / td->nr_files;
822 f->file_offset = td->start_offset;
825 fio_sem_init(&td->mutex, 0);
827 td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;
828 td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
829 td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX;
831 if (td->stonewall && td->thread_number > 1)
834 td->groupid = groupid;
839 if (td->write_lat_log) {
840 setup_log(&td->ts.slat_log);
841 setup_log(&td->ts.clat_log);
843 if (td->write_bw_log)
844 setup_log(&td->ts.bw_log);
847 td->name = strdup(jobname);
851 if (td->io_ops->flags & FIO_CPUIO)
852 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
854 char *c1, *c2, *c3, *c4;
856 c1 = to_kmg(td->min_bs[DDIR_READ]);
857 c2 = to_kmg(td->max_bs[DDIR_READ]);
858 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
859 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
861 fprintf(f_out, "%s: (g=%d): rw=%s, bs=%s-%s/%s-%s, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[td->td_ddir], c1, c2, c3, c4, td->io_ops->name, td->iodepth);
868 } else if (job_add_num == 1)
869 fprintf(f_out, "...\n");
873 * recurse add identical jobs, clear numjobs and stonewall options
874 * as they don't apply to sub-jobs
876 numjobs = td->numjobs;
878 struct thread_data *td_new = get_new_job(0, td);
884 td_new->stonewall = 0;
885 job_add_num = numjobs - 1;
887 if (add_job(td_new, jobname, job_add_num))
897 * Initialize the various random states we need (random io, block size ranges,
898 * read/write mix, etc).
900 int init_random_state(struct thread_data *td)
902 unsigned long seeds[5];
903 int fd, num_maps, blocks, i;
906 if (td->io_ops->flags & FIO_CPUIO)
909 fd = open("/dev/urandom", O_RDONLY);
911 td_verror(td, errno, "open");
915 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
916 td_verror(td, EIO, "read");
923 os_random_seed(seeds[0], &td->bsrange_state);
924 os_random_seed(seeds[1], &td->verify_state);
925 os_random_seed(seeds[2], &td->rwmix_state);
927 if (td->file_service_type == FIO_FSERVICE_RANDOM)
928 os_random_seed(seeds[3], &td->next_file_state);
933 if (td->rand_repeatable)
934 seeds[4] = FIO_RANDSEED * td->thread_number;
936 if (!td->norandommap) {
937 for_each_file(td, f, i) {
938 blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs;
939 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
940 f->file_map = malloc(num_maps * sizeof(long));
941 f->num_maps = num_maps;
942 memset(f->file_map, 0, num_maps * sizeof(long));
946 os_random_seed(seeds[4], &td->random_state);
950 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
952 #ifdef FIO_HAVE_CPU_AFFINITY
957 for (i = 0; i < sizeof(int) * 8; i++) {
959 CPU_SET(i, &cpumask);
964 static int is_empty_or_comment(char *line)
968 for (i = 0; i < strlen(line); i++) {
973 if (!isspace(line[i]) && !iscntrl(line[i]))
981 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
983 static char *get_mmap_file(const char *str)
985 char *p = strstr(str, ":");
991 strip_blank_front(&p);
996 static int str_mem_cb(void *data, const char *mem)
998 struct thread_data *td = data;
1000 if (td->mem_type == MEM_MMAPHUGE || td->mem_type == MEM_MMAP) {
1001 td->mmapfile = get_mmap_file(mem);
1002 if (td->mem_type == MEM_MMAPHUGE && !td->mmapfile) {
1003 log_err("fio: mmaphuge:/path/to/file\n");
1011 static int str_ioengine_cb(void *data, const char *str)
1013 struct thread_data *td = data;
1015 td->io_ops = load_ioengine(td, str);
1022 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
1028 #ifdef FIO_HAVE_IOPRIO
1029 static int str_prioclass_cb(void *data, unsigned int *val)
1031 struct thread_data *td = data;
1033 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
1037 static int str_prio_cb(void *data, unsigned int *val)
1039 struct thread_data *td = data;
1046 static int str_exitall_cb(void)
1048 exitall_on_terminate = 1;
1052 static int str_cpumask_cb(void *data, unsigned int *val)
1054 struct thread_data *td = data;
1056 fill_cpu_mask(td->cpumask, *val);
1061 * This is our [ini] type file parser.
1063 static int parse_jobs_ini(char *file, int stonewall_flag)
1065 unsigned int global;
1066 struct thread_data *td;
1067 char *string, *name;
1071 int ret = 0, stonewall;
1073 f = fopen(file, "r");
1075 perror("fopen job file");
1079 string = malloc(4096);
1081 memset(name, 0, 256);
1083 stonewall = stonewall_flag;
1085 p = fgets(string, 4095, f);
1088 if (is_empty_or_comment(p))
1090 if (sscanf(p, "[%255s]", name) != 1)
1093 global = !strncmp(name, "global", 6);
1095 name[strlen(name) - 1] = '\0';
1097 td = get_new_job(global, &def_thread);
1104 * Seperate multiple job files by a stonewall
1106 if (!global && stonewall) {
1107 td->stonewall = stonewall;
1112 while ((p = fgets(string, 4096, f)) != NULL) {
1113 if (is_empty_or_comment(p))
1116 strip_blank_front(&p);
1126 * Don't break here, continue parsing options so we
1127 * dump all the bad ones. Makes trial/error fixups
1128 * easier on the user.
1130 ret |= parse_option(p, options, td);
1135 ret = add_job(td, name, 0);
1137 log_err("fio: job %s dropped\n", name);
1148 static int fill_def_thread(void)
1150 memset(&def_thread, 0, sizeof(def_thread));
1152 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1153 perror("sched_getaffinity");
1158 * fill default options
1160 fill_default_options(&def_thread, options);
1162 def_thread.timeout = def_timeout;
1163 def_thread.write_bw_log = write_bw_log;
1164 def_thread.write_lat_log = write_lat_log;
1166 #ifdef FIO_HAVE_DISK_UTIL
1167 def_thread.do_disk_util = 1;
1173 static void usage(void)
1175 printf("%s\n", fio_version_string);
1176 printf("\t--output\tWrite output to file\n");
1177 printf("\t--timeout\tRuntime in seconds\n");
1178 printf("\t--latency-log\tGenerate per-job latency logs\n");
1179 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1180 printf("\t--minimal\tMinimal (terse) output\n");
1181 printf("\t--version\tPrint version info and exit\n");
1182 printf("\t--help\t\tPrint this page\n");
1183 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
1186 static int parse_cmd_line(int argc, char *argv[])
1188 struct thread_data *td = NULL;
1189 int c, ini_idx = 0, lidx, ret, dont_add_job = 0;
1191 while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
1194 def_timeout = atoi(optarg);
1203 f_out = fopen(optarg, "w+");
1205 perror("fopen output");
1217 ret = show_cmd_help(options, optarg);
1220 printf("%s\n", fio_version_string);
1222 case FIO_GETOPT_JOB: {
1223 const char *opt = long_options[lidx].name;
1226 if (!strncmp(opt, "name", 4) && td) {
1227 ret = add_job(td, td->name ?: "fio", 0);
1235 int global = !strncmp(val, "global", 6);
1237 td = get_new_job(global, &def_thread);
1242 ret = parse_cmd_option(opt, val, options, td);
1256 ret = add_job(td, td->name ?: "fio", 0);
1262 while (optind < argc) {
1264 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1265 ini_file[ini_idx - 1] = strdup(argv[optind]);
1272 static void free_shm(void)
1274 struct shmid_ds sbuf;
1277 shmdt((void *) threads);
1279 shmctl(shm_id, IPC_RMID, &sbuf);
1284 * The thread area is shared between the main process and the job
1285 * threads/processes. So setup a shared memory segment that will hold
1288 static int setup_thread_area(void)
1291 * 1024 is too much on some machines, scale max_jobs if
1292 * we get a failure that looks like too large a shm segment
1295 size_t size = max_jobs * sizeof(struct thread_data);
1297 shm_id = shmget(0, size, IPC_CREAT | 0600);
1300 if (errno != EINVAL) {
1311 threads = shmat(shm_id, NULL, 0);
1312 if (threads == (void *) -1) {
1322 * Copy the fio options into the long options map, so we mirror
1323 * job and cmd line options.
1325 static void dupe_job_options(void)
1327 struct fio_option *o;
1331 while (long_options[i].name)
1336 long_options[i].name = o->name;
1337 long_options[i].val = FIO_GETOPT_JOB;
1338 if (o->type == FIO_OPT_STR_SET)
1339 long_options[i].has_arg = no_argument;
1341 long_options[i].has_arg = required_argument;
1345 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1349 int parse_options(int argc, char *argv[])
1356 options_init(options);
1360 if (setup_thread_area())
1362 if (fill_def_thread())
1365 job_files = parse_cmd_line(argc, argv);
1367 for (i = 0; i < job_files; i++) {
1368 if (fill_def_thread())
1370 if (parse_jobs_ini(ini_file[i], i))
1377 if (!thread_number) {
1378 log_err("No jobs defined(s)\n");