Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/include/linux/nmi.h |
| 3 | */ |
| 4 | #ifndef LINUX_NMI_H |
| 5 | #define LINUX_NMI_H |
| 6 | |
Michal Schmidt | 9938406 | 2006-09-29 01:59:03 -0700 | [diff] [blame] | 7 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <asm/irq.h> |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 9 | #if defined(CONFIG_HAVE_NMI_WATCHDOG) |
| 10 | #include <asm/nmi.h> |
| 11 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 13 | #ifdef CONFIG_LOCKUP_DETECTOR |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 14 | void lockup_detector_init(void); |
| 15 | #else |
| 16 | static inline void lockup_detector_init(void) |
| 17 | { |
| 18 | } |
| 19 | #endif |
| 20 | |
| 21 | #ifdef CONFIG_SOFTLOCKUP_DETECTOR |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 22 | extern void touch_softlockup_watchdog_sched(void); |
| 23 | extern void touch_softlockup_watchdog(void); |
| 24 | extern void touch_softlockup_watchdog_sync(void); |
| 25 | extern void touch_all_softlockup_watchdogs(void); |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 26 | extern unsigned int softlockup_panic; |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 27 | extern int soft_watchdog_enabled; |
| 28 | extern atomic_t watchdog_park_in_progress; |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 29 | #else |
| 30 | static inline void touch_softlockup_watchdog_sched(void) |
| 31 | { |
| 32 | } |
| 33 | static inline void touch_softlockup_watchdog(void) |
| 34 | { |
| 35 | } |
| 36 | static inline void touch_softlockup_watchdog_sync(void) |
| 37 | { |
| 38 | } |
| 39 | static inline void touch_all_softlockup_watchdogs(void) |
| 40 | { |
| 41 | } |
Ingo Molnar | d151b27 | 2017-02-02 11:17:23 +0100 | [diff] [blame] | 42 | #endif |
| 43 | |
| 44 | #ifdef CONFIG_DETECT_HUNG_TASK |
| 45 | void reset_hung_task_detector(void); |
| 46 | #else |
| 47 | static inline void reset_hung_task_detector(void) |
| 48 | { |
| 49 | } |
| 50 | #endif |
| 51 | |
Babu Moger | 249e52e | 2016-12-14 15:06:21 -0800 | [diff] [blame] | 52 | /* |
| 53 | * The run state of the lockup detectors is controlled by the content of the |
| 54 | * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit - |
| 55 | * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector. |
| 56 | * |
| 57 | * 'watchdog_user_enabled', 'nmi_watchdog_enabled' and 'soft_watchdog_enabled' |
| 58 | * are variables that are only used as an 'interface' between the parameters |
| 59 | * in /proc/sys/kernel and the internal state bits in 'watchdog_enabled'. The |
| 60 | * 'watchdog_thresh' variable is handled differently because its value is not |
| 61 | * boolean, and the lockup detectors are 'suspended' while 'watchdog_thresh' |
| 62 | * is equal zero. |
| 63 | */ |
| 64 | #define NMI_WATCHDOG_ENABLED_BIT 0 |
| 65 | #define SOFT_WATCHDOG_ENABLED_BIT 1 |
| 66 | #define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT) |
| 67 | #define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT) |
| 68 | |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 69 | #if defined(CONFIG_HARDLOCKUP_DETECTOR) |
| 70 | extern void hardlockup_detector_disable(void); |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 71 | extern unsigned int hardlockup_panic; |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 72 | #else |
| 73 | static inline void hardlockup_detector_disable(void) {} |
| 74 | #endif |
| 75 | |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 76 | #if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF) |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 77 | extern void arch_touch_nmi_watchdog(void); |
| 78 | #else |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 79 | #if !defined(CONFIG_HAVE_NMI_WATCHDOG) |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 80 | static inline void arch_touch_nmi_watchdog(void) {} |
| 81 | #endif |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 82 | #endif |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /** |
| 85 | * touch_nmi_watchdog - restart NMI watchdog timeout. |
| 86 | * |
| 87 | * If the architecture supports the NMI watchdog, touch_nmi_watchdog() |
| 88 | * may be used to reset the timeout - for code which intentionally |
| 89 | * disables interrupts for a long time. This call is stateless. |
| 90 | */ |
Ingo Molnar | 5d0e600 | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 91 | static inline void touch_nmi_watchdog(void) |
| 92 | { |
Nicholas Piggin | f2e0cff | 2017-07-12 14:35:43 -0700 | [diff] [blame] | 93 | arch_touch_nmi_watchdog(); |
Ingo Molnar | 5d0e600 | 2007-02-13 13:26:24 +0100 | [diff] [blame] | 94 | touch_softlockup_watchdog(); |
| 95 | } |
Ulrich Obergfell | 6e7458a | 2014-10-13 15:55:35 -0700 | [diff] [blame] | 96 | |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 97 | /* |
| 98 | * Create trigger_all_cpu_backtrace() out of the arch-provided |
| 99 | * base function. Return whether such support was available, |
| 100 | * to allow calling code to fall back to some other mechanism: |
| 101 | */ |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 102 | #ifdef arch_trigger_cpumask_backtrace |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 103 | static inline bool trigger_all_cpu_backtrace(void) |
| 104 | { |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 105 | arch_trigger_cpumask_backtrace(cpu_online_mask, false); |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 106 | return true; |
| 107 | } |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 108 | |
Aaron Tomlin | f3aca3d0 | 2014-06-23 13:22:05 -0700 | [diff] [blame] | 109 | static inline bool trigger_allbutself_cpu_backtrace(void) |
| 110 | { |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 111 | arch_trigger_cpumask_backtrace(cpu_online_mask, true); |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | static inline bool trigger_cpumask_backtrace(struct cpumask *mask) |
| 116 | { |
| 117 | arch_trigger_cpumask_backtrace(mask, false); |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | static inline bool trigger_single_cpu_backtrace(int cpu) |
| 122 | { |
| 123 | arch_trigger_cpumask_backtrace(cpumask_of(cpu), false); |
Aaron Tomlin | f3aca3d0 | 2014-06-23 13:22:05 -0700 | [diff] [blame] | 124 | return true; |
| 125 | } |
Russell King | b2c0b2c | 2014-09-03 23:57:13 +0100 | [diff] [blame] | 126 | |
| 127 | /* generic implementation */ |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 128 | void nmi_trigger_cpumask_backtrace(const cpumask_t *mask, |
| 129 | bool exclude_self, |
Russell King | b2c0b2c | 2014-09-03 23:57:13 +0100 | [diff] [blame] | 130 | void (*raise)(cpumask_t *mask)); |
| 131 | bool nmi_cpu_backtrace(struct pt_regs *regs); |
| 132 | |
Ingo Molnar | 47cab6a | 2009-08-03 09:31:54 +0200 | [diff] [blame] | 133 | #else |
| 134 | static inline bool trigger_all_cpu_backtrace(void) |
| 135 | { |
| 136 | return false; |
| 137 | } |
Aaron Tomlin | f3aca3d0 | 2014-06-23 13:22:05 -0700 | [diff] [blame] | 138 | static inline bool trigger_allbutself_cpu_backtrace(void) |
| 139 | { |
| 140 | return false; |
| 141 | } |
Chris Metcalf | 9a01c3e | 2016-10-07 17:02:45 -0700 | [diff] [blame] | 142 | static inline bool trigger_cpumask_backtrace(struct cpumask *mask) |
| 143 | { |
| 144 | return false; |
| 145 | } |
| 146 | static inline bool trigger_single_cpu_backtrace(int cpu) |
| 147 | { |
| 148 | return false; |
| 149 | } |
Andrew Morton | bb81a09 | 2006-12-07 02:14:01 +0100 | [diff] [blame] | 150 | #endif |
| 151 | |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 152 | #ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF |
Mandeep Singh Baines | 4eec42f | 2011-05-22 22:10:23 -0700 | [diff] [blame] | 153 | u64 hw_nmi_get_sample_period(int watchdog_thresh); |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 154 | #endif |
| 155 | |
| 156 | #ifdef CONFIG_LOCKUP_DETECTOR |
Ulrich Obergfell | 84d56e6 | 2015-04-14 15:43:55 -0700 | [diff] [blame] | 157 | extern int nmi_watchdog_enabled; |
Frederic Weisbecker | 3c00ea8 | 2013-05-19 20:45:15 +0200 | [diff] [blame] | 158 | extern int watchdog_user_enabled; |
Mandeep Singh Baines | 586692a | 2011-05-22 22:10:22 -0700 | [diff] [blame] | 159 | extern int watchdog_thresh; |
Babu Moger | 249e52e | 2016-12-14 15:06:21 -0800 | [diff] [blame] | 160 | extern unsigned long watchdog_enabled; |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 161 | extern struct cpumask watchdog_cpumask; |
Chris Metcalf | fe4ba3c | 2015-06-24 16:55:45 -0700 | [diff] [blame] | 162 | extern unsigned long *watchdog_cpumask_bits; |
Nicholas Piggin | 05a4a95 | 2017-07-12 14:35:46 -0700 | [diff] [blame] | 163 | extern int __read_mostly watchdog_suspended; |
Babu Moger | 249e52e | 2016-12-14 15:06:21 -0800 | [diff] [blame] | 164 | #ifdef CONFIG_SMP |
Aaron Tomlin | ed23587 | 2014-06-23 13:22:05 -0700 | [diff] [blame] | 165 | extern int sysctl_softlockup_all_cpu_backtrace; |
Jiri Kosina | 5553787 | 2015-11-05 18:44:41 -0800 | [diff] [blame] | 166 | extern int sysctl_hardlockup_all_cpu_backtrace; |
Babu Moger | 249e52e | 2016-12-14 15:06:21 -0800 | [diff] [blame] | 167 | #else |
| 168 | #define sysctl_softlockup_all_cpu_backtrace 0 |
| 169 | #define sysctl_hardlockup_all_cpu_backtrace 0 |
| 170 | #endif |
| 171 | extern bool is_hardlockup(void); |
Don Zickus | 504d7cf | 2010-02-12 17:19:19 -0500 | [diff] [blame] | 172 | struct ctl_table; |
Ulrich Obergfell | 83a80a3 | 2015-04-14 15:44:08 -0700 | [diff] [blame] | 173 | extern int proc_watchdog(struct ctl_table *, int , |
| 174 | void __user *, size_t *, loff_t *); |
| 175 | extern int proc_nmi_watchdog(struct ctl_table *, int , |
| 176 | void __user *, size_t *, loff_t *); |
| 177 | extern int proc_soft_watchdog(struct ctl_table *, int , |
| 178 | void __user *, size_t *, loff_t *); |
| 179 | extern int proc_watchdog_thresh(struct ctl_table *, int , |
| 180 | void __user *, size_t *, loff_t *); |
Chris Metcalf | fe4ba3c | 2015-06-24 16:55:45 -0700 | [diff] [blame] | 181 | extern int proc_watchdog_cpumask(struct ctl_table *, int, |
| 182 | void __user *, size_t *, loff_t *); |
Ulrich Obergfell | ec6a906 | 2015-09-04 15:45:28 -0700 | [diff] [blame] | 183 | extern int lockup_detector_suspend(void); |
| 184 | extern void lockup_detector_resume(void); |
Ulrich Obergfell | 999bbe4 | 2015-09-04 15:45:25 -0700 | [diff] [blame] | 185 | #else |
Ulrich Obergfell | ec6a906 | 2015-09-04 15:45:28 -0700 | [diff] [blame] | 186 | static inline int lockup_detector_suspend(void) |
Ulrich Obergfell | 999bbe4 | 2015-09-04 15:45:25 -0700 | [diff] [blame] | 187 | { |
| 188 | return 0; |
| 189 | } |
| 190 | |
Ulrich Obergfell | ec6a906 | 2015-09-04 15:45:28 -0700 | [diff] [blame] | 191 | static inline void lockup_detector_resume(void) |
Ulrich Obergfell | 999bbe4 | 2015-09-04 15:45:25 -0700 | [diff] [blame] | 192 | { |
| 193 | } |
Don Zickus | 84e478c | 2010-02-05 21:47:05 -0500 | [diff] [blame] | 194 | #endif |
| 195 | |
Tomasz Nowicki | 44a69f6 | 2014-07-22 11:20:12 +0200 | [diff] [blame] | 196 | #ifdef CONFIG_HAVE_ACPI_APEI_NMI |
| 197 | #include <asm/nmi.h> |
| 198 | #endif |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | #endif |