mbox series

[0/3] PM / Sleep: Introduce and use system sleep lock helpers

Message ID 20250520032545.29558-1-zhangzihuan@kylinos.cn
Headers show
Series PM / Sleep: Introduce and use system sleep lock helpers | expand

Message

Zihuan Zhang May 20, 2025, 3:25 a.m. UTC
This patch series introduces wrapper functions for locking
system_transition_mutex used in system sleep (suspend/hibernate) code,
and refactors the existing usage in kernel/power to improve maintainability,
readability, and future extensibility.

Currently, mutex_lock/unlock(&system_transition_mutex) is used directly
in multiple places in the suspend and hibernation paths. This results in
boilerplate repetition and makes it harder to change the locking mechanism
later if needed (e.g., for debugging, tracing, or replacing the mutex
with another primitive).

Summary:

- Patch 1 replaces mutex_lock with lock_system_sleep.

- Patch 2 adds a non-blocking `try_lock_system_sleep()` for code paths that
  should proceed only if the lock is immediately available.

- Patch 3 replaces remaining uses of `system_transition_mutex` in
  `kernel/power/` with the new helper functions.

This change brings all system sleep transition locking behind well-named
abstractions, preparing the code for future evolution while simplifying
reasoning and avoiding repeated direct mutex usage.

 include/linux/suspend.h  |  2 ++
 kernel/power/hibernate.c | 11 +++++++----
 kernel/power/main.c      | 12 ++++++++++++
 kernel/power/suspend.c   |  7 +++++--
 kernel/power/user.c      |  6 ++++--
 kernel/reboot.c          |  5 +++--
 6 files changed, 33 insertions(+), 10 deletions(-)