[dpdk-dev] [PATCH 7/9] bus: add helper to find a bus from a device name

Jan Blunck jblunck at infradead.org
Thu Jun 8 13:40:46 CEST 2017


On Thu, Jun 8, 2017 at 1:36 PM, Gaëtan Rivet <gaetan.rivet at 6wind.com> wrote:
> On Thu, Jun 08, 2017 at 12:45:17PM +0200, Jan Blunck wrote:
>> On Wed, Jun 7, 2017 at 10:03 PM, Gaëtan Rivet <gaetan.rivet at 6wind.com> wrote:
>> > On Wed, Jun 07, 2017 at 07:28:07PM +0200, Jan Blunck wrote:
>> >> On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet at 6wind.com> wrote:
>> >> > Find which bus should be able to parse this device name into an internal
>> >> > device representation.
>> >> >
>> >>
>> >> No, please don't add this. One should know to what bus a device
>> >> belongs to before plugging it. Artificially encoding the parent bus
>> >> into the device name is not the right thing to do. Please keep those
>> >> things separate.
>> >>
>> >
>>
>> When plugging a device the users know about:
>> - bus name
>> - device name
>>
>> Its not the case that the users invent the device names out of thin
>> air. The EAL shouldn't codify what the users of the EAL already know
>> about.
>>
>>
>
> Yes, but in that case the user is forced to explicitly name the bus used
> for a device.
>
> I think it might be sufficient to have this as a private function to the
> EAL, as it is currently only used within the rte_devargs parsing.
> Applications could use this helper to recognize a bus from a device
> name, but this is contrived.
>

Just remove it. Putting the knowledge of what bus a device name could
be for into code has failed before (e.g. biosdevname etc.). If the
application doesn't know what bus the device is living on we have a
different problem.

>> > The EAL has no way to know this currently. As you noted, it has to know
>> > onto which bus a device belongs before plugging it.
>> >
>> >> > Signed-off-by: Gaetan Rivet <gaetan.rivet at 6wind.com>
>> >> > ---
>> >> >  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
>> >> >  lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
>> >> >  lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
>> >> >  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
>> >> >  4 files changed, 29 insertions(+)
>> >> >
>> >> > diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
>> >> > index 3517d74..04fa882 100644
>> >> > --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
>> >> > +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
>> >> > @@ -202,5 +202,6 @@ DPDK_17.08 {
>> >> >         global:
>> >> >
>> >> >         rte_bus_from_name;
>> >> > +       rte_bus_from_dev;
>> >> >
>> >> >  } DPDK_17.05;
>> >> > diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
>> >> > index 7977190..08fff60 100644
>> >> > --- a/lib/librte_eal/common/eal_common_bus.c
>> >> > +++ b/lib/librte_eal/common/eal_common_bus.c
>> >> > @@ -242,3 +242,18 @@ rte_bus_from_name(const char *str)
>> >> >                 return NULL;
>> >> >         return rte_bus_find(bus_cmp_name, str);
>> >> >  }
>> >> > +
>> >> > +static int
>> >> > +bus_can_parse(const struct rte_bus *bus, const void *_name)
>> >> > +{
>> >> > +       const char *name = _name;
>> >> > +
>> >> > +       return (bus->parse && !bus->parse(name, NULL));
>> >> > +}
>> >> > +
>> >> > +/* find a bus capable of parsing a device description */
>> >> > +struct rte_bus *
>> >> > +rte_bus_from_dev(const char *str)
>> >> > +{
>> >> > +       return rte_bus_find(bus_can_parse, str);
>> >> > +}
>> >> > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
>> >> > index 5b87ac4..0b48e66 100644
>> >> > --- a/lib/librte_eal/common/include/rte_bus.h
>> >> > +++ b/lib/librte_eal/common/include/rte_bus.h
>> >> > @@ -251,6 +251,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
>> >> >  struct rte_bus *rte_bus_from_name(const char *str);
>> >> >
>> >> >  /**
>> >> > + * Find a bus capable of identifying a device.
>> >> > + *
>> >> > + * @param str
>> >> > + *   A device identifier (PCI address, virtual PMD name, ...).
>> >> > + *
>> >> > + * @return
>> >> > + *   A valid bus structure if found.
>> >> > + *   NULL if no bus is able to parse this device.
>> >> > + */
>> >> > +struct rte_bus *rte_bus_from_dev(const char *str);
>> >> > +
>> >> > +/**
>> >> >   * Helper for Bus registration.
>> >> >   * The constructor has higher priority than PMD constructors.
>> >> >   */
>> >> > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
>> >> > index 6607acc..a5127d6 100644
>> >> > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
>> >> > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
>> >> > @@ -206,5 +206,6 @@ DPDK_17.08 {
>> >> >         global:
>> >> >
>> >> >         rte_bus_from_name;
>> >> > +       rte_bus_from_dev;
>> >> >
>> >> >  } DPDK_17.05;
>> >> > --
>> >> > 2.1.4
>> >> >
>> >
>> > --
>> > Gaėtan Rivet
>> > 6WIND
>
> --
> Gaëtan Rivet
> 6WIND


More information about the dev mailing list