Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b6fc5dc authored by Srivatsa S. Bhat's avatar Srivatsa S. Bhat Committed by Rafael J. Wysocki
Browse files

PM / Sleep: Make [un]lock_system_sleep() generic



The [un]lock_system_sleep() APIs were originally introduced to mutually
exclude memory hotplug and hibernation.

Directly using mutex_lock(&pm_mutex) to achieve mutual exclusion with
suspend or hibernation code can lead to freezing failures. However, the
APIs [un]lock_system_sleep() can be safely used to achieve the same,
without causing freezing failures.

So, since it would be beneficial to modify all the existing users of
mutex_lock(&pm_mutex) (in all parts of the kernel), so that they use these
safe APIs intead, make these APIs generic by removing the restriction that
they work only when CONFIG_HIBERNATE_CALLBACKS is set. Moreover, that
restriction didn't buy us anything anyway.

Suggested-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
parent 33e638b9
Loading
Loading
Loading
Loading
+16 −20
Original line number Original line Diff line number Diff line
@@ -332,6 +332,8 @@ static inline bool system_entering_hibernation(void) { return false; }
#define PM_RESTORE_PREPARE	0x0005 /* Going to restore a saved image */
#define PM_RESTORE_PREPARE	0x0005 /* Going to restore a saved image */
#define PM_POST_RESTORE		0x0006 /* Restore failed */
#define PM_POST_RESTORE		0x0006 /* Restore failed */


extern struct mutex pm_mutex;

#ifdef CONFIG_PM_SLEEP
#ifdef CONFIG_PM_SLEEP
void save_processor_state(void);
void save_processor_state(void);
void restore_processor_state(void);
void restore_processor_state(void);
@@ -352,6 +354,19 @@ extern bool events_check_enabled;
extern bool pm_wakeup_pending(void);
extern bool pm_wakeup_pending(void);
extern bool pm_get_wakeup_count(unsigned int *count);
extern bool pm_get_wakeup_count(unsigned int *count);
extern bool pm_save_wakeup_count(unsigned int count);
extern bool pm_save_wakeup_count(unsigned int count);

static inline void lock_system_sleep(void)
{
	freezer_do_not_count();
	mutex_lock(&pm_mutex);
}

static inline void unlock_system_sleep(void)
{
	mutex_unlock(&pm_mutex);
	freezer_count();
}

#else /* !CONFIG_PM_SLEEP */
#else /* !CONFIG_PM_SLEEP */


static inline int register_pm_notifier(struct notifier_block *nb)
static inline int register_pm_notifier(struct notifier_block *nb)
@@ -367,30 +382,11 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)
#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; }
#endif /* !CONFIG_PM_SLEEP */

extern struct mutex pm_mutex;


#ifndef CONFIG_HIBERNATE_CALLBACKS
static inline void lock_system_sleep(void) {}
static inline void lock_system_sleep(void) {}
static inline void unlock_system_sleep(void) {}
static inline void unlock_system_sleep(void) {}


#else
#endif /* !CONFIG_PM_SLEEP */

/* Let some subsystems like memory hotadd exclude hibernation */

static inline void lock_system_sleep(void)
{
	freezer_do_not_count();
	mutex_lock(&pm_mutex);
}

static inline void unlock_system_sleep(void)
{
	mutex_unlock(&pm_mutex);
	freezer_count();
}
#endif


#ifdef CONFIG_ARCH_SAVE_PAGE_KEYS
#ifdef CONFIG_ARCH_SAVE_PAGE_KEYS
/*
/*