io_u: ensure that we align new start offset properly for time_based
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index f86367bd707a89a425130471a99412d3dff0c206..8d3491281ddebd665b9cc294b87b324e7bd1d4b7 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -285,8 +285,15 @@ static int get_next_seq_offset(struct thread_data *td, struct fio_file *f,
        assert(ddir_rw(ddir));
 
        if (f->last_pos[ddir] >= f->io_size + get_start_offset(td, f) &&
-           o->time_based)
-               f->last_pos[ddir] = f->last_pos[ddir] - f->io_size;
+           o->time_based) {
+               struct thread_options *o = &td->o;
+               uint64_t io_size = f->io_size + (f->io_size % o->min_bs[ddir]);
+
+               if (io_size > f->last_pos[ddir])
+                       f->last_pos[ddir] = 0;
+               else
+                       f->last_pos[ddir] = f->last_pos[ddir] - io_size;
+       }
 
        if (f->last_pos[ddir] < f->real_file_size) {
                uint64_t pos;
@@ -1559,7 +1566,7 @@ struct io_u *get_io_u(struct thread_data *td)
 out:
        assert(io_u->file);
        if (!td_io_prep(td, io_u)) {
-               if (!td->o.disable_slat)
+               if (!td->o.disable_lat)
                        fio_gettime(&io_u->start_time, NULL);
                if (do_scramble)
                        small_content_scramble(io_u);
@@ -1605,8 +1612,8 @@ void io_u_log_error(struct thread_data *td, struct io_u *io_u)
 
 static inline bool gtod_reduce(struct thread_data *td)
 {
-       return td->o.disable_clat && td->o.disable_lat && td->o.disable_slat
-               && td->o.disable_bw;
+       return (td->o.disable_clat && td->o.disable_slat && td->o.disable_bw)
+                       || td->o.gtod_reduce;
 }
 
 static void account_io_completion(struct thread_data *td, struct io_u *io_u,