Skip to contentSkip to conversation

net/ring: refactor to reduce indentation in probe

PATCH In review Ferruh Yigit 1 participant 3 messages Oct 2, 2020 – Apr 20, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 net/ring: refactor to reduce indentation in probe

No functional change.

---
 drivers/net/ring/rte_eth_ring.c | 137 +++++++++++++++-----------------
 1 file changed, 66 insertions(+), 71 deletions(-)
drivers/net/ring/rte_eth_ring.c +66 -71
index 83c5502123..6d3deaa81a 100644
@@ -598,85 +598,80 @@ rte_pmd_ring_probe(struct rte_vdev_device *dev)
 	PMD_LOG(INFO, "Initializing pmd_ring for %s", name);
 
 	if (params == NULL || params[0] == '\0') {
-		ret = eth_dev_ring_create(name, dev, rte_socket_id(), DEV_CREATE,
-				&eth_dev);
+		ret = eth_dev_ring_create(name, dev, rte_socket_id(),
+				DEV_CREATE, &eth_dev);
 		if (ret == -1) {
-			PMD_LOG(INFO,
-				"Attach to pmd_ring for %s", name);
+			PMD_LOG(INFO, "Attach to pmd_ring for %s", name);
 			ret = eth_dev_ring_create(name, dev, rte_socket_id(),
-						  DEV_ATTACH, &eth_dev);
+					DEV_ATTACH, &eth_dev);
 		}
