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