From patchwork Mon May 16 11:10:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ding, Xuan" X-Patchwork-Id: 111180 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 3D716A00BE; Mon, 16 May 2022 13:16:00 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4249942B53; Mon, 16 May 2022 13:15:52 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id C27BC42686 for ; Mon, 16 May 2022 13:15:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652699748; x=1684235748; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=w56xqCmLDCgaivu1u3wG2gymPSOMMnT97D/z/E0XGJM=; b=AWgKyGcBmYxmEuidDMz0lPMCBE8Mjqp1T/7jkdKLu4f0U03/BDZW7iC2 t9qKe/k2gowOObOP21S9nqN6Or64hhwT9xwqlrcvREggsF+SzS4zab432 /NRQK7MvME+jpI6mYfOE7gdbWRQ/wnCANFZ/JrhsA3XiCzVPF13M2EIGX 9pQhl+dbWgRN2vbyf6V/nI8OaVvRR5SKyIChLgCmO12ZWYe2E6tFvtZTm 0TcP62mC8y5560BC1qqf0lh8LB64yEkRKnGZMk87mxNpyU9taALcC1eqp Wd0LHSCUDd65GPHHH2vN24qTjrHu6maFLZe7FfzCRorWYqotHocTdMfn3 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10348"; a="296063056" X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="296063056" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2022 04:15:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="568272363" Received: from npg-dpdk-xuan-cbdma.sh.intel.com ([10.67.110.228]) by orsmga007.jf.intel.com with ESMTP; 16 May 2022 04:15:39 -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 v8 2/5] vhost: prepare async for descriptor to mbuf refactoring Date: Mon, 16 May 2022 11:10:38 +0000 Message-Id: <20220516111041.63914-3-xuan.ding@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220516111041.63914-1-xuan.ding@intel.com> References: <20220407152546.38167-1-xuan.ding@intel.com> <20220516111041.63914-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,