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