Improve submission latency calculation
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index 7e5bfcc190585362a075d47b1134fbb049d5f1d2..6234c42b3a91b32305110f96e9e216472a9f537c 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -379,7 +379,7 @@ struct io_u *get_io_u(struct thread_data *td)
         * from a requeue, io_u already setup
         */
        if (io_u->file)
-               return io_u;
+               goto out;
 
        f = get_next_file(td);
        if (!f) {
@@ -423,6 +423,7 @@ struct io_u *get_io_u(struct thread_data *td)
        /*
         * Set io data pointers.
         */
+out:
        io_u->xfer_buf = io_u->buf;
        io_u->xfer_buflen = io_u->buflen;
 
@@ -525,6 +526,7 @@ long io_u_queued_complete(struct thread_data *td, int min_events,
 
 {
        struct io_completion_data icd;
+       struct timespec *tvp = NULL;
        int ret;
 
        if (min_events > 0) {
@@ -533,9 +535,13 @@ long io_u_queued_complete(struct thread_data *td, int min_events,
                        td_verror(td, -ret);
                        return ret;
                }
+       } else {
+               struct timespec ts = { .tv_sec = 0, .tv_nsec = 0, };
+
+               tvp = &ts;
        }
 
-       ret = td_io_getevents(td, min_events, td->cur_depth, NULL);
+       ret = td_io_getevents(td, min_events, td->cur_depth, tvp);
        if (ret < 0) {
                td_verror(td, -ret);
                return ret;
@@ -549,3 +555,14 @@ long io_u_queued_complete(struct thread_data *td, int min_events,
 
        return -1;
 }
+
+/*
+ * Call when io_u is really queued, to update the submission latency.
+ */
+void io_u_queued(struct thread_data *td, struct io_u *io_u)
+{
+       unsigned long slat_time;
+
+       slat_time = mtime_since(&io_u->start_time, &io_u->issue_time);
+       add_slat_sample(td, io_u->ddir, slat_time);
+}