Kernel: Change preemption condition

Instead of keeping track of the current time and rescheduling when
interval has passed, keep track of the next expected reschedule time.
This prevents theoretically missing every second pre-emption when
scheduler's timer is interrupting at same rate as the interval.
This commit is contained in:
2026-04-07 03:59:08 +03:00
parent 80c4213501
commit 9084d9305c
2 changed files with 6 additions and 7 deletions

View File

@@ -101,7 +101,7 @@ namespace Kernel
InterruptStack* m_interrupt_stack { nullptr };
InterruptRegisters* m_interrupt_registers { nullptr };
uint64_t m_last_reschedule_ns { 0 };
uint64_t m_next_reschedule_ns { 0 };
uint64_t m_last_load_balance_ns { 0 };
struct ThreadInfo

View File

@@ -139,6 +139,8 @@ namespace Kernel
if (Processor::count() > 1)
Processor::set_smp_enabled();
m_next_reschedule_ns = SystemTimer::get().ns_since_boot();
return {};
}
@@ -348,13 +350,10 @@ namespace Kernel
wake_up_sleeping_threads();
if (SystemTimer::get().ns_since_boot() >= m_next_reschedule_ns)
{
const uint64_t current_ns = SystemTimer::get().ns_since_boot();
if (current_ns >= m_last_reschedule_ns + s_reschedule_interval_ns)
{
m_last_reschedule_ns = current_ns;
Processor::yield();
}
m_next_reschedule_ns += s_reschedule_interval_ns;
Processor::yield();
}
}