[dpdk-dev] Proposal for a big eal / ethdev cleanup

Jan Viktorin viktorin at rehivetech.com
Thu Jan 14 12:46:52 CET 2016


Hello David,

nice to see that the things are moving... 

On Thu, 14 Jan 2016 11:38:16 +0100
David Marchand <david.marchand at 6wind.com> wrote:

> Hello all,
> 
> Here is a proposal of a big cleanup in ethdev (cryptodev would have to
> follow) and eal structures.
> This is something I wanted to do for quite some time and the arrival of
> a new bus makes me think we need it.
> 
> This is an alternative to what Jan proposed [1].

As I need to extend DPDK by a non-PCI bus system, I would prefer any such
working solution :). By [1], you probably mean:

[1] http://comments.gmane.org/gmane.comp.networking.dpdk.devel/30973

(I didn't find it in the e-mail.)

> 
> ABI is most likely broken with this, but I think this discussion can come later.

I was trying in my initial approach to stay as much API and ABI backwards
compatible as possible to be acceptable into upstream. As just a few
people have shown their interest in these changes, I consider the ABI
compatibility very important.

I can see, that your approach does not care too much... Otherwise, it looks
good to me. It is closer to the Linux drivers infra, so it seems to be clearer
then the current one.

> 
> 
> First some context on how dpdk is initialized at the moment :
> 
> Let's imagine a system with one ixgbe pci device and take some
> part of ixgbe driver as an example.
> 
> static struct eth_driver rte_ixgbe_pmd = {
>         .pci_drv = {
>                 .name = "rte_ixgbe_pmd",
>                 .id_table = pci_id_ixgbe_map,
>                 .drv_flags = RTE_PCI_DRV_NEED_MAPPING |
> RTE_PCI_DRV_INTR_LSC | RTE_PCI_DRV_DETACHABLE,
>         },
>         .eth_dev_init = eth_ixgbe_dev_init,
>         .eth_dev_uninit = eth_ixgbe_dev_uninit,
>         .dev_private_size = sizeof(struct ixgbe_adapter),
> };

Note, that the biggest issue here is that the eth_driver has no way to
distinguish among PCI or other subsystem. There is no field that helps
the generic ethdev code (librte_ether) to decide what bus we are on
(and it needs to know it in the current DPDK).

Another point is that the ethdev infra should not know about the
underlying bus infra. The question is whether we do a big clean
up (extract PCI-bus code out) or a small clean up (give the ethdev
infra a hint which bus system it deals with).

> 
> static int
> rte_ixgbe_pmd_init(const char *name __rte_unused, const char *params
> __rte_unused)
> {
>         PMD_INIT_FUNC_TRACE();
>         rte_eth_driver_register(&rte_ixgbe_pmd);
>         return 0;
> }
> 
> static struct rte_driver rte_ixgbe_driver = {
>         .type = PMD_PDEV,
>         .init = rte_ixgbe_pmd_init,
> };
> 
> PMD_REGISTER_DRIVER(rte_ixgbe_driver)
> 
> 
> DPDK initialisation goes as follows (focusing on ixgbe driver):
> 
> PMD_REGISTER_DRIVER(rte_ixgbe_driver) which adds it to dev_driver_list
> 
> rte_eal_init()
>  -> rte_eal_pci_init()
>   -> rte_eal_pci_scan() which fills pci_device_list  
> 
>  -> rte_eal_dev_init()
>   -> for each rte_driver (first vdev, then pdev), call driver->init()  
>      so here rte_ixgbe_pmd_init(NULL, NULL)
>    -> rte_eth_driver_register(&rte_ixgbe_pmd);
>     -> fills rte_ixgbe_pmd.pci_drv.devinit = rte_eth_dev_init
>     -> call rte_eal_pci_register() which adds it to pci_driver_list  
> 
>  -> rte_eal_pci_probe()
>   -> for each rte_pci_device found in rte_eal_pci_scan(), and for all  
>      rte_pci_driver registered, call devinit(dr, dev),
>      so here rte_eth_dev_init(dr, dev)
>    -> creates a new eth_dev (which is a rte_eth_dev), then adds  
>       reference to passed dev pointer (which is a rte_pci_device), to
>       passed dr pointer (which is a rte_pci_driver cast as a eth_driver)
>    -> call eth_drv->eth_dev_init(eth_dev)  
>       so here eth_ixgbe_dev_init(eth_dev)
>     -> fills other parts of eth_dev
>     -> rte_eth_copy_pci_info(eth_dev, pci_dev)  
> 
> 
> By the way, when invoking ethdev init, the pci-specific stuff is only
> handled in functions called from the drivers themselves, which already
> know that they are dealing with pci resources.

This is an important note as it allows to (almost) avoid touching the
current drivers.

> 
> 
> Later in the life of the application, ethdev api is called for hotplug.
> 
> int rte_eth_dev_attach(const char *devargs, uint8_t *port_id);
> 
> A devargs is used to identify a vdev/pdev driver and call it to create a
> new rte_eth_dev.
> Current code goes as far as parsing devargs to understand if this is a
> pci device or a vdev.
> This part should be moved to eal since this is where all the "bus" logic
> is.

Parsing of devargs is quite wierd - I mean whitelisting and
blacklisting. At the moment, it guesses whether the given argument is
a PCI device identification or an arbitrary string (vdev). It is not
easy to extend this reliably.

OK, I can see you are addressing this below.

> 
> 
> 
> So now, what I had in mind is something like this.
> It is far from perfect and I certainly did some shortcuts in my
> reasoning.
> 
> 
> Generic device/driver
> 
> - introduce a rte_device structure,
> - a rte_device has a name, that identifies it in a unique way across
> all buses, maybe something like pci:0000:00:01.0, and for vdev,
> vdev:name

Having a prefix is good but would this break the user API? Is the
name exposed to users?

> - a rte_device references a rte_driver,
> - a rte_device references devargs
> - a rte_device embeds a intr_handle
> - rte_device objects are created by "buses"
> - a function to retrieve rte_device objects based on name is added
> 
> - current rte_driver does not need to know about the pmd_type
> (pdev/vdev), this is only a way to order drivers init in eal, we could
> use the rte_driver names to order them or maybe remove this ordering

What is the main reason to have pdev/vdev distinction here? After I
register the driver, does eal really need to know the pmd_type?

Moreover, there is no way how to pass arguments to pdevs, only to
vdevs. This was shortly disscussed in [2] for the szedata2 PMD.

[2] http://dpdk.org/ml/archives/dev/2015-October/026285.html

> - init and uninit functions are changed to take a pointer to a
> rte_device
> 
> rte_device and rte_driver structures are at the "bus" level.
> Those are the basic structures we will build the other objects on.
> 
> 
> Impact on PCI device/driver
> 
> - rte_pci_device is modified to embed a rte_device (embedding makes it
> possible later to cast the rte_device and get the rte_pci_device in pci
> specific functions)
> - no need for a rte_pci_driver reference in rte_pci_device, since we
> have the rte_device driver

I've noticed that DPDK does not use any kind of the container_of macro
like the Linux Kernel does. Instead, some considerations like the
rte_pci_driver MUST be placed at the beginning of the eth_driver (if I
am not mistaken). Here, it should be considered to do it another way.

> 
> - rte_pci_driver is modified to embed a rte_driver
> - no more devinit and devuninit functions in rte_pci_driver, they can
> be moved as init / uninit functions in rte_driver
> 
> - pci scan code creates rte_pci_device objects, associates them to
> rte_pci_driver, fills the driver field of the rte_driver then pass
> them to rte_driver init function.
> 
> rte_pci_device and rte_pci_driver are specific implementation of
> rte_device and rte_driver.
> There are there to maintain pci private methods, create upper layer
> objects (ethdev / crypto) etc..
> 
> 
> Impact on vdev
> 
> - introduce a rte_vdev_driver structure
> - a rte_vdev_driver embeds a rte_driver
> - a rte_vdev_driver has a priv size for vdev objects creation
> 
> - no need for a vdev device object, this is specific to vdev drivers
> 
> - eal init code associates devargs to vdev drivers, creates a
> rte_device object (using the priv size), fills the driver field then
> pass them to rte_driver init function.
> 
> 
> Impact on ethdev
> 
> - a rte_eth_dev object references a rte_device in place of
> rte_pci_device
> - no more information about a driver in rte_eth_dev, this is the
> rte_device that has a reference to its rte_driver
> - eth_driver can be removed, it is only a wrapper of a rte_pci_driver
> at the moment, maybe some init function wrappers can stay in ethdev
> with dev_private_size to be handled in the rte_driver
> - rte_eth_dev objects are created by rte_drivers during probe (pci
> scan, vdev init, hotplug)
> - ethdev ops are populated by rte_drivers
> 
> 
> Impact on hotplug
> 
> - hotplug moves from ethdev to eal
> - a notification framework is added to ethdev when hotplugging

This seems to be a good idea. I was suprised to find such code in
librte_ether...

> 
> - eal uses the name (remember the pci:0000:00:01.0 / vdev:name
> example) in devargs to identify the right bus (pci / vdev)
> - pci scan code is reused to create a rte_pci_device object etc...
> - vdev init code is reused
> 
> 
> We end up with something like this.
> An arrow means that the structure contains a pointer to an object of the
> other struct.
> I only wrote the fields I mentioned in this mail, for pci device a lot
> of other fields are omitted.
> 
> - for ethdev on top of pci devices
> 
>                 +------------------+ +-------------------------------+
>                 |                  | |                               |
>                 | rte_pci_device   | | rte_pci_driver                |
>                 |                  | |                               |
> +-------------+ | +--------------+ | | +---------------------------+ |
> |             | | |              | | | |                           | |
> | rte_eth_dev +---> rte_device   +-----> rte_driver                | |
> |             | | |  char name[] | | | |  char name[]              | |
> +-------------+ | |              | | | |  int init(rte_device *)   | |
>                 | +--------------+ | | |  int uninit(rte_device *) | |
>                 |                  | | |                           | |
>                 +------------------+ | +---------------------------+ |
>                                      |                               |
>                                      +-------------------------------+
> 
> - for ethdev on top of vdev devices
> 
>                 +------------------+ +-------------------------------+
>                 |                  | |                               |
>                 | drv specific     | | rte_vdev_driver               |
>                 |                  | |                               |
> +-------------+ | +--------------+ | | +---------------------------+ |
> |             | | |              | | | |                           | |
> | rte_eth_dev +---> rte_device   +-----> rte_driver                | |
> |             | | |  char name[] | | | |  char name[]              | |
> +-------------+ | |              | | | |  int init(rte_device *)   | |
>                 | +--------------+ | | |  int uninit(rte_device *) | |
>                 |                  | | |                           | |
>                 +------------------+ | +---------------------------+ |
>                                      |                               |
>                                      |   int priv_size               |
>                                      |                               |
>                                      +-------------------------------+
> 
> 
> Thanks for reading.
> Comments ?
> 
> 

-- 
   Jan Viktorin                  E-mail: Viktorin at RehiveTech.com
   System Architect              Web:    www.RehiveTech.com
   RehiveTech
   Brno, Czech Republic


More information about the dev mailing list