nmi.h 6.7 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
L
Linus Torvalds 已提交
2 3 4 5 6 7
/*
 *  linux/include/linux/nmi.h
 */
#ifndef LINUX_NMI_H
#define LINUX_NMI_H

8
#include <linux/sched.h>
L
Linus Torvalds 已提交
9
#include <asm/irq.h>
10 11 12
#if defined(CONFIG_HAVE_NMI_WATCHDOG)
#include <asm/nmi.h>
#endif
L
Linus Torvalds 已提交
13

14
#ifdef CONFIG_LOCKUP_DETECTOR
15
void lockup_detector_init(void);
16
void lockup_detector_soft_poweroff(void);
17
void lockup_detector_cleanup(void);
18 19 20
bool is_hardlockup(void);

extern int watchdog_user_enabled;
21 22
extern int nmi_watchdog_user_enabled;
extern int soft_watchdog_user_enabled;
23 24 25 26 27 28 29 30
extern int watchdog_thresh;
extern unsigned long watchdog_enabled;

extern struct cpumask watchdog_cpumask;
extern unsigned long *watchdog_cpumask_bits;
#ifdef CONFIG_SMP
extern int sysctl_softlockup_all_cpu_backtrace;
extern int sysctl_hardlockup_all_cpu_backtrace;
31
#else
32 33 34 35 36
#define sysctl_softlockup_all_cpu_backtrace 0
#define sysctl_hardlockup_all_cpu_backtrace 0
#endif /* !CONFIG_SMP */

#else /* CONFIG_LOCKUP_DETECTOR */
37 38
static inline void lockup_detector_init(void) { }
static inline void lockup_detector_soft_poweroff(void) { }
39
static inline void lockup_detector_cleanup(void) { }
40
#endif /* !CONFIG_LOCKUP_DETECTOR */
41 42

#ifdef CONFIG_SOFTLOCKUP_DETECTOR
43 44 45 46 47
extern void touch_softlockup_watchdog_sched(void);
extern void touch_softlockup_watchdog(void);
extern void touch_softlockup_watchdog_sync(void);
extern void touch_all_softlockup_watchdogs(void);
extern unsigned int  softlockup_panic;
48 49 50 51

extern int lockup_detector_online_cpu(unsigned int cpu);
extern int lockup_detector_offline_cpu(unsigned int cpu);
#else /* CONFIG_SOFTLOCKUP_DETECTOR */
52 53 54 55
static inline void touch_softlockup_watchdog_sched(void) { }
static inline void touch_softlockup_watchdog(void) { }
static inline void touch_softlockup_watchdog_sync(void) { }
static inline void touch_all_softlockup_watchdogs(void) { }
56 57 58 59

#define lockup_detector_online_cpu	NULL
#define lockup_detector_offline_cpu	NULL
#endif /* CONFIG_SOFTLOCKUP_DETECTOR */
60 61 62 63

#ifdef CONFIG_DETECT_HUNG_TASK
void reset_hung_task_detector(void);
#else
64
static inline void reset_hung_task_detector(void) { }
65 66
#endif

67 68 69 70 71
/*
 * The run state of the lockup detectors is controlled by the content of the
 * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit -
 * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector.
 *
72 73 74 75 76 77
 * 'watchdog_user_enabled', 'nmi_watchdog_user_enabled' and
 * 'soft_watchdog_user_enabled' are variables that are only used as an
 * 'interface' between the parameters in /proc/sys/kernel and the internal
 * state bits in 'watchdog_enabled'. The 'watchdog_thresh' variable is
 * handled differently because its value is not boolean, and the lockup
 * detectors are 'suspended' while 'watchdog_thresh' is equal zero.
78 79 80 81 82 83
 */
#define NMI_WATCHDOG_ENABLED_BIT   0
#define SOFT_WATCHDOG_ENABLED_BIT  1
#define NMI_WATCHDOG_ENABLED      (1 << NMI_WATCHDOG_ENABLED_BIT)
#define SOFT_WATCHDOG_ENABLED     (1 << SOFT_WATCHDOG_ENABLED_BIT)

84 85
#if defined(CONFIG_HARDLOCKUP_DETECTOR)
extern void hardlockup_detector_disable(void);
86
extern unsigned int hardlockup_panic;
87 88 89 90
#else
static inline void hardlockup_detector_disable(void) {}
#endif

91 92 93 94 95 96
#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
# define NMI_WATCHDOG_SYSCTL_PERM	0644
#else
# define NMI_WATCHDOG_SYSCTL_PERM	0444
#endif

