Kernel: APs now start their idle threads when scheduler is started

This commit is contained in:
Bananymous 2024-03-09 23:51:40 +02:00
parent 55d2a64f54
commit 45d6caa1d0
3 changed files with 11 additions and 3 deletions

View File

@ -12,6 +12,7 @@ namespace Kernel
public: public:
static BAN::ErrorOr<void> initialize(); static BAN::ErrorOr<void> initialize();
static Scheduler& get(); static Scheduler& get();
static bool is_started();
[[noreturn]] void start(); [[noreturn]] void start();

View File

@ -15,6 +15,7 @@ namespace Kernel
extern "C" [[noreturn]] void continue_thread(uintptr_t rsp, uintptr_t rip); extern "C" [[noreturn]] void continue_thread(uintptr_t rsp, uintptr_t rip);
static Scheduler* s_instance = nullptr; static Scheduler* s_instance = nullptr;
static BAN::Atomic<bool> s_started { false };
ALWAYS_INLINE static void load_temp_stack() ALWAYS_INLINE static void load_temp_stack()
{ {
@ -40,12 +41,17 @@ namespace Kernel
{ {
ASSERT(Processor::get_interrupt_state() == InterruptState::Disabled); ASSERT(Processor::get_interrupt_state() == InterruptState::Disabled);
m_lock.lock(); m_lock.lock();
ASSERT(!m_active_threads.empty()); s_started = true;
advance_current_thread(); advance_current_thread();
execute_current_thread_locked(); execute_current_thread_locked();
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
bool Scheduler::is_started()
{
return s_started;
}
Thread& Scheduler::current_thread() Thread& Scheduler::current_thread()
{ {
auto* current = Processor::get_current_thread(); auto* current = Processor::get_current_thread();

View File

@ -217,6 +217,7 @@ extern "C" void ap_main()
dprintln("ap{} initialized", Processor::current_id()); dprintln("ap{} initialized", Processor::current_id());
for (;;) while (!Scheduler::is_started())
asm volatile("hlt"); __builtin_ia32_pause();
Scheduler::get().start();
} }