【问题标题】:System halt in linuxlinux系统停机
【发布时间】:2014-05-18 20:36:53
【问题描述】:

我正在查看 Linux 内核中的 reboot.c。

http://lxr.free-electrons.com/source/kernel/reboot.c

有一个对 kernel_halt 的调用,它说这个函数将 关闭一切并执行干净的系统停止。 干净的系统停止是什么意思? 任何人都可以解释这个停止实际上做了什么吗? 我也想知道 syscore 什么样的操作算是 syscore 操作?

  0 void kernel_halt(void)
    161 {
    162         kernel_shutdown_prepare(SYSTEM_HALT);
    163         migrate_to_reboot_cpu();
    164         syscore_shutdown();
    165         pr_emerg("System halted\n");
    166         kmsg_dump(KMSG_DUMP_HALT);
    167         machine_halt();
    168 }

【问题讨论】:

    标签: c linux kernel


    【解决方案1】:

    syscore_shutdown() 将检查所有已注册的 syscore 操作 (drivers/base/syscore.c"执行所有已注册的系统核心关闭回调。") 以查找非 NULL 操作 shutdown 并将执行它们。 Syscore操作使用register_syscore_ops注册,大多数驱动只注册syscore_ops的resumesuspend字段。

    对于 x86/x86_64 的 linux 内核版本 3.13,有部分带有 shutdown 字段的 syscore 注册列表:

    1)arch/x86/kernel/i8259.c:i8259A_shutdown

    261         /* Put the i8259A into a quiescent state that
    262          * the kernel initialization code can get it
    263          * out of.
    264          */
    265         outb(0xff, PIC_MASTER_IMR);     /* mask all of 8259A-1 */
    266         outb(0xff, PIC_SLAVE_IMR);      /* mask all of 8259A-2 */
    

    2) arch/x86/kernel/cpu/mcheck/mce.c, mce_syscore_shutdown 调用mce_disable_error_reporting

    2026  * Disable machine checks on suspend and shutdown. We can't really handle
    2027  * them later.
     ....
    2037                         wrmsrl(MSR_IA32_MCx_CTL(i), 0);
    

    3)kernel/irq/generic-chip.cirq_gc_shutdown:对于gc_list中的每个元素,尝试运行ct->chip.irq_pm_shutdown(data);; “@irq_pm_shutdown:每个芯片关闭时从核心代码调用的函数”(description)

    4)drivers/leds/trigger/ledtrig-cpu.c

     84 static void ledtrig_cpu_syscore_shutdown(void)
     85 {
     86         ledtrig_cpu(CPU_LED_HALTED);
     87 }
    ...
     61         case CPU_LED_HALTED:
     62                 /* Will turn the LED off */
     63                 led_trigger_event(trig->_trig, LED_OFF);
    

    干净的系统停止是什么意思?

    干净地卸载所有东西,关闭所有硬件。

    我也想知道关于syscore 什么样的操作算是syscore操作?

    Syscore 用于注册一些在挂起/恢复和关机时工作的函数。极少数驱动注册 syscore 关闭虚拟功能,例如:打开 PC 机箱 LED(not keyboard's leds 关闭,禁用中断,禁用机器检查(我认为像 ECC 错误,因为没有人将它们报告到系统日志), ...

    谁能解释一下这个停止实际上做了什么?

    此停止:切换到 0 CPU 内核,因为只有它可以重新启动或关闭,运行所有注册的预关闭处理程序,然后打印“系统停止”并要求硬件执行实际关机。

    162         kernel_shutdown_prepare(SYSTEM_HALT);
    163         migrate_to_reboot_cpu();
    164         syscore_shutdown();
    165         pr_emerg("System halted\n");
    166         kmsg_dump(KMSG_DUMP_HALT);
    167         machine_halt();
    

    【讨论】:

      猜你喜欢
      • 2010-09-08
      • 2011-02-17
      • 1970-01-01
      • 1970-01-01
      • 2011-10-28
      • 1970-01-01
      • 1970-01-01
      • 2012-06-30
      • 2015-08-07
      相关资源
      最近更新 更多