2 * This file contains job initialization and setup functions.
15 #include <sys/types.h>
25 #define DEF_TIMEOUT (0)
26 #define DEF_RATE_CYCLE (1000)
27 #define DEF_ODIRECT (1)
28 #define DEF_IO_ENGINE (FIO_SYNCIO)
29 #define DEF_IO_ENGINE_NAME "sync"
30 #define DEF_SEQUENTIAL (1)
31 #define DEF_RAND_REPEAT (1)
32 #define DEF_OVERWRITE (0)
33 #define DEF_INVALIDATE (1)
34 #define DEF_SYNCIO (0)
35 #define DEF_RANDSEED (0xb1899bedUL)
36 #define DEF_BWAVGTIME (500)
37 #define DEF_CREATE_SER (1)
38 #define DEF_CREATE_FSYNC (1)
40 #define DEF_VERIFY (0)
41 #define DEF_STONEWALL (0)
42 #define DEF_NUMJOBS (1)
43 #define DEF_USE_THREAD (0)
44 #define DEF_FILE_SIZE (1024 * 1024 * 1024UL)
45 #define DEF_ZONE_SIZE (0)
46 #define DEF_ZONE_SKIP (0)
47 #define DEF_RWMIX_CYCLE (500)
48 #define DEF_RWMIX_READ (50)
50 #define DEF_NR_FILES (1)
51 #define DEF_UNLINK (1)
52 #define DEF_WRITE_BW_LOG (0)
53 #define DEF_WRITE_LAT_LOG (0)
54 #define DEF_NO_RAND_MAP (0)
55 #define DEF_HUGEPAGE_SIZE FIO_HUGE_PAGE
56 #define DEF_THINKTIME_BLOCKS (1)
58 #define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var)
60 static int str_rw_cb(void *, const char *);
61 static int str_ioengine_cb(void *, const char *);
62 static int str_mem_cb(void *, const char *);
63 static int str_verify_cb(void *, const char *);
64 static int str_lockmem_cb(void *, unsigned long *);
65 #ifdef FIO_HAVE_IOPRIO
66 static int str_prio_cb(void *, unsigned int *);
67 static int str_prioclass_cb(void *, unsigned int *);
69 static int str_exitall_cb(void);
70 static int str_cpumask_cb(void *, unsigned int *);
73 * Map of job/command line options
75 static struct fio_option options[] = {
78 .type = FIO_OPT_STR_STORE,
79 .off1 = td_var_offset(name),
83 .type = FIO_OPT_STR_STORE,
84 .off1 = td_var_offset(directory),
88 .type = FIO_OPT_STR_STORE,
89 .off1 = td_var_offset(filename),
99 .cb = str_ioengine_cb,
112 .name = "write_iolog",
113 .type = FIO_OPT_STR_STORE,
114 .off1 = td_var_offset(write_iolog_file),
117 .name = "read_iolog",
118 .type = FIO_OPT_STR_STORE,
119 .off1 = td_var_offset(read_iolog_file),
122 .name = "exec_prerun",
123 .type = FIO_OPT_STR_STORE,
124 .off1 = td_var_offset(exec_prerun),
127 .name = "exec_postrun",
128 .type = FIO_OPT_STR_STORE,
129 .off1 = td_var_offset(exec_postrun),
131 #ifdef FIO_HAVE_IOSCHED_SWITCH
133 .name = "ioscheduler",
134 .type = FIO_OPT_STR_STORE,
135 .off1 = td_var_offset(ioscheduler),
140 .type = FIO_OPT_STR_VAL,
141 .off1 = td_var_offset(total_file_size),
145 .type = FIO_OPT_STR_VAL_INT,
146 .off1 = td_var_offset(bs[DDIR_READ]),
147 .off2 = td_var_offset(bs[DDIR_WRITE]),
151 .type = FIO_OPT_STR_VAL,
152 .off1 = td_var_offset(start_offset),
156 .type = FIO_OPT_STR_VAL,
157 .off1 = td_var_offset(zone_size),
161 .type = FIO_OPT_STR_VAL,
162 .off1 = td_var_offset(zone_skip),
166 .type = FIO_OPT_STR_VAL,
167 .cb = str_lockmem_cb,
171 .type = FIO_OPT_RANGE,
172 .off1 = td_var_offset(min_bs[DDIR_READ]),
173 .off2 = td_var_offset(max_bs[DDIR_READ]),
174 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
175 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
180 .off1 = td_var_offset(nr_files),
185 .off1 = td_var_offset(iodepth),
190 .off1 = td_var_offset(fsync_blocks),
193 .name = "rwmixcycle",
195 .off1 = td_var_offset(rwmixcycle),
200 .off1 = td_var_offset(rwmixread),
204 .name = "rwmixwrite",
206 .off1 = td_var_offset(rwmixwrite),
212 .off1 = td_var_offset(nice),
214 #ifdef FIO_HAVE_IOPRIO
223 .cb = str_prioclass_cb,
229 .off1 = td_var_offset(thinktime),
232 .name = "thinktime_blocks",
234 .off1 = td_var_offset(thinktime_blocks),
239 .off1 = td_var_offset(rate),
244 .off1 = td_var_offset(ratemin),
249 .off1 = td_var_offset(ratecycle),
252 .name = "startdelay",
254 .off1 = td_var_offset(start_delay),
258 .type = FIO_OPT_STR_VAL_TIME,
259 .off1 = td_var_offset(timeout),
262 .name = "invalidate",
264 .off1 = td_var_offset(invalidate_cache),
269 .off1 = td_var_offset(sync_io),
274 .off1 = td_var_offset(bw_avg_time),
277 .name = "create_serialize",
279 .off1 = td_var_offset(create_serialize),
282 .name = "create_fsync",
284 .off1 = td_var_offset(create_fsync),
289 .off1 = td_var_offset(loops),
294 .off1 = td_var_offset(numjobs),
299 .off1 = td_var_offset(cpuload),
304 .off1 = td_var_offset(cpucycle),
309 .off1 = td_var_offset(odirect),
314 .off1 = td_var_offset(overwrite),
316 #ifdef FIO_HAVE_CPU_AFFINITY
320 .cb = str_cpumask_cb,
326 .off1 = td_var_offset(end_fsync),
331 .off1 = td_var_offset(unlink),
335 .type = FIO_OPT_STR_SET,
336 .cb = str_exitall_cb,
340 .type = FIO_OPT_STR_SET,
341 .off1 = td_var_offset(stonewall),
345 .type = FIO_OPT_STR_SET,
346 .off1 = td_var_offset(thread),
349 .name = "write_bw_log",
350 .type = FIO_OPT_STR_SET,
351 .off1 = td_var_offset(write_bw_log),
354 .name = "write_lat_log",
355 .type = FIO_OPT_STR_SET,
356 .off1 = td_var_offset(write_lat_log),
359 .name = "norandommap",
360 .type = FIO_OPT_STR_SET,
361 .off1 = td_var_offset(norandommap),
364 .name = "bs_unaligned",
365 .type = FIO_OPT_STR_SET,
366 .off1 = td_var_offset(bs_unaligned),
369 .name = "hugepage-size",
370 .type = FIO_OPT_STR_VAL,
371 .off1 = td_var_offset(hugepage_size),
378 #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option))
379 #define FIO_CMD_OPTS (16)
380 #define FIO_GETOPT_JOB (0x89988998)
383 * Command line options. These will contain the above, plus a few
384 * extra that only pertain to fio itself and not jobs.
386 static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = {
389 .has_arg = required_argument,
394 .has_arg = required_argument,
398 .name = "latency-log",
399 .has_arg = required_argument,
403 .name = "bandwidth-log",
404 .has_arg = required_argument,
409 .has_arg = optional_argument,
414 .has_arg = no_argument,
422 static int def_timeout = DEF_TIMEOUT;
424 static char fio_version_string[] = "fio 1.10";
426 static char **ini_file;
427 static int max_jobs = MAX_JOBS;
429 struct thread_data def_thread;
430 struct thread_data *threads = NULL;
432 int exitall_on_terminate = 0;
433 int terse_output = 0;
434 unsigned long long mlock_size = 0;
438 static int write_lat_log = DEF_WRITE_LAT_LOG;
439 static int write_bw_log = DEF_WRITE_BW_LOG;
442 * Return a free job structure.
444 static struct thread_data *get_new_job(int global, struct thread_data *parent)
446 struct thread_data *td;
450 if (thread_number >= max_jobs)
453 td = &threads[thread_number++];
456 td->thread_number = thread_number;
460 static void put_job(struct thread_data *td)
462 if (td == &def_thread)
465 memset(&threads[td->thread_number - 1], 0, sizeof(*td));
470 * Lazy way of fixing up options that depend on each other. We could also
471 * define option callback handlers, but this is easier.
473 static void fixup_options(struct thread_data *td)
475 if (!td->rwmixread && td->rwmixwrite)
476 td->rwmixread = 100 - td->rwmixwrite;
478 if (td->write_iolog_file && td->read_iolog_file) {
479 log_err("fio: read iolog overrides write_iolog\n");
480 free(td->write_iolog_file);
481 td->write_iolog_file = NULL;
484 if (td->io_ops->flags & FIO_SYNCIO)
488 td->iodepth = td->nr_files;
492 * only really works for sequential io for now, and with 1 file
494 if (td->zone_size && !td->sequential && td->nr_files == 1)
498 * Reads can do overwrites, we always need to pre-create the file
500 if (td_read(td) || td_rw(td))
503 if (!td->min_bs[DDIR_READ])
504 td->min_bs[DDIR_READ]= td->bs[DDIR_READ];
505 if (!td->max_bs[DDIR_READ])
506 td->max_bs[DDIR_READ] = td->bs[DDIR_READ];
507 if (!td->min_bs[DDIR_WRITE])
508 td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE];
509 if (!td->max_bs[DDIR_WRITE])
510 td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE];
512 td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]);
514 if (td_read(td) && !td_rw(td))
517 if (td->norandommap && td->verify != VERIFY_NONE) {
518 log_err("fio: norandommap given, verify disabled\n");
519 td->verify = VERIFY_NONE;
521 if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO))
522 log_err("fio: bs_unaligned may not work with raw io\n");
525 * O_DIRECT and char doesn't mix, clear that flag if necessary.
527 if (td->filetype == FIO_TYPE_CHAR && td->odirect)
532 * This function leaks the buffer
534 static char *to_kmg(unsigned int val)
536 char *buf = malloc(32);
537 char post[] = { 0, 'K', 'M', 'G', 'P', 0 };
548 snprintf(buf, 31, "%u%c", val, *p);
553 * Adds a job to the list of things todo. Sanitizes the various options
554 * to make sure we don't have conflicts, and initializes various
557 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
559 const char *ddir_str[] = { "read", "write", "randread", "randwrite",
560 "rw", NULL, "randrw" };
562 int numjobs, ddir, i;
566 * the def_thread is just for options, it's not a real job
568 if (td == &def_thread)
572 * Set default io engine, if none set
575 td->io_ops = load_ioengine(td, DEF_IO_ENGINE_NAME);
577 log_err("default engine %s not there?\n", DEF_IO_ENGINE_NAME);
583 td->io_ops->flags |= FIO_RAWIO;
585 td->filetype = FIO_TYPE_FILE;
586 if (!stat(jobname, &sb)) {
587 if (S_ISBLK(sb.st_mode))
588 td->filetype = FIO_TYPE_BD;
589 else if (S_ISCHR(sb.st_mode))
590 td->filetype = FIO_TYPE_CHAR;
596 td->nr_uniq_files = 1;
598 td->nr_uniq_files = td->nr_files;
600 if (td->filetype == FIO_TYPE_FILE || td->filename) {
604 if (td->directory && td->directory[0] != '\0')
605 len = sprintf(tmp, "%s/", td->directory);
607 td->files = malloc(sizeof(struct fio_file) * td->nr_files);
609 for_each_file(td, f, i) {
610 memset(f, 0, sizeof(*f));
614 sprintf(tmp + len, "%s", td->filename);
616 sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
617 f->file_name = strdup(tmp);
621 td->files = malloc(sizeof(struct fio_file));
624 memset(f, 0, sizeof(*f));
626 f->file_name = strdup(jobname);
629 for_each_file(td, f, i) {
630 f->file_size = td->total_file_size / td->nr_files;
631 f->file_offset = td->start_offset;
634 fio_sem_init(&td->mutex, 0);
636 td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX;
637 td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX;
638 td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX;
640 if (td->stonewall && td->thread_number > 1)
643 td->groupid = groupid;
648 if (td->write_lat_log) {
649 setup_log(&td->slat_log);
650 setup_log(&td->clat_log);
652 if (td->write_bw_log)
653 setup_log(&td->bw_log);
656 td->name = strdup(jobname);
658 ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2);
662 if (td->io_ops->flags & FIO_CPUIO)
663 fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle);
665 char *c1, *c2, *c3, *c4;
667 c1 = to_kmg(td->min_bs[DDIR_READ]);
668 c2 = to_kmg(td->max_bs[DDIR_READ]);
669 c3 = to_kmg(td->min_bs[DDIR_WRITE]);
670 c4 = to_kmg(td->max_bs[DDIR_WRITE]);
672 fprintf(f_out, "%s: (g=%d): rw=%s, odir=%u, bs=%s-%s/%s-%s, rate=%u, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[ddir], td->odirect, c1, c2, c3, c4, td->rate, td->io_ops->name, td->iodepth);
679 } else if (job_add_num == 1)
680 fprintf(f_out, "...\n");
684 * recurse add identical jobs, clear numjobs and stonewall options
685 * as they don't apply to sub-jobs
687 numjobs = td->numjobs;
689 struct thread_data *td_new = get_new_job(0, td);
695 td_new->stonewall = 0;
696 job_add_num = numjobs - 1;
698 if (add_job(td_new, jobname, job_add_num))
708 * Initialize the various random states we need (random io, block size ranges,
709 * read/write mix, etc).
711 int init_random_state(struct thread_data *td)
713 unsigned long seeds[4];
714 int fd, num_maps, blocks, i;
717 if (td->io_ops->flags & FIO_CPUIO)
720 fd = open("/dev/urandom", O_RDONLY);
722 td_verror(td, errno);
726 if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) {
734 os_random_seed(seeds[0], &td->bsrange_state);
735 os_random_seed(seeds[1], &td->verify_state);
736 os_random_seed(seeds[2], &td->rwmix_state);
741 if (td->rand_repeatable)
742 seeds[3] = DEF_RANDSEED;
744 if (!td->norandommap) {
745 for_each_file(td, f, i) {
746 blocks = (f->file_size + td->rw_min_bs - 1) / td->rw_min_bs;
747 num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP;
748 f->file_map = malloc(num_maps * sizeof(long));
749 f->num_maps = num_maps;
750 memset(f->file_map, 0, num_maps * sizeof(long));
754 os_random_seed(seeds[3], &td->random_state);
758 static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu)
760 #ifdef FIO_HAVE_CPU_AFFINITY
765 for (i = 0; i < sizeof(int) * 8; i++) {
767 CPU_SET(i, &cpumask);
772 static int is_empty_or_comment(char *line)
776 for (i = 0; i < strlen(line); i++) {
779 if (!isspace(line[i]) && !iscntrl(line[i]))
786 static int str_rw_cb(void *data, const char *mem)
788 struct thread_data *td = data;
790 if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) {
791 td->ddir = DDIR_READ;
794 } else if (!strncmp(mem, "randread", 8)) {
795 td->ddir = DDIR_READ;
798 } else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) {
799 td->ddir = DDIR_WRITE;
802 } else if (!strncmp(mem, "randwrite", 9)) {
803 td->ddir = DDIR_WRITE;
806 } else if (!strncmp(mem, "rw", 2)) {
807 td->ddir = DDIR_READ;
811 } else if (!strncmp(mem, "randrw", 6)) {
812 td->ddir = DDIR_READ;
818 log_err("fio: data direction: read, write, randread, randwrite, rw, randrw\n");
822 static int str_verify_cb(void *data, const char *mem)
824 struct thread_data *td = data;
826 if (!strncmp(mem, "0", 1)) {
827 td->verify = VERIFY_NONE;
829 } else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) {
830 td->verify = VERIFY_MD5;
832 } else if (!strncmp(mem, "crc32", 5)) {
833 td->verify = VERIFY_CRC32;
837 log_err("fio: verify types: md5, crc32\n");
842 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
844 static char *get_mmap_file(const char *str)
846 char *p = strstr(str, ":");
852 strip_blank_front(&p);
857 static int str_mem_cb(void *data, const char *mem)
859 struct thread_data *td = data;
861 if (!strncmp(mem, "malloc", 6)) {
862 td->mem_type = MEM_MALLOC;
864 } else if (!strncmp(mem, "mmaphuge", 8)) {
865 #ifdef FIO_HAVE_HUGETLB
867 * mmaphuge must be appended with the actual file
869 td->mmapfile = get_mmap_file(mem);
871 log_err("fio: mmaphuge:/path/to/file\n");
875 td->mem_type = MEM_MMAPHUGE;
878 log_err("fio: mmaphuge not available\n");
881 } else if (!strncmp(mem, "mmap", 4)) {
883 * Check if the user wants file backed memory. It's ok
884 * if there's no file given, we'll just use anon mamp then.
886 td->mmapfile = get_mmap_file(mem);
887 td->mem_type = MEM_MMAP;
889 } else if (!strncmp(mem, "shmhuge", 7)) {
890 #ifdef FIO_HAVE_HUGETLB
891 td->mem_type = MEM_SHMHUGE;
894 log_err("fio: shmhuge not available\n");
897 } else if (!strncmp(mem, "shm", 3)) {
898 td->mem_type = MEM_SHM;
902 log_err("fio: mem type: malloc, shm, shmhuge, mmap, mmaphuge\n");
906 static int str_ioengine_cb(void *data, const char *str)
908 struct thread_data *td = data;
910 td->io_ops = load_ioengine(td, str);
914 log_err("fio: ioengine= libaio, posixaio, sync, mmap, sgio, splice, cpu, null\n");
915 log_err("fio: or specify path to dynamic ioengine module\n");
919 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
925 #ifdef FIO_HAVE_IOPRIO
926 static int str_prioclass_cb(void *data, unsigned int *val)
928 struct thread_data *td = data;
930 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
934 static int str_prio_cb(void *data, unsigned int *val)
936 struct thread_data *td = data;
943 static int str_exitall_cb(void)
945 exitall_on_terminate = 1;
949 static int str_cpumask_cb(void *data, unsigned int *val)
951 struct thread_data *td = data;
953 fill_cpu_mask(td->cpumask, *val);
958 * This is our [ini] type file parser.
960 static int parse_jobs_ini(char *file, int stonewall_flag)
963 struct thread_data *td;
968 int ret = 0, stonewall;
970 f = fopen(file, "r");
972 perror("fopen job file");
976 string = malloc(4096);
978 memset(name, 0, 256);
980 stonewall = stonewall_flag;
982 p = fgets(string, 4095, f);
985 if (is_empty_or_comment(p))
987 if (sscanf(p, "[%255s]", name) != 1)
990 global = !strncmp(name, "global", 6);
992 name[strlen(name) - 1] = '\0';
994 td = get_new_job(global, &def_thread);
1001 * Seperate multiple job files by a stonewall
1003 if (!global && stonewall) {
1004 td->stonewall = stonewall;
1009 while ((p = fgets(string, 4096, f)) != NULL) {
1010 if (is_empty_or_comment(p))
1013 strip_blank_front(&p);
1023 * Don't break here, continue parsing options so we
1024 * dump all the bad ones. Makes trial/error fixups
1025 * easier on the user.
1027 ret |= parse_option(p, options, td);
1032 ret = add_job(td, name, 0);
1034 log_err("fio: job %s dropped\n", name);
1045 static int fill_def_thread(void)
1047 memset(&def_thread, 0, sizeof(def_thread));
1049 if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) {
1050 perror("sched_getaffinity");
1057 def_thread.ddir = DDIR_READ;
1058 def_thread.iomix = 0;
1059 def_thread.bs[DDIR_READ] = DEF_BS;
1060 def_thread.bs[DDIR_WRITE] = DEF_BS;
1061 def_thread.min_bs[DDIR_READ] = def_thread.min_bs[DDIR_WRITE] = 0;
1062 def_thread.max_bs[DDIR_READ] = def_thread.max_bs[DDIR_WRITE] = 0;
1063 def_thread.odirect = DEF_ODIRECT;
1064 def_thread.ratecycle = DEF_RATE_CYCLE;
1065 def_thread.sequential = DEF_SEQUENTIAL;
1066 def_thread.timeout = def_timeout;
1067 def_thread.overwrite = DEF_OVERWRITE;
1068 def_thread.invalidate_cache = DEF_INVALIDATE;
1069 def_thread.sync_io = DEF_SYNCIO;
1070 def_thread.mem_type = MEM_MALLOC;
1071 def_thread.bw_avg_time = DEF_BWAVGTIME;
1072 def_thread.create_serialize = DEF_CREATE_SER;
1073 def_thread.create_fsync = DEF_CREATE_FSYNC;
1074 def_thread.loops = DEF_LOOPS;
1075 def_thread.verify = DEF_VERIFY;
1076 def_thread.stonewall = DEF_STONEWALL;
1077 def_thread.numjobs = DEF_NUMJOBS;
1078 def_thread.use_thread = DEF_USE_THREAD;
1079 def_thread.rwmixcycle = DEF_RWMIX_CYCLE;
1080 def_thread.rwmixread = DEF_RWMIX_READ;
1081 def_thread.nice = DEF_NICE;
1082 def_thread.rand_repeatable = DEF_RAND_REPEAT;
1083 def_thread.nr_files = DEF_NR_FILES;
1084 def_thread.unlink = DEF_UNLINK;
1085 def_thread.write_bw_log = write_bw_log;
1086 def_thread.write_lat_log = write_lat_log;
1087 def_thread.norandommap = DEF_NO_RAND_MAP;
1088 def_thread.hugepage_size = DEF_HUGEPAGE_SIZE;
1089 def_thread.thinktime_blocks = DEF_THINKTIME_BLOCKS;
1090 #ifdef FIO_HAVE_DISK_UTIL
1091 def_thread.do_disk_util = 1;
1097 static void usage(void)
1099 printf("%s\n", fio_version_string);
1100 printf("\t--output\tWrite output to file\n");
1101 printf("\t--timeout\tRuntime in seconds\n");
1102 printf("\t--latency-log\tGenerate per-job latency logs\n");
1103 printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n");
1104 printf("\t--minimal\tMinimal (terse) output\n");
1105 printf("\t--version\tPrint version info and exit\n");
1108 static int parse_cmd_line(int argc, char *argv[])
1110 struct thread_data *td = NULL;
1111 int c, ini_idx = 0, lidx, ret;
1113 while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) {
1116 def_timeout = atoi(optarg);
1125 f_out = fopen(optarg, "w+");
1127 perror("fopen output");
1139 printf("%s\n", fio_version_string);
1141 case FIO_GETOPT_JOB: {
1142 const char *opt = long_options[lidx].name;
1145 if (!strncmp(opt, "name", 4) && td) {
1146 ret = add_job(td, td->name ?: "fio", 0);
1154 int global = !strncmp(val, "global", 6);
1156 td = get_new_job(global, &def_thread);
1161 ret = parse_cmd_option(opt, val, options, td);
1163 log_err("fio: job dropped\n");
1175 ret = add_job(td, td->name ?: "fio", 0);
1180 while (optind < argc) {
1182 ini_file = realloc(ini_file, ini_idx * sizeof(char *));
1183 ini_file[ini_idx - 1] = strdup(argv[optind]);
1190 static void free_shm(void)
1192 struct shmid_ds sbuf;
1195 shmdt((void *) threads);
1197 shmctl(shm_id, IPC_RMID, &sbuf);
1202 * The thread area is shared between the main process and the job
1203 * threads/processes. So setup a shared memory segment that will hold
1206 static int setup_thread_area(void)
1209 * 1024 is too much on some machines, scale max_jobs if
1210 * we get a failure that looks like too large a shm segment
1213 size_t size = max_jobs * sizeof(struct thread_data);
1215 shm_id = shmget(0, size, IPC_CREAT | 0600);
1218 if (errno != EINVAL) {
1229 threads = shmat(shm_id, NULL, 0);
1230 if (threads == (void *) -1) {
1240 * Copy the fio options into the long options map, so we mirror
1241 * job and cmd line options.
1243 static void dupe_job_options(void)
1245 struct fio_option *o;
1249 while (long_options[i].name)
1254 long_options[i].name = o->name;
1255 long_options[i].val = FIO_GETOPT_JOB;
1256 if (o->type == FIO_OPT_STR_SET)
1257 long_options[i].has_arg = no_argument;
1259 long_options[i].has_arg = required_argument;
1263 assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS);
1267 int parse_options(int argc, char *argv[])
1276 if (setup_thread_area())
1278 if (fill_def_thread())
1281 job_files = parse_cmd_line(argc, argv);
1283 for (i = 0; i < job_files; i++) {
1284 if (fill_def_thread())
1286 if (parse_jobs_ini(ini_file[i], i))
1293 if (!thread_number) {
1294 log_err("No jobs defined(s)\n");