Skip to contentSkip to conversation

virtio-blk: dataplane: one fix plus one optimization

PATCH In review Ming Lei 2 participants 9 messages Jul 4, 2014 – Jul 5, 2014

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

cover virtio-blk: dataplane: one fix plus one optimization

Hi,

The first one fixes one problem introduced recently.

The second one supresses notifications to guest.

Thanks,
--
Ming Lei

author
#1 lore raw

PATCH 1/2 virtio-blk: data-plane: fix save/set .complete_request in start

The callback has to be saved and reset in virtio_blk_data_plane_start(), otherwise dataplane's requests will be completed in qemu aio context.

---
 hw/block/dataplane/virtio-blk.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/block/dataplane/virtio-blk.c +4 -3
index 227bb15..e88862d 100644
@@ -125,7 +125,6 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
                                   Error **errp)
 {
     VirtIOBlockDataPlane *s;
-    VirtIOBlock *vblk = VIRTIO_BLK(vdev);
     Error *local_err = NULL;
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
@@ -178,8 +177,6 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
     bdrv_op_block_all(blk->conf.bs, s->blocker);
 
     *dataplane = s;
-    s->saved_complete_request = vblk->complete_request;
-    vblk->complete_request = complete_request_vring;
 }
 
 /* Context: QEMU global mutex held */
@@ -201,6 +198,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
 {
     BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s->vdev)));
     VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+    VirtIOBlock *vblk = VIRTIO_BLK(s->vdev);
     VirtQueue *vq;
 
     if (s->started) {
@@ -234,6 +232,9 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
     }
     s->host_notifier = *virtio_queue_get_host_notifier(vq);
 
+    s->saved_complete_request = vblk->complete_request;
+    vblk->complete_request = complete_request_vring;
+
     s->starting = false;
     s->started = true;
     trace_virtio_blk_data_plane_start(s);
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH 2/2 virtio-blk: dataplane: notify guest as a batch

In reply to Ming Lei

Now requests are submitted as a batch, so it is natural to notify guest as a batch too.

This may supress interrupt notification to VM:

- in my test, decreased by ~13K/sec

---
 hw/block/dataplane/virtio-blk.c |   13 ++++++++++++-
 hw/block/virtio-blk.c           |    1 +
 include/hw/virtio/virtio-blk.h  |    1 +
 3 files changed, 14 insertions(+), 1 deletion(-)
hw/block/dataplane/virtio-blk.c +12 -1
index e88862d..9d36659 100644
@@ -45,6 +45,8 @@ struct VirtIOBlockDataPlane {
     AioContext *ctx;
     EventNotifier host_notifier;    /* doorbell */
 
+    VirtIOBlockReq *last_submit;
+
     /* Operation blocker on BDS */
     Error *blocker;
     void (*saved_complete_request)(struct VirtIOBlockReq *req,
@@ -67,7 +69,10 @@ static void complete_request_vring(VirtIOBlockReq *req, unsigned char status)
 
     vring_push(&req->dev->dataplane->vring, &req->elem,
                req->qiov.size + sizeof(*req->in));
-    notify_guest(req->dev->dataplane);
+
+    if (req->last) {
+        notify_guest(req->dev->dataplane);
+    }
 }
 
 static void handle_notify(EventNotifier *e)
@@ -101,6 +106,8 @@ static void handle_notify(EventNotifier *e)
                                                         req->elem.index);
 
             virtio_blk_handle_request(req, &mrb);
+
+            s->last_submit = req;
         }
 
         virtio_submit_multiwrite(s->blk->conf.bs, &mrb);
@@ -116,6 +123,10 @@ static void handle_notify(EventNotifier *e)
             break;
         }
     }
+
+    if (s->last_submit) {
+        s->last_submit->last = true;
+    }
     bdrv_io_unplug(s->blk->conf.bs);
 }
 
hw/block/virtio-blk.c +1 -0
index 02cd6b0..86b37f7 100644
@@ -35,6 +35,7 @@ VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
     req->dev = s;
     req->qiov.size = 0;
     req->next = NULL;
+    req->last = false;
     return req;
 }
 
include/hw/virtio/virtio-blk.h +1 -0
index 992da26..07659c3 100644
@@ -150,6 +150,7 @@ typedef struct VirtIOBlockReq {
     QEMUIOVector qiov;
     struct VirtIOBlockReq *next;
     BlockAcctCookie acct;
+    bool last;
 } VirtIOBlockReq;
 
 #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
Signature · 1 line
1.7.9.5
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-blk: dataplane: notify guest as a batch

Il 04/07/2014 14:27, Ming Lei ha scritto:

Quoted 6 lines

Now requests are submitted as a batch, so it is natural to notify guest as a batch too.

This may supress interrupt notification to VM:

