国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
softlockup檢測(watchdog)原理(用于檢測系統(tǒng)調度是否正常)
摘自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=14528823&id=4215888    
softlockup(watchdog)用于檢測系統(tǒng)調度是否正常,即軟鎖的情況,當發(fā)生softlockup時,內核不能調度,但還能響應中斷,對用戶的表現(xiàn)可能為:能ping通,但無法登陸系統(tǒng),無法進行正常操作。
其基本原理為:為每個CPU啟動一個內核線程(watchdog/x),此線程為優(yōu)先級最高的實時線程,在該線程得到調度時,會更新相應的計數(shù)(時間戳),同時會啟動定時器,當定時器到期時檢查相應的時間戳,如果超過指定時間,都沒有更新,則說明這段時間內都沒有發(fā)生調度(因為此線程優(yōu)先級最高),則打印相應告警或根據配置可以進入panic流程。
基本代碼分析(2.6.32)
rest_init->kernel_init->lockup_detector_init->cpu_callback->watchdog_prepare_cpu(初始化watchdog定時器):

點擊(此處)折疊或打開

  1. static int watchdog_prepare_cpu(int cpu)
  2. {
  3.     struct hrtimer *hrtimer = &per_cpu(watchdog_hrtimer, cpu);

  4.     WARN_ON(per_cpu(softlockup_watchdog, cpu));
  5.     hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);//初始化高精度定時器
  6.     hrtimer->function = watchdog_timer_fn;//設置定時器處理函數(shù)

  7.     return 0;
  8. }
看門狗定時器處理函數(shù):

點擊(此處)折疊或打開

  1. static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
  2. {
  3. //獲取計數(shù)watchdog_touch_ts,該計數(shù)在watchdog內核線程被調度時更新
  4.     unsigned long touch_ts = __get_cpu_var(watchdog_touch_ts);
  5.     struct pt_regs *regs = get_irq_regs();
  6.     int duration;

  7.     /* kick the hardlockup detector */
  8. //增加中斷計數(shù),證明沒有發(fā)生硬鎖(關中斷死鎖)
  9.     watchdog_interrupt_count();

  10.     /* kick the softlockup detector */
  11. //喚醒wathdog內核線程
  12.     wake_up_process(__get_cpu_var(softlockup_watchdog));

  13.     /* .. and repeat */
  14. //重啟定時器
  15.     hrtimer_forward_now(hrtimer, ns_to_ktime(get_sample_period()));
  16.     if (touch_ts == 0) {
  17.         if (unlikely(__get_cpu_var(softlockup_touch_sync))) {
  18.             /*
  19.              * If the time stamp was touched atomically
  20.              * make sure the scheduler tick is up to date.
  21.              */
  22.             __get_cpu_var(softlockup_touch_sync) = false;
  23.             sched_clock_tick();
  24.         }
  25.         __touch_watchdog();
  26.         return HRTIMER_RESTART;
  27.     }

  28.     /* check for a softlockup
  29.      * This is done by making sure a high priority task is
  30.      * being scheduled. The task touches the watchdog to
  31.      * indicate it is getting cpu time. If it hasn't then
  32.      * this is a good indication some task is hogging the cpu
  33.      */
  34. //判斷是否發(fā)生了軟鎖,原理是判斷touch_ts(時間戳)是否超過一定時間沒有更新
  35.     duration = is_softlockup(touch_ts);
  36.     if (unlikely(duration)) {
  37.         /* only warn once */
  38.         if (__get_cpu_var(soft_watchdog_warn) == true)
  39.             return HRTIMER_RESTART;
  40. //發(fā)生了軟鎖后,進行一些列的信息記錄和告警。
  41.         printk(KERN_EMERG "BUG: soft lockup - CPU#%d stuck for %us! [%s:%d]\n",
  42.             smp_processor_id(), duration,
  43.             current->comm, task_pid_nr(current));
  44.         print_modules();
  45.         print_irqtrace_events(current);
  46.         if (regs)
  47.             show_regs(regs);
  48.         else
  49.             dump_stack();
  50. //如果配置了softlockup_panic(proc中配置),則panic
  51.         if (softlockup_panic)
  52.             panic("softlockup: hung tasks");
  53.         __get_cpu_var(soft_watchdog_warn) = true;
  54.     } else
  55.         __get_cpu_var(soft_watchdog_warn) = false;

  56.     return HRTIMER_RESTART;
  57. }

