1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Freezer declarations */ 3 4 #ifndef FREEZER_H_INCLUDED 5 #define FREEZER_H_INCLUDED 6 7 #include <linux/debug_locks.h> 8 #include <linux/sched.h> 9 #include <linux/wait.h> 10 #include <linux/atomic.h> 11 #include <linux/jump_label.h> 12 13 #ifdef CONFIG_FREEZER 14 DECLARE_STATIC_KEY_FALSE(freezer_active); 15 16 extern bool pm_freezing; /* PM freezing in effect */ 17 extern bool pm_nosig_freezing; /* PM nosig freezing in effect */ 18 19 /* 20 * Timeout for stopping processes 21 */ 22 extern unsigned int freeze_timeout_msecs; 23 24 /* 25 * Check if a process has been frozen for PM or cgroup1 freezer. Note that 26 * cgroup2 freezer uses the job control mechanism and does not interact with 27 * the PM freezer. 28 */ 29 extern bool frozen(struct task_struct *p); 30 31 extern bool freezing_slow_path(struct task_struct *p); 32 33 /* 34 * Check if there is a request to freeze a task from PM or cgroup1 freezer. 35 * Note that cgroup2 freezer uses the job control mechanism and does not 36 * interact with the PM freezer. 37 */ freezing(struct task_struct * p)38static inline bool freezing(struct task_struct *p) 39 { 40 if (static_branch_unlikely(&freezer_active)) 41 return freezing_slow_path(p); 42 43 return false; 44 } 45 46 /* Takes and releases task alloc lock using task_lock() */ 47 extern void __thaw_task(struct task_struct *t); 48 49 extern bool __refrigerator(bool check_kthr_stop); 50 extern int freeze_processes(void); 51 extern int freeze_kernel_threads(void); 52 extern void thaw_processes(void); 53 extern void thaw_kernel_threads(void); 54 extern void thaw_process(struct task_struct *p); 55 try_to_freeze(void)56static inline bool try_to_freeze(void) 57 { 58 might_sleep(); 59 if (likely(!freezing(current))) 60 return false; 61 if (!(current->flags & PF_NOFREEZE)) 62 debug_check_no_locks_held(); 63 return __refrigerator(false); 64 } 65 66 extern bool freeze_task(struct task_struct *p); 67 extern bool set_freezable(void); 68 69 #ifdef CONFIG_CGROUP_FREEZER 70 extern bool cgroup1_freezing(struct task_struct *task); 71 #else /* !CONFIG_CGROUP_FREEZER */ cgroup1_freezing(struct task_struct * task)72static inline bool cgroup1_freezing(struct task_struct *task) 73 { 74 return false; 75 } 76 #endif /* !CONFIG_CGROUP_FREEZER */ 77 78 #else /* !CONFIG_FREEZER */ frozen(struct task_struct * p)79static inline bool frozen(struct task_struct *p) { return false; } freezing(struct task_struct * p)80static inline bool freezing(struct task_struct *p) { return false; } __thaw_task(struct task_struct * t)81static inline void __thaw_task(struct task_struct *t) {} 82 __refrigerator(bool check_kthr_stop)83static inline bool __refrigerator(bool check_kthr_stop) { return false; } freeze_processes(void)84static inline int freeze_processes(void) { return -ENOSYS; } freeze_kernel_threads(void)85static inline int freeze_kernel_threads(void) { return -ENOSYS; } thaw_processes(void)86static inline void thaw_processes(void) {} thaw_kernel_threads(void)87static inline void thaw_kernel_threads(void) {} thaw_process(struct task_struct * p)88static inline void thaw_process(struct task_struct *p) {} 89 try_to_freeze(void)90static inline bool try_to_freeze(void) { return false; } 91 set_freezable(void)92static inline void set_freezable(void) {} 93 94 #endif /* !CONFIG_FREEZER */ 95 96 #endif /* FREEZER_H_INCLUDED */ 97