Softlockup detector and hardlockup detector (aka nmi_watchdog) (翻译by chatgpt)
原文:https://www.kernel.org/doc/html/latest/admin-guide/lockup-watchdogs.html
The Linux kernel can act as a watchdog to detect both soft and hard lockups.
Linux内核可以作为一个看门狗来检测软件和硬件死锁。
A 'softlockup' is defined as a bug that causes the kernel to loop in kernel mode for more than 20 seconds (see "Implementation" below for details), without giving other tasks a chance to run. The current stack trace is displayed upon detection and, by default, the system will stay locked up. Alternatively, the kernel can be configured to panic; a sysctl, "kernel.softlockup_panic", a kernel parameter, "softlockup_panic" (see "The kernel's command-line parameters" for details), and a compile option, "BOOTPARAM_SOFTLOCKUP_PANIC", are provided for this.
所谓的“软死锁”是指导致内核在内核模式下循环超过20秒(有关详细信息,请参见下面的“实现”),而不给其他任务运行的机会的错误。在检测到软死锁时,会显示当前的堆栈跟踪,并且默认情况下系统将保持死锁状态。另外,内核可以配置为发生panic;有一个sysctl,“kernel.softlockup_panic”,一个内核参数,“softlockup_panic”(有关详细信息,请参见“内核的命令行参数”),以及一个编译选项,“BOOTPARAM_SOFTLOCKUP_PANIC”,用于此目的。
A 'hardlockup' is defined as a bug that causes the CPU to loop in kernel mode for more than 10 seconds (see "Implementation" below for details), without letting other interrupts have a chance to run. Similarly to the softlockup case, the current stack trace is displayed upon detection and the system will stay locked up unless the default behavior is changed, which can be done through a sysctl, 'hardlockup_panic', a compile time knob, "BOOTPARAM_HARDLOCKUP_PANIC", and a kernel parameter, "nmi_watchdog" (see "The kernel's command-line parameters" for details).
所谓的“硬死锁”是指导致CPU在内核模式下循环超过10秒(有关详细信息,请参见下面的“实现”),而不让其他中断有机会运行的错误。与软死锁情况类似,检测到硬死锁时会显示当前的堆栈跟踪,并且系统将保持死锁状态,除非更改默认行为,这可以通过sysctl,“hardlockup_panic”,一个编译时开关,“BOOTPARAM_HARDLOCKUP_PANIC”,以及一个内核参数,“nmi_watchdog”(有关详细信息,请参见“内核的命令行参数”)来实现。
The panic option can be used in combination with panic_timeout (this timeout is set through the confusingly named "kernel.panic" sysctl), to cause the system to reboot automatically after a specified amount of time.
panic选项可以与panic_timeout(通过令人困惑地命名为“kernel.panic” sysctl设置此超时)结合使用,以在指定的时间后自动导致系统重新启动。
Implementation
The soft and hard lockup detectors are built on top of the hrtimer and perf subsystems, respectively. A direct consequence of this is that, in principle, they should work in any architecture where these subsystems are present.
软死锁和硬死锁检测器是建立在hrtimer和perf子系统之上的。这样做的直接结果是,在原则上,它们应该在任何存在这些子系统的架构中工作。
A periodic hrtimer runs to generate interrupts and kick the watchdog job. An NMI perf event is generated every "watchdog_thresh" (compile-time initialized to 10 and configurable through sysctl of the same name) seconds to check for hardlockups. If any CPU in the system does not receive any hrtimer interrupt during that time the 'hardlockup detector' (the handler for the NMI perf event) will generate a kernel warning or call panic, depending on the configuration.
一个周期性的hrtimer运行以生成中断并启动看门狗任务。每隔“watchdog_thresh”(编译时初始化为10,并可通过同名的sysctl进行配置)秒生成一个NMI perf事件,以检查硬死锁。如果系统中的任何CPU在此期间没有收到任何hrtimer中断,则“硬死锁检测器”(NMI perf事件的处理程序)将生成内核警告或调用panic,具体取决于配置。
The watchdog job runs in a stop scheduling thread that updates a timestamp every time it is scheduled. If that timestamp is not updated for 2*watchdog_thresh seconds (the softlockup threshold) the 'softlockup detector' (coded inside the hrtimer callback function) will dump useful debug information to the system log, after which it will call panic if it was instructed to do so or resume execution of other kernel code.
看门狗任务在一个停止调度线程中运行,每次被调度时更新一个时间戳。如果该时间戳在2*watchdog_thresh秒(软死锁阈值)内没有更新,则“软死锁检测器”(编码在hrtimer回调函数内部)将向系统日志中转储有用的调试信息,然后根据指示调用panic或恢复执行其他内核代码。
The period of the hrtimer is 2*watchdog_thresh/5, which means it has two or three chances to generate an interrupt before the hardlockup detector kicks in.
hrtimer的周期是2*watchdog_thresh/5,这意味着它有两到三次机会在硬死锁检测器启动之前生成中断。
As explained above, a kernel knob is provided that allows administrators to configure the period of the hrtimer and the perf event. The right value for a particular environment is a trade-off between fast response to lockups and detection overhead.
如上所述,提供了一个内核开关,允许管理员配置hrtimer和perf事件的周期。对于特定环境的正确值是快速响应死锁和检测开销之间的权衡。
By default, the watchdog runs on all online cores. However, on a kernel configured with NO_HZ_FULL, by default the watchdog runs only on the housekeeping cores, not the cores specified in the "nohz_full" boot argument. If we allowed the watchdog to run by default on the "nohz_full" cores, we would have to run timer ticks to activate the scheduler, which would prevent the "nohz_full" functionality from protecting the user code on those cores from the kernel. Of course, disabling it by default on the nohz_full cores means that when those cores do enter the kernel, by default we will not be able to detect if they lock up. However, allowing the watchdog to continue to run on the housekeeping (non-tickless) cores means that we will continue to detect lockups properly on those cores.
默认情况下,看门狗在所有在线核心上运行。但是,在配置了NO_HZ_FULL的内核上,默认情况下,看门狗只在维护核心上运行,而不在“nohz_full”引导参数中指定的核心上运行。如果我们允许看门狗默认在“nohz_full”核心上运行,我们将不得不运行定时器滴答来激活调度器,这将阻止“nohz_full”功能保护这些核心上的用户代码免受内核的影响。当然,默认情况下在nohz_full核心上禁用它意味着当这些核心进入内核时,默认情况下我们将无法检测到它们是否死锁。然而,允许看门狗继续在维护(非无滴答)核心上运行意味着我们将继续正确地检测到这些核心上的死锁。
In either case, the set of cores excluded from running the watchdog may be adjusted via the kernel.watchdog_cpumask sysctl. For nohz_full cores, this may be useful for debugging a case where the kernel seems to be hanging on the nohz_full cores.
在任一情况下,排除不运行看门狗的核心集合可以通过kernel.watchdog_cpumask sysctl进行调整。对于nohz_full核心,这可能对调试内核似乎在nohz_full核心上挂起的情况很有用。
本文来自博客园,作者:dolinux,未经同意,禁止转载

浙公网安备 33010602011771号