Merge tag 'drm-fixes-2024-06-22' of https://gitlab.freedesktop.org/drm/kernel
[linux-2.6-block.git] / include / linux / freezer.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
7dfb7103
NC
2/* Freezer declarations */
3
83144186
RW
4#ifndef FREEZER_H_INCLUDED
5#define FREEZER_H_INCLUDED
6
0f9548ca 7#include <linux/debug_locks.h>
5c543eff 8#include <linux/sched.h>
e42837bc 9#include <linux/wait.h>
a3201227 10#include <linux/atomic.h>
f5d39b02 11#include <linux/jump_label.h>
5c543eff 12
8174f150 13#ifdef CONFIG_FREEZER
f5d39b02
PZ
14DECLARE_STATIC_KEY_FALSE(freezer_active);
15
a3201227
TH
16extern bool pm_freezing; /* PM freezing in effect */
17extern bool pm_nosig_freezing; /* PM nosig freezing in effect */
18
957d1282
LF
19/*
20 * Timeout for stopping processes
21 */
22extern unsigned int freeze_timeout_msecs;
23
7dfb7103
NC
24/*
25 * Check if a process has been frozen
26 */
f5d39b02 27extern bool frozen(struct task_struct *p);
7dfb7103 28
a3201227 29extern bool freezing_slow_path(struct task_struct *p);
7dfb7103
NC
30
31/*
a3201227 32 * Check if there is a request to freeze a process
7dfb7103 33 */
a3201227 34static inline bool freezing(struct task_struct *p)
7dfb7103 35{
f5d39b02
PZ
36 if (static_branch_unlikely(&freezer_active))
37 return freezing_slow_path(p);
38
39 return false;
7dfb7103
NC
40}
41
dc52ddc0 42/* Takes and releases task alloc lock using task_lock() */
a5be2d0d 43extern void __thaw_task(struct task_struct *t);
7dfb7103 44
8a32c441 45extern bool __refrigerator(bool check_kthr_stop);
7dfb7103 46extern int freeze_processes(void);
2aede851 47extern int freeze_kernel_threads(void);
a9b6f562 48extern void thaw_processes(void);
181e9bde 49extern void thaw_kernel_threads(void);
7dfb7103 50
f5d39b02 51static inline bool try_to_freeze(void)
7dfb7103 52{
a0acae0e
TH
53 might_sleep();
54 if (likely(!freezing(current)))
55 return false;
0f9548ca
MSB
56 if (!(current->flags & PF_NOFREEZE))
57 debug_check_no_locks_held();
f5d39b02 58 return __refrigerator(false);
416ad3c9
CC
59}
60
839e3407 61extern bool freeze_task(struct task_struct *p);
34b087e4 62extern bool set_freezable(void);
8174f150 63
dc52ddc0 64#ifdef CONFIG_CGROUP_FREEZER
22b4e111 65extern bool cgroup_freezing(struct task_struct *task);
dc52ddc0 66#else /* !CONFIG_CGROUP_FREEZER */
22b4e111 67static inline bool cgroup_freezing(struct task_struct *task)
5a7aadfe 68{
22b4e111 69 return false;
5a7aadfe 70}
dc52ddc0
MH
71#endif /* !CONFIG_CGROUP_FREEZER */
72
8174f150 73#else /* !CONFIG_FREEZER */
948246f7 74static inline bool frozen(struct task_struct *p) { return false; }
a3201227 75static inline bool freezing(struct task_struct *p) { return false; }
62c9ea6b 76static inline void __thaw_task(struct task_struct *t) {}
7dfb7103 77
8a32c441 78static inline bool __refrigerator(bool check_kthr_stop) { return false; }
2aede851
RW
79static inline int freeze_processes(void) { return -ENOSYS; }
80static inline int freeze_kernel_threads(void) { return -ENOSYS; }
7dfb7103 81static inline void thaw_processes(void) {}
181e9bde 82static inline void thaw_kernel_threads(void) {}
7dfb7103 83
a0acae0e 84static inline bool try_to_freeze(void) { return false; }
7dfb7103 85
83144186 86static inline void set_freezable(void) {}
e42837bc 87
8174f150 88#endif /* !CONFIG_FREEZER */
83144186
RW
89
90#endif /* FREEZER_H_INCLUDED */