Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file contains the ini and command liner parser. It will create |
| 3 | * and initialize the specified jobs. |
| 4 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <unistd.h> |
| 8 | #include <fcntl.h> |
| 9 | #include <ctype.h> |
| 10 | #include <string.h> |
| 11 | #include <errno.h> |
| 12 | #include <sys/ipc.h> |
| 13 | #include <sys/shm.h> |
| 14 | #include <sys/types.h> |
| 15 | #include <sys/stat.h> |
| 16 | |
| 17 | #include "fio.h" |
| 18 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 19 | /* |
| 20 | * The default options |
| 21 | */ |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 22 | #define DEF_BS (4096) |
| 23 | #define DEF_TIMEOUT (0) |
| 24 | #define DEF_RATE_CYCLE (1000) |
| 25 | #define DEF_ODIRECT (1) |
| 26 | #define DEF_IO_ENGINE (FIO_SYNCIO) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 27 | #define DEF_IO_ENGINE_NAME "sync" |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 28 | #define DEF_SEQUENTIAL (1) |
| 29 | #define DEF_RAND_REPEAT (1) |
| 30 | #define DEF_OVERWRITE (1) |
| 31 | #define DEF_CREATE (1) |
| 32 | #define DEF_INVALIDATE (1) |
| 33 | #define DEF_SYNCIO (0) |
| 34 | #define DEF_RANDSEED (0xb1899bedUL) |
| 35 | #define DEF_BWAVGTIME (500) |
| 36 | #define DEF_CREATE_SER (1) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 37 | #define DEF_CREATE_FSYNC (1) |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 38 | #define DEF_LOOPS (1) |
| 39 | #define DEF_VERIFY (0) |
| 40 | #define DEF_STONEWALL (0) |
| 41 | #define DEF_NUMJOBS (1) |
| 42 | #define DEF_USE_THREAD (0) |
| 43 | #define DEF_FILE_SIZE (1024 * 1024 * 1024UL) |
| 44 | #define DEF_ZONE_SIZE (0) |
| 45 | #define DEF_ZONE_SKIP (0) |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 46 | #define DEF_RWMIX_CYCLE (500) |
| 47 | #define DEF_RWMIX_READ (50) |
Jens Axboe | b6f4d88 | 2006-06-02 10:32:51 +0200 | [diff] [blame] | 48 | #define DEF_NICE (0) |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 49 | #define DEF_NR_FILES (1) |
Jens Axboe | f6cbb26 | 2006-10-18 14:16:42 +0200 | [diff] [blame] | 50 | #define DEF_UNLINK (0) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 51 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 52 | static int def_timeout = DEF_TIMEOUT; |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 53 | |
Jens Axboe | f4866ec | 2006-06-13 09:38:36 +0200 | [diff] [blame] | 54 | static char fio_version_string[] = "fio 1.5"; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 55 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 56 | static char **ini_file; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 57 | static int max_jobs = MAX_JOBS; |
| 58 | |
| 59 | struct thread_data def_thread; |
| 60 | struct thread_data *threads = NULL; |
| 61 | |
| 62 | int rate_quit = 0; |
| 63 | int write_lat_log = 0; |
| 64 | int write_bw_log = 0; |
| 65 | int exitall_on_terminate = 0; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 66 | int terse_output = 0; |
Jens Axboe | c04f7ec | 2006-05-31 10:13:16 +0200 | [diff] [blame] | 67 | unsigned long long mlock_size = 0; |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 68 | FILE *f_out = NULL; |
| 69 | FILE *f_err = NULL; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 70 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 71 | /* |
| 72 | * Return a free job structure. |
| 73 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 74 | static struct thread_data *get_new_job(int global, struct thread_data *parent) |
| 75 | { |
| 76 | struct thread_data *td; |
| 77 | |
| 78 | if (global) |
| 79 | return &def_thread; |
| 80 | if (thread_number >= max_jobs) |
| 81 | return NULL; |
| 82 | |
| 83 | td = &threads[thread_number++]; |
Jens Axboe | ddaeaa5 | 2006-06-08 11:00:58 +0200 | [diff] [blame] | 84 | *td = *parent; |
| 85 | td->name[0] = '\0'; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 86 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 87 | td->thread_number = thread_number; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 88 | return td; |
| 89 | } |
| 90 | |
| 91 | static void put_job(struct thread_data *td) |
| 92 | { |
| 93 | memset(&threads[td->thread_number - 1], 0, sizeof(*td)); |
| 94 | thread_number--; |
| 95 | } |
| 96 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 97 | /* |
| 98 | * Adds a job to the list of things todo. Sanitizes the various options |
| 99 | * to make sure we don't have conflicts, and initializes various |
| 100 | * members of td. |
| 101 | */ |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 102 | 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] | 103 | { |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 104 | char *ddir_str[] = { "read", "write", "randread", "randwrite", |
| 105 | "rw", NULL, "randrw" }; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 106 | struct stat sb; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 107 | int numjobs, ddir, i; |
| 108 | struct fio_file *f; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 109 | |
| 110 | #ifndef FIO_HAVE_LIBAIO |
| 111 | if (td->io_engine == FIO_LIBAIO) { |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 112 | log_err("Linux libaio not available\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 113 | return 1; |
| 114 | } |
| 115 | #endif |
| 116 | #ifndef FIO_HAVE_POSIXAIO |
| 117 | if (td->io_engine == FIO_POSIXAIO) { |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 118 | log_err("posix aio not available\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 119 | return 1; |
| 120 | } |
| 121 | #endif |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 122 | |
| 123 | /* |
| 124 | * the def_thread is just for options, it's not a real job |
| 125 | */ |
| 126 | if (td == &def_thread) |
| 127 | return 0; |
| 128 | |
Jens Axboe | df64119 | 2006-10-12 07:55:41 +0200 | [diff] [blame] | 129 | /* |
| 130 | * Set default io engine, if none set |
| 131 | */ |
| 132 | if (!td->io_ops) { |
| 133 | td->io_ops = load_ioengine(td, DEF_IO_ENGINE_NAME); |
| 134 | if (!td->io_ops) { |
| 135 | log_err("default engine %s not there?\n", DEF_IO_ENGINE_NAME); |
| 136 | return 1; |
| 137 | } |
| 138 | } |
| 139 | |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 140 | if (td->io_ops->flags & FIO_SYNCIO) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 141 | td->iodepth = 1; |
| 142 | else { |
| 143 | if (!td->iodepth) |
| 144 | td->iodepth = 1; |
| 145 | } |
| 146 | |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 147 | /* |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 148 | * only really works for sequential io for now, and with 1 file |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 149 | */ |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 150 | if (td->zone_size && !td->sequential && td->nr_files == 1) |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 151 | td->zone_size = 0; |
| 152 | |
Jens Axboe | 9cc935a | 2006-06-13 09:11:18 +0200 | [diff] [blame] | 153 | /* |
| 154 | * Reads can do overwrites, we always need to pre-create the file |
| 155 | */ |
| 156 | if (td_read(td) || td_rw(td)) |
| 157 | td->overwrite = 1; |
| 158 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 159 | td->filetype = FIO_TYPE_FILE; |
Jens Axboe | 0af7b54 | 2006-02-17 10:10:12 +0100 | [diff] [blame] | 160 | if (!stat(jobname, &sb)) { |
| 161 | if (S_ISBLK(sb.st_mode)) |
| 162 | td->filetype = FIO_TYPE_BD; |
| 163 | else if (S_ISCHR(sb.st_mode)) |
| 164 | td->filetype = FIO_TYPE_CHAR; |
| 165 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 166 | |
Jens Axboe | b2a1519 | 2006-10-18 14:10:42 +0200 | [diff] [blame] | 167 | if (td->odirect) |
| 168 | td->io_ops->flags |= FIO_RAWIO; |
| 169 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 170 | if (td->filetype == FIO_TYPE_FILE) { |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 171 | char tmp[PATH_MAX]; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 172 | int len = 0; |
| 173 | int i; |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 174 | |
Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 175 | if (td->directory && td->directory[0] != '\0') |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 176 | sprintf(tmp, "%s/", td->directory); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 177 | |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 178 | td->files = malloc(sizeof(struct fio_file) * td->nr_files); |
| 179 | |
| 180 | for_each_file(td, f, i) { |
| 181 | memset(f, 0, sizeof(*f)); |
| 182 | f->fd = -1; |
Jens Axboe | b2a1519 | 2006-10-18 14:10:42 +0200 | [diff] [blame] | 183 | f->fileno = i; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 184 | |
| 185 | sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i); |
| 186 | f->file_name = strdup(tmp); |
| 187 | } |
| 188 | } else { |
| 189 | td->nr_files = 1; |
| 190 | td->files = malloc(sizeof(struct fio_file)); |
| 191 | f = &td->files[0]; |
| 192 | |
| 193 | memset(f, 0, sizeof(*f)); |
| 194 | f->fd = -1; |
| 195 | f->file_name = strdup(jobname); |
| 196 | } |
| 197 | |
| 198 | for_each_file(td, f, i) { |
| 199 | f->file_size = td->total_file_size / td->nr_files; |
| 200 | f->file_offset = td->start_offset; |
| 201 | } |
| 202 | |
Jens Axboe | bbfd6b0 | 2006-06-07 19:42:54 +0200 | [diff] [blame] | 203 | fio_sem_init(&td->mutex, 0); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 204 | |
| 205 | td->clat_stat[0].min_val = td->clat_stat[1].min_val = ULONG_MAX; |
| 206 | td->slat_stat[0].min_val = td->slat_stat[1].min_val = ULONG_MAX; |
| 207 | td->bw_stat[0].min_val = td->bw_stat[1].min_val = ULONG_MAX; |
| 208 | |
| 209 | if (td->min_bs == -1U) |
| 210 | td->min_bs = td->bs; |
| 211 | if (td->max_bs == -1U) |
| 212 | td->max_bs = td->bs; |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 213 | if (td_read(td) && !td_rw(td)) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 214 | td->verify = 0; |
| 215 | |
| 216 | if (td->stonewall && td->thread_number > 1) |
| 217 | groupid++; |
| 218 | |
| 219 | td->groupid = groupid; |
| 220 | |
| 221 | if (setup_rate(td)) |
| 222 | goto err; |
| 223 | |
| 224 | if (write_lat_log) { |
| 225 | setup_log(&td->slat_log); |
| 226 | setup_log(&td->clat_log); |
| 227 | } |
| 228 | if (write_bw_log) |
| 229 | setup_log(&td->bw_log); |
| 230 | |
Jens Axboe | 0145205 | 2006-06-07 10:29:47 +0200 | [diff] [blame] | 231 | if (td->name[0] == '\0') |
| 232 | snprintf(td->name, sizeof(td->name)-1, "client%d", td->thread_number); |
| 233 | |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 234 | ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2); |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 235 | |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 236 | if (!terse_output) { |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 237 | if (!job_add_num) { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 238 | if (td->io_ops->flags & FIO_CPUIO) |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 239 | fprintf(f_out, "%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->name, td->cpuload, td->cpucycle); |
| 240 | else |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 241 | fprintf(f_out, "%s: (g=%d): rw=%s, odir=%d, bs=%d-%d, rate=%d, ioengine=%s, iodepth=%d\n", td->name, td->groupid, ddir_str[ddir], td->odirect, td->min_bs, td->max_bs, td->rate, td->io_ops->name, td->iodepth); |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 242 | } else if (job_add_num == 1) |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 243 | fprintf(f_out, "...\n"); |
| 244 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 245 | |
| 246 | /* |
| 247 | * recurse add identical jobs, clear numjobs and stonewall options |
| 248 | * as they don't apply to sub-jobs |
| 249 | */ |
| 250 | numjobs = td->numjobs; |
| 251 | while (--numjobs) { |
| 252 | struct thread_data *td_new = get_new_job(0, td); |
| 253 | |
| 254 | if (!td_new) |
| 255 | goto err; |
| 256 | |
| 257 | td_new->numjobs = 1; |
| 258 | td_new->stonewall = 0; |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 259 | job_add_num = numjobs - 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 260 | |
Jens Axboe | 7515484 | 2006-06-01 13:56:09 +0200 | [diff] [blame] | 261 | if (add_job(td_new, jobname, job_add_num)) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 262 | goto err; |
| 263 | } |
| 264 | return 0; |
| 265 | err: |
| 266 | put_job(td); |
| 267 | return -1; |
| 268 | } |
| 269 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 270 | /* |
| 271 | * Initialize the various random states we need (random io, block size ranges, |
| 272 | * read/write mix, etc). |
| 273 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 274 | int init_random_state(struct thread_data *td) |
| 275 | { |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 276 | unsigned long seeds[4]; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 277 | int fd, num_maps, blocks, i; |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame^] | 278 | struct fio_file *f; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 279 | |
Jens Axboe | 1ac267b | 2006-05-31 20:29:00 +0200 | [diff] [blame] | 280 | fd = open("/dev/urandom", O_RDONLY); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 281 | if (fd == -1) { |
| 282 | td_verror(td, errno); |
| 283 | return 1; |
| 284 | } |
| 285 | |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 286 | if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 287 | td_verror(td, EIO); |
| 288 | close(fd); |
| 289 | return 1; |
| 290 | } |
| 291 | |
| 292 | close(fd); |
| 293 | |
Jens Axboe | 6dfd46b | 2006-06-07 13:57:06 +0200 | [diff] [blame] | 294 | os_random_seed(seeds[0], &td->bsrange_state); |
| 295 | os_random_seed(seeds[1], &td->verify_state); |
| 296 | os_random_seed(seeds[2], &td->rwmix_state); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 297 | |
| 298 | if (td->sequential) |
| 299 | return 0; |
| 300 | |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 301 | if (td->rand_repeatable) |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 302 | seeds[3] = DEF_RANDSEED; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 303 | |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame^] | 304 | for_each_file(td, f, i) { |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 305 | blocks = (f->file_size + td->min_bs - 1) / td->min_bs; |
| 306 | num_maps = blocks / BLOCKS_PER_MAP; |
| 307 | f->file_map = malloc(num_maps * sizeof(long)); |
| 308 | f->num_maps = num_maps; |
| 309 | memset(f->file_map, 0, num_maps * sizeof(long)); |
| 310 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 311 | |
Jens Axboe | 6dfd46b | 2006-06-07 13:57:06 +0200 | [diff] [blame] | 312 | os_random_seed(seeds[3], &td->random_state); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu) |
| 317 | { |
| 318 | #ifdef FIO_HAVE_CPU_AFFINITY |
| 319 | unsigned int i; |
| 320 | |
| 321 | CPU_ZERO(&cpumask); |
| 322 | |
| 323 | for (i = 0; i < sizeof(int) * 8; i++) { |
| 324 | if ((1 << i) & cpu) |
| 325 | CPU_SET(i, &cpumask); |
| 326 | } |
| 327 | #endif |
| 328 | } |
| 329 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 330 | static unsigned long get_mult_time(char c) |
| 331 | { |
| 332 | switch (c) { |
| 333 | case 'm': |
| 334 | case 'M': |
| 335 | return 60; |
| 336 | case 'h': |
| 337 | case 'H': |
| 338 | return 60 * 60; |
| 339 | case 'd': |
| 340 | case 'D': |
| 341 | return 24 * 60 * 60; |
| 342 | default: |
| 343 | return 1; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | static unsigned long get_mult_bytes(char c) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 348 | { |
| 349 | switch (c) { |
| 350 | case 'k': |
| 351 | case 'K': |
| 352 | return 1024; |
| 353 | case 'm': |
| 354 | case 'M': |
| 355 | return 1024 * 1024; |
| 356 | case 'g': |
| 357 | case 'G': |
| 358 | return 1024 * 1024 * 1024; |
| 359 | default: |
| 360 | return 1; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /* |
| 365 | * convert string after '=' into decimal value, noting any size suffix |
| 366 | */ |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 367 | static int str_to_decimal(char *p, unsigned long long *val, int kilo) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 368 | { |
| 369 | char *str; |
| 370 | int len; |
| 371 | |
Jens Axboe | f5d3e5e | 2005-12-08 20:05:38 +0100 | [diff] [blame] | 372 | str = strchr(p, '='); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 373 | if (!str) |
| 374 | return 1; |
| 375 | |
| 376 | str++; |
| 377 | len = strlen(str); |
| 378 | |
| 379 | *val = strtoul(str, NULL, 10); |
| 380 | if (*val == ULONG_MAX && errno == ERANGE) |
| 381 | return 1; |
| 382 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 383 | if (kilo) |
| 384 | *val *= get_mult_bytes(str[len - 1]); |
| 385 | else |
| 386 | *val *= get_mult_time(str[len - 1]); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 390 | static int check_str_bytes(char *p, char *name, unsigned long long *val) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 391 | { |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 392 | if (strncmp(p, name, strlen(name) - 1)) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 393 | return 1; |
| 394 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 395 | return str_to_decimal(p, val, 1); |
| 396 | } |
| 397 | |
| 398 | static int check_str_time(char *p, char *name, unsigned long long *val) |
| 399 | { |
| 400 | if (strncmp(p, name, strlen(name) - 1)) |
| 401 | return 1; |
| 402 | |
| 403 | return str_to_decimal(p, val, 0); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static void strip_blank_front(char **p) |
| 407 | { |
| 408 | char *s = *p; |
| 409 | |
Jens Axboe | 4ae3f76 | 2006-05-30 13:35:14 +0200 | [diff] [blame] | 410 | while (isspace(*s)) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 411 | s++; |
| 412 | } |
| 413 | |
| 414 | static void strip_blank_end(char *p) |
| 415 | { |
Jens Axboe | 4ae3f76 | 2006-05-30 13:35:14 +0200 | [diff] [blame] | 416 | char *s = p + strlen(p) - 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 417 | |
Jens Axboe | 4ae3f76 | 2006-05-30 13:35:14 +0200 | [diff] [blame] | 418 | while (isspace(*s) || iscntrl(*s)) |
| 419 | s--; |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 420 | |
Jens Axboe | 4ae3f76 | 2006-05-30 13:35:14 +0200 | [diff] [blame] | 421 | *(s + 1) = '\0'; |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 422 | } |
| 423 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 424 | typedef int (str_cb_fn)(struct thread_data *, char *); |
| 425 | |
| 426 | static int check_str(char *p, char *name, str_cb_fn *cb, struct thread_data *td) |
| 427 | { |
Jens Axboe | 843a741 | 2006-06-01 21:14:21 -0700 | [diff] [blame] | 428 | char *s; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 429 | |
Jens Axboe | 843a741 | 2006-06-01 21:14:21 -0700 | [diff] [blame] | 430 | if (strncmp(p, name, strlen(name))) |
| 431 | return 1; |
| 432 | |
| 433 | s = strstr(p, name); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 434 | if (!s) |
| 435 | return 1; |
| 436 | |
Jens Axboe | f5d3e5e | 2005-12-08 20:05:38 +0100 | [diff] [blame] | 437 | s = strchr(s, '='); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 438 | if (!s) |
| 439 | return 1; |
| 440 | |
| 441 | s++; |
| 442 | strip_blank_front(&s); |
| 443 | return cb(td, s); |
| 444 | } |
| 445 | |
| 446 | static int check_strstore(char *p, char *name, char *dest) |
| 447 | { |
Jens Axboe | 843a741 | 2006-06-01 21:14:21 -0700 | [diff] [blame] | 448 | char *s; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 449 | |
Jens Axboe | 843a741 | 2006-06-01 21:14:21 -0700 | [diff] [blame] | 450 | if (strncmp(p, name, strlen(name))) |
| 451 | return 1; |
| 452 | |
| 453 | s = strstr(p, name); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 454 | if (!s) |
| 455 | return 1; |
| 456 | |
Jens Axboe | f5d3e5e | 2005-12-08 20:05:38 +0100 | [diff] [blame] | 457 | s = strchr(p, '='); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 458 | if (!s) |
| 459 | return 1; |
| 460 | |
| 461 | s++; |
| 462 | strip_blank_front(&s); |
| 463 | |
| 464 | strcpy(dest, s); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 465 | return 0; |
| 466 | } |
| 467 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 468 | static int __check_range_bytes(char *str, unsigned long *val) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 469 | { |
Jens Axboe | 01617be | 2005-12-08 19:50:40 +0100 | [diff] [blame] | 470 | char suffix; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 471 | |
Jens Axboe | 01617be | 2005-12-08 19:50:40 +0100 | [diff] [blame] | 472 | if (sscanf(str, "%lu%c", val, &suffix) == 2) { |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 473 | *val *= get_mult_bytes(suffix); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 474 | return 0; |
| 475 | } |
| 476 | |
Jens Axboe | 01617be | 2005-12-08 19:50:40 +0100 | [diff] [blame] | 477 | if (sscanf(str, "%lu", val) == 1) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 478 | return 0; |
| 479 | |
| 480 | return 1; |
Jens Axboe | 01617be | 2005-12-08 19:50:40 +0100 | [diff] [blame] | 481 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 482 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 483 | static int check_range_bytes(char *p, char *name, unsigned long *s, |
| 484 | unsigned long *e) |
Jens Axboe | 01617be | 2005-12-08 19:50:40 +0100 | [diff] [blame] | 485 | { |
| 486 | char option[128]; |
| 487 | char *str, *p1, *p2; |
| 488 | |
Jens Axboe | 843a741 | 2006-06-01 21:14:21 -0700 | [diff] [blame] | 489 | if (strncmp(p, name, strlen(name))) |
| 490 | return 1; |
| 491 | |
Jens Axboe | 01617be | 2005-12-08 19:50:40 +0100 | [diff] [blame] | 492 | strcpy(option, p); |
| 493 | p = option; |
| 494 | |
| 495 | str = strstr(p, name); |
| 496 | if (!str) |
| 497 | return 1; |
| 498 | |
| 499 | p += strlen(name); |
| 500 | |
| 501 | str = strchr(p, '='); |
| 502 | if (!str) |
| 503 | return 1; |
| 504 | |
| 505 | /* |
| 506 | * 'p' now holds whatever is after the '=' sign |
| 507 | */ |
| 508 | p1 = str + 1; |
| 509 | |
| 510 | /* |
| 511 | * terminate p1 at the '-' sign |
| 512 | */ |
| 513 | p = strchr(p1, '-'); |
| 514 | if (!p) |
| 515 | return 1; |
| 516 | |
| 517 | p2 = p + 1; |
| 518 | *p = '\0'; |
| 519 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 520 | if (!__check_range_bytes(p1, s) && !__check_range_bytes(p2, e)) |
Jens Axboe | 01617be | 2005-12-08 19:50:40 +0100 | [diff] [blame] | 521 | return 0; |
| 522 | |
| 523 | return 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | static int check_int(char *p, char *name, unsigned int *val) |
| 527 | { |
Jens Axboe | f5d3e5e | 2005-12-08 20:05:38 +0100 | [diff] [blame] | 528 | char *str; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 529 | |
Jens Axboe | b6754f9 | 2006-05-30 14:29:32 +0200 | [diff] [blame] | 530 | if (strncmp(p, name, strlen(name))) |
| 531 | return 1; |
| 532 | |
Jens Axboe | f5d3e5e | 2005-12-08 20:05:38 +0100 | [diff] [blame] | 533 | str = strstr(p, name); |
| 534 | if (!str) |
| 535 | return 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 536 | |
Jens Axboe | f5d3e5e | 2005-12-08 20:05:38 +0100 | [diff] [blame] | 537 | str = strchr(p, '='); |
| 538 | if (!str) |
| 539 | return 1; |
| 540 | |
| 541 | str++; |
| 542 | |
| 543 | if (sscanf(str, "%u", val) == 1) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 544 | return 0; |
| 545 | |
| 546 | return 1; |
| 547 | } |
| 548 | |
| 549 | static int check_strset(char *p, char *name) |
| 550 | { |
| 551 | return strncmp(p, name, strlen(name)); |
| 552 | } |
| 553 | |
| 554 | static int is_empty_or_comment(char *line) |
| 555 | { |
| 556 | unsigned int i; |
| 557 | |
| 558 | for (i = 0; i < strlen(line); i++) { |
| 559 | if (line[i] == ';') |
| 560 | return 1; |
| 561 | if (!isspace(line[i]) && !iscntrl(line[i])) |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | return 1; |
| 566 | } |
| 567 | |
| 568 | static int str_rw_cb(struct thread_data *td, char *mem) |
| 569 | { |
| 570 | if (!strncmp(mem, "read", 4) || !strncmp(mem, "0", 1)) { |
| 571 | td->ddir = DDIR_READ; |
| 572 | td->sequential = 1; |
| 573 | return 0; |
| 574 | } else if (!strncmp(mem, "randread", 8)) { |
| 575 | td->ddir = DDIR_READ; |
| 576 | td->sequential = 0; |
| 577 | return 0; |
| 578 | } else if (!strncmp(mem, "write", 5) || !strncmp(mem, "1", 1)) { |
| 579 | td->ddir = DDIR_WRITE; |
| 580 | td->sequential = 1; |
| 581 | return 0; |
| 582 | } else if (!strncmp(mem, "randwrite", 9)) { |
| 583 | td->ddir = DDIR_WRITE; |
| 584 | td->sequential = 0; |
| 585 | return 0; |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 586 | } else if (!strncmp(mem, "rw", 2)) { |
| 587 | td->ddir = 0; |
| 588 | td->iomix = 1; |
| 589 | td->sequential = 1; |
| 590 | return 0; |
| 591 | } else if (!strncmp(mem, "randrw", 6)) { |
| 592 | td->ddir = 0; |
| 593 | td->iomix = 1; |
| 594 | td->sequential = 0; |
| 595 | return 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 596 | } |
| 597 | |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 598 | log_err("fio: data direction: read, write, randread, randwrite, rw, randrw\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 599 | return 1; |
| 600 | } |
| 601 | |
| 602 | static int str_verify_cb(struct thread_data *td, char *mem) |
| 603 | { |
| 604 | if (!strncmp(mem, "0", 1)) { |
| 605 | td->verify = VERIFY_NONE; |
| 606 | return 0; |
| 607 | } else if (!strncmp(mem, "md5", 3) || !strncmp(mem, "1", 1)) { |
| 608 | td->verify = VERIFY_MD5; |
| 609 | return 0; |
| 610 | } else if (!strncmp(mem, "crc32", 5)) { |
| 611 | td->verify = VERIFY_CRC32; |
| 612 | return 0; |
| 613 | } |
| 614 | |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 615 | log_err("fio: verify types: md5, crc32\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 616 | return 1; |
| 617 | } |
| 618 | |
| 619 | static int str_mem_cb(struct thread_data *td, char *mem) |
| 620 | { |
| 621 | if (!strncmp(mem, "malloc", 6)) { |
| 622 | td->mem_type = MEM_MALLOC; |
| 623 | return 0; |
| 624 | } else if (!strncmp(mem, "shm", 3)) { |
| 625 | td->mem_type = MEM_SHM; |
| 626 | return 0; |
| 627 | } else if (!strncmp(mem, "mmap", 4)) { |
| 628 | td->mem_type = MEM_MMAP; |
| 629 | return 0; |
| 630 | } |
| 631 | |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 632 | log_err("fio: mem type: malloc, shm, mmap\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 633 | return 1; |
| 634 | } |
| 635 | |
| 636 | static int str_ioengine_cb(struct thread_data *td, char *str) |
| 637 | { |
Jens Axboe | 2866c82 | 2006-10-09 15:57:48 +0200 | [diff] [blame] | 638 | td->io_ops = load_ioengine(td, str); |
| 639 | if (td->io_ops) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 640 | return 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 641 | |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 642 | log_err("fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice, cpu\n"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 643 | return 1; |
| 644 | } |
| 645 | |
Jens Axboe | 0726198 | 2006-06-07 10:51:12 +0200 | [diff] [blame] | 646 | /* |
| 647 | * This is our [ini] type file parser. |
| 648 | */ |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 649 | int parse_jobs_ini(char *file, int stonewall_flag) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 650 | { |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 651 | unsigned int prioclass, prio, cpu, global, il; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 652 | unsigned long long ull; |
| 653 | unsigned long ul1, ul2; |
| 654 | struct thread_data *td; |
Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 655 | char *string, *name, *tmpbuf; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 656 | fpos_t off; |
| 657 | FILE *f; |
| 658 | char *p; |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 659 | int ret = 0, stonewall; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 660 | |
| 661 | f = fopen(file, "r"); |
| 662 | if (!f) { |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 663 | perror("fopen job file"); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 664 | return 1; |
| 665 | } |
| 666 | |
| 667 | string = malloc(4096); |
| 668 | name = malloc(256); |
Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 669 | tmpbuf = malloc(4096); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 670 | |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 671 | stonewall = stonewall_flag; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 672 | while ((p = fgets(string, 4096, f)) != NULL) { |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 673 | if (ret) |
| 674 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 675 | if (is_empty_or_comment(p)) |
| 676 | continue; |
| 677 | if (sscanf(p, "[%s]", name) != 1) |
| 678 | continue; |
| 679 | |
| 680 | global = !strncmp(name, "global", 6); |
| 681 | |
| 682 | name[strlen(name) - 1] = '\0'; |
| 683 | |
| 684 | td = get_new_job(global, &def_thread); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 685 | if (!td) { |
| 686 | ret = 1; |
| 687 | break; |
| 688 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 689 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 690 | /* |
| 691 | * Seperate multiple job files by a stonewall |
| 692 | */ |
Jens Axboe | f948191 | 2006-06-09 11:37:28 +0200 | [diff] [blame] | 693 | if (!global && stonewall) { |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 694 | td->stonewall = stonewall; |
| 695 | stonewall = 0; |
| 696 | } |
| 697 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 698 | fgetpos(f, &off); |
| 699 | while ((p = fgets(string, 4096, f)) != NULL) { |
| 700 | if (is_empty_or_comment(p)) |
| 701 | continue; |
| 702 | if (strstr(p, "[")) |
| 703 | break; |
Jens Axboe | b6754f9 | 2006-05-30 14:29:32 +0200 | [diff] [blame] | 704 | strip_blank_front(&p); |
Jens Axboe | 4ae3f76 | 2006-05-30 13:35:14 +0200 | [diff] [blame] | 705 | strip_blank_end(p); |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 706 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 707 | if (!check_int(p, "prio", &prio)) { |
| 708 | #ifndef FIO_HAVE_IOPRIO |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 709 | log_err("io priorities not available\n"); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 710 | ret = 1; |
| 711 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 712 | #endif |
Jens Axboe | 8756e4d | 2006-05-27 20:24:53 +0200 | [diff] [blame] | 713 | td->ioprio |= prio; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 714 | fgetpos(f, &off); |
| 715 | continue; |
| 716 | } |
| 717 | if (!check_int(p, "prioclass", &prioclass)) { |
| 718 | #ifndef FIO_HAVE_IOPRIO |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 719 | log_err("io priorities not available\n"); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 720 | ret = 1; |
| 721 | break; |
Jens Axboe | 5c4e1db | 2006-06-07 14:17:08 +0200 | [diff] [blame] | 722 | #else |
Jens Axboe | 8756e4d | 2006-05-27 20:24:53 +0200 | [diff] [blame] | 723 | td->ioprio |= prioclass << IOPRIO_CLASS_SHIFT; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 724 | fgetpos(f, &off); |
| 725 | continue; |
Jens Axboe | 5c4e1db | 2006-06-07 14:17:08 +0200 | [diff] [blame] | 726 | #endif |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 727 | } |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 728 | if (!check_int(p, "direct", &il)) { |
| 729 | td->odirect = il; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 730 | fgetpos(f, &off); |
| 731 | continue; |
| 732 | } |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 733 | if (!check_int(p, "rand_repeatable", &il)) { |
| 734 | td->rand_repeatable = il; |
| 735 | fgetpos(f, &off); |
| 736 | continue; |
| 737 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 738 | if (!check_int(p, "rate", &td->rate)) { |
| 739 | fgetpos(f, &off); |
| 740 | continue; |
| 741 | } |
| 742 | if (!check_int(p, "ratemin", &td->ratemin)) { |
| 743 | fgetpos(f, &off); |
| 744 | continue; |
| 745 | } |
| 746 | if (!check_int(p, "ratecycle", &td->ratecycle)) { |
| 747 | fgetpos(f, &off); |
| 748 | continue; |
| 749 | } |
Jens Axboe | b990b5c | 2006-09-14 09:48:22 +0200 | [diff] [blame] | 750 | if (!check_int(p, "cpuload", &td->cpuload)) { |
| 751 | fgetpos(f, &off); |
| 752 | continue; |
| 753 | } |
| 754 | if (!check_int(p, "cpuchunks", &td->cpucycle)) { |
| 755 | fgetpos(f, &off); |
| 756 | continue; |
| 757 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 758 | if (!check_int(p, "thinktime", &td->thinktime)) { |
| 759 | fgetpos(f, &off); |
| 760 | continue; |
| 761 | } |
| 762 | if (!check_int(p, "cpumask", &cpu)) { |
| 763 | #ifndef FIO_HAVE_CPU_AFFINITY |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 764 | log_err("cpu affinity not available\n"); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 765 | ret = 1; |
| 766 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 767 | #endif |
| 768 | fill_cpu_mask(td->cpumask, cpu); |
| 769 | fgetpos(f, &off); |
| 770 | continue; |
| 771 | } |
| 772 | if (!check_int(p, "fsync", &td->fsync_blocks)) { |
| 773 | fgetpos(f, &off); |
Jens Axboe | fc1a471 | 2006-05-30 13:04:05 +0200 | [diff] [blame] | 774 | td->end_fsync = 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 775 | continue; |
| 776 | } |
| 777 | if (!check_int(p, "startdelay", &td->start_delay)) { |
| 778 | fgetpos(f, &off); |
| 779 | continue; |
| 780 | } |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 781 | if (!check_str_time(p, "timeout", &ull)) { |
Jens Axboe | af959a7 | 2006-07-13 14:36:02 -0700 | [diff] [blame] | 782 | td->timeout = ull; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 783 | fgetpos(f, &off); |
| 784 | continue; |
| 785 | } |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 786 | if (!check_int(p, "invalidate", &il)) { |
| 787 | td->invalidate_cache = il; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 788 | fgetpos(f, &off); |
| 789 | continue; |
| 790 | } |
| 791 | if (!check_int(p, "iodepth", &td->iodepth)) { |
| 792 | fgetpos(f, &off); |
| 793 | continue; |
| 794 | } |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 795 | if (!check_int(p, "sync", &il)) { |
| 796 | td->sync_io = il; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 797 | fgetpos(f, &off); |
| 798 | continue; |
| 799 | } |
| 800 | if (!check_int(p, "bwavgtime", &td->bw_avg_time)) { |
| 801 | fgetpos(f, &off); |
| 802 | continue; |
| 803 | } |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 804 | if (!check_int(p, "create_serialize", &il)) { |
| 805 | td->create_serialize = il; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 806 | fgetpos(f, &off); |
| 807 | continue; |
| 808 | } |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 809 | if (!check_int(p, "create_fsync", &il)) { |
| 810 | td->create_fsync = il; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 811 | fgetpos(f, &off); |
| 812 | continue; |
| 813 | } |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 814 | if (!check_int(p, "end_fsync", &il)) { |
| 815 | td->end_fsync = il; |
Jens Axboe | fc1a471 | 2006-05-30 13:04:05 +0200 | [diff] [blame] | 816 | fgetpos(f, &off); |
| 817 | continue; |
| 818 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 819 | if (!check_int(p, "loops", &td->loops)) { |
| 820 | fgetpos(f, &off); |
| 821 | continue; |
| 822 | } |
| 823 | if (!check_int(p, "numjobs", &td->numjobs)) { |
| 824 | fgetpos(f, &off); |
| 825 | continue; |
| 826 | } |
Jens Axboe | e9c047a | 2006-06-07 21:13:04 +0200 | [diff] [blame] | 827 | if (!check_int(p, "overwrite", &il)) { |
| 828 | td->overwrite = il; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 829 | fgetpos(f, &off); |
| 830 | continue; |
| 831 | } |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 832 | if (!check_int(p, "rwmixcycle", &td->rwmixcycle)) { |
| 833 | fgetpos(f, &off); |
| 834 | continue; |
| 835 | } |
| 836 | if (!check_int(p, "rwmixread", &il)) { |
| 837 | if (il > 100) |
| 838 | il = 100; |
| 839 | td->rwmixread = il; |
| 840 | fgetpos(f, &off); |
| 841 | continue; |
| 842 | } |
| 843 | if (!check_int(p, "rwmixwrite", &il)) { |
| 844 | if (il > 100) |
| 845 | il = 100; |
| 846 | td->rwmixread = 100 - il; |
| 847 | fgetpos(f, &off); |
| 848 | continue; |
| 849 | } |
Jens Axboe | b6f4d88 | 2006-06-02 10:32:51 +0200 | [diff] [blame] | 850 | if (!check_int(p, "nice", &td->nice)) { |
| 851 | fgetpos(f, &off); |
| 852 | continue; |
| 853 | } |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 854 | if (!check_int(p, "nrfiles", &td->nr_files)) { |
| 855 | fgetpos(f, &off); |
| 856 | continue; |
| 857 | } |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 858 | if (!check_range_bytes(p, "bsrange", &ul1, &ul2)) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 859 | if (ul1 > ul2) { |
| 860 | td->max_bs = ul1; |
| 861 | td->min_bs = ul2; |
| 862 | } else { |
| 863 | td->max_bs = ul2; |
| 864 | td->min_bs = ul1; |
| 865 | } |
| 866 | fgetpos(f, &off); |
| 867 | continue; |
| 868 | } |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 869 | if (!check_str_bytes(p, "bs", &ull)) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 870 | td->bs = ull; |
| 871 | fgetpos(f, &off); |
| 872 | continue; |
| 873 | } |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 874 | if (!check_str_bytes(p, "size", &td->total_file_size)) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 875 | fgetpos(f, &off); |
| 876 | continue; |
| 877 | } |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 878 | if (!check_str_bytes(p, "offset", &td->start_offset)) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 879 | fgetpos(f, &off); |
| 880 | continue; |
| 881 | } |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 882 | if (!check_str_bytes(p, "zonesize", &td->zone_size)) { |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 883 | fgetpos(f, &off); |
| 884 | continue; |
| 885 | } |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 886 | if (!check_str_bytes(p, "zoneskip", &td->zone_skip)) { |
Jens Axboe | 20dc95c | 2005-12-09 10:29:35 +0100 | [diff] [blame] | 887 | fgetpos(f, &off); |
| 888 | continue; |
| 889 | } |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 890 | if (!check_str_bytes(p, "lockmem", &mlock_size)) { |
Jens Axboe | c04f7ec | 2006-05-31 10:13:16 +0200 | [diff] [blame] | 891 | fgetpos(f, &off); |
| 892 | continue; |
| 893 | } |
Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 894 | if (!check_strstore(p, "directory", tmpbuf)) { |
| 895 | td->directory = strdup(tmpbuf); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 896 | fgetpos(f, &off); |
| 897 | continue; |
| 898 | } |
Jens Axboe | 0145205 | 2006-06-07 10:29:47 +0200 | [diff] [blame] | 899 | if (!check_strstore(p, "name", tmpbuf)) { |
| 900 | snprintf(td->name, sizeof(td->name)-1, "%s%d", tmpbuf, td->thread_number); |
| 901 | fgetpos(f, &off); |
| 902 | continue; |
| 903 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 904 | if (!check_str(p, "mem", str_mem_cb, td)) { |
| 905 | fgetpos(f, &off); |
| 906 | continue; |
| 907 | } |
| 908 | if (!check_str(p, "verify", str_verify_cb, td)) { |
| 909 | fgetpos(f, &off); |
| 910 | continue; |
| 911 | } |
| 912 | if (!check_str(p, "rw", str_rw_cb, td)) { |
| 913 | fgetpos(f, &off); |
| 914 | continue; |
| 915 | } |
| 916 | if (!check_str(p, "ioengine", str_ioengine_cb, td)) { |
| 917 | fgetpos(f, &off); |
| 918 | continue; |
| 919 | } |
| 920 | if (!check_strset(p, "create")) { |
| 921 | td->create_file = 1; |
| 922 | fgetpos(f, &off); |
| 923 | continue; |
| 924 | } |
| 925 | if (!check_strset(p, "exitall")) { |
| 926 | exitall_on_terminate = 1; |
| 927 | fgetpos(f, &off); |
| 928 | continue; |
| 929 | } |
| 930 | if (!check_strset(p, "stonewall")) { |
| 931 | td->stonewall = 1; |
| 932 | fgetpos(f, &off); |
| 933 | continue; |
| 934 | } |
| 935 | if (!check_strset(p, "thread")) { |
| 936 | td->use_thread = 1; |
| 937 | fgetpos(f, &off); |
| 938 | continue; |
| 939 | } |
Jens Axboe | f6cbb26 | 2006-10-18 14:16:42 +0200 | [diff] [blame] | 940 | if (!check_strset(p, "unlink")) { |
| 941 | td->unlink = 1; |
| 942 | fgetpos(f, &off); |
| 943 | continue; |
| 944 | } |
Jens Axboe | 80b9feb | 2006-06-07 10:34:49 +0200 | [diff] [blame] | 945 | if (!check_strstore(p, "iolog", tmpbuf)) { |
Jens Axboe | 4f693b9 | 2006-06-07 22:52:28 +0200 | [diff] [blame] | 946 | if (td->write_iolog) { |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 947 | log_err("fio: read iolog overrides given write_iolog\n"); |
Jens Axboe | af8c0b4 | 2006-06-07 22:33:17 +0200 | [diff] [blame] | 948 | free(td->iolog_file); |
Jens Axboe | 4f693b9 | 2006-06-07 22:52:28 +0200 | [diff] [blame] | 949 | td->write_iolog = 0; |
| 950 | } |
Jens Axboe | 80b9feb | 2006-06-07 10:34:49 +0200 | [diff] [blame] | 951 | td->iolog_file = strdup(tmpbuf); |
Jens Axboe | 843a741 | 2006-06-01 21:14:21 -0700 | [diff] [blame] | 952 | td->read_iolog = 1; |
Jens Axboe | 843a741 | 2006-06-01 21:14:21 -0700 | [diff] [blame] | 953 | fgetpos(f, &off); |
| 954 | continue; |
| 955 | } |
Jens Axboe | af8c0b4 | 2006-06-07 22:33:17 +0200 | [diff] [blame] | 956 | if (!check_strstore(p, "write_iolog", tmpbuf)) { |
| 957 | if (!td->read_iolog) { |
| 958 | td->iolog_file = strdup(tmpbuf); |
| 959 | td->write_iolog = 1; |
Jens Axboe | 4f693b9 | 2006-06-07 22:52:28 +0200 | [diff] [blame] | 960 | } else |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 961 | log_err("fio: read iolog overrides given write_iolog\n"); |
Jens Axboe | aea47d4 | 2006-05-26 19:27:29 +0200 | [diff] [blame] | 962 | fgetpos(f, &off); |
| 963 | continue; |
| 964 | } |
Jens Axboe | 80b9feb | 2006-06-07 10:34:49 +0200 | [diff] [blame] | 965 | if (!check_strstore(p, "exec_prerun", tmpbuf)) { |
| 966 | td->exec_prerun = strdup(tmpbuf); |
Jens Axboe | 4e0ba8a | 2006-06-06 09:36:28 +0200 | [diff] [blame] | 967 | fgetpos(f, &off); |
| 968 | continue; |
| 969 | } |
Jens Axboe | 80b9feb | 2006-06-07 10:34:49 +0200 | [diff] [blame] | 970 | if (!check_strstore(p, "exec_postrun", tmpbuf)) { |
| 971 | td->exec_postrun = strdup(tmpbuf); |
Jens Axboe | 4e0ba8a | 2006-06-06 09:36:28 +0200 | [diff] [blame] | 972 | fgetpos(f, &off); |
| 973 | continue; |
| 974 | } |
Jens Axboe | 80b9feb | 2006-06-07 10:34:49 +0200 | [diff] [blame] | 975 | if (!check_strstore(p, "ioscheduler", tmpbuf)) { |
Jens Axboe | 22f78b3 | 2006-06-07 11:30:07 +0200 | [diff] [blame] | 976 | #ifndef FIO_HAVE_IOSCHED_SWITCH |
Jens Axboe | 3b70d7e | 2006-06-08 21:48:46 +0200 | [diff] [blame] | 977 | log_err("io scheduler switching not available\n"); |
Jens Axboe | 22f78b3 | 2006-06-07 11:30:07 +0200 | [diff] [blame] | 978 | ret = 1; |
| 979 | break; |
| 980 | #else |
Jens Axboe | 80b9feb | 2006-06-07 10:34:49 +0200 | [diff] [blame] | 981 | td->ioscheduler = strdup(tmpbuf); |
Jens Axboe | da86774 | 2006-06-06 10:39:10 -0700 | [diff] [blame] | 982 | fgetpos(f, &off); |
| 983 | continue; |
Jens Axboe | 22f78b3 | 2006-06-07 11:30:07 +0200 | [diff] [blame] | 984 | #endif |
Jens Axboe | da86774 | 2006-06-06 10:39:10 -0700 | [diff] [blame] | 985 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 986 | |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 987 | /* |
| 988 | * Don't break here, continue parsing options so we |
| 989 | * dump all the bad ones. Makes trial/error fixups |
| 990 | * easier on the user. |
| 991 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 992 | printf("Client%d: bad option %s\n",td->thread_number,p); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 993 | ret = 1; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 994 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 995 | |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 996 | if (!ret) { |
| 997 | fsetpos(f, &off); |
| 998 | ret = add_job(td, name, 0); |
| 999 | } |
| 1000 | if (ret) |
| 1001 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | free(string); |
| 1005 | free(name); |
Jens Axboe | ef899b6 | 2006-06-06 09:31:00 +0200 | [diff] [blame] | 1006 | free(tmpbuf); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1007 | fclose(f); |
Jens Axboe | 45410ac | 2006-06-07 11:10:39 +0200 | [diff] [blame] | 1008 | return ret; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | static int fill_def_thread(void) |
| 1012 | { |
| 1013 | memset(&def_thread, 0, sizeof(def_thread)); |
| 1014 | |
| 1015 | if (fio_getaffinity(getpid(), &def_thread.cpumask) == -1) { |
| 1016 | perror("sched_getaffinity"); |
| 1017 | return 1; |
| 1018 | } |
| 1019 | |
| 1020 | /* |
| 1021 | * fill globals |
| 1022 | */ |
| 1023 | def_thread.ddir = DDIR_READ; |
Jens Axboe | 3d60d1e | 2006-05-25 06:31:06 +0200 | [diff] [blame] | 1024 | def_thread.iomix = 0; |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 1025 | def_thread.bs = DEF_BS; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1026 | def_thread.min_bs = -1; |
| 1027 | def_thread.max_bs = -1; |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 1028 | def_thread.odirect = DEF_ODIRECT; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1029 | def_thread.ratecycle = DEF_RATE_CYCLE; |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 1030 | def_thread.sequential = DEF_SEQUENTIAL; |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1031 | def_thread.timeout = def_timeout; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1032 | def_thread.create_file = DEF_CREATE; |
| 1033 | def_thread.overwrite = DEF_OVERWRITE; |
| 1034 | def_thread.invalidate_cache = DEF_INVALIDATE; |
| 1035 | def_thread.sync_io = DEF_SYNCIO; |
| 1036 | def_thread.mem_type = MEM_MALLOC; |
| 1037 | def_thread.bw_avg_time = DEF_BWAVGTIME; |
| 1038 | def_thread.create_serialize = DEF_CREATE_SER; |
| 1039 | def_thread.create_fsync = DEF_CREATE_FSYNC; |
| 1040 | def_thread.loops = DEF_LOOPS; |
| 1041 | def_thread.verify = DEF_VERIFY; |
| 1042 | def_thread.stonewall = DEF_STONEWALL; |
| 1043 | def_thread.numjobs = DEF_NUMJOBS; |
| 1044 | def_thread.use_thread = DEF_USE_THREAD; |
Jens Axboe | a6ccc7b | 2006-06-02 10:14:15 +0200 | [diff] [blame] | 1045 | def_thread.rwmixcycle = DEF_RWMIX_CYCLE; |
| 1046 | def_thread.rwmixread = DEF_RWMIX_READ; |
Jens Axboe | b6f4d88 | 2006-06-02 10:32:51 +0200 | [diff] [blame] | 1047 | def_thread.nice = DEF_NICE; |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 1048 | def_thread.rand_repeatable = DEF_RAND_REPEAT; |
Jens Axboe | 53cdc68 | 2006-10-18 11:50:58 +0200 | [diff] [blame] | 1049 | def_thread.nr_files = DEF_NR_FILES; |
Jens Axboe | f6cbb26 | 2006-10-18 14:16:42 +0200 | [diff] [blame] | 1050 | def_thread.unlink = DEF_UNLINK; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1051 | #ifdef FIO_HAVE_DISK_UTIL |
| 1052 | def_thread.do_disk_util = 1; |
| 1053 | #endif |
| 1054 | |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame^] | 1058 | static void usage(void) |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 1059 | { |
| 1060 | printf("%s\n", fio_version_string); |
Jens Axboe | 47623c7 | 2006-06-12 10:23:28 +0200 | [diff] [blame] | 1061 | printf("\t-o Write output to file\n"); |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 1062 | printf("\t-t Runtime in seconds\n"); |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 1063 | printf("\t-l Generate per-job latency logs\n"); |
| 1064 | printf("\t-w Generate per-job bandwidth logs\n"); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 1065 | printf("\t-m Minimal (terse) output\n"); |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 1066 | printf("\t-v Print version info and exit\n"); |
| 1067 | } |
| 1068 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1069 | static int parse_cmd_line(int argc, char *argv[]) |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1070 | { |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1071 | int c, idx = 1, ini_idx = 0; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1072 | |
Jens Axboe | 2e77841 | 2006-06-16 10:00:50 +0200 | [diff] [blame] | 1073 | while ((c = getopt(argc, argv, "t:o:lwvhm")) != EOF) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1074 | switch (c) { |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1075 | case 't': |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1076 | def_timeout = atoi(optarg); |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 1077 | idx = optind; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1078 | break; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1079 | case 'l': |
| 1080 | write_lat_log = 1; |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 1081 | idx = optind; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1082 | break; |
| 1083 | case 'w': |
| 1084 | write_bw_log = 1; |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 1085 | idx = optind; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1086 | break; |
Jens Axboe | 9ebc27e | 2006-06-12 10:21:50 +0200 | [diff] [blame] | 1087 | case 'o': |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 1088 | f_out = fopen(optarg, "w+"); |
| 1089 | if (!f_out) { |
| 1090 | perror("fopen output"); |
| 1091 | exit(1); |
| 1092 | } |
| 1093 | f_err = f_out; |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 1094 | idx = optind; |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 1095 | break; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 1096 | case 'm': |
| 1097 | terse_output = 1; |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 1098 | idx = optind; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 1099 | break; |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 1100 | case 'h': |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame^] | 1101 | usage(); |
Jens Axboe | 4785f99 | 2006-05-26 03:59:10 +0200 | [diff] [blame] | 1102 | exit(0); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1103 | case 'v': |
| 1104 | printf("%s\n", fio_version_string); |
| 1105 | exit(0); |
| 1106 | } |
| 1107 | } |
Jens Axboe | c9fad89 | 2006-05-27 17:26:50 +0200 | [diff] [blame] | 1108 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1109 | while (idx < argc) { |
| 1110 | ini_idx++; |
| 1111 | ini_file = realloc(ini_file, ini_idx * sizeof(char *)); |
| 1112 | ini_file[ini_idx - 1] = strdup(argv[idx]); |
| 1113 | idx++; |
| 1114 | } |
Jens Axboe | 774a617 | 2006-08-24 08:44:26 +0200 | [diff] [blame] | 1115 | |
Jens Axboe | eb8bbf4 | 2006-06-08 21:40:11 +0200 | [diff] [blame] | 1116 | if (!f_out) { |
| 1117 | f_out = stdout; |
| 1118 | f_err = stderr; |
| 1119 | } |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1120 | |
| 1121 | return ini_idx; |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | static void free_shm(void) |
| 1125 | { |
| 1126 | struct shmid_ds sbuf; |
| 1127 | |
| 1128 | if (threads) { |
Jens Axboe | 2c0ecd2 | 2006-06-08 13:25:41 +0200 | [diff] [blame] | 1129 | shmdt((void *) threads); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1130 | threads = NULL; |
| 1131 | shmctl(shm_id, IPC_RMID, &sbuf); |
| 1132 | } |
| 1133 | } |
| 1134 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1135 | /* |
| 1136 | * The thread area is shared between the main process and the job |
| 1137 | * threads/processes. So setup a shared memory segment that will hold |
| 1138 | * all the job info. |
| 1139 | */ |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1140 | static int setup_thread_area(void) |
| 1141 | { |
| 1142 | /* |
| 1143 | * 1024 is too much on some machines, scale max_jobs if |
| 1144 | * we get a failure that looks like too large a shm segment |
| 1145 | */ |
| 1146 | do { |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1147 | size_t size = max_jobs * sizeof(struct thread_data); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1148 | |
Jens Axboe | 906c8d7 | 2006-06-13 09:37:56 +0200 | [diff] [blame] | 1149 | shm_id = shmget(0, size, IPC_CREAT | 0600); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1150 | if (shm_id != -1) |
| 1151 | break; |
| 1152 | if (errno != EINVAL) { |
| 1153 | perror("shmget"); |
| 1154 | break; |
| 1155 | } |
| 1156 | |
| 1157 | max_jobs >>= 1; |
| 1158 | } while (max_jobs); |
| 1159 | |
| 1160 | if (shm_id == -1) |
| 1161 | return 1; |
| 1162 | |
| 1163 | threads = shmat(shm_id, NULL, 0); |
| 1164 | if (threads == (void *) -1) { |
| 1165 | perror("shmat"); |
| 1166 | return 1; |
| 1167 | } |
| 1168 | |
| 1169 | atexit(free_shm); |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
| 1173 | int parse_options(int argc, char *argv[]) |
| 1174 | { |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1175 | int job_files, i; |
| 1176 | |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1177 | if (setup_thread_area()) |
| 1178 | return 1; |
| 1179 | if (fill_def_thread()) |
| 1180 | return 1; |
| 1181 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1182 | job_files = parse_cmd_line(argc, argv); |
| 1183 | if (!job_files) { |
| 1184 | log_err("Need job file(s)\n"); |
Jens Axboe | 0ab8db8 | 2006-10-18 17:16:23 +0200 | [diff] [blame^] | 1185 | usage(); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1186 | return 1; |
| 1187 | } |
| 1188 | |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1189 | for (i = 0; i < job_files; i++) { |
| 1190 | if (fill_def_thread()) |
| 1191 | return 1; |
Jens Axboe | 0c7e37a | 2006-06-13 14:53:38 +0200 | [diff] [blame] | 1192 | if (parse_jobs_ini(ini_file[i], i)) |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1193 | return 1; |
Jens Axboe | 88c6ed8 | 2006-06-09 11:28:10 +0200 | [diff] [blame] | 1194 | free(ini_file[i]); |
Jens Axboe | 972cfd2 | 2006-06-09 11:08:56 +0200 | [diff] [blame] | 1195 | } |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1196 | |
Jens Axboe | 88c6ed8 | 2006-06-09 11:28:10 +0200 | [diff] [blame] | 1197 | free(ini_file); |
Jens Axboe | ebac465 | 2005-12-08 15:25:21 +0100 | [diff] [blame] | 1198 | return 0; |
| 1199 | } |