Skip to content

Commit 3e34796

Browse files
Sajid Dalvibjorn-helgaas
authored andcommitted
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>
1 parent 4c00cba commit 3e34796

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

drivers/pci/pci.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ struct pci_pme_device {
6666

6767
static void pci_dev_d3_sleep(struct pci_dev *dev)
6868
{
69-
unsigned int delay = dev->d3hot_delay;
70-
71-
if (delay < pci_pm_d3hot_delay)
72-
delay = pci_pm_d3hot_delay;
73-
74-
if (delay)
75-
msleep(delay);
69+
unsigned int delay_ms = max(dev->d3hot_delay, pci_pm_d3hot_delay);
70+
unsigned int upper;
71+
72+
if (delay_ms) {
73+
/* Use a 20% upper bound, 1ms minimum */
74+
upper = max(DIV_ROUND_CLOSEST(delay_ms, 5), 1U);
75+
usleep_range(delay_ms * USEC_PER_MSEC,
76+
(delay_ms + upper) * USEC_PER_MSEC);
77+
}
7678
}
7779

7880
bool pci_reset_supported(struct pci_dev *dev)

0 commit comments

Comments
 (0)