blob: 27e249ed7c5c8dfcbd969e347ff844a56899edc7 [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);
Thomas Gleixner3b371b52017-09-12 21:37:13 +020017bool is_hardlockup(void);
18
19extern int watchdog_user_enabled;
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +020020extern int nmi_watchdog_user_enabled;
21extern int soft_watchdog_user_enabled;
Thomas Gleixner3b371b52017-09-12 21:37:13 +020022extern int watchdog_thresh;
23extern unsigned long watchdog_enabled;
24
25extern struct cpumask watchdog_cpumask;
26extern unsigned long *watchdog_cpumask_bits;
27#ifdef CONFIG_SMP
28extern int sysctl_softlockup_all_cpu_backtrace;
29extern int sysctl_hardlockup_all_cpu_backtrace;
Nicholas Piggin05a4a952017-07-12 14:35:46 -070030#else
Thomas Gleixner3b371b52017-09-12 21:37:13 +020031#define sysctl_softlockup_all_cpu_backtrace 0
32#define sysctl_hardlockup_all_cpu_backtrace 0
33#endif /* !CONFIG_SMP */
34
35#else /* CONFIG_LOCKUP_DETECTOR */
Thomas Gleixner6554fd82017-09-12 21:36:57 +020036static inline void lockup_detector_init(void) { }
37static inline void lockup_detector_soft_poweroff(void) { }
Thomas Gleixner941154b2017-09-12 21:37:04 +020038static inline void lockup_detector_cleanup(void) { }
Thomas Gleixner3b371b52017-09-12 21:37:13 +020039#endif /* !CONFIG_LOCKUP_DETECTOR */
Nicholas Piggin05a4a952017-07-12 14:35:46 -070040
41#ifdef CONFIG_SOFTLOCKUP_DETECTOR
Ingo Molnard151b272017-02-02 11:17:23 +010042extern void touch_softlockup_watchdog_sched(void);
43extern void touch_softlockup_watchdog(void);
44extern void touch_softlockup_watchdog_sync(void);
45extern void touch_all_softlockup_watchdogs(void);
Ingo Molnard151b272017-02-02 11:17:23 +010046extern unsigned int softlockup_panic;
Ingo Molnard151b272017-02-02 11:17:23 +010047#else
Thomas Gleixner3b371b52017-09-12 21:37:13 +020048static inline void touch_softlockup_watchdog_sched(void) { }
49static inline void touch_softlockup_watchdog(void) { }
50static inline void touch_softlockup_watchdog_sync(void) { }
51static inline void touch_all_softlockup_watchdogs(void) { }
Ingo Molnard151b272017-02-02 11:17:23 +010052#endif
53
54#ifdef CONFIG_DETECT_HUNG_TASK
55void reset_hung_task_detector(void);
56#else
Thomas Gleixner3b371b52017-09-12 21:37:13 +020057static inline void reset_hung_task_detector(void) { }
Ingo Molnard151b272017-02-02 11:17:23 +010058#endif
59
Babu Moger249e52e2016-12-14 15:06:21 -080060/*
61 * The run state of the lockup detectors is controlled by the content of the
62 * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit -
63 * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector.
64 *
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +020065 * 'watchdog_user_enabled', 'nmi_watchdog_user_enabled' and
66 * 'soft_watchdog_user_enabled' are variables that are only used as an
67 * 'interface' between the parameters in /proc/sys/kernel and the internal
68 * state bits in 'watchdog_enabled'. The 'watchdog_thresh' variable is
69 * handled differently because its value is not boolean, and the lockup
70 * detectors are 'suspended' while 'watchdog_thresh' is equal zero.
Babu Moger249e52e2016-12-14 15:06:21 -080071 */
72#define NMI_WATCHDOG_ENABLED_BIT 0
73#define SOFT_WATCHDOG_ENABLED_BIT 1
74#define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT)
75#define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT)
76
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070077#if defined(CONFIG_HARDLOCKUP_DETECTOR)
78extern void hardlockup_detector_disable(void);
Nicholas Piggin05a4a952017-07-12 14:35:46 -070079extern unsigned int hardlockup_panic;
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070080#else
81static inline void hardlockup_detector_disable(void) {}
82#endif
83
Thomas Gleixner51d40522017-09-12 21:37:14 +020084#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
85# define NMI_WATCHDOG_SYSCTL_PERM 0644
86#else
87# define NMI_WATCHDOG_SYSCTL_PERM 0444
88#endif
89
Nicholas Piggin05a4a952017-07-12 14:35:46 -070090#if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070091extern void arch_touch_nmi_watchdog(void);
Peter Zijlstrad0b6e0a2017-09-12 21:36:55 +020092extern void hardlockup_detector_perf_stop(void);
93extern void hardlockup_detector_perf_restart(void);
Thomas Gleixner941154b2017-09-12 21:37:04 +020094extern void hardlockup_detector_perf_disable(void);
Thomas Gleixner2a1b8ee2017-09-12 21:37:20 +020095extern void hardlockup_detector_perf_enable(void);
Thomas Gleixner941154b2017-09-12 21:37:04 +020096extern void hardlockup_detector_perf_cleanup(void);
Thomas Gleixner178b9f72017-09-12 21:37:18 +020097extern int hardlockup_detector_perf_init(void);
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -070098#else
Peter Zijlstrad0b6e0a2017-09-12 21:36:55 +020099static inline void hardlockup_detector_perf_stop(void) { }
100static inline void hardlockup_detector_perf_restart(void) { }
Thomas Gleixner941154b2017-09-12 21:37:04 +0200101static inline void hardlockup_detector_perf_disable(void) { }
Thomas Gleixner2a1b8ee2017-09-12 21:37:20 +0200102static inline void hardlockup_detector_perf_enable(void) { }
Thomas Gleixner941154b2017-09-12 21:37:04 +0200103static inline void hardlockup_detector_perf_cleanup(void) { }
Thomas Gleixner178b9f72017-09-12 21:37:18 +0200104# if !defined(CONFIG_HAVE_NMI_WATCHDOG)
105static inline int hardlockup_detector_perf_init(void) { return -ENODEV; }
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -0700106static inline void arch_touch_nmi_watchdog(void) {}
Thomas Gleixner178b9f72017-09-12 21:37:18 +0200107# else
108static inline int hardlockup_detector_perf_init(void) { return 0; }
109# endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700110#endif
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -0700111
Thomas Gleixner6b9dc482017-10-02 12:34:50 +0200112void watchdog_nmi_stop(void);
113void watchdog_nmi_start(void);
Thomas Gleixner34ddaa32017-10-03 16:39:02 +0200114int watchdog_nmi_probe(void);
Thomas Gleixner6592ad22017-09-12 21:37:16 +0200115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116/**
117 * touch_nmi_watchdog - restart NMI watchdog timeout.
Thomas Gleixner3b371b52017-09-12 21:37:13 +0200118 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 * If the architecture supports the NMI watchdog, touch_nmi_watchdog()
120 * may be used to reset the timeout - for code which intentionally
121 * disables interrupts for a long time. This call is stateless.
122 */
Ingo Molnar5d0e6002007-02-13 13:26:24 +0100123static inline void touch_nmi_watchdog(void)
124{
Nicholas Pigginf2e0cff2017-07-12 14:35:43 -0700125 arch_touch_nmi_watchdog();
Ingo Molnar5d0e6002007-02-13 13:26:24 +0100126 touch_softlockup_watchdog();
127}
Ulrich Obergfell6e7458a2014-10-13 15:55:35 -0700128
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200129/*
130 * Create trigger_all_cpu_backtrace() out of the arch-provided
131 * base function. Return whether such support was available,
132 * to allow calling code to fall back to some other mechanism:
133 */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700134#ifdef arch_trigger_cpumask_backtrace
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200135static inline bool trigger_all_cpu_backtrace(void)
136{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700137 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200138 return true;
139}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700140
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700141static inline bool trigger_allbutself_cpu_backtrace(void)
142{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700143 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
144 return true;
145}
146
147static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
148{
149 arch_trigger_cpumask_backtrace(mask, false);
150 return true;
151}
152
153static inline bool trigger_single_cpu_backtrace(int cpu)
154{
155 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700156 return true;
157}
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100158
159/* generic implementation */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700160void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
161 bool exclude_self,
Russell Kingb2c0b2c2014-09-03 23:57:13 +0100162 void (*raise)(cpumask_t *mask));
163bool nmi_cpu_backtrace(struct pt_regs *regs);
164
Ingo Molnar47cab6a2009-08-03 09:31:54 +0200165#else
166static inline bool trigger_all_cpu_backtrace(void)
167{
168 return false;
169}
Aaron Tomlinf3aca3d02014-06-23 13:22:05 -0700170static inline bool trigger_allbutself_cpu_backtrace(void)
171{
172 return false;
173}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -0700174static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
175{
176 return false;
177}
178static inline bool trigger_single_cpu_backtrace(int cpu)
179{
180 return false;
181}
Andrew Mortonbb81a092006-12-07 02:14:01 +0100182#endif
183
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700184#ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
Mandeep Singh Baines4eec42f2011-05-22 22:10:23 -0700185u64 hw_nmi_get_sample_period(int watchdog_thresh);
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700186#endif
187
Thomas Gleixner7edaeb62017-08-15 09:50:13 +0200188#if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
189 defined(CONFIG_HARDLOCKUP_DETECTOR)
190void watchdog_update_hrtimer_threshold(u64 period);
191#else
192static inline void watchdog_update_hrtimer_threshold(u64 period) { }
193#endif
194
Don Zickus504d7cf2010-02-12 17:19:19 -0500195struct ctl_table;
Ulrich Obergfell83a80a32015-04-14 15:44:08 -0700196extern int proc_watchdog(struct ctl_table *, int ,
197 void __user *, size_t *, loff_t *);
198extern int proc_nmi_watchdog(struct ctl_table *, int ,
199 void __user *, size_t *, loff_t *);
200extern int proc_soft_watchdog(struct ctl_table *, int ,
201 void __user *, size_t *, loff_t *);
202extern int proc_watchdog_thresh(struct ctl_table *, int ,
203 void __user *, size_t *, loff_t *);
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700204extern int proc_watchdog_cpumask(struct ctl_table *, int,
205 void __user *, size_t *, loff_t *);
Don Zickus84e478c2010-02-05 21:47:05 -0500206
Tomasz Nowicki44a69f62014-07-22 11:20:12 +0200207#ifdef CONFIG_HAVE_ACPI_APEI_NMI
208#include <asm/nmi.h>
209#endif
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211#endif