mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 01:10:28 +03:00
Kernel: Merge PowerStateSwitchTask reboot and shutdown procedures
The reboot procedure should prepare to "shutdown" the system cleanly and therefore has to be merged with how shutdown is handled.
This commit is contained in:
parent
b81b2c3fe7
commit
ef6133337e
Notes:
sideshowbarker
2024-07-17 01:23:08 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/ef6133337e Pull-request: https://github.com/SerenityOS/serenity/pull/20665 Issue: https://github.com/SerenityOS/serenity/issues/20560 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/BertalanD
@ -35,10 +35,10 @@ void PowerStateSwitchTask::power_state_switch_task(void* raw_entry_data)
|
|||||||
auto entry_data = bit_cast<PowerStateCommand>(raw_entry_data);
|
auto entry_data = bit_cast<PowerStateCommand>(raw_entry_data);
|
||||||
switch (entry_data) {
|
switch (entry_data) {
|
||||||
case PowerStateCommand::Shutdown:
|
case PowerStateCommand::Shutdown:
|
||||||
MUST(PowerStateSwitchTask::perform_shutdown());
|
MUST(PowerStateSwitchTask::perform_shutdown(DoReboot::No));
|
||||||
break;
|
break;
|
||||||
case PowerStateCommand::Reboot:
|
case PowerStateCommand::Reboot:
|
||||||
MUST(PowerStateSwitchTask::perform_reboot());
|
MUST(PowerStateSwitchTask::perform_shutdown(DoReboot::Yes));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PANIC("Unknown power state command: {}", to_underlying(entry_data));
|
PANIC("Unknown power state command: {}", to_underlying(entry_data));
|
||||||
@ -57,24 +57,7 @@ void PowerStateSwitchTask::spawn(PowerStateCommand command)
|
|||||||
g_power_state_switch_task = move(power_state_switch_task_thread);
|
g_power_state_switch_task = move(power_state_switch_task_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> PowerStateSwitchTask::perform_reboot()
|
ErrorOr<void> PowerStateSwitchTask::perform_shutdown(PowerStateSwitchTask::DoReboot do_reboot)
|
||||||
{
|
|
||||||
dbgln("acquiring FS locks...");
|
|
||||||
FileSystem::lock_all();
|
|
||||||
dbgln("syncing mounted filesystems...");
|
|
||||||
FileSystem::sync();
|
|
||||||
|
|
||||||
dbgln("attempting reboot via ACPI");
|
|
||||||
if (ACPI::is_enabled())
|
|
||||||
ACPI::Parser::the()->try_acpi_reboot();
|
|
||||||
arch_specific_reboot();
|
|
||||||
|
|
||||||
dbgln("reboot attempts failed, applications will stop responding.");
|
|
||||||
dmesgln("Reboot can't be completed. It's safe to turn off the computer!");
|
|
||||||
Processor::halt();
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorOr<void> PowerStateSwitchTask::perform_shutdown()
|
|
||||||
{
|
{
|
||||||
// We assume that by this point userland has tried as much as possible to shut down everything in an orderly fashion.
|
// We assume that by this point userland has tried as much as possible to shut down everything in an orderly fashion.
|
||||||
// Therefore, we force kill remaining processes, including Kernel processes, except the finalizer and ourselves.
|
// Therefore, we force kill remaining processes, including Kernel processes, except the finalizer and ourselves.
|
||||||
@ -146,13 +129,25 @@ ErrorOr<void> PowerStateSwitchTask::perform_shutdown()
|
|||||||
// Therefore, we just lock the scheduler big lock to ensure nothing happens
|
// Therefore, we just lock the scheduler big lock to ensure nothing happens
|
||||||
// beyond this point forward.
|
// beyond this point forward.
|
||||||
SpinlockLocker lock(g_scheduler_lock);
|
SpinlockLocker lock(g_scheduler_lock);
|
||||||
|
|
||||||
|
if (do_reboot == DoReboot::Yes) {
|
||||||
|
dbgln("Attempting system reboot...");
|
||||||
|
dbgln("attempting reboot via ACPI");
|
||||||
|
if (ACPI::is_enabled())
|
||||||
|
ACPI::Parser::the()->try_acpi_reboot();
|
||||||
|
arch_specific_reboot();
|
||||||
|
|
||||||
|
dmesgln("Reboot can't be completed. It's safe to turn off the computer!");
|
||||||
|
Processor::halt();
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
VERIFY(do_reboot == DoReboot::No);
|
||||||
|
|
||||||
dbgln("Attempting system shutdown...");
|
dbgln("Attempting system shutdown...");
|
||||||
|
|
||||||
arch_specific_poweroff();
|
arch_specific_poweroff();
|
||||||
|
|
||||||
dbgln("shutdown attempts failed, applications will stop responding.");
|
|
||||||
dmesgln("Shutdown can't be completed. It's safe to turn off the computer!");
|
dmesgln("Shutdown can't be completed. It's safe to turn off the computer!");
|
||||||
Processor::halt();
|
Processor::halt();
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> PowerStateSwitchTask::kill_all_user_processes()
|
ErrorOr<void> PowerStateSwitchTask::kill_all_user_processes()
|
||||||
|
@ -29,10 +29,13 @@ private:
|
|||||||
static void spawn(PowerStateCommand);
|
static void spawn(PowerStateCommand);
|
||||||
|
|
||||||
static void power_state_switch_task(void* raw_entry_data);
|
static void power_state_switch_task(void* raw_entry_data);
|
||||||
static ErrorOr<void> perform_reboot();
|
|
||||||
static ErrorOr<void> perform_shutdown();
|
|
||||||
|
|
||||||
static ErrorOr<void> kill_all_user_processes();
|
static ErrorOr<void> kill_all_user_processes();
|
||||||
|
enum class DoReboot {
|
||||||
|
No,
|
||||||
|
Yes,
|
||||||
|
};
|
||||||
|
static ErrorOr<void> perform_shutdown(DoReboot);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user