linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* How can a userspace program tell if the system supports the ACPI S4 state (Suspend-to-Disk)?
@ 2020-12-12  1:20 Dexuan Cui
  2020-12-21 19:07 ` Pavel Machek
  2021-02-05 13:05 ` Rafael J. Wysocki
  0 siblings, 2 replies; 7+ messages in thread
From: Dexuan Cui @ 2020-12-12  1:20 UTC (permalink / raw)
  To: linux-acpi; +Cc: linux-kernel, linux-hyperv, Michael Kelley

Hi all,
It looks like Linux can hibernate even if the system does not support the ACPI
S4 state, as long as the system can shut down, so "cat /sys/power/state"
always contains "disk", unless we specify the kernel parameter "nohibernate"
or we use LOCKDOWN_HIBERNATION.

In some scenarios IMO it can still be useful if the userspace is able to detect
if the ACPI S4 state is supported or not, e.g. when a Linux guest runs on 
Hyper-V, Hyper-V uses the virtual ACPI S4 state as an indicator of the proper
support of the tool stack on the host, i.e. the guest is discouraged from 
trying hibernation if the state is not supported.

I know we can check the S4 state by 'dmesg':

# dmesg |grep ACPI: | grep support
[    3.034134] ACPI: (supports S0 S4 S5)

But this method is unreliable because the kernel msg buffer can be filled
and overwritten. Is there any better method? If not, do you think if the
below patch is appropriate? Thanks!

diff --git a/kernel/power/main.c b/kernel/power/main.c
index 0aefd6f57e0a..931a1526ea69 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -9,6 +9,7 @@
 #include <linux/export.h>
 #include <linux/kobject.h>
 #include <linux/string.h>
+#include <linux/acpi.h>
 #include <linux/pm-trace.h>
 #include <linux/workqueue.h>
 #include <linux/debugfs.h>
@@ -600,8 +601,12 @@ static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
                        s += sprintf(s,"%s ", pm_states[i]);

 #endif
-       if (hibernation_available())
-               s += sprintf(s, "disk ");
+       if (hibernation_available()) {
+               if (acpi_sleep_state_supported(ACPI_STATE_S4))
+                       s += sprintf(s, "disk+ ");
+               else
+                       s += sprintf(s, "disk ");
+       }
        if (s != buf)
                /* convert the last space to a newline */
                *(s-1) = '\n';

Thanks,
-- Dexuan



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-02-10  7:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-12  1:20 How can a userspace program tell if the system supports the ACPI S4 state (Suspend-to-Disk)? Dexuan Cui
2020-12-21 19:07 ` Pavel Machek
2020-12-23 21:04   ` Dexuan Cui
2021-02-05 13:05 ` Rafael J. Wysocki
2021-02-05 19:36   ` Dexuan Cui
2021-02-09 18:15     ` James Morse
2021-02-10  7:00       ` Dexuan Cui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).