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> |
0c68bda6 PM |
10 | |
11 | /* Arch specific watchdogs might need to share extra watchdog-related APIs. */ | |
7ca8fe94 | 12 | #if defined(CONFIG_HARDLOCKUP_DETECTOR_ARCH) || defined(CONFIG_HARDLOCKUP_DETECTOR_SPARC64) |
f2e0cff8 NP |
13 | #include <asm/nmi.h> |
14 | #endif | |
1da177e4 | 15 | |
d151b27d | 16 | #ifdef CONFIG_LOCKUP_DETECTOR |
05a4a952 | 17 | void lockup_detector_init(void); |
930d8f8d | 18 | void lockup_detector_retry_init(void); |
6554fd8c | 19 | void lockup_detector_soft_poweroff(void); |
3b371b59 TG |
20 | |
21 | extern int watchdog_user_enabled; | |
3b371b59 TG |
22 | extern int watchdog_thresh; |
23 | extern unsigned long watchdog_enabled; | |
24 | ||
25 | extern struct cpumask watchdog_cpumask; | |
26 | extern unsigned long *watchdog_cpumask_bits; | |
27 | #ifdef CONFIG_SMP | |
28 | extern int sysctl_softlockup_all_cpu_backtrace; | |
29 | extern int sysctl_hardlockup_all_cpu_backtrace; | |
05a4a952 | 30 | #else |
3b371b59 TG |
31 | #define sysctl_softlockup_all_cpu_backtrace 0 |
32 | #define sysctl_hardlockup_all_cpu_backtrace 0 | |
33 | #endif /* !CONFIG_SMP */ | |
34 | ||
35 | #else /* CONFIG_LOCKUP_DETECTOR */ | |
6554fd8c | 36 | static inline void lockup_detector_init(void) { } |
930d8f8d | 37 | static inline void lockup_detector_retry_init(void) { } |
6554fd8c | 38 | static inline void lockup_detector_soft_poweroff(void) { } |
3b371b59 | 39 | #endif /* !CONFIG_LOCKUP_DETECTOR */ |
05a4a952 NP |
40 | |
41 | #ifdef CONFIG_SOFTLOCKUP_DETECTOR | |
d151b27d IM |
42 | extern void touch_softlockup_watchdog_sched(void); |
43 | extern void touch_softlockup_watchdog(void); | |
44 | extern void touch_softlockup_watchdog_sync(void); | |
45 | extern void touch_all_softlockup_watchdogs(void); | |
d151b27d | 46 | extern unsigned int softlockup_panic; |
aef92a8b PZ |
47 | |
48 | extern int lockup_detector_online_cpu(unsigned int cpu); | |
49 | extern int lockup_detector_offline_cpu(unsigned int cpu); | |
50 | #else /* CONFIG_SOFTLOCKUP_DETECTOR */ | |
3b371b59 TG |
51 | static inline void touch_softlockup_watchdog_sched(void) { } |
52 | static inline void touch_softlockup_watchdog(void) { } | |
53 | static inline void touch_softlockup_watchdog_sync(void) { } | |
54 | static inline void touch_all_softlockup_watchdogs(void) { } | |
aef92a8b PZ |
55 | |
56 | #define lockup_detector_online_cpu NULL | |
57 | #define lockup_detector_offline_cpu NULL | |
58 | #endif /* CONFIG_SOFTLOCKUP_DETECTOR */ | |
d151b27d IM |
59 | |
60 | #ifdef CONFIG_DETECT_HUNG_TASK | |
61 | void reset_hung_task_detector(void); | |
62 | #else | |
3b371b59 | 63 | static inline void reset_hung_task_detector(void) { } |
d151b27d IM |
64 | #endif |
65 | ||
249e52e3 BM |
66 | /* |
67 | * The run state of the lockup detectors is controlled by the content of the | |
68 | * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit - | |
69 | * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector. | |
70 | * | |
df95d308 DA |
71 | * 'watchdog_user_enabled', 'watchdog_hardlockup_user_enabled' and |
72 | * 'watchdog_softlockup_user_enabled' are variables that are only used as an | |
7feeb9cd TG |
73 | * 'interface' between the parameters in /proc/sys/kernel and the internal |
74 | * state bits in 'watchdog_enabled'. The 'watchdog_thresh' variable is | |
75 | * handled differently because its value is not boolean, and the lockup | |
76 | * detectors are 'suspended' while 'watchdog_thresh' is equal zero. | |
249e52e3 | 77 | */ |
df95d308 DA |
78 | #define WATCHDOG_HARDLOCKUP_ENABLED_BIT 0 |
79 | #define WATCHDOG_SOFTOCKUP_ENABLED_BIT 1 | |
80 | #define WATCHDOG_HARDLOCKUP_ENABLED (1 << WATCHDOG_HARDLOCKUP_ENABLED_BIT) | |
81 | #define WATCHDOG_SOFTOCKUP_ENABLED (1 << WATCHDOG_SOFTOCKUP_ENABLED_BIT) | |
249e52e3 | 82 | |
f2e0cff8 NP |
83 | #if defined(CONFIG_HARDLOCKUP_DETECTOR) |
84 | extern void hardlockup_detector_disable(void); | |
05a4a952 | 85 | extern unsigned int hardlockup_panic; |
f2e0cff8 NP |
86 | #else |
87 | static inline void hardlockup_detector_disable(void) {} | |
88 | #endif | |
89 | ||
0c68bda6 | 90 | /* Sparc64 has special implemetantion that is always enabled. */ |
47f4cb43 | 91 | #if defined(CONFIG_HARDLOCKUP_DETECTOR) || defined(CONFIG_HARDLOCKUP_DETECTOR_SPARC64) |
ed92e1ef | 92 | void arch_touch_nmi_watchdog(void); |
0c68bda6 PM |
93 | #else |
94 | static inline void arch_touch_nmi_watchdog(void) { } | |
95 | #endif | |
96 | ||
97 | #if defined(CONFIG_HARDLOCKUP_DETECTOR_COUNTS_HRTIMER) | |
1f423c90 | 98 | void watchdog_hardlockup_touch_cpu(unsigned int cpu); |
77c12fc9 | 99 | void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs); |
81972551 DA |
100 | #endif |
101 | ||
05a4a952 | 102 | #if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF) |
d0b6e0a8 PZ |
103 | extern void hardlockup_detector_perf_stop(void); |
104 | extern void hardlockup_detector_perf_restart(void); | |
393fb313 | 105 | extern void hardlockup_config_perf_event(const char *str); |
f2e0cff8 | 106 | #else |
d0b6e0a8 PZ |
107 | static inline void hardlockup_detector_perf_stop(void) { } |
108 | static inline void hardlockup_detector_perf_restart(void) { } | |
393fb313 | 109 | static inline void hardlockup_config_perf_event(const char *str) { } |
05a4a952 | 110 | #endif |
f2e0cff8 | 111 | |
df95d308 DA |
112 | void watchdog_hardlockup_stop(void); |
113 | void watchdog_hardlockup_start(void); | |
114 | int watchdog_hardlockup_probe(void); | |
115 | void watchdog_hardlockup_enable(unsigned int cpu); | |
116 | void watchdog_hardlockup_disable(unsigned int cpu); | |
6592ad2f | 117 | |
7c56a873 LD |
118 | void lockup_detector_reconfigure(void); |
119 | ||
1f423c90 | 120 | #ifdef CONFIG_HARDLOCKUP_DETECTOR_BUDDY |
d3b62ace | 121 | void watchdog_buddy_check_hardlockup(int hrtimer_interrupts); |
1f423c90 | 122 | #else |
d3b62ace | 123 | static inline void watchdog_buddy_check_hardlockup(int hrtimer_interrupts) {} |
1f423c90 DA |
124 | #endif |
125 | ||
1da177e4 | 126 | /** |
8b5c59a9 | 127 | * touch_nmi_watchdog - manually reset the hardlockup watchdog timeout. |
3b371b59 | 128 | * |
8b5c59a9 DA |
129 | * If we support detecting hardlockups, touch_nmi_watchdog() may be |
130 | * used to pet the watchdog (reset the timeout) - for code which | |
131 | * intentionally disables interrupts for a long time. This call is stateless. | |
132 | * | |
133 | * Though this function has "nmi" in the name, the hardlockup watchdog might | |
134 | * not be backed by NMIs. This function will likely be renamed to | |
135 | * touch_hardlockup_watchdog() in the future. | |
1da177e4 | 136 | */ |
5d0e600d IM |
137 | static inline void touch_nmi_watchdog(void) |
138 | { | |
8b5c59a9 DA |
139 | /* |
140 | * Pass on to the hardlockup detector selected via CONFIG_. Note that | |
141 | * the hardlockup detector may not be arch-specific nor using NMIs | |
142 | * and the arch_touch_nmi_watchdog() function will likely be renamed | |
143 | * in the future. | |
144 | */ | |
f2e0cff8 | 145 | arch_touch_nmi_watchdog(); |
8b5c59a9 | 146 | |
5d0e600d IM |
147 | touch_softlockup_watchdog(); |
148 | } | |
6e7458a6 | 149 | |
47cab6a7 IM |
150 | /* |
151 | * Create trigger_all_cpu_backtrace() out of the arch-provided | |
152 | * base function. Return whether such support was available, | |
153 | * to allow calling code to fall back to some other mechanism: | |
154 | */ | |
9a01c3ed | 155 | #ifdef arch_trigger_cpumask_backtrace |
47cab6a7 IM |
156 | static inline bool trigger_all_cpu_backtrace(void) |
157 | { | |
8d539b84 | 158 | arch_trigger_cpumask_backtrace(cpu_online_mask, -1); |
47cab6a7 IM |
159 | return true; |
160 | } | |
9a01c3ed | 161 | |
8d539b84 | 162 | static inline bool trigger_allbutcpu_cpu_backtrace(int exclude_cpu) |
f3aca3d0 | 163 | { |
8d539b84 | 164 | arch_trigger_cpumask_backtrace(cpu_online_mask, exclude_cpu); |
9a01c3ed CM |
165 | return true; |
166 | } | |
167 | ||
168 | static inline bool trigger_cpumask_backtrace(struct cpumask *mask) | |
169 | { | |
8d539b84 | 170 | arch_trigger_cpumask_backtrace(mask, -1); |
9a01c3ed CM |
171 | return true; |
172 | } | |
173 | ||
174 | static inline bool trigger_single_cpu_backtrace(int cpu) | |
175 | { | |
8d539b84 | 176 | arch_trigger_cpumask_backtrace(cpumask_of(cpu), -1); |
f3aca3d0 AT |
177 | return true; |
178 | } | |
b2c0b2cb RK |
179 | |
180 | /* generic implementation */ | |
9a01c3ed | 181 | void nmi_trigger_cpumask_backtrace(const cpumask_t *mask, |
8d539b84 | 182 | int exclude_cpu, |
b2c0b2cb RK |
183 | void (*raise)(cpumask_t *mask)); |
184 | bool nmi_cpu_backtrace(struct pt_regs *regs); | |
185 | ||
47cab6a7 IM |
186 | #else |
187 | static inline bool trigger_all_cpu_backtrace(void) | |
188 | { | |
189 | return false; | |
190 | } | |
8d539b84 | 191 | static inline bool trigger_allbutcpu_cpu_backtrace(int exclude_cpu) |
f3aca3d0 AT |
192 | { |
193 | return false; | |
194 | } | |
9a01c3ed CM |
195 | static inline bool trigger_cpumask_backtrace(struct cpumask *mask) |
196 | { | |
197 | return false; | |
198 | } | |
199 | static inline bool trigger_single_cpu_backtrace(int cpu) | |
200 | { | |
201 | return false; | |
202 | } | |
bb81a09e AM |
203 | #endif |
204 | ||
05a4a952 | 205 | #ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF |
4eec42f3 | 206 | u64 hw_nmi_get_sample_period(int watchdog_thresh); |
b17aa959 | 207 | bool arch_perf_nmi_is_available(void); |
05a4a952 NP |
208 | #endif |
209 | ||
7edaeb68 | 210 | #if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \ |
5e008df1 | 211 | defined(CONFIG_HARDLOCKUP_DETECTOR_PERF) |
7edaeb68 TG |
212 | void watchdog_update_hrtimer_threshold(u64 period); |
213 | #else | |
214 | static inline void watchdog_update_hrtimer_threshold(u64 period) { } | |
215 | #endif | |
216 | ||
44a69f61 TN |
217 | #ifdef CONFIG_HAVE_ACPI_APEI_NMI |
218 | #include <asm/nmi.h> | |
219 | #endif | |
220 | ||
344da544 PM |
221 | #ifdef CONFIG_NMI_CHECK_CPU |
222 | void nmi_backtrace_stall_snap(const struct cpumask *btp); | |
223 | void nmi_backtrace_stall_check(const struct cpumask *btp); | |
224 | #else | |
225 | static inline void nmi_backtrace_stall_snap(const struct cpumask *btp) {} | |
226 | static inline void nmi_backtrace_stall_check(const struct cpumask *btp) {} | |
227 | #endif | |
228 | ||
1da177e4 | 229 | #endif |