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> |
| 12 | #include <assert.h> |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 13 | #include <sys/ipc.h> |
| 14 | #include <sys/shm.h> |
| 15 | #include <sys/types.h> |
| 16 | #include <sys/stat.h> |
| 17 | |
| 18 | #include "fio.h" |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 19 | #include "parse.h" |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 20 | |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 21 | #define FIO_RANDSEED (0xb1899bedUL) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 22 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 23 | #define td_var_offset(var) ((size_t) &((struct thread_data *)0)->var) |
| 24 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 25 | static int str_rw_cb(void *, const char *); |
| 26 | static int str_ioengine_cb(void *, const char *); |
| 27 | static int str_mem_cb(void *, const char *); |
| 28 | static int str_verify_cb(void *, const char *); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 29 | static int str_lockmem_cb(void *, unsigned long *); |
Jens Axboe | 34cfcda | 2006-11-03 14:00:45 +0100 | [diff] [blame] | 30 | #ifdef FIO_HAVE_IOPRIO |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 31 | static int str_prio_cb(void *, unsigned int *); |
| 32 | static int str_prioclass_cb(void *, unsigned int *); |
Jens Axboe | 34cfcda | 2006-11-03 14:00:45 +0100 | [diff] [blame] | 33 | #endif |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 34 | static int str_exitall_cb(void); |
| 35 | static int str_cpumask_cb(void *, unsigned int *); |
Jens Axboe | 0aabe16 | 2007-02-23 08:45:55 +0100 | [diff] [blame] | 36 | static int str_file_service_cb(void *, const char *); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 37 | |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 38 | #define __stringify_1(x) #x |
| 39 | #define __stringify(x) __stringify_1(x) |
| 40 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 41 | /* |
| 42 | * Map of job/command line options |
| 43 | */ |
| 44 | static struct fio_option options[] = { |
| 45 | { |
Jens Axboe | 61697c3 | 2007-02-05 15:04:46 +0100 | [diff] [blame] | 46 | .name = "description", |
| 47 | .type = FIO_OPT_STR_STORE, |
| 48 | .off1 = td_var_offset(description), |
| 49 | .help = "Text job description", |
| 50 | }, |
| 51 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 52 | .name = "name", |
| 53 | .type = FIO_OPT_STR_STORE, |
| 54 | .off1 = td_var_offset(name), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 55 | .help = "Name of this job", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 56 | }, |
| 57 | { |
| 58 | .name = "directory", |
| 59 | .type = FIO_OPT_STR_STORE, |
| 60 | .off1 = td_var_offset(directory), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 61 | .help = "Directory to store files in", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 62 | }, |
| 63 | { |
| 64 | .name = "filename", |
| 65 | .type = FIO_OPT_STR_STORE, |
| 66 | .off1 = td_var_offset(filename), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 67 | .help = "Force the use of a specific file", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 68 | }, |
| 69 | { |
| 70 | .name = "rw", |
| 71 | .type = FIO_OPT_STR, |
| 72 | .cb = str_rw_cb, |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 73 | .help = "IO direction", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 74 | .def = "read", |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 75 | .posval = { "read", "write", "randwrite", "randread", "rw", |
| 76 | "randrw", }, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 77 | }, |
| 78 | { |
| 79 | .name = "ioengine", |
| 80 | .type = FIO_OPT_STR, |
| 81 | .cb = str_ioengine_cb, |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 82 | .help = "IO engine to use", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 83 | .def = "sync", |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 84 | .posval = { "sync", "libaio", "posixaio", "mmap", "splice", |
Jens Axboe | a4f4fdd | 2007-02-14 01:16:39 +0100 | [diff] [blame] | 85 | "sg", "null", "net", "syslet-rw" }, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 86 | }, |
| 87 | { |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 88 | .name = "iodepth", |
| 89 | .type = FIO_OPT_INT, |
| 90 | .off1 = td_var_offset(iodepth), |
| 91 | .help = "Amount of IO buffers to keep in flight", |
| 92 | .def = "1", |
| 93 | }, |
| 94 | { |
Jens Axboe | e916b39 | 2007-02-20 14:37:26 +0100 | [diff] [blame] | 95 | .name = "iodepth_low", |
| 96 | .type = FIO_OPT_INT, |
| 97 | .off1 = td_var_offset(iodepth_low), |
| 98 | .help = "Low water mark for queuing depth", |
| 99 | }, |
| 100 | { |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 101 | .name = "size", |
| 102 | .type = FIO_OPT_STR_VAL, |
| 103 | .off1 = td_var_offset(total_file_size), |
| 104 | .help = "Size of device or file", |
| 105 | }, |
| 106 | { |
| 107 | .name = "bs", |
| 108 | .type = FIO_OPT_STR_VAL_INT, |
| 109 | .off1 = td_var_offset(bs[DDIR_READ]), |
| 110 | .off2 = td_var_offset(bs[DDIR_WRITE]), |
| 111 | .help = "Block size unit", |
| 112 | .def = "4k", |
| 113 | }, |
| 114 | { |
| 115 | .name = "bsrange", |
| 116 | .type = FIO_OPT_RANGE, |
| 117 | .off1 = td_var_offset(min_bs[DDIR_READ]), |
| 118 | .off2 = td_var_offset(max_bs[DDIR_READ]), |
| 119 | .off3 = td_var_offset(min_bs[DDIR_WRITE]), |
| 120 | .off4 = td_var_offset(max_bs[DDIR_WRITE]), |
| 121 | .help = "Set block size range (in more detail than bs)", |
| 122 | }, |
| 123 | { |
| 124 | .name = "bs_unaligned", |
| 125 | .type = FIO_OPT_STR_SET, |
| 126 | .off1 = td_var_offset(bs_unaligned), |
| 127 | .help = "Don't sector align IO buffer sizes", |
| 128 | }, |
| 129 | { |
| 130 | .name = "offset", |
| 131 | .type = FIO_OPT_STR_VAL, |
| 132 | .off1 = td_var_offset(start_offset), |
| 133 | .help = "Start IO from this offset", |
| 134 | .def = "0", |
| 135 | }, |
| 136 | { |
| 137 | .name = "randrepeat", |
| 138 | .type = FIO_OPT_BOOL, |
| 139 | .off1 = td_var_offset(rand_repeatable), |
| 140 | .help = "Use repeatable random IO pattern", |
| 141 | .def = "1", |
| 142 | }, |
| 143 | { |
| 144 | .name = "norandommap", |
| 145 | .type = FIO_OPT_STR_SET, |
| 146 | .off1 = td_var_offset(norandommap), |
| 147 | .help = "Accept potential duplicate random blocks", |
| 148 | }, |
| 149 | { |
| 150 | .name = "nrfiles", |
| 151 | .type = FIO_OPT_INT, |
| 152 | .off1 = td_var_offset(nr_files), |
| 153 | .help = "Split job workload between this number of files", |
| 154 | .def = "1", |
| 155 | }, |
| 156 | { |
Jens Axboe | 0aabe16 | 2007-02-23 08:45:55 +0100 | [diff] [blame] | 157 | .name = "file_service_type", |
| 158 | .type = FIO_OPT_STR, |
| 159 | .cb = str_file_service_cb, |
| 160 | .help = "How to select which file to service next", |
| 161 | .def = "roundrobin", |
| 162 | .posval = { "random", "roundrobin" }, |
| 163 | }, |
| 164 | { |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 165 | .name = "fsync", |
| 166 | .type = FIO_OPT_INT, |
| 167 | .off1 = td_var_offset(fsync_blocks), |
| 168 | .help = "Issue fsync for writes every given number of blocks", |
| 169 | .def = "0", |
| 170 | }, |
| 171 | { |
| 172 | .name = "direct", |
| 173 | .type = FIO_OPT_BOOL, |
| 174 | .off1 = td_var_offset(odirect), |
Jens Axboe | 76a43db | 2007-01-11 13:24:44 +0100 | [diff] [blame] | 175 | .help = "Use O_DIRECT IO (negates buffered)", |
| 176 | .def = "0", |
| 177 | }, |
| 178 | { |
| 179 | .name = "buffered", |
| 180 | .type = FIO_OPT_BOOL, |
| 181 | .off1 = td_var_offset(odirect), |
| 182 | .neg = 1, |
| 183 | .help = "Use buffered IO (negates direct)", |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 184 | .def = "1", |
| 185 | }, |
| 186 | { |
| 187 | .name = "overwrite", |
| 188 | .type = FIO_OPT_BOOL, |
| 189 | .off1 = td_var_offset(overwrite), |
| 190 | .help = "When writing, set whether to overwrite current data", |
| 191 | .def = "0", |
| 192 | }, |
| 193 | { |
| 194 | .name = "loops", |
| 195 | .type = FIO_OPT_INT, |
| 196 | .off1 = td_var_offset(loops), |
| 197 | .help = "Number of times to run the job", |
| 198 | .def = "1", |
| 199 | }, |
| 200 | { |
| 201 | .name = "numjobs", |
| 202 | .type = FIO_OPT_INT, |
| 203 | .off1 = td_var_offset(numjobs), |
| 204 | .help = "Duplicate this job this many times", |
| 205 | .def = "1", |
| 206 | }, |
| 207 | { |
| 208 | .name = "startdelay", |
| 209 | .type = FIO_OPT_INT, |
| 210 | .off1 = td_var_offset(start_delay), |
| 211 | .help = "Only start job when this period has passed", |
| 212 | .def = "0", |
| 213 | }, |
| 214 | { |
| 215 | .name = "runtime", |
| 216 | .alias = "timeout", |
| 217 | .type = FIO_OPT_STR_VAL_TIME, |
| 218 | .off1 = td_var_offset(timeout), |
| 219 | .help = "Stop workload when this amount of time has passed", |
| 220 | .def = "0", |
| 221 | }, |
| 222 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 223 | .name = "mem", |
| 224 | .type = FIO_OPT_STR, |
| 225 | .cb = str_mem_cb, |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 226 | .help = "Backing type for IO buffers", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 227 | .def = "malloc", |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 228 | .posval = { "malloc", "shm", "shmhuge", "mmap", "mmaphuge", }, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 229 | }, |
| 230 | { |
| 231 | .name = "verify", |
| 232 | .type = FIO_OPT_STR, |
| 233 | .cb = str_verify_cb, |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 234 | .help = "Verify sum function", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 235 | .def = "0", |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 236 | .posval = { "crc32", "md5", }, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 237 | }, |
| 238 | { |
| 239 | .name = "write_iolog", |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 240 | .type = FIO_OPT_STR_STORE, |
| 241 | .off1 = td_var_offset(write_iolog_file), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 242 | .help = "Store IO pattern to file", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 243 | }, |
| 244 | { |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 245 | .name = "read_iolog", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 246 | .type = FIO_OPT_STR_STORE, |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 247 | .off1 = td_var_offset(read_iolog_file), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 248 | .help = "Playback IO pattern from file", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 249 | }, |
| 250 | { |
| 251 | .name = "exec_prerun", |
| 252 | .type = FIO_OPT_STR_STORE, |
| 253 | .off1 = td_var_offset(exec_prerun), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 254 | .help = "Execute this file prior to running job", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 255 | }, |
| 256 | { |
| 257 | .name = "exec_postrun", |
| 258 | .type = FIO_OPT_STR_STORE, |
| 259 | .off1 = td_var_offset(exec_postrun), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 260 | .help = "Execute this file after running job", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 261 | }, |
| 262 | #ifdef FIO_HAVE_IOSCHED_SWITCH |
| 263 | { |
| 264 | .name = "ioscheduler", |
| 265 | .type = FIO_OPT_STR_STORE, |
| 266 | .off1 = td_var_offset(ioscheduler), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 267 | .help = "Use this IO scheduler on the backing device", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 268 | }, |
| 269 | #endif |
| 270 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 271 | .name = "zonesize", |
| 272 | .type = FIO_OPT_STR_VAL, |
| 273 | .off1 = td_var_offset(zone_size), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 274 | .help = "Give size of an IO zone", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 275 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 276 | }, |
| 277 | { |
| 278 | .name = "zoneskip", |
| 279 | .type = FIO_OPT_STR_VAL, |
| 280 | .off1 = td_var_offset(zone_skip), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 281 | .help = "Space between IO zones", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 282 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 283 | }, |
| 284 | { |
| 285 | .name = "lockmem", |
| 286 | .type = FIO_OPT_STR_VAL, |
| 287 | .cb = str_lockmem_cb, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 288 | .help = "Lock down this amount of memory", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 289 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 290 | }, |
| 291 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 292 | .name = "rwmixcycle", |
| 293 | .type = FIO_OPT_INT, |
| 294 | .off1 = td_var_offset(rwmixcycle), |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 295 | .help = "Cycle period for mixed read/write workloads (msec)", |
| 296 | .def = "500", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 297 | }, |
| 298 | { |
| 299 | .name = "rwmixread", |
| 300 | .type = FIO_OPT_INT, |
| 301 | .off1 = td_var_offset(rwmixread), |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 302 | .maxval = 100, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 303 | .help = "Percentage of mixed workload that is reads", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 304 | .def = "50", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 305 | }, |
| 306 | { |
| 307 | .name = "rwmixwrite", |
| 308 | .type = FIO_OPT_INT, |
| 309 | .off1 = td_var_offset(rwmixwrite), |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 310 | .maxval = 100, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 311 | .help = "Percentage of mixed workload that is writes", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 312 | .def = "50", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 313 | }, |
| 314 | { |
| 315 | .name = "nice", |
| 316 | .type = FIO_OPT_INT, |
| 317 | .off1 = td_var_offset(nice), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 318 | .help = "Set job CPU nice value", |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 319 | .minval = -19, |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 320 | .maxval = 20, |
| 321 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 322 | }, |
| 323 | #ifdef FIO_HAVE_IOPRIO |
| 324 | { |
| 325 | .name = "prio", |
| 326 | .type = FIO_OPT_INT, |
| 327 | .cb = str_prio_cb, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 328 | .help = "Set job IO priority value", |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 329 | .minval = 0, |
| 330 | .maxval = 7, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 331 | }, |
| 332 | { |
| 333 | .name = "prioclass", |
| 334 | .type = FIO_OPT_INT, |
| 335 | .cb = str_prioclass_cb, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 336 | .help = "Set job IO priority class", |
Jens Axboe | 15f7918 | 2007-01-10 12:26:18 +0100 | [diff] [blame] | 337 | .minval = 0, |
| 338 | .maxval = 3, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 339 | }, |
| 340 | #endif |
| 341 | { |
| 342 | .name = "thinktime", |
| 343 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 344 | .off1 = td_var_offset(thinktime), |
Jens Axboe | 5fa0f81 | 2007-01-11 14:06:35 +0100 | [diff] [blame] | 345 | .help = "Idle time between IO buffers (usec)", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 346 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 347 | }, |
| 348 | { |
Jens Axboe | 48097d5 | 2007-02-17 06:30:44 +0100 | [diff] [blame] | 349 | .name = "thinktime_spin", |
| 350 | .type = FIO_OPT_INT, |
| 351 | .off1 = td_var_offset(thinktime_spin), |
| 352 | .help = "Start thinktime by spinning this amount (usec)", |
| 353 | .def = "0", |
| 354 | }, |
| 355 | { |
Jens Axboe | 9c1f743 | 2007-01-03 20:43:19 +0100 | [diff] [blame] | 356 | .name = "thinktime_blocks", |
| 357 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 358 | .off1 = td_var_offset(thinktime_blocks), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 359 | .help = "IO buffer period between 'thinktime'", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 360 | .def = "1", |
Jens Axboe | 9c1f743 | 2007-01-03 20:43:19 +0100 | [diff] [blame] | 361 | }, |
| 362 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 363 | .name = "rate", |
| 364 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 365 | .off1 = td_var_offset(rate), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 366 | .help = "Set bandwidth rate", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 367 | }, |
| 368 | { |
| 369 | .name = "ratemin", |
| 370 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 371 | .off1 = td_var_offset(ratemin), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 372 | .help = "The bottom limit accepted", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 373 | }, |
| 374 | { |
| 375 | .name = "ratecycle", |
| 376 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 377 | .off1 = td_var_offset(ratecycle), |
Jens Axboe | 6da1fa7 | 2007-01-10 11:27:48 +0100 | [diff] [blame] | 378 | .help = "Window average for rate limits (msec)", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 379 | .def = "1000", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 380 | }, |
| 381 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 382 | .name = "invalidate", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 383 | .type = FIO_OPT_BOOL, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 384 | .off1 = td_var_offset(invalidate_cache), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 385 | .help = "Invalidate buffer/page cache prior to running job", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 386 | .def = "1", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 387 | }, |
| 388 | { |
| 389 | .name = "sync", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 390 | .type = FIO_OPT_BOOL, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 391 | .off1 = td_var_offset(sync_io), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 392 | .help = "Use O_SYNC for buffered writes", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 393 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 394 | }, |
| 395 | { |
| 396 | .name = "bwavgtime", |
| 397 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 398 | .off1 = td_var_offset(bw_avg_time), |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 399 | .help = "Time window over which to calculate bandwidth (msec)", |
| 400 | .def = "500", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 401 | }, |
| 402 | { |
| 403 | .name = "create_serialize", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 404 | .type = FIO_OPT_BOOL, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 405 | .off1 = td_var_offset(create_serialize), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 406 | .help = "Serialize creating of job files", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 407 | .def = "1", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 408 | }, |
| 409 | { |
| 410 | .name = "create_fsync", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 411 | .type = FIO_OPT_BOOL, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 412 | .off1 = td_var_offset(create_fsync), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 413 | .help = "Fsync file after creation", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 414 | .def = "1", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 415 | }, |
| 416 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 417 | .name = "cpuload", |
| 418 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 419 | .off1 = td_var_offset(cpuload), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 420 | .help = "Use this percentage of CPU", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 421 | }, |
| 422 | { |
| 423 | .name = "cpuchunks", |
| 424 | .type = FIO_OPT_INT, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 425 | .off1 = td_var_offset(cpucycle), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 426 | .help = "Length of the CPU burn cycles", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 427 | }, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 428 | #ifdef FIO_HAVE_CPU_AFFINITY |
| 429 | { |
| 430 | .name = "cpumask", |
| 431 | .type = FIO_OPT_INT, |
| 432 | .cb = str_cpumask_cb, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 433 | .help = "CPU affinity mask", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 434 | }, |
| 435 | #endif |
| 436 | { |
| 437 | .name = "end_fsync", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 438 | .type = FIO_OPT_BOOL, |
Jens Axboe | 1304923 | 2007-01-03 20:45:09 +0100 | [diff] [blame] | 439 | .off1 = td_var_offset(end_fsync), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 440 | .help = "Include fsync at the end of job", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 441 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 442 | }, |
| 443 | { |
| 444 | .name = "unlink", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 445 | .type = FIO_OPT_BOOL, |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 446 | .off1 = td_var_offset(unlink), |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 447 | .help = "Unlink created files after job has completed", |
Jens Axboe | e545a6c | 2007-01-14 00:00:29 +0100 | [diff] [blame] | 448 | .def = "0", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 449 | }, |
| 450 | { |
| 451 | .name = "exitall", |
| 452 | .type = FIO_OPT_STR_SET, |
| 453 | .cb = str_exitall_cb, |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 454 | .help = "Terminate all jobs when one exits", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 455 | }, |
| 456 | { |
| 457 | .name = "stonewall", |
| 458 | .type = FIO_OPT_STR_SET, |
| 459 | .off1 = td_var_offset(stonewall), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 460 | .help = "Insert a hard barrier between this job and previous", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 461 | }, |
| 462 | { |
| 463 | .name = "thread", |
| 464 | .type = FIO_OPT_STR_SET, |
Jens Axboe | d9bb3b8 | 2007-01-10 20:30:53 +0100 | [diff] [blame] | 465 | .off1 = td_var_offset(use_thread), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 466 | .help = "Use threads instead of forks", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 467 | }, |
| 468 | { |
| 469 | .name = "write_bw_log", |
| 470 | .type = FIO_OPT_STR_SET, |
| 471 | .off1 = td_var_offset(write_bw_log), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 472 | .help = "Write log of bandwidth during run", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 473 | }, |
| 474 | { |
| 475 | .name = "write_lat_log", |
| 476 | .type = FIO_OPT_STR_SET, |
| 477 | .off1 = td_var_offset(write_lat_log), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 478 | .help = "Write log of latency during run", |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 479 | }, |
| 480 | { |
Jens Axboe | 56bb17f | 2006-12-20 20:27:36 +0100 | [diff] [blame] | 481 | .name = "hugepage-size", |
| 482 | .type = FIO_OPT_STR_VAL, |
| 483 | .off1 = td_var_offset(hugepage_size), |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 484 | .help = "When using hugepages, specify size of each page", |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 485 | .def = __stringify(FIO_HUGE_PAGE), |
Jens Axboe | 56bb17f | 2006-12-20 20:27:36 +0100 | [diff] [blame] | 486 | }, |
| 487 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 488 | .name = NULL, |
| 489 | }, |
| 490 | }; |
| 491 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 492 | #define FIO_JOB_OPTS (sizeof(options) / sizeof(struct fio_option)) |
| 493 | #define FIO_CMD_OPTS (16) |
| 494 | #define FIO_GETOPT_JOB (0x89988998) |
| 495 | |
| 496 | /* |
| 497 | * Command line options. These will contain the above, plus a few |
| 498 | * extra that only pertain to fio itself and not jobs. |
| 499 | */ |
| 500 | static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = { |
| 501 | { |
| 502 | .name = "output", |
| 503 | .has_arg = required_argument, |
| 504 | .val = 'o', |
| 505 | }, |
| 506 | { |
| 507 | .name = "timeout", |
| 508 | .has_arg = required_argument, |
| 509 | .val = 't', |
| 510 | }, |
| 511 | { |
| 512 | .name = "latency-log", |
| 513 | .has_arg = required_argument, |
| 514 | .val = 'l', |
| 515 | }, |
| 516 | { |
| 517 | .name = "bandwidth-log", |
| 518 | .has_arg = required_argument, |
| 519 | .val = 'b', |
| 520 | }, |
| 521 | { |
| 522 | .name = "minimal", |
| 523 | .has_arg = optional_argument, |
| 524 | .val = 'm', |
| 525 | }, |
| 526 | { |
| 527 | .name = "version", |
| 528 | .has_arg = no_argument, |
| 529 | .val = 'v', |
| 530 | }, |
| 531 | { |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 532 | .name = "help", |
| 533 | .has_arg = no_argument, |
| 534 | .val = 'h', |
| 535 | }, |
| 536 | { |
| 537 | .name = "cmdhelp", |
| 538 | .has_arg = required_argument, |
| 539 | .val = 'c', |
| 540 | }, |
| 541 | { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 542 | .name = NULL, |
| 543 | }, |
| 544 | }; |
| 545 | |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 546 | static int def_timeout = 0; |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 547 | |
Jens Axboe | 5cd033b | 2007-01-09 08:19:01 +0100 | [diff] [blame] | 548 | static char fio_version_string[] = "fio 1.11"; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 549 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 550 | static char **ini_file; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 551 | static int max_jobs = MAX_JOBS; |
| 552 | |
| 553 | struct thread_data def_thread; |
| 554 | struct thread_data *threads = NULL; |
| 555 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 556 | int exitall_on_terminate = 0; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 557 | int terse_output = 0; |
Jens Axboe | c04f7ec | 2006-05-31 10:13:16 +0200 | [diff] [blame] | 558 | unsigned long long mlock_size = 0; |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 559 | FILE *f_out = NULL; |
| 560 | FILE *f_err = NULL; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 561 | |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 562 | static int write_lat_log = 0; |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 563 | int write_bw_log = 0; |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 564 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 565 | /* |
| 566 | * Return a free job structure. |
| 567 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 568 | static struct thread_data *get_new_job(int global, struct thread_data *parent) |
| 569 | { |
| 570 | struct thread_data *td; |
| 571 | |
| 572 | if (global) |
| 573 | return &def_thread; |
| 574 | if (thread_number >= max_jobs) |
| 575 | return NULL; |
| 576 | |
| 577 | td = &threads[thread_number++]; |
Jens Axboe | ddaeaa5 | 2006-06-08 11:00:58 +0200 | [diff] [blame] | 578 | *td = *parent; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 579 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 580 | td->thread_number = thread_number; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 581 | return td; |
| 582 | } |
| 583 | |
| 584 | static void put_job(struct thread_data *td) |
| 585 | { |
Jens Axboe | 549577a | 2006-10-30 12:23:41 +0100 | [diff] [blame] | 586 | if (td == &def_thread) |
| 587 | return; |
| 588 | |
Jens Axboe | 16edf25 | 2007-02-10 14:59:22 +0100 | [diff] [blame] | 589 | if (td->error) |
| 590 | fprintf(f_out, "fio: %s\n", td->verror); |
| 591 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 592 | memset(&threads[td->thread_number - 1], 0, sizeof(*td)); |
| 593 | thread_number--; |
| 594 | } |
| 595 | |
Jens Axboe | dad915e | 2006-10-27 11:10:18 +0200 | [diff] [blame] | 596 | /* |
| 597 | * Lazy way of fixing up options that depend on each other. We could also |
| 598 | * define option callback handlers, but this is easier. |
| 599 | */ |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 600 | static void fixup_options(struct thread_data *td) |
| 601 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 602 | if (!td->rwmixread && td->rwmixwrite) |
| 603 | td->rwmixread = 100 - td->rwmixwrite; |
Jens Axboe | dad915e | 2006-10-27 11:10:18 +0200 | [diff] [blame] | 604 | |
Jens Axboe | 076efc7 | 2006-10-27 11:24:25 +0200 | [diff] [blame] | 605 | if (td->write_iolog_file && td->read_iolog_file) { |
| 606 | log_err("fio: read iolog overrides write_iolog\n"); |
| 607 | free(td->write_iolog_file); |
| 608 | td->write_iolog_file = NULL; |
| 609 | } |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 610 | |
| 611 | if (td->io_ops->flags & FIO_SYNCIO) |
| 612 | td->iodepth = 1; |
| 613 | else { |
| 614 | if (!td->iodepth) |
| 615 | td->iodepth = td->nr_files; |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | * only really works for sequential io for now, and with 1 file |
| 620 | */ |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame^] | 621 | if (td->zone_size && td_random(td) && td->nr_files == 1) |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 622 | td->zone_size = 0; |
| 623 | |
| 624 | /* |
| 625 | * Reads can do overwrites, we always need to pre-create the file |
| 626 | */ |
| 627 | if (td_read(td) || td_rw(td)) |
| 628 | td->overwrite = 1; |
| 629 | |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 630 | if (!td->min_bs[DDIR_READ]) |
| 631 | td->min_bs[DDIR_READ]= td->bs[DDIR_READ]; |
| 632 | if (!td->max_bs[DDIR_READ]) |
| 633 | td->max_bs[DDIR_READ] = td->bs[DDIR_READ]; |
| 634 | if (!td->min_bs[DDIR_WRITE]) |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 635 | td->min_bs[DDIR_WRITE]= td->bs[DDIR_WRITE]; |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 636 | if (!td->max_bs[DDIR_WRITE]) |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 637 | td->max_bs[DDIR_WRITE] = td->bs[DDIR_WRITE]; |
Jens Axboe | a00735e | 2006-11-03 08:58:08 +0100 | [diff] [blame] | 638 | |
| 639 | td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]); |
| 640 | |
Jens Axboe | 16b462a | 2006-10-30 12:35:18 +0100 | [diff] [blame] | 641 | if (td_read(td) && !td_rw(td)) |
| 642 | td->verify = 0; |
Jens Axboe | bb8895e | 2006-10-30 15:14:48 +0100 | [diff] [blame] | 643 | |
| 644 | if (td->norandommap && td->verify != VERIFY_NONE) { |
| 645 | log_err("fio: norandommap given, verify disabled\n"); |
| 646 | td->verify = VERIFY_NONE; |
| 647 | } |
Jens Axboe | 690adba | 2006-10-30 15:25:09 +0100 | [diff] [blame] | 648 | if (td->bs_unaligned && (td->odirect || td->io_ops->flags & FIO_RAWIO)) |
| 649 | log_err("fio: bs_unaligned may not work with raw io\n"); |
Jens Axboe | e0a2233 | 2006-12-20 12:54:25 +0100 | [diff] [blame] | 650 | |
| 651 | /* |
| 652 | * O_DIRECT and char doesn't mix, clear that flag if necessary. |
| 653 | */ |
| 654 | if (td->filetype == FIO_TYPE_CHAR && td->odirect) |
| 655 | td->odirect = 0; |
Jens Axboe | 48097d5 | 2007-02-17 06:30:44 +0100 | [diff] [blame] | 656 | |
| 657 | /* |
| 658 | * thinktime_spin must be less than thinktime |
| 659 | */ |
| 660 | if (td->thinktime_spin > td->thinktime) |
| 661 | td->thinktime_spin = td->thinktime; |
Jens Axboe | e916b39 | 2007-02-20 14:37:26 +0100 | [diff] [blame] | 662 | |
| 663 | /* |
| 664 | * The low water mark cannot be bigger than the iodepth |
| 665 | */ |
| 666 | if (td->iodepth_low > td->iodepth || !td->iodepth_low) |
| 667 | td->iodepth_low = td->iodepth; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 668 | } |
| 669 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 670 | /* |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 671 | * This function leaks the buffer |
| 672 | */ |
| 673 | static char *to_kmg(unsigned int val) |
| 674 | { |
| 675 | char *buf = malloc(32); |
Jens Axboe | f3502ba | 2007-02-14 01:27:09 +0100 | [diff] [blame] | 676 | char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 }; |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 677 | char *p = post; |
| 678 | |
Jens Axboe | 245142f | 2006-11-08 12:49:21 +0100 | [diff] [blame] | 679 | do { |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 680 | if (val & 1023) |
| 681 | break; |
| 682 | |
| 683 | val >>= 10; |
| 684 | p++; |
Jens Axboe | 245142f | 2006-11-08 12:49:21 +0100 | [diff] [blame] | 685 | } while (*p); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 686 | |
| 687 | snprintf(buf, 31, "%u%c", val, *p); |
| 688 | return buf; |
| 689 | } |
| 690 | |
| 691 | /* |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 692 | * Adds a job to the list of things todo. Sanitizes the various options |
| 693 | * to make sure we don't have conflicts, and initializes various |
| 694 | * members of td. |
| 695 | */ |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 696 | 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] | 697 | { |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame^] | 698 | const char *ddir_str[] = { NULL, "read", "write", "rw", NULL, |
| 699 | "randread", "randwrite", "randrw" }; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 700 | struct stat sb; |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame^] | 701 | int numjobs, i; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 702 | struct fio_file *f; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 703 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 704 | /* |
| 705 | * the def_thread is just for options, it's not a real job |
| 706 | */ |
| 707 | if (td == &def_thread) |
| 708 | return 0; |
| 709 | |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 710 | assert(td->io_ops); |
Jens Axboe | df64119 | 2006-10-12 07:55:41 +0200 | [diff] [blame] | 711 | |
Jens Axboe | 690adba | 2006-10-30 15:25:09 +0100 | [diff] [blame] | 712 | if (td->odirect) |
| 713 | td->io_ops->flags |= FIO_RAWIO; |
| 714 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 715 | td->filetype = FIO_TYPE_FILE; |
Jens Axboe | 890df53 | 2007-02-17 01:51:13 +0100 | [diff] [blame] | 716 | if (td->filename && !lstat(td->filename, &sb)) { |
Jens Axboe | 0af7b54 | 2006-02-17 10:10:12 +0100 | [diff] [blame] | 717 | if (S_ISBLK(sb.st_mode)) |
| 718 | td->filetype = FIO_TYPE_BD; |
| 719 | else if (S_ISCHR(sb.st_mode)) |
| 720 | td->filetype = FIO_TYPE_CHAR; |
| 721 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 722 | |
Jens Axboe | e0a2233 | 2006-12-20 12:54:25 +0100 | [diff] [blame] | 723 | fixup_options(td); |
| 724 | |
Jens Axboe | 13f8e2d | 2006-10-24 09:29:45 +0200 | [diff] [blame] | 725 | if (td->filename) |
| 726 | td->nr_uniq_files = 1; |
| 727 | else |
| 728 | td->nr_uniq_files = td->nr_files; |
| 729 | |
| 730 | if (td->filetype == FIO_TYPE_FILE || td->filename) { |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 731 | char tmp[PATH_MAX]; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 732 | int len = 0; |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 733 | |
Jens Axboe | 16edf25 | 2007-02-10 14:59:22 +0100 | [diff] [blame] | 734 | if (td->directory && td->directory[0] != '\0') { |
| 735 | if (lstat(td->directory, &sb) < 0) { |
| 736 | log_err("fio: %s is not a directory\n", td->directory); |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 737 | td_verror(td, errno, "lstat"); |
Jens Axboe | 16edf25 | 2007-02-10 14:59:22 +0100 | [diff] [blame] | 738 | return 1; |
| 739 | } |
| 740 | if (!S_ISDIR(sb.st_mode)) { |
| 741 | log_err("fio: %s is not a directory\n", td->directory); |
| 742 | return 1; |
| 743 | } |
Jens Axboe | 8aeebd5 | 2007-01-08 10:47:43 +0100 | [diff] [blame] | 744 | len = sprintf(tmp, "%s/", td->directory); |
Jens Axboe | 16edf25 | 2007-02-10 14:59:22 +0100 | [diff] [blame] | 745 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 746 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 747 | td->files = malloc(sizeof(struct fio_file) * td->nr_files); |
| 748 | |
| 749 | for_each_file(td, f, i) { |
| 750 | memset(f, 0, sizeof(*f)); |
| 751 | f->fd = -1; |
| 752 | |
Jens Axboe | 13f8e2d | 2006-10-24 09:29:45 +0200 | [diff] [blame] | 753 | if (td->filename) |
| 754 | sprintf(tmp + len, "%s", td->filename); |
| 755 | else |
| 756 | sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i); |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 757 | f->file_name = strdup(tmp); |
| 758 | } |
| 759 | } else { |
| 760 | td->nr_files = 1; |
| 761 | td->files = malloc(sizeof(struct fio_file)); |
| 762 | f = &td->files[0]; |
| 763 | |
| 764 | memset(f, 0, sizeof(*f)); |
| 765 | f->fd = -1; |
| 766 | f->file_name = strdup(jobname); |
| 767 | } |
| 768 | |
| 769 | for_each_file(td, f, i) { |
| 770 | f->file_size = td->total_file_size / td->nr_files; |
| 771 | f->file_offset = td->start_offset; |
| 772 | } |
| 773 | |
Jens Axboe | bbfd6b0 | 2006-06-07 19:42:54 +0200 | [diff] [blame] | 774 | fio_sem_init(&td->mutex, 0); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 775 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 776 | td->ts.clat_stat[0].min_val = td->ts.clat_stat[1].min_val = ULONG_MAX; |
| 777 | td->ts.slat_stat[0].min_val = td->ts.slat_stat[1].min_val = ULONG_MAX; |
| 778 | td->ts.bw_stat[0].min_val = td->ts.bw_stat[1].min_val = ULONG_MAX; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 779 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 780 | if (td->stonewall && td->thread_number > 1) |
| 781 | groupid++; |
| 782 | |
| 783 | td->groupid = groupid; |
| 784 | |
| 785 | if (setup_rate(td)) |
| 786 | goto err; |
| 787 | |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 788 | if (td->write_lat_log) { |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 789 | setup_log(&td->ts.slat_log); |
| 790 | setup_log(&td->ts.clat_log); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 791 | } |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 792 | if (td->write_bw_log) |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 793 | setup_log(&td->ts.bw_log); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 794 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 795 | if (!td->name) |
| 796 | td->name = strdup(jobname); |
Jens Axboe | 0145205 | 2006-06-07 10:29:47 +0200 | [diff] [blame] | 797 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 798 | if (!terse_output) { |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 799 | if (!job_add_num) { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 800 | if (td->io_ops->flags & FIO_CPUIO) |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 801 | fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 802 | else { |
| 803 | char *c1, *c2, *c3, *c4; |
| 804 | |
| 805 | c1 = to_kmg(td->min_bs[DDIR_READ]); |
| 806 | c2 = to_kmg(td->max_bs[DDIR_READ]); |
| 807 | c3 = to_kmg(td->min_bs[DDIR_WRITE]); |
| 808 | c4 = to_kmg(td->max_bs[DDIR_WRITE]); |
| 809 | |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame^] | 810 | fprintf(f_out, "%s: (g=%d): rw=%s, bs=%s-%s/%s-%s, ioengine=%s, iodepth=%u\n", td->name, td->groupid, ddir_str[td->td_ddir], c1, c2, c3, c4, td->io_ops->name, td->iodepth); |
Jens Axboe | f8977ee | 2006-11-06 14:03:03 +0100 | [diff] [blame] | 811 | |
| 812 | free(c1); |
| 813 | free(c2); |
| 814 | free(c3); |
| 815 | free(c4); |
| 816 | } |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 817 | } else if (job_add_num == 1) |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 818 | fprintf(f_out, "...\n"); |
| 819 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 820 | |
| 821 | /* |
| 822 | * recurse add identical jobs, clear numjobs and stonewall options |
| 823 | * as they don't apply to sub-jobs |
| 824 | */ |
| 825 | numjobs = td->numjobs; |
| 826 | while (--numjobs) { |
| 827 | struct thread_data *td_new = get_new_job(0, td); |
| 828 | |
| 829 | if (!td_new) |
| 830 | goto err; |
| 831 | |
| 832 | td_new->numjobs = 1; |
| 833 | td_new->stonewall = 0; |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 834 | job_add_num = numjobs - 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 835 | |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 836 | if (add_job(td_new, jobname, job_add_num)) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 837 | goto err; |
| 838 | } |
| 839 | return 0; |
| 840 | err: |
| 841 | put_job(td); |
| 842 | return -1; |
| 843 | } |
| 844 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 845 | /* |
| 846 | * Initialize the various random states we need (random io, block size ranges, |
| 847 | * read/write mix, etc). |
| 848 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 849 | int init_random_state(struct thread_data *td) |
| 850 | { |
Jens Axboe | 0aabe16 | 2007-02-23 08:45:55 +0100 | [diff] [blame] | 851 | unsigned long seeds[5]; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 852 | int fd, num_maps, blocks, i; |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame] | 853 | struct fio_file *f; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 854 | |
Jens Axboe | f48b467 | 2006-10-27 11:30:07 +0200 | [diff] [blame] | 855 | if (td->io_ops->flags & FIO_CPUIO) |
| 856 | return 0; |
| 857 | |
Jens Axboe | 1ac267b | 2006-05-31 20:29:00 +0200 | [diff] [blame] | 858 | fd = open("/dev/urandom", O_RDONLY); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 859 | if (fd == -1) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 860 | td_verror(td, errno, "open"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 861 | return 1; |
| 862 | } |
| 863 | |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 864 | if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) { |
Jens Axboe | e1161c3 | 2007-02-22 19:36:48 +0100 | [diff] [blame] | 865 | td_verror(td, EIO, "read"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 866 | close(fd); |
| 867 | return 1; |
| 868 | } |
| 869 | |
| 870 | close(fd); |
| 871 | |
Jens Axboe | 6dfd46b | 2006-06-07 13:57:06 +0200 | [diff] [blame] | 872 | os_random_seed(seeds[0], &td->bsrange_state); |
| 873 | os_random_seed(seeds[1], &td->verify_state); |
| 874 | os_random_seed(seeds[2], &td->rwmix_state); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 875 | |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame^] | 876 | if (td->file_service_type == FIO_FSERVICE_RANDOM) |
| 877 | os_random_seed(seeds[3], &td->next_file_state); |
| 878 | |
| 879 | if (!td_random(td)) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 880 | return 0; |
| 881 | |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 882 | if (td->rand_repeatable) |
Jens Axboe | 0aabe16 | 2007-02-23 08:45:55 +0100 | [diff] [blame] | 883 | seeds[4] = FIO_RANDSEED * td->thread_number; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 884 | |
Jens Axboe | bb8895e | 2006-10-30 15:14:48 +0100 | [diff] [blame] | 885 | if (!td->norandommap) { |
| 886 | for_each_file(td, f, i) { |
Jens Axboe | a4a8171 | 2007-02-13 20:07:26 +0100 | [diff] [blame] | 887 | blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs; |
Jens Axboe | c7c280e | 2006-11-02 20:10:33 +0100 | [diff] [blame] | 888 | num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP; |
Jens Axboe | bb8895e | 2006-10-30 15:14:48 +0100 | [diff] [blame] | 889 | f->file_map = malloc(num_maps * sizeof(long)); |
| 890 | f->num_maps = num_maps; |
| 891 | memset(f->file_map, 0, num_maps * sizeof(long)); |
| 892 | } |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 893 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 894 | |
Jens Axboe | 0aabe16 | 2007-02-23 08:45:55 +0100 | [diff] [blame] | 895 | os_random_seed(seeds[4], &td->random_state); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 896 | return 0; |
| 897 | } |
| 898 | |
| 899 | static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu) |
| 900 | { |
| 901 | #ifdef FIO_HAVE_CPU_AFFINITY |
| 902 | unsigned int i; |
| 903 | |
| 904 | CPU_ZERO(&cpumask); |
| 905 | |
| 906 | for (i = 0; i < sizeof(int) * 8; i++) { |
| 907 | if ((1 << i) & cpu) |
| 908 | CPU_SET(i, &cpumask); |
| 909 | } |
| 910 | #endif |
| 911 | } |
| 912 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 913 | static int is_empty_or_comment(char *line) |
| 914 | { |
| 915 | unsigned int i; |
| 916 | |
| 917 | for (i = 0; i < strlen(line); i++) { |
| 918 | if (line[i] == ';') |
| 919 | return 1; |
Ingo Molnar | 5cc2da3 | 2007-02-20 10:19:44 +0100 | [diff] [blame] | 920 | if (line[i] == '#') |
| 921 | return 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 922 | if (!isspace(line[i]) && !iscntrl(line[i])) |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | return 1; |
| 927 | } |
| 928 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 929 | static int str_rw_cb(void *data, const char *mem) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 930 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 931 | struct thread_data *td = data; |
| 932 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 933 | if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) { |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame^] | 934 | td->td_ddir = TD_DDIR_READ; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 935 | return 0; |
| 936 | } else if (!strncmp(mem, "randread", 8)) { |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame^] | 937 | td->td_ddir = TD_DDIR_READ | TD_DDIR_RAND; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 938 | return 0; |
| 939 | } else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) { |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame^] | 940 | td->td_ddir = TD_DDIR_WRITE; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 941 | return 0; |
| 942 | } else if (!strncmp(mem, "randwrite", 9)) { |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame^] | 943 | td->td_ddir = TD_DDIR_WRITE | TD_DDIR_RAND; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 944 | return 0; |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 945 | } else if (!strncmp(mem, "rw", 2)) { |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame^] | 946 | td->td_ddir = TD_DDIR_RW; |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 947 | return 0; |
| 948 | } else if (!strncmp(mem, "randrw", 6)) { |
Jens Axboe | 413dd45 | 2007-02-23 09:26:09 +0100 | [diff] [blame^] | 949 | td->td_ddir = TD_DDIR_RW | TD_DDIR_RAND; |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 950 | return 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 951 | } |
| 952 | |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 953 | log_err("fio: data direction: read, write, randread, randwrite, rw, randrw\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 954 | return 1; |
| 955 | } |
| 956 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 957 | static int str_verify_cb(void *data, const char *mem) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 958 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 959 | struct thread_data *td = data; |
| 960 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 961 | if (!strncmp(mem, "0", 1)) { |
| 962 | td->verify = VERIFY_NONE; |
| 963 | return 0; |
| 964 | } else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) { |
| 965 | td->verify = VERIFY_MD5; |
| 966 | return 0; |
| 967 | } else if (!strncmp(mem, "crc32", 5)) { |
| 968 | td->verify = VERIFY_CRC32; |
| 969 | return 0; |
| 970 | } |
| 971 | |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 972 | log_err("fio: verify types: md5, crc32\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 973 | return 1; |
| 974 | } |
| 975 | |
Jens Axboe | 313cb20 | 2006-12-21 09:50:00 +0100 | [diff] [blame] | 976 | /* |
| 977 | * Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that. |
| 978 | */ |
| 979 | static char *get_mmap_file(const char *str) |
| 980 | { |
| 981 | char *p = strstr(str, ":"); |
| 982 | |
| 983 | if (!p) |
| 984 | return NULL; |
| 985 | |
| 986 | p++; |
| 987 | strip_blank_front(&p); |
| 988 | strip_blank_end(p); |
| 989 | return strdup(p); |
| 990 | } |
| 991 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 992 | static int str_mem_cb(void *data, const char *mem) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 993 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 994 | struct thread_data *td = data; |
| 995 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 996 | if (!strncmp(mem, "malloc", 6)) { |
| 997 | td->mem_type = MEM_MALLOC; |
| 998 | return 0; |
Jens Axboe | d0bdaf4 | 2006-12-20 14:40:44 +0100 | [diff] [blame] | 999 | } else if (!strncmp(mem, "mmaphuge", 8)) { |
| 1000 | #ifdef FIO_HAVE_HUGETLB |
Jens Axboe | d0bdaf4 | 2006-12-20 14:40:44 +0100 | [diff] [blame] | 1001 | /* |
| 1002 | * mmaphuge must be appended with the actual file |
| 1003 | */ |
Jens Axboe | 313cb20 | 2006-12-21 09:50:00 +0100 | [diff] [blame] | 1004 | td->mmapfile = get_mmap_file(mem); |
| 1005 | if (!td->mmapfile) { |
Jens Axboe | d0bdaf4 | 2006-12-20 14:40:44 +0100 | [diff] [blame] | 1006 | log_err("fio: mmaphuge:/path/to/file\n"); |
| 1007 | return 1; |
| 1008 | } |
| 1009 | |
Jens Axboe | d0bdaf4 | 2006-12-20 14:40:44 +0100 | [diff] [blame] | 1010 | td->mem_type = MEM_MMAPHUGE; |
| 1011 | return 0; |
| 1012 | #else |
| 1013 | log_err("fio: mmaphuge not available\n"); |
| 1014 | return 1; |
| 1015 | #endif |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1016 | } else if (!strncmp(mem, "mmap", 4)) { |
Jens Axboe | 313cb20 | 2006-12-21 09:50:00 +0100 | [diff] [blame] | 1017 | /* |
| 1018 | * Check if the user wants file backed memory. It's ok |
| 1019 | * if there's no file given, we'll just use anon mamp then. |
| 1020 | */ |
| 1021 | td->mmapfile = get_mmap_file(mem); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1022 | td->mem_type = MEM_MMAP; |
| 1023 | return 0; |
Jens Axboe | 74b025b | 2006-12-19 15:18:14 +0100 | [diff] [blame] | 1024 | } else if (!strncmp(mem, "shmhuge", 7)) { |
| 1025 | #ifdef FIO_HAVE_HUGETLB |
| 1026 | td->mem_type = MEM_SHMHUGE; |
| 1027 | return 0; |
| 1028 | #else |
| 1029 | log_err("fio: shmhuge not available\n"); |
| 1030 | return 1; |
| 1031 | #endif |
Jens Axboe | 0268b8b | 2006-12-20 12:48:23 +0100 | [diff] [blame] | 1032 | } else if (!strncmp(mem, "shm", 3)) { |
| 1033 | td->mem_type = MEM_SHM; |
| 1034 | return 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1035 | } |
| 1036 | |
Jens Axboe | d0bdaf4 | 2006-12-20 14:40:44 +0100 | [diff] [blame] | 1037 | log_err("fio: mem type: malloc, shm, shmhuge, mmap, mmaphuge\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1038 | return 1; |
| 1039 | } |
| 1040 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1041 | static int str_ioengine_cb(void *data, const char *str) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1042 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 1043 | struct thread_data *td = data; |
| 1044 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 1045 | td->io_ops = load_ioengine(td, str); |
| 1046 | if (td->io_ops) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1047 | return 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1048 | |
Jens Axboe | 94cd00d | 2007-02-22 14:08:36 +0100 | [diff] [blame] | 1049 | log_err("fio: ioengine= libaio, posixaio, sync, syslet-rw, mmap, sgio, splice, cpu, null\n"); |
Jens Axboe | 5f35095 | 2006-11-07 15:20:59 +0100 | [diff] [blame] | 1050 | log_err("fio: or specify path to dynamic ioengine module\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1051 | return 1; |
| 1052 | } |
| 1053 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1054 | static int str_lockmem_cb(void fio_unused *data, unsigned long *val) |
| 1055 | { |
| 1056 | mlock_size = *val; |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
Jens Axboe | 34cfcda | 2006-11-03 14:00:45 +0100 | [diff] [blame] | 1060 | #ifdef FIO_HAVE_IOPRIO |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1061 | static int str_prioclass_cb(void *data, unsigned int *val) |
| 1062 | { |
| 1063 | struct thread_data *td = data; |
| 1064 | |
| 1065 | td->ioprio |= *val << IOPRIO_CLASS_SHIFT; |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
| 1069 | static int str_prio_cb(void *data, unsigned int *val) |
| 1070 | { |
| 1071 | struct thread_data *td = data; |
| 1072 | |
| 1073 | td->ioprio |= *val; |
| 1074 | return 0; |
| 1075 | } |
Jens Axboe | 34cfcda | 2006-11-03 14:00:45 +0100 | [diff] [blame] | 1076 | #endif |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1077 | |
| 1078 | static int str_exitall_cb(void) |
| 1079 | { |
| 1080 | exitall_on_terminate = 1; |
| 1081 | return 0; |
| 1082 | } |
| 1083 | |
| 1084 | static int str_cpumask_cb(void *data, unsigned int *val) |
| 1085 | { |
| 1086 | struct thread_data *td = data; |
| 1087 | |
| 1088 | fill_cpu_mask(td->cpumask, *val); |
| 1089 | return 0; |
| 1090 | } |
| 1091 | |
Jens Axboe | 0aabe16 | 2007-02-23 08:45:55 +0100 | [diff] [blame] | 1092 | static int str_file_service_cb(void *data, const char *str) |
| 1093 | { |
| 1094 | struct thread_data *td = data; |
| 1095 | |
| 1096 | if (!strncmp(str, "random", 6)) { |
| 1097 | td->file_service_type = FIO_FSERVICE_RANDOM; |
| 1098 | return 0; |
| 1099 | } else if (!strncmp(str, "roundrobin", 10)) { |
| 1100 | td->file_service_type = FIO_FSERVICE_RR; |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
| 1104 | log_err("fio: file_service= random, roundrobin\n"); |
| 1105 | return 1; |
| 1106 | } |
| 1107 | |
Jens Axboe | 0726198 | 2006-06-07 10:51:12 +0200 | [diff] [blame] | 1108 | /* |
| 1109 | * This is our [ini] type file parser. |
| 1110 | */ |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 1111 | static int parse_jobs_ini(char *file, int stonewall_flag) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1112 | { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1113 | unsigned int global; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1114 | struct thread_data *td; |
Jens Axboe | fee3bb4 | 2006-10-30 13:32:08 +0100 | [diff] [blame] | 1115 | char *string, *name; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1116 | fpos_t off; |
| 1117 | FILE *f; |
| 1118 | char *p; |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 1119 | int ret = 0, stonewall; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1120 | |
| 1121 | f = fopen(file, "r"); |
| 1122 | if (!f) { |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 1123 | perror("fopen job file"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1124 | return 1; |
| 1125 | } |
| 1126 | |
| 1127 | string = malloc(4096); |
| 1128 | name = malloc(256); |
Jens Axboe | fee3bb4 | 2006-10-30 13:32:08 +0100 | [diff] [blame] | 1129 | memset(name, 0, 256); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1130 | |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 1131 | stonewall = stonewall_flag; |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1132 | do { |
| 1133 | p = fgets(string, 4095, f); |
| 1134 | if (!p) |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1135 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1136 | if (is_empty_or_comment(p)) |
| 1137 | continue; |
Jens Axboe | fee3bb4 | 2006-10-30 13:32:08 +0100 | [diff] [blame] | 1138 | if (sscanf(p, "[%255s]", name) != 1) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1139 | continue; |
| 1140 | |
| 1141 | global = !strncmp(name, "global", 6); |
| 1142 | |
| 1143 | name[strlen(name) - 1] = '\0'; |
| 1144 | |
| 1145 | td = get_new_job(global, &def_thread); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1146 | if (!td) { |
| 1147 | ret = 1; |
| 1148 | break; |
| 1149 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1150 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1151 | /* |
| 1152 | * Seperate multiple job files by a stonewall |
| 1153 | */ |
Jens Axboe | f948191 | 2006-06-09 11:37:28 +0200 | [diff] [blame] | 1154 | if (!global && stonewall) { |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1155 | td->stonewall = stonewall; |
| 1156 | stonewall = 0; |
| 1157 | } |
| 1158 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1159 | fgetpos(f, &off); |
| 1160 | while ((p = fgets(string, 4096, f)) != NULL) { |
| 1161 | if (is_empty_or_comment(p)) |
| 1162 | continue; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1163 | |
Jens Axboe | b6754f9 | 2006-05-30 14:29:32 +0200 | [diff] [blame] | 1164 | strip_blank_front(&p); |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1165 | |
| 1166 | if (p[0] == '[') |
| 1167 | break; |
| 1168 | |
Jens Axboe | 4ae3f76 | 2006-05-30 13:35:14 +0200 | [diff] [blame] | 1169 | strip_blank_end(p); |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 1170 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 1171 | fgetpos(f, &off); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1172 | |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1173 | /* |
| 1174 | * Don't break here, continue parsing options so we |
| 1175 | * dump all the bad ones. Makes trial/error fixups |
| 1176 | * easier on the user. |
| 1177 | */ |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1178 | ret |= parse_option(p, options, td); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1179 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1180 | |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1181 | if (!ret) { |
| 1182 | fsetpos(f, &off); |
| 1183 | ret = add_job(td, name, 0); |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 1184 | } else { |
| 1185 | log_err("fio: job %s dropped\n", name); |
| 1186 | put_job(td); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1187 | } |
Jens Axboe | 7c124ac | 2006-10-30 13:36:52 +0100 | [diff] [blame] | 1188 | } while (!ret); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1189 | |
| 1190 | free(string); |
| 1191 | free(name); |
| 1192 | fclose(f); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1193 | return ret; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | static int fill_def_thread(void) |
| 1197 | { |
| 1198 | memset(&def_thread, 0, sizeof(def_thread)); |
| 1199 | |
| 1200 | if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) { |
| 1201 | perror("sched_getaffinity"); |
| 1202 | return 1; |
| 1203 | } |
| 1204 | |
| 1205 | /* |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1206 | * fill default options |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1207 | */ |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1208 | fill_default_options(&def_thread, options); |
| 1209 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1210 | def_thread.timeout = def_timeout; |
Jens Axboe | ec94ec5 | 2006-10-20 10:59:19 +0200 | [diff] [blame] | 1211 | def_thread.write_bw_log = write_bw_log; |
| 1212 | def_thread.write_lat_log = write_lat_log; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 1213 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1214 | #ifdef FIO_HAVE_DISK_UTIL |
| 1215 | def_thread.do_disk_util = 1; |
| 1216 | #endif |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame] | 1221 | static void usage(void) |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 1222 | { |
| 1223 | printf("%s\n", fio_version_string); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1224 | printf("\t--output\tWrite output to file\n"); |
| 1225 | printf("\t--timeout\tRuntime in seconds\n"); |
| 1226 | printf("\t--latency-log\tGenerate per-job latency logs\n"); |
| 1227 | printf("\t--bandwidth-log\tGenerate per-job bandwidth logs\n"); |
| 1228 | printf("\t--minimal\tMinimal (terse) output\n"); |
| 1229 | printf("\t--version\tPrint version info and exit\n"); |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 1230 | printf("\t--help\t\tPrint this page\n"); |
| 1231 | printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n"); |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 1232 | } |
| 1233 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1234 | static int parse_cmd_line(int argc, char *argv[]) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1235 | { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1236 | struct thread_data *td = NULL; |
Jens Axboe | c2b1e75 | 2006-10-30 09:03:13 +0100 | [diff] [blame] | 1237 | int c, ini_idx = 0, lidx, ret; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1238 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1239 | while ((c = getopt_long(argc, argv, "", long_options, &lidx)) != -1) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1240 | switch (c) { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1241 | case 't': |
| 1242 | def_timeout = atoi(optarg); |
| 1243 | break; |
| 1244 | case 'l': |
| 1245 | write_lat_log = 1; |
| 1246 | break; |
| 1247 | case 'w': |
| 1248 | write_bw_log = 1; |
| 1249 | break; |
| 1250 | case 'o': |
| 1251 | f_out = fopen(optarg, "w+"); |
| 1252 | if (!f_out) { |
| 1253 | perror("fopen output"); |
| 1254 | exit(1); |
| 1255 | } |
| 1256 | f_err = f_out; |
| 1257 | break; |
| 1258 | case 'm': |
| 1259 | terse_output = 1; |
| 1260 | break; |
| 1261 | case 'h': |
| 1262 | usage(); |
| 1263 | exit(0); |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 1264 | case 'c': |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 1265 | ret = show_cmd_help(options, optarg); |
| 1266 | exit(ret); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1267 | case 'v': |
| 1268 | printf("%s\n", fio_version_string); |
| 1269 | exit(0); |
| 1270 | case FIO_GETOPT_JOB: { |
| 1271 | const char *opt = long_options[lidx].name; |
| 1272 | char *val = optarg; |
| 1273 | |
Jens Axboe | c2b1e75 | 2006-10-30 09:03:13 +0100 | [diff] [blame] | 1274 | if (!strncmp(opt, "name", 4) && td) { |
| 1275 | ret = add_job(td, td->name ?: "fio", 0); |
| 1276 | if (ret) { |
| 1277 | put_job(td); |
| 1278 | return 0; |
| 1279 | } |
| 1280 | td = NULL; |
| 1281 | } |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1282 | if (!td) { |
Jens Axboe | 38d0adb | 2006-10-30 12:21:25 +0100 | [diff] [blame] | 1283 | int global = !strncmp(val, "global", 6); |
Jens Axboe | c2b1e75 | 2006-10-30 09:03:13 +0100 | [diff] [blame] | 1284 | |
| 1285 | td = get_new_job(global, &def_thread); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1286 | if (!td) |
| 1287 | return 0; |
| 1288 | } |
Jens Axboe | 38d0adb | 2006-10-30 12:21:25 +0100 | [diff] [blame] | 1289 | |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 1290 | ret = parse_cmd_option(opt, val, options, td); |
| 1291 | if (ret) { |
| 1292 | log_err("fio: job dropped\n"); |
| 1293 | put_job(td); |
| 1294 | td = NULL; |
| 1295 | } |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1296 | break; |
| 1297 | } |
| 1298 | default: |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1299 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1300 | } |
| 1301 | } |
Jens Axboe | c9fad89 | 2006-05-27 17:26:50 +0200 | [diff] [blame] | 1302 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1303 | if (td) { |
Jens Axboe | c2b1e75 | 2006-10-30 09:03:13 +0100 | [diff] [blame] | 1304 | ret = add_job(td, td->name ?: "fio", 0); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1305 | if (ret) |
| 1306 | put_job(td); |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1307 | } |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 1308 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1309 | while (optind < argc) { |
| 1310 | ini_idx++; |
| 1311 | ini_file = realloc(ini_file, ini_idx * sizeof(char *)); |
| 1312 | ini_file[ini_idx - 1] = strdup(argv[optind]); |
| 1313 | optind++; |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 1314 | } |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1315 | |
| 1316 | return ini_idx; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | static void free_shm(void) |
| 1320 | { |
| 1321 | struct shmid_ds sbuf; |
| 1322 | |
| 1323 | if (threads) { |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 1324 | shmdt((void *) threads); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1325 | threads = NULL; |
| 1326 | shmctl(shm_id, IPC_RMID, &sbuf); |
| 1327 | } |
| 1328 | } |
| 1329 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1330 | /* |
| 1331 | * The thread area is shared between the main process and the job |
| 1332 | * threads/processes. So setup a shared memory segment that will hold |
| 1333 | * all the job info. |
| 1334 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1335 | static int setup_thread_area(void) |
| 1336 | { |
| 1337 | /* |
| 1338 | * 1024 is too much on some machines, scale max_jobs if |
| 1339 | * we get a failure that looks like too large a shm segment |
| 1340 | */ |
| 1341 | do { |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1342 | size_t size = max_jobs * sizeof(struct thread_data); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1343 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1344 | shm_id = shmget(0, size, IPC_CREAT | 0600); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1345 | if (shm_id != -1) |
| 1346 | break; |
| 1347 | if (errno != EINVAL) { |
| 1348 | perror("shmget"); |
| 1349 | break; |
| 1350 | } |
| 1351 | |
| 1352 | max_jobs >>= 1; |
| 1353 | } while (max_jobs); |
| 1354 | |
| 1355 | if (shm_id == -1) |
| 1356 | return 1; |
| 1357 | |
| 1358 | threads = shmat(shm_id, NULL, 0); |
| 1359 | if (threads == (void *) -1) { |
| 1360 | perror("shmat"); |
| 1361 | return 1; |
| 1362 | } |
| 1363 | |
| 1364 | atexit(free_shm); |
| 1365 | return 0; |
| 1366 | } |
| 1367 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1368 | /* |
| 1369 | * Copy the fio options into the long options map, so we mirror |
| 1370 | * job and cmd line options. |
| 1371 | */ |
| 1372 | static void dupe_job_options(void) |
| 1373 | { |
| 1374 | struct fio_option *o; |
| 1375 | unsigned int i; |
| 1376 | |
| 1377 | i = 0; |
| 1378 | while (long_options[i].name) |
| 1379 | i++; |
| 1380 | |
| 1381 | o = &options[0]; |
| 1382 | while (o->name) { |
| 1383 | long_options[i].name = o->name; |
| 1384 | long_options[i].val = FIO_GETOPT_JOB; |
| 1385 | if (o->type == FIO_OPT_STR_SET) |
| 1386 | long_options[i].has_arg = no_argument; |
| 1387 | else |
| 1388 | long_options[i].has_arg = required_argument; |
| 1389 | |
| 1390 | i++; |
| 1391 | o++; |
| 1392 | assert(i < FIO_JOB_OPTS + FIO_CMD_OPTS); |
| 1393 | } |
| 1394 | } |
| 1395 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1396 | int parse_options(int argc, char *argv[]) |
| 1397 | { |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1398 | int job_files, i; |
| 1399 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1400 | f_out = stdout; |
| 1401 | f_err = stderr; |
| 1402 | |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 1403 | options_init(options); |
| 1404 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1405 | dupe_job_options(); |
| 1406 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1407 | if (setup_thread_area()) |
| 1408 | return 1; |
| 1409 | if (fill_def_thread()) |
| 1410 | return 1; |
| 1411 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1412 | job_files = parse_cmd_line(argc, argv); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1413 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1414 | for (i = 0; i < job_files; i++) { |
| 1415 | if (fill_def_thread()) |
| 1416 | return 1; |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 1417 | if (parse_jobs_ini(ini_file[i], i)) |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1418 | return 1; |
Jens Axboe | 88c6ed8 | 2006-06-09 11:28:10 +0200 | [diff] [blame] | 1419 | free(ini_file[i]); |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1420 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1421 | |
Jens Axboe | 88c6ed8 | 2006-06-09 11:28:10 +0200 | [diff] [blame] | 1422 | free(ini_file); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1423 | |
| 1424 | if (!thread_number) { |
| 1425 | log_err("No jobs defined(s)\n"); |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 1426 | return 1; |
| 1427 | } |
| 1428 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1429 | return 0; |
| 1430 | } |