[dpdk-dev,v9,04/12] eal: remove loop over drivers in device detach

Message ID 1484735880-17178-5-git-send-email-shreyansh.jain@nxp.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel compilation success Compilation OK

Commit Message

Shreyansh Jain Jan. 18, 2017, 10:37 a.m. UTC
  rte_eal_pci_detach calls pci_detach_all_drivers which loops over all
PCI drivers for detaching the device. This is unnecessary as the device
already has the PCI driver reference which can be used directly.

Removing pci_detach_all_drivers and restructuring rte_eal_pci_detach
and rte_eal_pci_detach_dev to work without looping over driver list.

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_pci.c | 41 +++++++++-------------------------
 1 file changed, 10 insertions(+), 31 deletions(-)
  

Comments

Shreyansh Jain Jan. 18, 2017, 10:41 a.m. UTC | #1
Thomas,

On Wednesday 18 January 2017 04:07 PM, Shreyansh Jain wrote:
> diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
> index 4f155c6..7548ab0 100644
> --- a/lib/librte_eal/common/eal_common_pci.c
> +++ b/lib/librte_eal/common/eal_common_pci.c
> @@ -259,15 +259,17 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
>   * driver.
>   */
>  static int
> -rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
> -		struct rte_pci_device *dev)
> +rte_eal_pci_detach_dev(struct rte_pci_device *dev)
>  {
>  	int ret;
>  	struct rte_pci_addr *loc;
> +	struct rte_pci_driver *dr;
>
> -	if ((dr == NULL) || (dev == NULL))
> +	if ((dev == NULL))

There is a checkpatch warning here which missed my check (double
paranthesis). Let me know if you want me to send v10 for this.
Or, if there is anything major, I will send it along with that.

>  		return -EINVAL;
>
> +	dr = dev->driver;
> +
>  	ret = rte_pci_match(dr, dev);
>  	if (ret) {

-
Shreyansh
  
Thomas Monjalon Jan. 18, 2017, 11:12 a.m. UTC | #2
2017-01-18 16:07, Shreyansh Jain:
> +       dr = dev->driver;
> +
>         ret = rte_pci_match(dr, dev);
> 

I think you don't need to match driver anymore.
  
Shreyansh Jain Jan. 18, 2017, 12:15 p.m. UTC | #3
> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> Sent: Wednesday, January 18, 2017 4:43 PM
> To: Shreyansh Jain <shreyansh.jain@nxp.com>
> Cc: dev@dpdk.org
> Subject: Re: [PATCH v9 04/12] eal: remove loop over drivers in device detach
> 
> 2017-01-18 16:07, Shreyansh Jain:
> > +       dr = dev->driver;
> > +
> >         ret = rte_pci_match(dr, dev);
> >
> 
> I think you don't need to match driver anymore.

:(
I really need to have a strong shot of caffeine.
Will send out in v10.
  

Patch

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 4f155c6..7548ab0 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -259,15 +259,17 @@  rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
  * driver.
  */
 static int
-rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
-		struct rte_pci_device *dev)
+rte_eal_pci_detach_dev(struct rte_pci_device *dev)
 {
 	int ret;
 	struct rte_pci_addr *loc;
+	struct rte_pci_driver *dr;
 
-	if ((dr == NULL) || (dev == NULL))
+	if ((dev == NULL))
 		return -EINVAL;
 
+	dr = dev->driver;
+
 	ret = rte_pci_match(dr, dev);
 	if (ret) {
 		/* Device and driver don't match */
@@ -328,33 +330,6 @@  pci_probe_all_drivers(struct rte_pci_device *dev)
 }
 
 /*
- * If vendor/device ID match, call the remove() function of all
- * registered driver for the given device. Return -1 if initialization
- * failed, return 1 if no driver is found for this device.
- */
-static int
-pci_detach_all_drivers(struct rte_pci_device *dev)
-{
-	struct rte_pci_driver *dr = NULL;
-	int rc = 0;
-
-	if (dev == NULL)
-		return -1;
-
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
-		rc = rte_eal_pci_detach_dev(dr, dev);
-		if (rc < 0)
-			/* negative value is an error */
-			return -1;
-		if (rc > 0)
-			/* positive value means driver doesn't support it */
-			continue;
-		return 0;
-	}
-	return 1;
-}
-
-/*
  * Find the pci device specified by pci address, then invoke probe function of
  * the driver of the devive.
  */
@@ -407,9 +382,13 @@  rte_eal_pci_detach(const struct rte_pci_addr *addr)
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
-		ret = pci_detach_all_drivers(dev);
+		ret = rte_eal_pci_detach_dev(dev);
 		if (ret < 0)
+			/* negative value is an error */
 			goto err_return;
+		if (ret > 0)
+			/* positive value means driver doesn't support it */
+			continue;
 
 		TAILQ_REMOVE(&pci_device_list, dev, next);
 		free(dev);