iolog: account for wasted time in ipo stall
[fio.git] / iolog.c
diff --git a/iolog.c b/iolog.c
index cfcab2712d1026e20a71c27dcc2428a1a76923f2..99f8bc18d8694cca0c141c51d116aced1b4130f2 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -28,7 +28,7 @@ void queue_io_piece(struct thread_data *td, struct io_piece *ipo)
        td->total_io_size += ipo->len;
 }
 
-void log_io_u(struct thread_data *td, struct io_u *io_u)
+void log_io_u(const struct thread_data *td, const struct io_u *io_u)
 {
        if (!td->o.write_iolog_file)
                return;
@@ -60,14 +60,22 @@ void log_file(struct thread_data *td, struct fio_file *f,
 
 static void iolog_delay(struct thread_data *td, unsigned long delay)
 {
-       unsigned long usec = utime_since_now(&td->last_issue);
-       unsigned long this_delay;
+       uint64_t usec = utime_since_now(&td->last_issue);
+       uint64_t this_delay;
+       struct timeval tv;
 
+       if (delay < td->time_offset) {
+               td->time_offset = 0;
+               return;
+       }
+
+       delay -= td->time_offset;
        if (delay < usec)
                return;
 
        delay -= usec;
 
+       fio_gettime(&tv, NULL);
        while (delay && !td->terminate) {
                this_delay = delay;
                if (this_delay > 500000)
@@ -76,6 +84,12 @@ static void iolog_delay(struct thread_data *td, unsigned long delay)
                usec_sleep(td, this_delay);
                delay -= this_delay;
        }
+
+       usec = utime_since_now(&tv);
+       if (usec > delay)
+               td->time_offset = usec - delay;
+       else
+               td->time_offset = 0;
 }
 
 static int ipo_special(struct thread_data *td, struct io_piece *ipo)
@@ -173,7 +187,7 @@ void prune_io_piece_log(struct thread_data *td)
        }
 
        while (!flist_empty(&td->io_hist_list)) {
-               ipo = flist_entry(&td->io_hist_list, struct io_piece, list);
+               ipo = flist_first_entry(&td->io_hist_list, struct io_piece, list);
                flist_del(&ipo->list);
                remove_trim_entry(td, ipo);
                td->io_hist_len--;
@@ -282,7 +296,7 @@ void unlog_io_piece(struct thread_data *td, struct io_u *io_u)
        td->io_hist_len--;
 }
 
-void trim_io_piece(struct thread_data *td, struct io_u *io_u)
+void trim_io_piece(struct thread_data *td, const struct io_u *io_u)
 {
        struct io_piece *ipo = io_u->ipo;
 
@@ -871,18 +885,18 @@ int iolog_file_inflate(const char *file)
         */
        total = ic.len;
        do {
-               size_t ret;
+               size_t iret;
 
-               ret = inflate_chunk(&ic,  1, stdout, &stream, &iter);
-               total -= ret;
+               iret = inflate_chunk(&ic,  1, stdout, &stream, &iter);
+               total -= iret;
                if (!total)
                        break;
                if (iter.err)
                        break;
 
                ic.seq++;
-               ic.len -= ret;
-               ic.buf += ret;
+               ic.len -= iret;
+               ic.buf += iret;
        } while (1);
 
        if (iter.seq) {