Improve submission latency calculation
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index 4f4865b206cabcad74037d06675aaf82445add1a..6234c42b3a91b32305110f96e9e216472a9f537c 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -526,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) {
@@ -534,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;
@@ -550,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);
+}