From patchwork Tue Mar 16 12:41:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 89229 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 594EEA054F; Tue, 16 Mar 2021 13:42:22 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5004F242909; Tue, 16 Mar 2021 13:42:12 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 013E22428EF for ; Tue, 16 Mar 2021 13:42:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615898530; 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=SORgBwzO5XSKRnZ/uvTm8/1/oZxWv0M55W4ReM43xWA=; b=PN9I7NRSW7KR2rBsrHdMpMFT8t3ArXZb2nNL4bKSIqzrQy6jBZT33tNStJbZOcIIob0Y51 PAOFyUa0qO9oiMWFykguxmTBJgjGJlLpZ9Pn7ko56wZdokdlIJGdEayvL/ebf1xCE8ZLf/ q/qqv3HLYPuM5qtnO9q8so5TyfqDgxg= 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-521-QE6pNEIlPKGpI_1xuX2fSw-1; Tue, 16 Mar 2021 08:42:06 -0400 X-MC-Unique: QE6pNEIlPKGpI_1xuX2fSw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E437835B7E; Tue, 16 Mar 2021 12:42:05 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id C098B5B4A8; Tue, 16 Mar 2021 12:42:03 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, amorenoz@redhat.com, david.marchand@redhat.com, olivier.matz@6wind.com, bnemeth@redhat.com Cc: Maxime Coquelin Date: Tue, 16 Mar 2021 13:41:51 +0100 Message-Id: <20210316124153.503928-2-maxime.coquelin@redhat.com> In-Reply-To: <20210316124153.503928-1-maxime.coquelin@redhat.com> References: <20210316124153.503928-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 Subject: [dpdk-dev] [PATCH v2 1/3] vhost: remove unused Vhost virtqueue field X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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 removes the "backend" field of the vhost_virtqueue struct, which is not used by the library. Signed-off-by: Maxime Coquelin Reviewed-by: Chenbo Xia --- lib/librte_vhost/vhost.c | 2 -- lib/librte_vhost/vhost.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 52ab93d1ec..5a7c0c6cff 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -558,8 +558,6 @@ init_vring_queue(struct virtio_net *dev, uint32_t vring_idx) vq->notif_enable = VIRTIO_UNINITIALIZED_NOTIF; vhost_user_iotlb_init(dev, vring_idx); - /* Backends are set to -1 indicating an inactive device. */ - vq->backend = -1; } static void diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 658f6fc287..717f410548 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -143,8 +143,6 @@ struct vhost_virtqueue { #define VIRTIO_INVALID_EVENTFD (-1) #define VIRTIO_UNINITIALIZED_EVENTFD (-2) - /* Backend value to determine if device should started/stopped */ - int backend; int enabled; int access_ok; int ready; From patchwork Tue Mar 16 12:41:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 89230 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A4B2FA054F; Tue, 16 Mar 2021 13:42:28 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7F856242917; Tue, 16 Mar 2021 13:42:14 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mails.dpdk.org (Postfix) with ESMTP id A3BE924290F for ; Tue, 16 Mar 2021 13:42:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615898532; 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=8PQt1jw8sowMmCCKta8A2nFsggQwrhVnXWlzCTYnVd4=; b=IDADIzDKxguEBAdU2SVXc45CASzrx0TCeldu112p+pisy7fpL9jZ6HmK7jLPhYGI94y1/x bU/eLFx75CCk+c8uFC0pKq1yhySVVmibsB4GOXxGF5dEd4WTdWUejIbZ1xu845oHQ9Jgu5 t/7Jku7zi1eSFuFUmj8RbhHRTQyQr70= 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-576-kmI2qcMBNwqiU2C21j1GjQ-1; Tue, 16 Mar 2021 08:42:08 -0400 X-MC-Unique: kmI2qcMBNwqiU2C21j1GjQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C17E61934102; Tue, 16 Mar 2021 12:42:07 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAEE050FBF; Tue, 16 Mar 2021 12:42:05 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, amorenoz@redhat.com, david.marchand@redhat.com, olivier.matz@6wind.com, bnemeth@redhat.com Cc: Maxime Coquelin Date: Tue, 16 Mar 2021 13:41:52 +0100 Message-Id: <20210316124153.503928-3-maxime.coquelin@redhat.com> In-Reply-To: <20210316124153.503928-1-maxime.coquelin@redhat.com> References: <20210316124153.503928-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 Subject: [dpdk-dev] [PATCH v2 2/3] vhost: move dirty logging cache out of the virtqueue X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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 | 14 ++++++++++++++ lib/librte_vhost/vhost.h | 2 +- lib/librte_vhost/vhost_user.c | 25 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 5a7c0c6cff..c3490ce897 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -145,6 +145,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_atomic_thread_fence(__ATOMIC_RELEASE); log_base = (unsigned long *)(uintptr_t)dev->log_base; @@ -177,6 +181,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; @@ -354,6 +366,8 @@ free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq) } rte_free(vq->batch_copy_elems); rte_mempool_free(vq->iotlb_pool); + if (vq->log_cache) + rte_free(vq->log_cache); rte_free(vq); } diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 717f410548..3a71dfeed9 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 a60bb945ad..0f452d6ff3 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -2022,6 +2022,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; @@ -2121,6 +2126,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; @@ -2174,6 +2180,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. From patchwork Tue Mar 16 12:41:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 89231 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 69DEEA054F; Tue, 16 Mar 2021 13:42:35 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A93EA242921; Tue, 16 Mar 2021 13:42:16 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 4B6BB24291D for ; Tue, 16 Mar 2021 13:42:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615898534; 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=gHbfSw/nXWDU3P3qL1HOO/9bKMN68IzAVsUZjlwWeYM=; b=P0LQ4HG8jw/Naj1Tdh1EylqVKVFVB5fvCmDC3JemonSogLw5LLm2ge42duLvuwx/LOizp+ r/3fBGlsNIv4JyPeICYZihIGEEAJKN0wgFyxnQUCnmBU5SnZJ1SkXSLQbeiondN1sjfv3H FsLXLinwBPky2cP06WmqGMci4oOnCiM= 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-547-E21Ghv2vPS2mlVZYy4sOsw-1; Tue, 16 Mar 2021 08:42:11 -0400 X-MC-Unique: E21Ghv2vPS2mlVZYy4sOsw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CD3DD835BCC; Tue, 16 Mar 2021 12:42:09 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A14419CAD; Tue, 16 Mar 2021 12:42:07 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, amorenoz@redhat.com, david.marchand@redhat.com, olivier.matz@6wind.com, bnemeth@redhat.com Cc: Maxime Coquelin Date: Tue, 16 Mar 2021 13:41:53 +0100 Message-Id: <20210316124153.503928-4-maxime.coquelin@redhat.com> In-Reply-To: <20210316124153.503928-1-maxime.coquelin@redhat.com> References: <20210316124153.503928-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 Subject: [dpdk-dev] [PATCH v2 3/3] vhost: optimize vhost virtqueue struct X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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 vhost_virtuqueue struct fields in order to both optimize packing and move hot fields on the first cachelines. Signed-off-by: Maxime Coquelin --- lib/librte_vhost/vhost.h | 52 +++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 3a71dfeed9..ae45b05dd1 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -133,7 +133,7 @@ struct vhost_virtqueue { struct vring_used *used; struct vring_packed_desc_event *device_event; }; - uint32_t size; + uint16_t size; uint16_t last_avail_idx; uint16_t last_used_idx; @@ -143,29 +143,12 @@ struct vhost_virtqueue { #define VIRTIO_INVALID_EVENTFD (-1) #define VIRTIO_UNINITIALIZED_EVENTFD (-2) - int enabled; - int access_ok; - int ready; - int notif_enable; -#define VIRTIO_UNINITIALIZED_NOTIF (-1) + bool enabled; + bool access_ok; + bool ready; rte_spinlock_t access_lock; - /* Used to notify the guest (trigger interrupt) */ - int callfd; - /* Currently unused as polling mode is enabled */ - int kickfd; - - /* Physical address of used ring, for logging */ - uint64_t log_guest_addr; - - /* inflight share memory info */ - union { - struct rte_vhost_inflight_info_split *inflight_split; - struct rte_vhost_inflight_info_packed *inflight_packed; - }; - struct rte_vhost_resubmit_info *resubmit_inflight; - uint64_t global_counter; union { struct vring_used_elem *shadow_used_split; @@ -176,22 +159,36 @@ struct vhost_virtqueue { uint16_t shadow_aligned_idx; /* Record packed ring first dequeue desc index */ uint16_t shadow_last_used_idx; - struct vhost_vring_addr ring_addrs; - struct batch_copy_elem *batch_copy_elems; uint16_t batch_copy_nb_elems; + struct batch_copy_elem *batch_copy_elems; bool used_wrap_counter; bool avail_wrap_counter; - struct log_cache_entry *log_cache; + /* Physical address of used ring, for logging */ uint16_t log_cache_nb_elem; + uint64_t log_guest_addr; + struct log_cache_entry *log_cache; rte_rwlock_t iotlb_lock; rte_rwlock_t iotlb_pending_lock; struct rte_mempool *iotlb_pool; TAILQ_HEAD(, vhost_iotlb_entry) iotlb_list; - int iotlb_cache_nr; TAILQ_HEAD(, vhost_iotlb_entry) iotlb_pending_list; + int iotlb_cache_nr; + + /* Used to notify the guest (trigger interrupt) */ + int callfd; + /* Currently unused as polling mode is enabled */ + int kickfd; + + /* inflight share memory info */ + union { + struct rte_vhost_inflight_info_split *inflight_split; + struct rte_vhost_inflight_info_packed *inflight_packed; + }; + struct rte_vhost_resubmit_info *resubmit_inflight; + uint64_t global_counter; /* operation callbacks for async dma */ struct rte_vhost_async_channel_ops async_ops; @@ -212,6 +209,11 @@ struct vhost_virtqueue { bool async_inorder; bool async_registered; uint16_t async_threshold; + + int notif_enable; +#define VIRTIO_UNINITIALIZED_NOTIF (-1) + + struct vhost_vring_addr ring_addrs; } __rte_cache_aligned; /* Virtio device status as per Virtio specification */