From patchwork Thu Sep 8 08:34:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 9321047 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 C5D9E60752 for ; Thu, 8 Sep 2016 11:31:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9B06297E3 for ; Thu, 8 Sep 2016 11:31:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA209297EC; Thu, 8 Sep 2016 11:31:11 +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 5FCC8297DA for ; Thu, 8 Sep 2016 11:31:09 +0000 (UTC) Received: from localhost ([::1]:47298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhxXw-00081M-79 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 08 Sep 2016 07:31:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhumt-0001rJ-QP for qemu-devel@nongnu.org; Thu, 08 Sep 2016 04:34:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhums-0005UM-Fa for qemu-devel@nongnu.org; Thu, 08 Sep 2016 04:34:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27158) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhums-0005U2-7D for qemu-devel@nongnu.org; Thu, 08 Sep 2016 04:34:22 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 CE0458A4D4; Thu, 8 Sep 2016 08:34:21 +0000 (UTC) Received: from max-t460s.redhat.com (vpn1-4-117.ams2.redhat.com [10.36.4.117]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u888YCc4013403; Thu, 8 Sep 2016 04:34:19 -0400 From: Maxime Coquelin To: mst@redhat.com, qemu-devel@nongnu.org Date: Thu, 8 Sep 2016 10:34:10 +0200 Message-Id: <1473323650-13298-3-git-send-email-maxime.coquelin@redhat.com> In-Reply-To: <1473323650-13298-1-git-send-email-maxime.coquelin@redhat.com> References: <1473323650-13298-1-git-send-email-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 08 Sep 2016 08:34:21 +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 2/2] vhost-user: only seek a reply if needed in set_mem_table 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: peter.maydell@linaro.org, marcandre.lureau@redhat.com, Maxime Coquelin , prerna.saxena@nutanix.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The goal of this patch is to only request a sync (reply_ack, or get_features) in set_mem_table only when necessary. It should not be necessary the first time we set the table, or when we add a new regions which hadn't been merged with an existing ones. Suggested-by: Michael S. Tsirkin Cc: Prerna Saxena Cc: Marc-André Lureau Signed-off-by: Maxime Coquelin --- hw/virtio/vhost-user.c | 7 +++++++ hw/virtio/vhost.c | 10 ++++++++++ include/hw/virtio/vhost.h | 1 + 3 files changed, 18 insertions(+) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 1a7d53c..ca41728 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -531,6 +531,11 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev, vhost_user_write(dev, &msg, fds, fd_num); + if (!dev->mem_changed_req_sync) { + /* The update only add regions, skip the sync */ + return 0; + } + if (reply_supported) { return process_message_reply(dev, msg.request); } else { @@ -541,6 +546,8 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev, vhost_user_get_features(dev, &features); } + dev->mem_changed_req_sync = false; + return 0; } diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 3d0c807..e653067 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -303,7 +303,11 @@ static void vhost_dev_assign_memory(struct vhost_dev *dev, reg->guest_phys_addr = start_addr; reg->userspace_addr = uaddr; ++to; + } else { + /* Existing mapping updated, sync is required */ + dev->mem_changed_req_sync = true; } + assert(to <= dev->mem->nregions + 1); dev->mem->nregions = to; } @@ -533,6 +537,7 @@ static void vhost_set_memory(MemoryListener *listener, } else { /* Remove old mapping for this memory, if any. */ vhost_dev_unassign_memory(dev, start_addr, size); + dev->mem_changed_req_sync = true; } dev->mem_changed_start_addr = MIN(dev->mem_changed_start_addr, start_addr); dev->mem_changed_end_addr = MAX(dev->mem_changed_end_addr, start_addr + size - 1); @@ -1126,6 +1131,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, hdev->log_enabled = false; hdev->started = false; hdev->memory_changed = false; + hdev->mem_changed_req_sync = false; memory_listener_register(&hdev->memory_listener, &address_space_memory); QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); return 0; @@ -1301,6 +1307,10 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev) if (r < 0) { goto fail_features; } + + /* First time the mem table is set, skip sync for completion */ + hdev->mem_changed_req_sync = false; + r = hdev->vhost_ops->vhost_set_mem_table(hdev, hdev->mem); if (r < 0) { VHOST_OPS_DEBUG("vhost_set_mem_table failed"); diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index e433089..4bbf36a 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -55,6 +55,7 @@ struct vhost_dev { uint64_t log_size; Error *migration_blocker; bool memory_changed; + bool mem_changed_req_sync; hwaddr mem_changed_start_addr; hwaddr mem_changed_end_addr; const VhostOps *vhost_ops;