Kernel: Replace HPET CriticalScope with SpinLock

This commit is contained in:
Bananymous 2024-02-28 23:06:48 +02:00
parent 18253b6966
commit 682de62c57
2 changed files with 17 additions and 12 deletions

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <kernel/InterruptController.h> #include <kernel/InterruptController.h>
#include <kernel/Lock/SpinLock.h>
#include <kernel/Timer/Timer.h> #include <kernel/Timer/Timer.h>
namespace Kernel namespace Kernel
@ -30,6 +31,8 @@ namespace Kernel
uint64_t read_main_counter() const; uint64_t read_main_counter() const;
private: private:
mutable SpinLock m_lock;
bool m_is_64bit { false }; bool m_is_64bit { false };
uint64_t m_last_ticks { 0 }; uint64_t m_last_ticks { 0 };

View File

@ -244,7 +244,7 @@ namespace Kernel
if (m_is_64bit) if (m_is_64bit)
return regs.main_counter.full; return regs.main_counter.full;
CriticalScope _; SpinLockGuard _(m_lock);
uint32_t current_low = regs.main_counter.low; uint32_t current_low = regs.main_counter.low;
uint32_t wraps = m_32bit_wraps; uint32_t wraps = m_32bit_wraps;
if (current_low < (uint32_t)m_last_ticks) if (current_low < (uint32_t)m_last_ticks)
@ -256,19 +256,21 @@ namespace Kernel
{ {
auto& regs = registers(); auto& regs = registers();
uint64_t current_ticks;
if (m_is_64bit)
current_ticks = regs.main_counter.full;
else
{ {
uint32_t current_low = regs.main_counter.low; SpinLockGuard _(m_lock);
if (current_low < (uint32_t)m_last_ticks)
m_32bit_wraps++;
current_ticks = ((uint64_t)m_32bit_wraps << 32) | current_low;
}
m_last_ticks = current_ticks; uint64_t current_ticks;
if (m_is_64bit)
current_ticks = regs.main_counter.full;
else
{
uint32_t current_low = regs.main_counter.low;
if (current_low < (uint32_t)m_last_ticks)
m_32bit_wraps++;
current_ticks = ((uint64_t)m_32bit_wraps << 32) | current_low;
}
m_last_ticks = current_ticks;
}
Scheduler::get().timer_reschedule(); Scheduler::get().timer_reschedule();
} }