blob: 04648a08ffdf8005fe87fbddf9a9ca542c823396 [file] [log] [blame]
Jens Axboefb7b71a2007-05-15 08:44:04 +02001/*
2 * blktrace support code for fio
3 */
4#include <stdio.h>
5#include <stdlib.h>
Jens Axboe5e6c2062007-05-16 14:40:29 +02006#include <sys/stat.h>
7#include <dirent.h>
Jens Axboe8c1fdf02007-05-15 11:54:21 +02008
Jens Axboe01743ee2008-06-02 12:19:19 +02009#include "flist.h"
Jens Axboefb7b71a2007-05-15 08:44:04 +020010#include "fio.h"
11#include "blktrace_api.h"
12
Jens Axboe2da7df12010-08-01 21:27:28 +020013#define TRACE_FIFO_SIZE 8192
Jens Axboee2887562007-05-16 09:25:09 +020014
15/*
16 * fifo refill frontend, to avoid reading data in trace sized bites
17 */
18static int refill_fifo(struct thread_data *td, struct fifo *fifo, int fd)
19{
20 char buf[TRACE_FIFO_SIZE];
Jens Axboef12b3232007-05-16 12:16:44 +020021 unsigned int total;
Jens Axboee2887562007-05-16 09:25:09 +020022 int ret;
23
Jens Axboef12b3232007-05-16 12:16:44 +020024 total = sizeof(buf);
25 if (total > fifo_room(fifo))
26 total = fifo_room(fifo);
Jens Axboee2887562007-05-16 09:25:09 +020027
Jens Axboef12b3232007-05-16 12:16:44 +020028 ret = read(fd, buf, total);
29 if (ret < 0) {
30 td_verror(td, errno, "read blktrace file");
31 return -1;
Jens Axboee2887562007-05-16 09:25:09 +020032 }
33
Jens Axboef12b3232007-05-16 12:16:44 +020034 if (ret > 0)
35 ret = fifo_put(fifo, buf, ret);
36
Jens Axboebd6f78b2008-02-01 20:27:52 +010037 dprint(FD_BLKTRACE, "refill: filled %d bytes\n", ret);
Jens Axboef12b3232007-05-16 12:16:44 +020038 return ret;
Jens Axboee2887562007-05-16 09:25:09 +020039}
40
41/*
42 * Retrieve 'len' bytes from the fifo, refilling if necessary.
43 */
44static int trace_fifo_get(struct thread_data *td, struct fifo *fifo, int fd,
45 void *buf, unsigned int len)
46{
Jens Axboef12b3232007-05-16 12:16:44 +020047 if (fifo_len(fifo) < len) {
48 int ret = refill_fifo(td, fifo, fd);
Jens Axboee2887562007-05-16 09:25:09 +020049
Jens Axboef12b3232007-05-16 12:16:44 +020050 if (ret < 0)
51 return ret;
52 }
Jens Axboee2887562007-05-16 09:25:09 +020053
54 return fifo_get(fifo, buf, len);
55}
56
Jens Axboe8c1fdf02007-05-15 11:54:21 +020057/*
58 * Just discard the pdu by seeking past it.
59 */
Jens Axboef12b3232007-05-16 12:16:44 +020060static int discard_pdu(struct thread_data *td, struct fifo *fifo, int fd,
61 struct blk_io_trace *t)
Jens Axboefb7b71a2007-05-15 08:44:04 +020062{
63 if (t->pdu_len == 0)
64 return 0;
65
Jens Axboebd6f78b2008-02-01 20:27:52 +010066 dprint(FD_BLKTRACE, "discard pdu len %u\n", t->pdu_len);
Jens Axboef12b3232007-05-16 12:16:44 +020067 return trace_fifo_get(td, fifo, fd, NULL, t->pdu_len);
Jens Axboefb7b71a2007-05-15 08:44:04 +020068}
69
Jens Axboe8c1fdf02007-05-15 11:54:21 +020070/*
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 Axboed95b34a2013-11-21 09:55:49 -070074int is_blktrace(const char *filename, int *need_swap)
Jens Axboefb7b71a2007-05-15 08:44:04 +020075{
76 struct blk_io_trace t;
77 int fd, ret;
78
79 fd = open(filename, O_RDONLY);
Jens Axboe4dced402007-07-23 14:16:55 +020080 if (fd < 0)
Jens Axboefb7b71a2007-05-15 08:44:04 +020081 return 0;
Jens Axboefb7b71a2007-05-15 08:44:04 +020082
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
Jens Axboed95b34a2013-11-21 09:55:49 -070094 if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) {
95 *need_swap = 0;
Jens Axboefb7b71a2007-05-15 08:44:04 +020096 return 1;
Jens Axboed95b34a2013-11-21 09:55:49 -070097 }
98
99 /*
100 * Maybe it needs to be endian swapped...
101 */
102 t.magic = fio_swap32(t.magic);
103 if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) {
104 *need_swap = 1;
105 return 1;
106 }
Jens Axboefb7b71a2007-05-15 08:44:04 +0200107
108 return 0;
109}
110
David Nellansd1c46c02010-08-31 21:20:47 +0200111static int lookup_device(struct thread_data *td, char *path, unsigned int maj,
112 unsigned int min)
Jens Axboe5e6c2062007-05-16 14:40:29 +0200113{
114 struct dirent *dir;
115 struct stat st;
116 int found = 0;
117 DIR *D;
118
119 D = opendir(path);
120 if (!D)
121 return 0;
122
123 while ((dir = readdir(D)) != NULL) {
124 char full_path[256];
125
126 if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."))
127 continue;
128
Bruce Cranb9fd7882012-02-20 17:01:46 +0000129 sprintf(full_path, "%s%s%s", path, FIO_OS_PATH_SEPARATOR, dir->d_name);
Jens Axboe5e6c2062007-05-16 14:40:29 +0200130 if (lstat(full_path, &st) == -1) {
131 perror("lstat");
132 break;
133 }
134
135 if (S_ISDIR(st.st_mode)) {
David Nellansd1c46c02010-08-31 21:20:47 +0200136 found = lookup_device(td, full_path, maj, min);
Jens Axboe5e6c2062007-05-16 14:40:29 +0200137 if (found) {
138 strcpy(path, full_path);
139 break;
140 }
141 }
142
143 if (!S_ISBLK(st.st_mode))
144 continue;
145
David Nellansd1c46c02010-08-31 21:20:47 +0200146 /*
147 * If replay_redirect is set then always return this device
148 * upon lookup which overrides the device lookup based on
149 * major minor in the actual blktrace
150 */
151 if (td->o.replay_redirect) {
152 dprint(FD_BLKTRACE, "device lookup: %d/%d\n overridden"
153 " with: %s", maj, min,
154 td->o.replay_redirect);
155 strcpy(path, td->o.replay_redirect);
156 found = 1;
157 break;
158 }
159
Jens Axboe5e6c2062007-05-16 14:40:29 +0200160 if (maj == major(st.st_rdev) && min == minor(st.st_rdev)) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100161 dprint(FD_BLKTRACE, "device lookup: %d/%d\n", maj, min);
Jens Axboe5e6c2062007-05-16 14:40:29 +0200162 strcpy(path, full_path);
163 found = 1;
164 break;
165 }
166 }
167
168 closedir(D);
169 return found;
170}
171
Jens Axboec69aa912007-05-22 15:51:50 +0200172#define FMINORBITS 20
173#define FMINORMASK ((1U << FMINORBITS) - 1)
174#define FMAJOR(dev) ((unsigned int) ((dev) >> FMINORBITS))
175#define FMINOR(dev) ((unsigned int) ((dev) & FMINORMASK))
Jens Axboeeeb9c2a2007-05-16 18:28:47 +0200176
Shaohua Li89ac1d42012-06-11 08:56:32 +0200177static void trace_add_open_close_event(struct thread_data *td, int fileno, enum file_log_act action)
Jens Axboe691c8fb2008-03-07 14:26:26 +0100178{
179 struct io_piece *ipo;
180
181 ipo = calloc(1, sizeof(*ipo));
Jens Axboe0d29de82010-09-01 13:54:15 +0200182 init_ipo(ipo);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100183
184 ipo->ddir = DDIR_INVAL;
185 ipo->fileno = fileno;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200186 ipo->file_action = action;
Jens Axboe01743ee2008-06-02 12:19:19 +0200187 flist_add_tail(&ipo->list, &td->io_log_list);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100188}
189
Shaohua Li89ac1d42012-06-11 08:56:32 +0200190static int trace_add_file(struct thread_data *td, __u32 device)
Jens Axboe5e6c2062007-05-16 14:40:29 +0200191{
Shaohua Li89ac1d42012-06-11 08:56:32 +0200192 static unsigned int last_maj, last_min, last_fileno;
Jens Axboec69aa912007-05-22 15:51:50 +0200193 unsigned int maj = FMAJOR(device);
194 unsigned int min = FMINOR(device);
Jens Axboe5e6c2062007-05-16 14:40:29 +0200195 struct fio_file *f;
196 char dev[256];
197 unsigned int i;
198
199 if (last_maj == maj && last_min == min)
Shaohua Li89ac1d42012-06-11 08:56:32 +0200200 return last_fileno;
Jens Axboe5e6c2062007-05-16 14:40:29 +0200201
202 last_maj = maj;
203 last_min = min;
204
205 /*
206 * check for this file in our list
207 */
208 for_each_file(td, f, i)
Shaohua Li89ac1d42012-06-11 08:56:32 +0200209 if (f->major == maj && f->minor == min) {
210 last_fileno = f->fileno;
211 return last_fileno;
212 }
Jens Axboe5e6c2062007-05-16 14:40:29 +0200213
214 strcpy(dev, "/dev");
David Nellansd1c46c02010-08-31 21:20:47 +0200215 if (lookup_device(td, dev, maj, min)) {
Jens Axboe691c8fb2008-03-07 14:26:26 +0100216 int fileno;
217
Jens Axboebd6f78b2008-02-01 20:27:52 +0100218 dprint(FD_BLKTRACE, "add devices %s\n", dev);
Jens Axboe49ffb4a2010-08-24 15:01:37 +0200219 fileno = add_file_exclusive(td, dev);
Shaohua Li89ac1d42012-06-11 08:56:32 +0200220 trace_add_open_close_event(td, fileno, FIO_LOG_OPEN_FILE);
221 last_fileno = fileno;
Jens Axboebd6f78b2008-02-01 20:27:52 +0100222 }
Shaohua Li89ac1d42012-06-11 08:56:32 +0200223 return last_fileno;
Jens Axboe5e6c2062007-05-16 14:40:29 +0200224}
225
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200226/*
227 * Store blk_io_trace data in an ipo for later retrieval.
228 */
Jens Axboefdefd982007-05-15 10:12:26 +0200229static void store_ipo(struct thread_data *td, unsigned long long offset,
Shaohua Li89ac1d42012-06-11 08:56:32 +0200230 unsigned int bytes, int rw, unsigned long long ttime,
231 int fileno)
Jens Axboefdefd982007-05-15 10:12:26 +0200232{
233 struct io_piece *ipo = malloc(sizeof(*ipo));
234
Jens Axboe0d29de82010-09-01 13:54:15 +0200235 init_ipo(ipo);
236
Jens Axboea2eea812007-05-15 13:10:41 +0200237 /*
238 * the 512 is wrong here, it should be the hardware sector size...
239 */
240 ipo->offset = offset * 512;
Jens Axboefdefd982007-05-15 10:12:26 +0200241 ipo->len = bytes;
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200242 ipo->delay = ttime / 1000;
Jens Axboefdefd982007-05-15 10:12:26 +0200243 if (rw)
244 ipo->ddir = DDIR_WRITE;
245 else
246 ipo->ddir = DDIR_READ;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200247 ipo->fileno = fileno;
Jens Axboefdefd982007-05-15 10:12:26 +0200248
Jens Axboebd6f78b2008-02-01 20:27:52 +0100249 dprint(FD_BLKTRACE, "store ddir=%d, off=%llu, len=%lu, delay=%lu\n",
250 ipo->ddir, ipo->offset,
251 ipo->len, ipo->delay);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100252 queue_io_piece(td, ipo);
Jens Axboefdefd982007-05-15 10:12:26 +0200253}
254
Jens Axboe0b9d69e2009-09-11 22:29:54 +0200255static void handle_trace_notify(struct blk_io_trace *t)
Jens Axboe691c8fb2008-03-07 14:26:26 +0100256{
257 switch (t->action) {
258 case BLK_TN_PROCESS:
Jens Axboed95b34a2013-11-21 09:55:49 -0700259 log_info("blktrace: got process notify: %x, %d\n",
260 t->action, t->pid);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100261 break;
262 case BLK_TN_TIMESTAMP:
Jens Axboed95b34a2013-11-21 09:55:49 -0700263 log_info("blktrace: got timestamp notify: %x, %d\n",
264 t->action, t->pid);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100265 break;
Jens Axboeff58fce2010-08-25 12:02:08 +0200266 case BLK_TN_MESSAGE:
267 break;
Jens Axboe691c8fb2008-03-07 14:26:26 +0100268 default:
269 dprint(FD_BLKTRACE, "unknown trace act %x\n", t->action);
270 break;
271 }
272}
273
Jens Axboeff58fce2010-08-25 12:02:08 +0200274static void handle_trace_discard(struct thread_data *td, struct blk_io_trace *t,
275 unsigned long long ttime, unsigned long *ios)
276{
277 struct io_piece *ipo = malloc(sizeof(*ipo));
Shaohua Li89ac1d42012-06-11 08:56:32 +0200278 int fileno;
Jens Axboeff58fce2010-08-25 12:02:08 +0200279
Jens Axboe0d29de82010-09-01 13:54:15 +0200280 init_ipo(ipo);
Shaohua Li89ac1d42012-06-11 08:56:32 +0200281 fileno = trace_add_file(td, t->device);
Jens Axboeff58fce2010-08-25 12:02:08 +0200282
283 ios[DDIR_WRITE]++;
284 td->o.size += t->bytes;
285
286 memset(ipo, 0, sizeof(*ipo));
287 INIT_FLIST_HEAD(&ipo->list);
288
289 /*
290 * the 512 is wrong here, it should be the hardware sector size...
291 */
292 ipo->offset = t->sector * 512;
293 ipo->len = t->bytes;
294 ipo->delay = ttime / 1000;
295 ipo->ddir = DDIR_TRIM;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200296 ipo->fileno = fileno;
Jens Axboeff58fce2010-08-25 12:02:08 +0200297
298 dprint(FD_BLKTRACE, "store discard, off=%llu, len=%lu, delay=%lu\n",
299 ipo->offset, ipo->len,
300 ipo->delay);
301 queue_io_piece(td, ipo);
302}
303
Jens Axboe691c8fb2008-03-07 14:26:26 +0100304static void handle_trace_fs(struct thread_data *td, struct blk_io_trace *t,
305 unsigned long long ttime, unsigned long *ios,
306 unsigned int *bs)
Jens Axboefb7b71a2007-05-15 08:44:04 +0200307{
Jens Axboefdefd982007-05-15 10:12:26 +0200308 int rw;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200309 int fileno;
Jens Axboefdefd982007-05-15 10:12:26 +0200310
Shaohua Li89ac1d42012-06-11 08:56:32 +0200311 fileno = trace_add_file(td, t->device);
Jens Axboe5e6c2062007-05-16 14:40:29 +0200312
Jens Axboee7a7d702007-05-15 10:13:04 +0200313 rw = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
Jens Axboed84f8d42007-05-16 08:47:46 +0200314
315 if (t->bytes > bs[rw])
316 bs[rw] = t->bytes;
317
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200318 ios[rw]++;
Jens Axboe6df8ada2007-05-15 13:23:19 +0200319 td->o.size += t->bytes;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200320 store_ipo(td, t->sector, t->bytes, rw, ttime, fileno);
Jens Axboefb7b71a2007-05-15 08:44:04 +0200321}
322
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200323/*
Jens Axboe691c8fb2008-03-07 14:26:26 +0100324 * We only care for queue traces, most of the others are side effects
325 * due to internal workings of the block layer.
326 */
327static void handle_trace(struct thread_data *td, struct blk_io_trace *t,
328 unsigned long long ttime, unsigned long *ios,
329 unsigned int *bs)
330{
331 if ((t->action & 0xffff) != __BLK_TA_QUEUE)
332 return;
333 if (t->action & BLK_TC_ACT(BLK_TC_PC))
334 return;
335
336 if (t->action & BLK_TC_ACT(BLK_TC_NOTIFY))
Jens Axboeaec2de22008-04-24 12:44:42 +0200337 handle_trace_notify(t);
Jens Axboeff58fce2010-08-25 12:02:08 +0200338 else if (t->action & BLK_TC_ACT(BLK_TC_DISCARD))
339 handle_trace_discard(td, t, ttime, ios);
Jens Axboe691c8fb2008-03-07 14:26:26 +0100340 else
341 handle_trace_fs(td, t, ttime, ios, bs);
342}
343
Jens Axboed95b34a2013-11-21 09:55:49 -0700344static void byteswap_trace(struct blk_io_trace *t)
345{
346 t->magic = fio_swap32(t->magic);
347 t->sequence = fio_swap32(t->sequence);
348 t->time = fio_swap64(t->time);
349 t->sector = fio_swap64(t->sector);
350 t->bytes = fio_swap32(t->bytes);
351 t->action = fio_swap32(t->action);
352 t->pid = fio_swap32(t->pid);
353 t->device = fio_swap32(t->device);
354 t->cpu = fio_swap32(t->cpu);
355 t->error = fio_swap16(t->error);
356 t->pdu_len = fio_swap16(t->pdu_len);
357}
358
Jens Axboe691c8fb2008-03-07 14:26:26 +0100359/*
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200360 * Load a blktrace file by reading all the blk_io_trace entries, and storing
361 * them as io_pieces like the fio text version would do.
362 */
Jens Axboed95b34a2013-11-21 09:55:49 -0700363int load_blktrace(struct thread_data *td, const char *filename, int need_swap)
Jens Axboefb7b71a2007-05-15 08:44:04 +0200364{
Jens Axboea61edde2007-05-15 14:29:58 +0200365 unsigned long long ttime, delay;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200366 struct blk_io_trace t;
Jens Axboe4241ea82007-09-12 08:18:36 +0200367 unsigned long ios[2], skipped_writes;
Jens Axboea61edde2007-05-15 14:29:58 +0200368 unsigned int cpu;
Jens Axboed84f8d42007-05-16 08:47:46 +0200369 unsigned int rw_bs[2];
Jens Axboee2887562007-05-16 09:25:09 +0200370 struct fifo *fifo;
Shaohua Li89ac1d42012-06-11 08:56:32 +0200371 int fd, i;
372 struct fio_file *f;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200373
374 fd = open(filename, O_RDONLY);
375 if (fd < 0) {
376 td_verror(td, errno, "open blktrace file");
377 return 1;
378 }
379
Jens Axboee2887562007-05-16 09:25:09 +0200380 fifo = fifo_alloc(TRACE_FIFO_SIZE);
381
Jens Axboe6df8ada2007-05-15 13:23:19 +0200382 td->o.size = 0;
383
Jens Axboea61edde2007-05-15 14:29:58 +0200384 cpu = 0;
Jens Axboed84f8d42007-05-16 08:47:46 +0200385 ttime = 0;
386 ios[0] = ios[1] = 0;
387 rw_bs[0] = rw_bs[1] = 0;
Jens Axboe4241ea82007-09-12 08:18:36 +0200388 skipped_writes = 0;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200389 do {
Jens Axboee2887562007-05-16 09:25:09 +0200390 int ret = trace_fifo_get(td, fifo, fd, &t, sizeof(t));
Jens Axboefb7b71a2007-05-15 08:44:04 +0200391
Jens Axboee2887562007-05-16 09:25:09 +0200392 if (ret < 0)
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200393 goto err;
Jens Axboee2887562007-05-16 09:25:09 +0200394 else if (!ret)
Jens Axboefb7b71a2007-05-15 08:44:04 +0200395 break;
Jens Axboee2887562007-05-16 09:25:09 +0200396 else if (ret < (int) sizeof(t)) {
397 log_err("fio: short fifo get\n");
398 break;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200399 }
400
Jens Axboed95b34a2013-11-21 09:55:49 -0700401 if (need_swap)
402 byteswap_trace(&t);
403
Jens Axboefb7b71a2007-05-15 08:44:04 +0200404 if ((t.magic & 0xffffff00) != BLK_IO_TRACE_MAGIC) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100405 log_err("fio: bad magic in blktrace data: %x\n",
406 t.magic);
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200407 goto err;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200408 }
409 if ((t.magic & 0xff) != BLK_IO_TRACE_VERSION) {
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100410 log_err("fio: bad blktrace version %d\n",
411 t.magic & 0xff);
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200412 goto err;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200413 }
Jens Axboef12b3232007-05-16 12:16:44 +0200414 ret = discard_pdu(td, fifo, fd, &t);
415 if (ret < 0) {
Jens Axboefb7b71a2007-05-15 08:44:04 +0200416 td_verror(td, ret, "blktrace lseek");
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200417 goto err;
Jens Axboef12b3232007-05-16 12:16:44 +0200418 } else if (t.pdu_len != ret) {
419 log_err("fio: discarded %d of %d\n", ret, t.pdu_len);
420 goto err;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200421 }
Jens Axboe691c8fb2008-03-07 14:26:26 +0100422 if ((t.action & BLK_TC_ACT(BLK_TC_NOTIFY)) == 0) {
423 if (!ttime) {
424 ttime = t.time;
425 cpu = t.cpu;
426 }
427
428 delay = 0;
429 if (cpu == t.cpu)
430 delay = t.time - ttime;
431 if ((t.action & BLK_TC_ACT(BLK_TC_WRITE)) && read_only)
432 skipped_writes++;
David Nellans64bbb862010-08-24 22:13:30 +0200433 else {
434 /*
435 * set delay to zero if no_stall enabled for
436 * fast replay
437 */
438 if (td->o.no_stall)
439 delay = 0;
440
Jens Axboe691c8fb2008-03-07 14:26:26 +0100441 handle_trace(td, &t, delay, ios, rw_bs);
David Nellans64bbb862010-08-24 22:13:30 +0200442 }
Jens Axboe691c8fb2008-03-07 14:26:26 +0100443
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200444 ttime = t.time;
Jens Axboea61edde2007-05-15 14:29:58 +0200445 cpu = t.cpu;
Jens Axboea6edd632008-03-07 21:41:54 +0100446 } else {
447 delay = 0;
Jens Axboe4241ea82007-09-12 08:18:36 +0200448 handle_trace(td, &t, delay, ios, rw_bs);
Jens Axboea6edd632008-03-07 21:41:54 +0100449 }
Jens Axboefb7b71a2007-05-15 08:44:04 +0200450 } while (1);
451
Jens Axboe85a47ca2012-06-11 13:19:13 +0200452 for (i = 0; i < td->files_index; i++) {
453 f= td->files[i];
Shaohua Li89ac1d42012-06-11 08:56:32 +0200454 trace_add_open_close_event(td, f->fileno, FIO_LOG_CLOSE_FILE);
Jens Axboe85a47ca2012-06-11 13:19:13 +0200455 }
Shaohua Li89ac1d42012-06-11 08:56:32 +0200456
Jens Axboe38470f82007-05-16 09:26:23 +0200457 fifo_free(fifo);
Jens Axboefb7b71a2007-05-15 08:44:04 +0200458 close(fd);
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200459
Jens Axboe4241ea82007-09-12 08:18:36 +0200460 if (skipped_writes)
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100461 log_err("fio: %s skips replay of %lu writes due to read-only\n",
462 td->o.name, skipped_writes);
Jens Axboe4241ea82007-09-12 08:18:36 +0200463
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200464 if (!ios[DDIR_READ] && !ios[DDIR_WRITE]) {
465 log_err("fio: found no ios in blktrace data\n");
466 return 1;
Jens Axboed84f8d42007-05-16 08:47:46 +0200467 } else if (ios[DDIR_READ] && !ios[DDIR_READ]) {
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200468 td->o.td_ddir = TD_DDIR_READ;
Jens Axboed84f8d42007-05-16 08:47:46 +0200469 td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ];
470 } else if (!ios[DDIR_READ] && ios[DDIR_WRITE]) {
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200471 td->o.td_ddir = TD_DDIR_WRITE;
Jens Axboed84f8d42007-05-16 08:47:46 +0200472 td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE];
473 } else {
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200474 td->o.td_ddir = TD_DDIR_RW;
Jens Axboed84f8d42007-05-16 08:47:46 +0200475 td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ];
476 td->o.max_bs[DDIR_WRITE] = rw_bs[DDIR_WRITE];
477 }
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200478
479 /*
480 * We need to do direct/raw ios to the device, to avoid getting
481 * read-ahead in our way.
482 */
483 td->o.odirect = 1;
484
Jens Axboefb7b71a2007-05-15 08:44:04 +0200485 return 0;
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200486err:
487 close(fd);
Jens Axboe38470f82007-05-16 09:26:23 +0200488 fifo_free(fifo);
Jens Axboe8c1fdf02007-05-15 11:54:21 +0200489 return 1;
Jens Axboefb7b71a2007-05-15 08:44:04 +0200490}