fio: document locking for overlap checking in offload mode
authorVincent Fu <vincent.fu@wdc.com>
Wed, 17 Oct 2018 16:03:24 +0000 (12:03 -0400)
committerJens Axboe <axboe@kernel.dk>
Fri, 19 Oct 2018 17:09:19 +0000 (11:09 -0600)
Overlap checking in offload submission mode uses locks in an unusual
manner. Add some comments in the code to clarify how locks are used.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c
ioengines.c
rate-submit.c

index 1c60138c50b5a957b35378368734b83e906baf92..d6450baf1efdef1da5945445e7f9325c2e7f0efd 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1874,6 +1874,11 @@ static void *thread_main(void *data)
                         "perhaps try --debug=io option for details?\n",
                         td->o.name, td->io_ops->name);
 
                         "perhaps try --debug=io option for details?\n",
                         td->o.name, td->io_ops->name);
 
+       /*
+        * Acquire this lock if we were doing overlap checking in
+        * offload mode so that we don't clean up this job while
+        * another thread is checking its io_u's for overlap
+        */
        if (td_offload_overlap(td))
                pthread_mutex_lock(&overlap_check);
        td_set_runstate(td, TD_FINISHING);
        if (td_offload_overlap(td))
                pthread_mutex_lock(&overlap_check);
        td_set_runstate(td, TD_FINISHING);
index 56723addc5af2f57348d2b3784c4594a5c8e88b1..b7df860825e55bb433b20a981f45c2ebf6439734 100644 (file)
@@ -288,6 +288,13 @@ enum fio_q_status td_io_queue(struct thread_data *td, struct io_u *io_u)
 
        assert((io_u->flags & IO_U_F_FLIGHT) == 0);
        io_u_set(td, io_u, IO_U_F_FLIGHT);
 
        assert((io_u->flags & IO_U_F_FLIGHT) == 0);
        io_u_set(td, io_u, IO_U_F_FLIGHT);
+
+       /*
+        * If overlap checking was enabled in offload mode we
+        * can release this lock that was acquired when we
+        * started the overlap check because the IO_U_F_FLIGHT
+        * flag is now set
+        */
        if (td_offload_overlap(td))
                pthread_mutex_unlock(&overlap_check);
 
        if (td_offload_overlap(td))
                pthread_mutex_unlock(&overlap_check);
 
index 68ad755d948056c0ff9fabc0a26a14961f410a05..e5c6204351db00304db32fa376837faa9c420cc9 100644 (file)
@@ -21,6 +21,14 @@ static void check_overlap(struct io_u *io_u)
                 * time to prevent two threads from thinking the coast
                 * is clear and then submitting IOs that overlap with
                 * each other
                 * time to prevent two threads from thinking the coast
                 * is clear and then submitting IOs that overlap with
                 * each other
+                *
+                * If an overlap is found, release the lock and
+                * re-acquire it before checking again to give other
+                * threads a chance to make progress
+                *
+                * If an overlap is not found, release the lock when the
+                * io_u's IO_U_F_FLIGHT flag is set so that this io_u
+                * can be checked by other threads as they assess overlap
                 */
                pthread_mutex_lock(&overlap_check);
                for_each_td(td, i) {
                 */
                pthread_mutex_lock(&overlap_check);
                for_each_td(td, i) {