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