Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * blktrace support code for fio |
| 3 | */ |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 6 | #include <sys/stat.h> |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 7 | #include <sys/ioctl.h> |
| 8 | #include <linux/fs.h> |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 9 | #include <dirent.h> |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 10 | |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 11 | #include "flist.h" |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 12 | #include "fio.h" |
| 13 | #include "blktrace_api.h" |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 14 | #include "oslib/linux-dev-lookup.h" |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 15 | |
Jens Axboe | 2da7df1 | 2010-08-01 21:27:28 +0200 | [diff] [blame] | 16 | #define TRACE_FIFO_SIZE 8192 |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | * fifo refill frontend, to avoid reading data in trace sized bites |
| 20 | */ |
| 21 | static int refill_fifo(struct thread_data *td, struct fifo *fifo, int fd) |
| 22 | { |
| 23 | char buf[TRACE_FIFO_SIZE]; |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 24 | unsigned int total; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 25 | int ret; |
| 26 | |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 27 | total = sizeof(buf); |
| 28 | if (total > fifo_room(fifo)) |
| 29 | total = fifo_room(fifo); |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 30 | |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 31 | ret = read(fd, buf, total); |
| 32 | if (ret < 0) { |
| 33 | td_verror(td, errno, "read blktrace file"); |
| 34 | return -1; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 35 | } |
| 36 | |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 37 | if (ret > 0) |
| 38 | ret = fifo_put(fifo, buf, ret); |
| 39 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 40 | dprint(FD_BLKTRACE, "refill: filled %d bytes\n", ret); |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 41 | return ret; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /* |
| 45 | * Retrieve 'len' bytes from the fifo, refilling if necessary. |
| 46 | */ |
| 47 | static int trace_fifo_get(struct thread_data *td, struct fifo *fifo, int fd, |
| 48 | void *buf, unsigned int len) |
| 49 | { |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 50 | if (fifo_len(fifo) < len) { |
| 51 | int ret = refill_fifo(td, fifo, fd); |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 52 | |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 53 | if (ret < 0) |
| 54 | return ret; |
| 55 | } |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 56 | |
| 57 | return fifo_get(fifo, buf, len); |
| 58 | } |
| 59 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 60 | /* |
| 61 | * Just discard the pdu by seeking past it. |
| 62 | */ |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 63 | static int discard_pdu(struct thread_data *td, struct fifo *fifo, int fd, |
| 64 | struct blk_io_trace *t) |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 65 | { |
| 66 | if (t->pdu_len == 0) |
| 67 | return 0; |
| 68 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 69 | dprint(FD_BLKTRACE, "discard pdu len %u\n", t->pdu_len); |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 70 | return trace_fifo_get(td, fifo, fd, NULL, t->pdu_len); |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 71 | } |
| 72 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 73 | /* |
| 74 | * Check if this is a blktrace binary data file. We read a single trace |
| 75 | * into memory and check for the magic signature. |
| 76 | */ |
Jens Axboe | d95b34a | 2013-11-21 09:55:49 -0700 | [diff] [blame] | 77 | int is_blktrace(const char *filename, int *need_swap) |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 78 | { |
| 79 | struct blk_io_trace t; |
| 80 | int fd, ret; |
| 81 | |
| 82 | fd = open(filename, O_RDONLY); |
Jens Axboe | 4dced40 | 2007-07-23 14:16:55 +0200 | [diff] [blame] | 83 | if (fd < 0) |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 84 | return 0; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 85 | |
| 86 | ret = read(fd, &t, sizeof(t)); |
| 87 | close(fd); |
| 88 | |
| 89 | if (ret < 0) { |
| 90 | perror("read blktrace"); |
| 91 | return 0; |
| 92 | } else if (ret != sizeof(t)) { |
| 93 | log_err("fio: short read on blktrace file\n"); |
| 94 | return 0; |
| 95 | } |
| 96 | |
Jens Axboe | d95b34a | 2013-11-21 09:55:49 -0700 | [diff] [blame] | 97 | if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) { |
| 98 | *need_swap = 0; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 99 | return 1; |
Jens Axboe | d95b34a | 2013-11-21 09:55:49 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* |
| 103 | * Maybe it needs to be endian swapped... |
| 104 | */ |
| 105 | t.magic = fio_swap32(t.magic); |
| 106 | if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) { |
| 107 | *need_swap = 1; |
| 108 | return 1; |
| 109 | } |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
Jens Axboe | c69aa91 | 2007-05-22 15:51:50 +0200 | [diff] [blame] | 114 | #define FMINORBITS 20 |
| 115 | #define FMINORMASK ((1U << FMINORBITS) - 1) |
| 116 | #define FMAJOR(dev) ((unsigned int) ((dev) >> FMINORBITS)) |
| 117 | #define FMINOR(dev) ((unsigned int) ((dev) & FMINORMASK)) |
Jens Axboe | eeb9c2a | 2007-05-16 18:28:47 +0200 | [diff] [blame] | 118 | |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 119 | static void trace_add_open_close_event(struct thread_data *td, int fileno, enum file_log_act action) |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 120 | { |
| 121 | struct io_piece *ipo; |
| 122 | |
| 123 | ipo = calloc(1, sizeof(*ipo)); |
Jens Axboe | 0d29de8 | 2010-09-01 13:54:15 +0200 | [diff] [blame] | 124 | init_ipo(ipo); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 125 | |
| 126 | ipo->ddir = DDIR_INVAL; |
| 127 | ipo->fileno = fileno; |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 128 | ipo->file_action = action; |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 129 | flist_add_tail(&ipo->list, &td->io_log_list); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 130 | } |
| 131 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 132 | static int get_dev_blocksize(const char *dev, unsigned int *bs) |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 133 | { |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 134 | int fd; |
| 135 | |
| 136 | fd = open(dev, O_RDONLY); |
| 137 | if (fd < 0) |
| 138 | return 1; |
| 139 | |
| 140 | if (ioctl(fd, BLKSSZGET, bs) < 0) { |
| 141 | close(fd); |
| 142 | return 1; |
| 143 | } |
| 144 | |
| 145 | close(fd); |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static int trace_add_file(struct thread_data *td, __u32 device, |
| 150 | unsigned int *bs) |
| 151 | { |
| 152 | static unsigned int last_maj, last_min, last_fileno, last_bs; |
Jens Axboe | c69aa91 | 2007-05-22 15:51:50 +0200 | [diff] [blame] | 153 | unsigned int maj = FMAJOR(device); |
| 154 | unsigned int min = FMINOR(device); |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 155 | struct fio_file *f; |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 156 | unsigned int i; |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 157 | char dev[256]; |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 158 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 159 | if (last_maj == maj && last_min == min) { |
| 160 | *bs = last_bs; |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 161 | return last_fileno; |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 162 | } |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 163 | |
| 164 | last_maj = maj; |
| 165 | last_min = min; |
| 166 | |
| 167 | /* |
| 168 | * check for this file in our list |
| 169 | */ |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 170 | for_each_file(td, f, i) { |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 171 | if (f->major == maj && f->minor == min) { |
| 172 | last_fileno = f->fileno; |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 173 | last_bs = f->bs; |
| 174 | goto out; |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 175 | } |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 176 | } |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 177 | |
| 178 | strcpy(dev, "/dev"); |
Jens Axboe | 42a80e3 | 2014-09-16 17:06:52 +0200 | [diff] [blame] | 179 | if (blktrace_lookup_device(td->o.replay_redirect, dev, maj, min)) { |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 180 | unsigned int this_bs; |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 181 | int fileno; |
| 182 | |
Jens Axboe | 42a80e3 | 2014-09-16 17:06:52 +0200 | [diff] [blame] | 183 | if (td->o.replay_redirect) |
| 184 | dprint(FD_BLKTRACE, "device lookup: %d/%d\n overridden" |
| 185 | " with: %s\n", maj, min, |
| 186 | td->o.replay_redirect); |
| 187 | else |
| 188 | dprint(FD_BLKTRACE, "device lookup: %d/%d\n", maj, min); |
| 189 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 190 | dprint(FD_BLKTRACE, "add devices %s\n", dev); |
Jens Axboe | 49ffb4a | 2010-08-24 15:01:37 +0200 | [diff] [blame] | 191 | fileno = add_file_exclusive(td, dev); |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 192 | |
| 193 | if (get_dev_blocksize(dev, &this_bs)) |
| 194 | this_bs = 512; |
| 195 | |
Jens Axboe | b53f2c5 | 2014-04-08 21:07:12 -0600 | [diff] [blame] | 196 | td->o.open_files++; |
Jens Axboe | 5903e7b | 2014-02-26 13:42:13 -0800 | [diff] [blame] | 197 | td->files[fileno]->major = maj; |
| 198 | td->files[fileno]->minor = min; |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 199 | td->files[fileno]->bs = this_bs; |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 200 | trace_add_open_close_event(td, fileno, FIO_LOG_OPEN_FILE); |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 201 | |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 202 | last_fileno = fileno; |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 203 | last_bs = this_bs; |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 204 | } |
Jens Axboe | f01b34a | 2013-11-21 11:13:12 -0700 | [diff] [blame] | 205 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 206 | out: |
| 207 | *bs = last_bs; |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 208 | return last_fileno; |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 211 | static void t_bytes_align(struct thread_options *o, struct blk_io_trace *t) |
| 212 | { |
| 213 | if (!o->replay_align) |
| 214 | return; |
| 215 | |
| 216 | t->bytes = (t->bytes + o->replay_align - 1) & ~(o->replay_align - 1); |
| 217 | } |
| 218 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 219 | /* |
| 220 | * Store blk_io_trace data in an ipo for later retrieval. |
| 221 | */ |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 222 | static void store_ipo(struct thread_data *td, unsigned long long offset, |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 223 | unsigned int bytes, int rw, unsigned long long ttime, |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 224 | int fileno, unsigned int bs) |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 225 | { |
| 226 | struct io_piece *ipo = malloc(sizeof(*ipo)); |
| 227 | |
Jens Axboe | 0d29de8 | 2010-09-01 13:54:15 +0200 | [diff] [blame] | 228 | init_ipo(ipo); |
| 229 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 230 | ipo->offset = offset * bs; |
| 231 | if (td->o.replay_scale) |
| 232 | ipo->offset = ipo->offset / td->o.replay_scale; |
| 233 | ipo_bytes_align(td->o.replay_align, ipo); |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 234 | ipo->len = bytes; |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 235 | ipo->delay = ttime / 1000; |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 236 | if (rw) |
| 237 | ipo->ddir = DDIR_WRITE; |
| 238 | else |
| 239 | ipo->ddir = DDIR_READ; |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 240 | ipo->fileno = fileno; |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 241 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 242 | dprint(FD_BLKTRACE, "store ddir=%d, off=%llu, len=%lu, delay=%lu\n", |
| 243 | ipo->ddir, ipo->offset, |
| 244 | ipo->len, ipo->delay); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 245 | queue_io_piece(td, ipo); |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 246 | } |
| 247 | |
Jens Axboe | 0b9d69e | 2009-09-11 22:29:54 +0200 | [diff] [blame] | 248 | static void handle_trace_notify(struct blk_io_trace *t) |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 249 | { |
| 250 | switch (t->action) { |
| 251 | case BLK_TN_PROCESS: |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 252 | dprint(FD_BLKTRACE, "got process notify: %x, %d\n", |
Jens Axboe | d95b34a | 2013-11-21 09:55:49 -0700 | [diff] [blame] | 253 | t->action, t->pid); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 254 | break; |
| 255 | case BLK_TN_TIMESTAMP: |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 256 | dprint(FD_BLKTRACE, "got timestamp notify: %x, %d\n", |
Jens Axboe | d95b34a | 2013-11-21 09:55:49 -0700 | [diff] [blame] | 257 | t->action, t->pid); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 258 | break; |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 259 | case BLK_TN_MESSAGE: |
| 260 | break; |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 261 | default: |
| 262 | dprint(FD_BLKTRACE, "unknown trace act %x\n", t->action); |
| 263 | break; |
| 264 | } |
| 265 | } |
| 266 | |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 267 | static void handle_trace_discard(struct thread_data *td, |
| 268 | struct blk_io_trace *t, |
| 269 | unsigned long long ttime, |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 270 | unsigned long *ios, unsigned int *rw_bs) |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 271 | { |
| 272 | struct io_piece *ipo = malloc(sizeof(*ipo)); |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 273 | unsigned int bs; |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 274 | int fileno; |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 275 | |
Jens Axboe | 0d29de8 | 2010-09-01 13:54:15 +0200 | [diff] [blame] | 276 | init_ipo(ipo); |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 277 | fileno = trace_add_file(td, t->device, &bs); |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 278 | |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 279 | ios[DDIR_TRIM]++; |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 280 | if (t->bytes > rw_bs[DDIR_TRIM]) |
| 281 | rw_bs[DDIR_TRIM] = t->bytes; |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 282 | |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 283 | td->o.size += t->bytes; |
| 284 | |
| 285 | memset(ipo, 0, sizeof(*ipo)); |
| 286 | INIT_FLIST_HEAD(&ipo->list); |
| 287 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 288 | ipo->offset = t->sector * bs; |
| 289 | if (td->o.replay_scale) |
| 290 | ipo->offset = ipo->offset / td->o.replay_scale; |
| 291 | ipo_bytes_align(td->o.replay_align, ipo); |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 292 | ipo->len = t->bytes; |
| 293 | ipo->delay = ttime / 1000; |
| 294 | ipo->ddir = DDIR_TRIM; |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 295 | ipo->fileno = fileno; |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 296 | |
| 297 | dprint(FD_BLKTRACE, "store discard, off=%llu, len=%lu, delay=%lu\n", |
| 298 | ipo->offset, ipo->len, |
| 299 | ipo->delay); |
| 300 | queue_io_piece(td, ipo); |
| 301 | } |
| 302 | |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 303 | static void handle_trace_fs(struct thread_data *td, struct blk_io_trace *t, |
| 304 | unsigned long long ttime, unsigned long *ios, |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 305 | unsigned int *rw_bs) |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 306 | { |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 307 | unsigned int bs; |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 308 | int rw; |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 309 | int fileno; |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 310 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 311 | fileno = trace_add_file(td, t->device, &bs); |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 312 | |
Jens Axboe | e7a7d70 | 2007-05-15 10:13:04 +0200 | [diff] [blame] | 313 | rw = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 314 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 315 | if (t->bytes > rw_bs[rw]) |
| 316 | rw_bs[rw] = t->bytes; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 317 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 318 | ios[rw]++; |
Jens Axboe | 6df8ada | 2007-05-15 13:23:19 +0200 | [diff] [blame] | 319 | td->o.size += t->bytes; |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 320 | store_ipo(td, t->sector, t->bytes, rw, ttime, fileno, bs); |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 323 | /* |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 324 | * We only care for queue traces, most of the others are side effects |
| 325 | * due to internal workings of the block layer. |
| 326 | */ |
| 327 | static void handle_trace(struct thread_data *td, struct blk_io_trace *t, |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 328 | unsigned long *ios, unsigned int *bs) |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 329 | { |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 330 | static unsigned long long last_ttime; |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 331 | unsigned long long delay = 0; |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 332 | |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 333 | if ((t->action & 0xffff) != __BLK_TA_QUEUE) |
| 334 | return; |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 335 | |
| 336 | if (!(t->action & BLK_TC_ACT(BLK_TC_NOTIFY))) { |
| 337 | if (!last_ttime || td->o.no_stall) { |
| 338 | last_ttime = t->time; |
| 339 | delay = 0; |
| 340 | } else { |
| 341 | delay = t->time - last_ttime; |
| 342 | last_ttime = t->time; |
| 343 | } |
| 344 | } |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 345 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 346 | t_bytes_align(&td->o, t); |
| 347 | |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 348 | if (t->action & BLK_TC_ACT(BLK_TC_NOTIFY)) |
Jens Axboe | aec2de2 | 2008-04-24 12:44:42 +0200 | [diff] [blame] | 349 | handle_trace_notify(t); |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 350 | else if (t->action & BLK_TC_ACT(BLK_TC_DISCARD)) |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 351 | handle_trace_discard(td, t, delay, ios, bs); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 352 | else |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 353 | handle_trace_fs(td, t, delay, ios, bs); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Jens Axboe | d95b34a | 2013-11-21 09:55:49 -0700 | [diff] [blame] | 356 | static void byteswap_trace(struct blk_io_trace *t) |
| 357 | { |
| 358 | t->magic = fio_swap32(t->magic); |
| 359 | t->sequence = fio_swap32(t->sequence); |
| 360 | t->time = fio_swap64(t->time); |
| 361 | t->sector = fio_swap64(t->sector); |
| 362 | t->bytes = fio_swap32(t->bytes); |
| 363 | t->action = fio_swap32(t->action); |
| 364 | t->pid = fio_swap32(t->pid); |
| 365 | t->device = fio_swap32(t->device); |
| 366 | t->cpu = fio_swap32(t->cpu); |
| 367 | t->error = fio_swap16(t->error); |
| 368 | t->pdu_len = fio_swap16(t->pdu_len); |
| 369 | } |
| 370 | |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 371 | static int t_is_write(struct blk_io_trace *t) |
| 372 | { |
| 373 | return (t->action & BLK_TC_ACT(BLK_TC_WRITE | BLK_TC_DISCARD)) != 0; |
| 374 | } |
| 375 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 376 | static enum fio_ddir t_get_ddir(struct blk_io_trace *t) |
| 377 | { |
| 378 | if (t->action & BLK_TC_ACT(BLK_TC_READ)) |
| 379 | return DDIR_READ; |
| 380 | else if (t->action & BLK_TC_ACT(BLK_TC_WRITE)) |
| 381 | return DDIR_WRITE; |
| 382 | else if (t->action & BLK_TC_ACT(BLK_TC_DISCARD)) |
| 383 | return DDIR_TRIM; |
| 384 | |
| 385 | return DDIR_INVAL; |
| 386 | } |
| 387 | |
| 388 | static void depth_inc(struct blk_io_trace *t, int *depth) |
| 389 | { |
| 390 | enum fio_ddir ddir; |
| 391 | |
| 392 | ddir = t_get_ddir(t); |
| 393 | if (ddir != DDIR_INVAL) |
| 394 | depth[ddir]++; |
| 395 | } |
| 396 | |
| 397 | static void depth_dec(struct blk_io_trace *t, int *depth) |
| 398 | { |
| 399 | enum fio_ddir ddir; |
| 400 | |
| 401 | ddir = t_get_ddir(t); |
| 402 | if (ddir != DDIR_INVAL) |
| 403 | depth[ddir]--; |
| 404 | } |
| 405 | |
| 406 | static void depth_end(struct blk_io_trace *t, int *this_depth, int *depth) |
| 407 | { |
| 408 | enum fio_ddir ddir = DDIR_INVAL; |
| 409 | |
| 410 | ddir = t_get_ddir(t); |
| 411 | if (ddir != DDIR_INVAL) { |
| 412 | depth[ddir] = max(depth[ddir], this_depth[ddir]); |
| 413 | this_depth[ddir] = 0; |
| 414 | } |
| 415 | } |
| 416 | |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 417 | /* |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 418 | * Load a blktrace file by reading all the blk_io_trace entries, and storing |
| 419 | * them as io_pieces like the fio text version would do. |
| 420 | */ |
Jens Axboe | d95b34a | 2013-11-21 09:55:49 -0700 | [diff] [blame] | 421 | int load_blktrace(struct thread_data *td, const char *filename, int need_swap) |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 422 | { |
| 423 | struct blk_io_trace t; |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 424 | unsigned long ios[DDIR_RWDIR_CNT], skipped_writes; |
| 425 | unsigned int rw_bs[DDIR_RWDIR_CNT]; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 426 | struct fifo *fifo; |
Jens Axboe | 5903e7b | 2014-02-26 13:42:13 -0800 | [diff] [blame] | 427 | int fd, i, old_state; |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 428 | struct fio_file *f; |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 429 | int this_depth[DDIR_RWDIR_CNT], depth[DDIR_RWDIR_CNT], max_depth; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 430 | |
| 431 | fd = open(filename, O_RDONLY); |
| 432 | if (fd < 0) { |
| 433 | td_verror(td, errno, "open blktrace file"); |
| 434 | return 1; |
| 435 | } |
| 436 | |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 437 | fifo = fifo_alloc(TRACE_FIFO_SIZE); |
| 438 | |
Jens Axboe | 8edd973 | 2014-03-01 08:24:03 -0700 | [diff] [blame] | 439 | old_state = td_bump_runstate(td, TD_SETTING_UP); |
Jens Axboe | 5903e7b | 2014-02-26 13:42:13 -0800 | [diff] [blame] | 440 | |
Jens Axboe | 6df8ada | 2007-05-15 13:23:19 +0200 | [diff] [blame] | 441 | td->o.size = 0; |
| 442 | |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 443 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
| 444 | ios[i] = 0; |
| 445 | rw_bs[i] = 0; |
| 446 | this_depth[i] = 0; |
| 447 | depth[i] = 0; |
| 448 | } |
| 449 | |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 450 | skipped_writes = 0; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 451 | do { |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 452 | int ret = trace_fifo_get(td, fifo, fd, &t, sizeof(t)); |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 453 | |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 454 | if (ret < 0) |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 455 | goto err; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 456 | else if (!ret) |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 457 | break; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 458 | else if (ret < (int) sizeof(t)) { |
| 459 | log_err("fio: short fifo get\n"); |
| 460 | break; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 461 | } |
| 462 | |
Jens Axboe | d95b34a | 2013-11-21 09:55:49 -0700 | [diff] [blame] | 463 | if (need_swap) |
| 464 | byteswap_trace(&t); |
| 465 | |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 466 | if ((t.magic & 0xffffff00) != BLK_IO_TRACE_MAGIC) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 467 | log_err("fio: bad magic in blktrace data: %x\n", |
| 468 | t.magic); |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 469 | goto err; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 470 | } |
| 471 | if ((t.magic & 0xff) != BLK_IO_TRACE_VERSION) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 472 | log_err("fio: bad blktrace version %d\n", |
| 473 | t.magic & 0xff); |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 474 | goto err; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 475 | } |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 476 | ret = discard_pdu(td, fifo, fd, &t); |
| 477 | if (ret < 0) { |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 478 | td_verror(td, ret, "blktrace lseek"); |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 479 | goto err; |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 480 | } else if (t.pdu_len != ret) { |
| 481 | log_err("fio: discarded %d of %d\n", ret, t.pdu_len); |
| 482 | goto err; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 483 | } |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 484 | if ((t.action & BLK_TC_ACT(BLK_TC_NOTIFY)) == 0) { |
Jens Axboe | eb5fdcf | 2014-04-08 13:43:19 -0600 | [diff] [blame] | 485 | if ((t.action & 0xffff) == __BLK_TA_QUEUE) |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 486 | depth_inc(&t, this_depth); |
| 487 | else if (((t.action & 0xffff) == __BLK_TA_BACKMERGE) || |
| 488 | ((t.action & 0xffff) == __BLK_TA_FRONTMERGE)) |
| 489 | depth_dec(&t, this_depth); |
| 490 | else if ((t.action & 0xffff) == __BLK_TA_COMPLETE) |
| 491 | depth_end(&t, this_depth, depth); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 492 | |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 493 | if (t_is_write(&t) && read_only) { |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 494 | skipped_writes++; |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 495 | continue; |
David Nellans | 64bbb86 | 2010-08-24 22:13:30 +0200 | [diff] [blame] | 496 | } |
Jens Axboe | a6edd63 | 2008-03-07 21:41:54 +0100 | [diff] [blame] | 497 | } |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 498 | |
| 499 | handle_trace(td, &t, ios, rw_bs); |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 500 | } while (1); |
| 501 | |
Jens Axboe | 85a47ca | 2012-06-11 13:19:13 +0200 | [diff] [blame] | 502 | for (i = 0; i < td->files_index; i++) { |
Jens Axboe | f01b34a | 2013-11-21 11:13:12 -0700 | [diff] [blame] | 503 | f = td->files[i]; |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 504 | trace_add_open_close_event(td, f->fileno, FIO_LOG_CLOSE_FILE); |
Jens Axboe | 85a47ca | 2012-06-11 13:19:13 +0200 | [diff] [blame] | 505 | } |
Shaohua Li | 89ac1d4 | 2012-06-11 08:56:32 +0200 | [diff] [blame] | 506 | |
Jens Axboe | 38470f8 | 2007-05-16 09:26:23 +0200 | [diff] [blame] | 507 | fifo_free(fifo); |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 508 | close(fd); |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 509 | |
Jens Axboe | 8edd973 | 2014-03-01 08:24:03 -0700 | [diff] [blame] | 510 | td_restore_runstate(td, old_state); |
Jens Axboe | 5903e7b | 2014-02-26 13:42:13 -0800 | [diff] [blame] | 511 | |
Jens Axboe | f01b34a | 2013-11-21 11:13:12 -0700 | [diff] [blame] | 512 | if (!td->files_index) { |
| 513 | log_err("fio: did not find replay device(s)\n"); |
| 514 | return 1; |
| 515 | } |
| 516 | |
Jens Axboe | eb5fdcf | 2014-04-08 13:43:19 -0600 | [diff] [blame] | 517 | /* |
| 518 | * For stacked devices, we don't always get a COMPLETE event so |
| 519 | * the depth grows to insane values. Limit it to something sane(r). |
| 520 | */ |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 521 | max_depth = 0; |
| 522 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
| 523 | if (depth[i] > 1024) |
| 524 | depth[i] = 1024; |
| 525 | else if (!depth[i] && ios[i]) |
| 526 | depth[i] = 1; |
| 527 | max_depth = max(depth[i], max_depth); |
| 528 | } |
Jens Axboe | eb5fdcf | 2014-04-08 13:43:19 -0600 | [diff] [blame] | 529 | |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 530 | if (skipped_writes) |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 531 | log_err("fio: %s skips replay of %lu writes due to read-only\n", |
| 532 | td->o.name, skipped_writes); |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 533 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 534 | if (!ios[DDIR_READ] && !ios[DDIR_WRITE]) { |
| 535 | log_err("fio: found no ios in blktrace data\n"); |
| 536 | return 1; |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 537 | } else if (ios[DDIR_READ] && !ios[DDIR_WRITE]) { |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 538 | td->o.td_ddir = TD_DDIR_READ; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 539 | td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ]; |
| 540 | } else if (!ios[DDIR_READ] && ios[DDIR_WRITE]) { |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 541 | td->o.td_ddir = TD_DDIR_WRITE; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 542 | td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE]; |
| 543 | } else { |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 544 | td->o.td_ddir = TD_DDIR_RW; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 545 | td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ]; |
| 546 | td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE]; |
Jens Axboe | 5bca6f9 | 2014-07-14 15:07:11 +0200 | [diff] [blame] | 547 | td->o.max_bs[DDIR_TRIM] = rw_bs[DDIR_TRIM]; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 548 | } |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 549 | |
| 550 | /* |
| 551 | * We need to do direct/raw ios to the device, to avoid getting |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 552 | * read-ahead in our way. But only do so if the minimum block size |
| 553 | * is a multiple of 4k, otherwise we don't know if it's safe to do so. |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 554 | */ |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 555 | if (!fio_option_is_set(&td->o, odirect) && !(td_min_bs(td) & 4095)) |
| 556 | td->o.odirect = 1; |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 557 | |
Jens Axboe | eb5fdcf | 2014-04-08 13:43:19 -0600 | [diff] [blame] | 558 | /* |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 559 | * If depth wasn't manually set, use probed depth |
Jens Axboe | eb5fdcf | 2014-04-08 13:43:19 -0600 | [diff] [blame] | 560 | */ |
Elliott Hughes | eda3a60 | 2017-05-19 18:53:02 -0700 | [diff] [blame] | 561 | if (!fio_option_is_set(&td->o, iodepth)) |
| 562 | td->o.iodepth = td->o.iodepth_low = max_depth; |
Jens Axboe | eb5fdcf | 2014-04-08 13:43:19 -0600 | [diff] [blame] | 563 | |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 564 | return 0; |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 565 | err: |
| 566 | close(fd); |
Jens Axboe | 38470f8 | 2007-05-16 09:26:23 +0200 | [diff] [blame] | 567 | fifo_free(fifo); |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 568 | return 1; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 569 | } |