强制关闭Linux内核线程,Linux内核线程死锁或死循环之后如何让系统宕机重启

Based on kernel version 3.8. Page generated on 2013-02-20 22:01 EST.

===============================================================

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/kernel-parameters.txt" for

details), and a compile option, "BOOTPARAM_HARDLOCKUP_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 compile time knob,

"BOOTPARAM_HARDLOCKUP_PANIC", and a kernel parameter, "nmi_watchdog"

(see "Documentation/kernel-parameters.txt" 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

task. 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 task is a high priority kernel 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.0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值