Kernel: Move interrupt status stuff to Processor.h

SpinLocks are now locked with processor id instead of thread id. This
allows having multiple processors running while scheduler is not yet
activated.
This commit is contained in:
2024-03-03 01:47:22 +02:00
parent efd8203232
commit 1de9daa40f
3 changed files with 31 additions and 21 deletions

View File

@@ -9,38 +9,38 @@ namespace Kernel
InterruptState SpinLock::lock()
{
auto tid = Scheduler::current_tid();
ASSERT_NEQ(m_locker.load(), tid);
auto id = get_processor_id();
ASSERT_NEQ(m_locker.load(), id);
auto state = get_interrupt_state();
set_interrupt_state(InterruptState::Disabled);
if (!m_locker.compare_exchange(-1, tid))
ASSERT_NOT_REACHED();
while (!m_locker.compare_exchange(PROCESSOR_NONE, id, BAN::MemoryOrder::memory_order_acquire))
__builtin_ia32_pause();
return state;
}
void SpinLock::unlock(InterruptState state)
{
ASSERT_EQ(m_locker.load(), Scheduler::current_tid());
m_locker.store(-1);
ASSERT_EQ(m_locker.load(), get_processor_id());
m_locker.store(PROCESSOR_NONE, BAN::MemoryOrder::memory_order_release);
set_interrupt_state(state);
}
InterruptState RecursiveSpinLock::lock()
{
auto tid = Scheduler::current_tid();
auto id = get_processor_id();
auto state = get_interrupt_state();
set_interrupt_state(InterruptState::Disabled);
if (tid == m_locker)
if (id == m_locker)
ASSERT_GT(m_lock_depth, 0);
else
{
if (!m_locker.compare_exchange(-1, tid))
ASSERT_NOT_REACHED();
while (!m_locker.compare_exchange(PROCESSOR_NONE, id, BAN::MemoryOrder::memory_order_acquire))
__builtin_ia32_pause();
ASSERT_EQ(m_lock_depth, 0);
}
@@ -51,11 +51,10 @@ namespace Kernel
void RecursiveSpinLock::unlock(InterruptState state)
{
auto tid = Scheduler::current_tid();
ASSERT_EQ(m_locker.load(), tid);
ASSERT_EQ(m_locker.load(), get_processor_id());
ASSERT_GT(m_lock_depth, 0);
if (--m_lock_depth == 0)
m_locker = -1;
m_locker.store(PROCESSOR_NONE, BAN::MemoryOrder::memory_order_release);
set_interrupt_state(state);
}