gpt4 book ai didi

c - linux 系统停止

转载 作者:IT王子 更新时间:2023-10-29 00:35:18 25 4
gpt4 key购买 nike

我正在查看 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 }

最佳答案

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.c irq_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);

What does a clean system halt mean?

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

I am also wondering about syscore what kind of operations are considered as syscore operation?

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

Can any one explain what this halt actually does?

This halt:切换到 0 CPU 核心,因为只有它可以重启或关机,运行所有已注册的预关机处理程序,然后打印“System halted”并要求硬件进行实际关机。

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();

关于c - linux 系统停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23720654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com