Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | /* |
3 | * linux/include/linux/nmi.h | |
4 | */ | |
5 | #ifndef LINUX_NMI_H | |
6 | #define LINUX_NMI_H | |
7 | ||
9938406a | 8 | #include <linux/sched.h> |
1da177e4 | 9 | #include <asm/irq.h> |
f2e0cff8 NP |
10 | #if defined(CONFIG_HAVE_NMI_WATCHDOG) |
11 | #include <asm/nmi.h> | |
12 | #endif | |
1da177e4 | 13 | |
d151b27d | 14 | #ifdef CONFIG_LOCKUP_DETECTOR |
05a4a952 | 15 | void lockup_detector_init(void); |
6554fd8c | 16 | void lockup_detector_soft_poweroff(void); |
941154bd | 17 | void lockup_detector_cleanup(void); |
3b371b59 TG |
18 | bool is_hardlockup(void); |
19 | ||
20 | extern int watchdog_user_enabled; | |
7feeb9cd TG |
21 | extern int nmi_watchdog_user_enabled; |
22 | extern int soft_watchdog_user_enabled; | |
3b371b59 TG |
23 | extern int watchdog_thresh; |
24 | extern unsigned long watchdog_enabled; | |
25 | ||
26 | extern struct cpumask watchdog_cpumask; | |
27 | extern unsigned long *watchdog_cpumask_bits; | |
28 | #ifdef CONFIG_SMP | |
29 | extern int sysctl_softlockup_all_cpu_backtrace; | |
30 | extern int sysctl_hardlockup_all_cpu_backtrace; | |
05a4a952 | 31 | #else |
3b371b59 TG |
32 | #define sysctl_softlockup_all_cpu_backtrace 0 |
33 | #define sysctl_hardlockup_all_cpu_backtrace 0 | |
34 | #endif /* !CONFIG_SMP */ | |
35 | ||
36 | #else /* CONFIG_LOCKUP_DETECTOR */ | |
6554fd8c TG |
37 | static inline void lockup_detector_init(void) { } |
38 | static inline void lockup_detector_soft_poweroff(void) { } | |
941154bd | 39 | static inline void lockup_detector_cleanup(void) { } |
3b371b59 | 40 | #endif /* !CONFIG_LOCKUP_DETECTOR */ |
05a4a952 NP |
41 | |
42 | #ifdef CONFIG_SOFTLOCKUP_DETECTOR | |
d151b27d IM |
43 | extern void touch_softlockup_watchdog_sched(void); |
44 | extern void touch_softlockup_watchdog(void); | |
45 | extern void touch_softlockup_watchdog_sync(void); | |
46 | extern void touch_all_softlockup_watchdogs(void); | |
d151b27d | 47 | extern unsigned int softlockup_panic; |
aef92a8b PZ |
48 | |
49 | extern int lockup_detector_online_cpu(unsigned int cpu); | |
50 | extern int lockup_detector_offline_cpu(unsigned int cpu); | |
51 | #else /* CONFIG_SOFTLOCKUP_DETECTOR */ | |
3b371b59 TG |
52 | static inline void touch_softlockup_watchdog_sched(void) { } |
53 | static inline void touch_softlockup_watchdog(void) { } | |
54 | static inline void touch_softlockup_watchdog_sync(void) { } | |
55 | static inline void touch_all_softlockup_watchdogs(void) { } | |
aef92a8b PZ |
56 | |
57 | #define lockup_detector_online_cpu NULL | |
58 | #define lockup_detector_offline_cpu NULL | |
59 | #endif /* CONFIG_SOFTLOCKUP_DETECTOR */ | |
d151b27d IM |
60 | |
61 | #ifdef CONFIG_DETECT_HUNG_TASK | |
62 | void reset_hung_task_detector(void); | |
63 | #else | |
3b371b59 | 64 | static inline void reset_hung_task_detector(void) { } |
d151b27d IM |
65 | #endif |
66 | ||
249e52e3 BM |
67 | /* |
68 | * The run state of the lockup detectors is controlled by the content of the | |
69 | * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit - | |
70 | * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector. | |
71 | * | |
7feeb9cd TG |
72 | * 'watchdog_user_enabled', 'nmi_watchdog_user_enabled' and |
73 | * 'soft_watchdog_user_enabled' are variables that are only used as an | |
74 | * 'interface' between the parameters in /proc/sys/kernel and the internal | |
75 | * state bits in 'watchdog_enabled'. The 'watchdog_thresh' variable is | |
76 | * handled differently because its value is not boolean, and the lockup | |
77 | * detectors are 'suspended' while 'watchdog_thresh' is equal zero. | |
249e52e3 BM |
78 | */ |
79 | #define NMI_WATCHDOG_ENABLED_BIT 0 | |
80 | #define SOFT_WATCHDOG_ENABLED_BIT 1 | |
81 | #define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT) | |
82 | #define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT) | |
83 | ||
f2e0cff8 NP |
84 | #if defined(CONFIG_HARDLOCKUP_DETECTOR) |
85 | extern void hardlockup_detector_disable(void); | |
05a4a952 | 86 | extern unsigned int hardlockup_panic; |
f2e0cff8 NP |
87 | #else |
88 | static inline void hardlockup_detector_disable(void) {} | |
89 | #endif | |
90 | ||
51d4052b TG |
91 | #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR) |
92 | # define NMI_WATCHDOG_SYSCTL_PERM 0644 | |
93 | #else | |
94 | # define NMI_WATCHDOG_SYSCTL_PERM 0444 | |
95 | #endif | |
96 | ||
05a4a952 | 97 | #if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF) |
f2e0cff8 | 98 | extern void arch_touch_nmi_watchdog(void); |
d0b6e0a8 PZ |
99 | extern void hardlockup_detector_perf_stop(void); |
100 | extern void hardlockup_detector_perf_restart(void); | |
941154bd | 101 | extern void hardlockup_detector_perf_disable(void); |
2a1b8ee4 | 102 | extern void hardlockup_detector_perf_enable(void); |
941154bd | 103 | extern void hardlockup_detector_perf_cleanup(void); |
178b9f7a | 104 | extern int hardlockup_detector_perf_init(void); |
f2e0cff8 | 105 | #else |
d0b6e0a8 PZ |
106 | static inline void hardlockup_detector_perf_stop(void) { } |
107 | static inline void hardlockup_detector_perf_restart(void) { } | |
941154bd | 108 | static inline void hardlockup_detector_perf_disable(void) { } |
2a1b8ee4 | 109 | static inline void hardlockup_detector_perf_enable(void) { } |
941154bd | 110 | static inline void hardlockup_detector_perf_cleanup(void) { } |
178b9f7a TG |
111 | # if !defined(CONFIG_HAVE_NMI_WATCHDOG) |
112 | static inline int hardlockup_detector_perf_init(void) { return -ENODEV; } | |
f2e0cff8 | 113 | static inline void arch_touch_nmi_watchdog(void) {} |
178b9f7a TG |
114 | # else |
115 | static inline int hardlockup_detector_perf_init(void) { return 0; } | |
116 | # endif | |
05a4a952 | 117 | #endif |
f2e0cff8 | 118 | |
6b9dc480 TG |
119 | void watchdog_nmi_stop(void); |
120 | void watchdog_nmi_start(void); | |
34ddaa3e | 121 | int watchdog_nmi_probe(void); |
6592ad2f | 122 | |
1da177e4 LT |
123 | /** |
124 | * touch_nmi_watchdog - restart NMI watchdog timeout. | |
3b371b59 | 125 | * |
1da177e4 LT |
126 | * If the architecture supports the NMI watchdog, touch_nmi_watchdog() |
127 | * may be used to reset the timeout - for code which intentionally | |
128 | * disables interrupts for a long time. This call is stateless. | |
129 | */ | |
5d0e600d IM |
130 | static inline void touch_nmi_watchdog(void) |
131 | { | |
f2e0cff8 | 132 | arch_touch_nmi_watchdog(); |
5d0e600d IM |
133 | touch_softlockup_watchdog(); |
134 | } | |
6e7458a6 | 135 | |
47cab6a7 IM |
136 | /* |
137 | * Create trigger_all_cpu_backtrace() out of the arch-provided | |
138 | * base function. Return whether such support was available, | |
139 | * to allow calling code to fall back to some other mechanism: | |
140 | */ | |
9a01c3ed | 141 | #ifdef arch_trigger_cpumask_backtrace |
47cab6a7 IM |
142 | static inline bool trigger_all_cpu_backtrace(void) |
143 | { | |
9a01c3ed | 144 | arch_trigger_cpumask_backtrace(cpu_online_mask, false); |
47cab6a7 IM |
145 | return true; |
146 | } | |
9a01c3ed | 147 | |
f3aca3d0 AT |
148 | static inline bool trigger_allbutself_cpu_backtrace(void) |
149 | { | |
9a01c3ed CM |
150 | arch_trigger_cpumask_backtrace(cpu_online_mask, true); |
151 | return true; | |
152 | } | |
153 | ||
154 | static inline bool trigger_cpumask_backtrace(struct cpumask *mask) | |
155 | { | |
156 | arch_trigger_cpumask_backtrace(mask, false); | |
157 | return true; | |
158 | } | |
159 | ||
160 | static inline bool trigger_single_cpu_backtrace(int cpu) | |
161 | { | |
162 | arch_trigger_cpumask_backtrace(cpumask_of(cpu), false); | |
f3aca3d0 AT |
163 | return true; |
164 | } | |
b2c0b2cb RK |
165 | |
166 | /* generic implementation */ | |
9a01c3ed CM |
167 | void nmi_trigger_cpumask_backtrace(const cpumask_t *mask, |
168 | bool exclude_self, | |
b2c0b2cb RK |
169 | void (*raise)(cpumask_t *mask)); |
170 | bool nmi_cpu_backtrace(struct pt_regs *regs); | |
171 | ||
47cab6a7 IM |
172 | #else |
173 | static inline bool trigger_all_cpu_backtrace(void) | |
174 | { | |
175 | return false; | |
176 | } | |
f3aca3d0 AT |
177 | static inline bool trigger_allbutself_cpu_backtrace(void) |
178 | { | |
179 | return false; | |
180 | } | |
9a01c3ed CM |
181 | static inline bool trigger_cpumask_backtrace(struct cpumask *mask) |
182 | { | |
183 | return false; | |
184 | } | |
185 | static inline bool trigger_single_cpu_backtrace(int cpu) | |
186 | { | |
187 | return false; | |
188 | } | |
bb81a09e AM |
189 | #endif |
190 | ||
05a4a952 | 191 | #ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF |
4eec42f3 | 192 | u64 hw_nmi_get_sample_period(int watchdog_thresh); |
05a4a952 NP |
193 | #endif |
194 | ||
7edaeb68 TG |
195 | #if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \ |
196 | defined(CONFIG_HARDLOCKUP_DETECTOR) | |
197 | void watchdog_update_hrtimer_threshold(u64 period); | |
198 | #else | |
199 | static inline void watchdog_update_hrtimer_threshold(u64 period) { } | |
200 | #endif | |
201 | ||
504d7cf1 | 202 | struct ctl_table; |
83a80a39 UO |
203 | extern int proc_watchdog(struct ctl_table *, int , |
204 | void __user *, size_t *, loff_t *); | |
205 | extern int proc_nmi_watchdog(struct ctl_table *, int , | |
206 | void __user *, size_t *, loff_t *); | |
207 | extern int proc_soft_watchdog(struct ctl_table *, int , | |
208 | void __user *, size_t *, loff_t *); | |
209 | extern int proc_watchdog_thresh(struct ctl_table *, int , | |
210 | void __user *, size_t *, loff_t *); | |
fe4ba3c3 CM |
211 | extern int proc_watchdog_cpumask(struct ctl_table *, int, |
212 | void __user *, size_t *, loff_t *); | |
84e478c6 | 213 | |
44a69f61 TN |
214 | #ifdef CONFIG_HAVE_ACPI_APEI_NMI |
215 | #include <asm/nmi.h> | |
216 | #endif | |
217 | ||
1da177e4 | 218 | #endif |