From patchwork Mon Oct 18 13:02:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102025 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 8B4B2A0C43; Mon, 18 Oct 2021 15:03:25 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7A3C5410E5; Mon, 18 Oct 2021 15:03:25 +0200 (CEST) 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 A8D5D410E5 for ; Mon, 18 Oct 2021 15:03:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562203; 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=1hHyODl9y/XvpqE8nkZNFy3gJguIRUnOB939KwM2ZTg=; b=f3Jjq344lmv7c9pOl2TXcthZhKH4pr1kWTfiVoulbsc28j2QYGNYcZMmnM4jDezMyUoekE 7JC4dLEMXn8NidbXolRiRsp+MfL2J5by2s0dzRwnA7ym2QXWcVOODb1P4xLzq4g1R2ORH+ XJRmjWtST6aZRbx4J7+JOkZaAztoONc= 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-465-5GSyEOSLM3SHwFWVAOLncg-1; Mon, 18 Oct 2021 09:03:20 -0400 X-MC-Unique: 5GSyEOSLM3SHwFWVAOLncg-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 871A081CBDF; Mon, 18 Oct 2021 13:03:18 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0BEF57CA4; Mon, 18 Oct 2021 13:03:10 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:16 +0200 Message-Id: <20211018130229.308694-2-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 01/14] vhost: move async data in a dedicated structure 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 async-related metadata from vhost_virtqueue to a dedicated struct. It makes it clear which fields are async related, and also saves some memory when async feature is not in use. Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.c | 130 +++++++++++++++++------------------------ lib/vhost/vhost.h | 53 ++++++++--------- lib/vhost/vhost_user.c | 4 +- lib/vhost/virtio_net.c | 114 +++++++++++++++++++----------------- 4 files changed, 142 insertions(+), 159 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 9540522dac..6c38ec038d 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -340,19 +340,18 @@ cleanup_device(struct virtio_net *dev, int destroy) static void vhost_free_async_mem(struct vhost_virtqueue *vq) { - rte_free(vq->async_pkts_info); + if (!vq->async) + return; - rte_free(vq->async_buffers_packed); - vq->async_buffers_packed = NULL; - rte_free(vq->async_descs_split); - vq->async_descs_split = NULL; + rte_free(vq->async->pkts_info); - rte_free(vq->it_pool); - rte_free(vq->vec_pool); + rte_free(vq->async->buffers_packed); + vq->async->buffers_packed = NULL; + rte_free(vq->async->descs_split); + vq->async->descs_split = NULL; - vq->async_pkts_info = NULL; - vq->it_pool = NULL; - vq->vec_pool = NULL; + rte_free(vq->async); + vq->async = NULL; } void @@ -1629,77 +1628,63 @@ async_channel_register(int vid, uint16_t queue_id, { struct virtio_net *dev = get_device(vid); struct vhost_virtqueue *vq = dev->virtqueue[queue_id]; + struct vhost_async *async; + int node = vq->numa_node; - if (unlikely(vq->async_registered)) { + if (unlikely(vq->async)) { VHOST_LOG_CONFIG(ERR, - "async register failed: channel already registered " - "(vid %d, qid: %d)\n", vid, queue_id); + "async register failed: already registered (vid %d, qid: %d)\n", + vid, queue_id); return -1; } - vq->async_pkts_info = rte_malloc_socket(NULL, - vq->size * sizeof(struct async_inflight_info), - RTE_CACHE_LINE_SIZE, vq->numa_node); - if (!vq->async_pkts_info) { - vhost_free_async_mem(vq); - VHOST_LOG_CONFIG(ERR, - "async register failed: cannot allocate memory for async_pkts_info " - "(vid %d, qid: %d)\n", vid, queue_id); + async = rte_zmalloc_socket(NULL, sizeof(struct vhost_async), 0, node); + if (!async) { + VHOST_LOG_CONFIG(ERR, "failed to allocate async metadata (vid %d, qid: %d)\n", + vid, queue_id); return -1; } - vq->it_pool = rte_malloc_socket(NULL, - VHOST_MAX_ASYNC_IT * sizeof(struct rte_vhost_iov_iter), - RTE_CACHE_LINE_SIZE, vq->numa_node); - if (!vq->it_pool) { - vhost_free_async_mem(vq); - VHOST_LOG_CONFIG(ERR, - "async register failed: cannot allocate memory for it_pool " - "(vid %d, qid: %d)\n", vid, queue_id); - return -1; - } - - vq->vec_pool = rte_malloc_socket(NULL, - VHOST_MAX_ASYNC_VEC * sizeof(struct iovec), - RTE_CACHE_LINE_SIZE, vq->numa_node); - if (!vq->vec_pool) { - vhost_free_async_mem(vq); - VHOST_LOG_CONFIG(ERR, - "async register failed: cannot allocate memory for vec_pool " - "(vid %d, qid: %d)\n", vid, queue_id); - return -1; + async->pkts_info = rte_malloc_socket(NULL, vq->size * sizeof(struct async_inflight_info), + RTE_CACHE_LINE_SIZE, node); + if (!async->pkts_info) { + VHOST_LOG_CONFIG(ERR, "failed to allocate async_pkts_info (vid %d, qid: %d)\n", + vid, queue_id); + goto out_free_async; } if (vq_is_packed(dev)) { - vq->async_buffers_packed = rte_malloc_socket(NULL, - vq->size * sizeof(struct vring_used_elem_packed), - RTE_CACHE_LINE_SIZE, vq->numa_node); - if (!vq->async_buffers_packed) { - vhost_free_async_mem(vq); - VHOST_LOG_CONFIG(ERR, - "async register failed: cannot allocate memory for async buffers " - "(vid %d, qid: %d)\n", vid, queue_id); - return -1; + async->buffers_packed = rte_malloc_socket(NULL, + vq->size * sizeof(struct vring_used_elem_packed), + RTE_CACHE_LINE_SIZE, node); + if (!async->buffers_packed) { + VHOST_LOG_CONFIG(ERR, "failed to allocate async buffers (vid %d, qid: %d)\n", + vid, queue_id); + goto out_free_inflight; } } else { - vq->async_descs_split = rte_malloc_socket(NULL, - vq->size * sizeof(struct vring_used_elem), - RTE_CACHE_LINE_SIZE, vq->numa_node); - if (!vq->async_descs_split) { - vhost_free_async_mem(vq); - VHOST_LOG_CONFIG(ERR, - "async register failed: cannot allocate memory for async descs " - "(vid %d, qid: %d)\n", vid, queue_id); - return -1; + async->descs_split = rte_malloc_socket(NULL, + vq->size * sizeof(struct vring_used_elem), + RTE_CACHE_LINE_SIZE, node); + if (!async->descs_split) { + VHOST_LOG_CONFIG(ERR, "failed to allocate async descs (vid %d, qid: %d)\n", + vid, queue_id); + goto out_free_inflight; } } - vq->async_ops.check_completed_copies = ops->check_completed_copies; - vq->async_ops.transfer_data = ops->transfer_data; + async->ops.check_completed_copies = ops->check_completed_copies; + async->ops.transfer_data = ops->transfer_data; - vq->async_registered = true; + vq->async = async; return 0; +out_free_inflight: + rte_free(async->pkts_info); +out_free_async: + rte_free(async); + + return -1; } int @@ -1793,7 +1778,7 @@ rte_vhost_async_channel_unregister(int vid, uint16_t queue_id) ret = 0; - if (!vq->async_registered) + if (!vq->async) return ret; if (!rte_spinlock_trylock(&vq->access_lock)) { @@ -1802,7 +1787,7 @@ rte_vhost_async_channel_unregister(int vid, uint16_t queue_id) return -1; } - if (vq->async_pkts_inflight_n) { + if (vq->async->pkts_inflight_n) { VHOST_LOG_CONFIG(ERR, "Failed to unregister async channel. " "async inflight packets must be completed before unregistration.\n"); ret = -1; @@ -1810,11 +1795,6 @@ rte_vhost_async_channel_unregister(int vid, uint16_t queue_id) } vhost_free_async_mem(vq); - - vq->async_ops.transfer_data = NULL; - vq->async_ops.check_completed_copies = NULL; - vq->async_registered = false; - out: rte_spinlock_unlock(&vq->access_lock); @@ -1838,10 +1818,10 @@ rte_vhost_async_channel_unregister_thread_unsafe(int vid, uint16_t queue_id) if (vq == NULL) return -1; - if (!vq->async_registered) + if (!vq->async) return 0; - if (vq->async_pkts_inflight_n) { + if (vq->async->pkts_inflight_n) { VHOST_LOG_CONFIG(ERR, "Failed to unregister async channel. " "async inflight packets must be completed before unregistration.\n"); return -1; @@ -1849,10 +1829,6 @@ rte_vhost_async_channel_unregister_thread_unsafe(int vid, uint16_t queue_id) vhost_free_async_mem(vq); - vq->async_ops.transfer_data = NULL; - vq->async_ops.check_completed_copies = NULL; - vq->async_registered = false; - return 0; } @@ -1874,7 +1850,7 @@ rte_vhost_async_get_inflight(int vid, uint16_t queue_id) if (vq == NULL) return ret; - if (!vq->async_registered) + if (!vq->async) return ret; if (!rte_spinlock_trylock(&vq->access_lock)) { @@ -1883,7 +1859,7 @@ rte_vhost_async_get_inflight(int vid, uint16_t queue_id) return ret; } - ret = vq->async_pkts_inflight_n; + ret = vq->async->pkts_inflight_n; rte_spinlock_unlock(&vq->access_lock); return ret; diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index 1e56311725..ba33c6a69d 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -119,6 +119,32 @@ struct vring_used_elem_packed { uint32_t count; }; +struct vhost_async { + /* operation callbacks for DMA */ + struct rte_vhost_async_channel_ops ops; + + struct rte_vhost_iov_iter it_pool[VHOST_MAX_ASYNC_IT]; + struct iovec vec_pool[VHOST_MAX_ASYNC_VEC]; + + /* data transfer status */ + struct async_inflight_info *pkts_info; + uint16_t pkts_idx; + uint16_t pkts_inflight_n; + uint16_t last_pkts_n; + union { + struct vring_used_elem *descs_split; + struct vring_used_elem_packed *buffers_packed; + }; + union { + uint16_t desc_idx_split; + uint16_t buffer_idx_packed; + }; + union { + uint16_t last_desc_idx_split; + uint16_t last_buffer_idx_packed; + }; +}; + /** * Structure contains variables relevant to RX/TX virtqueues. */ @@ -193,32 +219,7 @@ struct vhost_virtqueue { struct rte_vhost_resubmit_info *resubmit_inflight; uint64_t global_counter; - /* operation callbacks for async dma */ - struct rte_vhost_async_channel_ops async_ops; - - struct rte_vhost_iov_iter *it_pool; - struct iovec *vec_pool; - - /* async data transfer status */ - struct async_inflight_info *async_pkts_info; - uint16_t async_pkts_idx; - uint16_t async_pkts_inflight_n; - uint16_t async_last_pkts_n; - union { - struct vring_used_elem *async_descs_split; - struct vring_used_elem_packed *async_buffers_packed; - }; - union { - uint16_t async_desc_idx_split; - uint16_t async_buffer_idx_packed; - }; - union { - uint16_t last_async_desc_idx_split; - uint16_t last_async_buffer_idx_packed; - }; - - /* vq async features */ - bool async_registered; + struct vhost_async *async; int notif_enable; #define VIRTIO_UNINITIALIZED_NOTIF (-1) diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 5a894ca0cc..dad4463d45 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -2140,8 +2140,8 @@ vhost_user_set_vring_enable(struct virtio_net **pdev, "set queue enable: %d to qp idx: %d\n", enable, index); - if (enable && dev->virtqueue[index]->async_registered) { - if (dev->virtqueue[index]->async_pkts_inflight_n) { + if (enable && dev->virtqueue[index]->async) { + if (dev->virtqueue[index]->async->pkts_inflight_n) { VHOST_LOG_CONFIG(ERR, "failed to enable vring. " "async inflight packets must be completed first\n"); return RTE_VHOST_MSG_RESULT_ERR; diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index e481906113..a109c2a316 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1510,12 +1510,13 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, uint16_t num_buffers; uint16_t avail_head; - struct rte_vhost_iov_iter *it_pool = vq->it_pool; - struct iovec *vec_pool = vq->vec_pool; + struct vhost_async *async = vq->async; + struct rte_vhost_iov_iter *it_pool = async->it_pool; + struct iovec *vec_pool = async->vec_pool; struct rte_vhost_async_desc tdes[MAX_PKT_BURST]; struct iovec *src_iovec = vec_pool; struct iovec *dst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >> 1); - struct async_inflight_info *pkts_info = vq->async_pkts_info; + struct async_inflight_info *pkts_info = async->pkts_info; uint32_t n_pkts = 0, pkt_err = 0; int32_t n_xfer; uint16_t segs_await = 0; @@ -1556,7 +1557,7 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, async_fill_desc(&tdes[pkt_burst_idx++], &it_pool[it_idx], &it_pool[it_idx + 1]); - slot_idx = (vq->async_pkts_idx + pkt_idx) & (vq->size - 1); + slot_idx = (async->pkts_idx + pkt_idx) & (vq->size - 1); pkts_info[slot_idx].descs = num_buffers; pkts_info[slot_idx].mbuf = pkts[pkt_idx]; @@ -1574,7 +1575,7 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, if (unlikely(pkt_burst_idx >= VHOST_ASYNC_BATCH_THRESHOLD || ((VHOST_MAX_ASYNC_VEC >> 1) - segs_await < BUF_VECTOR_MAX))) { - n_xfer = vq->async_ops.transfer_data(dev->vid, + n_xfer = async->ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); if (likely(n_xfer >= 0)) { n_pkts = n_xfer; @@ -1606,7 +1607,7 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, } if (pkt_burst_idx) { - n_xfer = vq->async_ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); + n_xfer = async->ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); if (likely(n_xfer >= 0)) { n_pkts = n_xfer; } else { @@ -1638,15 +1639,15 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, /* keep used descriptors */ if (likely(vq->shadow_used_idx)) { - uint16_t to = vq->async_desc_idx_split & (vq->size - 1); + uint16_t to = async->desc_idx_split & (vq->size - 1); store_dma_desc_info_split(vq->shadow_used_split, - vq->async_descs_split, vq->size, 0, to, + async->descs_split, vq->size, 0, to, vq->shadow_used_idx); - vq->async_desc_idx_split += vq->shadow_used_idx; - vq->async_pkts_idx += pkt_idx; - vq->async_pkts_inflight_n += pkt_idx; + async->desc_idx_split += vq->shadow_used_idx; + async->pkts_idx += pkt_idx; + async->pkts_inflight_n += pkt_idx; vq->shadow_used_idx = 0; } @@ -1798,7 +1799,7 @@ dma_error_handler_packed(struct vhost_virtqueue *vq, uint16_t slot_idx, { uint16_t descs_err = 0; uint16_t buffers_err = 0; - struct async_inflight_info *pkts_info = vq->async_pkts_info; + struct async_inflight_info *pkts_info = vq->async->pkts_info; *pkt_idx -= nr_err; /* calculate the sum of buffers and descs of DMA-error packets. */ @@ -1829,12 +1830,13 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, uint16_t num_buffers; uint16_t num_descs; - struct rte_vhost_iov_iter *it_pool = vq->it_pool; - struct iovec *vec_pool = vq->vec_pool; + struct vhost_async *async = vq->async; + struct rte_vhost_iov_iter *it_pool = async->it_pool; + struct iovec *vec_pool = async->vec_pool; struct rte_vhost_async_desc tdes[MAX_PKT_BURST]; struct iovec *src_iovec = vec_pool; struct iovec *dst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >> 1); - struct async_inflight_info *pkts_info = vq->async_pkts_info; + struct async_inflight_info *pkts_info = async->pkts_info; uint32_t n_pkts = 0, pkt_err = 0; uint16_t slot_idx = 0; uint16_t segs_await = 0; @@ -1851,7 +1853,7 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, &it_pool[it_idx], &it_pool[it_idx + 1]) < 0)) break; - slot_idx = (vq->async_pkts_idx + pkt_idx) % vq->size; + slot_idx = (async->pkts_idx + pkt_idx) % vq->size; async_fill_desc(&tdes[pkt_burst_idx++], &it_pool[it_idx], &it_pool[it_idx + 1]); @@ -1873,7 +1875,7 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, */ if (unlikely(pkt_burst_idx >= VHOST_ASYNC_BATCH_THRESHOLD || ((VHOST_MAX_ASYNC_VEC >> 1) - segs_await < BUF_VECTOR_MAX))) { - n_xfer = vq->async_ops.transfer_data(dev->vid, + n_xfer = async->ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); if (likely(n_xfer >= 0)) { n_pkts = n_xfer; @@ -1904,7 +1906,7 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, } while (pkt_idx < count); if (pkt_burst_idx) { - n_xfer = vq->async_ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); + n_xfer = async->ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); if (likely(n_xfer >= 0)) { n_pkts = n_xfer; } else { @@ -1922,20 +1924,20 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, if (likely(vq->shadow_used_idx)) { /* keep used descriptors. */ - store_dma_desc_info_packed(vq->shadow_used_packed, vq->async_buffers_packed, - vq->size, 0, vq->async_buffer_idx_packed, + store_dma_desc_info_packed(vq->shadow_used_packed, async->buffers_packed, + vq->size, 0, async->buffer_idx_packed, vq->shadow_used_idx); - vq->async_buffer_idx_packed += vq->shadow_used_idx; - if (vq->async_buffer_idx_packed >= vq->size) - vq->async_buffer_idx_packed -= vq->size; + async->buffer_idx_packed += vq->shadow_used_idx; + if (async->buffer_idx_packed >= vq->size) + async->buffer_idx_packed -= vq->size; - vq->async_pkts_idx += pkt_idx; - if (vq->async_pkts_idx >= vq->size) - vq->async_pkts_idx -= vq->size; + async->pkts_idx += pkt_idx; + if (async->pkts_idx >= vq->size) + async->pkts_idx -= vq->size; vq->shadow_used_idx = 0; - vq->async_pkts_inflight_n += pkt_idx; + async->pkts_inflight_n += pkt_idx; } return pkt_idx; @@ -1944,28 +1946,29 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, static __rte_always_inline void write_back_completed_descs_split(struct vhost_virtqueue *vq, uint16_t n_descs) { + struct vhost_async *async = vq->async; uint16_t nr_left = n_descs; uint16_t nr_copy; uint16_t to, from; do { - from = vq->last_async_desc_idx_split & (vq->size - 1); + from = async->last_desc_idx_split & (vq->size - 1); nr_copy = nr_left + from <= vq->size ? nr_left : vq->size - from; to = vq->last_used_idx & (vq->size - 1); if (to + nr_copy <= vq->size) { - rte_memcpy(&vq->used->ring[to], &vq->async_descs_split[from], + rte_memcpy(&vq->used->ring[to], &async->descs_split[from], nr_copy * sizeof(struct vring_used_elem)); } else { uint16_t size = vq->size - to; - rte_memcpy(&vq->used->ring[to], &vq->async_descs_split[from], + rte_memcpy(&vq->used->ring[to], &async->descs_split[from], size * sizeof(struct vring_used_elem)); - rte_memcpy(&vq->used->ring[0], &vq->async_descs_split[from + size], + rte_memcpy(&vq->used->ring[0], &async->descs_split[from + size], (nr_copy - size) * sizeof(struct vring_used_elem)); } - vq->last_async_desc_idx_split += nr_copy; + async->last_desc_idx_split += nr_copy; vq->last_used_idx += nr_copy; nr_left -= nr_copy; } while (nr_left > 0); @@ -1975,20 +1978,21 @@ static __rte_always_inline void write_back_completed_descs_packed(struct vhost_virtqueue *vq, uint16_t n_buffers) { + struct vhost_async *async = vq->async; uint16_t nr_left = n_buffers; uint16_t from, to; do { - from = vq->last_async_buffer_idx_packed; + from = async->last_buffer_idx_packed; to = (from + nr_left) % vq->size; if (to > from) { - vhost_update_used_packed(vq, vq->async_buffers_packed + from, to - from); - vq->last_async_buffer_idx_packed += nr_left; + vhost_update_used_packed(vq, async->buffers_packed + from, to - from); + async->last_buffer_idx_packed += nr_left; nr_left = 0; } else { - vhost_update_used_packed(vq, vq->async_buffers_packed + from, + vhost_update_used_packed(vq, async->buffers_packed + from, vq->size - from); - vq->last_async_buffer_idx_packed = 0; + async->last_buffer_idx_packed = 0; nr_left -= vq->size - from; } } while (nr_left > 0); @@ -1999,6 +2003,7 @@ vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, struct rte_mbuf **pkts, uint16_t count) { struct vhost_virtqueue *vq; + struct vhost_async *async; struct async_inflight_info *pkts_info; int32_t n_cpl; uint16_t n_pkts_cpl = 0, n_pkts_put = 0, n_descs = 0, n_buffers = 0; @@ -2006,15 +2011,16 @@ vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, uint16_t from, i; vq = dev->virtqueue[queue_id]; - pkts_idx = vq->async_pkts_idx % vq->size; - pkts_info = vq->async_pkts_info; + async = vq->async; + pkts_idx = async->pkts_idx % vq->size; + pkts_info = async->pkts_info; vq_size = vq->size; start_idx = virtio_dev_rx_async_get_info_idx(pkts_idx, - vq_size, vq->async_pkts_inflight_n); + vq_size, async->pkts_inflight_n); - if (count > vq->async_last_pkts_n) { - n_cpl = vq->async_ops.check_completed_copies(dev->vid, - queue_id, 0, count - vq->async_last_pkts_n); + if (count > async->last_pkts_n) { + n_cpl = async->ops.check_completed_copies(dev->vid, + queue_id, 0, count - async->last_pkts_n); if (likely(n_cpl >= 0)) { n_pkts_cpl = n_cpl; } else { @@ -2025,10 +2031,10 @@ vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, } } - n_pkts_cpl += vq->async_last_pkts_n; + n_pkts_cpl += async->last_pkts_n; n_pkts_put = RTE_MIN(n_pkts_cpl, count); if (unlikely(n_pkts_put == 0)) { - vq->async_last_pkts_n = n_pkts_cpl; + async->last_pkts_n = n_pkts_cpl; return 0; } @@ -2045,8 +2051,8 @@ vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, pkts[i] = pkts_info[from].mbuf; } } - vq->async_last_pkts_n = n_pkts_cpl - n_pkts_put; - vq->async_pkts_inflight_n -= n_pkts_put; + async->last_pkts_n = n_pkts_cpl - n_pkts_put; + async->pkts_inflight_n -= n_pkts_put; if (likely(vq->enabled && vq->access_ok)) { if (vq_is_packed(dev)) { @@ -2062,11 +2068,11 @@ vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, } } else { if (vq_is_packed(dev)) { - vq->last_async_buffer_idx_packed += n_buffers; - if (vq->last_async_buffer_idx_packed >= vq->size) - vq->last_async_buffer_idx_packed -= vq->size; + async->last_buffer_idx_packed += n_buffers; + if (async->last_buffer_idx_packed >= vq->size) + async->last_buffer_idx_packed -= vq->size; } else { - vq->last_async_desc_idx_split += n_descs; + async->last_desc_idx_split += n_descs; } } @@ -2093,7 +2099,7 @@ rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id, vq = dev->virtqueue[queue_id]; - if (unlikely(!vq->async_registered)) { + if (unlikely(!vq->async)) { VHOST_LOG_DATA(ERR, "(%d) %s: async not registered for queue id %d.\n", dev->vid, __func__, queue_id); return 0; @@ -2128,7 +2134,7 @@ rte_vhost_clear_queue_thread_unsafe(int vid, uint16_t queue_id, vq = dev->virtqueue[queue_id]; - if (unlikely(!vq->async_registered)) { + if (unlikely(!vq->async)) { VHOST_LOG_DATA(ERR, "(%d) %s: async not registered for queue id %d.\n", dev->vid, __func__, queue_id); return 0; @@ -2157,7 +2163,7 @@ virtio_dev_rx_async_submit(struct virtio_net *dev, uint16_t queue_id, rte_spinlock_lock(&vq->access_lock); - if (unlikely(!vq->enabled || !vq->async_registered)) + if (unlikely(!vq->enabled || !vq->async)) goto out_access_unlock; if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) From patchwork Mon Oct 18 13:02:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102026 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 2F50DA0C43; Mon, 18 Oct 2021 15:03:32 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6F918410EF; Mon, 18 Oct 2021 15:03:27 +0200 (CEST) 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 08625410EB for ; Mon, 18 Oct 2021 15:03:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562205; 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=ShlvuPlRXIHMFCugihnLX86DsVTwWXwU/xBrPygUMcI=; b=buxYlj5/zLjM3zqxZMvbc+0RuHbFaOOPfVTJWK5k48wiGrNvYcGS8yG/FjOC+Ca5i01Dqq SgIcL/vwl8XqgUmMbfwDFUOJlxLDxXzdnmu4TmjKDKtPZPtgby5jho4UgNWUuCXCOu1ePD bo4DEAplMYdkAQC2rjX80KG+hWVJnH8= 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-399-LZUXbQ0EPVqkTb_5Jk4goQ-1; Mon, 18 Oct 2021 09:03:22 -0400 X-MC-Unique: LZUXbQ0EPVqkTb_5Jk4goQ-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 E14D91B18BD2; Mon, 18 Oct 2021 13:03:20 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3E9657CA4; Mon, 18 Oct 2021 13:03:18 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:17 +0200 Message-Id: <20211018130229.308694-3-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 02/14] vhost: hide inflight async structure 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 async_inflight_info struct to internal header since it should not be part of the API. Signed-off-by: Maxime Coquelin --- lib/vhost/rte_vhost_async.h | 9 --------- lib/vhost/vhost.h | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h index ad71555a7f..789b80f5a0 100644 --- a/lib/vhost/rte_vhost_async.h +++ b/lib/vhost/rte_vhost_async.h @@ -83,15 +83,6 @@ struct rte_vhost_async_channel_ops { uint16_t max_packets); }; -/** - * inflight async packet information - */ -struct async_inflight_info { - struct rte_mbuf *mbuf; - uint16_t descs; /* num of descs inflight */ - uint16_t nr_buffers; /* num of buffers inflight for packed ring */ -}; - /** * async channel features */ diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index ba33c6a69d..9de87d20cc 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -119,6 +119,15 @@ struct vring_used_elem_packed { uint32_t count; }; +/** + * inflight async packet information + */ +struct async_inflight_info { + struct rte_mbuf *mbuf; + uint16_t descs; /* num of descs inflight */ + uint16_t nr_buffers; /* num of buffers inflight for packed ring */ +}; + struct vhost_async { /* operation callbacks for DMA */ struct rte_vhost_async_channel_ops ops; From patchwork Mon Oct 18 13:02:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102027 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 E73DDA0C43; Mon, 18 Oct 2021 15:03:47 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D3AC3410EE; Mon, 18 Oct 2021 15:03:47 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 5B99B40141 for ; Mon, 18 Oct 2021 15:03:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562225; 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=x72n5PZzRvC+MHEcgyciapk4uuGHpP9CaOQNzNn2mcI=; b=ZhLyKcin8x4kxATntc/360lOlamEgUB6NdC+vsRXaoY55bXGXzYIFH0WksVswCIBEet6yR X0Bu87VnfvgD+hMHtcwAGWy2yX/MoG+CfQwIyM7AuOtw9OYOTkWg9Eh+ak/Aic2StuIkGI WJiR4j7SF37wJ7vf7MvYc1UbB6gPyF0= 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-404-tyDMWJr6MCuS88nIUFChLQ-1; Mon, 18 Oct 2021 09:03:40 -0400 X-MC-Unique: tyDMWJr6MCuS88nIUFChLQ-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 8879E5074E; Mon, 18 Oct 2021 13:03:38 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41DB169119; Mon, 18 Oct 2021 13:03:21 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:18 +0200 Message-Id: <20211018130229.308694-4-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 03/14] vhost: simplify async IO vectors 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" IO vectors implementation is unnecessarily complex, mixing source and destinations vectors in the same array. This patch declares two arrays, one for the source and one for the destination. It also get rid off seg_awaits variable in both packed and split implementation, which is the same as iovec_idx. Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.h | 5 +++-- lib/vhost/virtio_net.c | 28 +++++++++++----------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index 9de87d20cc..f2d9535174 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -49,7 +49,7 @@ #define MAX_PKT_BURST 32 #define VHOST_MAX_ASYNC_IT (MAX_PKT_BURST * 2) -#define VHOST_MAX_ASYNC_VEC (BUF_VECTOR_MAX * 4) +#define VHOST_MAX_ASYNC_VEC (BUF_VECTOR_MAX * 2) #define PACKED_DESC_ENQUEUE_USED_FLAG(w) \ ((w) ? (VRING_DESC_F_AVAIL | VRING_DESC_F_USED | VRING_DESC_F_WRITE) : \ @@ -133,7 +133,8 @@ struct vhost_async { struct rte_vhost_async_channel_ops ops; struct rte_vhost_iov_iter it_pool[VHOST_MAX_ASYNC_IT]; - struct iovec vec_pool[VHOST_MAX_ASYNC_VEC]; + struct iovec src_iovec[VHOST_MAX_ASYNC_VEC]; + struct iovec dst_iovec[VHOST_MAX_ASYNC_VEC]; /* data transfer status */ struct async_inflight_info *pkts_info; diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index a109c2a316..4e0e1584b8 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1512,14 +1512,12 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, struct vhost_async *async = vq->async; struct rte_vhost_iov_iter *it_pool = async->it_pool; - struct iovec *vec_pool = async->vec_pool; struct rte_vhost_async_desc tdes[MAX_PKT_BURST]; - struct iovec *src_iovec = vec_pool; - struct iovec *dst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >> 1); + struct iovec *src_iovec = async->src_iovec; + struct iovec *dst_iovec = async->dst_iovec; struct async_inflight_info *pkts_info = async->pkts_info; uint32_t n_pkts = 0, pkt_err = 0; int32_t n_xfer; - uint16_t segs_await = 0; uint16_t iovec_idx = 0, it_idx = 0, slot_idx = 0; /* @@ -1562,7 +1560,6 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, pkts_info[slot_idx].mbuf = pkts[pkt_idx]; iovec_idx += it_pool[it_idx].nr_segs; - segs_await += it_pool[it_idx].nr_segs; it_idx += 2; vq->last_avail_idx += num_buffers; @@ -1573,8 +1570,7 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, * - unused async iov number is less than max vhost vector */ if (unlikely(pkt_burst_idx >= VHOST_ASYNC_BATCH_THRESHOLD || - ((VHOST_MAX_ASYNC_VEC >> 1) - segs_await < - BUF_VECTOR_MAX))) { + (VHOST_MAX_ASYNC_VEC - iovec_idx < BUF_VECTOR_MAX))) { n_xfer = async->ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); if (likely(n_xfer >= 0)) { @@ -1588,7 +1584,6 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, iovec_idx = 0; it_idx = 0; - segs_await = 0; if (unlikely(n_pkts < pkt_burst_idx)) { /* @@ -1745,8 +1740,11 @@ vhost_enqueue_async_packed(struct virtio_net *dev, if (unlikely(++tries > max_tries)) return -1; - if (unlikely(fill_vec_buf_packed(dev, vq, avail_idx, &desc_count, buf_vec, &nr_vec, - &buf_id, &len, VHOST_ACCESS_RW) < 0)) + if (unlikely(fill_vec_buf_packed(dev, vq, + avail_idx, &desc_count, + buf_vec, &nr_vec, + &buf_id, &len, + VHOST_ACCESS_RW) < 0)) return -1; len = RTE_MIN(len, size); @@ -1832,14 +1830,12 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, struct vhost_async *async = vq->async; struct rte_vhost_iov_iter *it_pool = async->it_pool; - struct iovec *vec_pool = async->vec_pool; struct rte_vhost_async_desc tdes[MAX_PKT_BURST]; - struct iovec *src_iovec = vec_pool; - struct iovec *dst_iovec = vec_pool + (VHOST_MAX_ASYNC_VEC >> 1); + struct iovec *src_iovec = async->src_iovec; + struct iovec *dst_iovec = async->dst_iovec; struct async_inflight_info *pkts_info = async->pkts_info; uint32_t n_pkts = 0, pkt_err = 0; uint16_t slot_idx = 0; - uint16_t segs_await = 0; uint16_t iovec_idx = 0, it_idx = 0; do { @@ -1861,7 +1857,6 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, pkts_info[slot_idx].nr_buffers = num_buffers; pkts_info[slot_idx].mbuf = pkts[pkt_idx]; iovec_idx += it_pool[it_idx].nr_segs; - segs_await += it_pool[it_idx].nr_segs; it_idx += 2; pkt_idx++; @@ -1874,7 +1869,7 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, * - unused async iov number is less than max vhost vector */ if (unlikely(pkt_burst_idx >= VHOST_ASYNC_BATCH_THRESHOLD || - ((VHOST_MAX_ASYNC_VEC >> 1) - segs_await < BUF_VECTOR_MAX))) { + (VHOST_MAX_ASYNC_VEC - iovec_idx < BUF_VECTOR_MAX))) { n_xfer = async->ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); if (likely(n_xfer >= 0)) { @@ -1888,7 +1883,6 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, iovec_idx = 0; it_idx = 0; - segs_await = 0; if (unlikely(n_pkts < pkt_burst_idx)) { /* From patchwork Mon Oct 18 13:02:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102028 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 E10EDA0C43; Mon, 18 Oct 2021 15:03:52 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C9DAF410E4; Mon, 18 Oct 2021 15:03:52 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 4620340DDE for ; Mon, 18 Oct 2021 15:03:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562230; 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=vKjLAjtJUhKkW9lQfbmdIhT7+PaRXFgE6YQdfTqtGbU=; b=GW9NILNTtYCIhW2v5t8Qonj9ShjBVXWwYa1jhD+WQdvXGrlngZ0R0OHAbuHYAtIGPpccJC N4VsdOGOtNmUhEQd3bXEo+TEyz5z45H/ONjyeToR8W4+h0WwwPMZGZw/dgxxn3za0NR2Ww S1aGsxWPDcudcHGrLV6bczgHeiqkoY4= 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-94-lbS3BYCsOEiAj5dv_FZJHw-1; Mon, 18 Oct 2021 09:03:47 -0400 X-MC-Unique: lbS3BYCsOEiAj5dv_FZJHw-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 43577100B700; Mon, 18 Oct 2021 13:03:46 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id DADAA60BD8; Mon, 18 Oct 2021 13:03:38 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:19 +0200 Message-Id: <20211018130229.308694-5-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 04/14] vhost: simplify async IO vectors iterators 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 splits the iterator arrays in two, one for source and one for destination. The goal is make the code easier to understand. Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.h | 5 +++-- lib/vhost/virtio_net.c | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index f2d9535174..cb4c0f022a 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -48,7 +48,7 @@ #define MAX_PKT_BURST 32 -#define VHOST_MAX_ASYNC_IT (MAX_PKT_BURST * 2) +#define VHOST_MAX_ASYNC_IT (MAX_PKT_BURST) #define VHOST_MAX_ASYNC_VEC (BUF_VECTOR_MAX * 2) #define PACKED_DESC_ENQUEUE_USED_FLAG(w) \ @@ -132,7 +132,8 @@ struct vhost_async { /* operation callbacks for DMA */ struct rte_vhost_async_channel_ops ops; - struct rte_vhost_iov_iter it_pool[VHOST_MAX_ASYNC_IT]; + struct rte_vhost_iov_iter src_iov_iter[VHOST_MAX_ASYNC_IT]; + struct rte_vhost_iov_iter dst_iov_iter[VHOST_MAX_ASYNC_IT]; struct iovec src_iovec[VHOST_MAX_ASYNC_VEC]; struct iovec dst_iovec[VHOST_MAX_ASYNC_VEC]; diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 4e0e1584b8..e2a9e138b7 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1511,7 +1511,8 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, uint16_t avail_head; struct vhost_async *async = vq->async; - struct rte_vhost_iov_iter *it_pool = async->it_pool; + struct rte_vhost_iov_iter *src_iter = async->src_iov_iter; + struct rte_vhost_iov_iter *dst_iter = async->dst_iov_iter; struct rte_vhost_async_desc tdes[MAX_PKT_BURST]; struct iovec *src_iovec = async->src_iovec; struct iovec *dst_iovec = async->dst_iovec; @@ -1547,20 +1548,19 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, if (async_mbuf_to_desc(dev, vq, pkts[pkt_idx], buf_vec, nr_vec, num_buffers, &src_iovec[iovec_idx], &dst_iovec[iovec_idx], - &it_pool[it_idx], &it_pool[it_idx + 1]) < 0) { + &src_iter[it_idx], &dst_iter[it_idx]) < 0) { vq->shadow_used_idx -= num_buffers; break; } - async_fill_desc(&tdes[pkt_burst_idx++], &it_pool[it_idx], - &it_pool[it_idx + 1]); + async_fill_desc(&tdes[pkt_burst_idx++], &src_iter[it_idx], &dst_iter[it_idx]); slot_idx = (async->pkts_idx + pkt_idx) & (vq->size - 1); pkts_info[slot_idx].descs = num_buffers; pkts_info[slot_idx].mbuf = pkts[pkt_idx]; - iovec_idx += it_pool[it_idx].nr_segs; - it_idx += 2; + iovec_idx += src_iter[it_idx].nr_segs; + it_idx++; vq->last_avail_idx += num_buffers; @@ -1829,7 +1829,8 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, uint16_t num_descs; struct vhost_async *async = vq->async; - struct rte_vhost_iov_iter *it_pool = async->it_pool; + struct rte_vhost_iov_iter *src_iter = async->src_iov_iter; + struct rte_vhost_iov_iter *dst_iter = async->dst_iov_iter; struct rte_vhost_async_desc tdes[MAX_PKT_BURST]; struct iovec *src_iovec = async->src_iovec; struct iovec *dst_iovec = async->dst_iovec; @@ -1846,18 +1847,17 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, if (unlikely(virtio_dev_rx_async_packed(dev, vq, pkts[pkt_idx], &num_descs, &num_buffers, &src_iovec[iovec_idx], &dst_iovec[iovec_idx], - &it_pool[it_idx], &it_pool[it_idx + 1]) < 0)) + &src_iter[it_idx], &dst_iter[it_idx]) < 0)) break; slot_idx = (async->pkts_idx + pkt_idx) % vq->size; - async_fill_desc(&tdes[pkt_burst_idx++], &it_pool[it_idx], - &it_pool[it_idx + 1]); + async_fill_desc(&tdes[pkt_burst_idx++], &src_iter[it_idx], &dst_iter[it_idx]); pkts_info[slot_idx].descs = num_descs; pkts_info[slot_idx].nr_buffers = num_buffers; pkts_info[slot_idx].mbuf = pkts[pkt_idx]; - iovec_idx += it_pool[it_idx].nr_segs; - it_idx += 2; + iovec_idx += src_iter[it_idx].nr_segs; + it_idx++; pkt_idx++; remained--; From patchwork Mon Oct 18 13:02:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102029 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 0EF5DA0C43; Mon, 18 Oct 2021 15:03:59 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B8562410FF; Mon, 18 Oct 2021 15:03:54 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 793C4410F8 for ; Mon, 18 Oct 2021 15:03:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562233; 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=nPiOlUzKgb0I3XgyfsmMPvVhnOS3ZCVkyJXTT5xJnFE=; b=fEa2aFN1abAqqIKoKfD1nlYSmUITv6VUUyh28XoOtOqDHniwBzHn/MX3qeoHQzNn07/Y9C B5PhCkTbGR49r2hYbucljsjON2U41kpIKXVrCpCxn/HD+Bu7JaFIUkGfYT6g0usDu5EzZc Zu4vLCWz15J1fcu+CN4fbc6PfZceSv4= 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-31-F5uUqbwsO7i3JN-1lsy1yA-1; Mon, 18 Oct 2021 09:03:49 -0400 X-MC-Unique: F5uUqbwsO7i3JN-1lsy1yA-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 8833B8735C6; Mon, 18 Oct 2021 13:03:48 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E1AC57CA4; Mon, 18 Oct 2021 13:03:46 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:20 +0200 Message-Id: <20211018130229.308694-6-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 05/14] vhost: remove async batch threshold 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" Reaching the async batch threshold was one of the condition to trigger the DMA transfer. However, this condition was never met since the threshold value is 32, same as the MAX_PKT_BURST value. Signed-off-by: Maxime Coquelin --- lib/vhost/virtio_net.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index e2a9e138b7..a939481eaf 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -25,8 +25,6 @@ #define MAX_BATCH_LEN 256 -#define VHOST_ASYNC_BATCH_THRESHOLD 32 - static __rte_always_inline bool rxvq_is_mergeable(struct virtio_net *dev) { @@ -1565,12 +1563,10 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, vq->last_avail_idx += num_buffers; /* - * conditions to trigger async device transfer: - * - buffered packet number reaches transfer threshold + * condition to trigger async device transfer: * - unused async iov number is less than max vhost vector */ - if (unlikely(pkt_burst_idx >= VHOST_ASYNC_BATCH_THRESHOLD || - (VHOST_MAX_ASYNC_VEC - iovec_idx < BUF_VECTOR_MAX))) { + if (unlikely(VHOST_MAX_ASYNC_VEC - iovec_idx < BUF_VECTOR_MAX)) { n_xfer = async->ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); if (likely(n_xfer >= 0)) { @@ -1864,12 +1860,10 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, vq_inc_last_avail_packed(vq, num_descs); /* - * conditions to trigger async device transfer: - * - buffered packet number reaches transfer threshold + * condition to trigger async device transfer: * - unused async iov number is less than max vhost vector */ - if (unlikely(pkt_burst_idx >= VHOST_ASYNC_BATCH_THRESHOLD || - (VHOST_MAX_ASYNC_VEC - iovec_idx < BUF_VECTOR_MAX))) { + if (unlikely(VHOST_MAX_ASYNC_VEC - iovec_idx < BUF_VECTOR_MAX)) { n_xfer = async->ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); if (likely(n_xfer >= 0)) { From patchwork Mon Oct 18 13:02:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102030 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 11B20A0C43; Mon, 18 Oct 2021 15:04:05 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B6C7D410E8; Mon, 18 Oct 2021 15:03:57 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 8BCEB41103 for ; Mon, 18 Oct 2021 15:03:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562235; 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=Kss1lV0mtKlanzCw+pu8e5PHp2G0LlGk5XII/ZU1svs=; b=S+YBgm7VJTHnBo68lYSJM5Khzo8QRneCBcQLeTvtFsWeMJJf4kXfxsWHiSCWKZ3xYygI7Z o3Lxb4PFZXPHk8W1TIygO9Xe3a3DDOq/yEji4R7W310nSpPnvWbwplZoiUtxo9GjPWAino gEG4vrGfAk+e6cICO+ARwZjb2/T8rwo= 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-586-Oky8-DhFNvu6x78-Qdk46Q-1; Mon, 18 Oct 2021 09:03:52 -0400 X-MC-Unique: Oky8-DhFNvu6x78-Qdk46Q-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 D1C2A802682; Mon, 18 Oct 2021 13:03:50 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE24157CA4; Mon, 18 Oct 2021 13:03:48 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:21 +0200 Message-Id: <20211018130229.308694-7-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 06/14] vhost: introduce specific iovec structure 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 introduces rte_vhost_iovec struct that contains both source and destination addresses since we always have a 1:1 mapping between source and destination. While using the standard iovec struct might have seemed better, having to duplicate IO vectors and its iterators is memory inefficient and make the implementation more complex. Signed-off-by: Maxime Coquelin --- examples/vhost/ioat.c | 24 ++++++------- lib/vhost/rte_vhost_async.h | 19 +++++++---- lib/vhost/vhost.h | 6 ++-- lib/vhost/virtio_net.c | 68 ++++++++++++++----------------------- 4 files changed, 52 insertions(+), 65 deletions(-) diff --git a/examples/vhost/ioat.c b/examples/vhost/ioat.c index 457f8171f0..dcbcf65e4e 100644 --- a/examples/vhost/ioat.c +++ b/examples/vhost/ioat.c @@ -129,33 +129,31 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, { uint32_t i_desc; uint16_t dev_id = dma_bind[vid].dmas[queue_id * 2 + VIRTIO_RXQ].dev_id; - struct rte_vhost_iov_iter *src = NULL; - struct rte_vhost_iov_iter *dst = NULL; + struct rte_vhost_iov_iter *iter = NULL; unsigned long i_seg; unsigned short mask = MAX_ENQUEUED_SIZE - 1; unsigned short write = cb_tracker[dev_id].next_write; if (!opaque_data) { for (i_desc = 0; i_desc < count; i_desc++) { - src = descs[i_desc].src; - dst = descs[i_desc].dst; + iter = descs[i_desc].iter; i_seg = 0; - if (cb_tracker[dev_id].ioat_space < src->nr_segs) + if (cb_tracker[dev_id].ioat_space < iter->nr_segs) break; - while (i_seg < src->nr_segs) { + while (i_seg < iter->nr_segs) { rte_ioat_enqueue_copy(dev_id, - (uintptr_t)(src->iov[i_seg].iov_base) - + src->offset, - (uintptr_t)(dst->iov[i_seg].iov_base) - + dst->offset, - src->iov[i_seg].iov_len, + (uintptr_t)(iter->iov[i_seg].src_addr) + + iter->offset, + (uintptr_t)(iter->iov[i_seg].dst_addr) + + iter->offset, + iter->iov[i_seg].len, 0, 0); i_seg++; } write &= mask; - cb_tracker[dev_id].size_track[write] = src->nr_segs; - cb_tracker[dev_id].ioat_space -= src->nr_segs; + cb_tracker[dev_id].size_track[write] = iter->nr_segs; + cb_tracker[dev_id].ioat_space -= iter->nr_segs; write++; } } else { diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h index 789b80f5a0..d7bb77bf90 100644 --- a/lib/vhost/rte_vhost_async.h +++ b/lib/vhost/rte_vhost_async.h @@ -7,6 +7,15 @@ #include "rte_vhost.h" +/** + * iovec + */ +struct rte_vhost_iovec { + void *src_addr; + void *dst_addr; + size_t len; +}; + /** * iovec iterator */ @@ -16,19 +25,17 @@ struct rte_vhost_iov_iter { /** total bytes of data in this iterator */ size_t count; /** pointer to the iovec array */ - struct iovec *iov; + struct rte_vhost_iovec *iov; /** number of iovec in this iterator */ unsigned long nr_segs; }; /** - * dma transfer descriptor pair + * dma transfer descriptor */ struct rte_vhost_async_desc { - /** source memory iov_iter */ - struct rte_vhost_iov_iter *src; - /** destination memory iov_iter */ - struct rte_vhost_iov_iter *dst; + /* memory iov_iter */ + struct rte_vhost_iov_iter *iter; }; /** diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index cb4c0f022a..dae9a1ac2d 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -132,10 +132,8 @@ struct vhost_async { /* operation callbacks for DMA */ struct rte_vhost_async_channel_ops ops; - struct rte_vhost_iov_iter src_iov_iter[VHOST_MAX_ASYNC_IT]; - struct rte_vhost_iov_iter dst_iov_iter[VHOST_MAX_ASYNC_IT]; - struct iovec src_iovec[VHOST_MAX_ASYNC_VEC]; - struct iovec dst_iovec[VHOST_MAX_ASYNC_VEC]; + struct rte_vhost_iov_iter iov_iter[VHOST_MAX_ASYNC_IT]; + struct rte_vhost_iovec iovec[VHOST_MAX_ASYNC_VEC]; /* data transfer status */ struct async_inflight_info *pkts_info; diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index a939481eaf..7b1c52ea7d 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -925,15 +925,16 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, } static __rte_always_inline void -async_fill_vec(struct iovec *v, void *base, size_t len) +async_fill_vec(struct rte_vhost_iovec *v, void *src, void *dst, size_t len) { - v->iov_base = base; - v->iov_len = len; + v->src_addr = src; + v->dst_addr = dst; + v->len = len; } static __rte_always_inline void async_fill_iter(struct rte_vhost_iov_iter *it, size_t count, - struct iovec *vec, unsigned long nr_seg) + struct rte_vhost_iovec *vec, unsigned long nr_seg) { it->offset = 0; it->count = count; @@ -948,20 +949,16 @@ async_fill_iter(struct rte_vhost_iov_iter *it, size_t count, } static __rte_always_inline void -async_fill_desc(struct rte_vhost_async_desc *desc, - struct rte_vhost_iov_iter *src, struct rte_vhost_iov_iter *dst) +async_fill_desc(struct rte_vhost_async_desc *desc, struct rte_vhost_iov_iter *iter) { - desc->src = src; - desc->dst = dst; + desc->iter = iter; } static __rte_always_inline int async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, struct rte_mbuf *m, struct buf_vector *buf_vec, uint16_t nr_vec, uint16_t num_buffers, - struct iovec *src_iovec, struct iovec *dst_iovec, - struct rte_vhost_iov_iter *src_it, - struct rte_vhost_iov_iter *dst_it) + struct rte_vhost_iovec *iovec, struct rte_vhost_iov_iter *iter) { struct rte_mbuf *hdr_mbuf; struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL; @@ -1075,11 +1072,9 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, goto out; } - async_fill_vec(src_iovec + tvec_idx, + async_fill_vec(iovec + tvec_idx, (void *)(uintptr_t)rte_pktmbuf_iova_offset(m, - mbuf_offset), (size_t)mapped_len); - async_fill_vec(dst_iovec + tvec_idx, - hpa, (size_t)mapped_len); + mbuf_offset), hpa, (size_t)mapped_len); tlen += (uint32_t)mapped_len; cpy_len -= (uint32_t)mapped_len; @@ -1091,8 +1086,7 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, } } - async_fill_iter(src_it, tlen, src_iovec, tvec_idx); - async_fill_iter(dst_it, tlen, dst_iovec, tvec_idx); + async_fill_iter(iter, tlen, iovec, tvec_idx); out: return error; } @@ -1509,11 +1503,9 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, uint16_t avail_head; struct vhost_async *async = vq->async; - struct rte_vhost_iov_iter *src_iter = async->src_iov_iter; - struct rte_vhost_iov_iter *dst_iter = async->dst_iov_iter; + struct rte_vhost_iov_iter *iter = async->iov_iter; struct rte_vhost_async_desc tdes[MAX_PKT_BURST]; - struct iovec *src_iovec = async->src_iovec; - struct iovec *dst_iovec = async->dst_iovec; + struct rte_vhost_iovec *iovec = async->iovec; struct async_inflight_info *pkts_info = async->pkts_info; uint32_t n_pkts = 0, pkt_err = 0; int32_t n_xfer; @@ -1545,19 +1537,18 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, vq->last_avail_idx + num_buffers); if (async_mbuf_to_desc(dev, vq, pkts[pkt_idx], buf_vec, nr_vec, num_buffers, - &src_iovec[iovec_idx], &dst_iovec[iovec_idx], - &src_iter[it_idx], &dst_iter[it_idx]) < 0) { + &iovec[iovec_idx], &iter[it_idx]) < 0) { vq->shadow_used_idx -= num_buffers; break; } - async_fill_desc(&tdes[pkt_burst_idx++], &src_iter[it_idx], &dst_iter[it_idx]); + async_fill_desc(&tdes[pkt_burst_idx++], &iter[it_idx]); slot_idx = (async->pkts_idx + pkt_idx) & (vq->size - 1); pkts_info[slot_idx].descs = num_buffers; pkts_info[slot_idx].mbuf = pkts[pkt_idx]; - iovec_idx += src_iter[it_idx].nr_segs; + iovec_idx += iter[it_idx].nr_segs; it_idx++; vq->last_avail_idx += num_buffers; @@ -1707,9 +1698,8 @@ vhost_enqueue_async_packed(struct virtio_net *dev, struct buf_vector *buf_vec, uint16_t *nr_descs, uint16_t *nr_buffers, - struct iovec *src_iovec, struct iovec *dst_iovec, - struct rte_vhost_iov_iter *src_it, - struct rte_vhost_iov_iter *dst_it) + struct rte_vhost_iovec *iovec, + struct rte_vhost_iov_iter *iter) { uint16_t nr_vec = 0; uint16_t avail_idx = vq->last_avail_idx; @@ -1757,8 +1747,7 @@ vhost_enqueue_async_packed(struct virtio_net *dev, } if (unlikely(async_mbuf_to_desc(dev, vq, pkt, buf_vec, nr_vec, - *nr_buffers, src_iovec, dst_iovec, - src_it, dst_it) < 0)) + *nr_buffers, iovec, iter) < 0)) return -1; vhost_shadow_enqueue_packed(vq, buffer_len, buffer_buf_id, buffer_desc_count, *nr_buffers); @@ -1769,14 +1758,12 @@ vhost_enqueue_async_packed(struct virtio_net *dev, static __rte_always_inline int16_t virtio_dev_rx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, struct rte_mbuf *pkt, uint16_t *nr_descs, uint16_t *nr_buffers, - struct iovec *src_iovec, struct iovec *dst_iovec, - struct rte_vhost_iov_iter *src_it, struct rte_vhost_iov_iter *dst_it) + struct rte_vhost_iovec *iovec, struct rte_vhost_iov_iter *iter) { struct buf_vector buf_vec[BUF_VECTOR_MAX]; if (unlikely(vhost_enqueue_async_packed(dev, vq, pkt, buf_vec, nr_descs, nr_buffers, - src_iovec, dst_iovec, - src_it, dst_it) < 0)) { + iovec, iter) < 0)) { VHOST_LOG_DATA(DEBUG, "(%d) failed to get enough desc from vring\n", dev->vid); return -1; } @@ -1825,11 +1812,9 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, uint16_t num_descs; struct vhost_async *async = vq->async; - struct rte_vhost_iov_iter *src_iter = async->src_iov_iter; - struct rte_vhost_iov_iter *dst_iter = async->dst_iov_iter; + struct rte_vhost_iov_iter *iter = async->iov_iter; struct rte_vhost_async_desc tdes[MAX_PKT_BURST]; - struct iovec *src_iovec = async->src_iovec; - struct iovec *dst_iovec = async->dst_iovec; + struct rte_vhost_iovec *iovec = async->iovec; struct async_inflight_info *pkts_info = async->pkts_info; uint32_t n_pkts = 0, pkt_err = 0; uint16_t slot_idx = 0; @@ -1842,17 +1827,16 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, num_descs = 0; if (unlikely(virtio_dev_rx_async_packed(dev, vq, pkts[pkt_idx], &num_descs, &num_buffers, - &src_iovec[iovec_idx], &dst_iovec[iovec_idx], - &src_iter[it_idx], &dst_iter[it_idx]) < 0)) + &iovec[iovec_idx], &iter[it_idx]) < 0)) break; slot_idx = (async->pkts_idx + pkt_idx) % vq->size; - async_fill_desc(&tdes[pkt_burst_idx++], &src_iter[it_idx], &dst_iter[it_idx]); + async_fill_desc(&tdes[pkt_burst_idx++], &iter[it_idx]); pkts_info[slot_idx].descs = num_descs; pkts_info[slot_idx].nr_buffers = num_buffers; pkts_info[slot_idx].mbuf = pkts[pkt_idx]; - iovec_idx += src_iter[it_idx].nr_segs; + iovec_idx += iter[it_idx].nr_segs; it_idx++; pkt_idx++; From patchwork Mon Oct 18 13:02:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102031 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 26D78A0C43; Mon, 18 Oct 2021 15:04:13 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 21A6A41123; Mon, 18 Oct 2021 15:03:59 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id E34E141109 for ; Mon, 18 Oct 2021 15:03:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562237; 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=xvejkVjPXKUm/4sEHk+Ul6AHf7CX74VtirVioP89gyk=; b=HVNA1T2dYX/jaepYD4nFq0M6B2IZ+kpiLG8QcSveChK3YJ+cahVj+VIZxpgkZx9nlrkMc1 x5hd0GZPjLWKY0JOLeGmsDd1BehUjRXykHltgv7V5LmUtJuuu/wpzh3C8uQxnfXS8y73Gr /Qdw8nd474SvkJoiKFacXFUngslDW1s= 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-198-vEVXpRBdPOKEPpGjBPEKkw-1; Mon, 18 Oct 2021 09:03:54 -0400 X-MC-Unique: vEVXpRBdPOKEPpGjBPEKkw-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 183138735D0; Mon, 18 Oct 2021 13:03:53 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 296C61980E; Mon, 18 Oct 2021 13:03:51 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:22 +0200 Message-Id: <20211018130229.308694-8-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 07/14] vhost: remove useless fields in async iterator 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" Offset and count fields are unused and so can be removed. The offset field was actually in the Vhost example, but in a way that does not make sense. Signed-off-by: Maxime Coquelin --- examples/vhost/ioat.c | 6 ++---- lib/vhost/rte_vhost_async.h | 4 ---- lib/vhost/virtio_net.c | 19 ++++--------------- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/examples/vhost/ioat.c b/examples/vhost/ioat.c index dcbcf65e4e..a8c588deff 100644 --- a/examples/vhost/ioat.c +++ b/examples/vhost/ioat.c @@ -142,10 +142,8 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, break; while (i_seg < iter->nr_segs) { rte_ioat_enqueue_copy(dev_id, - (uintptr_t)(iter->iov[i_seg].src_addr) - + iter->offset, - (uintptr_t)(iter->iov[i_seg].dst_addr) - + iter->offset, + (uintptr_t)(iter->iov[i_seg].src_addr), + (uintptr_t)(iter->iov[i_seg].dst_addr), iter->iov[i_seg].len, 0, 0); diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h index d7bb77bf90..4ea5cfab10 100644 --- a/lib/vhost/rte_vhost_async.h +++ b/lib/vhost/rte_vhost_async.h @@ -20,10 +20,6 @@ struct rte_vhost_iovec { * iovec iterator */ struct rte_vhost_iov_iter { - /** offset to the first byte of interesting data */ - size_t offset; - /** total bytes of data in this iterator */ - size_t count; /** pointer to the iovec array */ struct rte_vhost_iovec *iov; /** number of iovec in this iterator */ diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 7b1c52ea7d..ae7dded979 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -933,19 +933,10 @@ async_fill_vec(struct rte_vhost_iovec *v, void *src, void *dst, size_t len) } static __rte_always_inline void -async_fill_iter(struct rte_vhost_iov_iter *it, size_t count, - struct rte_vhost_iovec *vec, unsigned long nr_seg) +async_fill_iter(struct rte_vhost_iov_iter *it, struct rte_vhost_iovec *vec, unsigned long nr_seg) { - it->offset = 0; - it->count = count; - - if (count) { - it->iov = vec; - it->nr_segs = nr_seg; - } else { - it->iov = 0; - it->nr_segs = 0; - } + it->iov = vec; + it->nr_segs = nr_seg; } static __rte_always_inline void @@ -971,7 +962,6 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, uint32_t cpy_len, buf_len; int error = 0; - uint32_t tlen = 0; int tvec_idx = 0; void *hpa; @@ -1076,7 +1066,6 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, (void *)(uintptr_t)rte_pktmbuf_iova_offset(m, mbuf_offset), hpa, (size_t)mapped_len); - tlen += (uint32_t)mapped_len; cpy_len -= (uint32_t)mapped_len; mbuf_avail -= (uint32_t)mapped_len; mbuf_offset += (uint32_t)mapped_len; @@ -1086,7 +1075,7 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, } } - async_fill_iter(iter, tlen, iovec, tvec_idx); + async_fill_iter(iter, iovec, tvec_idx); out: return error; } From patchwork Mon Oct 18 13:02:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102032 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 1F658A0C43; Mon, 18 Oct 2021 15:04:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2FE8440DF5; Mon, 18 Oct 2021 15:04:08 +0200 (CEST) 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 0EA0540DDE for ; Mon, 18 Oct 2021 15:04:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562246; 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=ViTn7s8XQ+i7yeE6un41uHeb2HVO8tj61P3i3A4DHE4=; b=FYQjqKOHKFAIXDT+AtmXOncBvXRrfGXMY1dSxskHdez5PA9XTm+HWC1eucHh3SEE7BTUr8 0d/41kDkXe47+4o5wZ5jXWlSxH8tF+qQ7QiLrboTF4j++gxtmAAOh3o4iI8EKakiHVnuOV Gy5B0QBabhju7oqGfiOSivOMvcmjFK0= 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-585-edD8dU9cNY6VJ2X8wVXBJw-1; Mon, 18 Oct 2021 09:04:01 -0400 X-MC-Unique: edD8dU9cNY6VJ2X8wVXBJw-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 10D5E800685; Mon, 18 Oct 2021 13:03:59 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 638C41980E; Mon, 18 Oct 2021 13:03:53 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:23 +0200 Message-Id: <20211018130229.308694-9-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 08/14] vhost: improve IO vector logic 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" IO vectors and their iterators arrays were part of the async metadata but not their indexes. In order to makes this more consistent, the patch adds the indexes to the async metadata. Doing that, we can avoid triggering DMA transfer within the loop as it IO vector index overflow is now prevented in the async_mbuf_to_desc() function. Note that previous detection mechanism was broken since the overflow already happened when detected, so OOB memory access would already have happened. With this changes done, virtio_dev_rx_async_submit_split() and virtio_dev_rx_async_submit_packed() can be further simplified. Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.h | 2 + lib/vhost/virtio_net.c | 291 ++++++++++++++++++----------------------- 2 files changed, 131 insertions(+), 162 deletions(-) diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index dae9a1ac2d..812d4c55a5 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -134,6 +134,8 @@ struct vhost_async { struct rte_vhost_iov_iter iov_iter[VHOST_MAX_ASYNC_IT]; struct rte_vhost_iovec iovec[VHOST_MAX_ASYNC_VEC]; + uint16_t iter_idx; + uint16_t iovec_idx; /* data transfer status */ struct async_inflight_info *pkts_info; diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index ae7dded979..c80823a8de 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -924,33 +924,86 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, return error; } +static __rte_always_inline int +async_iter_initialize(struct vhost_async *async) +{ + struct rte_vhost_iov_iter *iter; + + if (unlikely(async->iovec_idx >= VHOST_MAX_ASYNC_VEC)) { + VHOST_LOG_DATA(ERR, "no more async iovec available\n"); + return -1; + } + + iter = async->iov_iter + async->iter_idx; + iter->iov = async->iovec + async->iovec_idx; + iter->nr_segs = 0; + + return 0; +} + +static __rte_always_inline int +async_iter_add_iovec(struct vhost_async *async, void *src, void *dst, size_t len) +{ + struct rte_vhost_iov_iter *iter; + struct rte_vhost_iovec *iovec; + + if (unlikely(async->iovec_idx >= VHOST_MAX_ASYNC_VEC)) { + VHOST_LOG_DATA(ERR, "no more async iovec available\n"); + return -1; + } + + iter = async->iov_iter + async->iter_idx; + iovec = async->iovec + async->iovec_idx; + + iovec->src_addr = src; + iovec->dst_addr = dst; + iovec->len = len; + + iter->nr_segs++; + async->iovec_idx++; + + return 0; +} + static __rte_always_inline void -async_fill_vec(struct rte_vhost_iovec *v, void *src, void *dst, size_t len) +async_iter_finalize(struct vhost_async *async) { - v->src_addr = src; - v->dst_addr = dst; - v->len = len; + async->iter_idx++; } static __rte_always_inline void -async_fill_iter(struct rte_vhost_iov_iter *it, struct rte_vhost_iovec *vec, unsigned long nr_seg) +async_iter_cancel(struct vhost_async *async) { - it->iov = vec; - it->nr_segs = nr_seg; + struct rte_vhost_iov_iter *iter; + + iter = async->iov_iter + async->iter_idx; + async->iovec_idx -= iter->nr_segs; + iter->nr_segs = 0; + iter->iov = NULL; } static __rte_always_inline void -async_fill_desc(struct rte_vhost_async_desc *desc, struct rte_vhost_iov_iter *iter) +async_iter_reset(struct vhost_async *async) { - desc->iter = iter; + async->iter_idx = 0; + async->iovec_idx = 0; +} + +static __rte_always_inline void +async_fill_descs(struct vhost_async *async, struct rte_vhost_async_desc *descs) +{ + int i; + + for (i = 0; i < async->iter_idx; i++) + descs[i].iter = async->iov_iter + i; } static __rte_always_inline int async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, struct rte_mbuf *m, struct buf_vector *buf_vec, - uint16_t nr_vec, uint16_t num_buffers, - struct rte_vhost_iovec *iovec, struct rte_vhost_iov_iter *iter) + uint16_t nr_vec, uint16_t num_buffers) { + struct vhost_async *async = vq->async; struct rte_mbuf *hdr_mbuf; struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL; uint64_t buf_addr, buf_iova; @@ -960,24 +1013,18 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, uint32_t mbuf_offset, mbuf_avail; uint32_t buf_offset, buf_avail; uint32_t cpy_len, buf_len; - int error = 0; - int tvec_idx = 0; void *hpa; - if (unlikely(m == NULL)) { - error = -1; - goto out; - } + if (unlikely(m == NULL)) + return -1; buf_addr = buf_vec[vec_idx].buf_addr; buf_iova = buf_vec[vec_idx].buf_iova; buf_len = buf_vec[vec_idx].buf_len; - if (unlikely(buf_len < dev->vhost_hlen && nr_vec <= 1)) { - error = -1; - goto out; - } + if (unlikely(buf_len < dev->vhost_hlen && nr_vec <= 1)) + return -1; hdr_mbuf = m; hdr_addr = buf_addr; @@ -1005,14 +1052,15 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, mbuf_avail = rte_pktmbuf_data_len(m); mbuf_offset = 0; + if (async_iter_initialize(async)) + return -1; + while (mbuf_avail != 0 || m->next != NULL) { /* done with current buf, get the next one */ if (buf_avail == 0) { vec_idx++; - if (unlikely(vec_idx >= nr_vec)) { - error = -1; - goto out; - } + if (unlikely(vec_idx >= nr_vec)) + goto error; buf_addr = buf_vec[vec_idx].buf_addr; buf_iova = buf_vec[vec_idx].buf_iova; @@ -1058,26 +1106,30 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, if (unlikely(!hpa)) { VHOST_LOG_DATA(ERR, "(%d) %s: failed to get hpa.\n", dev->vid, __func__); - error = -1; - goto out; + goto error; } - async_fill_vec(iovec + tvec_idx, - (void *)(uintptr_t)rte_pktmbuf_iova_offset(m, - mbuf_offset), hpa, (size_t)mapped_len); + if (unlikely(async_iter_add_iovec(async, + (void *)(uintptr_t)rte_pktmbuf_iova_offset(m, + mbuf_offset), + hpa, (size_t)mapped_len))) + goto error; cpy_len -= (uint32_t)mapped_len; mbuf_avail -= (uint32_t)mapped_len; mbuf_offset += (uint32_t)mapped_len; buf_avail -= (uint32_t)mapped_len; buf_offset += (uint32_t)mapped_len; - tvec_idx++; } } - async_fill_iter(iter, iovec, tvec_idx); -out: - return error; + async_iter_finalize(async); + + return 0; +error: + async_iter_cancel(async); + + return -1; } static __rte_always_inline int @@ -1487,18 +1539,16 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, struct rte_mbuf **pkts, uint32_t count) { struct buf_vector buf_vec[BUF_VECTOR_MAX]; - uint32_t pkt_idx = 0, pkt_burst_idx = 0; + uint32_t pkt_idx = 0; uint16_t num_buffers; uint16_t avail_head; struct vhost_async *async = vq->async; - struct rte_vhost_iov_iter *iter = async->iov_iter; - struct rte_vhost_async_desc tdes[MAX_PKT_BURST]; - struct rte_vhost_iovec *iovec = async->iovec; + struct rte_vhost_async_desc async_descs[MAX_PKT_BURST]; struct async_inflight_info *pkts_info = async->pkts_info; - uint32_t n_pkts = 0, pkt_err = 0; + uint32_t pkt_err = 0; int32_t n_xfer; - uint16_t iovec_idx = 0, it_idx = 0, slot_idx = 0; + uint16_t slot_idx = 0; /* * The ordering between avail index and desc reads need to be enforced. @@ -1507,95 +1557,53 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, rte_prefetch0(&vq->avail->ring[vq->last_avail_idx & (vq->size - 1)]); + async_iter_reset(async); + for (pkt_idx = 0; pkt_idx < count; pkt_idx++) { uint32_t pkt_len = pkts[pkt_idx]->pkt_len + dev->vhost_hlen; uint16_t nr_vec = 0; - if (unlikely(reserve_avail_buf_split(dev, vq, - pkt_len, buf_vec, &num_buffers, - avail_head, &nr_vec) < 0)) { - VHOST_LOG_DATA(DEBUG, - "(%d) failed to get enough desc from vring\n", - dev->vid); + if (unlikely(reserve_avail_buf_split(dev, vq, pkt_len, buf_vec, + &num_buffers, avail_head, &nr_vec) < 0)) { + VHOST_LOG_DATA(DEBUG, "(%d) failed to get enough desc from vring\n", + dev->vid); vq->shadow_used_idx -= num_buffers; break; } VHOST_LOG_DATA(DEBUG, "(%d) current index %d | end index %d\n", - dev->vid, vq->last_avail_idx, - vq->last_avail_idx + num_buffers); + dev->vid, vq->last_avail_idx, vq->last_avail_idx + num_buffers); - if (async_mbuf_to_desc(dev, vq, pkts[pkt_idx], buf_vec, nr_vec, num_buffers, - &iovec[iovec_idx], &iter[it_idx]) < 0) { + if (async_mbuf_to_desc(dev, vq, pkts[pkt_idx], buf_vec, nr_vec, num_buffers) < 0) { vq->shadow_used_idx -= num_buffers; break; } - async_fill_desc(&tdes[pkt_burst_idx++], &iter[it_idx]); - slot_idx = (async->pkts_idx + pkt_idx) & (vq->size - 1); pkts_info[slot_idx].descs = num_buffers; pkts_info[slot_idx].mbuf = pkts[pkt_idx]; - iovec_idx += iter[it_idx].nr_segs; - it_idx++; - vq->last_avail_idx += num_buffers; + } - /* - * condition to trigger async device transfer: - * - unused async iov number is less than max vhost vector - */ - if (unlikely(VHOST_MAX_ASYNC_VEC - iovec_idx < BUF_VECTOR_MAX)) { - n_xfer = async->ops.transfer_data(dev->vid, - queue_id, tdes, 0, pkt_burst_idx); - if (likely(n_xfer >= 0)) { - n_pkts = n_xfer; - } else { - VHOST_LOG_DATA(ERR, - "(%d) %s: failed to transfer data for queue id %d.\n", - dev->vid, __func__, queue_id); - n_pkts = 0; - } - - iovec_idx = 0; - it_idx = 0; - - if (unlikely(n_pkts < pkt_burst_idx)) { - /* - * log error packets number here and do actual - * error processing when applications poll - * completion - */ - pkt_err = pkt_burst_idx - n_pkts; - pkt_idx++; - pkt_burst_idx = 0; - break; - } + if (unlikely(pkt_idx == 0)) + return 0; - pkt_burst_idx = 0; - } - } + async_fill_descs(async, async_descs); - if (pkt_burst_idx) { - n_xfer = async->ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); - if (likely(n_xfer >= 0)) { - n_pkts = n_xfer; - } else { - VHOST_LOG_DATA(ERR, "(%d) %s: failed to transfer data for queue id %d.\n", + n_xfer = async->ops.transfer_data(dev->vid, queue_id, async_descs, 0, pkt_idx); + if (unlikely(n_xfer < 0)) { + VHOST_LOG_DATA(ERR, "(%d) %s: failed to transfer data for queue id %d.\n", dev->vid, __func__, queue_id); - n_pkts = 0; - } - - if (unlikely(n_pkts < pkt_burst_idx)) - pkt_err = pkt_burst_idx - n_pkts; + n_xfer = 0; } + pkt_err = pkt_idx - n_xfer; if (unlikely(pkt_err)) { uint16_t num_descs = 0; /* update number of completed packets */ - pkt_idx -= pkt_err; + pkt_idx = n_xfer; /* calculate the sum of descriptors to revert */ while (pkt_err-- > 0) { @@ -1686,9 +1694,7 @@ vhost_enqueue_async_packed(struct virtio_net *dev, struct rte_mbuf *pkt, struct buf_vector *buf_vec, uint16_t *nr_descs, - uint16_t *nr_buffers, - struct rte_vhost_iovec *iovec, - struct rte_vhost_iov_iter *iter) + uint16_t *nr_buffers) { uint16_t nr_vec = 0; uint16_t avail_idx = vq->last_avail_idx; @@ -1736,7 +1742,7 @@ vhost_enqueue_async_packed(struct virtio_net *dev, } if (unlikely(async_mbuf_to_desc(dev, vq, pkt, buf_vec, nr_vec, - *nr_buffers, iovec, iter) < 0)) + *nr_buffers) < 0)) return -1; vhost_shadow_enqueue_packed(vq, buffer_len, buffer_buf_id, buffer_desc_count, *nr_buffers); @@ -1746,13 +1752,12 @@ vhost_enqueue_async_packed(struct virtio_net *dev, static __rte_always_inline int16_t virtio_dev_rx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, - struct rte_mbuf *pkt, uint16_t *nr_descs, uint16_t *nr_buffers, - struct rte_vhost_iovec *iovec, struct rte_vhost_iov_iter *iter) + struct rte_mbuf *pkt, uint16_t *nr_descs, uint16_t *nr_buffers) { struct buf_vector buf_vec[BUF_VECTOR_MAX]; - if (unlikely(vhost_enqueue_async_packed(dev, vq, pkt, buf_vec, nr_descs, nr_buffers, - iovec, iter) < 0)) { + if (unlikely(vhost_enqueue_async_packed(dev, vq, pkt, buf_vec, + nr_descs, nr_buffers) < 0)) { VHOST_LOG_DATA(DEBUG, "(%d) failed to get enough desc from vring\n", dev->vid); return -1; } @@ -1794,20 +1799,17 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, struct vhost_virtqueue *vq, uint16_t queue_id, struct rte_mbuf **pkts, uint32_t count) { - uint32_t pkt_idx = 0, pkt_burst_idx = 0; + uint32_t pkt_idx = 0; uint32_t remained = count; int32_t n_xfer; uint16_t num_buffers; uint16_t num_descs; struct vhost_async *async = vq->async; - struct rte_vhost_iov_iter *iter = async->iov_iter; - struct rte_vhost_async_desc tdes[MAX_PKT_BURST]; - struct rte_vhost_iovec *iovec = async->iovec; + struct rte_vhost_async_desc async_descs[MAX_PKT_BURST]; struct async_inflight_info *pkts_info = async->pkts_info; - uint32_t n_pkts = 0, pkt_err = 0; + uint32_t pkt_err = 0; uint16_t slot_idx = 0; - uint16_t iovec_idx = 0, it_idx = 0; do { rte_prefetch0(&vq->desc_packed[vq->last_avail_idx]); @@ -1815,71 +1817,36 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, num_buffers = 0; num_descs = 0; if (unlikely(virtio_dev_rx_async_packed(dev, vq, pkts[pkt_idx], - &num_descs, &num_buffers, - &iovec[iovec_idx], &iter[it_idx]) < 0)) + &num_descs, &num_buffers) < 0)) break; slot_idx = (async->pkts_idx + pkt_idx) % vq->size; - async_fill_desc(&tdes[pkt_burst_idx++], &iter[it_idx]); pkts_info[slot_idx].descs = num_descs; pkts_info[slot_idx].nr_buffers = num_buffers; pkts_info[slot_idx].mbuf = pkts[pkt_idx]; - iovec_idx += iter[it_idx].nr_segs; - it_idx++; pkt_idx++; remained--; vq_inc_last_avail_packed(vq, num_descs); + } while (pkt_idx < count); - /* - * condition to trigger async device transfer: - * - unused async iov number is less than max vhost vector - */ - if (unlikely(VHOST_MAX_ASYNC_VEC - iovec_idx < BUF_VECTOR_MAX)) { - n_xfer = async->ops.transfer_data(dev->vid, - queue_id, tdes, 0, pkt_burst_idx); - if (likely(n_xfer >= 0)) { - n_pkts = n_xfer; - } else { - VHOST_LOG_DATA(ERR, - "(%d) %s: failed to transfer data for queue id %d.\n", - dev->vid, __func__, queue_id); - n_pkts = 0; - } - - iovec_idx = 0; - it_idx = 0; - - if (unlikely(n_pkts < pkt_burst_idx)) { - /* - * log error packets number here and do actual - * error processing when applications poll - * completion - */ - pkt_err = pkt_burst_idx - n_pkts; - pkt_burst_idx = 0; - break; - } + if (unlikely(pkt_idx == 0)) + return 0; - pkt_burst_idx = 0; - } - } while (pkt_idx < count); + async_fill_descs(async, async_descs); - if (pkt_burst_idx) { - n_xfer = async->ops.transfer_data(dev->vid, queue_id, tdes, 0, pkt_burst_idx); - if (likely(n_xfer >= 0)) { - n_pkts = n_xfer; - } else { - VHOST_LOG_DATA(ERR, "(%d) %s: failed to transfer data for queue id %d.\n", + n_xfer = async->ops.transfer_data(dev->vid, queue_id, async_descs, 0, pkt_idx); + if (unlikely(n_xfer < 0)) { + VHOST_LOG_DATA(ERR, "(%d) %s: failed to transfer data for queue id %d.\n", dev->vid, __func__, queue_id); - n_pkts = 0; - } - - if (unlikely(n_pkts < pkt_burst_idx)) - pkt_err = pkt_burst_idx - n_pkts; + n_xfer = 0; } + pkt_err = pkt_idx - n_xfer; + + async_iter_reset(async); + if (unlikely(pkt_err)) dma_error_handler_packed(vq, slot_idx, pkt_err, &pkt_idx); From patchwork Mon Oct 18 13:02:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102033 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 1F8FBA0C43; Mon, 18 Oct 2021 15:04:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 350AE410FE; Mon, 18 Oct 2021 15:04:12 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 95700410F1 for ; Mon, 18 Oct 2021 15:04:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562250; 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=y8DywlaxYL20S46X7g6L4popFbs/nhHmYuqocqrRxjw=; b=Pf1+LsfV9RHGKp4HsZv0RUCThndBBVByKCvaZyxk3TuTiXnOPEwlAmH1VuS1OkL+HBrULE uqsRkVVyLrsGYq+yAdr1SvY6iqxb3tBXMWTAt6fHLcP6CK+E/ZXreljmQhNLt9Qpa+gvus JL9nbIQMIIwsTU2Lhhf9XYPhufneyNo= 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-62-9Xxpno8vNB6wQQUCPnSyEg-1; Mon, 18 Oct 2021 09:04:06 -0400 X-MC-Unique: 9Xxpno8vNB6wQQUCPnSyEg-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 5C4E91B18BC1; Mon, 18 Oct 2021 13:04:04 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71FDF60BD8; Mon, 18 Oct 2021 13:03:59 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:24 +0200 Message-Id: <20211018130229.308694-10-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 09/14] vhost: remove notion of async descriptor 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" Now that IO vectors iterator have been simplified, the rte_vhost_async_desc struct only contains a pointer on the iterator array stored in the async metadata. This patch removes it, and pass directly the iterators array pointer to the transfer_data callback. Doing that, we avoid declaring the descriptor array in the stack, and also avoid the cost of filling it. Signed-off-by: Maxime Coquelin --- examples/vhost/ioat.c | 10 +++++----- examples/vhost/ioat.h | 2 +- lib/vhost/rte_vhost_async.h | 16 ++++------------ lib/vhost/virtio_net.c | 19 ++----------------- 4 files changed, 12 insertions(+), 35 deletions(-) diff --git a/examples/vhost/ioat.c b/examples/vhost/ioat.c index a8c588deff..9aeeb12fd9 100644 --- a/examples/vhost/ioat.c +++ b/examples/vhost/ioat.c @@ -124,10 +124,10 @@ open_ioat(const char *value) int32_t ioat_transfer_data_cb(int vid, uint16_t queue_id, - struct rte_vhost_async_desc *descs, + struct rte_vhost_iov_iter *iov_iter, struct rte_vhost_async_status *opaque_data, uint16_t count) { - uint32_t i_desc; + uint32_t i_iter; uint16_t dev_id = dma_bind[vid].dmas[queue_id * 2 + VIRTIO_RXQ].dev_id; struct rte_vhost_iov_iter *iter = NULL; unsigned long i_seg; @@ -135,8 +135,8 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, unsigned short write = cb_tracker[dev_id].next_write; if (!opaque_data) { - for (i_desc = 0; i_desc < count; i_desc++) { - iter = descs[i_desc].iter; + for (i_iter = 0; i_iter < count; i_iter++) { + iter = iov_iter + i_iter; i_seg = 0; if (cb_tracker[dev_id].ioat_space < iter->nr_segs) break; @@ -161,7 +161,7 @@ ioat_transfer_data_cb(int vid, uint16_t queue_id, /* ring the doorbell */ rte_ioat_perform_ops(dev_id); cb_tracker[dev_id].next_write = write; - return i_desc; + return i_iter; } int32_t diff --git a/examples/vhost/ioat.h b/examples/vhost/ioat.h index 62e163c585..a4f09ee39b 100644 --- a/examples/vhost/ioat.h +++ b/examples/vhost/ioat.h @@ -29,7 +29,7 @@ int open_ioat(const char *value); int32_t ioat_transfer_data_cb(int vid, uint16_t queue_id, - struct rte_vhost_async_desc *descs, + struct rte_vhost_iov_iter *iov_iter, struct rte_vhost_async_status *opaque_data, uint16_t count); int32_t diff --git a/lib/vhost/rte_vhost_async.h b/lib/vhost/rte_vhost_async.h index 4ea5cfab10..a87ea6ba37 100644 --- a/lib/vhost/rte_vhost_async.h +++ b/lib/vhost/rte_vhost_async.h @@ -26,14 +26,6 @@ struct rte_vhost_iov_iter { unsigned long nr_segs; }; -/** - * dma transfer descriptor - */ -struct rte_vhost_async_desc { - /* memory iov_iter */ - struct rte_vhost_iov_iter *iter; -}; - /** * dma transfer status */ @@ -55,17 +47,17 @@ struct rte_vhost_async_channel_ops { * id of vhost device to perform data copies * @param queue_id * queue id to perform data copies - * @param descs - * an array of DMA transfer memory descriptors + * @param iov_iter + * an array of IOV iterators * @param opaque_data * opaque data pair sending to DMA engine * @param count * number of elements in the "descs" array * @return - * number of descs processed, negative value means error + * number of IOV iterators processed, negative value means error */ int32_t (*transfer_data)(int vid, uint16_t queue_id, - struct rte_vhost_async_desc *descs, + struct rte_vhost_iov_iter *iov_iter, struct rte_vhost_async_status *opaque_data, uint16_t count); /** diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index c80823a8de..9b2d22dea2 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -989,15 +989,6 @@ async_iter_reset(struct vhost_async *async) async->iovec_idx = 0; } -static __rte_always_inline void -async_fill_descs(struct vhost_async *async, struct rte_vhost_async_desc *descs) -{ - int i; - - for (i = 0; i < async->iter_idx; i++) - descs[i].iter = async->iov_iter + i; -} - static __rte_always_inline int async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, struct rte_mbuf *m, struct buf_vector *buf_vec, @@ -1544,7 +1535,6 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, uint16_t avail_head; struct vhost_async *async = vq->async; - struct rte_vhost_async_desc async_descs[MAX_PKT_BURST]; struct async_inflight_info *pkts_info = async->pkts_info; uint32_t pkt_err = 0; int32_t n_xfer; @@ -1589,9 +1579,7 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, if (unlikely(pkt_idx == 0)) return 0; - async_fill_descs(async, async_descs); - - n_xfer = async->ops.transfer_data(dev->vid, queue_id, async_descs, 0, pkt_idx); + n_xfer = async->ops.transfer_data(dev->vid, queue_id, async->iov_iter, 0, pkt_idx); if (unlikely(n_xfer < 0)) { VHOST_LOG_DATA(ERR, "(%d) %s: failed to transfer data for queue id %d.\n", dev->vid, __func__, queue_id); @@ -1806,7 +1794,6 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, uint16_t num_descs; struct vhost_async *async = vq->async; - struct rte_vhost_async_desc async_descs[MAX_PKT_BURST]; struct async_inflight_info *pkts_info = async->pkts_info; uint32_t pkt_err = 0; uint16_t slot_idx = 0; @@ -1834,9 +1821,7 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, if (unlikely(pkt_idx == 0)) return 0; - async_fill_descs(async, async_descs); - - n_xfer = async->ops.transfer_data(dev->vid, queue_id, async_descs, 0, pkt_idx); + n_xfer = async->ops.transfer_data(dev->vid, queue_id, async->iov_iter, 0, pkt_idx); if (unlikely(n_xfer < 0)) { VHOST_LOG_DATA(ERR, "(%d) %s: failed to transfer data for queue id %d.\n", dev->vid, __func__, queue_id); From patchwork Mon Oct 18 13:02:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102035 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 C02F1A0C43; Mon, 18 Oct 2021 15:04:39 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 38BF84113A; Mon, 18 Oct 2021 15:04:16 +0200 (CEST) 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 CB58A41109 for ; Mon, 18 Oct 2021 15:04:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562253; 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=uzbEHteBa+eWkNbXpr/xkypme/ddjjhL4KdhYZKs65I=; b=KXTq/BK0Bkp7V8Q/iNy4dQErQqis22gBYuU/FUOYhTdiPC4x+SX8Fjazy5QSIlPj9wr6Tu ukVzbBzZoCpzVdqr37HRgO59hqjfkKQeNpzWdfUFpiklB86g2SWXRDvzB3jJH1CL81XNCP m1wHIu3vkwEvmfoaklDhgcNBHm21uSk= 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-343-3XTFgMfEMCO9CUwhyGH_Zg-1; Mon, 18 Oct 2021 09:04:08 -0400 X-MC-Unique: 3XTFgMfEMCO9CUwhyGH_Zg-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 A6421100B709; Mon, 18 Oct 2021 13:04:06 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id B259569C83; Mon, 18 Oct 2021 13:04:04 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:25 +0200 Message-Id: <20211018130229.308694-11-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 10/14] vhost: simplify async enqueue completion 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" vhost_poll_enqueue_completed() assumes some inflight packets could have been completed in a previous call but not returned to the application. But this is not the case, since check_completed_copies callback is never called with more than the current count as argument. In other words, async->last_pkts_n is always 0. Removing it greatly simplfies the function. Signed-off-by: Maxime Coquelin --- lib/vhost/vhost.h | 1 - lib/vhost/virtio_net.c | 76 ++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 49 deletions(-) diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index 812d4c55a5..1a2cd21a1d 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -141,7 +141,6 @@ struct vhost_async { struct async_inflight_info *pkts_info; uint16_t pkts_idx; uint16_t pkts_inflight_n; - uint16_t last_pkts_n; union { struct vring_used_elem *descs_split; struct vring_used_elem_packed *buffers_packed; diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 9b2d22dea2..4ab560c2f4 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1613,7 +1613,11 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, vq->shadow_used_idx); async->desc_idx_split += vq->shadow_used_idx; + async->pkts_idx += pkt_idx; + if (async->pkts_idx >= vq->size) + async->pkts_idx -= vq->size; + async->pkts_inflight_n += pkt_idx; vq->shadow_used_idx = 0; } @@ -1915,68 +1919,44 @@ static __rte_always_inline uint16_t vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, struct rte_mbuf **pkts, uint16_t count) { - struct vhost_virtqueue *vq; - struct vhost_async *async; - struct async_inflight_info *pkts_info; + struct vhost_virtqueue *vq = dev->virtqueue[queue_id]; + struct vhost_async *async = vq->async; + struct async_inflight_info *pkts_info = async->pkts_info; int32_t n_cpl; - uint16_t n_pkts_cpl = 0, n_pkts_put = 0, n_descs = 0, n_buffers = 0; - uint16_t start_idx, pkts_idx, vq_size; - uint16_t from, i; + uint16_t n_descs = 0, n_buffers = 0; + uint16_t start_idx, from, i; - vq = dev->virtqueue[queue_id]; - async = vq->async; - pkts_idx = async->pkts_idx % vq->size; - pkts_info = async->pkts_info; - vq_size = vq->size; - start_idx = virtio_dev_rx_async_get_info_idx(pkts_idx, - vq_size, async->pkts_inflight_n); - - if (count > async->last_pkts_n) { - n_cpl = async->ops.check_completed_copies(dev->vid, - queue_id, 0, count - async->last_pkts_n); - if (likely(n_cpl >= 0)) { - n_pkts_cpl = n_cpl; - } else { - VHOST_LOG_DATA(ERR, - "(%d) %s: failed to check completed copies for queue id %d.\n", + start_idx = virtio_dev_rx_async_get_info_idx(async->pkts_idx, + vq->size, async->pkts_inflight_n); + + n_cpl = async->ops.check_completed_copies(dev->vid, queue_id, 0, count); + if (unlikely(n_cpl < 0)) { + VHOST_LOG_DATA(ERR, "(%d) %s: failed to check completed copies for queue id %d.\n", dev->vid, __func__, queue_id); - n_pkts_cpl = 0; - } + return 0; } - n_pkts_cpl += async->last_pkts_n; - n_pkts_put = RTE_MIN(n_pkts_cpl, count); - if (unlikely(n_pkts_put == 0)) { - async->last_pkts_n = n_pkts_cpl; + if (n_cpl == 0) return 0; - } - if (vq_is_packed(dev)) { - for (i = 0; i < n_pkts_put; i++) { - from = (start_idx + i) % vq_size; - n_buffers += pkts_info[from].nr_buffers; - pkts[i] = pkts_info[from].mbuf; - } - } else { - for (i = 0; i < n_pkts_put; i++) { - from = (start_idx + i) & (vq_size - 1); - n_descs += pkts_info[from].descs; - pkts[i] = pkts_info[from].mbuf; - } + for (i = 0; i < n_cpl; i++) { + from = (start_idx + i) % vq->size; + /* Only used with packed ring */ + n_buffers += pkts_info[from].nr_buffers; + /* Only used with split ring */ + n_descs += pkts_info[from].descs; + pkts[i] = pkts_info[from].mbuf; } - async->last_pkts_n = n_pkts_cpl - n_pkts_put; - async->pkts_inflight_n -= n_pkts_put; + + async->pkts_inflight_n -= n_cpl; if (likely(vq->enabled && vq->access_ok)) { if (vq_is_packed(dev)) { write_back_completed_descs_packed(vq, n_buffers); - vhost_vring_call_packed(dev, vq); } else { write_back_completed_descs_split(vq, n_descs); - - __atomic_add_fetch(&vq->used->idx, n_descs, - __ATOMIC_RELEASE); + __atomic_add_fetch(&vq->used->idx, n_descs, __ATOMIC_RELEASE); vhost_vring_call_split(dev, vq); } } else { @@ -1989,7 +1969,7 @@ vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, } } - return n_pkts_put; + return n_cpl; } uint16_t From patchwork Mon Oct 18 13:02:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102034 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 6816AA0C43; Mon, 18 Oct 2021 15:04:33 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 21AF14111C; Mon, 18 Oct 2021 15:04:14 +0200 (CEST) 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 0EAD040141 for ; Mon, 18 Oct 2021 15:04:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562251; 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=QOhMas54VkoPAUOJboJRxNHFdgyLJIM1og16gUZfJf4=; b=C/2yJyVVunBOEE5c1dHx38bFB93jeJhunoy5tj72BUG8vLXMiReerrVLaVTYTzkOh6A8NE 3lmSN1RxJziNBwW4qpydimso8UNAK5W288PVLvDrpnC2klMi2STdXjfus1pLS3ZC/fK7+l spNiA5o2GfgJpQKjpyslKi5qFP21G2o= 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-415-iPhyV5spPwyXoGRklkKsVA-1; Mon, 18 Oct 2021 09:04:10 -0400 X-MC-Unique: iPhyV5spPwyXoGRklkKsVA-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 E1CF1800685; Mon, 18 Oct 2021 13:04:08 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id F15186911C; Mon, 18 Oct 2021 13:04:06 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:26 +0200 Message-Id: <20211018130229.308694-12-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 11/14] vhost: simplify getting the first in-flight index 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 reworks the function getting the index for the first packet in-flight. When this index turns out to be zero, let's use the simple path. Doing that avoid having to do a modulo with the virtqueue size. The patch also rename the function for better clarifty, and only pass the virtqueue metadata pointer, as all the needed information are stored there. Signed-off-by: Maxime Coquelin --- lib/vhost/virtio_net.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 4ab560c2f4..eca00af8c8 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1484,11 +1484,14 @@ rte_vhost_enqueue_burst(int vid, uint16_t queue_id, } static __rte_always_inline uint16_t -virtio_dev_rx_async_get_info_idx(uint16_t pkts_idx, - uint16_t vq_size, uint16_t n_inflight) +async_get_first_inflight_pkt_idx(struct vhost_virtqueue *vq) { - return pkts_idx > n_inflight ? (pkts_idx - n_inflight) : - (vq_size - n_inflight + pkts_idx) % vq_size; + struct vhost_async *async = vq->async; + + if (async->pkts_idx >= async->pkts_inflight_n) + return async->pkts_idx - async->pkts_inflight_n; + else + return vq->size - async->pkts_inflight_n + async->pkts_idx; } static __rte_always_inline void @@ -1926,9 +1929,6 @@ vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, uint16_t n_descs = 0, n_buffers = 0; uint16_t start_idx, from, i; - start_idx = virtio_dev_rx_async_get_info_idx(async->pkts_idx, - vq->size, async->pkts_inflight_n); - n_cpl = async->ops.check_completed_copies(dev->vid, queue_id, 0, count); if (unlikely(n_cpl < 0)) { VHOST_LOG_DATA(ERR, "(%d) %s: failed to check completed copies for queue id %d.\n", @@ -1939,6 +1939,8 @@ vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, if (n_cpl == 0) return 0; + start_idx = async_get_first_inflight_pkt_idx(vq); + for (i = 0; i < n_cpl; i++) { from = (start_idx + i) % vq->size; /* Only used with packed ring */ From patchwork Mon Oct 18 13:02:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102036 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 6FAA7A0C43; Mon, 18 Oct 2021 15:04:47 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A72F641125; Mon, 18 Oct 2021 15:04:24 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 3BC624111A for ; Mon, 18 Oct 2021 15:04:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562262; 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=e1DjHbuZ26Y9xNDJPLY1feyHzQ8aatpECKmt2dj2NVA=; b=L/cHznvNsGxcZHeWNLGBXGKi0s5mSvCpHPWTCXUrCV+Tl0BNiVMLpIcgCI/MmUNoT8dGho ny0gG11ayq5Gk90DHeOjx8a57Vsq5U9yTrSld3VPPMf5G/Zqoi57m2e54bUkilXLeokDOh ZePm8hcv00CidSBhkL8oTJxotEtJM0k= 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-132-vTunA0GFMzmQozZf2YaY_w-1; Mon, 18 Oct 2021 09:04:21 -0400 X-MC-Unique: vTunA0GFMzmQozZf2YaY_w-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 B27E080ED95; Mon, 18 Oct 2021 13:04:19 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E10B69119; Mon, 18 Oct 2021 13:04:09 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:27 +0200 Message-Id: <20211018130229.308694-13-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 12/14] vhost: prepare async for mbuf to desc refactoring 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 extracts the IO vectors filling from async_mbuf_to_desc() into a dedicated function as a preliminary step of merging copy_mubf_to_desc() and async_mbuf_to_desc(). Signed-off-by: Maxime Coquelin --- lib/vhost/virtio_net.c | 194 ++++++++++++++++++++++------------------- 1 file changed, 105 insertions(+), 89 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index eca00af8c8..9d3337abad 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -791,6 +791,103 @@ copy_vnet_hdr_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, } } +static __rte_always_inline int +async_iter_initialize(struct vhost_async *async) +{ + struct rte_vhost_iov_iter *iter; + + if (unlikely(async->iovec_idx >= VHOST_MAX_ASYNC_VEC)) { + VHOST_LOG_DATA(ERR, "no more async iovec available\n"); + return -1; + } + + iter = async->iov_iter + async->iter_idx; + iter->iov = async->iovec + async->iovec_idx; + iter->nr_segs = 0; + + return 0; +} + +static __rte_always_inline int +async_iter_add_iovec(struct vhost_async *async, void *src, void *dst, size_t len) +{ + struct rte_vhost_iov_iter *iter; + struct rte_vhost_iovec *iovec; + + if (unlikely(async->iovec_idx >= VHOST_MAX_ASYNC_VEC)) { + VHOST_LOG_DATA(ERR, "no more async iovec available\n"); + return -1; + } + + iter = async->iov_iter + async->iter_idx; + iovec = async->iovec + async->iovec_idx; + + iovec->src_addr = src; + iovec->dst_addr = dst; + iovec->len = len; + + iter->nr_segs++; + async->iovec_idx++; + + return 0; +} + +static __rte_always_inline void +async_iter_finalize(struct vhost_async *async) +{ + async->iter_idx++; +} + +static __rte_always_inline void +async_iter_cancel(struct vhost_async *async) +{ + struct rte_vhost_iov_iter *iter; + + iter = async->iov_iter + async->iter_idx; + async->iovec_idx -= iter->nr_segs; + iter->nr_segs = 0; + iter->iov = NULL; +} + +static __rte_always_inline void +async_iter_reset(struct vhost_async *async) +{ + async->iter_idx = 0; + async->iovec_idx = 0; +} + +static __rte_always_inline int +async_mbuf_to_desc_seg(struct virtio_net *dev, struct vhost_virtqueue *vq, + struct rte_mbuf *m, uint32_t mbuf_offset, + uint64_t buf_iova, uint32_t cpy_len) +{ + struct vhost_async *async = vq->async; + uint64_t mapped_len; + uint32_t buf_offset = 0; + void *hpa; + + while (cpy_len) { + hpa = (void *)(uintptr_t)gpa_to_first_hpa(dev, + buf_iova + buf_offset, cpy_len, &mapped_len); + if (unlikely(!hpa)) { + VHOST_LOG_DATA(ERR, "(%d) %s: failed to get hpa.\n", dev->vid, __func__); + return -1; + } + + if (unlikely(async_iter_add_iovec(async, + (void *)(uintptr_t)rte_pktmbuf_iova_offset(m, + mbuf_offset), + hpa, (size_t)mapped_len))) + return -1; + + cpy_len -= (uint32_t)mapped_len; + mbuf_offset += (uint32_t)mapped_len; + buf_offset += (uint32_t)mapped_len; + } + + return 0; +} + static __rte_always_inline int copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, struct rte_mbuf *m, struct buf_vector *buf_vec, @@ -924,71 +1021,6 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, return error; } -static __rte_always_inline int -async_iter_initialize(struct vhost_async *async) -{ - struct rte_vhost_iov_iter *iter; - - if (unlikely(async->iovec_idx >= VHOST_MAX_ASYNC_VEC)) { - VHOST_LOG_DATA(ERR, "no more async iovec available\n"); - return -1; - } - - iter = async->iov_iter + async->iter_idx; - iter->iov = async->iovec + async->iovec_idx; - iter->nr_segs = 0; - - return 0; -} - -static __rte_always_inline int -async_iter_add_iovec(struct vhost_async *async, void *src, void *dst, size_t len) -{ - struct rte_vhost_iov_iter *iter; - struct rte_vhost_iovec *iovec; - - if (unlikely(async->iovec_idx >= VHOST_MAX_ASYNC_VEC)) { - VHOST_LOG_DATA(ERR, "no more async iovec available\n"); - return -1; - } - - iter = async->iov_iter + async->iter_idx; - iovec = async->iovec + async->iovec_idx; - - iovec->src_addr = src; - iovec->dst_addr = dst; - iovec->len = len; - - iter->nr_segs++; - async->iovec_idx++; - - return 0; -} - -static __rte_always_inline void -async_iter_finalize(struct vhost_async *async) -{ - async->iter_idx++; -} - -static __rte_always_inline void -async_iter_cancel(struct vhost_async *async) -{ - struct rte_vhost_iov_iter *iter; - - iter = async->iov_iter + async->iter_idx; - async->iovec_idx -= iter->nr_segs; - iter->nr_segs = 0; - iter->iov = NULL; -} - -static __rte_always_inline void -async_iter_reset(struct vhost_async *async) -{ - async->iter_idx = 0; - async->iovec_idx = 0; -} - static __rte_always_inline int async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, struct rte_mbuf *m, struct buf_vector *buf_vec, @@ -999,14 +1031,11 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL; uint64_t buf_addr, buf_iova; uint64_t hdr_addr; - uint64_t mapped_len; uint32_t vec_idx = 0; uint32_t mbuf_offset, mbuf_avail; uint32_t buf_offset, buf_avail; uint32_t cpy_len, buf_len; - void *hpa; - if (unlikely(m == NULL)) return -1; @@ -1090,28 +1119,15 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, cpy_len = RTE_MIN(buf_avail, mbuf_avail); - while (unlikely(cpy_len)) { - hpa = (void *)(uintptr_t)gpa_to_first_hpa(dev, - buf_iova + buf_offset, - cpy_len, &mapped_len); - if (unlikely(!hpa)) { - VHOST_LOG_DATA(ERR, "(%d) %s: failed to get hpa.\n", - dev->vid, __func__); - goto error; - } - - if (unlikely(async_iter_add_iovec(async, - (void *)(uintptr_t)rte_pktmbuf_iova_offset(m, - mbuf_offset), - hpa, (size_t)mapped_len))) - goto error; - - cpy_len -= (uint32_t)mapped_len; - mbuf_avail -= (uint32_t)mapped_len; - mbuf_offset += (uint32_t)mapped_len; - buf_avail -= (uint32_t)mapped_len; - buf_offset += (uint32_t)mapped_len; + if (async_mbuf_to_desc_seg(dev, vq, m, mbuf_offset, + buf_iova + buf_offset, cpy_len) < 0) { + goto error; } + + mbuf_avail -= cpy_len; + mbuf_offset += cpy_len; + buf_avail -= cpy_len; + buf_offset += cpy_len; } async_iter_finalize(async); From patchwork Mon Oct 18 13:02:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102037 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 01131A0C43; Mon, 18 Oct 2021 15:04:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9C1F4410EE; Mon, 18 Oct 2021 15:04:29 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 112B4410E7 for ; Mon, 18 Oct 2021 15:04:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562267; 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=nWhWatzc9KvFEd02jQ4Je9TiQ+GSF830ysz/0c789hc=; b=WQrRw6EePTw8NyoklWwGRTKfy5Wmu1Z7DRlVwjv+MaPzCo90z4FYQFknfJeFUq+MVvhDcM AxwP5kJF+WgCtPzTw5bLTvdwwoLa+Xa+BYJk9zVa6J63h7NCCTjkJMS/uzDCJmBbov0geb 9ffCmx+DHxml9ShaqBVdy6Pb7BXHoOc= 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-434-1NW0Cy9uMsaZ1HCzzahraQ-1; Mon, 18 Oct 2021 09:04:26 -0400 X-MC-Unique: 1NW0Cy9uMsaZ1HCzzahraQ-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 5336687301D; Mon, 18 Oct 2021 13:04:25 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13FAF60BD8; Mon, 18 Oct 2021 13:04:19 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:28 +0200 Message-Id: <20211018130229.308694-14-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 13/14] vhost: prepare sync for mbuf to desc refactoring 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 extracts the descriptors buffers filling from copy_mbuf_to_desc() into a dedicated function as a preliminary step of merging copy_mubf_to_desc() and async_mbuf_to_desc(). Signed-off-by: Maxime Coquelin --- lib/vhost/virtio_net.c | 73 +++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 9d3337abad..7e66113006 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -888,6 +888,30 @@ async_mbuf_to_desc_seg(struct virtio_net *dev, struct vhost_virtqueue *vq, return 0; } +static __rte_always_inline void +sync_mbuf_to_desc_seg(struct virtio_net *dev, struct vhost_virtqueue *vq, + struct rte_mbuf *m, uint32_t mbuf_offset, + uint64_t buf_addr, uint64_t buf_iova, uint32_t cpy_len) +{ + struct batch_copy_elem *batch_copy = vq->batch_copy_elems; + + if (likely(cpy_len > MAX_BATCH_LEN || vq->batch_copy_nb_elems >= vq->size)) { + rte_memcpy((void *)((uintptr_t)(buf_addr)), + rte_pktmbuf_mtod_offset(m, void *, mbuf_offset), + cpy_len); + vhost_log_cache_write_iova(dev, vq, buf_iova, cpy_len); + PRINT_PACKET(dev, (uintptr_t)(buf_addr), cpy_len, 0); + } else { + batch_copy[vq->batch_copy_nb_elems].dst = + (void *)((uintptr_t)(buf_addr)); + batch_copy[vq->batch_copy_nb_elems].src = + rte_pktmbuf_mtod_offset(m, void *, mbuf_offset); + batch_copy[vq->batch_copy_nb_elems].log_addr = buf_iova; + batch_copy[vq->batch_copy_nb_elems].len = cpy_len; + vq->batch_copy_nb_elems++; + } +} + static __rte_always_inline int copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, struct rte_mbuf *m, struct buf_vector *buf_vec, @@ -900,23 +924,17 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, uint32_t cpy_len; uint64_t hdr_addr; struct rte_mbuf *hdr_mbuf; - struct batch_copy_elem *batch_copy = vq->batch_copy_elems; struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL; - int error = 0; - if (unlikely(m == NULL)) { - error = -1; - goto out; - } + if (unlikely(m == NULL)) + return -1; buf_addr = buf_vec[vec_idx].buf_addr; buf_iova = buf_vec[vec_idx].buf_iova; buf_len = buf_vec[vec_idx].buf_len; - if (unlikely(buf_len < dev->vhost_hlen && nr_vec <= 1)) { - error = -1; - goto out; - } + if (unlikely(buf_len < dev->vhost_hlen && nr_vec <= 1)) + return -1; hdr_mbuf = m; hdr_addr = buf_addr; @@ -947,10 +965,8 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, /* done with current buf, get the next one */ if (buf_avail == 0) { vec_idx++; - if (unlikely(vec_idx >= nr_vec)) { - error = -1; - goto out; - } + if (unlikely(vec_idx >= nr_vec)) + goto error; buf_addr = buf_vec[vec_idx].buf_addr; buf_iova = buf_vec[vec_idx].buf_iova; @@ -989,26 +1005,9 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, cpy_len = RTE_MIN(buf_avail, mbuf_avail); - if (likely(cpy_len > MAX_BATCH_LEN || - vq->batch_copy_nb_elems >= vq->size)) { - rte_memcpy((void *)((uintptr_t)(buf_addr + buf_offset)), - rte_pktmbuf_mtod_offset(m, void *, mbuf_offset), - cpy_len); - vhost_log_cache_write_iova(dev, vq, - buf_iova + buf_offset, - cpy_len); - PRINT_PACKET(dev, (uintptr_t)(buf_addr + buf_offset), - cpy_len, 0); - } else { - batch_copy[vq->batch_copy_nb_elems].dst = - (void *)((uintptr_t)(buf_addr + buf_offset)); - batch_copy[vq->batch_copy_nb_elems].src = - rte_pktmbuf_mtod_offset(m, void *, mbuf_offset); - batch_copy[vq->batch_copy_nb_elems].log_addr = - buf_iova + buf_offset; - batch_copy[vq->batch_copy_nb_elems].len = cpy_len; - vq->batch_copy_nb_elems++; - } + sync_mbuf_to_desc_seg(dev, vq, m, mbuf_offset, + buf_addr + buf_offset, + buf_iova + buf_offset, cpy_len); mbuf_avail -= cpy_len; mbuf_offset += cpy_len; @@ -1016,9 +1015,9 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, buf_offset += cpy_len; } -out: - - return error; + return 0; +error: + return -1; } static __rte_always_inline int From patchwork Mon Oct 18 13:02:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 102038 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 45AD6A0C43; Mon, 18 Oct 2021 15:04:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EFC27410F4; Mon, 18 Oct 2021 15:04:35 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id C4E08410F4 for ; Mon, 18 Oct 2021 15:04:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634562274; 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=We4IZQkHzACEpX6BcLuOKCaqfWFQWJRjc4koQzJnR/c=; b=PrJswl5bmAeO7UmL90xiab78xQ95lzCzZ29yK4h8BZ3aKAaWl+qvSOaN5JMFJY9B54s3+I 3BqcqDO3KvTQy/NCULXDdFlEQ4rUr/aXfWteVEuOd3fwFy3yKvUZXcYpsRWR96++oDGLts vK7L0XeuCrT4apr91DbZbO/EBIS9xkY= 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-596-t_VMXhe0O4GBev7FF3C3kw-1; Mon, 18 Oct 2021 09:04:30 -0400 X-MC-Unique: t_VMXhe0O4GBev7FF3C3kw-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 A353310055BF; Mon, 18 Oct 2021 13:04:27 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8505060BD8; Mon, 18 Oct 2021 13:04:25 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, jiayu.hu@intel.com, yuanx.wang@intel.com, wenwux.ma@intel.com, bruce.richardson@intel.com, john.mcnamara@intel.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Mon, 18 Oct 2021 15:02:29 +0200 Message-Id: <20211018130229.308694-15-maxime.coquelin@redhat.com> In-Reply-To: <20211018130229.308694-1-maxime.coquelin@redhat.com> References: <20211018130229.308694-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 v1 14/14] vhost: merge sync and async mbuf to desc filling 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 patches merges copy_mbuf_to_desc() used by the sync path with async_mbuf_to_desc() used by the async path. Most of these complex functions are identical, so merging them will make the maintenance easier. In order not to degrade performance, the patch introduces a boolean function parameter to specify whether it is called in async context. This boolean is statically passed to this always-inlined function, so the compiler will optimize this out. Signed-off-by: Maxime Coquelin --- lib/vhost/virtio_net.c | 153 +++++++---------------------------------- 1 file changed, 26 insertions(+), 127 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 7e66113006..0e1fd01e31 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -913,9 +913,9 @@ sync_mbuf_to_desc_seg(struct virtio_net *dev, struct vhost_virtqueue *vq, } static __rte_always_inline int -copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, - struct rte_mbuf *m, struct buf_vector *buf_vec, - uint16_t nr_vec, uint16_t num_buffers) +mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, + struct rte_mbuf *m, struct buf_vector *buf_vec, + uint16_t nr_vec, uint16_t num_buffers, bool is_async) { uint32_t vec_idx = 0; uint32_t mbuf_offset, mbuf_avail; @@ -925,115 +925,7 @@ copy_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, uint64_t hdr_addr; struct rte_mbuf *hdr_mbuf; struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL; - - if (unlikely(m == NULL)) - return -1; - - buf_addr = buf_vec[vec_idx].buf_addr; - buf_iova = buf_vec[vec_idx].buf_iova; - buf_len = buf_vec[vec_idx].buf_len; - - if (unlikely(buf_len < dev->vhost_hlen && nr_vec <= 1)) - return -1; - - hdr_mbuf = m; - hdr_addr = buf_addr; - if (unlikely(buf_len < dev->vhost_hlen)) { - memset(&tmp_hdr, 0, sizeof(struct virtio_net_hdr_mrg_rxbuf)); - hdr = &tmp_hdr; - } else - hdr = (struct virtio_net_hdr_mrg_rxbuf *)(uintptr_t)hdr_addr; - - VHOST_LOG_DATA(DEBUG, "(%d) RX: num merge buffers %d\n", - dev->vid, num_buffers); - - if (unlikely(buf_len < dev->vhost_hlen)) { - buf_offset = dev->vhost_hlen - buf_len; - vec_idx++; - buf_addr = buf_vec[vec_idx].buf_addr; - buf_iova = buf_vec[vec_idx].buf_iova; - buf_len = buf_vec[vec_idx].buf_len; - buf_avail = buf_len - buf_offset; - } else { - buf_offset = dev->vhost_hlen; - buf_avail = buf_len - dev->vhost_hlen; - } - - mbuf_avail = rte_pktmbuf_data_len(m); - mbuf_offset = 0; - while (mbuf_avail != 0 || m->next != NULL) { - /* done with current buf, get the next one */ - if (buf_avail == 0) { - vec_idx++; - if (unlikely(vec_idx >= nr_vec)) - goto error; - - buf_addr = buf_vec[vec_idx].buf_addr; - buf_iova = buf_vec[vec_idx].buf_iova; - buf_len = buf_vec[vec_idx].buf_len; - - buf_offset = 0; - buf_avail = buf_len; - } - - /* done with current mbuf, get the next one */ - if (mbuf_avail == 0) { - m = m->next; - - mbuf_offset = 0; - mbuf_avail = rte_pktmbuf_data_len(m); - } - - if (hdr_addr) { - virtio_enqueue_offload(hdr_mbuf, &hdr->hdr); - if (rxvq_is_mergeable(dev)) - ASSIGN_UNLESS_EQUAL(hdr->num_buffers, - num_buffers); - - if (unlikely(hdr == &tmp_hdr)) { - copy_vnet_hdr_to_desc(dev, vq, buf_vec, hdr); - } else { - PRINT_PACKET(dev, (uintptr_t)hdr_addr, - dev->vhost_hlen, 0); - vhost_log_cache_write_iova(dev, vq, - buf_vec[0].buf_iova, - dev->vhost_hlen); - } - - hdr_addr = 0; - } - - cpy_len = RTE_MIN(buf_avail, mbuf_avail); - - sync_mbuf_to_desc_seg(dev, vq, m, mbuf_offset, - buf_addr + buf_offset, - buf_iova + buf_offset, cpy_len); - - mbuf_avail -= cpy_len; - mbuf_offset += cpy_len; - buf_avail -= cpy_len; - buf_offset += cpy_len; - } - - return 0; -error: - return -1; -} - -static __rte_always_inline int -async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, - struct rte_mbuf *m, struct buf_vector *buf_vec, - uint16_t nr_vec, uint16_t num_buffers) -{ struct vhost_async *async = vq->async; - struct rte_mbuf *hdr_mbuf; - struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL; - uint64_t buf_addr, buf_iova; - uint64_t hdr_addr; - uint32_t vec_idx = 0; - uint32_t mbuf_offset, mbuf_avail; - uint32_t buf_offset, buf_avail; - uint32_t cpy_len, buf_len; if (unlikely(m == NULL)) return -1; @@ -1071,8 +963,10 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, mbuf_avail = rte_pktmbuf_data_len(m); mbuf_offset = 0; - if (async_iter_initialize(async)) - return -1; + if (is_async) { + if (async_iter_initialize(async)) + return -1; + } while (mbuf_avail != 0 || m->next != NULL) { /* done with current buf, get the next one */ @@ -1086,7 +980,7 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, buf_len = buf_vec[vec_idx].buf_len; buf_offset = 0; - buf_avail = buf_len; + buf_avail = buf_len; } /* done with current mbuf, get the next one */ @@ -1094,7 +988,7 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, m = m->next; mbuf_offset = 0; - mbuf_avail = rte_pktmbuf_data_len(m); + mbuf_avail = rte_pktmbuf_data_len(m); } if (hdr_addr) { @@ -1118,9 +1012,14 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, cpy_len = RTE_MIN(buf_avail, mbuf_avail); - if (async_mbuf_to_desc_seg(dev, vq, m, mbuf_offset, - buf_iova + buf_offset, cpy_len) < 0) { - goto error; + if (is_async) { + if (async_mbuf_to_desc_seg(dev, vq, m, mbuf_offset, + buf_iova + buf_offset, cpy_len) < 0) + goto error; + } else { + sync_mbuf_to_desc_seg(dev, vq, m, mbuf_offset, + buf_addr + buf_offset, + buf_iova + buf_offset, cpy_len); } mbuf_avail -= cpy_len; @@ -1129,11 +1028,13 @@ async_mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, buf_offset += cpy_len; } - async_iter_finalize(async); + if (is_async) + async_iter_finalize(async); return 0; error: - async_iter_cancel(async); + if (is_async) + async_iter_cancel(async); return -1; } @@ -1192,7 +1093,7 @@ vhost_enqueue_single_packed(struct virtio_net *dev, avail_idx -= vq->size; } - if (copy_mbuf_to_desc(dev, vq, pkt, buf_vec, nr_vec, num_buffers) < 0) + if (mbuf_to_desc(dev, vq, pkt, buf_vec, nr_vec, num_buffers, false) < 0) return -1; vhost_shadow_enqueue_single_packed(dev, vq, buffer_len, buffer_buf_id, @@ -1236,9 +1137,8 @@ virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq, dev->vid, vq->last_avail_idx, vq->last_avail_idx + num_buffers); - if (copy_mbuf_to_desc(dev, vq, pkts[pkt_idx], - buf_vec, nr_vec, - num_buffers) < 0) { + if (mbuf_to_desc(dev, vq, pkts[pkt_idx], buf_vec, nr_vec, + num_buffers, false) < 0) { vq->shadow_used_idx -= num_buffers; break; } @@ -1582,7 +1482,7 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, VHOST_LOG_DATA(DEBUG, "(%d) current index %d | end index %d\n", dev->vid, vq->last_avail_idx, vq->last_avail_idx + num_buffers); - if (async_mbuf_to_desc(dev, vq, pkts[pkt_idx], buf_vec, nr_vec, num_buffers) < 0) { + if (mbuf_to_desc(dev, vq, pkts[pkt_idx], buf_vec, nr_vec, num_buffers, true) < 0) { vq->shadow_used_idx -= num_buffers; break; } @@ -1751,8 +1651,7 @@ vhost_enqueue_async_packed(struct virtio_net *dev, avail_idx -= vq->size; } - if (unlikely(async_mbuf_to_desc(dev, vq, pkt, buf_vec, nr_vec, - *nr_buffers) < 0)) + if (unlikely(mbuf_to_desc(dev, vq, pkt, buf_vec, nr_vec, *nr_buffers, true) < 0)) return -1; vhost_shadow_enqueue_packed(vq, buffer_len, buffer_buf_id, buffer_desc_count, *nr_buffers);