From patchwork Tue Jun 23 14:29:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Loftus, Ciara" X-Patchwork-Id: 72041 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 47A4EA0350; Tue, 23 Jun 2020 16:50:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9D8711D682; Tue, 23 Jun 2020 16:50:43 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 93AA11D675 for ; Tue, 23 Jun 2020 16:50:41 +0200 (CEST) IronPort-SDR: q2fjXNgQ1bZbJIlKadrQXa/JJeXJY+cemmeOKmzn2wvf6Cy/KFW6cAdpZU9ryS2xuWGwBK0+ex +0+6htAE32Vg== X-IronPort-AV: E=McAfee;i="6000,8403,9661"; a="141585813" X-IronPort-AV: E=Sophos;i="5.75,271,1589266800"; d="scan'208";a="141585813" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2020 07:50:40 -0700 IronPort-SDR: S8WQri6nEzbFn+mIeTaLbXNJ8jXhN/dzexw8LMkFSQtQs6IjzuGJDfwRsdcKWvGT5e+dWJ+d/E 66wmhj0p/OYA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,271,1589266800"; d="scan'208";a="301276642" Received: from silpixa00399839.ir.intel.com (HELO localhost.localdomain) ([10.237.222.8]) by fmsmga004.fm.intel.com with ESMTP; 23 Jun 2020 07:50:39 -0700 From: Ciara Loftus To: dev@dpdk.org Cc: stephen@networkplumber.org, magnus.karlsson@intel.com, qi.z.zhang@intel.com, Ciara Loftus Date: Tue, 23 Jun 2020 14:29:25 +0000 Message-Id: <20200623142925.28305-1-ciara.loftus@intel.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2] net/af_xdp: optimisations to improve packet loss X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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 commit makes some changes to the AF_XDP PMD in an effort to improve its packet loss characteristics. 1. In the case of failed transmission due to inability to reserve a tx descriptor, the PMD now pulls from the completion ring, issues a syscall in which the kernel attempts to complete outstanding tx operations, then tries to reserve the tx descriptor again. Prior to this we dropped the packet after the syscall and didn't try to re-reserve. 2. During completion ring cleanup, always pull as many entries as possible from the ring as opposed to the batch size or just how many packets we're going to attempt to send. Keeping the completion ring emptier should reduce failed transmissions in the kernel, as the kernel requires space in the completion ring to successfully tx. 3. Size the fill ring as twice the receive ring size which may help reduce allocation failures in the driver. 4. Emulate a tx_free_thresh - when the number of available entries in the completion ring rises above this, we pull from it. The threshold is set to 1k entries. With these changes, a benchmark which measured the packet rate at which 0.01% packet loss could be reached improved from ~0.1G to ~3Gbps. Signed-off-by: Ciara Loftus Acked-by: Xiaolong Ye --- v1->v2: - added emulated tx_free_thresh as suggested by Stephen Hemminger drivers/net/af_xdp/rte_eth_af_xdp.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c index 06124ba789..2d69221c1b 100644 --- a/drivers/net/af_xdp/rte_eth_af_xdp.c +++ b/drivers/net/af_xdp/rte_eth_af_xdp.c @@ -396,6 +396,8 @@ kick_tx(struct pkt_tx_queue *txq) { struct xsk_umem_info *umem = txq->umem; + pull_umem_cq(umem, XSK_RING_CONS__DEFAULT_NUM_DESCS); + #if defined(XDP_USE_NEED_WAKEUP) if (xsk_ring_prod__needs_wakeup(&txq->tx)) #endif @@ -407,11 +409,9 @@ kick_tx(struct pkt_tx_queue *txq) /* pull from completion queue to leave more space */ if (errno == EAGAIN) - pull_umem_cq(umem, ETH_AF_XDP_TX_BATCH_SIZE); + pull_umem_cq(umem, + XSK_RING_CONS__DEFAULT_NUM_DESCS); } -#ifndef XDP_UMEM_UNALIGNED_CHUNK_FLAG - pull_umem_cq(umem, ETH_AF_XDP_TX_BATCH_SIZE); -#endif } #if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG) @@ -427,8 +427,10 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) uint16_t count = 0; struct xdp_desc *desc; uint64_t addr, offset; + uint32_t free_thresh = umem->cq.size >> 1; - pull_umem_cq(umem, nb_pkts); + if (xsk_cons_nb_avail(&umem->cq, free_thresh) >= free_thresh) + pull_umem_cq(umem, XSK_RING_CONS__DEFAULT_NUM_DESCS); for (i = 0; i < nb_pkts; i++) { mbuf = bufs[i]; @@ -436,7 +438,9 @@ af_xdp_tx_zc(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) if (mbuf->pool == umem->mb_pool) { if (!xsk_ring_prod__reserve(&txq->tx, 1, &idx_tx)) { kick_tx(txq); - goto out; + if (!xsk_ring_prod__reserve(&txq->tx, 1, + &idx_tx)) + goto out; } desc = xsk_ring_prod__tx_desc(&txq->tx, idx_tx); desc->len = mbuf->pkt_len; @@ -758,7 +762,7 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals __rte_unused, struct xsk_umem_info *umem; int ret; struct xsk_umem_config usr_config = { - .fill_size = ETH_AF_XDP_DFLT_NUM_DESCS, + .fill_size = ETH_AF_XDP_DFLT_NUM_DESCS * 2, .comp_size = ETH_AF_XDP_DFLT_NUM_DESCS, .flags = XDP_UMEM_UNALIGNED_CHUNK_FLAG}; void *base_addr = NULL; @@ -867,7 +871,7 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq, struct xsk_socket_config cfg; struct pkt_tx_queue *txq = rxq->pair; int ret = 0; - int reserve_size = ETH_AF_XDP_DFLT_NUM_DESCS / 2; + int reserve_size = ETH_AF_XDP_DFLT_NUM_DESCS; struct rte_mbuf *fq_bufs[reserve_size]; rxq->umem = xdp_umem_configure(internals, rxq);