Received: from eggs.gnu.org ([2001:4830:134:3::10]:48458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X3HRi-0004MY-0J for qemu-devel@nongnu.org; Sat, 05 Jul 2014 00:19:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X3HRb-0003NX-U1 for qemu-devel@nongnu.org; Sat, 05 Jul 2014 00:19:29 -0400 Received: from mail-pd0-f181.google.com ([209.85.192.181]:36716) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X3HRb-0003NT-OW for qemu-devel@nongnu.org; Sat, 05 Jul 2014 00:19:23 -0400 Received: by mail-pd0-f181.google.com with SMTP id v10so2673303pde.12 for ; Fri, 04 Jul 2014 21:19:23 -0700 (PDT) From: Ming Lei Date: Sat, 5 Jul 2014 12:18:55 +0800 Message-Id: <1404533935-12365-3-git-send-email-ming.lei@canonical.com> In-Reply-To: <1404533935-12365-1-git-send-email-ming.lei@canonical.com> References: <1404533935-12365-1-git-send-email-ming.lei@canonical.com> Subject: [Qemu-devel] [PATCH v1 2/2] virtio-blk: dataplane: notify guest as a batch List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , qemu-devel@nongnu.org, Paolo Bonzini , Stefan Hajnoczi Cc: Kevin Wolf , Ming Lei , Fam Zheng , "Michael S. Tsirkin" 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 --- hw/block/dataplane/virtio-blk.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index e88862d..d65e022 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,13 +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, + vring_push(&s->vring, &req->elem, req->qiov.size + sizeof(*req->in)); - notify_guest(req->dev->dataplane); + + /* 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) @@ -172,6 +188,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); @@ -190,6 +207,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