// SPDX-License-Identifier: GPL-2.0/* * Detect hard and soft lockups on a system * * started by Don Zickus, Copyright (C) 2010 Red Hat, Inc. * * Note: Most of this code is borrowed heavily from the original softlockup * detector, so thanks to Ingo for the initial implementation. * Some chunks also taken from the old x86-specific nmi watchdog code, thanks * to those contributors as well. */#define pr_fmt(fmt) "watchdog: " fmt#include<linux/cpu.h>#include<linux/init.h>#include<linux/irq.h>#include<linux/irqdesc.h>#include<linux/kernel_stat.h>#include<linux/kvm_para.h>#include<linux/math64.h>#include<linux/mm.h>#include<linux/module.h>#include<linux/nmi.h>#include<linux/stop_machine.h>#include<linux/sysctl.h>#include<linux/tick.h>#include<linux/sys_info.h>#include<linux/sched/clock.h>#include<linux/sched/debug.h>#include<linux/sched/isolation.h>#include<asm/irq_regs.h>staticDEFINE_MUTEX(watchdog_mutex);#if defined(CONFIG_HARDLOCKUP_DETECTOR) || defined(CONFIG_HARDLOCKUP_DETECTOR_SPARC64)# define WATCHDOG_HARDLOCKUP_DEFAULT 1#else# define WATCHDOG_HARDLOCKUP_DEFAULT 0#endif#define NUM_SAMPLE_PERIODS 5unsignedlong__read_mostlywatchdog_enabled;int__read_mostlywatchdog_user_enabled=1;staticint__read_mostlywatchdog_hardlockup_user_enabled=WATCHDOG_HARDLOCKUP_DEFAULT;staticint__read_mostlywatchdog_softlockup_user_enabled=1;int__read_mostlywatchdog_thresh=10;staticint__read_mostlywatchdog_thresh_next;staticint__read_mostlywatchdog_hardlockup_available;structcpumaskwatchdog_cpumask__read_mostly;unsignedlong*watchdog_cpumask_bits=cpumask_bits(&watchdog_cpumask);#ifdef CONFIG_HARDLOCKUP_DETECTOR# ifdef CONFIG_SMPint__read_mostlysysctl_hardlockup_all_cpu_backtrace;# endif /* CONFIG_SMP *//* * Number of consecutive missed interrupts before declaring a lockup. * Default to 1 (immediate) for NMI/Perf. Buddy will overwrite this to 3. */int__read_mostlywatchdog_hardlockup_miss_thresh=1;EXPORT_SYMBOL_GPL(watchdog_hardlockup_miss_thresh);/* * Should we panic when a soft-lockup or hard-lockup occurs: */unsignedint__read_mostlyhardlockup_panic=IS_ENABLED(CONFIG_BOOTPARAM_HARDLOCKUP_PANIC