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