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