blktrace: change barrier to a flush
[fio.git] / blktrace.c
index dcddd4f21b15e322ef2796d319734c4fb94a5b2a..29d1ff748d1b7b1e3017429f216f5b91e206137c 100644 (file)
@@ -3,13 +3,12 @@
  */
 #include <stdio.h>
 #include <stdlib.h>
-#include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <linux/fs.h>
-#include <dirent.h>
 
 #include "flist.h"
 #include "fio.h"
+#include "blktrace.h"
 #include "blktrace_api.h"
 #include "oslib/linux-dev-lookup.h"
 
@@ -216,15 +215,6 @@ static void t_bytes_align(struct thread_options *o, struct blk_io_trace *t)
        t->bytes = (t->bytes + o->replay_align - 1) & ~(o->replay_align - 1);
 }
 
-static void ipo_bytes_align(struct thread_options *o, struct io_piece *ipo)
-{
-       if (!o->replay_align)
-               return;
-
-       ipo->offset &= ~(o->replay_align - (uint64_t)1);
-}
-
-
 /*
  * Store blk_io_trace data in an ipo for later retrieval.
  */
@@ -232,14 +222,15 @@ static void store_ipo(struct thread_data *td, unsigned long long offset,
                      unsigned int bytes, int rw, unsigned long long ttime,
                      int fileno, unsigned int bs)
 {
-       struct io_piece *ipo = malloc(sizeof(*ipo));
+       struct io_piece *ipo;
 
+       ipo = calloc(1, sizeof(*ipo));
        init_ipo(ipo);
 
        ipo->offset = offset * bs;
        if (td->o.replay_scale)
                ipo->offset = ipo->offset / td->o.replay_scale;
-       ipo_bytes_align(&td->o, ipo);
+       ipo_bytes_align(td->o.replay_align, ipo);
        ipo->len = bytes;
        ipo->delay = ttime / 1000;
        if (rw)
@@ -278,10 +269,11 @@ static void handle_trace_discard(struct thread_data *td,
                                 unsigned long long ttime,
                                 unsigned long *ios, unsigned int *rw_bs)
 {
-       struct io_piece *ipo = malloc(sizeof(*ipo));
+       struct io_piece *ipo;
        unsigned int bs;
        int fileno;
 
+       ipo = calloc(1, sizeof(*ipo));
        init_ipo(ipo);
        fileno = trace_add_file(td, t->device, &bs);
 
@@ -291,13 +283,12 @@ static void handle_trace_discard(struct thread_data *td,
 
        td->o.size += t->bytes;
 
-       memset(ipo, 0, sizeof(*ipo));
        INIT_FLIST_HEAD(&ipo->list);
 
        ipo->offset = t->sector * bs;
        if (td->o.replay_scale)
                ipo->offset = ipo->offset / td->o.replay_scale;
-       ipo_bytes_align(&td->o, ipo);
+       ipo_bytes_align(td->o.replay_align, ipo);
        ipo->len = t->bytes;
        ipo->delay = ttime / 1000;
        ipo->ddir = DDIR_TRIM;
@@ -321,7 +312,13 @@ static void handle_trace_fs(struct thread_data *td, struct blk_io_trace *t,
 
        rw = (t->action & BLK_TC_ACT(BLK_TC_WRITE)) != 0;
 
-       if (t->bytes > rw_bs[rw])
+       /*
+        * Need to figure out why 0 byte writes end up here sometimes, for
+        * now just ignore them.
+        */
+       if (!t->bytes)
+               return;
+       else if (t->bytes > rw_bs[rw])
                rw_bs[rw] = t->bytes;
 
        ios[rw]++;
@@ -343,13 +340,19 @@ static void handle_trace(struct thread_data *td, struct blk_io_trace *t,
                return;
 
        if (!(t->action & BLK_TC_ACT(BLK_TC_NOTIFY))) {
-               if (!last_ttime || td->o.no_stall) {
-                       last_ttime = t->time;
+               if (!last_ttime || td->o.no_stall)
                        delay = 0;
-               } else {
+               else if (td->o.replay_time_scale == 100)
                        delay = t->time - last_ttime;
-                       last_ttime = t->time;
+               else {
+                       double tmp = t->time - last_ttime;
+                       double scale;
+
+                       scale = (double) 100.0 / (double) td->o.replay_time_scale;
+                       tmp *= scale;
+                       delay = tmp;
                }
+               last_ttime = t->time;
        }
 
        t_bytes_align(&td->o, t);
@@ -508,10 +511,8 @@ int load_blktrace(struct thread_data *td, const char *filename, int need_swap)
                handle_trace(td, &t, ios, rw_bs);
        } while (1);
 
-       for (i = 0; i < td->files_index; i++) {
-               f = td->files[i];
+       for_each_file(td, f, i)
                trace_add_open_close_event(td, f->fileno, FIO_LOG_CLOSE_FILE);
-       }
 
        fifo_free(fifo);
        close(fd);