From patchwork Thu Oct 7 22:00:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100732 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 D9204A0C43; Fri, 8 Oct 2021 00:14:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5F34841467; Fri, 8 Oct 2021 00:14:04 +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 BEA7A4146E for ; Fri, 8 Oct 2021 00:14:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644842; 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=bnhd04TnRn+fsADLu8CGpKvdricoZVrFumCMVqCpAWg=; b=O9Srn7S8FOwPHX6WfqS+V8jHZm9PW5hf5VRmLzNXZKHG40W4fGb6+dI69u09piH76i64mW 3qXxYmJC9yNuCORgc7u9FVYz23vOkrAlgoIgp60jEixisk0+srfj9+46CojV8OO6QGTPo7 5d2SXpkvM8jFLjK63Hi4CJPCdftE3bM= 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-507-lb3fbOzWPfqZYTvQnK1wUA-1; Thu, 07 Oct 2021 18:13:55 -0400 X-MC-Unique: lb3fbOzWPfqZYTvQnK1wUA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB6261A767D7; Thu, 7 Oct 2021 22:00:20 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BC875C1A3; Thu, 7 Oct 2021 22:00: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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:00 +0200 Message-Id: <20211007220013.355530-2-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 | 129 ++++++++++++++++------------------------- lib/vhost/vhost.h | 53 ++++++++--------- lib/vhost/vhost_user.c | 4 +- lib/vhost/virtio_net.c | 114 +++++++++++++++++++----------------- 4 files changed, 140 insertions(+), 160 deletions(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 9540522dac..58f72b633c 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -340,19 +340,15 @@ cleanup_device(struct virtio_net *dev, int destroy) static void vhost_free_async_mem(struct vhost_virtqueue *vq) { - rte_free(vq->async_pkts_info); + rte_free(vq->async->pkts_info); - 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->buffers_packed); + vq->async->buffers_packed = NULL; + rte_free(vq->async->descs_split); + vq->async->descs_split = NULL; - rte_free(vq->it_pool); - rte_free(vq->vec_pool); - - vq->async_pkts_info = NULL; - vq->it_pool = NULL; - vq->vec_pool = NULL; + rte_free(vq->async); + vq->async = NULL; } void @@ -1629,77 +1625,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 +1775,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 +1784,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 +1792,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 +1815,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 +1826,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 +1847,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 +1856,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 Thu Oct 7 22:00:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100721 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 C88DEA0C43; Fri, 8 Oct 2021 00:10:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B0D2F4116F; Fri, 8 Oct 2021 00:10:21 +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 0D532410F7 for ; Fri, 8 Oct 2021 00:10:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644620; 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=DLFhfUztjsDlQfj7miwJZ9QxVe6aghzrMGZKUM+UhLfq5/7XUn8kCGdJL4DezmFK72pVuo KBwmvIMss7WXhN1VZ1C7ioodiCq1G+Gh24+0srch+EiGjtyt/U8p00tVBA6BmK2v/y8zvE 0i5XH4rmDQceIizn0jDOQXKdUihjUgg= 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-400-M-YWXTsKN-aNNCpGCVhDMw-1; Thu, 07 Oct 2021 18:10:19 -0400 X-MC-Unique: M-YWXTsKN-aNNCpGCVhDMw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E3C8D1A2B58C; Thu, 7 Oct 2021 22:00:22 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26C765C1A3; Thu, 7 Oct 2021 22:00:20 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:01 +0200 Message-Id: <20211007220013.355530-3-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 Thu Oct 7 22:00:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100731 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 000ECA0C43; Fri, 8 Oct 2021 00:14:01 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E4DC441406; Fri, 8 Oct 2021 00:14:00 +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 3A0944145D for ; Fri, 8 Oct 2021 00:13:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644838; 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=L0nG/+REbuH88jzyfQ/rtotmNJjg1wh4QUywi3SxGdaH7dRyNBMukVHBVDN/2B3yxxgD0V Zg9ZEu2SGTAii1yuPXCdonsEfveUCNvwQ2iPJrZMuahUUgT60lK/6LTx70zgdiwoaFe+0r HLdUGw3obQxd6JfH9NMC16JzLREqlPQ= 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-248-e0g_dufxOxeKuuWtbPQeWg-1; Thu, 07 Oct 2021 18:13:55 -0400 X-MC-Unique: e0g_dufxOxeKuuWtbPQeWg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1207A11ED92C; Thu, 7 Oct 2021 22:00:25 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D0B85C1CF; Thu, 7 Oct 2021 22:00:23 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:02 +0200 Message-Id: <20211007220013.355530-4-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 Thu Oct 7 22:00:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100730 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 D853DA0C43; Fri, 8 Oct 2021 00:13:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C740C41271; Fri, 8 Oct 2021 00:13:57 +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 CC56041271 for ; Fri, 8 Oct 2021 00:13:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644835; 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=Oa99anl3lk/AMpclmkd+bkmK+tk5Pzb6sezh/czXB72uoQdvPPVDjWLqVRPMQJ1/pRCDAr Se4B06CaU918A223JXER6J8TkyMPuDMHqt3Rw7voB9EsUmtdpC/KDWWhc0SA6nAsgmTc3O k38pkZj/xVc+QQ7GsCPccuzTErIikDI= 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-41-8vt5z87rN8OQ5y-5hjiChA-1; Thu, 07 Oct 2021 18:13:54 -0400 X-MC-Unique: 8vt5z87rN8OQ5y-5hjiChA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 28CE296317B; Thu, 7 Oct 2021 22:00:27 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CB325C1D0; Thu, 7 Oct 2021 22:00: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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:03 +0200 Message-Id: <20211007220013.355530-5-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 Thu Oct 7 22:00:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100726 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 8D18EA0C43; Fri, 8 Oct 2021 00:13:29 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D8513413D1; Fri, 8 Oct 2021 00:13:25 +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 A77ED411FE for ; Fri, 8 Oct 2021 00:13:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644803; 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=KmrLZMaP/ChZFbx3H+YCl0FEH9+pjj6O2GGZUXO9Q7yEHGjrCT/UtwYdW1mS/RQ2YMA/p8 fszZUTIJgBmuGy1hr4Jn5ywEYoBHrv4SNxZYPZtdcvRyHSRANP3u3U9sAY6aK0LEobx7N+ iirIik4spNod4g+Uer2faejwRbkHXgA= 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-458-kXVnUH8eNRKar7xSM1Hr5g-1; Thu, 07 Oct 2021 18:13:19 -0400 X-MC-Unique: kXVnUH8eNRKar7xSM1Hr5g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4485A95C478; Thu, 7 Oct 2021 22:00:29 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74CA45C1B4; Thu, 7 Oct 2021 22:00:27 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:04 +0200 Message-Id: <20211007220013.355530-6-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 Thu Oct 7 22:00:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100727 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 8BE69A0C43; Fri, 8 Oct 2021 00:13:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EC4184142B; Fri, 8 Oct 2021 00:13: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 34A8C41406 for ; Fri, 8 Oct 2021 00:13:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644805; 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=L7hD+TChRDlPH9v5n//dLtyIO6g6ZROy1PS2S//2neYYuK/hmLem9t4v1y2p+xPuWU/Wh9 MDyYGcy8EPaTlr37fB32OJ/G5X7qmxfXfW5VILnYwfWI/X4+1rnZOucEplszzYy/V+0TJG XFfsrCBN39xp0OTuEEWKOKPY1vy/ldg= 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-189-NEpnXrYhOSmOkxo8yJiF-w-1; Thu, 07 Oct 2021 18:13:22 -0400 X-MC-Unique: NEpnXrYhOSmOkxo8yJiF-w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 759A912C12A; Thu, 7 Oct 2021 22:00:35 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FAD05C1B4; Thu, 7 Oct 2021 22:00:29 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:05 +0200 Message-Id: <20211007220013.355530-7-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 Thu Oct 7 22:00:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100733 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 E5D50A0C43; Fri, 8 Oct 2021 00:14:14 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 84A0B41470; Fri, 8 Oct 2021 00:14:06 +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 BF1BC41459 for ; Fri, 8 Oct 2021 00:14:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644843; 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=hQCqgiMHhux3HuWPDa/giJ77DqinebDNvFnCJgBW73VZgLtJIxKcNYlCcRsNFE0Dfaz5I4 UQ5sHQLCQ+F2k8p8ugN6ZzLKjii0bnmiSvYrmker8UN3fuU40jnma0O+SaNu4yavqIrtgk XzgkmSFZAgFkvFdpTBHXdStTylZ5+xQ= 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-598-05Kdo1_QN1maIMYpzV9sDQ-1; Thu, 07 Oct 2021 18:14:00 -0400 X-MC-Unique: 05Kdo1_QN1maIMYpzV9sDQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7F3C961152; Thu, 7 Oct 2021 22:00:37 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB5AA5C1B4; Thu, 7 Oct 2021 22:00:35 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:06 +0200 Message-Id: <20211007220013.355530-8-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 Thu Oct 7 22:00:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100729 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 5E3A6A0C43; Fri, 8 Oct 2021 00:13:46 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B374D41450; Fri, 8 Oct 2021 00:13:34 +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 6B57E41441 for ; Fri, 8 Oct 2021 00:13:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644811; 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=nonxIr4PYpVnOh/PDWgwGoQRLMHcuLDry/AsIVWMSLQ=; b=MqxyrF+WCgUa6fB5HuuLjLsCqVNkML7ZmGy1KWZkcIjRNI4BWDl8QqNS5ZDG6DLhI7QTWB qPWbXgKWKexAnxOwiqi+HZ0QEWxQo1gyGTwcwR76fJTGM4O7QNZFyEbadVsNnQ4fXB6BKq +D56TzwaPORU+B5GB8ZQSBtYixwXp7M= 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-594-ZDzHvlrWMT6v_ZF34RR-NQ-1; Thu, 07 Oct 2021 18:13:27 -0400 X-MC-Unique: ZDzHvlrWMT6v_ZF34RR-NQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4CCEF236B79; Thu, 7 Oct 2021 22:00:43 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AAD55C1B4; Thu, 7 Oct 2021 22:00:37 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:07 +0200 Message-Id: <20211007220013.355530-9-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 | 296 +++++++++++++++++++---------------------- 2 files changed, 136 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..5ce4c14a73 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -924,33 +924,91 @@ 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->iter_idx >= VHOST_MAX_ASYNC_IT)) { + VHOST_LOG_DATA(ERR, "no more async iterators available\n"); + return -1; + } + + 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++; + + 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 +1018,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 +1057,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 +1111,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 +1544,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 +1562,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 +1699,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 +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, 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 +1757,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 +1804,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 +1822,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 Thu Oct 7 22:00:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100728 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 A7846A0C43; Fri, 8 Oct 2021 00:13:39 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2A123413DD; Fri, 8 Oct 2021 00:13:32 +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 75F8A4124B for ; Fri, 8 Oct 2021 00:13:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644810; 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=V+zZLpnIGikbp5/hW2+ymT7rklSfYR4P0DEz+0tHcHA=; b=Dfvq0T6eXnxUJndkIeKrnq3geKCNWxh8Z9oV9hGzi6SUAkp8RsoL0z6ABAwSofE47PBFPw wx9Wn9Xx19c2NizNj2RYEP6+26fo4swQUH7HXuHADzPl46n7BI90R4/BnZRvhgLkb+2wTL yd/m0MceKwNHNBvZ1eCtKixgOmR+sP4= 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-558-ED6gavXoMVycESD1ZbGzKQ-1; Thu, 07 Oct 2021 18:13:27 -0400 X-MC-Unique: ED6gavXoMVycESD1ZbGzKQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D6A48E71E5; Thu, 7 Oct 2021 22:00:45 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 954285C1D0; Thu, 7 Oct 2021 22:00:43 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:08 +0200 Message-Id: <20211007220013.355530-10-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 5ce4c14a73..b295dc1d39 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -994,15 +994,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, @@ -1549,7 +1540,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; @@ -1594,9 +1584,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); @@ -1811,7 +1799,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; @@ -1839,9 +1826,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 Thu Oct 7 22:00:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100734 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 65922A0C43; Fri, 8 Oct 2021 00:14:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B28FB41443; Fri, 8 Oct 2021 00:14:15 +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 247E341443 for ; Fri, 8 Oct 2021 00:14:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644853; 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=N1d2l+UmCX9qmE1dbTbPmsL9Kl/u2RFqNKq7w1qSn8Y=; b=JISSSVrANBFE+bXtbrN6kMGXRx6se512DdaJoJ47kRdMz2lckKhyAdvyl/WOnHPWGriRR2 BgsLP+uMKSYihPTrg0uyv9PxZKs5edaB5qrDO84bC8d/OOW1H3Vm9gXJXVIAC/ysmnAIUT hxJ7jc3BVqI5nGPnL92FuDp8Mlukhss= 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-20-lPw1mSvLOwSh2URTyO-g7A-1; Thu, 07 Oct 2021 18:14:12 -0400 X-MC-Unique: lPw1mSvLOwSh2URTyO-g7A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73D108C2FB7; Thu, 7 Oct 2021 22:00:54 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id C30495C1B4; Thu, 7 Oct 2021 22:00:45 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:09 +0200 Message-Id: <20211007220013.355530-11-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 b295dc1d39..c5651f1e0f 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1618,7 +1618,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; } @@ -1920,68 +1924,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 { @@ -1994,7 +1974,7 @@ vhost_poll_enqueue_completed(struct virtio_net *dev, uint16_t queue_id, } } - return n_pkts_put; + return n_cpl; } uint16_t From patchwork Thu Oct 7 22:00:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100737 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 85D75A0C43; Fri, 8 Oct 2021 00:14:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6FF9E4144A; Fri, 8 Oct 2021 00:14:42 +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 42F43413D1 for ; Fri, 8 Oct 2021 00:14:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644880; 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=2SOIUIjyy+S/caL7rnP5/rff1qUzjFXRF68rt+evcZc=; b=hVjuyFINzqItG/owQnaXE8Jc2s03c+lW9Cd1Gev+jAZPFhIySjZ6DKJalgDinf9XzJD3FA P+YjSh8lpnNaaVxbXFl39rWqbr5H+41u59G5i4Ku9RvjKfqn55v1ZYzQ18RcnzY1ZB5blJ pCrqxku4nNBSR6fyOXqAlQ5Z8c7HBKY= 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-571-9uPjsHj8Oeq9PnTI71Rjuw-1; Thu, 07 Oct 2021 18:14:37 -0400 X-MC-Unique: 9uPjsHj8Oeq9PnTI71Rjuw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD6408CE093; Thu, 7 Oct 2021 22:00:56 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id C75725C1A3; Thu, 7 Oct 2021 22:00:54 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:10 +0200 Message-Id: <20211007220013.355530-12-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 c5651f1e0f..2aa06a958c 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1489,11 +1489,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 @@ -1931,9 +1934,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", @@ -1944,6 +1944,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 Thu Oct 7 22:00:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100736 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 E1570A0C43; Fri, 8 Oct 2021 00:14:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4FD9341447; Fri, 8 Oct 2021 00:14:28 +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 3E64B41432 for ; Fri, 8 Oct 2021 00:14:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644866; 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=8na/3MMAW6x8fopyGKOVbwWD8Cvi0NC7KDIyN/fZXN0=; b=BaD8o8krDbeWH7PyB6YYI0sJNvSThxri+VbkWHAc8mbqXa1iIfEnryIhQeYW8MgaAiP0lD Dkf0YMNHOmEWeNheQS0MWgCz+YeuQGLkPLjqL6h6hckbiwiUkTyHBlhca7MsKDvUxGh2Ya aQ70Oxe2jI19arrrbOyIwWEtFm1ntug= 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-187-7IUZRQAnMCKFDChydVZ3_Q-1; Thu, 07 Oct 2021 18:14:16 -0400 X-MC-Unique: 7IUZRQAnMCKFDChydVZ3_Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CFC208C3381; Thu, 7 Oct 2021 22:00:58 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F8695C1A3; Thu, 7 Oct 2021 22:00:56 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:11 +0200 Message-Id: <20211007220013.355530-13-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 | 205 ++++++++++++++++++++++------------------- 1 file changed, 111 insertions(+), 94 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 2aa06a958c..9d131e6df1 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -791,6 +791,109 @@ 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->iter_idx >= VHOST_MAX_ASYNC_IT)) { + VHOST_LOG_DATA(ERR, "no more async iterators available\n"); + return -1; + } + + 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++; + + 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,76 +1027,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->iter_idx >= VHOST_MAX_ASYNC_IT)) { - VHOST_LOG_DATA(ERR, "no more async iterators available\n"); - return -1; - } - - 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++; - - 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, @@ -1004,14 +1037,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; @@ -1095,28 +1125,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 Thu Oct 7 22:00:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100735 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 E8175A0C43; Fri, 8 Oct 2021 00:14:26 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 373004144D; Fri, 8 Oct 2021 00:14:21 +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 7C749413DD for ; Fri, 8 Oct 2021 00:14:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644860; 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=KWovxchsJd53uRrhSy/HQUJdJ8LneG3VeC0V27cIZyg=; b=gyf5lxncKqLqM143BbHEeKvTVvWthPO88cju9/vYviLQR40/Day65S3dt/zuEo+4pB8u99 xXGd3PJLdUZp/vydWhUDBTApFGiZUZ94R3Hf+RrW0hi3ylPCMd8V3xoWD8yjWC71vd0Ob7 aVWR2AZmbSGUkU+MGOuIq7PqIS84FkI= 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-310-QBsieEkVMLqCEW7cmAiFBw-1; Thu, 07 Oct 2021 18:14:19 -0400 X-MC-Unique: QBsieEkVMLqCEW7cmAiFBw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 134C38C3383; Thu, 7 Oct 2021 22:01:01 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 315A35C1B4; Thu, 7 Oct 2021 22:00:58 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:12 +0200 Message-Id: <20211007220013.355530-14-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 9d131e6df1..868ac77dff 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -894,6 +894,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, @@ -906,23 +930,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; @@ -953,10 +971,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; @@ -995,26 +1011,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; @@ -1022,9 +1021,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 Thu Oct 7 22:00:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 100738 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 987DBA0C43; Fri, 8 Oct 2021 00:14:51 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 826B841406; Fri, 8 Oct 2021 00:14:51 +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 BFC2F4124B for ; Fri, 8 Oct 2021 00:14:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633644890; 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=+AONDDt+XdoMMrk4bmsVthYNMYRpwDOSZS+JIP0W6N8=; b=C8oz6IT0FnYOlgTtqLa7c4p3lBnKyi+cd/floAJ8AvXlJp0+yBWOBDWjbi8i4QFeUtlBL3 SZTTgoymeaCn+/hFX2bDThzuVBa/diye314e40qlm74w+1IX0noyLVrENgZo1Z5JPdv1Gz qNN4D7Ysmwk1OcUnPFT4rOzdadaT5AU= 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-290-OhUYDUUFNEuych4WUVqnOA-1; Thu, 07 Oct 2021 18:14:42 -0400 X-MC-Unique: OhUYDUUFNEuych4WUVqnOA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5FF2C10598AD; Thu, 7 Oct 2021 22:01:03 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.39.208.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72EEC5C1A3; Thu, 7 Oct 2021 22:01:01 +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 Cc: Maxime Coquelin Date: Fri, 8 Oct 2021 00:00:13 +0200 Message-Id: <20211007220013.355530-15-maxime.coquelin@redhat.com> In-Reply-To: <20211007220013.355530-1-maxime.coquelin@redhat.com> References: <20211007220013.355530-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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] [RFC 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 868ac77dff..6ef2e1352d 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -919,9 +919,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; @@ -931,115 +931,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; @@ -1077,8 +969,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 */ @@ -1092,7 +986,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 */ @@ -1100,7 +994,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) { @@ -1124,9 +1018,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; @@ -1135,11 +1034,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; } @@ -1198,7 +1099,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, @@ -1242,9 +1143,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; } @@ -1588,7 +1488,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; } @@ -1757,8 +1657,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);