Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
14DECLARE_STATIC_KEY_FALSE(freezer_active);
15
16extern bool pm_freezing; /* PM freezing in effect */
17extern bool pm_nosig_freezing; /* PM nosig freezing in effect */
18
19/*
20 * Timeout for stopping processes
21 */
22extern 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 */
29extern bool frozen(struct task_struct *p);
30
31extern 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 */
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() */
47extern void __thaw_task(struct task_struct *t);
48
49extern bool __refrigerator(bool check_kthr_stop);
50extern int freeze_processes(void);
51extern int freeze_kernel_threads(void);
52extern void thaw_processes(void);
53extern void thaw_kernel_threads(void);
54extern void thaw_process(struct task_struct *p);
55
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
66extern bool freeze_task(struct task_struct *p);
67extern bool set_freezable(void);
68
69#ifdef CONFIG_CGROUP_FREEZER
70extern bool cgroup1_freezing(struct task_struct *task);
71#else /* !CONFIG_CGROUP_FREEZER */
72static inline bool cgroup1_freezing(struct task_struct *task)
73{
74 return false;
75}
76#endif /* !CONFIG_CGROUP_FREEZER */
77
78#else /* !CONFIG_FREEZER */
79static inline bool frozen(struct task_struct *p) { return false; }
80static inline bool freezing(struct task_struct *p) { return false; }
81static inline void __thaw_task(struct task_struct *t) {}
82
83static inline bool __refrigerator(bool check_kthr_stop) { return false; }
84static inline int freeze_processes(void) { return -ENOSYS; }
85static inline int freeze_kernel_threads(void) { return -ENOSYS; }
86static inline void thaw_processes(void) {}
87static inline void thaw_kernel_threads(void) {}
88static inline void thaw_process(struct task_struct *p) {}
89
90static inline bool try_to_freeze(void) { return false; }
91
92static inline void set_freezable(void) {}
93
94#endif /* !CONFIG_FREEZER */
95
96#endif /* FREEZER_H_INCLUDED */