[PATCH 2/3] PCI: Support asynchronous shutdown
Jeremy Allison
jallison at ciq.com
Thu Dec 14 16:03:57 PST 2023
From: Tanjore Suresh <tansuresh at google.com>
Enhances the base PCI driver to add support for asynchronous
shutdown. Adds shutdown_pre/shutdown_post callbacks only
called in preference to shutdown if both are defined.
Assume a device takes n secs to shutdown. If a machine has been
populated with M such devices, the total time spent in shutting down
all the devices will be M * n secs, if the shutdown is done
synchronously. For example, if NVMe PCI Controllers take 5 secs
to shutdown and if there are 16 such NVMe controllers in a system,
system will spend a total of 80 secs to shutdown all
NVMe devices in that system.
In order to speed up the shutdown time, asynchronous interface to
shutdown has been implemented. This will significantly reduce
the machine reboot time.
Signed-off-by: Tanjore Suresh <tansuresh at google.com>
Signed-off-by: Jeremy Allison <jallison at ciq.com>
---
drivers/pci/pci-driver.c | 18 +++++++++++++++---
include/linux/pci.h | 6 ++++++
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 51ec9e7e784f..865316e5236b 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -502,14 +502,17 @@ static void pci_device_remove(struct device *dev)
pci_dev_put(pci_dev);
}
-static void pci_device_shutdown(struct device *dev)
+static void pci_device_shutdown_pre(struct device *dev)
{
struct pci_dev *pci_dev = to_pci_dev(dev);
struct pci_driver *drv = pci_dev->driver;
pm_runtime_resume(dev);
- if (drv && drv->shutdown)
+ /* Only call shutdown_pre if shutdown_post is also defined. */
+ if (drv && drv->shutdown_pre && drv->shutdown_post)
+ drv->shutdown_pre(pci_dev);
+ else if (drv && drv->shutdown)
drv->shutdown(pci_dev);
/*
@@ -547,6 +550,14 @@ static int pci_restore_standard_config(struct pci_dev *pci_dev)
}
#endif /* CONFIG_PM_SLEEP */
+static void pci_device_shutdown_post(struct device *dev)
+{
+ struct pci_dev *pci_dev = to_pci_dev(dev);
+ struct pci_driver *drv = pci_dev->driver;
+
+ if (drv && drv->shutdown_post)
+ drv->shutdown_post(pci_dev);
+}
#ifdef CONFIG_PM
/* Auxiliary functions used for system resume and run-time resume */
@@ -1681,7 +1692,8 @@ struct bus_type pci_bus_type = {
.uevent = pci_uevent,
.probe = pci_device_probe,
.remove = pci_device_remove,
- .shutdown = pci_device_shutdown,
+ .shutdown_pre = pci_device_shutdown_pre,
+ .shutdown_post = pci_device_shutdown_post,
.dev_groups = pci_dev_groups,
.bus_groups = pci_bus_groups,
.drv_groups = pci_drv_groups,
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 60ca768bc867..a25d1a3a3764 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -917,6 +917,10 @@ struct module;
* Useful for enabling wake-on-lan (NIC) or changing
* the power state of a device before reboot.
* e.g. drivers/net/e100.c.
+ * @shutdown_pre: Optional driver callback to allow asynchronous
+ * shutdown request. Called instead of shutdown only
+ * if shutdown_post is also defined.
+ * @shutdown_post: Matching driver callback to shutdown_pre.
* @sriov_configure: Optional driver callback to allow configuration of
* number of VFs to enable via sysfs "sriov_numvfs" file.
* @sriov_set_msix_vec_count: PF Driver callback to change number of MSI-X
@@ -948,6 +952,8 @@ struct pci_driver {
int (*suspend)(struct pci_dev *dev, pm_message_t state); /* Device suspended */
int (*resume)(struct pci_dev *dev); /* Device woken up */
void (*shutdown)(struct pci_dev *dev);
+ void (*shutdown_pre)(struct pci_dev *dev);
+ void (*shutdown_post)(struct pci_dev *dev);
int (*sriov_configure)(struct pci_dev *dev, int num_vfs); /* On PF */
int (*sriov_set_msix_vec_count)(struct pci_dev *vf, int msix_vec_count); /* On PF */
u32 (*sriov_get_vf_total_msix)(struct pci_dev *pf);
--
2.39.3
More information about the Linux-nvme
mailing list