blob: 80354e6fa86d688f04d167a237b674103edc1ce1 [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);
Thomas Gleixner941154b2017-09-12 21:37:04 +020016void lockup_detector_cleanup(void);
Nicholas Piggin05a4a952017-07-12 14:35:46 -070017#else
Thomas Gleixner6554fd82017-09-12 21:36:57 +020018static inline void lockup_detector_init(void) { }
19static inline void lockup_detector_soft_poweroff(void) { }
Thomas Gleixner941154b2017-09-12 21:37:04 +020020static inline void lockup_detector_cleanup(void) { }
Nicholas Piggin05a4a952017-07-12 14:35:46 -070021#endif
22
23#ifdef CONFIG_SOFTLOCKUP_DETECTOR
Ingo Molnard151b272017-02-02 11:17:23 +010024extern void touch_softlockup_watchdog_sched(void);
25extern void touch_softlockup_watchdog(void);
26extern void touch_softlockup_watchdog_sync(void);
27extern void touch_all_softlockup_watchdogs(void);
Ingo Molnard151b272017-02-02 11:17:23 +010028extern unsigned int softlockup_panic;
Nicholas Piggin05a4a952017-07-12 14:35:46 -070029extern int soft_watchdog_enabled;
30extern atomic_t watchdog_park_in_progress;
Ingo Molnard151b272017-02-02 11:17:23 +010031#else
32static inline void touch_softlockup_watchdog_sched(void)
33{
34}
35static inline void touch_softlockup_watchdog(void)
36{
37}
38static inline void touch_softlockup_watchdog_sync(void)
39{
40}
41static inline void touch_all_softlockup_watchdogs(void)
42{
43}
Ingo Molnard151b272017-02-02 11:17:23 +010044#endif
45
46#ifdef CONFIG_DETECT_HUNG_TASK
47void reset_hung_task_detector(void);
48#else
49static inline void reset_hung_task_detector(void)
50{
51}
52#endif
53
Babu Moger249e52e2016-12-14 15:06:21 -080054/*
55 * The run state of the lockup detectors is controlled by the content of the
56 * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit -
57 * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector.
58 *
59 * 'watchdog_user_enabled', 'nmi_watchdog_enabled' and 'soft_watchdog_enabled'
60 * are variables that are only used as an 'interface' between the parameters
61 * in /proc/sys/kernel and the internal state bits in 'watchdog_enabled'. The
62 * 'watchdog_thresh' variable is handled differently because its value is not
63 * boolean, and the lockup detectors are 'suspended' while 'watchdog_thresh'
64 * is equal zero.
65 */
66#define NMI_WATCHDOG_ENABLED_BIT 0
67#define SOFT_WATCHDOG_ENABLED_BIT 1
68#define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT)
69#define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT)
70
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070071#if defined(CONFIG_HARDLOCKUP_DETECTOR)
72extern void hardlockup_detector_disable(void);
Nicholas Piggin05a4a952017-07-12 14:35:46 -070073extern unsigned int hardlockup_panic;
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070074#else
75static inline void hardlockup_detector_disable(void) {}
76#endif
77
Nicholas Piggin05a4a952017-07-12 14:35:46 -070078#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070079extern void arch_touch_nmi_watchdog(void);
Peter Zijlstrad0b6e0a2017-09-12 21:36:55 +020080extern void hardlockup_detector_perf_stop(void);
81extern void hardlockup_detector_perf_restart(void);
Thomas Gleixner941154b2017-09-12 21:37:04 +020082extern void hardlockup_detector_perf_disable(void);
83extern void hardlockup_detector_perf_cleanup(void);
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070084#else
Peter Zijlstrad0b6e0a2017-09-12 21:36:55 +020085static inline void hardlockup_detector_perf_stop(void) { }
86static inline void hardlockup_detector_perf_restart(void) { }
Thomas Gleixner941154b2017-09-12 21:37:04 +020087static inline void hardlockup_detector_perf_disable(void) { }
88static inline void hardlockup_detector_perf_cleanup(void) { }
Nicholas Piggin05a4a952017-07-12 14:35:46 -070089#if !defined(CONFIG_HAVE_NMI_WATCHDOG)
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070090static inline void arch_touch_nmi_watchdog(void) {}
91#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -070092#endif
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/**
95 * touch_nmi_watchdog - restart NMI watchdog timeout.
96 *
97 * If the architecture supports the NMI watchdog, touch_nmi_watchdog()
98 * may be used to reset the timeout - for code which intentionally
99 * disables interrupts for a long time. This call is stateless.
100 */
Ingo Molnar5d0e6002007-02-13 13:26:24 +0100101static inline void touch_nmi_watchdog(void)
102{
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -0700103 arch_touch_nmi_watchdog();
Ingo Molnar5d0e6002007-02-13 13:26:24 +0100104 touch_softlockup_watchdog();
105}
Ulrich Obergfell6e7458a2014-10-13 15:55:35 -0700106
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200107/*
108 * Create trigger_all_cpu_backtrace() out of the arch-provided
109 * base function. Return whether such support was available,
110 * to allow calling code to fall back to some other mechanism:
111 */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700112#ifdef arch_trigger_cpumask_backtrace
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200113static inline bool trigger_all_cpu_backtrace(void)
114{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700115 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200116 return true;
117}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700118
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700119static inline bool trigger_allbutself_cpu_backtrace(void)
120{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700121 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
122 return true;
123}
124
125static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
126{
127 arch_trigger_cpumask_backtrace(mask, false);
128 return true;
129}
130
131static inline bool trigger_single_cpu_backtrace(int cpu)
132{
133 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700134 return true;
135}
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100136
137/* generic implementation */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700138void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
139 bool exclude_self,
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100140 void (*raise)(cpumask_t *mask));
141bool nmi_cpu_backtrace(struct pt_regs *regs);
142
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200143#else
144static inline bool trigger_all_cpu_backtrace(void)
145{
146 return false;
147}
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700148static inline bool trigger_allbutself_cpu_backtrace(void)
149{
150 return false;
151}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700152static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
153{
154 return false;
155}
156static inline bool trigger_single_cpu_backtrace(int cpu)
157{
158 return false;
159}
Andrew Mortonbb81a092006-12-07 02:14:01 +0100160#endif
161
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700162#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
Mandeep Singh Baines4eec42f2011-05-22 22:10:23 -0700163u64 hw_nmi_get_sample_period(int watchdog_thresh);
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700164#endif
165
166#ifdef CONFIG_LOCKUP_DETECTOR
Ulrich Obergfell84d56e62015-04-14 15:43:55 -0700167extern int nmi_watchdog_enabled;
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200168extern int watchdog_user_enabled;
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700169extern int watchdog_thresh;
Babu Moger249e52e2016-12-14 15:06:21 -0800170extern unsigned long watchdog_enabled;
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700171extern struct cpumask watchdog_cpumask;
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700172extern unsigned long *watchdog_cpumask_bits;
Babu Moger249e52e2016-12-14 15:06:21 -0800173#ifdef CONFIG_SMP
Aaron Tomlined235872014-06-23 13:22:05 -0700174extern int sysctl_softlockup_all_cpu_backtrace;
Jiri Kosina55537872015-11-05 18:44:41 -0800175extern int sysctl_hardlockup_all_cpu_backtrace;
Babu Moger249e52e2016-12-14 15:06:21 -0800176#else
177#define sysctl_softlockup_all_cpu_backtrace 0
178#define sysctl_hardlockup_all_cpu_backtrace 0
179#endif
Thomas Gleixner7edaeb62017-08-15 09:50:13 +0200180
181#if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
182 defined(CONFIG_HARDLOCKUP_DETECTOR)
183void watchdog_update_hrtimer_threshold(u64 period);
184#else
185static inline void watchdog_update_hrtimer_threshold(u64 period) { }
186#endif
187
Babu Moger249e52e2016-12-14 15:06:21 -0800188extern bool is_hardlockup(void);
Don Zickus504d7cf2010-02-12 17:19:19 -0500189struct ctl_table;
Ulrich Obergfell83a80a32015-04-14 15:44:08 -0700190extern int proc_watchdog(struct ctl_table *, int ,
191 void __user *, size_t *, loff_t *);
192extern int proc_nmi_watchdog(struct ctl_table *, int ,
193 void __user *, size_t *, loff_t *);
194extern int proc_soft_watchdog(struct ctl_table *, int ,
195 void __user *, size_t *, loff_t *);
196extern int proc_watchdog_thresh(struct ctl_table *, int ,
197 void __user *, size_t *, loff_t *);
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700198extern int proc_watchdog_cpumask(struct ctl_table *, int,
199 void __user *, size_t *, loff_t *);
Don Zickus84e478c2010-02-05 21:47:05 -0500200#endif
201
Tomasz Nowicki44a69f62014-07-22 11:20:12 +0200202#ifdef CONFIG_HAVE_ACPI_APEI_NMI
203#include <asm/nmi.h>
204#endif
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206#endif