啟動看門狗,即創(chuàng)建watchdog內核線程。

點擊(此處)折疊或打開

  1. static int watchdog_enable(int cpu)
  2. {
  3.     struct task_struct *p = per_cpu(softlockup_watchdog, cpu);
  4.     int err = 0;

  5.     /* enable the perf event */
  6.     err = watchdog_nmi_enable(cpu);

  7.     /* Regardless of err above, fall through and start softlockup */

  8.     /* create the watchdog thread */
  9.     if (!p) {
  10. //創(chuàng)建watchdog內核線程
  11.         p = kthread_create(watchdog, (void *)(unsigned long)cpu, "watchdog/%d", cpu);
  12.         if (IS_ERR(p)) {
  13.             printk(KERN_ERR "softlockup watchdog for %i failed\n", cpu);
  14.             if (!err)
  15.                 /* if hardlockup hasn't already set this */
  16.                 err = PTR_ERR(p);
  17.             goto out;
  18.         }
  19.         kthread_bind(p, cpu);
  20.         per_cpu(watchdog_touch_ts, cpu) = 0;
  21.         per_cpu(softlockup_watchdog, cpu) = p;
  22.         wake_up_process(p);
  23.     }

  24. out:
  25.     return err;
  26. }

watchdog內核線程執(zhí)行主函數(shù),主要是要更新計數(shù)(時間戳)

點擊(此處)折疊或打開

  1. static int watchdog(void *unused)
  2. {
  3. //設置為最高優(yōu)先級
  4.     struct sched_param param = { .sched_priority = MAX_RT_PRIO-1 };
  5.     struct hrtimer *hrtimer = &__raw_get_cpu_var(watchdog_hrtimer);
  6. //設置為實時線程
  7.     sched_setscheduler(current, SCHED_FIFO, &param);

  8.     /* initialize timestamp */
  9. //初始化計數(shù)(時間戳)
  10.     __touch_watchdog();

  11.     /* kick off the timer for the hardlockup detector */
  12.     /* done here because hrtimer_start can only pin to smp_processor_id() */
  13. //啟動定時器,用于檢測是否發(fā)生軟鎖
  14.     hrtimer_start(hrtimer, ns_to_ktime(get_sample_period()),
  15.          HRTIMER_MODE_REL_PINNED);
  16. //睡眠
  17.     set_current_state(TASK_INTERRUPTIBLE);
  18.     /*
  19.      * Run briefly once per second to reset the softlockup timestamp.
  20.      * If this gets delayed for more than 60 seconds then the
  21.      * debug-printout triggers in watchdog_timer_fn().
  22.      */
  23.     while (!kthread_should_stop()) {
  24. //更新計數(shù)
  25.         __touch_watchdog();
  26.         schedule();

  27.         if (kthread_should_stop())
  28.             break;

  29.         set_current_state(TASK_INTERRUPTIBLE);
  30.     }
  31.     __set_current_state(TASK_RUNNING);

  32.     return 0;
  33. }

判斷是否發(fā)生軟鎖:is_softlockup

點擊(此處)折疊或打開

  1. static int is_softlockup(unsigned long touch_ts)
  2. {
  3.     unsigned long now = get_timestamp(smp_processor_id());

  4.     /* Warn about unreasonable delays: */
  5. //檢測計數(shù)多久沒有更新了,如果超過了60s,則表示發(fā)生了軟鎖
  6.     if (time_after(now, touch_ts + softlockup_thresh))
  7.         return now - touch_ts;

  8.     return 0;
  9. }

本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
watchdog(二)
linux 內核筆記之watchdog
淺談linux的死鎖檢測
嵌套OOPS導致系統(tǒng)卡死 每個CPU都上報softlockup的問題
GTP968(ic)觸摸屏調試實際代碼的分析
delay work and hrtimer
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服