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_mem_cb(void *, const char *);
26 static int str_lockmem_cb(void *, unsigned long *);
27 #ifdef FIO_HAVE_IOPRIO
28 static int str_prio_cb(void *, unsigned int *);
29 static int str_prioclass_cb(void *, unsigned int *);
31 static int str_exitall_cb(void);
32 static int str_cpumask_cb(void *, unsigned int *);
34 #define __stringify_1(x) #x
35 #define __stringify(x) __stringify_1(x)
38 * Map of job/command line options
40 static struct fio_option options[] = {
42 .name = "description",
43 .type = FIO_OPT_STR_STORE,
44 .off1 = td_var_offset(description),
45 .help = "Text job description",
49 .type = FIO_OPT_STR_STORE,
50 .off1 = td_var_offset(name),
51 .help = "Name of this job",
55 .type = FIO_OPT_STR_STORE,
56 .off1 = td_var_offset(directory),
57 .help = "Directory to store files in",
61 .type = FIO_OPT_STR_STORE,
62 .off1 = td_var_offset(filename),
63 .help = "Force the use of a specific file",
68 .off1 = td_var_offset(td_ddir),
69 .help = "IO direction",
72 { .ival = "read", .oval = TD_DDIR_READ },
73 { .ival = "write", .oval = TD_DDIR_WRITE },
74 { .ival = "randread", .oval = TD_DDIR_RANDREAD },
75 { .ival = "randwrite", .oval = TD_DDIR_RANDWRITE },
76 { .ival = "rw", .oval = TD_DDIR_RW },
77 { .ival = "randrw", .oval = TD_DDIR_RANDRW },
82 .type = FIO_OPT_STR_STORE,
83 .off1 = td_var_offset(ioengine),
84 .help = "IO engine to use",
88 #ifdef FIO_HAVE_LIBAIO
89 { .ival = "libaio", },
91 #ifdef FIO_HAVE_POSIXAIO
92 { .ival = "posixaio", },
95 #ifdef FIO_HAVE_SPLICE
96 { .ival = "splice", },
101 { .ival = "null", }, { .ival = "net", },
102 #ifdef FIO_HAVE_SYSLET
103 { .ival = "syslet-rw", },
105 { .ival = "external", },
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",
186 .off1 = td_var_offset(open_files),
187 .help = "Number of files to keep open at the same time",
190 .name = "file_service_type",
192 .off1 = td_var_offset(file_service_type),
193 .help = "How to select which file to service next",
196 { .ival = "random", .oval = FIO_FSERVICE_RANDOM },
197 { .ival = "roundrobin", .oval = FIO_FSERVICE_RR },
203 .off1 = td_var_offset(fsync_blocks),
204 .help = "Issue fsync for writes every given number of blocks",
209 .type = FIO_OPT_BOOL,
210 .off1 = td_var_offset(odirect),
211 .help = "Use O_DIRECT IO (negates buffered)",
216 .type = FIO_OPT_BOOL,
217 .off1 = td_var_offset(odirect),
219 .help = "Use buffered IO (negates direct)",
224 .type = FIO_OPT_BOOL,
225 .off1 = td_var_offset(overwrite),
226 .help = "When writing, set whether to overwrite current data",
232 .off1 = td_var_offset(loops),
233 .help = "Number of times to run the job",
239 .off1 = td_var_offset(numjobs),
240 .help = "Duplicate this job this many times",
244 .name = "startdelay",
246 .off1 = td_var_offset(start_delay),
247 .help = "Only start job when this period has passed",
253 .type = FIO_OPT_STR_VAL_TIME,
254 .off1 = td_var_offset(timeout),
255 .help = "Stop workload when this amount of time has passed",
262 .off1 = td_var_offset(mem_type),
263 .help = "Backing type for IO buffers",
266 { .ival = "malloc", .oval = MEM_MALLOC },
267 { .ival = "shm", .oval = MEM_SHM },
268 #ifdef FIO_HAVE_HUGETLB
269 { .ival = "shmhuge", .oval = MEM_SHMHUGE },
271 { .ival = "mmap", .oval = MEM_MMAP },
272 #ifdef FIO_HAVE_HUGETLB
273 { .ival = "mmaphuge", .oval = MEM_MMAPHUGE },
280 .off1 = td_var_offset(verify),
281 .help = "Verify sum function",
284 { .ival = "0", .oval = VERIFY_NONE },
285 { .ival = "crc32", .oval = VERIFY_CRC32 },
286 { .ival = "md5", .oval = VERIFY_MD5 },
290 .name = "write_iolog",
291 .type = FIO_OPT_STR_STORE,
292 .off1 = td_var_offset(write_iolog_file),
293 .help = "Store IO pattern to file",
296 .name = "read_iolog",
297 .type = FIO_OPT_STR_STORE,
298 .off1 = td_var_offset(read_iolog_file),
299 .help = "Playback IO pattern from file",
302 .name = "exec_prerun",
303 .type = FIO_OPT_STR_STORE,
304 .off1 = td_var_offset(exec_prerun),
305 .help = "Execute this file prior to running job",
308 .name = "exec_postrun",
309 .type = FIO_OPT_STR_STORE,
310 .off1 = td_var_offset(exec_postrun),
311 .help = "Execute this file after running job",
313 #ifdef FIO_HAVE_IOSCHED_SWITCH
315 .name = "ioscheduler",
316 .type = FIO_OPT_STR_STORE,
317 .off1 = td_var_offset(ioscheduler),
318 .help = "Use this IO scheduler on the backing device",
323 .type = FIO_OPT_STR_VAL,
324 .off1 = td_var_offset(zone_size),
325 .help = "Give size of an IO zone",
330 .type = FIO_OPT_STR_VAL,
331 .off1 = td_var_offset(zone_skip),
332 .help = "Space between IO zones",
337 .type = FIO_OPT_STR_VAL,
338 .cb = str_lockmem_cb,
339 .help = "Lock down this amount of memory",
343 .name = "rwmixcycle",
345 .off1 = td_var_offset(rwmixcycle),
346 .help = "Cycle period for mixed read/write workloads (msec)",
352 .off1 = td_var_offset(rwmixread),
354 .help = "Percentage of mixed workload that is reads",
358 .name = "rwmixwrite",
360 .off1 = td_var_offset(rwmixwrite),
362 .help = "Percentage of mixed workload that is writes",
368 .off1 = td_var_offset(nice),
369 .help = "Set job CPU nice value",
374 #ifdef FIO_HAVE_IOPRIO
379 .help = "Set job IO priority value",
386 .cb = str_prioclass_cb,
387 .help = "Set job IO priority class",
395 .off1 = td_var_offset(thinktime),
396 .help = "Idle time between IO buffers (usec)",
400 .name = "thinktime_spin",
402 .off1 = td_var_offset(thinktime_spin),
403 .help = "Start think time by spinning this amount (usec)",
407 .name = "thinktime_blocks",
409 .off1 = td_var_offset(thinktime_blocks),
410 .help = "IO buffer period between 'thinktime'",
416 .off1 = td_var_offset(rate),
417 .help = "Set bandwidth rate",
422 .off1 = td_var_offset(ratemin),
423 .help = "The bottom limit accepted",
428 .off1 = td_var_offset(ratecycle),
429 .help = "Window average for rate limits (msec)",
433 .name = "invalidate",
434 .type = FIO_OPT_BOOL,
435 .off1 = td_var_offset(invalidate_cache),
436 .help = "Invalidate buffer/page cache prior to running job",
441 .type = FIO_OPT_BOOL,
442 .off1 = td_var_offset(sync_io),
443 .help = "Use O_SYNC for buffered writes",
449 .off1 = td_var_offset(bw_avg_time),
450 .help = "Time window over which to calculate bandwidth (msec)",
454 .name = "create_serialize",
455 .type = FIO_OPT_BOOL,
456 .off1 = td_var_offset(create_serialize),
457 .help = "Serialize creating of job files",
461 .name = "create_fsync",
462 .type = FIO_OPT_BOOL,
463 .off1 = td_var_offset(create_fsync),
464 .help = "Fsync file after creation",
470 .off1 = td_var_offset(cpuload),
471 .help = "Use this percentage of CPU",
476 .off1 = td_var_offset(cpucycle),
477 .help = "Length of the CPU burn cycles",
479 #ifdef FIO_HAVE_CPU_AFFINITY
483 .cb = str_cpumask_cb,
484 .help = "CPU affinity mask",
489 .type = FIO_OPT_BOOL,
490 .off1 = td_var_offset(end_fsync),
491 .help = "Include fsync at the end of job",
496 .type = FIO_OPT_BOOL,
497 .off1 = td_var_offset(unlink),
498 .help = "Unlink created files after job has completed",
503 .type = FIO_OPT_STR_SET,
504 .cb = str_exitall_cb,
505 .help = "Terminate all jobs when one exits",
509 .type = FIO_OPT_STR_SET,
510 .off1 = td_var_offset(stonewall),
511 .help = "Insert a hard barrier between this job and previous",
515 .type = FIO_OPT_STR_SET,
516 .off1 = td_var_offset(use_thread),
517 .help = "Use threads instead of forks",
520 .name = "write_bw_log",
521 .type = FIO_OPT_STR_SET,
522 .off1 = td_var_offset(write_bw_log),
523 .help = "Write log of bandwidth during run",
526 .name = "write_lat_log",
527 .type = FIO_OPT_STR_SET,
528 .off1 = td_var_offset(write_lat_log),
529 .help = "Write log of latency during run",
532 .name = "hugepage-size",
533 .type = FIO_OPT_STR_VAL,
534 .off1 = td_var_offset(hugepage_size),
535 .help = "When using hugepages, specify size of each page",
536 .def = __stringify(FIO_HUGE_PAGE),
539 .name = "group_reporting",
540 .type = FIO_OPT_STR_SET,
541 .off1 = td_var_offset(group_reporting),
542 .help = "Do reporting on a per-group basis",
549 #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
550 #define FIO_CMD_OPTS (16)
551 #define FIO_GETOPT_JOB (0x89988998)
554 * Command line options. These will contain the above, plus a few
555 * extra that only pertain to fio itself and not jobs.
557 static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
560 .has_arg = required_argument,
565 .has_arg = required_argument,
569 .name = "latency-log",
570 .has_arg = required_argument,
574 .name = "bandwidth-log",
575 .has_arg = required_argument,
580 .has_arg = optional_argument,
585 .has_arg = no_argument,
590 .has_arg = no_argument,
595 .has_arg = optional_argument,
603 static int def_timeout = 0;
605 static char fio_version_string[] = "fio 1.13";
607 static char **ini_file;
608 static int max_jobs = MAX_JOBS;
610 struct thread_data def_thread;
611 struct thread_data *threads = NULL;
613 int exitall_on_terminate = 0;
614 int terse_output = 0;
615 unsigned long long mlock_size = 0;
619 static int write_lat_log = 0;
620 int write_bw_log = 0;
633 * Return a free job structure.
635 static struct thread_data *get_new_job(int global, struct thread_data *parent)
637 struct thread_data *td;
641 if (thread_number >= max_jobs)
644 td = &threads[thread_number++];
647 td->thread_number = thread_number;
651 static void put_job(struct thread_data *td)
653 if (td == &def_thread)
657 fprintf(f_out, "fio: %s\n", td->verror);
659 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
664 * Lazy way of fixing up options that depend on each other. We could also
665 * define option callback handlers, but this is easier.
667 static void fixup_options(struct thread_data *td)
669 if (!td->rwmixread && td->rwmixwrite)
670 td->rwmixread = 100 - td->rwmixwrite;
672 if (td->write_iolog_file && td->read_iolog_file) {
673 log_err("fio: read iolog overrides write_iolog\n");
674 free(td->write_iolog_file);
675 td->write_iolog_file = NULL;
678 if (td->io_ops->flags & FIO_SYNCIO)
682 td->iodepth = td->open_files;
686 * only really works for sequential io for now, and with 1 file
688 if (td->zone_size && td_random(td) && td->open_files == 1)
692 * Reads can do overwrites, we always need to pre-create the file
694 if (td_read(td) || td_rw(td))
697 if (!td->min_bs[DDIR_READ])
698 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
699 if (!td->max_bs[DDIR_READ])
700 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
701 if (!td->min_bs[DDIR_WRITE])
702 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
703 if (!td->max_bs[DDIR_WRITE])
704 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
706 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
708 if (td_read(td) && !td_rw(td))
711 if (td->norandommap && td->verify != VERIFY_NONE) {
712 log_err("fio: norandommap given, verify disabled\n");
713 td->verify = VERIFY_NONE;
715 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
716 log_err("fio: bs_unaligned may not work with raw io\n");
719 * O_DIRECT and char doesn't mix, clear that flag if necessary.
721 if (td->filetype == FIO_TYPE_CHAR && td->odirect)
725 * thinktime_spin must be less than thinktime
727 if (td->thinktime_spin > td->thinktime)
728 td->thinktime_spin = td->thinktime;
731 * The low water mark cannot be bigger than the iodepth
733 if (td->iodepth_low > td->iodepth || !td->iodepth_low) {
735 * syslet work around - if the workload is sequential,
736 * we want to let the queue drain all the way down to
737 * avoid seeking between async threads
739 if (!strcmp(td->io_ops->name, "syslet-rw") && !td_random(td))
742 td->iodepth_low = td->iodepth;
746 * If batch number isn't set, default to the same as iodepth
748 if (td->iodepth_batch > td->iodepth || !td->iodepth_batch)
749 td->iodepth_batch = td->iodepth;
751 if (td->open_files > td->nr_files || !td->open_files)
752 td->open_files = td->nr_files;
756 * This function leaks the buffer
758 static char *to_kmg(unsigned int val)
760 char *buf = malloc(32);
761 char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
772 snprintf(buf, 31, "%u%c", val, *p);
776 /* External engines are specified by "external:name.o") */
777 static const char *get_engine_name(const char *str)
779 char *p = strstr(str, ":");
785 strip_blank_front(&p);
791 * Adds a job to the list of things todo. Sanitizes the various options
792 * to make sure we don't have conflicts, and initializes various
795 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
797 const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
798 "randread", "randwrite", "randrw" };
805 * the def_thread is just for options, it's not a real job
807 if (td == &def_thread)
810 engine = get_engine_name(td->ioengine);
811 td->io_ops = load_ioengine(td, engine);
813 log_err("fio: failed to load engine %s\n", engine);
818 td->io_ops->flags |= FIO_RAWIO;
820 td->filetype = FIO_TYPE_FILE;
821 if (td->filename && !lstat(td->filename, &sb)) {
822 if (S_ISBLK(sb.st_mode))
823 td->filetype = FIO_TYPE_BD;
824 else if (S_ISCHR(sb.st_mode))
825 td->filetype = FIO_TYPE_CHAR;
831 td->nr_uniq_files = 1;
833 td->nr_uniq_files = td->open_files;
835 if (td->filetype == FIO_TYPE_FILE || td->filename) {
839 if (td->directory && td->directory[0] != '\0') {
840 if (lstat(td->directory, &sb) < 0) {
841 log_err("fio: %s is not a directory\n", td->directory);
842 td_verror(td, errno, "lstat");
845 if (!S_ISDIR(sb.st_mode)) {
846 log_err("fio: %s is not a directory\n", td->directory);
849 len = sprintf(tmp, "%s/", td->directory);
852 td->files = malloc(sizeof(struct fio_file) * td->open_files);
854 for_each_file(td, f, i) {
855 memset(f, 0, sizeof(*f));
859 sprintf(tmp + len, "%s", td->filename);
861 sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
862 f->file_name = strdup(tmp);
865 td->open_files = td->nr_files = 1;
866 td->files = malloc(sizeof(struct fio_file));
869 memset(f, 0, sizeof(*f));
871 f->file_name = strdup(jobname);
874 for_each_file(td, f, i) {
875 f->file_size = td->total_file_size / td->nr_files;
876 f->file_offset = td->start_offset;
879 td->mutex = fio_sem_init(0);
881 td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX;
882 td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX;
883 td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX;
885 if (td->stonewall && td->thread_number > 1)
888 td->groupid = groupid;
893 if (td->write_lat_log) {
894 setup_log(&td->ts.slat_log);
895 setup_log(&td->ts.clat_log);
897 if (td->write_bw_log)
898 setup_log(&td->ts.bw_log);
901 td->name = strdup(jobname);
905 if (td->io_ops->flags & FIO_CPUIO)
906 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
908 char *c1, *c2, *c3, *c4;
910 c1 = to_kmg(td->min_bs[DDIR_READ]);
911 c2 = to_kmg(td->max_bs[DDIR_READ]);
912 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
913 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
915 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);
922 } else if (job_add_num == 1)
923 fprintf(f_out, "...\n");
927 * recurse add identical jobs, clear numjobs and stonewall options
928 * as they don't apply to sub-jobs
930 numjobs = td->numjobs;
932 struct thread_data *td_new = get_new_job(0, td);
938 td_new->stonewall = 0;
939 job_add_num = numjobs - 1;
941 if (add_job(td_new, jobname, job_add_num))
951 * Initialize the various random states we need (random io, block size ranges,
952 * read/write mix, etc).
954 int init_random_state(struct thread_data *td)
956 unsigned long seeds[5];
957 int fd, num_maps, blocks, i;
960 if (td->io_ops->flags & FIO_CPUIO)
963 fd = open("/dev/urandom", O_RDONLY);
965 td_verror(td, errno, "open");
969 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
970 td_verror(td, EIO, "read");
977 os_random_seed(seeds[0], &td->bsrange_state);
978 os_random_seed(seeds[1], &td->verify_state);
979 os_random_seed(seeds[2], &td->rwmix_state);
981 if (td->file_service_type == FIO_FSERVICE_RANDOM)
982 os_random_seed(seeds[3], &td->next_file_state);
987 if (td->rand_repeatable)
988 seeds[4] = FIO_RANDSEED * td->thread_number;
990 if (!td->norandommap) {
991 for_each_file(td, f, i) {
992 blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs;
993 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
994 f->file_map = malloc(num_maps * sizeof(long));
995 f->num_maps = num_maps;
996 memset(f->file_map, 0, num_maps * sizeof(long));
1000 os_random_seed(seeds[4], &td->random_state);
1004 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
1006 #ifdef FIO_HAVE_CPU_AFFINITY
1011 for (i = 0; i < sizeof(int) * 8; i++) {
1013 CPU_SET(i, &cpumask);
1018 static int is_empty_or_comment(char *line)
1022 for (i = 0; i < strlen(line); i++) {
1027 if (!isspace(line[i]) && !iscntrl(line[i]))
1035 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
1037 static char *get_mmap_file(const char *str)
1039 char *p = strstr(str, ":");
1045 strip_blank_front(&p);
1050 static int str_mem_cb(void *data, const char *mem)
1052 struct thread_data *td = data;
1054 if (td->mem_type == MEM_MMAPHUGE || td->mem_type == MEM_MMAP) {
1055 td->mmapfile = get_mmap_file(mem);
1056 if (td->mem_type == MEM_MMAPHUGE && !td->mmapfile) {
1057 log_err("fio: mmaphuge:/path/to/file\n");
1065 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
1071 #ifdef FIO_HAVE_IOPRIO
1072 static int str_prioclass_cb(void *data, unsigned int *val)
1074 struct thread_data *td = data;
1076 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
1080 static int str_prio_cb(void *data, unsigned int *val)
1082 struct thread_data *td = data;
1089 static int str_exitall_cb(void)
1091 exitall_on_terminate = 1;
1095 static int str_cpumask_cb(void *data, unsigned int *val)
1097 struct thread_data *td = data;
1099 fill_cpu_mask(td->cpumask, *val);
1104 * This is our [ini] type file parser.
1106 static int parse_jobs_ini(char *file, int stonewall_flag)
1108 unsigned int global;
1109 struct thread_data *td;
1110 char *string, *name;
1114 int ret = 0, stonewall;
1116 f = fopen(file, "r");
1118 perror("fopen job file");
1122 string = malloc(4096);
1124 memset(name, 0, 256);
1126 stonewall = stonewall_flag;
1128 p = fgets(string, 4095, f);
1131 if (is_empty_or_comment(p))
1133 if (sscanf(p, "[%255s]", name) != 1)
1136 global = !strncmp(name, "global", 6);
1138 name[strlen(name) - 1] = '\0';
1140 td = get_new_job(global, &def_thread);
1147 * Seperate multiple job files by a stonewall
1149 if (!global && stonewall) {
1150 td->stonewall = stonewall;
1155 while ((p = fgets(string, 4096, f)) != NULL) {
1156 if (is_empty_or_comment(p))
1159 strip_blank_front(&p);
1169 * Don't break here, continue parsing options so we
1170 * dump all the bad ones. Makes trial/error fixups
1171 * easier on the user.
1173 ret |= parse_option(p, options, td);
1178 ret = add_job(td, name, 0);
1180 log_err("fio: job %s dropped\n", name);
1191 static int fill_def_thread(void)
1193 memset(&def_thread, 0, sizeof(def_thread));
1195 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1196 perror("sched_getaffinity");
1201 * fill default options
1203 fill_default_options(&def_thread, options);
1205 def_thread.timeout = def_timeout;
1206 def_thread.write_bw_log = write_bw_log;
1207 def_thread.write_lat_log = write_lat_log;
1209 #ifdef FIO_HAVE_DISK_UTIL
1210 def_thread.do_disk_util = 1;
1216 static void usage(void)
1218 printf("%s\n", fio_version_string);
1219 printf("\t--output\tWrite output to file\n");
1220 printf("\t--timeout\tRuntime in seconds\n");
1221 printf("\t--latency-log\tGenerate per-job latency logs\n");
1222 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1223 printf("\t--minimal\tMinimal (terse) output\n");
1224 printf("\t--version\tPrint version info and exit\n");
1225 printf("\t--help\t\tPrint this page\n");
1226 printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
1229 static int parse_cmd_line(int argc, char *argv[])
1231 struct thread_data *td = NULL;
1232 int c, ini_idx = 0, lidx, ret, dont_add_job = 0;
1234 while ((c = getopt_long_only(argc, argv, "", long_options, &lidx)) != -1) {
1237 def_timeout = atoi(optarg);
1246 f_out = fopen(optarg, "w+");
1248 perror("fopen output");
1260 ret = show_cmd_help(options, optarg);
1263 printf("%s\n", fio_version_string);
1265 case FIO_GETOPT_JOB: {
1266 const char *opt = long_options[lidx].name;
1269 if (!strncmp(opt, "name", 4) && td) {
1270 ret = add_job(td, td->name ?: "fio", 0);
1278 int global = !strncmp(val, "global", 6);
1280 td = get_new_job(global, &def_thread);
1285 ret = parse_cmd_option(opt, val, options, td);
1299 ret = add_job(td, td->name ?: "fio", 0);
1305 while (optind < argc) {
1307 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1308 ini_file[ini_idx - 1] = strdup(argv[optind]);
1315 static void free_shm(void)
1317 struct shmid_ds sbuf;
1320 shmdt((void *) threads);
1322 shmctl(shm_id, IPC_RMID, &sbuf);
1327 * The thread area is shared between the main process and the job
1328 * threads/processes. So setup a shared memory segment that will hold
1331 static int setup_thread_area(void)
1334 * 1024 is too much on some machines, scale max_jobs if
1335 * we get a failure that looks like too large a shm segment
1338 size_t size = max_jobs * sizeof(struct thread_data);
1340 shm_id = shmget(0, size, IPC_CREAT | 0600);
1343 if (errno != EINVAL) {
1354 threads = shmat(shm_id, NULL, 0);
1355 if (threads == (void *) -1) {
1365 * Copy the fio options into the long options map, so we mirror
1366 * job and cmd line options.
1368 static void dupe_job_options(void)
1370 struct fio_option *o;
1374 while (long_options[i].name)
1379 long_options[i].name = o->name;
1380 long_options[i].val = FIO_GETOPT_JOB;
1381 if (o->type == FIO_OPT_STR_SET)
1382 long_options[i].has_arg = no_argument;
1384 long_options[i].has_arg = required_argument;
1388 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1392 int parse_options(int argc, char *argv[])
1399 options_init(options);
1403 if (setup_thread_area())
1405 if (fill_def_thread())
1408 job_files = parse_cmd_line(argc, argv);
1410 for (i = 0; i < job_files; i++) {
1411 if (fill_def_thread())
1413 if (parse_jobs_ini(ini_file[i], i))
1420 if (!thread_number) {
1421 log_err("No jobs defined(s)\n");