[dpdk-dev] [PATCH v5 02/12] bus: add device iterator method

Gaëtan Rivet gaetan.rivet at 6wind.com
Mon Jun 26 23:13:49 CEST 2017


On Mon, Jun 26, 2017 at 05:20:37PM +0100, Bruce Richardson wrote:
> On Mon, Jun 26, 2017 at 02:22:00AM +0200, Gaetan Rivet wrote:
> > From: Jan Blunck <jblunck at infradead.org>
> > 
> > Signed-off-by: Jan Blunck <jblunck at infradead.org>
> > Signed-off-by: Gaetan Rivet <gaetan.rivet at 6wind.com>
> > ---
> >  lib/librte_eal/common/include/rte_bus.h | 19 +++++++++++++++++++
> >  lib/librte_eal/common/include/rte_dev.h | 21 +++++++++++++++++++++
> >  2 files changed, 40 insertions(+)
> > 
> > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> > index ecf839b..5efb76e 100644
> > --- a/lib/librte_eal/common/include/rte_bus.h
> > +++ b/lib/librte_eal/common/include/rte_bus.h
> > @@ -82,6 +82,24 @@ typedef int (*rte_bus_scan_t)(void);
> >  typedef int (*rte_bus_probe_t)(void);
> >  
> >  /**
> > + * Device iterator to find a device on a bus.
> > + *
> > + * This function returns an rte_device if one of those held by the bus
> > + * matches the data passed as parameter.
> > + *
> > + * @param cmp
> > + *	Comparison function.
> > + *
> > + * @param data
> > + *	Data to compare each device against.
> > + *
> > + * @return
> > + *	The first device matching the data, NULL if none exists.
> > + */
> > +typedef struct rte_device * (*rte_bus_find_device_t)(rte_dev_cmp_t cmp,
> > +						     const void *data);
> > +
> > +/**
> 
> The bus find function takes a third, start, parameter. Is it worthwhile
> including such a parameter here, for consistency sake if nothing else?
> 

I was wondering this actually.

Doing so would deport the added complexity, to be repeated in
each bus implementation. It would in turn simplify my own calls,
ever so slightly. That means a few small-ish additional spots of
complexity instead of a single one.

I'm also thinking that maybe a few buses could avoid having linked lists
for their containers (I know it's frowned upon to roll your own, but
some might have good reasons for doing so), allowing random access, bypassing
cycling through each.

Well, I will do as you suggest, if anyone objects, please shout before I send the
next version.

> Otherwise:
> 
> Acked-by: Bruce Richardson <bruce.richardson at intel.com>

-- 
Gaëtan Rivet
6WIND


More information about the dev mailing list