blob: 10e58dbad5caad8c56be621c2df57fe5e3e4ed29 [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 Axboe5d7c5d32010-06-21 15:08:17 +020019#include "crc/crc32c.h"
20
Jens Axboe214e1ec2007-03-15 10:48:13 +010021/*
22 * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
23 */
24static char *get_opt_postfix(const char *str)
25{
26 char *p = strstr(str, ":");
27
28 if (!p)
29 return NULL;
30
31 p++;
32 strip_blank_front(&p);
33 strip_blank_end(p);
34 return strdup(p);
35}
36
Radha Ramachandran0e92f872009-10-27 20:14:27 +010037static int converthexchartoint(char a)
38{
39 int base;
40
41 switch(a) {
42 case '0'...'9':
43 base = '0';
44 break;
45 case 'A'...'F':
46 base = 'A' - 10;
47 break;
48 case 'a'...'f':
49 base = 'a' - 10;
50 break;
51 default:
52 base = 0;
53 }
54 return (a - base);
55}
56
Jens Axboe564ca972007-12-14 12:21:19 +010057static int bs_cmp(const void *p1, const void *p2)
58{
59 const struct bssplit *bsp1 = p1;
60 const struct bssplit *bsp2 = p2;
61
62 return bsp1->perc < bsp2->perc;
63}
64
Jens Axboe720e84a2009-04-21 08:29:55 +020065static int bssplit_ddir(struct thread_data *td, int ddir, char *str)
Jens Axboe564ca972007-12-14 12:21:19 +010066{
Jens Axboe720e84a2009-04-21 08:29:55 +020067 struct bssplit *bssplit;
Jens Axboe564ca972007-12-14 12:21:19 +010068 unsigned int i, perc, perc_missing;
69 unsigned int max_bs, min_bs;
70 long long val;
Jens Axboe720e84a2009-04-21 08:29:55 +020071 char *fname;
Jens Axboe564ca972007-12-14 12:21:19 +010072
Jens Axboe720e84a2009-04-21 08:29:55 +020073 td->o.bssplit_nr[ddir] = 4;
74 bssplit = malloc(4 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010075
76 i = 0;
77 max_bs = 0;
78 min_bs = -1;
79 while ((fname = strsep(&str, ":")) != NULL) {
80 char *perc_str;
81
82 if (!strlen(fname))
83 break;
84
85 /*
86 * grow struct buffer, if needed
87 */
Jens Axboe720e84a2009-04-21 08:29:55 +020088 if (i == td->o.bssplit_nr[ddir]) {
89 td->o.bssplit_nr[ddir] <<= 1;
90 bssplit = realloc(bssplit, td->o.bssplit_nr[ddir]
Jens Axboe5ec10ea2008-03-06 15:42:00 +010091 * sizeof(struct bssplit));
Jens Axboe564ca972007-12-14 12:21:19 +010092 }
93
94 perc_str = strstr(fname, "/");
95 if (perc_str) {
96 *perc_str = '\0';
97 perc_str++;
98 perc = atoi(perc_str);
99 if (perc > 100)
100 perc = 100;
101 else if (!perc)
102 perc = -1;
103 } else
104 perc = -1;
105
Kenneth Watersdf9cf922009-10-15 07:08:48 +0200106 if (str_to_decimal(fname, &val, 1, td)) {
Jens Axboe564ca972007-12-14 12:21:19 +0100107 log_err("fio: bssplit conversion failed\n");
108 free(td->o.bssplit);
109 return 1;
110 }
111
112 if (val > max_bs)
113 max_bs = val;
114 if (val < min_bs)
115 min_bs = val;
116
Jens Axboe720e84a2009-04-21 08:29:55 +0200117 bssplit[i].bs = val;
118 bssplit[i].perc = perc;
Jens Axboe564ca972007-12-14 12:21:19 +0100119 i++;
120 }
121
Jens Axboe720e84a2009-04-21 08:29:55 +0200122 td->o.bssplit_nr[ddir] = i;
Jens Axboe564ca972007-12-14 12:21:19 +0100123
124 /*
125 * Now check if the percentages add up, and how much is missing
126 */
127 perc = perc_missing = 0;
Jens Axboe720e84a2009-04-21 08:29:55 +0200128 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
129 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100130
131 if (bsp->perc == (unsigned char) -1)
132 perc_missing++;
133 else
134 perc += bsp->perc;
135 }
136
137 if (perc > 100) {
138 log_err("fio: bssplit percentages add to more than 100%%\n");
Jens Axboe720e84a2009-04-21 08:29:55 +0200139 free(bssplit);
Jens Axboe564ca972007-12-14 12:21:19 +0100140 return 1;
141 }
142 /*
143 * If values didn't have a percentage set, divide the remains between
144 * them.
145 */
146 if (perc_missing) {
Jens Axboe720e84a2009-04-21 08:29:55 +0200147 for (i = 0; i < td->o.bssplit_nr[ddir]; i++) {
148 struct bssplit *bsp = &bssplit[i];
Jens Axboe564ca972007-12-14 12:21:19 +0100149
150 if (bsp->perc == (unsigned char) -1)
151 bsp->perc = (100 - perc) / perc_missing;
152 }
153 }
154
Jens Axboe720e84a2009-04-21 08:29:55 +0200155 td->o.min_bs[ddir] = min_bs;
156 td->o.max_bs[ddir] = max_bs;
Jens Axboe564ca972007-12-14 12:21:19 +0100157
158 /*
159 * now sort based on percentages, for ease of lookup
160 */
Jens Axboe720e84a2009-04-21 08:29:55 +0200161 qsort(bssplit, td->o.bssplit_nr[ddir], sizeof(struct bssplit), bs_cmp);
162 td->o.bssplit[ddir] = bssplit;
163 return 0;
164
165}
166
167static int str_bssplit_cb(void *data, const char *input)
168{
169 struct thread_data *td = data;
170 char *str, *p, *odir;
171 int ret = 0;
172
173 p = str = strdup(input);
174
175 strip_blank_front(&str);
176 strip_blank_end(str);
177
178 odir = strchr(str, ',');
179 if (odir) {
180 ret = bssplit_ddir(td, DDIR_WRITE, odir + 1);
181 if (!ret) {
182 *odir = '\0';
183 ret = bssplit_ddir(td, DDIR_READ, str);
184 }
185 } else {
186 char *op;
187
188 op = strdup(str);
189
190 ret = bssplit_ddir(td, DDIR_READ, str);
191 if (!ret)
192 ret = bssplit_ddir(td, DDIR_WRITE, op);
193
194 free(op);
195 }
Jens Axboe564ca972007-12-14 12:21:19 +0100196
197 free(p);
Jens Axboe720e84a2009-04-21 08:29:55 +0200198 return ret;
Jens Axboe564ca972007-12-14 12:21:19 +0100199}
200
Jens Axboe211097b2007-03-22 18:56:45 +0100201static int str_rw_cb(void *data, const char *str)
202{
203 struct thread_data *td = data;
204 char *nr = get_opt_postfix(str);
205
Jens Axboe5736c102010-07-20 12:03:25 -0600206 td->o.ddir_seq_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100207 if (nr) {
Jens Axboe5736c102010-07-20 12:03:25 -0600208 td->o.ddir_seq_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100209 free(nr);
210 }
Jens Axboe211097b2007-03-22 18:56:45 +0100211
Jens Axboe211097b2007-03-22 18:56:45 +0100212 return 0;
213}
214
Jens Axboe214e1ec2007-03-15 10:48:13 +0100215static int str_mem_cb(void *data, const char *mem)
216{
217 struct thread_data *td = data;
218
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100219 if (td->o.mem_type == MEM_MMAPHUGE || td->o.mem_type == MEM_MMAP) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100220 td->mmapfile = get_opt_postfix(mem);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100221 if (td->o.mem_type == MEM_MMAPHUGE && !td->mmapfile) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100222 log_err("fio: mmaphuge:/path/to/file\n");
223 return 1;
224 }
225 }
226
227 return 0;
228}
229
Jens Axboe5d7c5d32010-06-21 15:08:17 +0200230static int str_verify_cb(void *data, const char *mem)
231{
232 struct thread_data *td = data;
233
234 if (td->o.verify != VERIFY_CRC32C_INTEL)
235 return 0;
236
237 if (!crc32c_intel_works()) {
238 log_info("fio: System does not support hw accelerated crc32c. Falling back to sw crc32c.\n");
239 td->o.verify = VERIFY_CRC32C;
240 }
241
242 return 0;
243}
244
Jens Axboec223da82010-03-24 13:23:53 +0100245static int fio_clock_source_cb(void *data, const char *str)
246{
247 struct thread_data *td = data;
248
249 fio_clock_source = td->o.clocksource;
250 fio_time_init();
251 return 0;
252}
253
Jens Axboe214e1ec2007-03-15 10:48:13 +0100254static int str_lockmem_cb(void fio_unused *data, unsigned long *val)
255{
256 mlock_size = *val;
257 return 0;
258}
259
Jens Axboecb499fc2008-05-28 10:33:32 +0200260static int str_rwmix_read_cb(void *data, unsigned int *val)
261{
262 struct thread_data *td = data;
263
264 td->o.rwmix[DDIR_READ] = *val;
265 td->o.rwmix[DDIR_WRITE] = 100 - *val;
266 return 0;
267}
268
269static int str_rwmix_write_cb(void *data, unsigned int *val)
270{
271 struct thread_data *td = data;
272
273 td->o.rwmix[DDIR_WRITE] = *val;
274 td->o.rwmix[DDIR_READ] = 100 - *val;
275 return 0;
276}
277
Jens Axboe214e1ec2007-03-15 10:48:13 +0100278#ifdef FIO_HAVE_IOPRIO
279static int str_prioclass_cb(void *data, unsigned int *val)
280{
281 struct thread_data *td = data;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200282 unsigned short mask;
283
284 /*
285 * mask off old class bits, str_prio_cb() may have set a default class
286 */
287 mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
288 td->ioprio &= mask;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100289
290 td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
Jens Axboeac684782007-11-08 08:29:07 +0100291 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100292 return 0;
293}
294
295static int str_prio_cb(void *data, unsigned int *val)
296{
297 struct thread_data *td = data;
298
299 td->ioprio |= *val;
Jens Axboe6cefbe32007-04-18 12:46:56 +0200300
301 /*
302 * If no class is set, assume BE
303 */
304 if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
305 td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
306
Jens Axboeac684782007-11-08 08:29:07 +0100307 td->ioprio_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100308 return 0;
309}
310#endif
311
312static int str_exitall_cb(void)
313{
314 exitall_on_terminate = 1;
315 return 0;
316}
317
Jens Axboe214e1ec2007-03-15 10:48:13 +0100318#ifdef FIO_HAVE_CPU_AFFINITY
Jens Axboe214e1ec2007-03-15 10:48:13 +0100319static int str_cpumask_cb(void *data, unsigned int *val)
320{
321 struct thread_data *td = data;
Jens Axboed2e268b2007-06-15 10:33:49 +0200322 unsigned int i;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100323 long max_cpu;
Jens Axboed2ce18b2008-12-12 20:51:40 +0100324 int ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100325
Jens Axboed2ce18b2008-12-12 20:51:40 +0100326 ret = fio_cpuset_init(&td->o.cpumask);
327 if (ret < 0) {
328 log_err("fio: cpuset_init failed\n");
329 td_verror(td, ret, "fio_cpuset_init");
330 return 1;
331 }
332
Jens Axboeb03daaf2008-12-08 20:31:43 +0100333 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
Jens Axboed2e268b2007-06-15 10:33:49 +0200334
Jens Axboe62a72732008-12-08 11:37:01 +0100335 for (i = 0; i < sizeof(int) * 8; i++) {
336 if ((1 << i) & *val) {
Jens Axboeb03daaf2008-12-08 20:31:43 +0100337 if (i > max_cpu) {
338 log_err("fio: CPU %d too large (max=%ld)\n", i,
339 max_cpu);
340 return 1;
341 }
Jens Axboe62a72732008-12-08 11:37:01 +0100342 dprint(FD_PARSE, "set cpu allowed %d\n", i);
Jens Axboe6d459ee2008-12-12 20:02:58 +0100343 fio_cpu_set(&td->o.cpumask, i);
Jens Axboe62a72732008-12-08 11:37:01 +0100344 }
345 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200346
Jens Axboe375b2692007-05-22 09:13:02 +0200347 td->o.cpumask_set = 1;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100348 return 0;
349}
350
Jens Axboee8462bd2009-07-06 12:59:04 +0200351static int set_cpus_allowed(struct thread_data *td, os_cpu_mask_t *mask,
352 const char *input)
Jens Axboed2e268b2007-06-15 10:33:49 +0200353{
Jens Axboed2e268b2007-06-15 10:33:49 +0200354 char *cpu, *str, *p;
Jens Axboeb03daaf2008-12-08 20:31:43 +0100355 long max_cpu;
Jens Axboe19608d62008-12-08 15:03:12 +0100356 int ret = 0;
Jens Axboed2e268b2007-06-15 10:33:49 +0200357
Jens Axboee8462bd2009-07-06 12:59:04 +0200358 ret = fio_cpuset_init(mask);
Jens Axboed2ce18b2008-12-12 20:51:40 +0100359 if (ret < 0) {
360 log_err("fio: cpuset_init failed\n");
361 td_verror(td, ret, "fio_cpuset_init");
362 return 1;
363 }
Jens Axboed2e268b2007-06-15 10:33:49 +0200364
365 p = str = strdup(input);
366
367 strip_blank_front(&str);
368 strip_blank_end(str);
369
Jens Axboeb03daaf2008-12-08 20:31:43 +0100370 max_cpu = sysconf(_SC_NPROCESSORS_ONLN);
371
Jens Axboed2e268b2007-06-15 10:33:49 +0200372 while ((cpu = strsep(&str, ",")) != NULL) {
Jens Axboe62a72732008-12-08 11:37:01 +0100373 char *str2, *cpu2;
374 int icpu, icpu2;
375
Jens Axboed2e268b2007-06-15 10:33:49 +0200376 if (!strlen(cpu))
377 break;
Jens Axboe62a72732008-12-08 11:37:01 +0100378
379 str2 = cpu;
380 icpu2 = -1;
381 while ((cpu2 = strsep(&str2, "-")) != NULL) {
382 if (!strlen(cpu2))
383 break;
384
385 icpu2 = atoi(cpu2);
386 }
387
388 icpu = atoi(cpu);
389 if (icpu2 == -1)
390 icpu2 = icpu;
391 while (icpu <= icpu2) {
Jens Axboe6d459ee2008-12-12 20:02:58 +0100392 if (icpu >= FIO_MAX_CPUS) {
Jens Axboe19608d62008-12-08 15:03:12 +0100393 log_err("fio: your OS only supports up to"
Jens Axboe6d459ee2008-12-12 20:02:58 +0100394 " %d CPUs\n", (int) FIO_MAX_CPUS);
Jens Axboe19608d62008-12-08 15:03:12 +0100395 ret = 1;
396 break;
397 }
Jens Axboeb03daaf2008-12-08 20:31:43 +0100398 if (icpu > max_cpu) {
399 log_err("fio: CPU %d too large (max=%ld)\n",
400 icpu, max_cpu);
401 ret = 1;
402 break;
403 }
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200404
Jens Axboe62a72732008-12-08 11:37:01 +0100405 dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
Jens Axboee8462bd2009-07-06 12:59:04 +0200406 fio_cpu_set(mask, icpu);
Jens Axboe62a72732008-12-08 11:37:01 +0100407 icpu++;
408 }
Jens Axboe19608d62008-12-08 15:03:12 +0100409 if (ret)
410 break;
Jens Axboed2e268b2007-06-15 10:33:49 +0200411 }
412
413 free(p);
Jens Axboe19608d62008-12-08 15:03:12 +0100414 if (!ret)
415 td->o.cpumask_set = 1;
416 return ret;
Jens Axboed2e268b2007-06-15 10:33:49 +0200417}
Jens Axboee8462bd2009-07-06 12:59:04 +0200418
419static int str_cpus_allowed_cb(void *data, const char *input)
420{
421 struct thread_data *td = data;
422 int ret;
423
424 ret = set_cpus_allowed(td, &td->o.cpumask, input);
425 if (!ret)
426 td->o.cpumask_set = 1;
427
428 return ret;
429}
430
431static int str_verify_cpus_allowed_cb(void *data, const char *input)
432{
433 struct thread_data *td = data;
434 int ret;
435
436 ret = set_cpus_allowed(td, &td->o.verify_cpumask, input);
437 if (!ret)
438 td->o.verify_cpumask_set = 1;
439
440 return ret;
441}
Jens Axboed2e268b2007-06-15 10:33:49 +0200442#endif
443
Jens Axboe214e1ec2007-03-15 10:48:13 +0100444static int str_fst_cb(void *data, const char *str)
445{
446 struct thread_data *td = data;
447 char *nr = get_opt_postfix(str);
448
449 td->file_service_nr = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100450 if (nr) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100451 td->file_service_nr = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100452 free(nr);
453 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100454
455 return 0;
456}
457
Jens Axboe3ae06372010-03-19 19:17:15 +0100458#ifdef FIO_HAVE_SYNC_FILE_RANGE
Jens Axboe44f29692010-03-09 20:09:44 +0100459static int str_sfr_cb(void *data, const char *str)
460{
461 struct thread_data *td = data;
462 char *nr = get_opt_postfix(str);
463
464 td->sync_file_range_nr = 1;
465 if (nr) {
466 td->sync_file_range_nr = atoi(nr);
467 free(nr);
468 }
469
470 return 0;
471}
Jens Axboe3ae06372010-03-19 19:17:15 +0100472#endif
Jens Axboe44f29692010-03-09 20:09:44 +0100473
Jens Axboe921c7662008-03-26 09:17:55 +0100474static int check_dir(struct thread_data *td, char *fname)
475{
476 char file[PATH_MAX], *dir;
Jens Axboebc838912008-04-07 09:00:54 +0200477 int elen = 0;
Jens Axboe921c7662008-03-26 09:17:55 +0100478
Jens Axboebc838912008-04-07 09:00:54 +0200479 if (td->o.directory) {
480 strcpy(file, td->o.directory);
Jens Axboefcef0b32008-05-26 14:53:24 +0200481 strcat(file, "/");
Jens Axboebc838912008-04-07 09:00:54 +0200482 elen = strlen(file);
483 }
484
Jens Axboefcef0b32008-05-26 14:53:24 +0200485 sprintf(file + elen, "%s", fname);
Jens Axboe921c7662008-03-26 09:17:55 +0100486 dir = dirname(file);
487
Jens Axboefcef0b32008-05-26 14:53:24 +0200488#if 0
489 {
490 struct stat sb;
491 /*
492 * We can't do this on FIO_DISKLESSIO engines. The engine isn't loaded
493 * yet, so we can't do this check right here...
494 */
Jens Axboe921c7662008-03-26 09:17:55 +0100495 if (lstat(dir, &sb) < 0) {
496 int ret = errno;
497
498 log_err("fio: %s is not a directory\n", dir);
499 td_verror(td, ret, "lstat");
500 return 1;
501 }
502
503 if (!S_ISDIR(sb.st_mode)) {
504 log_err("fio: %s is not a directory\n", dir);
505 return 1;
506 }
Jens Axboefcef0b32008-05-26 14:53:24 +0200507 }
508#endif
Jens Axboe921c7662008-03-26 09:17:55 +0100509
510 return 0;
511}
512
Jens Axboe8e827d32009-08-04 09:51:48 +0200513/*
514 * Return next file in the string. Files are separated with ':'. If the ':'
515 * is escaped with a '\', then that ':' is part of the filename and does not
516 * indicate a new file.
517 */
518static char *get_next_file_name(char **ptr)
519{
520 char *str = *ptr;
521 char *p, *start;
522
523 if (!str || !strlen(str))
524 return NULL;
525
526 start = str;
527 do {
528 /*
529 * No colon, we are done
530 */
531 p = strchr(str, ':');
532 if (!p) {
533 *ptr = NULL;
534 break;
535 }
536
537 /*
538 * We got a colon, but it's the first character. Skip and
539 * continue
540 */
541 if (p == start) {
542 str = ++start;
543 continue;
544 }
545
546 if (*(p - 1) != '\\') {
547 *p = '\0';
548 *ptr = p + 1;
549 break;
550 }
551
552 memmove(p - 1, p, strlen(p) + 1);
553 str = p;
554 } while (1);
555
556 return start;
557}
558
Jens Axboe214e1ec2007-03-15 10:48:13 +0100559static int str_filename_cb(void *data, const char *input)
560{
561 struct thread_data *td = data;
562 char *fname, *str, *p;
563
564 p = str = strdup(input);
565
566 strip_blank_front(&str);
567 strip_blank_end(str);
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 Axboe8e827d32009-08-04 09:51:48 +0200572 while ((fname = get_next_file_name(&str)) != NULL) {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100573 if (!strlen(fname))
574 break;
Jens Axboe921c7662008-03-26 09:17:55 +0100575 if (check_dir(td, fname)) {
576 free(p);
577 return 1;
578 }
Jens Axboe214e1ec2007-03-15 10:48:13 +0100579 add_file(td, fname);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100580 td->o.nr_files++;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100581 }
582
583 free(p);
584 return 0;
585}
586
587static int str_directory_cb(void *data, const char fio_unused *str)
588{
589 struct thread_data *td = data;
590 struct stat sb;
591
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100592 if (lstat(td->o.directory, &sb) < 0) {
Jens Axboe921c7662008-03-26 09:17:55 +0100593 int ret = errno;
594
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100595 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe921c7662008-03-26 09:17:55 +0100596 td_verror(td, ret, "lstat");
Jens Axboe214e1ec2007-03-15 10:48:13 +0100597 return 1;
598 }
599 if (!S_ISDIR(sb.st_mode)) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100600 log_err("fio: %s is not a directory\n", td->o.directory);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100601 return 1;
602 }
603
604 return 0;
605}
606
607static int str_opendir_cb(void *data, const char fio_unused *str)
608{
609 struct thread_data *td = data;
610
611 if (!td->files_index)
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100612 td->o.nr_files = 0;
Jens Axboe214e1ec2007-03-15 10:48:13 +0100613
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100614 return add_dir_files(td, td->o.opendir);
Jens Axboe214e1ec2007-03-15 10:48:13 +0100615}
616
Jens Axboea59e1702007-07-30 08:53:27 +0200617static int str_verify_offset_cb(void *data, unsigned int *off)
Shawn Lewis546a9142007-07-28 21:11:37 +0200618{
619 struct thread_data *td = data;
Jens Axboea59e1702007-07-30 08:53:27 +0200620
Shawn Lewis546a9142007-07-28 21:11:37 +0200621 if (*off && *off < sizeof(struct verify_header)) {
Jens Axboea59e1702007-07-30 08:53:27 +0200622 log_err("fio: verify_offset too small\n");
Shawn Lewis546a9142007-07-28 21:11:37 +0200623 return 1;
624 }
Jens Axboea59e1702007-07-30 08:53:27 +0200625
626 td->o.verify_offset = *off;
Shawn Lewis546a9142007-07-28 21:11:37 +0200627 return 0;
628}
629
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100630static int str_verify_pattern_cb(void *data, const char *input)
Jens Axboe90059d62007-07-30 09:33:12 +0200631{
632 struct thread_data *td = data;
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100633 long off;
634 int i = 0, j = 0, len, k, base = 10;
635 char* loc1, * loc2;
Jens Axboe90059d62007-07-30 09:33:12 +0200636
Radha Ramachandran0e92f872009-10-27 20:14:27 +0100637 loc1 = strstr(input, "0x");
638 loc2 = strstr(input, "0X");
639 if (loc1 || loc2)
640 base = 16;
641 off = strtol(input, NULL, base);
642 if (off != LONG_MAX || errno != ERANGE) {
643 while (off) {
644 td->o.verify_pattern[i] = off & 0xff;
645 off >>= 8;
646 i++;
647 }
648 } else {
649 len = strlen(input);
650 k = len - 1;
651 if (base == 16) {
652 if (loc1)
653 j = loc1 - input + 2;
654 else
655 j = loc2 - input + 2;
656 } else
657 return 1;
658 if (len - j < MAX_PATTERN_SIZE * 2) {
659 while (k >= j) {
660 off = converthexchartoint(input[k--]);
661 if (k >= j)
662 off += (converthexchartoint(input[k--])
663 * 16);
664 td->o.verify_pattern[i++] = (char) off;
665 }
666 }
667 }
668 td->o.verify_pattern_bytes = i;
Jens Axboe90059d62007-07-30 09:33:12 +0200669 return 0;
670}
Jens Axboe214e1ec2007-03-15 10:48:13 +0100671
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100672static int str_lockfile_cb(void *data, const char *str)
673{
674 struct thread_data *td = data;
675 char *nr = get_opt_postfix(str);
676
677 td->o.lockfile_batch = 1;
Jens Axboe182ec6e2008-11-14 13:06:06 +0100678 if (nr) {
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100679 td->o.lockfile_batch = atoi(nr);
Jens Axboe182ec6e2008-11-14 13:06:06 +0100680 free(nr);
681 }
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100682
683 return 0;
684}
685
Jens Axboee3cedca2008-11-19 19:57:52 +0100686static int str_write_bw_log_cb(void *data, const char *str)
687{
688 struct thread_data *td = data;
689
690 if (str)
691 td->o.bw_log_file = strdup(str);
692
693 td->o.write_bw_log = 1;
694 return 0;
695}
696
697static int str_write_lat_log_cb(void *data, const char *str)
698{
699 struct thread_data *td = data;
700
701 if (str)
702 td->o.lat_log_file = strdup(str);
703
704 td->o.write_lat_log = 1;
705 return 0;
706}
707
Jens Axboe993bf482008-11-14 13:04:53 +0100708static int str_gtod_reduce_cb(void *data, int *il)
709{
710 struct thread_data *td = data;
711 int val = *il;
712
Jens Axboe02af0982010-06-24 09:59:34 +0200713 td->o.disable_lat = !!val;
Jens Axboe993bf482008-11-14 13:04:53 +0100714 td->o.disable_clat = !!val;
715 td->o.disable_slat = !!val;
716 td->o.disable_bw = !!val;
717 if (val)
718 td->tv_cache_mask = 63;
719
720 return 0;
721}
722
Jens Axboebe4ecfd2008-12-08 14:10:52 +0100723static int str_gtod_cpu_cb(void *data, int *il)
724{
725 struct thread_data *td = data;
726 int val = *il;
727
728 td->o.gtod_cpu = val;
729 td->o.gtod_offload = 1;
730 return 0;
731}
732
Jens Axboe896cac22009-07-01 10:38:35 +0200733static int rw_verify(struct fio_option *o, void *data)
734{
735 struct thread_data *td = data;
736
737 if (read_only && td_write(td)) {
738 log_err("fio: job <%s> has write bit set, but fio is in"
739 " read-only mode\n", td->o.name);
740 return 1;
741 }
742
743 return 0;
744}
745
Jens Axboe276ca4f2009-07-01 10:43:05 +0200746static int gtod_cpu_verify(struct fio_option *o, void *data)
Jens Axboe29d43ff2009-07-01 10:42:18 +0200747{
Jens Axboe276ca4f2009-07-01 10:43:05 +0200748#ifndef FIO_HAVE_CPU_AFFINITY
Jens Axboe29d43ff2009-07-01 10:42:18 +0200749 struct thread_data *td = data;
750
Jens Axboe29d43ff2009-07-01 10:42:18 +0200751 if (td->o.gtod_cpu) {
752 log_err("fio: platform must support CPU affinity for"
753 "gettimeofday() offloading\n");
754 return 1;
755 }
756#endif
757
758 return 0;
759}
760
Jens Axboe90fef2d2009-07-17 22:33:32 +0200761static int kb_base_verify(struct fio_option *o, void *data)
762{
763 struct thread_data *td = data;
764
765 if (td->o.kb_base != 1024 && td->o.kb_base != 1000) {
766 log_err("fio: kb_base set to nonsensical value: %u\n",
767 td->o.kb_base);
768 return 1;
769 }
770
771 return 0;
772}
773
Jens Axboe214e1ec2007-03-15 10:48:13 +0100774#define __stringify_1(x) #x
775#define __stringify(x) __stringify_1(x)
776
777/*
778 * Map of job/command line options
779 */
Jens Axboe07b32322010-03-05 09:48:44 +0100780static struct fio_option options[FIO_MAX_OPTS] = {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100781 {
782 .name = "description",
783 .type = FIO_OPT_STR_STORE,
784 .off1 = td_var_offset(description),
785 .help = "Text job description",
786 },
787 {
788 .name = "name",
789 .type = FIO_OPT_STR_STORE,
790 .off1 = td_var_offset(name),
791 .help = "Name of this job",
792 },
793 {
794 .name = "directory",
795 .type = FIO_OPT_STR_STORE,
796 .off1 = td_var_offset(directory),
797 .cb = str_directory_cb,
798 .help = "Directory to store files in",
799 },
800 {
801 .name = "filename",
802 .type = FIO_OPT_STR_STORE,
803 .off1 = td_var_offset(filename),
804 .cb = str_filename_cb,
Jens Axboef0d524b2009-04-27 08:00:48 +0200805 .prio = -1, /* must come after "directory" */
Jens Axboe214e1ec2007-03-15 10:48:13 +0100806 .help = "File(s) to use for the workload",
807 },
808 {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200809 .name = "kb_base",
810 .type = FIO_OPT_INT,
811 .off1 = td_var_offset(kb_base),
Jens Axboe90fef2d2009-07-17 22:33:32 +0200812 .verify = kb_base_verify,
Jens Axboea639f0b2009-07-18 08:25:35 +0200813 .prio = 1,
Jens Axboe90fef2d2009-07-17 22:33:32 +0200814 .def = "1024",
Jens Axboea639f0b2009-07-18 08:25:35 +0200815 .help = "How many bytes per KB for reporting (1000 or 1024)",
Jens Axboe90fef2d2009-07-17 22:33:32 +0200816 },
817 {
Jens Axboe29c13492008-03-01 19:25:20 +0100818 .name = "lockfile",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100819 .type = FIO_OPT_STR,
820 .cb = str_lockfile_cb,
821 .off1 = td_var_offset(file_lock_mode),
Jens Axboe29c13492008-03-01 19:25:20 +0100822 .help = "Lock file when doing IO to it",
823 .parent = "filename",
Jens Axboe4d4e80f2008-03-04 10:18:56 +0100824 .def = "none",
825 .posval = {
826 { .ival = "none",
827 .oval = FILE_LOCK_NONE,
828 .help = "No file locking",
829 },
830 { .ival = "exclusive",
831 .oval = FILE_LOCK_EXCLUSIVE,
832 .help = "Exclusive file lock",
833 },
834 {
835 .ival = "readwrite",
836 .oval = FILE_LOCK_READWRITE,
837 .help = "Read vs write lock",
838 },
839 },
Jens Axboe29c13492008-03-01 19:25:20 +0100840 },
841 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100842 .name = "opendir",
843 .type = FIO_OPT_STR_STORE,
844 .off1 = td_var_offset(opendir),
845 .cb = str_opendir_cb,
846 .help = "Recursively add files from this directory and down",
847 },
848 {
849 .name = "rw",
Jens Axboed3aad8f2007-03-15 14:12:05 +0100850 .alias = "readwrite",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100851 .type = FIO_OPT_STR,
Jens Axboe211097b2007-03-22 18:56:45 +0100852 .cb = str_rw_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100853 .off1 = td_var_offset(td_ddir),
854 .help = "IO direction",
855 .def = "read",
Jens Axboe896cac22009-07-01 10:38:35 +0200856 .verify = rw_verify,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100857 .posval = {
858 { .ival = "read",
859 .oval = TD_DDIR_READ,
860 .help = "Sequential read",
861 },
862 { .ival = "write",
863 .oval = TD_DDIR_WRITE,
864 .help = "Sequential write",
865 },
866 { .ival = "randread",
867 .oval = TD_DDIR_RANDREAD,
868 .help = "Random read",
869 },
870 { .ival = "randwrite",
871 .oval = TD_DDIR_RANDWRITE,
872 .help = "Random write",
873 },
874 { .ival = "rw",
875 .oval = TD_DDIR_RW,
876 .help = "Sequential read and write mix",
877 },
878 { .ival = "randrw",
879 .oval = TD_DDIR_RANDRW,
880 .help = "Random read and write mix"
881 },
882 },
883 },
884 {
Jens Axboe38dad622010-07-20 14:46:00 -0600885 .name = "rw_sequencer",
886 .type = FIO_OPT_STR,
887 .off1 = td_var_offset(rw_seq),
888 .help = "IO offset generator modifier",
889 .def = "sequential",
890 .posval = {
891 { .ival = "sequential",
892 .oval = RW_SEQ_SEQ,
893 .help = "Generate sequential offsets",
894 },
895 { .ival = "identical",
896 .oval = RW_SEQ_IDENT,
897 .help = "Generate identical offsets",
898 },
899 },
900 },
901
902 {
Jens Axboe214e1ec2007-03-15 10:48:13 +0100903 .name = "ioengine",
904 .type = FIO_OPT_STR_STORE,
905 .off1 = td_var_offset(ioengine),
906 .help = "IO engine to use",
907 .def = "sync",
908 .posval = {
909 { .ival = "sync",
910 .help = "Use read/write",
911 },
gurudas paia31041e2007-10-23 15:12:30 +0200912 { .ival = "psync",
913 .help = "Use pread/pwrite",
914 },
Jens Axboe1d2af022008-02-04 10:59:07 +0100915 { .ival = "vsync",
916 .help = "Use readv/writev",
917 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100918#ifdef FIO_HAVE_LIBAIO
919 { .ival = "libaio",
920 .help = "Linux native asynchronous IO",
921 },
922#endif
923#ifdef FIO_HAVE_POSIXAIO
924 { .ival = "posixaio",
925 .help = "POSIX asynchronous IO",
926 },
927#endif
Jens Axboe417f0062008-06-02 11:59:30 +0200928#ifdef FIO_HAVE_SOLARISAIO
929 { .ival = "solarisaio",
930 .help = "Solaris native asynchronous IO",
931 },
932#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100933 { .ival = "mmap",
934 .help = "Memory mapped IO",
935 },
936#ifdef FIO_HAVE_SPLICE
937 { .ival = "splice",
938 .help = "splice/vmsplice based IO",
939 },
Jens Axboe9cce02e2007-06-22 15:42:21 +0200940 { .ival = "netsplice",
941 .help = "splice/vmsplice to/from the network",
942 },
Jens Axboe214e1ec2007-03-15 10:48:13 +0100943#endif
944#ifdef FIO_HAVE_SGIO
945 { .ival = "sg",
946 .help = "SCSI generic v3 IO",
947 },
948#endif
949 { .ival = "null",
950 .help = "Testing engine (no data transfer)",
951 },
952 { .ival = "net",
953 .help = "Network IO",
954 },
955#ifdef FIO_HAVE_SYSLET
956 { .ival = "syslet-rw",
957 .help = "syslet enabled async pread/pwrite IO",
958 },
959#endif
960 { .ival = "cpuio",
961 .help = "CPU cycler burner engine",
962 },
Jens Axboeb8c82a42007-03-21 08:48:26 +0100963#ifdef FIO_HAVE_GUASI
964 { .ival = "guasi",
965 .help = "GUASI IO engine",
966 },
967#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +0100968 { .ival = "external",
969 .help = "Load external engine (append name)",
970 },
971 },
972 },
973 {
974 .name = "iodepth",
975 .type = FIO_OPT_INT,
976 .off1 = td_var_offset(iodepth),
977 .help = "Amount of IO buffers to keep in flight",
Jens Axboe757aff42007-12-12 19:42:13 +0100978 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +0100979 .def = "1",
980 },
981 {
982 .name = "iodepth_batch",
Jens Axboe49504212008-06-05 09:03:30 +0200983 .alias = "iodepth_batch_submit",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100984 .type = FIO_OPT_INT,
985 .off1 = td_var_offset(iodepth_batch),
Jens Axboed65db442009-01-16 19:15:33 +0100986 .help = "Number of IO buffers to submit in one go",
Jens Axboeafdf9352007-07-31 16:14:34 +0200987 .parent = "iodepth",
Jens Axboea2e6f8a2008-01-18 10:28:11 +0100988 .minval = 1,
989 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +0100990 },
991 {
Jens Axboe49504212008-06-05 09:03:30 +0200992 .name = "iodepth_batch_complete",
993 .type = FIO_OPT_INT,
994 .off1 = td_var_offset(iodepth_batch_complete),
Jens Axboed65db442009-01-16 19:15:33 +0100995 .help = "Number of IO buffers to retrieve in one go",
Jens Axboe49504212008-06-05 09:03:30 +0200996 .parent = "iodepth",
997 .minval = 0,
998 .def = "1",
999 },
1000 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001001 .name = "iodepth_low",
1002 .type = FIO_OPT_INT,
1003 .off1 = td_var_offset(iodepth_low),
1004 .help = "Low water mark for queuing depth",
Jens Axboeafdf9352007-07-31 16:14:34 +02001005 .parent = "iodepth",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001006 },
1007 {
1008 .name = "size",
1009 .type = FIO_OPT_STR_VAL,
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001010 .off1 = td_var_offset(size),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001011 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001012 .help = "Total size of device or files",
1013 },
1014 {
Shawn Lewisaa31f1f2008-01-11 09:45:11 +01001015 .name = "fill_device",
1016 .type = FIO_OPT_BOOL,
1017 .off1 = td_var_offset(fill_device),
1018 .help = "Write until an ENOSPC error occurs",
1019 .def = "0",
1020 },
1021 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001022 .name = "filesize",
1023 .type = FIO_OPT_STR_VAL,
1024 .off1 = td_var_offset(file_size_low),
1025 .off2 = td_var_offset(file_size_high),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001026 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001027 .help = "Size of individual files",
1028 },
1029 {
Jens Axboe67a10002007-07-31 23:12:16 +02001030 .name = "offset",
1031 .alias = "fileoffset",
1032 .type = FIO_OPT_STR_VAL,
1033 .off1 = td_var_offset(start_offset),
1034 .help = "Start IO from this offset",
1035 .def = "0",
1036 },
1037 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001038 .name = "bs",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001039 .alias = "blocksize",
Jens Axboee01b22b2009-06-09 15:43:25 +02001040 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001041 .off1 = td_var_offset(bs[DDIR_READ]),
1042 .off2 = td_var_offset(bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001043 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001044 .help = "Block size unit",
1045 .def = "4k",
Jens Axboe67a10002007-07-31 23:12:16 +02001046 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001047 },
1048 {
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001049 .name = "ba",
1050 .alias = "blockalign",
Jens Axboee01b22b2009-06-09 15:43:25 +02001051 .type = FIO_OPT_INT,
Jens Axboe2b7a01d2009-03-11 11:00:13 +01001052 .off1 = td_var_offset(ba[DDIR_READ]),
1053 .off2 = td_var_offset(ba[DDIR_WRITE]),
1054 .minval = 1,
1055 .help = "IO block offset alignment",
1056 .parent = "rw",
1057 },
1058 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001059 .name = "bsrange",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001060 .alias = "blocksize_range",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001061 .type = FIO_OPT_RANGE,
1062 .off1 = td_var_offset(min_bs[DDIR_READ]),
1063 .off2 = td_var_offset(max_bs[DDIR_READ]),
1064 .off3 = td_var_offset(min_bs[DDIR_WRITE]),
1065 .off4 = td_var_offset(max_bs[DDIR_WRITE]),
Jens Axboec3edbdb2007-07-20 14:25:31 +02001066 .minval = 1,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001067 .help = "Set block size range (in more detail than bs)",
Jens Axboe67a10002007-07-31 23:12:16 +02001068 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001069 },
1070 {
Jens Axboe564ca972007-12-14 12:21:19 +01001071 .name = "bssplit",
1072 .type = FIO_OPT_STR,
1073 .cb = str_bssplit_cb,
1074 .help = "Set a specific mix of block sizes",
1075 .parent = "rw",
1076 },
1077 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001078 .name = "bs_unaligned",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001079 .alias = "blocksize_unaligned",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001080 .type = FIO_OPT_STR_SET,
1081 .off1 = td_var_offset(bs_unaligned),
1082 .help = "Don't sector align IO buffer sizes",
Jens Axboe67a10002007-07-31 23:12:16 +02001083 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001084 },
1085 {
1086 .name = "randrepeat",
1087 .type = FIO_OPT_BOOL,
1088 .off1 = td_var_offset(rand_repeatable),
1089 .help = "Use repeatable random IO pattern",
1090 .def = "1",
Jens Axboe67a10002007-07-31 23:12:16 +02001091 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001092 },
1093 {
1094 .name = "norandommap",
1095 .type = FIO_OPT_STR_SET,
1096 .off1 = td_var_offset(norandommap),
1097 .help = "Accept potential duplicate random blocks",
Jens Axboe67a10002007-07-31 23:12:16 +02001098 .parent = "rw",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001099 },
1100 {
Jens Axboe2b386d22008-03-26 10:32:57 +01001101 .name = "softrandommap",
1102 .type = FIO_OPT_BOOL,
1103 .off1 = td_var_offset(softrandommap),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001104 .help = "Set norandommap if randommap allocation fails",
Jens Axboe2b386d22008-03-26 10:32:57 +01001105 .parent = "norandommap",
1106 .def = "0",
1107 },
1108 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001109 .name = "nrfiles",
1110 .type = FIO_OPT_INT,
1111 .off1 = td_var_offset(nr_files),
1112 .help = "Split job workload between this number of files",
1113 .def = "1",
1114 },
1115 {
1116 .name = "openfiles",
1117 .type = FIO_OPT_INT,
1118 .off1 = td_var_offset(open_files),
1119 .help = "Number of files to keep open at the same time",
1120 },
1121 {
1122 .name = "file_service_type",
1123 .type = FIO_OPT_STR,
1124 .cb = str_fst_cb,
1125 .off1 = td_var_offset(file_service_type),
1126 .help = "How to select which file to service next",
1127 .def = "roundrobin",
1128 .posval = {
1129 { .ival = "random",
1130 .oval = FIO_FSERVICE_RANDOM,
1131 .help = "Choose a file at random",
1132 },
1133 { .ival = "roundrobin",
1134 .oval = FIO_FSERVICE_RR,
1135 .help = "Round robin select files",
1136 },
Jens Axboea086c252009-03-04 08:27:37 +01001137 { .ival = "sequential",
1138 .oval = FIO_FSERVICE_SEQ,
1139 .help = "Finish one file before moving to the next",
1140 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001141 },
Jens Axboe67a10002007-07-31 23:12:16 +02001142 .parent = "nrfiles",
1143 },
Jens Axboe7bc8c2c2010-01-28 11:31:31 +01001144#ifdef FIO_HAVE_FALLOCATE
1145 {
1146 .name = "fallocate",
1147 .type = FIO_OPT_BOOL,
1148 .off1 = td_var_offset(fallocate),
1149 .help = "Use fallocate() when laying out files",
1150 .def = "1",
1151 },
1152#endif
Jens Axboe67a10002007-07-31 23:12:16 +02001153 {
1154 .name = "fadvise_hint",
1155 .type = FIO_OPT_BOOL,
1156 .off1 = td_var_offset(fadvise_hint),
1157 .help = "Use fadvise() to advise the kernel on IO pattern",
1158 .def = "1",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001159 },
1160 {
1161 .name = "fsync",
1162 .type = FIO_OPT_INT,
1163 .off1 = td_var_offset(fsync_blocks),
1164 .help = "Issue fsync for writes every given number of blocks",
1165 .def = "0",
1166 },
1167 {
Jens Axboe5f9099e2009-06-16 22:40:26 +02001168 .name = "fdatasync",
1169 .type = FIO_OPT_INT,
1170 .off1 = td_var_offset(fdatasync_blocks),
1171 .help = "Issue fdatasync for writes every given number of blocks",
1172 .def = "0",
1173 },
Jens Axboe44f29692010-03-09 20:09:44 +01001174#ifdef FIO_HAVE_SYNC_FILE_RANGE
1175 {
1176 .name = "sync_file_range",
1177 .posval = {
1178 { .ival = "wait_before",
1179 .oval = SYNC_FILE_RANGE_WAIT_BEFORE,
1180 .help = "SYNC_FILE_RANGE_WAIT_BEFORE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001181 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001182 },
1183 { .ival = "write",
1184 .oval = SYNC_FILE_RANGE_WRITE,
1185 .help = "SYNC_FILE_RANGE_WRITE",
Jens Axboe3843deb2010-03-09 20:41:15 +01001186 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001187 },
1188 {
1189 .ival = "wait_after",
1190 .oval = SYNC_FILE_RANGE_WAIT_AFTER,
1191 .help = "SYNC_FILE_RANGE_WAIT_AFTER",
Jens Axboe3843deb2010-03-09 20:41:15 +01001192 .or = 1,
Jens Axboe44f29692010-03-09 20:09:44 +01001193 },
1194 },
Jens Axboe3843deb2010-03-09 20:41:15 +01001195 .type = FIO_OPT_STR_MULTI,
Jens Axboe44f29692010-03-09 20:09:44 +01001196 .cb = str_sfr_cb,
1197 .off1 = td_var_offset(sync_file_range),
1198 .help = "Use sync_file_range()",
1199 },
1200#endif
Jens Axboe5f9099e2009-06-16 22:40:26 +02001201 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001202 .name = "direct",
1203 .type = FIO_OPT_BOOL,
1204 .off1 = td_var_offset(odirect),
1205 .help = "Use O_DIRECT IO (negates buffered)",
1206 .def = "0",
1207 },
1208 {
1209 .name = "buffered",
1210 .type = FIO_OPT_BOOL,
1211 .off1 = td_var_offset(odirect),
1212 .neg = 1,
1213 .help = "Use buffered IO (negates direct)",
1214 .def = "1",
1215 },
1216 {
1217 .name = "overwrite",
1218 .type = FIO_OPT_BOOL,
1219 .off1 = td_var_offset(overwrite),
1220 .help = "When writing, set whether to overwrite current data",
1221 .def = "0",
1222 },
1223 {
1224 .name = "loops",
1225 .type = FIO_OPT_INT,
1226 .off1 = td_var_offset(loops),
1227 .help = "Number of times to run the job",
1228 .def = "1",
1229 },
1230 {
1231 .name = "numjobs",
1232 .type = FIO_OPT_INT,
1233 .off1 = td_var_offset(numjobs),
1234 .help = "Duplicate this job this many times",
1235 .def = "1",
1236 },
1237 {
1238 .name = "startdelay",
Jens Axboea5737c92010-06-29 10:40:30 +02001239 .type = FIO_OPT_STR_VAL_TIME,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001240 .off1 = td_var_offset(start_delay),
1241 .help = "Only start job when this period has passed",
1242 .def = "0",
1243 },
1244 {
1245 .name = "runtime",
1246 .alias = "timeout",
1247 .type = FIO_OPT_STR_VAL_TIME,
1248 .off1 = td_var_offset(timeout),
1249 .help = "Stop workload when this amount of time has passed",
1250 .def = "0",
1251 },
1252 {
Jens Axboecf4464c2007-04-17 20:14:42 +02001253 .name = "time_based",
1254 .type = FIO_OPT_STR_SET,
1255 .off1 = td_var_offset(time_based),
1256 .help = "Keep running until runtime/timeout is met",
1257 },
1258 {
Jens Axboe721938a2008-09-10 09:46:16 +02001259 .name = "ramp_time",
1260 .type = FIO_OPT_STR_VAL_TIME,
1261 .off1 = td_var_offset(ramp_time),
1262 .help = "Ramp up time before measuring performance",
1263 },
1264 {
Jens Axboec223da82010-03-24 13:23:53 +01001265 .name = "clocksource",
1266 .type = FIO_OPT_STR,
1267 .cb = fio_clock_source_cb,
1268 .off1 = td_var_offset(clocksource),
1269 .help = "What type of timing source to use",
Jens Axboec223da82010-03-24 13:23:53 +01001270 .posval = {
1271 { .ival = "gettimeofday",
1272 .oval = CS_GTOD,
1273 .help = "Use gettimeofday(2) for timing",
1274 },
1275 { .ival = "clock_gettime",
1276 .oval = CS_CGETTIME,
1277 .help = "Use clock_gettime(2) for timing",
1278 },
1279#ifdef ARCH_HAVE_CPU_CLOCK
1280 { .ival = "cpu",
1281 .oval = CS_CPUCLOCK,
1282 .help = "Use CPU private clock",
1283 },
1284#endif
1285 },
1286 },
1287 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001288 .name = "mem",
Jens Axboed3aad8f2007-03-15 14:12:05 +01001289 .alias = "iomem",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001290 .type = FIO_OPT_STR,
1291 .cb = str_mem_cb,
1292 .off1 = td_var_offset(mem_type),
1293 .help = "Backing type for IO buffers",
1294 .def = "malloc",
1295 .posval = {
1296 { .ival = "malloc",
1297 .oval = MEM_MALLOC,
1298 .help = "Use malloc(3) for IO buffers",
1299 },
Jens Axboeb370e462007-03-19 10:51:49 +01001300 { .ival = "shm",
1301 .oval = MEM_SHM,
1302 .help = "Use shared memory segments for IO buffers",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001303 },
1304#ifdef FIO_HAVE_HUGETLB
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001305 { .ival = "shmhuge",
1306 .oval = MEM_SHMHUGE,
1307 .help = "Like shm, but use huge pages",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001308 },
1309#endif
Jens Axboeb370e462007-03-19 10:51:49 +01001310 { .ival = "mmap",
1311 .oval = MEM_MMAP,
1312 .help = "Use mmap(2) (file or anon) for IO buffers",
1313 },
Jens Axboe37c8cdf2007-03-19 13:14:03 +01001314#ifdef FIO_HAVE_HUGETLB
1315 { .ival = "mmaphuge",
1316 .oval = MEM_MMAPHUGE,
1317 .help = "Like mmap, but use huge pages",
1318 },
1319#endif
Jens Axboe214e1ec2007-03-15 10:48:13 +01001320 },
1321 },
1322 {
Jens Axboed529ee12009-07-01 10:33:03 +02001323 .name = "iomem_align",
1324 .alias = "mem_align",
1325 .type = FIO_OPT_INT,
1326 .off1 = td_var_offset(mem_align),
1327 .minval = 0,
1328 .help = "IO memory buffer offset alignment",
1329 .def = "0",
1330 .parent = "iomem",
1331 },
1332 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001333 .name = "verify",
1334 .type = FIO_OPT_STR,
1335 .off1 = td_var_offset(verify),
1336 .help = "Verify data written",
Jens Axboe5d7c5d32010-06-21 15:08:17 +02001337 .cb = str_verify_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001338 .def = "0",
1339 .posval = {
1340 { .ival = "0",
1341 .oval = VERIFY_NONE,
1342 .help = "Don't do IO verification",
1343 },
Jens Axboefcca4b52007-07-27 15:42:00 +02001344 { .ival = "md5",
1345 .oval = VERIFY_MD5,
1346 .help = "Use md5 checksums for verification",
1347 },
Jens Axboed77a7af2007-07-27 15:35:06 +02001348 { .ival = "crc64",
1349 .oval = VERIFY_CRC64,
1350 .help = "Use crc64 checksums for verification",
1351 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001352 { .ival = "crc32",
1353 .oval = VERIFY_CRC32,
1354 .help = "Use crc32 checksums for verification",
1355 },
Jens Axboeaf497e62008-08-04 15:40:35 +02001356 { .ival = "crc32c-intel",
1357 .oval = VERIFY_CRC32C_INTEL,
1358 .help = "Use hw crc32c checksums for verification",
1359 },
Jens Axboebac39e02008-06-11 20:46:19 +02001360 { .ival = "crc32c",
1361 .oval = VERIFY_CRC32C,
1362 .help = "Use crc32c checksums for verification",
1363 },
Jens Axboe969f7ed2007-07-27 09:07:17 +02001364 { .ival = "crc16",
1365 .oval = VERIFY_CRC16,
1366 .help = "Use crc16 checksums for verification",
1367 },
Jens Axboe1e154bd2007-07-27 09:52:40 +02001368 { .ival = "crc7",
1369 .oval = VERIFY_CRC7,
1370 .help = "Use crc7 checksums for verification",
1371 },
Jens Axboe7c353ce2009-08-09 22:40:33 +02001372 { .ival = "sha1",
1373 .oval = VERIFY_SHA1,
1374 .help = "Use sha1 checksums for verification",
1375 },
Jens Axboecd14cc12007-07-30 10:59:33 +02001376 { .ival = "sha256",
1377 .oval = VERIFY_SHA256,
1378 .help = "Use sha256 checksums for verification",
1379 },
1380 { .ival = "sha512",
1381 .oval = VERIFY_SHA512,
1382 .help = "Use sha512 checksums for verification",
1383 },
Shawn Lewis7437ee82007-08-02 21:05:58 +02001384 { .ival = "meta",
1385 .oval = VERIFY_META,
1386 .help = "Use io information",
1387 },
Jens Axboe36690c92007-03-26 10:23:34 +02001388 {
1389 .ival = "null",
1390 .oval = VERIFY_NULL,
1391 .help = "Pretend to verify",
1392 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001393 },
1394 },
1395 {
Jens Axboe005c5652007-08-02 22:21:36 +02001396 .name = "do_verify",
Jens Axboe68e1f292007-08-10 10:32:14 +02001397 .type = FIO_OPT_BOOL,
Jens Axboe005c5652007-08-02 22:21:36 +02001398 .off1 = td_var_offset(do_verify),
1399 .help = "Run verification stage after write",
1400 .def = "1",
1401 .parent = "verify",
1402 },
1403 {
Jens Axboe160b9662007-03-27 10:59:49 +02001404 .name = "verifysort",
1405 .type = FIO_OPT_BOOL,
1406 .off1 = td_var_offset(verifysort),
1407 .help = "Sort written verify blocks for read back",
1408 .def = "1",
Jens Axboec83f2df2007-07-31 22:51:47 +02001409 .parent = "verify",
Jens Axboe160b9662007-03-27 10:59:49 +02001410 },
1411 {
Jens Axboea59e1702007-07-30 08:53:27 +02001412 .name = "verify_interval",
Jens Axboee01b22b2009-06-09 15:43:25 +02001413 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001414 .off1 = td_var_offset(verify_interval),
Jens Axboe819a9682007-07-28 21:30:31 +02001415 .minval = 2 * sizeof(struct verify_header),
Jens Axboea59e1702007-07-30 08:53:27 +02001416 .help = "Store verify buffer header every N bytes",
Jens Axboeafdf9352007-07-31 16:14:34 +02001417 .parent = "verify",
Shawn Lewis3f9f4e22007-07-28 21:10:37 +02001418 },
1419 {
Jens Axboea59e1702007-07-30 08:53:27 +02001420 .name = "verify_offset",
Jens Axboee01b22b2009-06-09 15:43:25 +02001421 .type = FIO_OPT_INT,
Jens Axboea59e1702007-07-30 08:53:27 +02001422 .help = "Offset verify header location by N bytes",
Shawn Lewis546a9142007-07-28 21:11:37 +02001423 .def = "0",
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001424 .cb = str_verify_offset_cb,
Jens Axboeafdf9352007-07-31 16:14:34 +02001425 .parent = "verify",
Shawn Lewis546a9142007-07-28 21:11:37 +02001426 },
1427 {
Shawn Lewise28218f2008-01-16 11:01:33 +01001428 .name = "verify_pattern",
Radha Ramachandran0e92f872009-10-27 20:14:27 +01001429 .type = FIO_OPT_STR,
Shawn Lewise28218f2008-01-16 11:01:33 +01001430 .cb = str_verify_pattern_cb,
1431 .help = "Fill pattern for IO buffers",
1432 .parent = "verify",
1433 },
1434 {
Jens Axboea12a3b42007-08-09 10:20:54 +02001435 .name = "verify_fatal",
Jens Axboe68e1f292007-08-10 10:32:14 +02001436 .type = FIO_OPT_BOOL,
Jens Axboea12a3b42007-08-09 10:20:54 +02001437 .off1 = td_var_offset(verify_fatal),
1438 .def = "0",
1439 .help = "Exit on a single verify failure, don't continue",
1440 .parent = "verify",
1441 },
1442 {
Jens Axboee8462bd2009-07-06 12:59:04 +02001443 .name = "verify_async",
1444 .type = FIO_OPT_INT,
1445 .off1 = td_var_offset(verify_async),
1446 .def = "0",
1447 .help = "Number of async verifier threads to use",
1448 .parent = "verify",
1449 },
Jens Axboe9e144182010-06-15 14:25:36 +02001450 {
1451 .name = "verify_backlog",
1452 .type = FIO_OPT_STR_VAL,
1453 .off1 = td_var_offset(verify_backlog),
1454 .help = "Verify after this number of blocks are written",
1455 .parent = "verify",
1456 },
1457 {
1458 .name = "verify_backlog_batch",
1459 .type = FIO_OPT_INT,
1460 .off1 = td_var_offset(verify_batch),
1461 .help = "Verify this number of IO blocks",
1462 .parent = "verify_backlog",
1463 },
Jens Axboee8462bd2009-07-06 12:59:04 +02001464#ifdef FIO_HAVE_CPU_AFFINITY
1465 {
1466 .name = "verify_async_cpus",
1467 .type = FIO_OPT_STR,
1468 .cb = str_verify_cpus_allowed_cb,
1469 .help = "Set CPUs allowed for async verify threads",
1470 .parent = "verify_async",
1471 },
1472#endif
1473 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001474 .name = "write_iolog",
1475 .type = FIO_OPT_STR_STORE,
1476 .off1 = td_var_offset(write_iolog_file),
1477 .help = "Store IO pattern to file",
1478 },
1479 {
1480 .name = "read_iolog",
1481 .type = FIO_OPT_STR_STORE,
1482 .off1 = td_var_offset(read_iolog_file),
1483 .help = "Playback IO pattern from file",
1484 },
1485 {
1486 .name = "exec_prerun",
1487 .type = FIO_OPT_STR_STORE,
1488 .off1 = td_var_offset(exec_prerun),
1489 .help = "Execute this file prior to running job",
1490 },
1491 {
1492 .name = "exec_postrun",
1493 .type = FIO_OPT_STR_STORE,
1494 .off1 = td_var_offset(exec_postrun),
1495 .help = "Execute this file after running job",
1496 },
1497#ifdef FIO_HAVE_IOSCHED_SWITCH
1498 {
1499 .name = "ioscheduler",
1500 .type = FIO_OPT_STR_STORE,
1501 .off1 = td_var_offset(ioscheduler),
1502 .help = "Use this IO scheduler on the backing device",
1503 },
1504#endif
1505 {
1506 .name = "zonesize",
1507 .type = FIO_OPT_STR_VAL,
1508 .off1 = td_var_offset(zone_size),
1509 .help = "Give size of an IO zone",
1510 .def = "0",
1511 },
1512 {
1513 .name = "zoneskip",
1514 .type = FIO_OPT_STR_VAL,
1515 .off1 = td_var_offset(zone_skip),
1516 .help = "Space between IO zones",
1517 .def = "0",
1518 },
1519 {
1520 .name = "lockmem",
1521 .type = FIO_OPT_STR_VAL,
1522 .cb = str_lockmem_cb,
1523 .help = "Lock down this amount of memory",
1524 .def = "0",
1525 },
1526 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001527 .name = "rwmixread",
1528 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001529 .cb = str_rwmix_read_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001530 .maxval = 100,
1531 .help = "Percentage of mixed workload that is reads",
1532 .def = "50",
1533 },
1534 {
1535 .name = "rwmixwrite",
1536 .type = FIO_OPT_INT,
Jens Axboecb499fc2008-05-28 10:33:32 +02001537 .cb = str_rwmix_write_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001538 .maxval = 100,
1539 .help = "Percentage of mixed workload that is writes",
1540 .def = "50",
1541 },
1542 {
Jens Axboeafdf9352007-07-31 16:14:34 +02001543 .name = "rwmixcycle",
Jens Axboe15ca1502008-04-07 09:26:02 +02001544 .type = FIO_OPT_DEPRECATED,
Jens Axboeafdf9352007-07-31 16:14:34 +02001545 },
1546 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001547 .name = "nice",
1548 .type = FIO_OPT_INT,
1549 .off1 = td_var_offset(nice),
1550 .help = "Set job CPU nice value",
1551 .minval = -19,
1552 .maxval = 20,
1553 .def = "0",
1554 },
1555#ifdef FIO_HAVE_IOPRIO
1556 {
1557 .name = "prio",
1558 .type = FIO_OPT_INT,
1559 .cb = str_prio_cb,
1560 .help = "Set job IO priority value",
1561 .minval = 0,
1562 .maxval = 7,
1563 },
1564 {
1565 .name = "prioclass",
1566 .type = FIO_OPT_INT,
1567 .cb = str_prioclass_cb,
1568 .help = "Set job IO priority class",
1569 .minval = 0,
1570 .maxval = 3,
1571 },
1572#endif
1573 {
1574 .name = "thinktime",
1575 .type = FIO_OPT_INT,
1576 .off1 = td_var_offset(thinktime),
1577 .help = "Idle time between IO buffers (usec)",
1578 .def = "0",
1579 },
1580 {
1581 .name = "thinktime_spin",
1582 .type = FIO_OPT_INT,
1583 .off1 = td_var_offset(thinktime_spin),
1584 .help = "Start think time by spinning this amount (usec)",
1585 .def = "0",
Jens Axboeafdf9352007-07-31 16:14:34 +02001586 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001587 },
1588 {
1589 .name = "thinktime_blocks",
1590 .type = FIO_OPT_INT,
1591 .off1 = td_var_offset(thinktime_blocks),
1592 .help = "IO buffer period between 'thinktime'",
1593 .def = "1",
Jens Axboeafdf9352007-07-31 16:14:34 +02001594 .parent = "thinktime",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001595 },
1596 {
1597 .name = "rate",
Jens Axboee01b22b2009-06-09 15:43:25 +02001598 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001599 .off1 = td_var_offset(rate[0]),
1600 .off2 = td_var_offset(rate[1]),
Jens Axboe214e1ec2007-03-15 10:48:13 +01001601 .help = "Set bandwidth rate",
1602 },
1603 {
1604 .name = "ratemin",
Jens Axboee01b22b2009-06-09 15:43:25 +02001605 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001606 .off1 = td_var_offset(ratemin[0]),
1607 .off2 = td_var_offset(ratemin[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001608 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001609 .parent = "rate",
Jens Axboe4e991c22007-03-15 11:41:11 +01001610 },
1611 {
1612 .name = "rate_iops",
Jens Axboee01b22b2009-06-09 15:43:25 +02001613 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001614 .off1 = td_var_offset(rate_iops[0]),
1615 .off2 = td_var_offset(rate_iops[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001616 .help = "Limit IO used to this number of IO operations/sec",
1617 },
1618 {
1619 .name = "rate_iops_min",
Jens Axboee01b22b2009-06-09 15:43:25 +02001620 .type = FIO_OPT_INT,
Jens Axboe581e7142009-06-09 12:47:16 +02001621 .off1 = td_var_offset(rate_iops_min[0]),
1622 .off2 = td_var_offset(rate_iops_min[1]),
Jens Axboe4e991c22007-03-15 11:41:11 +01001623 .help = "Job must meet this rate or it will be shutdown",
Jens Axboeafdf9352007-07-31 16:14:34 +02001624 .parent = "rate_iops",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001625 },
1626 {
1627 .name = "ratecycle",
1628 .type = FIO_OPT_INT,
1629 .off1 = td_var_offset(ratecycle),
1630 .help = "Window average for rate limits (msec)",
1631 .def = "1000",
Jens Axboeafdf9352007-07-31 16:14:34 +02001632 .parent = "rate",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001633 },
1634 {
1635 .name = "invalidate",
1636 .type = FIO_OPT_BOOL,
1637 .off1 = td_var_offset(invalidate_cache),
1638 .help = "Invalidate buffer/page cache prior to running job",
1639 .def = "1",
1640 },
1641 {
1642 .name = "sync",
1643 .type = FIO_OPT_BOOL,
1644 .off1 = td_var_offset(sync_io),
1645 .help = "Use O_SYNC for buffered writes",
1646 .def = "0",
Jens Axboe67a10002007-07-31 23:12:16 +02001647 .parent = "buffered",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001648 },
1649 {
1650 .name = "bwavgtime",
1651 .type = FIO_OPT_INT,
1652 .off1 = td_var_offset(bw_avg_time),
Jens Axboe5ec10ea2008-03-06 15:42:00 +01001653 .help = "Time window over which to calculate bandwidth"
1654 " (msec)",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001655 .def = "500",
1656 },
1657 {
1658 .name = "create_serialize",
1659 .type = FIO_OPT_BOOL,
1660 .off1 = td_var_offset(create_serialize),
1661 .help = "Serialize creating of job files",
1662 .def = "1",
1663 },
1664 {
1665 .name = "create_fsync",
1666 .type = FIO_OPT_BOOL,
1667 .off1 = td_var_offset(create_fsync),
1668 .help = "Fsync file after creation",
1669 .def = "1",
1670 },
1671 {
Jens Axboe814452b2009-03-04 12:53:13 +01001672 .name = "create_on_open",
1673 .type = FIO_OPT_BOOL,
1674 .off1 = td_var_offset(create_on_open),
1675 .help = "Create files when they are opened for IO",
1676 .def = "0",
1677 },
Jens Axboe0b9d69e2009-09-11 22:29:54 +02001678 {
Zhang, Yanminafad68f2009-05-20 11:30:55 +02001679 .name = "pre_read",
1680 .type = FIO_OPT_BOOL,
1681 .off1 = td_var_offset(pre_read),
1682 .help = "Preread files before starting official testing",
1683 .def = "0",
1684 },
Jens Axboe814452b2009-03-04 12:53:13 +01001685 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001686 .name = "cpuload",
1687 .type = FIO_OPT_INT,
1688 .off1 = td_var_offset(cpuload),
1689 .help = "Use this percentage of CPU",
1690 },
1691 {
1692 .name = "cpuchunks",
1693 .type = FIO_OPT_INT,
1694 .off1 = td_var_offset(cpucycle),
1695 .help = "Length of the CPU burn cycles (usecs)",
1696 .def = "50000",
Jens Axboe67a10002007-07-31 23:12:16 +02001697 .parent = "cpuload",
Jens Axboe214e1ec2007-03-15 10:48:13 +01001698 },
1699#ifdef FIO_HAVE_CPU_AFFINITY
1700 {
1701 .name = "cpumask",
1702 .type = FIO_OPT_INT,
1703 .cb = str_cpumask_cb,
1704 .help = "CPU affinity mask",
1705 },
Jens Axboed2e268b2007-06-15 10:33:49 +02001706 {
1707 .name = "cpus_allowed",
1708 .type = FIO_OPT_STR,
1709 .cb = str_cpus_allowed_cb,
1710 .help = "Set CPUs allowed",
1711 },
Jens Axboe214e1ec2007-03-15 10:48:13 +01001712#endif
1713 {
1714 .name = "end_fsync",
1715 .type = FIO_OPT_BOOL,
1716 .off1 = td_var_offset(end_fsync),
1717 .help = "Include fsync at the end of job",
1718 .def = "0",
1719 },
1720 {
1721 .name = "fsync_on_close",
1722 .type = FIO_OPT_BOOL,
1723 .off1 = td_var_offset(fsync_on_close),
1724 .help = "fsync files on close",
1725 .def = "0",
1726 },
1727 {
1728 .name = "unlink",
1729 .type = FIO_OPT_BOOL,
1730 .off1 = td_var_offset(unlink),
1731 .help = "Unlink created files after job has completed",
1732 .def = "0",
1733 },
1734 {
1735 .name = "exitall",
1736 .type = FIO_OPT_STR_SET,
1737 .cb = str_exitall_cb,
1738 .help = "Terminate all jobs when one exits",
1739 },
1740 {
1741 .name = "stonewall",
1742 .type = FIO_OPT_STR_SET,
1743 .off1 = td_var_offset(stonewall),
1744 .help = "Insert a hard barrier between this job and previous",
1745 },
1746 {
Jens Axboeb3d62a72007-03-20 14:23:26 +01001747 .name = "new_group",
1748 .type = FIO_OPT_STR_SET,
1749 .off1 = td_var_offset(new_group),
1750 .help = "Mark the start of a new group (for reporting)",
1751 },
1752 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001753 .name = "thread",
1754 .type = FIO_OPT_STR_SET,
1755 .off1 = td_var_offset(use_thread),
1756 .help = "Use threads instead of forks",
1757 },
1758 {
1759 .name = "write_bw_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001760 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001761 .off1 = td_var_offset(write_bw_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001762 .cb = str_write_bw_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001763 .help = "Write log of bandwidth during run",
1764 },
1765 {
1766 .name = "write_lat_log",
Jens Axboee3cedca2008-11-19 19:57:52 +01001767 .type = FIO_OPT_STR,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001768 .off1 = td_var_offset(write_lat_log),
Jens Axboee3cedca2008-11-19 19:57:52 +01001769 .cb = str_write_lat_log_cb,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001770 .help = "Write log of latency during run",
1771 },
1772 {
1773 .name = "hugepage-size",
Jens Axboee01b22b2009-06-09 15:43:25 +02001774 .type = FIO_OPT_INT,
Jens Axboe214e1ec2007-03-15 10:48:13 +01001775 .off1 = td_var_offset(hugepage_size),
1776 .help = "When using hugepages, specify size of each page",
1777 .def = __stringify(FIO_HUGE_PAGE),
1778 },
1779 {
1780 .name = "group_reporting",
1781 .type = FIO_OPT_STR_SET,
1782 .off1 = td_var_offset(group_reporting),
1783 .help = "Do reporting on a per-group basis",
1784 },
1785 {
Jens Axboee9459e52007-04-17 15:46:32 +02001786 .name = "zero_buffers",
1787 .type = FIO_OPT_STR_SET,
1788 .off1 = td_var_offset(zero_buffers),
1789 .help = "Init IO buffers to all zeroes",
1790 },
Jens Axboe5973caf2008-05-21 19:52:35 +02001791 {
1792 .name = "refill_buffers",
1793 .type = FIO_OPT_STR_SET,
1794 .off1 = td_var_offset(refill_buffers),
1795 .help = "Refill IO buffers on every IO submit",
1796 },
Jens Axboe0a839f32007-04-26 09:02:34 +02001797#ifdef FIO_HAVE_DISK_UTIL
1798 {
1799 .name = "disk_util",
1800 .type = FIO_OPT_BOOL,
1801 .off1 = td_var_offset(do_disk_util),
Jens Axboef66ab3c2008-06-05 11:48:22 +02001802 .help = "Log disk utilization statistics",
Jens Axboe0a839f32007-04-26 09:02:34 +02001803 .def = "1",
1804 },
1805#endif
Jens Axboee9459e52007-04-17 15:46:32 +02001806 {
Jens Axboe993bf482008-11-14 13:04:53 +01001807 .name = "gtod_reduce",
1808 .type = FIO_OPT_BOOL,
1809 .help = "Greatly reduce number of gettimeofday() calls",
1810 .cb = str_gtod_reduce_cb,
1811 .def = "0",
1812 },
1813 {
Jens Axboe02af0982010-06-24 09:59:34 +02001814 .name = "disable_lat",
1815 .type = FIO_OPT_BOOL,
1816 .off1 = td_var_offset(disable_lat),
1817 .help = "Disable latency numbers",
1818 .parent = "gtod_reduce",
1819 .def = "0",
1820 },
1821 {
Jens Axboe9520ebb2008-10-16 21:03:27 +02001822 .name = "disable_clat",
1823 .type = FIO_OPT_BOOL,
1824 .off1 = td_var_offset(disable_clat),
1825 .help = "Disable completion latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001826 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001827 .def = "0",
1828 },
1829 {
1830 .name = "disable_slat",
1831 .type = FIO_OPT_BOOL,
1832 .off1 = td_var_offset(disable_slat),
1833 .help = "Disable submissionn latency numbers",
Jens Axboe993bf482008-11-14 13:04:53 +01001834 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001835 .def = "0",
1836 },
1837 {
1838 .name = "disable_bw_measurement",
1839 .type = FIO_OPT_BOOL,
1840 .off1 = td_var_offset(disable_bw),
1841 .help = "Disable bandwidth logging",
Jens Axboe993bf482008-11-14 13:04:53 +01001842 .parent = "gtod_reduce",
Jens Axboe9520ebb2008-10-16 21:03:27 +02001843 .def = "0",
1844 },
1845 {
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001846 .name = "gtod_cpu",
1847 .type = FIO_OPT_INT,
1848 .cb = str_gtod_cpu_cb,
1849 .help = "Setup dedicated gettimeofday() thread on this CPU",
Jens Axboe29d43ff2009-07-01 10:42:18 +02001850 .verify = gtod_cpu_verify,
Jens Axboebe4ecfd2008-12-08 14:10:52 +01001851 },
1852 {
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001853 .name = "continue_on_error",
1854 .type = FIO_OPT_BOOL,
1855 .off1 = td_var_offset(continue_on_error),
1856 .help = "Continue on non-fatal errors during I/O",
1857 .def = "0",
1858 },
1859 {
Jens Axboe9ac8a792009-11-13 21:23:07 +01001860 .name = "profile",
Jens Axboe79d16312010-03-04 12:43:20 +01001861 .type = FIO_OPT_STR_STORE,
Jens Axboe9ac8a792009-11-13 21:23:07 +01001862 .off1 = td_var_offset(profile),
Jens Axboe9ac8a792009-11-13 21:23:07 +01001863 .help = "Select a specific builtin performance test",
1864 },
1865 {
Jens Axboea696fa22009-12-04 10:05:02 +01001866 .name = "cgroup",
1867 .type = FIO_OPT_STR_STORE,
1868 .off1 = td_var_offset(cgroup),
1869 .help = "Add job to cgroup of this name",
1870 },
1871 {
1872 .name = "cgroup_weight",
1873 .type = FIO_OPT_INT,
1874 .off1 = td_var_offset(cgroup_weight),
1875 .help = "Use given weight for cgroup",
1876 .minval = 100,
1877 .maxval = 1000,
Jens Axboea696fa22009-12-04 10:05:02 +01001878 },
1879 {
Vivek Goyal7de87092010-03-31 22:55:15 +02001880 .name = "cgroup_nodelete",
1881 .type = FIO_OPT_BOOL,
1882 .off1 = td_var_offset(cgroup_nodelete),
1883 .help = "Do not delete cgroups after job completion",
1884 .def = "0",
1885 },
1886 {
Jens Axboee0b0d892009-12-08 10:10:14 +01001887 .name = "uid",
1888 .type = FIO_OPT_INT,
1889 .off1 = td_var_offset(uid),
1890 .help = "Run job with this user ID",
1891 },
1892 {
1893 .name = "gid",
1894 .type = FIO_OPT_INT,
1895 .off1 = td_var_offset(gid),
1896 .help = "Run job with this group ID",
1897 },
1898 {
Jens Axboe214e1ec2007-03-15 10:48:13 +01001899 .name = NULL,
1900 },
1901};
1902
Jens Axboe17af15d2010-04-13 10:38:16 +02001903static void add_to_lopt(struct option *lopt, struct fio_option *o,
1904 const char *name)
Jens Axboe9f817362010-03-04 14:38:10 +01001905{
Jens Axboe17af15d2010-04-13 10:38:16 +02001906 lopt->name = (char *) name;
Jens Axboe9f817362010-03-04 14:38:10 +01001907 lopt->val = FIO_GETOPT_JOB;
1908 if (o->type == FIO_OPT_STR_SET)
1909 lopt->has_arg = no_argument;
1910 else
1911 lopt->has_arg = required_argument;
1912}
1913
Jens Axboe214e1ec2007-03-15 10:48:13 +01001914void fio_options_dup_and_init(struct option *long_options)
1915{
1916 struct fio_option *o;
1917 unsigned int i;
1918
1919 options_init(options);
1920
1921 i = 0;
1922 while (long_options[i].name)
1923 i++;
1924
1925 o = &options[0];
1926 while (o->name) {
Jens Axboe17af15d2010-04-13 10:38:16 +02001927 add_to_lopt(&long_options[i], o, o->name);
1928 if (o->alias) {
1929 i++;
1930 add_to_lopt(&long_options[i], o, o->alias);
1931 }
Jens Axboe214e1ec2007-03-15 10:48:13 +01001932
1933 i++;
1934 o++;
1935 assert(i < FIO_NR_OPTIONS);
1936 }
1937}
1938
Jens Axboe74929ac2009-08-05 11:42:37 +02001939struct fio_keyword {
1940 const char *word;
1941 const char *desc;
1942 char *replace;
1943};
1944
1945static struct fio_keyword fio_keywords[] = {
1946 {
1947 .word = "$pagesize",
1948 .desc = "Page size in the system",
1949 },
1950 {
1951 .word = "$mb_memory",
1952 .desc = "Megabytes of memory online",
1953 },
1954 {
1955 .word = "$ncpus",
1956 .desc = "Number of CPUs online in the system",
1957 },
1958 {
1959 .word = NULL,
1960 },
1961};
1962
1963void fio_keywords_init(void)
1964{
Jens Axboe3b2e1462009-12-15 08:58:10 +01001965 unsigned long long mb_memory;
Jens Axboe74929ac2009-08-05 11:42:37 +02001966 char buf[128];
1967 long l;
1968
1969 sprintf(buf, "%lu", page_size);
1970 fio_keywords[0].replace = strdup(buf);
1971
Jens Axboe3b2e1462009-12-15 08:58:10 +01001972 mb_memory = os_phys_mem() / page_size;
1973 sprintf(buf, "%llu", mb_memory);
Jens Axboe74929ac2009-08-05 11:42:37 +02001974 fio_keywords[1].replace = strdup(buf);
1975
1976 l = sysconf(_SC_NPROCESSORS_ONLN);
1977 sprintf(buf, "%lu", l);
1978 fio_keywords[2].replace = strdup(buf);
1979}
1980
Jens Axboe892a6ff2009-11-13 12:19:49 +01001981#define BC_APP "bc"
1982
1983static char *bc_calc(char *str)
1984{
1985 char *buf, *tmp, opt[80];
1986 FILE *f;
1987 int ret;
1988
1989 /*
1990 * No math, just return string
1991 */
1992 if (!strchr(str, '+') && !strchr(str, '-') && !strchr(str, '*') &&
1993 !strchr(str, '/'))
1994 return str;
1995
1996 /*
1997 * Split option from value, we only need to calculate the value
1998 */
1999 tmp = strchr(str, '=');
2000 if (!tmp)
2001 return str;
2002
2003 tmp++;
Jens Axboe9ac8a792009-11-13 21:23:07 +01002004 memset(opt, 0, sizeof(opt));
Jens Axboe892a6ff2009-11-13 12:19:49 +01002005 strncpy(opt, str, tmp - str);
2006
2007 buf = malloc(128);
2008
2009 sprintf(buf, "which %s > /dev/null", BC_APP);
2010 if (system(buf)) {
2011 log_err("fio: bc is needed for performing math\n");
2012 free(buf);
2013 return NULL;
2014 }
2015
2016 sprintf(buf, "echo %s | %s", tmp, BC_APP);
2017 f = popen(buf, "r");
2018 if (!f) {
2019 free(buf);
2020 return NULL;
2021 }
2022
2023 ret = fread(buf, 1, 128, f);
2024 if (ret <= 0) {
2025 free(buf);
2026 return NULL;
2027 }
2028
2029 buf[ret - 1] = '\0';
2030 strcat(opt, buf);
2031 strcpy(buf, opt);
2032 pclose(f);
2033 free(str);
2034 return buf;
2035}
2036
Jens Axboe74929ac2009-08-05 11:42:37 +02002037/*
2038 * Look for reserved variable names and replace them with real values
2039 */
2040static char *fio_keyword_replace(char *opt)
2041{
2042 char *s;
2043 int i;
2044
2045 for (i = 0; fio_keywords[i].word != NULL; i++) {
2046 struct fio_keyword *kw = &fio_keywords[i];
2047
2048 while ((s = strstr(opt, kw->word)) != NULL) {
2049 char *new = malloc(strlen(opt) + 1);
2050 char *o_org = opt;
2051 int olen = s - opt;
2052 int len;
2053
2054 /*
2055 * Copy part of the string before the keyword and
2056 * sprintf() the replacement after it.
2057 */
2058 memcpy(new, opt, olen);
2059 len = sprintf(new + olen, "%s", kw->replace);
2060
2061 /*
2062 * If there's more in the original string, copy that
2063 * in too
2064 */
2065 opt += strlen(kw->word) + olen;
2066 if (strlen(opt))
2067 memcpy(new + olen + len, opt, opt - o_org - 1);
2068
2069 /*
2070 * replace opt and free the old opt
2071 */
2072 opt = new;
Jens Axboe9ac8a792009-11-13 21:23:07 +01002073 //free(o_org);
Jens Axboe7a958bd2009-11-13 12:33:54 +01002074
2075 /*
2076 * Check for potential math and invoke bc, if possible
2077 */
2078 opt = bc_calc(opt);
Jens Axboe74929ac2009-08-05 11:42:37 +02002079 }
2080 }
2081
Jens Axboe7a958bd2009-11-13 12:33:54 +01002082 return opt;
Jens Axboe74929ac2009-08-05 11:42:37 +02002083}
2084
Jens Axboe3b8b7132008-06-10 19:46:23 +02002085int fio_options_parse(struct thread_data *td, char **opts, int num_opts)
Jens Axboe214e1ec2007-03-15 10:48:13 +01002086{
Jens Axboe3b8b7132008-06-10 19:46:23 +02002087 int i, ret;
2088
2089 sort_options(opts, options, num_opts);
2090
Jens Axboe74929ac2009-08-05 11:42:37 +02002091 for (ret = 0, i = 0; i < num_opts; i++) {
2092 opts[i] = fio_keyword_replace(opts[i]);
Jens Axboe07b32322010-03-05 09:48:44 +01002093 ret |= parse_option(opts[i], options, td);
Jens Axboe74929ac2009-08-05 11:42:37 +02002094 }
Jens Axboe3b8b7132008-06-10 19:46:23 +02002095
2096 return ret;
Jens Axboe214e1ec2007-03-15 10:48:13 +01002097}
2098
2099int fio_cmd_option_parse(struct thread_data *td, const char *opt, char *val)
2100{
Jens Axboe07b32322010-03-05 09:48:44 +01002101 return parse_cmd_option(opt, val, options, td);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002102}
2103
2104void fio_fill_default_options(struct thread_data *td)
2105{
2106 fill_default_options(td, options);
2107}
2108
2109int fio_show_option_help(const char *opt)
2110{
Jens Axboe07b32322010-03-05 09:48:44 +01002111 return show_cmd_help(options, opt);
Jens Axboe214e1ec2007-03-15 10:48:13 +01002112}
Jens Axboed23bb322007-03-23 15:57:56 +01002113
2114static void __options_mem(struct thread_data *td, int alloc)
2115{
2116 struct thread_options *o = &td->o;
2117 struct fio_option *opt;
2118 char **ptr;
2119 int i;
2120
2121 for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
2122 if (opt->type != FIO_OPT_STR_STORE)
2123 continue;
2124
2125 ptr = (void *) o + opt->off1;
2126 if (*ptr) {
2127 if (alloc)
2128 *ptr = strdup(*ptr);
2129 else {
2130 free(*ptr);
2131 *ptr = NULL;
2132 }
2133 }
2134 }
2135}
2136
2137/*
2138 * dupe FIO_OPT_STR_STORE options
2139 */
2140void options_mem_dupe(struct thread_data *td)
2141{
2142 __options_mem(td, 1);
2143}
2144
Jens Axboe22d66212007-03-27 20:06:25 +02002145void options_mem_free(struct thread_data fio_unused *td)
Jens Axboed23bb322007-03-23 15:57:56 +01002146{
Jens Axboe22d66212007-03-27 20:06:25 +02002147#if 0
Jens Axboed23bb322007-03-23 15:57:56 +01002148 __options_mem(td, 0);
Jens Axboe22d66212007-03-27 20:06:25 +02002149#endif
Jens Axboed23bb322007-03-23 15:57:56 +01002150}
Jens Axboed6978a32009-07-18 21:04:09 +02002151
2152unsigned int fio_get_kb_base(void *data)
2153{
2154 struct thread_data *td = data;
2155 unsigned int kb_base = 0;
2156
2157 if (td)
2158 kb_base = td->o.kb_base;
2159 if (!kb_base)
2160 kb_base = 1024;
2161
2162 return kb_base;
2163}
Jens Axboe9f988e22010-03-04 10:42:38 +01002164
Jens Axboe07b32322010-03-05 09:48:44 +01002165int add_option(struct fio_option *o)
Jens Axboe9f988e22010-03-04 10:42:38 +01002166{
Jens Axboe07b32322010-03-05 09:48:44 +01002167 struct fio_option *__o;
2168 int opt_index = 0;
2169
2170 __o = options;
2171 while (__o->name) {
2172 opt_index++;
2173 __o++;
2174 }
2175
2176 memcpy(&options[opt_index], o, sizeof(*o));
2177 return 0;
Jens Axboe9f988e22010-03-04 10:42:38 +01002178}
Jens Axboee2de69d2010-03-04 14:05:48 +01002179
Jens Axboe07b32322010-03-05 09:48:44 +01002180void invalidate_profile_options(const char *prof_name)
Jens Axboee2de69d2010-03-04 14:05:48 +01002181{
Jens Axboe07b32322010-03-05 09:48:44 +01002182 struct fio_option *o;
Jens Axboee2de69d2010-03-04 14:05:48 +01002183
Jens Axboe07b32322010-03-05 09:48:44 +01002184 o = options;
2185 while (o->name) {
2186 if (o->prof_name && !strcmp(o->prof_name, prof_name)) {
2187 o->type = FIO_OPT_INVALID;
2188 o->prof_name = NULL;
2189 }
2190 o++;
Jens Axboee2de69d2010-03-04 14:05:48 +01002191 }
2192}
Jens Axboef5b6bb82010-03-05 10:09:59 +01002193
2194void add_opt_posval(const char *optname, const char *ival, const char *help)
2195{
2196 struct fio_option *o;
2197 unsigned int i;
2198
2199 o = find_option(options, optname);
2200 if (!o)
2201 return;
2202
2203 for (i = 0; i < PARSE_MAX_VP; i++) {
2204 if (o->posval[i].ival)
2205 continue;
2206
2207 o->posval[i].ival = ival;
2208 o->posval[i].help = help;
2209 break;
2210 }
2211}
2212
2213void del_opt_posval(const char *optname, const char *ival)
2214{
2215 struct fio_option *o;
2216 unsigned int i;
2217
2218 o = find_option(options, optname);
2219 if (!o)
2220 return;
2221
2222 for (i = 0; i < PARSE_MAX_VP; i++) {
2223 if (!o->posval[i].ival)
2224 continue;
2225 if (strcmp(o->posval[i].ival, ival))
2226 continue;
2227
2228 o->posval[i].ival = NULL;
2229 o->posval[i].help = NULL;
2230 }
2231}