]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/nmi.h
watchdog/core, powerpc: Make watchdog_nmi_reconfigure() two stage
[mirror_ubuntu-bionic-kernel.git] / include / linux / nmi.h
1 /*
2 * linux/include/linux/nmi.h
3 */
4 #ifndef LINUX_NMI_H
5 #define LINUX_NMI_H
6
7 #include <linux/sched.h>
8 #include <asm/irq.h>
9 #if defined(CONFIG_HAVE_NMI_WATCHDOG)
10 #include <asm/nmi.h>
11 #endif
12
13 #ifdef CONFIG_LOCKUP_DETECTOR
14 void lockup_detector_init(void);
15 void lockup_detector_soft_poweroff(void);
16 void lockup_detector_cleanup(void);
17 bool is_hardlockup(void);
18
19 extern int watchdog_user_enabled;
20 extern int nmi_watchdog_user_enabled;
21 extern int soft_watchdog_user_enabled;
22 extern int watchdog_thresh;
23 extern unsigned long watchdog_enabled;
24
25 extern struct cpumask watchdog_cpumask;
26 extern unsigned long *watchdog_cpumask_bits;
27 #ifdef CONFIG_SMP
28 extern int sysctl_softlockup_all_cpu_backtrace;
29 extern 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 */
36 static inline void lockup_detector_init(void) { }
37 static inline void lockup_detector_soft_poweroff(void) { }
38 static inline void lockup_detector_cleanup(void) { }
39 #endif /* !CONFIG_LOCKUP_DETECTOR */
40
41 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
42 extern void touch_softlockup_watchdog_sched(void);
43 extern void touch_softlockup_watchdog(void);
44 extern void touch_softlockup_watchdog_sync(void);
45 extern void touch_all_softlockup_watchdogs(void);
46 extern unsigned int softlockup_panic;
47 #else
48 static inline void touch_softlockup_watchdog_sched(void) { }
49 static inline void touch_softlockup_watchdog(void) { }
50 static inline void touch_softlockup_watchdog_sync(void) { }
51 static inline void touch_all_softlockup_watchdogs(void) { }
52 #endif
53
54 #ifdef CONFIG_DETECT_HUNG_TASK
55 void reset_hung_task_detector(void);
56 #else
57 static inline void reset_hung_task_detector(void) { }
58 #endif
59
60 /*
61 * The run state of the lockup detectors is controlled by the content of the
62 * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit -
63 * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector.
64 *
65 * 'watchdog_user_enabled', 'nmi_watchdog_user_enabled' and
66 * 'soft_watchdog_user_enabled' are variables that are only used as an
67 * 'interface' between the parameters in /proc/sys/kernel and the internal
68 * state bits in 'watchdog_enabled'. The 'watchdog_thresh' variable is
69 * handled differently because its value is not boolean, and the lockup
70 * detectors are 'suspended' while 'watchdog_thresh' is equal zero.
71 */
72 #define NMI_WATCHDOG_ENABLED_BIT 0
73 #define SOFT_WATCHDOG_ENABLED_BIT 1
74 #define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT)
75 #define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT)
76
77 #if defined(CONFIG_HARDLOCKUP_DETECTOR)
78 extern void hardlockup_detector_disable(void);
79 extern unsigned int hardlockup_panic;
80 #else
81 static inline void hardlockup_detector_disable(void) {}
82 #endif
83
84 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
85 # define NMI_WATCHDOG_SYSCTL_PERM 0644
86 #else
87 # define NMI_WATCHDOG_SYSCTL_PERM 0444
88 #endif
89
90 #if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
91 extern void arch_touch_nmi_watchdog(void);
92 extern void hardlockup_detector_perf_stop(void);
93 extern void hardlockup_detector_perf_restart(void);
94 extern void hardlockup_detector_perf_disable(void);
95 extern void hardlockup_detector_perf_cleanup(void);
96 #else
97 static inline void hardlockup_detector_perf_stop(void) { }
98 static inline void hardlockup_detector_perf_restart(void) { }
99 static inline void hardlockup_detector_perf_disable(void) { }
100 static inline void hardlockup_detector_perf_cleanup(void) { }
101 #if !defined(CONFIG_HAVE_NMI_WATCHDOG)
102 static inline void arch_touch_nmi_watchdog(void) {}
103 #endif
104 #endif
105
106 void watchdog_nmi_reconfigure(bool run);
107
108 /**
109 * touch_nmi_watchdog - restart NMI watchdog timeout.
110 *
111 * If the architecture supports the NMI watchdog, touch_nmi_watchdog()
112 * may be used to reset the timeout - for code which intentionally
113 * disables interrupts for a long time. This call is stateless.
114 */
115 static inline void touch_nmi_watchdog(void)
116 {
117 arch_touch_nmi_watchdog();
118 touch_softlockup_watchdog();
119 }
120
121 /*
122 * Create trigger_all_cpu_backtrace() out of the arch-provided
123 * base function. Return whether such support was available,
124 * to allow calling code to fall back to some other mechanism:
125 */
126 #ifdef arch_trigger_cpumask_backtrace
127 static inline bool trigger_all_cpu_backtrace(void)
128 {
129 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
130 return true;
131 }
132
133 static inline bool trigger_allbutself_cpu_backtrace(void)
134 {
135 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
136 return true;
137 }
138
139 static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
140 {
141 arch_trigger_cpumask_backtrace(mask, false);
142 return true;
143 }
144
145 static inline bool trigger_single_cpu_backtrace(int cpu)
146 {
147 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
148 return true;
149 }
150
151 /* generic implementation */
152 void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
153 bool exclude_self,
154 void (*raise)(cpumask_t *mask));
155 bool nmi_cpu_backtrace(struct pt_regs *regs);
156
157 #else
158 static inline bool trigger_all_cpu_backtrace(void)
159 {
160 return false;
161 }
162 static inline bool trigger_allbutself_cpu_backtrace(void)
163 {
164 return false;
165 }
166 static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
167 {
168 return false;
169 }
170 static inline bool trigger_single_cpu_backtrace(int cpu)
171 {
172 return false;
173 }
174 #endif
175
176 #ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
177 u64 hw_nmi_get_sample_period(int watchdog_thresh);
178 #endif
179
180 #if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
181 defined(CONFIG_HARDLOCKUP_DETECTOR)
182 void watchdog_update_hrtimer_threshold(u64 period);
183 #else
184 static inline void watchdog_update_hrtimer_threshold(u64 period) { }
185 #endif
186
187 struct ctl_table;
188 extern int proc_watchdog(struct ctl_table *, int ,
189 void __user *, size_t *, loff_t *);
190 extern int proc_nmi_watchdog(struct ctl_table *, int ,
191 void __user *, size_t *, loff_t *);
192 extern int proc_soft_watchdog(struct ctl_table *, int ,
193 void __user *, size_t *, loff_t *);
194 extern int proc_watchdog_thresh(struct ctl_table *, int ,
195 void __user *, size_t *, loff_t *);
196 extern int proc_watchdog_cpumask(struct ctl_table *, int,
197 void __user *, size_t *, loff_t *);
198
199 #ifdef CONFIG_HAVE_ACPI_APEI_NMI
200 #include <asm/nmi.h>
201 #endif
202
203 #endif