1
2
3
4
5#ifndef LINUX_NMI_H
6#define LINUX_NMI_H
7
8#include <linux/sched.h>
9#include <asm/irq.h>
10#if defined(CONFIG_HAVE_NMI_WATCHDOG)
11#include <asm/nmi.h>
12#endif
13
14#ifdef CONFIG_LOCKUP_DETECTOR
15void lockup_detector_init(void);
16void lockup_detector_soft_poweroff(void);
17void lockup_detector_cleanup(void);
18bool is_hardlockup(void);
19
20extern int watchdog_user_enabled;
21extern int nmi_watchdog_user_enabled;
22extern int soft_watchdog_user_enabled;
23extern int watchdog_thresh;
24extern unsigned long watchdog_enabled;
25
26extern struct cpumask watchdog_cpumask;
27extern unsigned long *watchdog_cpumask_bits;
28#ifdef CONFIG_SMP
29extern int sysctl_softlockup_all_cpu_backtrace;
30extern int sysctl_hardlockup_all_cpu_backtrace;
31#else
32#define sysctl_softlockup_all_cpu_backtrace 0
33#define sysctl_hardlockup_all_cpu_backtrace 0
34#endif
35
36#else
37static inline void lockup_detector_init(void) { }
38static inline void lockup_detector_soft_poweroff(void) { }
39static inline void lockup_detector_cleanup(void) { }
40#endif
41
42#ifdef CONFIG_SOFTLOCKUP_DETECTOR
43extern void touch_softlockup_watchdog_sched(void);
44extern void touch_softlockup_watchdog(void);
45extern void touch_softlockup_watchdog_sync(void);
46extern void touch_all_softlockup_watchdogs(void);
47extern unsigned int softlockup_panic;
48
49extern int lockup_detector_online_cpu(unsigned int cpu);
50extern int lockup_detector_offline_cpu(unsigned int cpu);
51#else
52static inline void touch_softlockup_watchdog_sched(void) { }
53static inline void touch_softlockup_watchdog(void) { }
54static inline void touch_softlockup_watchdog_sync(void) { }
55static inline void touch_all_softlockup_watchdogs(void) { }
56
57#define lockup_detector_online_cpu NULL
58#define lockup_detector_offline_cpu NULL
59#endif
60
61#ifdef CONFIG_DETECT_HUNG_TASK
62void reset_hung_task_detector(void);
63#else
64static inline void reset_hung_task_detector(void) { }
65#endif
66
67
68
69
70
71
72
73
74
75
76
77
78
79#define NMI_WATCHDOG_ENABLED_BIT 0
80#define SOFT_WATCHDOG_ENABLED_BIT 1
81#define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT)
82#define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT)
83
84#if defined(CONFIG_HARDLOCKUP_DETECTOR)
85extern void hardlockup_detector_disable(void);
86extern unsigned int hardlockup_panic;
87#else
88static inline void hardlockup_detector_disable(void) {}
89#endif
90
91#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
92# define NMI_WATCHDOG_SYSCTL_PERM 0644
93#else
94# define NMI_WATCHDOG_SYSCTL_PERM 0444
95#endif
96
97#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
98extern void arch_touch_nmi_watchdog(void);
99extern void hardlockup_detector_perf_stop(void);
100extern void hardlockup_detector_perf_restart(void);
101extern void hardlockup_detector_perf_disable(void);
102extern void hardlockup_detector_perf_enable(void);
103extern void hardlockup_detector_perf_cleanup(void);
104extern int hardlockup_detector_perf_init(void);
105#else
106static inline void hardlockup_detector_perf_stop(void) { }
107static inline void hardlockup_detector_perf_restart(void) { }
108static inline void hardlockup_detector_perf_disable(void) { }
109static inline void hardlockup_detector_perf_enable(void) { }
110static inline void hardlockup_detector_perf_cleanup(void) { }
111# if !defined(CONFIG_HAVE_NMI_WATCHDOG)
112static inline int hardlockup_detector_perf_init(void) { return -ENODEV; }
113static inline void arch_touch_nmi_watchdog(void) {}
114# else
115static inline int hardlockup_detector_perf_init(void) { return 0; }
116# endif
117#endif
118
119void watchdog_nmi_stop(void);
120void watchdog_nmi_start(void);
121int watchdog_nmi_probe(void);
122
123
124
125
126
127
128
129
130static inline void touch_nmi_watchdog(void)
131{
132 arch_touch_nmi_watchdog();
133 touch_softlockup_watchdog();
134}
135
136
137
138
139
140
141#ifdef arch_trigger_cpumask_backtrace
142static inline bool trigger_all_cpu_backtrace(void)
143{
144 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
145 return true;
146}
147
148static inline bool trigger_allbutself_cpu_backtrace(void)
149{
150 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
151 return true;
152}
153
154static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
155{
156 arch_trigger_cpumask_backtrace(mask, false);
157 return true;
158}
159
160static inline bool trigger_single_cpu_backtrace(int cpu)
161{
162 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
163 return true;
164}
165
166
167void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
168 bool exclude_self,
169 void (*raise)(cpumask_t *mask));
170bool nmi_cpu_backtrace(struct pt_regs *regs);
171
172#else
173static inline bool trigger_all_cpu_backtrace(void)
174{
175 return false;
176}
177static inline bool trigger_allbutself_cpu_backtrace(void)
178{
179 return false;
180}
181static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
182{
183 return false;
184}
185static inline bool trigger_single_cpu_backtrace(int cpu)
186{
187 return false;
188}
189#endif
190
191#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
192u64 hw_nmi_get_sample_period(int watchdog_thresh);
193#endif
194
195#if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
196 defined(CONFIG_HARDLOCKUP_DETECTOR)
197void watchdog_update_hrtimer_threshold(u64 period);
198#else
199static inline void watchdog_update_hrtimer_threshold(u64 period) { }
200#endif
201
202struct ctl_table;
203extern int proc_watchdog(struct ctl_table *, int ,
204 void __user *, size_t *, loff_t *);
205extern int proc_nmi_watchdog(struct ctl_table *, int ,
206 void __user *, size_t *, loff_t *);
207extern int proc_soft_watchdog(struct ctl_table *, int ,
208 void __user *, size_t *, loff_t *);
209extern int proc_watchdog_thresh(struct ctl_table *, int ,
210 void __user *, size_t *, loff_t *);
211extern int proc_watchdog_cpumask(struct ctl_table *, int,
212 void __user *, size_t *, loff_t *);
213
214#ifdef CONFIG_HAVE_ACPI_APEI_NMI
215#include <asm/nmi.h>
216#endif
217
218#endif
219