blob: e2daf37df09c26be2663a36a0b2f3aa031477ba8 [file] [log] [blame]
Jens Axboe214e1ec2007-03-15 10:48:13 +01001#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>
Jens Axboe921c7662008-03-26 09:17:55 +01008#include <libgen.h>
Jens Axboe5921e802008-05-30 15:02:38 +02009#include <fcntl.h>
10#include <sys/types.h>
11#include <sys/stat.h>
Jens Axboe214e1ec2007-03-15 10:48:13 +010012
13#include "fio.h"
Jens Axboe4f5af7b2009-06-03 08:45:40 +020014#include "verify.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010015#include "parse.h"
Jens Axboeeef32352008-06-02 13:31:26 +020016#include "lib/fls.h"
Jens Axboe9f988e22010-03-04 10:42:38 +010017#include "options.h"
Jens Axboe214e1ec2007-03-15 10:48:13 +010018
Jens Axboe214e1ec2007-03-15 10:48:13 +010019/*
20 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
21 */
22static 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
Radha Ramachandran0e92f872009-10-27 20:14:27 +010035static 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
Jens Axboe564ca972007-12-14 12:21:19 +010055static 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
Jens Axboe720e84a2009-04-21 08:29:55 +020063static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
Jens Axboe564ca972007-12-14 12:21:19 +010064{
Jens Axboe720e84a2009-04-21 08:29:55 +020065 struct bssplit *bssplit;
Jens Axboe564ca972007-12-14 12:21:19 +010066 unsigned int i, perc, perc_missing;
67 unsigned int max_bs, min_bs;
68 long long val;
Jens Axboe720e84a2009-04-21 08:29:55 +020069 char *fname;
Jens Axboe564ca972007-12-14 12:21:19 +010070
Jens Axboe720e84a2009-04-21 08:29:55 +020071 td->o.bssplit_nr[ddir] = 4;
72 bssplit = malloc(4 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010073
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 */
Jens Axboe720e84a2009-04-21 08:29:55 +020086 if (i == td->o.bssplit_nr[ddir]) {
87 td->o.bssplit_nr[ddir] <<= 1;
88 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
Jens Axboe5ec10ea2008-03-06 15:42:00 +010089 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010090 }
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
Kenneth Watersdf9cf922009-10-15 07:08:48 +0200104 if (str_to_decimal(fname, &val, 1, td)) {
Jens Axboe564ca972007-12-14 12:21:19 +0100105 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
Jens Axboe720e84a2009-04-21 08:29:55 +0200115 bssplit[i].bs = val;
116 bssplit[i].perc = perc;
Jens Axboe564ca972007-12-14 12:21:19 +0100117 i++;
118 }
119
Jens Axboe720e84a2009-04-21 08:29:55 +0200120 td->o.bssplit_nr[ddir] = i;
Jens Axboe564ca972007-12-14 12:21:19 +0100121
122 /*
123 * Now check if the percentages add up, and how much is missing
124 */
125 perc = perc_missing = 0;
Jens Axboe720e84a2009-04-21 08:29:55 +0200126 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
127 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100128
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");
Jens Axboe720e84a2009-04-21 08:29:55 +0200137 free(bssplit);
Jens Axboe564ca972007-12-14 12:21:19 +0100138 return 1;
139 }
140 /*
141 * If values didn't have a percentage set, divide the remains between
142 * them.
143 */
144 if (perc_missing) {
Jens Axboe720e84a2009-04-21 08:29:55 +0200145 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
146 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100147
148 if (bsp->perc == (unsigned char) -1)
149 bsp->perc = (100 - perc) / perc_missing;
150 }
151 }
152
Jens Axboe720e84a2009-04-21 08:29:55 +0200153 td->o.min_bs[ddir] = min_bs;
154 td->o.max_bs[ddir] = max_bs;
Jens Axboe564ca972007-12-14 12:21:19 +0100155
156 /*
157 * now sort based on percentages, for ease of lookup
158 */
Jens Axboe720e84a2009-04-21 08:29:55 +0200159 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
160 td->o.bssplit[ddir] = bssplit;
161 return 0;
162
163}
164
165static 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 }
Jens Axboe564ca972007-12-14 12:21:19 +0100194
195 free(p);
Jens Axboe720e84a2009-04-21 08:29:55 +0200196 return ret;
Jens Axboe564ca972007-12-14 12:21:19 +0100197}
198
Jens Axboe211097b2007-03-22 18:56:45 +0100199static int str_rw_cb(void *data, const char *str)
200{
201 struct thread_data *td = data;
202 char *nr = get_opt_postfix(str);
203
Jens Axboefafdba32007-03-26 10:09:12 +0200204 td->o.ddir_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100205 if (nr) {
Jens Axboe211097b2007-03-22 18:56:45 +0100206 td->o.ddir_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100207 free(nr);
208 }
Jens Axboe211097b2007-03-22 18:56:45 +0100209
Jens Axboe211097b2007-03-22 18:56:45 +0100210 return 0;
211}
212
Jens Axboe214e1ec2007-03-15 10:48:13 +0100213static int str_mem_cb(void *data, const char *mem)
214{
215 struct thread_data *td = data;
216
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100217 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100218 td->mmapfile = get_opt_postfix(mem);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100219 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100220 log_err("fio: mmaphuge:/path/to/file\n");
221 return 1;
222 }
223 }
224
225 return 0;
226}
227
228static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
229{
230 mlock_size = *val;
231 return 0;
232}
233
Jens Axboecb499fc2008-05-28 10:33:32 +0200234static int str_rwmix_read_cb(void *data, unsigned int *val)
235{
236 struct thread_data *td = data;
237
238 td->o.rwmix[DDIR_READ] = *val;
239 td->o.rwmix[DDIR_WRITE] = 100 - *val;
240 return 0;
241}
242
243static int str_rwmix_write_cb(void *data, unsigned int *val)
244{
245 struct thread_data *td = data;
246
247 td->o.rwmix[DDIR_WRITE] = *val;
248 td->o.rwmix[DDIR_READ] = 100 - *val;
249 return 0;
250}
251
Jens Axboe214e1ec2007-03-15 10:48:13 +0100252#ifdef FIO_HAVE_IOPRIO
253static int str_prioclass_cb(void *data, unsigned int *val)
254{
255 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200256 unsigned short mask;
257
258 /*
259 * mask off old class bits, str_prio_cb() may have set a default class
260 */
261 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
262 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100263
264 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
Jens Axboeac684782007-11-08 08:29:07 +0100265 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100266 return 0;
267}
268
269static int str_prio_cb(void *data, unsigned int *val)
270{
271 struct thread_data *td = data;
272
273 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200274
275 /*
276 * If no class is set, assume BE
277 */
278 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
279 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
280
Jens Axboeac684782007-11-08 08:29:07 +0100281 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100282 return 0;
283}
284#endif
285
286static int str_exitall_cb(void)
287{
288 exitall_on_terminate = 1;
289 return 0;
290}
291
Jens Axboe214e1ec2007-03-15 10:48:13 +0100292#ifdef FIO_HAVE_CPU_AFFINITY
Jens Axboe214e1ec2007-03-15 10:48:13 +0100293static int str_cpumask_cb(void *data, unsigned int *val)
294{
295 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200296 unsigned int i;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100297 long max_cpu;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100298 int ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100299
Jens Axboed2ce18b2008-12-12 20:51:40 +0100300 ret = fio_cpuset_init(&td->o.cpumask);
301 if (ret < 0) {
302 log_err("fio: cpuset_init failed\n");
303 td_verror(td, ret, "fio_cpuset_init");
304 return 1;
305 }
306
Jens Axboeb03daaf2008-12-08 20:31:43 +0100307 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
Jens Axboed2e268b2007-06-15 10:33:49 +0200308
Jens Axboe62a72732008-12-08 11:37:01 +0100309 for (i = 0; i < sizeof(int) * 8; i++) {
310 if ((1 << i) & *val) {
Jens Axboeb03daaf2008-12-08 20:31:43 +0100311 if (i > max_cpu) {
312 log_err("fio: CPU %d too large (max=%ld)\n", i,
313 max_cpu);
314 return 1;
315 }
Jens Axboe62a72732008-12-08 11:37:01 +0100316 dprint(FD_PARSE, "set cpu allowed %d\n", i);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100317 fio_cpu_set(&td->o.cpumask, i);
Jens Axboe62a72732008-12-08 11:37:01 +0100318 }
319 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200320
Jens Axboe375b2692007-05-22 09:13:02 +0200321 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100322 return 0;
323}
324
Jens Axboee8462bd2009-07-06 12:59:04 +0200325static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
326 const char *input)
Jens Axboed2e268b2007-06-15 10:33:49 +0200327{
Jens Axboed2e268b2007-06-15 10:33:49 +0200328 char *cpu, *str, *p;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100329 long max_cpu;
Jens Axboe19608d62008-12-08 15:03:12 +0100330 int ret = 0;
Jens Axboed2e268b2007-06-15 10:33:49 +0200331
Jens Axboee8462bd2009-07-06 12:59:04 +0200332 ret = fio_cpuset_init(mask);
Jens Axboed2ce18b2008-12-12 20:51:40 +0100333 if (ret < 0) {
334 log_err("fio: cpuset_init failed\n");
335 td_verror(td, ret, "fio_cpuset_init");
336 return 1;
337 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200338
339 p = str = strdup(input);
340
341 strip_blank_front(&str);
342 strip_blank_end(str);
343
Jens Axboeb03daaf2008-12-08 20:31:43 +0100344 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
345
Jens Axboed2e268b2007-06-15 10:33:49 +0200346 while ((cpu = strsep(&str, ",")) != NULL) {
Jens Axboe62a72732008-12-08 11:37:01 +0100347 char *str2, *cpu2;
348 int icpu, icpu2;
349
Jens Axboed2e268b2007-06-15 10:33:49 +0200350 if (!strlen(cpu))
351 break;
Jens Axboe62a72732008-12-08 11:37:01 +0100352
353 str2 = cpu;
354 icpu2 = -1;
355 while ((cpu2 = strsep(&str2, "-")) != NULL) {
356 if (!strlen(cpu2))
357 break;
358
359 icpu2 = atoi(cpu2);
360 }
361
362 icpu = atoi(cpu);
363 if (icpu2 == -1)
364 icpu2 = icpu;
365 while (icpu <= icpu2) {
Jens Axboe6d459ee2008-12-12 20:02:58 +0100366 if (icpu >= FIO_MAX_CPUS) {
Jens Axboe19608d62008-12-08 15:03:12 +0100367 log_err("fio: your OS only supports up to"
Jens Axboe6d459ee2008-12-12 20:02:58 +0100368 " %d CPUs\n", (int) FIO_MAX_CPUS);
Jens Axboe19608d62008-12-08 15:03:12 +0100369 ret = 1;
370 break;
371 }
Jens Axboeb03daaf2008-12-08 20:31:43 +0100372 if (icpu > max_cpu) {
373 log_err("fio: CPU %d too large (max=%ld)\n",
374 icpu, max_cpu);
375 ret = 1;
376 break;
377 }
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200378
Jens Axboe62a72732008-12-08 11:37:01 +0100379 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
Jens Axboee8462bd2009-07-06 12:59:04 +0200380 fio_cpu_set(mask, icpu);
Jens Axboe62a72732008-12-08 11:37:01 +0100381 icpu++;
382 }
Jens Axboe19608d62008-12-08 15:03:12 +0100383 if (ret)
384 break;
Jens Axboed2e268b2007-06-15 10:33:49 +0200385 }
386
387 free(p);
Jens Axboe19608d62008-12-08 15:03:12 +0100388 if (!ret)
389 td->o.cpumask_set = 1;
390 return ret;
Jens Axboed2e268b2007-06-15 10:33:49 +0200391}
Jens Axboee8462bd2009-07-06 12:59:04 +0200392
393static int str_cpus_allowed_cb(void *data, const char *input)
394{
395 struct thread_data *td = data;
396 int ret;
397
398 ret = set_cpus_allowed(td, &td->o.cpumask, input);
399 if (!ret)
400 td->o.cpumask_set = 1;
401
402 return ret;
403}
404
405static int str_verify_cpus_allowed_cb(void *data, const char *input)
406{
407 struct thread_data *td = data;
408 int ret;
409
410 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
411 if (!ret)
412 td->o.verify_cpumask_set = 1;
413
414 return ret;
415}
Jens Axboed2e268b2007-06-15 10:33:49 +0200416#endif
417
Jens Axboe214e1ec2007-03-15 10:48:13 +0100418static int str_fst_cb(void *data, const char *str)
419{
420 struct thread_data *td = data;
421 char *nr = get_opt_postfix(str);
422
423 td->file_service_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100424 if (nr) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100425 td->file_service_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100426 free(nr);
427 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100428
429 return 0;
430}
431
Jens Axboe921c7662008-03-26 09:17:55 +0100432static int check_dir(struct thread_data *td, char *fname)
433{
434 char file[PATH_MAX], *dir;
Jens Axboebc838912008-04-07 09:00:54 +0200435 int elen = 0;
Jens Axboe921c7662008-03-26 09:17:55 +0100436
Jens Axboebc838912008-04-07 09:00:54 +0200437 if (td->o.directory) {
438 strcpy(file, td->o.directory);
Jens Axboefcef0b32008-05-26 14:53:24 +0200439 strcat(file, "/");
Jens Axboebc838912008-04-07 09:00:54 +0200440 elen = strlen(file);
441 }
442
Jens Axboefcef0b32008-05-26 14:53:24 +0200443 sprintf(file + elen, "%s", fname);
Jens Axboe921c7662008-03-26 09:17:55 +0100444 dir = dirname(file);
445
Jens Axboefcef0b32008-05-26 14:53:24 +0200446#if 0
447 {
448 struct stat sb;
449 /*
450 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
451 * yet, so we can't do this check right here...
452 */
Jens Axboe921c7662008-03-26 09:17:55 +0100453 if (lstat(dir, &sb) < 0) {
454 int ret = errno;
455
456 log_err("fio: %s is not a directory\n", dir);
457 td_verror(td, ret, "lstat");
458 return 1;
459 }
460
461 if (!S_ISDIR(sb.st_mode)) {
462 log_err("fio: %s is not a directory\n", dir);
463 return 1;
464 }
Jens Axboefcef0b32008-05-26 14:53:24 +0200465 }
466#endif
Jens Axboe921c7662008-03-26 09:17:55 +0100467
468 return 0;
469}
470
Jens Axboe8e827d32009-08-04 09:51:48 +0200471/*
472 * Return next file in the string. Files are separated with ':'. If the ':'
473 * is escaped with a '\', then that ':' is part of the filename and does not
474 * indicate a new file.
475 */
476static char *get_next_file_name(char **ptr)
477{
478 char *str = *ptr;
479 char *p, *start;
480
481 if (!str || !strlen(str))
482 return NULL;
483
484 start = str;
485 do {
486 /*
487 * No colon, we are done
488 */
489 p = strchr(str, ':');
490 if (!p) {
491 *ptr = NULL;
492 break;
493 }
494
495 /*
496 * We got a colon, but it's the first character. Skip and
497 * continue
498 */
499 if (p == start) {
500 str = ++start;
501 continue;
502 }
503
504 if (*(p - 1) != '\\') {
505 *p = '\0';
506 *ptr = p + 1;
507 break;
508 }
509
510 memmove(p - 1, p, strlen(p) + 1);
511 str = p;
512 } while (1);
513
514 return start;
515}
516
Jens Axboe214e1ec2007-03-15 10:48:13 +0100517static int str_filename_cb(void *data, const char *input)
518{
519 struct thread_data *td = data;
520 char *fname, *str, *p;
521
522 p = str = strdup(input);
523
524 strip_blank_front(&str);
525 strip_blank_end(str);
526
527 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100528 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100529
Jens Axboe8e827d32009-08-04 09:51:48 +0200530 while ((fname = get_next_file_name(&str)) != NULL) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100531 if (!strlen(fname))
532 break;
Jens Axboe921c7662008-03-26 09:17:55 +0100533 if (check_dir(td, fname)) {
534 free(p);
535 return 1;
536 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100537 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100538 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100539 }
540
541 free(p);
542 return 0;
543}
544
545static int str_directory_cb(void *data, const char fio_unused *str)
546{
547 struct thread_data *td = data;
548 struct stat sb;
549
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100550 if (lstat(td->o.directory, &sb) < 0) {
Jens Axboe921c7662008-03-26 09:17:55 +0100551 int ret = errno;
552
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100553 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe921c7662008-03-26 09:17:55 +0100554 td_verror(td, ret, "lstat");
Jens Axboe214e1ec2007-03-15 10:48:13 +0100555 return 1;
556 }
557 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100558 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100559 return 1;
560 }
561
562 return 0;
563}
564
565static int str_opendir_cb(void *data, const char fio_unused *str)
566{
567 struct thread_data *td = data;
568
569 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100570 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100571
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100572 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100573}
574
Jens Axboea59e1702007-07-30 08:53:27 +0200575static int str_verify_offset_cb(void *data, unsigned int *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200576{
577 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200578
Shawn Lewis546a9142007-07-28 21:11:37 +0200579 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200580 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200581 return 1;
582 }
Jens Axboea59e1702007-07-30 08:53:27 +0200583
584 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200585 return 0;
586}
587
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100588static int str_verify_pattern_cb(void *data, const char *input)
Jens Axboe90059d62007-07-30 09:33:12 +0200589{
590 struct thread_data *td = data;
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100591 long off;
592 int i = 0, j = 0, len, k, base = 10;
593 char* loc1, * loc2;
Jens Axboe90059d62007-07-30 09:33:12 +0200594
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100595 loc1 = strstr(input, "0x");
596 loc2 = strstr(input, "0X");
597 if (loc1 || loc2)
598 base = 16;
599 off = strtol(input, NULL, base);
600 if (off != LONG_MAX || errno != ERANGE) {
601 while (off) {
602 td->o.verify_pattern[i] = off & 0xff;
603 off >>= 8;
604 i++;
605 }
606 } else {
607 len = strlen(input);
608 k = len - 1;
609 if (base == 16) {
610 if (loc1)
611 j = loc1 - input + 2;
612 else
613 j = loc2 - input + 2;
614 } else
615 return 1;
616 if (len - j < MAX_PATTERN_SIZE * 2) {
617 while (k >= j) {
618 off = converthexchartoint(input[k--]);
619 if (k >= j)
620 off += (converthexchartoint(input[k--])
621 * 16);
622 td->o.verify_pattern[i++] = (char) off;
623 }
624 }
625 }
626 td->o.verify_pattern_bytes = i;
Jens Axboe90059d62007-07-30 09:33:12 +0200627 return 0;
628}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100629
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100630static int str_lockfile_cb(void *data, const char *str)
631{
632 struct thread_data *td = data;
633 char *nr = get_opt_postfix(str);
634
635 td->o.lockfile_batch = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100636 if (nr) {
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100637 td->o.lockfile_batch = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100638 free(nr);
639 }
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100640
641 return 0;
642}
643
Jens Axboee3cedca2008-11-19 19:57:52 +0100644static int str_write_bw_log_cb(void *data, const char *str)
645{
646 struct thread_data *td = data;
647
648 if (str)
649 td->o.bw_log_file = strdup(str);
650
651 td->o.write_bw_log = 1;
652 return 0;
653}
654
655static int str_write_lat_log_cb(void *data, const char *str)
656{
657 struct thread_data *td = data;
658
659 if (str)
660 td->o.lat_log_file = strdup(str);
661
662 td->o.write_lat_log = 1;
663 return 0;
664}
665
Jens Axboe993bf482008-11-14 13:04:53 +0100666static int str_gtod_reduce_cb(void *data, int *il)
667{
668 struct thread_data *td = data;
669 int val = *il;
670
671 td->o.disable_clat = !!val;
672 td->o.disable_slat = !!val;
673 td->o.disable_bw = !!val;
674 if (val)
675 td->tv_cache_mask = 63;
676
677 return 0;
678}
679
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100680static int str_gtod_cpu_cb(void *data, int *il)
681{
682 struct thread_data *td = data;
683 int val = *il;
684
685 td->o.gtod_cpu = val;
686 td->o.gtod_offload = 1;
687 return 0;
688}
689
Jens Axboe896cac22009-07-01 10:38:35 +0200690static int rw_verify(struct fio_option *o, void *data)
691{
692 struct thread_data *td = data;
693
694 if (read_only && td_write(td)) {
695 log_err("fio: job <%s> has write bit set, but fio is in"
696 " read-only mode\n", td->o.name);
697 return 1;
698 }
699
700 return 0;
701}
702
Jens Axboe276ca4f2009-07-01 10:43:05 +0200703static int gtod_cpu_verify(struct fio_option *o, void *data)
Jens Axboe29d43ff2009-07-01 10:42:18 +0200704{
Jens Axboe276ca4f2009-07-01 10:43:05 +0200705#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboe29d43ff2009-07-01 10:42:18 +0200706 struct thread_data *td = data;
707
Jens Axboe29d43ff2009-07-01 10:42:18 +0200708 if (td->o.gtod_cpu) {
709 log_err("fio: platform must support CPU affinity for"
710 "gettimeofday() offloading\n");
711 return 1;
712 }
713#endif
714
715 return 0;
716}
717
Jens Axboe90fef2d2009-07-17 22:33:32 +0200718static int kb_base_verify(struct fio_option *o, void *data)
719{
720 struct thread_data *td = data;
721
722 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
723 log_err("fio: kb_base set to nonsensical value: %u\n",
724 td->o.kb_base);
725 return 1;
726 }
727
728 return 0;
729}
730
Jens Axboe214e1ec2007-03-15 10:48:13 +0100731#define __stringify_1(x) #x
732#define __stringify(x) __stringify_1(x)
733
734/*
735 * Map of job/command line options
736 */
Jens Axboe07b32322010-03-05 09:48:44 +0100737static struct fio_option options[FIO_MAX_OPTS] = {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100738 {
739 .name = "description",
740 .type = FIO_OPT_STR_STORE,
741 .off1 = td_var_offset(description),
742 .help = "Text job description",
743 },
744 {
745 .name = "name",
746 .type = FIO_OPT_STR_STORE,
747 .off1 = td_var_offset(name),
748 .help = "Name of this job",
749 },
750 {
751 .name = "directory",
752 .type = FIO_OPT_STR_STORE,
753 .off1 = td_var_offset(directory),
754 .cb = str_directory_cb,
755 .help = "Directory to store files in",
756 },
757 {
758 .name = "filename",
759 .type = FIO_OPT_STR_STORE,
760 .off1 = td_var_offset(filename),
761 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +0200762 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +0100763 .help = "File(s) to use for the workload",
764 },
765 {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200766 .name = "kb_base",
767 .type = FIO_OPT_INT,
768 .off1 = td_var_offset(kb_base),
Jens Axboe90fef2d2009-07-17 22:33:32 +0200769 .verify = kb_base_verify,
Jens Axboea639f0b2009-07-18 08:25:35 +0200770 .prio = 1,
Jens Axboe90fef2d2009-07-17 22:33:32 +0200771 .def = "1024",
Jens Axboea639f0b2009-07-18 08:25:35 +0200772 .help = "How many bytes per KB for reporting (1000 or 1024)",
Jens Axboe90fef2d2009-07-17 22:33:32 +0200773 },
774 {
Jens Axboe29c13492008-03-01 19:25:20 +0100775 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100776 .type = FIO_OPT_STR,
777 .cb = str_lockfile_cb,
778 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +0100779 .help = "Lock file when doing IO to it",
780 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100781 .def = "none",
782 .posval = {
783 { .ival = "none",
784 .oval = FILE_LOCK_NONE,
785 .help = "No file locking",
786 },
787 { .ival = "exclusive",
788 .oval = FILE_LOCK_EXCLUSIVE,
789 .help = "Exclusive file lock",
790 },
791 {
792 .ival = "readwrite",
793 .oval = FILE_LOCK_READWRITE,
794 .help = "Read vs write lock",
795 },
796 },
Jens Axboe29c13492008-03-01 19:25:20 +0100797 },
798 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100799 .name = "opendir",
800 .type = FIO_OPT_STR_STORE,
801 .off1 = td_var_offset(opendir),
802 .cb = str_opendir_cb,
803 .help = "Recursively add files from this directory and down",
804 },
805 {
806 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100807 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100808 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +0100809 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100810 .off1 = td_var_offset(td_ddir),
811 .help = "IO direction",
812 .def = "read",
Jens Axboe896cac22009-07-01 10:38:35 +0200813 .verify = rw_verify,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100814 .posval = {
815 { .ival = "read",
816 .oval = TD_DDIR_READ,
817 .help = "Sequential read",
818 },
819 { .ival = "write",
820 .oval = TD_DDIR_WRITE,
821 .help = "Sequential write",
822 },
823 { .ival = "randread",
824 .oval = TD_DDIR_RANDREAD,
825 .help = "Random read",
826 },
827 { .ival = "randwrite",
828 .oval = TD_DDIR_RANDWRITE,
829 .help = "Random write",
830 },
831 { .ival = "rw",
832 .oval = TD_DDIR_RW,
833 .help = "Sequential read and write mix",
834 },
835 { .ival = "randrw",
836 .oval = TD_DDIR_RANDRW,
837 .help = "Random read and write mix"
838 },
839 },
840 },
841 {
842 .name = "ioengine",
843 .type = FIO_OPT_STR_STORE,
844 .off1 = td_var_offset(ioengine),
845 .help = "IO engine to use",
846 .def = "sync",
847 .posval = {
848 { .ival = "sync",
849 .help = "Use read/write",
850 },
gurudas paia31041e2007-10-23 15:12:30 +0200851 { .ival = "psync",
852 .help = "Use pread/pwrite",
853 },
Jens Axboe1d2af022008-02-04 10:59:07 +0100854 { .ival = "vsync",
855 .help = "Use readv/writev",
856 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100857#ifdef FIO_HAVE_LIBAIO
858 { .ival = "libaio",
859 .help = "Linux native asynchronous IO",
860 },
861#endif
862#ifdef FIO_HAVE_POSIXAIO
863 { .ival = "posixaio",
864 .help = "POSIX asynchronous IO",
865 },
866#endif
Jens Axboe417f0062008-06-02 11:59:30 +0200867#ifdef FIO_HAVE_SOLARISAIO
868 { .ival = "solarisaio",
869 .help = "Solaris native asynchronous IO",
870 },
871#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100872 { .ival = "mmap",
873 .help = "Memory mapped IO",
874 },
875#ifdef FIO_HAVE_SPLICE
876 { .ival = "splice",
877 .help = "splice/vmsplice based IO",
878 },
Jens Axboe9cce02e2007-06-22 15:42:21 +0200879 { .ival = "netsplice",
880 .help = "splice/vmsplice to/from the network",
881 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100882#endif
883#ifdef FIO_HAVE_SGIO
884 { .ival = "sg",
885 .help = "SCSI generic v3 IO",
886 },
887#endif
888 { .ival = "null",
889 .help = "Testing engine (no data transfer)",
890 },
891 { .ival = "net",
892 .help = "Network IO",
893 },
894#ifdef FIO_HAVE_SYSLET
895 { .ival = "syslet-rw",
896 .help = "syslet enabled async pread/pwrite IO",
897 },
898#endif
899 { .ival = "cpuio",
900 .help = "CPU cycler burner engine",
901 },
Jens Axboeb8c82a42007-03-21 08:48:26 +0100902#ifdef FIO_HAVE_GUASI
903 { .ival = "guasi",
904 .help = "GUASI IO engine",
905 },
906#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100907 { .ival = "external",
908 .help = "Load external engine (append name)",
909 },
910 },
911 },
912 {
913 .name = "iodepth",
914 .type = FIO_OPT_INT,
915 .off1 = td_var_offset(iodepth),
916 .help = "Amount of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +0100917 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100918 .def = "1",
919 },
920 {
921 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +0200922 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100923 .type = FIO_OPT_INT,
924 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +0100925 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +0200926 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +0100927 .minval = 1,
928 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100929 },
930 {
Jens Axboe49504212008-06-05 09:03:30 +0200931 .name = "iodepth_batch_complete",
932 .type = FIO_OPT_INT,
933 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +0100934 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +0200935 .parent = "iodepth",
936 .minval = 0,
937 .def = "1",
938 },
939 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100940 .name = "iodepth_low",
941 .type = FIO_OPT_INT,
942 .off1 = td_var_offset(iodepth_low),
943 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +0200944 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100945 },
946 {
947 .name = "size",
948 .type = FIO_OPT_STR_VAL,
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100949 .off1 = td_var_offset(size),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200950 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100951 .help = "Total size of device or files",
952 },
953 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +0100954 .name = "fill_device",
955 .type = FIO_OPT_BOOL,
956 .off1 = td_var_offset(fill_device),
957 .help = "Write until an ENOSPC error occurs",
958 .def = "0",
959 },
960 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100961 .name = "filesize",
962 .type = FIO_OPT_STR_VAL,
963 .off1 = td_var_offset(file_size_low),
964 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200965 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100966 .help = "Size of individual files",
967 },
968 {
Jens Axboe67a10002007-07-31 23:12:16 +0200969 .name = "offset",
970 .alias = "fileoffset",
971 .type = FIO_OPT_STR_VAL,
972 .off1 = td_var_offset(start_offset),
973 .help = "Start IO from this offset",
974 .def = "0",
975 },
976 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100977 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100978 .alias = "blocksize",
Jens Axboee01b22b2009-06-09 15:43:25 +0200979 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100980 .off1 = td_var_offset(bs[DDIR_READ]),
981 .off2 = td_var_offset(bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200982 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100983 .help = "Block size unit",
984 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +0200985 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100986 },
987 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +0100988 .name = "ba",
989 .alias = "blockalign",
Jens Axboee01b22b2009-06-09 15:43:25 +0200990 .type = FIO_OPT_INT,
Jens Axboe2b7a01d2009-03-11 11:00:13 +0100991 .off1 = td_var_offset(ba[DDIR_READ]),
992 .off2 = td_var_offset(ba[DDIR_WRITE]),
993 .minval = 1,
994 .help = "IO block offset alignment",
995 .parent = "rw",
996 },
997 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100998 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100999 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001000 .type = FIO_OPT_RANGE,
1001 .off1 = td_var_offset(min_bs[DDIR_READ]),
1002 .off2 = td_var_offset(max_bs[DDIR_READ]),
1003 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1004 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001005 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001006 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +02001007 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001008 },
1009 {
Jens Axboe564ca972007-12-14 12:21:19 +01001010 .name = "bssplit",
1011 .type = FIO_OPT_STR,
1012 .cb = str_bssplit_cb,
1013 .help = "Set a specific mix of block sizes",
1014 .parent = "rw",
1015 },
1016 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001017 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001018 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001019 .type = FIO_OPT_STR_SET,
1020 .off1 = td_var_offset(bs_unaligned),
1021 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +02001022 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001023 },
1024 {
1025 .name = "randrepeat",
1026 .type = FIO_OPT_BOOL,
1027 .off1 = td_var_offset(rand_repeatable),
1028 .help = "Use repeatable random IO pattern",
1029 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +02001030 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001031 },
1032 {
1033 .name = "norandommap",
1034 .type = FIO_OPT_STR_SET,
1035 .off1 = td_var_offset(norandommap),
1036 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +02001037 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001038 },
1039 {
Jens Axboe2b386d22008-03-26 10:32:57 +01001040 .name = "softrandommap",
1041 .type = FIO_OPT_BOOL,
1042 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001043 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +01001044 .parent = "norandommap",
1045 .def = "0",
1046 },
1047 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001048 .name = "nrfiles",
1049 .type = FIO_OPT_INT,
1050 .off1 = td_var_offset(nr_files),
1051 .help = "Split job workload between this number of files",
1052 .def = "1",
1053 },
1054 {
1055 .name = "openfiles",
1056 .type = FIO_OPT_INT,
1057 .off1 = td_var_offset(open_files),
1058 .help = "Number of files to keep open at the same time",
1059 },
1060 {
1061 .name = "file_service_type",
1062 .type = FIO_OPT_STR,
1063 .cb = str_fst_cb,
1064 .off1 = td_var_offset(file_service_type),
1065 .help = "How to select which file to service next",
1066 .def = "roundrobin",
1067 .posval = {
1068 { .ival = "random",
1069 .oval = FIO_FSERVICE_RANDOM,
1070 .help = "Choose a file at random",
1071 },
1072 { .ival = "roundrobin",
1073 .oval = FIO_FSERVICE_RR,
1074 .help = "Round robin select files",
1075 },
Jens Axboea086c252009-03-04 08:27:37 +01001076 { .ival = "sequential",
1077 .oval = FIO_FSERVICE_SEQ,
1078 .help = "Finish one file before moving to the next",
1079 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001080 },
Jens Axboe67a10002007-07-31 23:12:16 +02001081 .parent = "nrfiles",
1082 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001083#ifdef FIO_HAVE_FALLOCATE
1084 {
1085 .name = "fallocate",
1086 .type = FIO_OPT_BOOL,
1087 .off1 = td_var_offset(fallocate),
1088 .help = "Use fallocate() when laying out files",
1089 .def = "1",
1090 },
1091#endif
Jens Axboe67a10002007-07-31 23:12:16 +02001092 {
1093 .name = "fadvise_hint",
1094 .type = FIO_OPT_BOOL,
1095 .off1 = td_var_offset(fadvise_hint),
1096 .help = "Use fadvise() to advise the kernel on IO pattern",
1097 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001098 },
1099 {
1100 .name = "fsync",
1101 .type = FIO_OPT_INT,
1102 .off1 = td_var_offset(fsync_blocks),
1103 .help = "Issue fsync for writes every given number of blocks",
1104 .def = "0",
1105 },
1106 {
Jens Axboe5f9099e2009-06-16 22:40:26 +02001107 .name = "fdatasync",
1108 .type = FIO_OPT_INT,
1109 .off1 = td_var_offset(fdatasync_blocks),
1110 .help = "Issue fdatasync for writes every given number of blocks",
1111 .def = "0",
1112 },
1113 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001114 .name = "direct",
1115 .type = FIO_OPT_BOOL,
1116 .off1 = td_var_offset(odirect),
1117 .help = "Use O_DIRECT IO (negates buffered)",
1118 .def = "0",
1119 },
1120 {
1121 .name = "buffered",
1122 .type = FIO_OPT_BOOL,
1123 .off1 = td_var_offset(odirect),
1124 .neg = 1,
1125 .help = "Use buffered IO (negates direct)",
1126 .def = "1",
1127 },
1128 {
1129 .name = "overwrite",
1130 .type = FIO_OPT_BOOL,
1131 .off1 = td_var_offset(overwrite),
1132 .help = "When writing, set whether to overwrite current data",
1133 .def = "0",
1134 },
1135 {
1136 .name = "loops",
1137 .type = FIO_OPT_INT,
1138 .off1 = td_var_offset(loops),
1139 .help = "Number of times to run the job",
1140 .def = "1",
1141 },
1142 {
1143 .name = "numjobs",
1144 .type = FIO_OPT_INT,
1145 .off1 = td_var_offset(numjobs),
1146 .help = "Duplicate this job this many times",
1147 .def = "1",
1148 },
1149 {
1150 .name = "startdelay",
1151 .type = FIO_OPT_INT,
1152 .off1 = td_var_offset(start_delay),
1153 .help = "Only start job when this period has passed",
1154 .def = "0",
1155 },
1156 {
1157 .name = "runtime",
1158 .alias = "timeout",
1159 .type = FIO_OPT_STR_VAL_TIME,
1160 .off1 = td_var_offset(timeout),
1161 .help = "Stop workload when this amount of time has passed",
1162 .def = "0",
1163 },
1164 {
Jens Axboecf4464c2007-04-17 20:14:42 +02001165 .name = "time_based",
1166 .type = FIO_OPT_STR_SET,
1167 .off1 = td_var_offset(time_based),
1168 .help = "Keep running until runtime/timeout is met",
1169 },
1170 {
Jens Axboe721938a2008-09-10 09:46:16 +02001171 .name = "ramp_time",
1172 .type = FIO_OPT_STR_VAL_TIME,
1173 .off1 = td_var_offset(ramp_time),
1174 .help = "Ramp up time before measuring performance",
1175 },
1176 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001177 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001178 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001179 .type = FIO_OPT_STR,
1180 .cb = str_mem_cb,
1181 .off1 = td_var_offset(mem_type),
1182 .help = "Backing type for IO buffers",
1183 .def = "malloc",
1184 .posval = {
1185 { .ival = "malloc",
1186 .oval = MEM_MALLOC,
1187 .help = "Use malloc(3) for IO buffers",
1188 },
Jens Axboeb370e462007-03-19 10:51:49 +01001189 { .ival = "shm",
1190 .oval = MEM_SHM,
1191 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001192 },
1193#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001194 { .ival = "shmhuge",
1195 .oval = MEM_SHMHUGE,
1196 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001197 },
1198#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001199 { .ival = "mmap",
1200 .oval = MEM_MMAP,
1201 .help = "Use mmap(2) (file or anon) for IO buffers",
1202 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001203#ifdef FIO_HAVE_HUGETLB
1204 { .ival = "mmaphuge",
1205 .oval = MEM_MMAPHUGE,
1206 .help = "Like mmap, but use huge pages",
1207 },
1208#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001209 },
1210 },
1211 {
Jens Axboed529ee12009-07-01 10:33:03 +02001212 .name = "iomem_align",
1213 .alias = "mem_align",
1214 .type = FIO_OPT_INT,
1215 .off1 = td_var_offset(mem_align),
1216 .minval = 0,
1217 .help = "IO memory buffer offset alignment",
1218 .def = "0",
1219 .parent = "iomem",
1220 },
1221 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001222 .name = "verify",
1223 .type = FIO_OPT_STR,
1224 .off1 = td_var_offset(verify),
1225 .help = "Verify data written",
1226 .def = "0",
1227 .posval = {
1228 { .ival = "0",
1229 .oval = VERIFY_NONE,
1230 .help = "Don't do IO verification",
1231 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001232 { .ival = "md5",
1233 .oval = VERIFY_MD5,
1234 .help = "Use md5 checksums for verification",
1235 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001236 { .ival = "crc64",
1237 .oval = VERIFY_CRC64,
1238 .help = "Use crc64 checksums for verification",
1239 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001240 { .ival = "crc32",
1241 .oval = VERIFY_CRC32,
1242 .help = "Use crc32 checksums for verification",
1243 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001244 { .ival = "crc32c-intel",
1245 .oval = VERIFY_CRC32C_INTEL,
1246 .help = "Use hw crc32c checksums for verification",
1247 },
Jens Axboebac39e02008-06-11 20:46:19 +02001248 { .ival = "crc32c",
1249 .oval = VERIFY_CRC32C,
1250 .help = "Use crc32c checksums for verification",
1251 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001252 { .ival = "crc16",
1253 .oval = VERIFY_CRC16,
1254 .help = "Use crc16 checksums for verification",
1255 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001256 { .ival = "crc7",
1257 .oval = VERIFY_CRC7,
1258 .help = "Use crc7 checksums for verification",
1259 },
Jens Axboe7c353ce2009-08-09 22:40:33 +02001260 { .ival = "sha1",
1261 .oval = VERIFY_SHA1,
1262 .help = "Use sha1 checksums for verification",
1263 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001264 { .ival = "sha256",
1265 .oval = VERIFY_SHA256,
1266 .help = "Use sha256 checksums for verification",
1267 },
1268 { .ival = "sha512",
1269 .oval = VERIFY_SHA512,
1270 .help = "Use sha512 checksums for verification",
1271 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001272 { .ival = "meta",
1273 .oval = VERIFY_META,
1274 .help = "Use io information",
1275 },
Jens Axboe36690c92007-03-26 10:23:34 +02001276 {
1277 .ival = "null",
1278 .oval = VERIFY_NULL,
1279 .help = "Pretend to verify",
1280 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001281 },
1282 },
1283 {
Jens Axboe005c5652007-08-02 22:21:36 +02001284 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001285 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001286 .off1 = td_var_offset(do_verify),
1287 .help = "Run verification stage after write",
1288 .def = "1",
1289 .parent = "verify",
1290 },
1291 {
Jens Axboe160b9662007-03-27 10:59:49 +02001292 .name = "verifysort",
1293 .type = FIO_OPT_BOOL,
1294 .off1 = td_var_offset(verifysort),
1295 .help = "Sort written verify blocks for read back",
1296 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001297 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001298 },
1299 {
Jens Axboea59e1702007-07-30 08:53:27 +02001300 .name = "verify_interval",
Jens Axboee01b22b2009-06-09 15:43:25 +02001301 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001302 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001303 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001304 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001305 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001306 },
1307 {
Jens Axboea59e1702007-07-30 08:53:27 +02001308 .name = "verify_offset",
Jens Axboee01b22b2009-06-09 15:43:25 +02001309 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001310 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001311 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001312 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001313 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001314 },
1315 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001316 .name = "verify_pattern",
Radha Ramachandran0e92f872009-10-27 20:14:27 +01001317 .type = FIO_OPT_STR,
Shawn Lewise28218f2008-01-16 11:01:33 +01001318 .cb = str_verify_pattern_cb,
1319 .help = "Fill pattern for IO buffers",
1320 .parent = "verify",
1321 },
1322 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001323 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001324 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001325 .off1 = td_var_offset(verify_fatal),
1326 .def = "0",
1327 .help = "Exit on a single verify failure, don't continue",
1328 .parent = "verify",
1329 },
1330 {
Jens Axboee8462bd2009-07-06 12:59:04 +02001331 .name = "verify_async",
1332 .type = FIO_OPT_INT,
1333 .off1 = td_var_offset(verify_async),
1334 .def = "0",
1335 .help = "Number of async verifier threads to use",
1336 .parent = "verify",
1337 },
1338#ifdef FIO_HAVE_CPU_AFFINITY
1339 {
1340 .name = "verify_async_cpus",
1341 .type = FIO_OPT_STR,
1342 .cb = str_verify_cpus_allowed_cb,
1343 .help = "Set CPUs allowed for async verify threads",
1344 .parent = "verify_async",
1345 },
1346#endif
1347 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001348 .name = "write_iolog",
1349 .type = FIO_OPT_STR_STORE,
1350 .off1 = td_var_offset(write_iolog_file),
1351 .help = "Store IO pattern to file",
1352 },
1353 {
1354 .name = "read_iolog",
1355 .type = FIO_OPT_STR_STORE,
1356 .off1 = td_var_offset(read_iolog_file),
1357 .help = "Playback IO pattern from file",
1358 },
1359 {
1360 .name = "exec_prerun",
1361 .type = FIO_OPT_STR_STORE,
1362 .off1 = td_var_offset(exec_prerun),
1363 .help = "Execute this file prior to running job",
1364 },
1365 {
1366 .name = "exec_postrun",
1367 .type = FIO_OPT_STR_STORE,
1368 .off1 = td_var_offset(exec_postrun),
1369 .help = "Execute this file after running job",
1370 },
1371#ifdef FIO_HAVE_IOSCHED_SWITCH
1372 {
1373 .name = "ioscheduler",
1374 .type = FIO_OPT_STR_STORE,
1375 .off1 = td_var_offset(ioscheduler),
1376 .help = "Use this IO scheduler on the backing device",
1377 },
1378#endif
1379 {
1380 .name = "zonesize",
1381 .type = FIO_OPT_STR_VAL,
1382 .off1 = td_var_offset(zone_size),
1383 .help = "Give size of an IO zone",
1384 .def = "0",
1385 },
1386 {
1387 .name = "zoneskip",
1388 .type = FIO_OPT_STR_VAL,
1389 .off1 = td_var_offset(zone_skip),
1390 .help = "Space between IO zones",
1391 .def = "0",
1392 },
1393 {
1394 .name = "lockmem",
1395 .type = FIO_OPT_STR_VAL,
1396 .cb = str_lockmem_cb,
1397 .help = "Lock down this amount of memory",
1398 .def = "0",
1399 },
1400 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001401 .name = "rwmixread",
1402 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001403 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001404 .maxval = 100,
1405 .help = "Percentage of mixed workload that is reads",
1406 .def = "50",
1407 },
1408 {
1409 .name = "rwmixwrite",
1410 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001411 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001412 .maxval = 100,
1413 .help = "Percentage of mixed workload that is writes",
1414 .def = "50",
1415 },
1416 {
Jens Axboeafdf9352007-07-31 16:14:34 +02001417 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02001418 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02001419 },
1420 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001421 .name = "nice",
1422 .type = FIO_OPT_INT,
1423 .off1 = td_var_offset(nice),
1424 .help = "Set job CPU nice value",
1425 .minval = -19,
1426 .maxval = 20,
1427 .def = "0",
1428 },
1429#ifdef FIO_HAVE_IOPRIO
1430 {
1431 .name = "prio",
1432 .type = FIO_OPT_INT,
1433 .cb = str_prio_cb,
1434 .help = "Set job IO priority value",
1435 .minval = 0,
1436 .maxval = 7,
1437 },
1438 {
1439 .name = "prioclass",
1440 .type = FIO_OPT_INT,
1441 .cb = str_prioclass_cb,
1442 .help = "Set job IO priority class",
1443 .minval = 0,
1444 .maxval = 3,
1445 },
1446#endif
1447 {
1448 .name = "thinktime",
1449 .type = FIO_OPT_INT,
1450 .off1 = td_var_offset(thinktime),
1451 .help = "Idle time between IO buffers (usec)",
1452 .def = "0",
1453 },
1454 {
1455 .name = "thinktime_spin",
1456 .type = FIO_OPT_INT,
1457 .off1 = td_var_offset(thinktime_spin),
1458 .help = "Start think time by spinning this amount (usec)",
1459 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02001460 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001461 },
1462 {
1463 .name = "thinktime_blocks",
1464 .type = FIO_OPT_INT,
1465 .off1 = td_var_offset(thinktime_blocks),
1466 .help = "IO buffer period between 'thinktime'",
1467 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02001468 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001469 },
1470 {
1471 .name = "rate",
Jens Axboee01b22b2009-06-09 15:43:25 +02001472 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001473 .off1 = td_var_offset(rate[0]),
1474 .off2 = td_var_offset(rate[1]),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001475 .help = "Set bandwidth rate",
1476 },
1477 {
1478 .name = "ratemin",
Jens Axboee01b22b2009-06-09 15:43:25 +02001479 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001480 .off1 = td_var_offset(ratemin[0]),
1481 .off2 = td_var_offset(ratemin[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001482 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001483 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01001484 },
1485 {
1486 .name = "rate_iops",
Jens Axboee01b22b2009-06-09 15:43:25 +02001487 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001488 .off1 = td_var_offset(rate_iops[0]),
1489 .off2 = td_var_offset(rate_iops[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001490 .help = "Limit IO used to this number of IO operations/sec",
1491 },
1492 {
1493 .name = "rate_iops_min",
Jens Axboee01b22b2009-06-09 15:43:25 +02001494 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001495 .off1 = td_var_offset(rate_iops_min[0]),
1496 .off2 = td_var_offset(rate_iops_min[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001497 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001498 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001499 },
1500 {
1501 .name = "ratecycle",
1502 .type = FIO_OPT_INT,
1503 .off1 = td_var_offset(ratecycle),
1504 .help = "Window average for rate limits (msec)",
1505 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02001506 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001507 },
1508 {
1509 .name = "invalidate",
1510 .type = FIO_OPT_BOOL,
1511 .off1 = td_var_offset(invalidate_cache),
1512 .help = "Invalidate buffer/page cache prior to running job",
1513 .def = "1",
1514 },
1515 {
1516 .name = "sync",
1517 .type = FIO_OPT_BOOL,
1518 .off1 = td_var_offset(sync_io),
1519 .help = "Use O_SYNC for buffered writes",
1520 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02001521 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001522 },
1523 {
1524 .name = "bwavgtime",
1525 .type = FIO_OPT_INT,
1526 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001527 .help = "Time window over which to calculate bandwidth"
1528 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001529 .def = "500",
1530 },
1531 {
1532 .name = "create_serialize",
1533 .type = FIO_OPT_BOOL,
1534 .off1 = td_var_offset(create_serialize),
1535 .help = "Serialize creating of job files",
1536 .def = "1",
1537 },
1538 {
1539 .name = "create_fsync",
1540 .type = FIO_OPT_BOOL,
1541 .off1 = td_var_offset(create_fsync),
1542 .help = "Fsync file after creation",
1543 .def = "1",
1544 },
1545 {
Jens Axboe814452b2009-03-04 12:53:13 +01001546 .name = "create_on_open",
1547 .type = FIO_OPT_BOOL,
1548 .off1 = td_var_offset(create_on_open),
1549 .help = "Create files when they are opened for IO",
1550 .def = "0",
1551 },
Jens Axboe0b9d69e2009-09-11 22:29:54 +02001552 {
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001553 .name = "pre_read",
1554 .type = FIO_OPT_BOOL,
1555 .off1 = td_var_offset(pre_read),
1556 .help = "Preread files before starting official testing",
1557 .def = "0",
1558 },
Jens Axboe814452b2009-03-04 12:53:13 +01001559 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001560 .name = "cpuload",
1561 .type = FIO_OPT_INT,
1562 .off1 = td_var_offset(cpuload),
1563 .help = "Use this percentage of CPU",
1564 },
1565 {
1566 .name = "cpuchunks",
1567 .type = FIO_OPT_INT,
1568 .off1 = td_var_offset(cpucycle),
1569 .help = "Length of the CPU burn cycles (usecs)",
1570 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02001571 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001572 },
1573#ifdef FIO_HAVE_CPU_AFFINITY
1574 {
1575 .name = "cpumask",
1576 .type = FIO_OPT_INT,
1577 .cb = str_cpumask_cb,
1578 .help = "CPU affinity mask",
1579 },
Jens Axboed2e268b2007-06-15 10:33:49 +02001580 {
1581 .name = "cpus_allowed",
1582 .type = FIO_OPT_STR,
1583 .cb = str_cpus_allowed_cb,
1584 .help = "Set CPUs allowed",
1585 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001586#endif
1587 {
1588 .name = "end_fsync",
1589 .type = FIO_OPT_BOOL,
1590 .off1 = td_var_offset(end_fsync),
1591 .help = "Include fsync at the end of job",
1592 .def = "0",
1593 },
1594 {
1595 .name = "fsync_on_close",
1596 .type = FIO_OPT_BOOL,
1597 .off1 = td_var_offset(fsync_on_close),
1598 .help = "fsync files on close",
1599 .def = "0",
1600 },
1601 {
1602 .name = "unlink",
1603 .type = FIO_OPT_BOOL,
1604 .off1 = td_var_offset(unlink),
1605 .help = "Unlink created files after job has completed",
1606 .def = "0",
1607 },
1608 {
1609 .name = "exitall",
1610 .type = FIO_OPT_STR_SET,
1611 .cb = str_exitall_cb,
1612 .help = "Terminate all jobs when one exits",
1613 },
1614 {
1615 .name = "stonewall",
1616 .type = FIO_OPT_STR_SET,
1617 .off1 = td_var_offset(stonewall),
1618 .help = "Insert a hard barrier between this job and previous",
1619 },
1620 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01001621 .name = "new_group",
1622 .type = FIO_OPT_STR_SET,
1623 .off1 = td_var_offset(new_group),
1624 .help = "Mark the start of a new group (for reporting)",
1625 },
1626 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001627 .name = "thread",
1628 .type = FIO_OPT_STR_SET,
1629 .off1 = td_var_offset(use_thread),
1630 .help = "Use threads instead of forks",
1631 },
1632 {
1633 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001634 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001635 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001636 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001637 .help = "Write log of bandwidth during run",
1638 },
1639 {
1640 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001641 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001642 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001643 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001644 .help = "Write log of latency during run",
1645 },
1646 {
1647 .name = "hugepage-size",
Jens Axboee01b22b2009-06-09 15:43:25 +02001648 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001649 .off1 = td_var_offset(hugepage_size),
1650 .help = "When using hugepages, specify size of each page",
1651 .def = __stringify(FIO_HUGE_PAGE),
1652 },
1653 {
1654 .name = "group_reporting",
1655 .type = FIO_OPT_STR_SET,
1656 .off1 = td_var_offset(group_reporting),
1657 .help = "Do reporting on a per-group basis",
1658 },
1659 {
Jens Axboee9459e52007-04-17 15:46:32 +02001660 .name = "zero_buffers",
1661 .type = FIO_OPT_STR_SET,
1662 .off1 = td_var_offset(zero_buffers),
1663 .help = "Init IO buffers to all zeroes",
1664 },
Jens Axboe5973caf2008-05-21 19:52:35 +02001665 {
1666 .name = "refill_buffers",
1667 .type = FIO_OPT_STR_SET,
1668 .off1 = td_var_offset(refill_buffers),
1669 .help = "Refill IO buffers on every IO submit",
1670 },
Jens Axboe0a839f32007-04-26 09:02:34 +02001671#ifdef FIO_HAVE_DISK_UTIL
1672 {
1673 .name = "disk_util",
1674 .type = FIO_OPT_BOOL,
1675 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001676 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02001677 .def = "1",
1678 },
1679#endif
Jens Axboee9459e52007-04-17 15:46:32 +02001680 {
Jens Axboe993bf482008-11-14 13:04:53 +01001681 .name = "gtod_reduce",
1682 .type = FIO_OPT_BOOL,
1683 .help = "Greatly reduce number of gettimeofday() calls",
1684 .cb = str_gtod_reduce_cb,
1685 .def = "0",
1686 },
1687 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02001688 .name = "disable_clat",
1689 .type = FIO_OPT_BOOL,
1690 .off1 = td_var_offset(disable_clat),
1691 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001692 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001693 .def = "0",
1694 },
1695 {
1696 .name = "disable_slat",
1697 .type = FIO_OPT_BOOL,
1698 .off1 = td_var_offset(disable_slat),
1699 .help = "Disable submissionn latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001700 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001701 .def = "0",
1702 },
1703 {
1704 .name = "disable_bw_measurement",
1705 .type = FIO_OPT_BOOL,
1706 .off1 = td_var_offset(disable_bw),
1707 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01001708 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001709 .def = "0",
1710 },
1711 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001712 .name = "gtod_cpu",
1713 .type = FIO_OPT_INT,
1714 .cb = str_gtod_cpu_cb,
1715 .help = "Setup dedicated gettimeofday() thread on this CPU",
Jens Axboe29d43ff2009-07-01 10:42:18 +02001716 .verify = gtod_cpu_verify,
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001717 },
1718 {
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001719 .name = "continue_on_error",
1720 .type = FIO_OPT_BOOL,
1721 .off1 = td_var_offset(continue_on_error),
1722 .help = "Continue on non-fatal errors during I/O",
1723 .def = "0",
1724 },
1725 {
Jens Axboe9ac8a792009-11-13 21:23:07 +01001726 .name = "profile",
Jens Axboe79d16312010-03-04 12:43:20 +01001727 .type = FIO_OPT_STR_STORE,
Jens Axboe9ac8a792009-11-13 21:23:07 +01001728 .off1 = td_var_offset(profile),
Jens Axboe9ac8a792009-11-13 21:23:07 +01001729 .help = "Select a specific builtin performance test",
1730 },
1731 {
Jens Axboea696fa22009-12-04 10:05:02 +01001732 .name = "cgroup",
1733 .type = FIO_OPT_STR_STORE,
1734 .off1 = td_var_offset(cgroup),
1735 .help = "Add job to cgroup of this name",
1736 },
1737 {
1738 .name = "cgroup_weight",
1739 .type = FIO_OPT_INT,
1740 .off1 = td_var_offset(cgroup_weight),
1741 .help = "Use given weight for cgroup",
1742 .minval = 100,
1743 .maxval = 1000,
Jens Axboea696fa22009-12-04 10:05:02 +01001744 },
1745 {
Jens Axboee0b0d892009-12-08 10:10:14 +01001746 .name = "uid",
1747 .type = FIO_OPT_INT,
1748 .off1 = td_var_offset(uid),
1749 .help = "Run job with this user ID",
1750 },
1751 {
1752 .name = "gid",
1753 .type = FIO_OPT_INT,
1754 .off1 = td_var_offset(gid),
1755 .help = "Run job with this group ID",
1756 },
1757 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001758 .name = NULL,
1759 },
1760};
1761
Jens Axboe9f817362010-03-04 14:38:10 +01001762static void add_to_lopt(struct option *lopt, struct fio_option *o)
1763{
1764 lopt->name = (char *) o->name;
1765 lopt->val = FIO_GETOPT_JOB;
1766 if (o->type == FIO_OPT_STR_SET)
1767 lopt->has_arg = no_argument;
1768 else
1769 lopt->has_arg = required_argument;
1770}
1771
Jens Axboe214e1ec2007-03-15 10:48:13 +01001772void fio_options_dup_and_init(struct option *long_options)
1773{
1774 struct fio_option *o;
1775 unsigned int i;
1776
1777 options_init(options);
1778
1779 i = 0;
1780 while (long_options[i].name)
1781 i++;
1782
1783 o = &options[0];
1784 while (o->name) {
Jens Axboe9f817362010-03-04 14:38:10 +01001785 add_to_lopt(&long_options[i], o);
Jens Axboe214e1ec2007-03-15 10:48:13 +01001786
1787 i++;
1788 o++;
1789 assert(i < FIO_NR_OPTIONS);
1790 }
1791}
1792
Jens Axboe74929ac2009-08-05 11:42:37 +02001793struct fio_keyword {
1794 const char *word;
1795 const char *desc;
1796 char *replace;
1797};
1798
1799static struct fio_keyword fio_keywords[] = {
1800 {
1801 .word = "$pagesize",
1802 .desc = "Page size in the system",
1803 },
1804 {
1805 .word = "$mb_memory",
1806 .desc = "Megabytes of memory online",
1807 },
1808 {
1809 .word = "$ncpus",
1810 .desc = "Number of CPUs online in the system",
1811 },
1812 {
1813 .word = NULL,
1814 },
1815};
1816
1817void fio_keywords_init(void)
1818{
Jens Axboe3b2e1462009-12-15 08:58:10 +01001819 unsigned long long mb_memory;
Jens Axboe74929ac2009-08-05 11:42:37 +02001820 char buf[128];
1821 long l;
1822
1823 sprintf(buf, "%lu", page_size);
1824 fio_keywords[0].replace = strdup(buf);
1825
Jens Axboe3b2e1462009-12-15 08:58:10 +01001826 mb_memory = os_phys_mem() / page_size;
1827 sprintf(buf, "%llu", mb_memory);
Jens Axboe74929ac2009-08-05 11:42:37 +02001828 fio_keywords[1].replace = strdup(buf);
1829
1830 l = sysconf(_SC_NPROCESSORS_ONLN);
1831 sprintf(buf, "%lu", l);
1832 fio_keywords[2].replace = strdup(buf);
1833}
1834
Jens Axboe892a6ff2009-11-13 12:19:49 +01001835#define BC_APP "bc"
1836
1837static char *bc_calc(char *str)
1838{
1839 char *buf, *tmp, opt[80];
1840 FILE *f;
1841 int ret;
1842
1843 /*
1844 * No math, just return string
1845 */
1846 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1847 !strchr(str, '/'))
1848 return str;
1849
1850 /*
1851 * Split option from value, we only need to calculate the value
1852 */
1853 tmp = strchr(str, '=');
1854 if (!tmp)
1855 return str;
1856
1857 tmp++;
Jens Axboe9ac8a792009-11-13 21:23:07 +01001858 memset(opt, 0, sizeof(opt));
Jens Axboe892a6ff2009-11-13 12:19:49 +01001859 strncpy(opt, str, tmp - str);
1860
1861 buf = malloc(128);
1862
1863 sprintf(buf, "which %s > /dev/null", BC_APP);
1864 if (system(buf)) {
1865 log_err("fio: bc is needed for performing math\n");
1866 free(buf);
1867 return NULL;
1868 }
1869
1870 sprintf(buf, "echo %s | %s", tmp, BC_APP);
1871 f = popen(buf, "r");
1872 if (!f) {
1873 free(buf);
1874 return NULL;
1875 }
1876
1877 ret = fread(buf, 1, 128, f);
1878 if (ret <= 0) {
1879 free(buf);
1880 return NULL;
1881 }
1882
1883 buf[ret - 1] = '\0';
1884 strcat(opt, buf);
1885 strcpy(buf, opt);
1886 pclose(f);
1887 free(str);
1888 return buf;
1889}
1890
Jens Axboe74929ac2009-08-05 11:42:37 +02001891/*
1892 * Look for reserved variable names and replace them with real values
1893 */
1894static char *fio_keyword_replace(char *opt)
1895{
1896 char *s;
1897 int i;
1898
1899 for (i = 0; fio_keywords[i].word != NULL; i++) {
1900 struct fio_keyword *kw = &fio_keywords[i];
1901
1902 while ((s = strstr(opt, kw->word)) != NULL) {
1903 char *new = malloc(strlen(opt) + 1);
1904 char *o_org = opt;
1905 int olen = s - opt;
1906 int len;
1907
1908 /*
1909 * Copy part of the string before the keyword and
1910 * sprintf() the replacement after it.
1911 */
1912 memcpy(new, opt, olen);
1913 len = sprintf(new + olen, "%s", kw->replace);
1914
1915 /*
1916 * If there's more in the original string, copy that
1917 * in too
1918 */
1919 opt += strlen(kw->word) + olen;
1920 if (strlen(opt))
1921 memcpy(new + olen + len, opt, opt - o_org - 1);
1922
1923 /*
1924 * replace opt and free the old opt
1925 */
1926 opt = new;
Jens Axboe9ac8a792009-11-13 21:23:07 +01001927 //free(o_org);
Jens Axboe7a958bd2009-11-13 12:33:54 +01001928
1929 /*
1930 * Check for potential math and invoke bc, if possible
1931 */
1932 opt = bc_calc(opt);
Jens Axboe74929ac2009-08-05 11:42:37 +02001933 }
1934 }
1935
Jens Axboe7a958bd2009-11-13 12:33:54 +01001936 return opt;
Jens Axboe74929ac2009-08-05 11:42:37 +02001937}
1938
Jens Axboe3b8b7132008-06-10 19:46:23 +02001939int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01001940{
Jens Axboe3b8b7132008-06-10 19:46:23 +02001941 int i, ret;
1942
1943 sort_options(opts, options, num_opts);
1944
Jens Axboe74929ac2009-08-05 11:42:37 +02001945 for (ret = 0, i = 0; i < num_opts; i++) {
1946 opts[i] = fio_keyword_replace(opts[i]);
Jens Axboe07b32322010-03-05 09:48:44 +01001947 ret |= parse_option(opts[i], options, td);
Jens Axboe74929ac2009-08-05 11:42:37 +02001948 }
Jens Axboe3b8b7132008-06-10 19:46:23 +02001949
1950 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001951}
1952
1953int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1954{
Jens Axboe07b32322010-03-05 09:48:44 +01001955 return parse_cmd_option(opt, val, options, td);
Jens Axboe214e1ec2007-03-15 10:48:13 +01001956}
1957
1958void fio_fill_default_options(struct thread_data *td)
1959{
1960 fill_default_options(td, options);
1961}
1962
1963int fio_show_option_help(const char *opt)
1964{
Jens Axboe07b32322010-03-05 09:48:44 +01001965 return show_cmd_help(options, opt);
Jens Axboe214e1ec2007-03-15 10:48:13 +01001966}
Jens Axboed23bb322007-03-23 15:57:56 +01001967
1968static void __options_mem(struct thread_data *td, int alloc)
1969{
1970 struct thread_options *o = &td->o;
1971 struct fio_option *opt;
1972 char **ptr;
1973 int i;
1974
1975 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1976 if (opt->type != FIO_OPT_STR_STORE)
1977 continue;
1978
1979 ptr = (void *) o + opt->off1;
1980 if (*ptr) {
1981 if (alloc)
1982 *ptr = strdup(*ptr);
1983 else {
1984 free(*ptr);
1985 *ptr = NULL;
1986 }
1987 }
1988 }
1989}
1990
1991/*
1992 * dupe FIO_OPT_STR_STORE options
1993 */
1994void options_mem_dupe(struct thread_data *td)
1995{
1996 __options_mem(td, 1);
1997}
1998
Jens Axboe22d66212007-03-27 20:06:25 +02001999void options_mem_free(struct thread_data fio_unused *td)
Jens Axboed23bb322007-03-23 15:57:56 +01002000{
Jens Axboe22d66212007-03-27 20:06:25 +02002001#if 0
Jens Axboed23bb322007-03-23 15:57:56 +01002002 __options_mem(td, 0);
Jens Axboe22d66212007-03-27 20:06:25 +02002003#endif
Jens Axboed23bb322007-03-23 15:57:56 +01002004}
Jens Axboed6978a32009-07-18 21:04:09 +02002005
2006unsigned int fio_get_kb_base(void *data)
2007{
2008 struct thread_data *td = data;
2009 unsigned int kb_base = 0;
2010
2011 if (td)
2012 kb_base = td->o.kb_base;
2013 if (!kb_base)
2014 kb_base = 1024;
2015
2016 return kb_base;
2017}
Jens Axboe9f988e22010-03-04 10:42:38 +01002018
Jens Axboe07b32322010-03-05 09:48:44 +01002019int add_option(struct fio_option *o)
Jens Axboe9f988e22010-03-04 10:42:38 +01002020{
Jens Axboe07b32322010-03-05 09:48:44 +01002021 struct fio_option *__o;
2022 int opt_index = 0;
2023
2024 __o = options;
2025 while (__o->name) {
2026 opt_index++;
2027 __o++;
2028 }
2029
2030 memcpy(&options[opt_index], o, sizeof(*o));
2031 return 0;
Jens Axboe9f988e22010-03-04 10:42:38 +01002032}
Jens Axboee2de69d2010-03-04 14:05:48 +01002033
Jens Axboe07b32322010-03-05 09:48:44 +01002034void invalidate_profile_options(const char *prof_name)
Jens Axboee2de69d2010-03-04 14:05:48 +01002035{
Jens Axboe07b32322010-03-05 09:48:44 +01002036 struct fio_option *o;
Jens Axboee2de69d2010-03-04 14:05:48 +01002037
Jens Axboe07b32322010-03-05 09:48:44 +01002038 o = options;
2039 while (o->name) {
2040 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2041 o->type = FIO_OPT_INVALID;
2042 o->prof_name = NULL;
2043 }
2044 o++;
Jens Axboee2de69d2010-03-04 14:05:48 +01002045 }
2046}
Jens Axboef5b6bb82010-03-05 10:09:59 +01002047
2048void add_opt_posval(const char *optname, const char *ival, const char *help)
2049{
2050 struct fio_option *o;
2051 unsigned int i;
2052
2053 o = find_option(options, optname);
2054 if (!o)
2055 return;
2056
2057 for (i = 0; i < PARSE_MAX_VP; i++) {
2058 if (o->posval[i].ival)
2059 continue;
2060
2061 o->posval[i].ival = ival;
2062 o->posval[i].help = help;
2063 break;
2064 }
2065}
2066
2067void del_opt_posval(const char *optname, const char *ival)
2068{
2069 struct fio_option *o;
2070 unsigned int i;
2071
2072 o = find_option(options, optname);
2073 if (!o)
2074 return;
2075
2076 for (i = 0; i < PARSE_MAX_VP; i++) {
2077 if (!o->posval[i].ival)
2078 continue;
2079 if (strcmp(o->posval[i].ival, ival))
2080 continue;
2081
2082 o->posval[i].ival = NULL;
2083 o->posval[i].help = NULL;
2084 }
2085}