Add cpus_allowed option
[fio.git] / options.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <ctype.h>
5 #include <string.h>
6 #include <getopt.h>
7 #include <assert.h>
8
9 #include "fio.h"
10 #include "parse.h"
11
12 #define td_var_offset(var)      ((size_t) &((struct thread_options *)0)->var)
13
14 /*
15  * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
16  */
17 static char *get_opt_postfix(const char *str)
18 {
19         char *p = strstr(str, ":");
20
21         if (!p)
22                 return NULL;
23
24         p++;
25         strip_blank_front(&p);
26         strip_blank_end(p);
27         return strdup(p);
28 }
29
30 static int str_rw_cb(void *data, const char *str)
31 {
32         struct thread_data *td = data;
33         char *nr = get_opt_postfix(str);
34
35         td->o.ddir_nr = 1;
36         if (nr)
37                 td->o.ddir_nr = atoi(nr);
38
39         return 0;
40 }
41
42 static int str_mem_cb(void *data, const char *mem)
43 {
44         struct thread_data *td = data;
45
46         if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
47                 td->mmapfile = get_opt_postfix(mem);
48                 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
49                         log_err("fio: mmaphuge:/path/to/file\n");
50                         return 1;
51                 }
52         }
53
54         return 0;
55 }
56
57 static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
58 {
59         mlock_size = *val;
60         return 0;
61 }
62
63 #ifdef FIO_HAVE_IOPRIO
64 static int str_prioclass_cb(void *data, unsigned int *val)
65 {
66         struct thread_data *td = data;
67         unsigned short mask;
68
69         /*
70          * mask off old class bits, str_prio_cb() may have set a default class
71          */
72         mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
73         td->ioprio &= mask;
74
75         td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
76         return 0;
77 }
78
79 static int str_prio_cb(void *data, unsigned int *val)
80 {
81         struct thread_data *td = data;
82
83         td->ioprio |= *val;
84
85         /*
86          * If no class is set, assume BE
87          */
88         if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
89                 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
90
91         return 0;
92 }
93 #endif
94
95 static int str_exitall_cb(void)
96 {
97         exitall_on_terminate = 1;
98         return 0;
99 }
100
101 #ifdef FIO_HAVE_CPU_AFFINITY
102 static int str_cpumask_cb(void *data, unsigned int *val)
103 {
104         struct thread_data *td = data;
105         unsigned int i;
106
107         CPU_ZERO(&td->o.cpumask);
108
109         for (i = 0; i < sizeof(int) * 8; i++)
110                 if ((1 << i) & *val)
111                         CPU_SET(*val, &td->o.cpumask);
112
113         td->o.cpumask_set = 1;
114         return 0;
115 }
116
117 static int str_cpus_allowed_cb(void *data, const char *input)
118 {
119         struct thread_data *td = data;
120         char *cpu, *str, *p;
121
122         CPU_ZERO(&td->o.cpumask);
123
124         p = str = strdup(input);
125
126         strip_blank_front(&str);
127         strip_blank_end(str);
128
129         while ((cpu = strsep(&str, ",")) != NULL) {
130                 if (!strlen(cpu))
131                         break;
132                 CPU_SET(atoi(cpu), &td->o.cpumask);
133         }
134
135         free(p);
136         td->o.cpumask_set = 1;
137         exit(0);
138         return 0;
139 }
140 #endif
141
142 static int str_fst_cb(void *data, const char *str)
143 {
144         struct thread_data *td = data;
145         char *nr = get_opt_postfix(str);
146
147         td->file_service_nr = 1;
148         if (nr)
149                 td->file_service_nr = atoi(nr);
150
151         return 0;
152 }
153
154 static int str_filename_cb(void *data, const char *input)
155 {
156         struct thread_data *td = data;
157         char *fname, *str, *p;
158
159         p = str = strdup(input);
160
161         strip_blank_front(&str);
162         strip_blank_end(str);
163
164         if (!td->files_index)
165                 td->o.nr_files = 0;
166
167         while ((fname = strsep(&str, ":")) != NULL) {
168                 if (!strlen(fname))
169                         break;
170                 add_file(td, fname);
171                 td->o.nr_files++;
172         }
173
174         free(p);
175         return 0;
176 }
177
178 static int str_directory_cb(void *data, const char fio_unused *str)
179 {
180         struct thread_data *td = data;
181         struct stat sb;
182
183         if (lstat(td->o.directory, &sb) < 0) {
184                 log_err("fio: %s is not a directory\n", td->o.directory);
185                 td_verror(td, errno, "lstat");
186                 return 1;
187         }
188         if (!S_ISDIR(sb.st_mode)) {
189                 log_err("fio: %s is not a directory\n", td->o.directory);
190                 return 1;
191         }
192
193         return 0;
194 }
195
196 static int str_opendir_cb(void *data, const char fio_unused *str)
197 {
198         struct thread_data *td = data;
199
200         if (!td->files_index)
201                 td->o.nr_files = 0;
202
203         return add_dir_files(td, td->o.opendir);
204 }
205
206
207 #define __stringify_1(x)        #x
208 #define __stringify(x)          __stringify_1(x)
209
210 /*
211  * Map of job/command line options
212  */
213 static struct fio_option options[] = {
214         {
215                 .name   = "description",
216                 .type   = FIO_OPT_STR_STORE,
217                 .off1   = td_var_offset(description),
218                 .help   = "Text job description",
219         },
220         {
221                 .name   = "name",
222                 .type   = FIO_OPT_STR_STORE,
223                 .off1   = td_var_offset(name),
224                 .help   = "Name of this job",
225         },
226         {
227                 .name   = "directory",
228                 .type   = FIO_OPT_STR_STORE,
229                 .off1   = td_var_offset(directory),
230                 .cb     = str_directory_cb,
231                 .help   = "Directory to store files in",
232         },
233         {
234                 .name   = "filename",
235                 .type   = FIO_OPT_STR_STORE,
236                 .off1   = td_var_offset(filename),
237                 .cb     = str_filename_cb,
238                 .help   = "File(s) to use for the workload",
239         },
240         {
241                 .name   = "opendir",
242                 .type   = FIO_OPT_STR_STORE,
243                 .off1   = td_var_offset(opendir),
244                 .cb     = str_opendir_cb,
245                 .help   = "Recursively add files from this directory and down",
246         },
247         {
248                 .name   = "rw",
249                 .alias  = "readwrite",
250                 .type   = FIO_OPT_STR,
251                 .cb     = str_rw_cb,
252                 .off1   = td_var_offset(td_ddir),
253                 .help   = "IO direction",
254                 .def    = "read",
255                 .posval = {
256                           { .ival = "read",
257                             .oval = TD_DDIR_READ,
258                             .help = "Sequential read",
259                           },
260                           { .ival = "write",
261                             .oval = TD_DDIR_WRITE,
262                             .help = "Sequential write",
263                           },
264                           { .ival = "randread",
265                             .oval = TD_DDIR_RANDREAD,
266                             .help = "Random read",
267                           },
268                           { .ival = "randwrite",
269                             .oval = TD_DDIR_RANDWRITE,
270                             .help = "Random write",
271                           },
272                           { .ival = "rw",
273                             .oval = TD_DDIR_RW,
274                             .help = "Sequential read and write mix",
275                           },
276                           { .ival = "randrw",
277                             .oval = TD_DDIR_RANDRW,
278                             .help = "Random read and write mix"
279                           },
280                 },
281         },
282         {
283                 .name   = "fadvise_hint",
284                 .type   = FIO_OPT_BOOL,
285                 .off1   = td_var_offset(fadvise_hint),
286                 .help   = "Use fadvise() to advise the kernel on IO pattern",
287                 .def    = "1",
288         },
289         {
290                 .name   = "ioengine",
291                 .type   = FIO_OPT_STR_STORE,
292                 .off1   = td_var_offset(ioengine),
293                 .help   = "IO engine to use",
294                 .def    = "sync",
295                 .posval = {
296                           { .ival = "sync",
297                             .help = "Use read/write",
298                           },
299 #ifdef FIO_HAVE_LIBAIO
300                           { .ival = "libaio",
301                             .help = "Linux native asynchronous IO",
302                           },
303 #endif
304 #ifdef FIO_HAVE_POSIXAIO
305                           { .ival = "posixaio",
306                             .help = "POSIX asynchronous IO",
307                           },
308 #endif
309                           { .ival = "mmap",
310                             .help = "Memory mapped IO",
311                           },
312 #ifdef FIO_HAVE_SPLICE
313                           { .ival = "splice",
314                             .help = "splice/vmsplice based IO",
315                           },
316 #endif
317 #ifdef FIO_HAVE_SGIO
318                           { .ival = "sg",
319                             .help = "SCSI generic v3 IO",
320                           },
321 #endif
322                           { .ival = "null",
323                             .help = "Testing engine (no data transfer)",
324                           },
325                           { .ival = "net",
326                             .help = "Network IO",
327                           },
328 #ifdef FIO_HAVE_SYSLET
329                           { .ival = "syslet-rw",
330                             .help = "syslet enabled async pread/pwrite IO",
331                           },
332 #endif
333                           { .ival = "cpuio",
334                             .help = "CPU cycler burner engine",
335                           },
336 #ifdef FIO_HAVE_GUASI
337                           { .ival = "guasi",
338                             .help = "GUASI IO engine",
339                           },
340 #endif
341                           { .ival = "external",
342                             .help = "Load external engine (append name)",
343                           },
344                 },
345         },
346         {
347                 .name   = "iodepth",
348                 .type   = FIO_OPT_INT,
349                 .off1   = td_var_offset(iodepth),
350                 .help   = "Amount of IO buffers to keep in flight",
351                 .def    = "1",
352         },
353         {
354                 .name   = "iodepth_batch",
355                 .type   = FIO_OPT_INT,
356                 .off1   = td_var_offset(iodepth_batch),
357                 .help   = "Number of IO to submit in one go",
358         },
359         {
360                 .name   = "iodepth_low",
361                 .type   = FIO_OPT_INT,
362                 .off1   = td_var_offset(iodepth_low),
363                 .help   = "Low water mark for queuing depth",
364         },
365         {
366                 .name   = "size",
367                 .type   = FIO_OPT_STR_VAL,
368                 .off1   = td_var_offset(size),
369                 .help   = "Total size of device or files",
370         },
371         {
372                 .name   = "filesize",
373                 .type   = FIO_OPT_STR_VAL,
374                 .off1   = td_var_offset(file_size_low),
375                 .off2   = td_var_offset(file_size_high),
376                 .help   = "Size of individual files",
377         },
378         {
379                 .name   = "bs",
380                 .alias  = "blocksize",
381                 .type   = FIO_OPT_STR_VAL_INT,
382                 .off1   = td_var_offset(bs[DDIR_READ]),
383                 .off2   = td_var_offset(bs[DDIR_WRITE]),
384                 .help   = "Block size unit",
385                 .def    = "4k",
386         },
387         {
388                 .name   = "bsrange",
389                 .alias  = "blocksize_range",
390                 .type   = FIO_OPT_RANGE,
391                 .off1   = td_var_offset(min_bs[DDIR_READ]),
392                 .off2   = td_var_offset(max_bs[DDIR_READ]),
393                 .off3   = td_var_offset(min_bs[DDIR_WRITE]),
394                 .off4   = td_var_offset(max_bs[DDIR_WRITE]),
395                 .help   = "Set block size range (in more detail than bs)",
396         },
397         {
398                 .name   = "bs_unaligned",
399                 .alias  = "blocksize_unaligned",
400                 .type   = FIO_OPT_STR_SET,
401                 .off1   = td_var_offset(bs_unaligned),
402                 .help   = "Don't sector align IO buffer sizes",
403         },
404         {
405                 .name   = "offset",
406                 .type   = FIO_OPT_STR_VAL,
407                 .off1   = td_var_offset(start_offset),
408                 .help   = "Start IO from this offset",
409                 .def    = "0",
410         },
411         {
412                 .name   = "randrepeat",
413                 .type   = FIO_OPT_BOOL,
414                 .off1   = td_var_offset(rand_repeatable),
415                 .help   = "Use repeatable random IO pattern",
416                 .def    = "1",
417         },
418         {
419                 .name   = "norandommap",
420                 .type   = FIO_OPT_STR_SET,
421                 .off1   = td_var_offset(norandommap),
422                 .help   = "Accept potential duplicate random blocks",
423         },
424         {
425                 .name   = "nrfiles",
426                 .type   = FIO_OPT_INT,
427                 .off1   = td_var_offset(nr_files),
428                 .help   = "Split job workload between this number of files",
429                 .def    = "1",
430         },
431         {
432                 .name   = "openfiles",
433                 .type   = FIO_OPT_INT,
434                 .off1   = td_var_offset(open_files),
435                 .help   = "Number of files to keep open at the same time",
436         },
437         {
438                 .name   = "file_service_type",
439                 .type   = FIO_OPT_STR,
440                 .cb     = str_fst_cb,
441                 .off1   = td_var_offset(file_service_type),
442                 .help   = "How to select which file to service next",
443                 .def    = "roundrobin",
444                 .posval = {
445                           { .ival = "random",
446                             .oval = FIO_FSERVICE_RANDOM,
447                             .help = "Choose a file at random",
448                           },
449                           { .ival = "roundrobin",
450                             .oval = FIO_FSERVICE_RR,
451                             .help = "Round robin select files",
452                           },
453                 },
454         },
455         {
456                 .name   = "fsync",
457                 .type   = FIO_OPT_INT,
458                 .off1   = td_var_offset(fsync_blocks),
459                 .help   = "Issue fsync for writes every given number of blocks",
460                 .def    = "0",
461         },
462         {
463                 .name   = "direct",
464                 .type   = FIO_OPT_BOOL,
465                 .off1   = td_var_offset(odirect),
466                 .help   = "Use O_DIRECT IO (negates buffered)",
467                 .def    = "0",
468         },
469         {
470                 .name   = "buffered",
471                 .type   = FIO_OPT_BOOL,
472                 .off1   = td_var_offset(odirect),
473                 .neg    = 1,
474                 .help   = "Use buffered IO (negates direct)",
475                 .def    = "1",
476         },
477         {
478                 .name   = "overwrite",
479                 .type   = FIO_OPT_BOOL,
480                 .off1   = td_var_offset(overwrite),
481                 .help   = "When writing, set whether to overwrite current data",
482                 .def    = "0",
483         },
484         {
485                 .name   = "loops",
486                 .type   = FIO_OPT_INT,
487                 .off1   = td_var_offset(loops),
488                 .help   = "Number of times to run the job",
489                 .def    = "1",
490         },
491         {
492                 .name   = "numjobs",
493                 .type   = FIO_OPT_INT,
494                 .off1   = td_var_offset(numjobs),
495                 .help   = "Duplicate this job this many times",
496                 .def    = "1",
497         },
498         {
499                 .name   = "startdelay",
500                 .type   = FIO_OPT_INT,
501                 .off1   = td_var_offset(start_delay),
502                 .help   = "Only start job when this period has passed",
503                 .def    = "0",
504         },
505         {
506                 .name   = "runtime",
507                 .alias  = "timeout",
508                 .type   = FIO_OPT_STR_VAL_TIME,
509                 .off1   = td_var_offset(timeout),
510                 .help   = "Stop workload when this amount of time has passed",
511                 .def    = "0",
512         },
513         {
514                 .name   = "time_based",
515                 .type   = FIO_OPT_STR_SET,
516                 .off1   = td_var_offset(time_based),
517                 .help   = "Keep running until runtime/timeout is met",
518         },
519         {
520                 .name   = "mem",
521                 .alias  = "iomem",
522                 .type   = FIO_OPT_STR,
523                 .cb     = str_mem_cb,
524                 .off1   = td_var_offset(mem_type),
525                 .help   = "Backing type for IO buffers",
526                 .def    = "malloc",
527                 .posval = {
528                           { .ival = "malloc",
529                             .oval = MEM_MALLOC,
530                             .help = "Use malloc(3) for IO buffers",
531                           },
532                           { .ival = "shm",
533                             .oval = MEM_SHM,
534                             .help = "Use shared memory segments for IO buffers",
535                           },
536 #ifdef FIO_HAVE_HUGETLB
537                           { .ival = "shmhuge",
538                             .oval = MEM_SHMHUGE,
539                             .help = "Like shm, but use huge pages",
540                           },
541 #endif
542                           { .ival = "mmap",
543                             .oval = MEM_MMAP,
544                             .help = "Use mmap(2) (file or anon) for IO buffers",
545                           },
546 #ifdef FIO_HAVE_HUGETLB
547                           { .ival = "mmaphuge",
548                             .oval = MEM_MMAPHUGE,
549                             .help = "Like mmap, but use huge pages",
550                           },
551 #endif
552                   },
553         },
554         {
555                 .name   = "verify",
556                 .type   = FIO_OPT_STR,
557                 .off1   = td_var_offset(verify),
558                 .help   = "Verify data written",
559                 .def    = "0",
560                 .posval = {
561                           { .ival = "0",
562                             .oval = VERIFY_NONE,
563                             .help = "Don't do IO verification",
564                           },
565                           { .ival = "crc32",
566                             .oval = VERIFY_CRC32,
567                             .help = "Use crc32 checksums for verification",
568                           },
569                           { .ival = "md5",
570                             .oval = VERIFY_MD5,
571                             .help = "Use md5 checksums for verification",
572                           },
573                           {
574                             .ival = "null",
575                             .oval = VERIFY_NULL,
576                             .help = "Pretend to verify",
577                           },
578                 },
579         },
580         {
581                 .name   = "verifysort",
582                 .type   = FIO_OPT_BOOL,
583                 .off1   = td_var_offset(verifysort),
584                 .help   = "Sort written verify blocks for read back",
585                 .def    = "1",
586         },
587         {
588                 .name   = "write_iolog",
589                 .type   = FIO_OPT_STR_STORE,
590                 .off1   = td_var_offset(write_iolog_file),
591                 .help   = "Store IO pattern to file",
592         },
593         {
594                 .name   = "read_iolog",
595                 .type   = FIO_OPT_STR_STORE,
596                 .off1   = td_var_offset(read_iolog_file),
597                 .help   = "Playback IO pattern from file",
598         },
599         {
600                 .name   = "exec_prerun",
601                 .type   = FIO_OPT_STR_STORE,
602                 .off1   = td_var_offset(exec_prerun),
603                 .help   = "Execute this file prior to running job",
604         },
605         {
606                 .name   = "exec_postrun",
607                 .type   = FIO_OPT_STR_STORE,
608                 .off1   = td_var_offset(exec_postrun),
609                 .help   = "Execute this file after running job",
610         },
611 #ifdef FIO_HAVE_IOSCHED_SWITCH
612         {
613                 .name   = "ioscheduler",
614                 .type   = FIO_OPT_STR_STORE,
615                 .off1   = td_var_offset(ioscheduler),
616                 .help   = "Use this IO scheduler on the backing device",
617         },
618 #endif
619         {
620                 .name   = "zonesize",
621                 .type   = FIO_OPT_STR_VAL,
622                 .off1   = td_var_offset(zone_size),
623                 .help   = "Give size of an IO zone",
624                 .def    = "0",
625         },
626         {
627                 .name   = "zoneskip",
628                 .type   = FIO_OPT_STR_VAL,
629                 .off1   = td_var_offset(zone_skip),
630                 .help   = "Space between IO zones",
631                 .def    = "0",
632         },
633         {
634                 .name   = "lockmem",
635                 .type   = FIO_OPT_STR_VAL,
636                 .cb     = str_lockmem_cb,
637                 .help   = "Lock down this amount of memory",
638                 .def    = "0",
639         },
640         {
641                 .name   = "rwmixcycle",
642                 .type   = FIO_OPT_INT,
643                 .off1   = td_var_offset(rwmixcycle),
644                 .help   = "Cycle period for mixed read/write workloads (msec)",
645                 .def    = "500",
646         },
647         {
648                 .name   = "rwmixread",
649                 .type   = FIO_OPT_INT,
650                 .off1   = td_var_offset(rwmix[DDIR_READ]),
651                 .maxval = 100,
652                 .help   = "Percentage of mixed workload that is reads",
653                 .def    = "50",
654         },
655         {
656                 .name   = "rwmixwrite",
657                 .type   = FIO_OPT_INT,
658                 .off1   = td_var_offset(rwmix[DDIR_WRITE]),
659                 .maxval = 100,
660                 .help   = "Percentage of mixed workload that is writes",
661                 .def    = "50",
662         },
663         {
664                 .name   = "nice",
665                 .type   = FIO_OPT_INT,
666                 .off1   = td_var_offset(nice),
667                 .help   = "Set job CPU nice value",
668                 .minval = -19,
669                 .maxval = 20,
670                 .def    = "0",
671         },
672 #ifdef FIO_HAVE_IOPRIO
673         {
674                 .name   = "prio",
675                 .type   = FIO_OPT_INT,
676                 .cb     = str_prio_cb,
677                 .help   = "Set job IO priority value",
678                 .minval = 0,
679                 .maxval = 7,
680         },
681         {
682                 .name   = "prioclass",
683                 .type   = FIO_OPT_INT,
684                 .cb     = str_prioclass_cb,
685                 .help   = "Set job IO priority class",
686                 .minval = 0,
687                 .maxval = 3,
688         },
689 #endif
690         {
691                 .name   = "thinktime",
692                 .type   = FIO_OPT_INT,
693                 .off1   = td_var_offset(thinktime),
694                 .help   = "Idle time between IO buffers (usec)",
695                 .def    = "0",
696         },
697         {
698                 .name   = "thinktime_spin",
699                 .type   = FIO_OPT_INT,
700                 .off1   = td_var_offset(thinktime_spin),
701                 .help   = "Start think time by spinning this amount (usec)",
702                 .def    = "0",
703         },
704         {
705                 .name   = "thinktime_blocks",
706                 .type   = FIO_OPT_INT,
707                 .off1   = td_var_offset(thinktime_blocks),
708                 .help   = "IO buffer period between 'thinktime'",
709                 .def    = "1",
710         },
711         {
712                 .name   = "rate",
713                 .type   = FIO_OPT_INT,
714                 .off1   = td_var_offset(rate),
715                 .help   = "Set bandwidth rate",
716         },
717         {
718                 .name   = "ratemin",
719                 .type   = FIO_OPT_INT,
720                 .off1   = td_var_offset(ratemin),
721                 .help   = "Job must meet this rate or it will be shutdown",
722         },
723         {
724                 .name   = "rate_iops",
725                 .type   = FIO_OPT_INT,
726                 .off1   = td_var_offset(rate_iops),
727                 .help   = "Limit IO used to this number of IO operations/sec",
728         },
729         {
730                 .name   = "rate_iops_min",
731                 .type   = FIO_OPT_INT,
732                 .off1   = td_var_offset(rate_iops_min),
733                 .help   = "Job must meet this rate or it will be shutdown",
734         },
735         {
736                 .name   = "ratecycle",
737                 .type   = FIO_OPT_INT,
738                 .off1   = td_var_offset(ratecycle),
739                 .help   = "Window average for rate limits (msec)",
740                 .def    = "1000",
741         },
742         {
743                 .name   = "invalidate",
744                 .type   = FIO_OPT_BOOL,
745                 .off1   = td_var_offset(invalidate_cache),
746                 .help   = "Invalidate buffer/page cache prior to running job",
747                 .def    = "1",
748         },
749         {
750                 .name   = "sync",
751                 .type   = FIO_OPT_BOOL,
752                 .off1   = td_var_offset(sync_io),
753                 .help   = "Use O_SYNC for buffered writes",
754                 .def    = "0",
755         },
756         {
757                 .name   = "bwavgtime",
758                 .type   = FIO_OPT_INT,
759                 .off1   = td_var_offset(bw_avg_time),
760                 .help   = "Time window over which to calculate bandwidth (msec)",
761                 .def    = "500",
762         },
763         {
764                 .name   = "create_serialize",
765                 .type   = FIO_OPT_BOOL,
766                 .off1   = td_var_offset(create_serialize),
767                 .help   = "Serialize creating of job files",
768                 .def    = "1",
769         },
770         {
771                 .name   = "create_fsync",
772                 .type   = FIO_OPT_BOOL,
773                 .off1   = td_var_offset(create_fsync),
774                 .help   = "Fsync file after creation",
775                 .def    = "1",
776         },
777         {
778                 .name   = "cpuload",
779                 .type   = FIO_OPT_INT,
780                 .off1   = td_var_offset(cpuload),
781                 .help   = "Use this percentage of CPU",
782         },
783         {
784                 .name   = "cpuchunks",
785                 .type   = FIO_OPT_INT,
786                 .off1   = td_var_offset(cpucycle),
787                 .help   = "Length of the CPU burn cycles (usecs)",
788                 .def    = "50000",
789         },
790 #ifdef FIO_HAVE_CPU_AFFINITY
791         {
792                 .name   = "cpumask",
793                 .type   = FIO_OPT_INT,
794                 .cb     = str_cpumask_cb,
795                 .help   = "CPU affinity mask",
796         },
797         {
798                 .name   = "cpus_allowed",
799                 .type   = FIO_OPT_STR,
800                 .cb     = str_cpus_allowed_cb,
801                 .help   = "Set CPUs allowed",
802         },
803 #endif
804         {
805                 .name   = "end_fsync",
806                 .type   = FIO_OPT_BOOL,
807                 .off1   = td_var_offset(end_fsync),
808                 .help   = "Include fsync at the end of job",
809                 .def    = "0",
810         },
811         {
812                 .name   = "fsync_on_close",
813                 .type   = FIO_OPT_BOOL,
814                 .off1   = td_var_offset(fsync_on_close),
815                 .help   = "fsync files on close",
816                 .def    = "0",
817         },
818         {
819                 .name   = "unlink",
820                 .type   = FIO_OPT_BOOL,
821                 .off1   = td_var_offset(unlink),
822                 .help   = "Unlink created files after job has completed",
823                 .def    = "0",
824         },
825         {
826                 .name   = "exitall",
827                 .type   = FIO_OPT_STR_SET,
828                 .cb     = str_exitall_cb,
829                 .help   = "Terminate all jobs when one exits",
830         },
831         {
832                 .name   = "stonewall",
833                 .type   = FIO_OPT_STR_SET,
834                 .off1   = td_var_offset(stonewall),
835                 .help   = "Insert a hard barrier between this job and previous",
836         },
837         {
838                 .name   = "new_group",
839                 .type   = FIO_OPT_STR_SET,
840                 .off1   = td_var_offset(new_group),
841                 .help   = "Mark the start of a new group (for reporting)",
842         },
843         {
844                 .name   = "thread",
845                 .type   = FIO_OPT_STR_SET,
846                 .off1   = td_var_offset(use_thread),
847                 .help   = "Use threads instead of forks",
848         },
849         {
850                 .name   = "write_bw_log",
851                 .type   = FIO_OPT_STR_SET,
852                 .off1   = td_var_offset(write_bw_log),
853                 .help   = "Write log of bandwidth during run",
854         },
855         {
856                 .name   = "write_lat_log",
857                 .type   = FIO_OPT_STR_SET,
858                 .off1   = td_var_offset(write_lat_log),
859                 .help   = "Write log of latency during run",
860         },
861         {
862                 .name   = "hugepage-size",
863                 .type   = FIO_OPT_STR_VAL,
864                 .off1   = td_var_offset(hugepage_size),
865                 .help   = "When using hugepages, specify size of each page",
866                 .def    = __stringify(FIO_HUGE_PAGE),
867         },
868         {
869                 .name   = "group_reporting",
870                 .type   = FIO_OPT_STR_SET,
871                 .off1   = td_var_offset(group_reporting),
872                 .help   = "Do reporting on a per-group basis",
873         },
874         {
875                 .name   = "zero_buffers",
876                 .type   = FIO_OPT_STR_SET,
877                 .off1   = td_var_offset(zero_buffers),
878                 .help   = "Init IO buffers to all zeroes",
879         },
880 #ifdef FIO_HAVE_DISK_UTIL
881         {
882                 .name   = "disk_util",
883                 .type   = FIO_OPT_BOOL,
884                 .off1   = td_var_offset(do_disk_util),
885                 .help   = "Log disk utilization stats",
886                 .def    = "1",
887         },
888 #endif
889         {
890                 .name = NULL,
891         },
892 };
893
894 void fio_options_dup_and_init(struct option *long_options)
895 {
896         struct fio_option *o;
897         unsigned int i;
898
899         options_init(options);
900
901         i = 0;
902         while (long_options[i].name)
903                 i++;
904
905         o = &options[0];
906         while (o->name) {
907                 long_options[i].name = o->name;
908                 long_options[i].val = FIO_GETOPT_JOB;
909                 if (o->type == FIO_OPT_STR_SET)
910                         long_options[i].has_arg = no_argument;
911                 else
912                         long_options[i].has_arg = required_argument;
913
914                 i++;
915                 o++;
916                 assert(i < FIO_NR_OPTIONS);
917         }
918 }
919
920 int fio_option_parse(struct thread_data *td, const char *opt)
921 {
922         return parse_option(opt, options, td);
923 }
924
925 int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
926 {
927         return parse_cmd_option(opt, val, options, td);
928 }
929
930 void fio_fill_default_options(struct thread_data *td)
931 {
932         fill_default_options(td, options);
933 }
934
935 int fio_show_option_help(const char *opt)
936 {
937         return show_cmd_help(options, opt);
938 }
939
940 static void __options_mem(struct thread_data *td, int alloc)
941 {
942         struct thread_options *o = &td->o;
943         struct fio_option *opt;
944         char **ptr;
945         int i;
946
947         for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
948                 if (opt->type != FIO_OPT_STR_STORE)
949                         continue;
950
951                 ptr = (void *) o + opt->off1;
952                 if (*ptr) {
953                         if (alloc)
954                                 *ptr = strdup(*ptr);
955                         else {
956                                 free(*ptr);
957                                 *ptr = NULL;
958                         }
959                 }
960         }
961 }
962
963 /*
964  * dupe FIO_OPT_STR_STORE options
965  */
966 void options_mem_dupe(struct thread_data *td)
967 {
968         __options_mem(td, 1);
969 }
970
971 void options_mem_free(struct thread_data fio_unused *td)
972 {
973 #if 0
974         __options_mem(td, 0);
975 #endif
976 }