-	} else {
-		kvlist = rte_kvargs_parse(params, valid_arguments);
 
-		if (!kvlist) {
-			PMD_LOG(INFO,
-				"Ignoring unsupported parameters when creatingrings-backed ethernet device");
+		return ret;
+	}
+
+	kvlist = rte_kvargs_parse(params, valid_arguments);
+	if (!kvlist) {
+		PMD_LOG(INFO,
+			"Ignoring unsupported parameters when creatingrings-backed ethernet device");
+		ret = eth_dev_ring_create(name, dev, rte_socket_id(),
+				DEV_CREATE, &eth_dev);
+		if (ret == -1) {
+			PMD_LOG(INFO, "Attach to pmd_ring for %s", name);
 			ret = eth_dev_ring_create(name, dev, rte_socket_id(),
-						  DEV_CREATE, &eth_dev);
-			if (ret == -1) {
-				PMD_LOG(INFO,
-					"Attach to pmd_ring for %s",
-					name);
-				ret = eth_dev_ring_create(name, dev, rte_socket_id(),
-							  DEV_ATTACH, &eth_dev);
-			}
-
-			return ret;
+					DEV_ATTACH, &eth_dev);
 		}
 
-		if (rte_kvargs_count(kvlist, ETH_RING_INTERNAL_ARG) == 1) {
-			ret = rte_kvargs_process(kvlist, ETH_RING_INTERNAL_ARG,
-						 parse_internal_args,
-						 &internal_args);
-			if (ret < 0)
-				goto out_free;
-
-			ret = do_eth_dev_ring_create(name, dev,
-				internal_args->rx_queues,
-				internal_args->nb_rx_queues,
-				internal_args->tx_queues,
-				internal_args->nb_tx_queues,
-				internal_args->numa_node,
-				DEV_ATTACH,
+		return ret;
+	}
+
+	if (rte_kvargs_count(kvlist, ETH_RING_INTERNAL_ARG) == 1) {
+		ret = rte_kvargs_process(kvlist, ETH_RING_INTERNAL_ARG,
+					 parse_internal_args,
+					 &internal_args);
+		if (ret < 0)
+			goto out_free;
+
+		ret = do_eth_dev_ring_create(name, dev,
+			internal_args->rx_queues,
+			internal_args->nb_rx_queues,
+			internal_args->tx_queues,
+			internal_args->nb_tx_queues,
+			internal_args->numa_node,
+			DEV_ATTACH,
+			&eth_dev);
+		if (ret >= 0)
+			ret = 0;
+		goto out_free;
+	}
+
+	ret = rte_kvargs_count(kvlist, ETH_RING_NUMA_NODE_ACTION_ARG);
+	info = rte_zmalloc("struct node_action_list",
+			   sizeof(struct node_action_list) +
+			   (sizeof(struct node_action_pair) * ret),
+			   0);
+	if (!info)
+		goto out_free;
+
+	info->total = ret;
+	info->list = (struct node_action_pair *)(info + 1);
+
+	ret = rte_kvargs_process(kvlist, ETH_RING_NUMA_NODE_ACTION_ARG,
+				 parse_kvlist, info);
+
+	if (ret < 0)
+		goto out_free;
+
+	for (info->count = 0; info->count < info->total; info->count++) {
+		ret = eth_dev_ring_create(info->list[info->count].name, dev,
+				info->list[info->count].node,
+				info->list[info->count].action,
 				&eth_dev);
-			if (ret >= 0)
-				ret = 0;
-		} else {
-			ret = rte_kvargs_count(kvlist, ETH_RING_NUMA_NODE_ACTION_ARG);
-			info = rte_zmalloc("struct node_action_list",
-					   sizeof(struct node_action_list) +
-					   (sizeof(struct node_action_pair) * ret),
-					   0);
-			if (!info)
-				goto out_free;
-
-			info->total = ret;
-			info->list = (struct node_action_pair *)(info + 1);
-
-			ret = rte_kvargs_process(kvlist, ETH_RING_NUMA_NODE_ACTION_ARG,
-						 parse_kvlist, info);
-
-			if (ret < 0)
-				goto out_free;
-
-			for (info->count = 0; info->count < info->total; info->count++) {
-				ret = eth_dev_ring_create(info->list[info->count].name,
-							  dev,
-							  info->list[info->count].node,
-							  info->list[info->count].action,
-							  &eth_dev);
-				if ((ret == -1) &&
-				    (info->list[info->count].action == DEV_CREATE)) {
-					PMD_LOG(INFO,
-						"Attach to pmd_ring for %s",
-						name);
-					ret = eth_dev_ring_create(name, dev,
-							info->list[info->count].node,
-							DEV_ATTACH,
-							&eth_dev);
-				}
-			}
+		if ((ret == -1) && (info->list[info->count].action == DEV_CREATE)) {
+			PMD_LOG(INFO, "Attach to pmd_ring for %s", name);
+			ret = eth_dev_ring_create(name, dev,
+					info->list[info->count].node,
+					DEV_ATTACH,
+					&eth_dev);
 		}
 	}
 
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/2 net/ring: prevent nodeaction arg create multiple ethdev

PMD accepts multiple 'nodeaction' arguments per vdev, for each instance of the devarg an ethdev is created.
Like:
"--vdev net_ring0,nodeaction=r1:0:CREATE,nodeaction=r2:0:CREATE" allocates two ethdevs.
Here ethdev names will be 'r1' and 'r2' respectively (each ethdev with hardcoded number of queues).

If multiple ring ethdev is required, this can already be achieved by providing multiple '--vdev'.

This patch updates the multiple 'nodeaction' arguments behavior, it now creates single ethdev per a '--vdev' and each 'nodeaction' argument used to define a queue of the ethdev. Number of 'nodeaction' argument defines number of the queues in device.
Like for above sample:
"--vdev net_ring0,nodeaction=r1:0:CREATE,nodeaction=r2:0:CREATE", creates an ethdev named 'net_ring0' with two queues from newly created rings. Ring names are 'r1' and 'r2'.
For ethdev device 'node' and 'action' values are used from first instance of the 'nodeaction' argument.

The behavior of the single 'nodeaction' argument behavior is slightly changed, it now allocates (create or attach) single queue, instead of hardcoded number of queues as done before.

The behavior without 'nodeaction' argument, "--vdev net_ring0", has not been changed at all.

This also allows following, which was broken before:
"--vdev net_ring0,nodeaction=r1:0:CREATE,nodeaction=r2:0:CREATE \
--vdev net_ring1,nodeaction=r1:0:ATTACH,nodeaction=r2:0:ATTACH"

---
 drivers/net/ring/rte_eth_ring.c | 53 +++++++++++++++++++++++++--------
 1 file changed, 40 insertions(+), 13 deletions(-)
drivers/net/ring/rte_eth_ring.c +40 -13
index 6d3deaa81a..fd02c06c56 100644
@@ -495,6 +495,38 @@ struct node_action_list {
 	struct node_action_pair *list;
 };
 
+static int
+eth_dev_ring_create_nodeaction(const char *name,
+		struct rte_vdev_device *vdev,
+		const unsigned int numa_node,
+		enum dev_action action,
+		struct rte_eth_dev **eth_dev,
+		struct node_action_list *info)
+{
+	struct rte_ring *rxtx[RTE_PMD_RING_MAX_RX_RINGS];
+	unsigned int num_rings;
+	unsigned int i;
+
+	num_rings = info->total;
+
+	for (i = 0; i < num_rings; i++) {
+		if (action == DEV_CREATE)
+			rxtx[i] = rte_ring_create(info->list[i].name, 1024,
+					numa_node,
+					RING_F_SP_ENQ|RING_F_SC_DEQ);
+		else
+			rxtx[i] = rte_ring_lookup(info->list[i].name);
+		if (rxtx[i] == NULL)
+			return -1;
+	}
+
+	if (do_eth_dev_ring_create(name, vdev, rxtx, num_rings, rxtx,
+			num_rings, numa_node, action, eth_dev) < 0)
+		return -1;
+
+	return 0;
+}
+
 static int parse_kvlist(const char *key __rte_unused,
 			const char *value, void *data)
 {
@@ -657,22 +689,17 @@ rte_pmd_ring_probe(struct rte_vdev_device *dev)
 
 	ret = rte_kvargs_process(kvlist, ETH_RING_NUMA_NODE_ACTION_ARG,
 				 parse_kvlist, info);
-
 	if (ret < 0)
 		goto out_free;
 
-	for (info->count = 0; info->count < info->total; info->count++) {
-		ret = eth_dev_ring_create(info->list[info->count].name, dev,
-				info->list[info->count].node,
-				info->list[info->count].action,
-				&eth_dev);
-		if ((ret == -1) && (info->list[info->count].action == DEV_CREATE)) {
-			PMD_LOG(INFO, "Attach to pmd_ring for %s", name);
-			ret = eth_dev_ring_create(name, dev,
-					info->list[info->count].node,
-					DEV_ATTACH,
-					&eth_dev);
-		}
+	ret = eth_dev_ring_create_nodeaction(name, dev,
+			info->list[0].node,
+			info->list[0].action, &eth_dev, info);
+	if ((ret == -1) && (info->list[0].action == DEV_CREATE)) {
+		PMD_LOG(INFO, "Attach to pmd_ring for %s", name);
+		ret = eth_dev_ring_create_nodeaction(name, dev,
+				info->list[0].node,
+				DEV_ATTACH, &eth_dev, info);
 	}
 
 out_free:
Signature · 1 line
2.26.2