backend: fix runtime when used with thinktime
authorAnkit Kumar <ankit.kumar@samsung.com>
Fri, 17 Feb 2023 07:03:22 +0000 (12:33 +0530)
committerJens Axboe <axboe@kernel.dk>
Sat, 18 Feb 2023 02:52:50 +0000 (19:52 -0700)
Runtime for fio jobs when used in conjuction with thinktime,
thinktime_iotime and thinktime_spin were sometimes more than
what is specified. Add a fix so that fio doesn't spin or sleep
for any duration beyond runtime.

For the first cycle fio starts by doing I/O for
thinktime + thinktime_iotime, which should just be for
thinktime_iotime. Add a fix for that.

Signed-off-by: Ankit Kumar <ankit.kumar@samsung.com>
Link: https://lore.kernel.org/r/20230217070322.14163-2-ankit.kumar@samsung.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c

index 9e981bf408016aadb40f30dd5ca06db87febd0c6..cb1fbf424136d03de69774d0b36112c5789857a7 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -866,6 +866,7 @@ static void handle_thinktime(struct thread_data *td, enum fio_ddir ddir,
                             struct timespec *time)
 {
        unsigned long long b;
+       unsigned long long runtime_left;
        uint64_t total;
        int left;
        struct timespec now;
@@ -874,7 +875,7 @@ static void handle_thinktime(struct thread_data *td, enum fio_ddir ddir,
        if (td->o.thinktime_iotime) {
                fio_gettime(&now, NULL);
                if (utime_since(&td->last_thinktime, &now)
-                   >= td->o.thinktime_iotime + td->o.thinktime) {
+                   >= td->o.thinktime_iotime) {
                        stall = true;
                } else if (!fio_option_is_set(&td->o, thinktime_blocks)) {
                        /*
@@ -897,11 +898,24 @@ static void handle_thinktime(struct thread_data *td, enum fio_ddir ddir,
 
        io_u_quiesce(td);
 
+       left = td->o.thinktime_spin;
+       if (td->o.timeout) {
+               runtime_left = td->o.timeout - utime_since_now(&td->epoch);
+               if (runtime_left < (unsigned long long)left)
+                       left = runtime_left;
+       }
+
        total = 0;
-       if (td->o.thinktime_spin)
-               total = usec_spin(td->o.thinktime_spin);
+       if (left)
+               total = usec_spin(left);
 
        left = td->o.thinktime - total;
+       if (td->o.timeout) {
+               runtime_left = td->o.timeout - utime_since_now(&td->epoch);
+               if (runtime_left < (unsigned long long)left)
+                       left = runtime_left;
+       }
+
        if (left)
                total += usec_sleep(td, left);
 
@@ -930,8 +944,10 @@ static void handle_thinktime(struct thread_data *td, enum fio_ddir ddir,
                fio_gettime(time, NULL);
 
        td->last_thinktime_blocks = b;
-       if (td->o.thinktime_iotime)
+       if (td->o.thinktime_iotime) {
+               fio_gettime(&now, NULL);
                td->last_thinktime = now;
+       }
 }
 
 /*