All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: optimize acpi companion search for usb port devices
@ 2017-08-18 11:02 Mathias Nyman
  2017-08-18 16:17 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Mathias Nyman @ 2017-08-18 11:02 UTC (permalink / raw)
  To: stable; +Cc: Mathias Nyman, Greg Kroah-Hartman

commit ed18c5fa945768a9bec994e786edbbbc7695acf6 upstream

This optimization significantly reduces xhci driver load time.

In ACPI tables the acpi companion port devices are children of
the hub device. The port devices are identified by their port number
returned by the ACPI _ADR method.
_ADR 0 is reserved for the root hub device.

The current implementation to find a acpi companion port device
loops through all acpi port devices under that parent hub, evaluating
their _ADR method each time a new port device is added.

for a xHC controller with 25 ports under its roothub it
will end up invoking ACPI bytecode 625 times before all ports
are ready, making it really slow.

The _ADR values are already read and cached earler. So instead of
running the bytecode again we can check the cached _ADR value first,
and then fall back to the old way.

As one of the more significant changes, the xhci load time on
Intel kabylake reduced by 70%, (28ms) from
initcall xhci_pci_init+0x0/0x49 returned 0 after 39537 usecs
to
initcall xhci_pci_init+0x0/0x49 returned 0 after 11270 usecs

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/core/usb-acpi.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c
index 2776cfe..ef9cf4a 100644
--- a/drivers/usb/core/usb-acpi.c
+++ b/drivers/usb/core/usb-acpi.c
@@ -127,6 +127,22 @@ out:
  */
 #define USB_ACPI_LOCATION_VALID (1 << 31)
 
+static struct acpi_device *usb_acpi_find_port(struct acpi_device *parent,
+					      int raw)
+{
+	struct acpi_device *adev;
+
+	if (!parent)
+		return NULL;
+
+	list_for_each_entry(adev, &parent->children, node) {
+		if (acpi_device_adr(adev) == raw)
+			return adev;
+	}
+
+	return acpi_find_child_device(parent, raw, false);
+}
+
 static struct acpi_device *usb_acpi_find_companion(struct device *dev)
 {
 	struct usb_device *udev;
@@ -174,8 +190,10 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev)
 			int raw;
 
 			raw = usb_hcd_find_raw_port_number(hcd, port1);
-			adev = acpi_find_child_device(ACPI_COMPANION(&udev->dev),
-					raw, false);
+
+			adev = usb_acpi_find_port(ACPI_COMPANION(&udev->dev),
+						  raw);
+
 			if (!adev)
 				return NULL;
 		} else {
@@ -186,7 +204,9 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev)
 				return NULL;
 
 			acpi_bus_get_device(parent_handle, &adev);
-			adev = acpi_find_child_device(adev, port1, false);
+
+			adev = usb_acpi_find_port(adev, port1);
+
 			if (!adev)
 				return NULL;
 		}
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: optimize acpi companion search for usb port devices
  2017-08-18 11:02 [PATCH] usb: optimize acpi companion search for usb port devices Mathias Nyman
@ 2017-08-18 16:17 ` Greg Kroah-Hartman
  2017-08-21  6:36   ` Mathias Nyman
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2017-08-18 16:17 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: stable

On Fri, Aug 18, 2017 at 02:02:57PM +0300, Mathias Nyman wrote:
> commit ed18c5fa945768a9bec994e786edbbbc7695acf6 upstream
> 
> This optimization significantly reduces xhci driver load time.
> 
> In ACPI tables the acpi companion port devices are children of
> the hub device. The port devices are identified by their port number
> returned by the ACPI _ADR method.
> _ADR 0 is reserved for the root hub device.
> 
> The current implementation to find a acpi companion port device
> loops through all acpi port devices under that parent hub, evaluating
> their _ADR method each time a new port device is added.
> 
> for a xHC controller with 25 ports under its roothub it
> will end up invoking ACPI bytecode 625 times before all ports
> are ready, making it really slow.
> 
> The _ADR values are already read and cached earler. So instead of
> running the bytecode again we can check the cached _ADR value first,
> and then fall back to the old way.
> 
> As one of the more significant changes, the xhci load time on
> Intel kabylake reduced by 70%, (28ms) from
> initcall xhci_pci_init+0x0/0x49 returned 0 after 39537 usecs
> to
> initcall xhci_pci_init+0x0/0x49 returned 0 after 11270 usecs
> 
> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  drivers/usb/core/usb-acpi.c | 26 +++++++++++++++++++++++---
>  1 file changed, 23 insertions(+), 3 deletions(-)

What stable kernel tree(s) is this for?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: optimize acpi companion search for usb port devices
  2017-08-18 16:17 ` Greg Kroah-Hartman
@ 2017-08-21  6:36   ` Mathias Nyman
  0 siblings, 0 replies; 3+ messages in thread
From: Mathias Nyman @ 2017-08-21  6:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: stable

On 18.08.2017 19:17, Greg Kroah-Hartman wrote:
> On Fri, Aug 18, 2017 at 02:02:57PM +0300, Mathias Nyman wrote:
>> commit ed18c5fa945768a9bec994e786edbbbc7695acf6 upstream
>>
>> This optimization significantly reduces xhci driver load time.
>>
>> In ACPI tables the acpi companion port devices are children of
>> the hub device. The port devices are identified by their port number
>> returned by the ACPI _ADR method.
>> _ADR 0 is reserved for the root hub device.
>>
>> The current implementation to find a acpi companion port device
>> loops through all acpi port devices under that parent hub, evaluating
>> their _ADR method each time a new port device is added.
>>
>> for a xHC controller with 25 ports under its roothub it
>> will end up invoking ACPI bytecode 625 times before all ports
>> are ready, making it really slow.
>>
>> The _ADR values are already read and cached earler. So instead of
>> running the bytecode again we can check the cached _ADR value first,
>> and then fall back to the old way.
>>
>> As one of the more significant changes, the xhci load time on
>> Intel kabylake reduced by 70%, (28ms) from
>> initcall xhci_pci_init+0x0/0x49 returned 0 after 39537 usecs
>> to
>> initcall xhci_pci_init+0x0/0x49 returned 0 after 11270 usecs
>>
>> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
>> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> ---
>>   drivers/usb/core/usb-acpi.c | 26 +++++++++++++++++++++++---
>>   1 file changed, 23 insertions(+), 3 deletions(-)
>
> What stable kernel tree(s) is this for?
>

Oh, right, should have mentioned that as well.

4.4 and later

Thanks
Mathias

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-21  6:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-18 11:02 [PATCH] usb: optimize acpi companion search for usb port devices Mathias Nyman
2017-08-18 16:17 ` Greg Kroah-Hartman
2017-08-21  6:36   ` Mathias Nyman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.