요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
구현
lockup-watchdogs.rst:33-66hrtimer, perf NMI, watchdog thread와 threshold 계산을 설명합니다.
NO_HZ_FULL
lockup-watchdogs.rst:67-83housekeeping core 기본 동작과 watchdog_cpumask를 설명합니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
===============================================================
Softlockup detector and hardlockup detector (aka nmi_watchdog)
===============================================================
The Linux kernel can act as a watchdog to detect both soft and hard
lockups.
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 "Documentation/admin-guide/kernel-parameters.rst" for
details), and a compile option, "BOOTPARAM_SOFTLOCKUP_PANIC", are
provided for this.
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 "Documentation/admin-guide/kernel-parameters.rst" for details).
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.
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.
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.
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.
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.
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.
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.
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.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Softlockup·hardlockup 정의
1-32Linux kernel은 soft lockup과 hard lockup을 모두 감지하는 watchdog으로 동작할 수 있습니다.
softlockup은 kernel이 다른 task에 실행 기회를 주지 않고 kernel mode에서 20초 넘게 loop하는 bug입니다. 감지하면 current stack trace를 표시하고 기본적으로 system은 lockup 상태에 머뭅니다.
softlockup 때 panic하도록 `kernel.softlockup_panic` sysctl, `softlockup_panic` kernel parameter, `BOOTPARAM_SOFTLOCKUP_PANIC` compile option을 사용할 수 있습니다. parameter 상세는 `Documentation/admin-guide/kernel-parameters.rst`를 참조하십시오.
hardlockup은 CPU가 다른 interrupt를 실행할 기회를 주지 않고 kernel mode에서 10초 넘게 loop하는 bug입니다. 감지 시 stack trace를 표시하고 기본적으로 lockup 상태에 머뭅니다.
hardlockup panic은 `hardlockup_panic` sysctl, `BOOTPARAM_HARDLOCKUP_PANIC` compile-time knob, `nmi_watchdog` kernel parameter로 설정합니다.
panic option과 `panic_timeout`을 함께 사용하면 지정 시간이 지난 뒤 자동 reboot할 수 있습니다. 이 timeout을 설정하는 sysctl 이름은 다소 혼동스럽게도 `kernel.panic`입니다.
hrtimer·perf 구현
33-66softlockup detector는 hrtimer, hardlockup detector는 perf subsystem 위에 구현됩니다. 원칙적으로 이 subsystem이 있는 architecture에서 동작합니다.
periodic hrtimer가 interrupt를 만들고 watchdog job을 깨웁니다. `watchdog_thresh`초마다 NMI perf event를 생성해 hardlockup을 검사합니다. 이 값은 compile time에 `10`으로 초기화되고 같은 이름의 sysctl로 바꿀 수 있습니다.
해당 시간 동안 어느 CPU가 hrtimer interrupt를 하나도 받지 못하면 NMI perf event handler인 hardlockup detector가 configuration에 따라 kernel warning을 만들거나 panic을 호출합니다.
watchdog job은 scheduled될 때마다 timestamp를 갱신하는 stop-scheduling thread에서 실행됩니다. `2*watchdog_thresh`초 동안 timestamp가 갱신되지 않으면 hrtimer callback 내부 softlockup detector가 debug 정보를 system log에 dump하고, 지시된 경우 panic하거나 다른 kernel code 실행을 재개합니다.
hrtimer period는 `2*watchdog_thresh/5`이므로 hardlockup detector가 동작하기 전 interrupt를 만들 기회가 두세 번 있습니다.
administrator는 kernel knob으로 hrtimer와 perf event period를 설정할 수 있습니다. 적합한 값은 빠른 lockup response와 detection overhead 사이의 trade-off입니다.
NO_HZ_FULL과 watchdog CPU mask
67-83기본적으로 watchdog은 모든 online core에서 실행됩니다. `NO_HZ_FULL` kernel에서는 기본적으로 housekeeping core에서만 실행하고 `nohz_full` boot argument의 core에서는 실행하지 않습니다.
nohz_full core에서 watchdog을 실행하려면 scheduler 활성화를 위한 timer tick이 필요해 해당 core의 user code를 kernel로부터 보호하는 nohz_full 목적을 깨뜨립니다.
반대로 watchdog을 끄면 그 core가 kernel에 들어가 lockup해도 기본적으로 감지하지 못합니다. housekeeping(non-tickless) core에서는 계속 정상 감지합니다.
watchdog에서 제외할 core set은 `kernel.watchdog_cpumask` sysctl로 조정할 수 있습니다. nohz_full core에서 kernel hang을 debug할 때 유용합니다.
Lockup 정의
lockup-watchdogs.rst:1-32soft 20초, hard 10초 기준과 panic 설정을 설명합니다.