blob: 85bb268be39ce2d6c87b0af38d0347e0b958fefe [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);
Thomas Gleixner6554fd82017-09-12 21:36:57 +020015void lockup_detector_soft_poweroff(void);
Nicholas Piggin05a4a952017-07-12 14:35:46 -070016#else
Thomas Gleixner6554fd82017-09-12 21:36:57 +020017static inline void lockup_detector_init(void) { }
18static inline void lockup_detector_soft_poweroff(void) { }
Nicholas Piggin05a4a952017-07-12 14:35:46 -070019#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);
Peter Zijlstrad0b6e0a2017-09-12 21:36:55 +020078extern void hardlockup_detector_perf_stop(void);
79extern void hardlockup_detector_perf_restart(void);
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070080#else
Peter Zijlstrad0b6e0a2017-09-12 21:36:55 +020081static inline void hardlockup_detector_perf_stop(void) { }
82static inline void hardlockup_detector_perf_restart(void) { }
Nicholas Piggin05a4a952017-07-12 14:35:46 -070083#if !defined(CONFIG_HAVE_NMI_WATCHDOG)
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070084static inline void arch_touch_nmi_watchdog(void) {}
85#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -070086#endif
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070087
Linus Torvalds1da177e2005-04-16 15:20:36 -070088/**
89 * touch_nmi_watchdog - restart NMI watchdog timeout.
90 *
91 * If the architecture supports the NMI watchdog, touch_nmi_watchdog()
92 * may be used to reset the timeout - for code which intentionally
93 * disables interrupts for a long time. This call is stateless.
94 */
Ingo Molnar5d0e6002007-02-13 13:26:24 +010095static inline void touch_nmi_watchdog(void)
96{
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070097 arch_touch_nmi_watchdog();
Ingo Molnar5d0e6002007-02-13 13:26:24 +010098 touch_softlockup_watchdog();
99}
Ulrich Obergfell6e7458a2014-10-13 15:55:35 -0700100
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200101/*
102 * Create trigger_all_cpu_backtrace() out of the arch-provided
103 * base function. Return whether such support was available,
104 * to allow calling code to fall back to some other mechanism:
105 */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700106#ifdef arch_trigger_cpumask_backtrace
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200107static inline bool trigger_all_cpu_backtrace(void)
108{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700109 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200110 return true;
111}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700112
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700113static inline bool trigger_allbutself_cpu_backtrace(void)
114{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700115 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
116 return true;
117}
118
119static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
120{
121 arch_trigger_cpumask_backtrace(mask, false);
122 return true;
123}
124
125static inline bool trigger_single_cpu_backtrace(int cpu)
126{
127 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700128 return true;
129}
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100130
131/* generic implementation */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700132void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
133 bool exclude_self,
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100134 void (*raise)(cpumask_t *mask));
135bool nmi_cpu_backtrace(struct pt_regs *regs);
136
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200137#else
138static inline bool trigger_all_cpu_backtrace(void)
139{
140 return false;
141}
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700142static inline bool trigger_allbutself_cpu_backtrace(void)
143{
144 return false;
145}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700146static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
147{
148 return false;
149}
150static inline bool trigger_single_cpu_backtrace(int cpu)
151{
152 return false;
153}
Andrew Mortonbb81a092006-12-07 02:14:01 +0100154#endif
155
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700156#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
Mandeep Singh Baines4eec42f2011-05-22 22:10:23 -0700157u64 hw_nmi_get_sample_period(int watchdog_thresh);
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700158#endif
159
160#ifdef CONFIG_LOCKUP_DETECTOR
Ulrich Obergfell84d56e62015-04-14 15:43:55 -0700161extern int nmi_watchdog_enabled;
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200162extern int watchdog_user_enabled;
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700163extern int watchdog_thresh;
Babu Moger249e52e2016-12-14 15:06:21 -0800164extern unsigned long watchdog_enabled;
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700165extern struct cpumask watchdog_cpumask;
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700166extern unsigned long *watchdog_cpumask_bits;
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700167extern int __read_mostly watchdog_suspended;
Babu Moger249e52e2016-12-14 15:06:21 -0800168#ifdef CONFIG_SMP
Aaron Tomlined235872014-06-23 13:22:05 -0700169extern int sysctl_softlockup_all_cpu_backtrace;
Jiri Kosina55537872015-11-05 18:44:41 -0800170extern int sysctl_hardlockup_all_cpu_backtrace;
Babu Moger249e52e2016-12-14 15:06:21 -0800171#else
172#define sysctl_softlockup_all_cpu_backtrace 0
173#define sysctl_hardlockup_all_cpu_backtrace 0
174#endif
Thomas Gleixner7edaeb62017-08-15 09:50:13 +0200175
176#if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
177 defined(CONFIG_HARDLOCKUP_DETECTOR)
178void watchdog_update_hrtimer_threshold(u64 period);
179#else
180static inline void watchdog_update_hrtimer_threshold(u64 period) { }
181#endif
182
Babu Moger249e52e2016-12-14 15:06:21 -0800183extern bool is_hardlockup(void);
Don Zickus504d7cf2010-02-12 17:19:19 -0500184struct ctl_table;
Ulrich Obergfell83a80a32015-04-14 15:44:08 -0700185extern int proc_watchdog(struct ctl_table *, int ,
186 void __user *, size_t *, loff_t *);
187extern int proc_nmi_watchdog(struct ctl_table *, int ,
188 void __user *, size_t *, loff_t *);
189extern int proc_soft_watchdog(struct ctl_table *, int ,
190 void __user *, size_t *, loff_t *);
191extern int proc_watchdog_thresh(struct ctl_table *, int ,
192 void __user *, size_t *, loff_t *);
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700193extern int proc_watchdog_cpumask(struct ctl_table *, int,
194 void __user *, size_t *, loff_t *);
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700195extern int lockup_detector_suspend(void);
196extern void lockup_detector_resume(void);
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700197#else
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700198static inline int lockup_detector_suspend(void)
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700199{
200 return 0;
201}
202
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700203static inline void lockup_detector_resume(void)
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700204{
205}
Don Zickus84e478c2010-02-05 21:47:05 -0500206#endif
207
Tomasz Nowicki44a69f62014-07-22 11:20:12 +0200208#ifdef CONFIG_HAVE_ACPI_APEI_NMI
209#include <asm/nmi.h>
210#endif
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#endif