From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8D8EFA052A; Tue, 22 Dec 2020 14:58:05 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3E12DCAAF; Tue, 22 Dec 2020 14:57:17 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by dpdk.org (Postfix) with ESMTP id 04B59CA68 for ; Tue, 22 Dec 2020 14:57:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608645432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eglID2G+/axcWJYp+9zS8/f6fU0qZsYDK3Av2TPU3kM=; b=CEW4LTFAspNUF6pGfcY6bLNg2CDw5oqPnFQrSQLQpDZKANVhvw2IdkPHQD9PH9nswYpAEK moqtlWxryBYtyAm26FQvWNxq3L2fok9kGQl3omUJNHizWDXRZzT670OEOln+dIlKmQUUnO uQsI0dlagAWbH1cyPsxmQvv9NBluq8Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-246-l9kQ59B8Py6vP7hq7C0l-Q-1; Tue, 22 Dec 2020 08:57:08 -0500 X-MC-Unique: l9kQ59B8Py6vP7hq7C0l-Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E592E107ACE8; Tue, 22 Dec 2020 13:57:07 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id C322D6F985; Tue, 22 Dec 2020 13:57:06 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, amorenoz@redhat.com Cc: Maxime Coquelin Date: Tue, 22 Dec 2020 14:56:57 +0100 Message-Id: <20201222135658.53916-3-maxime.coquelin@redhat.com> In-Reply-To: <20201222135658.53916-1-maxime.coquelin@redhat.com> References: <20201222135658.53916-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH 2/3] vhost: move dirty logging cache out of the virtqueue X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch moves the per-virtqueue's dirty logging cache out of the virtqueue struct, by allocating it dynamically only when live-migration is enabled. It saves 8 cachelines in vhost_virtqueue struct. Signed-off-by: Maxime Coquelin --- lib/librte_vhost/vhost.c | 12 ++++++++++++ lib/librte_vhost/vhost.h | 2 +- lib/librte_vhost/vhost_user.c | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 4e5df862aa..ec6459b2d1 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -144,6 +144,10 @@ __vhost_log_cache_sync(struct virtio_net *dev, struct vhost_virtqueue *vq) if (unlikely(!dev->log_base)) return; + /* No cache, nothing to sync */ + if (unlikely(!vq->log_cache)) + return; + rte_smp_wmb(); log_base = (unsigned long *)(uintptr_t)dev->log_base; @@ -176,6 +180,14 @@ vhost_log_cache_page(struct virtio_net *dev, struct vhost_virtqueue *vq, uint32_t offset = page / (sizeof(unsigned long) << 3); int i; + if (unlikely(!vq->log_cache)) { + /* No logging cache allocated, write dirty log map directly */ + rte_smp_wmb(); + vhost_log_page((uint8_t *)(uintptr_t)dev->log_base, page); + + return; + } + for (i = 0; i < vq->log_cache_nb_elem; i++) { struct log_cache_entry *elem = vq->log_cache + i; diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index d132e4ae54..e2f14034b4 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -183,7 +183,7 @@ struct vhost_virtqueue { bool used_wrap_counter; bool avail_wrap_counter; - struct log_cache_entry log_cache[VHOST_LOG_CACHE_NR]; + struct log_cache_entry *log_cache; uint16_t log_cache_nb_elem; rte_rwlock_t iotlb_lock; diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 45c8ac09da..7ac3963a07 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -1978,6 +1978,11 @@ vhost_user_get_vring_base(struct virtio_net **pdev, rte_free(vq->batch_copy_elems); vq->batch_copy_elems = NULL; + if (vq->log_cache) { + rte_free(vq->log_cache); + vq->log_cache = NULL; + } + msg->size = sizeof(msg->payload.state); msg->fd_num = 0; @@ -2077,6 +2082,7 @@ vhost_user_set_log_base(struct virtio_net **pdev, struct VhostUserMsg *msg, int fd = msg->fds[0]; uint64_t size, off; void *addr; + uint32_t i; if (validate_msg_fds(msg, 1) != 0) return RTE_VHOST_MSG_RESULT_ERR; @@ -2130,6 +2136,25 @@ vhost_user_set_log_base(struct virtio_net **pdev, struct VhostUserMsg *msg, dev->log_base = dev->log_addr + off; dev->log_size = size; + for (i = 0; i < dev->nr_vring; i++) { + struct vhost_virtqueue *vq = dev->virtqueue[i]; + + if (vq->log_cache) { + rte_free(vq->log_cache); + vq->log_cache = NULL; + } + vq->log_cache_nb_elem = 0; + vq->log_cache = rte_zmalloc("vq log cache", + sizeof(struct log_cache_entry) * VHOST_LOG_CACHE_NR, + 0); + /* + * If log cache alloc fail, don't fail migration, but no + * caching will be done, which will impact performance + */ + if (!vq->log_cache) + VHOST_LOG_CONFIG(ERR, "Failed to allocate VQ logging cache\n"); + } + /* * The spec is not clear about it (yet), but QEMU doesn't expect * any payload in the reply. -- 2.29.2