From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 04ED9A0562; Tue, 23 Mar 2021 10:02:59 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DF316140D22; Tue, 23 Mar 2021 10:02:58 +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 47798140D22 for ; Tue, 23 Mar 2021 10:02:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616490176; 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=T1sws2orpPeM6Ho61t5dgVDSTCx3uSrxVsyLpQ+vDnc=; b=QFJgwEI1M51GPItwZaalgly8tChXvCBpnOIdwKCdtdFCgMdVqy8/oBmGmRU/bTwroaNY33 81C+2KjMrdM3D73FC6I/K0+8Is1Jf3GVIGb56ls0HXaX98soN/zjW4I3aBHlOmEJLlXrvC 2rTcmE9At3/ZNj+KcAgVFF7j+qnVlEY= 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-35-9zypQz15N3KTsjrjuWW33A-1; Tue, 23 Mar 2021 05:02:52 -0400 X-MC-Unique: 9zypQz15N3KTsjrjuWW33A-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 7FF5F1009446; Tue, 23 Mar 2021 09:02:51 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id F27216C354; Tue, 23 Mar 2021 09:02:40 +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, 23 Mar 2021 10:02:19 +0100 Message-Id: <20210323090219.126712-4-maxime.coquelin@redhat.com> In-Reply-To: <20210323090219.126712-1-maxime.coquelin@redhat.com> References: <20210323090219.126712-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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH v4 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_virtqueue 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.c | 6 ++-- lib/librte_vhost/vhost.h | 54 ++++++++++++++++++----------------- lib/librte_vhost/vhost_user.c | 23 +++++++-------- lib/librte_vhost/virtio_net.c | 12 ++++---- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index a8032e3ba1..04d63b2f02 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -524,7 +524,7 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq) if (log_translate(dev, vq) < 0) return -1; - vq->access_ok = 1; + vq->access_ok = true; return 0; } @@ -535,7 +535,7 @@ vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq) if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) vhost_user_iotlb_wr_lock(vq); - vq->access_ok = 0; + vq->access_ok = false; vq->desc = NULL; vq->avail = NULL; vq->used = NULL; @@ -1451,7 +1451,7 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) rte_spinlock_lock(&vq->access_lock); - if (unlikely(vq->enabled == 0 || vq->avail == NULL)) + if (unlikely(!vq->enabled || vq->avail == NULL)) goto out; ret = *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx; diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 3a71dfeed9..f628714c24 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; - uint16_t log_cache_nb_elem; + /* 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 */ diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 4d9e76e49e..2f4f89aeac 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -406,6 +406,11 @@ vhost_user_set_vring_num(struct virtio_net **pdev, if (validate_msg_fds(msg, 0) != 0) return RTE_VHOST_MSG_RESULT_ERR; + if (msg->payload.state.num > 32768) { + VHOST_LOG_CONFIG(ERR, "invalid virtqueue size %u\n", msg->payload.state.num); + return RTE_VHOST_MSG_RESULT_ERR; + } + vq->size = msg->payload.state.num; /* VIRTIO 1.0, 2.4 Virtqueues says: @@ -425,12 +430,6 @@ vhost_user_set_vring_num(struct virtio_net **pdev, } } - if (vq->size > 32768) { - VHOST_LOG_CONFIG(ERR, - "invalid virtqueue size %u\n", vq->size); - return RTE_VHOST_MSG_RESULT_ERR; - } - if (vq_is_packed(dev)) { if (vq->shadow_used_packed) rte_free(vq->shadow_used_packed); @@ -713,7 +712,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) return dev; } - vq->access_ok = 1; + vq->access_ok = true; return dev; } @@ -771,7 +770,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) vq->last_avail_idx = vq->used->idx; } - vq->access_ok = 1; + vq->access_ok = true; VHOST_LOG_CONFIG(DEBUG, "(%d) mapped address desc: %p\n", dev->vid, vq->desc); @@ -1658,7 +1657,7 @@ vhost_user_set_vring_call(struct virtio_net **pdev, struct VhostUserMsg *msg, vq = dev->virtqueue[file.index]; if (vq->ready) { - vq->ready = 0; + vq->ready = false; vhost_user_notify_queue_state(dev, file.index, 0); } @@ -1918,14 +1917,14 @@ vhost_user_set_vring_kick(struct virtio_net **pdev, struct VhostUserMsg *msg, * the SET_VRING_ENABLE message. */ if (!(dev->features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES))) { - vq->enabled = 1; + vq->enabled = true; if (dev->notify_ops->vring_state_changed) dev->notify_ops->vring_state_changed( dev->vid, file.index, 1); } if (vq->ready) { - vq->ready = 0; + vq->ready = false; vhost_user_notify_queue_state(dev, file.index, 0); } @@ -2043,7 +2042,7 @@ vhost_user_set_vring_enable(struct virtio_net **pdev, int main_fd __rte_unused) { struct virtio_net *dev = *pdev; - int enable = (int)msg->payload.state.num; + bool enable = !!msg->payload.state.num; int index = (int)msg->payload.state.index; if (validate_msg_fds(msg, 0) != 0) diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c index 583bf379c6..3d8e29df09 100644 --- a/lib/librte_vhost/virtio_net.c +++ b/lib/librte_vhost/virtio_net.c @@ -1396,13 +1396,13 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, rte_spinlock_lock(&vq->access_lock); - if (unlikely(vq->enabled == 0)) + if (unlikely(!vq->enabled)) goto out_access_unlock; if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) vhost_user_iotlb_rd_lock(vq); - if (unlikely(vq->access_ok == 0)) + if (unlikely(!vq->access_ok)) if (unlikely(vring_translate(dev, vq) < 0)) goto out; @@ -1753,13 +1753,13 @@ virtio_dev_rx_async_submit(struct virtio_net *dev, uint16_t queue_id, rte_spinlock_lock(&vq->access_lock); - if (unlikely(vq->enabled == 0 || !vq->async_registered)) + if (unlikely(!vq->enabled || !vq->async_registered)) goto out_access_unlock; if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) vhost_user_iotlb_rd_lock(vq); - if (unlikely(vq->access_ok == 0)) + if (unlikely(!vq->access_ok)) if (unlikely(vring_translate(dev, vq) < 0)) goto out; @@ -2518,7 +2518,7 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, if (unlikely(rte_spinlock_trylock(&vq->access_lock) == 0)) return 0; - if (unlikely(vq->enabled == 0)) { + if (unlikely(!vq->enabled)) { count = 0; goto out_access_unlock; } @@ -2526,7 +2526,7 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) vhost_user_iotlb_rd_lock(vq); - if (unlikely(vq->access_ok == 0)) + if (unlikely(!vq->access_ok)) if (unlikely(vring_translate(dev, vq) < 0)) { count = 0; goto out; -- 2.30.2