linux内核研究--watchdog实现分析

本文深入探讨Linux内核的watchdog机制,包括软锁up和硬锁up检测。通过分析`watchdog.c`文件,了解watchdog线程如何通过高精度定时器监测系统,防止CPU长时间无响应。当检测到潜在的锁up情况时,系统将触发警告或采取相应措施。
摘要由CSDN通过智能技术生成

/kernel/watchdog.c

tatic DEFINE_PER_CPU(unsigned long, watchdog_touch_ts);  //记录是时间戳,主要在watchdog线程中更新

static DEFINE_PER_CPU(struct task_struct *, softlockup_watchdog);

static DEFINE_PER_CPU(struct hrtimer, watchdog_hrtimer);

static DEFINE_PER_CPU(bool, softlockup_touch_sync);

static DEFINE_PER_CPU(bool, soft_watchdog_warn);

static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts);   //在hrtimer处理函数中更新

static DEFINE_PER_CPU(unsigned long, soft_lockup_hrtimer_cnt);

static DEFINE_PER_CPU(struct task_struct *, softlockup_task_ptr_saved);

#ifdef CONFIG_HARDLOCKUP_DETECTOR

static DEFINE_PER_CPU(bool, hard_watchdog_warn);

static DEFINE_PER_CPU(bool, watchdog_nmi_touch);

static DEFINE_PER_CPU(unsigned long, hrtimer_interrupts_saved);  //在is_hardlockup中更新,更新为hrtimer_interrupts

static DEFINE_PER_CPU(struct perf_event *, watchdog_ev);

 

 

/* Commands for resetting the watchdog */

static void __touch_watchdog(void)

{

__this_cpu_write(watchdog_touch_ts, get_timestamp());

}

static void watchdog(unsigned int cpu)

{

__this_cpu_write(soft_lockup_hrtimer_cnt,

 __this_cpu_read(hrtimer_interrupts));

__touch_watchdog();

}

static struct smp_hotplug_thread watchdog_threads = {

.store                        = &softlockup_watchdog,

.thread_should_run        = watchdog_should_run,

.thread_fn                = watchdog,                                //线程函数就是更新当前CPU的watchdog_touch_ts变量的值

.thread_comm                = "watchdog/%u",

.setup                        = watchdog_enable,

.cleanup                = watchdog_cleanup,

.park                        = watchdog_disable,

.unpark                        = watchdog_enable,

};

 

 

 

//启动nmi中断来检查hardlockup

//启动了一个高精度定时器,定时器的处理函数watchdog_timer_fn 负责检查是否发生了softlockup

static void watchdog_enable(unsigned int cpu)

{

struct hrtimer *hrtimer = raw_cpu_ptr(&watchdog_hrtimer);

 

/* kick off the timer for the hardlockup detector */

hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRT

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值