From patchwork Sun Jan 31 10:29:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8173281 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 126FBBEEE5 for ; Sun, 31 Jan 2016 10:32:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 57DAD202FE for ; Sun, 31 Jan 2016 10:32:52 +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 A43C8202F0 for ; Sun, 31 Jan 2016 10:32:51 +0000 (UTC) Received: from localhost ([::1]:41129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpJL-0004w6-2m for patchwork-qemu-devel@patchwork.kernel.org; Sun, 31 Jan 2016 05:32:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpFx-0007XZ-Vn for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aPpFx-0007o7-1S for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:21 -0500 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aPpFw-0007nz-Rf for qemu-devel@nongnu.org; Sun, 31 Jan 2016 05:29:20 -0500 Received: by mail-wm0-x242.google.com with SMTP id p63so4658695wmp.1 for ; Sun, 31 Jan 2016 02:29:20 -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=XlL9ybJgVyTkgKZflwCmulCalnxmwEFyi2bu3KYhfvc=; b=I1spbVYBgZU21jn4dSRAZ89kGegQ+qT+p//haMULDHT0CF6tdOdq+sbRX7dKZb4mkN vGr77SPtWvU7hCqduPcjzyn1jtrO4Muvdau1DupBsS1URxls9uJIjvt5G/ointEDx9PX /3VClQRQ6gv6UrBM14+XSXbi+LZcNa8bF6SyiMaD50c5EgqTt6PE6RqnCajKGeSU7Q1d kpTqSxJrCxAnT8pDapdLgnpqRSY7iQetQc44U4sZXrgo0ga9j4xCACJoc8Dd0kJgoXAH i++UwF+wAFWAHC6lqF92aXPENU6JRzGMuAf3W2gbQAgUJMdce26FaqHP3HNDrBqZjsmA pgsA== 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=XlL9ybJgVyTkgKZflwCmulCalnxmwEFyi2bu3KYhfvc=; b=H5Y5GOBeYzlO46gcHkPQ7L0vz2kCiad3GvV0MVAKNWIL7rrNJWtr0otdWlYvpsqwN8 P+fg6nciaczvFTjw44FjXG4vwihZ0uQ47A+kQdo5OuIObN+BDOymL8tQMmJpn+hbMjhT a+OZMTLjphcfo/5yQDO89OooX8JteNSKO+/5CeQ50vLyXQyz2ZS+0iMveELl8j5HythW 8aI96ALpFD+dj8PujpEHM5rRe0CDs3nCiZFDmmPF0B+rl3FbmvrxsGl83BLxx8KOi6XY AzqnF3cjsegAZhZt90VIjh0TLfQBJlfy9QPjSachS71ZGubbEkiTpuJY0G8w7/+/VVH/ 69+Q== X-Gm-Message-State: AG10YORb5ZWhcA3rHEN51OMay+0/XIUHkHPnSgE30y55izpiVYJENfWssgux/JgLExYA0Q== X-Received: by 10.28.6.213 with SMTP id 204mr6072703wmg.47.1454236160337; Sun, 31 Jan 2016 02:29:20 -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.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Jan 2016 02:29:19 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 31 Jan 2016 11:29:06 +0100 Message-Id: <1454236146-23293-11-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::242 Cc: cornelia.huck@de.ibm.com, Vincenzo Maffione , mst@redhat.com Subject: [Qemu-devel] [PATCH 10/10] virtio: combine write of an entry into used ring 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 Fill in an element of the used ring with a single combined access to the guest physical memory, rather than using two separated accesses. This reduces the overhead due to expensive address translation. Signed-off-by: Vincenzo Maffione Message-Id: Reviewed-by: Cornelia Huck Signed-off-by: Paolo Bonzini --- hw/virtio/virtio.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 6842938..241c7e3 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -153,18 +153,15 @@ static inline uint16_t vring_get_used_event(VirtQueue *vq) return vring_avail_ring(vq, vq->vring.num); } -static inline void vring_used_ring_id(VirtQueue *vq, int i, uint32_t val) +static inline void vring_used_write(VirtQueue *vq, VRingUsedElem *uelem, + int i) { hwaddr pa; - pa = vq->vring.used + offsetof(VRingUsed, ring[i].id); - virtio_stl_phys(vq->vdev, pa, val); -} - -static inline void vring_used_ring_len(VirtQueue *vq, int i, uint32_t val) -{ - hwaddr pa; - pa = vq->vring.used + offsetof(VRingUsed, ring[i].len); - virtio_stl_phys(vq->vdev, pa, val); + virtio_tswap32s(vq->vdev, &uelem->id); + virtio_tswap32s(vq->vdev, &uelem->len); + pa = vq->vring.used + offsetof(VRingUsed, ring[i]); + address_space_write(&address_space_memory, pa, MEMTXATTRS_UNSPECIFIED, + (void *)uelem, sizeof(VRingUsedElem)); } static uint16_t vring_used_idx(VirtQueue *vq) @@ -273,15 +270,17 @@ void virtqueue_discard(VirtQueue *vq, const VirtQueueElement *elem, void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem, unsigned int len, unsigned int idx) { + VRingUsedElem uelem; + trace_virtqueue_fill(vq, elem, len, idx); virtqueue_unmap_sg(vq, elem, len); 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); - vring_used_ring_len(vq, idx, len); + uelem.id = elem->index; + uelem.len = len; + vring_used_write(vq, &uelem, idx); } void virtqueue_flush(VirtQueue *vq, unsigned int count)