blob: 8aa01fd859fb84e5f64e9d7ffb0c20957afdfd2d [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
Nicholas Piggin05a4a952017-07-12 14:35:46 -070014void lockup_detector_init(void);
15#else
16static inline void lockup_detector_init(void)
17{
18}
19#endif
20
21#ifdef CONFIG_SOFTLOCKUP_DETECTOR
Ingo Molnard151b272017-02-02 11:17:23 +010022extern void touch_softlockup_watchdog_sched(void);
23extern void touch_softlockup_watchdog(void);
24extern void touch_softlockup_watchdog_sync(void);
25extern void touch_all_softlockup_watchdogs(void);
Ingo Molnard151b272017-02-02 11:17:23 +010026extern unsigned int softlockup_panic;
Nicholas Piggin05a4a952017-07-12 14:35:46 -070027extern int soft_watchdog_enabled;
28extern atomic_t watchdog_park_in_progress;
Ingo Molnard151b272017-02-02 11:17:23 +010029#else
30static inline void touch_softlockup_watchdog_sched(void)
31{
32}
33static inline void touch_softlockup_watchdog(void)
34{
35}
36static inline void touch_softlockup_watchdog_sync(void)
37{
38}
39static inline void touch_all_softlockup_watchdogs(void)
40{
41}
Ingo Molnard151b272017-02-02 11:17:23 +010042#endif
43
44#ifdef CONFIG_DETECT_HUNG_TASK
45void reset_hung_task_detector(void);
46#else
47static inline void reset_hung_task_detector(void)
48{
49}
50#endif
51
Babu Moger249e52e2016-12-14 15:06:21 -080052/*
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 Pigginf2e0cff2017-07-12 14:35:43 -070069#if defined(CONFIG_HARDLOCKUP_DETECTOR)
70extern void hardlockup_detector_disable(void);
Nicholas Piggin05a4a952017-07-12 14:35:46 -070071extern unsigned int hardlockup_panic;
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070072#else
73static inline void hardlockup_detector_disable(void) {}
74#endif
75
Nicholas Piggin05a4a952017-07-12 14:35:46 -070076#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070077extern void arch_touch_nmi_watchdog(void);
78#else
Nicholas Piggin05a4a952017-07-12 14:35:46 -070079#if !defined(CONFIG_HAVE_NMI_WATCHDOG)
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070080static inline void arch_touch_nmi_watchdog(void) {}
81#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -070082#endif
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/**
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 Molnar5d0e6002007-02-13 13:26:24 +010091static inline void touch_nmi_watchdog(void)
92{
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070093 arch_touch_nmi_watchdog();
Ingo Molnar5d0e6002007-02-13 13:26:24 +010094 touch_softlockup_watchdog();
95}
Ulrich Obergfell6e7458a2014-10-13 15:55:35 -070096
Ingo Molnar47cab6a2009-08-03 09:31:54 +020097/*
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 Metcalf9a01c3e2016-10-07 17:02:45 -0700102#ifdef arch_trigger_cpumask_backtrace
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200103static inline bool trigger_all_cpu_backtrace(void)
104{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700105 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200106 return true;
107}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700108
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700109static inline bool trigger_allbutself_cpu_backtrace(void)
110{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700111 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
112 return true;
113}
114
115static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
116{
117 arch_trigger_cpumask_backtrace(mask, false);
118 return true;
119}
120
121static inline bool trigger_single_cpu_backtrace(int cpu)
122{
123 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700124 return true;
125}
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100126
127/* generic implementation */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700128void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
129 bool exclude_self,
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100130 void (*raise)(cpumask_t *mask));
131bool nmi_cpu_backtrace(struct pt_regs *regs);
132
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200133#else
134static inline bool trigger_all_cpu_backtrace(void)
135{
136 return false;
137}
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700138static inline bool trigger_allbutself_cpu_backtrace(void)
139{
140 return false;
141}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700142static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
143{
144 return false;
145}
146static inline bool trigger_single_cpu_backtrace(int cpu)
147{
148 return false;
149}
Andrew Mortonbb81a092006-12-07 02:14:01 +0100150#endif
151
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700152#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
Mandeep Singh Baines4eec42f2011-05-22 22:10:23 -0700153u64 hw_nmi_get_sample_period(int watchdog_thresh);
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700154#endif
155
156#ifdef CONFIG_LOCKUP_DETECTOR
Ulrich Obergfell84d56e62015-04-14 15:43:55 -0700157extern int nmi_watchdog_enabled;
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200158extern int watchdog_user_enabled;
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700159extern int watchdog_thresh;
Babu Moger249e52e2016-12-14 15:06:21 -0800160extern unsigned long watchdog_enabled;
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700161extern struct cpumask watchdog_cpumask;
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700162extern unsigned long *watchdog_cpumask_bits;
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700163extern int __read_mostly watchdog_suspended;
Babu Moger249e52e2016-12-14 15:06:21 -0800164#ifdef CONFIG_SMP
Aaron Tomlined235872014-06-23 13:22:05 -0700165extern int sysctl_softlockup_all_cpu_backtrace;
Jiri Kosina55537872015-11-05 18:44:41 -0800166extern int sysctl_hardlockup_all_cpu_backtrace;
Babu Moger249e52e2016-12-14 15:06:21 -0800167#else
168#define sysctl_softlockup_all_cpu_backtrace 0
169#define sysctl_hardlockup_all_cpu_backtrace 0
170#endif
171extern bool is_hardlockup(void);
Don Zickus504d7cf2010-02-12 17:19:19 -0500172struct ctl_table;
Ulrich Obergfell83a80a32015-04-14 15:44:08 -0700173extern int proc_watchdog(struct ctl_table *, int ,
174 void __user *, size_t *, loff_t *);
175extern int proc_nmi_watchdog(struct ctl_table *, int ,
176 void __user *, size_t *, loff_t *);
177extern int proc_soft_watchdog(struct ctl_table *, int ,
178 void __user *, size_t *, loff_t *);
179extern int proc_watchdog_thresh(struct ctl_table *, int ,
180 void __user *, size_t *, loff_t *);
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700181extern int proc_watchdog_cpumask(struct ctl_table *, int,
182 void __user *, size_t *, loff_t *);
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700183extern int lockup_detector_suspend(void);
184extern void lockup_detector_resume(void);
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700185#else
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700186static inline int lockup_detector_suspend(void)
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700187{
188 return 0;
189}
190
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700191static inline void lockup_detector_resume(void)
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700192{
193}
Don Zickus84e478c2010-02-05 21:47:05 -0500194#endif
195
Tomasz Nowicki44a69f62014-07-22 11:20:12 +0200196#ifdef CONFIG_HAVE_ACPI_APEI_NMI
197#include <asm/nmi.h>
198#endif
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#endif