Skip to contentSkip to conversation

net/ark: add recovery code for lack of mbufs during runtime

PATCH Superseded Ed Czeck 2 participants 9 messages Oct 8, 2018 – Oct 15, 2018 Network drivers

lore
Share & tools
lore

Ed Czeck

author
#0 lore raw

PATCH 1/3 net/ark: add recovery code for lack of mbufs during runtime

Fail with rte_exit() when the lack of mbufs is not recoverable.

---
 drivers/net/ark/ark_ethdev_rx.c | 52 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 46 insertions(+), 6 deletions(-)
drivers/net/ark/ark_ethdev_rx.c +46 -6
index 16f0d11..77149f6 100644
@@ -25,6 +25,9 @@ static uint32_t eth_ark_rx_jumbo(struct ark_rx_queue *queue,
 				 struct rte_mbuf *mbuf0,
 				 uint32_t cons_index);
 static inline int eth_ark_rx_seed_mbufs(struct ark_rx_queue *queue);
+static int eth_ark_rx_seed_recovery(struct ark_rx_queue *queue,
+				    uint32_t *pnb,
+				    struct rte_mbuf **mbufs);
 
 /* ************************************************************************* */
 struct ark_rx_queue {
@@ -196,20 +199,25 @@ eth_ark_dev_rx_queue_setup(struct rte_eth_dev *dev,
 	/* populate mbuf reserve */
 	status = eth_ark_rx_seed_mbufs(queue);
 
+	if (queue->seed_index != nb_desc) {
+		PMD_DRV_LOG(ERR, "ARK: Failed to allocate %u mbufs for RX queue %d\n",
+			    nb_desc, qidx);
+		status = -1;
+	}
 	/* MPU Setup */
 	if (status == 0)
 		status = eth_ark_rx_hw_setup(dev, queue, qidx, queue_idx);
 
 	if (unlikely(status != 0)) {
-		struct rte_mbuf *mbuf;
+		struct rte_mbuf **mbuf;
 
 		PMD_DRV_LOG(ERR, "Failed to initialize RX queue %d %s\n",
 			    qidx,
 			    __func__);
 		/* Free the mbufs allocated */
-		for (i = 0, mbuf = queue->reserve_q[0];
-		     i < nb_desc; ++i, mbuf++) {
-			rte_pktmbuf_free(mbuf);
+		for (i = 0, mbuf = queue->reserve_q;
+		     i < queue->seed_index; ++i, mbuf++) {
+			rte_pktmbuf_free(*mbuf);
 		}
 		rte_free(queue->reserve_q);
 		rte_free(queue->paddress_q);
@@ -446,8 +454,13 @@ eth_ark_rx_seed_mbufs(struct ark_rx_queue *queue)
 	struct rte_mbuf **mbufs = &queue->reserve_q[seed_m];
 	int status = rte_pktmbuf_alloc_bulk(queue->mb_pool, mbufs, nb);
 
-	if (unlikely(status != 0))
-		return -1;
+	if (unlikely(status != 0)) {
+		/* Try to recover from lack of mbufs in pool */
+		status = eth_ark_rx_seed_recovery(queue, &nb, mbufs);
+		if (unlikely(status != 0)) {
+			return -1;
+		}
+	}
 
 	if (ARK_RX_DEBUG) {		/* DEBUG */
 		while (count != nb) {
@@ -495,6 +508,33 @@ eth_ark_rx_seed_mbufs(struct ark_rx_queue *queue)
 	return 0;
 }
 
+int
+eth_ark_rx_seed_recovery(struct ark_rx_queue *queue,
+			 uint32_t *pnb,
+			 struct rte_mbuf **mbufs)
+{
+	int status = -1;
+
+	/* Ignore small allocation failures */
+	if (*pnb <= 64)
+		return -1;
+
+	*pnb = 64U;
+	status = rte_pktmbuf_alloc_bulk(queue->mb_pool, mbufs, *pnb);
+	if (status != 0) {
+		PMD_DRV_LOG(ERR,
+			    "ARK: Could not allocate %u mbufs from pool for RX queue %u;"
+			    " %u free buffers remaining in queue\n",
+			    *pnb, queue->queue_index,
+			    queue->seed_index - queue->cons_index);
+		if (queue->seed_index - queue->cons_index < 64) {
+			rte_exit(EXIT_FAILURE,
+				 "ARK: No mbufs in pool;  do you have a leak?\n");
+		}
+	}
+	return status;
+}
+
 void
 eth_ark_rx_dump_queue(struct rte_eth_dev *dev, uint16_t queue_id,
 		      const char *msg)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 2/3 net/ark: remove useless hardware notifications

Only send notification to mpu when crossing 64 index boundary.

---
 drivers/net/ark/ark_ethdev_rx.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ark/ark_ethdev_rx.c +5 -2
index 77149f6..e019b9d 100644
@@ -53,7 +53,7 @@ struct ark_rx_queue {
 	/* The queue Index is used within the dpdk device structures */
 	uint16_t queue_index;
 
-	uint32_t pad1;
+	uint32_t last_cons;
 
 	/* separate cache line */
 	/* second cache line - fields only used in slow path */
@@ -105,7 +105,10 @@ eth_ark_rx_update_cons_index(struct ark_rx_queue *queue, uint32_t cons_index)
 {
 	queue->cons_index = cons_index;
 	eth_ark_rx_seed_mbufs(queue);
-	ark_mpu_set_producer(queue->mpu, queue->seed_index);
+	if (((cons_index - queue->last_cons) >= 64U)) {
+		queue->last_cons = cons_index;
+		ark_mpu_set_producer(queue->mpu, queue->seed_index);
+	}
 }
 
 /* ************************************************************************* */
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH 3/3 net/ark: support for updated Tx hardware with user meta data

In reply to Ed Czeck

Support for version 2 of DDM hardware.
Add configurable setup for using DDM user meta data via CONFIG_RTE_LIBRTE_ARK_DDM_USER_META
defaults to 0 for the meta data compatible with v1 hardware. Set to 1 use uudata64.

---
 config/common_base              |  1 +
 drivers/net/ark/ark_ddm.c       |  5 ++++-
 drivers/net/ark/ark_ddm.h       |  7 +++++--
 drivers/net/ark/ark_ethdev_tx.c | 11 ++++++++++-
 4 files changed, 20 insertions(+), 4 deletions(-)
config/common_base +1 -0
index 4bcbaf9..c346229 100644
@@ -162,6 +162,7 @@ CONFIG_RTE_LIBRTE_ARK_DEBUG_RX=n
 CONFIG_RTE_LIBRTE_ARK_DEBUG_TX=n
 CONFIG_RTE_LIBRTE_ARK_DEBUG_STATS=n
 CONFIG_RTE_LIBRTE_ARK_DEBUG_TRACE=n
+CONFIG_RTE_LIBRTE_ARK_DDM_USER_META=0
 
 #
 # Compile AMD PMD
drivers/net/ark/ark_ddm.c +4 -1
index eea388a..70910d5 100644
@@ -11,13 +11,16 @@
 int
 ark_ddm_verify(struct ark_ddm_t *ddm)
 {
+	uint32_t hw_const;
 	if (sizeof(struct ark_ddm_t) != ARK_DDM_EXPECTED_SIZE) {
 		PMD_DRV_LOG(ERR, "ARK: DDM structure looks incorrect %d vs %zd\n",
 			    ARK_DDM_EXPECTED_SIZE, sizeof(struct ark_ddm_t));
 		return -1;
 	}
 
-	if (ddm->cfg.const0 != ARK_DDM_CONST) {
+	hw_const = ddm->cfg.const0;
+	if (hw_const != ARK_DDM_CONST1 &&
+	    hw_const != ARK_DDM_CONST2) {
 		PMD_DRV_LOG(ERR, "ARK: DDM module not found as expected 0x%08x\n",
 			    ddm->cfg.const0);
 		return -1;
drivers/net/ark/ark_ddm.h +5 -2
index b37d1e0..5456b4b 100644
@@ -19,7 +19,7 @@
 /* struct defining Tx meta data --  fixed in FPGA -- 16 bytes */
 struct ark_tx_meta {
 	uint64_t physaddr;
-	uint32_t delta_ns;
+	uint32_t user1;
 	uint16_t data_len;		/* of this MBUF */
 #define   ARK_DDM_EOP   0x01
 #define   ARK_DDM_SOP   0x02
@@ -34,7 +34,10 @@ struct ark_tx_meta {
  * structs will never be instantiated in ram memory
  */
 #define ARK_DDM_CFG 0x0000
-#define ARK_DDM_CONST 0xfacecafe
+/* Set unique HW ID for hardware version */
+#define ARK_DDM_CONST2 (0x324d4444)
+#define ARK_DDM_CONST1 (0xfacecafe)
+
 struct ark_ddm_cfg_t {
 	uint32_t r0;
 	volatile uint32_t tlp_stats_clear;
drivers/net/ark/ark_ethdev_tx.c +10 -1
index 57188c2..ad5ab06 100644
@@ -14,6 +14,15 @@
 #define ARK_TX_META_OFFSET (RTE_PKTMBUF_HEADROOM - ARK_TX_META_SIZE)
 #define ARK_TX_MAX_NOCHAIN (RTE_MBUF_DEFAULT_DATAROOM)
 
+/* Define source for TX meta data, const 0, from udata64 or user defined */
+#ifndef RTE_LIBRTE_ARK_DDM_USER_META
+#define ARK_DDM_USER_META 0
+#elseif RTE_LIBRTE_ARK_DDM_USER_META == 1
+#define  ARK_DDM_USER_META ((uint32_t)mbuf->udata64)
+#else
+#define  ARK_DDM_USER_META RTE_LIBRTE_ARK_DDM_USER_META
+#endif
+
 
 /* ************************************************************************* */
 struct ark_tx_queue {
@@ -65,7 +74,7 @@ eth_ark_tx_meta_from_mbuf(struct ark_tx_meta *meta,
 			  uint8_t flags)
 {
 	meta->physaddr = rte_mbuf_data_iova(mbuf);
-	meta->delta_ns = 0;
+	meta->user1 = ARK_DDM_USER_META;
 	meta->data_len = rte_pktmbuf_data_len(mbuf);
 	meta->flags = flags;
 }
Signature · 1 line
2.7.4
#6 lore raw
In reply to Ed Czeck
Quoted 3 lines · Ed Czeck

Fail with rte_exit() when the lack of mbufs is not recoverable.

<...>

Quoted 16 lines
drivers/net/ark/ark_ethdev_rx.c +12 -0
@@ -495,6 +508,33 @@ eth_ark_rx_seed_mbufs(struct ark_rx_queue *queue)
 	return 0;
 }
 
+int
+eth_ark_rx_seed_recovery(struct ark_rx_queue *queue,
+			 uint32_t *pnb,
+			 struct rte_mbuf **mbufs)
+{
+	int status = -1;
+
+	/* Ignore small allocation failures */
+	if (*pnb <= 64)
+		return -1;
+
+	*pnb = 64U;

drivers/net/ark/ark_ethdev_rx.c eth_ark_rx_seed_mbufs(struct ark_rx_queue *queue) · line 532

Quoted 10 lines
drivers/net/ark/ark_ethdev_rx.c +10 -0
+	status = rte_pktmbuf_alloc_bulk(queue->mb_pool, mbufs, *pnb);
+	if (status != 0) {
+		PMD_DRV_LOG(ERR,
+			    "ARK: Could not allocate %u mbufs from pool for RX queue %u;"
+			    " %u free buffers remaining in queue\n",
+			    *pnb, queue->queue_index,
+			    queue->seed_index - queue->cons_index);
+		if (queue->seed_index - queue->cons_index < 64) {
+			rte_exit(EXIT_FAILURE,
+				 "ARK: No mbufs in pool;  do you have a leak?\n");

Hi Ed,

We are trying to get rid of rte_exit() calls, reasoning is DPDK is a library and application should decide to exit or not, and a DPDK application may be using multiple NICs/libraries/functionalities, failure in one of them should not cause all application to exit.

Can you please replace rte_exit() usage?

#4 lore raw

Re: [PATCH 3/3] net/ark: support for updated Tx hardware with user meta data

In reply to Ed Czeck
Quoted 19 lines · Ed Czeck

Support for version 2 of DDM hardware.
Add configurable setup for using DDM user meta data via CONFIG_RTE_LIBRTE_ARK_DDM_USER_META
defaults to 0 for the meta data compatible with v1 hardware. Set to 1 use uudata64.

---
 config/common_base              |  1 +
 drivers/net/ark/ark_ddm.c       |  5 ++++-
 drivers/net/ark/ark_ddm.h       |  7 +++++--
 drivers/net/ark/ark_ethdev_tx.c | 11 ++++++++++-
 4 files changed, 20 insertions(+), 4 deletions(-)
config/common_base +0 -0
index 4bcbaf9..c346229 100644

config/common_base CONFIG_RTE_LIBRTE_ARK_DEBUG_RX=n · line 165

Quoted 4 lines
config/common_base +1 -0
@@ -162,6 +162,7 @@ CONFIG_RTE_LIBRTE_ARK_DEBUG_RX=n
 CONFIG_RTE_LIBRTE_ARK_DEBUG_TX=n
 CONFIG_RTE_LIBRTE_ARK_DEBUG_STATS=n
 CONFIG_RTE_LIBRTE_ARK_DEBUG_TRACE=n
+CONFIG_RTE_LIBRTE_ARK_DDM_USER_META=0

Hi Ed,

We are trying to reduce our compile time configuration, what do you think providing same functionality with devargs?

author
#7 lore raw

PATCH v2 1/3 net/ark: add recovery code for lack of mbufs during runtime

In reply to Ed Czeck

Attempt to allocate smaller chunk of mbufs when larger amount is not available. Report error when small chunk not available.

---
 drivers/net/ark/ark_ethdev_rx.c | 48 +++++++++++++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 6 deletions(-)
drivers/net/ark/ark_ethdev_rx.c +42 -6
index 16f0d11..5751585 100644
@@ -25,6 +25,9 @@ static uint32_t eth_ark_rx_jumbo(struct ark_rx_queue *queue,
 				 struct rte_mbuf *mbuf0,
 				 uint32_t cons_index);
 static inline int eth_ark_rx_seed_mbufs(struct ark_rx_queue *queue);
+static int eth_ark_rx_seed_recovery(struct ark_rx_queue *queue,
+				    uint32_t *pnb,
+				    struct rte_mbuf **mbufs);
 
 /* ************************************************************************* */
 struct ark_rx_queue {
@@ -196,20 +199,25 @@ eth_ark_dev_rx_queue_setup(struct rte_eth_dev *dev,
 	/* populate mbuf reserve */
 	status = eth_ark_rx_seed_mbufs(queue);
 
+	if (queue->seed_index != nb_desc) {
+		PMD_DRV_LOG(ERR, "ARK: Failed to allocate %u mbufs for RX queue %d\n",
+			    nb_desc, qidx);
+		status = -1;
+	}
 	/* MPU Setup */
 	if (status == 0)
 		status = eth_ark_rx_hw_setup(dev, queue, qidx, queue_idx);
 
 	if (unlikely(status != 0)) {
-		struct rte_mbuf *mbuf;
+		struct rte_mbuf **mbuf;
 
 		PMD_DRV_LOG(ERR, "Failed to initialize RX queue %d %s\n",
 			    qidx,
 			    __func__);
 		/* Free the mbufs allocated */
-		for (i = 0, mbuf = queue->reserve_q[0];
-		     i < nb_desc; ++i, mbuf++) {
-			rte_pktmbuf_free(mbuf);
+		for (i = 0, mbuf = queue->reserve_q;
+		     i < queue->seed_index; ++i, mbuf++) {
+			rte_pktmbuf_free(*mbuf);
 		}
 		rte_free(queue->reserve_q);
 		rte_free(queue->paddress_q);
@@ -446,8 +454,13 @@ eth_ark_rx_seed_mbufs(struct ark_rx_queue *queue)
 	struct rte_mbuf **mbufs = &queue->reserve_q[seed_m];
 	int status = rte_pktmbuf_alloc_bulk(queue->mb_pool, mbufs, nb);
 
-	if (unlikely(status != 0))
-		return -1;
+	if (unlikely(status != 0)) {
+		/* Try to recover from lack of mbufs in pool */
+		status = eth_ark_rx_seed_recovery(queue, &nb, mbufs);
+		if (unlikely(status != 0)) {
+			return -1;
+		}
+	}
 
 	if (ARK_RX_DEBUG) {		/* DEBUG */
 		while (count != nb) {
@@ -495,6 +508,29 @@ eth_ark_rx_seed_mbufs(struct ark_rx_queue *queue)
 	return 0;
 }
 
+int
+eth_ark_rx_seed_recovery(struct ark_rx_queue *queue,
+			 uint32_t *pnb,
+			 struct rte_mbuf **mbufs)
+{
+	int status = -1;
+
+	/* Ignore small allocation failures */
+	if (*pnb <= 64)
+		return -1;
+
+	*pnb = 64U;
+	status = rte_pktmbuf_alloc_bulk(queue->mb_pool, mbufs, *pnb);
+	if (status != 0) {
+		PMD_DRV_LOG(ERR,
+			    "ARK: Could not allocate %u mbufs from pool for RX queue %u;"
+			    " %u free buffers remaining in queue\n",
+			    *pnb, queue->queue_index,
+			    queue->seed_index - queue->cons_index);
+	}
+	return status;
+}
+
 void
 eth_ark_rx_dump_queue(struct rte_eth_dev *dev, uint16_t queue_id,
 		      const char *msg)
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v2 2/3 net/ark: remove useless hardware notifications

In reply to Ed Czeck

Only send notification to mpu when crossing 64 index boundary.

---
 drivers/net/ark/ark_ethdev_rx.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ark/ark_ethdev_rx.c +5 -2
index 5751585..300029d 100644
@@ -53,7 +53,7 @@ struct ark_rx_queue {
 	/* The queue Index is used within the dpdk device structures */
 	uint16_t queue_index;
 
-	uint32_t pad1;
+	uint32_t last_cons;
 
 	/* separate cache line */
 	/* second cache line - fields only used in slow path */
@@ -105,7 +105,10 @@ eth_ark_rx_update_cons_index(struct ark_rx_queue *queue, uint32_t cons_index)
 {
 	queue->cons_index = cons_index;
 	eth_ark_rx_seed_mbufs(queue);
-	ark_mpu_set_producer(queue->mpu, queue->seed_index);
+	if (((cons_index - queue->last_cons) >= 64U)) {
+		queue->last_cons = cons_index;
+		ark_mpu_set_producer(queue->mpu, queue->seed_index);
+	}
 }
 
 /* ************************************************************************* */
Signature · 1 line
2.7.4
author
#5 lore raw

PATCH v2 3/3 net/ark: support for updated hardware and Tx meta data

In reply to Ed Czeck

Support for version 2 of DDM hardware and user tx meta data. Verify version during initialization.

---
 drivers/net/ark/ark_ddm.c       | 12 ++++++++++--
 drivers/net/ark/ark_ddm.h       |  7 +++++--
 drivers/net/ark/ark_ethdev.c    |  3 +++
 drivers/net/ark/ark_ethdev_tx.c |  2 +-
 4 files changed, 19 insertions(+), 5 deletions(-)
drivers/net/ark/ark_ddm.c +10 -2
index eea388a..57026f8 100644
@@ -11,14 +11,22 @@
 int
 ark_ddm_verify(struct ark_ddm_t *ddm)
 {
+	uint32_t hw_const;
 	if (sizeof(struct ark_ddm_t) != ARK_DDM_EXPECTED_SIZE) {
 		PMD_DRV_LOG(ERR, "ARK: DDM structure looks incorrect %d vs %zd\n",
 			    ARK_DDM_EXPECTED_SIZE, sizeof(struct ark_ddm_t));
 		return -1;
 	}
 
-	if (ddm->cfg.const0 != ARK_DDM_CONST) {
-		PMD_DRV_LOG(ERR, "ARK: DDM module not found as expected 0x%08x\n",
+	hw_const = ddm->cfg.const0;
+	if (hw_const == ARK_DDM_CONST1) {
+		PMD_DRV_LOG(ERR,
+			    "ARK: DDM module is version 1, "
+			    "PMD expects version 2\n");
+		return -1;
+	} else if (hw_const != ARK_DDM_CONST2) {
+		PMD_DRV_LOG(ERR,
+			    "ARK: DDM module not found as expected 0x%08x\n",
 			    ddm->cfg.const0);
 		return -1;
 	}
drivers/net/ark/ark_ddm.h +5 -2
index b37d1e0..5456b4b 100644
@@ -19,7 +19,7 @@
 /* struct defining Tx meta data --  fixed in FPGA -- 16 bytes */
 struct ark_tx_meta {
 	uint64_t physaddr;
-	uint32_t delta_ns;
+	uint32_t user1;
 	uint16_t data_len;		/* of this MBUF */
 #define   ARK_DDM_EOP   0x01
 #define   ARK_DDM_SOP   0x02
@@ -34,7 +34,10 @@ struct ark_tx_meta {
  * structs will never be instantiated in ram memory
  */
 #define ARK_DDM_CFG 0x0000
-#define ARK_DDM_CONST 0xfacecafe
+/* Set unique HW ID for hardware version */
+#define ARK_DDM_CONST2 (0x324d4444)
+#define ARK_DDM_CONST1 (0xfacecafe)
+
 struct ark_ddm_cfg_t {
 	uint32_t r0;
 	volatile uint32_t tlp_stats_clear;
drivers/net/ark/ark_ethdev.c +3 -0
index 552ca01..c26f076 100644
@@ -313,6 +313,9 @@ eth_ark_dev_init(struct rte_eth_dev *dev)
 
 	/* We are a single function multi-port device. */
 	ret = ark_config_device(dev);
+	if (ret)
+		return -1;
+
 	dev->dev_ops = &ark_eth_dev_ops;
 
 	dev->data->mac_addrs = rte_zmalloc("ark", ETHER_ADDR_LEN, 0);
drivers/net/ark/ark_ethdev_tx.c +1 -1
index 57188c2..94da5f9 100644
@@ -65,7 +65,7 @@ eth_ark_tx_meta_from_mbuf(struct ark_tx_meta *meta,
 			  uint8_t flags)
 {
 	meta->physaddr = rte_mbuf_data_iova(mbuf);
-	meta->delta_ns = 0;
+	meta->user1 = (uint32_t)mbuf->udata64;
 	meta->data_len = rte_pktmbuf_data_len(mbuf);
 	meta->flags = flags;
 }
Signature · 1 line
2.7.4