Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  linux/include/linux/nmi.h
0004  */
0005 #ifndef LINUX_NMI_H
0006 #define LINUX_NMI_H
0007 
0008 #include <linux/sched.h>
0009 #include <asm/irq.h>
0010 #if defined(CONFIG_HAVE_NMI_WATCHDOG)
0011 #include <asm/nmi.h>
0012 #endif
0013 
0014 #ifdef CONFIG_LOCKUP_DETECTOR
0015 void lockup_detector_init(void);
0016 void lockup_detector_soft_poweroff(void);
0017 void lockup_detector_cleanup(void);
0018 bool is_hardlockup(void);
0019 
0020 extern int watchdog_user_enabled;
0021 extern int nmi_watchdog_user_enabled;
0022 extern int soft_watchdog_user_enabled;
0023 extern int watchdog_thresh;
0024 extern unsigned long watchdog_enabled;
0025 
0026 extern struct cpumask watchdog_cpumask;
0027 extern unsigned long *watchdog_cpumask_bits;
0028 #ifdef CONFIG_SMP
0029 extern int sysctl_softlockup_all_cpu_backtrace;
0030 extern int sysctl_hardlockup_all_cpu_backtrace;
0031 #else
0032 #define sysctl_softlockup_all_cpu_backtrace 0
0033 #define sysctl_hardlockup_all_cpu_backtrace 0
0034 #endif /* !CONFIG_SMP */
0035 
0036 #else /* CONFIG_LOCKUP_DETECTOR */
0037 static inline void lockup_detector_init(void) { }
0038 static inline void lockup_detector_soft_poweroff(void) { }
0039 static inline void lockup_detector_cleanup(void) { }
0040 #endif /* !CONFIG_LOCKUP_DETECTOR */
0041 
0042 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
0043 extern void touch_softlockup_watchdog_sched(void);
0044 extern void touch_softlockup_watchdog(void);
0045 extern void touch_softlockup_watchdog_sync(void);
0046 extern void touch_all_softlockup_watchdogs(void);
0047 extern unsigned int  softlockup_panic;
0048 
0049 extern int lockup_detector_online_cpu(unsigned int cpu);
0050 extern int lockup_detector_offline_cpu(unsigned int cpu);
0051 #else /* CONFIG_SOFTLOCKUP_DETECTOR */
0052 static inline void touch_softlockup_watchdog_sched(void) { }
0053 static inline void touch_softlockup_watchdog(void) { }
0054 static inline void touch_softlockup_watchdog_sync(void) { }
0055 static inline void touch_all_softlockup_watchdogs(void) { }
0056 
0057 #define lockup_detector_online_cpu  NULL
0058 #define lockup_detector_offline_cpu NULL
0059 #endif /* CONFIG_SOFTLOCKUP_DETECTOR */
0060 
0061 #ifdef CONFIG_DETECT_HUNG_TASK
0062 void reset_hung_task_detector(void);
0063 #else
0064 static inline void reset_hung_task_detector(void) { }
0065 #endif
0066 
0067 /*
0068  * The run state of the lockup detectors is controlled by the content of the
0069  * 'watchdog_enabled' variable. Each lockup detector has its dedicated bit -
0070  * bit 0 for the hard lockup detector and bit 1 for the soft lockup detector.
0071  *
0072  * 'watchdog_user_enabled', 'nmi_watchdog_user_enabled' and
0073  * 'soft_watchdog_user_enabled' are variables that are only used as an
0074  * 'interface' between the parameters in /proc/sys/kernel and the internal
0075  * state bits in 'watchdog_enabled'. The 'watchdog_thresh' variable is
0076  * handled differently because its value is not boolean, and the lockup
0077  * detectors are 'suspended' while 'watchdog_thresh' is equal zero.
0078  */
0079 #define NMI_WATCHDOG_ENABLED_BIT   0
0080 #define SOFT_WATCHDOG_ENABLED_BIT  1
0081 #define NMI_WATCHDOG_ENABLED      (1 << NMI_WATCHDOG_ENABLED_BIT)
0082 #define SOFT_WATCHDOG_ENABLED     (1 << SOFT_WATCHDOG_ENABLED_BIT)
0083 
0084 #if defined(CONFIG_HARDLOCKUP_DETECTOR)
0085 extern void hardlockup_detector_disable(void);
0086 extern unsigned int hardlockup_panic;
0087 #else
0088 static inline void hardlockup_detector_disable(void) {}
0089 #endif
0090 
0091 #if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
0092 # define NMI_WATCHDOG_SYSCTL_PERM   0644
0093 #else
0094 # define NMI_WATCHDOG_SYSCTL_PERM   0444
0095 #endif
0096 
0097 #if defined(CONFIG_HARDLOCKUP_DETECTOR_PERF)
0098 extern void arch_touch_nmi_watchdog(void);
0099 extern void hardlockup_detector_perf_stop(void);
0100 extern void hardlockup_detector_perf_restart(void);
0101 extern void hardlockup_detector_perf_disable(void);
0102 extern void hardlockup_detector_perf_enable(void);
0103 extern void hardlockup_detector_perf_cleanup(void);
0104 extern int hardlockup_detector_perf_init(void);
0105 #else
0106 static inline void hardlockup_detector_perf_stop(void) { }
0107 static inline void hardlockup_detector_perf_restart(void) { }
0108 static inline void hardlockup_detector_perf_disable(void) { }
0109 static inline void hardlockup_detector_perf_enable(void) { }
0110 static inline void hardlockup_detector_perf_cleanup(void) { }
0111 # if !defined(CONFIG_HAVE_NMI_WATCHDOG)
0112 static inline int hardlockup_detector_perf_init(void) { return -ENODEV; }
0113 static inline void arch_touch_nmi_watchdog(void) {}
0114 # else
0115 static inline int hardlockup_detector_perf_init(void) { return 0; }
0116 # endif
0117 #endif
0118 
0119 void watchdog_nmi_stop(void);
0120 void watchdog_nmi_start(void);
0121 int watchdog_nmi_probe(void);
0122 int watchdog_nmi_enable(unsigned int cpu);
0123 void watchdog_nmi_disable(unsigned int cpu);
0124 
0125 void lockup_detector_reconfigure(void);
0126 
0127 /**
0128  * touch_nmi_watchdog - restart NMI watchdog timeout.
0129  *
0130  * If the architecture supports the NMI watchdog, touch_nmi_watchdog()
0131  * may be used to reset the timeout - for code which intentionally
0132  * disables interrupts for a long time. This call is stateless.
0133  */
0134 static inline void touch_nmi_watchdog(void)
0135 {
0136     arch_touch_nmi_watchdog();
0137     touch_softlockup_watchdog();
0138 }
0139 
0140 /*
0141  * Create trigger_all_cpu_backtrace() out of the arch-provided
0142  * base function. Return whether such support was available,
0143  * to allow calling code to fall back to some other mechanism:
0144  */
0145 #ifdef arch_trigger_cpumask_backtrace
0146 static inline bool trigger_all_cpu_backtrace(void)
0147 {
0148     arch_trigger_cpumask_backtrace(cpu_online_mask, false);
0149     return true;
0150 }
0151 
0152 static inline bool trigger_allbutself_cpu_backtrace(void)
0153 {
0154     arch_trigger_cpumask_backtrace(cpu_online_mask, true);
0155     return true;
0156 }
0157 
0158 static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
0159 {
0160     arch_trigger_cpumask_backtrace(mask, false);
0161     return true;
0162 }
0163 
0164 static inline bool trigger_single_cpu_backtrace(int cpu)
0165 {
0166     arch_trigger_cpumask_backtrace(cpumask_of(cpu), false);
0167     return true;
0168 }
0169 
0170 /* generic implementation */
0171 void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
0172                    bool exclude_self,
0173                    void (*raise)(cpumask_t *mask));
0174 bool nmi_cpu_backtrace(struct pt_regs *regs);
0175 
0176 #else
0177 static inline bool trigger_all_cpu_backtrace(void)
0178 {
0179     return false;
0180 }
0181 static inline bool trigger_allbutself_cpu_backtrace(void)
0182 {
0183     return false;
0184 }
0185 static inline bool trigger_cpumask_backtrace(struct cpumask *mask)
0186 {
0187     return false;
0188 }
0189 static inline bool trigger_single_cpu_backtrace(int cpu)
0190 {
0191     return false;
0192 }
0193 #endif
0194 
0195 #ifdef CONFIG_HARDLOCKUP_DETECTOR_PERF
0196 u64 hw_nmi_get_sample_period(int watchdog_thresh);
0197 #endif
0198 
0199 #if defined(CONFIG_HARDLOCKUP_CHECK_TIMESTAMP) && \
0200     defined(CONFIG_HARDLOCKUP_DETECTOR)
0201 void watchdog_update_hrtimer_threshold(u64 period);
0202 #else
0203 static inline void watchdog_update_hrtimer_threshold(u64 period) { }
0204 #endif
0205 
0206 struct ctl_table;
0207 int proc_watchdog(struct ctl_table *, int, void *, size_t *, loff_t *);
0208 int proc_nmi_watchdog(struct ctl_table *, int , void *, size_t *, loff_t *);
0209 int proc_soft_watchdog(struct ctl_table *, int , void *, size_t *, loff_t *);
0210 int proc_watchdog_thresh(struct ctl_table *, int , void *, size_t *, loff_t *);
0211 int proc_watchdog_cpumask(struct ctl_table *, int, void *, size_t *, loff_t *);
0212 
0213 #ifdef CONFIG_HAVE_ACPI_APEI_NMI
0214 #include <asm/nmi.h>
0215 #endif
0216 
0217 #endif