From 0843b8989d4d450a2ecf8ea29e9296c9e519b01c Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 7 Jul 2026 05:59:34 +0300 Subject: [PATCH] Kernel: Fix timer deadline issues in scheduler Don't wake up threads when getting the next timer deadline. If we are idling this can: remove thread from block list, get the deadline for the next blocked thread, return to idle thread. This will end up sleeping until the next wake up condition which in the worst case would be rebalance, or indefinitely when not running SMP. Make sure we always set the next timer deadline. I was not doing that if the timer interrupt did not lead to a yield --- kernel/kernel/Scheduler.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/kernel/Scheduler.cpp b/kernel/kernel/Scheduler.cpp index 82d4deea..c3d50f70 100644 --- a/kernel/kernel/Scheduler.cpp +++ b/kernel/kernel/Scheduler.cpp @@ -326,8 +326,6 @@ namespace Kernel if (!interrupt_controller.is_using_apic()) return; - wake_up_sleeping_threads(); - uint64_t deadline_ns = m_next_reschedule_ns; if (!m_block_queue.empty()) deadline_ns = BAN::Math::min(deadline_ns, m_block_queue.front()->wake_time_ns); @@ -368,8 +366,12 @@ namespace Kernel wake_up_sleeping_threads(); + // NOTE: yield will update the timer deadline, but if we do not yield make sure + // we set the next deadline or we won't get another timer interrupt if (is_idle() || SystemTimer::get().ns_since_boot() >= m_next_reschedule_ns) Processor::yield(); + else + update_wake_up_deadline(); } void Scheduler::unblock_thread(SchedulerQueue::Node* node)