diff mbox series

[v2,1/2] PM: enable support for imminent power loss

Message ID 20210726132223.1661-2-sshivamurthy@micron.com (mailing list archive)
State Not Applicable, archived
Headers show
Series Abrupt Shutdown for NVMe SSD | expand

Commit Message

shiva.linuxworks@gmail.com July 26, 2021, 1:22 p.m. UTC
From: Shivamurthy Shastri <sshivamurthy@micron.com>

If the shutdown is pwerformed when the platform is running on the
limited backup power supply, some of the devices might not have enough
power to perform a clean shutdown.

It is necessary to inform the driver about the limited backup power
supply, to allow the driver to decide to perform the minimal required
operation for a fast and clean shutdown.

Signed-off-by: Keith Busch <kbush@kernel.org>
Signed-off-by: Shivamurthy Shastri <sshivamurthy@micron.com>
---
 include/linux/suspend.h | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

Comments

Pavel Machek July 26, 2021, 7:41 p.m. UTC | #1
Hi!

> If the shutdown is pwerformed when the platform is running on the
> limited backup power supply, some of the devices might not have enough
> power to perform a clean shutdown.
> 
> It is necessary to inform the driver about the limited backup power
> supply, to allow the driver to decide to perform the minimal required
> operation for a fast and clean shutdown.

If you can do shutdown that is fast & clean, why not do it always?

How fast is normal shutdown vs. fast shutdown?

> +#define PM_SUSPEND_FLAG_POWER_LOSS_IMMINENT	BIT(3)

I believe we should be more concrete here. Like explaining use (did
UPS say battery is low? Or does it mean 10 seconds remaining? Or...?)

Plus, who sets this flag? Userland?

Best regards,
								Pavel


--
Keith Busch July 26, 2021, 8:16 p.m. UTC | #2
On Mon, Jul 26, 2021 at 09:41:46PM +0200, Pavel Machek wrote:
> > If the shutdown is pwerformed when the platform is running on the
> > limited backup power supply, some of the devices might not have enough
> > power to perform a clean shutdown.
> > 
> > It is necessary to inform the driver about the limited backup power
> > supply, to allow the driver to decide to perform the minimal required
> > operation for a fast and clean shutdown.
> 
> If you can do shutdown that is fast & clean, why not do it always?

At least for nvme, I don't think this faster shutdown qualifies as
"clean". It's just a little better than removing power without telling
the device. Typical implementations take longer to become ready on their
next power-on following the abrupt shutdown sequence.
diff mbox series

Patch

diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index 8af13ba60c7e..1898792c10d3 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -210,9 +210,10 @@  extern int suspend_valid_only_mem(suspend_state_t state);
 
 extern unsigned int pm_suspend_global_flags;
 
-#define PM_SUSPEND_FLAG_FW_SUSPEND	BIT(0)
-#define PM_SUSPEND_FLAG_FW_RESUME	BIT(1)
-#define PM_SUSPEND_FLAG_NO_PLATFORM	BIT(2)
+#define PM_SUSPEND_FLAG_FW_SUSPEND		BIT(0)
+#define PM_SUSPEND_FLAG_FW_RESUME		BIT(1)
+#define PM_SUSPEND_FLAG_NO_PLATFORM		BIT(2)
+#define PM_SUSPEND_FLAG_POWER_LOSS_IMMINENT	BIT(3)
 
 static inline void pm_suspend_clear_flags(void)
 {
@@ -234,6 +235,11 @@  static inline void pm_set_suspend_no_platform(void)
 	pm_suspend_global_flags |= PM_SUSPEND_FLAG_NO_PLATFORM;
 }
 
+static inline void pm_set_power_loss_imminent(void)
+{
+	pm_suspend_global_flags |= PM_SUSPEND_FLAG_POWER_LOSS_IMMINENT;
+}
+
 /**
  * pm_suspend_via_firmware - Check if platform firmware will suspend the system.
  *
@@ -291,6 +297,22 @@  static inline bool pm_suspend_no_platform(void)
 	return !!(pm_suspend_global_flags & PM_SUSPEND_FLAG_NO_PLATFORM);
 }
 
+/**
+ * pm_power_loss_imminent - Check if platform is running on limited backup power
+ * source
+ *
+ * To be called during system-wide power management transitions to sleep states.
+ *
+ * Return 'true' if power loss may be imminent due to platform running on
+ * limited backup supply. If set during a shutdown, drivers should use any
+ * available shortcuts to prepare their device for abrupt power loss.
+ */
+static inline bool pm_power_loss_imminent(void)
+{
+	return !!(pm_suspend_global_flags &
+		  PM_SUSPEND_FLAG_POWER_LOSS_IMMINENT);
+}
+
 /* Suspend-to-idle state machnine. */
 enum s2idle_states {
 	S2IDLE_STATE_NONE,      /* Not suspended/suspending. */