[PATCH v2 6/7] PCI: pciehp: Replace msleep(10) with usleep_range() for precise delays

Hans Zhang posted 7 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v2 6/7] PCI: pciehp: Replace msleep(10) with usleep_range() for precise delays
Posted by Hans Zhang 1 month, 1 week ago
The msleep(10) in pcie_poll_cmd() and pcie_wait_for_presence() may sleep
longer than intended due to timer granularity, which can cause unnecessary
delays in hotplug operations. Replace them with usleep_range() calls using
macros for more precise delays of approximately 10ms.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/hotplug/pciehp_hpc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index bcc51b26d03d..f9ae48b7b6ad 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -28,6 +28,9 @@
 #include "../pci.h"
 #include "pciehp.h"
 
+#define WAIT_PDS_TIMEOUT_US	10000
+#define POLL_CMD_TIMEOUT_US	10000
+
 static const struct dmi_system_id inband_presence_disabled_dmi_table[] = {
 	/*
 	 * Match all Dell systems, as some Dell systems have inband
@@ -103,7 +106,7 @@ static int pcie_poll_cmd(struct controller *ctrl, int timeout)
 			smp_mb();
 			return 1;
 		}
-		msleep(10);
+		usleep_range(POLL_CMD_TIMEOUT_US, POLL_CMD_TIMEOUT_US + 100);
 		timeout -= 10;
 	} while (timeout >= 0);
 	return 0;	/* timeout */
@@ -284,6 +287,7 @@ static void pcie_wait_for_presence(struct pci_dev *pdev)
 		if (slot_status & PCI_EXP_SLTSTA_PDS)
 			return;
 		msleep(10);
+		usleep_range(WAIT_PDS_TIMEOUT_US, WAIT_PDS_TIMEOUT_US + 100);
 		timeout -= 10;
 	} while (timeout > 0);
 }
-- 
2.25.1