File Index
Files and directories
Sign in
FILE

nmi.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/nmi.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 *  linux/include/linux/nmi.h
  4 */
  5#ifndef LINUX_NMI_H
  6#define LINUX_NMI_H
  7
  8#include <linux/sched.h>
  9#include <asm/irq.h>
 10
 11/* Arch specific watchdogs might need to share extra watchdog-related APIs. */
 12#if defined(CONFIG_HARDLOCKUP_DETECTOR_ARCH) || defined(CONFIG_HARDLOCKUP_DETECTOR_SPARC64)
 13#include <asm/nmi.h>
 14#endif
 15
 16#ifdef CONFIG_LOCKUP_DETECTOR
 17void lockup_detector_init(void);
 18void lockup_detector_retry_init(void);
 19void lockup_detector_soft_poweroff(void);
 20
 21extern int watchdog_user_enabled;
 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;
 30#else
 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 */
 36static inline void lockup_detector_init(void) { }
 37static inline void lockup_detector_retry_init(void) { }
 38static inline void lockup_detector_soft_poweroff(void) { }
 39#endif /* !CONFIG_LOCKUP_DETECTOR */
 40
 41#ifdef CONFIG_SOFTLOCKUP_DETECTOR
 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);
 46extern unsigned int  softlockup_panic;
 47
 48extern int lockup_detector_online_cpu(unsigned int cpu);
 49extern int lockup_detector_offline_cpu(unsigned int cpu);
 50#else /* CONFIG_SOFTLOCKUP_DETECTOR */
 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) { }
 55
 56#define lockup_detector_online_cpu	NULL
 57#define lockup_detector_offline_cpu	NULL
 58#endif /* CONFIG_SOFTLOCKUP_DETECTOR */
 59
 60#ifdef CONFIG_DETECT_HUNG_TASK
 61void reset_hung_task_detector(void);
 62#else
 63static inline void reset_hung_task_detector(void) { }
 64#endif
 65
 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 *
 71 * 'watchdog_user_enabled', 'watchdog_hardlockup_user_enabled' and
 72 * 'watchdog_softlockup_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.
 77 */
 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)
 82
 83#if defined(CONFIG_HARDLOCKUP_DETECTOR)
 84extern void hardlockup_detector_disable(void);
 85extern unsigned int hardlockup_panic;
 86extern unsigned long hardlockup_si_mask;
 87#else
 88static inline void hardlockup_detector_disable(void) {}
 89#endif
 90
 91/* Sparc64 has special implemetantion that is always enabled. */
 92#if defined(CONFIG_HARDLOCKUP_DETECTOR) || defined(CONFIG_HARDLOCKUP_DETECTOR_SPARC64)
 93void arch_touch_nmi_watchdog(void);
 94#else
 95static inline void arch_touch_nmi_watchdog(void) { }
 96#endif
 97
 98#if defined(CONFIG_HARDLOCKUP_DETECTOR_COUNTS_HRTIMER)
 99void watchdog_hardlockup_touch_cpu(unsigned int cpu);
100void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs);
101#endif
102
103#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
104extern void hardlockup_detector_perf_stop(void);
105extern void hardlockup_detector_perf_restart(void);
106extern void hardlockup_config_perf_event(const char *str);
107extern void hardlockup_detector_perf_adjust_period(u64 period);
108#else
109static inline void hardlockup_detector_perf_stop(void) { }
110static inline void hardlockup_detector_perf_restart(void) { }
111static inline void hardlockup_config_perf_event(const char *str) { }
112static inline void hardlockup_detector_perf_adjust_period(u64 period) { }
113#endif
114
115void watchdog_hardlockup_stop(void);
116void watchdog_hardlockup_start(void);
117int watchdog_hardlockup_probe(void);
118void watchdog_hardlockup_enable(unsigned int cpu);
119void watchdog_hardlockup_disable(unsigned int cpu);
120
121void lockup_detector_reconfigure(void);
122
123#ifdef CONFIG_HARDLOCKUP_DETECTOR_BUDDY
124void watchdog_buddy_check_hardlockup(int hrtimer_interrupts);
125#else
126static inline void watchdog_buddy_check_hardlockup(int hrtimer_interrupts) {}
127#endif
128
129/**
130 * touch_nmi_watchdog - manually reset the hardlockup watchdog timeout.
131 *
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.
135 *
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.
139 */
140static inline void touch_nmi_watchdog(void)
141{
142	/*
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
146	 * in the future.
147	 */
148	arch_touch_nmi_watchdog();
149
150	touch_softlockup_watchdog();
151}
152
153/*
154 * Create trigger_all_cpu_backtrace() out of the arch-provided
155 * base function. Return whether such support was available,
156 * to allow calling code to fall back to some other mechanism:
157 */
158#ifdef arch_trigger_cpumask_backtrace
159static inline bool trigger_all_cpu_backtrace(void)
160{
161	arch_trigger_cpumask_backtrace(cpu_online_mask, -1);
162	return true;
163}
164
165static inline bool trigger_allbutcpu_cpu_backtrace(int exclude_cpu)
166{
167	arch_trigger_cpumask_backtrace(cpu_online_mask, exclude_cpu);
168	return true;
169}
170
171static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
172{
173	arch_trigger_cpumask_backtrace(mask, -1);
174	return true;
175}
176
177static inline bool trigger_single_cpu_backtrace(int cpu)
178{
179	arch_trigger_cpumask_backtrace(cpumask_of(cpu), -1);
180	return true;
181}
182
183/* generic implementation */
184void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
185				   int exclude_cpu,
186				   void (*raise)(cpumask_t *mask));
187bool nmi_cpu_backtrace(struct pt_regs *regs);
188
189#else
190static inline bool trigger_all_cpu_backtrace(void)
191{
192	return false;
193}
194static inline bool trigger_allbutcpu_cpu_backtrace(int exclude_cpu)
195{
196	return false;
197}
198static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
199{
200	return false;
201}
202static inline bool trigger_single_cpu_backtrace(int cpu)
203{
204	return false;
205}
206#endif
207
208#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
209u64 hw_nmi_get_sample_period(int watchdog_thresh);
210bool arch_perf_nmi_is_available(void);
211#endif
212
213#if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
214    defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
215void watchdog_update_hrtimer_threshold(u64 period);
216#else
217static inline void watchdog_update_hrtimer_threshold(u64 period) { }
218#endif
219
220#ifdef CONFIG_HAVE_ACPI_APEI_NMI
221#include <asm/nmi.h>
222#endif
223
224#ifdef CONFIG_NMI_CHECK_CPU
225void nmi_backtrace_stall_snap(const struct cpumask *btp);
226void nmi_backtrace_stall_check(const struct cpumask *btp);
227#else
228static inline void nmi_backtrace_stall_snap(const struct cpumask *btp) {}
229static inline void nmi_backtrace_stall_check(const struct cpumask *btp) {}
230#endif
231
232#endif
~/ Read-only file preview.