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> | |
921c766f | 8 | #include <libgen.h> |
5921e80c JA |
9 | #include <fcntl.h> |
10 | #include <sys/types.h> | |
11 | #include <sys/stat.h> | |
214e1eca JA |
12 | |
13 | #include "fio.h" | |
4f5af7b2 | 14 | #include "verify.h" |
214e1eca | 15 | #include "parse.h" |
eef32359 | 16 | #include "lib/fls.h" |
9f988e2e | 17 | #include "options.h" |
214e1eca | 18 | |
214e1eca JA |
19 | /* |
20 | * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that. | |
21 | */ | |
22 | static char *get_opt_postfix(const char *str) | |
23 | { | |
24 | char *p = strstr(str, ":"); | |
25 | ||
26 | if (!p) | |
27 | return NULL; | |
28 | ||
29 | p++; | |
30 | strip_blank_front(&p); | |
31 | strip_blank_end(p); | |
32 | return strdup(p); | |
33 | } | |
34 | ||
0e92f873 RR |
35 | static int converthexchartoint(char a) |
36 | { | |
37 | int base; | |
38 | ||
39 | switch(a) { | |
40 | case '0'...'9': | |
41 | base = '0'; | |
42 | break; | |
43 | case 'A'...'F': | |
44 | base = 'A' - 10; | |
45 | break; | |
46 | case 'a'...'f': | |
47 | base = 'a' - 10; | |
48 | break; | |
49 | default: | |
50 | base = 0; | |
51 | } | |
52 | return (a - base); | |
53 | } | |
54 | ||
564ca972 JA |
55 | static int bs_cmp(const void *p1, const void *p2) |
56 | { | |
57 | const struct bssplit *bsp1 = p1; | |
58 | const struct bssplit *bsp2 = p2; | |
59 | ||
60 | return bsp1->perc < bsp2->perc; | |
61 | } | |
62 | ||
720e84ad | 63 | static int bssplit_ddir(struct thread_data *td, int ddir, char *str) |
564ca972 | 64 | { |
720e84ad | 65 | struct bssplit *bssplit; |
564ca972 JA |
66 | unsigned int i, perc, perc_missing; |
67 | unsigned int max_bs, min_bs; | |
68 | long long val; | |
720e84ad | 69 | char *fname; |
564ca972 | 70 | |
720e84ad JA |
71 | td->o.bssplit_nr[ddir] = 4; |
72 | bssplit = malloc(4 * sizeof(struct bssplit)); | |
564ca972 JA |
73 | |
74 | i = 0; | |
75 | max_bs = 0; | |
76 | min_bs = -1; | |
77 | while ((fname = strsep(&str, ":")) != NULL) { | |
78 | char *perc_str; | |
79 | ||
80 | if (!strlen(fname)) | |
81 | break; | |
82 | ||
83 | /* | |
84 | * grow struct buffer, if needed | |
85 | */ | |
720e84ad JA |
86 | if (i == td->o.bssplit_nr[ddir]) { |
87 | td->o.bssplit_nr[ddir] <<= 1; | |
88 | bssplit = realloc(bssplit, td->o.bssplit_nr[ddir] | |
5ec10eaa | 89 | * sizeof(struct bssplit)); |
564ca972 JA |
90 | } |
91 | ||
92 | perc_str = strstr(fname, "/"); | |
93 | if (perc_str) { | |
94 | *perc_str = '\0'; | |
95 | perc_str++; | |
96 | perc = atoi(perc_str); | |
97 | if (perc > 100) | |
98 | perc = 100; | |
99 | else if (!perc) | |
100 | perc = -1; | |
101 | } else | |
102 | perc = -1; | |
103 | ||
df9cf928 | 104 | if (str_to_decimal(fname, &val, 1, td)) { |
564ca972 JA |
105 | log_err("fio: bssplit conversion failed\n"); |
106 | free(td->o.bssplit); | |
107 | return 1; | |
108 | } | |
109 | ||
110 | if (val > max_bs) | |
111 | max_bs = val; | |
112 | if (val < min_bs) | |
113 | min_bs = val; | |
114 | ||
720e84ad JA |
115 | bssplit[i].bs = val; |
116 | bssplit[i].perc = perc; | |
564ca972 JA |
117 | i++; |
118 | } | |
119 | ||
720e84ad | 120 | td->o.bssplit_nr[ddir] = i; |
564ca972 JA |
121 | |
122 | /* | |
123 | * Now check if the percentages add up, and how much is missing | |
124 | */ | |
125 | perc = perc_missing = 0; | |
720e84ad JA |
126 | for (i = 0; i < td->o.bssplit_nr[ddir]; i++) { |
127 | struct bssplit *bsp = &bssplit[i]; | |
564ca972 JA |
128 | |
129 | if (bsp->perc == (unsigned char) -1) | |
130 | perc_missing++; | |
131 | else | |
132 | perc += bsp->perc; | |
133 | } | |
134 | ||
135 | if (perc > 100) { | |
136 | log_err("fio: bssplit percentages add to more than 100%%\n"); | |
720e84ad | 137 | free(bssplit); |
564ca972 JA |
138 | return 1; |
139 | } | |
140 | /* | |
141 | * If values didn't have a percentage set, divide the remains between | |
142 | * them. | |
143 | */ | |
144 | if (perc_missing) { | |
720e84ad JA |
145 | for (i = 0; i < td->o.bssplit_nr[ddir]; i++) { |
146 | struct bssplit *bsp = &bssplit[i]; | |
564ca972 JA |
147 | |
148 | if (bsp->perc == (unsigned char) -1) | |
149 | bsp->perc = (100 - perc) / perc_missing; | |
150 | } | |
151 | } | |
152 | ||
720e84ad JA |
153 | td->o.min_bs[ddir] = min_bs; |
154 | td->o.max_bs[ddir] = max_bs; | |
564ca972 JA |
155 | |
156 | /* | |
157 | * now sort based on percentages, for ease of lookup | |
158 | */ | |
720e84ad JA |
159 | qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp); |
160 | td->o.bssplit[ddir] = bssplit; | |
161 | return 0; | |
162 | ||
163 | } | |
164 | ||
165 | static int str_bssplit_cb(void *data, const char *input) | |
166 | { | |
167 | struct thread_data *td = data; | |
168 | char *str, *p, *odir; | |
169 | int ret = 0; | |
170 | ||
171 | p = str = strdup(input); | |
172 | ||
173 | strip_blank_front(&str); | |
174 | strip_blank_end(str); | |
175 | ||
176 | odir = strchr(str, ','); | |
177 | if (odir) { | |
178 | ret = bssplit_ddir(td, DDIR_WRITE, odir + 1); | |
179 | if (!ret) { | |
180 | *odir = '\0'; | |
181 | ret = bssplit_ddir(td, DDIR_READ, str); | |
182 | } | |
183 | } else { | |
184 | char *op; | |
185 | ||
186 | op = strdup(str); | |
187 | ||
188 | ret = bssplit_ddir(td, DDIR_READ, str); | |
189 | if (!ret) | |
190 | ret = bssplit_ddir(td, DDIR_WRITE, op); | |
191 | ||
192 | free(op); | |
193 | } | |
564ca972 JA |
194 | |
195 | free(p); | |
720e84ad | 196 | return ret; |
564ca972 JA |
197 | } |
198 | ||
211097b2 JA |
199 | static int str_rw_cb(void *data, const char *str) |
200 | { | |
201 | struct thread_data *td = data; | |
202 | char *nr = get_opt_postfix(str); | |
203 | ||
fafdba3c | 204 | td->o.ddir_nr = 1; |
182ec6ee | 205 | if (nr) { |
211097b2 | 206 | td->o.ddir_nr = atoi(nr); |
182ec6ee JA |
207 | free(nr); |
208 | } | |
211097b2 | 209 | |
211097b2 JA |
210 | return 0; |
211 | } | |
212 | ||
214e1eca JA |
213 | static int str_mem_cb(void *data, const char *mem) |
214 | { | |
215 | struct thread_data *td = data; | |
216 | ||
2dc1bbeb | 217 | if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) { |
214e1eca | 218 | td->mmapfile = get_opt_postfix(mem); |
2dc1bbeb | 219 | if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) { |
214e1eca JA |
220 | log_err("fio: mmaphuge:/path/to/file\n"); |
221 | return 1; | |
222 | } | |
223 | } | |
224 | ||
225 | return 0; | |
226 | } | |
227 | ||
c223da83 JA |
228 | static int fio_clock_source_cb(void *data, const char *str) |
229 | { | |
230 | struct thread_data *td = data; | |
231 | ||
232 | fio_clock_source = td->o.clocksource; | |
233 | fio_time_init(); | |
234 | return 0; | |
235 | } | |
236 | ||
214e1eca JA |
237 | static int str_lockmem_cb(void fio_unused *data, unsigned long *val) |
238 | { | |
239 | mlock_size = *val; | |
240 | return 0; | |
241 | } | |
242 | ||
cb499fc4 JA |
243 | static int str_rwmix_read_cb(void *data, unsigned int *val) |
244 | { | |
245 | struct thread_data *td = data; | |
246 | ||
247 | td->o.rwmix[DDIR_READ] = *val; | |
248 | td->o.rwmix[DDIR_WRITE] = 100 - *val; | |
249 | return 0; | |
250 | } | |
251 | ||
252 | static int str_rwmix_write_cb(void *data, unsigned int *val) | |
253 | { | |
254 | struct thread_data *td = data; | |
255 | ||
256 | td->o.rwmix[DDIR_WRITE] = *val; | |
257 | td->o.rwmix[DDIR_READ] = 100 - *val; | |
258 | return 0; | |
259 | } | |
260 | ||
214e1eca JA |
261 | #ifdef FIO_HAVE_IOPRIO |
262 | static int str_prioclass_cb(void *data, unsigned int *val) | |
263 | { | |
264 | struct thread_data *td = data; | |
6cefbe33 JA |
265 | unsigned short mask; |
266 | ||
267 | /* | |
268 | * mask off old class bits, str_prio_cb() may have set a default class | |
269 | */ | |
270 | mask = (1 << IOPRIO_CLASS_SHIFT) - 1; | |
271 | td->ioprio &= mask; | |
214e1eca JA |
272 | |
273 | td->ioprio |= *val << IOPRIO_CLASS_SHIFT; | |
ac684785 | 274 | td->ioprio_set = 1; |
214e1eca JA |
275 | return 0; |
276 | } | |
277 | ||
278 | static int str_prio_cb(void *data, unsigned int *val) | |
279 | { | |
280 | struct thread_data *td = data; | |
281 | ||
282 | td->ioprio |= *val; | |
6cefbe33 JA |
283 | |
284 | /* | |
285 | * If no class is set, assume BE | |
286 | */ | |
287 | if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0) | |
288 | td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT; | |
289 | ||
ac684785 | 290 | td->ioprio_set = 1; |
214e1eca JA |
291 | return 0; |
292 | } | |
293 | #endif | |
294 | ||
295 | static int str_exitall_cb(void) | |
296 | { | |
297 | exitall_on_terminate = 1; | |
298 | return 0; | |
299 | } | |
300 | ||
214e1eca | 301 | #ifdef FIO_HAVE_CPU_AFFINITY |
d2e268b0 JA |
302 | static int str_cpumask_cb(void *data, unsigned int *val) |
303 | { | |
304 | struct thread_data *td = data; | |
214e1eca | 305 | unsigned int i; |
b03daafb | 306 | long max_cpu; |
d2ce18b5 JA |
307 | int ret; |
308 | ||
309 | ret = fio_cpuset_init(&td->o.cpumask); | |
310 | if (ret < 0) { | |
311 | log_err("fio: cpuset_init failed\n"); | |
312 | td_verror(td, ret, "fio_cpuset_init"); | |
313 | return 1; | |
314 | } | |
214e1eca | 315 | |
b03daafb | 316 | max_cpu = sysconf(_SC_NPROCESSORS_ONLN); |
214e1eca | 317 | |
62a7273d JA |
318 | for (i = 0; i < sizeof(int) * 8; i++) { |
319 | if ((1 << i) & *val) { | |
b03daafb JA |
320 | if (i > max_cpu) { |
321 | log_err("fio: CPU %d too large (max=%ld)\n", i, | |
322 | max_cpu); | |
323 | return 1; | |
324 | } | |
62a7273d | 325 | dprint(FD_PARSE, "set cpu allowed %d\n", i); |
6d459ee7 | 326 | fio_cpu_set(&td->o.cpumask, i); |
62a7273d JA |
327 | } |
328 | } | |
d2e268b0 JA |
329 | |
330 | td->o.cpumask_set = 1; | |
331 | return 0; | |
214e1eca JA |
332 | } |
333 | ||
e8462bd8 JA |
334 | static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask, |
335 | const char *input) | |
214e1eca | 336 | { |
d2e268b0 | 337 | char *cpu, *str, *p; |
b03daafb | 338 | long max_cpu; |
19608d6c | 339 | int ret = 0; |
d2e268b0 | 340 | |
e8462bd8 | 341 | ret = fio_cpuset_init(mask); |
d2ce18b5 JA |
342 | if (ret < 0) { |
343 | log_err("fio: cpuset_init failed\n"); | |
344 | td_verror(td, ret, "fio_cpuset_init"); | |
345 | return 1; | |
346 | } | |
d2e268b0 JA |
347 | |
348 | p = str = strdup(input); | |
214e1eca | 349 | |
d2e268b0 JA |
350 | strip_blank_front(&str); |
351 | strip_blank_end(str); | |
352 | ||
b03daafb JA |
353 | max_cpu = sysconf(_SC_NPROCESSORS_ONLN); |
354 | ||
d2e268b0 | 355 | while ((cpu = strsep(&str, ",")) != NULL) { |
62a7273d JA |
356 | char *str2, *cpu2; |
357 | int icpu, icpu2; | |
358 | ||
d2e268b0 JA |
359 | if (!strlen(cpu)) |
360 | break; | |
62a7273d JA |
361 | |
362 | str2 = cpu; | |
363 | icpu2 = -1; | |
364 | while ((cpu2 = strsep(&str2, "-")) != NULL) { | |
365 | if (!strlen(cpu2)) | |
366 | break; | |
367 | ||
368 | icpu2 = atoi(cpu2); | |
369 | } | |
370 | ||
371 | icpu = atoi(cpu); | |
372 | if (icpu2 == -1) | |
373 | icpu2 = icpu; | |
374 | while (icpu <= icpu2) { | |
6d459ee7 | 375 | if (icpu >= FIO_MAX_CPUS) { |
19608d6c | 376 | log_err("fio: your OS only supports up to" |
6d459ee7 | 377 | " %d CPUs\n", (int) FIO_MAX_CPUS); |
19608d6c JA |
378 | ret = 1; |
379 | break; | |
380 | } | |
b03daafb JA |
381 | if (icpu > max_cpu) { |
382 | log_err("fio: CPU %d too large (max=%ld)\n", | |
383 | icpu, max_cpu); | |
384 | ret = 1; | |
385 | break; | |
386 | } | |
0b9d69ec | 387 | |
62a7273d | 388 | dprint(FD_PARSE, "set cpu allowed %d\n", icpu); |
e8462bd8 | 389 | fio_cpu_set(mask, icpu); |
62a7273d JA |
390 | icpu++; |
391 | } | |
19608d6c JA |
392 | if (ret) |
393 | break; | |
d2e268b0 JA |
394 | } |
395 | ||
396 | free(p); | |
19608d6c JA |
397 | if (!ret) |
398 | td->o.cpumask_set = 1; | |
399 | return ret; | |
214e1eca | 400 | } |
e8462bd8 JA |
401 | |
402 | static int str_cpus_allowed_cb(void *data, const char *input) | |
403 | { | |
404 | struct thread_data *td = data; | |
405 | int ret; | |
406 | ||
407 | ret = set_cpus_allowed(td, &td->o.cpumask, input); | |
408 | if (!ret) | |
409 | td->o.cpumask_set = 1; | |
410 | ||
411 | return ret; | |
412 | } | |
413 | ||
414 | static int str_verify_cpus_allowed_cb(void *data, const char *input) | |
415 | { | |
416 | struct thread_data *td = data; | |
417 | int ret; | |
418 | ||
419 | ret = set_cpus_allowed(td, &td->o.verify_cpumask, input); | |
420 | if (!ret) | |
421 | td->o.verify_cpumask_set = 1; | |
422 | ||
423 | return ret; | |
424 | } | |
d2e268b0 | 425 | #endif |
214e1eca JA |
426 | |
427 | static int str_fst_cb(void *data, const char *str) | |
428 | { | |
429 | struct thread_data *td = data; | |
430 | char *nr = get_opt_postfix(str); | |
431 | ||
432 | td->file_service_nr = 1; | |
182ec6ee | 433 | if (nr) { |
214e1eca | 434 | td->file_service_nr = atoi(nr); |
182ec6ee JA |
435 | free(nr); |
436 | } | |
214e1eca JA |
437 | |
438 | return 0; | |
439 | } | |
440 | ||
3ae06371 | 441 | #ifdef FIO_HAVE_SYNC_FILE_RANGE |
44f29692 JA |
442 | static int str_sfr_cb(void *data, const char *str) |
443 | { | |
444 | struct thread_data *td = data; | |
445 | char *nr = get_opt_postfix(str); | |
446 | ||
447 | td->sync_file_range_nr = 1; | |
448 | if (nr) { | |
449 | td->sync_file_range_nr = atoi(nr); | |
450 | free(nr); | |
451 | } | |
452 | ||
453 | return 0; | |
454 | } | |
3ae06371 | 455 | #endif |
44f29692 | 456 | |
921c766f JA |
457 | static int check_dir(struct thread_data *td, char *fname) |
458 | { | |
459 | char file[PATH_MAX], *dir; | |
bc838919 | 460 | int elen = 0; |
921c766f | 461 | |
bc838919 JA |
462 | if (td->o.directory) { |
463 | strcpy(file, td->o.directory); | |
fcef0b35 | 464 | strcat(file, "/"); |
bc838919 JA |
465 | elen = strlen(file); |
466 | } | |
467 | ||
fcef0b35 | 468 | sprintf(file + elen, "%s", fname); |
921c766f JA |
469 | dir = dirname(file); |
470 | ||
fcef0b35 JA |
471 | #if 0 |
472 | { | |
473 | struct stat sb; | |
474 | /* | |
475 | * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded | |
476 | * yet, so we can't do this check right here... | |
477 | */ | |
921c766f JA |
478 | if (lstat(dir, &sb) < 0) { |
479 | int ret = errno; | |
480 | ||
481 | log_err("fio: %s is not a directory\n", dir); | |
482 | td_verror(td, ret, "lstat"); | |
483 | return 1; | |
484 | } | |
485 | ||
486 | if (!S_ISDIR(sb.st_mode)) { | |
487 | log_err("fio: %s is not a directory\n", dir); | |
488 | return 1; | |
489 | } | |
fcef0b35 JA |
490 | } |
491 | #endif | |
921c766f JA |
492 | |
493 | return 0; | |
494 | } | |
495 | ||
8e827d35 JA |
496 | /* |
497 | * Return next file in the string. Files are separated with ':'. If the ':' | |
498 | * is escaped with a '\', then that ':' is part of the filename and does not | |
499 | * indicate a new file. | |
500 | */ | |
501 | static char *get_next_file_name(char **ptr) | |
502 | { | |
503 | char *str = *ptr; | |
504 | char *p, *start; | |
505 | ||
506 | if (!str || !strlen(str)) | |
507 | return NULL; | |
508 | ||
509 | start = str; | |
510 | do { | |
511 | /* | |
512 | * No colon, we are done | |
513 | */ | |
514 | p = strchr(str, ':'); | |
515 | if (!p) { | |
516 | *ptr = NULL; | |
517 | break; | |
518 | } | |
519 | ||
520 | /* | |
521 | * We got a colon, but it's the first character. Skip and | |
522 | * continue | |
523 | */ | |
524 | if (p == start) { | |
525 | str = ++start; | |
526 | continue; | |
527 | } | |
528 | ||
529 | if (*(p - 1) != '\\') { | |
530 | *p = '\0'; | |
531 | *ptr = p + 1; | |
532 | break; | |
533 | } | |
534 | ||
535 | memmove(p - 1, p, strlen(p) + 1); | |
536 | str = p; | |
537 | } while (1); | |
538 | ||
539 | return start; | |
540 | } | |
541 | ||
214e1eca JA |
542 | static int str_filename_cb(void *data, const char *input) |
543 | { | |
544 | struct thread_data *td = data; | |
545 | char *fname, *str, *p; | |
546 | ||
547 | p = str = strdup(input); | |
548 | ||
549 | strip_blank_front(&str); | |
550 | strip_blank_end(str); | |
551 | ||
552 | if (!td->files_index) | |
2dc1bbeb | 553 | td->o.nr_files = 0; |
214e1eca | 554 | |
8e827d35 | 555 | while ((fname = get_next_file_name(&str)) != NULL) { |
214e1eca JA |
556 | if (!strlen(fname)) |
557 | break; | |
921c766f JA |
558 | if (check_dir(td, fname)) { |
559 | free(p); | |
560 | return 1; | |
561 | } | |
214e1eca | 562 | add_file(td, fname); |
2dc1bbeb | 563 | td->o.nr_files++; |
214e1eca JA |
564 | } |
565 | ||
566 | free(p); | |
567 | return 0; | |
568 | } | |
569 | ||
570 | static int str_directory_cb(void *data, const char fio_unused *str) | |
571 | { | |
572 | struct thread_data *td = data; | |
573 | struct stat sb; | |
574 | ||
2dc1bbeb | 575 | if (lstat(td->o.directory, &sb) < 0) { |
921c766f JA |
576 | int ret = errno; |
577 | ||
2dc1bbeb | 578 | log_err("fio: %s is not a directory\n", td->o.directory); |
921c766f | 579 | td_verror(td, ret, "lstat"); |
214e1eca JA |
580 | return 1; |
581 | } | |
582 | if (!S_ISDIR(sb.st_mode)) { | |
2dc1bbeb | 583 | log_err("fio: %s is not a directory\n", td->o.directory); |
214e1eca JA |
584 | return 1; |
585 | } | |
586 | ||
587 | return 0; | |
588 | } | |
589 | ||
590 | static int str_opendir_cb(void *data, const char fio_unused *str) | |
591 | { | |
592 | struct thread_data *td = data; | |
593 | ||
594 | if (!td->files_index) | |
2dc1bbeb | 595 | td->o.nr_files = 0; |
214e1eca | 596 | |
2dc1bbeb | 597 | return add_dir_files(td, td->o.opendir); |
214e1eca JA |
598 | } |
599 | ||
a59e170d | 600 | static int str_verify_offset_cb(void *data, unsigned int *off) |
546a9142 SL |
601 | { |
602 | struct thread_data *td = data; | |
a59e170d | 603 | |
546a9142 | 604 | if (*off && *off < sizeof(struct verify_header)) { |
a59e170d | 605 | log_err("fio: verify_offset too small\n"); |
546a9142 SL |
606 | return 1; |
607 | } | |
a59e170d JA |
608 | |
609 | td->o.verify_offset = *off; | |
546a9142 SL |
610 | return 0; |
611 | } | |
612 | ||
0e92f873 | 613 | static int str_verify_pattern_cb(void *data, const char *input) |
90059d65 JA |
614 | { |
615 | struct thread_data *td = data; | |
0e92f873 RR |
616 | long off; |
617 | int i = 0, j = 0, len, k, base = 10; | |
618 | char* loc1, * loc2; | |
619 | ||
620 | loc1 = strstr(input, "0x"); | |
621 | loc2 = strstr(input, "0X"); | |
622 | if (loc1 || loc2) | |
623 | base = 16; | |
624 | off = strtol(input, NULL, base); | |
625 | if (off != LONG_MAX || errno != ERANGE) { | |
626 | while (off) { | |
627 | td->o.verify_pattern[i] = off & 0xff; | |
628 | off >>= 8; | |
629 | i++; | |
630 | } | |
631 | } else { | |
632 | len = strlen(input); | |
633 | k = len - 1; | |
634 | if (base == 16) { | |
635 | if (loc1) | |
636 | j = loc1 - input + 2; | |
637 | else | |
638 | j = loc2 - input + 2; | |
639 | } else | |
640 | return 1; | |
641 | if (len - j < MAX_PATTERN_SIZE * 2) { | |
642 | while (k >= j) { | |
643 | off = converthexchartoint(input[k--]); | |
644 | if (k >= j) | |
645 | off += (converthexchartoint(input[k--]) | |
646 | * 16); | |
647 | td->o.verify_pattern[i++] = (char) off; | |
648 | } | |
649 | } | |
650 | } | |
651 | td->o.verify_pattern_bytes = i; | |
90059d65 JA |
652 | return 0; |
653 | } | |
214e1eca | 654 | |
4d4e80f2 JA |
655 | static int str_lockfile_cb(void *data, const char *str) |
656 | { | |
657 | struct thread_data *td = data; | |
658 | char *nr = get_opt_postfix(str); | |
659 | ||
660 | td->o.lockfile_batch = 1; | |
182ec6ee | 661 | if (nr) { |
4d4e80f2 | 662 | td->o.lockfile_batch = atoi(nr); |
182ec6ee JA |
663 | free(nr); |
664 | } | |
4d4e80f2 JA |
665 | |
666 | return 0; | |
667 | } | |
668 | ||
e3cedca7 JA |
669 | static int str_write_bw_log_cb(void *data, const char *str) |
670 | { | |
671 | struct thread_data *td = data; | |
672 | ||
673 | if (str) | |
674 | td->o.bw_log_file = strdup(str); | |
675 | ||
676 | td->o.write_bw_log = 1; | |
677 | return 0; | |
678 | } | |
679 | ||
680 | static int str_write_lat_log_cb(void *data, const char *str) | |
681 | { | |
682 | struct thread_data *td = data; | |
683 | ||
684 | if (str) | |
685 | td->o.lat_log_file = strdup(str); | |
686 | ||
687 | td->o.write_lat_log = 1; | |
688 | return 0; | |
689 | } | |
690 | ||
993bf48b JA |
691 | static int str_gtod_reduce_cb(void *data, int *il) |
692 | { | |
693 | struct thread_data *td = data; | |
694 | int val = *il; | |
695 | ||
696 | td->o.disable_clat = !!val; | |
697 | td->o.disable_slat = !!val; | |
698 | td->o.disable_bw = !!val; | |
699 | if (val) | |
700 | td->tv_cache_mask = 63; | |
701 | ||
702 | return 0; | |
703 | } | |
704 | ||
be4ecfdf JA |
705 | static int str_gtod_cpu_cb(void *data, int *il) |
706 | { | |
707 | struct thread_data *td = data; | |
708 | int val = *il; | |
709 | ||
710 | td->o.gtod_cpu = val; | |
711 | td->o.gtod_offload = 1; | |
712 | return 0; | |
713 | } | |
714 | ||
896cac2a JA |
715 | static int rw_verify(struct fio_option *o, void *data) |
716 | { | |
717 | struct thread_data *td = data; | |
718 | ||
719 | if (read_only && td_write(td)) { | |
720 | log_err("fio: job <%s> has write bit set, but fio is in" | |
721 | " read-only mode\n", td->o.name); | |
722 | return 1; | |
723 | } | |
724 | ||
725 | return 0; | |
726 | } | |
727 | ||
276ca4f7 | 728 | static int gtod_cpu_verify(struct fio_option *o, void *data) |
29d43ff9 | 729 | { |
276ca4f7 | 730 | #ifndef FIO_HAVE_CPU_AFFINITY |
29d43ff9 JA |
731 | struct thread_data *td = data; |
732 | ||
29d43ff9 JA |
733 | if (td->o.gtod_cpu) { |
734 | log_err("fio: platform must support CPU affinity for" | |
735 | "gettimeofday() offloading\n"); | |
736 | return 1; | |
737 | } | |
738 | #endif | |
739 | ||
740 | return 0; | |
741 | } | |
742 | ||
90fef2d1 JA |
743 | static int kb_base_verify(struct fio_option *o, void *data) |
744 | { | |
745 | struct thread_data *td = data; | |
746 | ||
747 | if (td->o.kb_base != 1024 && td->o.kb_base != 1000) { | |
748 | log_err("fio: kb_base set to nonsensical value: %u\n", | |
749 | td->o.kb_base); | |
750 | return 1; | |
751 | } | |
752 | ||
753 | return 0; | |
754 | } | |
755 | ||
214e1eca JA |
756 | #define __stringify_1(x) #x |
757 | #define __stringify(x) __stringify_1(x) | |
758 | ||
759 | /* | |
760 | * Map of job/command line options | |
761 | */ | |
07b3232d | 762 | static struct fio_option options[FIO_MAX_OPTS] = { |
214e1eca JA |
763 | { |
764 | .name = "description", | |
765 | .type = FIO_OPT_STR_STORE, | |
766 | .off1 = td_var_offset(description), | |
767 | .help = "Text job description", | |
768 | }, | |
769 | { | |
770 | .name = "name", | |
771 | .type = FIO_OPT_STR_STORE, | |
772 | .off1 = td_var_offset(name), | |
773 | .help = "Name of this job", | |
774 | }, | |
775 | { | |
776 | .name = "directory", | |
777 | .type = FIO_OPT_STR_STORE, | |
778 | .off1 = td_var_offset(directory), | |
779 | .cb = str_directory_cb, | |
780 | .help = "Directory to store files in", | |
781 | }, | |
782 | { | |
783 | .name = "filename", | |
784 | .type = FIO_OPT_STR_STORE, | |
785 | .off1 = td_var_offset(filename), | |
786 | .cb = str_filename_cb, | |
f0d524b0 | 787 | .prio = -1, /* must come after "directory" */ |
214e1eca JA |
788 | .help = "File(s) to use for the workload", |
789 | }, | |
90fef2d1 JA |
790 | { |
791 | .name = "kb_base", | |
792 | .type = FIO_OPT_INT, | |
793 | .off1 = td_var_offset(kb_base), | |
90fef2d1 | 794 | .verify = kb_base_verify, |
a639f0bb | 795 | .prio = 1, |
90fef2d1 | 796 | .def = "1024", |
a639f0bb | 797 | .help = "How many bytes per KB for reporting (1000 or 1024)", |
90fef2d1 | 798 | }, |
29c1349f JA |
799 | { |
800 | .name = "lockfile", | |
4d4e80f2 JA |
801 | .type = FIO_OPT_STR, |
802 | .cb = str_lockfile_cb, | |
803 | .off1 = td_var_offset(file_lock_mode), | |
29c1349f JA |
804 | .help = "Lock file when doing IO to it", |
805 | .parent = "filename", | |
4d4e80f2 JA |
806 | .def = "none", |
807 | .posval = { | |
808 | { .ival = "none", | |
809 | .oval = FILE_LOCK_NONE, | |
810 | .help = "No file locking", | |
811 | }, | |
812 | { .ival = "exclusive", | |
813 | .oval = FILE_LOCK_EXCLUSIVE, | |
814 | .help = "Exclusive file lock", | |
815 | }, | |
816 | { | |
817 | .ival = "readwrite", | |
818 | .oval = FILE_LOCK_READWRITE, | |
819 | .help = "Read vs write lock", | |
820 | }, | |
821 | }, | |
29c1349f | 822 | }, |
214e1eca JA |
823 | { |
824 | .name = "opendir", | |
825 | .type = FIO_OPT_STR_STORE, | |
826 | .off1 = td_var_offset(opendir), | |
827 | .cb = str_opendir_cb, | |
828 | .help = "Recursively add files from this directory and down", | |
829 | }, | |
830 | { | |
831 | .name = "rw", | |
d3aad8f2 | 832 | .alias = "readwrite", |
214e1eca | 833 | .type = FIO_OPT_STR, |
211097b2 | 834 | .cb = str_rw_cb, |
214e1eca JA |
835 | .off1 = td_var_offset(td_ddir), |
836 | .help = "IO direction", | |
837 | .def = "read", | |
896cac2a | 838 | .verify = rw_verify, |
214e1eca JA |
839 | .posval = { |
840 | { .ival = "read", | |
841 | .oval = TD_DDIR_READ, | |
842 | .help = "Sequential read", | |
843 | }, | |
844 | { .ival = "write", | |
845 | .oval = TD_DDIR_WRITE, | |
846 | .help = "Sequential write", | |
847 | }, | |
848 | { .ival = "randread", | |
849 | .oval = TD_DDIR_RANDREAD, | |
850 | .help = "Random read", | |
851 | }, | |
852 | { .ival = "randwrite", | |
853 | .oval = TD_DDIR_RANDWRITE, | |
854 | .help = "Random write", | |
855 | }, | |
856 | { .ival = "rw", | |
857 | .oval = TD_DDIR_RW, | |
858 | .help = "Sequential read and write mix", | |
859 | }, | |
860 | { .ival = "randrw", | |
861 | .oval = TD_DDIR_RANDRW, | |
862 | .help = "Random read and write mix" | |
863 | }, | |
864 | }, | |
865 | }, | |
866 | { | |
867 | .name = "ioengine", | |
868 | .type = FIO_OPT_STR_STORE, | |
869 | .off1 = td_var_offset(ioengine), | |
870 | .help = "IO engine to use", | |
871 | .def = "sync", | |
872 | .posval = { | |
873 | { .ival = "sync", | |
874 | .help = "Use read/write", | |
875 | }, | |
a31041ea | 876 | { .ival = "psync", |
877 | .help = "Use pread/pwrite", | |
878 | }, | |
1d2af02a JA |
879 | { .ival = "vsync", |
880 | .help = "Use readv/writev", | |
881 | }, | |
214e1eca JA |
882 | #ifdef FIO_HAVE_LIBAIO |
883 | { .ival = "libaio", | |
884 | .help = "Linux native asynchronous IO", | |
885 | }, | |
886 | #endif | |
887 | #ifdef FIO_HAVE_POSIXAIO | |
888 | { .ival = "posixaio", | |
889 | .help = "POSIX asynchronous IO", | |
890 | }, | |
417f0068 JA |
891 | #endif |
892 | #ifdef FIO_HAVE_SOLARISAIO | |
893 | { .ival = "solarisaio", | |
894 | .help = "Solaris native asynchronous IO", | |
895 | }, | |
214e1eca JA |
896 | #endif |
897 | { .ival = "mmap", | |
898 | .help = "Memory mapped IO", | |
899 | }, | |
900 | #ifdef FIO_HAVE_SPLICE | |
901 | { .ival = "splice", | |
902 | .help = "splice/vmsplice based IO", | |
903 | }, | |
9cce02e8 JA |
904 | { .ival = "netsplice", |
905 | .help = "splice/vmsplice to/from the network", | |
906 | }, | |
214e1eca JA |
907 | #endif |
908 | #ifdef FIO_HAVE_SGIO | |
909 | { .ival = "sg", | |
910 | .help = "SCSI generic v3 IO", | |
911 | }, | |
912 | #endif | |
913 | { .ival = "null", | |
914 | .help = "Testing engine (no data transfer)", | |
915 | }, | |
916 | { .ival = "net", | |
917 | .help = "Network IO", | |
918 | }, | |
919 | #ifdef FIO_HAVE_SYSLET | |
920 | { .ival = "syslet-rw", | |
921 | .help = "syslet enabled async pread/pwrite IO", | |
922 | }, | |
923 | #endif | |
924 | { .ival = "cpuio", | |
925 | .help = "CPU cycler burner engine", | |
926 | }, | |
b8c82a46 JA |
927 | #ifdef FIO_HAVE_GUASI |
928 | { .ival = "guasi", | |
929 | .help = "GUASI IO engine", | |
930 | }, | |
931 | #endif | |
214e1eca JA |
932 | { .ival = "external", |
933 | .help = "Load external engine (append name)", | |
934 | }, | |
935 | }, | |
936 | }, | |
937 | { | |
938 | .name = "iodepth", | |
939 | .type = FIO_OPT_INT, | |
940 | .off1 = td_var_offset(iodepth), | |
941 | .help = "Amount of IO buffers to keep in flight", | |
757aff4f | 942 | .minval = 1, |
214e1eca JA |
943 | .def = "1", |
944 | }, | |
945 | { | |
946 | .name = "iodepth_batch", | |
4950421a | 947 | .alias = "iodepth_batch_submit", |
214e1eca JA |
948 | .type = FIO_OPT_INT, |
949 | .off1 = td_var_offset(iodepth_batch), | |
d65db441 | 950 | .help = "Number of IO buffers to submit in one go", |
afdf9352 | 951 | .parent = "iodepth", |
a2e6f8ac JA |
952 | .minval = 1, |
953 | .def = "1", | |
4950421a JA |
954 | }, |
955 | { | |
956 | .name = "iodepth_batch_complete", | |
957 | .type = FIO_OPT_INT, | |
958 | .off1 = td_var_offset(iodepth_batch_complete), | |
d65db441 | 959 | .help = "Number of IO buffers to retrieve in one go", |
4950421a JA |
960 | .parent = "iodepth", |
961 | .minval = 0, | |
962 | .def = "1", | |
214e1eca JA |
963 | }, |
964 | { | |
965 | .name = "iodepth_low", | |
966 | .type = FIO_OPT_INT, | |
967 | .off1 = td_var_offset(iodepth_low), | |
968 | .help = "Low water mark for queuing depth", | |
afdf9352 | 969 | .parent = "iodepth", |
214e1eca JA |
970 | }, |
971 | { | |
972 | .name = "size", | |
973 | .type = FIO_OPT_STR_VAL, | |
2dc1bbeb | 974 | .off1 = td_var_offset(size), |
c3edbdba | 975 | .minval = 1, |
214e1eca JA |
976 | .help = "Total size of device or files", |
977 | }, | |
aa31f1f1 SL |
978 | { |
979 | .name = "fill_device", | |
980 | .type = FIO_OPT_BOOL, | |
981 | .off1 = td_var_offset(fill_device), | |
982 | .help = "Write until an ENOSPC error occurs", | |
983 | .def = "0", | |
984 | }, | |
214e1eca JA |
985 | { |
986 | .name = "filesize", | |
987 | .type = FIO_OPT_STR_VAL, | |
988 | .off1 = td_var_offset(file_size_low), | |
989 | .off2 = td_var_offset(file_size_high), | |
c3edbdba | 990 | .minval = 1, |
214e1eca JA |
991 | .help = "Size of individual files", |
992 | }, | |
67a1000f JA |
993 | { |
994 | .name = "offset", | |
995 | .alias = "fileoffset", | |
996 | .type = FIO_OPT_STR_VAL, | |
997 | .off1 = td_var_offset(start_offset), | |
998 | .help = "Start IO from this offset", | |
999 | .def = "0", | |
1000 | }, | |
214e1eca JA |
1001 | { |
1002 | .name = "bs", | |
d3aad8f2 | 1003 | .alias = "blocksize", |
e01b22b8 | 1004 | .type = FIO_OPT_INT, |
214e1eca JA |
1005 | .off1 = td_var_offset(bs[DDIR_READ]), |
1006 | .off2 = td_var_offset(bs[DDIR_WRITE]), | |
c3edbdba | 1007 | .minval = 1, |
214e1eca JA |
1008 | .help = "Block size unit", |
1009 | .def = "4k", | |
67a1000f | 1010 | .parent = "rw", |
214e1eca | 1011 | }, |
2b7a01d0 JA |
1012 | { |
1013 | .name = "ba", | |
1014 | .alias = "blockalign", | |
e01b22b8 | 1015 | .type = FIO_OPT_INT, |
2b7a01d0 JA |
1016 | .off1 = td_var_offset(ba[DDIR_READ]), |
1017 | .off2 = td_var_offset(ba[DDIR_WRITE]), | |
1018 | .minval = 1, | |
1019 | .help = "IO block offset alignment", | |
1020 | .parent = "rw", | |
1021 | }, | |
214e1eca JA |
1022 | { |
1023 | .name = "bsrange", | |
d3aad8f2 | 1024 | .alias = "blocksize_range", |
214e1eca JA |
1025 | .type = FIO_OPT_RANGE, |
1026 | .off1 = td_var_offset(min_bs[DDIR_READ]), | |
1027 | .off2 = td_var_offset(max_bs[DDIR_READ]), | |
1028 | .off3 = td_var_offset(min_bs[DDIR_WRITE]), | |
1029 | .off4 = td_var_offset(max_bs[DDIR_WRITE]), | |
c3edbdba | 1030 | .minval = 1, |
214e1eca | 1031 | .help = "Set block size range (in more detail than bs)", |
67a1000f | 1032 | .parent = "rw", |
214e1eca | 1033 | }, |
564ca972 JA |
1034 | { |
1035 | .name = "bssplit", | |
1036 | .type = FIO_OPT_STR, | |
1037 | .cb = str_bssplit_cb, | |
1038 | .help = "Set a specific mix of block sizes", | |
1039 | .parent = "rw", | |
1040 | }, | |
214e1eca JA |
1041 | { |
1042 | .name = "bs_unaligned", | |
d3aad8f2 | 1043 | .alias = "blocksize_unaligned", |
214e1eca JA |
1044 | .type = FIO_OPT_STR_SET, |
1045 | .off1 = td_var_offset(bs_unaligned), | |
1046 | .help = "Don't sector align IO buffer sizes", | |
67a1000f | 1047 | .parent = "rw", |
214e1eca JA |
1048 | }, |
1049 | { | |
1050 | .name = "randrepeat", | |
1051 | .type = FIO_OPT_BOOL, | |
1052 | .off1 = td_var_offset(rand_repeatable), | |
1053 | .help = "Use repeatable random IO pattern", | |
1054 | .def = "1", | |
67a1000f | 1055 | .parent = "rw", |
214e1eca JA |
1056 | }, |
1057 | { | |
1058 | .name = "norandommap", | |
1059 | .type = FIO_OPT_STR_SET, | |
1060 | .off1 = td_var_offset(norandommap), | |
1061 | .help = "Accept potential duplicate random blocks", | |
67a1000f | 1062 | .parent = "rw", |
214e1eca | 1063 | }, |
2b386d25 JA |
1064 | { |
1065 | .name = "softrandommap", | |
1066 | .type = FIO_OPT_BOOL, | |
1067 | .off1 = td_var_offset(softrandommap), | |
f66ab3c8 | 1068 | .help = "Set norandommap if randommap allocation fails", |
2b386d25 JA |
1069 | .parent = "norandommap", |
1070 | .def = "0", | |
1071 | }, | |
214e1eca JA |
1072 | { |
1073 | .name = "nrfiles", | |
1074 | .type = FIO_OPT_INT, | |
1075 | .off1 = td_var_offset(nr_files), | |
1076 | .help = "Split job workload between this number of files", | |
1077 | .def = "1", | |
1078 | }, | |
1079 | { | |
1080 | .name = "openfiles", | |
1081 | .type = FIO_OPT_INT, | |
1082 | .off1 = td_var_offset(open_files), | |
1083 | .help = "Number of files to keep open at the same time", | |
1084 | }, | |
1085 | { | |
1086 | .name = "file_service_type", | |
1087 | .type = FIO_OPT_STR, | |
1088 | .cb = str_fst_cb, | |
1089 | .off1 = td_var_offset(file_service_type), | |
1090 | .help = "How to select which file to service next", | |
1091 | .def = "roundrobin", | |
1092 | .posval = { | |
1093 | { .ival = "random", | |
1094 | .oval = FIO_FSERVICE_RANDOM, | |
1095 | .help = "Choose a file at random", | |
1096 | }, | |
1097 | { .ival = "roundrobin", | |
1098 | .oval = FIO_FSERVICE_RR, | |
1099 | .help = "Round robin select files", | |
1100 | }, | |
a086c257 JA |
1101 | { .ival = "sequential", |
1102 | .oval = FIO_FSERVICE_SEQ, | |
1103 | .help = "Finish one file before moving to the next", | |
1104 | }, | |
214e1eca | 1105 | }, |
67a1000f JA |
1106 | .parent = "nrfiles", |
1107 | }, | |
7bc8c2cf JA |
1108 | #ifdef FIO_HAVE_FALLOCATE |
1109 | { | |
1110 | .name = "fallocate", | |
1111 | .type = FIO_OPT_BOOL, | |
1112 | .off1 = td_var_offset(fallocate), | |
1113 | .help = "Use fallocate() when laying out files", | |
1114 | .def = "1", | |
1115 | }, | |
1116 | #endif | |
67a1000f JA |
1117 | { |
1118 | .name = "fadvise_hint", | |
1119 | .type = FIO_OPT_BOOL, | |
1120 | .off1 = td_var_offset(fadvise_hint), | |
1121 | .help = "Use fadvise() to advise the kernel on IO pattern", | |
1122 | .def = "1", | |
214e1eca JA |
1123 | }, |
1124 | { | |
1125 | .name = "fsync", | |
1126 | .type = FIO_OPT_INT, | |
1127 | .off1 = td_var_offset(fsync_blocks), | |
1128 | .help = "Issue fsync for writes every given number of blocks", | |
1129 | .def = "0", | |
1130 | }, | |
5f9099ea JA |
1131 | { |
1132 | .name = "fdatasync", | |
1133 | .type = FIO_OPT_INT, | |
1134 | .off1 = td_var_offset(fdatasync_blocks), | |
1135 | .help = "Issue fdatasync for writes every given number of blocks", | |
1136 | .def = "0", | |
1137 | }, | |
44f29692 JA |
1138 | #ifdef FIO_HAVE_SYNC_FILE_RANGE |
1139 | { | |
1140 | .name = "sync_file_range", | |
1141 | .posval = { | |
1142 | { .ival = "wait_before", | |
1143 | .oval = SYNC_FILE_RANGE_WAIT_BEFORE, | |
1144 | .help = "SYNC_FILE_RANGE_WAIT_BEFORE", | |
3843deb3 | 1145 | .or = 1, |
44f29692 JA |
1146 | }, |
1147 | { .ival = "write", | |
1148 | .oval = SYNC_FILE_RANGE_WRITE, | |
1149 | .help = "SYNC_FILE_RANGE_WRITE", | |
3843deb3 | 1150 | .or = 1, |
44f29692 JA |
1151 | }, |
1152 | { | |
1153 | .ival = "wait_after", | |
1154 | .oval = SYNC_FILE_RANGE_WAIT_AFTER, | |
1155 | .help = "SYNC_FILE_RANGE_WAIT_AFTER", | |
3843deb3 | 1156 | .or = 1, |
44f29692 JA |
1157 | }, |
1158 | }, | |
3843deb3 | 1159 | .type = FIO_OPT_STR_MULTI, |
44f29692 JA |
1160 | .cb = str_sfr_cb, |
1161 | .off1 = td_var_offset(sync_file_range), | |
1162 | .help = "Use sync_file_range()", | |
1163 | }, | |
1164 | #endif | |
214e1eca JA |
1165 | { |
1166 | .name = "direct", | |
1167 | .type = FIO_OPT_BOOL, | |
1168 | .off1 = td_var_offset(odirect), | |
1169 | .help = "Use O_DIRECT IO (negates buffered)", | |
1170 | .def = "0", | |
1171 | }, | |
1172 | { | |
1173 | .name = "buffered", | |
1174 | .type = FIO_OPT_BOOL, | |
1175 | .off1 = td_var_offset(odirect), | |
1176 | .neg = 1, | |
1177 | .help = "Use buffered IO (negates direct)", | |
1178 | .def = "1", | |
1179 | }, | |
1180 | { | |
1181 | .name = "overwrite", | |
1182 | .type = FIO_OPT_BOOL, | |
1183 | .off1 = td_var_offset(overwrite), | |
1184 | .help = "When writing, set whether to overwrite current data", | |
1185 | .def = "0", | |
1186 | }, | |
1187 | { | |
1188 | .name = "loops", | |
1189 | .type = FIO_OPT_INT, | |
1190 | .off1 = td_var_offset(loops), | |
1191 | .help = "Number of times to run the job", | |
1192 | .def = "1", | |
1193 | }, | |
1194 | { | |
1195 | .name = "numjobs", | |
1196 | .type = FIO_OPT_INT, | |
1197 | .off1 = td_var_offset(numjobs), | |
1198 | .help = "Duplicate this job this many times", | |
1199 | .def = "1", | |
1200 | }, | |
1201 | { | |
1202 | .name = "startdelay", | |
1203 | .type = FIO_OPT_INT, | |
1204 | .off1 = td_var_offset(start_delay), | |
1205 | .help = "Only start job when this period has passed", | |
1206 | .def = "0", | |
1207 | }, | |
1208 | { | |
1209 | .name = "runtime", | |
1210 | .alias = "timeout", | |
1211 | .type = FIO_OPT_STR_VAL_TIME, | |
1212 | .off1 = td_var_offset(timeout), | |
1213 | .help = "Stop workload when this amount of time has passed", | |
1214 | .def = "0", | |
1215 | }, | |
cf4464ca JA |
1216 | { |
1217 | .name = "time_based", | |
1218 | .type = FIO_OPT_STR_SET, | |
1219 | .off1 = td_var_offset(time_based), | |
1220 | .help = "Keep running until runtime/timeout is met", | |
1221 | }, | |
721938ae JA |
1222 | { |
1223 | .name = "ramp_time", | |
1224 | .type = FIO_OPT_STR_VAL_TIME, | |
1225 | .off1 = td_var_offset(ramp_time), | |
1226 | .help = "Ramp up time before measuring performance", | |
1227 | }, | |
c223da83 JA |
1228 | { |
1229 | .name = "clocksource", | |
1230 | .type = FIO_OPT_STR, | |
1231 | .cb = fio_clock_source_cb, | |
1232 | .off1 = td_var_offset(clocksource), | |
1233 | .help = "What type of timing source to use", | |
c223da83 JA |
1234 | .posval = { |
1235 | { .ival = "gettimeofday", | |
1236 | .oval = CS_GTOD, | |
1237 | .help = "Use gettimeofday(2) for timing", | |
1238 | }, | |
1239 | { .ival = "clock_gettime", | |
1240 | .oval = CS_CGETTIME, | |
1241 | .help = "Use clock_gettime(2) for timing", | |
1242 | }, | |
1243 | #ifdef ARCH_HAVE_CPU_CLOCK | |
1244 | { .ival = "cpu", | |
1245 | .oval = CS_CPUCLOCK, | |
1246 | .help = "Use CPU private clock", | |
1247 | }, | |
1248 | #endif | |
1249 | }, | |
1250 | }, | |
214e1eca JA |
1251 | { |
1252 | .name = "mem", | |
d3aad8f2 | 1253 | .alias = "iomem", |
214e1eca JA |
1254 | .type = FIO_OPT_STR, |
1255 | .cb = str_mem_cb, | |
1256 | .off1 = td_var_offset(mem_type), | |
1257 | .help = "Backing type for IO buffers", | |
1258 | .def = "malloc", | |
1259 | .posval = { | |
1260 | { .ival = "malloc", | |
1261 | .oval = MEM_MALLOC, | |
1262 | .help = "Use malloc(3) for IO buffers", | |
1263 | }, | |
37c8cdfe JA |
1264 | { .ival = "shm", |
1265 | .oval = MEM_SHM, | |
1266 | .help = "Use shared memory segments for IO buffers", | |
1267 | }, | |
214e1eca JA |
1268 | #ifdef FIO_HAVE_HUGETLB |
1269 | { .ival = "shmhuge", | |
1270 | .oval = MEM_SHMHUGE, | |
1271 | .help = "Like shm, but use huge pages", | |
1272 | }, | |
b370e46a | 1273 | #endif |
37c8cdfe JA |
1274 | { .ival = "mmap", |
1275 | .oval = MEM_MMAP, | |
1276 | .help = "Use mmap(2) (file or anon) for IO buffers", | |
1277 | }, | |
214e1eca JA |
1278 | #ifdef FIO_HAVE_HUGETLB |
1279 | { .ival = "mmaphuge", | |
1280 | .oval = MEM_MMAPHUGE, | |
1281 | .help = "Like mmap, but use huge pages", | |
1282 | }, | |
1283 | #endif | |
1284 | }, | |
1285 | }, | |
d529ee19 JA |
1286 | { |
1287 | .name = "iomem_align", | |
1288 | .alias = "mem_align", | |
1289 | .type = FIO_OPT_INT, | |
1290 | .off1 = td_var_offset(mem_align), | |
1291 | .minval = 0, | |
1292 | .help = "IO memory buffer offset alignment", | |
1293 | .def = "0", | |
1294 | .parent = "iomem", | |
1295 | }, | |
214e1eca JA |
1296 | { |
1297 | .name = "verify", | |
1298 | .type = FIO_OPT_STR, | |
1299 | .off1 = td_var_offset(verify), | |
1300 | .help = "Verify data written", | |
1301 | .def = "0", | |
1302 | .posval = { | |
1303 | { .ival = "0", | |
1304 | .oval = VERIFY_NONE, | |
1305 | .help = "Don't do IO verification", | |
1306 | }, | |
fcca4b58 JA |
1307 | { .ival = "md5", |
1308 | .oval = VERIFY_MD5, | |
1309 | .help = "Use md5 checksums for verification", | |
1310 | }, | |
d77a7af3 JA |
1311 | { .ival = "crc64", |
1312 | .oval = VERIFY_CRC64, | |
1313 | .help = "Use crc64 checksums for verification", | |
1314 | }, | |
214e1eca JA |
1315 | { .ival = "crc32", |
1316 | .oval = VERIFY_CRC32, | |
1317 | .help = "Use crc32 checksums for verification", | |
1318 | }, | |
af497e6a JA |
1319 | { .ival = "crc32c-intel", |
1320 | .oval = VERIFY_CRC32C_INTEL, | |
1321 | .help = "Use hw crc32c checksums for verification", | |
1322 | }, | |
bac39e0e JA |
1323 | { .ival = "crc32c", |
1324 | .oval = VERIFY_CRC32C, | |
1325 | .help = "Use crc32c checksums for verification", | |
1326 | }, | |
969f7ed3 JA |
1327 | { .ival = "crc16", |
1328 | .oval = VERIFY_CRC16, | |
1329 | .help = "Use crc16 checksums for verification", | |
1330 | }, | |
1e154bdb JA |
1331 | { .ival = "crc7", |
1332 | .oval = VERIFY_CRC7, | |
1333 | .help = "Use crc7 checksums for verification", | |
1334 | }, | |
7c353ceb JA |
1335 | { .ival = "sha1", |
1336 | .oval = VERIFY_SHA1, | |
1337 | .help = "Use sha1 checksums for verification", | |
1338 | }, | |
cd14cc10 JA |
1339 | { .ival = "sha256", |
1340 | .oval = VERIFY_SHA256, | |
1341 | .help = "Use sha256 checksums for verification", | |
1342 | }, | |
1343 | { .ival = "sha512", | |
1344 | .oval = VERIFY_SHA512, | |
1345 | .help = "Use sha512 checksums for verification", | |
1346 | }, | |
7437ee87 SL |
1347 | { .ival = "meta", |
1348 | .oval = VERIFY_META, | |
1349 | .help = "Use io information", | |
1350 | }, | |
36690c9b JA |
1351 | { |
1352 | .ival = "null", | |
1353 | .oval = VERIFY_NULL, | |
1354 | .help = "Pretend to verify", | |
1355 | }, | |
214e1eca JA |
1356 | }, |
1357 | }, | |
005c565a JA |
1358 | { |
1359 | .name = "do_verify", | |
68e1f29a | 1360 | .type = FIO_OPT_BOOL, |
005c565a JA |
1361 | .off1 = td_var_offset(do_verify), |
1362 | .help = "Run verification stage after write", | |
1363 | .def = "1", | |
1364 | .parent = "verify", | |
1365 | }, | |
160b966d JA |
1366 | { |
1367 | .name = "verifysort", | |
1368 | .type = FIO_OPT_BOOL, | |
1369 | .off1 = td_var_offset(verifysort), | |
1370 | .help = "Sort written verify blocks for read back", | |
1371 | .def = "1", | |
c83f2df1 | 1372 | .parent = "verify", |
160b966d | 1373 | }, |
3f9f4e26 | 1374 | { |
a59e170d | 1375 | .name = "verify_interval", |
e01b22b8 | 1376 | .type = FIO_OPT_INT, |
a59e170d | 1377 | .off1 = td_var_offset(verify_interval), |
819a9680 | 1378 | .minval = 2 * sizeof(struct verify_header), |
a59e170d | 1379 | .help = "Store verify buffer header every N bytes", |
afdf9352 | 1380 | .parent = "verify", |
3f9f4e26 | 1381 | }, |
546a9142 | 1382 | { |
a59e170d | 1383 | .name = "verify_offset", |
e01b22b8 | 1384 | .type = FIO_OPT_INT, |
a59e170d | 1385 | .help = "Offset verify header location by N bytes", |
546a9142 | 1386 | .def = "0", |
5ec10eaa | 1387 | .cb = str_verify_offset_cb, |
afdf9352 | 1388 | .parent = "verify", |
546a9142 | 1389 | }, |
e28218f3 SL |
1390 | { |
1391 | .name = "verify_pattern", | |
0e92f873 | 1392 | .type = FIO_OPT_STR, |
e28218f3 SL |
1393 | .cb = str_verify_pattern_cb, |
1394 | .help = "Fill pattern for IO buffers", | |
1395 | .parent = "verify", | |
1396 | }, | |
a12a3b4d JA |
1397 | { |
1398 | .name = "verify_fatal", | |
68e1f29a | 1399 | .type = FIO_OPT_BOOL, |
a12a3b4d JA |
1400 | .off1 = td_var_offset(verify_fatal), |
1401 | .def = "0", | |
1402 | .help = "Exit on a single verify failure, don't continue", | |
1403 | .parent = "verify", | |
1404 | }, | |
e8462bd8 JA |
1405 | { |
1406 | .name = "verify_async", | |
1407 | .type = FIO_OPT_INT, | |
1408 | .off1 = td_var_offset(verify_async), | |
1409 | .def = "0", | |
1410 | .help = "Number of async verifier threads to use", | |
1411 | .parent = "verify", | |
1412 | }, | |
1413 | #ifdef FIO_HAVE_CPU_AFFINITY | |
1414 | { | |
1415 | .name = "verify_async_cpus", | |
1416 | .type = FIO_OPT_STR, | |
1417 | .cb = str_verify_cpus_allowed_cb, | |
1418 | .help = "Set CPUs allowed for async verify threads", | |
1419 | .parent = "verify_async", | |
1420 | }, | |
1421 | #endif | |
214e1eca JA |
1422 | { |
1423 | .name = "write_iolog", | |
1424 | .type = FIO_OPT_STR_STORE, | |
1425 | .off1 = td_var_offset(write_iolog_file), | |
1426 | .help = "Store IO pattern to file", | |
1427 | }, | |
1428 | { | |
1429 | .name = "read_iolog", | |
1430 | .type = FIO_OPT_STR_STORE, | |
1431 | .off1 = td_var_offset(read_iolog_file), | |
1432 | .help = "Playback IO pattern from file", | |
1433 | }, | |
1434 | { | |
1435 | .name = "exec_prerun", | |
1436 | .type = FIO_OPT_STR_STORE, | |
1437 | .off1 = td_var_offset(exec_prerun), | |
1438 | .help = "Execute this file prior to running job", | |
1439 | }, | |
1440 | { | |
1441 | .name = "exec_postrun", | |
1442 | .type = FIO_OPT_STR_STORE, | |
1443 | .off1 = td_var_offset(exec_postrun), | |
1444 | .help = "Execute this file after running job", | |
1445 | }, | |
1446 | #ifdef FIO_HAVE_IOSCHED_SWITCH | |
1447 | { | |
1448 | .name = "ioscheduler", | |
1449 | .type = FIO_OPT_STR_STORE, | |
1450 | .off1 = td_var_offset(ioscheduler), | |
1451 | .help = "Use this IO scheduler on the backing device", | |
1452 | }, | |
1453 | #endif | |
1454 | { | |
1455 | .name = "zonesize", | |
1456 | .type = FIO_OPT_STR_VAL, | |
1457 | .off1 = td_var_offset(zone_size), | |
1458 | .help = "Give size of an IO zone", | |
1459 | .def = "0", | |
1460 | }, | |
1461 | { | |
1462 | .name = "zoneskip", | |
1463 | .type = FIO_OPT_STR_VAL, | |
1464 | .off1 = td_var_offset(zone_skip), | |
1465 | .help = "Space between IO zones", | |
1466 | .def = "0", | |
1467 | }, | |
1468 | { | |
1469 | .name = "lockmem", | |
1470 | .type = FIO_OPT_STR_VAL, | |
1471 | .cb = str_lockmem_cb, | |
1472 | .help = "Lock down this amount of memory", | |
1473 | .def = "0", | |
1474 | }, | |
214e1eca JA |
1475 | { |
1476 | .name = "rwmixread", | |
1477 | .type = FIO_OPT_INT, | |
cb499fc4 | 1478 | .cb = str_rwmix_read_cb, |
214e1eca JA |
1479 | .maxval = 100, |
1480 | .help = "Percentage of mixed workload that is reads", | |
1481 | .def = "50", | |
1482 | }, | |
1483 | { | |
1484 | .name = "rwmixwrite", | |
1485 | .type = FIO_OPT_INT, | |
cb499fc4 | 1486 | .cb = str_rwmix_write_cb, |
214e1eca JA |
1487 | .maxval = 100, |
1488 | .help = "Percentage of mixed workload that is writes", | |
1489 | .def = "50", | |
1490 | }, | |
afdf9352 JA |
1491 | { |
1492 | .name = "rwmixcycle", | |
15ca150e | 1493 | .type = FIO_OPT_DEPRECATED, |
afdf9352 | 1494 | }, |
214e1eca JA |
1495 | { |
1496 | .name = "nice", | |
1497 | .type = FIO_OPT_INT, | |
1498 | .off1 = td_var_offset(nice), | |
1499 | .help = "Set job CPU nice value", | |
1500 | .minval = -19, | |
1501 | .maxval = 20, | |
1502 | .def = "0", | |
1503 | }, | |
1504 | #ifdef FIO_HAVE_IOPRIO | |
1505 | { | |
1506 | .name = "prio", | |
1507 | .type = FIO_OPT_INT, | |
1508 | .cb = str_prio_cb, | |
1509 | .help = "Set job IO priority value", | |
1510 | .minval = 0, | |
1511 | .maxval = 7, | |
1512 | }, | |
1513 | { | |
1514 | .name = "prioclass", | |
1515 | .type = FIO_OPT_INT, | |
1516 | .cb = str_prioclass_cb, | |
1517 | .help = "Set job IO priority class", | |
1518 | .minval = 0, | |
1519 | .maxval = 3, | |
1520 | }, | |
1521 | #endif | |
1522 | { | |
1523 | .name = "thinktime", | |
1524 | .type = FIO_OPT_INT, | |
1525 | .off1 = td_var_offset(thinktime), | |
1526 | .help = "Idle time between IO buffers (usec)", | |
1527 | .def = "0", | |
1528 | }, | |
1529 | { | |
1530 | .name = "thinktime_spin", | |
1531 | .type = FIO_OPT_INT, | |
1532 | .off1 = td_var_offset(thinktime_spin), | |
1533 | .help = "Start think time by spinning this amount (usec)", | |
1534 | .def = "0", | |
afdf9352 | 1535 | .parent = "thinktime", |
214e1eca JA |
1536 | }, |
1537 | { | |
1538 | .name = "thinktime_blocks", | |
1539 | .type = FIO_OPT_INT, | |
1540 | .off1 = td_var_offset(thinktime_blocks), | |
1541 | .help = "IO buffer period between 'thinktime'", | |
1542 | .def = "1", | |
afdf9352 | 1543 | .parent = "thinktime", |
214e1eca JA |
1544 | }, |
1545 | { | |
1546 | .name = "rate", | |
e01b22b8 | 1547 | .type = FIO_OPT_INT, |
581e7141 JA |
1548 | .off1 = td_var_offset(rate[0]), |
1549 | .off2 = td_var_offset(rate[1]), | |
214e1eca JA |
1550 | .help = "Set bandwidth rate", |
1551 | }, | |
1552 | { | |
1553 | .name = "ratemin", | |
e01b22b8 | 1554 | .type = FIO_OPT_INT, |
581e7141 JA |
1555 | .off1 = td_var_offset(ratemin[0]), |
1556 | .off2 = td_var_offset(ratemin[1]), | |
4e991c23 | 1557 | .help = "Job must meet this rate or it will be shutdown", |
afdf9352 | 1558 | .parent = "rate", |
4e991c23 JA |
1559 | }, |
1560 | { | |
1561 | .name = "rate_iops", | |
e01b22b8 | 1562 | .type = FIO_OPT_INT, |
581e7141 JA |
1563 | .off1 = td_var_offset(rate_iops[0]), |
1564 | .off2 = td_var_offset(rate_iops[1]), | |
4e991c23 JA |
1565 | .help = "Limit IO used to this number of IO operations/sec", |
1566 | }, | |
1567 | { | |
1568 | .name = "rate_iops_min", | |
e01b22b8 | 1569 | .type = FIO_OPT_INT, |
581e7141 JA |
1570 | .off1 = td_var_offset(rate_iops_min[0]), |
1571 | .off2 = td_var_offset(rate_iops_min[1]), | |
4e991c23 | 1572 | .help = "Job must meet this rate or it will be shutdown", |
afdf9352 | 1573 | .parent = "rate_iops", |
214e1eca JA |
1574 | }, |
1575 | { | |
1576 | .name = "ratecycle", | |
1577 | .type = FIO_OPT_INT, | |
1578 | .off1 = td_var_offset(ratecycle), | |
1579 | .help = "Window average for rate limits (msec)", | |
1580 | .def = "1000", | |
afdf9352 | 1581 | .parent = "rate", |
214e1eca JA |
1582 | }, |
1583 | { | |
1584 | .name = "invalidate", | |
1585 | .type = FIO_OPT_BOOL, | |
1586 | .off1 = td_var_offset(invalidate_cache), | |
1587 | .help = "Invalidate buffer/page cache prior to running job", | |
1588 | .def = "1", | |
1589 | }, | |
1590 | { | |
1591 | .name = "sync", | |
1592 | .type = FIO_OPT_BOOL, | |
1593 | .off1 = td_var_offset(sync_io), | |
1594 | .help = "Use O_SYNC for buffered writes", | |
1595 | .def = "0", | |
67a1000f | 1596 | .parent = "buffered", |
214e1eca JA |
1597 | }, |
1598 | { | |
1599 | .name = "bwavgtime", | |
1600 | .type = FIO_OPT_INT, | |
1601 | .off1 = td_var_offset(bw_avg_time), | |
5ec10eaa JA |
1602 | .help = "Time window over which to calculate bandwidth" |
1603 | " (msec)", | |
214e1eca JA |
1604 | .def = "500", |
1605 | }, | |
1606 | { | |
1607 | .name = "create_serialize", | |
1608 | .type = FIO_OPT_BOOL, | |
1609 | .off1 = td_var_offset(create_serialize), | |
1610 | .help = "Serialize creating of job files", | |
1611 | .def = "1", | |
1612 | }, | |
1613 | { | |
1614 | .name = "create_fsync", | |
1615 | .type = FIO_OPT_BOOL, | |
1616 | .off1 = td_var_offset(create_fsync), | |
1617 | .help = "Fsync file after creation", | |
1618 | .def = "1", | |
1619 | }, | |
814452bd JA |
1620 | { |
1621 | .name = "create_on_open", | |
1622 | .type = FIO_OPT_BOOL, | |
1623 | .off1 = td_var_offset(create_on_open), | |
1624 | .help = "Create files when they are opened for IO", | |
1625 | .def = "0", | |
1626 | }, | |
0b9d69ec | 1627 | { |
afad68f7 ZY |
1628 | .name = "pre_read", |
1629 | .type = FIO_OPT_BOOL, | |
1630 | .off1 = td_var_offset(pre_read), | |
1631 | .help = "Preread files before starting official testing", | |
1632 | .def = "0", | |
1633 | }, | |
214e1eca JA |
1634 | { |
1635 | .name = "cpuload", | |
1636 | .type = FIO_OPT_INT, | |
1637 | .off1 = td_var_offset(cpuload), | |
1638 | .help = "Use this percentage of CPU", | |
1639 | }, | |
1640 | { | |
1641 | .name = "cpuchunks", | |
1642 | .type = FIO_OPT_INT, | |
1643 | .off1 = td_var_offset(cpucycle), | |
1644 | .help = "Length of the CPU burn cycles (usecs)", | |
1645 | .def = "50000", | |
67a1000f | 1646 | .parent = "cpuload", |
214e1eca JA |
1647 | }, |
1648 | #ifdef FIO_HAVE_CPU_AFFINITY | |
1649 | { | |
1650 | .name = "cpumask", | |
1651 | .type = FIO_OPT_INT, | |
1652 | .cb = str_cpumask_cb, | |
1653 | .help = "CPU affinity mask", | |
1654 | }, | |
d2e268b0 JA |
1655 | { |
1656 | .name = "cpus_allowed", | |
1657 | .type = FIO_OPT_STR, | |
1658 | .cb = str_cpus_allowed_cb, | |
1659 | .help = "Set CPUs allowed", | |
1660 | }, | |
214e1eca JA |
1661 | #endif |
1662 | { | |
1663 | .name = "end_fsync", | |
1664 | .type = FIO_OPT_BOOL, | |
1665 | .off1 = td_var_offset(end_fsync), | |
1666 | .help = "Include fsync at the end of job", | |
1667 | .def = "0", | |
1668 | }, | |
1669 | { | |
1670 | .name = "fsync_on_close", | |
1671 | .type = FIO_OPT_BOOL, | |
1672 | .off1 = td_var_offset(fsync_on_close), | |
1673 | .help = "fsync files on close", | |
1674 | .def = "0", | |
1675 | }, | |
1676 | { | |
1677 | .name = "unlink", | |
1678 | .type = FIO_OPT_BOOL, | |
1679 | .off1 = td_var_offset(unlink), | |
1680 | .help = "Unlink created files after job has completed", | |
1681 | .def = "0", | |
1682 | }, | |
1683 | { | |
1684 | .name = "exitall", | |
1685 | .type = FIO_OPT_STR_SET, | |
1686 | .cb = str_exitall_cb, | |
1687 | .help = "Terminate all jobs when one exits", | |
1688 | }, | |
1689 | { | |
1690 | .name = "stonewall", | |
1691 | .type = FIO_OPT_STR_SET, | |
1692 | .off1 = td_var_offset(stonewall), | |
1693 | .help = "Insert a hard barrier between this job and previous", | |
1694 | }, | |
b3d62a75 JA |
1695 | { |
1696 | .name = "new_group", | |
1697 | .type = FIO_OPT_STR_SET, | |
1698 | .off1 = td_var_offset(new_group), | |
1699 | .help = "Mark the start of a new group (for reporting)", | |
1700 | }, | |
214e1eca JA |
1701 | { |
1702 | .name = "thread", | |
1703 | .type = FIO_OPT_STR_SET, | |
1704 | .off1 = td_var_offset(use_thread), | |
1705 | .help = "Use threads instead of forks", | |
1706 | }, | |
1707 | { | |
1708 | .name = "write_bw_log", | |
e3cedca7 | 1709 | .type = FIO_OPT_STR, |
214e1eca | 1710 | .off1 = td_var_offset(write_bw_log), |
e3cedca7 | 1711 | .cb = str_write_bw_log_cb, |
214e1eca JA |
1712 | .help = "Write log of bandwidth during run", |
1713 | }, | |
1714 | { | |
1715 | .name = "write_lat_log", | |
e3cedca7 | 1716 | .type = FIO_OPT_STR, |
214e1eca | 1717 | .off1 = td_var_offset(write_lat_log), |
e3cedca7 | 1718 | .cb = str_write_lat_log_cb, |
214e1eca JA |
1719 | .help = "Write log of latency during run", |
1720 | }, | |
1721 | { | |
1722 | .name = "hugepage-size", | |
e01b22b8 | 1723 | .type = FIO_OPT_INT, |
214e1eca JA |
1724 | .off1 = td_var_offset(hugepage_size), |
1725 | .help = "When using hugepages, specify size of each page", | |
1726 | .def = __stringify(FIO_HUGE_PAGE), | |
1727 | }, | |
1728 | { | |
1729 | .name = "group_reporting", | |
1730 | .type = FIO_OPT_STR_SET, | |
1731 | .off1 = td_var_offset(group_reporting), | |
1732 | .help = "Do reporting on a per-group basis", | |
1733 | }, | |
e9459e5a JA |
1734 | { |
1735 | .name = "zero_buffers", | |
1736 | .type = FIO_OPT_STR_SET, | |
1737 | .off1 = td_var_offset(zero_buffers), | |
1738 | .help = "Init IO buffers to all zeroes", | |
1739 | }, | |
5973cafb JA |
1740 | { |
1741 | .name = "refill_buffers", | |
1742 | .type = FIO_OPT_STR_SET, | |
1743 | .off1 = td_var_offset(refill_buffers), | |
1744 | .help = "Refill IO buffers on every IO submit", | |
1745 | }, | |
0a839f30 JA |
1746 | #ifdef FIO_HAVE_DISK_UTIL |
1747 | { | |
1748 | .name = "disk_util", | |
1749 | .type = FIO_OPT_BOOL, | |
1750 | .off1 = td_var_offset(do_disk_util), | |
f66ab3c8 | 1751 | .help = "Log disk utilization statistics", |
0a839f30 JA |
1752 | .def = "1", |
1753 | }, | |
1754 | #endif | |
993bf48b JA |
1755 | { |
1756 | .name = "gtod_reduce", | |
1757 | .type = FIO_OPT_BOOL, | |
1758 | .help = "Greatly reduce number of gettimeofday() calls", | |
1759 | .cb = str_gtod_reduce_cb, | |
1760 | .def = "0", | |
1761 | }, | |
9520ebb9 JA |
1762 | { |
1763 | .name = "disable_clat", | |
1764 | .type = FIO_OPT_BOOL, | |
1765 | .off1 = td_var_offset(disable_clat), | |
1766 | .help = "Disable completion latency numbers", | |
993bf48b | 1767 | .parent = "gtod_reduce", |
9520ebb9 JA |
1768 | .def = "0", |
1769 | }, | |
1770 | { | |
1771 | .name = "disable_slat", | |
1772 | .type = FIO_OPT_BOOL, | |
1773 | .off1 = td_var_offset(disable_slat), | |
1774 | .help = "Disable submissionn latency numbers", | |
993bf48b | 1775 | .parent = "gtod_reduce", |
9520ebb9 JA |
1776 | .def = "0", |
1777 | }, | |
1778 | { | |
1779 | .name = "disable_bw_measurement", | |
1780 | .type = FIO_OPT_BOOL, | |
1781 | .off1 = td_var_offset(disable_bw), | |
1782 | .help = "Disable bandwidth logging", | |
993bf48b | 1783 | .parent = "gtod_reduce", |
9520ebb9 JA |
1784 | .def = "0", |
1785 | }, | |
be4ecfdf JA |
1786 | { |
1787 | .name = "gtod_cpu", | |
1788 | .type = FIO_OPT_INT, | |
1789 | .cb = str_gtod_cpu_cb, | |
1790 | .help = "Setup dedicated gettimeofday() thread on this CPU", | |
29d43ff9 | 1791 | .verify = gtod_cpu_verify, |
be4ecfdf | 1792 | }, |
f2bba182 RR |
1793 | { |
1794 | .name = "continue_on_error", | |
1795 | .type = FIO_OPT_BOOL, | |
1796 | .off1 = td_var_offset(continue_on_error), | |
1797 | .help = "Continue on non-fatal errors during I/O", | |
1798 | .def = "0", | |
1799 | }, | |
9ac8a797 JA |
1800 | { |
1801 | .name = "profile", | |
79d16311 | 1802 | .type = FIO_OPT_STR_STORE, |
9ac8a797 | 1803 | .off1 = td_var_offset(profile), |
9ac8a797 JA |
1804 | .help = "Select a specific builtin performance test", |
1805 | }, | |
a696fa2a JA |
1806 | { |
1807 | .name = "cgroup", | |
1808 | .type = FIO_OPT_STR_STORE, | |
1809 | .off1 = td_var_offset(cgroup), | |
1810 | .help = "Add job to cgroup of this name", | |
1811 | }, | |
1812 | { | |
1813 | .name = "cgroup_weight", | |
1814 | .type = FIO_OPT_INT, | |
1815 | .off1 = td_var_offset(cgroup_weight), | |
1816 | .help = "Use given weight for cgroup", | |
1817 | .minval = 100, | |
1818 | .maxval = 1000, | |
a696fa2a | 1819 | }, |
7de87099 VG |
1820 | { |
1821 | .name = "cgroup_nodelete", | |
1822 | .type = FIO_OPT_BOOL, | |
1823 | .off1 = td_var_offset(cgroup_nodelete), | |
1824 | .help = "Do not delete cgroups after job completion", | |
1825 | .def = "0", | |
1826 | }, | |
e0b0d892 JA |
1827 | { |
1828 | .name = "uid", | |
1829 | .type = FIO_OPT_INT, | |
1830 | .off1 = td_var_offset(uid), | |
1831 | .help = "Run job with this user ID", | |
1832 | }, | |
1833 | { | |
1834 | .name = "gid", | |
1835 | .type = FIO_OPT_INT, | |
1836 | .off1 = td_var_offset(gid), | |
1837 | .help = "Run job with this group ID", | |
1838 | }, | |
214e1eca JA |
1839 | { |
1840 | .name = NULL, | |
1841 | }, | |
1842 | }; | |
1843 | ||
17af15d4 JA |
1844 | static void add_to_lopt(struct option *lopt, struct fio_option *o, |
1845 | const char *name) | |
9f81736c | 1846 | { |
17af15d4 | 1847 | lopt->name = (char *) name; |
9f81736c JA |
1848 | lopt->val = FIO_GETOPT_JOB; |
1849 | if (o->type == FIO_OPT_STR_SET) | |
1850 | lopt->has_arg = no_argument; | |
1851 | else | |
1852 | lopt->has_arg = required_argument; | |
1853 | } | |
1854 | ||
214e1eca JA |
1855 | void fio_options_dup_and_init(struct option *long_options) |
1856 | { | |
1857 | struct fio_option *o; | |
1858 | unsigned int i; | |
1859 | ||
1860 | options_init(options); | |
1861 | ||
1862 | i = 0; | |
1863 | while (long_options[i].name) | |
1864 | i++; | |
1865 | ||
1866 | o = &options[0]; | |
1867 | while (o->name) { | |
17af15d4 JA |
1868 | add_to_lopt(&long_options[i], o, o->name); |
1869 | if (o->alias) { | |
1870 | i++; | |
1871 | add_to_lopt(&long_options[i], o, o->alias); | |
1872 | } | |
214e1eca JA |
1873 | |
1874 | i++; | |
1875 | o++; | |
1876 | assert(i < FIO_NR_OPTIONS); | |
1877 | } | |
1878 | } | |
1879 | ||
74929ac2 JA |
1880 | struct fio_keyword { |
1881 | const char *word; | |
1882 | const char *desc; | |
1883 | char *replace; | |
1884 | }; | |
1885 | ||
1886 | static struct fio_keyword fio_keywords[] = { | |
1887 | { | |
1888 | .word = "$pagesize", | |
1889 | .desc = "Page size in the system", | |
1890 | }, | |
1891 | { | |
1892 | .word = "$mb_memory", | |
1893 | .desc = "Megabytes of memory online", | |
1894 | }, | |
1895 | { | |
1896 | .word = "$ncpus", | |
1897 | .desc = "Number of CPUs online in the system", | |
1898 | }, | |
1899 | { | |
1900 | .word = NULL, | |
1901 | }, | |
1902 | }; | |
1903 | ||
1904 | void fio_keywords_init(void) | |
1905 | { | |
3b2e1464 | 1906 | unsigned long long mb_memory; |
74929ac2 JA |
1907 | char buf[128]; |
1908 | long l; | |
1909 | ||
1910 | sprintf(buf, "%lu", page_size); | |
1911 | fio_keywords[0].replace = strdup(buf); | |
1912 | ||
3b2e1464 JA |
1913 | mb_memory = os_phys_mem() / page_size; |
1914 | sprintf(buf, "%llu", mb_memory); | |
74929ac2 JA |
1915 | fio_keywords[1].replace = strdup(buf); |
1916 | ||
1917 | l = sysconf(_SC_NPROCESSORS_ONLN); | |
1918 | sprintf(buf, "%lu", l); | |
1919 | fio_keywords[2].replace = strdup(buf); | |
1920 | } | |
1921 | ||
892a6ffc JA |
1922 | #define BC_APP "bc" |
1923 | ||
1924 | static char *bc_calc(char *str) | |
1925 | { | |
1926 | char *buf, *tmp, opt[80]; | |
1927 | FILE *f; | |
1928 | int ret; | |
1929 | ||
1930 | /* | |
1931 | * No math, just return string | |
1932 | */ | |
1933 | if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') && | |
1934 | !strchr(str, '/')) | |
1935 | return str; | |
1936 | ||
1937 | /* | |
1938 | * Split option from value, we only need to calculate the value | |
1939 | */ | |
1940 | tmp = strchr(str, '='); | |
1941 | if (!tmp) | |
1942 | return str; | |
1943 | ||
1944 | tmp++; | |
9ac8a797 | 1945 | memset(opt, 0, sizeof(opt)); |
892a6ffc JA |
1946 | strncpy(opt, str, tmp - str); |
1947 | ||
1948 | buf = malloc(128); | |
1949 | ||
1950 | sprintf(buf, "which %s > /dev/null", BC_APP); | |
1951 | if (system(buf)) { | |
1952 | log_err("fio: bc is needed for performing math\n"); | |
1953 | free(buf); | |
1954 | return NULL; | |
1955 | } | |
1956 | ||
1957 | sprintf(buf, "echo %s | %s", tmp, BC_APP); | |
1958 | f = popen(buf, "r"); | |
1959 | if (!f) { | |
1960 | free(buf); | |
1961 | return NULL; | |
1962 | } | |
1963 | ||
1964 | ret = fread(buf, 1, 128, f); | |
1965 | if (ret <= 0) { | |
1966 | free(buf); | |
1967 | return NULL; | |
1968 | } | |
1969 | ||
1970 | buf[ret - 1] = '\0'; | |
1971 | strcat(opt, buf); | |
1972 | strcpy(buf, opt); | |
1973 | pclose(f); | |
1974 | free(str); | |
1975 | return buf; | |
1976 | } | |
1977 | ||
74929ac2 JA |
1978 | /* |
1979 | * Look for reserved variable names and replace them with real values | |
1980 | */ | |
1981 | static char *fio_keyword_replace(char *opt) | |
1982 | { | |
1983 | char *s; | |
1984 | int i; | |
1985 | ||
1986 | for (i = 0; fio_keywords[i].word != NULL; i++) { | |
1987 | struct fio_keyword *kw = &fio_keywords[i]; | |
1988 | ||
1989 | while ((s = strstr(opt, kw->word)) != NULL) { | |
1990 | char *new = malloc(strlen(opt) + 1); | |
1991 | char *o_org = opt; | |
1992 | int olen = s - opt; | |
1993 | int len; | |
1994 | ||
1995 | /* | |
1996 | * Copy part of the string before the keyword and | |
1997 | * sprintf() the replacement after it. | |
1998 | */ | |
1999 | memcpy(new, opt, olen); | |
2000 | len = sprintf(new + olen, "%s", kw->replace); | |
2001 | ||
2002 | /* | |
2003 | * If there's more in the original string, copy that | |
2004 | * in too | |
2005 | */ | |
2006 | opt += strlen(kw->word) + olen; | |
2007 | if (strlen(opt)) | |
2008 | memcpy(new + olen + len, opt, opt - o_org - 1); | |
2009 | ||
2010 | /* | |
2011 | * replace opt and free the old opt | |
2012 | */ | |
2013 | opt = new; | |
9ac8a797 | 2014 | //free(o_org); |
7a958bd5 JA |
2015 | |
2016 | /* | |
2017 | * Check for potential math and invoke bc, if possible | |
2018 | */ | |
2019 | opt = bc_calc(opt); | |
74929ac2 JA |
2020 | } |
2021 | } | |
2022 | ||
7a958bd5 | 2023 | return opt; |
74929ac2 JA |
2024 | } |
2025 | ||
3b8b7135 | 2026 | int fio_options_parse(struct thread_data *td, char **opts, int num_opts) |
214e1eca | 2027 | { |
3b8b7135 JA |
2028 | int i, ret; |
2029 | ||
2030 | sort_options(opts, options, num_opts); | |
2031 | ||
74929ac2 JA |
2032 | for (ret = 0, i = 0; i < num_opts; i++) { |
2033 | opts[i] = fio_keyword_replace(opts[i]); | |
07b3232d | 2034 | ret |= parse_option(opts[i], options, td); |
74929ac2 | 2035 | } |
3b8b7135 JA |
2036 | |
2037 | return ret; | |
214e1eca JA |
2038 | } |
2039 | ||
2040 | int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val) | |
2041 | { | |
07b3232d | 2042 | return parse_cmd_option(opt, val, options, td); |
214e1eca JA |
2043 | } |
2044 | ||
2045 | void fio_fill_default_options(struct thread_data *td) | |
2046 | { | |
2047 | fill_default_options(td, options); | |
2048 | } | |
2049 | ||
2050 | int fio_show_option_help(const char *opt) | |
2051 | { | |
07b3232d | 2052 | return show_cmd_help(options, opt); |
214e1eca | 2053 | } |
d23bb327 JA |
2054 | |
2055 | static void __options_mem(struct thread_data *td, int alloc) | |
2056 | { | |
2057 | struct thread_options *o = &td->o; | |
2058 | struct fio_option *opt; | |
2059 | char **ptr; | |
2060 | int i; | |
2061 | ||
2062 | for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) { | |
2063 | if (opt->type != FIO_OPT_STR_STORE) | |
2064 | continue; | |
2065 | ||
2066 | ptr = (void *) o + opt->off1; | |
2067 | if (*ptr) { | |
2068 | if (alloc) | |
2069 | *ptr = strdup(*ptr); | |
2070 | else { | |
2071 | free(*ptr); | |
2072 | *ptr = NULL; | |
2073 | } | |
2074 | } | |
2075 | } | |
2076 | } | |
2077 | ||
2078 | /* | |
2079 | * dupe FIO_OPT_STR_STORE options | |
2080 | */ | |
2081 | void options_mem_dupe(struct thread_data *td) | |
2082 | { | |
2083 | __options_mem(td, 1); | |
2084 | } | |
2085 | ||
22d66213 | 2086 | void options_mem_free(struct thread_data fio_unused *td) |
d23bb327 | 2087 | { |
22d66213 | 2088 | #if 0 |
d23bb327 | 2089 | __options_mem(td, 0); |
22d66213 | 2090 | #endif |
d23bb327 | 2091 | } |
d6978a32 JA |
2092 | |
2093 | unsigned int fio_get_kb_base(void *data) | |
2094 | { | |
2095 | struct thread_data *td = data; | |
2096 | unsigned int kb_base = 0; | |
2097 | ||
2098 | if (td) | |
2099 | kb_base = td->o.kb_base; | |
2100 | if (!kb_base) | |
2101 | kb_base = 1024; | |
2102 | ||
2103 | return kb_base; | |
2104 | } | |
9f988e2e | 2105 | |
07b3232d | 2106 | int add_option(struct fio_option *o) |
9f988e2e | 2107 | { |
07b3232d JA |
2108 | struct fio_option *__o; |
2109 | int opt_index = 0; | |
2110 | ||
2111 | __o = options; | |
2112 | while (__o->name) { | |
2113 | opt_index++; | |
2114 | __o++; | |
2115 | } | |
2116 | ||
2117 | memcpy(&options[opt_index], o, sizeof(*o)); | |
2118 | return 0; | |
9f988e2e | 2119 | } |
e2de69da | 2120 | |
07b3232d | 2121 | void invalidate_profile_options(const char *prof_name) |
e2de69da | 2122 | { |
07b3232d | 2123 | struct fio_option *o; |
e2de69da | 2124 | |
07b3232d JA |
2125 | o = options; |
2126 | while (o->name) { | |
2127 | if (o->prof_name && !strcmp(o->prof_name, prof_name)) { | |
2128 | o->type = FIO_OPT_INVALID; | |
2129 | o->prof_name = NULL; | |
2130 | } | |
2131 | o++; | |
e2de69da JA |
2132 | } |
2133 | } | |
f5b6bb85 JA |
2134 | |
2135 | void add_opt_posval(const char *optname, const char *ival, const char *help) | |
2136 | { | |
2137 | struct fio_option *o; | |
2138 | unsigned int i; | |
2139 | ||
2140 | o = find_option(options, optname); | |
2141 | if (!o) | |
2142 | return; | |
2143 | ||
2144 | for (i = 0; i < PARSE_MAX_VP; i++) { | |
2145 | if (o->posval[i].ival) | |
2146 | continue; | |
2147 | ||
2148 | o->posval[i].ival = ival; | |
2149 | o->posval[i].help = help; | |
2150 | break; | |
2151 | } | |
2152 | } | |
2153 | ||
2154 | void del_opt_posval(const char *optname, const char *ival) | |
2155 | { | |
2156 | struct fio_option *o; | |
2157 | unsigned int i; | |
2158 | ||
2159 | o = find_option(options, optname); | |
2160 | if (!o) | |
2161 | return; | |
2162 | ||
2163 | for (i = 0; i < PARSE_MAX_VP; i++) { | |
2164 | if (!o->posval[i].ival) | |
2165 | continue; | |
2166 | if (strcmp(o->posval[i].ival, ival)) | |
2167 | continue; | |
2168 | ||
2169 | o->posval[i].ival = NULL; | |
2170 | o->posval[i].help = NULL; | |
2171 | } | |
2172 | } |