From patchwork Fri May 20 23:40:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9130231 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1CD3760221 for ; Sat, 21 May 2016 00:00:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CF0627E3D for ; Sat, 21 May 2016 00:00:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2FD127F17; Sat, 21 May 2016 00:00:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9352827E3D for ; Sat, 21 May 2016 00:00:31 +0000 (UTC) Received: from localhost ([::1]:38218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3uLG-0004UE-MF for patchwork-qemu-devel@patchwork.kernel.org; Fri, 20 May 2016 20:00:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3u2k-00020k-VL for qemu-devel@nongnu.org; Fri, 20 May 2016 19:41:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3u2i-0006hu-Tr for qemu-devel@nongnu.org; Fri, 20 May 2016 19:41:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57162) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3u2i-0006hX-LH for qemu-devel@nongnu.org; Fri, 20 May 2016 19:41:20 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 36C29341454; Fri, 20 May 2016 23:41:20 +0000 (UTC) Received: from localhost (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4KNfHeL028124; Fri, 20 May 2016 19:41:19 -0400 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Fri, 20 May 2016 16:40:28 -0700 Message-Id: <1463787632-7241-6-git-send-email-stefanha@redhat.com> In-Reply-To: <1463787632-7241-1-git-send-email-stefanha@redhat.com> References: <1463787632-7241-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 20 May 2016 23:41:20 +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 5/9] 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 , Paolo Bonzini , Ming Lei , Fam Zheng , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The batch notification BH needs to know which virtqueues to notify when multiqueue is enabled. Use a bitmap to track the virtqueues that with pending notifications. Signed-off-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 20 ++++++++++++++++---- include/hw/virtio/virtio-blk.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index d16a1b7..ab0f589 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -54,11 +54,19 @@ static void virtio_blk_batch_notify_bh(void *opaque) { VirtIOBlock *s = opaque; VirtIODevice *vdev = VIRTIO_DEVICE(s); + unsigned nvqs = s->conf.num_queues; + unsigned i = 0; - if (s->dataplane_started && !s->dataplane_disabled) { - virtio_blk_data_plane_notify(s->dataplane, s->vq); - } else { - virtio_notify(vdev, s->vq); + while ((i = find_next_bit(s->batch_notify_vqs, nvqs, i)) < nvqs) { + VirtQueue *vq = virtio_get_queue(vdev, i); + + bitmap_clear(s->batch_notify_vqs, i, 1); + + if (s->dataplane_started && !s->dataplane_disabled) { + virtio_blk_data_plane_notify(s->dataplane, vq); + } else { + virtio_notify(vdev, vq); + } } } @@ -77,6 +85,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); + + bitmap_set(s->batch_notify_vqs, virtio_queue_get_id(req->vq), 1); qemu_bh_schedule(s->batch_notify_bh); } @@ -922,6 +932,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp) s->batch_notify_bh = aio_bh_new(blk_get_aio_context(s->blk), virtio_blk_batch_notify_bh, s); + s->batch_notify_vqs = bitmap_new(conf->num_queues); s->change = qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s); register_savevm(dev, "virtio-blk", virtio_blk_id++, 2, @@ -938,6 +949,7 @@ static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp) VirtIOBlock *s = VIRTIO_BLK(dev); qemu_bh_delete(s->batch_notify_bh); + 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;