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