1 /* SPDX-License-Identifier: GPL-2.0 */
3 * linux/include/linux/nmi.h
8 #include <linux/sched.h>
10 #if defined(CONFIG_HAVE_NMI_WATCHDOG)
14 #ifdef CONFIG_LOCKUP_DETECTOR
15 void lockup_detector_init(void);
16 void lockup_detector_soft_poweroff(void);
17 void lockup_detector_cleanup(void);
19 extern int watchdog_user_enabled;
20 extern int watchdog_thresh;
21 extern unsigned long watchdog_enabled;
23 extern struct cpumask watchdog_cpumask;
24 extern unsigned long *watchdog_cpumask_bits;
26 extern int sysctl_softlockup_all_cpu_backtrace;
27 extern int sysctl_hardlockup_all_cpu_backtrace;
29 #define sysctl_softlockup_all_cpu_backtrace 0
30 #define sysctl_hardlockup_all_cpu_backtrace 0
31 #endif /* !CONFIG_SMP */
33 #else /* CONFIG_LOCKUP_DETECTOR */
34 static inline void lockup_detector_init(void) { }
35 static inline void lockup_detector_soft_poweroff(void) { }
36 static inline void lockup_detector_cleanup(void) { }
37 #endif /* !CONFIG_LOCKUP_DETECTOR */
39 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
40 extern void touch_softlockup_watchdog_sched(void);
41 extern void touch_softlockup_watchdog(void);
42 extern void touch_softlockup_watchdog_sync(void);
43 extern void touch_all_softlockup_watchdogs(void);
44 extern unsigned int softlockup_panic;
46 extern int lockup_detector_online_cpu(unsigned int cpu);
47 extern int lockup_detector_offline_cpu(unsigned int cpu);
48 #else /* CONFIG_SOFTLOCKUP_DETECTOR */
49 static inline void touch_softlockup_watchdog_sched(void) { }
50 static inline void touch_softlockup_watchdog(void) { }
51 static inline void touch_softlockup_watchdog_sync(void) { }
52 static inline void touch_all_softlockup_watchdogs(void) { }
54 #define lockup_detector_online_cpu NULL
55 #define lockup_detector_offline_cpu NULL
56 #endif /* CONFIG_SOFTLOCKUP_DETECTOR */
58 #ifdef CONFIG_DETECT_HUNG_TASK
59 void reset_hung_task_detector(void);
61 static inline void reset_hung_task_detector(void) { }
65 * The run state of the lockup detectors is controlled by the content of the
66 * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit -
67 * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector.
69 * 'watchdog_user_enabled', 'watchdog_hardlockup_user_enabled' and
70 * 'watchdog_softlockup_user_enabled' are variables that are only used as an
71 * 'interface' between the parameters in /proc/sys/kernel and the internal
72 * state bits in 'watchdog_enabled'. The 'watchdog_thresh' variable is
73 * handled differently because its value is not boolean, and the lockup
74 * detectors are 'suspended' while 'watchdog_thresh' is equal zero.
76 #define WATCHDOG_HARDLOCKUP_ENABLED_BIT 0
77 #define WATCHDOG_SOFTOCKUP_ENABLED_BIT 1
78 #define WATCHDOG_HARDLOCKUP_ENABLED (1 << WATCHDOG_HARDLOCKUP_ENABLED_BIT)
79 #define WATCHDOG_SOFTOCKUP_ENABLED (1 << WATCHDOG_SOFTOCKUP_ENABLED_BIT)
81 #if defined(CONFIG_HARDLOCKUP_DETECTOR)
82 extern void hardlockup_detector_disable(void);
83 extern unsigned int hardlockup_panic;
85 static inline void hardlockup_detector_disable(void) {}
88 #if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
89 void arch_touch_nmi_watchdog(void);
90 void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs);
91 #elif !defined(CONFIG_HAVE_NMI_WATCHDOG)
92 static inline void arch_touch_nmi_watchdog(void) { }
95 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
96 # define NMI_WATCHDOG_SYSCTL_PERM 0644
98 # define NMI_WATCHDOG_SYSCTL_PERM 0444
101 #if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
102 extern void hardlockup_detector_perf_stop(void);
103 extern void hardlockup_detector_perf_restart(void);
104 extern void hardlockup_detector_perf_disable(void);
105 extern void hardlockup_detector_perf_enable(void);
106 extern void hardlockup_detector_perf_cleanup(void);
107 extern int hardlockup_detector_perf_init(void);
109 static inline void hardlockup_detector_perf_stop(void) { }
110 static inline void hardlockup_detector_perf_restart(void) { }
111 static inline void hardlockup_detector_perf_disable(void) { }
112 static inline void hardlockup_detector_perf_enable(void) { }
113 static inline void hardlockup_detector_perf_cleanup(void) { }
114 # if !defined(CONFIG_HAVE_NMI_WATCHDOG)
115 static inline int hardlockup_detector_perf_init(void) { return -ENODEV; }
117 static inline int hardlockup_detector_perf_init(void) { return 0; }
121 void watchdog_hardlockup_stop(void);
122 void watchdog_hardlockup_start(void);
123 int watchdog_hardlockup_probe(void);
124 void watchdog_hardlockup_enable(unsigned int cpu);
125 void watchdog_hardlockup_disable(unsigned int cpu);
127 void lockup_detector_reconfigure(void);
130 * touch_nmi_watchdog - manually reset the hardlockup watchdog timeout.
132 * If we support detecting hardlockups, touch_nmi_watchdog() may be
133 * used to pet the watchdog (reset the timeout) - for code which
134 * intentionally disables interrupts for a long time. This call is stateless.
136 * Though this function has "nmi" in the name, the hardlockup watchdog might
137 * not be backed by NMIs. This function will likely be renamed to
138 * touch_hardlockup_watchdog() in the future.
140 static inline void touch_nmi_watchdog(void)
143 * Pass on to the hardlockup detector selected via CONFIG_. Note that
144 * the hardlockup detector may not be arch-specific nor using NMIs
145 * and the arch_touch_nmi_watchdog() function will likely be renamed
148 arch_touch_nmi_watchdog();
151 * Touching the hardlock detector implicitly resets the
152 * softlockup detector too
154 touch_softlockup_watchdog();
158 * Create trigger_all_cpu_backtrace() out of the arch-provided
159 * base function. Return whether such support was available,
160 * to allow calling code to fall back to some other mechanism:
162 #ifdef arch_trigger_cpumask_backtrace
163 static inline bool trigger_all_cpu_backtrace(void)
165 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
169 static inline bool trigger_allbutself_cpu_backtrace(void)
171 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
175 static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
177 arch_trigger_cpumask_backtrace(mask, false);
181 static inline bool trigger_single_cpu_backtrace(int cpu)
183 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
187 /* generic implementation */
188 void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
190 void (*raise)(cpumask_t *mask));
191 bool nmi_cpu_backtrace(struct pt_regs *regs);
194 static inline bool trigger_all_cpu_backtrace(void)
198 static inline bool trigger_allbutself_cpu_backtrace(void)
202 static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
206 static inline bool trigger_single_cpu_backtrace(int cpu)
212 #ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
213 u64 hw_nmi_get_sample_period(int watchdog_thresh);
216 #if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
217 defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
218 void watchdog_update_hrtimer_threshold(u64 period);
220 static inline void watchdog_update_hrtimer_threshold(u64 period) { }
224 int proc_watchdog(struct ctl_table *, int, void *, size_t *, loff_t *);
225 int proc_nmi_watchdog(struct ctl_table *, int , void *, size_t *, loff_t *);
226 int proc_soft_watchdog(struct ctl_table *, int , void *, size_t *, loff_t *);
227 int proc_watchdog_thresh(struct ctl_table *, int , void *, size_t *, loff_t *);
228 int proc_watchdog_cpumask(struct ctl_table *, int, void *, size_t *, loff_t *);
230 #ifdef CONFIG_HAVE_ACPI_APEI_NMI
234 #ifdef CONFIG_NMI_CHECK_CPU
235 void nmi_backtrace_stall_snap(const struct cpumask *btp);
236 void nmi_backtrace_stall_check(const struct cpumask *btp);
238 static inline void nmi_backtrace_stall_snap(const struct cpumask *btp) {}
239 static inline void nmi_backtrace_stall_check(const struct cpumask *btp) {}