From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ob0-f170.google.com (mail-ob0-f170.google.com [209.85.214.170]) by dpdk.org (Postfix) with ESMTP id 9D48B8E82 for ; Thu, 14 Jan 2016 11:38:36 +0100 (CET) Received: by mail-ob0-f170.google.com with SMTP id vt7so79582434obb.1 for ; Thu, 14 Jan 2016 02:38:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to:cc:content-type; bh=Ha5OB0jLX9tjLgL0XOpao/QXXrlb84H7S7v++JT1yHM=; b=RUYBNuqcRhOwahcPds3FObBxHQB5bQ//tSiV0VkAewGsUngKFMSGnFrP52flEMVlnH rrGVlUtAUlWB58ZmPXmJjvfMv5G5pDP2vcndU/ZYbRGgC4JHOep/84unTQjLgfyvlEdo dVpDH7EgdE9tHMJ5B7d/UEvcsI1Fq6DFGBCU5yftiyBvCmpJAzVK7LY/FWvh3KFnjABE 81PsS34rXi1rjGo/+gCNs0PWmO83PHB9AFBMYXyNh3PORI929wXlIdQY1pf6xZLkNhRy ZdTm+8e7t2xjVBGWs4+x+6ubQicDH/Bxzo0pNafDmjuO9mXJFvXUyTsJEd7Nr4gakAMD lqhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc :content-type; bh=Ha5OB0jLX9tjLgL0XOpao/QXXrlb84H7S7v++JT1yHM=; b=YsUDk/GuSV3wAGwayk9nr+dpy9lSIasqVLnR2CEkI/Y1YXkIaxIsKN1k4sMNZdK0ti tqPDG+ILXdVfqUsBYPmEvyInTgj2pwUkcZr+Kh6a3JUvJG/OaFzAHfG0xlZlOUqvdDnG eM5gg+AkuhX2vgNQVVyLXVg6VRv5wW4FwxOTfpN3zToGeNrDx9bnbYiFEjQ3NxtyKrmF NDbe7ej02c8Bk5TJ9+I1UfQd+2840RnCKQ/qVZamcxl5NFvCOQQAPfVK4l5fgdSZgscR 1+cu483t+qDefNFuNRijriZ/U25oMbwjwK23poD5fzzS7ZLrwCHm/YwTnev8fPXOEbtu UFWA== X-Gm-Message-State: ALoCoQmPz31UYffV1jvbfpjxmFgyUlfTuu+eJsz/FpgSjOJiyzwPumc97PS4qikttplJwM//cmB3oLeBwvg8hF2K3XPYjQeMyMgDA/cf9gbfkFjjpWOq65Y= X-Received: by 10.60.35.130 with SMTP id h2mr2558206oej.6.1452767915934; Thu, 14 Jan 2016 02:38:35 -0800 (PST) MIME-Version: 1.0 Received: by 10.76.180.72 with HTTP; Thu, 14 Jan 2016 02:38:16 -0800 (PST) From: David Marchand Date: Thu, 14 Jan 2016 11:38:16 +0100 Message-ID: To: "dev@dpdk.org" Content-Type: text/plain; charset=UTF-8 Cc: Jan Viktorin Subject: [dpdk-dev] Proposal for a big eal / ethdev cleanup X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jan 2016 10:38:36 -0000 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]. ABI is most likely broken with this, but I think this discussion can come later. 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), }; 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. 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. 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 - 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 - 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 - 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 - 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 ? -- David Marchand [1] http://dpdk.org/ml/archives/dev/2016-January/030975.html