From patchwork Fri May 13 02:50:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ding, Xuan" X-Patchwork-Id: 111090 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 7EA7AA00C3; Fri, 13 May 2022 04:55:40 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 79BFB42831; Fri, 13 May 2022 04:55:34 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 34B9240DDE for ; Fri, 13 May 2022 04:55:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652410533; x=1683946533; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=w56xqCmLDCgaivu1u3wG2gymPSOMMnT97D/z/E0XGJM=; b=Ji1FY3RRB1OcyJL/CW3skOEj9WCX43N0mcZ24o0WT0yhI5mW4AlL0RBC h7t7Wf+wBOHkT+fAHaUDqishf30N/8yYHbstCgYHYZelddN91zijaEz3j PqjVa4EnVbFAaSNyJ4KMNIncGc3EqqxT9z0/O9YWelX7llLsw/Jas/EsO +fsV6Lzgxd2d0N4b4lUVVLctAyum7+oR+XZL8sZ5M9JI1YzeeW4BCnZqo Roy29OEKFqSPx9xw7fQDldstKO0cgbApF1W8xDQpoOp0C1S9YgWZQCh+S frmchauddlCn64ejTMSXOrPkFSMethL/LVR79NcuwCTojl8yleH17t7TN g==; X-IronPort-AV: E=McAfee;i="6400,9594,10345"; a="295455728" X-IronPort-AV: E=Sophos;i="5.91,221,1647327600"; d="scan'208";a="295455728" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2022 19:55:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,221,1647327600"; d="scan'208";a="543069785" Received: from npg-dpdk-xuan-cbdma.sh.intel.com ([10.67.110.228]) by orsmga006.jf.intel.com with ESMTP; 12 May 2022 19:55:30 -0700 From: xuan.ding@intel.com To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, jiayu.hu@intel.com, cheng1.jiang@intel.com, sunil.pai.g@intel.com, liangma@liangbit.com, Xuan Ding Subject: [PATCH v6 2/5] vhost: prepare async for descriptor to mbuf refactoring Date: Fri, 13 May 2022 02:50:55 +0000 Message-Id: <20220513025058.12898-3-xuan.ding@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220513025058.12898-1-xuan.ding@intel.com> References: <20220407152546.38167-1-xuan.ding@intel.com> <20220513025058.12898-1-xuan.ding@intel.com> 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 From: Xuan Ding This patch refactors vhost async enqueue path and dequeue path to use the same function async_fill_seg() for preparing batch elements, which simplifies the code without performance degradation. Signed-off-by: Xuan Ding Tested-by: Yvonne Yang Reviewed-by: Maxime Coquelin --- lib/vhost/virtio_net.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index d4c94d2a9b..a9e2dcd9ce 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -997,13 +997,14 @@ async_iter_reset(struct vhost_async *async) } static __rte_always_inline int -async_mbuf_to_desc_seg(struct virtio_net *dev, struct vhost_virtqueue *vq, +async_fill_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) + uint64_t buf_iova, uint32_t cpy_len, bool to_desc) { struct vhost_async *async = vq->async; uint64_t mapped_len; uint32_t buf_offset = 0; + void *src, *dst; void *host_iova; while (cpy_len) { @@ -1015,10 +1016,15 @@ async_mbuf_to_desc_seg(struct virtio_net *dev, struct vhost_virtqueue *vq, return -1; } - if (unlikely(async_iter_add_iovec(dev, async, - (void *)(uintptr_t)rte_pktmbuf_iova_offset(m, - mbuf_offset), - host_iova, (size_t)mapped_len))) + if (to_desc) { + src = (void *)(uintptr_t)rte_pktmbuf_iova_offset(m, mbuf_offset); + dst = host_iova; + } else { + src = host_iova; + dst = (void *)(uintptr_t)rte_pktmbuf_iova_offset(m, mbuf_offset); + } + + if (unlikely(async_iter_add_iovec(dev, async, src, dst, (size_t)mapped_len))) return -1; cpy_len -= (uint32_t)mapped_len; @@ -1167,8 +1173,8 @@ mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, cpy_len = RTE_MIN(buf_avail, mbuf_avail); if (is_async) { - if (async_mbuf_to_desc_seg(dev, vq, m, mbuf_offset, - buf_iova + buf_offset, cpy_len) < 0) + if (async_fill_seg(dev, vq, m, mbuf_offset, + buf_iova + buf_offset, cpy_len, true) < 0) goto error; } else { sync_fill_seg(dev, vq, m, mbuf_offset,