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> |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 11 | #include <getopt.h> |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 12 | #include <sys/ipc.h> |
| 13 | #include <sys/shm.h> |
| 14 | #include <sys/types.h> |
| 15 | #include <sys/stat.h> |
| 16 | |
| 17 | #include "fio.h" |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 18 | #include "parse.h" |
Jens Axboe | 2e5cdb1 | 2008-03-01 18:52:49 +0100 | [diff] [blame] | 19 | #include "smalloc.h" |
Jens Axboe | 380065a | 2008-03-01 18:56:24 +0100 | [diff] [blame] | 20 | #include "filehash.h" |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 21 | |
Jens Axboe | 112b52d | 2009-02-06 14:12:03 +0100 | [diff] [blame^] | 22 | static char fio_version_string[] = "fio 1.24"; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 23 | |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 24 | #define FIO_RANDSEED (0xb1899bedUL) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 25 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 26 | static char **ini_file; |
| 27 | static int max_jobs = MAX_JOBS; |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 28 | static int dump_cmdline; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 29 | |
Jens Axboe | be4ecfd | 2008-12-08 14:10:52 +0100 | [diff] [blame] | 30 | static struct thread_data def_thread; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 31 | struct thread_data *threads = NULL; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 32 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 33 | int exitall_on_terminate = 0; |
| 34 | int terse_output = 0; |
Aaron Carroll | e592a06 | 2007-09-14 09:49:41 +0200 | [diff] [blame] | 35 | int eta_print; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 36 | unsigned long long mlock_size = 0; |
| 37 | FILE *f_out = NULL; |
| 38 | FILE *f_err = NULL; |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 39 | char *job_section = NULL; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 40 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 41 | int write_bw_log = 0; |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 42 | int read_only = 0; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 43 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 44 | static int def_timeout; |
| 45 | static int write_lat_log; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 46 | |
| 47 | static int prev_group_jobs; |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 48 | |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 49 | unsigned long fio_debug = 0; |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 50 | unsigned int fio_debug_jobno = -1; |
| 51 | unsigned int *fio_debug_jobp = NULL; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 52 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 53 | /* |
| 54 | * Command line options. These will contain the above, plus a few |
| 55 | * extra that only pertain to fio itself and not jobs. |
| 56 | */ |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 57 | static struct option l_opts[FIO_NR_OPTIONS] = { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 58 | { |
| 59 | .name = "output", |
| 60 | .has_arg = required_argument, |
| 61 | .val = 'o', |
| 62 | }, |
| 63 | { |
| 64 | .name = "timeout", |
| 65 | .has_arg = required_argument, |
| 66 | .val = 't', |
| 67 | }, |
| 68 | { |
| 69 | .name = "latency-log", |
| 70 | .has_arg = required_argument, |
| 71 | .val = 'l', |
| 72 | }, |
| 73 | { |
| 74 | .name = "bandwidth-log", |
| 75 | .has_arg = required_argument, |
| 76 | .val = 'b', |
| 77 | }, |
| 78 | { |
| 79 | .name = "minimal", |
| 80 | .has_arg = optional_argument, |
| 81 | .val = 'm', |
| 82 | }, |
| 83 | { |
| 84 | .name = "version", |
| 85 | .has_arg = no_argument, |
| 86 | .val = 'v', |
| 87 | }, |
| 88 | { |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 89 | .name = "help", |
| 90 | .has_arg = no_argument, |
| 91 | .val = 'h', |
| 92 | }, |
| 93 | { |
| 94 | .name = "cmdhelp", |
Jens Axboe | 320beef | 2007-03-01 10:44:12 +0100 | [diff] [blame] | 95 | .has_arg = optional_argument, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 96 | .val = 'c', |
| 97 | }, |
| 98 | { |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 99 | .name = "showcmd", |
| 100 | .has_arg = no_argument, |
Jens Axboe | 724e443 | 2007-09-11 20:02:05 +0200 | [diff] [blame] | 101 | .val = 's', |
| 102 | }, |
| 103 | { |
| 104 | .name = "readonly", |
| 105 | .has_arg = no_argument, |
| 106 | .val = 'r', |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 107 | }, |
| 108 | { |
Aaron Carroll | e592a06 | 2007-09-14 09:49:41 +0200 | [diff] [blame] | 109 | .name = "eta", |
| 110 | .has_arg = required_argument, |
| 111 | .val = 'e', |
| 112 | }, |
| 113 | { |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 114 | .name = "debug", |
| 115 | .has_arg = required_argument, |
| 116 | .val = 'd', |
| 117 | }, |
| 118 | { |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 119 | .name = "section", |
| 120 | .has_arg = required_argument, |
| 121 | .val = 'x', |
| 122 | }, |
| 123 | { |
Jens Axboe | 2b386d2 | 2008-03-26 10:32:57 +0100 | [diff] [blame] | 124 | .name = "alloc-size", |
| 125 | .has_arg = required_argument, |
| 126 | .val = 'a', |
| 127 | }, |
| 128 | { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 129 | .name = NULL, |
| 130 | }, |
| 131 | }; |
| 132 | |
Joel Becker | 9728ce3 | 2007-03-01 08:24:39 +0100 | [diff] [blame] | 133 | FILE *get_f_out() |
| 134 | { |
| 135 | return f_out; |
| 136 | } |
| 137 | |
| 138 | FILE *get_f_err() |
| 139 | { |
| 140 | return f_err; |
| 141 | } |
| 142 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 143 | /* |
| 144 | * Return a free job structure. |
| 145 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 146 | static struct thread_data *get_new_job(int global, struct thread_data *parent) |
| 147 | { |
| 148 | struct thread_data *td; |
| 149 | |
| 150 | if (global) |
| 151 | return &def_thread; |
| 152 | if (thread_number >= max_jobs) |
| 153 | return NULL; |
| 154 | |
| 155 | td = &threads[thread_number++]; |
Jens Axboe | ddaeaa5 | 2006-06-08 11:00:58 +0200 | [diff] [blame] | 156 | *td = *parent; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 157 | |
Jens Axboe | cade3ef | 2007-03-23 15:29:45 +0100 | [diff] [blame] | 158 | dup_files(td, parent); |
Jens Axboe | d23bb32 | 2007-03-23 15:57:56 +0100 | [diff] [blame] | 159 | options_mem_dupe(td); |
Jens Axboe | cade3ef | 2007-03-23 15:29:45 +0100 | [diff] [blame] | 160 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 161 | td->thread_number = thread_number; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 162 | return td; |
| 163 | } |
| 164 | |
| 165 | static void put_job(struct thread_data *td) |
| 166 | { |
Jens Axboe | 549577a | 2006-10-30 12:23:41 +0100 | [diff] [blame] | 167 | if (td == &def_thread) |
| 168 | return; |
| 169 | |
Jens Axboe | 16edf25 | 2007-02-10 14:59:22 +0100 | [diff] [blame] | 170 | if (td->error) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 171 | log_info("fio: %s\n", td->verror); |
Jens Axboe | 16edf25 | 2007-02-10 14:59:22 +0100 | [diff] [blame] | 172 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 173 | memset(&threads[td->thread_number - 1], 0, sizeof(*td)); |
| 174 | thread_number--; |
| 175 | } |
| 176 | |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 177 | static int setup_rate(struct thread_data *td) |
| 178 | { |
| 179 | unsigned long nr_reads_per_msec; |
| 180 | unsigned long long rate; |
| 181 | unsigned int bs; |
| 182 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 183 | if (!td->o.rate && !td->o.rate_iops) |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 184 | return 0; |
| 185 | |
| 186 | if (td_rw(td)) |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 187 | bs = td->o.rw_min_bs; |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 188 | else if (td_read(td)) |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 189 | bs = td->o.min_bs[DDIR_READ]; |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 190 | else |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 191 | bs = td->o.min_bs[DDIR_WRITE]; |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 192 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 193 | if (td->o.rate) { |
| 194 | rate = td->o.rate; |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 195 | nr_reads_per_msec = (rate * 1024 * 1000LL) / bs; |
| 196 | } else |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 197 | nr_reads_per_msec = td->o.rate_iops * 1000UL; |
Jens Axboe | 127f686 | 2007-03-15 12:09:57 +0100 | [diff] [blame] | 198 | |
| 199 | if (!nr_reads_per_msec) { |
| 200 | log_err("rate lower than supported\n"); |
| 201 | return -1; |
| 202 | } |
| 203 | |
| 204 | td->rate_usec_cycle = 1000000000ULL / nr_reads_per_msec; |
| 205 | td->rate_pending_usleep = 0; |
| 206 | return 0; |
| 207 | } |
| 208 | |
Jens Axboe | dad915e | 2006-10-27 11:10:18 +0200 | [diff] [blame] | 209 | /* |
| 210 | * Lazy way of fixing up options that depend on each other. We could also |
| 211 | * define option callback handlers, but this is easier. |
| 212 | */ |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 213 | static int fixup_options(struct thread_data *td) |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 214 | { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 215 | struct thread_options *o = &td->o; |
Jens Axboe | dad915e | 2006-10-27 11:10:18 +0200 | [diff] [blame] | 216 | |
Jens Axboe | f356d01 | 2009-01-05 09:56:29 +0100 | [diff] [blame] | 217 | #ifndef FIO_HAVE_PSHARED_MUTEX |
| 218 | if (!td->o.use_thread) { |
| 219 | log_info("fio: this platform does not support process shared" |
| 220 | " mutexes, forcing use of threads. Use the 'thread'" |
| 221 | " option to get rid of this warning.\n"); |
| 222 | td->o.use_thread = 1; |
| 223 | } |
| 224 | #endif |
| 225 | |
Jens Axboe | be4ecfd | 2008-12-08 14:10:52 +0100 | [diff] [blame] | 226 | #ifndef FIO_HAVE_CPU_AFFINITY |
| 227 | if (td->o.gtod_cpu) { |
| 228 | log_err("fio: platform must support CPU affinity for" |
| 229 | "gettimeofday() offloading\n"); |
| 230 | return 1; |
| 231 | } |
| 232 | #endif |
| 233 | |
Jens Axboe | 724e443 | 2007-09-11 20:02:05 +0200 | [diff] [blame] | 234 | if (read_only && td_write(td)) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 235 | log_err("fio: job <%s> has write bit set, but fio is in" |
| 236 | " read-only mode\n", td->o.name); |
Jens Axboe | 724e443 | 2007-09-11 20:02:05 +0200 | [diff] [blame] | 237 | return 1; |
| 238 | } |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 239 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 240 | if (o->write_iolog_file && o->read_iolog_file) { |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 241 | log_err("fio: read iolog overrides write_iolog\n"); |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 242 | free(o->write_iolog_file); |
| 243 | o->write_iolog_file = NULL; |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 244 | } |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 245 | |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 246 | /* |
| 247 | * only really works for sequential io for now, and with 1 file |
| 248 | */ |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 249 | if (o->zone_size && td_random(td) && o->open_files == 1) |
| 250 | o->zone_size = 0; |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 251 | |
| 252 | /* |
| 253 | * Reads can do overwrites, we always need to pre-create the file |
| 254 | */ |
| 255 | if (td_read(td) || td_rw(td)) |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 256 | o->overwrite = 1; |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 257 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 258 | if (!o->min_bs[DDIR_READ]) |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 259 | o->min_bs[DDIR_READ] = o->bs[DDIR_READ]; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 260 | if (!o->max_bs[DDIR_READ]) |
| 261 | o->max_bs[DDIR_READ] = o->bs[DDIR_READ]; |
| 262 | if (!o->min_bs[DDIR_WRITE]) |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 263 | o->min_bs[DDIR_WRITE] = o->bs[DDIR_WRITE]; |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 264 | if (!o->max_bs[DDIR_WRITE]) |
| 265 | o->max_bs[DDIR_WRITE] = o->bs[DDIR_WRITE]; |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 266 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 267 | o->rw_min_bs = min(o->min_bs[DDIR_READ], o->min_bs[DDIR_WRITE]); |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 268 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 269 | if (!o->file_size_high) |
| 270 | o->file_size_high = o->file_size_low; |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 271 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 272 | if (o->norandommap && o->verify != VERIFY_NONE) { |
Jens Axboe | bb8895e | 2006-10-30 15:14:48 +0100 | [diff] [blame] | 273 | log_err("fio: norandommap given, verify disabled\n"); |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 274 | o->verify = VERIFY_NONE; |
Jens Axboe | bb8895e | 2006-10-30 15:14:48 +0100 | [diff] [blame] | 275 | } |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 276 | if (o->bs_unaligned && (o->odirect || td->io_ops->flags & FIO_RAWIO)) |
Jens Axboe | 690adba | 2006-10-30 15:25:09 +0100 | [diff] [blame] | 277 | log_err("fio: bs_unaligned may not work with raw io\n"); |
Jens Axboe | e0a2233 | 2006-12-20 12:54:25 +0100 | [diff] [blame] | 278 | |
| 279 | /* |
Jens Axboe | 48097d5 | 2007-02-17 06:30:44 +0100 | [diff] [blame] | 280 | * thinktime_spin must be less than thinktime |
| 281 | */ |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 282 | if (o->thinktime_spin > o->thinktime) |
| 283 | o->thinktime_spin = o->thinktime; |
Jens Axboe | e916b39 | 2007-02-20 14:37:26 +0100 | [diff] [blame] | 284 | |
| 285 | /* |
| 286 | * The low water mark cannot be bigger than the iodepth |
| 287 | */ |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 288 | if (o->iodepth_low > o->iodepth || !o->iodepth_low) { |
Jens Axboe | 9467b77 | 2007-02-27 19:56:43 +0100 | [diff] [blame] | 289 | /* |
| 290 | * syslet work around - if the workload is sequential, |
| 291 | * we want to let the queue drain all the way down to |
| 292 | * avoid seeking between async threads |
| 293 | */ |
| 294 | if (!strcmp(td->io_ops->name, "syslet-rw") && !td_random(td)) |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 295 | o->iodepth_low = 1; |
Jens Axboe | 9467b77 | 2007-02-27 19:56:43 +0100 | [diff] [blame] | 296 | else |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 297 | o->iodepth_low = o->iodepth; |
Jens Axboe | 9467b77 | 2007-02-27 19:56:43 +0100 | [diff] [blame] | 298 | } |
Jens Axboe | cb5ab51 | 2007-02-26 12:57:09 +0100 | [diff] [blame] | 299 | |
| 300 | /* |
| 301 | * If batch number isn't set, default to the same as iodepth |
| 302 | */ |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 303 | if (o->iodepth_batch > o->iodepth || !o->iodepth_batch) |
| 304 | o->iodepth_batch = o->iodepth; |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 305 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 306 | if (o->nr_files > td->files_index) |
| 307 | o->nr_files = td->files_index; |
Jens Axboe | 9f9214f | 2007-03-13 14:02:16 +0100 | [diff] [blame] | 308 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 309 | if (o->open_files > o->nr_files || !o->open_files) |
| 310 | o->open_files = o->nr_files; |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 311 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 312 | if ((o->rate && o->rate_iops) || (o->ratemin && o->rate_iops_min)) { |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 313 | log_err("fio: rate and rate_iops are mutually exclusive\n"); |
| 314 | return 1; |
| 315 | } |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 316 | if ((o->rate < o->ratemin) || (o->rate_iops < o->rate_iops_min)) { |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 317 | log_err("fio: minimum rate exceeds rate\n"); |
| 318 | return 1; |
| 319 | } |
| 320 | |
Jens Axboe | cf4464c | 2007-04-17 20:14:42 +0200 | [diff] [blame] | 321 | if (!o->timeout && o->time_based) { |
| 322 | log_err("fio: time_based requires a runtime/timeout setting\n"); |
| 323 | o->time_based = 0; |
| 324 | } |
| 325 | |
Shawn Lewis | aa31f1f | 2008-01-11 09:45:11 +0100 | [diff] [blame] | 326 | if (o->fill_device && !o->size) |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 327 | o->size = -1ULL; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 328 | |
Jens Axboe | 7971314 | 2008-02-06 14:40:14 +0100 | [diff] [blame] | 329 | if (td_rw(td) && td->o.verify != VERIFY_NONE) |
| 330 | log_info("fio: mixed read/write workload with verify. May not " |
| 331 | "work as expected, unless you pre-populated the file\n"); |
Shawn Lewis | aa31f1f | 2008-01-11 09:45:11 +0100 | [diff] [blame] | 332 | |
Jens Axboe | 41ccd84 | 2008-05-22 09:17:33 +0200 | [diff] [blame] | 333 | if (td->o.verify != VERIFY_NONE) |
| 334 | td->o.refill_buffers = 1; |
| 335 | |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 336 | return 0; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 339 | /* |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 340 | * This function leaks the buffer |
| 341 | */ |
| 342 | static char *to_kmg(unsigned int val) |
| 343 | { |
| 344 | char *buf = malloc(32); |
Jens Axboe | f3502ba | 2007-02-14 01:27:09 +0100 | [diff] [blame] | 345 | char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 }; |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 346 | char *p = post; |
| 347 | |
Jens Axboe | 245142f | 2006-11-08 12:49:21 +0100 | [diff] [blame] | 348 | do { |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 349 | if (val & 1023) |
| 350 | break; |
| 351 | |
| 352 | val >>= 10; |
| 353 | p++; |
Jens Axboe | 245142f | 2006-11-08 12:49:21 +0100 | [diff] [blame] | 354 | } while (*p); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 355 | |
| 356 | snprintf(buf, 31, "%u%c", val, *p); |
| 357 | return buf; |
| 358 | } |
| 359 | |
Jens Axboe | 09629a9 | 2007-03-09 09:00:06 +0100 | [diff] [blame] | 360 | /* External engines are specified by "external:name.o") */ |
| 361 | static const char *get_engine_name(const char *str) |
| 362 | { |
| 363 | char *p = strstr(str, ":"); |
| 364 | |
| 365 | if (!p) |
| 366 | return str; |
| 367 | |
| 368 | p++; |
| 369 | strip_blank_front(&p); |
| 370 | strip_blank_end(p); |
| 371 | return p; |
| 372 | } |
| 373 | |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 374 | static int exists_and_not_file(const char *filename) |
| 375 | { |
| 376 | struct stat sb; |
| 377 | |
| 378 | if (lstat(filename, &sb) == -1) |
| 379 | return 0; |
| 380 | |
| 381 | if (S_ISREG(sb.st_mode)) |
| 382 | return 0; |
| 383 | |
| 384 | return 1; |
| 385 | } |
| 386 | |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 387 | /* |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 388 | * Initialize the various random states we need (random io, block size ranges, |
| 389 | * read/write mix, etc). |
| 390 | */ |
| 391 | static int init_random_state(struct thread_data *td) |
| 392 | { |
| 393 | unsigned long seeds[6]; |
Jens Axboe | 6872707 | 2007-03-15 20:49:25 +0100 | [diff] [blame] | 394 | int fd; |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 395 | |
| 396 | fd = open("/dev/urandom", O_RDONLY); |
| 397 | if (fd == -1) { |
| 398 | td_verror(td, errno, "open"); |
| 399 | return 1; |
| 400 | } |
| 401 | |
| 402 | if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) { |
| 403 | td_verror(td, EIO, "read"); |
| 404 | close(fd); |
| 405 | return 1; |
| 406 | } |
| 407 | |
| 408 | close(fd); |
| 409 | |
| 410 | os_random_seed(seeds[0], &td->bsrange_state); |
| 411 | os_random_seed(seeds[1], &td->verify_state); |
| 412 | os_random_seed(seeds[2], &td->rwmix_state); |
| 413 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 414 | if (td->o.file_service_type == FIO_FSERVICE_RANDOM) |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 415 | os_random_seed(seeds[3], &td->next_file_state); |
| 416 | |
| 417 | os_random_seed(seeds[5], &td->file_size_state); |
| 418 | |
| 419 | if (!td_random(td)) |
| 420 | return 0; |
| 421 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 422 | if (td->o.rand_repeatable) |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 423 | seeds[4] = FIO_RANDSEED * td->thread_number; |
| 424 | |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 425 | os_random_seed(seeds[4], &td->random_state); |
| 426 | return 0; |
| 427 | } |
| 428 | |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 429 | /* |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 430 | * Adds a job to the list of things todo. Sanitizes the various options |
| 431 | * to make sure we don't have conflicts, and initializes various |
| 432 | * members of td. |
| 433 | */ |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 434 | static int add_job(struct thread_data *td, const char *jobname, int job_add_num) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 435 | { |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame] | 436 | const char *ddir_str[] = { NULL, "read", "write", "rw", NULL, |
| 437 | "randread", "randwrite", "randrw" }; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 438 | unsigned int i; |
Jens Axboe | 09629a9 | 2007-03-09 09:00:06 +0100 | [diff] [blame] | 439 | const char *engine; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 440 | char fname[PATH_MAX]; |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 441 | int numjobs, file_alloced; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 442 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 443 | /* |
| 444 | * the def_thread is just for options, it's not a real job |
| 445 | */ |
| 446 | if (td == &def_thread) |
| 447 | return 0; |
| 448 | |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 449 | /* |
| 450 | * if we are just dumping the output command line, don't add the job |
| 451 | */ |
| 452 | if (dump_cmdline) { |
| 453 | put_job(td); |
| 454 | return 0; |
| 455 | } |
| 456 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 457 | engine = get_engine_name(td->o.ioengine); |
Jens Axboe | 09629a9 | 2007-03-09 09:00:06 +0100 | [diff] [blame] | 458 | td->io_ops = load_ioengine(td, engine); |
| 459 | if (!td->io_ops) { |
| 460 | log_err("fio: failed to load engine %s\n", engine); |
Jens Axboe | 205927a | 2007-03-15 11:06:32 +0100 | [diff] [blame] | 461 | goto err; |
Jens Axboe | 09629a9 | 2007-03-09 09:00:06 +0100 | [diff] [blame] | 462 | } |
Jens Axboe | df64119 | 2006-10-12 07:55:41 +0200 | [diff] [blame] | 463 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 464 | if (td->o.use_thread) |
Jens Axboe | 9cedf16 | 2007-03-12 11:29:30 +0100 | [diff] [blame] | 465 | nr_thread++; |
| 466 | else |
| 467 | nr_process++; |
| 468 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 469 | if (td->o.odirect) |
Jens Axboe | 690adba | 2006-10-30 15:25:09 +0100 | [diff] [blame] | 470 | td->io_ops->flags |= FIO_RAWIO; |
| 471 | |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 472 | file_alloced = 0; |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 473 | if (!td->o.filename && !td->files_index && !td->o.read_iolog_file) { |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 474 | file_alloced = 1; |
Jens Axboe | 80be24f | 2007-03-12 11:01:25 +0100 | [diff] [blame] | 475 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 476 | if (td->o.nr_files == 1 && exists_and_not_file(jobname)) |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 477 | add_file(td, jobname); |
Jens Axboe | 7b05a21 | 2007-03-13 11:17:07 +0100 | [diff] [blame] | 478 | else { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 479 | for (i = 0; i < td->o.nr_files; i++) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 480 | sprintf(fname, "%s.%d.%d", jobname, |
| 481 | td->thread_number, i); |
Jens Axboe | 7b05a21 | 2007-03-13 11:17:07 +0100 | [diff] [blame] | 482 | add_file(td, fname); |
| 483 | } |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 484 | } |
Jens Axboe | 0af7b54 | 2006-02-17 10:10:12 +0100 | [diff] [blame] | 485 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 486 | |
Jens Axboe | 4e991c2 | 2007-03-15 11:41:11 +0100 | [diff] [blame] | 487 | if (fixup_options(td)) |
| 488 | goto err; |
Jens Axboe | e0a2233 | 2006-12-20 12:54:25 +0100 | [diff] [blame] | 489 | |
Jens Axboe | 07eb79d | 2007-04-12 13:02:38 +0200 | [diff] [blame] | 490 | if (td->io_ops->flags & FIO_DISKLESSIO) { |
| 491 | struct fio_file *f; |
| 492 | |
| 493 | for_each_file(td, f, i) |
| 494 | f->real_file_size = -1ULL; |
| 495 | } |
| 496 | |
Jens Axboe | cdd18ad | 2008-02-27 18:58:00 +0100 | [diff] [blame] | 497 | td->mutex = fio_mutex_init(0); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 498 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 499 | td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX; |
| 500 | td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX; |
| 501 | td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX; |
Jens Axboe | 1e3d53a | 2007-03-22 19:01:48 +0100 | [diff] [blame] | 502 | td->ddir_nr = td->o.ddir_nr; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 503 | |
Jens Axboe | b3d62a7 | 2007-03-20 14:23:26 +0100 | [diff] [blame] | 504 | if ((td->o.stonewall || td->o.numjobs > 1 || td->o.new_group) |
| 505 | && prev_group_jobs) { |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 506 | prev_group_jobs = 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 507 | groupid++; |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 508 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 509 | |
| 510 | td->groupid = groupid; |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 511 | prev_group_jobs++; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 512 | |
Jens Axboe | 9c60ce6 | 2007-03-15 09:14:47 +0100 | [diff] [blame] | 513 | if (init_random_state(td)) |
| 514 | goto err; |
| 515 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 516 | if (setup_rate(td)) |
| 517 | goto err; |
| 518 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 519 | if (td->o.write_lat_log) { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 520 | setup_log(&td->ts.slat_log); |
| 521 | setup_log(&td->ts.clat_log); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 522 | } |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 523 | if (td->o.write_bw_log) |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 524 | setup_log(&td->ts.bw_log); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 525 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 526 | if (!td->o.name) |
| 527 | td->o.name = strdup(jobname); |
Jens Axboe | 0145205 | 2006-06-07 10:29:47 +0200 | [diff] [blame] | 528 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 529 | if (!terse_output) { |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 530 | if (!job_add_num) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 531 | if (!strcmp(td->io_ops->name, "cpuio")) { |
| 532 | log_info("%s: ioengine=cpu, cpuload=%u," |
| 533 | " cpucycle=%u\n", td->o.name, |
| 534 | td->o.cpuload, |
| 535 | td->o.cpucycle); |
| 536 | } else { |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 537 | char *c1, *c2, *c3, *c4; |
| 538 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 539 | c1 = to_kmg(td->o.min_bs[DDIR_READ]); |
| 540 | c2 = to_kmg(td->o.max_bs[DDIR_READ]); |
| 541 | c3 = to_kmg(td->o.min_bs[DDIR_WRITE]); |
| 542 | c4 = to_kmg(td->o.max_bs[DDIR_WRITE]); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 543 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 544 | log_info("%s: (g=%d): rw=%s, bs=%s-%s/%s-%s," |
| 545 | " ioengine=%s, iodepth=%u\n", |
| 546 | td->o.name, td->groupid, |
| 547 | ddir_str[td->o.td_ddir], |
| 548 | c1, c2, c3, c4, |
| 549 | td->io_ops->name, |
| 550 | td->o.iodepth); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 551 | |
| 552 | free(c1); |
| 553 | free(c2); |
| 554 | free(c3); |
| 555 | free(c4); |
| 556 | } |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 557 | } else if (job_add_num == 1) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 558 | log_info("...\n"); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 559 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 560 | |
| 561 | /* |
| 562 | * recurse add identical jobs, clear numjobs and stonewall options |
| 563 | * as they don't apply to sub-jobs |
| 564 | */ |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 565 | numjobs = td->o.numjobs; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 566 | while (--numjobs) { |
| 567 | struct thread_data *td_new = get_new_job(0, td); |
| 568 | |
| 569 | if (!td_new) |
| 570 | goto err; |
| 571 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 572 | td_new->o.numjobs = 1; |
| 573 | td_new->o.stonewall = 0; |
Jens Axboe | 92c1d41 | 2007-03-28 10:04:08 +0200 | [diff] [blame] | 574 | td_new->o.new_group = 0; |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 575 | |
| 576 | if (file_alloced) { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 577 | td_new->o.filename = NULL; |
Jens Axboe | e132cba | 2007-03-14 14:23:54 +0100 | [diff] [blame] | 578 | td_new->files_index = 0; |
| 579 | td_new->files = NULL; |
| 580 | } |
| 581 | |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 582 | job_add_num = numjobs - 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 583 | |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 584 | if (add_job(td_new, jobname, job_add_num)) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 585 | goto err; |
| 586 | } |
Jens Axboe | 3c5df6f | 2007-03-12 15:09:24 +0100 | [diff] [blame] | 587 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 588 | return 0; |
| 589 | err: |
| 590 | put_job(td); |
| 591 | return -1; |
| 592 | } |
| 593 | |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 594 | static int skip_this_section(const char *name) |
| 595 | { |
| 596 | if (!job_section) |
| 597 | return 0; |
| 598 | if (!strncmp(name, "global", 6)) |
| 599 | return 0; |
| 600 | |
| 601 | return strncmp(job_section, name, strlen(job_section)); |
| 602 | } |
| 603 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 604 | static int is_empty_or_comment(char *line) |
| 605 | { |
| 606 | unsigned int i; |
| 607 | |
| 608 | for (i = 0; i < strlen(line); i++) { |
| 609 | if (line[i] == ';') |
| 610 | return 1; |
Ingo Molnar | 5cc2da3 | 2007-02-20 10:19:44 +0100 | [diff] [blame] | 611 | if (line[i] == '#') |
| 612 | return 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 613 | if (!isspace(line[i]) && !iscntrl(line[i])) |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | return 1; |
| 618 | } |
| 619 | |
Jens Axboe | 313cb20 | 2006-12-21 09:50:00 +0100 | [diff] [blame] | 620 | /* |
Jens Axboe | 0726198 | 2006-06-07 10:51:12 +0200 | [diff] [blame] | 621 | * This is our [ini] type file parser. |
| 622 | */ |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 623 | static int parse_jobs_ini(char *file, int stonewall_flag) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 624 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 625 | unsigned int global; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 626 | struct thread_data *td; |
Jens Axboe | fee3bb4 | 2006-10-30 13:32:08 +0100 | [diff] [blame] | 627 | char *string, *name; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 628 | FILE *f; |
| 629 | char *p; |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 630 | int ret = 0, stonewall; |
Jens Axboe | 097b299 | 2007-04-19 09:41:45 +0200 | [diff] [blame] | 631 | int first_sect = 1; |
Jens Axboe | ccf8f12 | 2007-09-27 10:48:55 +0200 | [diff] [blame] | 632 | int skip_fgets = 0; |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 633 | int inside_skip = 0; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 634 | char **opts; |
| 635 | int i, alloc_opts, num_opts; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 636 | |
Aaron Carroll | 5a729cb | 2007-09-27 09:03:55 +0200 | [diff] [blame] | 637 | if (!strcmp(file, "-")) |
| 638 | f = stdin; |
| 639 | else |
| 640 | f = fopen(file, "r"); |
| 641 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 642 | if (!f) { |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 643 | perror("fopen job file"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 644 | return 1; |
| 645 | } |
| 646 | |
| 647 | string = malloc(4096); |
Jens Axboe | 7f7e6e5 | 2007-07-19 14:50:05 +0200 | [diff] [blame] | 648 | |
| 649 | /* |
| 650 | * it's really 256 + small bit, 280 should suffice |
| 651 | */ |
| 652 | name = malloc(280); |
| 653 | memset(name, 0, 280); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 654 | |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 655 | alloc_opts = 8; |
| 656 | opts = malloc(sizeof(char *) * alloc_opts); |
Jens Axboe | b7c6302 | 2008-06-11 11:47:56 +0200 | [diff] [blame] | 657 | num_opts = 0; |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 658 | |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 659 | stonewall = stonewall_flag; |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 660 | do { |
Jens Axboe | ccf8f12 | 2007-09-27 10:48:55 +0200 | [diff] [blame] | 661 | /* |
| 662 | * if skip_fgets is set, we already have loaded a line we |
| 663 | * haven't handled. |
| 664 | */ |
| 665 | if (!skip_fgets) { |
| 666 | p = fgets(string, 4095, f); |
| 667 | if (!p) |
| 668 | break; |
| 669 | } |
gurudas pai | cdc7f19 | 2007-03-29 10:10:56 +0200 | [diff] [blame] | 670 | |
Jens Axboe | ccf8f12 | 2007-09-27 10:48:55 +0200 | [diff] [blame] | 671 | skip_fgets = 0; |
gurudas pai | cdc7f19 | 2007-03-29 10:10:56 +0200 | [diff] [blame] | 672 | strip_blank_front(&p); |
Jens Axboe | 6c7c7da | 2007-03-29 14:12:57 -0800 | [diff] [blame] | 673 | strip_blank_end(p); |
gurudas pai | cdc7f19 | 2007-03-29 10:10:56 +0200 | [diff] [blame] | 674 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 675 | if (is_empty_or_comment(p)) |
| 676 | continue; |
Jens Axboe | 6c7c7da | 2007-03-29 14:12:57 -0800 | [diff] [blame] | 677 | if (sscanf(p, "[%255s]", name) != 1) { |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 678 | if (inside_skip) |
| 679 | continue; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 680 | log_err("fio: option <%s> outside of [] job section\n", |
| 681 | p); |
Jens Axboe | 088b420 | 2007-07-19 14:53:01 +0200 | [diff] [blame] | 682 | break; |
Jens Axboe | 6c7c7da | 2007-03-29 14:12:57 -0800 | [diff] [blame] | 683 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 684 | |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 685 | if (skip_this_section(name)) { |
| 686 | inside_skip = 1; |
| 687 | continue; |
| 688 | } else |
| 689 | inside_skip = 0; |
| 690 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 691 | global = !strncmp(name, "global", 6); |
| 692 | |
| 693 | name[strlen(name) - 1] = '\0'; |
| 694 | |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 695 | if (dump_cmdline) { |
Jens Axboe | 097b299 | 2007-04-19 09:41:45 +0200 | [diff] [blame] | 696 | if (first_sect) |
| 697 | log_info("fio "); |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 698 | if (!global) |
| 699 | log_info("--name=%s ", name); |
Jens Axboe | 097b299 | 2007-04-19 09:41:45 +0200 | [diff] [blame] | 700 | first_sect = 0; |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 701 | } |
| 702 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 703 | td = get_new_job(global, &def_thread); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 704 | if (!td) { |
| 705 | ret = 1; |
| 706 | break; |
| 707 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 708 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 709 | /* |
| 710 | * Seperate multiple job files by a stonewall |
| 711 | */ |
Jens Axboe | f948191 | 2006-06-09 11:37:28 +0200 | [diff] [blame] | 712 | if (!global && stonewall) { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 713 | td->o.stonewall = stonewall; |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 714 | stonewall = 0; |
| 715 | } |
| 716 | |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 717 | num_opts = 0; |
| 718 | memset(opts, 0, alloc_opts * sizeof(char *)); |
| 719 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 720 | while ((p = fgets(string, 4096, f)) != NULL) { |
| 721 | if (is_empty_or_comment(p)) |
| 722 | continue; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 723 | |
Jens Axboe | b6754f9 | 2006-05-30 14:29:32 +0200 | [diff] [blame] | 724 | strip_blank_front(&p); |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 725 | |
Jens Axboe | ccf8f12 | 2007-09-27 10:48:55 +0200 | [diff] [blame] | 726 | /* |
| 727 | * new section, break out and make sure we don't |
| 728 | * fgets() a new line at the top. |
| 729 | */ |
| 730 | if (p[0] == '[') { |
| 731 | skip_fgets = 1; |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 732 | break; |
Jens Axboe | ccf8f12 | 2007-09-27 10:48:55 +0200 | [diff] [blame] | 733 | } |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 734 | |
Jens Axboe | 4ae3f76 | 2006-05-30 13:35:14 +0200 | [diff] [blame] | 735 | strip_blank_end(p); |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 736 | |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 737 | if (num_opts == alloc_opts) { |
| 738 | alloc_opts <<= 1; |
| 739 | opts = realloc(opts, |
| 740 | alloc_opts * sizeof(char *)); |
| 741 | } |
| 742 | |
| 743 | opts[num_opts] = strdup(p); |
| 744 | num_opts++; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 745 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 746 | |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 747 | ret = fio_options_parse(td, opts, num_opts); |
| 748 | if (!ret) { |
| 749 | if (dump_cmdline) |
| 750 | for (i = 0; i < num_opts; i++) |
| 751 | log_info("--%s ", opts[i]); |
| 752 | |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 753 | ret = add_job(td, name, 0); |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 754 | } else { |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 755 | log_err("fio: job %s dropped\n", name); |
| 756 | put_job(td); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 757 | } |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 758 | |
| 759 | for (i = 0; i < num_opts; i++) |
| 760 | free(opts[i]); |
| 761 | num_opts = 0; |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 762 | } while (!ret); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 763 | |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 764 | if (dump_cmdline) |
| 765 | log_info("\n"); |
| 766 | |
Jens Axboe | 3b8b713 | 2008-06-10 19:46:23 +0200 | [diff] [blame] | 767 | for (i = 0; i < num_opts; i++) |
| 768 | free(opts[i]); |
| 769 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 770 | free(string); |
| 771 | free(name); |
Jens Axboe | 2577594 | 2008-06-10 20:26:06 +0200 | [diff] [blame] | 772 | free(opts); |
Aaron Carroll | 5a729cb | 2007-09-27 09:03:55 +0200 | [diff] [blame] | 773 | if (f != stdin) |
| 774 | fclose(f); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 775 | return ret; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | static int fill_def_thread(void) |
| 779 | { |
| 780 | memset(&def_thread, 0, sizeof(def_thread)); |
| 781 | |
Jens Axboe | 375b269 | 2007-05-22 09:13:02 +0200 | [diff] [blame] | 782 | fio_getaffinity(getpid(), &def_thread.o.cpumask); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 783 | |
| 784 | /* |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 785 | * fill default options |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 786 | */ |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 787 | fio_fill_default_options(&def_thread); |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 788 | |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 789 | def_thread.o.timeout = def_timeout; |
| 790 | def_thread.o.write_bw_log = write_bw_log; |
| 791 | def_thread.o.write_lat_log = write_lat_log; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 792 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 793 | return 0; |
| 794 | } |
| 795 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 796 | static void free_shm(void) |
| 797 | { |
| 798 | struct shmid_ds sbuf; |
| 799 | |
| 800 | if (threads) { |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 801 | void *tp = threads; |
| 802 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 803 | threads = NULL; |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 804 | file_hash_exit(); |
| 805 | fio_debug_jobp = NULL; |
| 806 | shmdt(tp); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 807 | shmctl(shm_id, IPC_RMID, &sbuf); |
| 808 | } |
Jens Axboe | 2e5cdb1 | 2008-03-01 18:52:49 +0100 | [diff] [blame] | 809 | |
| 810 | scleanup(); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 811 | } |
| 812 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 813 | /* |
| 814 | * The thread area is shared between the main process and the job |
| 815 | * threads/processes. So setup a shared memory segment that will hold |
Jens Axboe | 380065a | 2008-03-01 18:56:24 +0100 | [diff] [blame] | 816 | * all the job info. We use the end of the region for keeping track of |
| 817 | * open files across jobs, for file sharing. |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 818 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 819 | static int setup_thread_area(void) |
| 820 | { |
Jens Axboe | 380065a | 2008-03-01 18:56:24 +0100 | [diff] [blame] | 821 | void *hash; |
| 822 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 823 | /* |
| 824 | * 1024 is too much on some machines, scale max_jobs if |
| 825 | * we get a failure that looks like too large a shm segment |
| 826 | */ |
| 827 | do { |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 828 | size_t size = max_jobs * sizeof(struct thread_data); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 829 | |
Jens Axboe | 380065a | 2008-03-01 18:56:24 +0100 | [diff] [blame] | 830 | size += file_hash_size; |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 831 | size += sizeof(unsigned int); |
Jens Axboe | 380065a | 2008-03-01 18:56:24 +0100 | [diff] [blame] | 832 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 833 | shm_id = shmget(0, size, IPC_CREAT | 0600); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 834 | if (shm_id != -1) |
| 835 | break; |
| 836 | if (errno != EINVAL) { |
| 837 | perror("shmget"); |
| 838 | break; |
| 839 | } |
| 840 | |
| 841 | max_jobs >>= 1; |
| 842 | } while (max_jobs); |
| 843 | |
| 844 | if (shm_id == -1) |
| 845 | return 1; |
| 846 | |
| 847 | threads = shmat(shm_id, NULL, 0); |
| 848 | if (threads == (void *) -1) { |
| 849 | perror("shmat"); |
| 850 | return 1; |
| 851 | } |
| 852 | |
Jens Axboe | 1f809d1 | 2007-10-25 18:34:02 +0200 | [diff] [blame] | 853 | memset(threads, 0, max_jobs * sizeof(struct thread_data)); |
Jens Axboe | 380065a | 2008-03-01 18:56:24 +0100 | [diff] [blame] | 854 | hash = (void *) threads + max_jobs * sizeof(struct thread_data); |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 855 | fio_debug_jobp = (void *) hash + file_hash_size; |
| 856 | *fio_debug_jobp = -1; |
Jens Axboe | 380065a | 2008-03-01 18:56:24 +0100 | [diff] [blame] | 857 | file_hash_init(hash); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 858 | atexit(free_shm); |
| 859 | return 0; |
| 860 | } |
| 861 | |
Jens Axboe | 45378b3 | 2007-12-19 13:54:38 +0100 | [diff] [blame] | 862 | static void usage(const char *name) |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 863 | { |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 864 | printf("%s\n", fio_version_string); |
Jens Axboe | 45378b3 | 2007-12-19 13:54:38 +0100 | [diff] [blame] | 865 | printf("%s [options] [job options] <job file(s)>\n", name); |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 866 | printf("\t--debug=options\tEnable debug logging\n"); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 867 | printf("\t--output\tWrite output to file\n"); |
| 868 | printf("\t--timeout\tRuntime in seconds\n"); |
| 869 | printf("\t--latency-log\tGenerate per-job latency logs\n"); |
| 870 | printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n"); |
| 871 | printf("\t--minimal\tMinimal (terse) output\n"); |
| 872 | printf("\t--version\tPrint version info and exit\n"); |
| 873 | printf("\t--help\t\tPrint this page\n"); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 874 | printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of" |
| 875 | " them\n"); |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 876 | printf("\t--showcmd\tTurn a job file into command line options\n"); |
Aaron Carroll | e592a06 | 2007-09-14 09:49:41 +0200 | [diff] [blame] | 877 | printf("\t--eta=when\tWhen ETA estimate should be printed\n"); |
| 878 | printf("\t \tMay be \"always\", \"never\" or \"auto\"\n"); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 879 | printf("\t--readonly\tTurn on safety read-only checks, preventing" |
| 880 | " writes\n"); |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 881 | printf("\t--section=name\tOnly run specified section in job file\n"); |
Jens Axboe | 2b386d2 | 2008-03-26 10:32:57 +0100 | [diff] [blame] | 882 | printf("\t--alloc-size=kb\tSet smalloc pool to this size in kb" |
| 883 | " (def 1024)\n"); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 884 | } |
| 885 | |
Jens Axboe | 79e48f7 | 2008-02-01 20:37:09 +0100 | [diff] [blame] | 886 | #ifdef FIO_INC_DEBUG |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 887 | struct debug_level debug_levels[] = { |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 888 | { .name = "process", .shift = FD_PROCESS, }, |
| 889 | { .name = "file", .shift = FD_FILE, }, |
| 890 | { .name = "io", .shift = FD_IO, }, |
| 891 | { .name = "mem", .shift = FD_MEM, }, |
| 892 | { .name = "blktrace", .shift = FD_BLKTRACE }, |
| 893 | { .name = "verify", .shift = FD_VERIFY }, |
Jens Axboe | 84422ac | 2008-02-19 20:10:26 +0100 | [diff] [blame] | 894 | { .name = "random", .shift = FD_RANDOM }, |
Jens Axboe | a3d741f | 2008-02-27 18:32:33 +0100 | [diff] [blame] | 895 | { .name = "parse", .shift = FD_PARSE }, |
Jens Axboe | cd991b9 | 2008-03-07 13:19:35 +0100 | [diff] [blame] | 896 | { .name = "diskutil", .shift = FD_DISKUTIL }, |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 897 | { .name = "job", .shift = FD_JOB }, |
Jens Axboe | 29adda3 | 2009-01-05 19:06:39 +0100 | [diff] [blame] | 898 | { .name = "mutex", .shift = FD_MUTEX }, |
Jens Axboe | 02444ad | 2008-10-07 11:33:00 +0200 | [diff] [blame] | 899 | { .name = NULL, }, |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 900 | }; |
| 901 | |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 902 | static int set_debug(const char *string) |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 903 | { |
| 904 | struct debug_level *dl; |
| 905 | char *p = (char *) string; |
| 906 | char *opt; |
| 907 | int i; |
| 908 | |
| 909 | if (!strcmp(string, "?") || !strcmp(string, "help")) { |
| 910 | int i; |
| 911 | |
| 912 | log_info("fio: dumping debug options:"); |
| 913 | for (i = 0; debug_levels[i].name; i++) { |
| 914 | dl = &debug_levels[i]; |
| 915 | log_info("%s,", dl->name); |
| 916 | } |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 917 | log_info("all\n"); |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 918 | return 1; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | while ((opt = strsep(&p, ",")) != NULL) { |
| 922 | int found = 0; |
| 923 | |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 924 | if (!strncmp(opt, "all", 3)) { |
| 925 | log_info("fio: set all debug options\n"); |
| 926 | fio_debug = ~0UL; |
| 927 | continue; |
| 928 | } |
| 929 | |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 930 | for (i = 0; debug_levels[i].name; i++) { |
| 931 | dl = &debug_levels[i]; |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 932 | found = !strncmp(opt, dl->name, strlen(dl->name)); |
| 933 | if (!found) |
| 934 | continue; |
| 935 | |
| 936 | if (dl->shift == FD_JOB) { |
| 937 | opt = strchr(opt, ':'); |
| 938 | if (!opt) { |
| 939 | log_err("fio: missing job number\n"); |
| 940 | break; |
| 941 | } |
| 942 | opt++; |
| 943 | fio_debug_jobno = atoi(opt); |
| 944 | log_info("fio: set debug jobno %d\n", |
| 945 | fio_debug_jobno); |
| 946 | } else { |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 947 | log_info("fio: set debug option %s\n", opt); |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 948 | fio_debug |= (1UL << dl->shift); |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 949 | } |
Jens Axboe | 5e1d306 | 2008-05-23 11:55:53 +0200 | [diff] [blame] | 950 | break; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | if (!found) |
| 954 | log_err("fio: debug mask %s not found\n", opt); |
| 955 | } |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 956 | return 0; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 957 | } |
Jens Axboe | 79e48f7 | 2008-02-01 20:37:09 +0100 | [diff] [blame] | 958 | #else |
Jens Axboe | 69b98d4 | 2008-05-30 22:25:32 +0200 | [diff] [blame] | 959 | static int set_debug(const char *string) |
Jens Axboe | 79e48f7 | 2008-02-01 20:37:09 +0100 | [diff] [blame] | 960 | { |
| 961 | log_err("fio: debug tracing not included in build\n"); |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 962 | return 1; |
Jens Axboe | 79e48f7 | 2008-02-01 20:37:09 +0100 | [diff] [blame] | 963 | } |
| 964 | #endif |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 965 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 966 | static int parse_cmd_line(int argc, char *argv[]) |
| 967 | { |
| 968 | struct thread_data *td = NULL; |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 969 | int c, ini_idx = 0, lidx, ret = 0, do_exit = 0, exit_val = 0; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 970 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 971 | while ((c = getopt_long_only(argc, argv, "", l_opts, &lidx)) != -1) { |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 972 | switch (c) { |
Jens Axboe | 2b386d2 | 2008-03-26 10:32:57 +0100 | [diff] [blame] | 973 | case 'a': |
| 974 | smalloc_pool_size = atoi(optarg); |
| 975 | break; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 976 | case 't': |
| 977 | def_timeout = atoi(optarg); |
| 978 | break; |
| 979 | case 'l': |
| 980 | write_lat_log = 1; |
| 981 | break; |
| 982 | case 'w': |
| 983 | write_bw_log = 1; |
| 984 | break; |
| 985 | case 'o': |
| 986 | f_out = fopen(optarg, "w+"); |
| 987 | if (!f_out) { |
| 988 | perror("fopen output"); |
| 989 | exit(1); |
| 990 | } |
| 991 | f_err = f_out; |
| 992 | break; |
| 993 | case 'm': |
| 994 | terse_output = 1; |
| 995 | break; |
| 996 | case 'h': |
Jens Axboe | 45378b3 | 2007-12-19 13:54:38 +0100 | [diff] [blame] | 997 | usage(argv[0]); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 998 | exit(0); |
| 999 | case 'c': |
| 1000 | exit(fio_show_option_help(optarg)); |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 1001 | case 's': |
| 1002 | dump_cmdline = 1; |
| 1003 | break; |
Jens Axboe | 724e443 | 2007-09-11 20:02:05 +0200 | [diff] [blame] | 1004 | case 'r': |
| 1005 | read_only = 1; |
| 1006 | break; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1007 | case 'v': |
| 1008 | printf("%s\n", fio_version_string); |
| 1009 | exit(0); |
Aaron Carroll | e592a06 | 2007-09-14 09:49:41 +0200 | [diff] [blame] | 1010 | case 'e': |
| 1011 | if (!strcmp("always", optarg)) |
| 1012 | eta_print = FIO_ETA_ALWAYS; |
| 1013 | else if (!strcmp("never", optarg)) |
| 1014 | eta_print = FIO_ETA_NEVER; |
| 1015 | break; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1016 | case 'd': |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1017 | if (set_debug(optarg)) |
| 1018 | do_exit++; |
Jens Axboe | ee56ad5 | 2008-02-01 10:30:20 +0100 | [diff] [blame] | 1019 | break; |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1020 | case 'x': |
| 1021 | if (!strcmp(optarg, "global")) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1022 | log_err("fio: can't use global as only " |
| 1023 | "section\n"); |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1024 | do_exit++; |
| 1025 | exit_val = 1; |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1026 | break; |
| 1027 | } |
| 1028 | if (job_section) |
| 1029 | free(job_section); |
| 1030 | job_section = strdup(optarg); |
| 1031 | break; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1032 | case FIO_GETOPT_JOB: { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1033 | const char *opt = l_opts[lidx].name; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1034 | char *val = optarg; |
| 1035 | |
| 1036 | if (!strncmp(opt, "name", 4) && td) { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 1037 | ret = add_job(td, td->o.name ?: "fio", 0); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1038 | if (ret) { |
| 1039 | put_job(td); |
| 1040 | return 0; |
| 1041 | } |
| 1042 | td = NULL; |
| 1043 | } |
| 1044 | if (!td) { |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1045 | int is_section = !strncmp(opt, "name", 4); |
Jens Axboe | 3106f22 | 2007-04-19 09:53:28 +0200 | [diff] [blame] | 1046 | int global = 0; |
| 1047 | |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1048 | if (!is_section || !strncmp(val, "global", 6)) |
Jens Axboe | 3106f22 | 2007-04-19 09:53:28 +0200 | [diff] [blame] | 1049 | global = 1; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1050 | |
Jens Axboe | 01f06b6 | 2008-02-18 20:53:47 +0100 | [diff] [blame] | 1051 | if (is_section && skip_this_section(val)) |
| 1052 | continue; |
| 1053 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1054 | td = get_new_job(global, &def_thread); |
| 1055 | if (!td) |
| 1056 | return 0; |
| 1057 | } |
| 1058 | |
| 1059 | ret = fio_cmd_option_parse(td, opt, val); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1060 | break; |
| 1061 | } |
| 1062 | default: |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1063 | do_exit++; |
| 1064 | exit_val = 1; |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1065 | break; |
| 1066 | } |
| 1067 | } |
| 1068 | |
Jens Axboe | c09823a | 2008-02-19 20:16:57 +0100 | [diff] [blame] | 1069 | if (do_exit) |
| 1070 | exit(exit_val); |
Jens Axboe | 536582b | 2008-02-18 20:26:32 +0100 | [diff] [blame] | 1071 | |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1072 | if (td) { |
Jens Axboe | 7d6a890 | 2008-02-18 20:59:18 +0100 | [diff] [blame] | 1073 | if (!ret) |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 1074 | ret = add_job(td, td->o.name ?: "fio", 0); |
Jens Axboe | 7d6a890 | 2008-02-18 20:59:18 +0100 | [diff] [blame] | 1075 | if (ret) |
| 1076 | put_job(td); |
Jens Axboe | 214e1ec | 2007-03-15 10:48:13 +0100 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | while (optind < argc) { |
| 1080 | ini_idx++; |
| 1081 | ini_file = realloc(ini_file, ini_idx * sizeof(char *)); |
| 1082 | ini_file[ini_idx - 1] = strdup(argv[optind]); |
| 1083 | optind++; |
| 1084 | } |
| 1085 | |
| 1086 | return ini_idx; |
| 1087 | } |
| 1088 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1089 | int parse_options(int argc, char *argv[]) |
| 1090 | { |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1091 | int job_files, i; |
| 1092 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1093 | f_out = stdout; |
| 1094 | f_err = stderr; |
| 1095 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 1096 | fio_options_dup_and_init(l_opts); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1097 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1098 | if (setup_thread_area()) |
| 1099 | return 1; |
| 1100 | if (fill_def_thread()) |
| 1101 | return 1; |
| 1102 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1103 | job_files = parse_cmd_line(argc, argv); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1104 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1105 | for (i = 0; i < job_files; i++) { |
| 1106 | if (fill_def_thread()) |
| 1107 | return 1; |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 1108 | if (parse_jobs_ini(ini_file[i], i)) |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1109 | return 1; |
Jens Axboe | 88c6ed8 | 2006-06-09 11:28:10 +0200 | [diff] [blame] | 1110 | free(ini_file[i]); |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1111 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1112 | |
Jens Axboe | 88c6ed8 | 2006-06-09 11:28:10 +0200 | [diff] [blame] | 1113 | free(ini_file); |
Jens Axboe | d23bb32 | 2007-03-23 15:57:56 +0100 | [diff] [blame] | 1114 | options_mem_free(&def_thread); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1115 | |
| 1116 | if (!thread_number) { |
Jens Axboe | cca73aa | 2007-04-04 11:09:19 +0200 | [diff] [blame] | 1117 | if (dump_cmdline) |
| 1118 | return 0; |
| 1119 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1120 | log_err("No jobs defined(s)\n"); |
Jens Axboe | 45378b3 | 2007-12-19 13:54:38 +0100 | [diff] [blame] | 1121 | usage(argv[0]); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1122 | return 1; |
| 1123 | } |
| 1124 | |
Jens Axboe | be4ecfd | 2008-12-08 14:10:52 +0100 | [diff] [blame] | 1125 | if (def_thread.o.gtod_offload) { |
| 1126 | fio_gtod_init(); |
| 1127 | fio_gtod_offload = 1; |
| 1128 | fio_gtod_cpu = def_thread.o.gtod_cpu; |
| 1129 | } |
| 1130 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1131 | return 0; |
| 1132 | } |