From patchwork Sat Jul 12 04:08:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 369274 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 B47A9140115 for ; Sat, 12 Jul 2014 14:11:00 +1000 (EST) Received: from localhost ([::1]:47648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5oeI-00015Q-NJ for incoming@patchwork.ozlabs.org; Sat, 12 Jul 2014 00:10:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5ocw-0007ip-M7 for qemu-devel@nongnu.org; Sat, 12 Jul 2014 00:09:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X5ocq-0008Gm-GY for qemu-devel@nongnu.org; Sat, 12 Jul 2014 00:09:34 -0400 Received: from mail-pd0-f180.google.com ([209.85.192.180]:56277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5ocq-0008Gd-AS for qemu-devel@nongnu.org; Sat, 12 Jul 2014 00:09:28 -0400 Received: by mail-pd0-f180.google.com with SMTP id y13so142010pdi.11 for ; Fri, 11 Jul 2014 21:09:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=455O3nc2IBy5vfXomd+4hHDRcmi4cmzRxODqN9b/8tQ=; b=T5w7y0ZgPBXnEzkyQRG99g4F8AigYvC38YBunCFY+WlZjtlyW9VszyQTMwUEzMhmIy ct7E5+VulbH8h/TfArdqkrETbJAk3s+Mph+o9ZUXCcwfcsY5RTtf+yIVe/hkhysgjYod 6olkoUnOYXMvrQcvSMSpcg8g+c23kFq+hs3RA0Apxzn+P2WJctaa7roh4j38bnLTwFKL NwwqEYoeVhf/AkpKUVYJpDWqG/TFzOAiWq5rY7jNPb0VinX4UZ/I6x2k9UjQrL3m4o45 GKcQyWNU7yZqwiP+A8X7bRNMi17d7Rrl5kts7Nv2ed6bTu9RNwk6Y0ssES++iKyYHUPi cung== X-Received: by 10.70.35.45 with SMTP id e13mr2929773pdj.81.1405138167778; Fri, 11 Jul 2014 21:09:27 -0700 (PDT) Received: from localhost ([121.15.171.107]) by mx.google.com with ESMTPSA id vr9sm16593982pab.6.2014.07.11.21.09.21 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 11 Jul 2014 21:09:26 -0700 (PDT) From: Ming Lei To: qemu-devel@nongnu.org, Paolo Bonzini , Stefan Hajnoczi Date: Sat, 12 Jul 2014 12:08:53 +0800 Message-Id: <1405138133-27045-3-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1405138133-27045-1-git-send-email-ming.lei@canonical.com> References: <1405138133-27045-1-git-send-email-ming.lei@canonical.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.180 Cc: Kevin Wolf , Ming Lei , Ming Lei , Fam Zheng , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH v1 resend 2/2] virtio-blk: dataplane: notify guest as a batch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Ming Lei 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 | 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); }