verify: fix bytes_done accounting of experimental verify
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Thu, 20 Oct 2022 06:38:51 +0000 (15:38 +0900)
committerVincent Fu <vincent.fu@samsung.com>
Mon, 24 Oct 2022 14:34:57 +0000 (10:34 -0400)
The commit 55312f9f5572 ("Add ->bytes_done[] to struct thread_data")
moved bytes_done[] on stack to struct thread_data. However, this unified
two bytes_done[] in do_io() and do_verify() stacks into single
td->bytes_done[]. This caused wrong condition check in do_verify() in
experimental verify path since td->bytes_done[] holds values for do_io()
not for do_verify(). This caused unexpected loop break in do_verify()
and verify read skip when experimental_verify=1 option is specified.

To fix this, add bytes_verified to struct thread_data for do_verify() in
same manner as bytes_done[] for do_io(). Introduce a helper function
io_u_update_bytes_done() to factor out same code for bytes_done[] and
bytes_verified[].

Fixes: 55312f9f5572 ("Add ->bytes_done[] to struct thread_data")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
backend.c
fio.h
io_u.c
libfio.c
rate-submit.c

index d8f4f2a508119638b212d9dc1c3481ca50e7a989..15c6e0b3c061897c3d86e1e91c49a7f946c3bc2d 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -682,7 +682,7 @@ static void do_verify(struct thread_data *td, uint64_t verify_bytes)
                                break;
                        }
                } else {
-                       if (ddir_rw_sum(td->bytes_done) + td->o.rw_min_bs > verify_bytes)
+                       if (td->bytes_verified + td->o.rw_min_bs > verify_bytes)
                                break;
 
                        while ((io_u = get_io_u(td)) != NULL) {
diff --git a/fio.h b/fio.h
index de7eca79cb1a42c53dcbd0e6d4ca9d6a89f75eff..0592a4c3dc38a26db237f1cd99278719e99eecbb 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -370,6 +370,7 @@ struct thread_data {
        uint64_t zone_bytes;
        struct fio_sem *sem;
        uint64_t bytes_done[DDIR_RWDIR_CNT];
+       uint64_t bytes_verified;
 
        uint64_t *thinktime_blocks_counter;
        struct timespec last_thinktime;
diff --git a/io_u.c b/io_u.c
index 91f1a3584da4761b43e066d431b9c16f8bb64f69..8035f4b725fc13b64be0c11aa5b45853e19a7982 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -2121,13 +2121,26 @@ static void ios_completed(struct thread_data *td,
        }
 }
 
+static void io_u_update_bytes_done(struct thread_data *td,
+                                  struct io_completion_data *icd)
+{
+       int ddir;
+
+       if (td->runstate == TD_VERIFYING) {
+               td->bytes_verified += icd->bytes_done[DDIR_READ];
+               return;
+       }
+
+       for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++)
+               td->bytes_done[ddir] += icd->bytes_done[ddir];
+}
+
 /*
  * Complete a single io_u for the sync engines.
  */
 int io_u_sync_complete(struct thread_data *td, struct io_u *io_u)
 {
        struct io_completion_data icd;
-       int ddir;
 
        init_icd(td, &icd, 1);
        io_completed(td, &io_u, &icd);
@@ -2140,8 +2153,7 @@ int io_u_sync_complete(struct thread_data *td, struct io_u *io_u)
                return -1;
        }
 
-       for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++)
-               td->bytes_done[ddir] += icd.bytes_done[ddir];
+       io_u_update_bytes_done(td, &icd);
 
        return 0;
 }
@@ -2153,7 +2165,7 @@ int io_u_queued_complete(struct thread_data *td, int min_evts)
 {
        struct io_completion_data icd;
        struct timespec *tvp = NULL;
-       int ret, ddir;
+       int ret;
        struct timespec ts = { .tv_sec = 0, .tv_nsec = 0, };
 
        dprint(FD_IO, "io_u_queued_complete: min=%d\n", min_evts);
@@ -2179,8 +2191,7 @@ int io_u_queued_complete(struct thread_data *td, int min_evts)
                return -1;
        }
 
-       for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++)
-               td->bytes_done[ddir] += icd.bytes_done[ddir];
+       io_u_update_bytes_done(td, &icd);
 
        return ret;
 }
index 1a8917768b86eeabe8ffefa8e0bc9675c51162c3..ac5219744e3dc41906c3ac16a25b6e1d24fc8d74 100644 (file)
--- a/libfio.c
+++ b/libfio.c
@@ -94,6 +94,7 @@ static void reset_io_counters(struct thread_data *td, int all)
                        td->rate_next_io_time[ddir] = 0;
                        td->last_usec[ddir] = 0;
                }
+               td->bytes_verified = 0;
        }
 
        td->zone_bytes = 0;
index 268356d17a1f1b35a6eaa0ad82219db86177a4de..2fe768c0bea84e785000c782df1b586db57cf42a 100644 (file)
@@ -263,6 +263,8 @@ static void sum_ddir(struct thread_data *dst, struct thread_data *src,
        sum_val(&dst->this_io_blocks[ddir], &src->this_io_blocks[ddir]);
        sum_val(&dst->this_io_bytes[ddir], &src->this_io_bytes[ddir]);
        sum_val(&dst->bytes_done[ddir], &src->bytes_done[ddir]);
+       if (ddir == DDIR_READ)
+               sum_val(&dst->bytes_verified, &src->bytes_verified);
 
        pthread_double_unlock(&dst->io_wq.stat_lock, &src->io_wq.stat_lock);
 }