linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/1] suspend: make sync() on suspend-to-RAM optional
@ 2015-07-15  2:24 Len Brown
  2015-07-15  2:24 ` [PATCH 1/1] " Len Brown
  0 siblings, 1 reply; 26+ messages in thread
From: Len Brown @ 2015-07-15  2:24 UTC (permalink / raw)
  To: rjw, linux-pm; +Cc: linux-kernel

Based on discussion resulting from...
https://lkml.org/lkml/2015/5/8/82 [PATCH 1/1] suspend: delete sys_sync(),
this patch makes sys_sync() optional, rather than deleting it entirely.

This is an update to the original patch for this issue from Jan, 2014:
patch https://lkml.org/lkml/2014/1/23/73
[PATCH v3] suspend: make sync() on suspend-to-RAM optional

Aside from applying to Linux 4.1, rather than 3.13...
the change is that suspend always checks the flag from the
sysfs attribute before invoking sys_sync(); and the config option
just sets the default value.  Before the config option deleted all code.
Also, the config dependency is corrected, and some varialbes re-named.


^ permalink raw reply	[flat|nested] 26+ messages in thread
* [PATCH 1/1] suspend: make sync() on suspend-to-RAM optional
@ 2014-01-23  7:11 Len Brown
  2014-01-23  7:29 ` Zhang Rui
                   ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Len Brown @ 2014-01-23  7:11 UTC (permalink / raw)
  To: rjw; +Cc: linux-pm, linux-kernel, Len Brown

From: Len Brown <len.brown@intel.com>

Linux suspend-to-RAM was unreliable when first developed,
and so sys_sync() was invoked inside the kernel at the
start of every suspend flow.

Today, many devices are invoking suspend with
high reliability and high frequency, and they don't
want to be forced to pay for sync on every suspend.

So here we make it optional.
De-select CONFIG_PM_SLEEP_SYNC to delete the call entirely.
or keep CONFIG_PM_SLEEP and you can now clear the
sys/power/sleep_sync attribte to disable the sync
from user-space.

As we have had this call for a long time,
the default remains to keep the call, and to
invoke it on every suspend.

Signed-off-by: Len Brown <len.brown@intel.com>
---
 kernel/power/Kconfig   |  8 ++++++++
 kernel/power/main.c    | 33 +++++++++++++++++++++++++++++++++
 kernel/power/power.h   |  1 +
 kernel/power/suspend.c | 10 +++++++---
 4 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 2fac9cc..d2927ce 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -102,6 +102,14 @@ config PM_SLEEP_SMP
 	depends on PM_SLEEP
 	select HOTPLUG_CPU
 
+config PM_SLEEP_SYNC
+	bool "Suspend to RAM starts with in-kernel call to sync()"
+	default y
+	depends on PM_SLEEP
+	---help---
+	Build a call to sync() into the Linux kernel suspend to RAM flow.
+	The sync can still be skipped by clearing /sys/power/sleep_sync.
+
 config PM_AUTOSLEEP
 	bool "Opportunistic sleep"
 	depends on PM_SLEEP
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 1d1bf63..1102871 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -71,6 +71,36 @@ static ssize_t pm_async_store(struct kobject *kobj, struct kobj_attribute *attr,
 
 power_attr(pm_async);
 
+#ifdef CONFIG_PM_SLEEP_SYNC
+
+/* If set, sync file systems at start of suspend flow */
+int pm_sleep_sync_enabled = 1;
+
+static ssize_t pm_sleep_sync_show(struct kobject *kobj, struct kobj_attribute *attr,
+			     char *buf)
+{
+	return sprintf(buf, "%d\n", pm_sleep_sync_enabled);
+}
+
+static ssize_t pm_sleep_sync_store(struct kobject *kobj, struct kobj_attribute *attr,
+			      const char *buf, size_t n)
+{
+	unsigned long val;
+
+	if (kstrtoul(buf, 10, &val))
+		return -EINVAL;
+
+	if (val > 1)
+		return -EINVAL;
+
+	pm_sleep_sync_enabled = val;
+	return n;
+}
+
+power_attr(pm_sleep_sync);
+
+#endif /* CONFIG_PM_SLEEP_SYNC */
+
 #ifdef CONFIG_PM_DEBUG
 int pm_test_level = TEST_NONE;
 
@@ -592,6 +622,9 @@ static struct attribute * g[] = {
 #ifdef CONFIG_PM_SLEEP
 	&pm_async_attr.attr,
 	&wakeup_count_attr.attr,
+#ifdef CONFIG_PM_SLEEP_SYNC
+	&pm_sleep_sync_attr.attr,
+#endif
 #ifdef CONFIG_PM_AUTOSLEEP
 	&autosleep_attr.attr,
 #endif
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 7d4b7ff..dca60a7 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -200,6 +200,7 @@ static inline void suspend_test_finish(const char *label) {}
 #ifdef CONFIG_PM_SLEEP
 /* kernel/power/main.c */
 extern int pm_notifier_call_chain(unsigned long val);
+extern int pm_sleep_sync_enabled;
 #endif
 
 #ifdef CONFIG_HIGHMEM
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 62ee437..2fb2f51 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -333,9 +333,13 @@ static int enter_state(suspend_state_t state)
 	if (state == PM_SUSPEND_FREEZE)
 		freeze_begin();
 
-	printk(KERN_INFO "PM: Syncing filesystems ... ");
-	sys_sync();
-	printk("done.\n");
+#ifdef CONFIG_PM_SLEEP_SYNC
+	if (pm_sleep_sync_enabled) {
+		printk(KERN_INFO "PM: Syncing filesystems ... ");
+		sys_sync();
+		printk("done.\n");
+	}
+#endif /* CONFIG_PM_SLEEP_SYNC */
 
 	pr_debug("PM: Preparing system for %s sleep\n", pm_states[state]);
 	error = suspend_prepare(state);
-- 
1.8.3.2


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

end of thread, other threads:[~2015-10-08 15:50 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-15  2:24 [PATCH v4 0/1] suspend: make sync() on suspend-to-RAM optional Len Brown
2015-07-15  2:24 ` [PATCH 1/1] " Len Brown
2015-07-15  6:43   ` Pavel Machek
2015-07-15 14:06     ` Austin S Hemmelgarn
2015-07-15 14:58       ` Brown, Len
2015-07-17 23:54         ` Rafael J. Wysocki
2015-07-21  9:38           ` Pavel Machek
2015-07-21 14:41             ` Rafael J. Wysocki
2015-07-21 15:19               ` Pavel Machek
2015-07-21 15:36                 ` Austin S Hemmelgarn
2015-07-21 20:11                   ` Pavel Machek
2015-07-21 20:01                 ` Brown, Len
2015-07-21 20:05                   ` Pavel Machek
2015-07-22  1:25                 ` Rafael J. Wysocki
2015-07-22  7:23                   ` Pavel Machek
2015-07-22  8:55                   ` Oliver Neukum
2015-07-31 16:02                     ` Len Brown
2015-07-31 23:56                       ` Rafael J. Wysocki
2015-10-08 15:50                         ` Pavel Machek
  -- strict thread matches above, loose matches on Subject: below --
2014-01-23  7:11 Len Brown
2014-01-23  7:29 ` Zhang Rui
2014-01-23  7:41   ` Brown, Len
2014-01-23  7:38 ` Srivatsa S. Bhat
2014-01-23  7:59   ` Brown, Len
2014-01-26 21:08 ` Pavel Machek
2015-05-08  6:41   ` Len Brown

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).