blob: 0a3fadc32693a9cf869693f4c406eee5d168e36b [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>
9
Babu Moger0ce66ee2016-12-14 15:06:21 -080010/*
11 * The run state of the lockup detectors is controlled by the content of the
12 * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit -
13 * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector.
14 *
15 * 'watchdog_user_enabled', 'nmi_watchdog_enabled' and 'soft_watchdog_enabled'
16 * are variables that are only used as an 'interface' between the parameters
17 * in /proc/sys/kernel and the internal state bits in 'watchdog_enabled'. The
18 * 'watchdog_thresh' variable is handled differently because its value is not
19 * boolean, and the lockup detectors are 'suspended' while 'watchdog_thresh'
20 * is equal zero.
21 */
22#define NMI_WATCHDOG_ENABLED_BIT 0
23#define SOFT_WATCHDOG_ENABLED_BIT 1
24#define NMI_WATCHDOG_ENABLED (1 << NMI_WATCHDOG_ENABLED_BIT)
25#define SOFT_WATCHDOG_ENABLED (1 << SOFT_WATCHDOG_ENABLED_BIT)
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027/**
28 * touch_nmi_watchdog - restart NMI watchdog timeout.
29 *
30 * If the architecture supports the NMI watchdog, touch_nmi_watchdog()
31 * may be used to reset the timeout - for code which intentionally
32 * disables interrupts for a long time. This call is stateless.
33 */
Cong Wangd314d742012-03-23 15:01:51 -070034#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
Andrew Mortonbb81a092006-12-07 02:14:01 +010035#include <asm/nmi.h>
Don Zickus96a84c22010-11-29 17:07:16 -050036extern void touch_nmi_watchdog(void);
37#else
Ingo Molnar5d0e6002007-02-13 13:26:24 +010038static inline void touch_nmi_watchdog(void)
39{
40 touch_softlockup_watchdog();
41}
Don Zickus96a84c22010-11-29 17:07:16 -050042#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Ulrich Obergfell6e7458a2014-10-13 15:55:35 -070044#if defined(CONFIG_HARDLOCKUP_DETECTOR)
Ulrich Obergfell692297d2015-04-14 15:44:19 -070045extern void hardlockup_detector_disable(void);
Ulrich Obergfell6e7458a2014-10-13 15:55:35 -070046#else
Guenter Roeckaacfbe62015-09-04 15:45:12 -070047static inline void hardlockup_detector_disable(void) {}
Ulrich Obergfell6e7458a2014-10-13 15:55:35 -070048#endif
49
Ingo Molnar47cab6a2009-08-03 09:31:54 +020050/*
51 * Create trigger_all_cpu_backtrace() out of the arch-provided
52 * base function. Return whether such support was available,
53 * to allow calling code to fall back to some other mechanism:
54 */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -070055#ifdef arch_trigger_cpumask_backtrace
Ingo Molnar47cab6a2009-08-03 09:31:54 +020056static inline bool trigger_all_cpu_backtrace(void)
57{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -070058 arch_trigger_cpumask_backtrace(cpu_online_mask, false);
Ingo Molnar47cab6a2009-08-03 09:31:54 +020059 return true;
60}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -070061
Aaron Tomlinf3aca3d2014-06-23 13:22:05 -070062static inline bool trigger_allbutself_cpu_backtrace(void)
63{
Chris Metcalf9a01c3e2016-10-07 17:02:45 -070064 arch_trigger_cpumask_backtrace(cpu_online_mask, true);
65 return true;
66}
67
68static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
69{
70 arch_trigger_cpumask_backtrace(mask, false);
71 return true;
72}
73
74static inline bool trigger_single_cpu_backtrace(int cpu)
75{
76 arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
Aaron Tomlinf3aca3d2014-06-23 13:22:05 -070077 return true;
78}
Russell Kingb2c0b2c2014-09-03 23:57:13 +010079
80/* generic implementation */
Chris Metcalf9a01c3e2016-10-07 17:02:45 -070081void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
82 bool exclude_self,
Russell Kingb2c0b2c2014-09-03 23:57:13 +010083 void (*raise)(cpumask_t *mask));
84bool nmi_cpu_backtrace(struct pt_regs *regs);
85
Ingo Molnar47cab6a2009-08-03 09:31:54 +020086#else
87static inline bool trigger_all_cpu_backtrace(void)
88{
89 return false;
90}
Aaron Tomlinf3aca3d2014-06-23 13:22:05 -070091static inline bool trigger_allbutself_cpu_backtrace(void)
92{
93 return false;
94}
Chris Metcalf9a01c3e2016-10-07 17:02:45 -070095static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
96{
97 return false;
98}
99static inline bool trigger_single_cpu_backtrace(int cpu)
100{
101 return false;
102}
Andrew Mortonbb81a092006-12-07 02:14:01 +0100103#endif
104
Don Zickus58687ac2010-05-07 17:11:44 -0400105#ifdef CONFIG_LOCKUP_DETECTOR
Mandeep Singh Baines4eec42f2011-05-22 22:10:23 -0700106u64 hw_nmi_get_sample_period(int watchdog_thresh);
Ulrich Obergfell84d56e62015-04-14 15:43:55 -0700107extern int nmi_watchdog_enabled;
108extern int soft_watchdog_enabled;
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200109extern int watchdog_user_enabled;
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700110extern int watchdog_thresh;
Babu Moger0ce66ee2016-12-14 15:06:21 -0800111extern unsigned long watchdog_enabled;
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700112extern unsigned long *watchdog_cpumask_bits;
Don Zickusb13b3b72017-01-24 15:17:53 -0800113extern atomic_t watchdog_park_in_progress;
Babu Moger0ce66ee2016-12-14 15:06:21 -0800114#ifdef CONFIG_SMP
Aaron Tomlined235872014-06-23 13:22:05 -0700115extern int sysctl_softlockup_all_cpu_backtrace;
Jiri Kosina55537872015-11-05 18:44:41 -0800116extern int sysctl_hardlockup_all_cpu_backtrace;
Babu Moger0ce66ee2016-12-14 15:06:21 -0800117#else
118#define sysctl_softlockup_all_cpu_backtrace 0
119#define sysctl_hardlockup_all_cpu_backtrace 0
120#endif
121extern bool is_hardlockup(void);
Don Zickus504d7cf2010-02-12 17:19:19 -0500122struct ctl_table;
Ulrich Obergfell83a80a32015-04-14 15:44:08 -0700123extern int proc_watchdog(struct ctl_table *, int ,
124 void __user *, size_t *, loff_t *);
125extern int proc_nmi_watchdog(struct ctl_table *, int ,
126 void __user *, size_t *, loff_t *);
127extern int proc_soft_watchdog(struct ctl_table *, int ,
128 void __user *, size_t *, loff_t *);
129extern int proc_watchdog_thresh(struct ctl_table *, int ,
130 void __user *, size_t *, loff_t *);
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700131extern int proc_watchdog_cpumask(struct ctl_table *, int,
132 void __user *, size_t *, loff_t *);
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700133extern int lockup_detector_suspend(void);
134extern void lockup_detector_resume(void);
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700135#else
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700136static inline int lockup_detector_suspend(void)
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700137{
138 return 0;
139}
140
Ulrich Obergfellec6a9062015-09-04 15:45:28 -0700141static inline void lockup_detector_resume(void)
Ulrich Obergfell999bbe42015-09-04 15:45:25 -0700142{
143}
Don Zickus84e478c2010-02-05 21:47:05 -0500144#endif
145
Tomasz Nowicki44a69f62014-07-22 11:20:12 +0200146#ifdef CONFIG_HAVE_ACPI_APEI_NMI
147#include <asm/nmi.h>
148#endif
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#endif