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> |
| 7 | #include <dirent.h> |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 8 | |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 9 | #include "flist.h" |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 10 | #include "fio.h" |
| 11 | #include "blktrace_api.h" |
| 12 | |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 13 | #define TRACE_FIFO_SIZE 65536 |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 14 | |
| 15 | /* |
| 16 | * fifo refill frontend, to avoid reading data in trace sized bites |
| 17 | */ |
| 18 | static int refill_fifo(struct thread_data *td, struct fifo *fifo, int fd) |
| 19 | { |
| 20 | char buf[TRACE_FIFO_SIZE]; |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 21 | unsigned int total; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 22 | int ret; |
| 23 | |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 24 | total = sizeof(buf); |
| 25 | if (total > fifo_room(fifo)) |
| 26 | total = fifo_room(fifo); |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 27 | |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 28 | ret = read(fd, buf, total); |
| 29 | if (ret < 0) { |
| 30 | td_verror(td, errno, "read blktrace file"); |
| 31 | return -1; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 32 | } |
| 33 | |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 34 | if (ret > 0) |
| 35 | ret = fifo_put(fifo, buf, ret); |
| 36 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 37 | dprint(FD_BLKTRACE, "refill: filled %d bytes\n", ret); |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 38 | return ret; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | /* |
| 42 | * Retrieve 'len' bytes from the fifo, refilling if necessary. |
| 43 | */ |
| 44 | static int trace_fifo_get(struct thread_data *td, struct fifo *fifo, int fd, |
| 45 | void *buf, unsigned int len) |
| 46 | { |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 47 | if (fifo_len(fifo) < len) { |
| 48 | int ret = refill_fifo(td, fifo, fd); |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 49 | |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 50 | if (ret < 0) |
| 51 | return ret; |
| 52 | } |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 53 | |
| 54 | return fifo_get(fifo, buf, len); |
| 55 | } |
| 56 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 57 | /* |
| 58 | * Just discard the pdu by seeking past it. |
| 59 | */ |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 60 | static int discard_pdu(struct thread_data *td, struct fifo *fifo, int fd, |
| 61 | struct blk_io_trace *t) |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 62 | { |
| 63 | if (t->pdu_len == 0) |
| 64 | return 0; |
| 65 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 66 | dprint(FD_BLKTRACE, "discard pdu len %u\n", t->pdu_len); |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 67 | return trace_fifo_get(td, fifo, fd, NULL, t->pdu_len); |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 68 | } |
| 69 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 70 | /* |
| 71 | * Check if this is a blktrace binary data file. We read a single trace |
| 72 | * into memory and check for the magic signature. |
| 73 | */ |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 74 | int is_blktrace(const char *filename) |
| 75 | { |
| 76 | struct blk_io_trace t; |
| 77 | int fd, ret; |
| 78 | |
| 79 | fd = open(filename, O_RDONLY); |
Jens Axboe | 4dced40 | 2007-07-23 14:16:55 +0200 | [diff] [blame] | 80 | if (fd < 0) |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 81 | return 0; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 82 | |
| 83 | ret = read(fd, &t, sizeof(t)); |
| 84 | close(fd); |
| 85 | |
| 86 | if (ret < 0) { |
| 87 | perror("read blktrace"); |
| 88 | return 0; |
| 89 | } else if (ret != sizeof(t)) { |
| 90 | log_err("fio: short read on blktrace file\n"); |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) |
| 95 | return 1; |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 100 | static int lookup_device(char *path, unsigned int maj, unsigned int min) |
| 101 | { |
| 102 | struct dirent *dir; |
| 103 | struct stat st; |
| 104 | int found = 0; |
| 105 | DIR *D; |
| 106 | |
| 107 | D = opendir(path); |
| 108 | if (!D) |
| 109 | return 0; |
| 110 | |
| 111 | while ((dir = readdir(D)) != NULL) { |
| 112 | char full_path[256]; |
| 113 | |
| 114 | if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) |
| 115 | continue; |
| 116 | |
| 117 | sprintf(full_path, "%s/%s", path, dir->d_name); |
| 118 | if (lstat(full_path, &st) == -1) { |
| 119 | perror("lstat"); |
| 120 | break; |
| 121 | } |
| 122 | |
| 123 | if (S_ISDIR(st.st_mode)) { |
| 124 | found = lookup_device(full_path, maj, min); |
| 125 | if (found) { |
| 126 | strcpy(path, full_path); |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if (!S_ISBLK(st.st_mode)) |
| 132 | continue; |
| 133 | |
| 134 | if (maj == major(st.st_rdev) && min == minor(st.st_rdev)) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 135 | dprint(FD_BLKTRACE, "device lookup: %d/%d\n", maj, min); |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 136 | strcpy(path, full_path); |
| 137 | found = 1; |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | closedir(D); |
| 143 | return found; |
| 144 | } |
| 145 | |
Jens Axboe | c69aa91 | 2007-05-22 15:51:50 +0200 | [diff] [blame] | 146 | #define FMINORBITS 20 |
| 147 | #define FMINORMASK ((1U << FMINORBITS) - 1) |
| 148 | #define FMAJOR(dev) ((unsigned int) ((dev) >> FMINORBITS)) |
| 149 | #define FMINOR(dev) ((unsigned int) ((dev) & FMINORMASK)) |
Jens Axboe | eeb9c2a | 2007-05-16 18:28:47 +0200 | [diff] [blame] | 150 | |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 151 | static void trace_add_open_event(struct thread_data *td, int fileno) |
| 152 | { |
| 153 | struct io_piece *ipo; |
| 154 | |
| 155 | ipo = calloc(1, sizeof(*ipo)); |
| 156 | |
| 157 | ipo->ddir = DDIR_INVAL; |
| 158 | ipo->fileno = fileno; |
| 159 | ipo->file_action = FIO_LOG_OPEN_FILE; |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 160 | flist_add_tail(&ipo->list, &td->io_log_list); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 163 | static void trace_add_file(struct thread_data *td, __u32 device) |
| 164 | { |
| 165 | static unsigned int last_maj, last_min; |
Jens Axboe | c69aa91 | 2007-05-22 15:51:50 +0200 | [diff] [blame] | 166 | unsigned int maj = FMAJOR(device); |
| 167 | unsigned int min = FMINOR(device); |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 168 | struct fio_file *f; |
| 169 | char dev[256]; |
| 170 | unsigned int i; |
| 171 | |
| 172 | if (last_maj == maj && last_min == min) |
| 173 | return; |
| 174 | |
| 175 | last_maj = maj; |
| 176 | last_min = min; |
| 177 | |
| 178 | /* |
| 179 | * check for this file in our list |
| 180 | */ |
| 181 | for_each_file(td, f, i) |
| 182 | if (f->major == maj && f->minor == min) |
| 183 | return; |
| 184 | |
| 185 | strcpy(dev, "/dev"); |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 186 | if (lookup_device(dev, maj, min)) { |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 187 | int fileno; |
| 188 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 189 | dprint(FD_BLKTRACE, "add devices %s\n", dev); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 190 | fileno = add_file(td, dev); |
| 191 | trace_add_open_event(td, fileno); |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 192 | } |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 193 | } |
| 194 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 195 | /* |
| 196 | * Store blk_io_trace data in an ipo for later retrieval. |
| 197 | */ |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 198 | static void store_ipo(struct thread_data *td, unsigned long long offset, |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 199 | unsigned int bytes, int rw, unsigned long long ttime) |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 200 | { |
| 201 | struct io_piece *ipo = malloc(sizeof(*ipo)); |
| 202 | |
| 203 | memset(ipo, 0, sizeof(*ipo)); |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 204 | INIT_FLIST_HEAD(&ipo->list); |
Jens Axboe | a2eea81 | 2007-05-15 13:10:41 +0200 | [diff] [blame] | 205 | /* |
| 206 | * the 512 is wrong here, it should be the hardware sector size... |
| 207 | */ |
| 208 | ipo->offset = offset * 512; |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 209 | ipo->len = bytes; |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 210 | ipo->delay = ttime / 1000; |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 211 | if (rw) |
| 212 | ipo->ddir = DDIR_WRITE; |
| 213 | else |
| 214 | ipo->ddir = DDIR_READ; |
| 215 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 216 | dprint(FD_BLKTRACE, "store ddir=%d, off=%llu, len=%lu, delay=%lu\n", |
| 217 | ipo->ddir, ipo->offset, |
| 218 | ipo->len, ipo->delay); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 219 | queue_io_piece(td, ipo); |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 220 | } |
| 221 | |
Jens Axboe | aec2de2 | 2008-04-24 12:44:42 +0200 | [diff] [blame] | 222 | static void handle_trace_notify( struct blk_io_trace *t) |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 223 | { |
| 224 | switch (t->action) { |
| 225 | case BLK_TN_PROCESS: |
| 226 | printf("got process notify: %x, %d\n", t->action, t->pid); |
| 227 | break; |
| 228 | case BLK_TN_TIMESTAMP: |
| 229 | printf("got timestamp notify: %x, %d\n", t->action, t->pid); |
| 230 | break; |
| 231 | default: |
| 232 | dprint(FD_BLKTRACE, "unknown trace act %x\n", t->action); |
| 233 | break; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | static void handle_trace_fs(struct thread_data *td, struct blk_io_trace *t, |
| 238 | unsigned long long ttime, unsigned long *ios, |
| 239 | unsigned int *bs) |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 240 | { |
Jens Axboe | fdefd98 | 2007-05-15 10:12:26 +0200 | [diff] [blame] | 241 | int rw; |
| 242 | |
Jens Axboe | 5e6c206 | 2007-05-16 14:40:29 +0200 | [diff] [blame] | 243 | trace_add_file(td, t->device); |
| 244 | |
Jens Axboe | e7a7d70 | 2007-05-15 10:13:04 +0200 | [diff] [blame] | 245 | rw = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 246 | |
| 247 | if (t->bytes > bs[rw]) |
| 248 | bs[rw] = t->bytes; |
| 249 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 250 | ios[rw]++; |
Jens Axboe | 6df8ada | 2007-05-15 13:23:19 +0200 | [diff] [blame] | 251 | td->o.size += t->bytes; |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 252 | store_ipo(td, t->sector, t->bytes, rw, ttime); |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 255 | /* |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 256 | * We only care for queue traces, most of the others are side effects |
| 257 | * due to internal workings of the block layer. |
| 258 | */ |
| 259 | static void handle_trace(struct thread_data *td, struct blk_io_trace *t, |
| 260 | unsigned long long ttime, unsigned long *ios, |
| 261 | unsigned int *bs) |
| 262 | { |
| 263 | if ((t->action & 0xffff) != __BLK_TA_QUEUE) |
| 264 | return; |
| 265 | if (t->action & BLK_TC_ACT(BLK_TC_PC)) |
| 266 | return; |
| 267 | |
| 268 | if (t->action & BLK_TC_ACT(BLK_TC_NOTIFY)) |
Jens Axboe | aec2de2 | 2008-04-24 12:44:42 +0200 | [diff] [blame] | 269 | handle_trace_notify(t); |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 270 | else |
| 271 | handle_trace_fs(td, t, ttime, ios, bs); |
| 272 | } |
| 273 | |
| 274 | /* |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 275 | * Load a blktrace file by reading all the blk_io_trace entries, and storing |
| 276 | * them as io_pieces like the fio text version would do. |
| 277 | */ |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 278 | int load_blktrace(struct thread_data *td, const char *filename) |
| 279 | { |
Jens Axboe | a61edde | 2007-05-15 14:29:58 +0200 | [diff] [blame] | 280 | unsigned long long ttime, delay; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 281 | struct blk_io_trace t; |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 282 | unsigned long ios[2], skipped_writes; |
Jens Axboe | a61edde | 2007-05-15 14:29:58 +0200 | [diff] [blame] | 283 | unsigned int cpu; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 284 | unsigned int rw_bs[2]; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 285 | struct fifo *fifo; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 286 | int fd; |
| 287 | |
| 288 | fd = open(filename, O_RDONLY); |
| 289 | if (fd < 0) { |
| 290 | td_verror(td, errno, "open blktrace file"); |
| 291 | return 1; |
| 292 | } |
| 293 | |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 294 | fifo = fifo_alloc(TRACE_FIFO_SIZE); |
| 295 | |
Jens Axboe | 6df8ada | 2007-05-15 13:23:19 +0200 | [diff] [blame] | 296 | td->o.size = 0; |
| 297 | |
Jens Axboe | a61edde | 2007-05-15 14:29:58 +0200 | [diff] [blame] | 298 | cpu = 0; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 299 | ttime = 0; |
| 300 | ios[0] = ios[1] = 0; |
| 301 | rw_bs[0] = rw_bs[1] = 0; |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 302 | skipped_writes = 0; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 303 | do { |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 304 | int ret = trace_fifo_get(td, fifo, fd, &t, sizeof(t)); |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 305 | |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 306 | if (ret < 0) |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 307 | goto err; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 308 | else if (!ret) |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 309 | break; |
Jens Axboe | e288756 | 2007-05-16 09:25:09 +0200 | [diff] [blame] | 310 | else if (ret < (int) sizeof(t)) { |
| 311 | log_err("fio: short fifo get\n"); |
| 312 | break; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | if ((t.magic & 0xffffff00) != BLK_IO_TRACE_MAGIC) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 316 | log_err("fio: bad magic in blktrace data: %x\n", |
| 317 | t.magic); |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 318 | goto err; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 319 | } |
| 320 | if ((t.magic & 0xff) != BLK_IO_TRACE_VERSION) { |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 321 | log_err("fio: bad blktrace version %d\n", |
| 322 | t.magic & 0xff); |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 323 | goto err; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 324 | } |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 325 | ret = discard_pdu(td, fifo, fd, &t); |
| 326 | if (ret < 0) { |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 327 | td_verror(td, ret, "blktrace lseek"); |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 328 | goto err; |
Jens Axboe | f12b323 | 2007-05-16 12:16:44 +0200 | [diff] [blame] | 329 | } else if (t.pdu_len != ret) { |
| 330 | log_err("fio: discarded %d of %d\n", ret, t.pdu_len); |
| 331 | goto err; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 332 | } |
Jens Axboe | 691c8fb | 2008-03-07 14:26:26 +0100 | [diff] [blame] | 333 | if ((t.action & BLK_TC_ACT(BLK_TC_NOTIFY)) == 0) { |
| 334 | if (!ttime) { |
| 335 | ttime = t.time; |
| 336 | cpu = t.cpu; |
| 337 | } |
| 338 | |
| 339 | delay = 0; |
| 340 | if (cpu == t.cpu) |
| 341 | delay = t.time - ttime; |
| 342 | if ((t.action & BLK_TC_ACT(BLK_TC_WRITE)) && read_only) |
| 343 | skipped_writes++; |
| 344 | else |
| 345 | handle_trace(td, &t, delay, ios, rw_bs); |
| 346 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 347 | ttime = t.time; |
Jens Axboe | a61edde | 2007-05-15 14:29:58 +0200 | [diff] [blame] | 348 | cpu = t.cpu; |
Jens Axboe | a6edd63 | 2008-03-07 21:41:54 +0100 | [diff] [blame] | 349 | } else { |
| 350 | delay = 0; |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 351 | handle_trace(td, &t, delay, ios, rw_bs); |
Jens Axboe | a6edd63 | 2008-03-07 21:41:54 +0100 | [diff] [blame] | 352 | } |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 353 | } while (1); |
| 354 | |
Jens Axboe | 38470f8 | 2007-05-16 09:26:23 +0200 | [diff] [blame] | 355 | fifo_free(fifo); |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 356 | close(fd); |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 357 | |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 358 | if (skipped_writes) |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 359 | log_err("fio: %s skips replay of %lu writes due to read-only\n", |
| 360 | td->o.name, skipped_writes); |
Jens Axboe | 4241ea8 | 2007-09-12 08:18:36 +0200 | [diff] [blame] | 361 | |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 362 | if (!ios[DDIR_READ] && !ios[DDIR_WRITE]) { |
| 363 | log_err("fio: found no ios in blktrace data\n"); |
| 364 | return 1; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 365 | } else if (ios[DDIR_READ] && !ios[DDIR_READ]) { |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 366 | td->o.td_ddir = TD_DDIR_READ; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 367 | td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ]; |
| 368 | } else if (!ios[DDIR_READ] && ios[DDIR_WRITE]) { |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 369 | td->o.td_ddir = TD_DDIR_WRITE; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 370 | td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE]; |
| 371 | } else { |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 372 | td->o.td_ddir = TD_DDIR_RW; |
Jens Axboe | d84f8d4 | 2007-05-16 08:47:46 +0200 | [diff] [blame] | 373 | td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ]; |
| 374 | td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE]; |
| 375 | } |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 376 | |
| 377 | /* |
| 378 | * We need to do direct/raw ios to the device, to avoid getting |
| 379 | * read-ahead in our way. |
| 380 | */ |
| 381 | td->o.odirect = 1; |
| 382 | |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 383 | return 0; |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 384 | err: |
| 385 | close(fd); |
Jens Axboe | 38470f8 | 2007-05-16 09:26:23 +0200 | [diff] [blame] | 386 | fifo_free(fifo); |
Jens Axboe | 8c1fdf0 | 2007-05-15 11:54:21 +0200 | [diff] [blame] | 387 | return 1; |
Jens Axboe | fb7b71a | 2007-05-15 08:44:04 +0200 | [diff] [blame] | 388 | } |