From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?iso-8859-1?Q?Ga=EBtan?= Rivet Subject: Re: [PATCH v2 2/4] ethdev: add siblings iterators Date: Wed, 27 Feb 2019 11:07:24 +0100 Message-ID: <20190227100724.tjkxtuis5yfwvvrd@bidouze.vm.6wind.com> References: <20181130002716.27325-1-thomas@monjalon.net> <20190220221051.7928-1-thomas@monjalon.net> <20190220221051.7928-3-thomas@monjalon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Cc: Ferruh Yigit , Andrew Rybchenko , dev@dpdk.org To: Thomas Monjalon Return-path: Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by dpdk.org (Postfix) with ESMTP id 395A84CAB for ; Wed, 27 Feb 2019 11:07:28 +0100 (CET) Received: by mail-wm1-f67.google.com with SMTP id z84so4962140wmg.4 for ; Wed, 27 Feb 2019 02:07:28 -0800 (PST) Content-Disposition: inline In-Reply-To: <20190220221051.7928-3-thomas@monjalon.net> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Thomas, On Wed, Feb 20, 2019 at 11:10:49PM +0100, Thomas Monjalon wrote: > 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. > > Signed-off-by: Thomas Monjalon > --- > 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(+) > > diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c > index b3b2fb1dba..42154787f8 100644 > --- a/lib/librte_ethdev/rte_ethdev.c > +++ b/lib/librte_ethdev/rte_ethdev.c > @@ -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). -- Gaëtan Rivet 6WIND