Commit | Line | Data |
---|---|---|
214e1eca JA |
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 | ||
2dc1bbeb | 12 | #define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var) |
214e1eca JA |
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 | ||
211097b2 JA |
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 | ||
fafdba3c | 35 | td->o.ddir_nr = 1; |
211097b2 JA |
36 | if (nr) |
37 | td->o.ddir_nr = atoi(nr); | |
38 | ||
211097b2 JA |
39 | return 0; |
40 | } | |
41 | ||
214e1eca JA |
42 | static int str_mem_cb(void *data, const char *mem) |
43 | { | |
44 | struct thread_data *td = data; | |
45 | ||
2dc1bbeb | 46 | if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) { |
214e1eca | 47 | td->mmapfile = get_opt_postfix(mem); |
2dc1bbeb | 48 | if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) { |
214e1eca JA |
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; | |
6cefbe33 JA |
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; | |
214e1eca JA |
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; | |
6cefbe33 JA |
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 | ||
214e1eca JA |
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 | ||
214e1eca | 101 | #ifdef FIO_HAVE_CPU_AFFINITY |
d2e268b0 JA |
102 | static int str_cpumask_cb(void *data, unsigned int *val) |
103 | { | |
104 | struct thread_data *td = data; | |
214e1eca JA |
105 | unsigned int i; |
106 | ||
d2e268b0 | 107 | CPU_ZERO(&td->o.cpumask); |
214e1eca | 108 | |
e600f7f1 | 109 | for (i = 0; i < sizeof(int) * 8; i++) |
d2e268b0 JA |
110 | if ((1 << i) & *val) |
111 | CPU_SET(*val, &td->o.cpumask); | |
112 | ||
113 | td->o.cpumask_set = 1; | |
114 | return 0; | |
214e1eca JA |
115 | } |
116 | ||
d2e268b0 | 117 | static int str_cpus_allowed_cb(void *data, const char *input) |
214e1eca JA |
118 | { |
119 | struct thread_data *td = data; | |
d2e268b0 JA |
120 | char *cpu, *str, *p; |
121 | ||
122 | CPU_ZERO(&td->o.cpumask); | |
123 | ||
124 | p = str = strdup(input); | |
214e1eca | 125 | |
d2e268b0 JA |
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); | |
375b2695 | 136 | td->o.cpumask_set = 1; |
d2e268b0 | 137 | exit(0); |
214e1eca JA |
138 | return 0; |
139 | } | |
d2e268b0 | 140 | #endif |
214e1eca JA |
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) | |
2dc1bbeb | 165 | td->o.nr_files = 0; |
214e1eca JA |
166 | |
167 | while ((fname = strsep(&str, ":")) != NULL) { | |
168 | if (!strlen(fname)) | |
169 | break; | |
170 | add_file(td, fname); | |
2dc1bbeb | 171 | td->o.nr_files++; |
214e1eca JA |
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 | ||
2dc1bbeb JA |
183 | if (lstat(td->o.directory, &sb) < 0) { |
184 | log_err("fio: %s is not a directory\n", td->o.directory); | |
214e1eca JA |
185 | td_verror(td, errno, "lstat"); |
186 | return 1; | |
187 | } | |
188 | if (!S_ISDIR(sb.st_mode)) { | |
2dc1bbeb | 189 | log_err("fio: %s is not a directory\n", td->o.directory); |
214e1eca JA |
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) | |
2dc1bbeb | 201 | td->o.nr_files = 0; |
214e1eca | 202 | |
2dc1bbeb | 203 | return add_dir_files(td, td->o.opendir); |
214e1eca JA |
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", | |
d3aad8f2 | 249 | .alias = "readwrite", |
214e1eca | 250 | .type = FIO_OPT_STR, |
211097b2 | 251 | .cb = str_rw_cb, |
214e1eca JA |
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 | }, | |
d2f3ac35 JA |
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 | }, | |
214e1eca JA |
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 | }, | |
9cce02e8 JA |
316 | { .ival = "netsplice", |
317 | .help = "splice/vmsplice to/from the network", | |
318 | }, | |
214e1eca JA |
319 | #endif |
320 | #ifdef FIO_HAVE_SGIO | |
321 | { .ival = "sg", | |
322 | .help = "SCSI generic v3 IO", | |
323 | }, | |
324 | #endif | |
325 | { .ival = "null", | |
326 | .help = "Testing engine (no data transfer)", | |
327 | }, | |
328 | { .ival = "net", | |
329 | .help = "Network IO", | |
330 | }, | |
331 | #ifdef FIO_HAVE_SYSLET | |
332 | { .ival = "syslet-rw", | |
333 | .help = "syslet enabled async pread/pwrite IO", | |
334 | }, | |
335 | #endif | |
336 | { .ival = "cpuio", | |
337 | .help = "CPU cycler burner engine", | |
338 | }, | |
b8c82a46 JA |
339 | #ifdef FIO_HAVE_GUASI |
340 | { .ival = "guasi", | |
341 | .help = "GUASI IO engine", | |
342 | }, | |
343 | #endif | |
214e1eca JA |
344 | { .ival = "external", |
345 | .help = "Load external engine (append name)", | |
346 | }, | |
347 | }, | |
348 | }, | |
349 | { | |
350 | .name = "iodepth", | |
351 | .type = FIO_OPT_INT, | |
352 | .off1 = td_var_offset(iodepth), | |
353 | .help = "Amount of IO buffers to keep in flight", | |
354 | .def = "1", | |
355 | }, | |
356 | { | |
357 | .name = "iodepth_batch", | |
358 | .type = FIO_OPT_INT, | |
359 | .off1 = td_var_offset(iodepth_batch), | |
360 | .help = "Number of IO to submit in one go", | |
361 | }, | |
362 | { | |
363 | .name = "iodepth_low", | |
364 | .type = FIO_OPT_INT, | |
365 | .off1 = td_var_offset(iodepth_low), | |
366 | .help = "Low water mark for queuing depth", | |
367 | }, | |
368 | { | |
369 | .name = "size", | |
370 | .type = FIO_OPT_STR_VAL, | |
2dc1bbeb | 371 | .off1 = td_var_offset(size), |
c3edbdba | 372 | .minval = 1, |
214e1eca JA |
373 | .help = "Total size of device or files", |
374 | }, | |
375 | { | |
376 | .name = "filesize", | |
377 | .type = FIO_OPT_STR_VAL, | |
378 | .off1 = td_var_offset(file_size_low), | |
379 | .off2 = td_var_offset(file_size_high), | |
c3edbdba | 380 | .minval = 1, |
214e1eca JA |
381 | .help = "Size of individual files", |
382 | }, | |
383 | { | |
384 | .name = "bs", | |
d3aad8f2 | 385 | .alias = "blocksize", |
214e1eca JA |
386 | .type = FIO_OPT_STR_VAL_INT, |
387 | .off1 = td_var_offset(bs[DDIR_READ]), | |
388 | .off2 = td_var_offset(bs[DDIR_WRITE]), | |
c3edbdba | 389 | .minval = 1, |
214e1eca JA |
390 | .help = "Block size unit", |
391 | .def = "4k", | |
392 | }, | |
393 | { | |
394 | .name = "bsrange", | |
d3aad8f2 | 395 | .alias = "blocksize_range", |
214e1eca JA |
396 | .type = FIO_OPT_RANGE, |
397 | .off1 = td_var_offset(min_bs[DDIR_READ]), | |
398 | .off2 = td_var_offset(max_bs[DDIR_READ]), | |
399 | .off3 = td_var_offset(min_bs[DDIR_WRITE]), | |
400 | .off4 = td_var_offset(max_bs[DDIR_WRITE]), | |
c3edbdba | 401 | .minval = 1, |
214e1eca JA |
402 | .help = "Set block size range (in more detail than bs)", |
403 | }, | |
404 | { | |
405 | .name = "bs_unaligned", | |
d3aad8f2 | 406 | .alias = "blocksize_unaligned", |
214e1eca JA |
407 | .type = FIO_OPT_STR_SET, |
408 | .off1 = td_var_offset(bs_unaligned), | |
409 | .help = "Don't sector align IO buffer sizes", | |
410 | }, | |
411 | { | |
412 | .name = "offset", | |
413 | .type = FIO_OPT_STR_VAL, | |
414 | .off1 = td_var_offset(start_offset), | |
415 | .help = "Start IO from this offset", | |
416 | .def = "0", | |
417 | }, | |
418 | { | |
419 | .name = "randrepeat", | |
420 | .type = FIO_OPT_BOOL, | |
421 | .off1 = td_var_offset(rand_repeatable), | |
422 | .help = "Use repeatable random IO pattern", | |
423 | .def = "1", | |
424 | }, | |
425 | { | |
426 | .name = "norandommap", | |
427 | .type = FIO_OPT_STR_SET, | |
428 | .off1 = td_var_offset(norandommap), | |
429 | .help = "Accept potential duplicate random blocks", | |
430 | }, | |
431 | { | |
432 | .name = "nrfiles", | |
433 | .type = FIO_OPT_INT, | |
434 | .off1 = td_var_offset(nr_files), | |
435 | .help = "Split job workload between this number of files", | |
436 | .def = "1", | |
437 | }, | |
438 | { | |
439 | .name = "openfiles", | |
440 | .type = FIO_OPT_INT, | |
441 | .off1 = td_var_offset(open_files), | |
442 | .help = "Number of files to keep open at the same time", | |
443 | }, | |
444 | { | |
445 | .name = "file_service_type", | |
446 | .type = FIO_OPT_STR, | |
447 | .cb = str_fst_cb, | |
448 | .off1 = td_var_offset(file_service_type), | |
449 | .help = "How to select which file to service next", | |
450 | .def = "roundrobin", | |
451 | .posval = { | |
452 | { .ival = "random", | |
453 | .oval = FIO_FSERVICE_RANDOM, | |
454 | .help = "Choose a file at random", | |
455 | }, | |
456 | { .ival = "roundrobin", | |
457 | .oval = FIO_FSERVICE_RR, | |
458 | .help = "Round robin select files", | |
459 | }, | |
460 | }, | |
461 | }, | |
462 | { | |
463 | .name = "fsync", | |
464 | .type = FIO_OPT_INT, | |
465 | .off1 = td_var_offset(fsync_blocks), | |
466 | .help = "Issue fsync for writes every given number of blocks", | |
467 | .def = "0", | |
468 | }, | |
469 | { | |
470 | .name = "direct", | |
471 | .type = FIO_OPT_BOOL, | |
472 | .off1 = td_var_offset(odirect), | |
473 | .help = "Use O_DIRECT IO (negates buffered)", | |
474 | .def = "0", | |
475 | }, | |
476 | { | |
477 | .name = "buffered", | |
478 | .type = FIO_OPT_BOOL, | |
479 | .off1 = td_var_offset(odirect), | |
480 | .neg = 1, | |
481 | .help = "Use buffered IO (negates direct)", | |
482 | .def = "1", | |
483 | }, | |
484 | { | |
485 | .name = "overwrite", | |
486 | .type = FIO_OPT_BOOL, | |
487 | .off1 = td_var_offset(overwrite), | |
488 | .help = "When writing, set whether to overwrite current data", | |
489 | .def = "0", | |
490 | }, | |
491 | { | |
492 | .name = "loops", | |
493 | .type = FIO_OPT_INT, | |
494 | .off1 = td_var_offset(loops), | |
495 | .help = "Number of times to run the job", | |
496 | .def = "1", | |
497 | }, | |
498 | { | |
499 | .name = "numjobs", | |
500 | .type = FIO_OPT_INT, | |
501 | .off1 = td_var_offset(numjobs), | |
502 | .help = "Duplicate this job this many times", | |
503 | .def = "1", | |
504 | }, | |
505 | { | |
506 | .name = "startdelay", | |
507 | .type = FIO_OPT_INT, | |
508 | .off1 = td_var_offset(start_delay), | |
509 | .help = "Only start job when this period has passed", | |
510 | .def = "0", | |
511 | }, | |
512 | { | |
513 | .name = "runtime", | |
514 | .alias = "timeout", | |
515 | .type = FIO_OPT_STR_VAL_TIME, | |
516 | .off1 = td_var_offset(timeout), | |
517 | .help = "Stop workload when this amount of time has passed", | |
518 | .def = "0", | |
519 | }, | |
cf4464ca JA |
520 | { |
521 | .name = "time_based", | |
522 | .type = FIO_OPT_STR_SET, | |
523 | .off1 = td_var_offset(time_based), | |
524 | .help = "Keep running until runtime/timeout is met", | |
525 | }, | |
214e1eca JA |
526 | { |
527 | .name = "mem", | |
d3aad8f2 | 528 | .alias = "iomem", |
214e1eca JA |
529 | .type = FIO_OPT_STR, |
530 | .cb = str_mem_cb, | |
531 | .off1 = td_var_offset(mem_type), | |
532 | .help = "Backing type for IO buffers", | |
533 | .def = "malloc", | |
534 | .posval = { | |
535 | { .ival = "malloc", | |
536 | .oval = MEM_MALLOC, | |
537 | .help = "Use malloc(3) for IO buffers", | |
538 | }, | |
37c8cdfe JA |
539 | { .ival = "shm", |
540 | .oval = MEM_SHM, | |
541 | .help = "Use shared memory segments for IO buffers", | |
542 | }, | |
214e1eca JA |
543 | #ifdef FIO_HAVE_HUGETLB |
544 | { .ival = "shmhuge", | |
545 | .oval = MEM_SHMHUGE, | |
546 | .help = "Like shm, but use huge pages", | |
547 | }, | |
b370e46a | 548 | #endif |
37c8cdfe JA |
549 | { .ival = "mmap", |
550 | .oval = MEM_MMAP, | |
551 | .help = "Use mmap(2) (file or anon) for IO buffers", | |
552 | }, | |
214e1eca JA |
553 | #ifdef FIO_HAVE_HUGETLB |
554 | { .ival = "mmaphuge", | |
555 | .oval = MEM_MMAPHUGE, | |
556 | .help = "Like mmap, but use huge pages", | |
557 | }, | |
558 | #endif | |
559 | }, | |
560 | }, | |
561 | { | |
562 | .name = "verify", | |
563 | .type = FIO_OPT_STR, | |
564 | .off1 = td_var_offset(verify), | |
565 | .help = "Verify data written", | |
566 | .def = "0", | |
567 | .posval = { | |
568 | { .ival = "0", | |
569 | .oval = VERIFY_NONE, | |
570 | .help = "Don't do IO verification", | |
571 | }, | |
572 | { .ival = "crc32", | |
573 | .oval = VERIFY_CRC32, | |
574 | .help = "Use crc32 checksums for verification", | |
575 | }, | |
576 | { .ival = "md5", | |
577 | .oval = VERIFY_MD5, | |
578 | .help = "Use md5 checksums for verification", | |
579 | }, | |
36690c9b JA |
580 | { |
581 | .ival = "null", | |
582 | .oval = VERIFY_NULL, | |
583 | .help = "Pretend to verify", | |
584 | }, | |
214e1eca JA |
585 | }, |
586 | }, | |
160b966d JA |
587 | { |
588 | .name = "verifysort", | |
589 | .type = FIO_OPT_BOOL, | |
590 | .off1 = td_var_offset(verifysort), | |
591 | .help = "Sort written verify blocks for read back", | |
592 | .def = "1", | |
593 | }, | |
214e1eca JA |
594 | { |
595 | .name = "write_iolog", | |
596 | .type = FIO_OPT_STR_STORE, | |
597 | .off1 = td_var_offset(write_iolog_file), | |
598 | .help = "Store IO pattern to file", | |
599 | }, | |
600 | { | |
601 | .name = "read_iolog", | |
602 | .type = FIO_OPT_STR_STORE, | |
603 | .off1 = td_var_offset(read_iolog_file), | |
604 | .help = "Playback IO pattern from file", | |
605 | }, | |
606 | { | |
607 | .name = "exec_prerun", | |
608 | .type = FIO_OPT_STR_STORE, | |
609 | .off1 = td_var_offset(exec_prerun), | |
610 | .help = "Execute this file prior to running job", | |
611 | }, | |
612 | { | |
613 | .name = "exec_postrun", | |
614 | .type = FIO_OPT_STR_STORE, | |
615 | .off1 = td_var_offset(exec_postrun), | |
616 | .help = "Execute this file after running job", | |
617 | }, | |
618 | #ifdef FIO_HAVE_IOSCHED_SWITCH | |
619 | { | |
620 | .name = "ioscheduler", | |
621 | .type = FIO_OPT_STR_STORE, | |
622 | .off1 = td_var_offset(ioscheduler), | |
623 | .help = "Use this IO scheduler on the backing device", | |
624 | }, | |
625 | #endif | |
626 | { | |
627 | .name = "zonesize", | |
628 | .type = FIO_OPT_STR_VAL, | |
629 | .off1 = td_var_offset(zone_size), | |
630 | .help = "Give size of an IO zone", | |
631 | .def = "0", | |
632 | }, | |
633 | { | |
634 | .name = "zoneskip", | |
635 | .type = FIO_OPT_STR_VAL, | |
636 | .off1 = td_var_offset(zone_skip), | |
637 | .help = "Space between IO zones", | |
638 | .def = "0", | |
639 | }, | |
640 | { | |
641 | .name = "lockmem", | |
642 | .type = FIO_OPT_STR_VAL, | |
643 | .cb = str_lockmem_cb, | |
644 | .help = "Lock down this amount of memory", | |
645 | .def = "0", | |
646 | }, | |
647 | { | |
648 | .name = "rwmixcycle", | |
649 | .type = FIO_OPT_INT, | |
650 | .off1 = td_var_offset(rwmixcycle), | |
651 | .help = "Cycle period for mixed read/write workloads (msec)", | |
652 | .def = "500", | |
653 | }, | |
654 | { | |
655 | .name = "rwmixread", | |
656 | .type = FIO_OPT_INT, | |
e47f799f | 657 | .off1 = td_var_offset(rwmix[DDIR_READ]), |
214e1eca JA |
658 | .maxval = 100, |
659 | .help = "Percentage of mixed workload that is reads", | |
660 | .def = "50", | |
661 | }, | |
662 | { | |
663 | .name = "rwmixwrite", | |
664 | .type = FIO_OPT_INT, | |
e47f799f | 665 | .off1 = td_var_offset(rwmix[DDIR_WRITE]), |
214e1eca JA |
666 | .maxval = 100, |
667 | .help = "Percentage of mixed workload that is writes", | |
668 | .def = "50", | |
669 | }, | |
670 | { | |
671 | .name = "nice", | |
672 | .type = FIO_OPT_INT, | |
673 | .off1 = td_var_offset(nice), | |
674 | .help = "Set job CPU nice value", | |
675 | .minval = -19, | |
676 | .maxval = 20, | |
677 | .def = "0", | |
678 | }, | |
679 | #ifdef FIO_HAVE_IOPRIO | |
680 | { | |
681 | .name = "prio", | |
682 | .type = FIO_OPT_INT, | |
683 | .cb = str_prio_cb, | |
684 | .help = "Set job IO priority value", | |
685 | .minval = 0, | |
686 | .maxval = 7, | |
687 | }, | |
688 | { | |
689 | .name = "prioclass", | |
690 | .type = FIO_OPT_INT, | |
691 | .cb = str_prioclass_cb, | |
692 | .help = "Set job IO priority class", | |
693 | .minval = 0, | |
694 | .maxval = 3, | |
695 | }, | |
696 | #endif | |
697 | { | |
698 | .name = "thinktime", | |
699 | .type = FIO_OPT_INT, | |
700 | .off1 = td_var_offset(thinktime), | |
701 | .help = "Idle time between IO buffers (usec)", | |
702 | .def = "0", | |
703 | }, | |
704 | { | |
705 | .name = "thinktime_spin", | |
706 | .type = FIO_OPT_INT, | |
707 | .off1 = td_var_offset(thinktime_spin), | |
708 | .help = "Start think time by spinning this amount (usec)", | |
709 | .def = "0", | |
710 | }, | |
711 | { | |
712 | .name = "thinktime_blocks", | |
713 | .type = FIO_OPT_INT, | |
714 | .off1 = td_var_offset(thinktime_blocks), | |
715 | .help = "IO buffer period between 'thinktime'", | |
716 | .def = "1", | |
717 | }, | |
718 | { | |
719 | .name = "rate", | |
720 | .type = FIO_OPT_INT, | |
721 | .off1 = td_var_offset(rate), | |
722 | .help = "Set bandwidth rate", | |
723 | }, | |
724 | { | |
725 | .name = "ratemin", | |
726 | .type = FIO_OPT_INT, | |
727 | .off1 = td_var_offset(ratemin), | |
4e991c23 JA |
728 | .help = "Job must meet this rate or it will be shutdown", |
729 | }, | |
730 | { | |
731 | .name = "rate_iops", | |
732 | .type = FIO_OPT_INT, | |
733 | .off1 = td_var_offset(rate_iops), | |
734 | .help = "Limit IO used to this number of IO operations/sec", | |
735 | }, | |
736 | { | |
737 | .name = "rate_iops_min", | |
738 | .type = FIO_OPT_INT, | |
739 | .off1 = td_var_offset(rate_iops_min), | |
740 | .help = "Job must meet this rate or it will be shutdown", | |
214e1eca JA |
741 | }, |
742 | { | |
743 | .name = "ratecycle", | |
744 | .type = FIO_OPT_INT, | |
745 | .off1 = td_var_offset(ratecycle), | |
746 | .help = "Window average for rate limits (msec)", | |
747 | .def = "1000", | |
748 | }, | |
749 | { | |
750 | .name = "invalidate", | |
751 | .type = FIO_OPT_BOOL, | |
752 | .off1 = td_var_offset(invalidate_cache), | |
753 | .help = "Invalidate buffer/page cache prior to running job", | |
754 | .def = "1", | |
755 | }, | |
756 | { | |
757 | .name = "sync", | |
758 | .type = FIO_OPT_BOOL, | |
759 | .off1 = td_var_offset(sync_io), | |
760 | .help = "Use O_SYNC for buffered writes", | |
761 | .def = "0", | |
762 | }, | |
763 | { | |
764 | .name = "bwavgtime", | |
765 | .type = FIO_OPT_INT, | |
766 | .off1 = td_var_offset(bw_avg_time), | |
767 | .help = "Time window over which to calculate bandwidth (msec)", | |
768 | .def = "500", | |
769 | }, | |
770 | { | |
771 | .name = "create_serialize", | |
772 | .type = FIO_OPT_BOOL, | |
773 | .off1 = td_var_offset(create_serialize), | |
774 | .help = "Serialize creating of job files", | |
775 | .def = "1", | |
776 | }, | |
777 | { | |
778 | .name = "create_fsync", | |
779 | .type = FIO_OPT_BOOL, | |
780 | .off1 = td_var_offset(create_fsync), | |
781 | .help = "Fsync file after creation", | |
782 | .def = "1", | |
783 | }, | |
784 | { | |
785 | .name = "cpuload", | |
786 | .type = FIO_OPT_INT, | |
787 | .off1 = td_var_offset(cpuload), | |
788 | .help = "Use this percentage of CPU", | |
789 | }, | |
790 | { | |
791 | .name = "cpuchunks", | |
792 | .type = FIO_OPT_INT, | |
793 | .off1 = td_var_offset(cpucycle), | |
794 | .help = "Length of the CPU burn cycles (usecs)", | |
795 | .def = "50000", | |
796 | }, | |
797 | #ifdef FIO_HAVE_CPU_AFFINITY | |
798 | { | |
799 | .name = "cpumask", | |
800 | .type = FIO_OPT_INT, | |
801 | .cb = str_cpumask_cb, | |
802 | .help = "CPU affinity mask", | |
803 | }, | |
d2e268b0 JA |
804 | { |
805 | .name = "cpus_allowed", | |
806 | .type = FIO_OPT_STR, | |
807 | .cb = str_cpus_allowed_cb, | |
808 | .help = "Set CPUs allowed", | |
809 | }, | |
214e1eca JA |
810 | #endif |
811 | { | |
812 | .name = "end_fsync", | |
813 | .type = FIO_OPT_BOOL, | |
814 | .off1 = td_var_offset(end_fsync), | |
815 | .help = "Include fsync at the end of job", | |
816 | .def = "0", | |
817 | }, | |
818 | { | |
819 | .name = "fsync_on_close", | |
820 | .type = FIO_OPT_BOOL, | |
821 | .off1 = td_var_offset(fsync_on_close), | |
822 | .help = "fsync files on close", | |
823 | .def = "0", | |
824 | }, | |
825 | { | |
826 | .name = "unlink", | |
827 | .type = FIO_OPT_BOOL, | |
828 | .off1 = td_var_offset(unlink), | |
829 | .help = "Unlink created files after job has completed", | |
830 | .def = "0", | |
831 | }, | |
832 | { | |
833 | .name = "exitall", | |
834 | .type = FIO_OPT_STR_SET, | |
835 | .cb = str_exitall_cb, | |
836 | .help = "Terminate all jobs when one exits", | |
837 | }, | |
838 | { | |
839 | .name = "stonewall", | |
840 | .type = FIO_OPT_STR_SET, | |
841 | .off1 = td_var_offset(stonewall), | |
842 | .help = "Insert a hard barrier between this job and previous", | |
843 | }, | |
b3d62a75 JA |
844 | { |
845 | .name = "new_group", | |
846 | .type = FIO_OPT_STR_SET, | |
847 | .off1 = td_var_offset(new_group), | |
848 | .help = "Mark the start of a new group (for reporting)", | |
849 | }, | |
214e1eca JA |
850 | { |
851 | .name = "thread", | |
852 | .type = FIO_OPT_STR_SET, | |
853 | .off1 = td_var_offset(use_thread), | |
854 | .help = "Use threads instead of forks", | |
855 | }, | |
856 | { | |
857 | .name = "write_bw_log", | |
858 | .type = FIO_OPT_STR_SET, | |
859 | .off1 = td_var_offset(write_bw_log), | |
860 | .help = "Write log of bandwidth during run", | |
861 | }, | |
862 | { | |
863 | .name = "write_lat_log", | |
864 | .type = FIO_OPT_STR_SET, | |
865 | .off1 = td_var_offset(write_lat_log), | |
866 | .help = "Write log of latency during run", | |
867 | }, | |
868 | { | |
869 | .name = "hugepage-size", | |
870 | .type = FIO_OPT_STR_VAL, | |
871 | .off1 = td_var_offset(hugepage_size), | |
872 | .help = "When using hugepages, specify size of each page", | |
873 | .def = __stringify(FIO_HUGE_PAGE), | |
874 | }, | |
875 | { | |
876 | .name = "group_reporting", | |
877 | .type = FIO_OPT_STR_SET, | |
878 | .off1 = td_var_offset(group_reporting), | |
879 | .help = "Do reporting on a per-group basis", | |
880 | }, | |
e9459e5a JA |
881 | { |
882 | .name = "zero_buffers", | |
883 | .type = FIO_OPT_STR_SET, | |
884 | .off1 = td_var_offset(zero_buffers), | |
885 | .help = "Init IO buffers to all zeroes", | |
886 | }, | |
0a839f30 JA |
887 | #ifdef FIO_HAVE_DISK_UTIL |
888 | { | |
889 | .name = "disk_util", | |
890 | .type = FIO_OPT_BOOL, | |
891 | .off1 = td_var_offset(do_disk_util), | |
892 | .help = "Log disk utilization stats", | |
893 | .def = "1", | |
894 | }, | |
895 | #endif | |
214e1eca JA |
896 | { |
897 | .name = NULL, | |
898 | }, | |
899 | }; | |
900 | ||
901 | void fio_options_dup_and_init(struct option *long_options) | |
902 | { | |
903 | struct fio_option *o; | |
904 | unsigned int i; | |
905 | ||
906 | options_init(options); | |
907 | ||
908 | i = 0; | |
909 | while (long_options[i].name) | |
910 | i++; | |
911 | ||
912 | o = &options[0]; | |
913 | while (o->name) { | |
914 | long_options[i].name = o->name; | |
915 | long_options[i].val = FIO_GETOPT_JOB; | |
916 | if (o->type == FIO_OPT_STR_SET) | |
917 | long_options[i].has_arg = no_argument; | |
918 | else | |
919 | long_options[i].has_arg = required_argument; | |
920 | ||
921 | i++; | |
922 | o++; | |
923 | assert(i < FIO_NR_OPTIONS); | |
924 | } | |
925 | } | |
926 | ||
927 | int fio_option_parse(struct thread_data *td, const char *opt) | |
928 | { | |
929 | return parse_option(opt, options, td); | |
930 | } | |
931 | ||
932 | int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val) | |
933 | { | |
934 | return parse_cmd_option(opt, val, options, td); | |
935 | } | |
936 | ||
937 | void fio_fill_default_options(struct thread_data *td) | |
938 | { | |
939 | fill_default_options(td, options); | |
940 | } | |
941 | ||
942 | int fio_show_option_help(const char *opt) | |
943 | { | |
944 | return show_cmd_help(options, opt); | |
945 | } | |
d23bb327 JA |
946 | |
947 | static void __options_mem(struct thread_data *td, int alloc) | |
948 | { | |
949 | struct thread_options *o = &td->o; | |
950 | struct fio_option *opt; | |
951 | char **ptr; | |
952 | int i; | |
953 | ||
954 | for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) { | |
955 | if (opt->type != FIO_OPT_STR_STORE) | |
956 | continue; | |
957 | ||
958 | ptr = (void *) o + opt->off1; | |
959 | if (*ptr) { | |
960 | if (alloc) | |
961 | *ptr = strdup(*ptr); | |
962 | else { | |
963 | free(*ptr); | |
964 | *ptr = NULL; | |
965 | } | |
966 | } | |
967 | } | |
968 | } | |
969 | ||
970 | /* | |
971 | * dupe FIO_OPT_STR_STORE options | |
972 | */ | |
973 | void options_mem_dupe(struct thread_data *td) | |
974 | { | |
975 | __options_mem(td, 1); | |
976 | } | |
977 | ||
22d66213 | 978 | void options_mem_free(struct thread_data fio_unused *td) |
d23bb327 | 979 | { |
22d66213 | 980 | #if 0 |
d23bb327 | 981 | __options_mem(td, 0); |
22d66213 | 982 | #endif |
d23bb327 | 983 | } |