watchdog/hardlockup: add a "cpu" param to watchdog_hardlockup_check()
[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
18
19extern int watchdog_user_enabled;
7feeb9cd
TG
20extern int nmi_watchdog_user_enabled;
21extern int soft_watchdog_user_enabled;
3b371b59
TG
22extern int watchdog_thresh;
23extern unsigned long watchdog_enabled;
24
25extern struct cpumask watchdog_cpumask;
26extern unsigned long *watchdog_cpumask_bits;
27#ifdef CONFIG_SMP
28extern int sysctl_softlockup_all_cpu_backtrace;
29extern 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
TG
36static inline void lockup_detector_init(void) { }
37static inline void lockup_detector_soft_poweroff(void) { }
941154bd 38static inline void lockup_detector_cleanup(void) { }
3b371b59 39#endif /* !CONFIG_LOCKUP_DETECTOR */
05a4a952
NP
40
41#ifdef CONFIG_SOFTLOCKUP_DETECTOR
d151b27d
IM
42extern void touch_softlockup_watchdog_sched(void);
43extern void touch_softlockup_watchdog(void);
44extern void touch_softlockup_watchdog_sync(void);
45extern void touch_all_softlockup_watchdogs(void);
d151b27d 46extern unsigned int softlockup_panic;
aef92a8b
PZ
47
48extern int lockup_detector_online_cpu(unsigned int cpu);
49extern int lockup_detector_offline_cpu(unsigned int cpu);
50#else /* CONFIG_SOFTLOCKUP_DETECTOR */
3b371b59
TG
51static inline void touch_softlockup_watchdog_sched(void) { }
52static inline void touch_softlockup_watchdog(void) { }
53static inline void touch_softlockup_watchdog_sync(void) { }
54static 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
61void reset_hung_task_detector(void);
62#else
3b371b59 63static 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 *
7feeb9cd
TG
71 * 'watchdog_user_enabled', 'nmi_watchdog_user_enabled' and
72 * 'soft_watchdog_user_enabled' are variables that are only used as an
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
BM
77 */
78#define NMI_WATCHDOG_ENABLED_BIT 0
79#define SOFT_WATCHDOG_ENABLED_BIT 1
80#define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT)
81#define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT)
82
f2e0cff8
NP
83#if defined(CONFIG_HARDLOCKUP_DETECTOR)
84extern void hardlockup_detector_disable(void);
05a4a952 85extern unsigned int hardlockup_panic;
f2e0cff8
NP
86#else
87static inline void hardlockup_detector_disable(void) {}
88#endif
89
81972551 90#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
77c12fc9 91void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs);
81972551
DA
92#endif
93
51d4052b
TG
94#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
95# define NMI_WATCHDOG_SYSCTL_PERM 0644
96#else
97# define NMI_WATCHDOG_SYSCTL_PERM 0444
98#endif
99
05a4a952 100#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
f2e0cff8 101extern void arch_touch_nmi_watchdog(void);
d0b6e0a8
PZ
102extern void hardlockup_detector_perf_stop(void);
103extern void hardlockup_detector_perf_restart(void);
941154bd 104extern void hardlockup_detector_perf_disable(void);
2a1b8ee4 105extern void hardlockup_detector_perf_enable(void);
941154bd 106extern void hardlockup_detector_perf_cleanup(void);
178b9f7a 107extern int hardlockup_detector_perf_init(void);
f2e0cff8 108#else
d0b6e0a8
PZ
109static inline void hardlockup_detector_perf_stop(void) { }
110static inline void hardlockup_detector_perf_restart(void) { }
941154bd 111static inline void hardlockup_detector_perf_disable(void) { }
2a1b8ee4 112static inline void hardlockup_detector_perf_enable(void) { }
941154bd 113static inline void hardlockup_detector_perf_cleanup(void) { }
178b9f7a
TG
114# if !defined(CONFIG_HAVE_NMI_WATCHDOG)
115static inline int hardlockup_detector_perf_init(void) { return -ENODEV; }
f2e0cff8 116static inline void arch_touch_nmi_watchdog(void) {}
178b9f7a
TG
117# else
118static inline int hardlockup_detector_perf_init(void) { return 0; }
119# endif
05a4a952 120#endif
f2e0cff8 121
6b9dc480
TG
122void watchdog_nmi_stop(void);
123void watchdog_nmi_start(void);
34ddaa3e 124int watchdog_nmi_probe(void);
73021118 125void watchdog_nmi_enable(unsigned int cpu);
81bd415c 126void watchdog_nmi_disable(unsigned int cpu);
6592ad2f 127
7c56a873
LD
128void lockup_detector_reconfigure(void);
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
DA
150
151 /*
152 * Touching the hardlock detector implicitly resets the
153 * softlockup detector too
154 */
5d0e600d
IM
155 touch_softlockup_watchdog();
156}
6e7458a6 157
47cab6a7
IM
158/*
159 * Create trigger_all_cpu_backtrace() out of the arch-provided
160 * base function. Return whether such support was available,
161 * to allow calling code to fall back to some other mechanism:
162 */
9a01c3ed 163#ifdef arch_trigger_cpumask_backtrace
47cab6a7
IM
164static inline bool trigger_all_cpu_backtrace(void)
165{
9a01c3ed 166 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
47cab6a7
IM
167 return true;
168}
9a01c3ed 169
f3aca3d0
AT
170static inline bool trigger_allbutself_cpu_backtrace(void)
171{
9a01c3ed
CM
172 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
173 return true;
174}
175
176static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
177{
178 arch_trigger_cpumask_backtrace(mask, false);
179 return true;
180}
181
182static inline bool trigger_single_cpu_backtrace(int cpu)
183{
184 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
f3aca3d0
AT
185 return true;
186}
b2c0b2cb
RK
187
188/* generic implementation */
9a01c3ed
CM
189void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
190 bool exclude_self,
b2c0b2cb
RK
191 void (*raise)(cpumask_t *mask));
192bool nmi_cpu_backtrace(struct pt_regs *regs);
193
47cab6a7
IM
194#else
195static inline bool trigger_all_cpu_backtrace(void)
196{
197 return false;
198}
f3aca3d0
AT
199static inline bool trigger_allbutself_cpu_backtrace(void)
200{
201 return false;
202}
9a01c3ed
CM
203static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
204{
205 return false;
206}
207static inline bool trigger_single_cpu_backtrace(int cpu)
208{
209 return false;
210}
bb81a09e
AM
211#endif
212
05a4a952 213#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
4eec42f3 214u64 hw_nmi_get_sample_period(int watchdog_thresh);
05a4a952
NP
215#endif
216
7edaeb68 217#if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
5e008df1 218 defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
7edaeb68
TG
219void watchdog_update_hrtimer_threshold(u64 period);
220#else
221static inline void watchdog_update_hrtimer_threshold(u64 period) { }
222#endif
223
504d7cf1 224struct ctl_table;
32927393
CH
225int proc_watchdog(struct ctl_table *, int, void *, size_t *, loff_t *);
226int proc_nmi_watchdog(struct ctl_table *, int , void *, size_t *, loff_t *);
227int proc_soft_watchdog(struct ctl_table *, int , void *, size_t *, loff_t *);
228int proc_watchdog_thresh(struct ctl_table *, int , void *, size_t *, loff_t *);
229int proc_watchdog_cpumask(struct ctl_table *, int, void *, size_t *, loff_t *);
84e478c6 230
44a69f61
TN
231#ifdef CONFIG_HAVE_ACPI_APEI_NMI
232#include <asm/nmi.h>
233#endif
234
344da544
PM
235#ifdef CONFIG_NMI_CHECK_CPU
236void nmi_backtrace_stall_snap(const struct cpumask *btp);
237void nmi_backtrace_stall_check(const struct cpumask *btp);
238#else
239static inline void nmi_backtrace_stall_snap(const struct cpumask *btp) {}
240static inline void nmi_backtrace_stall_check(const struct cpumask *btp) {}
241#endif
242
1da177e4 243#endif