nmi.h 7.0 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
#if defined(CONFIG_HAVE_NMI_WATCHDOG) && !defined(CONFIG_SDEI_WATCHDOG)
11 12
#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 void watchdog_hardlockup_check(struct pt_regs *regs);
87
extern unsigned int hardlockup_panic;
88 89 90 91
#else
static inline void hardlockup_detector_disable(void) {}
#endif

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

98 99
#if defined(CONFIG_HARDLOCKUP_DETECTOR)
#ifndef CONFIG_PPC
100
extern void arch_touch_nmi_watchdog(void);
101 102 103 104 105 106 107 108
#endif
#else
# if !defined(CONFIG_HAVE_NMI_WATCHDOG)
static inline void arch_touch_nmi_watchdog(void) {}
# endif
#endif

#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
109 110
extern void hardlockup_detector_perf_stop(void);
extern void hardlockup_detector_perf_restart(void);
111
extern void hardlockup_detector_perf_disable(void);
112
extern void hardlockup_detector_perf_enable(void);
113
extern void hardlockup_detector_perf_cleanup(void);
114
extern int hardlockup_detector_perf_init(void);
115
#else
116 117
static inline void hardlockup_detector_perf_stop(void) { }
static inline void hardlockup_detector_perf_restart(void) { }
118
static inline void hardlockup_detector_perf_disable(void) { }
119
static inline void hardlockup_detector_perf_enable(void) { }
120
static inline void hardlockup_detector_perf_cleanup(void) { }
121 122 123 124 125
# if !defined(CONFIG_HAVE_NMI_WATCHDOG)
static inline int hardlockup_detector_perf_init(void) { return -ENODEV; }
# else
static inline int hardlockup_detector_perf_init(void) { return 0; }
# endif
126
#endif
127

128 129
void watchdog_nmi_stop(void);
void watchdog_nmi_start(void);
130
int watchdog_nmi_probe(void);
131 132
int watchdog_nmi_enable(unsigned int cpu);
void watchdog_nmi_disable(unsigned int cpu);
133

L
Linus Torvalds 已提交
134 135
/**
 * touch_nmi_watchdog - restart NMI watchdog timeout.
136
 *
L
Linus Torvalds 已提交
137 138 139 140
 * 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.
 */
141 142
static inline void touch_nmi_watchdog(void)
{
143
	arch_touch_nmi_watchdog();
144 145
	touch_softlockup_watchdog();
}
146

147 148 149 150 151
/*
 * 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:
 */
152
#ifdef arch_trigger_cpumask_backtrace
153 154
static inline bool trigger_all_cpu_backtrace(void)
{
155
	arch_trigger_cpumask_backtrace(cpu_online_mask, false);
156 157
	return true;
}
158

159 160
static inline bool trigger_allbutself_cpu_backtrace(void)
{
161 162 163 164 165 166 167 168 169 170 171 172 173
	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);
174 175
	return true;
}
176 177

/* generic implementation */
178 179
void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
				   bool exclude_self,
180 181 182
				   void (*raise)(cpumask_t *mask));
bool nmi_cpu_backtrace(struct pt_regs *regs);

183 184 185 186 187
#else
static inline bool trigger_all_cpu_backtrace(void)
{
	return false;
}
188 189 190 191
static inline bool trigger_allbutself_cpu_backtrace(void)
{
	return false;
}
192 193 194 195 196 197 198 199
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 已提交
200 201
#endif

202
#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
203
u64 hw_nmi_get_sample_period(int watchdog_thresh);
204 205
#endif

206 207 208
#if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
    defined(CONFIG_HARDLOCKUP_DETECTOR)
void watchdog_update_hrtimer_threshold(u64 period);
209
void refresh_hld_last_timestamp(void);
210 211 212 213
#else
static inline void watchdog_update_hrtimer_threshold(u64 period) { }
#endif

214
struct ctl_table;
215 216 217 218 219
int proc_watchdog(struct ctl_table *, int, void *, size_t *, loff_t *);
int proc_nmi_watchdog(struct ctl_table *, int , void *, size_t *, loff_t *);
int proc_soft_watchdog(struct ctl_table *, int , void *, size_t *, loff_t *);
int proc_watchdog_thresh(struct ctl_table *, int , void *, size_t *, loff_t *);
int proc_watchdog_cpumask(struct ctl_table *, int, void *, size_t *, loff_t *);
220

221 222 223 224
#ifdef CONFIG_HAVE_ACPI_APEI_NMI
#include <asm/nmi.h>
#endif

L
Linus Torvalds 已提交
225
#endif