freezer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Freezer declarations */
  3. #ifndef FREEZER_H_INCLUDED
  4. #define FREEZER_H_INCLUDED
  5. #include <linux/debug_locks.h>
  6. #include <linux/sched.h>
  7. #include <linux/wait.h>
  8. #include <linux/atomic.h>
  9. #include <linux/jump_label.h>
  10. #ifdef CONFIG_FREEZER
  11. DECLARE_STATIC_KEY_FALSE(freezer_active);
  12. extern bool pm_freezing; /* PM freezing in effect */
  13. extern bool pm_nosig_freezing; /* PM nosig freezing in effect */
  14. /*
  15. * Timeout for stopping processes
  16. */
  17. extern unsigned int freeze_timeout_msecs;
  18. /*
  19. * Check if a process has been frozen
  20. */
  21. extern bool frozen(struct task_struct *p);
  22. extern bool freezing_slow_path(struct task_struct *p);
  23. /*
  24. * Check if there is a request to freeze a process
  25. */
  26. static inline bool freezing(struct task_struct *p)
  27. {
  28. if (static_branch_unlikely(&freezer_active))
  29. return freezing_slow_path(p);
  30. return false;
  31. }
  32. /* Takes and releases task alloc lock using task_lock() */
  33. extern void __thaw_task(struct task_struct *t);
  34. extern bool __refrigerator(bool check_kthr_stop);
  35. extern int freeze_processes(void);
  36. extern int freeze_kernel_threads(void);
  37. extern void thaw_processes(void);
  38. extern void thaw_kernel_threads(void);
  39. static inline bool try_to_freeze(void)
  40. {
  41. might_sleep();
  42. if (likely(!freezing(current)))
  43. return false;
  44. if (!(current->flags & PF_NOFREEZE))
  45. debug_check_no_locks_held();
  46. return __refrigerator(false);
  47. }
  48. extern bool freeze_task(struct task_struct *p);
  49. extern bool set_freezable(void);
  50. #ifdef CONFIG_CGROUP_FREEZER
  51. extern bool cgroup_freezing(struct task_struct *task);
  52. #else /* !CONFIG_CGROUP_FREEZER */
  53. static inline bool cgroup_freezing(struct task_struct *task)
  54. {
  55. return false;
  56. }
  57. #endif /* !CONFIG_CGROUP_FREEZER */
  58. #else /* !CONFIG_FREEZER */
  59. static inline bool frozen(struct task_struct *p) { return false; }
  60. static inline bool freezing(struct task_struct *p) { return false; }
  61. static inline void __thaw_task(struct task_struct *t) {}
  62. static inline bool __refrigerator(bool check_kthr_stop) { return false; }
  63. static inline int freeze_processes(void) { return -ENOSYS; }
  64. static inline int freeze_kernel_threads(void) { return -ENOSYS; }
  65. static inline void thaw_processes(void) {}
  66. static inline void thaw_kernel_threads(void) {}
  67. static inline bool try_to_freeze(void) { return false; }
  68. static inline void set_freezable(void) {}
  69. #endif /* !CONFIG_FREEZER */
  70. #endif /* FREEZER_H_INCLUDED */