From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7YS5-0001Sj-La for qemu-devel@nongnu.org; Mon, 30 May 2016 21:26:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b7YS1-0002UY-EI for qemu-devel@nongnu.org; Mon, 30 May 2016 21:26:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52861) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7YS1-0002UT-5t for qemu-devel@nongnu.org; Mon, 30 May 2016 21:26:33 -0400 From: Stefan Hajnoczi Date: Mon, 30 May 2016 18:26:03 -0700 Message-Id: <1464657966-26186-6-git-send-email-stefanha@redhat.com> In-Reply-To: <1464657966-26186-1-git-send-email-stefanha@redhat.com> References: <1464657966-26186-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH v2 5/8] virtio-blk: multiqueue batch notify List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Roman Pen , Fam Zheng , Christian Borntraeger , Paolo Bonzini , Ming Lei , Stefan Hajnoczi The batch notification BH needs to know which virtqueues to notify when multiqueue is enabled. Use a bitmap to track the virtqueues with pending notifications. Signed-off-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 29 +++++++++++++++++++++++++---- include/hw/virtio/virtio-blk.h | 1 + 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index c8d66f0..9de749b 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -54,11 +54,28 @@ static void virtio_blk_batch_notify_bh(void *opaque) { VirtIOBlock *s = opaque; VirtIODevice *vdev = VIRTIO_DEVICE(s); + unsigned nvqs = s->conf.num_queues; + unsigned long bitmap[BITS_TO_LONGS(nvqs)]; + unsigned j; - if (s->dataplane_started && !s->dataplane_disabled) { - virtio_blk_data_plane_notify(s->dataplane, s->vq); - } else { - virtio_notify(vdev, s->vq); + memcpy(bitmap, s->batch_notify_vqs, sizeof(bitmap)); + memset(s->batch_notify_vqs, 0, sizeof(bitmap)); + + for (j = 0; j < nvqs; j += BITS_PER_LONG) { + unsigned long bits = bitmap[j]; + + while (bits != 0) { + unsigned i = j + ctzl(bits); + VirtQueue *vq = virtio_get_queue(vdev, i); + + if (s->dataplane_started && !s->dataplane_disabled) { + virtio_blk_data_plane_notify(s->dataplane, vq); + } else { + virtio_notify(vdev, vq); + } + + bits &= bits - 1; /* clear right-most bit */ + } } } @@ -97,6 +114,8 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status) stb_p(&req->in->status, status); virtqueue_push(req->vq, &req->elem, req->in_len); + + set_bit(virtio_queue_get_id(req->vq), s->batch_notify_vqs); qemu_bh_schedule(s->batch_notify_bh); } @@ -940,6 +959,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) return; } + s->batch_notify_vqs = bitmap_new(conf->num_queues); blk_add_aio_context_notifier(s->blk, virtio_blk_attached_aio_context, virtio_blk_detach_aio_context, s); virtio_blk_attached_aio_context(blk_get_aio_context(s->blk), s); @@ -961,6 +981,7 @@ static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp) blk_remove_aio_context_notifier(s->blk, virtio_blk_attached_aio_context, virtio_blk_detach_aio_context, s); virtio_blk_detach_aio_context(s); + g_free(s->batch_notify_vqs); virtio_blk_data_plane_destroy(s->dataplane); s->dataplane = NULL; qemu_del_vm_change_state_handler(s->change); diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 487b28d..b6e7860 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -51,6 +51,7 @@ typedef struct VirtIOBlock { void *rq; QEMUBH *bh; QEMUBH *batch_notify_bh; + unsigned long *batch_notify_vqs; VirtIOBlkConf conf; unsigned short sector_mask; bool original_wce; -- 2.5.5