Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1 | /* |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 2 | * This file contains job initialization and setup functions. |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 3 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <unistd.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <ctype.h> |
| 9 | #include <string.h> |
| 10 | #include <errno.h> |
| 11 | #include <sys/ipc.h> |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 12 | #include <sys/types.h> |
| 13 | #include <sys/stat.h> |
| 14 | |
| 15 | #include "fio.h" |
Oleg | a5e0ee1 | 2013-03-12 00:06:53 -0700 | [diff] [blame] | 16 | #ifndef FIO_NO_HAVE_SHM_H |
| 17 | #include <sys/shm.h> |
| 18 | #endif |
| 19 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 20 | #include "parse.h" |
Jens Axboe | 2e5cdb1 | 2008-03-01 18:52:49 +0100 | [diff] [blame] | 21 | #include "smalloc.h" |
Jens Axboe | 380065a | 2008-03-01 18:56:24 +0100 | [diff] [blame] | 22 | #include "filehash.h" |
Jens Axboe | 4f5af7b | 2009-06-03 08:45:40 +0200 | [diff] [blame] | 23 | #include "verify.h" |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 24 | #include "profile.h" |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 25 | #include "server.h" |
Huadong Liu | f2a2ce0 | 2013-01-30 13:22:24 +0100 | [diff] [blame] | 26 | #include "idletime.h" |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 27 | |
Cigy Cyriac | bf2e821 | 2010-08-10 19:51:11 -0400 | [diff] [blame] | 28 | #include "lib/getopt.h" |
Jens Axboe | e25b6d5 | 2013-04-05 14:44:51 +0200 | [diff] [blame] | 29 | #include "lib/strcasestr.h" |
Cigy Cyriac | bf2e821 | 2010-08-10 19:51:11 -0400 | [diff] [blame] | 30 | |
Jens Axboe | 3d43382 | 2012-03-21 22:25:22 +0100 | [diff] [blame] | 31 | const char fio_version_string[] = FIO_VERSION; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 32 | |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 33 | #define FIO_RANDSEED (0xb1899bedUL) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 34 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 35 | static char **ini_file; |
Jens Axboe | fca7035 | 2011-07-06 20:12:54 +0200 | [diff] [blame] | 36 | static int max_jobs = FIO_MAX_JOBS; |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 37 | static int dump_cmdline; |
Jens Axboe | 8c02937 | 2011-10-05 09:54:30 +0200 | [diff] [blame] | 38 | static int def_timeout; |
Jens Axboe | 111e032 | 2013-03-07 11:31:20 +0100 | [diff] [blame] | 39 | static int parse_only; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 40 | |
Jens Axboe | be4ecfd | 2008-12-08 14:10:52 +0100 | [diff] [blame] | 41 | static struct thread_data def_thread; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 42 | struct thread_data *threads = NULL; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 43 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 44 | int exitall_on_terminate = 0; |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 45 | int output_format = FIO_OUTPUT_NORMAL; |
Christian Ehrhardt | 2b8c71b | 2014-02-20 14:20:04 +0100 | [diff] [blame] | 46 | int append_terse_output = 0; |
Jens Axboe | 5be4c94 | 2013-02-11 16:33:25 +0100 | [diff] [blame] | 47 | int eta_print = FIO_ETA_AUTO; |
Jens Axboe | e382e66 | 2013-02-22 20:48:56 +0100 | [diff] [blame] | 48 | int eta_new_line = 0; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 49 | FILE *f_out = NULL; |
| 50 | FILE *f_err = NULL; |
Jens Axboe | ad0a273 | 2011-03-11 10:16:17 +0100 | [diff] [blame] | 51 | char **job_sections = NULL; |
| 52 | int nr_job_sections = 0; |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 53 | char *exec_profile = NULL; |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 54 | int warnings_fatal = 0; |
Jens Axboe | 4d65865 | 2011-10-17 15:05:47 +0200 | [diff] [blame] | 55 | int terse_version = 3; |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 56 | int is_backend = 0; |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 57 | int nr_clients = 0; |
Jens Axboe | e46d809 | 2011-10-03 09:11:02 +0200 | [diff] [blame] | 58 | int log_syslog = 0; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 59 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 60 | int write_bw_log = 0; |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 61 | int read_only = 0; |
Jens Axboe | 0646490 | 2013-04-24 20:38:54 -0600 | [diff] [blame] | 62 | int status_interval = 0; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 63 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 64 | static int write_lat_log; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 65 | |
| 66 | static int prev_group_jobs; |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 67 | |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 68 | unsigned long fio_debug = 0; |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 69 | unsigned int fio_debug_jobno = -1; |
| 70 | unsigned int *fio_debug_jobp = NULL; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 71 | |
Jens Axboe | 4c6107f | 2011-01-18 05:22:22 -0700 | [diff] [blame] | 72 | static char cmd_optstr[256]; |
Jens Axboe | 085399d | 2011-10-06 09:01:22 +0200 | [diff] [blame] | 73 | static int did_arg; |
Jens Axboe | 4c6107f | 2011-01-18 05:22:22 -0700 | [diff] [blame] | 74 | |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 75 | #define FIO_CLIENT_FLAG (1 << 16) |
| 76 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 77 | /* |
| 78 | * Command line options. These will contain the above, plus a few |
| 79 | * extra that only pertain to fio itself and not jobs. |
| 80 | */ |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 81 | static struct option l_opts[FIO_NR_OPTIONS] = { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 82 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 83 | .name = (char *) "output", |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 84 | .has_arg = required_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 85 | .val = 'o' | FIO_CLIENT_FLAG, |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 86 | }, |
| 87 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 88 | .name = (char *) "timeout", |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 89 | .has_arg = required_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 90 | .val = 't' | FIO_CLIENT_FLAG, |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 91 | }, |
| 92 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 93 | .name = (char *) "latency-log", |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 94 | .has_arg = required_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 95 | .val = 'l' | FIO_CLIENT_FLAG, |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 96 | }, |
| 97 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 98 | .name = (char *) "bandwidth-log", |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 99 | .has_arg = required_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 100 | .val = 'b' | FIO_CLIENT_FLAG, |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 101 | }, |
| 102 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 103 | .name = (char *) "minimal", |
Stefan Hajnoczi | c4ec0a1 | 2014-02-04 14:27:10 +0100 | [diff] [blame] | 104 | .has_arg = no_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 105 | .val = 'm' | FIO_CLIENT_FLAG, |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 106 | }, |
| 107 | { |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 108 | .name = (char *) "output-format", |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 109 | .has_arg = optional_argument, |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 110 | .val = 'F' | FIO_CLIENT_FLAG, |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 111 | }, |
| 112 | { |
Christian Ehrhardt | 2b8c71b | 2014-02-20 14:20:04 +0100 | [diff] [blame] | 113 | .name = (char *) "append-terse", |
| 114 | .has_arg = optional_argument, |
| 115 | .val = 'f', |
| 116 | }, |
| 117 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 118 | .name = (char *) "version", |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 119 | .has_arg = no_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 120 | .val = 'v' | FIO_CLIENT_FLAG, |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 121 | }, |
| 122 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 123 | .name = (char *) "help", |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 124 | .has_arg = no_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 125 | .val = 'h' | FIO_CLIENT_FLAG, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 126 | }, |
| 127 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 128 | .name = (char *) "cmdhelp", |
Jens Axboe | 320beef | 2007-03-01 10:44:12 +0100 | [diff] [blame] | 129 | .has_arg = optional_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 130 | .val = 'c' | FIO_CLIENT_FLAG, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 131 | }, |
| 132 | { |
Jens Axboe | 0646490 | 2013-04-24 20:38:54 -0600 | [diff] [blame] | 133 | .name = (char *) "enghelp", |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 134 | .has_arg = optional_argument, |
Jens Axboe | 0646490 | 2013-04-24 20:38:54 -0600 | [diff] [blame] | 135 | .val = 'i' | FIO_CLIENT_FLAG, |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 136 | }, |
| 137 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 138 | .name = (char *) "showcmd", |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 139 | .has_arg = no_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 140 | .val = 's' | FIO_CLIENT_FLAG, |
Jens Axboe | 724e443 | 2007-09-11 20:02:05 +0200 | [diff] [blame] | 141 | }, |
| 142 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 143 | .name = (char *) "readonly", |
Jens Axboe | 724e443 | 2007-09-11 20:02:05 +0200 | [diff] [blame] | 144 | .has_arg = no_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 145 | .val = 'r' | FIO_CLIENT_FLAG, |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 146 | }, |
| 147 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 148 | .name = (char *) "eta", |
Aaron Carroll | e592a06 | 2007-09-14 09:49:41 +0200 | [diff] [blame] | 149 | .has_arg = required_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 150 | .val = 'e' | FIO_CLIENT_FLAG, |
Aaron Carroll | e592a06 | 2007-09-14 09:49:41 +0200 | [diff] [blame] | 151 | }, |
| 152 | { |
Jens Axboe | e382e66 | 2013-02-22 20:48:56 +0100 | [diff] [blame] | 153 | .name = (char *) "eta-newline", |
| 154 | .has_arg = required_argument, |
| 155 | .val = 'E' | FIO_CLIENT_FLAG, |
| 156 | }, |
| 157 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 158 | .name = (char *) "debug", |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 159 | .has_arg = required_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 160 | .val = 'd' | FIO_CLIENT_FLAG, |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 161 | }, |
| 162 | { |
Jens Axboe | 111e032 | 2013-03-07 11:31:20 +0100 | [diff] [blame] | 163 | .name = (char *) "parse-only", |
| 164 | .has_arg = no_argument, |
| 165 | .val = 'P' | FIO_CLIENT_FLAG, |
| 166 | }, |
| 167 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 168 | .name = (char *) "section", |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 169 | .has_arg = required_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 170 | .val = 'x' | FIO_CLIENT_FLAG, |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 171 | }, |
| 172 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 173 | .name = (char *) "alloc-size", |
Jens Axboe | 2b386d2 | 2008-03-26 10:32:57 +0100 | [diff] [blame] | 174 | .has_arg = required_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 175 | .val = 'a' | FIO_CLIENT_FLAG, |
Jens Axboe | 2b386d2 | 2008-03-26 10:32:57 +0100 | [diff] [blame] | 176 | }, |
| 177 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 178 | .name = (char *) "profile", |
Jens Axboe | 9ac8a79 | 2009-11-13 21:23:07 +0100 | [diff] [blame] | 179 | .has_arg = required_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 180 | .val = 'p' | FIO_CLIENT_FLAG, |
Jens Axboe | 9ac8a79 | 2009-11-13 21:23:07 +0100 | [diff] [blame] | 181 | }, |
| 182 | { |
Jens Axboe | 08d2a19 | 2011-05-11 13:28:30 +0200 | [diff] [blame] | 183 | .name = (char *) "warnings-fatal", |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 184 | .has_arg = no_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 185 | .val = 'w' | FIO_CLIENT_FLAG, |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 186 | }, |
| 187 | { |
Jens Axboe | fca7035 | 2011-07-06 20:12:54 +0200 | [diff] [blame] | 188 | .name = (char *) "max-jobs", |
| 189 | .has_arg = required_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 190 | .val = 'j' | FIO_CLIENT_FLAG, |
Jens Axboe | fca7035 | 2011-07-06 20:12:54 +0200 | [diff] [blame] | 191 | }, |
| 192 | { |
Jens Axboe | f57a9c5 | 2011-09-09 21:01:37 +0200 | [diff] [blame] | 193 | .name = (char *) "terse-version", |
| 194 | .has_arg = required_argument, |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 195 | .val = 'V' | FIO_CLIENT_FLAG, |
Jens Axboe | f57a9c5 | 2011-09-09 21:01:37 +0200 | [diff] [blame] | 196 | }, |
| 197 | { |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 198 | .name = (char *) "server", |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 199 | .has_arg = optional_argument, |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 200 | .val = 'S', |
| 201 | }, |
Jens Axboe | e46d809 | 2011-10-03 09:11:02 +0200 | [diff] [blame] | 202 | { .name = (char *) "daemonize", |
Jens Axboe | 402668f | 2011-10-10 15:28:58 +0200 | [diff] [blame] | 203 | .has_arg = required_argument, |
Jens Axboe | e46d809 | 2011-10-03 09:11:02 +0200 | [diff] [blame] | 204 | .val = 'D', |
| 205 | }, |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 206 | { |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 207 | .name = (char *) "client", |
| 208 | .has_arg = required_argument, |
| 209 | .val = 'C', |
| 210 | }, |
| 211 | { |
Jens Axboe | 7d11f87 | 2012-12-17 12:03:29 +0100 | [diff] [blame] | 212 | .name = (char *) "cpuclock-test", |
| 213 | .has_arg = no_argument, |
| 214 | .val = 'T', |
| 215 | }, |
| 216 | { |
Jens Axboe | fec0f21 | 2014-02-07 14:39:33 -0700 | [diff] [blame] | 217 | .name = (char *) "crctest", |
| 218 | .has_arg = optional_argument, |
| 219 | .val = 'G', |
| 220 | }, |
| 221 | { |
Huadong Liu | f2a2ce0 | 2013-01-30 13:22:24 +0100 | [diff] [blame] | 222 | .name = (char *) "idle-prof", |
| 223 | .has_arg = required_argument, |
| 224 | .val = 'I', |
| 225 | }, |
| 226 | { |
Jens Axboe | 0646490 | 2013-04-24 20:38:54 -0600 | [diff] [blame] | 227 | .name = (char *) "status-interval", |
| 228 | .has_arg = required_argument, |
| 229 | .val = 'L', |
| 230 | }, |
| 231 | { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 232 | .name = NULL, |
| 233 | }, |
| 234 | }; |
| 235 | |
Jens Axboe | 2bb3f0a | 2012-03-28 12:22:40 +0200 | [diff] [blame] | 236 | void free_threads_shm(void) |
Jens Axboe | 9d9eb2e | 2011-10-03 12:01:42 +0200 | [diff] [blame] | 237 | { |
| 238 | struct shmid_ds sbuf; |
| 239 | |
| 240 | if (threads) { |
| 241 | void *tp = threads; |
| 242 | |
| 243 | threads = NULL; |
Jens Axboe | 2bb3f0a | 2012-03-28 12:22:40 +0200 | [diff] [blame] | 244 | shmdt(tp); |
| 245 | shmctl(shm_id, IPC_RMID, &sbuf); |
| 246 | shm_id = -1; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | void free_shm(void) |
| 251 | { |
| 252 | if (threads) { |
Jens Axboe | 9d9eb2e | 2011-10-03 12:01:42 +0200 | [diff] [blame] | 253 | file_hash_exit(); |
Dan Ehrenberg | 9e684a4 | 2012-02-20 11:05:14 +0100 | [diff] [blame] | 254 | flow_exit(); |
Jens Axboe | 9d9eb2e | 2011-10-03 12:01:42 +0200 | [diff] [blame] | 255 | fio_debug_jobp = NULL; |
Jens Axboe | 2bb3f0a | 2012-03-28 12:22:40 +0200 | [diff] [blame] | 256 | free_threads_shm(); |
Jens Axboe | 9d9eb2e | 2011-10-03 12:01:42 +0200 | [diff] [blame] | 257 | } |
| 258 | |
Jens Axboe | eb0c74a | 2014-02-11 10:33:06 -0700 | [diff] [blame] | 259 | options_free(fio_options, &def_thread); |
Jens Axboe | 9d9eb2e | 2011-10-03 12:01:42 +0200 | [diff] [blame] | 260 | scleanup(); |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * The thread area is shared between the main process and the job |
| 265 | * threads/processes. So setup a shared memory segment that will hold |
| 266 | * all the job info. We use the end of the region for keeping track of |
| 267 | * open files across jobs, for file sharing. |
| 268 | */ |
| 269 | static int setup_thread_area(void) |
| 270 | { |
| 271 | void *hash; |
| 272 | |
| 273 | if (threads) |
| 274 | return 0; |
| 275 | |
| 276 | /* |
| 277 | * 1024 is too much on some machines, scale max_jobs if |
| 278 | * we get a failure that looks like too large a shm segment |
| 279 | */ |
| 280 | do { |
| 281 | size_t size = max_jobs * sizeof(struct thread_data); |
| 282 | |
| 283 | size += file_hash_size; |
| 284 | size += sizeof(unsigned int); |
| 285 | |
| 286 | shm_id = shmget(0, size, IPC_CREAT | 0600); |
| 287 | if (shm_id != -1) |
| 288 | break; |
Jens Axboe | f0c77f0 | 2012-09-21 15:05:45 +0200 | [diff] [blame] | 289 | if (errno != EINVAL && errno != ENOMEM && errno != ENOSPC) { |
Jens Axboe | 9d9eb2e | 2011-10-03 12:01:42 +0200 | [diff] [blame] | 290 | perror("shmget"); |
| 291 | break; |
| 292 | } |
| 293 | |
| 294 | max_jobs >>= 1; |
| 295 | } while (max_jobs); |
| 296 | |
| 297 | if (shm_id == -1) |
| 298 | return 1; |
| 299 | |
| 300 | threads = shmat(shm_id, NULL, 0); |
| 301 | if (threads == (void *) -1) { |
| 302 | perror("shmat"); |
| 303 | return 1; |
| 304 | } |
| 305 | |
| 306 | memset(threads, 0, max_jobs * sizeof(struct thread_data)); |
| 307 | hash = (void *) threads + max_jobs * sizeof(struct thread_data); |
| 308 | fio_debug_jobp = (void *) hash + file_hash_size; |
| 309 | *fio_debug_jobp = -1; |
| 310 | file_hash_init(hash); |
Dan Ehrenberg | 9e684a4 | 2012-02-20 11:05:14 +0100 | [diff] [blame] | 311 | |
| 312 | flow_init(); |
| 313 | |
Jens Axboe | 9d9eb2e | 2011-10-03 12:01:42 +0200 | [diff] [blame] | 314 | return 0; |
| 315 | } |
| 316 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 317 | /* |
| 318 | * Return a free job structure. |
| 319 | */ |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 320 | static struct thread_data *get_new_job(int global, struct thread_data *parent, |
| 321 | int preserve_eo) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 322 | { |
| 323 | struct thread_data *td; |
| 324 | |
| 325 | if (global) |
| 326 | return &def_thread; |
Jens Axboe | 9d9eb2e | 2011-10-03 12:01:42 +0200 | [diff] [blame] | 327 | if (setup_thread_area()) { |
| 328 | log_err("error: failed to setup shm segment\n"); |
| 329 | return NULL; |
| 330 | } |
Bruce Cran | e61f1ec | 2011-01-14 18:30:26 +0100 | [diff] [blame] | 331 | if (thread_number >= max_jobs) { |
| 332 | log_err("error: maximum number of jobs (%d) reached.\n", |
| 333 | max_jobs); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 334 | return NULL; |
Bruce Cran | e61f1ec | 2011-01-14 18:30:26 +0100 | [diff] [blame] | 335 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 336 | |
| 337 | td = &threads[thread_number++]; |
Jens Axboe | ddaeaa5 | 2006-06-08 11:00:58 +0200 | [diff] [blame] | 338 | *td = *parent; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 339 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 340 | td->io_ops = NULL; |
| 341 | if (!preserve_eo) |
| 342 | td->eo = NULL; |
| 343 | |
Jens Axboe | e0b0d89 | 2009-12-08 10:10:14 +0100 | [diff] [blame] | 344 | td->o.uid = td->o.gid = -1U; |
| 345 | |
Jens Axboe | cade3ef | 2007-03-23 15:29:45 +0100 | [diff] [blame] | 346 | dup_files(td, parent); |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 347 | fio_options_mem_dupe(td); |
Jens Axboe | cade3ef | 2007-03-23 15:29:45 +0100 | [diff] [blame] | 348 | |
Jens Axboe | 15dc193 | 2010-03-05 10:59:06 +0100 | [diff] [blame] | 349 | profile_add_hooks(td); |
| 350 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 351 | td->thread_number = thread_number; |
Jens Axboe | 108fea7 | 2012-11-14 13:09:45 -0700 | [diff] [blame] | 352 | |
| 353 | if (!parent || !parent->o.group_reporting) |
| 354 | stat_number++; |
| 355 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 356 | return td; |
| 357 | } |
| 358 | |
| 359 | static void put_job(struct thread_data *td) |
| 360 | { |
Jens Axboe | 549577a | 2006-10-30 12:23:41 +0100 | [diff] [blame] | 361 | if (td == &def_thread) |
| 362 | return; |
Bruce Cran | 84dd188 | 2011-05-05 08:14:09 -0600 | [diff] [blame] | 363 | |
Jens Axboe | 58c55ba | 2010-03-09 12:20:08 +0100 | [diff] [blame] | 364 | profile_td_exit(td); |
Dan Ehrenberg | 9e684a4 | 2012-02-20 11:05:14 +0100 | [diff] [blame] | 365 | flow_exit_job(td); |
Jens Axboe | 549577a | 2006-10-30 12:23:41 +0100 | [diff] [blame] | 366 | |
Jens Axboe | 16edf25 | 2007-02-10 14:59:22 +0100 | [diff] [blame] | 367 | if (td->error) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 368 | log_info("fio: %s\n", td->verror); |
Jens Axboe | 16edf25 | 2007-02-10 14:59:22 +0100 | [diff] [blame] | 369 | |
Jens Axboe | 7e356b2 | 2011-10-14 10:55:16 +0200 | [diff] [blame] | 370 | fio_options_free(td); |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 371 | if (td->io_ops) |
| 372 | free_ioengine(td); |
Jens Axboe | 7e356b2 | 2011-10-14 10:55:16 +0200 | [diff] [blame] | 373 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 374 | memset(&threads[td->thread_number - 1], 0, sizeof(*td)); |
| 375 | thread_number--; |
| 376 | } |
| 377 | |
Jens Axboe | 581e714 | 2009-06-09 12:47:16 +0200 | [diff] [blame] | 378 | static int __setup_rate(struct thread_data *td, enum fio_ddir ddir) |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 379 | { |
Jens Axboe | 581e714 | 2009-06-09 12:47:16 +0200 | [diff] [blame] | 380 | unsigned int bs = td->o.min_bs[ddir]; |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 381 | |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 382 | assert(ddir_rw(ddir)); |
| 383 | |
Radha Ramachandran | ba3e4e0 | 2009-12-09 22:31:44 +0100 | [diff] [blame] | 384 | if (td->o.rate[ddir]) |
Steven Lang | 1b8dbf2 | 2011-11-09 13:48:01 +0100 | [diff] [blame] | 385 | td->rate_bps[ddir] = td->o.rate[ddir]; |
Radha Ramachandran | ba3e4e0 | 2009-12-09 22:31:44 +0100 | [diff] [blame] | 386 | else |
Steven Lang | 1b8dbf2 | 2011-11-09 13:48:01 +0100 | [diff] [blame] | 387 | td->rate_bps[ddir] = td->o.rate_iops[ddir] * bs; |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 388 | |
Steven Lang | 1b8dbf2 | 2011-11-09 13:48:01 +0100 | [diff] [blame] | 389 | if (!td->rate_bps[ddir]) { |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 390 | log_err("rate lower than supported\n"); |
| 391 | return -1; |
| 392 | } |
| 393 | |
Jens Axboe | 581e714 | 2009-06-09 12:47:16 +0200 | [diff] [blame] | 394 | td->rate_pending_usleep[ddir] = 0; |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
Jens Axboe | 581e714 | 2009-06-09 12:47:16 +0200 | [diff] [blame] | 398 | static int setup_rate(struct thread_data *td) |
| 399 | { |
| 400 | int ret = 0; |
| 401 | |
| 402 | if (td->o.rate[DDIR_READ] || td->o.rate_iops[DDIR_READ]) |
| 403 | ret = __setup_rate(td, DDIR_READ); |
| 404 | if (td->o.rate[DDIR_WRITE] || td->o.rate_iops[DDIR_WRITE]) |
| 405 | ret |= __setup_rate(td, DDIR_WRITE); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 406 | if (td->o.rate[DDIR_TRIM] || td->o.rate_iops[DDIR_TRIM]) |
| 407 | ret |= __setup_rate(td, DDIR_TRIM); |
Jens Axboe | 581e714 | 2009-06-09 12:47:16 +0200 | [diff] [blame] | 408 | |
| 409 | return ret; |
| 410 | } |
| 411 | |
Jens Axboe | 8347239 | 2009-02-19 21:32:12 +0100 | [diff] [blame] | 412 | static int fixed_block_size(struct thread_options *o) |
| 413 | { |
| 414 | return o->min_bs[DDIR_READ] == o->max_bs[DDIR_READ] && |
| 415 | o->min_bs[DDIR_WRITE] == o->max_bs[DDIR_WRITE] && |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 416 | o->min_bs[DDIR_TRIM] == o->max_bs[DDIR_TRIM] && |
| 417 | o->min_bs[DDIR_READ] == o->min_bs[DDIR_WRITE] && |
| 418 | o->min_bs[DDIR_READ] == o->min_bs[DDIR_TRIM]; |
Jens Axboe | 8347239 | 2009-02-19 21:32:12 +0100 | [diff] [blame] | 419 | } |
| 420 | |
Christian Ehrhardt | 23ed19b | 2014-02-20 09:07:02 -0800 | [diff] [blame] | 421 | |
| 422 | static unsigned long long get_rand_start_delay(struct thread_data *td) |
| 423 | { |
| 424 | unsigned long long delayrange; |
| 425 | unsigned long r; |
| 426 | |
| 427 | delayrange = td->o.start_delay_high - td->o.start_delay; |
| 428 | |
| 429 | if (td->o.use_os_rand) { |
| 430 | r = os_random_long(&td->delay_state); |
| 431 | delayrange = (unsigned long long) ((double) delayrange * (r / (OS_RAND_MAX + 1.0))); |
| 432 | } else { |
| 433 | r = __rand(&td->__delay_state); |
| 434 | delayrange = (unsigned long long) ((double) delayrange * (r / (FRAND_MAX + 1.0))); |
| 435 | } |
| 436 | |
| 437 | delayrange += td->o.start_delay; |
| 438 | return delayrange; |
| 439 | } |
| 440 | |
Jens Axboe | dad915e | 2006-10-27 11:10:18 +0200 | [diff] [blame] | 441 | /* |
| 442 | * Lazy way of fixing up options that depend on each other. We could also |
| 443 | * define option callback handlers, but this is easier. |
| 444 | */ |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 445 | static int fixup_options(struct thread_data *td) |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 446 | { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 447 | struct thread_options *o = &td->o; |
Jens Axboe | eefd98b | 2013-07-25 12:30:06 -0600 | [diff] [blame] | 448 | int ret = 0; |
Jens Axboe | dad915e | 2006-10-27 11:10:18 +0200 | [diff] [blame] | 449 | |
Jens Axboe | f356d01 | 2009-01-05 09:56:29 +0100 | [diff] [blame] | 450 | #ifndef FIO_HAVE_PSHARED_MUTEX |
Jens Axboe | 9bbf57c | 2010-03-18 20:45:43 +0100 | [diff] [blame] | 451 | if (!o->use_thread) { |
Jens Axboe | f356d01 | 2009-01-05 09:56:29 +0100 | [diff] [blame] | 452 | log_info("fio: this platform does not support process shared" |
| 453 | " mutexes, forcing use of threads. Use the 'thread'" |
| 454 | " option to get rid of this warning.\n"); |
Jens Axboe | 9bbf57c | 2010-03-18 20:45:43 +0100 | [diff] [blame] | 455 | o->use_thread = 1; |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 456 | ret = warnings_fatal; |
Jens Axboe | f356d01 | 2009-01-05 09:56:29 +0100 | [diff] [blame] | 457 | } |
| 458 | #endif |
| 459 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 460 | if (o->write_iolog_file && o->read_iolog_file) { |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 461 | log_err("fio: read iolog overrides write_iolog\n"); |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 462 | free(o->write_iolog_file); |
| 463 | o->write_iolog_file = NULL; |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 464 | ret = warnings_fatal; |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 465 | } |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 466 | |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 467 | /* |
Steven Noonan | ed33585 | 2012-01-31 13:58:00 +0100 | [diff] [blame] | 468 | * only really works with 1 file |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 469 | */ |
Jens Axboe | 627aa1a | 2013-02-07 13:06:18 +0100 | [diff] [blame] | 470 | if (o->zone_size && o->open_files > 1) |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 471 | o->zone_size = 0; |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 472 | |
| 473 | /* |
Steven Noonan | ed33585 | 2012-01-31 13:58:00 +0100 | [diff] [blame] | 474 | * If zone_range isn't specified, backward compatibility dictates it |
| 475 | * should be made equal to zone_size. |
| 476 | */ |
| 477 | if (o->zone_size && !o->zone_range) |
| 478 | o->zone_range = o->zone_size; |
| 479 | |
| 480 | /* |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 481 | * Reads can do overwrites, we always need to pre-create the file |
| 482 | */ |
| 483 | if (td_read(td) || td_rw(td)) |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 484 | o->overwrite = 1; |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 485 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 486 | if (!o->min_bs[DDIR_READ]) |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 487 | o->min_bs[DDIR_READ] = o->bs[DDIR_READ]; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 488 | if (!o->max_bs[DDIR_READ]) |
| 489 | o->max_bs[DDIR_READ] = o->bs[DDIR_READ]; |
| 490 | if (!o->min_bs[DDIR_WRITE]) |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 491 | o->min_bs[DDIR_WRITE] = o->bs[DDIR_WRITE]; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 492 | if (!o->max_bs[DDIR_WRITE]) |
| 493 | o->max_bs[DDIR_WRITE] = o->bs[DDIR_WRITE]; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 494 | if (!o->min_bs[DDIR_TRIM]) |
| 495 | o->min_bs[DDIR_TRIM] = o->bs[DDIR_TRIM]; |
| 496 | if (!o->max_bs[DDIR_TRIM]) |
| 497 | o->max_bs[DDIR_TRIM] = o->bs[DDIR_TRIM]; |
| 498 | |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 499 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 500 | o->rw_min_bs = min(o->min_bs[DDIR_READ], o->min_bs[DDIR_WRITE]); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 501 | o->rw_min_bs = min(o->min_bs[DDIR_TRIM], o->rw_min_bs); |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 502 | |
Jens Axboe | 2b7a01d | 2009-03-11 11:00:13 +0100 | [diff] [blame] | 503 | /* |
| 504 | * For random IO, allow blockalign offset other than min_bs. |
| 505 | */ |
| 506 | if (!o->ba[DDIR_READ] || !td_random(td)) |
| 507 | o->ba[DDIR_READ] = o->min_bs[DDIR_READ]; |
| 508 | if (!o->ba[DDIR_WRITE] || !td_random(td)) |
| 509 | o->ba[DDIR_WRITE] = o->min_bs[DDIR_WRITE]; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 510 | if (!o->ba[DDIR_TRIM] || !td_random(td)) |
| 511 | o->ba[DDIR_TRIM] = o->min_bs[DDIR_TRIM]; |
Jens Axboe | 2b7a01d | 2009-03-11 11:00:13 +0100 | [diff] [blame] | 512 | |
| 513 | if ((o->ba[DDIR_READ] != o->min_bs[DDIR_READ] || |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 514 | o->ba[DDIR_WRITE] != o->min_bs[DDIR_WRITE] || |
| 515 | o->ba[DDIR_TRIM] != o->min_bs[DDIR_TRIM]) && |
Jens Axboe | 9bbf57c | 2010-03-18 20:45:43 +0100 | [diff] [blame] | 516 | !o->norandommap) { |
Jens Axboe | 2b7a01d | 2009-03-11 11:00:13 +0100 | [diff] [blame] | 517 | log_err("fio: Any use of blockalign= turns off randommap\n"); |
Jens Axboe | 9bbf57c | 2010-03-18 20:45:43 +0100 | [diff] [blame] | 518 | o->norandommap = 1; |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 519 | ret = warnings_fatal; |
Jens Axboe | 2b7a01d | 2009-03-11 11:00:13 +0100 | [diff] [blame] | 520 | } |
| 521 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 522 | if (!o->file_size_high) |
| 523 | o->file_size_high = o->file_size_low; |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 524 | |
Christian Ehrhardt | 23ed19b | 2014-02-20 09:07:02 -0800 | [diff] [blame] | 525 | if (o->start_delay_high) |
| 526 | o->start_delay = get_rand_start_delay(td); |
| 527 | |
Jens Axboe | 8347239 | 2009-02-19 21:32:12 +0100 | [diff] [blame] | 528 | if (o->norandommap && o->verify != VERIFY_NONE |
| 529 | && !fixed_block_size(o)) { |
| 530 | log_err("fio: norandommap given for variable block sizes, " |
| 531 | "verify disabled\n"); |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 532 | o->verify = VERIFY_NONE; |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 533 | ret = warnings_fatal; |
Jens Axboe | bb8895e | 2006-10-30 15:14:48 +0100 | [diff] [blame] | 534 | } |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 535 | if (o->bs_unaligned && (o->odirect || td->io_ops->flags & FIO_RAWIO)) |
Jens Axboe | 690adba | 2006-10-30 15:25:09 +0100 | [diff] [blame] | 536 | log_err("fio: bs_unaligned may not work with raw io\n"); |
Jens Axboe | e0a2233 | 2006-12-20 12:54:25 +0100 | [diff] [blame] | 537 | |
| 538 | /* |
Jens Axboe | 48097d5 | 2007-02-17 06:30:44 +0100 | [diff] [blame] | 539 | * thinktime_spin must be less than thinktime |
| 540 | */ |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 541 | if (o->thinktime_spin > o->thinktime) |
| 542 | o->thinktime_spin = o->thinktime; |
Jens Axboe | e916b39 | 2007-02-20 14:37:26 +0100 | [diff] [blame] | 543 | |
| 544 | /* |
| 545 | * The low water mark cannot be bigger than the iodepth |
| 546 | */ |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 547 | if (o->iodepth_low > o->iodepth || !o->iodepth_low) |
| 548 | o->iodepth_low = o->iodepth; |
Jens Axboe | cb5ab51 | 2007-02-26 12:57:09 +0100 | [diff] [blame] | 549 | |
| 550 | /* |
| 551 | * If batch number isn't set, default to the same as iodepth |
| 552 | */ |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 553 | if (o->iodepth_batch > o->iodepth || !o->iodepth_batch) |
| 554 | o->iodepth_batch = o->iodepth; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 555 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 556 | if (o->nr_files > td->files_index) |
| 557 | o->nr_files = td->files_index; |
Jens Axboe | 9f9214f | 2007-03-13 14:02:16 +0100 | [diff] [blame] | 558 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 559 | if (o->open_files > o->nr_files || !o->open_files) |
| 560 | o->open_files = o->nr_files; |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 561 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 562 | if (((o->rate[DDIR_READ] + o->rate[DDIR_WRITE] + o->rate[DDIR_TRIM]) && |
| 563 | (o->rate_iops[DDIR_READ] + o->rate_iops[DDIR_WRITE] + o->rate_iops[DDIR_TRIM])) || |
| 564 | ((o->ratemin[DDIR_READ] + o->ratemin[DDIR_WRITE] + o->ratemin[DDIR_TRIM]) && |
| 565 | (o->rate_iops_min[DDIR_READ] + o->rate_iops_min[DDIR_WRITE] + o->rate_iops_min[DDIR_TRIM]))) { |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 566 | log_err("fio: rate and rate_iops are mutually exclusive\n"); |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 567 | ret = 1; |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 568 | } |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 569 | if ((o->rate[DDIR_READ] < o->ratemin[DDIR_READ]) || |
| 570 | (o->rate[DDIR_WRITE] < o->ratemin[DDIR_WRITE]) || |
| 571 | (o->rate[DDIR_TRIM] < o->ratemin[DDIR_TRIM]) || |
| 572 | (o->rate_iops[DDIR_READ] < o->rate_iops_min[DDIR_READ]) || |
| 573 | (o->rate_iops[DDIR_WRITE] < o->rate_iops_min[DDIR_WRITE]) || |
| 574 | (o->rate_iops[DDIR_TRIM] < o->rate_iops_min[DDIR_TRIM])) { |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 575 | log_err("fio: minimum rate exceeds rate\n"); |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 576 | ret = 1; |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 577 | } |
| 578 | |
Jens Axboe | cf4464c | 2007-04-17 20:14:42 +0200 | [diff] [blame] | 579 | if (!o->timeout && o->time_based) { |
| 580 | log_err("fio: time_based requires a runtime/timeout setting\n"); |
| 581 | o->time_based = 0; |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 582 | ret = warnings_fatal; |
Jens Axboe | cf4464c | 2007-04-17 20:14:42 +0200 | [diff] [blame] | 583 | } |
| 584 | |
Shawn Lewis | aa31f1f | 2008-01-11 09:45:11 +0100 | [diff] [blame] | 585 | if (o->fill_device && !o->size) |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 586 | o->size = -1ULL; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 587 | |
Jens Axboe | 9bbf57c | 2010-03-18 20:45:43 +0100 | [diff] [blame] | 588 | if (o->verify != VERIFY_NONE) { |
Jens Axboe | 996936f | 2011-01-18 05:41:39 -0700 | [diff] [blame] | 589 | if (td_write(td) && o->do_verify && o->numjobs > 1) { |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 590 | log_info("Multiple writers may overwrite blocks that " |
| 591 | "belong to other jobs. This can cause " |
| 592 | "verification failures.\n"); |
| 593 | ret = warnings_fatal; |
| 594 | } |
| 595 | |
Jens Axboe | 9bbf57c | 2010-03-18 20:45:43 +0100 | [diff] [blame] | 596 | o->refill_buffers = 1; |
Jens Axboe | 2f1b8e8 | 2010-06-18 09:22:56 +0200 | [diff] [blame] | 597 | if (o->max_bs[DDIR_WRITE] != o->min_bs[DDIR_WRITE] && |
| 598 | !o->verify_interval) |
| 599 | o->verify_interval = o->min_bs[DDIR_WRITE]; |
Jens Axboe | d990588 | 2010-03-18 20:43:00 +0100 | [diff] [blame] | 600 | } |
Jens Axboe | 41ccd84 | 2008-05-22 09:17:33 +0200 | [diff] [blame] | 601 | |
Jens Axboe | 9bbf57c | 2010-03-18 20:45:43 +0100 | [diff] [blame] | 602 | if (o->pre_read) { |
| 603 | o->invalidate_cache = 0; |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 604 | if (td->io_ops->flags & FIO_PIPEIO) { |
Jens Axboe | 9c0d224 | 2009-07-01 12:26:28 +0200 | [diff] [blame] | 605 | log_info("fio: cannot pre-read files with an IO engine" |
| 606 | " that isn't seekable. Pre-read disabled.\n"); |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 607 | ret = warnings_fatal; |
| 608 | } |
Jens Axboe | 9c0d224 | 2009-07-01 12:26:28 +0200 | [diff] [blame] | 609 | } |
Jens Axboe | 34f1c04 | 2009-06-02 14:19:25 +0200 | [diff] [blame] | 610 | |
Steven Noonan | ad705bc | 2013-04-08 15:05:25 -0700 | [diff] [blame] | 611 | if (!o->unit_base) { |
| 612 | if (td->io_ops->flags & FIO_BIT_BASED) |
| 613 | o->unit_base = 1; |
| 614 | else |
| 615 | o->unit_base = 8; |
| 616 | } |
| 617 | |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 618 | #ifndef CONFIG_FDATASYNC |
Jens Axboe | 9bbf57c | 2010-03-18 20:45:43 +0100 | [diff] [blame] | 619 | if (o->fdatasync_blocks) { |
Joshua Aune | e72fa4d | 2010-02-11 00:59:18 -0700 | [diff] [blame] | 620 | log_info("fio: this platform does not support fdatasync()" |
| 621 | " falling back to using fsync(). Use the 'fsync'" |
| 622 | " option instead of 'fdatasync' to get rid of" |
| 623 | " this warning\n"); |
Jens Axboe | 9bbf57c | 2010-03-18 20:45:43 +0100 | [diff] [blame] | 624 | o->fsync_blocks = o->fdatasync_blocks; |
| 625 | o->fdatasync_blocks = 0; |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 626 | ret = warnings_fatal; |
Joshua Aune | e72fa4d | 2010-02-11 00:59:18 -0700 | [diff] [blame] | 627 | } |
| 628 | #endif |
| 629 | |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 630 | #ifdef WIN32 |
| 631 | /* |
| 632 | * Windows doesn't support O_DIRECT or O_SYNC with the _open interface, |
| 633 | * so fail if we're passed those flags |
| 634 | */ |
| 635 | if ((td->io_ops->flags & FIO_SYNCIO) && (td->o.odirect || td->o.sync_io)) { |
| 636 | log_err("fio: Windows does not support direct or non-buffered io with" |
| 637 | " the synchronous ioengines. Use the 'windowsaio' ioengine" |
| 638 | " with 'direct=1' and 'iodepth=1' instead.\n"); |
| 639 | ret = 1; |
| 640 | } |
| 641 | #endif |
| 642 | |
Jens Axboe | 811ac50 | 2012-03-02 22:23:36 +0100 | [diff] [blame] | 643 | /* |
| 644 | * For fully compressible data, just zero them at init time. |
| 645 | * It's faster than repeatedly filling it. |
| 646 | */ |
| 647 | if (td->o.compress_percentage == 100) { |
| 648 | td->o.zero_buffers = 1; |
| 649 | td->o.compress_percentage = 0; |
| 650 | } |
| 651 | |
Jens Axboe | 5881fda | 2012-11-15 15:21:23 -0700 | [diff] [blame] | 652 | /* |
| 653 | * Using a non-uniform random distribution excludes usage of |
| 654 | * a random map |
| 655 | */ |
| 656 | if (td->o.random_distribution != FIO_RAND_DIST_RANDOM) |
| 657 | td->o.norandommap = 1; |
| 658 | |
Jens Axboe | 8d916c9 | 2013-04-25 10:11:41 -0600 | [diff] [blame] | 659 | /* |
| 660 | * If size is set but less than the min block size, complain |
| 661 | */ |
| 662 | if (o->size && o->size < td_min_bs(td)) { |
| 663 | log_err("fio: size too small, must be larger than the IO size: %llu\n", (unsigned long long) o->size); |
| 664 | ret = 1; |
| 665 | } |
| 666 | |
Chris Mason | d01612f | 2013-11-15 15:52:58 -0700 | [diff] [blame] | 667 | /* |
| 668 | * O_ATOMIC implies O_DIRECT |
| 669 | */ |
| 670 | if (td->o.oatomic) |
| 671 | td->o.odirect = 1; |
| 672 | |
Jens Axboe | 04778ba | 2014-01-10 20:57:01 -0700 | [diff] [blame] | 673 | /* |
| 674 | * If randseed is set, that overrides randrepeat |
| 675 | */ |
| 676 | if (td->o.rand_seed) |
| 677 | td->o.rand_repeatable = 0; |
| 678 | |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 679 | return ret; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 680 | } |
| 681 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 682 | /* |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 683 | * This function leaks the buffer |
| 684 | */ |
Jens Axboe | 99d633a | 2012-03-15 15:55:04 +0100 | [diff] [blame] | 685 | char *fio_uint_to_kmg(unsigned int val) |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 686 | { |
| 687 | char *buf = malloc(32); |
Jens Axboe | f3502ba | 2007-02-14 01:27:09 +0100 | [diff] [blame] | 688 | char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 }; |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 689 | char *p = post; |
| 690 | |
Jens Axboe | 245142f | 2006-11-08 12:49:21 +0100 | [diff] [blame] | 691 | do { |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 692 | if (val & 1023) |
| 693 | break; |
| 694 | |
| 695 | val >>= 10; |
| 696 | p++; |
Jens Axboe | 245142f | 2006-11-08 12:49:21 +0100 | [diff] [blame] | 697 | } while (*p); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 698 | |
Ken Raeburn | 98ffb8f | 2013-01-30 22:31:09 +0100 | [diff] [blame] | 699 | snprintf(buf, 32, "%u%c", val, *p); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 700 | return buf; |
| 701 | } |
| 702 | |
Jens Axboe | 09629a9 | 2007-03-09 09:00:06 +0100 | [diff] [blame] | 703 | /* External engines are specified by "external:name.o") */ |
| 704 | static const char *get_engine_name(const char *str) |
| 705 | { |
| 706 | char *p = strstr(str, ":"); |
| 707 | |
| 708 | if (!p) |
| 709 | return str; |
| 710 | |
| 711 | p++; |
| 712 | strip_blank_front(&p); |
| 713 | strip_blank_end(p); |
| 714 | return p; |
| 715 | } |
| 716 | |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 717 | static int exists_and_not_file(const char *filename) |
| 718 | { |
| 719 | struct stat sb; |
| 720 | |
| 721 | if (lstat(filename, &sb) == -1) |
| 722 | return 0; |
| 723 | |
Bruce Cran | ecc314b | 2011-01-04 10:59:30 +0100 | [diff] [blame] | 724 | /* \\.\ is the device namespace in Windows, where every file |
| 725 | * is a device node */ |
| 726 | if (S_ISREG(sb.st_mode) && strncmp(filename, "\\\\.\\", 4) != 0) |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 727 | return 0; |
| 728 | |
| 729 | return 1; |
| 730 | } |
| 731 | |
Jens Axboe | 4c07ad8 | 2011-03-28 09:51:09 +0200 | [diff] [blame] | 732 | static void td_fill_rand_seeds_os(struct thread_data *td) |
Jens Axboe | 5bfc35d | 2009-04-07 13:28:12 +0200 | [diff] [blame] | 733 | { |
Jens Axboe | d24945f | 2012-12-04 13:10:29 +0100 | [diff] [blame] | 734 | os_random_seed(td->rand_seeds[FIO_RAND_BS_OFF], &td->bsrange_state); |
| 735 | os_random_seed(td->rand_seeds[FIO_RAND_VER_OFF], &td->verify_state); |
| 736 | os_random_seed(td->rand_seeds[FIO_RAND_MIX_OFF], &td->rwmix_state); |
Jens Axboe | 5bfc35d | 2009-04-07 13:28:12 +0200 | [diff] [blame] | 737 | |
| 738 | if (td->o.file_service_type == FIO_FSERVICE_RANDOM) |
Jens Axboe | d24945f | 2012-12-04 13:10:29 +0100 | [diff] [blame] | 739 | os_random_seed(td->rand_seeds[FIO_RAND_FILE_OFF], &td->next_file_state); |
Jens Axboe | 5bfc35d | 2009-04-07 13:28:12 +0200 | [diff] [blame] | 740 | |
Jens Axboe | d24945f | 2012-12-04 13:10:29 +0100 | [diff] [blame] | 741 | os_random_seed(td->rand_seeds[FIO_RAND_FILE_SIZE_OFF], &td->file_size_state); |
| 742 | os_random_seed(td->rand_seeds[FIO_RAND_TRIM_OFF], &td->trim_state); |
Christian Ehrhardt | 23ed19b | 2014-02-20 09:07:02 -0800 | [diff] [blame] | 743 | os_random_seed(td->rand_seeds[FIO_RAND_START_DELAY], &td->delay_state); |
Jens Axboe | 5bfc35d | 2009-04-07 13:28:12 +0200 | [diff] [blame] | 744 | |
| 745 | if (!td_random(td)) |
| 746 | return; |
| 747 | |
| 748 | if (td->o.rand_repeatable) |
Jens Axboe | d24945f | 2012-12-04 13:10:29 +0100 | [diff] [blame] | 749 | td->rand_seeds[FIO_RAND_BLOCK_OFF] = FIO_RANDSEED * td->thread_number; |
Jens Axboe | 5bfc35d | 2009-04-07 13:28:12 +0200 | [diff] [blame] | 750 | |
Jens Axboe | d24945f | 2012-12-04 13:10:29 +0100 | [diff] [blame] | 751 | os_random_seed(td->rand_seeds[FIO_RAND_BLOCK_OFF], &td->random_state); |
Jens Axboe | d947227 | 2013-07-25 10:20:45 -0600 | [diff] [blame] | 752 | |
| 753 | os_random_seed(td->rand_seeds[FIO_RAND_SEQ_RAND_READ_OFF], &td->seq_rand_state[DDIR_READ]); |
| 754 | os_random_seed(td->rand_seeds[FIO_RAND_SEQ_RAND_WRITE_OFF], &td->seq_rand_state[DDIR_WRITE]); |
| 755 | os_random_seed(td->rand_seeds[FIO_RAND_SEQ_RAND_TRIM_OFF], &td->seq_rand_state[DDIR_TRIM]); |
Jens Axboe | 4c07ad8 | 2011-03-28 09:51:09 +0200 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | static void td_fill_rand_seeds_internal(struct thread_data *td) |
| 759 | { |
Jens Axboe | d24945f | 2012-12-04 13:10:29 +0100 | [diff] [blame] | 760 | init_rand_seed(&td->__bsrange_state, td->rand_seeds[FIO_RAND_BS_OFF]); |
| 761 | init_rand_seed(&td->__verify_state, td->rand_seeds[FIO_RAND_VER_OFF]); |
| 762 | init_rand_seed(&td->__rwmix_state, td->rand_seeds[FIO_RAND_MIX_OFF]); |
Jens Axboe | 4c07ad8 | 2011-03-28 09:51:09 +0200 | [diff] [blame] | 763 | |
| 764 | if (td->o.file_service_type == FIO_FSERVICE_RANDOM) |
Jens Axboe | d24945f | 2012-12-04 13:10:29 +0100 | [diff] [blame] | 765 | init_rand_seed(&td->__next_file_state, td->rand_seeds[FIO_RAND_FILE_OFF]); |
Jens Axboe | 4c07ad8 | 2011-03-28 09:51:09 +0200 | [diff] [blame] | 766 | |
Jens Axboe | d24945f | 2012-12-04 13:10:29 +0100 | [diff] [blame] | 767 | init_rand_seed(&td->__file_size_state, td->rand_seeds[FIO_RAND_FILE_SIZE_OFF]); |
| 768 | init_rand_seed(&td->__trim_state, td->rand_seeds[FIO_RAND_TRIM_OFF]); |
Christian Ehrhardt | 23ed19b | 2014-02-20 09:07:02 -0800 | [diff] [blame] | 769 | init_rand_seed(&td->__delay_state, td->rand_seeds[FIO_RAND_START_DELAY]); |
Jens Axboe | 4c07ad8 | 2011-03-28 09:51:09 +0200 | [diff] [blame] | 770 | |
| 771 | if (!td_random(td)) |
| 772 | return; |
| 773 | |
| 774 | if (td->o.rand_repeatable) |
Jens Axboe | d24945f | 2012-12-04 13:10:29 +0100 | [diff] [blame] | 775 | td->rand_seeds[FIO_RAND_BLOCK_OFF] = FIO_RANDSEED * td->thread_number; |
Jens Axboe | 4c07ad8 | 2011-03-28 09:51:09 +0200 | [diff] [blame] | 776 | |
Jens Axboe | d24945f | 2012-12-04 13:10:29 +0100 | [diff] [blame] | 777 | init_rand_seed(&td->__random_state, td->rand_seeds[FIO_RAND_BLOCK_OFF]); |
Jens Axboe | d947227 | 2013-07-25 10:20:45 -0600 | [diff] [blame] | 778 | init_rand_seed(&td->__seq_rand_state[DDIR_READ], td->rand_seeds[FIO_RAND_SEQ_RAND_READ_OFF]); |
| 779 | init_rand_seed(&td->__seq_rand_state[DDIR_WRITE], td->rand_seeds[FIO_RAND_SEQ_RAND_WRITE_OFF]); |
| 780 | init_rand_seed(&td->__seq_rand_state[DDIR_TRIM], td->rand_seeds[FIO_RAND_SEQ_RAND_TRIM_OFF]); |
Jens Axboe | 5bfc35d | 2009-04-07 13:28:12 +0200 | [diff] [blame] | 781 | } |
| 782 | |
Jens Axboe | 4c07ad8 | 2011-03-28 09:51:09 +0200 | [diff] [blame] | 783 | void td_fill_rand_seeds(struct thread_data *td) |
| 784 | { |
Christian Ehrhardt | 56e2a5f | 2014-02-20 09:10:17 -0800 | [diff] [blame] | 785 | if (td->o.allrand_repeatable) { |
| 786 | for (int i = 0; i < FIO_RAND_NR_OFFS; i++) |
| 787 | td->rand_seeds[i] = FIO_RANDSEED * td->thread_number |
| 788 | + i; |
| 789 | } |
| 790 | |
Jens Axboe | 4c07ad8 | 2011-03-28 09:51:09 +0200 | [diff] [blame] | 791 | if (td->o.use_os_rand) |
| 792 | td_fill_rand_seeds_os(td); |
| 793 | else |
| 794 | td_fill_rand_seeds_internal(td); |
Jens Axboe | 3545a10 | 2011-08-31 15:20:15 -0600 | [diff] [blame] | 795 | |
Jens Axboe | d24945f | 2012-12-04 13:10:29 +0100 | [diff] [blame] | 796 | init_rand_seed(&td->buf_state, td->rand_seeds[FIO_RAND_BUF_OFF]); |
Jens Axboe | 4c07ad8 | 2011-03-28 09:51:09 +0200 | [diff] [blame] | 797 | } |
| 798 | |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 799 | /* |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 800 | * Initializes the ioengine configured for a job, if it has not been done so |
| 801 | * already. |
| 802 | */ |
| 803 | int ioengine_load(struct thread_data *td) |
| 804 | { |
| 805 | const char *engine; |
| 806 | |
| 807 | /* |
| 808 | * Engine has already been loaded. |
| 809 | */ |
| 810 | if (td->io_ops) |
| 811 | return 0; |
Jens Axboe | 6e5c4b8 | 2013-05-27 09:50:31 +0200 | [diff] [blame] | 812 | if (!td->o.ioengine) { |
| 813 | log_err("fio: internal fault, no IO engine specified\n"); |
| 814 | return 1; |
| 815 | } |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 816 | |
| 817 | engine = get_engine_name(td->o.ioengine); |
| 818 | td->io_ops = load_ioengine(td, engine); |
| 819 | if (!td->io_ops) { |
| 820 | log_err("fio: failed to load engine %s\n", engine); |
| 821 | return 1; |
| 822 | } |
| 823 | |
| 824 | if (td->io_ops->option_struct_size && td->io_ops->options) { |
| 825 | /* |
| 826 | * In cases where td->eo is set, clone it for a child thread. |
| 827 | * This requires that the parent thread has the same ioengine, |
| 828 | * but that requirement must be enforced by the code which |
| 829 | * cloned the thread. |
| 830 | */ |
| 831 | void *origeo = td->eo; |
| 832 | /* |
| 833 | * Otherwise use the default thread options. |
| 834 | */ |
| 835 | if (!origeo && td != &def_thread && def_thread.eo && |
| 836 | def_thread.io_ops->options == td->io_ops->options) |
| 837 | origeo = def_thread.eo; |
| 838 | |
| 839 | options_init(td->io_ops->options); |
| 840 | td->eo = malloc(td->io_ops->option_struct_size); |
| 841 | /* |
| 842 | * Use the default thread as an option template if this uses the |
| 843 | * same options structure and there are non-default options |
| 844 | * used. |
| 845 | */ |
| 846 | if (origeo) { |
| 847 | memcpy(td->eo, origeo, td->io_ops->option_struct_size); |
| 848 | options_mem_dupe(td->eo, td->io_ops->options); |
| 849 | } else { |
| 850 | memset(td->eo, 0, td->io_ops->option_struct_size); |
| 851 | fill_default_options(td->eo, td->io_ops->options); |
| 852 | } |
| 853 | *(struct thread_data **)td->eo = td; |
| 854 | } |
| 855 | |
| 856 | return 0; |
| 857 | } |
| 858 | |
Jens Axboe | d72be54 | 2012-11-30 19:37:46 +0100 | [diff] [blame] | 859 | static void init_flags(struct thread_data *td) |
| 860 | { |
| 861 | struct thread_options *o = &td->o; |
| 862 | |
| 863 | if (o->verify_backlog) |
| 864 | td->flags |= TD_F_VER_BACKLOG; |
| 865 | if (o->trim_backlog) |
| 866 | td->flags |= TD_F_TRIM_BACKLOG; |
| 867 | if (o->read_iolog_file) |
| 868 | td->flags |= TD_F_READ_IOLOG; |
| 869 | if (o->refill_buffers) |
| 870 | td->flags |= TD_F_REFILL_BUFFERS; |
Jens Axboe | bedc9dc | 2014-03-17 12:51:09 -0600 | [diff] [blame^] | 871 | if (o->scramble_buffers) |
Jens Axboe | d72be54 | 2012-11-30 19:37:46 +0100 | [diff] [blame] | 872 | td->flags |= TD_F_SCRAMBLE_BUFFERS; |
| 873 | if (o->verify != VERIFY_NONE) |
| 874 | td->flags |= TD_F_VER_NONE; |
| 875 | } |
| 876 | |
Jens Axboe | 9dbc7bf | 2013-01-23 09:26:53 -0700 | [diff] [blame] | 877 | static int setup_random_seeds(struct thread_data *td) |
| 878 | { |
| 879 | unsigned long seed; |
| 880 | unsigned int i; |
| 881 | |
Jens Axboe | 04778ba | 2014-01-10 20:57:01 -0700 | [diff] [blame] | 882 | if (!td->o.rand_repeatable && !td->o.rand_seed) |
Jens Axboe | 9dbc7bf | 2013-01-23 09:26:53 -0700 | [diff] [blame] | 883 | return init_random_state(td, td->rand_seeds, sizeof(td->rand_seeds)); |
| 884 | |
Jens Axboe | 04778ba | 2014-01-10 20:57:01 -0700 | [diff] [blame] | 885 | if (!td->o.rand_seed) |
| 886 | seed = 0x89; |
| 887 | else |
| 888 | seed = td->o.rand_seed; |
| 889 | |
| 890 | for (i = 0; i < 4; i++) |
Jens Axboe | 9dbc7bf | 2013-01-23 09:26:53 -0700 | [diff] [blame] | 891 | seed *= 0x9e370001UL; |
| 892 | |
| 893 | for (i = 0; i < FIO_RAND_NR_OFFS; i++) { |
| 894 | td->rand_seeds[i] = seed; |
| 895 | seed *= 0x9e370001UL; |
| 896 | } |
| 897 | |
| 898 | td_fill_rand_seeds(td); |
| 899 | return 0; |
| 900 | } |
| 901 | |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 902 | enum { |
| 903 | FPRE_NONE = 0, |
| 904 | FPRE_JOBNAME, |
| 905 | FPRE_JOBNUM, |
| 906 | FPRE_FILENUM |
| 907 | }; |
| 908 | |
| 909 | static struct fpre_keyword { |
| 910 | const char *keyword; |
| 911 | size_t strlen; |
| 912 | int key; |
| 913 | } fpre_keywords[] = { |
| 914 | { .keyword = "$jobname", .key = FPRE_JOBNAME, }, |
| 915 | { .keyword = "$jobnum", .key = FPRE_JOBNUM, }, |
| 916 | { .keyword = "$filenum", .key = FPRE_FILENUM, }, |
| 917 | { .keyword = NULL, }, |
| 918 | }; |
| 919 | |
| 920 | static char *make_filename(char *buf, struct thread_options *o, |
| 921 | const char *jobname, int jobnum, int filenum) |
| 922 | { |
| 923 | struct fpre_keyword *f; |
| 924 | char copy[PATH_MAX]; |
| 925 | |
| 926 | if (!o->filename_format || !strlen(o->filename_format)) { |
| 927 | sprintf(buf, "%s.%d.%d", jobname, jobnum, filenum); |
| 928 | return NULL; |
| 929 | } |
| 930 | |
| 931 | for (f = &fpre_keywords[0]; f->keyword; f++) |
| 932 | f->strlen = strlen(f->keyword); |
| 933 | |
| 934 | strcpy(buf, o->filename_format); |
| 935 | memset(copy, 0, sizeof(copy)); |
| 936 | for (f = &fpre_keywords[0]; f->keyword; f++) { |
| 937 | do { |
| 938 | size_t pre_len, post_start = 0; |
| 939 | char *str, *dst = copy; |
| 940 | |
Jens Axboe | e25b6d5 | 2013-04-05 14:44:51 +0200 | [diff] [blame] | 941 | str = strcasestr(buf, f->keyword); |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 942 | if (!str) |
| 943 | break; |
| 944 | |
| 945 | pre_len = str - buf; |
| 946 | if (strlen(str) != f->strlen) |
| 947 | post_start = pre_len + f->strlen; |
| 948 | |
| 949 | if (pre_len) { |
| 950 | strncpy(dst, buf, pre_len); |
| 951 | dst += pre_len; |
| 952 | } |
| 953 | |
| 954 | switch (f->key) { |
| 955 | case FPRE_JOBNAME: |
| 956 | dst += sprintf(dst, "%s", jobname); |
| 957 | break; |
| 958 | case FPRE_JOBNUM: |
| 959 | dst += sprintf(dst, "%d", jobnum); |
| 960 | break; |
| 961 | case FPRE_FILENUM: |
| 962 | dst += sprintf(dst, "%d", filenum); |
| 963 | break; |
| 964 | default: |
| 965 | assert(0); |
| 966 | break; |
| 967 | } |
| 968 | |
| 969 | if (post_start) |
| 970 | strcpy(dst, buf + post_start); |
| 971 | |
| 972 | strcpy(buf, copy); |
| 973 | } while (1); |
| 974 | } |
| 975 | |
| 976 | return buf; |
| 977 | } |
Jens Axboe | f9633d7 | 2013-09-06 09:59:56 -0600 | [diff] [blame] | 978 | |
| 979 | int parse_dryrun(void) |
| 980 | { |
| 981 | return dump_cmdline || parse_only; |
| 982 | } |
| 983 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 984 | /* |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 985 | * Adds a job to the list of things todo. Sanitizes the various options |
| 986 | * to make sure we don't have conflicts, and initializes various |
| 987 | * members of td. |
| 988 | */ |
Jens Axboe | b7cfb2e | 2012-03-12 07:47:27 +0100 | [diff] [blame] | 989 | static int add_job(struct thread_data *td, const char *jobname, int job_add_num, |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 990 | int recursed, int client_type) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 991 | { |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 992 | unsigned int i; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 993 | char fname[PATH_MAX]; |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 994 | int numjobs, file_alloced; |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 995 | struct thread_options *o = &td->o; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 996 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 997 | /* |
| 998 | * the def_thread is just for options, it's not a real job |
| 999 | */ |
| 1000 | if (td == &def_thread) |
| 1001 | return 0; |
| 1002 | |
Jens Axboe | d72be54 | 2012-11-30 19:37:46 +0100 | [diff] [blame] | 1003 | init_flags(td); |
| 1004 | |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 1005 | /* |
| 1006 | * if we are just dumping the output command line, don't add the job |
| 1007 | */ |
Jens Axboe | f9633d7 | 2013-09-06 09:59:56 -0600 | [diff] [blame] | 1008 | if (parse_dryrun()) { |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 1009 | put_job(td); |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 1013 | td->client_type = client_type; |
| 1014 | |
Jens Axboe | 58c55ba | 2010-03-09 12:20:08 +0100 | [diff] [blame] | 1015 | if (profile_td_init(td)) |
Jens Axboe | 6625155 | 2011-05-12 10:14:57 +0200 | [diff] [blame] | 1016 | goto err; |
Jens Axboe | 58c55ba | 2010-03-09 12:20:08 +0100 | [diff] [blame] | 1017 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1018 | if (ioengine_load(td)) |
Jens Axboe | 205927a | 2007-03-15 11:06:32 +0100 | [diff] [blame] | 1019 | goto err; |
Jens Axboe | df64119 | 2006-10-12 07:55:41 +0200 | [diff] [blame] | 1020 | |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 1021 | if (o->odirect) |
Jens Axboe | 690adba | 2006-10-30 15:25:09 +0100 | [diff] [blame] | 1022 | td->io_ops->flags |= FIO_RAWIO; |
| 1023 | |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 1024 | file_alloced = 0; |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 1025 | if (!o->filename && !td->files_index && !o->read_iolog_file) { |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 1026 | file_alloced = 1; |
Jens Axboe | 80be24f | 2007-03-12 11:01:25 +0100 | [diff] [blame] | 1027 | |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 1028 | if (o->nr_files == 1 && exists_and_not_file(jobname)) |
Jens Axboe | 5903e7b | 2014-02-26 13:42:13 -0800 | [diff] [blame] | 1029 | add_file(td, jobname, job_add_num, 0); |
Jens Axboe | 7b05a21 | 2007-03-13 11:17:07 +0100 | [diff] [blame] | 1030 | else { |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 1031 | for (i = 0; i < o->nr_files; i++) |
Jens Axboe | 5903e7b | 2014-02-26 13:42:13 -0800 | [diff] [blame] | 1032 | add_file(td, make_filename(fname, o, jobname, job_add_num, i), job_add_num, 0); |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 1033 | } |
Jens Axboe | 0af7b54 | 2006-02-17 10:10:12 +0100 | [diff] [blame] | 1034 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1035 | |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 1036 | if (fixup_options(td)) |
| 1037 | goto err; |
Jens Axboe | e0a2233 | 2006-12-20 12:54:25 +0100 | [diff] [blame] | 1038 | |
Dan Ehrenberg | 9e684a4 | 2012-02-20 11:05:14 +0100 | [diff] [blame] | 1039 | flow_init_job(td); |
| 1040 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1041 | /* |
| 1042 | * IO engines only need this for option callbacks, and the address may |
| 1043 | * change in subprocesses. |
| 1044 | */ |
| 1045 | if (td->eo) |
| 1046 | *(struct thread_data **)td->eo = NULL; |
| 1047 | |
Jens Axboe | 07eb79d | 2007-04-12 13:02:38 +0200 | [diff] [blame] | 1048 | if (td->io_ops->flags & FIO_DISKLESSIO) { |
| 1049 | struct fio_file *f; |
| 1050 | |
| 1051 | for_each_file(td, f, i) |
| 1052 | f->real_file_size = -1ULL; |
| 1053 | } |
| 1054 | |
Jens Axboe | 521da52 | 2012-08-02 11:21:36 +0200 | [diff] [blame] | 1055 | td->mutex = fio_mutex_init(FIO_MUTEX_LOCKED); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1056 | |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 1057 | td->ts.clat_percentiles = o->clat_percentiles; |
| 1058 | td->ts.percentile_precision = o->percentile_precision; |
| 1059 | memcpy(td->ts.percentile_list, o->percentile_list, sizeof(o->percentile_list)); |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 1060 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1061 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
| 1062 | td->ts.clat_stat[i].min_val = ULONG_MAX; |
| 1063 | td->ts.slat_stat[i].min_val = ULONG_MAX; |
| 1064 | td->ts.lat_stat[i].min_val = ULONG_MAX; |
| 1065 | td->ts.bw_stat[i].min_val = ULONG_MAX; |
| 1066 | } |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 1067 | td->ddir_seq_nr = o->ddir_seq_nr; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1068 | |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 1069 | if ((o->stonewall || o->new_group) && prev_group_jobs) { |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 1070 | prev_group_jobs = 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1071 | groupid++; |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 1072 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1073 | |
| 1074 | td->groupid = groupid; |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 1075 | prev_group_jobs++; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1076 | |
Jens Axboe | 9dbc7bf | 2013-01-23 09:26:53 -0700 | [diff] [blame] | 1077 | if (setup_random_seeds(td)) { |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 1078 | td_verror(td, errno, "init_random_state"); |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 1079 | goto err; |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 1080 | } |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 1081 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1082 | if (setup_rate(td)) |
| 1083 | goto err; |
| 1084 | |
Jens Axboe | 22f8045 | 2013-04-09 20:29:16 +0200 | [diff] [blame] | 1085 | if (o->lat_log_file) { |
| 1086 | setup_log(&td->lat_log, o->log_avg_msec, IO_LOG_TYPE_LAT); |
| 1087 | setup_log(&td->slat_log, o->log_avg_msec, IO_LOG_TYPE_SLAT); |
| 1088 | setup_log(&td->clat_log, o->log_avg_msec, IO_LOG_TYPE_CLAT); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1089 | } |
Jens Axboe | 22f8045 | 2013-04-09 20:29:16 +0200 | [diff] [blame] | 1090 | if (o->bw_log_file) |
| 1091 | setup_log(&td->bw_log, o->log_avg_msec, IO_LOG_TYPE_BW); |
| 1092 | if (o->iops_log_file) |
| 1093 | setup_log(&td->iops_log, o->log_avg_msec, IO_LOG_TYPE_IOPS); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1094 | |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 1095 | if (!o->name) |
| 1096 | o->name = strdup(jobname); |
Jens Axboe | 0145205 | 2006-06-07 10:29:47 +0200 | [diff] [blame] | 1097 | |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1098 | if (output_format == FIO_OUTPUT_NORMAL) { |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 1099 | if (!job_add_num) { |
Jens Axboe | b7cfb2e | 2012-03-12 07:47:27 +0100 | [diff] [blame] | 1100 | if (is_backend && !recursed) |
Jens Axboe | 2f122b1 | 2012-03-15 13:10:19 +0100 | [diff] [blame] | 1101 | fio_server_send_add_job(td); |
Jens Axboe | 807f997 | 2012-03-02 10:25:24 +0100 | [diff] [blame] | 1102 | |
Jens Axboe | 0353050 | 2012-03-19 21:45:12 +0100 | [diff] [blame] | 1103 | if (!(td->io_ops->flags & FIO_NOIO)) { |
Jens Axboe | d21e253 | 2013-07-25 13:01:11 -0600 | [diff] [blame] | 1104 | char *c1, *c2, *c3, *c4; |
| 1105 | char *c5 = NULL, *c6 = NULL; |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 1106 | |
Jens Axboe | 22f8045 | 2013-04-09 20:29:16 +0200 | [diff] [blame] | 1107 | c1 = fio_uint_to_kmg(o->min_bs[DDIR_READ]); |
| 1108 | c2 = fio_uint_to_kmg(o->max_bs[DDIR_READ]); |
| 1109 | c3 = fio_uint_to_kmg(o->min_bs[DDIR_WRITE]); |
| 1110 | c4 = fio_uint_to_kmg(o->max_bs[DDIR_WRITE]); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 1111 | |
Jens Axboe | d21e253 | 2013-07-25 13:01:11 -0600 | [diff] [blame] | 1112 | if (!o->bs_is_seq_rand) { |
| 1113 | c5 = fio_uint_to_kmg(o->min_bs[DDIR_TRIM]); |
| 1114 | c6 = fio_uint_to_kmg(o->max_bs[DDIR_TRIM]); |
| 1115 | } |
| 1116 | |
| 1117 | log_info("%s: (g=%d): rw=%s, ", td->o.name, |
| 1118 | td->groupid, |
| 1119 | ddir_str(o->td_ddir)); |
| 1120 | |
| 1121 | if (o->bs_is_seq_rand) |
| 1122 | log_info("bs(seq/rand)=%s-%s/%s-%s, ", |
| 1123 | c1, c2, c3, c4); |
| 1124 | else |
| 1125 | log_info("bs=%s-%s/%s-%s/%s-%s, ", |
| 1126 | c1, c2, c3, c4, c5, c6); |
| 1127 | |
| 1128 | log_info("ioengine=%s, iodepth=%u\n", |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 1129 | td->io_ops->name, o->iodepth); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 1130 | |
| 1131 | free(c1); |
| 1132 | free(c2); |
| 1133 | free(c3); |
| 1134 | free(c4); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1135 | free(c5); |
| 1136 | free(c6); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 1137 | } |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 1138 | } else if (job_add_num == 1) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 1139 | log_info("...\n"); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 1140 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1141 | |
| 1142 | /* |
| 1143 | * recurse add identical jobs, clear numjobs and stonewall options |
| 1144 | * as they don't apply to sub-jobs |
| 1145 | */ |
Jens Axboe | de98bd3 | 2013-04-05 11:09:20 +0200 | [diff] [blame] | 1146 | numjobs = o->numjobs; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1147 | while (--numjobs) { |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1148 | struct thread_data *td_new = get_new_job(0, td, 1); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1149 | |
| 1150 | if (!td_new) |
| 1151 | goto err; |
| 1152 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 1153 | td_new->o.numjobs = 1; |
| 1154 | td_new->o.stonewall = 0; |
Jens Axboe | 92c1d41 | 2007-03-28 10:04:08 +0200 | [diff] [blame] | 1155 | td_new->o.new_group = 0; |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 1156 | |
| 1157 | if (file_alloced) { |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 1158 | td_new->files_index = 0; |
Jens Axboe | 4e6ea2f | 2009-03-04 20:17:22 +0100 | [diff] [blame] | 1159 | td_new->files_size = 0; |
Christian Ehrhardt | 455a50f | 2014-02-19 10:42:41 -0800 | [diff] [blame] | 1160 | if (td_new->files) { |
| 1161 | struct fio_file *f; |
| 1162 | for_each_file(td_new, f, i) { |
| 1163 | if (f->file_name) |
| 1164 | free(f->file_name); |
| 1165 | free(f); |
| 1166 | } |
| 1167 | td_new->files = NULL; |
| 1168 | } |
| 1169 | if (td_new->o.filename) { |
| 1170 | free(td_new->o.filename); |
| 1171 | td_new->o.filename = NULL; |
| 1172 | } |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 1173 | } |
| 1174 | |
Christian Ehrhardt | bcbfeef | 2014-02-20 09:13:06 -0800 | [diff] [blame] | 1175 | if (add_job(td_new, jobname, numjobs, 1, client_type)) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1176 | goto err; |
| 1177 | } |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 1178 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1179 | return 0; |
| 1180 | err: |
| 1181 | put_job(td); |
| 1182 | return -1; |
| 1183 | } |
| 1184 | |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 1185 | /* |
| 1186 | * Parse as if 'o' was a command line |
| 1187 | */ |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 1188 | void add_job_opts(const char **o, int client_type) |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 1189 | { |
| 1190 | struct thread_data *td, *td_parent; |
| 1191 | int i, in_global = 1; |
| 1192 | char jobname[32]; |
| 1193 | |
| 1194 | i = 0; |
| 1195 | td_parent = td = NULL; |
| 1196 | while (o[i]) { |
| 1197 | if (!strncmp(o[i], "name", 4)) { |
| 1198 | in_global = 0; |
| 1199 | if (td) |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 1200 | add_job(td, jobname, 0, 0, client_type); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 1201 | td = NULL; |
| 1202 | sprintf(jobname, "%s", o[i] + 5); |
| 1203 | } |
| 1204 | if (in_global && !td_parent) |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1205 | td_parent = get_new_job(1, &def_thread, 0); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 1206 | else if (!in_global && !td) { |
| 1207 | if (!td_parent) |
| 1208 | td_parent = &def_thread; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1209 | td = get_new_job(0, td_parent, 0); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 1210 | } |
| 1211 | if (in_global) |
Jens Axboe | 292cc47 | 2013-11-26 20:39:35 -0700 | [diff] [blame] | 1212 | fio_options_parse(td_parent, (char **) &o[i], 1, 0); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 1213 | else |
Jens Axboe | 292cc47 | 2013-11-26 20:39:35 -0700 | [diff] [blame] | 1214 | fio_options_parse(td, (char **) &o[i], 1, 0); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 1215 | i++; |
| 1216 | } |
| 1217 | |
| 1218 | if (td) |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 1219 | add_job(td, jobname, 0, 0, client_type); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 1220 | } |
| 1221 | |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1222 | static int skip_this_section(const char *name) |
| 1223 | { |
Jens Axboe | ad0a273 | 2011-03-11 10:16:17 +0100 | [diff] [blame] | 1224 | int i; |
| 1225 | |
| 1226 | if (!nr_job_sections) |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1227 | return 0; |
| 1228 | if (!strncmp(name, "global", 6)) |
| 1229 | return 0; |
| 1230 | |
Jens Axboe | ad0a273 | 2011-03-11 10:16:17 +0100 | [diff] [blame] | 1231 | for (i = 0; i < nr_job_sections; i++) |
| 1232 | if (!strcmp(job_sections[i], name)) |
| 1233 | return 0; |
| 1234 | |
| 1235 | return 1; |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1236 | } |
| 1237 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1238 | static int is_empty_or_comment(char *line) |
| 1239 | { |
| 1240 | unsigned int i; |
| 1241 | |
| 1242 | for (i = 0; i < strlen(line); i++) { |
| 1243 | if (line[i] == ';') |
| 1244 | return 1; |
Ingo Molnar | 5cc2da3 | 2007-02-20 10:19:44 +0100 | [diff] [blame] | 1245 | if (line[i] == '#') |
| 1246 | return 1; |
Jens Axboe | 76cd937 | 2011-07-08 21:14:57 +0200 | [diff] [blame] | 1247 | if (!isspace((int) line[i]) && !iscntrl((int) line[i])) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1248 | return 0; |
| 1249 | } |
| 1250 | |
| 1251 | return 1; |
| 1252 | } |
| 1253 | |
Jens Axboe | 313cb20 | 2006-12-21 09:50:00 +0100 | [diff] [blame] | 1254 | /* |
Jens Axboe | 0726198 | 2006-06-07 10:51:12 +0200 | [diff] [blame] | 1255 | * This is our [ini] type file parser. |
| 1256 | */ |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 1257 | int parse_jobs_ini(char *file, int is_buf, int stonewall_flag, int type) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1258 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1259 | unsigned int global; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1260 | struct thread_data *td; |
Jens Axboe | fee3bb4 | 2006-10-30 13:32:08 +0100 | [diff] [blame] | 1261 | char *string, *name; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1262 | FILE *f; |
| 1263 | char *p; |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 1264 | int ret = 0, stonewall; |
Jens Axboe | 097b299 | 2007-04-19 09:41:45 +0200 | [diff] [blame] | 1265 | int first_sect = 1; |
Jens Axboe | ccf8f12 | 2007-09-27 10:48:55 +0200 | [diff] [blame] | 1266 | int skip_fgets = 0; |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1267 | int inside_skip = 0; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 1268 | char **opts; |
| 1269 | int i, alloc_opts, num_opts; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1270 | |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 1271 | if (is_buf) |
| 1272 | f = NULL; |
| 1273 | else { |
| 1274 | if (!strcmp(file, "-")) |
| 1275 | f = stdin; |
| 1276 | else |
| 1277 | f = fopen(file, "r"); |
Aaron Carroll | 5a729cb | 2007-09-27 09:03:55 +0200 | [diff] [blame] | 1278 | |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 1279 | if (!f) { |
| 1280 | perror("fopen job file"); |
| 1281 | return 1; |
| 1282 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | string = malloc(4096); |
Jens Axboe | 7f7e6e5 | 2007-07-19 14:50:05 +0200 | [diff] [blame] | 1286 | |
| 1287 | /* |
| 1288 | * it's really 256 + small bit, 280 should suffice |
| 1289 | */ |
| 1290 | name = malloc(280); |
| 1291 | memset(name, 0, 280); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1292 | |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 1293 | alloc_opts = 8; |
| 1294 | opts = malloc(sizeof(char *) * alloc_opts); |
Jens Axboe | b7c6302 | 2008-06-11 11:47:56 +0200 | [diff] [blame] | 1295 | num_opts = 0; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 1296 | |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 1297 | stonewall = stonewall_flag; |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1298 | do { |
Jens Axboe | ccf8f12 | 2007-09-27 10:48:55 +0200 | [diff] [blame] | 1299 | /* |
| 1300 | * if skip_fgets is set, we already have loaded a line we |
| 1301 | * haven't handled. |
| 1302 | */ |
| 1303 | if (!skip_fgets) { |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 1304 | if (is_buf) |
| 1305 | p = strsep(&file, "\n"); |
| 1306 | else |
Jens Axboe | 43f7479 | 2011-10-15 14:37:26 +0200 | [diff] [blame] | 1307 | p = fgets(string, 4096, f); |
Jens Axboe | ccf8f12 | 2007-09-27 10:48:55 +0200 | [diff] [blame] | 1308 | if (!p) |
| 1309 | break; |
| 1310 | } |
gurudas pai | cdc7f19 | 2007-03-29 10:10:56 +0200 | [diff] [blame] | 1311 | |
Jens Axboe | ccf8f12 | 2007-09-27 10:48:55 +0200 | [diff] [blame] | 1312 | skip_fgets = 0; |
gurudas pai | cdc7f19 | 2007-03-29 10:10:56 +0200 | [diff] [blame] | 1313 | strip_blank_front(&p); |
Jens Axboe | 6c7c7da | 2007-03-29 14:12:57 -0800 | [diff] [blame] | 1314 | strip_blank_end(p); |
gurudas pai | cdc7f19 | 2007-03-29 10:10:56 +0200 | [diff] [blame] | 1315 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1316 | if (is_empty_or_comment(p)) |
| 1317 | continue; |
Bruce Cran | 84dd188 | 2011-05-05 08:14:09 -0600 | [diff] [blame] | 1318 | if (sscanf(p, "[%255[^\n]]", name) != 1) { |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1319 | if (inside_skip) |
| 1320 | continue; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1321 | log_err("fio: option <%s> outside of [] job section\n", |
| 1322 | p); |
Jens Axboe | 088b420 | 2007-07-19 14:53:01 +0200 | [diff] [blame] | 1323 | break; |
Jens Axboe | 6c7c7da | 2007-03-29 14:12:57 -0800 | [diff] [blame] | 1324 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1325 | |
Jens Axboe | 7a4b80a | 2010-05-22 20:43:11 +0200 | [diff] [blame] | 1326 | name[strlen(name) - 1] = '\0'; |
| 1327 | |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1328 | if (skip_this_section(name)) { |
| 1329 | inside_skip = 1; |
| 1330 | continue; |
| 1331 | } else |
| 1332 | inside_skip = 0; |
| 1333 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1334 | global = !strncmp(name, "global", 6); |
| 1335 | |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 1336 | if (dump_cmdline) { |
Jens Axboe | 097b299 | 2007-04-19 09:41:45 +0200 | [diff] [blame] | 1337 | if (first_sect) |
| 1338 | log_info("fio "); |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 1339 | if (!global) |
| 1340 | log_info("--name=%s ", name); |
Jens Axboe | 097b299 | 2007-04-19 09:41:45 +0200 | [diff] [blame] | 1341 | first_sect = 0; |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 1342 | } |
| 1343 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1344 | td = get_new_job(global, &def_thread, 0); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1345 | if (!td) { |
| 1346 | ret = 1; |
| 1347 | break; |
| 1348 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1349 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1350 | /* |
Anatol Pomozov | de8f6de | 2013-09-26 16:31:34 -0700 | [diff] [blame] | 1351 | * Separate multiple job files by a stonewall |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1352 | */ |
Jens Axboe | f948191 | 2006-06-09 11:37:28 +0200 | [diff] [blame] | 1353 | if (!global && stonewall) { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 1354 | td->o.stonewall = stonewall; |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1355 | stonewall = 0; |
| 1356 | } |
| 1357 | |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 1358 | num_opts = 0; |
| 1359 | memset(opts, 0, alloc_opts * sizeof(char *)); |
| 1360 | |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 1361 | while (1) { |
| 1362 | if (is_buf) |
| 1363 | p = strsep(&file, "\n"); |
| 1364 | else |
| 1365 | p = fgets(string, 4096, f); |
| 1366 | if (!p) |
| 1367 | break; |
| 1368 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1369 | if (is_empty_or_comment(p)) |
| 1370 | continue; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1371 | |
Jens Axboe | b6754f9 | 2006-05-30 14:29:32 +0200 | [diff] [blame] | 1372 | strip_blank_front(&p); |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1373 | |
Jens Axboe | ccf8f12 | 2007-09-27 10:48:55 +0200 | [diff] [blame] | 1374 | /* |
| 1375 | * new section, break out and make sure we don't |
| 1376 | * fgets() a new line at the top. |
| 1377 | */ |
| 1378 | if (p[0] == '[') { |
| 1379 | skip_fgets = 1; |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1380 | break; |
Jens Axboe | ccf8f12 | 2007-09-27 10:48:55 +0200 | [diff] [blame] | 1381 | } |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1382 | |
Jens Axboe | 4ae3f76 | 2006-05-30 13:35:14 +0200 | [diff] [blame] | 1383 | strip_blank_end(p); |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 1384 | |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 1385 | if (num_opts == alloc_opts) { |
| 1386 | alloc_opts <<= 1; |
| 1387 | opts = realloc(opts, |
| 1388 | alloc_opts * sizeof(char *)); |
| 1389 | } |
| 1390 | |
| 1391 | opts[num_opts] = strdup(p); |
| 1392 | num_opts++; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1393 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1394 | |
Jens Axboe | 292cc47 | 2013-11-26 20:39:35 -0700 | [diff] [blame] | 1395 | ret = fio_options_parse(td, opts, num_opts, dump_cmdline); |
| 1396 | if (!ret) |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 1397 | ret = add_job(td, name, 0, 0, type); |
Jens Axboe | 292cc47 | 2013-11-26 20:39:35 -0700 | [diff] [blame] | 1398 | else { |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 1399 | log_err("fio: job %s dropped\n", name); |
| 1400 | put_job(td); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1401 | } |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 1402 | |
| 1403 | for (i = 0; i < num_opts; i++) |
| 1404 | free(opts[i]); |
| 1405 | num_opts = 0; |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1406 | } while (!ret); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1407 | |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 1408 | if (dump_cmdline) |
| 1409 | log_info("\n"); |
| 1410 | |
Jens Axboe | 7e356b2 | 2011-10-14 10:55:16 +0200 | [diff] [blame] | 1411 | i = 0; |
| 1412 | while (i < nr_job_sections) { |
| 1413 | free(job_sections[i]); |
| 1414 | i++; |
| 1415 | } |
| 1416 | |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 1417 | for (i = 0; i < num_opts; i++) |
| 1418 | free(opts[i]); |
| 1419 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1420 | free(string); |
| 1421 | free(name); |
Jens Axboe | 2577594 | 2008-06-10 20:26:06 +0200 | [diff] [blame] | 1422 | free(opts); |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 1423 | if (!is_buf && f != stdin) |
Aaron Carroll | 5a729cb | 2007-09-27 09:03:55 +0200 | [diff] [blame] | 1424 | fclose(f); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1425 | return ret; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | static int fill_def_thread(void) |
| 1429 | { |
| 1430 | memset(&def_thread, 0, sizeof(def_thread)); |
| 1431 | |
Jens Axboe | 375b269 | 2007-05-22 09:13:02 +0200 | [diff] [blame] | 1432 | fio_getaffinity(getpid(), &def_thread.o.cpumask); |
Jens Axboe | 8c02937 | 2011-10-05 09:54:30 +0200 | [diff] [blame] | 1433 | def_thread.o.timeout = def_timeout; |
Dmitry Monakhov | 8b28bd4 | 2012-09-23 15:46:09 +0400 | [diff] [blame] | 1434 | def_thread.o.error_dump = 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1435 | /* |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1436 | * fill default options |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1437 | */ |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1438 | fio_fill_default_options(&def_thread); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1439 | return 0; |
| 1440 | } |
| 1441 | |
Jens Axboe | 45378b3 | 2007-12-19 13:54:38 +0100 | [diff] [blame] | 1442 | static void usage(const char *name) |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1443 | { |
Jens Axboe | 3d43382 | 2012-03-21 22:25:22 +0100 | [diff] [blame] | 1444 | printf("%s\n", fio_version_string); |
Jens Axboe | 45378b3 | 2007-12-19 13:54:38 +0100 | [diff] [blame] | 1445 | printf("%s [options] [job options] <job file(s)>\n", name); |
Jens Axboe | 8388128 | 2011-10-17 19:58:51 +0200 | [diff] [blame] | 1446 | printf(" --debug=options\tEnable debug logging. May be one/more of:\n" |
| 1447 | "\t\t\tprocess,file,io,mem,blktrace,verify,random,parse,\n" |
Jens Axboe | 3e260a4 | 2013-12-09 12:38:53 -0700 | [diff] [blame] | 1448 | "\t\t\tdiskutil,job,mutex,profile,time,net,rate\n"); |
Jens Axboe | 111e032 | 2013-03-07 11:31:20 +0100 | [diff] [blame] | 1449 | printf(" --parse-only\t\tParse options only, don't start any IO\n"); |
Jens Axboe | 8388128 | 2011-10-17 19:58:51 +0200 | [diff] [blame] | 1450 | printf(" --output\t\tWrite output to file\n"); |
liang xie | b2cecdc | 2012-08-31 08:22:42 -0700 | [diff] [blame] | 1451 | printf(" --runtime\t\tRuntime in seconds\n"); |
Jens Axboe | 8388128 | 2011-10-17 19:58:51 +0200 | [diff] [blame] | 1452 | printf(" --latency-log\t\tGenerate per-job latency logs\n"); |
| 1453 | printf(" --bandwidth-log\tGenerate per-job bandwidth logs\n"); |
| 1454 | printf(" --minimal\t\tMinimal (terse) output\n"); |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1455 | printf(" --output-format=x\tOutput format (terse,json,normal)\n"); |
Jens Axboe | 75db6e2 | 2011-11-07 22:07:36 +0100 | [diff] [blame] | 1456 | printf(" --terse-version=x\tSet terse version output format to 'x'\n"); |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1457 | printf(" --version\t\tPrint version info and exit\n"); |
Jens Axboe | 8388128 | 2011-10-17 19:58:51 +0200 | [diff] [blame] | 1458 | printf(" --help\t\tPrint this page\n"); |
Jens Axboe | 2389364 | 2012-12-17 14:44:08 +0100 | [diff] [blame] | 1459 | printf(" --cpuclock-test\tPerform test/validation of CPU clock\n"); |
Jens Axboe | fec0f21 | 2014-02-07 14:39:33 -0700 | [diff] [blame] | 1460 | printf(" --crctest\t\tTest speed of checksum functions\n"); |
Jens Axboe | 8388128 | 2011-10-17 19:58:51 +0200 | [diff] [blame] | 1461 | printf(" --cmdhelp=cmd\t\tPrint command help, \"all\" for all of" |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1462 | " them\n"); |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1463 | printf(" --enghelp=engine\tPrint ioengine help, or list" |
| 1464 | " available ioengines\n"); |
| 1465 | printf(" --enghelp=engine,cmd\tPrint help for an ioengine" |
| 1466 | " cmd\n"); |
Jens Axboe | 8388128 | 2011-10-17 19:58:51 +0200 | [diff] [blame] | 1467 | printf(" --showcmd\t\tTurn a job file into command line options\n"); |
| 1468 | printf(" --eta=when\t\tWhen ETA estimate should be printed\n"); |
| 1469 | printf(" \t\tMay be \"always\", \"never\" or \"auto\"\n"); |
Jens Axboe | e382e66 | 2013-02-22 20:48:56 +0100 | [diff] [blame] | 1470 | printf(" --eta-newline=time\tForce a new line for every 'time'"); |
| 1471 | printf(" period passed\n"); |
Jens Axboe | 0646490 | 2013-04-24 20:38:54 -0600 | [diff] [blame] | 1472 | printf(" --status-interval=t\tForce full status dump every"); |
| 1473 | printf(" 't' period passed\n"); |
Jens Axboe | 8388128 | 2011-10-17 19:58:51 +0200 | [diff] [blame] | 1474 | printf(" --readonly\t\tTurn on safety read-only checks, preventing" |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1475 | " writes\n"); |
Jens Axboe | 8388128 | 2011-10-17 19:58:51 +0200 | [diff] [blame] | 1476 | printf(" --section=name\tOnly run specified section in job file\n"); |
| 1477 | printf(" --alloc-size=kb\tSet smalloc pool to this size in kb" |
Jens Axboe | 2b386d2 | 2008-03-26 10:32:57 +0100 | [diff] [blame] | 1478 | " (def 1024)\n"); |
Jens Axboe | 8388128 | 2011-10-17 19:58:51 +0200 | [diff] [blame] | 1479 | printf(" --warnings-fatal\tFio parser warnings are fatal\n"); |
| 1480 | printf(" --max-jobs=nr\t\tMaximum number of threads/processes to support\n"); |
| 1481 | printf(" --server=args\t\tStart a backend fio server\n"); |
| 1482 | printf(" --daemonize=pidfile\tBackground fio server, write pid to file\n"); |
| 1483 | printf(" --client=hostname\tTalk to remote backend fio server at hostname\n"); |
Huadong Liu | f2a2ce0 | 2013-01-30 13:22:24 +0100 | [diff] [blame] | 1484 | printf(" --idle-prof=option\tReport cpu idleness on a system or percpu basis\n" |
| 1485 | "\t\t\t(option=system,percpu) or run unit work\n" |
| 1486 | "\t\t\tcalibration only (option=calibrate)\n"); |
Jens Axboe | aa58d25 | 2010-06-09 09:49:38 +0200 | [diff] [blame] | 1487 | printf("\nFio was written by Jens Axboe <jens.axboe@oracle.com>"); |
Jens Axboe | bfca2c7 | 2014-01-29 16:39:04 -0700 | [diff] [blame] | 1488 | printf("\n Jens Axboe <jaxboe@fusionio.com>"); |
| 1489 | printf("\n Jens Axboe <axboe@fb.com>\n"); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1490 | } |
| 1491 | |
Jens Axboe | 79e48f7 | 2008-02-01 20:37:09 +0100 | [diff] [blame] | 1492 | #ifdef FIO_INC_DEBUG |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1493 | struct debug_level debug_levels[] = { |
Jens Axboe | 0b8d11e | 2012-03-02 19:44:15 +0100 | [diff] [blame] | 1494 | { .name = "process", |
| 1495 | .help = "Process creation/exit logging", |
| 1496 | .shift = FD_PROCESS, |
| 1497 | }, |
| 1498 | { .name = "file", |
| 1499 | .help = "File related action logging", |
| 1500 | .shift = FD_FILE, |
| 1501 | }, |
| 1502 | { .name = "io", |
| 1503 | .help = "IO and IO engine action logging (offsets, queue, completions, etc)", |
| 1504 | .shift = FD_IO, |
| 1505 | }, |
| 1506 | { .name = "mem", |
| 1507 | .help = "Memory allocation/freeing logging", |
| 1508 | .shift = FD_MEM, |
| 1509 | }, |
| 1510 | { .name = "blktrace", |
| 1511 | .help = "blktrace action logging", |
| 1512 | .shift = FD_BLKTRACE, |
| 1513 | }, |
| 1514 | { .name = "verify", |
| 1515 | .help = "IO verification action logging", |
| 1516 | .shift = FD_VERIFY, |
| 1517 | }, |
| 1518 | { .name = "random", |
| 1519 | .help = "Random generation logging", |
| 1520 | .shift = FD_RANDOM, |
| 1521 | }, |
| 1522 | { .name = "parse", |
| 1523 | .help = "Parser logging", |
| 1524 | .shift = FD_PARSE, |
| 1525 | }, |
| 1526 | { .name = "diskutil", |
| 1527 | .help = "Disk utility logging actions", |
| 1528 | .shift = FD_DISKUTIL, |
| 1529 | }, |
| 1530 | { .name = "job", |
| 1531 | .help = "Logging related to creating/destroying jobs", |
| 1532 | .shift = FD_JOB, |
| 1533 | }, |
| 1534 | { .name = "mutex", |
| 1535 | .help = "Mutex logging", |
| 1536 | .shift = FD_MUTEX |
| 1537 | }, |
| 1538 | { .name = "profile", |
| 1539 | .help = "Logging related to profiles", |
| 1540 | .shift = FD_PROFILE, |
| 1541 | }, |
| 1542 | { .name = "time", |
| 1543 | .help = "Logging related to time keeping functions", |
| 1544 | .shift = FD_TIME, |
| 1545 | }, |
| 1546 | { .name = "net", |
| 1547 | .help = "Network logging", |
| 1548 | .shift = FD_NET, |
| 1549 | }, |
Jens Axboe | 3e260a4 | 2013-12-09 12:38:53 -0700 | [diff] [blame] | 1550 | { .name = "rate", |
| 1551 | .help = "Rate logging", |
| 1552 | .shift = FD_RATE, |
| 1553 | }, |
Jens Axboe | 02444ad | 2008-10-07 11:33:00 +0200 | [diff] [blame] | 1554 | { .name = NULL, }, |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1555 | }; |
| 1556 | |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1557 | static int set_debug(const char *string) |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1558 | { |
| 1559 | struct debug_level *dl; |
| 1560 | char *p = (char *) string; |
| 1561 | char *opt; |
| 1562 | int i; |
| 1563 | |
| 1564 | if (!strcmp(string, "?") || !strcmp(string, "help")) { |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1565 | log_info("fio: dumping debug options:"); |
| 1566 | for (i = 0; debug_levels[i].name; i++) { |
| 1567 | dl = &debug_levels[i]; |
| 1568 | log_info("%s,", dl->name); |
| 1569 | } |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 1570 | log_info("all\n"); |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1571 | return 1; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | while ((opt = strsep(&p, ",")) != NULL) { |
| 1575 | int found = 0; |
| 1576 | |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 1577 | if (!strncmp(opt, "all", 3)) { |
| 1578 | log_info("fio: set all debug options\n"); |
| 1579 | fio_debug = ~0UL; |
| 1580 | continue; |
| 1581 | } |
| 1582 | |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1583 | for (i = 0; debug_levels[i].name; i++) { |
| 1584 | dl = &debug_levels[i]; |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 1585 | found = !strncmp(opt, dl->name, strlen(dl->name)); |
| 1586 | if (!found) |
| 1587 | continue; |
| 1588 | |
| 1589 | if (dl->shift == FD_JOB) { |
| 1590 | opt = strchr(opt, ':'); |
| 1591 | if (!opt) { |
| 1592 | log_err("fio: missing job number\n"); |
| 1593 | break; |
| 1594 | } |
| 1595 | opt++; |
| 1596 | fio_debug_jobno = atoi(opt); |
| 1597 | log_info("fio: set debug jobno %d\n", |
| 1598 | fio_debug_jobno); |
| 1599 | } else { |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1600 | log_info("fio: set debug option %s\n", opt); |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 1601 | fio_debug |= (1UL << dl->shift); |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1602 | } |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 1603 | break; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | if (!found) |
| 1607 | log_err("fio: debug mask %s not found\n", opt); |
| 1608 | } |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1609 | return 0; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1610 | } |
Jens Axboe | 79e48f7 | 2008-02-01 20:37:09 +0100 | [diff] [blame] | 1611 | #else |
Jens Axboe | 69b98d4 | 2008-05-30 22:25:32 +0200 | [diff] [blame] | 1612 | static int set_debug(const char *string) |
Jens Axboe | 79e48f7 | 2008-02-01 20:37:09 +0100 | [diff] [blame] | 1613 | { |
| 1614 | log_err("fio: debug tracing not included in build\n"); |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1615 | return 1; |
Jens Axboe | 79e48f7 | 2008-02-01 20:37:09 +0100 | [diff] [blame] | 1616 | } |
| 1617 | #endif |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1618 | |
Jens Axboe | 4c6107f | 2011-01-18 05:22:22 -0700 | [diff] [blame] | 1619 | static void fio_options_fill_optstring(void) |
| 1620 | { |
| 1621 | char *ostr = cmd_optstr; |
| 1622 | int i, c; |
| 1623 | |
| 1624 | c = i = 0; |
| 1625 | while (l_opts[i].name) { |
| 1626 | ostr[c++] = l_opts[i].val; |
| 1627 | if (l_opts[i].has_arg == required_argument) |
| 1628 | ostr[c++] = ':'; |
| 1629 | else if (l_opts[i].has_arg == optional_argument) { |
| 1630 | ostr[c++] = ':'; |
| 1631 | ostr[c++] = ':'; |
| 1632 | } |
| 1633 | i++; |
| 1634 | } |
| 1635 | ostr[c] = '\0'; |
| 1636 | } |
| 1637 | |
Jens Axboe | c2c9458 | 2011-10-05 20:31:30 +0200 | [diff] [blame] | 1638 | static int client_flag_set(char c) |
| 1639 | { |
| 1640 | int i; |
| 1641 | |
| 1642 | i = 0; |
| 1643 | while (l_opts[i].name) { |
| 1644 | int val = l_opts[i].val; |
| 1645 | |
| 1646 | if (c == (val & 0xff)) |
| 1647 | return (val & FIO_CLIENT_FLAG); |
| 1648 | |
| 1649 | i++; |
| 1650 | } |
| 1651 | |
| 1652 | return 0; |
| 1653 | } |
| 1654 | |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 1655 | void parse_cmd_client(void *client, char *opt) |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 1656 | { |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 1657 | fio_client_add_cmd_option(client, opt); |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 1658 | } |
| 1659 | |
Jens Axboe | fec0f21 | 2014-02-07 14:39:33 -0700 | [diff] [blame] | 1660 | extern int fio_crctest(const char *); |
| 1661 | |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 1662 | int parse_cmd_line(int argc, char *argv[], int client_type) |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1663 | { |
| 1664 | struct thread_data *td = NULL; |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1665 | int c, ini_idx = 0, lidx, ret = 0, do_exit = 0, exit_val = 0; |
Jens Axboe | 4c6107f | 2011-01-18 05:22:22 -0700 | [diff] [blame] | 1666 | char *ostr = cmd_optstr; |
Jens Axboe | 402668f | 2011-10-10 15:28:58 +0200 | [diff] [blame] | 1667 | void *pid_file = NULL; |
Jens Axboe | 9bae26e | 2011-10-07 10:07:22 +0200 | [diff] [blame] | 1668 | void *cur_client = NULL; |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 1669 | int backend = 0; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1670 | |
Jens Axboe | c2c9458 | 2011-10-05 20:31:30 +0200 | [diff] [blame] | 1671 | /* |
| 1672 | * Reset optind handling, since we may call this multiple times |
| 1673 | * for the backend. |
| 1674 | */ |
| 1675 | optind = 1; |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 1676 | |
Jens Axboe | c2c9458 | 2011-10-05 20:31:30 +0200 | [diff] [blame] | 1677 | while ((c = getopt_long_only(argc, argv, ostr, l_opts, &lidx)) != -1) { |
Jens Axboe | 085399d | 2011-10-06 09:01:22 +0200 | [diff] [blame] | 1678 | did_arg = 1; |
| 1679 | |
Jens Axboe | c2c9458 | 2011-10-05 20:31:30 +0200 | [diff] [blame] | 1680 | if ((c & FIO_CLIENT_FLAG) || client_flag_set(c)) { |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 1681 | parse_cmd_client(cur_client, argv[optind - 1]); |
Jens Axboe | 7a4b824 | 2011-10-05 17:35:15 +0200 | [diff] [blame] | 1682 | c &= ~FIO_CLIENT_FLAG; |
| 1683 | } |
| 1684 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1685 | switch (c) { |
Jens Axboe | 2b386d2 | 2008-03-26 10:32:57 +0100 | [diff] [blame] | 1686 | case 'a': |
| 1687 | smalloc_pool_size = atoi(optarg); |
| 1688 | break; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1689 | case 't': |
Jens Axboe | 8c02937 | 2011-10-05 09:54:30 +0200 | [diff] [blame] | 1690 | def_timeout = atoi(optarg); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1691 | break; |
| 1692 | case 'l': |
| 1693 | write_lat_log = 1; |
| 1694 | break; |
Jens Axboe | 3d73e5a | 2010-03-25 10:38:07 +0100 | [diff] [blame] | 1695 | case 'b': |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1696 | write_bw_log = 1; |
| 1697 | break; |
| 1698 | case 'o': |
| 1699 | f_out = fopen(optarg, "w+"); |
| 1700 | if (!f_out) { |
| 1701 | perror("fopen output"); |
| 1702 | exit(1); |
| 1703 | } |
| 1704 | f_err = f_out; |
| 1705 | break; |
| 1706 | case 'm': |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1707 | output_format = FIO_OUTPUT_TERSE; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1708 | break; |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1709 | case 'F': |
Stefan Hajnoczi | d10983d | 2014-02-04 14:27:11 +0100 | [diff] [blame] | 1710 | if (!optarg) { |
| 1711 | log_err("fio: missing --output-format argument\n"); |
| 1712 | exit_val = 1; |
| 1713 | do_exit++; |
| 1714 | break; |
| 1715 | } |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1716 | if (!strcmp(optarg, "minimal") || |
| 1717 | !strcmp(optarg, "terse") || |
| 1718 | !strcmp(optarg, "csv")) |
| 1719 | output_format = FIO_OUTPUT_TERSE; |
| 1720 | else if (!strcmp(optarg, "json")) |
| 1721 | output_format = FIO_OUTPUT_JSON; |
| 1722 | else |
| 1723 | output_format = FIO_OUTPUT_NORMAL; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1724 | break; |
Christian Ehrhardt | 2b8c71b | 2014-02-20 14:20:04 +0100 | [diff] [blame] | 1725 | case 'f': |
| 1726 | append_terse_output = 1; |
| 1727 | break; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1728 | case 'h': |
Jens Axboe | 7874f8b | 2011-10-06 09:18:20 +0200 | [diff] [blame] | 1729 | if (!cur_client) { |
Jens Axboe | c2c9458 | 2011-10-05 20:31:30 +0200 | [diff] [blame] | 1730 | usage(argv[0]); |
Jens Axboe | 7874f8b | 2011-10-06 09:18:20 +0200 | [diff] [blame] | 1731 | do_exit++; |
| 1732 | } |
Jens Axboe | c2c9458 | 2011-10-05 20:31:30 +0200 | [diff] [blame] | 1733 | break; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1734 | case 'c': |
Jens Axboe | 7874f8b | 2011-10-06 09:18:20 +0200 | [diff] [blame] | 1735 | if (!cur_client) { |
Jens Axboe | c2c9458 | 2011-10-05 20:31:30 +0200 | [diff] [blame] | 1736 | fio_show_option_help(optarg); |
Jens Axboe | 7874f8b | 2011-10-06 09:18:20 +0200 | [diff] [blame] | 1737 | do_exit++; |
| 1738 | } |
Jens Axboe | c2c9458 | 2011-10-05 20:31:30 +0200 | [diff] [blame] | 1739 | break; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1740 | case 'i': |
| 1741 | if (!cur_client) { |
| 1742 | fio_show_ioengine_help(optarg); |
| 1743 | do_exit++; |
| 1744 | } |
| 1745 | break; |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 1746 | case 's': |
| 1747 | dump_cmdline = 1; |
| 1748 | break; |
Jens Axboe | 724e443 | 2007-09-11 20:02:05 +0200 | [diff] [blame] | 1749 | case 'r': |
| 1750 | read_only = 1; |
| 1751 | break; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1752 | case 'v': |
Jens Axboe | 7874f8b | 2011-10-06 09:18:20 +0200 | [diff] [blame] | 1753 | if (!cur_client) { |
Jens Axboe | 3d43382 | 2012-03-21 22:25:22 +0100 | [diff] [blame] | 1754 | log_info("%s\n", fio_version_string); |
Jens Axboe | 7874f8b | 2011-10-06 09:18:20 +0200 | [diff] [blame] | 1755 | do_exit++; |
| 1756 | } |
Jens Axboe | c2c9458 | 2011-10-05 20:31:30 +0200 | [diff] [blame] | 1757 | break; |
Jens Axboe | f57a9c5 | 2011-09-09 21:01:37 +0200 | [diff] [blame] | 1758 | case 'V': |
| 1759 | terse_version = atoi(optarg); |
Jens Axboe | 09786f5 | 2012-10-04 17:06:49 +0200 | [diff] [blame] | 1760 | if (!(terse_version == 2 || terse_version == 3 || |
| 1761 | terse_version == 4)) { |
Jens Axboe | f57a9c5 | 2011-09-09 21:01:37 +0200 | [diff] [blame] | 1762 | log_err("fio: bad terse version format\n"); |
| 1763 | exit_val = 1; |
| 1764 | do_exit++; |
| 1765 | } |
| 1766 | break; |
Aaron Carroll | e592a06 | 2007-09-14 09:49:41 +0200 | [diff] [blame] | 1767 | case 'e': |
| 1768 | if (!strcmp("always", optarg)) |
| 1769 | eta_print = FIO_ETA_ALWAYS; |
| 1770 | else if (!strcmp("never", optarg)) |
| 1771 | eta_print = FIO_ETA_NEVER; |
| 1772 | break; |
Jens Axboe | e382e66 | 2013-02-22 20:48:56 +0100 | [diff] [blame] | 1773 | case 'E': { |
| 1774 | long long t = 0; |
| 1775 | |
Jens Axboe | 0de5b26 | 2014-02-21 15:26:01 -0800 | [diff] [blame] | 1776 | if (str_to_decimal(optarg, &t, 0, NULL, 1)) { |
Jens Axboe | e382e66 | 2013-02-22 20:48:56 +0100 | [diff] [blame] | 1777 | log_err("fio: failed parsing eta time %s\n", optarg); |
| 1778 | exit_val = 1; |
| 1779 | do_exit++; |
| 1780 | } |
| 1781 | eta_new_line = t; |
| 1782 | break; |
| 1783 | } |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1784 | case 'd': |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1785 | if (set_debug(optarg)) |
| 1786 | do_exit++; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1787 | break; |
Jens Axboe | 111e032 | 2013-03-07 11:31:20 +0100 | [diff] [blame] | 1788 | case 'P': |
| 1789 | parse_only = 1; |
| 1790 | break; |
Jens Axboe | ad0a273 | 2011-03-11 10:16:17 +0100 | [diff] [blame] | 1791 | case 'x': { |
| 1792 | size_t new_size; |
| 1793 | |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1794 | if (!strcmp(optarg, "global")) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1795 | log_err("fio: can't use global as only " |
| 1796 | "section\n"); |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1797 | do_exit++; |
| 1798 | exit_val = 1; |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1799 | break; |
| 1800 | } |
Jens Axboe | ad0a273 | 2011-03-11 10:16:17 +0100 | [diff] [blame] | 1801 | new_size = (nr_job_sections + 1) * sizeof(char *); |
| 1802 | job_sections = realloc(job_sections, new_size); |
| 1803 | job_sections[nr_job_sections] = strdup(optarg); |
| 1804 | nr_job_sections++; |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1805 | break; |
Jens Axboe | ad0a273 | 2011-03-11 10:16:17 +0100 | [diff] [blame] | 1806 | } |
Jens Axboe | 9ac8a79 | 2009-11-13 21:23:07 +0100 | [diff] [blame] | 1807 | case 'p': |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 1808 | exec_profile = strdup(optarg); |
Jens Axboe | 9ac8a79 | 2009-11-13 21:23:07 +0100 | [diff] [blame] | 1809 | break; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1810 | case FIO_GETOPT_JOB: { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1811 | const char *opt = l_opts[lidx].name; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1812 | char *val = optarg; |
| 1813 | |
| 1814 | if (!strncmp(opt, "name", 4) && td) { |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 1815 | ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type); |
Jens Axboe | 6625155 | 2011-05-12 10:14:57 +0200 | [diff] [blame] | 1816 | if (ret) |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1817 | return 0; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1818 | td = NULL; |
| 1819 | } |
| 1820 | if (!td) { |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1821 | int is_section = !strncmp(opt, "name", 4); |
Jens Axboe | 3106f22 | 2007-04-19 09:53:28 +0200 | [diff] [blame] | 1822 | int global = 0; |
| 1823 | |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1824 | if (!is_section || !strncmp(val, "global", 6)) |
Jens Axboe | 3106f22 | 2007-04-19 09:53:28 +0200 | [diff] [blame] | 1825 | global = 1; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1826 | |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1827 | if (is_section && skip_this_section(val)) |
| 1828 | continue; |
| 1829 | |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1830 | td = get_new_job(global, &def_thread, 1); |
| 1831 | if (!td || ioengine_load(td)) |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1832 | return 0; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1833 | fio_options_set_ioengine_opts(l_opts, td); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1834 | } |
| 1835 | |
Jens Axboe | 9d91818 | 2013-05-23 20:00:35 +0200 | [diff] [blame] | 1836 | if ((!val || !strlen(val)) && |
| 1837 | l_opts[lidx].has_arg == required_argument) { |
| 1838 | log_err("fio: option %s requires an argument\n", opt); |
| 1839 | ret = 1; |
| 1840 | } else |
| 1841 | ret = fio_cmd_option_parse(td, opt, val); |
| 1842 | |
Jens Axboe | bfb3ea2 | 2013-05-23 19:54:43 +0200 | [diff] [blame] | 1843 | if (ret) { |
| 1844 | if (td) { |
| 1845 | put_job(td); |
| 1846 | td = NULL; |
| 1847 | } |
Jens Axboe | a88c8c1 | 2013-04-24 22:25:22 -0600 | [diff] [blame] | 1848 | do_exit++; |
Jens Axboe | bfb3ea2 | 2013-05-23 19:54:43 +0200 | [diff] [blame] | 1849 | } |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1850 | |
| 1851 | if (!ret && !strcmp(opt, "ioengine")) { |
| 1852 | free_ioengine(td); |
| 1853 | if (ioengine_load(td)) |
| 1854 | return 0; |
| 1855 | fio_options_set_ioengine_opts(l_opts, td); |
| 1856 | } |
| 1857 | break; |
| 1858 | } |
| 1859 | case FIO_GETOPT_IOENGINE: { |
| 1860 | const char *opt = l_opts[lidx].name; |
| 1861 | char *val = optarg; |
Steven Lang | de890a1 | 2011-11-09 14:03:34 +0100 | [diff] [blame] | 1862 | ret = fio_cmd_ioengine_option_parse(td, opt, val); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1863 | break; |
| 1864 | } |
Jens Axboe | a9523c6 | 2011-01-17 16:49:54 -0700 | [diff] [blame] | 1865 | case 'w': |
| 1866 | warnings_fatal = 1; |
| 1867 | break; |
Jens Axboe | fca7035 | 2011-07-06 20:12:54 +0200 | [diff] [blame] | 1868 | case 'j': |
| 1869 | max_jobs = atoi(optarg); |
| 1870 | if (!max_jobs || max_jobs > REAL_MAX_JOBS) { |
| 1871 | log_err("fio: invalid max jobs: %d\n", max_jobs); |
| 1872 | do_exit++; |
| 1873 | exit_val = 1; |
| 1874 | } |
| 1875 | break; |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 1876 | case 'S': |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 1877 | if (nr_clients) { |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 1878 | log_err("fio: can't be both client and server\n"); |
| 1879 | do_exit++; |
| 1880 | exit_val = 1; |
| 1881 | break; |
| 1882 | } |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 1883 | if (optarg) |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 1884 | fio_server_set_arg(optarg); |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 1885 | is_backend = 1; |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 1886 | backend = 1; |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 1887 | break; |
Jens Axboe | e46d809 | 2011-10-03 09:11:02 +0200 | [diff] [blame] | 1888 | case 'D': |
Jens Axboe | 402668f | 2011-10-10 15:28:58 +0200 | [diff] [blame] | 1889 | pid_file = strdup(optarg); |
Jens Axboe | e46d809 | 2011-10-03 09:11:02 +0200 | [diff] [blame] | 1890 | break; |
Huadong Liu | f2a2ce0 | 2013-01-30 13:22:24 +0100 | [diff] [blame] | 1891 | case 'I': |
| 1892 | if ((ret = fio_idle_prof_parse_opt(optarg))) { |
| 1893 | /* exit on error and calibration only */ |
| 1894 | do_exit++; |
| 1895 | if (ret == -1) |
| 1896 | exit_val = 1; |
| 1897 | } |
| 1898 | break; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 1899 | case 'C': |
| 1900 | if (is_backend) { |
| 1901 | log_err("fio: can't be both client and server\n"); |
| 1902 | do_exit++; |
| 1903 | exit_val = 1; |
| 1904 | break; |
| 1905 | } |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1906 | if (fio_client_add(&fio_client_ops, optarg, &cur_client)) { |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 1907 | log_err("fio: failed adding client %s\n", optarg); |
| 1908 | do_exit++; |
| 1909 | exit_val = 1; |
| 1910 | break; |
| 1911 | } |
Jens Axboe | 14ea90e | 2012-08-26 17:33:34 +0200 | [diff] [blame] | 1912 | /* |
| 1913 | * If the next argument exists and isn't an option, |
| 1914 | * assume it's a job file for this client only. |
| 1915 | */ |
| 1916 | while (optind < argc) { |
| 1917 | if (!strncmp(argv[optind], "--", 2) || |
| 1918 | !strncmp(argv[optind], "-", 1)) |
| 1919 | break; |
| 1920 | |
| 1921 | fio_client_add_ini_file(cur_client, argv[optind]); |
| 1922 | optind++; |
| 1923 | } |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 1924 | break; |
Jens Axboe | 7d11f87 | 2012-12-17 12:03:29 +0100 | [diff] [blame] | 1925 | case 'T': |
| 1926 | do_exit++; |
| 1927 | exit_val = fio_monotonic_clocktest(); |
| 1928 | break; |
Jens Axboe | fec0f21 | 2014-02-07 14:39:33 -0700 | [diff] [blame] | 1929 | case 'G': |
| 1930 | do_exit++; |
| 1931 | exit_val = fio_crctest(optarg); |
| 1932 | break; |
Jens Axboe | 0646490 | 2013-04-24 20:38:54 -0600 | [diff] [blame] | 1933 | case 'L': { |
| 1934 | long long val; |
| 1935 | |
Jens Axboe | 0de5b26 | 2014-02-21 15:26:01 -0800 | [diff] [blame] | 1936 | if (check_str_time(optarg, &val, 1)) { |
Jens Axboe | 0646490 | 2013-04-24 20:38:54 -0600 | [diff] [blame] | 1937 | log_err("fio: failed parsing time %s\n", optarg); |
| 1938 | do_exit++; |
| 1939 | exit_val = 1; |
| 1940 | break; |
| 1941 | } |
| 1942 | status_interval = val * 1000; |
| 1943 | break; |
| 1944 | } |
Jens Axboe | 798827c | 2013-01-23 18:11:48 -0700 | [diff] [blame] | 1945 | case '?': |
| 1946 | log_err("%s: unrecognized option '%s'\n", argv[0], |
| 1947 | argv[optind - 1]); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1948 | default: |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1949 | do_exit++; |
| 1950 | exit_val = 1; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1951 | break; |
| 1952 | } |
Jens Axboe | c7d5c94 | 2011-10-03 11:48:17 +0200 | [diff] [blame] | 1953 | if (do_exit) |
| 1954 | break; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1955 | } |
| 1956 | |
Jens Axboe | 0b14f0a | 2013-05-23 21:27:54 +0200 | [diff] [blame] | 1957 | if (do_exit && !(is_backend || nr_clients)) |
| 1958 | exit(exit_val); |
Jens Axboe | 536582b | 2008-02-18 20:26:32 +0100 | [diff] [blame] | 1959 | |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 1960 | if (nr_clients && fio_clients_connect()) { |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 1961 | do_exit++; |
| 1962 | exit_val = 1; |
Jens Axboe | cdf54d8 | 2011-10-04 08:31:40 +0200 | [diff] [blame] | 1963 | return -1; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 1964 | } |
| 1965 | |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 1966 | if (is_backend && backend) |
Jens Axboe | 402668f | 2011-10-10 15:28:58 +0200 | [diff] [blame] | 1967 | return fio_start_server(pid_file); |
Jens Axboe | 50d1697 | 2011-09-29 17:45:28 -0600 | [diff] [blame] | 1968 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1969 | if (td) { |
Jens Axboe | 7d6a890 | 2008-02-18 20:59:18 +0100 | [diff] [blame] | 1970 | if (!ret) |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 1971 | ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1972 | } |
| 1973 | |
Jens Axboe | 7874f8b | 2011-10-06 09:18:20 +0200 | [diff] [blame] | 1974 | while (!ret && optind < argc) { |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1975 | ini_idx++; |
| 1976 | ini_file = realloc(ini_file, ini_idx * sizeof(char *)); |
| 1977 | ini_file[ini_idx - 1] = strdup(argv[optind]); |
| 1978 | optind++; |
| 1979 | } |
| 1980 | |
| 1981 | return ini_idx; |
| 1982 | } |
| 1983 | |
Jens Axboe | 0420ba6 | 2012-02-29 11:16:52 +0100 | [diff] [blame] | 1984 | int fio_init_options(void) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1985 | { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1986 | f_out = stdout; |
| 1987 | f_err = stderr; |
| 1988 | |
Jens Axboe | 4c6107f | 2011-01-18 05:22:22 -0700 | [diff] [blame] | 1989 | fio_options_fill_optstring(); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1990 | fio_options_dup_and_init(l_opts); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1991 | |
Jens Axboe | 9d9eb2e | 2011-10-03 12:01:42 +0200 | [diff] [blame] | 1992 | atexit(free_shm); |
| 1993 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1994 | if (fill_def_thread()) |
| 1995 | return 1; |
| 1996 | |
Jens Axboe | 0420ba6 | 2012-02-29 11:16:52 +0100 | [diff] [blame] | 1997 | return 0; |
| 1998 | } |
| 1999 | |
Jens Axboe | 5116779 | 2012-03-08 21:34:18 +0100 | [diff] [blame] | 2000 | extern int fio_check_options(struct thread_options *); |
| 2001 | |
Jens Axboe | 0420ba6 | 2012-02-29 11:16:52 +0100 | [diff] [blame] | 2002 | int parse_options(int argc, char *argv[]) |
| 2003 | { |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 2004 | const int type = FIO_CLIENT_TYPE_CLI; |
Jens Axboe | 0420ba6 | 2012-02-29 11:16:52 +0100 | [diff] [blame] | 2005 | int job_files, i; |
| 2006 | |
| 2007 | if (fio_init_options()) |
| 2008 | return 1; |
Jens Axboe | 5116779 | 2012-03-08 21:34:18 +0100 | [diff] [blame] | 2009 | if (fio_test_cconv(&def_thread.o)) |
| 2010 | log_err("fio: failed internal cconv test\n"); |
Jens Axboe | 0420ba6 | 2012-02-29 11:16:52 +0100 | [diff] [blame] | 2011 | |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 2012 | job_files = parse_cmd_line(argc, argv, type); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 2013 | |
Jens Axboe | cdf54d8 | 2011-10-04 08:31:40 +0200 | [diff] [blame] | 2014 | if (job_files > 0) { |
| 2015 | for (i = 0; i < job_files; i++) { |
| 2016 | if (fill_def_thread()) |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 2017 | return 1; |
Jens Axboe | cdf54d8 | 2011-10-04 08:31:40 +0200 | [diff] [blame] | 2018 | if (nr_clients) { |
| 2019 | if (fio_clients_send_ini(ini_file[i])) |
| 2020 | return 1; |
| 2021 | free(ini_file[i]); |
| 2022 | } else if (!is_backend) { |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 2023 | if (parse_jobs_ini(ini_file[i], 0, i, type)) |
Jens Axboe | cdf54d8 | 2011-10-04 08:31:40 +0200 | [diff] [blame] | 2024 | return 1; |
| 2025 | free(ini_file[i]); |
| 2026 | } |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 2027 | } |
Jens Axboe | 14ea90e | 2012-08-26 17:33:34 +0200 | [diff] [blame] | 2028 | } else if (nr_clients) { |
| 2029 | if (fill_def_thread()) |
| 2030 | return 1; |
| 2031 | if (fio_clients_send_ini(NULL)) |
| 2032 | return 1; |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 2033 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 2034 | |
Jens Axboe | 88c6ed8 | 2006-06-09 11:28:10 +0200 | [diff] [blame] | 2035 | free(ini_file); |
Jens Axboe | 7e356b2 | 2011-10-14 10:55:16 +0200 | [diff] [blame] | 2036 | fio_options_free(&def_thread); |
Christian Ehrhardt | bcbfeef | 2014-02-20 09:13:06 -0800 | [diff] [blame] | 2037 | filesetup_mem_free(); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 2038 | |
| 2039 | if (!thread_number) { |
Jens Axboe | f9633d7 | 2013-09-06 09:59:56 -0600 | [diff] [blame] | 2040 | if (parse_dryrun()) |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 2041 | return 0; |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 2042 | if (exec_profile) |
| 2043 | return 0; |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 2044 | if (is_backend || nr_clients) |
Jens Axboe | 5c341e9 | 2011-09-29 18:00:35 -0600 | [diff] [blame] | 2045 | return 0; |
Jens Axboe | 085399d | 2011-10-06 09:01:22 +0200 | [diff] [blame] | 2046 | if (did_arg) |
| 2047 | return 0; |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 2048 | |
Jens Axboe | d65e11c | 2011-10-05 09:56:53 +0200 | [diff] [blame] | 2049 | log_err("No jobs(s) defined\n\n"); |
Jens Axboe | 085399d | 2011-10-06 09:01:22 +0200 | [diff] [blame] | 2050 | |
| 2051 | if (!did_arg) { |
| 2052 | usage(argv[0]); |
| 2053 | return 1; |
| 2054 | } |
| 2055 | |
| 2056 | return 0; |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 2057 | } |
| 2058 | |
Jens Axboe | be4ecfd | 2008-12-08 14:10:52 +0100 | [diff] [blame] | 2059 | if (def_thread.o.gtod_offload) { |
| 2060 | fio_gtod_init(); |
| 2061 | fio_gtod_offload = 1; |
| 2062 | fio_gtod_cpu = def_thread.o.gtod_cpu; |
| 2063 | } |
| 2064 | |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 2065 | if (output_format == FIO_OUTPUT_NORMAL) |
Jens Axboe | 3d43382 | 2012-03-21 22:25:22 +0100 | [diff] [blame] | 2066 | log_info("%s\n", fio_version_string); |
Jens Axboe | f6dea4d | 2011-10-13 13:37:07 +0200 | [diff] [blame] | 2067 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 2068 | return 0; |
| 2069 | } |
Jens Axboe | 588b7f0 | 2012-03-19 20:37:41 +0100 | [diff] [blame] | 2070 | |
| 2071 | void options_default_fill(struct thread_options *o) |
| 2072 | { |
| 2073 | memcpy(o, &def_thread.o, sizeof(*o)); |
| 2074 | } |