PM / sleep: Refactor filesystems sync to reduce duplication

Create a common helper to sync filesystems for system suspend and
hibernation.

Signed-off-by: Harry Pan <harry.pan@intel.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
[ rjw: Changelog ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Harry Pan 2019-02-25 20:36:41 +08:00 committed by Rafael J. Wysocki
parent 74a1dd86d1
commit b5dee3130b
5 changed files with 19 additions and 16 deletions

View File

@ -425,6 +425,7 @@ void restore_processor_state(void);
/* kernel/power/main.c */ /* kernel/power/main.c */
extern int register_pm_notifier(struct notifier_block *nb); extern int register_pm_notifier(struct notifier_block *nb);
extern int unregister_pm_notifier(struct notifier_block *nb); extern int unregister_pm_notifier(struct notifier_block *nb);
extern void ksys_sync_helper(void);
#define pm_notifier(fn, pri) { \ #define pm_notifier(fn, pri) { \
static struct notifier_block fn##_nb = \ static struct notifier_block fn##_nb = \
@ -462,6 +463,8 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)
return 0; return 0;
} }
static inline void ksys_sync_helper(void) {}
#define pm_notifier(fn, pri) do { (void)(fn); } while (0) #define pm_notifier(fn, pri) do { (void)(fn); } while (0)
static inline bool pm_wakeup_pending(void) { return false; } static inline bool pm_wakeup_pending(void) { return false; }

View File

@ -14,7 +14,6 @@
#include <linux/export.h> #include <linux/export.h>
#include <linux/suspend.h> #include <linux/suspend.h>
#include <linux/syscalls.h>
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/device.h> #include <linux/device.h>
@ -709,9 +708,7 @@ int hibernate(void)
goto Exit; goto Exit;
} }
pr_info("Syncing filesystems ... \n"); ksys_sync_helper();
ksys_sync();
pr_info("done.\n");
error = freeze_processes(); error = freeze_processes();
if (error) if (error)

View File

@ -16,6 +16,7 @@
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/suspend.h> #include <linux/suspend.h>
#include <linux/syscalls.h>
#include "power.h" #include "power.h"
@ -51,6 +52,14 @@ void unlock_system_sleep(void)
} }
EXPORT_SYMBOL_GPL(unlock_system_sleep); EXPORT_SYMBOL_GPL(unlock_system_sleep);
void ksys_sync_helper(void)
{
pr_info("Syncing filesystems ... ");
ksys_sync();
pr_cont("done.\n");
}
EXPORT_SYMBOL_GPL(ksys_sync_helper);
/* Routines for PM-transition notifications */ /* Routines for PM-transition notifications */
static BLOCKING_NOTIFIER_HEAD(pm_chain_head); static BLOCKING_NOTIFIER_HEAD(pm_chain_head);

View File

@ -17,7 +17,6 @@
#include <linux/console.h> #include <linux/console.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/cpuidle.h> #include <linux/cpuidle.h>
#include <linux/syscalls.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/kernel.h> #include <linux/kernel.h>
@ -568,13 +567,11 @@ static int enter_state(suspend_state_t state)
if (state == PM_SUSPEND_TO_IDLE) if (state == PM_SUSPEND_TO_IDLE)
s2idle_begin(); s2idle_begin();
#ifndef CONFIG_SUSPEND_SKIP_SYNC if (!IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC)) {
trace_suspend_resume(TPS("sync_filesystems"), 0, true); trace_suspend_resume(TPS("sync_filesystems"), 0, true);
pr_info("Syncing filesystems ... "); ksys_sync_helper();
ksys_sync(); trace_suspend_resume(TPS("sync_filesystems"), 0, false);
pr_cont("done.\n"); }
trace_suspend_resume(TPS("sync_filesystems"), 0, false);
#endif
pm_pr_dbg("Preparing system for sleep (%s)\n", mem_sleep_labels[state]); pm_pr_dbg("Preparing system for sleep (%s)\n", mem_sleep_labels[state]);
pm_suspend_clear_flags(); pm_suspend_clear_flags();

View File

@ -10,7 +10,6 @@
*/ */
#include <linux/suspend.h> #include <linux/suspend.h>
#include <linux/syscalls.h>
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/device.h> #include <linux/device.h>
@ -228,9 +227,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
if (data->frozen) if (data->frozen)
break; break;
printk("Syncing filesystems ... "); ksys_sync_helper();
ksys_sync();
printk("done.\n");
error = freeze_processes(); error = freeze_processes();
if (error) if (error)