Skip to content

Commit b5dee31

Browse files
Harry Panrafaeljw
authored andcommitted
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>
1 parent 74a1dd8 commit b5dee31

5 files changed

Lines changed: 19 additions & 16 deletions

File tree

‎include/linux/suspend.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ void restore_processor_state(void);
425425
/* kernel/power/main.c */
426426
extern int register_pm_notifier(struct notifier_block *nb);
427427
extern int unregister_pm_notifier(struct notifier_block *nb);
428+
extern void ksys_sync_helper(void);
428429

429430
#define pm_notifier(fn, pri) { \
430431
static struct notifier_block fn##_nb = \
@@ -462,6 +463,8 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)
462463
return 0;
463464
}
464465

466+
static inline void ksys_sync_helper(void) {}
467+
465468
#define pm_notifier(fn, pri) do { (void)(fn); } while (0)
466469

467470
static inline bool pm_wakeup_pending(void) { return false; }

‎kernel/power/hibernate.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include <linux/export.h>
1616
#include <linux/suspend.h>
17-
#include <linux/syscalls.h>
1817
#include <linux/reboot.h>
1918
#include <linux/string.h>
2019
#include <linux/device.h>
@@ -709,9 +708,7 @@ int hibernate(void)
709708
goto Exit;
710709
}
711710

712-
pr_info("Syncing filesystems ... \n");
713-
ksys_sync();
714-
pr_info("done.\n");
711+
ksys_sync_helper();
715712

716713
error = freeze_processes();
717714
if (error)

‎kernel/power/main.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/debugfs.h>
1717
#include <linux/seq_file.h>
1818
#include <linux/suspend.h>
19+
#include <linux/syscalls.h>
1920

2021
#include "power.h"
2122

@@ -51,6 +52,14 @@ void unlock_system_sleep(void)
5152
}
5253
EXPORT_SYMBOL_GPL(unlock_system_sleep);
5354

55+
void ksys_sync_helper(void)
56+
{
57+
pr_info("Syncing filesystems ... ");
58+
ksys_sync();
59+
pr_cont("done.\n");
60+
}
61+
EXPORT_SYMBOL_GPL(ksys_sync_helper);
62+
5463
/* Routines for PM-transition notifications */
5564

5665
static BLOCKING_NOTIFIER_HEAD(pm_chain_head);

‎kernel/power/suspend.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <linux/console.h>
1818
#include <linux/cpu.h>
1919
#include <linux/cpuidle.h>
20-
#include <linux/syscalls.h>
2120
#include <linux/gfp.h>
2221
#include <linux/io.h>
2322
#include <linux/kernel.h>
@@ -568,13 +567,11 @@ static int enter_state(suspend_state_t state)
568567
if (state == PM_SUSPEND_TO_IDLE)
569568
s2idle_begin();
570569

571-
#ifndef CONFIG_SUSPEND_SKIP_SYNC
572-
trace_suspend_resume(TPS("sync_filesystems"), 0, true);
573-
pr_info("Syncing filesystems ... ");
574-
ksys_sync();
575-
pr_cont("done.\n");
576-
trace_suspend_resume(TPS("sync_filesystems"), 0, false);
577-
#endif
570+
if (!IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC)) {
571+
trace_suspend_resume(TPS("sync_filesystems"), 0, true);
572+
ksys_sync_helper();
573+
trace_suspend_resume(TPS("sync_filesystems"), 0, false);
574+
}
578575

579576
pm_pr_dbg("Preparing system for sleep (%s)\n", mem_sleep_labels[state]);
580577
pm_suspend_clear_flags();

‎kernel/power/user.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*/
1111

1212
#include <linux/suspend.h>
13-
#include <linux/syscalls.h>
1413
#include <linux/reboot.h>
1514
#include <linux/string.h>
1615
#include <linux/device.h>
@@ -228,9 +227,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
228227
if (data->frozen)
229228
break;
230229

231-
printk("Syncing filesystems ... ");
232-
ksys_sync();
233-
printk("done.\n");
230+
ksys_sync_helper();
234231

235232
error = freeze_processes();
236233
if (error)

0 commit comments

Comments
 (0)