97
#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
98
extern void arch_touch_nmi_watchdog(void);
99 100
extern void hardlockup_detector_perf_stop(void);
extern void hardlockup_detector_perf_restart(void);
101
extern void hardlockup_detector_perf_disable(void);
102
extern void hardlockup_detector_perf_enable(void);
103
extern void hardlockup_detector_perf_cleanup(void);
104
extern int hardlockup_detector_perf_init(void);
105
#else
106 107
static inline void hardlockup_detector_perf_stop(void) { }
static inline void hardlockup_detector_perf_restart(void) { }
108
static inline void hardlockup_detector_perf_disable(void) { }
109
static inline void hardlockup_detector_perf_enable(void) { }
110
static inline void hardlockup_detector_perf_cleanup(void) { }
111 112
# if !defined(CONFIG_HAVE_NMI_WATCHDOG)
static inline int hardlockup_detector_perf_init(void) { return -ENODEV; }
113
static inline void arch_touch_nmi_watchdog(void) {}
114 115 116
# else
static inline int hardlockup_detector_perf_init(void) { return 0; }
# endif
117
#endif
118

119 120
void watchdog_nmi_stop(void);
void watchdog_nmi_start(void);
121
int watchdog_nmi_probe(void);
122

L
Linus Torvalds 已提交
123 124
/**
 * touch_nmi_watchdog - restart NMI watchdog timeout.
125
 *
L
Linus Torvalds 已提交
126 127 128 129
 * If the architecture supports the NMI watchdog, touch_nmi_watchdog()
 * may be used to reset the timeout - for code which intentionally
 * disables interrupts for a long time. This call is stateless.
 */
130 131
static inline void touch_nmi_watchdog(void)
{
132
	arch_touch_nmi_watchdog();
133 134
	touch_softlockup_watchdog();
}
135

136 137 138 139 140
/*
 * Create trigger_all_cpu_backtrace() out of the arch-provided
 * base function. Return whether such support was available,
 * to allow calling code to fall back to some other mechanism:
 */
141
#ifdef arch_trigger_cpumask_backtrace
142 143
static inline bool trigger_all_cpu_backtrace(void)
{
144
	arch_trigger_cpumask_backtrace(cpu_online_mask, false);
145 146
	return true;
}
147

148 149
static inline bool trigger_allbutself_cpu_backtrace(void)
{
150 151 152 153 154 155 156 157 158 159 160 161 162
	arch_trigger_cpumask_backtrace(cpu_online_mask, true);
	return true;
}

static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
{
	arch_trigger_cpumask_backtrace(mask, false);
	return true;
}

static inline bool trigger_single_cpu_backtrace(int cpu)
{
	arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
163 164
	return true;
}
165 166

/* generic implementation */
167 168
void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
				   bool exclude_self,
169 170 171
				   void (*raise)(cpumask_t *mask));
bool nmi_cpu_backtrace(struct pt_regs *regs);

172 173 174 175 176
#else
static inline bool trigger_all_cpu_backtrace(void)
{
	return false;
}
177 178 179 180
static inline bool trigger_allbutself_cpu_backtrace(void)
{
	return false;
}
181 182 183 184 185 186 187 188
static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
{
	return false;
}
static inline bool trigger_single_cpu_backtrace(int cpu)
{
	return false;
}
A
Andrew Morton 已提交
189 190
#endif

191
#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
192
u64 hw_nmi_get_sample_period(int watchdog_thresh);
193 194
#endif

195 196 197 198 199 200 201
#if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
    defined(CONFIG_HARDLOCKUP_DETECTOR)
void watchdog_update_hrtimer_threshold(u64 period);
#else
static inline void watchdog_update_hrtimer_threshold(u64 period) { }
#endif

202
struct ctl_table;
203 204 205 206 207 208 209 210
extern int proc_watchdog(struct ctl_table *, int ,
			 void __user *, size_t *, loff_t *);
extern int proc_nmi_watchdog(struct ctl_table *, int ,
			     void __user *, size_t *, loff_t *);
extern int proc_soft_watchdog(struct ctl_table *, int ,
			      void __user *, size_t *, loff_t *);
extern int proc_watchdog_thresh(struct ctl_table *, int ,
				void __user *, size_t *, loff_t *);
211 212
extern int proc_watchdog_cpumask(struct ctl_table *, int,
				 void __user *, size_t *, loff_t *);
213

214 215 216 217
#ifdef CONFIG_HAVE_ACPI_APEI_NMI
#include <asm/nmi.h>
#endif

L
Linus Torvalds 已提交
218
#endif