- in my test, decreased by ~13K/sec

I don't think this can work. Requests are not completed FIFO.

What you can do is change notify_guest to something like

    qemu_bh_schedule(req->dev->dataplane->notify_guest_bh);

and do the actual notification in the bottom half. This should ensure that multiple notifications are coalesced, but it may also introduce new aio_notify calls even with my patch (a BH scheduled from a BH currently does an aio_notify; this can be fixed).

Paolo

Quoted 77 lines
---
 hw/block/dataplane/virtio-blk.c |   13 ++++++++++++-
 hw/block/virtio-blk.c           |    1 +
 include/hw/virtio/virtio-blk.h  |    1 +
 3 files changed, 14 insertions(+), 1 deletion(-)
hw/block/dataplane/virtio-blk.c +12 -1
index e88862d..9d36659 100644
@@ -45,6 +45,8 @@ struct VirtIOBlockDataPlane {
     AioContext *ctx;
     EventNotifier host_notifier;    /* doorbell */
 
+    VirtIOBlockReq *last_submit;
+
     /* Operation blocker on BDS */
     Error *blocker;
     void (*saved_complete_request)(struct VirtIOBlockReq *req,
@@ -67,7 +69,10 @@ static void complete_request_vring(VirtIOBlockReq *req, unsigned char status)
 
     vring_push(&req->dev->dataplane->vring, &req->elem,
                req->qiov.size + sizeof(*req->in));
-    notify_guest(req->dev->dataplane);
+
+    if (req->last) {
+        notify_guest(req->dev->dataplane);
+    }
 }
 
 static void handle_notify(EventNotifier *e)
@@ -101,6 +106,8 @@ static void handle_notify(EventNotifier *e)
                                                         req->elem.index);
 
             virtio_blk_handle_request(req, &mrb);
+
+            s->last_submit = req;
         }
 
         virtio_submit_multiwrite(s->blk->conf.bs, &mrb);
@@ -116,6 +123,10 @@ static void handle_notify(EventNotifier *e)
             break;
         }
     }
+
+    if (s->last_submit) {
+        s->last_submit->last = true;
+    }
     bdrv_io_unplug(s->blk->conf.bs);
 }
 
hw/block/virtio-blk.c +1 -0
index 02cd6b0..86b37f7 100644
@@ -35,6 +35,7 @@ VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
     req->dev = s;
     req->qiov.size = 0;
     req->next = NULL;
+    req->last = false;
     return req;
 }
 
include/hw/virtio/virtio-blk.h +1 -0
index 992da26..07659c3 100644
@@ -150,6 +150,7 @@ typedef struct VirtIOBlockReq {
     QEMUIOVector qiov;
     struct VirtIOBlockReq *next;
     BlockAcctCookie acct;
+    bool last;
 } VirtIOBlockReq;
 
 #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
author
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-blk: dataplane: notify guest as a batch

Quoted 11 lines · Paolo Bonzini

Il 04/07/2014 14:27, Ming Lei ha scritto:

Quoted 6 lines

Now requests are submitted as a batch, so it is natural to notify guest as a batch too.

This may supress interrupt notification to VM:

- in my test, decreased by ~13K/sec

I don't think this can work. Requests are not completed FIFO.

Yes, you are right.

What I want to do is to keep old dataplane's behavior: only call notify_guest() one time for one IO completion.

Switching to QEMU block makes it a bit difficult to implement, especially with io plug & unplug.

One approach I thought of is to introduce a notifier in bs->file, and write it inside linux aio completion handler, which looks a bit ugly, but shouldn't have performance effect because io completion becomes less frequent with io plug.

Quoted 9 lines

What you can do is change notify_guest to something like

    qemu_bh_schedule(req->dev->dataplane->notify_guest_bh);

and do the actual notification in the bottom half. This should ensure that multiple notifications are coalesced, but it may also introduce new aio_notify calls even with my patch (a BH scheduled from a BH currently does an aio_notify; this can be fixed).

I think we can do better than above because one aio IO completes lots of requests, and we just need to notify guest for all these requests.

Thanks,

Quoted 86 lines

Paolo

Quoted 80 lines
---
 hw/block/dataplane/virtio-blk.c |   13 ++++++++++++-
 hw/block/virtio-blk.c           |    1 +
 include/hw/virtio/virtio-blk.h  |    1 +
 3 files changed, 14 insertions(+), 1 deletion(-)
