All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>, John Snow <jsnow@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH v4 03/13] block/mirror: Use CoQueue to wait on in-flight ops
Date: Wed, 11 Apr 2018 20:54:15 +0200	[thread overview]
Message-ID: <20180411185425.2461-4-mreitz@redhat.com> (raw)
In-Reply-To: <20180411185425.2461-1-mreitz@redhat.com>

Attach a CoQueue to each in-flight operation so if we need to wait for
any we can use it to wait instead of just blindly yielding and hoping
for some operation to wake us.

A later patch will use this infrastructure to allow requests accessing
the same area of the virtual disk to specifically wait for each other.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
---
 block/mirror.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/block/mirror.c b/block/mirror.c
index bd8ee7d92c..1af6481876 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -13,6 +13,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
+#include "qemu/coroutine.h"
 #include "trace.h"
 #include "block/blockjob_int.h"
 #include "block/block_int.h"
@@ -34,6 +35,8 @@ typedef struct MirrorBuffer {
     QSIMPLEQ_ENTRY(MirrorBuffer) next;
 } MirrorBuffer;
 
+typedef struct MirrorOp MirrorOp;
+
 typedef struct MirrorBlockJob {
     BlockJob common;
     RateLimit limit;
@@ -67,15 +70,15 @@ typedef struct MirrorBlockJob {
     unsigned long *in_flight_bitmap;
     int in_flight;
     int64_t bytes_in_flight;
+    QTAILQ_HEAD(MirrorOpList, MirrorOp) ops_in_flight;
     int ret;
     bool unmap;
-    bool waiting_for_io;
     int target_cluster_size;
     int max_iov;
     bool initial_zeroing_ongoing;
 } MirrorBlockJob;
 
-typedef struct MirrorOp {
+struct MirrorOp {
     MirrorBlockJob *s;
     QEMUIOVector qiov;
     int64_t offset;
@@ -84,7 +87,11 @@ typedef struct MirrorOp {
     /* The pointee is set by mirror_co_read(), mirror_co_zero(), and
      * mirror_co_discard() before yielding for the first time */
     int64_t *bytes_handled;
-} MirrorOp;
+
+    CoQueue waiting_requests;
+
+    QTAILQ_ENTRY(MirrorOp) next;
+};
 
 typedef enum MirrorMethod {
     MIRROR_METHOD_COPY,
@@ -125,7 +132,9 @@ static void coroutine_fn mirror_iteration_done(MirrorOp *op, int ret)
 
     chunk_num = op->offset / s->granularity;
     nb_chunks = DIV_ROUND_UP(op->bytes, s->granularity);
+
     bitmap_clear(s->in_flight_bitmap, chunk_num, nb_chunks);
+    QTAILQ_REMOVE(&s->ops_in_flight, op, next);
     if (ret >= 0) {
         if (s->cow_bitmap) {
             bitmap_set(s->cow_bitmap, chunk_num, nb_chunks);
@@ -135,11 +144,9 @@ static void coroutine_fn mirror_iteration_done(MirrorOp *op, int ret)
         }
     }
     qemu_iovec_destroy(&op->qiov);
-    g_free(op);
 
-    if (s->waiting_for_io) {
-        qemu_coroutine_enter(s->common.co);
-    }
+    qemu_co_queue_restart_all(&op->waiting_requests);
+    g_free(op);
 }
 
 static void coroutine_fn mirror_write_complete(MirrorOp *op, int ret)
@@ -229,10 +236,11 @@ static int mirror_cow_align(MirrorBlockJob *s, int64_t *offset,
 
 static inline void mirror_wait_for_io(MirrorBlockJob *s)
 {
-    assert(!s->waiting_for_io);
-    s->waiting_for_io = true;
-    qemu_coroutine_yield();
-    s->waiting_for_io = false;
+    MirrorOp *op;
+
+    op = QTAILQ_FIRST(&s->ops_in_flight);
+    assert(op);
+    qemu_co_queue_wait(&op->waiting_requests, NULL);
 }
 
 /* Perform a mirror copy operation.
@@ -342,6 +350,7 @@ static unsigned mirror_perform(MirrorBlockJob *s, int64_t offset,
         .bytes          = bytes,
         .bytes_handled  = &bytes_handled,
     };
+    qemu_co_queue_init(&op->waiting_requests);
 
     switch (mirror_method) {
     case MIRROR_METHOD_COPY:
@@ -357,6 +366,7 @@ static unsigned mirror_perform(MirrorBlockJob *s, int64_t offset,
         abort();
     }
 
+    QTAILQ_INSERT_TAIL(&s->ops_in_flight, op, next);
     qemu_coroutine_enter(co);
     /* At this point, ownership of op has been moved to the coroutine
      * and the object may already be freed */
@@ -1283,6 +1293,8 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
         }
     }
 
+    QTAILQ_INIT(&s->ops_in_flight);
+
     trace_mirror_start(bs, s, opaque);
     block_job_start(&s->common);
     return;
-- 
2.14.3

  parent reply	other threads:[~2018-04-11 18:54 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-11 18:54 [Qemu-devel] [PATCH v4 for-2.13 00/13] block/mirror: Add active-sync mirroring Max Reitz
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 01/13] block/mirror: Pull out mirror_perform() Max Reitz
2018-04-19 13:31   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 02/13] block/mirror: Convert to coroutines Max Reitz
2018-04-11 18:54 ` Max Reitz [this message]
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 04/13] block/mirror: Wait for in-flight op conflicts Max Reitz
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 05/13] block/mirror: Use source as a BdrvChild Max Reitz
2018-04-19 14:48   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 06/13] block: Generalize should_update_child() rule Max Reitz
2018-04-19 15:19   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-04-20  8:36   ` Alberto Garcia
2018-04-20 13:29     ` Max Reitz
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 07/13] hbitmap: Add @advance param to hbitmap_iter_next() Max Reitz
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 08/13] test-hbitmap: Add non-advancing iter_next tests Max Reitz
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 09/13] block/dirty-bitmap: Add bdrv_dirty_iter_next_area Max Reitz
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 10/13] block/mirror: Add MirrorBDSOpaque Max Reitz
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 11/13] block/mirror: Add active mirroring Max Reitz
2018-04-11 22:14   ` Eric Blake
2018-04-20 13:24     ` Max Reitz
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 12/13] block/mirror: Add copy mode QAPI interface Max Reitz
2018-04-19 14:56   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-04-11 18:54 ` [Qemu-devel] [PATCH v4 13/13] iotests: Add test for active mirroring Max Reitz
2018-04-19 15:00   ` [Qemu-devel] [Qemu-block] " Alberto Garcia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180411185425.2461-4-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.