diff options
author | Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com> | 2011-12-06 17:24:38 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2011-12-08 17:22:21 -0500 |
commit | 9b6fc5dc879bc90f765db0e95eefcf123d0d06dd (patch) | |
tree | 1ccae80c48070963c2296a6e4c6d98107a0efbbf /include | |
parent | 33e638b9070ba5e8812836e20390da6a6af13900 (diff) |
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: Tejun Heo <tj@kernel.org>
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/suspend.h | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 906d62cfc15c..95040cc33107 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h | |||
@@ -332,6 +332,8 @@ static inline bool system_entering_hibernation(void) { return false; } | |||
332 | #define PM_RESTORE_PREPARE 0x0005 /* Going to restore a saved image */ | 332 | #define PM_RESTORE_PREPARE 0x0005 /* Going to restore a saved image */ |
333 | #define PM_POST_RESTORE 0x0006 /* Restore failed */ | 333 | #define PM_POST_RESTORE 0x0006 /* Restore failed */ |
334 | 334 | ||
335 | extern struct mutex pm_mutex; | ||
336 | |||
335 | #ifdef CONFIG_PM_SLEEP | 337 | #ifdef CONFIG_PM_SLEEP |
336 | void save_processor_state(void); | 338 | void save_processor_state(void); |
337 | void restore_processor_state(void); | 339 | void restore_processor_state(void); |
@@ -352,6 +354,19 @@ extern bool events_check_enabled; | |||
352 | extern bool pm_wakeup_pending(void); | 354 | extern bool pm_wakeup_pending(void); |
353 | extern bool pm_get_wakeup_count(unsigned int *count); | 355 | extern bool pm_get_wakeup_count(unsigned int *count); |
354 | extern bool pm_save_wakeup_count(unsigned int count); | 356 | extern bool pm_save_wakeup_count(unsigned int count); |
357 | |||
358 | static inline void lock_system_sleep(void) | ||
359 | { | ||
360 | freezer_do_not_count(); | ||
361 | mutex_lock(&pm_mutex); | ||
362 | } | ||
363 | |||
364 | static inline void unlock_system_sleep(void) | ||
365 | { | ||
366 | mutex_unlock(&pm_mutex); | ||
367 | freezer_count(); | ||
368 | } | ||
369 | |||
355 | #else /* !CONFIG_PM_SLEEP */ | 370 | #else /* !CONFIG_PM_SLEEP */ |
356 | 371 | ||
357 | static inline int register_pm_notifier(struct notifier_block *nb) | 372 | static inline int register_pm_notifier(struct notifier_block *nb) |
@@ -367,30 +382,11 @@ static inline int unregister_pm_notifier(struct notifier_block *nb) | |||
367 | #define pm_notifier(fn, pri) do { (void)(fn); } while (0) | 382 | #define pm_notifier(fn, pri) do { (void)(fn); } while (0) |
368 | 383 | ||
369 | static inline bool pm_wakeup_pending(void) { return false; } | 384 | static inline bool pm_wakeup_pending(void) { return false; } |
370 | #endif /* !CONFIG_PM_SLEEP */ | ||
371 | |||
372 | extern struct mutex pm_mutex; | ||
373 | 385 | ||
374 | #ifndef CONFIG_HIBERNATE_CALLBACKS | ||
375 | static inline void lock_system_sleep(void) {} | 386 | static inline void lock_system_sleep(void) {} |
376 | static inline void unlock_system_sleep(void) {} | 387 | static inline void unlock_system_sleep(void) {} |
377 | 388 | ||
378 | #else | 389 | #endif /* !CONFIG_PM_SLEEP */ |
379 | |||
380 | /* Let some subsystems like memory hotadd exclude hibernation */ | ||
381 | |||
382 | static inline void lock_system_sleep(void) | ||
383 | { | ||
384 | freezer_do_not_count(); | ||
385 | mutex_lock(&pm_mutex); | ||
386 | } | ||
387 | |||
388 | static inline void unlock_system_sleep(void) | ||
389 | { | ||
390 | mutex_unlock(&pm_mutex); | ||
391 | freezer_count(); | ||
392 | } | ||
393 | #endif | ||
394 | 390 | ||
395 | #ifdef CONFIG_ARCH_SAVE_PAGE_KEYS | 391 | #ifdef CONFIG_ARCH_SAVE_PAGE_KEYS |
396 | /* | 392 | /* |