blob: 1c07982d41cf23497862289d814b294a6e1edcb8 [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 Axboe214e1ec2007-03-15 10:48:13 +010017
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010018#define td_var_offset(var) ((size_t) &((struct thread_options *)0)->var)
Jens Axboe214e1ec2007-03-15 10:48:13 +010019
20/*
21 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
22 */
23static char *get_opt_postfix(const char *str)
24{
25 char *p = strstr(str, ":");
26
27 if (!p)
28 return NULL;
29
30 p++;
31 strip_blank_front(&p);
32 strip_blank_end(p);
33 return strdup(p);
34}
35
Radha Ramachandran0e92f872009-10-27 20:14:27 +010036static int converthexchartoint(char a)
37{
38 int base;
39
40 switch(a) {
41 case '0'...'9':
42 base = '0';
43 break;
44 case 'A'...'F':
45 base = 'A' - 10;
46 break;
47 case 'a'...'f':
48 base = 'a' - 10;
49 break;
50 default:
51 base = 0;
52 }
53 return (a - base);
54}
55
Jens Axboe564ca972007-12-14 12:21:19 +010056static int bs_cmp(const void *p1, const void *p2)
57{
58 const struct bssplit *bsp1 = p1;
59 const struct bssplit *bsp2 = p2;
60
61 return bsp1->perc < bsp2->perc;
62}
63
Jens Axboe720e84a2009-04-21 08:29:55 +020064static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
Jens Axboe564ca972007-12-14 12:21:19 +010065{
Jens Axboe720e84a2009-04-21 08:29:55 +020066 struct bssplit *bssplit;
Jens Axboe564ca972007-12-14 12:21:19 +010067 unsigned int i, perc, perc_missing;
68 unsigned int max_bs, min_bs;
69 long long val;
Jens Axboe720e84a2009-04-21 08:29:55 +020070 char *fname;
Jens Axboe564ca972007-12-14 12:21:19 +010071
Jens Axboe720e84a2009-04-21 08:29:55 +020072 td->o.bssplit_nr[ddir] = 4;
73 bssplit = malloc(4 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010074
75 i = 0;
76 max_bs = 0;
77 min_bs = -1;
78 while ((fname = strsep(&str, ":")) != NULL) {
79 char *perc_str;
80
81 if (!strlen(fname))
82 break;
83
84 /*
85 * grow struct buffer, if needed
86 */
Jens Axboe720e84a2009-04-21 08:29:55 +020087 if (i == td->o.bssplit_nr[ddir]) {
88 td->o.bssplit_nr[ddir] <<= 1;
89 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
Jens Axboe5ec10ea2008-03-06 15:42:00 +010090 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010091 }
92
93 perc_str = strstr(fname, "/");
94 if (perc_str) {
95 *perc_str = '\0';
96 perc_str++;
97 perc = atoi(perc_str);
98 if (perc > 100)
99 perc = 100;
100 else if (!perc)
101 perc = -1;
102 } else
103 perc = -1;
104
Kenneth Watersdf9cf922009-10-15 07:08:48 +0200105 if (str_to_decimal(fname, &val, 1, td)) {
Jens Axboe564ca972007-12-14 12:21:19 +0100106 log_err("fio: bssplit conversion failed\n");
107 free(td->o.bssplit);
108 return 1;
109 }
110
111 if (val > max_bs)
112 max_bs = val;
113 if (val < min_bs)
114 min_bs = val;
115
Jens Axboe720e84a2009-04-21 08:29:55 +0200116 bssplit[i].bs = val;
117 bssplit[i].perc = perc;
Jens Axboe564ca972007-12-14 12:21:19 +0100118 i++;
119 }
120
Jens Axboe720e84a2009-04-21 08:29:55 +0200121 td->o.bssplit_nr[ddir] = i;
Jens Axboe564ca972007-12-14 12:21:19 +0100122
123 /*
124 * Now check if the percentages add up, and how much is missing
125 */
126 perc = perc_missing = 0;
Jens Axboe720e84a2009-04-21 08:29:55 +0200127 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
128 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100129
130 if (bsp->perc == (unsigned char) -1)
131 perc_missing++;
132 else
133 perc += bsp->perc;
134 }
135
136 if (perc > 100) {
137 log_err("fio: bssplit percentages add to more than 100%%\n");
Jens Axboe720e84a2009-04-21 08:29:55 +0200138 free(bssplit);
Jens Axboe564ca972007-12-14 12:21:19 +0100139 return 1;
140 }
141 /*
142 * If values didn't have a percentage set, divide the remains between
143 * them.
144 */
145 if (perc_missing) {
Jens Axboe720e84a2009-04-21 08:29:55 +0200146 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
147 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100148
149 if (bsp->perc == (unsigned char) -1)
150 bsp->perc = (100 - perc) / perc_missing;
151 }
152 }
153
Jens Axboe720e84a2009-04-21 08:29:55 +0200154 td->o.min_bs[ddir] = min_bs;
155 td->o.max_bs[ddir] = max_bs;
Jens Axboe564ca972007-12-14 12:21:19 +0100156
157 /*
158 * now sort based on percentages, for ease of lookup
159 */
Jens Axboe720e84a2009-04-21 08:29:55 +0200160 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
161 td->o.bssplit[ddir] = bssplit;
162 return 0;
163
164}
165
166static int str_bssplit_cb(void *data, const char *input)
167{
168 struct thread_data *td = data;
169 char *str, *p, *odir;
170 int ret = 0;
171
172 p = str = strdup(input);
173
174 strip_blank_front(&str);
175 strip_blank_end(str);
176
177 odir = strchr(str, ',');
178 if (odir) {
179 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
180 if (!ret) {
181 *odir = '\0';
182 ret = bssplit_ddir(td, DDIR_READ, str);
183 }
184 } else {
185 char *op;
186
187 op = strdup(str);
188
189 ret = bssplit_ddir(td, DDIR_READ, str);
190 if (!ret)
191 ret = bssplit_ddir(td, DDIR_WRITE, op);
192
193 free(op);
194 }
Jens Axboe564ca972007-12-14 12:21:19 +0100195
196 free(p);
Jens Axboe720e84a2009-04-21 08:29:55 +0200197 return ret;
Jens Axboe564ca972007-12-14 12:21:19 +0100198}
199
Jens Axboe211097b2007-03-22 18:56:45 +0100200static int str_rw_cb(void *data, const char *str)
201{
202 struct thread_data *td = data;
203 char *nr = get_opt_postfix(str);
204
Jens Axboefafdba32007-03-26 10:09:12 +0200205 td->o.ddir_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100206 if (nr) {
Jens Axboe211097b2007-03-22 18:56:45 +0100207 td->o.ddir_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100208 free(nr);
209 }
Jens Axboe211097b2007-03-22 18:56:45 +0100210
Jens Axboe211097b2007-03-22 18:56:45 +0100211 return 0;
212}
213
Jens Axboe214e1ec2007-03-15 10:48:13 +0100214static int str_mem_cb(void *data, const char *mem)
215{
216 struct thread_data *td = data;
217
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100218 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100219 td->mmapfile = get_opt_postfix(mem);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100220 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100221 log_err("fio: mmaphuge:/path/to/file\n");
222 return 1;
223 }
224 }
225
226 return 0;
227}
228
229static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
230{
231 mlock_size = *val;
232 return 0;
233}
234
Jens Axboecb499fc2008-05-28 10:33:32 +0200235static int str_rwmix_read_cb(void *data, unsigned int *val)
236{
237 struct thread_data *td = data;
238
239 td->o.rwmix[DDIR_READ] = *val;
240 td->o.rwmix[DDIR_WRITE] = 100 - *val;
241 return 0;
242}
243
244static int str_rwmix_write_cb(void *data, unsigned int *val)
245{
246 struct thread_data *td = data;
247
248 td->o.rwmix[DDIR_WRITE] = *val;
249 td->o.rwmix[DDIR_READ] = 100 - *val;
250 return 0;
251}
252
Jens Axboe214e1ec2007-03-15 10:48:13 +0100253#ifdef FIO_HAVE_IOPRIO
254static int str_prioclass_cb(void *data, unsigned int *val)
255{
256 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200257 unsigned short mask;
258
259 /*
260 * mask off old class bits, str_prio_cb() may have set a default class
261 */
262 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
263 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100264
265 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
Jens Axboeac684782007-11-08 08:29:07 +0100266 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100267 return 0;
268}
269
270static int str_prio_cb(void *data, unsigned int *val)
271{
272 struct thread_data *td = data;
273
274 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200275
276 /*
277 * If no class is set, assume BE
278 */
279 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
280 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
281
Jens Axboeac684782007-11-08 08:29:07 +0100282 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100283 return 0;
284}
285#endif
286
287static int str_exitall_cb(void)
288{
289 exitall_on_terminate = 1;
290 return 0;
291}
292
Jens Axboe214e1ec2007-03-15 10:48:13 +0100293#ifdef FIO_HAVE_CPU_AFFINITY
Jens Axboe214e1ec2007-03-15 10:48:13 +0100294static int str_cpumask_cb(void *data, unsigned int *val)
295{
296 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200297 unsigned int i;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100298 long max_cpu;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100299 int ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100300
Jens Axboed2ce18b2008-12-12 20:51:40 +0100301 ret = fio_cpuset_init(&td->o.cpumask);
302 if (ret < 0) {
303 log_err("fio: cpuset_init failed\n");
304 td_verror(td, ret, "fio_cpuset_init");
305 return 1;
306 }
307
Jens Axboeb03daaf2008-12-08 20:31:43 +0100308 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
Jens Axboed2e268b2007-06-15 10:33:49 +0200309
Jens Axboe62a72732008-12-08 11:37:01 +0100310 for (i = 0; i < sizeof(int) * 8; i++) {
311 if ((1 << i) & *val) {
Jens Axboeb03daaf2008-12-08 20:31:43 +0100312 if (i > max_cpu) {
313 log_err("fio: CPU %d too large (max=%ld)\n", i,
314 max_cpu);
315 return 1;
316 }
Jens Axboe62a72732008-12-08 11:37:01 +0100317 dprint(FD_PARSE, "set cpu allowed %d\n", i);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100318 fio_cpu_set(&td->o.cpumask, i);
Jens Axboe62a72732008-12-08 11:37:01 +0100319 }
320 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200321
Jens Axboe375b2692007-05-22 09:13:02 +0200322 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100323 return 0;
324}
325
Jens Axboee8462bd2009-07-06 12:59:04 +0200326static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
327 const char *input)
Jens Axboed2e268b2007-06-15 10:33:49 +0200328{
Jens Axboed2e268b2007-06-15 10:33:49 +0200329 char *cpu, *str, *p;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100330 long max_cpu;
Jens Axboe19608d62008-12-08 15:03:12 +0100331 int ret = 0;
Jens Axboed2e268b2007-06-15 10:33:49 +0200332
Jens Axboee8462bd2009-07-06 12:59:04 +0200333 ret = fio_cpuset_init(mask);
Jens Axboed2ce18b2008-12-12 20:51:40 +0100334 if (ret < 0) {
335 log_err("fio: cpuset_init failed\n");
336 td_verror(td, ret, "fio_cpuset_init");
337 return 1;
338 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200339
340 p = str = strdup(input);
341
342 strip_blank_front(&str);
343 strip_blank_end(str);
344
Jens Axboeb03daaf2008-12-08 20:31:43 +0100345 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
346
Jens Axboed2e268b2007-06-15 10:33:49 +0200347 while ((cpu = strsep(&str, ",")) != NULL) {
Jens Axboe62a72732008-12-08 11:37:01 +0100348 char *str2, *cpu2;
349 int icpu, icpu2;
350
Jens Axboed2e268b2007-06-15 10:33:49 +0200351 if (!strlen(cpu))
352 break;
Jens Axboe62a72732008-12-08 11:37:01 +0100353
354 str2 = cpu;
355 icpu2 = -1;
356 while ((cpu2 = strsep(&str2, "-")) != NULL) {
357 if (!strlen(cpu2))
358 break;
359
360 icpu2 = atoi(cpu2);
361 }
362
363 icpu = atoi(cpu);
364 if (icpu2 == -1)
365 icpu2 = icpu;
366 while (icpu <= icpu2) {
Jens Axboe6d459ee2008-12-12 20:02:58 +0100367 if (icpu >= FIO_MAX_CPUS) {
Jens Axboe19608d62008-12-08 15:03:12 +0100368 log_err("fio: your OS only supports up to"
Jens Axboe6d459ee2008-12-12 20:02:58 +0100369 " %d CPUs\n", (int) FIO_MAX_CPUS);
Jens Axboe19608d62008-12-08 15:03:12 +0100370 ret = 1;
371 break;
372 }
Jens Axboeb03daaf2008-12-08 20:31:43 +0100373 if (icpu > max_cpu) {
374 log_err("fio: CPU %d too large (max=%ld)\n",
375 icpu, max_cpu);
376 ret = 1;
377 break;
378 }
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200379
Jens Axboe62a72732008-12-08 11:37:01 +0100380 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
Jens Axboee8462bd2009-07-06 12:59:04 +0200381 fio_cpu_set(mask, icpu);
Jens Axboe62a72732008-12-08 11:37:01 +0100382 icpu++;
383 }
Jens Axboe19608d62008-12-08 15:03:12 +0100384 if (ret)
385 break;
Jens Axboed2e268b2007-06-15 10:33:49 +0200386 }
387
388 free(p);
Jens Axboe19608d62008-12-08 15:03:12 +0100389 if (!ret)
390 td->o.cpumask_set = 1;
391 return ret;
Jens Axboed2e268b2007-06-15 10:33:49 +0200392}
Jens Axboee8462bd2009-07-06 12:59:04 +0200393
394static int str_cpus_allowed_cb(void *data, const char *input)
395{
396 struct thread_data *td = data;
397 int ret;
398
399 ret = set_cpus_allowed(td, &td->o.cpumask, input);
400 if (!ret)
401 td->o.cpumask_set = 1;
402
403 return ret;
404}
405
406static int str_verify_cpus_allowed_cb(void *data, const char *input)
407{
408 struct thread_data *td = data;
409 int ret;
410
411 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
412 if (!ret)
413 td->o.verify_cpumask_set = 1;
414
415 return ret;
416}
Jens Axboed2e268b2007-06-15 10:33:49 +0200417#endif
418
Jens Axboe214e1ec2007-03-15 10:48:13 +0100419static int str_fst_cb(void *data, const char *str)
420{
421 struct thread_data *td = data;
422 char *nr = get_opt_postfix(str);
423
424 td->file_service_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100425 if (nr) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100426 td->file_service_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100427 free(nr);
428 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100429
430 return 0;
431}
432
Jens Axboe921c7662008-03-26 09:17:55 +0100433static int check_dir(struct thread_data *td, char *fname)
434{
435 char file[PATH_MAX], *dir;
Jens Axboebc838912008-04-07 09:00:54 +0200436 int elen = 0;
Jens Axboe921c7662008-03-26 09:17:55 +0100437
Jens Axboebc838912008-04-07 09:00:54 +0200438 if (td->o.directory) {
439 strcpy(file, td->o.directory);
Jens Axboefcef0b32008-05-26 14:53:24 +0200440 strcat(file, "/");
Jens Axboebc838912008-04-07 09:00:54 +0200441 elen = strlen(file);
442 }
443
Jens Axboefcef0b32008-05-26 14:53:24 +0200444 sprintf(file + elen, "%s", fname);
Jens Axboe921c7662008-03-26 09:17:55 +0100445 dir = dirname(file);
446
Jens Axboefcef0b32008-05-26 14:53:24 +0200447#if 0
448 {
449 struct stat sb;
450 /*
451 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
452 * yet, so we can't do this check right here...
453 */
Jens Axboe921c7662008-03-26 09:17:55 +0100454 if (lstat(dir, &sb) < 0) {
455 int ret = errno;
456
457 log_err("fio: %s is not a directory\n", dir);
458 td_verror(td, ret, "lstat");
459 return 1;
460 }
461
462 if (!S_ISDIR(sb.st_mode)) {
463 log_err("fio: %s is not a directory\n", dir);
464 return 1;
465 }
Jens Axboefcef0b32008-05-26 14:53:24 +0200466 }
467#endif
Jens Axboe921c7662008-03-26 09:17:55 +0100468
469 return 0;
470}
471
Jens Axboe8e827d32009-08-04 09:51:48 +0200472/*
473 * Return next file in the string. Files are separated with ':'. If the ':'
474 * is escaped with a '\', then that ':' is part of the filename and does not
475 * indicate a new file.
476 */
477static char *get_next_file_name(char **ptr)
478{
479 char *str = *ptr;
480 char *p, *start;
481
482 if (!str || !strlen(str))
483 return NULL;
484
485 start = str;
486 do {
487 /*
488 * No colon, we are done
489 */
490 p = strchr(str, ':');
491 if (!p) {
492 *ptr = NULL;
493 break;
494 }
495
496 /*
497 * We got a colon, but it's the first character. Skip and
498 * continue
499 */
500 if (p == start) {
501 str = ++start;
502 continue;
503 }
504
505 if (*(p - 1) != '\\') {
506 *p = '\0';
507 *ptr = p + 1;
508 break;
509 }
510
511 memmove(p - 1, p, strlen(p) + 1);
512 str = p;
513 } while (1);
514
515 return start;
516}
517
Jens Axboe214e1ec2007-03-15 10:48:13 +0100518static int str_filename_cb(void *data, const char *input)
519{
520 struct thread_data *td = data;
521 char *fname, *str, *p;
522
523 p = str = strdup(input);
524
525 strip_blank_front(&str);
526 strip_blank_end(str);
527
528 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100529 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100530
Jens Axboe8e827d32009-08-04 09:51:48 +0200531 while ((fname = get_next_file_name(&str)) != NULL) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100532 if (!strlen(fname))
533 break;
Jens Axboe921c7662008-03-26 09:17:55 +0100534 if (check_dir(td, fname)) {
535 free(p);
536 return 1;
537 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100538 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100539 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100540 }
541
542 free(p);
543 return 0;
544}
545
546static int str_directory_cb(void *data, const char fio_unused *str)
547{
548 struct thread_data *td = data;
549 struct stat sb;
550
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100551 if (lstat(td->o.directory, &sb) < 0) {
Jens Axboe921c7662008-03-26 09:17:55 +0100552 int ret = errno;
553
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100554 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe921c7662008-03-26 09:17:55 +0100555 td_verror(td, ret, "lstat");
Jens Axboe214e1ec2007-03-15 10:48:13 +0100556 return 1;
557 }
558 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100559 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100560 return 1;
561 }
562
563 return 0;
564}
565
566static int str_opendir_cb(void *data, const char fio_unused *str)
567{
568 struct thread_data *td = data;
569
570 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100571 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100572
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100573 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100574}
575
Jens Axboea59e1702007-07-30 08:53:27 +0200576static int str_verify_offset_cb(void *data, unsigned int *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200577{
578 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200579
Shawn Lewis546a9142007-07-28 21:11:37 +0200580 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200581 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200582 return 1;
583 }
Jens Axboea59e1702007-07-30 08:53:27 +0200584
585 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200586 return 0;
587}
588
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100589static int str_verify_pattern_cb(void *data, const char *input)
Jens Axboe90059d62007-07-30 09:33:12 +0200590{
591 struct thread_data *td = data;
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100592 long off;
593 int i = 0, j = 0, len, k, base = 10;
594 char* loc1, * loc2;
Jens Axboe90059d62007-07-30 09:33:12 +0200595
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100596 loc1 = strstr(input, "0x");
597 loc2 = strstr(input, "0X");
598 if (loc1 || loc2)
599 base = 16;
600 off = strtol(input, NULL, base);
601 if (off != LONG_MAX || errno != ERANGE) {
602 while (off) {
603 td->o.verify_pattern[i] = off & 0xff;
604 off >>= 8;
605 i++;
606 }
607 } else {
608 len = strlen(input);
609 k = len - 1;
610 if (base == 16) {
611 if (loc1)
612 j = loc1 - input + 2;
613 else
614 j = loc2 - input + 2;
615 } else
616 return 1;
617 if (len - j < MAX_PATTERN_SIZE * 2) {
618 while (k >= j) {
619 off = converthexchartoint(input[k--]);
620 if (k >= j)
621 off += (converthexchartoint(input[k--])
622 * 16);
623 td->o.verify_pattern[i++] = (char) off;
624 }
625 }
626 }
627 td->o.verify_pattern_bytes = i;
Jens Axboe90059d62007-07-30 09:33:12 +0200628 return 0;
629}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100630
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100631static int str_lockfile_cb(void *data, const char *str)
632{
633 struct thread_data *td = data;
634 char *nr = get_opt_postfix(str);
635
636 td->o.lockfile_batch = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100637 if (nr) {
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100638 td->o.lockfile_batch = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100639 free(nr);
640 }
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100641
642 return 0;
643}
644
Jens Axboee3cedca2008-11-19 19:57:52 +0100645static int str_write_bw_log_cb(void *data, const char *str)
646{
647 struct thread_data *td = data;
648
649 if (str)
650 td->o.bw_log_file = strdup(str);
651
652 td->o.write_bw_log = 1;
653 return 0;
654}
655
656static int str_write_lat_log_cb(void *data, const char *str)
657{
658 struct thread_data *td = data;
659
660 if (str)
661 td->o.lat_log_file = strdup(str);
662
663 td->o.write_lat_log = 1;
664 return 0;
665}
666
Jens Axboe993bf482008-11-14 13:04:53 +0100667static int str_gtod_reduce_cb(void *data, int *il)
668{
669 struct thread_data *td = data;
670 int val = *il;
671
672 td->o.disable_clat = !!val;
673 td->o.disable_slat = !!val;
674 td->o.disable_bw = !!val;
675 if (val)
676 td->tv_cache_mask = 63;
677
678 return 0;
679}
680
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100681static int str_gtod_cpu_cb(void *data, int *il)
682{
683 struct thread_data *td = data;
684 int val = *il;
685
686 td->o.gtod_cpu = val;
687 td->o.gtod_offload = 1;
688 return 0;
689}
690
Jens Axboe896cac22009-07-01 10:38:35 +0200691static int rw_verify(struct fio_option *o, void *data)
692{
693 struct thread_data *td = data;
694
695 if (read_only && td_write(td)) {
696 log_err("fio: job <%s> has write bit set, but fio is in"
697 " read-only mode\n", td->o.name);
698 return 1;
699 }
700
701 return 0;
702}
703
Jens Axboe276ca4f2009-07-01 10:43:05 +0200704static int gtod_cpu_verify(struct fio_option *o, void *data)
Jens Axboe29d43ff2009-07-01 10:42:18 +0200705{
Jens Axboe276ca4f2009-07-01 10:43:05 +0200706#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboe29d43ff2009-07-01 10:42:18 +0200707 struct thread_data *td = data;
708
Jens Axboe29d43ff2009-07-01 10:42:18 +0200709 if (td->o.gtod_cpu) {
710 log_err("fio: platform must support CPU affinity for"
711 "gettimeofday() offloading\n");
712 return 1;
713 }
714#endif
715
716 return 0;
717}
718
Jens Axboe90fef2d2009-07-17 22:33:32 +0200719static int kb_base_verify(struct fio_option *o, void *data)
720{
721 struct thread_data *td = data;
722
723 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
724 log_err("fio: kb_base set to nonsensical value: %u\n",
725 td->o.kb_base);
726 return 1;
727 }
728
729 return 0;
730}
731
Jens Axboe214e1ec2007-03-15 10:48:13 +0100732#define __stringify_1(x) #x
733#define __stringify(x) __stringify_1(x)
734
735/*
736 * Map of job/command line options
737 */
738static struct fio_option options[] = {
739 {
740 .name = "description",
741 .type = FIO_OPT_STR_STORE,
742 .off1 = td_var_offset(description),
743 .help = "Text job description",
744 },
745 {
746 .name = "name",
747 .type = FIO_OPT_STR_STORE,
748 .off1 = td_var_offset(name),
749 .help = "Name of this job",
750 },
751 {
752 .name = "directory",
753 .type = FIO_OPT_STR_STORE,
754 .off1 = td_var_offset(directory),
755 .cb = str_directory_cb,
756 .help = "Directory to store files in",
757 },
758 {
759 .name = "filename",
760 .type = FIO_OPT_STR_STORE,
761 .off1 = td_var_offset(filename),
762 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +0200763 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +0100764 .help = "File(s) to use for the workload",
765 },
766 {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200767 .name = "kb_base",
768 .type = FIO_OPT_INT,
769 .off1 = td_var_offset(kb_base),
Jens Axboe90fef2d2009-07-17 22:33:32 +0200770 .verify = kb_base_verify,
Jens Axboea639f0b2009-07-18 08:25:35 +0200771 .prio = 1,
Jens Axboe90fef2d2009-07-17 22:33:32 +0200772 .def = "1024",
Jens Axboea639f0b2009-07-18 08:25:35 +0200773 .help = "How many bytes per KB for reporting (1000 or 1024)",
Jens Axboe90fef2d2009-07-17 22:33:32 +0200774 },
775 {
Jens Axboe29c13492008-03-01 19:25:20 +0100776 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100777 .type = FIO_OPT_STR,
778 .cb = str_lockfile_cb,
779 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +0100780 .help = "Lock file when doing IO to it",
781 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100782 .def = "none",
783 .posval = {
784 { .ival = "none",
785 .oval = FILE_LOCK_NONE,
786 .help = "No file locking",
787 },
788 { .ival = "exclusive",
789 .oval = FILE_LOCK_EXCLUSIVE,
790 .help = "Exclusive file lock",
791 },
792 {
793 .ival = "readwrite",
794 .oval = FILE_LOCK_READWRITE,
795 .help = "Read vs write lock",
796 },
797 },
Jens Axboe29c13492008-03-01 19:25:20 +0100798 },
799 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100800 .name = "opendir",
801 .type = FIO_OPT_STR_STORE,
802 .off1 = td_var_offset(opendir),
803 .cb = str_opendir_cb,
804 .help = "Recursively add files from this directory and down",
805 },
806 {
807 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100808 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100809 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +0100810 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100811 .off1 = td_var_offset(td_ddir),
812 .help = "IO direction",
813 .def = "read",
Jens Axboe896cac22009-07-01 10:38:35 +0200814 .verify = rw_verify,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100815 .posval = {
816 { .ival = "read",
817 .oval = TD_DDIR_READ,
818 .help = "Sequential read",
819 },
820 { .ival = "write",
821 .oval = TD_DDIR_WRITE,
822 .help = "Sequential write",
823 },
824 { .ival = "randread",
825 .oval = TD_DDIR_RANDREAD,
826 .help = "Random read",
827 },
828 { .ival = "randwrite",
829 .oval = TD_DDIR_RANDWRITE,
830 .help = "Random write",
831 },
832 { .ival = "rw",
833 .oval = TD_DDIR_RW,
834 .help = "Sequential read and write mix",
835 },
836 { .ival = "randrw",
837 .oval = TD_DDIR_RANDRW,
838 .help = "Random read and write mix"
839 },
840 },
841 },
842 {
843 .name = "ioengine",
844 .type = FIO_OPT_STR_STORE,
845 .off1 = td_var_offset(ioengine),
846 .help = "IO engine to use",
847 .def = "sync",
848 .posval = {
849 { .ival = "sync",
850 .help = "Use read/write",
851 },
gurudas paia31041e2007-10-23 15:12:30 +0200852 { .ival = "psync",
853 .help = "Use pread/pwrite",
854 },
Jens Axboe1d2af022008-02-04 10:59:07 +0100855 { .ival = "vsync",
856 .help = "Use readv/writev",
857 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100858#ifdef FIO_HAVE_LIBAIO
859 { .ival = "libaio",
860 .help = "Linux native asynchronous IO",
861 },
862#endif
863#ifdef FIO_HAVE_POSIXAIO
864 { .ival = "posixaio",
865 .help = "POSIX asynchronous IO",
866 },
867#endif
Jens Axboe417f0062008-06-02 11:59:30 +0200868#ifdef FIO_HAVE_SOLARISAIO
869 { .ival = "solarisaio",
870 .help = "Solaris native asynchronous IO",
871 },
872#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100873 { .ival = "mmap",
874 .help = "Memory mapped IO",
875 },
876#ifdef FIO_HAVE_SPLICE
877 { .ival = "splice",
878 .help = "splice/vmsplice based IO",
879 },
Jens Axboe9cce02e2007-06-22 15:42:21 +0200880 { .ival = "netsplice",
881 .help = "splice/vmsplice to/from the network",
882 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100883#endif
884#ifdef FIO_HAVE_SGIO
885 { .ival = "sg",
886 .help = "SCSI generic v3 IO",
887 },
888#endif
889 { .ival = "null",
890 .help = "Testing engine (no data transfer)",
891 },
892 { .ival = "net",
893 .help = "Network IO",
894 },
895#ifdef FIO_HAVE_SYSLET
896 { .ival = "syslet-rw",
897 .help = "syslet enabled async pread/pwrite IO",
898 },
899#endif
900 { .ival = "cpuio",
901 .help = "CPU cycler burner engine",
902 },
Jens Axboeb8c82a42007-03-21 08:48:26 +0100903#ifdef FIO_HAVE_GUASI
904 { .ival = "guasi",
905 .help = "GUASI IO engine",
906 },
907#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100908 { .ival = "external",
909 .help = "Load external engine (append name)",
910 },
911 },
912 },
913 {
914 .name = "iodepth",
915 .type = FIO_OPT_INT,
916 .off1 = td_var_offset(iodepth),
917 .help = "Amount of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +0100918 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100919 .def = "1",
920 },
921 {
922 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +0200923 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100924 .type = FIO_OPT_INT,
925 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +0100926 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +0200927 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +0100928 .minval = 1,
929 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100930 },
931 {
Jens Axboe49504212008-06-05 09:03:30 +0200932 .name = "iodepth_batch_complete",
933 .type = FIO_OPT_INT,
934 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +0100935 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +0200936 .parent = "iodepth",
937 .minval = 0,
938 .def = "1",
939 },
940 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100941 .name = "iodepth_low",
942 .type = FIO_OPT_INT,
943 .off1 = td_var_offset(iodepth_low),
944 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +0200945 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100946 },
947 {
948 .name = "size",
949 .type = FIO_OPT_STR_VAL,
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100950 .off1 = td_var_offset(size),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200951 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100952 .help = "Total size of device or files",
953 },
954 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +0100955 .name = "fill_device",
956 .type = FIO_OPT_BOOL,
957 .off1 = td_var_offset(fill_device),
958 .help = "Write until an ENOSPC error occurs",
959 .def = "0",
960 },
961 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100962 .name = "filesize",
963 .type = FIO_OPT_STR_VAL,
964 .off1 = td_var_offset(file_size_low),
965 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200966 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100967 .help = "Size of individual files",
968 },
969 {
Jens Axboe67a10002007-07-31 23:12:16 +0200970 .name = "offset",
971 .alias = "fileoffset",
972 .type = FIO_OPT_STR_VAL,
973 .off1 = td_var_offset(start_offset),
974 .help = "Start IO from this offset",
975 .def = "0",
976 },
977 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100978 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100979 .alias = "blocksize",
Jens Axboee01b22b2009-06-09 15:43:25 +0200980 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100981 .off1 = td_var_offset(bs[DDIR_READ]),
982 .off2 = td_var_offset(bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +0200983 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100984 .help = "Block size unit",
985 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +0200986 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100987 },
988 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +0100989 .name = "ba",
990 .alias = "blockalign",
Jens Axboee01b22b2009-06-09 15:43:25 +0200991 .type = FIO_OPT_INT,
Jens Axboe2b7a01d2009-03-11 11:00:13 +0100992 .off1 = td_var_offset(ba[DDIR_READ]),
993 .off2 = td_var_offset(ba[DDIR_WRITE]),
994 .minval = 1,
995 .help = "IO block offset alignment",
996 .parent = "rw",
997 },
998 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100999 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001000 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001001 .type = FIO_OPT_RANGE,
1002 .off1 = td_var_offset(min_bs[DDIR_READ]),
1003 .off2 = td_var_offset(max_bs[DDIR_READ]),
1004 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1005 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001006 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001007 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +02001008 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001009 },
1010 {
Jens Axboe564ca972007-12-14 12:21:19 +01001011 .name = "bssplit",
1012 .type = FIO_OPT_STR,
1013 .cb = str_bssplit_cb,
1014 .help = "Set a specific mix of block sizes",
1015 .parent = "rw",
1016 },
1017 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001018 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001019 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001020 .type = FIO_OPT_STR_SET,
1021 .off1 = td_var_offset(bs_unaligned),
1022 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +02001023 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001024 },
1025 {
1026 .name = "randrepeat",
1027 .type = FIO_OPT_BOOL,
1028 .off1 = td_var_offset(rand_repeatable),
1029 .help = "Use repeatable random IO pattern",
1030 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +02001031 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001032 },
1033 {
1034 .name = "norandommap",
1035 .type = FIO_OPT_STR_SET,
1036 .off1 = td_var_offset(norandommap),
1037 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +02001038 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001039 },
1040 {
Jens Axboe2b386d22008-03-26 10:32:57 +01001041 .name = "softrandommap",
1042 .type = FIO_OPT_BOOL,
1043 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001044 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +01001045 .parent = "norandommap",
1046 .def = "0",
1047 },
1048 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001049 .name = "nrfiles",
1050 .type = FIO_OPT_INT,
1051 .off1 = td_var_offset(nr_files),
1052 .help = "Split job workload between this number of files",
1053 .def = "1",
1054 },
1055 {
1056 .name = "openfiles",
1057 .type = FIO_OPT_INT,
1058 .off1 = td_var_offset(open_files),
1059 .help = "Number of files to keep open at the same time",
1060 },
1061 {
1062 .name = "file_service_type",
1063 .type = FIO_OPT_STR,
1064 .cb = str_fst_cb,
1065 .off1 = td_var_offset(file_service_type),
1066 .help = "How to select which file to service next",
1067 .def = "roundrobin",
1068 .posval = {
1069 { .ival = "random",
1070 .oval = FIO_FSERVICE_RANDOM,
1071 .help = "Choose a file at random",
1072 },
1073 { .ival = "roundrobin",
1074 .oval = FIO_FSERVICE_RR,
1075 .help = "Round robin select files",
1076 },
Jens Axboea086c252009-03-04 08:27:37 +01001077 { .ival = "sequential",
1078 .oval = FIO_FSERVICE_SEQ,
1079 .help = "Finish one file before moving to the next",
1080 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001081 },
Jens Axboe67a10002007-07-31 23:12:16 +02001082 .parent = "nrfiles",
1083 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001084#ifdef FIO_HAVE_FALLOCATE
1085 {
1086 .name = "fallocate",
1087 .type = FIO_OPT_BOOL,
1088 .off1 = td_var_offset(fallocate),
1089 .help = "Use fallocate() when laying out files",
1090 .def = "1",
1091 },
1092#endif
Jens Axboe67a10002007-07-31 23:12:16 +02001093 {
1094 .name = "fadvise_hint",
1095 .type = FIO_OPT_BOOL,
1096 .off1 = td_var_offset(fadvise_hint),
1097 .help = "Use fadvise() to advise the kernel on IO pattern",
1098 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001099 },
1100 {
1101 .name = "fsync",
1102 .type = FIO_OPT_INT,
1103 .off1 = td_var_offset(fsync_blocks),
1104 .help = "Issue fsync for writes every given number of blocks",
1105 .def = "0",
1106 },
1107 {
Jens Axboe5f9099e2009-06-16 22:40:26 +02001108 .name = "fdatasync",
1109 .type = FIO_OPT_INT,
1110 .off1 = td_var_offset(fdatasync_blocks),
1111 .help = "Issue fdatasync for writes every given number of blocks",
1112 .def = "0",
1113 },
1114 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001115 .name = "direct",
1116 .type = FIO_OPT_BOOL,
1117 .off1 = td_var_offset(odirect),
1118 .help = "Use O_DIRECT IO (negates buffered)",
1119 .def = "0",
1120 },
1121 {
1122 .name = "buffered",
1123 .type = FIO_OPT_BOOL,
1124 .off1 = td_var_offset(odirect),
1125 .neg = 1,
1126 .help = "Use buffered IO (negates direct)",
1127 .def = "1",
1128 },
1129 {
1130 .name = "overwrite",
1131 .type = FIO_OPT_BOOL,
1132 .off1 = td_var_offset(overwrite),
1133 .help = "When writing, set whether to overwrite current data",
1134 .def = "0",
1135 },
1136 {
1137 .name = "loops",
1138 .type = FIO_OPT_INT,
1139 .off1 = td_var_offset(loops),
1140 .help = "Number of times to run the job",
1141 .def = "1",
1142 },
1143 {
1144 .name = "numjobs",
1145 .type = FIO_OPT_INT,
1146 .off1 = td_var_offset(numjobs),
1147 .help = "Duplicate this job this many times",
1148 .def = "1",
1149 },
1150 {
1151 .name = "startdelay",
1152 .type = FIO_OPT_INT,
1153 .off1 = td_var_offset(start_delay),
1154 .help = "Only start job when this period has passed",
1155 .def = "0",
1156 },
1157 {
1158 .name = "runtime",
1159 .alias = "timeout",
1160 .type = FIO_OPT_STR_VAL_TIME,
1161 .off1 = td_var_offset(timeout),
1162 .help = "Stop workload when this amount of time has passed",
1163 .def = "0",
1164 },
1165 {
Jens Axboecf4464c2007-04-17 20:14:42 +02001166 .name = "time_based",
1167 .type = FIO_OPT_STR_SET,
1168 .off1 = td_var_offset(time_based),
1169 .help = "Keep running until runtime/timeout is met",
1170 },
1171 {
Jens Axboe721938a2008-09-10 09:46:16 +02001172 .name = "ramp_time",
1173 .type = FIO_OPT_STR_VAL_TIME,
1174 .off1 = td_var_offset(ramp_time),
1175 .help = "Ramp up time before measuring performance",
1176 },
1177 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001178 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001179 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001180 .type = FIO_OPT_STR,
1181 .cb = str_mem_cb,
1182 .off1 = td_var_offset(mem_type),
1183 .help = "Backing type for IO buffers",
1184 .def = "malloc",
1185 .posval = {
1186 { .ival = "malloc",
1187 .oval = MEM_MALLOC,
1188 .help = "Use malloc(3) for IO buffers",
1189 },
Jens Axboeb370e462007-03-19 10:51:49 +01001190 { .ival = "shm",
1191 .oval = MEM_SHM,
1192 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001193 },
1194#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001195 { .ival = "shmhuge",
1196 .oval = MEM_SHMHUGE,
1197 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001198 },
1199#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001200 { .ival = "mmap",
1201 .oval = MEM_MMAP,
1202 .help = "Use mmap(2) (file or anon) for IO buffers",
1203 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001204#ifdef FIO_HAVE_HUGETLB
1205 { .ival = "mmaphuge",
1206 .oval = MEM_MMAPHUGE,
1207 .help = "Like mmap, but use huge pages",
1208 },
1209#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001210 },
1211 },
1212 {
Jens Axboed529ee12009-07-01 10:33:03 +02001213 .name = "iomem_align",
1214 .alias = "mem_align",
1215 .type = FIO_OPT_INT,
1216 .off1 = td_var_offset(mem_align),
1217 .minval = 0,
1218 .help = "IO memory buffer offset alignment",
1219 .def = "0",
1220 .parent = "iomem",
1221 },
1222 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001223 .name = "verify",
1224 .type = FIO_OPT_STR,
1225 .off1 = td_var_offset(verify),
1226 .help = "Verify data written",
1227 .def = "0",
1228 .posval = {
1229 { .ival = "0",
1230 .oval = VERIFY_NONE,
1231 .help = "Don't do IO verification",
1232 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001233 { .ival = "md5",
1234 .oval = VERIFY_MD5,
1235 .help = "Use md5 checksums for verification",
1236 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001237 { .ival = "crc64",
1238 .oval = VERIFY_CRC64,
1239 .help = "Use crc64 checksums for verification",
1240 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001241 { .ival = "crc32",
1242 .oval = VERIFY_CRC32,
1243 .help = "Use crc32 checksums for verification",
1244 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001245 { .ival = "crc32c-intel",
1246 .oval = VERIFY_CRC32C_INTEL,
1247 .help = "Use hw crc32c checksums for verification",
1248 },
Jens Axboebac39e02008-06-11 20:46:19 +02001249 { .ival = "crc32c",
1250 .oval = VERIFY_CRC32C,
1251 .help = "Use crc32c checksums for verification",
1252 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001253 { .ival = "crc16",
1254 .oval = VERIFY_CRC16,
1255 .help = "Use crc16 checksums for verification",
1256 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001257 { .ival = "crc7",
1258 .oval = VERIFY_CRC7,
1259 .help = "Use crc7 checksums for verification",
1260 },
Jens Axboe7c353ce2009-08-09 22:40:33 +02001261 { .ival = "sha1",
1262 .oval = VERIFY_SHA1,
1263 .help = "Use sha1 checksums for verification",
1264 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001265 { .ival = "sha256",
1266 .oval = VERIFY_SHA256,
1267 .help = "Use sha256 checksums for verification",
1268 },
1269 { .ival = "sha512",
1270 .oval = VERIFY_SHA512,
1271 .help = "Use sha512 checksums for verification",
1272 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001273 { .ival = "meta",
1274 .oval = VERIFY_META,
1275 .help = "Use io information",
1276 },
Jens Axboe36690c92007-03-26 10:23:34 +02001277 {
1278 .ival = "null",
1279 .oval = VERIFY_NULL,
1280 .help = "Pretend to verify",
1281 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001282 },
1283 },
1284 {
Jens Axboe005c5652007-08-02 22:21:36 +02001285 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001286 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001287 .off1 = td_var_offset(do_verify),
1288 .help = "Run verification stage after write",
1289 .def = "1",
1290 .parent = "verify",
1291 },
1292 {
Jens Axboe160b9662007-03-27 10:59:49 +02001293 .name = "verifysort",
1294 .type = FIO_OPT_BOOL,
1295 .off1 = td_var_offset(verifysort),
1296 .help = "Sort written verify blocks for read back",
1297 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001298 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001299 },
1300 {
Jens Axboea59e1702007-07-30 08:53:27 +02001301 .name = "verify_interval",
Jens Axboee01b22b2009-06-09 15:43:25 +02001302 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001303 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001304 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001305 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001306 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001307 },
1308 {
Jens Axboea59e1702007-07-30 08:53:27 +02001309 .name = "verify_offset",
Jens Axboee01b22b2009-06-09 15:43:25 +02001310 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001311 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001312 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001313 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001314 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001315 },
1316 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001317 .name = "verify_pattern",
Radha Ramachandran0e92f872009-10-27 20:14:27 +01001318 .type = FIO_OPT_STR,
Shawn Lewise28218f2008-01-16 11:01:33 +01001319 .cb = str_verify_pattern_cb,
1320 .help = "Fill pattern for IO buffers",
1321 .parent = "verify",
1322 },
1323 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001324 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001325 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001326 .off1 = td_var_offset(verify_fatal),
1327 .def = "0",
1328 .help = "Exit on a single verify failure, don't continue",
1329 .parent = "verify",
1330 },
1331 {
Jens Axboee8462bd2009-07-06 12:59:04 +02001332 .name = "verify_async",
1333 .type = FIO_OPT_INT,
1334 .off1 = td_var_offset(verify_async),
1335 .def = "0",
1336 .help = "Number of async verifier threads to use",
1337 .parent = "verify",
1338 },
1339#ifdef FIO_HAVE_CPU_AFFINITY
1340 {
1341 .name = "verify_async_cpus",
1342 .type = FIO_OPT_STR,
1343 .cb = str_verify_cpus_allowed_cb,
1344 .help = "Set CPUs allowed for async verify threads",
1345 .parent = "verify_async",
1346 },
1347#endif
1348 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001349 .name = "write_iolog",
1350 .type = FIO_OPT_STR_STORE,
1351 .off1 = td_var_offset(write_iolog_file),
1352 .help = "Store IO pattern to file",
1353 },
1354 {
1355 .name = "read_iolog",
1356 .type = FIO_OPT_STR_STORE,
1357 .off1 = td_var_offset(read_iolog_file),
1358 .help = "Playback IO pattern from file",
1359 },
1360 {
1361 .name = "exec_prerun",
1362 .type = FIO_OPT_STR_STORE,
1363 .off1 = td_var_offset(exec_prerun),
1364 .help = "Execute this file prior to running job",
1365 },
1366 {
1367 .name = "exec_postrun",
1368 .type = FIO_OPT_STR_STORE,
1369 .off1 = td_var_offset(exec_postrun),
1370 .help = "Execute this file after running job",
1371 },
1372#ifdef FIO_HAVE_IOSCHED_SWITCH
1373 {
1374 .name = "ioscheduler",
1375 .type = FIO_OPT_STR_STORE,
1376 .off1 = td_var_offset(ioscheduler),
1377 .help = "Use this IO scheduler on the backing device",
1378 },
1379#endif
1380 {
1381 .name = "zonesize",
1382 .type = FIO_OPT_STR_VAL,
1383 .off1 = td_var_offset(zone_size),
1384 .help = "Give size of an IO zone",
1385 .def = "0",
1386 },
1387 {
1388 .name = "zoneskip",
1389 .type = FIO_OPT_STR_VAL,
1390 .off1 = td_var_offset(zone_skip),
1391 .help = "Space between IO zones",
1392 .def = "0",
1393 },
1394 {
1395 .name = "lockmem",
1396 .type = FIO_OPT_STR_VAL,
1397 .cb = str_lockmem_cb,
1398 .help = "Lock down this amount of memory",
1399 .def = "0",
1400 },
1401 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001402 .name = "rwmixread",
1403 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001404 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001405 .maxval = 100,
1406 .help = "Percentage of mixed workload that is reads",
1407 .def = "50",
1408 },
1409 {
1410 .name = "rwmixwrite",
1411 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001412 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001413 .maxval = 100,
1414 .help = "Percentage of mixed workload that is writes",
1415 .def = "50",
1416 },
1417 {
Jens Axboeafdf9352007-07-31 16:14:34 +02001418 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02001419 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02001420 },
1421 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001422 .name = "nice",
1423 .type = FIO_OPT_INT,
1424 .off1 = td_var_offset(nice),
1425 .help = "Set job CPU nice value",
1426 .minval = -19,
1427 .maxval = 20,
1428 .def = "0",
1429 },
1430#ifdef FIO_HAVE_IOPRIO
1431 {
1432 .name = "prio",
1433 .type = FIO_OPT_INT,
1434 .cb = str_prio_cb,
1435 .help = "Set job IO priority value",
1436 .minval = 0,
1437 .maxval = 7,
1438 },
1439 {
1440 .name = "prioclass",
1441 .type = FIO_OPT_INT,
1442 .cb = str_prioclass_cb,
1443 .help = "Set job IO priority class",
1444 .minval = 0,
1445 .maxval = 3,
1446 },
1447#endif
1448 {
1449 .name = "thinktime",
1450 .type = FIO_OPT_INT,
1451 .off1 = td_var_offset(thinktime),
1452 .help = "Idle time between IO buffers (usec)",
1453 .def = "0",
1454 },
1455 {
1456 .name = "thinktime_spin",
1457 .type = FIO_OPT_INT,
1458 .off1 = td_var_offset(thinktime_spin),
1459 .help = "Start think time by spinning this amount (usec)",
1460 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02001461 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001462 },
1463 {
1464 .name = "thinktime_blocks",
1465 .type = FIO_OPT_INT,
1466 .off1 = td_var_offset(thinktime_blocks),
1467 .help = "IO buffer period between 'thinktime'",
1468 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02001469 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001470 },
1471 {
1472 .name = "rate",
Jens Axboee01b22b2009-06-09 15:43:25 +02001473 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001474 .off1 = td_var_offset(rate[0]),
1475 .off2 = td_var_offset(rate[1]),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001476 .help = "Set bandwidth rate",
1477 },
1478 {
1479 .name = "ratemin",
Jens Axboee01b22b2009-06-09 15:43:25 +02001480 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001481 .off1 = td_var_offset(ratemin[0]),
1482 .off2 = td_var_offset(ratemin[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001483 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001484 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01001485 },
1486 {
1487 .name = "rate_iops",
Jens Axboee01b22b2009-06-09 15:43:25 +02001488 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001489 .off1 = td_var_offset(rate_iops[0]),
1490 .off2 = td_var_offset(rate_iops[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001491 .help = "Limit IO used to this number of IO operations/sec",
1492 },
1493 {
1494 .name = "rate_iops_min",
Jens Axboee01b22b2009-06-09 15:43:25 +02001495 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001496 .off1 = td_var_offset(rate_iops_min[0]),
1497 .off2 = td_var_offset(rate_iops_min[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001498 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001499 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001500 },
1501 {
1502 .name = "ratecycle",
1503 .type = FIO_OPT_INT,
1504 .off1 = td_var_offset(ratecycle),
1505 .help = "Window average for rate limits (msec)",
1506 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02001507 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001508 },
1509 {
1510 .name = "invalidate",
1511 .type = FIO_OPT_BOOL,
1512 .off1 = td_var_offset(invalidate_cache),
1513 .help = "Invalidate buffer/page cache prior to running job",
1514 .def = "1",
1515 },
1516 {
1517 .name = "sync",
1518 .type = FIO_OPT_BOOL,
1519 .off1 = td_var_offset(sync_io),
1520 .help = "Use O_SYNC for buffered writes",
1521 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02001522 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001523 },
1524 {
1525 .name = "bwavgtime",
1526 .type = FIO_OPT_INT,
1527 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001528 .help = "Time window over which to calculate bandwidth"
1529 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001530 .def = "500",
1531 },
1532 {
1533 .name = "create_serialize",
1534 .type = FIO_OPT_BOOL,
1535 .off1 = td_var_offset(create_serialize),
1536 .help = "Serialize creating of job files",
1537 .def = "1",
1538 },
1539 {
1540 .name = "create_fsync",
1541 .type = FIO_OPT_BOOL,
1542 .off1 = td_var_offset(create_fsync),
1543 .help = "Fsync file after creation",
1544 .def = "1",
1545 },
1546 {
Jens Axboe814452b2009-03-04 12:53:13 +01001547 .name = "create_on_open",
1548 .type = FIO_OPT_BOOL,
1549 .off1 = td_var_offset(create_on_open),
1550 .help = "Create files when they are opened for IO",
1551 .def = "0",
1552 },
Jens Axboe0b9d69e2009-09-11 22:29:54 +02001553 {
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001554 .name = "pre_read",
1555 .type = FIO_OPT_BOOL,
1556 .off1 = td_var_offset(pre_read),
1557 .help = "Preread files before starting official testing",
1558 .def = "0",
1559 },
Jens Axboe814452b2009-03-04 12:53:13 +01001560 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001561 .name = "cpuload",
1562 .type = FIO_OPT_INT,
1563 .off1 = td_var_offset(cpuload),
1564 .help = "Use this percentage of CPU",
1565 },
1566 {
1567 .name = "cpuchunks",
1568 .type = FIO_OPT_INT,
1569 .off1 = td_var_offset(cpucycle),
1570 .help = "Length of the CPU burn cycles (usecs)",
1571 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02001572 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001573 },
1574#ifdef FIO_HAVE_CPU_AFFINITY
1575 {
1576 .name = "cpumask",
1577 .type = FIO_OPT_INT,
1578 .cb = str_cpumask_cb,
1579 .help = "CPU affinity mask",
1580 },
Jens Axboed2e268b2007-06-15 10:33:49 +02001581 {
1582 .name = "cpus_allowed",
1583 .type = FIO_OPT_STR,
1584 .cb = str_cpus_allowed_cb,
1585 .help = "Set CPUs allowed",
1586 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001587#endif
1588 {
1589 .name = "end_fsync",
1590 .type = FIO_OPT_BOOL,
1591 .off1 = td_var_offset(end_fsync),
1592 .help = "Include fsync at the end of job",
1593 .def = "0",
1594 },
1595 {
1596 .name = "fsync_on_close",
1597 .type = FIO_OPT_BOOL,
1598 .off1 = td_var_offset(fsync_on_close),
1599 .help = "fsync files on close",
1600 .def = "0",
1601 },
1602 {
1603 .name = "unlink",
1604 .type = FIO_OPT_BOOL,
1605 .off1 = td_var_offset(unlink),
1606 .help = "Unlink created files after job has completed",
1607 .def = "0",
1608 },
1609 {
1610 .name = "exitall",
1611 .type = FIO_OPT_STR_SET,
1612 .cb = str_exitall_cb,
1613 .help = "Terminate all jobs when one exits",
1614 },
1615 {
1616 .name = "stonewall",
1617 .type = FIO_OPT_STR_SET,
1618 .off1 = td_var_offset(stonewall),
1619 .help = "Insert a hard barrier between this job and previous",
1620 },
1621 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01001622 .name = "new_group",
1623 .type = FIO_OPT_STR_SET,
1624 .off1 = td_var_offset(new_group),
1625 .help = "Mark the start of a new group (for reporting)",
1626 },
1627 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001628 .name = "thread",
1629 .type = FIO_OPT_STR_SET,
1630 .off1 = td_var_offset(use_thread),
1631 .help = "Use threads instead of forks",
1632 },
1633 {
1634 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001635 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001636 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001637 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001638 .help = "Write log of bandwidth during run",
1639 },
1640 {
1641 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001642 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001643 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001644 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001645 .help = "Write log of latency during run",
1646 },
1647 {
1648 .name = "hugepage-size",
Jens Axboee01b22b2009-06-09 15:43:25 +02001649 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001650 .off1 = td_var_offset(hugepage_size),
1651 .help = "When using hugepages, specify size of each page",
1652 .def = __stringify(FIO_HUGE_PAGE),
1653 },
1654 {
1655 .name = "group_reporting",
1656 .type = FIO_OPT_STR_SET,
1657 .off1 = td_var_offset(group_reporting),
1658 .help = "Do reporting on a per-group basis",
1659 },
1660 {
Jens Axboee9459e52007-04-17 15:46:32 +02001661 .name = "zero_buffers",
1662 .type = FIO_OPT_STR_SET,
1663 .off1 = td_var_offset(zero_buffers),
1664 .help = "Init IO buffers to all zeroes",
1665 },
Jens Axboe5973caf2008-05-21 19:52:35 +02001666 {
1667 .name = "refill_buffers",
1668 .type = FIO_OPT_STR_SET,
1669 .off1 = td_var_offset(refill_buffers),
1670 .help = "Refill IO buffers on every IO submit",
1671 },
Jens Axboe0a839f32007-04-26 09:02:34 +02001672#ifdef FIO_HAVE_DISK_UTIL
1673 {
1674 .name = "disk_util",
1675 .type = FIO_OPT_BOOL,
1676 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001677 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02001678 .def = "1",
1679 },
1680#endif
Jens Axboee9459e52007-04-17 15:46:32 +02001681 {
Jens Axboe993bf482008-11-14 13:04:53 +01001682 .name = "gtod_reduce",
1683 .type = FIO_OPT_BOOL,
1684 .help = "Greatly reduce number of gettimeofday() calls",
1685 .cb = str_gtod_reduce_cb,
1686 .def = "0",
1687 },
1688 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02001689 .name = "disable_clat",
1690 .type = FIO_OPT_BOOL,
1691 .off1 = td_var_offset(disable_clat),
1692 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001693 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001694 .def = "0",
1695 },
1696 {
1697 .name = "disable_slat",
1698 .type = FIO_OPT_BOOL,
1699 .off1 = td_var_offset(disable_slat),
1700 .help = "Disable submissionn latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001701 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001702 .def = "0",
1703 },
1704 {
1705 .name = "disable_bw_measurement",
1706 .type = FIO_OPT_BOOL,
1707 .off1 = td_var_offset(disable_bw),
1708 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01001709 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001710 .def = "0",
1711 },
1712 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001713 .name = "gtod_cpu",
1714 .type = FIO_OPT_INT,
1715 .cb = str_gtod_cpu_cb,
1716 .help = "Setup dedicated gettimeofday() thread on this CPU",
Jens Axboe29d43ff2009-07-01 10:42:18 +02001717 .verify = gtod_cpu_verify,
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001718 },
1719 {
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001720 .name = "continue_on_error",
1721 .type = FIO_OPT_BOOL,
1722 .off1 = td_var_offset(continue_on_error),
1723 .help = "Continue on non-fatal errors during I/O",
1724 .def = "0",
1725 },
1726 {
Jens Axboe9ac8a792009-11-13 21:23:07 +01001727 .name = "profile",
1728 .type = FIO_OPT_STR,
1729 .off1 = td_var_offset(profile),
1730 .posval = {
1731 { .ival = "tiobench",
1732 .oval = PROFILE_TIOBENCH,
1733 .help = "Perform tiobench like test",
1734 },
1735 },
1736 .help = "Select a specific builtin performance test",
1737 },
1738 {
Jens Axboea696fa22009-12-04 10:05:02 +01001739 .name = "cgroup",
1740 .type = FIO_OPT_STR_STORE,
1741 .off1 = td_var_offset(cgroup),
1742 .help = "Add job to cgroup of this name",
1743 },
1744 {
1745 .name = "cgroup_weight",
1746 .type = FIO_OPT_INT,
1747 .off1 = td_var_offset(cgroup_weight),
1748 .help = "Use given weight for cgroup",
1749 .minval = 100,
1750 .maxval = 1000,
Jens Axboea696fa22009-12-04 10:05:02 +01001751 },
1752 {
Jens Axboee0b0d892009-12-08 10:10:14 +01001753 .name = "uid",
1754 .type = FIO_OPT_INT,
1755 .off1 = td_var_offset(uid),
1756 .help = "Run job with this user ID",
1757 },
1758 {
1759 .name = "gid",
1760 .type = FIO_OPT_INT,
1761 .off1 = td_var_offset(gid),
1762 .help = "Run job with this group ID",
1763 },
1764 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001765 .name = NULL,
1766 },
1767};
1768
1769void fio_options_dup_and_init(struct option *long_options)
1770{
1771 struct fio_option *o;
1772 unsigned int i;
1773
1774 options_init(options);
1775
1776 i = 0;
1777 while (long_options[i].name)
1778 i++;
1779
1780 o = &options[0];
1781 while (o->name) {
Jens Axboe5921e802008-05-30 15:02:38 +02001782 long_options[i].name = (char *) o->name;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001783 long_options[i].val = FIO_GETOPT_JOB;
1784 if (o->type == FIO_OPT_STR_SET)
1785 long_options[i].has_arg = no_argument;
1786 else
1787 long_options[i].has_arg = required_argument;
1788
1789 i++;
1790 o++;
1791 assert(i < FIO_NR_OPTIONS);
1792 }
1793}
1794
Jens Axboe74929ac2009-08-05 11:42:37 +02001795struct fio_keyword {
1796 const char *word;
1797 const char *desc;
1798 char *replace;
1799};
1800
1801static struct fio_keyword fio_keywords[] = {
1802 {
1803 .word = "$pagesize",
1804 .desc = "Page size in the system",
1805 },
1806 {
1807 .word = "$mb_memory",
1808 .desc = "Megabytes of memory online",
1809 },
1810 {
1811 .word = "$ncpus",
1812 .desc = "Number of CPUs online in the system",
1813 },
1814 {
1815 .word = NULL,
1816 },
1817};
1818
1819void fio_keywords_init(void)
1820{
Jens Axboe3b2e1462009-12-15 08:58:10 +01001821 unsigned long long mb_memory;
Jens Axboe74929ac2009-08-05 11:42:37 +02001822 char buf[128];
1823 long l;
1824
1825 sprintf(buf, "%lu", page_size);
1826 fio_keywords[0].replace = strdup(buf);
1827
Jens Axboe3b2e1462009-12-15 08:58:10 +01001828 mb_memory = os_phys_mem() / page_size;
1829 sprintf(buf, "%llu", mb_memory);
Jens Axboe74929ac2009-08-05 11:42:37 +02001830 fio_keywords[1].replace = strdup(buf);
1831
1832 l = sysconf(_SC_NPROCESSORS_ONLN);
1833 sprintf(buf, "%lu", l);
1834 fio_keywords[2].replace = strdup(buf);
1835}
1836
Jens Axboe892a6ff2009-11-13 12:19:49 +01001837#define BC_APP "bc"
1838
1839static char *bc_calc(char *str)
1840{
1841 char *buf, *tmp, opt[80];
1842 FILE *f;
1843 int ret;
1844
1845 /*
1846 * No math, just return string
1847 */
1848 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1849 !strchr(str, '/'))
1850 return str;
1851
1852 /*
1853 * Split option from value, we only need to calculate the value
1854 */
1855 tmp = strchr(str, '=');
1856 if (!tmp)
1857 return str;
1858
1859 tmp++;
Jens Axboe9ac8a792009-11-13 21:23:07 +01001860 memset(opt, 0, sizeof(opt));
Jens Axboe892a6ff2009-11-13 12:19:49 +01001861 strncpy(opt, str, tmp - str);
1862
1863 buf = malloc(128);
1864
1865 sprintf(buf, "which %s > /dev/null", BC_APP);
1866 if (system(buf)) {
1867 log_err("fio: bc is needed for performing math\n");
1868 free(buf);
1869 return NULL;
1870 }
1871
1872 sprintf(buf, "echo %s | %s", tmp, BC_APP);
1873 f = popen(buf, "r");
1874 if (!f) {
1875 free(buf);
1876 return NULL;
1877 }
1878
1879 ret = fread(buf, 1, 128, f);
1880 if (ret <= 0) {
1881 free(buf);
1882 return NULL;
1883 }
1884
1885 buf[ret - 1] = '\0';
1886 strcat(opt, buf);
1887 strcpy(buf, opt);
1888 pclose(f);
1889 free(str);
1890 return buf;
1891}
1892
Jens Axboe74929ac2009-08-05 11:42:37 +02001893/*
1894 * Look for reserved variable names and replace them with real values
1895 */
1896static char *fio_keyword_replace(char *opt)
1897{
1898 char *s;
1899 int i;
1900
1901 for (i = 0; fio_keywords[i].word != NULL; i++) {
1902 struct fio_keyword *kw = &fio_keywords[i];
1903
1904 while ((s = strstr(opt, kw->word)) != NULL) {
1905 char *new = malloc(strlen(opt) + 1);
1906 char *o_org = opt;
1907 int olen = s - opt;
1908 int len;
1909
1910 /*
1911 * Copy part of the string before the keyword and
1912 * sprintf() the replacement after it.
1913 */
1914 memcpy(new, opt, olen);
1915 len = sprintf(new + olen, "%s", kw->replace);
1916
1917 /*
1918 * If there's more in the original string, copy that
1919 * in too
1920 */
1921 opt += strlen(kw->word) + olen;
1922 if (strlen(opt))
1923 memcpy(new + olen + len, opt, opt - o_org - 1);
1924
1925 /*
1926 * replace opt and free the old opt
1927 */
1928 opt = new;
Jens Axboe9ac8a792009-11-13 21:23:07 +01001929 //free(o_org);
Jens Axboe7a958bd2009-11-13 12:33:54 +01001930
1931 /*
1932 * Check for potential math and invoke bc, if possible
1933 */
1934 opt = bc_calc(opt);
Jens Axboe74929ac2009-08-05 11:42:37 +02001935 }
1936 }
1937
Jens Axboe7a958bd2009-11-13 12:33:54 +01001938 return opt;
Jens Axboe74929ac2009-08-05 11:42:37 +02001939}
1940
Jens Axboe3b8b7132008-06-10 19:46:23 +02001941int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01001942{
Jens Axboe3b8b7132008-06-10 19:46:23 +02001943 int i, ret;
1944
1945 sort_options(opts, options, num_opts);
1946
Jens Axboe74929ac2009-08-05 11:42:37 +02001947 for (ret = 0, i = 0; i < num_opts; i++) {
1948 opts[i] = fio_keyword_replace(opts[i]);
Jens Axboe3b8b7132008-06-10 19:46:23 +02001949 ret |= parse_option(opts[i], options, td);
Jens Axboe74929ac2009-08-05 11:42:37 +02001950 }
Jens Axboe3b8b7132008-06-10 19:46:23 +02001951
1952 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01001953}
1954
1955int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
1956{
1957 return parse_cmd_option(opt, val, options, td);
1958}
1959
1960void fio_fill_default_options(struct thread_data *td)
1961{
1962 fill_default_options(td, options);
1963}
1964
1965int fio_show_option_help(const char *opt)
1966{
1967 return show_cmd_help(options, opt);
1968}
Jens Axboed23bb322007-03-23 15:57:56 +01001969
1970static void __options_mem(struct thread_data *td, int alloc)
1971{
1972 struct thread_options *o = &td->o;
1973 struct fio_option *opt;
1974 char **ptr;
1975 int i;
1976
1977 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
1978 if (opt->type != FIO_OPT_STR_STORE)
1979 continue;
1980
1981 ptr = (void *) o + opt->off1;
1982 if (*ptr) {
1983 if (alloc)
1984 *ptr = strdup(*ptr);
1985 else {
1986 free(*ptr);
1987 *ptr = NULL;
1988 }
1989 }
1990 }
1991}
1992
1993/*
1994 * dupe FIO_OPT_STR_STORE options
1995 */
1996void options_mem_dupe(struct thread_data *td)
1997{
1998 __options_mem(td, 1);
1999}
2000
Jens Axboe22d66212007-03-27 20:06:25 +02002001void options_mem_free(struct thread_data fio_unused *td)
Jens Axboed23bb322007-03-23 15:57:56 +01002002{
Jens Axboe22d66212007-03-27 20:06:25 +02002003#if 0
Jens Axboed23bb322007-03-23 15:57:56 +01002004 __options_mem(td, 0);
Jens Axboe22d66212007-03-27 20:06:25 +02002005#endif
Jens Axboed23bb322007-03-23 15:57:56 +01002006}
Jens Axboed6978a32009-07-18 21:04:09 +02002007
2008unsigned int fio_get_kb_base(void *data)
2009{
2010 struct thread_data *td = data;
2011 unsigned int kb_base = 0;
2012
2013 if (td)
2014 kb_base = td->o.kb_base;
2015 if (!kb_base)
2016 kb_base = 1024;
2017
2018 return kb_base;
2019}