DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] ethdev: add siblings iterator
@ 2018-11-30  0:27 Thomas Monjalon
  2018-12-11 16:31 ` Ferruh Yigit
                   ` (2 more replies)
  0 siblings, 3 replies; 70+ messages in thread
From: Thomas Monjalon @ 2018-11-30  0:27 UTC (permalink / raw)
  To: ferruh.yigit, arybchenko; +Cc: dev

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.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 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(+)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 5f858174b..11e0ade6e 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -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)
 {
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index 1960f3a2d..647e6634d 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -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
diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map
index 92ac3de25..a0c930d04 100644
--- a/lib/librte_ethdev/rte_ethdev_version.map
+++ b/lib/librte_ethdev/rte_ethdev_version.map
@@ -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.19.0

^ permalink raw reply	[flat|nested] 70+ messages in thread

end of thread, other threads:[~2019-04-04 11:33 UTC | newest]

Thread overview: 70+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-30  0:27 [dpdk-dev] [PATCH] ethdev: add siblings iterator Thomas Monjalon
2018-12-11 16:31 ` Ferruh Yigit
2018-12-11 18:19   ` Thomas Monjalon
2019-02-20 22:10 ` [dpdk-dev] [PATCH v2 0/4] ethdev iterators for multi-ports device Thomas Monjalon
2019-02-20 22:10   ` [dpdk-dev] [PATCH v2 1/4] ethdev: simplify port state comparisons Thomas Monjalon
2019-02-24 17:18     ` Andrew Rybchenko
2019-02-20 22:10   ` [dpdk-dev] [PATCH v2 2/4] ethdev: add siblings iterators Thomas Monjalon
2019-02-24 17:22     ` Andrew Rybchenko
2019-02-27 10:07     ` Gaëtan Rivet
2019-02-27 10:51       ` Thomas Monjalon
2019-04-01  1:59         ` Thomas Monjalon
2019-04-01  1:59           ` Thomas Monjalon
2019-03-19 15:47     ` Ferruh Yigit
2019-03-19 15:47       ` Ferruh Yigit
2019-03-19 17:34       ` Thomas Monjalon
2019-03-19 17:34         ` Thomas Monjalon
2019-03-19 18:04         ` Ferruh Yigit
2019-03-19 18:04           ` Ferruh Yigit
2019-04-01  2:16           ` Thomas Monjalon
2019-04-01  2:16             ` Thomas Monjalon
2019-04-01  6:46             ` David Marchand
2019-04-01  6:46               ` David Marchand
2019-04-01  8:09               ` Thomas Monjalon
2019-04-01  8:09                 ` Thomas Monjalon
2019-04-02 23:35                 ` Ferruh Yigit
2019-04-02 23:35                   ` Ferruh Yigit
2019-04-02 23:37                   ` Thomas Monjalon
2019-04-02 23:37                     ` Thomas Monjalon
2019-02-20 22:10   ` [dpdk-dev] [PATCH v2 3/4] net/mlx5: use port sibling iterators Thomas Monjalon
2019-02-20 22:10   ` [dpdk-dev] [PATCH v2 4/4] app/testpmd: use port sibling iterator in device cleanup Thomas Monjalon
2019-04-01  2:26 ` [dpdk-dev] [PATCH v3 0/4] ethdev iterators for multi-ports device Thomas Monjalon
2019-04-01  2:26   ` Thomas Monjalon
2019-04-01  2:26   ` [dpdk-dev] [PATCH v3 1/4] ethdev: simplify port state comparisons Thomas Monjalon
2019-04-01  2:26     ` Thomas Monjalon
2019-04-01 14:58     ` Stephen Hemminger
2019-04-01 14:58       ` Stephen Hemminger
2019-04-01 15:17       ` Thomas Monjalon
2019-04-01 15:17         ` Thomas Monjalon
2019-04-01 16:07         ` Stephen Hemminger
2019-04-01 16:07           ` Stephen Hemminger
2019-04-03 15:03     ` Slava Ovsiienko
2019-04-03 15:03       ` Slava Ovsiienko
2019-04-01  2:26   ` [dpdk-dev] [PATCH v3 2/4] ethdev: add siblings iterators Thomas Monjalon
2019-04-01  2:26     ` Thomas Monjalon
2019-04-01  7:23     ` Andrew Rybchenko
2019-04-01  7:23       ` Andrew Rybchenko
2019-04-02 23:42     ` Ferruh Yigit
2019-04-02 23:42       ` Ferruh Yigit
2019-04-02 23:48       ` Thomas Monjalon
2019-04-02 23:48         ` Thomas Monjalon
2019-04-03 15:03     ` Slava Ovsiienko
2019-04-03 15:03       ` Slava Ovsiienko
2019-04-01  2:26   ` [dpdk-dev] [PATCH v3 3/4] net/mlx5: use port sibling iterators Thomas Monjalon
2019-04-01  2:26     ` Thomas Monjalon
2019-04-03 14:19     ` Ferruh Yigit
2019-04-03 14:19       ` Ferruh Yigit
2019-04-03 18:07       ` Yongseok Koh
2019-04-03 18:07         ` Yongseok Koh
2019-04-04 11:33         ` Ferruh Yigit
2019-04-04 11:33           ` Ferruh Yigit
2019-04-03 15:04     ` Slava Ovsiienko
2019-04-03 15:04       ` Slava Ovsiienko
2019-04-01  2:27   ` [dpdk-dev] [PATCH v3 4/4] app/testpmd: use port sibling iterator in device cleanup Thomas Monjalon
2019-04-01  2:27     ` Thomas Monjalon
2019-04-02 23:43     ` Ferruh Yigit
2019-04-02 23:43       ` Ferruh Yigit
2019-04-03 15:04     ` Slava Ovsiienko
2019-04-03 15:04       ` Slava Ovsiienko
2019-04-03 16:42   ` [dpdk-dev] [PATCH v3 0/4] ethdev iterators for multi-ports device Ferruh Yigit
2019-04-03 16:42     ` Ferruh Yigit

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).