From patchwork Sun Jan 31 10:29:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8173301 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BAF7C9F96D for ; Sun, 31 Jan 2016 10:34:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 05957202FE for ; Sun, 31 Jan 2016 10:34:04 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 4FAB1202F0 for ; Sun, 31 Jan 2016 10:34:03 +0000 (UTC) Received: from localhost ([::1]:41141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpKU-0006ud-P0 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 31 Jan 2016 05:34:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpFw-0007Ur-Os for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aPpFv-0007nV-Ge for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:20 -0500 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:35192) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpFv-0007nP-9K for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:19 -0500 Received: by mail-wm0-x244.google.com with SMTP id l66so4656434wml.2 for ; Sun, 31 Jan 2016 02:29:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=/U41skETtJveqLYbWa4jOvoTJMop7ZH2yYtmeXjFSHo=; b=bt2Mu+tsHsnUghMy9meVOilukNVkwacw/q/UXu9GrzZ/onst+k5hamiJ2DLWknTaSA iS55R/UagTb+m/aqUrDsYZJu7TS83qJ99fgldVEoHAWlDEhbtU21Aa8kFI9GFYcFu2qr xCUpwQPswOgvM3BmDcgiEMTgPUC4QFS+jLNWquTWUJrpb1K8jrwP0BABEjOqbVpqlOj3 8NdlnQIQ+SxmpEZu4w61RtaMA4kOp59sE9bpqjvaQ3HHgizLB+LD+mDEn6sfxVYv4oq9 klaFyATrz1aba5Lj941Lg8SCIEWffnmLAeCQEARA8fjxMvRwl27fISGo152QpwNzYNuu UlAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=/U41skETtJveqLYbWa4jOvoTJMop7ZH2yYtmeXjFSHo=; b=aupfC9cH11qbdhWdShIIOoQXJPriAy0pPTYLg21VZgByqN1HBisLMEtpBbUfLNu725 I1q6c6aOCP/v5obBvIZaLUHVeaNcfbusU4989HP/rUWkKOKoGP+ejb7JSOneaYuJkiZ4 moIsAFUSNr2lt68SF+571TguOeQeMnpBG8OOL7Yt84aLtAFntMl24HMyPCEANpssPOh8 pmMYDVY1OD7Zw+96gb1C8tVC8ENNjN777IJgOIEdkQxpqUvJIlc+KbokjnikekXSY/vg F/JQwCPszzQk/oJWAi2/7hpnVkdPx1lcjtJiy+GpYWt3wYJ5gyPEOQQzDAcpv2Zig312 3fQg== X-Gm-Message-State: AG10YOTlhFw9W7j9xLYLE3SBzX4fSHNqtQg6FfYY3Ioyf3tPRq+mzIFaQLlsh6DimStoUA== X-Received: by 10.28.228.87 with SMTP id b84mr5951461wmh.81.1454236158776; Sun, 31 Jan 2016 02:29:18 -0800 (PST) Received: from donizetti.fosdem.net ([2001:67c:1810:f051:7105:9465:633c:859]) by smtp.gmail.com with ESMTPSA id i79sm2349430wmf.24.2016.01.31.02.29.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Jan 2016 02:29:17 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 31 Jan 2016 11:29:04 +0100 Message-Id: <1454236146-23293-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454236146-23293-1-git-send-email-pbonzini@redhat.com> References: <1454236146-23293-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Cc: cornelia.huck@de.ibm.com, Vincenzo Maffione , mst@redhat.com Subject: [Qemu-devel] [PATCH 08/10] virtio: cache used_idx in a VirtQueue field 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Vincenzo Maffione Accessing used_idx in the VQ requires an expensive access to guest physical memory. Before this patch, 3 accesses are normally done for each pop/push/notify call. However, since the used_idx is only written by us, we can track it in our internal data structure. Signed-off-by: Vincenzo Maffione Message-Id: <3d062ec54e9a7bf9fb325c1fd693564951f2b319.1450218353.git.v.maffione@gmail.com> Reviewed-by: Cornelia Huck Signed-off-by: Paolo Bonzini --- hw/virtio/virtio.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 2433866..5116a2e 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -71,6 +71,9 @@ struct VirtQueue { VRing vring; uint16_t last_avail_idx; + + uint16_t used_idx; + /* Last used index value we have signalled on */ uint16_t signalled_used; @@ -170,6 +173,7 @@ static inline void vring_used_idx_set(VirtQueue *vq, uint16_t val) hwaddr pa; pa = vq->vring.used + offsetof(VRingUsed, idx); virtio_stw_phys(vq->vdev, pa, val); + vq->used_idx = val; } static inline void vring_used_flags_set_bit(VirtQueue *vq, int mask) @@ -261,7 +265,7 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, virtqueue_unmap_sg(vq, elem, len); - idx = (idx + vring_used_idx(vq)) % vq->vring.num; + idx = (idx + vq->used_idx) % vq->vring.num; /* Get a pointer to the next entry in the used ring. */ vring_used_ring_id(vq, idx, elem->index); @@ -274,7 +278,7 @@ void virtqueue_flush(VirtQueue *vq, unsigned int count) /* Make sure buffer is written before we update index. */ smp_wmb(); trace_virtqueue_flush(vq, count); - old = vring_used_idx(vq); + old = vq->used_idx; new = old + count; vring_used_idx_set(vq, new); vq->inuse -= count; @@ -782,6 +786,7 @@ void virtio_reset(void *opaque) vdev->vq[i].vring.avail = 0; vdev->vq[i].vring.used = 0; vdev->vq[i].last_avail_idx = 0; + vdev->vq[i].used_idx = 0; virtio_queue_set_vector(vdev, i, VIRTIO_NO_VECTOR); vdev->vq[i].signalled_used = 0; vdev->vq[i].signalled_used_valid = false; @@ -1161,7 +1166,7 @@ static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq) v = vq->signalled_used_valid; vq->signalled_used_valid = true; old = vq->signalled_used; - new = vq->signalled_used = vring_used_idx(vq); + new = vq->signalled_used = vq->used_idx; return !v || vring_need_event(vring_get_used_event(vq), new, old); } @@ -1573,6 +1578,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) vdev->vq[i].last_avail_idx, nheads); return -1; } + vdev->vq[i].used_idx = vring_used_idx(&vdev->vq[i]); } }