hw/block/dataplane/virtio-blk.c +6 -1
index e88862d..9d36659 100644
@@ -45,6 +45,8 @@ struct VirtIOBlockDataPlane {
     AioContext *ctx;
     EventNotifier host_notifier;    /* doorbell */
 
+    VirtIOBlockReq *last_submit;
+
     /* Operation blocker on BDS */
     Error *blocker;
     void (*saved_complete_request)(struct VirtIOBlockReq *req,
@@ -67,7 +69,10 @@ static void complete_request_vring(VirtIOBlockReq *req,
 unsigned char status)
 
     vring_push(&req->dev->dataplane->vring, &req->elem,
                req->qiov.size + sizeof(*req->in));
-    notify_guest(req->dev->dataplane);
+
+    if (req->last) {
+        notify_guest(req->dev->dataplane);
+    }
 }
 

static void handle_notify(EventNotifier *e)

hw/block/dataplane/virtio-blk.c +6 -0
@@ -101,6 +106,8 @@ static void handle_notify(EventNotifier *e)
                                                         req->elem.index);
 
             virtio_blk_handle_request(req, &mrb);
+
+            s->last_submit = req;
         }
 
         virtio_submit_multiwrite(s->blk->conf.bs, &mrb);
@@ -116,6 +123,10 @@ static void handle_notify(EventNotifier *e)
             break;
         }
     }
+
+    if (s->last_submit) {
+        s->last_submit->last = true;
+    }
     bdrv_io_unplug(s->blk->conf.bs);
 }
 
hw/block/virtio-blk.c +1 -0
index 02cd6b0..86b37f7 100644
@@ -35,6 +35,7 @@ VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
     req->dev = s;
     req->qiov.size = 0;
     req->next = NULL;
+    req->last = false;
     return req;
 }
 
include/hw/virtio/virtio-blk.h +1 -0
index 992da26..07659c3 100644
@@ -150,6 +150,7 @@ typedef struct VirtIOBlockReq {
     QEMUIOVector qiov;
     struct VirtIOBlockReq *next;
     BlockAcctCookie acct;
+    bool last;
 } VirtIOBlockReq;
 
 #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-blk: dataplane: notify guest as a batch

Il 04/07/2014 16:52, Ming Lei ha scritto:

Quoted 10 lines
Quoted 8 lines
Quoted 8 lines

What you can do is change notify_guest to something like

    qemu_bh_schedule(req->dev->dataplane->notify_guest_bh);

and do the actual notification in the bottom half. This should ensure that multiple notifications are coalesced, but it may also introduce new aio_notify calls even with my patch (a BH scheduled from a BH currently does an aio_notify; this can be fixed).

I think we can do better than above because one aio IO completes lots of requests, and we just need to notify guest for all these requests.

Exactly, there would be just one BH and thus just one notify.

Paolo

author
#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-blk: dataplane: notify guest as a batch

Quoted 13 lines · Paolo Bonzini

Il 04/07/2014 16:52, Ming Lei ha scritto:

Quoted 11 lines
Quoted 10 lines
Quoted 10 lines

What you can do is change notify_guest to something like

    qemu_bh_schedule(req->dev->dataplane->notify_guest_bh);

and do the actual notification in the bottom half. This should ensure that
multiple notifications are coalesced, but it may also introduce new aio_notify calls even with my patch (a BH scheduled from a BH currently does
an aio_notify; this can be fixed).

Quoted 5 lines
Quoted 2 lines

I think we can do better than above because one aio IO completes lots of requests, and we just need to notify guest for all these requests.

Exactly, there would be just one BH and thus just one notify.

But we have two cases to consider:

- one submitted IO includes requests from multi vq(virtio-blk or virtio-scsi maybe),
and each vq has to notify guest

- one submitted IO includes requests from multi bs for scsi device

The 2nd case should be easy to handle, but I am a bit headache for the 1st case.

Thanks,
--
Ming Lei

#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-blk: dataplane: notify guest as a batch

Il 04/07/2014 17:57, Ming Lei ha scritto:

Quoted 9 lines

But we have two cases to consider:

- one submitted IO includes requests from multi vq(virtio-blk or virtio-scsi maybe),
and each vq has to notify guest

- one submitted IO includes requests from multi bs for scsi device

The 2nd case should be easy to handle, but I am a bit headache for the 1st case.

You can just have one bottom half per virtqueue. :)

Paolo

author
#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] virtio-blk: dataplane: notify guest as a batch

Quoted 8 lines · Paolo Bonzini

Il 04/07/2014 17:57, Ming Lei ha scritto:

Quoted 6 lines

But we have two cases to consider:

- one submitted IO includes requests from multi vq(virtio-blk or virtio-scsi maybe),
and each vq has to notify guest

Quoted 7 lines
Quoted 4 lines

- one submitted IO includes requests from multi bs for scsi device

The 2nd case should be easy to handle, but I am a bit headache for the 1st case.

You can just have one bottom half per virtqueue. :)

Exactly, or one BH plus per virtqueue bit flag should be enough too, :-)

Thanks,
--
Ming Lei