qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v1 resend 0/2] virtio-blk: dataplane: one fix plus one optimization
@ 2014-07-12  4:08 Ming Lei
  2014-07-12  4:08 ` [Qemu-devel] [PATCH v1 resend 1/2] virtio-blk: data-plane: fix save/set .complete_request in start Ming Lei
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ming Lei @ 2014-07-12  4:08 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini, Stefan Hajnoczi
  Cc: Kevin Wolf, Fam Zheng, Michael S. Tsirkin

Hi,

The first one fixes one problem introduced recently.

The second one suppresses notifications to guest a lot.

V1:
	- use BH to suppress notifications to guest as suggested by Paolo


Thanks,
--
Ming Lei

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH v1 resend 1/2] virtio-blk: data-plane: fix save/set .complete_request in start
  2014-07-12  4:08 [Qemu-devel] [PATCH v1 resend 0/2] virtio-blk: dataplane: one fix plus one optimization Ming Lei
@ 2014-07-12  4:08 ` Ming Lei
  2014-07-12  4:08 ` [Qemu-devel] [PATCH v1 resend 2/2] virtio-blk: dataplane: notify guest as a batch Ming Lei
  2014-07-14  8:34 ` [Qemu-devel] [PATCH v1 resend 0/2] virtio-blk: dataplane: one fix plus one optimization Stefan Hajnoczi
  2 siblings, 0 replies; 4+ messages in thread
From: Ming Lei @ 2014-07-12  4:08 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini, Stefan Hajnoczi
  Cc: Kevin Wolf, Ming Lei, Fam Zheng, Michael S. Tsirkin

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.

Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Ming Lei <ming.lei@canonical.com>
---
 hw/block/dataplane/virtio-blk.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 4bc0729..60390ff 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -127,7 +127,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);
@@ -180,8 +179,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 */
@@ -203,6 +200,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) {
@@ -236,6 +234,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);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH v1 resend 2/2] virtio-blk: dataplane: notify guest as a batch
  2014-07-12  4:08 [Qemu-devel] [PATCH v1 resend 0/2] virtio-blk: dataplane: one fix plus one optimization Ming Lei
  2014-07-12  4:08 ` [Qemu-devel] [PATCH v1 resend 1/2] virtio-blk: data-plane: fix save/set .complete_request in start Ming Lei
@ 2014-07-12  4:08 ` Ming Lei
  2014-07-14  8:34 ` [Qemu-devel] [PATCH v1 resend 0/2] virtio-blk: dataplane: one fix plus one optimization Stefan Hajnoczi
  2 siblings, 0 replies; 4+ messages in thread
From: Ming Lei @ 2014-07-12  4:08 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini, Stefan Hajnoczi
  Cc: Kevin Wolf, Ming Lei, Ming Lei, Fam Zheng, Michael S. Tsirkin

From: Ming Lei <tom.leiming@gmail.com>

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

This may suppress interrupt notification to VM a lot:

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

Signed-off-by: Ming Lei <ming.lei@canonical.com>
---
 hw/block/dataplane/virtio-blk.c |   23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 60390ff..8a78eee 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -34,6 +34,7 @@ struct VirtIOBlockDataPlane {
     VirtIODevice *vdev;
     Vring vring;                    /* virtqueue vring */
     EventNotifier *guest_notifier;  /* irq */
+    QEMUBH *bh;                     /* bh for guest notification */
 
     /* Note that these EventNotifiers are assigned by value.  This is
      * fine as long as you do not call event_notifier_cleanup on them
@@ -61,14 +62,28 @@ static void notify_guest(VirtIOBlockDataPlane *s)
     event_notifier_set(s->guest_notifier);
 }
 
+static void notify_guest_bh(void *opaque)
+{
+    VirtIOBlockDataPlane *s = opaque;
+
+    notify_guest(s);
+}
+
 static void complete_request_vring(VirtIOBlockReq *req, unsigned char status)
 {
+    VirtIOBlockDataPlane *s = req->dev->dataplane;
     stb_p(&req->in->status, status);
 
-    vring_push(&req->dev->dataplane->vring, req->elem,
-               req->qiov.size + sizeof(*req->in));
-    notify_guest(req->dev->dataplane);
+    vring_push(&s->vring, req->elem, req->qiov.size + sizeof(*req->in));
     g_slice_free(VirtIOBlockReq, req);
+
+    /* Suppress notification to guest by BH and its scheduled
+     * flag because requests are completed as a batch after io
+     * plug & unplug is introduced, and the BH can still be
+     * executed in dataplane aio context even after it is
+     * stopped, so needn't worry about notification loss with BH.
+     */
+    qemu_bh_schedule(s->bh);
 }
 
 static void handle_notify(EventNotifier *e)
@@ -174,6 +189,7 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
         s->iothread = &s->internal_iothread_obj;
     }
     s->ctx = iothread_get_aio_context(s->iothread);
+    s->bh = aio_bh_new(s->ctx, notify_guest_bh, s);
 
     error_setg(&s->blocker, "block device is in use by data plane");
     bdrv_op_block_all(blk->conf.bs, s->blocker);
@@ -192,6 +208,7 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
     bdrv_op_unblock_all(s->blk->conf.bs, s->blocker);
     error_free(s->blocker);
     object_unref(OBJECT(s->iothread));
+    qemu_bh_delete(s->bh);
     g_free(s);
 }
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v1 resend 0/2] virtio-blk: dataplane: one fix plus one optimization
  2014-07-12  4:08 [Qemu-devel] [PATCH v1 resend 0/2] virtio-blk: dataplane: one fix plus one optimization Ming Lei
  2014-07-12  4:08 ` [Qemu-devel] [PATCH v1 resend 1/2] virtio-blk: data-plane: fix save/set .complete_request in start Ming Lei
  2014-07-12  4:08 ` [Qemu-devel] [PATCH v1 resend 2/2] virtio-blk: dataplane: notify guest as a batch Ming Lei
@ 2014-07-14  8:34 ` Stefan Hajnoczi
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2014-07-14  8:34 UTC (permalink / raw)
  To: Ming Lei
  Cc: Kevin Wolf, Paolo Bonzini, Fam Zheng, qemu-devel,
	Michael S. Tsirkin

[-- Attachment #1: Type: text/plain, Size: 365 bytes --]

On Sat, Jul 12, 2014 at 12:08:51PM +0800, Ming Lei wrote:
> Hi,
> 
> The first one fixes one problem introduced recently.
> 
> The second one suppresses notifications to guest a lot.
> 
> V1:
> 	- use BH to suppress notifications to guest as suggested by Paolo

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-07-14  8:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-12  4:08 [Qemu-devel] [PATCH v1 resend 0/2] virtio-blk: dataplane: one fix plus one optimization Ming Lei
2014-07-12  4:08 ` [Qemu-devel] [PATCH v1 resend 1/2] virtio-blk: data-plane: fix save/set .complete_request in start Ming Lei
2014-07-12  4:08 ` [Qemu-devel] [PATCH v1 resend 2/2] virtio-blk: dataplane: notify guest as a batch Ming Lei
2014-07-14  8:34 ` [Qemu-devel] [PATCH v1 resend 0/2] virtio-blk: dataplane: one fix plus one optimization Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).