關機時最後執行的功能是哪一個?

關機時最後執行的功能是哪一個?

我跟踪代碼並得到:

native_machine_shutdown()

https://elixir.bootlin.com/linux/latest/source/arch/x86/kernel/reboot.c#L682

但我沒有看到任何關閉電源或觸發哪個CPU暫存器斷電的程式碼?

我從那裡到達:

void kernel_power_off(void)
{
    kernel_shutdown_prepare(SYSTEM_POWER_OFF);
    if (pm_power_off_prepare)
        pm_power_off_prepare();
    migrate_to_reboot_cpu();
    syscore_shutdown();
    pr_emerg("Power down\n");
    kmsg_dump(KMSG_DUMP_SHUTDOWN);
    machine_power_off();
}

https://elixir.bootlin.com/linux/latest/source/kernel/reboot.c#L287

答案1

它在reboot.c,並且評論得很好。

static void native_machine_power_off(void)
{
    if (pm_power_off) {
        if (!reboot_force)
            machine_shutdown();
        pm_power_off();
    }
    /* A fallback in case there is no PM info available */
    tboot_shutdown(TB_SHUTDOWN_HALT);
}

所以,pm_power_off:現在是真的特定於平台;無論您使用的是遊戲機還是機架伺服器,情況都是不同的。

您可能正在尋找執行此操作的 EFI 驅動程式:

efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);

在驅動程式/韌體/efi/reboot.c

相關內容