Skip to contentSkip to conversation

ethdev: add siblings iterator

PATCH In review Thomas Monjalon 8 participants 41 messages Nov 30, 2018 – Apr 4, 2019 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ethdev: add siblings iterator

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new function and loop macro.

The ownership is not checked because siblings may have different owners.

---
 lib/librte_ethdev/rte_ethdev.c           | 15 +++++++++++++++
 lib/librte_ethdev/rte_ethdev.h           | 23 +++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  1 +
 3 files changed, 39 insertions(+)
lib/librte_ethdev/rte_ethdev.c +15 -0
index 5f858174b..11e0ade6e 100644
@@ -341,6 +341,21 @@ rte_eth_find_next(uint16_t port_id)
 	return port_id;
 }
 
+uint16_t __rte_experimental
+rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref)
+{
+	while (port_id < RTE_MAX_ETHPORTS &&
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED &&
+			rte_eth_devices[port_id].device !=
+				rte_eth_devices[ref].device)
+		port_id++;
+
+	if (port_id >= RTE_MAX_ETHPORTS)
+		return RTE_MAX_ETHPORTS;
+
+	return port_id;
+}
+
 static void
 rte_eth_dev_shared_data_prepare(void)
 {
lib/librte_ethdev/rte_ethdev.h +23 -0
index 1960f3a2d..647e6634d 100644
@@ -1383,6 +1383,29 @@ uint16_t rte_eth_find_next(uint16_t port_id);
 #define RTE_ETH_FOREACH_DEV(p) \
 	RTE_ETH_FOREACH_DEV_OWNED_BY(p, RTE_ETH_DEV_NO_OWNER)
 
+/**
+ * Iterates over sibling ethdev ports (i.e. sharing the same rte_device).
+ *
+ * @param port_id_start
+ *   The id of the next possible valid sibling port.
+ * @param ref
+ *   The id of a reference port to compare rte_device with.
+ * @return
+ *   Next sibling port id (or ref itself), RTE_MAX_ETHPORTS if there is none.
+ */
+__rte_experimental
+uint16_t rte_eth_find_next_sibling(uint16_t port_id_start, uint16_t ref);
+
+/**
+ * Macro to iterate over all ethdev ports sharing the same rte_device
+ * as the specified port.
+ * Note: the specified port is part of the loop iterations.
+ */
+#define RTE_ETH_FOREACH_DEV_SIBLING(p, ref) \
+	for (p = rte_eth_find_next_sibling(0, ref); \
+		p < RTE_MAX_ETHPORTS; \
+		p = rte_eth_find_next_sibling(p + 1, ref))
+
 
 /**
  * @warning
lib/librte_ethdev/rte_ethdev_version.map +1 -0
index 92ac3de25..a0c930d04 100644
@@ -245,6 +245,7 @@ EXPERIMENTAL {
 	rte_eth_dev_owner_set;
 	rte_eth_dev_owner_unset;
 	rte_eth_dev_rx_intr_ctl_q_get_fd;
+	rte_eth_find_next_sibling;
 	rte_eth_switch_domain_alloc;
 	rte_eth_switch_domain_free;
 	rte_flow_conv;
Signature · 1 line
2.19.0
#1 lore raw
Quoted 6 lines · Thomas Monjalon

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new function and loop macro.

The ownership is not checked because siblings may have different owners.

Looks good on its own, but I think now we require an implementation of any new API, so it can be good to have:
- a sample implementation of this new API and the macro
- an unit test for the API and the macro

Quoted 13 lines
---
 lib/librte_ethdev/rte_ethdev.c           | 15 +++++++++++++++
 lib/librte_ethdev/rte_ethdev.h           | 23 +++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  1 +
 3 files changed, 39 insertions(+)
lib/librte_ethdev/rte_ethdev.c +0 -0
index 5f858174b..11e0ade6e 100644

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 344

Quoted 4 lines
lib/librte_ethdev/rte_ethdev.c +1 -0
@@ -341,6 +341,21 @@ rte_eth_find_next(uint16_t port_id)
 	return port_id;
 }
 
+uint16_t __rte_experimental

I think __rte_experimental tag only in header file is sufficient

Quoted 64 lines
lib/librte_ethdev/rte_ethdev.c +14 -0
+rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref)
+{
+	while (port_id < RTE_MAX_ETHPORTS &&
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED &&
+			rte_eth_devices[port_id].device !=
+				rte_eth_devices[ref].device)
+		port_id++;
+
+	if (port_id >= RTE_MAX_ETHPORTS)
+		return RTE_MAX_ETHPORTS;
+
+	return port_id;
+}
+
 static void
 rte_eth_dev_shared_data_prepare(void)
 {
lib/librte_ethdev/rte_ethdev.h +23 -0
index 1960f3a2d..647e6634d 100644
@@ -1383,6 +1383,29 @@ uint16_t rte_eth_find_next(uint16_t port_id);
 #define RTE_ETH_FOREACH_DEV(p) \
 	RTE_ETH_FOREACH_DEV_OWNED_BY(p, RTE_ETH_DEV_NO_OWNER)
 
+/**
+ * Iterates over sibling ethdev ports (i.e. sharing the same rte_device).
+ *
+ * @param port_id_start
+ *   The id of the next possible valid sibling port.
+ * @param ref
+ *   The id of a reference port to compare rte_device with.
+ * @return
+ *   Next sibling port id (or ref itself), RTE_MAX_ETHPORTS if there is none.
+ */
+__rte_experimental
+uint16_t rte_eth_find_next_sibling(uint16_t port_id_start, uint16_t ref);
+
+/**
+ * Macro to iterate over all ethdev ports sharing the same rte_device
+ * as the specified port.
+ * Note: the specified port is part of the loop iterations.
+ */
+#define RTE_ETH_FOREACH_DEV_SIBLING(p, ref) \
+	for (p = rte_eth_find_next_sibling(0, ref); \
+		p < RTE_MAX_ETHPORTS; \
+		p = rte_eth_find_next_sibling(p + 1, ref))
+
 
 /**
  * @warning
lib/librte_ethdev/rte_ethdev_version.map +1 -0
index 92ac3de25..a0c930d04 100644
@@ -245,6 +245,7 @@ EXPERIMENTAL {
 	rte_eth_dev_owner_set;
 	rte_eth_dev_owner_unset;
 	rte_eth_dev_rx_intr_ctl_q_get_fd;
+	rte_eth_find_next_sibling;
 	rte_eth_switch_domain_alloc;
 	rte_eth_switch_domain_free;
 	rte_flow_conv;
#2 lore raw

11/12/2018 17:31, Ferruh Yigit:

Quoted 5 lines · Thomas Monjalon
Quoted 4 lines

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new function and loop macro.

Quoted 7 lines
Quoted 2 lines

The ownership is not checked because siblings may have different owners.

Looks good on its own, but I think now we require an implementation of any new API, so it can be good to have:
- a sample implementation of this new API and the macro
- an unit test for the API and the macro

Yes sure.
I should have added "RFC" in the title.
v2 will have some usage of this API.
About the unit test, I'm really not sure whether we should test the ehtdev API in test/test/ or just inside testpmd. We used to implement ethdev tests only in testpmd. Opinions?

#3 lore raw

v2 cover ethdev iterators for multi-ports device

In reply to Thomas Monjalon

Add port iterators in order to allow listing easily the ports of the same device.

The iterators can be tested by using mlx5 or testpmd.

Thomas Monjalon (4):
ethdev: simplify port state comparisons
ethdev: add siblings iterators
net/mlx5: use port sibling iterators app/testpmd: use port sibling iterator in device cleanup

 app/test-pmd/testpmd.c                   |  4 +--
 drivers/net/mlx5/mlx5.c                  | 34 +++++++-----------
 drivers/net/mlx5/mlx5_ethdev.c           |  6 +---
 lib/librte_ethdev/rte_ethdev.c           | 26 +++++++++++---
 lib/librte_ethdev/rte_ethdev.h           | 46 ++++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  2 ++
 6 files changed, 85 insertions(+), 33 deletions(-)
Signature · 1 line
2.20.1
#4 lore raw

PATCH v2 1/4 ethdev: simplify port state comparisons

There are three states for an ethdev port. Checking that the port is unused looks simpler than checking it is neither attached nor removed.

---
 lib/librte_ethdev/rte_ethdev.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/librte_ethdev/rte_ethdev.c +2 -4
index 0d192a24b2..b3b2fb1dba 100644
@@ -331,8 +331,7 @@ uint16_t
 rte_eth_find_next(uint16_t port_id)
 {
 	while (port_id < RTE_MAX_ETHPORTS &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED)
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)
 		port_id++;
 
 	if (port_id >= RTE_MAX_ETHPORTS)
@@ -558,8 +557,7 @@ uint64_t
 rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
 {
 	while (port_id < RTE_MAX_ETHPORTS &&
-	       ((rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED) ||
+	       (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED ||
 	       rte_eth_devices[port_id].data->owner.id != owner_id))
 		port_id++;
 
Signature · 1 line
2.20.1
Reviewed-by on v2 1/4
#5 lore raw

Re: [PATCH v2 1/4] ethdev: simplify port state comparisons

Quoted 5 lines · Thomas Monjalon

There are three states for an ethdev port. Checking that the port is unused looks simpler than checking it is neither attached nor removed.

It is not always equivalent (if/when more states added), but I think comparison to RTE_ETH_DEV_UNUSED is really better here.

#6 lore raw

PATCH v2 2/4 ethdev: add siblings iterators

In reply to Thomas Monjalon

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new functions and loop macros.
One iterator takes a port id as reference,
while the other one directly refers to the parent device.

The ownership is not checked because siblings may have different owners.

---
 lib/librte_ethdev/rte_ethdev.c           | 20 +++++++++++
 lib/librte_ethdev/rte_ethdev.h           | 46 ++++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  2 ++
 3 files changed, 68 insertions(+)
lib/librte_ethdev/rte_ethdev.c +20 -0
index b3b2fb1dba..42154787f8 100644
@@ -340,6 +340,26 @@ rte_eth_find_next(uint16_t port_id)
 	return port_id;
 }
 
+uint16_t __rte_experimental
+rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
+{
+	while (port_id < RTE_MAX_ETHPORTS &&
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED &&
+			rte_eth_devices[port_id].device != parent)
+		port_id++;
+
+	if (port_id >= RTE_MAX_ETHPORTS)
+		return RTE_MAX_ETHPORTS;
+
+	return port_id;
+}
+
+uint16_t __rte_experimental
+rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref)
+{
+	return rte_eth_find_next_of(port_id, rte_eth_devices[ref].device);
+}
+
 static void
 rte_eth_dev_shared_data_prepare(void)
 {
lib/librte_ethdev/rte_ethdev.h +46 -0

52 lines not on this page · raw message

lib/librte_ethdev/rte_ethdev_version.map +2 -0
index 92ac3de250..b37a4167d7 100644
@@ -245,6 +245,8 @@ EXPERIMENTAL {
 	rte_eth_dev_owner_set;
 	rte_eth_dev_owner_unset;
 	rte_eth_dev_rx_intr_ctl_q_get_fd;
+	rte_eth_find_next_of;
+	rte_eth_find_next_sibling;
 	rte_eth_switch_domain_alloc;
 	rte_eth_switch_domain_free;
 	rte_flow_conv;
Signature · 1 line
2.20.1
Reviewed-by on v2 2/4
#7 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

Quoted 10 lines · Thomas Monjalon

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new functions and loop macros.
One iterator takes a port id as reference,
while the other one directly refers to the parent device.

The ownership is not checked because siblings may have different owners.

LGTM

#8 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

In reply to Thomas Monjalon

Hi Thomas,

Quoted 21 lines · Thomas Monjalon

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new functions and loop macros.
One iterator takes a port id as reference,
while the other one directly refers to the parent device.

The ownership is not checked because siblings may have different owners.

---
 lib/librte_ethdev/rte_ethdev.c           | 20 +++++++++++
 lib/librte_ethdev/rte_ethdev.h           | 46 ++++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  2 ++
 3 files changed, 68 insertions(+)
lib/librte_ethdev/rte_ethdev.c +0 -0
index b3b2fb1dba..42154787f8 100644

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 349

Quoted 10 lines
lib/librte_ethdev/rte_ethdev.c +7 -0
@@ -340,6 +340,26 @@ rte_eth_find_next(uint16_t port_id)
 	return port_id;
 }
 
+uint16_t __rte_experimental
+rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
+{
+	while (port_id < RTE_MAX_ETHPORTS &&
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED &&
+			rte_eth_devices[port_id].device != parent)
+		port_id++;

Why not call rte_eth_find_next directly from this function, and add your specific test on top of it?

Something like:

    	while (port_id < RTE_MAX_ETHPORTS &&
    	       rte_eth_devices[port_id].device != parent)
    		port_id = rte_eth_find_next(port_id + 1);

this way you won't have to rewrite the test on the device state. Having the logic expressed in several places would make reworking the device states more complicated than necessary if it were to happen (just as you did when switching the test from !(ATTACHED || REMOVED) to (UNUSED).

Signature · 2 lines
Gaëtan Rivet
6WIND
#9 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

27/02/2019 11:07, Gaëtan Rivet:

Quoted 40 lines

Hi Thomas,

Quoted 21 lines · Thomas Monjalon

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new functions and loop macros.
One iterator takes a port id as reference,
while the other one directly refers to the parent device.

The ownership is not checked because siblings may have different owners.

---
 lib/librte_ethdev/rte_ethdev.c           | 20 +++++++++++
 lib/librte_ethdev/rte_ethdev.h           | 46 ++++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  2 ++
 3 files changed, 68 insertions(+)
lib/librte_ethdev/rte_ethdev.c +0 -0
index b3b2fb1dba..42154787f8 100644

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 349

Quoted 10 lines
lib/librte_ethdev/rte_ethdev.c +7 -0
@@ -340,6 +340,26 @@ rte_eth_find_next(uint16_t port_id)
 	return port_id;
 }
 
+uint16_t __rte_experimental
+rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
+{
+	while (port_id < RTE_MAX_ETHPORTS &&
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED &&
+			rte_eth_devices[port_id].device != parent)
+		port_id++;

Why not call rte_eth_find_next directly from this function, and add your specific test on top of it?

Something like:

Quoted 8 lines
    	while (port_id < RTE_MAX_ETHPORTS &&
    	       rte_eth_devices[port_id].device != parent)
    		port_id = rte_eth_find_next(port_id + 1);

this way you won't have to rewrite the test on the device state. Having the logic expressed in several places would make reworking the device states more complicated than necessary if it were to happen (just as you did when switching the test from !(ATTACHED || REMOVED) to (UNUSED).

About the intent, you are right.
About the solution, it seems buggy. We can try to find another way of coding this loop by using rte_eth_find_next()
and adding the parent condition.

#10 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

27/02/2019 11:51, Thomas Monjalon:

Quoted 24 lines

27/02/2019 11:07, Gaëtan Rivet:

Quoted 14 lines · Thomas Monjalon

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 349

Quoted 7 lines
lib/librte_ethdev/rte_ethdev.c +7 -0
+uint16_t __rte_experimental
+rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
+{
+	while (port_id < RTE_MAX_ETHPORTS &&
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED &&
+			rte_eth_devices[port_id].device != parent)
+		port_id++;

Why not call rte_eth_find_next directly from this function, and add your specific test on top of it?

Something like:

Quoted 8 lines
    	while (port_id < RTE_MAX_ETHPORTS &&
    	       rte_eth_devices[port_id].device != parent)
    		port_id = rte_eth_find_next(port_id + 1);

this way you won't have to rewrite the test on the device state. Having the logic expressed in several places would make reworking the device states more complicated than necessary if it were to happen (just as you did when switching the test from !(ATTACHED || REMOVED) to (UNUSED).

Quoted 4 lines

About the intent, you are right.
About the solution, it seems buggy. We can try to find another way of coding this loop by using rte_eth_find_next()
and adding the parent condition.

Your proposal is correct if adding a first call before the loop:

	port_id = rte_eth_find_next(port_id);
#11 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

In reply to Thomas Monjalon
Quoted 21 lines · Thomas Monjalon

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new functions and loop macros.
One iterator takes a port id as reference,
while the other one directly refers to the parent device.

The ownership is not checked because siblings may have different owners.

---
 lib/librte_ethdev/rte_ethdev.c           | 20 +++++++++++
 lib/librte_ethdev/rte_ethdev.h           | 46 ++++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  2 ++
 3 files changed, 68 insertions(+)
lib/librte_ethdev/rte_ethdev.c +0 -0
index b3b2fb1dba..42154787f8 100644

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 343

Quoted 4 lines
lib/librte_ethdev/rte_ethdev.c +1 -0
@@ -340,6 +340,26 @@ rte_eth_find_next(uint16_t port_id)
 	return port_id;
 }
 
+uint16_t __rte_experimental

Do we need _rte_experimental on function definitions? I guess only in .h file, function declaration is enough.

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 344

Quoted 1 line
lib/librte_ethdev/rte_ethdev.c +1 -0
+rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)

Out of curiosity, what '_of' refers to?

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 349

Quoted 5 lines
lib/librte_ethdev/rte_ethdev.c +5 -0
+{
+	while (port_id < RTE_MAX_ETHPORTS &&
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED &&
+			rte_eth_devices[port_id].device != parent)
+		port_id++;

Is this logic correct, or am I missing something.
When port status is ATTACHED, check will return false and exit from loop without checking if the 'device' is same.
+1 to Gaetan's suggestion to use 'rte_eth_find_next()', which moves status concern to that function.

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 358

Quoted 9 lines
lib/librte_ethdev/rte_ethdev.c +9 -0
+
+	if (port_id >= RTE_MAX_ETHPORTS)
+		return RTE_MAX_ETHPORTS;
+
+	return port_id;
+}
+
+uint16_t __rte_experimental
+rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref)

I think better to say 'ref_port_id' to clarify what we expect here is a port_id

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 360

Quoted 2 lines
lib/librte_ethdev/rte_ethdev.c +2 -0
+{
+	return rte_eth_find_next_of(port_id, rte_eth_devices[ref].device);

This is a public API, shouldn't we check if 'ref' if valid port_id value, before accessing the '.device' field?

Quoted 12 lines
lib/librte_ethdev/rte_ethdev.c +2 -0
+}
+
 static void
 rte_eth_dev_shared_data_prepare(void)
 {
lib/librte_ethdev/rte_ethdev.h +0 -0
index a3c864a134..a7c5c36277 100644
@@ -1383,6 +1383,52 @@ uint16_t rte_eth_find_next(uint16_t port_id);
 #define RTE_ETH_FOREACH_DEV(p) \
 	RTE_ETH_FOREACH_DEV_OWNED_BY(p, RTE_ETH_DEV_NO_OWNER)

lib/librte_ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id); · line 1394

Quoted 10 lines
lib/librte_ethdev/rte_ethdev.h +9 -0
 
+/**
+ * Iterates over ethdev ports of a specified device.
+ *
+ * @param port_id_start
+ *   The id of the next possible valid port.
+ * @param parent
+ *   The generic device behind the ports to iterate.
+ * @return
+ *   Next port id of the device, RTE_MAX_ETHPORTS if there is none.

Can return 'port_id_start', right? Should it be documented as it is done in below 'next_sibling' one?

lib/librte_ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id); · line 1402

Quoted 8 lines
lib/librte_ethdev/rte_ethdev.h +8 -0
+ */
+__rte_experimental
+uint16_t rte_eth_find_next_of(uint16_t port_id_start,
+		const struct rte_device *parent);
+
+/**
+ * Macro to iterate over all ethdev ports sharing the same rte_device
+ * as the specified port.

'specified port'? No port specified, a device pointer is specified.

lib/librte_ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id); · line 1404

Quoted 2 lines
lib/librte_ethdev/rte_ethdev.h +2 -0
+ * Note: the specified port is part of the loop iterations.
+ */

Does it make sense to clarify what 'p' is and what 'parent' is as we do in function doxygen comments? Since these are macros, harder to grasp the types, I think better to describe more in macro documentation.

Quoted 44 lines
lib/librte_ethdev/rte_ethdev.h +27 -0
+#define RTE_ETH_FOREACH_DEV_OF(p, parent) \
+	for (p = rte_eth_find_next_of(0, parent); \
+		p < RTE_MAX_ETHPORTS; \
+		p = rte_eth_find_next_of(p + 1, parent))
+
+/**
+ * Iterates over sibling ethdev ports (i.e. sharing the same rte_device).
+ *
+ * @param port_id_start
+ *   The id of the next possible valid sibling port.
+ * @param ref
+ *   The id of a reference port to compare rte_device with.
+ * @return
+ *   Next sibling port id (or ref itself), RTE_MAX_ETHPORTS if there is none.
+ */
+__rte_experimental
+uint16_t rte_eth_find_next_sibling(uint16_t port_id_start, uint16_t ref);
+
+/**
+ * Macro to iterate over all ethdev ports sharing the same rte_device
+ * as the specified port.
+ * Note: the specified port is part of the loop iterations.
+ */
+#define RTE_ETH_FOREACH_DEV_SIBLING(p, ref) \
+	for (p = rte_eth_find_next_sibling(0, ref); \
+		p < RTE_MAX_ETHPORTS; \
+		p = rte_eth_find_next_sibling(p + 1, ref))
 
 /**
  * @warning
lib/librte_ethdev/rte_ethdev_version.map +2 -0
index 92ac3de250..b37a4167d7 100644
@@ -245,6 +245,8 @@ EXPERIMENTAL {
 	rte_eth_dev_owner_set;
 	rte_eth_dev_owner_unset;
 	rte_eth_dev_rx_intr_ctl_q_get_fd;
+	rte_eth_find_next_of;
+	rte_eth_find_next_sibling;
 	rte_eth_switch_domain_alloc;
 	rte_eth_switch_domain_free;
 	rte_flow_conv;
#12 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

19/03/2019 16:47, Ferruh Yigit:

Quoted 25 lines · Thomas Monjalon
Quoted 24 lines

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new functions and loop macros.
One iterator takes a port id as reference,
while the other one directly refers to the parent device.

The ownership is not checked because siblings may have different owners.

---
 lib/librte_ethdev/rte_ethdev.c           | 20 +++++++++++
 lib/librte_ethdev/rte_ethdev.h           | 46 ++++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  2 ++
 3 files changed, 68 insertions(+)
lib/librte_ethdev/rte_ethdev.c +0 -0
index b3b2fb1dba..42154787f8 100644
@@ -340,6 +340,26 @@ rte_eth_find_next(uint16_t port_id)
 	return port_id;
 }
 
Quoted 4 lines

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 343

Quoted 1 line
lib/librte_ethdev/rte_ethdev.c +1 -0
+uint16_t __rte_experimental

Do we need _rte_experimental on function definitions? I guess only in .h file, function declaration is enough.

Yes we need them both in .h and .c files.

Quoted 3 lines

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 344

Quoted 1 line
lib/librte_ethdev/rte_ethdev.c +1 -0
+rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)

Out of curiosity, what '_of' refers to?

It means "next port of parent".
Is there a better word than "of"?

Quoted 9 lines

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 349

Quoted 5 lines
lib/librte_ethdev/rte_ethdev.c +5 -0
+{
+	while (port_id < RTE_MAX_ETHPORTS &&
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED &&
+			rte_eth_devices[port_id].device != parent)
+		port_id++;

Is this logic correct, or am I missing something.
When port status is ATTACHED, check will return false and exit from loop without checking if the 'device' is same.

Oops, I think you are right.

Quoted 2 lines

+1 to Gaetan's suggestion to use 'rte_eth_find_next()', which moves status concern to that function.

OK, will change.

Quoted 11 lines

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 358

Quoted 9 lines
lib/librte_ethdev/rte_ethdev.c +9 -0
+
+	if (port_id >= RTE_MAX_ETHPORTS)
+		return RTE_MAX_ETHPORTS;
+
+	return port_id;
+}
+
+uint16_t __rte_experimental
+rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref)

I think better to say 'ref_port_id' to clarify what we expect here is a port_id

OK

Quoted 5 lines

lib/librte_ethdev/rte_ethdev.c rte_eth_find_next(uint16_t port_id) · line 360

Quoted 2 lines
lib/librte_ethdev/rte_ethdev.c +2 -0
+{
+	return rte_eth_find_next_of(port_id, rte_eth_devices[ref].device);

This is a public API, shouldn't we check if 'ref' if valid port_id value, before accessing the '.device' field?

I'm not a fan of extra checks, but yes we may add one.

Quoted 6 lines
Quoted 6 lines
lib/librte_ethdev/rte_ethdev.h +4 -0
+/**
+ * Iterates over ethdev ports of a specified device.
+ *
+ * @param port_id_start
Quoted 8 lines
Quoted 5 lines

+ * The id of the next possible valid port.
+ * @param parent
+ * The generic device behind the ports to iterate.
+ * @return
+ * Next port id of the device, RTE_MAX_ETHPORTS if there is none.

Can return 'port_id_start', right? Should it be documented as it is done in below 'next_sibling' one?

Yes, OK.

Quoted 10 lines

lib/librte_ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id); · line 1402

Quoted 8 lines

+ */

lib/librte_ethdev/rte_ethdev.h +7 -0
+__rte_experimental
+uint16_t rte_eth_find_next_of(uint16_t port_id_start,
+		const struct rte_device *parent);
+
+/**
+ * Macro to iterate over all ethdev ports sharing the same rte_device
+ * as the specified port.

'specified port'? No port specified, a device pointer is specified.

Right, looks like a wrong a copy/paste.

Quoted 6 lines
Quoted 2 lines

+ * Note: the specified port is part of the loop iterations.
+ */

Does it make sense to clarify what 'p' is and what 'parent' is as we do in function doxygen comments? Since these are macros, harder to grasp the types, I think better to describe more in macro documentation.

Absolutely, yes. I thought I did it.

Quoted 19 lines
Quoted 19 lines
lib/librte_ethdev/rte_ethdev.h +19 -0
+#define RTE_ETH_FOREACH_DEV_OF(p, parent) \
+	for (p = rte_eth_find_next_of(0, parent); \
+		p < RTE_MAX_ETHPORTS; \
+		p = rte_eth_find_next_of(p + 1, parent))
+
+/**
+ * Iterates over sibling ethdev ports (i.e. sharing the same rte_device).
+ *
+ * @param port_id_start
+ *   The id of the next possible valid sibling port.
+ * @param ref
+ *   The id of a reference port to compare rte_device with.
+ * @return
+ *   Next sibling port id (or ref itself), RTE_MAX_ETHPORTS if there is none.
+ */
+__rte_experimental
+uint16_t rte_eth_find_next_sibling(uint16_t port_id_start, uint16_t ref);
+
+/**
Quoted 8 lines

lib/librte_ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id); · line 1431

Quoted 8 lines

+ * Macro to iterate over all ethdev ports sharing the same rte_device
+ * as the specified port.
+ * Note: the specified port is part of the loop iterations.
+ */

lib/librte_ethdev/rte_ethdev.h +4 -0
+#define RTE_ETH_FOREACH_DEV_SIBLING(p, ref) \
+	for (p = rte_eth_find_next_sibling(0, ref); \
+		p < RTE_MAX_ETHPORTS; \
+		p = rte_eth_find_next_sibling(p + 1, ref))

Thanks for the complete review Ferruh.

#13 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

Quoted 5 lines · Thomas Monjalon
Quoted 3 lines
Quoted 1 line

+uint16_t __rte_experimental

Do we need _rte_experimental on function definitions? I guess only in .h file, function declaration is enough.

Yes we need them both in .h and .c files.

Why we need them in .c file?
I think the compiler is interested in ones in .h file, because of the experimental checks.

#14 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

19/03/2019 19:04, Ferruh Yigit:

Quoted 11 lines · Thomas Monjalon
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+uint16_t __rte_experimental

Do we need _rte_experimental on function definitions? I guess only in .h file, function declaration is enough.

Yes we need them both in .h and .c files.

Why we need them in .c file?
I think the compiler is interested in ones in .h file, because of the experimental checks.

We need the tag in .c file because a check is done in the ELF object by buildtools/check-experimental-syms.sh

David tried a replacement of this script to run on header files, but it looks a bit slow:

	https://patches.dpdk.org/patch/49118/
#15 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

Quoted 8 lines · Thomas Monjalon

19/03/2019 19:04, Ferruh Yigit:

Quoted 4 lines · Thomas Monjalon
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

+uint16_t __rte_experimental

Do we need _rte_experimental on function definitions? I guess only in

.h file,

Quoted 2 lines
Quoted 2 lines
Quoted 1 line

function declaration is enough.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Yes we need them both in .h and .c files.

Why we need them in .c file?
I think the compiler is interested in ones in .h file, because of the experimental checks.

We need the tag in .c file because a check is done in the ELF object by buildtools/check-experimental-syms.sh

?
The attribute should be inherited from the declaration in the header. If you have a case where it does not work, I'd like to look at it.

Quoted 3 lines

David tried a replacement of this script to run on header files, but it looks a bit slow:

        https://patches.dpdk.org/patch/49118/

Never got any review/comment, will do a quick update in this thread.

Signature · 1 line
David Marchand
#16 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

01/04/2019 08:46, David Marchand:

Quoted 16 lines · Thomas Monjalon
Quoted 15 lines

19/03/2019 19:04, Ferruh Yigit:

Quoted 4 lines · Thomas Monjalon
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

+uint16_t __rte_experimental

Do we need _rte_experimental on function definitions? I guess only in

.h file,

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

function declaration is enough.

Yes we need them both in .h and .c files.

Why we need them in .c file?
I think the compiler is interested in ones in .h file, because of the experimental checks.

Quoted 7 lines
Quoted 3 lines

We need the tag in .c file because a check is done in the ELF object by buildtools/check-experimental-syms.sh

?
The attribute should be inherited from the declaration in the header. If you have a case where it does not work, I'd like to look at it.

I don't know such case, it was just a belief.

If we can confirm it works well with tag in headers only, I suggest we remove all of them at once.
For this patch, I prefer being on the safe side for now.

#17 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

Quoted 21 lines · Thomas Monjalon

01/04/2019 08:46, David Marchand:

Quoted 20 lines · Thomas Monjalon
Quoted 18 lines

19/03/2019 19:04, Ferruh Yigit:

Quoted 4 lines · Thomas Monjalon
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

+uint16_t __rte_experimental

Do we need _rte_experimental on function definitions? I guess only in

.h file,

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

function declaration is enough.

Yes we need them both in .h and .c files.

Why we need them in .c file?
I think the compiler is interested in ones in .h file, because of the experimental checks.

We need the tag in .c file because a check is done in the ELF object by buildtools/check-experimental-syms.sh

Quoted 5 lines
Quoted 3 lines

?
The attribute should be inherited from the declaration in the header. If you have a case where it does not work, I'd like to look at it.

I don't know such case, it was just a belief.

Putting the __rte_experimental tag into header files should be sufficient.

- buildtools/check-experimental-syms.sh
checks if symbols in .map file are marked with __rte_experimental, both putting the tag to the symbol in .c file or .h file is working.

- tag should be in header file so that application using it can get the warning.

Briefly, __rte_experimental needs to be in .h file, it is optional to have it in .c, I am for keeping it only in .h file function declaration.

Quoted 6 lines

If we can confirm it works well with tag in headers only, I suggest we remove all of them at once.
For this patch, I prefer being on the safe side for now.

#18 lore raw

Re: [PATCH v2 2/4] ethdev: add siblings iterators

03/04/2019 01:35, Ferruh Yigit:

Quoted 30 lines · Thomas Monjalon
Quoted 21 lines

01/04/2019 08:46, David Marchand:

Quoted 20 lines · Thomas Monjalon
Quoted 18 lines

19/03/2019 19:04, Ferruh Yigit:

Quoted 4 lines · Thomas Monjalon
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

+uint16_t __rte_experimental

Do we need _rte_experimental on function definitions? I guess only in

.h file,

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

function declaration is enough.

Yes we need them both in .h and .c files.

Why we need them in .c file?
I think the compiler is interested in ones in .h file, because of the experimental checks.

We need the tag in .c file because a check is done in the ELF object by buildtools/check-experimental-syms.sh

Quoted 5 lines
Quoted 3 lines

?
The attribute should be inherited from the declaration in the header. If you have a case where it does not work, I'd like to look at it.

I don't know such case, it was just a belief.

Putting the __rte_experimental tag into header files should be sufficient.

Quoted 8 lines

- buildtools/check-experimental-syms.sh
checks if symbols in .map file are marked with __rte_experimental, both putting the tag to the symbol in .c file or .h file is working.

- tag should be in header file so that application using it can get the warning.

Briefly, __rte_experimental needs to be in .h file, it is optional to have it in .c, I am for keeping it only in .h file function declaration.

I agree
As I said below, we can remove all experimental tags from .c files in a separate patch.

Quoted 3 lines
Quoted 3 lines

If we can confirm it works well with tag in headers only, I suggest we remove all of them at once.
For this patch, I prefer being on the safe side for now.

#19 lore raw

PATCH v2 3/4 net/mlx5: use port sibling iterators

In reply to Thomas Monjalon

Iterating over siblings was done with RTE_ETH_FOREACH_DEV() which skips the owned ports.
The new iterators RTE_ETH_FOREACH_DEV_SIBLING()
and RTE_ETH_FOREACH_DEV_OF() are more appropriate and more correct.

---
 drivers/net/mlx5/mlx5.c        | 34 +++++++++++++---------------------
 drivers/net/mlx5/mlx5_ethdev.c |  6 +-----
 2 files changed, 14 insertions(+), 26 deletions(-)
drivers/net/mlx5/mlx5.c +13 -21
index a913a5955f..6ed1ea0d5b 100644
@@ -330,17 +330,15 @@ mlx5_dev_close(struct rte_eth_dev *dev)
 			dev->data->port_id);
 	if (priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
 		unsigned int c = 0;
-		unsigned int i = mlx5_dev_to_port_id(dev->device, NULL, 0);
-		uint16_t port_id[i];
+		uint16_t port_id;
 
-		i = RTE_MIN(mlx5_dev_to_port_id(dev->device, port_id, i), i);
-		while (i--) {
+		RTE_ETH_FOREACH_DEV_OF(port_id, dev->device) {
 			struct priv *opriv =
-				rte_eth_devices[port_id[i]].data->dev_private;
+				rte_eth_devices[port_id].data->dev_private;
 
 			if (!opriv ||
 			    opriv->domain_id != priv->domain_id ||
-			    &rte_eth_devices[port_id[i]] == dev)
+			    &rte_eth_devices[port_id] == dev)
 				continue;
 			++c;
 		}
@@ -1001,22 +999,16 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 	 * Look for sibling devices in order to reuse their switch domain
 	 * if any, otherwise allocate one.
 	 */
-	i = mlx5_dev_to_port_id(dpdk_dev, NULL, 0);
-	if (i > 0) {
-		uint16_t port_id[i];
+	RTE_ETH_FOREACH_DEV_OF(port_id, dpdk_dev) {
+		const struct priv *opriv =
+			rte_eth_devices[port_id].data->dev_private;
 
-		i = RTE_MIN(mlx5_dev_to_port_id(dpdk_dev, port_id, i), i);
-		while (i--) {
-			const struct priv *opriv =
-				rte_eth_devices[port_id[i]].data->dev_private;
-
-			if (!opriv ||
-			    opriv->domain_id ==
-			    RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)
-				continue;
-			priv->domain_id = opriv->domain_id;
-			break;
-		}
+		if (!opriv ||
+			opriv->domain_id ==
+			RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)
+			continue;
+		priv->domain_id = opriv->domain_id;
+		break;
 	}
 	if (priv->domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
 		err = rte_eth_switch_domain_alloc(&priv->domain_id);
drivers/net/mlx5/mlx5_ethdev.c +1 -5
index d178ed6a18..039582a321 100644
@@ -1300,11 +1300,7 @@ mlx5_dev_to_port_id(const struct rte_device *dev, uint16_t *port_list,
 	uint16_t id;
 	unsigned int n = 0;
 
-	RTE_ETH_FOREACH_DEV(id) {
-		struct rte_eth_dev *ldev = &rte_eth_devices[id];
-
-		if (ldev->device != dev)
-			continue;
+	RTE_ETH_FOREACH_DEV_OF(id, dev) {
 		if (n < port_list_n)
 			port_list[n] = id;
 		n++;
Signature · 1 line
2.20.1
#20 lore raw

PATCH v2 4/4 app/testpmd: use port sibling iterator in device cleanup

In reply to Thomas Monjalon

When removing a rte_device on a port-based request,
all the sibling ports must be marked as closed.
The iterator loop can be simplified by using the dedicated macro.

---
 app/test-pmd/testpmd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
app/test-pmd/testpmd.c +1 -3
index 98c1baa8b1..fcc479aa39 100644
@@ -2361,9 +2361,7 @@ detach_port_device(portid_t port_id)
 		return;
 	}
 
-	for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++) {
-		if (rte_eth_devices[sibling].device != dev)
-			continue;
+	RTE_ETH_FOREACH_DEV_SIBLING(sibling, port_id) {
 		/* reset mapping between old ports and removed device */
 		rte_eth_devices[sibling].device = NULL;
 		if (ports[sibling].port_status != RTE_PORT_CLOSED) {
Signature · 1 line
2.20.1
#21 lore raw

v3 cover ethdev iterators for multi-ports device

In reply to Thomas Monjalon

Add port iterators in order to allow listing easily the ports of the same device.

The iterators can be tested by using mlx5 or testpmd.

v3: changes only in the (main) patch 2

Thomas Monjalon (4):
ethdev: simplify port state comparisons
ethdev: add siblings iterators
net/mlx5: use port sibling iterators app/testpmd: use port sibling iterator in device cleanup

 app/test-pmd/testpmd.c                   |  4 +-
 drivers/net/mlx5/mlx5.c                  | 34 +++++--------
 drivers/net/mlx5/mlx5_ethdev.c           |  6 +--
 lib/librte_ethdev/rte_ethdev.c           | 25 ++++++++--
 lib/librte_ethdev/rte_ethdev.h           | 63 ++++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  2 +
 6 files changed, 101 insertions(+), 33 deletions(-)
Signature · 1 line
2.21.0
#22 lore raw

PATCH v3 1/4 ethdev: simplify port state comparisons

There are three states for an ethdev port. Checking that the port is unused looks simpler than checking it is neither attached nor removed.

---
 lib/librte_ethdev/rte_ethdev.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/librte_ethdev/rte_ethdev.c +2 -4
index 10bdfb37e..33cffc498 100644
@@ -330,8 +330,7 @@ uint16_t
 rte_eth_find_next(uint16_t port_id)
 {
 	while (port_id < RTE_MAX_ETHPORTS &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED)
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)
 		port_id++;
 
 	if (port_id >= RTE_MAX_ETHPORTS)
@@ -567,8 +566,7 @@ uint64_t
 rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
 {
 	while (port_id < RTE_MAX_ETHPORTS &&
-	       ((rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED) ||
+	       (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED ||
 	       rte_eth_devices[port_id].data->owner.id != owner_id))
 		port_id++;
 
Signature · 1 line
2.21.0
#23 lore raw

Re: [PATCH v3 1/4] ethdev: simplify port state comparisons

lib/librte_ethdev/rte_ethdev.c uint16_t · line 333

Quoted 11 lines · On Mon, 1 Apr 2019 04:26:57 +0200 Thomas Monjalon <[email protected]> wrote:
lib/librte_ethdev/rte_ethdev.c +1 -2
index 10bdfb37e..33cffc498 100644
@@ -330,8 +330,7 @@ uint16_t
 rte_eth_find_next(uint16_t port_id)
 {
 	while (port_id < RTE_MAX_ETHPORTS &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED)
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)

For some applications that iterate over ports this is a hot path. What about keeping an unused port bit mask and using ffs (in the future)?

#24 lore raw

Re: [PATCH v3 1/4] ethdev: simplify port state comparisons

01/04/2019 16:58, Stephen Hemminger:

Quoted 16 lines

lib/librte_ethdev/rte_ethdev.c uint16_t · line 333

Quoted 11 lines · On Mon, 1 Apr 2019 04:26:57 +0200 Thomas Monjalon <[email protected]> wrote:
lib/librte_ethdev/rte_ethdev.c +1 -2
index 10bdfb37e..33cffc498 100644
@@ -330,8 +330,7 @@ uint16_t
 rte_eth_find_next(uint16_t port_id)
 {
 	while (port_id < RTE_MAX_ETHPORTS &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED)
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)

For some applications that iterate over ports this is a hot path.

Really?

Quoted 1 line

What about keeping an unused port bit mask and using ffs (in the future)?

I don't understand your proposal. Please could you elaborate?

Do you agree on this patch anyway?

#25 lore raw

Re: [PATCH v3 1/4] ethdev: simplify port state comparisons

Quoted 18 lines · On Mon, 01 Apr 2019 17:17:35 +0200 Thomas Monjalon <[email protected]> wrote:

01/04/2019 16:58, Stephen Hemminger:

Quoted 16 lines

lib/librte_ethdev/rte_ethdev.c uint16_t · line 333

Quoted 11 lines · On Mon, 1 Apr 2019 04:26:57 +0200 Thomas Monjalon <[email protected]> wrote:
lib/librte_ethdev/rte_ethdev.c +1 -2
index 10bdfb37e..33cffc498 100644
@@ -330,8 +330,7 @@ uint16_t
 rte_eth_find_next(uint16_t port_id)
 {
 	while (port_id < RTE_MAX_ETHPORTS &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED)
+			rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)  

For some applications that iterate over ports this is a hot path.

Quoted 7 lines

Really?

Quoted 1 line

What about keeping an unused port bit mask and using ffs (in the future)?

I don't understand your proposal. Please could you elaborate?

Do you agree on this patch anyway?

I have seen some applications spend lots of time doing:

	RTE_ETH_FOREACH_DEV(portid) {

If ethdev kept a bitmask for unused ports then it could use the find first set instruction.

Maybe the better way is to just fix the application to use its own bitmask of ports instead.

Tested-by Viacheslav Ovsiienko on v3 1/4
#26 lore raw

Re: [PATCH v3 1/4] ethdev: simplify port state comparisons

In reply to Thomas Monjalon
Quoted 8 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Thomas Monjalon
Sent: Monday, April 1, 2019 5:27
To: [email protected]; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>
Cc: [email protected]
Subject: [dpdk-dev] [PATCH v3 1/4] ethdev: simplify port state comparisons

Quoted 6 lines

There are three states for an ethdev port.
Checking that the port is unused looks simpler than checking it is neither attached nor removed.

Tested-by Viacheslav Ovsiienko <mellanox.com>
Quoted 30 lines
---
 lib/librte_ethdev/rte_ethdev.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
lib/librte_ethdev/rte_ethdev.c +1 -2
index 10bdfb37e..33cffc498 100644
@@ -330,8 +330,7 @@ uint16_t
 rte_eth_find_next(uint16_t port_id)
 {
 	while (port_id < RTE_MAX_ETHPORTS &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED)
+			rte_eth_devices[port_id].state ==
 RTE_ETH_DEV_UNUSED)
 		port_id++;
 
lib/librte_ethdev/rte_ethdev.c +1 -3
 	if (port_id >= RTE_MAX_ETHPORTS)
@@ -567,8 +566,7 @@ uint64_t
 rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)  {
 	while (port_id < RTE_MAX_ETHPORTS &&
-	       ((rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
-	       rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED) ||
+	       (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED ||
 	       rte_eth_devices[port_id].data->owner.id != owner_id))
 		port_id++;
 
--

2.21.0

#27 lore raw

PATCH v3 2/4 ethdev: add siblings iterators

In reply to Thomas Monjalon

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new functions and loop macros.
One iterator takes a port id as reference,
while the other one directly refers to the parent device.

The ownership is not checked because siblings may have different owners.

---
v2: Reviewed-by: Andrew Rybchenko - not kept because of changes in v3

v3:
- fix logic + re-use rte_eth_find_next()
- longer parameter names
- more and better doxygen comments

---
 lib/librte_ethdev/rte_ethdev.c           | 19 +++++++
 lib/librte_ethdev/rte_ethdev.h           | 63 ++++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  2 +
 3 files changed, 84 insertions(+)
lib/librte_ethdev/rte_ethdev.c +19 -0
index 33cffc498..3b125a642 100644
@@ -339,6 +339,25 @@ rte_eth_find_next(uint16_t port_id)
 	return port_id;
 }
 
+uint16_t __rte_experimental
+rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
+{
+	port_id = rte_eth_find_next(port_id);
+	while (port_id < RTE_MAX_ETHPORTS &&
+			rte_eth_devices[port_id].device != parent)
+		port_id = rte_eth_find_next(port_id + 1);
+
+	return port_id;
+}
+
+uint16_t __rte_experimental
+rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id)
+{
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id, RTE_MAX_ETHPORTS);
+	return rte_eth_find_next_of(port_id,
+			rte_eth_devices[ref_port_id].device);
+}
+
 static void
 rte_eth_dev_shared_data_prepare(void)
 {
lib/librte_ethdev/rte_ethdev.h +63 -0

69 lines not on this page · raw message

lib/librte_ethdev/rte_ethdev_version.map +2 -0
index 92ac3de25..b37a4167d 100644
@@ -245,6 +245,8 @@ EXPERIMENTAL {
 	rte_eth_dev_owner_set;
 	rte_eth_dev_owner_unset;
 	rte_eth_dev_rx_intr_ctl_q_get_fd;
+	rte_eth_find_next_of;
+	rte_eth_find_next_sibling;
 	rte_eth_switch_domain_alloc;
 	rte_eth_switch_domain_free;
 	rte_flow_conv;
Signature · 1 line
2.21.0
Reviewed-by on v3 2/4
#28 lore raw

Re: [PATCH v3 2/4] ethdev: add siblings iterators

Quoted 10 lines · Thomas Monjalon

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new functions and loop macros.
One iterator takes a port id as reference,
while the other one directly refers to the parent device.

The ownership is not checked because siblings may have different owners.

#29 lore raw

Re: [PATCH v3 2/4] ethdev: add siblings iterators

In reply to Thomas Monjalon
Quoted 10 lines · Thomas Monjalon

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new functions and loop macros.
One iterator takes a port id as reference,
while the other one directly refers to the parent device.

The ownership is not checked because siblings may have different owners.

<...>

Quoted 7 lines
lib/librte_ethdev/rte_ethdev.h +7 -0
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Iterates over ethdev ports of a specified device.
+ *
+ * @param port_id_start

lib/librte_ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id); · line 1406

Quoted 10 lines
lib/librte_ethdev/rte_ethdev.h +10 -0
+ *   The id of the next possible valid port.
+ * @param parent
+ *   The generic device behind the ports to iterate.
+ * @return
+ *   Next port id of the device, possibly port_id_start,
+ *   RTE_MAX_ETHPORTS if there is none.
+ */
+__rte_experimental
+uint16_t rte_eth_find_next_of(uint16_t port_id_start,
+		const struct rte_device *parent);

Minor nit, but other instances using the tag as:

uint16_t __rte_experimental
rte_eth_find_next_of(uint16_t port_id_start,

		const struct rte_device *parent);

What do you think updating it for consistency? Same for two APIs.

#30 lore raw

Re: [PATCH v3 2/4] ethdev: add siblings iterators

03/04/2019 01:42, Ferruh Yigit:

Quoted 7 lines · Thomas Monjalon

lib/librte_ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id); · line 1406

Quoted 3 lines
lib/librte_ethdev/rte_ethdev.h +3 -0
+__rte_experimental
+uint16_t rte_eth_find_next_of(uint16_t port_id_start,
+		const struct rte_device *parent);

Minor nit, but other instances using the tag as:

Quoted 5 lines

uint16_t __rte_experimental
rte_eth_find_next_of(uint16_t port_id_start,

		const struct rte_device *parent);

What do you think updating it for consistency? Same for two APIs.

I think I did it this way to minimize the patch removing it later. I'm OK to change it for consistency.

Tested-by Viacheslav Ovsiienko on v3 2/4
#31 lore raw

Re: [PATCH v3 2/4] ethdev: add siblings iterators

In reply to Thomas Monjalon
Quoted 8 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Thomas Monjalon
Sent: Monday, April 1, 2019 5:27
To: [email protected]; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>
Cc: [email protected]
Subject: [dpdk-dev] [PATCH v3 2/4] ethdev: add siblings iterators

Quoted 8 lines

If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new functions and loop macros. One iterator takes a port id as reference, while the other one directly refers to the parent device.

The ownership is not checked because siblings may have different owners.

Tested-by Viacheslav Ovsiienko <mellanox.com>
Quoted 134 lines

---
v2: Reviewed-by: Andrew Rybchenko - not kept because of changes in v3

v3:
- fix logic + re-use rte_eth_find_next()
- longer parameter names
- more and better doxygen comments

---
 lib/librte_ethdev/rte_ethdev.c           | 19 +++++++
 lib/librte_ethdev/rte_ethdev.h           | 63 ++++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  2 +
 3 files changed, 84 insertions(+)
lib/librte_ethdev/rte_ethdev.c +18 -0
index 33cffc498..3b125a642 100644
@@ -339,6 +339,25 @@ rte_eth_find_next(uint16_t port_id)
 	return port_id;
 }
 
+uint16_t __rte_experimental
+rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
+{
+	port_id = rte_eth_find_next(port_id);
+	while (port_id < RTE_MAX_ETHPORTS &&
+			rte_eth_devices[port_id].device != parent)
+		port_id = rte_eth_find_next(port_id + 1);
+
+	return port_id;
+}
+
+uint16_t __rte_experimental
+rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id) {
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id,
 RTE_MAX_ETHPORTS);
+	return rte_eth_find_next_of(port_id,
+			rte_eth_devices[ref_port_id].device);
+}
+
 static void
 rte_eth_dev_shared_data_prepare(void)
 {
lib/librte_ethdev/rte_ethdev.h +63 -0
index b6023c050..3d5bacaee 100644
@@ -1387,6 +1387,69 @@ uint16_t rte_eth_find_next(uint16_t port_id);
 #define RTE_ETH_FOREACH_DEV(p) \
 	RTE_ETH_FOREACH_DEV_OWNED_BY(p,
 RTE_ETH_DEV_NO_OWNER)
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Iterates over ethdev ports of a specified device.
+ *
+ * @param port_id_start
+ *   The id of the next possible valid port.
+ * @param parent
+ *   The generic device behind the ports to iterate.
+ * @return
+ *   Next port id of the device, possibly port_id_start,
+ *   RTE_MAX_ETHPORTS if there is none.
+ */
+__rte_experimental
+uint16_t rte_eth_find_next_of(uint16_t port_id_start,
+		const struct rte_device *parent);
+
+/**
+ * Macro to iterate over all ethdev ports of a specified device.
+ *
+ * @param port_id
+ *   The id of the matching port being iterated.
+ * @param parent
+ *   The rte_device pointer matching the iterated ports.
+ */
+#define RTE_ETH_FOREACH_DEV_OF(port_id, parent) \
+	for (port_id = rte_eth_find_next_of(0, parent); \
+		port_id < RTE_MAX_ETHPORTS; \
+		port_id = rte_eth_find_next_of(port_id + 1, parent))
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Iterates over sibling ethdev ports (i.e. sharing the same rte_device).
+ *
+ * @param port_id_start
+ *   The id of the next possible valid sibling port.
+ * @param ref_port_id
+ *   The id of a reference port to compare rte_device with.
+ * @return
+ *   Next sibling port id, possibly port_id_start or ref_port_id itself,
+ *   RTE_MAX_ETHPORTS if there is none.
+ */
+__rte_experimental
+uint16_t rte_eth_find_next_sibling(uint16_t port_id_start,
+		uint16_t ref_port_id);
+
+/**
+ * Macro to iterate over all ethdev ports sharing the same rte_device
+ * as the specified port.
+ * Note: the specified reference port is part of the loop iterations.
+ *
+ * @param port_id
+ *   The id of the matching port being iterated.
+ * @param ref_port_id
+ *   The id of the port being compared.
+ */
+#define RTE_ETH_FOREACH_DEV_SIBLING(port_id, ref_port_id) \
+	for (port_id = rte_eth_find_next_sibling(0, ref_port_id); \
+		port_id < RTE_MAX_ETHPORTS; \
+		port_id = rte_eth_find_next_sibling(port_id + 1, ref_port_id))
 
 /**

* @warning

lib/librte_ethdev/rte_ethdev_version.map +2 -1
index 92ac3de25..b37a4167d 100644
@@ -245,6 +245,8 @@ EXPERIMENTAL {
 	rte_eth_dev_owner_set;
 	rte_eth_dev_owner_unset;
 	rte_eth_dev_rx_intr_ctl_q_get_fd;
+	rte_eth_find_next_of;
+	rte_eth_find_next_sibling;
 	rte_eth_switch_domain_alloc;
 	rte_eth_switch_domain_free;
 	rte_flow_conv;
--

2.21.0

#32 lore raw

PATCH v3 3/4 net/mlx5: use port sibling iterators

In reply to Thomas Monjalon

Iterating over siblings was done with RTE_ETH_FOREACH_DEV() which skips the owned ports.
The new iterators RTE_ETH_FOREACH_DEV_SIBLING()
and RTE_ETH_FOREACH_DEV_OF() are more appropriate and more correct.

---
 drivers/net/mlx5/mlx5.c        | 34 +++++++++++++---------------------
 drivers/net/mlx5/mlx5_ethdev.c |  6 +-----
 2 files changed, 14 insertions(+), 26 deletions(-)
drivers/net/mlx5/mlx5.c +13 -21
index 1d7ca615b..3287a3d78 100644
@@ -493,17 +493,15 @@ mlx5_dev_close(struct rte_eth_dev *dev)
 			dev->data->port_id);
 	if (priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
 		unsigned int c = 0;
-		unsigned int i = mlx5_dev_to_port_id(dev->device, NULL, 0);
-		uint16_t port_id[i];
+		uint16_t port_id;
 
-		i = RTE_MIN(mlx5_dev_to_port_id(dev->device, port_id, i), i);
-		while (i--) {
+		RTE_ETH_FOREACH_DEV_OF(port_id, dev->device) {
 			struct mlx5_priv *opriv =
-				rte_eth_devices[port_id[i]].data->dev_private;
+				rte_eth_devices[port_id].data->dev_private;
 
 			if (!opriv ||
 			    opriv->domain_id != priv->domain_id ||
-			    &rte_eth_devices[port_id[i]] == dev)
+			    &rte_eth_devices[port_id] == dev)
 				continue;
 			++c;
 		}
@@ -1147,22 +1145,16 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 	 * Look for sibling devices in order to reuse their switch domain
 	 * if any, otherwise allocate one.
 	 */
-	i = mlx5_dev_to_port_id(dpdk_dev, NULL, 0);
-	if (i > 0) {
-		uint16_t port_id[i];
+	RTE_ETH_FOREACH_DEV_OF(port_id, dpdk_dev) {
+		const struct mlx5_priv *opriv =
+			rte_eth_devices[port_id].data->dev_private;
 
-		i = RTE_MIN(mlx5_dev_to_port_id(dpdk_dev, port_id, i), i);
-		while (i--) {
-			const struct mlx5_priv *opriv =
-				rte_eth_devices[port_id[i]].data->dev_private;
-
-			if (!opriv ||
-			    opriv->domain_id ==
-			    RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)
-				continue;
-			priv->domain_id = opriv->domain_id;
-			break;
-		}
+		if (!opriv ||
+			opriv->domain_id ==
+			RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)
+			continue;
+		priv->domain_id = opriv->domain_id;
+		break;
 	}
 	if (priv->domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
 		err = rte_eth_switch_domain_alloc(&priv->domain_id);
drivers/net/mlx5/mlx5_ethdev.c +1 -5
index 7273bd940..e01b698fc 100644
@@ -1398,11 +1398,7 @@ mlx5_dev_to_port_id(const struct rte_device *dev, uint16_t *port_list,
 	uint16_t id;
 	unsigned int n = 0;
 
-	RTE_ETH_FOREACH_DEV(id) {
-		struct rte_eth_dev *ldev = &rte_eth_devices[id];
-
-		if (ldev->device != dev)
-			continue;
+	RTE_ETH_FOREACH_DEV_OF(id, dev) {
 		if (n < port_list_n)
 			port_list[n] = id;
 		n++;
Signature · 1 line
2.21.0
#33 lore raw

Re: [PATCH v3 3/4] net/mlx5: use port sibling iterators

Quoted 6 lines · Thomas Monjalon

Iterating over siblings was done with RTE_ETH_FOREACH_DEV() which skips the owned ports.
The new iterators RTE_ETH_FOREACH_DEV_SIBLING()
and RTE_ETH_FOREACH_DEV_OF() are more appropriate and more correct.

Hi Shahaf, Yongseok,

Any comment on this patch?

#34 lore raw

Re: [PATCH v3 3/4] net/mlx5: use port sibling iterators

Quoted 9 lines · Ferruh Yigit
Quoted 5 lines · Thomas Monjalon

Iterating over siblings was done with RTE_ETH_FOREACH_DEV() which skips the owned ports.
The new iterators RTE_ETH_FOREACH_DEV_SIBLING()
and RTE_ETH_FOREACH_DEV_OF() are more appropriate and more correct.

Quoted 5 lines
Quoted 1 line

Hi Shahaf, Yongseok,

Any comment on this patch?

Sorry for late reply.
I know it has been merged but it looks okay to me.

Thanks,
Yongseok

Acked-by Yongseok Koh
#35 lore raw

Re: [PATCH v3 3/4] net/mlx5: use port sibling iterators

Quoted 9 lines · Yongseok Koh
Quoted 9 lines · Ferruh Yigit
Quoted 5 lines · Thomas Monjalon

Iterating over siblings was done with RTE_ETH_FOREACH_DEV() which skips the owned ports.
The new iterators RTE_ETH_FOREACH_DEV_SIBLING()
and RTE_ETH_FOREACH_DEV_OF() are more appropriate and more correct.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Hi Shahaf, Yongseok,

Any comment on this patch?

Sorry for late reply.
I know it has been merged but it looks okay to me.

Thanks, I am appending explicit ack to the patch:

Tested-by Viacheslav Ovsiienko on v3 3/4
#36 lore raw

Re: [PATCH v3 3/4] net/mlx5: use port sibling iterators

In reply to Thomas Monjalon
Quoted 8 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Thomas Monjalon
Sent: Monday, April 1, 2019 5:27
To: [email protected]; Shahaf Shuler <[email protected]>; Yongseok Koh <[email protected]>
Cc: [email protected]
Subject: [dpdk-dev] [PATCH v3 3/4] net/mlx5: use port sibling iterators

Quoted 6 lines

Iterating over siblings was done with RTE_ETH_FOREACH_DEV() which skips the owned ports.
The new iterators RTE_ETH_FOREACH_DEV_SIBLING() and RTE_ETH_FOREACH_DEV_OF() are more appropriate and more correct.

Tested-by Viacheslav Ovsiienko <mellanox.com>
Quoted 87 lines
---
 drivers/net/mlx5/mlx5.c        | 34 +++++++++++++---------------------
 drivers/net/mlx5/mlx5_ethdev.c |  6 +-----
 2 files changed, 14 insertions(+), 26 deletions(-)
drivers/net/mlx5/mlx5.c index renamed from drivers/net/mlx5/mlx5.c +0 -0

1d7ca615b..3287a3d78 100644

drivers/net/mlx5/mlx5.c +4 -6
@@ -493,17 +493,15 @@ mlx5_dev_close(struct rte_eth_dev *dev)
 			dev->data->port_id);
 	if (priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)
 {
 		unsigned int c = 0;
-		unsigned int i = mlx5_dev_to_port_id(dev->device, NULL, 0);
-		uint16_t port_id[i];
+		uint16_t port_id;
 
-		i = RTE_MIN(mlx5_dev_to_port_id(dev->device, port_id, i), i);
-		while (i--) {
+		RTE_ETH_FOREACH_DEV_OF(port_id, dev->device) {
 			struct mlx5_priv *opriv =
-				rte_eth_devices[port_id[i]].data-
 >dev_private;
+				rte_eth_devices[port_id].data->dev_private;
 
 			if (!opriv ||
 			    opriv->domain_id != priv->domain_id ||
-			    &rte_eth_devices[port_id[i]] == dev)
+			    &rte_eth_devices[port_id] == dev)
 				continue;
drivers/net/mlx5/mlx5.c +9 -15
 			++c;
 		}
@@ -1147,22 +1145,16 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 	 * Look for sibling devices in order to reuse their switch domain
 	 * if any, otherwise allocate one.
 	 */
-	i = mlx5_dev_to_port_id(dpdk_dev, NULL, 0);
-	if (i > 0) {
-		uint16_t port_id[i];
+	RTE_ETH_FOREACH_DEV_OF(port_id, dpdk_dev) {
+		const struct mlx5_priv *opriv =
+			rte_eth_devices[port_id].data->dev_private;
 
-		i = RTE_MIN(mlx5_dev_to_port_id(dpdk_dev, port_id, i), i);
-		while (i--) {
-			const struct mlx5_priv *opriv =
-				rte_eth_devices[port_id[i]].data-
 >dev_private;
-
-			if (!opriv ||
-			    opriv->domain_id ==
-			    RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)
-				continue;
-			priv->domain_id = opriv->domain_id;
-			break;
-		}
+		if (!opriv ||
+			opriv->domain_id ==
+			RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)
+			continue;
+		priv->domain_id = opriv->domain_id;
+		break;
 	}
 	if (priv->domain_id ==

RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {

drivers/net/mlx5/mlx5.c +0 -0
 		err = rte_eth_switch_domain_alloc(&priv->domain_id);
(quoted diff) +0 -0

b/drivers/net/mlx5/mlx5_ethdev.c index 7273bd940..e01b698fc 100644

drivers/net/mlx5/mlx5_ethdev.c +1 -5
@@ -1398,11 +1398,7 @@ mlx5_dev_to_port_id(const struct rte_device
 *dev, uint16_t *port_list,
 	uint16_t id;
 	unsigned int n = 0;
 
-	RTE_ETH_FOREACH_DEV(id) {
-		struct rte_eth_dev *ldev = &rte_eth_devices[id];
-
-		if (ldev->device != dev)
-			continue;
+	RTE_ETH_FOREACH_DEV_OF(id, dev) {
 		if (n < port_list_n)
 			port_list[n] = id;

n++;
--
2.21.0

#37 lore raw

PATCH v3 4/4 app/testpmd: use port sibling iterator in device cleanup

In reply to Thomas Monjalon

When removing a rte_device on a port-based request,
all the sibling ports must be marked as closed.
The iterator loop can be simplified by using the dedicated macro.

---
 app/test-pmd/testpmd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
app/test-pmd/testpmd.c +1 -3
index 40c873b97..aeaa74c98 100644
@@ -2370,9 +2370,7 @@ detach_port_device(portid_t port_id)
 		return;
 	}
 
-	for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++) {
-		if (rte_eth_devices[sibling].device != dev)
-			continue;
+	RTE_ETH_FOREACH_DEV_SIBLING(sibling, port_id) {
 		/* reset mapping between old ports and removed device */
 		rte_eth_devices[sibling].device = NULL;
 		if (ports[sibling].port_status != RTE_PORT_CLOSED) {
Signature · 1 line
2.21.0
Tested-by Viacheslav Ovsiienko on v3 4/4
#39 lore raw

Re: [PATCH v3 4/4] app/testpmd: use port sibling iterator in device cleanup

In reply to Thomas Monjalon
Quoted 10 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Thomas Monjalon
Sent: Monday, April 1, 2019 5:27
To: [email protected]; Wenzhuo Lu <[email protected]>; Jingjing Wu <[email protected]>; Bernard Iremonger <[email protected]>
Cc: [email protected]
Subject: [dpdk-dev] [PATCH v3 4/4] app/testpmd: use port sibling iterator in device cleanup

Quoted 5 lines

When removing a rte_device on a port-based request, all the sibling ports must be marked as closed.
The iterator loop can be simplified by using the dedicated macro.

Tested-by Viacheslav Ovsiienko <mellanox.com>
Quoted 21 lines
---
 app/test-pmd/testpmd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
app/test-pmd/testpmd.c index renamed from app/test-pmd/testpmd.c +0 -0

40c873b97..aeaa74c98 100644

app/test-pmd/testpmd.c +1 -4
@@ -2370,9 +2370,7 @@ detach_port_device(portid_t port_id)
 		return;
 	}
 
-	for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++) {
-		if (rte_eth_devices[sibling].device != dev)
-			continue;
+	RTE_ETH_FOREACH_DEV_SIBLING(sibling, port_id) {
 		/* reset mapping between old ports and removed device */
 		rte_eth_devices[sibling].device = NULL;
 		if (ports[sibling].port_status != RTE_PORT_CLOSED) {
--

2.21.0

#40 lore raw

Re: [PATCH v3 0/4] ethdev iterators for multi-ports device

In reply to Thomas Monjalon
Quoted 6 lines · Thomas Monjalon

Add port iterators in order to allow listing easily the ports of the same device.

The iterators can be tested by using mlx5 or testpmd.

Quoted 8 lines

v3: changes only in the (main) patch 2

Thomas Monjalon (4):
ethdev: simplify port state comparisons
ethdev: add siblings iterators
net/mlx5: use port sibling iterators app/testpmd: use port sibling iterator in device cleanup

Series applied to dpdk-next-net/master, thanks.