From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D9FBAA00C4; Sat, 6 Aug 2022 00:01:29 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A98B942C62; Sat, 6 Aug 2022 00:00:46 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mails.dpdk.org (Postfix) with ESMTP id D83D742BCA for ; Sat, 6 Aug 2022 00:00:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659736838; x=1691272838; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=huPtsityDprM+5RxCo7OAXHI1TTkmIEmvzv8bfl+9lQ=; b=AZDFbxJ5mOoN46Up2gYaHUhAAIqE9h+z+R6tyBZbGqdQqEz9/ZJfEGdC pjPd+IMSY0mRuZVDKtSXWu/q+c4aVojK1YUdvZFs/AsEaCl02D+AEpfPr e5vX4L9VdGLpf2jKd3gM18fbhQFi7Av+r20LB86MLj/t3UVViPh6xI6Xw m5flbd7n21mhvg3YR2GiBcnCwqUUh1oNQkvM8RSnOqy7iobVRbLkBsIaJ Pw0IaffoLANEAsXsvGoFY0BykamtYvA8EWPbrPrj0YpM3XgDFsOdyhctj D/Z0aSFgTiRptJWbYuQI8scVoQE12b6DKmvf9QFndJO2kJZlMIz+PlmH7 w==; X-IronPort-AV: E=McAfee;i="6400,9594,10430"; a="273348512" X-IronPort-AV: E=Sophos;i="5.93,217,1654585200"; d="scan'208";a="273348512" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Aug 2022 15:00:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,217,1654585200"; d="scan'208";a="693137552" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com.) ([10.237.223.157]) by FMSMGA003.fm.intel.com with ESMTP; 05 Aug 2022 15:00:32 -0700 From: Cristian Dumitrescu To: dev@dpdk.org Subject: [PATCH 03/10] port: rework the Ethernet device output port behavior to non-blocking Date: Fri, 5 Aug 2022 22:00:22 +0000 Message-Id: <20220805220029.1096212-4-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220805220029.1096212-1-cristian.dumitrescu@intel.com> References: <20220805220029.1096212-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Drop packets that cannot be sent instead of retry sending the same packets potentially forever when the Ethernet device that is down. Signed-off-by: Cristian Dumitrescu --- lib/port/rte_swx_port_ethdev.c | 103 +++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 36 deletions(-) diff --git a/lib/port/rte_swx_port_ethdev.c b/lib/port/rte_swx_port_ethdev.c index ca4a43ac4f..eae20d34ce 100644 --- a/lib/port/rte_swx_port_ethdev.c +++ b/lib/port/rte_swx_port_ethdev.c @@ -173,6 +173,7 @@ struct writer { struct rte_mbuf **pkts; int n_pkts; + uint32_t n_bytes; }; static void * @@ -214,34 +215,56 @@ writer_create(void *args) return p; } -static void +static inline void __writer_flush(struct writer *p) { - int n_pkts; - - for (n_pkts = 0; ; ) { - n_pkts += rte_eth_tx_burst(p->params.port_id, - p->params.queue_id, - p->pkts + n_pkts, - p->n_pkts - n_pkts); - - TRACE("[Ethdev TX port %u queue %u] %d packets out\n", - (uint32_t)p->params.port_id, - (uint32_t)p->params.queue_id, - n_pkts); - - if (n_pkts == p->n_pkts) - break; + struct rte_mbuf **pkts = p->pkts; + uint64_t n_pkts_total = p->stats.n_pkts; + uint64_t n_bytes_total = p->stats.n_bytes; + uint64_t n_pkts_drop_total = p->stats.n_pkts_drop; + uint64_t n_bytes_drop_total = p->stats.n_bytes_drop; + int n_pkts = p->n_pkts, n_pkts_drop, n_pkts_tx; + uint32_t n_bytes = p->n_bytes, n_bytes_drop = 0; + + /* Packet TX. */ + n_pkts_tx = rte_eth_tx_burst(p->params.port_id, + p->params.queue_id, + pkts, + n_pkts); + + /* Packet drop. */ + n_pkts_drop = n_pkts - n_pkts_tx; + + for ( ; n_pkts_tx < n_pkts; n_pkts_tx++) { + struct rte_mbuf *m = pkts[n_pkts_tx]; + + n_bytes_drop += m->pkt_len; + rte_pktmbuf_free(m); } + /* Port update. */ + p->stats.n_pkts = n_pkts_total + n_pkts - n_pkts_drop; + p->stats.n_bytes = n_bytes_total + n_bytes - n_bytes_drop; + p->stats.n_pkts_drop = n_pkts_drop_total + n_pkts_drop; + p->stats.n_bytes_drop = n_bytes_drop_total + n_bytes_drop; p->n_pkts = 0; + p->n_bytes = 0; + + TRACE("[Ethdev TX port %u queue %u] Buffered packets flushed: %d out, %d dropped\n", + (uint32_t)p->params.port_id, + (uint32_t)p->params.queue_id, + n_pkts - n_pkts_drop, + n_pkts_drop); } static void writer_pkt_tx(void *port, struct rte_swx_pkt *pkt) { struct writer *p = port; + int n_pkts = p->n_pkts; + uint32_t n_bytes = p->n_bytes; struct rte_mbuf *m = pkt->handle; + uint32_t pkt_length = pkt->length; TRACE("[Ethdev TX port %u queue %u] Pkt %d (%u bytes at offset %u)\n", (uint32_t)p->params.port_id, @@ -252,15 +275,15 @@ writer_pkt_tx(void *port, struct rte_swx_pkt *pkt) if (TRACE_LEVEL) rte_hexdump(stdout, NULL, &pkt->pkt[pkt->offset], pkt->length); - m->data_len = (uint16_t)(pkt->length + m->data_len - m->pkt_len); - m->pkt_len = pkt->length; + m->data_len = (uint16_t)(pkt_length + m->data_len - m->pkt_len); + m->pkt_len = pkt_length; m->data_off = (uint16_t)pkt->offset; - p->stats.n_pkts++; - p->stats.n_bytes += pkt->length; + p->pkts[n_pkts++] = m; + p->n_pkts = n_pkts; + p->n_bytes = n_bytes + pkt_length; - p->pkts[p->n_pkts++] = m; - if (p->n_pkts == (int)p->params.burst_size) + if (n_pkts == (int)p->params.burst_size) __writer_flush(p); } @@ -268,7 +291,11 @@ static void writer_pkt_fast_clone_tx(void *port, struct rte_swx_pkt *pkt) { struct writer *p = port; + int n_pkts = p->n_pkts; + uint32_t n_bytes = p->n_bytes; + uint64_t n_pkts_clone = p->stats.n_pkts_clone; struct rte_mbuf *m = pkt->handle; + uint32_t pkt_length = pkt->length; TRACE("[Ethdev TX port %u queue %u] Pkt %d (%u bytes at offset %u) (fast clone)\n", (uint32_t)p->params.port_id, @@ -279,17 +306,17 @@ writer_pkt_fast_clone_tx(void *port, struct rte_swx_pkt *pkt) if (TRACE_LEVEL) rte_hexdump(stdout, NULL, &pkt->pkt[pkt->offset], pkt->length); - m->data_len = (uint16_t)(pkt->length + m->data_len - m->pkt_len); - m->pkt_len = pkt->length; + m->data_len = (uint16_t)(pkt_length + m->data_len - m->pkt_len); + m->pkt_len = pkt_length; m->data_off = (uint16_t)pkt->offset; rte_pktmbuf_refcnt_update(m, 1); - p->stats.n_pkts++; - p->stats.n_bytes += pkt->length; - p->stats.n_pkts_clone++; + p->pkts[n_pkts++] = m; + p->n_pkts = n_pkts; + p->n_bytes = n_bytes + pkt_length; + p->stats.n_pkts_clone = n_pkts_clone + 1; - p->pkts[p->n_pkts++] = m; - if (p->n_pkts == (int)p->params.burst_size) + if (n_pkts == (int)p->params.burst_size) __writer_flush(p); } @@ -297,7 +324,11 @@ static void writer_pkt_clone_tx(void *port, struct rte_swx_pkt *pkt, uint32_t truncation_length) { struct writer *p = port; + int n_pkts = p->n_pkts; + uint32_t n_bytes = p->n_bytes; + uint64_t n_pkts_clone = p->stats.n_pkts_clone; struct rte_mbuf *m = pkt->handle, *m_clone; + uint32_t pkt_length = pkt->length; TRACE("[Ethdev TX port %u queue %u] Pkt %d (%u bytes at offset %u) (clone)\n", (uint32_t)p->params.port_id, @@ -308,8 +339,8 @@ writer_pkt_clone_tx(void *port, struct rte_swx_pkt *pkt, uint32_t truncation_len if (TRACE_LEVEL) rte_hexdump(stdout, NULL, &pkt->pkt[pkt->offset], pkt->length); - m->data_len = (uint16_t)(pkt->length + m->data_len - m->pkt_len); - m->pkt_len = pkt->length; + m->data_len = (uint16_t)(pkt_length + m->data_len - m->pkt_len); + m->pkt_len = pkt_length; m->data_off = (uint16_t)pkt->offset; m_clone = rte_pktmbuf_copy(m, m->pool, 0, truncation_length); @@ -318,12 +349,12 @@ writer_pkt_clone_tx(void *port, struct rte_swx_pkt *pkt, uint32_t truncation_len return; } - p->stats.n_pkts++; - p->stats.n_bytes += pkt->length; - p->stats.n_pkts_clone++; + p->pkts[n_pkts++] = m_clone; + p->n_pkts = n_pkts; + p->n_bytes = n_bytes + pkt_length; + p->stats.n_pkts_clone = n_pkts_clone + 1; - p->pkts[p->n_pkts++] = m_clone; - if (p->n_pkts == (int)p->params.burst_size) + if (n_pkts == (int)p->params.burst_size) __writer_flush(p); } -- 2.34.1