From patchwork Tue May 31 01:26:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 627979 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rJbTZ42rzz9sBG for ; Tue, 31 May 2016 11:28:02 +1000 (AEST) Received: from localhost ([::1]:33895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7YTQ-0002jG-IH for incoming@patchwork.ozlabs.org; Mon, 30 May 2016 21:28:00 -0400 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 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78FE2811DF; Tue, 31 May 2016 01:26:32 +0000 (UTC) Received: from localhost (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4V1QTsr001105; Mon, 30 May 2016 21:26:31 -0400 From: Stefan Hajnoczi To: qemu-devel@nongnu.org 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> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 31 May 2016 01:26:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 5/8] virtio-blk: multiqueue batch notify X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Stefan Hajnoczi , Ming Lei , Christian Borntraeger , Roman Pen , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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;