PCI/PM: Reduce D3hot delay with usleep_range()
authorSajid Dalvi <sdalvi@google.com>
Wed, 21 Sep 2022 21:27:35 +0000 (21:27 +0000)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 29 Sep 2022 19:31:40 +0000 (14:31 -0500)
commit3e347969a5776947a115649dae740a9ed47473f5
treebbc9ff6cdf06d8441d93ffc8f225cf082ba56fb5
parent4c00cba122f3f3ae54aa5a3a1aec3afc7a2e6f94
PCI/PM: Reduce D3hot delay with usleep_range()

PCIe r6.0, sec 5.9, requires a 10ms delay between programming a device to
change to or from D3hot and the time the device is next accessed (unless
Readiness Notifications are used).

The 10ms value (PCI_PM_D3HOT_WAIT) doesn't appear directly here because
some chipsets require 120ms for devices *below* them (pci_pm_d3hot_delay)
and some devices require more or less than 10ms (dev->d3hot_delay).

But msleep(10) typically waits about *20*ms, which is more than we need.
Switch to usleep_range() to improve the delay accuracy.

Based on a commit from Sajid in the Pixel 6 kernel tree [1].  On a Pixel 6,
the 10ms delay for the Exynos PCIe device delayed for an average of 19ms.
Switching to usleep_range() decreased the resume time by about 9ms.

[1] https://android.googlesource.com/kernel/gs/+/18a8cad68d8e6d50f339a716a18295e6d987cee3

[bhelgaas commit log, add timers-howto.rst link]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/timers/timers-howto.rst?id=v5.19#n73
Link: https://lore.kernel.org/r/20220921212735.2131588-1-willmcvicker@google.com
Signed-off-by: Sajid Dalvi <sdalvi@google.com>
Signed-off-by: Will McVicker <willmcvicker@google.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
drivers/pci/pci.c