blob: bd387ef8bccd2f98f5c9693318882df106d17dd1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/include/linux/nmi.h
3 */
4#ifndef LINUX_NMI_H
5#define LINUX_NMI_H
6
Michal Schmidt99384062006-09-29 01:59:03 -07007#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <asm/irq.h>
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -07009#if defined(CONFIG_HAVE_NMI_WATCHDOG)
10#include <asm/nmi.h>
11#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Ingo Molnard151b272017-02-02 11:17:23 +010013#ifdef CONFIG_LOCKUP_DETECTOR
14extern void touch_softlockup_watchdog_sched(void);
15extern void touch_softlockup_watchdog(void);
16extern void touch_softlockup_watchdog_sync(void);
17extern void touch_all_softlockup_watchdogs(void);
Ingo Molnard151b272017-02-02 11:17:23 +010018extern unsigned int softlockup_panic;
19extern unsigned int hardlockup_panic;
20void lockup_detector_init(void);
21#else
22static inline void touch_softlockup_watchdog_sched(void)
23{
24}
25static inline void touch_softlockup_watchdog(void)
26{
27}
28static inline void touch_softlockup_watchdog_sync(void)
29{
30}
31static inline void touch_all_softlockup_watchdogs(void)
32{
33}
34static inline void lockup_detector_init(void)
35{
36}
37#endif
38
39#ifdef CONFIG_DETECT_HUNG_TASK
40void reset_hung_task_detector(void);
41#else
42static inline void reset_hung_task_detector(void)
43{
44}
45#endif
46
Babu Moger249e52e2016-12-14 15:06:21 -080047/*
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
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070064#if defined(CONFIG_HARDLOCKUP_DETECTOR)
65extern void hardlockup_detector_disable(void);
66#else
67static inline void hardlockup_detector_disable(void) {}
68#endif
69
70#if defined(CONFIG_HARDLOCKUP_DETECTOR) || defined(CONFIG_HAVE_NMI_WATCHDOG)
71extern void arch_touch_nmi_watchdog(void);
72#else
73static inline void arch_touch_nmi_watchdog(void) {}
74#endif
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076/**
77 * touch_nmi_watchdog - restart NMI watchdog timeout.
78 *
79 * If the architecture supports the NMI watchdog, touch_nmi_watchdog()
80 * may be used to reset the timeout - for code which intentionally
81 * disables interrupts for a long time. This call is stateless.
82 */
Ingo Molnar5d0e6002007-02-13 13:26:24 +010083static inline void touch_nmi_watchdog(void)
84{
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070085 arch_touch_nmi_watchdog();
Ingo Molnar5d0e6002007-02-13 13:26:24 +010086 touch_softlockup_watchdog();
87}
Ulrich Obergfell6e7458a2014-10-13 15:55:35 -070088
Ingo Molnar47cab6a2009-08-03 09:31:54 +020089/*
90 * Create trigger_all_cpu_backtrace() out of the arch-provided
91 * base function. Return whether such support was available,
92 * to allow calling code to fall back to some other mechanism:
93 */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -070094#ifdef arch_trigger_cpumask_backtrace
Ingo Molnar47cab6a2009-08-03 09:31:54 +020095static inline bool trigger_all_cpu_backtrace(void)
96{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -070097 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
Ingo Molnar47cab6a2009-08-03 09:31:54 +020098 return true;
99}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700100
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700101static inline bool trigger_allbutself_cpu_backtrace(void)
102{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700103 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
104 return true;
105}
106
107static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
108{
109 arch_trigger_cpumask_backtrace(mask, false);
110 return true;
111}
112
113static inline bool trigger_single_cpu_backtrace(int cpu)
114{
115 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700116 return true;
117}
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100118
119/* generic implementation */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700120void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
121 bool exclude_self,
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100122 void (*raise)(cpumask_t *mask));
123bool nmi_cpu_backtrace(struct pt_regs *regs);
124
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200125#else
126static inline bool trigger_all_cpu_backtrace(void)
127{
128 return false;
129}
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700130static inline bool trigger_allbutself_cpu_backtrace(void)
131{
132 return false;
133}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700134static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
135{
136 return false;
137}
138static inline bool trigger_single_cpu_backtrace(int cpu)
139{
140 return false;
141}
Andrew Mortonbb81a092006-12-07 02:14:01 +0100142#endif
143
Don Zickus58687ac2010-05-07 17:11:44 -0400144#ifdef CONFIG_LOCKUP_DETECTOR
Mandeep Singh Baines4eec42f2011-05-22 22:10:23 -0700145u64 hw_nmi_get_sample_period(int watchdog_thresh);
Ulrich Obergfell84d56e62015-04-14 15:43:55 -0700146extern int nmi_watchdog_enabled;
147extern int soft_watchdog_enabled;
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200148extern int watchdog_user_enabled;
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700149extern int watchdog_thresh;
Babu Moger249e52e2016-12-14 15:06:21 -0800150extern unsigned long watchdog_enabled;
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700151extern unsigned long *watchdog_cpumask_bits;
Don Zickusb94f5112017-01-24 15:17:53 -0800152extern atomic_t watchdog_park_in_progress;
Babu Moger249e52e2016-12-14 15:06:21 -0800153#ifdef CONFIG_SMP
Aaron Tomlined235872014-06-23 13:22:05 -0700154extern int sysctl_softlockup_all_cpu_backtrace;
Jiri Kosina55537872015-11-05 18:44:41 -0800155extern int sysctl_hardlockup_all_cpu_backtrace;
Babu Moger249e52e2016-12-14 15:06:21 -0800156#else
157#define sysctl_softlockup_all_cpu_backtrace 0
158#define sysctl_hardlockup_all_cpu_backtrace 0
159#endif
160extern bool is_hardlockup(void);
Don Zickus504d7cf2010-02-12 17:19:19 -0500161struct ctl_table;
Ulrich Obergfell83a80a32015-04-14 15:44:08 -0700162extern int proc_watchdog(struct ctl_table *, int ,
163 void __user *, size_t *, loff_t *);
164extern int proc_nmi_watchdog(struct ctl_table *, int ,
165 void __user *, size_t *, loff_t *);
166extern int proc_soft_watchdog(struct ctl_table *, int ,
167 void __user *, size_t *, loff_t *);
168extern int proc_watchdog_thresh(struct ctl_table *, int ,
169 void __user *, size_t *, loff_t *);
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700170extern int proc_watchdog_cpumask(struct ctl_table *, int,
171 void __user *, size_t *, loff_t *);
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700172extern int lockup_detector_suspend(void);
173extern void lockup_detector_resume(void);
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700174#else
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700175static inline int lockup_detector_suspend(void)
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700176{
177 return 0;
178}
179
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700180static inline void lockup_detector_resume(void)
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700181{
182}
Don Zickus84e478c2010-02-05 21:47:05 -0500183#endif
184
Tomasz Nowicki44a69f62014-07-22 11:20:12 +0200185#ifdef CONFIG_HAVE_ACPI_APEI_NMI
186#include <asm/nmi.h>
187#endif
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189#endif