DPDK patches and discussions
 help / color / mirror / Atom feed
From: beilei.xing@intel.com
To: jingjing.wu@intel.com, qi.z.zhang@intel.com
Cc: dev@dpdk.org, stable@dpdk.org, Beilei Xing <beilei.xing@intel.com>
Subject: [PATCH 3/3] net/idpf: fix splitq xmit free
Date: Thu,  8 Dec 2022 07:27:25 +0000	[thread overview]
Message-ID: <20221208072725.32434-4-beilei.xing@intel.com> (raw)
In-Reply-To: <20221208072725.32434-1-beilei.xing@intel.com>

From: Jingjing Wu <jingjing.wu@intel.com>

When context descriptor is used during sending packets, mbuf
is not freed correctly, it will cause mempool be exhausted.
This patch refines the free function.

Fixes: 770f4dfe0f79 ("net/idpf: support basic Tx data path")
Cc: stable@dpdk.org

Signed-off-by: Jingjing Wu <jingjing.wu@intel.com>
Signed-off-by: Beilei Xing <beilei.xing@intel.com>
---
 drivers/net/idpf/idpf_rxtx.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/drivers/net/idpf/idpf_rxtx.c b/drivers/net/idpf/idpf_rxtx.c
index b4a396c3f5..5aef8ba2b6 100644
--- a/drivers/net/idpf/idpf_rxtx.c
+++ b/drivers/net/idpf/idpf_rxtx.c
@@ -1508,6 +1508,7 @@ idpf_split_tx_free(struct idpf_tx_queue *cq)
 	struct idpf_tx_entry *txe;
 	struct idpf_tx_queue *txq;
 	uint16_t gen, qid, q_head;
+	uint16_t nb_desc_clean;
 	uint8_t ctype;
 
 	txd = &compl_ring[next];
@@ -1525,20 +1526,24 @@ idpf_split_tx_free(struct idpf_tx_queue *cq)
 
 	switch (ctype) {
 	case IDPF_TXD_COMPLT_RE:
-		if (q_head == 0)
-			txq->last_desc_cleaned = txq->nb_tx_desc - 1;
-		else
-			txq->last_desc_cleaned = q_head - 1;
-		if (unlikely((txq->last_desc_cleaned % 32) == 0)) {
+		/* clean to q_head which indicates be fetched txq desc id + 1.
+		 * TODO: need to refine and remove the if condition.
+		 */
+		if (unlikely(q_head % 32)) {
 			PMD_DRV_LOG(ERR, "unexpected desc (head = %u) completion.",
 						q_head);
 			return;
 		}
-
+		if (txq->last_desc_cleaned > q_head)
+			nb_desc_clean = (txq->nb_tx_desc - txq->last_desc_cleaned) +
+				q_head;
+		else
+			nb_desc_clean = q_head - txq->last_desc_cleaned;
+		txq->nb_free += nb_desc_clean;
+		txq->last_desc_cleaned = q_head;
 		break;
 	case IDPF_TXD_COMPLT_RS:
-		txq->nb_free++;
-		txq->nb_used--;
+		/* q_head indicates sw_id when ctype is 2 */
 		txe = &txq->sw_ring[q_head];
 		if (txe->mbuf != NULL) {
 			rte_pktmbuf_free_seg(txe->mbuf);
@@ -1693,12 +1698,16 @@ idpf_splitq_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 		/* fill the last descriptor with End of Packet (EOP) bit */
 		txd->qw1.cmd_dtype |= IDPF_TXD_FLEX_FLOW_CMD_EOP;
 
-		if (unlikely((tx_id % 32) == 0))
-			txd->qw1.cmd_dtype |= IDPF_TXD_FLEX_FLOW_CMD_RE;
 		if (ol_flags & IDPF_TX_CKSUM_OFFLOAD_MASK)
 			txd->qw1.cmd_dtype |= IDPF_TXD_FLEX_FLOW_CMD_CS_EN;
 		txq->nb_free = (uint16_t)(txq->nb_free - nb_used);
 		txq->nb_used = (uint16_t)(txq->nb_used + nb_used);
+
+		if (txq->nb_used >= 32) {
+			txd->qw1.cmd_dtype |= IDPF_TXD_FLEX_FLOW_CMD_RE;
+			/* Update txq RE bit counters */
+			txq->nb_used = 0;
+		}
 	}
 
 	/* update the tail pointer if any packets were processed */
-- 
2.26.2


  parent reply	other threads:[~2022-12-08  7:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08  7:27 [PATCH 0/3] net/idpf: code refine beilei.xing
2022-12-08  7:27 ` [PATCH 1/3] net/idpf: remove vport req and recv info from adapter beilei.xing
2022-12-08  7:27 ` [PATCH 2/3] net/idpf: remove req vports " beilei.xing
2022-12-08  7:27 ` beilei.xing [this message]
2023-01-06  9:04 ` [PATCH v2 0/5] net/idpf: code refine beilei.xing
2023-01-06  9:04   ` [PATCH v2 1/5] net/idpf: remove vport req and recv info from adapter beilei.xing
2023-01-06  9:04   ` [PATCH v2 2/5] net/idpf: remove req vports " beilei.xing
2023-01-06  9:04   ` [PATCH v2 3/5] net/idpf: fix splitq xmit free beilei.xing
2023-01-06  9:05   ` [PATCH v2 4/5] net/idpf: fix driver init symbols beilei.xing
2023-01-06  9:05   ` [PATCH v2 5/5] net/idpf: refine MTU setting beilei.xing
2023-01-16  7:59   ` [PATCH v2 0/5] net/idpf: code refine Zhang, Qi Z

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221208072725.32434-4-beilei.xing@intel.com \
    --to=beilei.xing@intel.com \
    --cc=dev@dpdk.org \
    --cc=jingjing.wu@intel.com \
    --cc=qi.z.zhang@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).