From 3841ceaf5b156a8518424ebdaa6ac6e331e29412 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Tue, 9 Jun 2026 19:33:20 +0200 Subject: [PATCH] Refactor processor affinity logic --- xtoskrnl/hl/data.cc | 2 +- xtoskrnl/hl/x86/cpu.cc | 11 ++++++----- xtoskrnl/includes/hl/cpu.hh | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/xtoskrnl/hl/data.cc b/xtoskrnl/hl/data.cc index f20821d28..7fa0b08a7 100644 --- a/xtoskrnl/hl/data.cc +++ b/xtoskrnl/hl/data.cc @@ -28,7 +28,7 @@ ACPI_SYSTEM_INFO HL::Acpi::SystemInfo; ACPI_TIMER_INFO HL::Acpi::TimerInfo; /* Represents the number of active processors */ -KAFFINITY HL::Cpu::ActiveProcessors; +KAFFINITY_MAP HL::Cpu::ActiveProcessors; /* Metadata detailing the linear frame buffer geometry */ HL_FRAMEBUFFER_DATA HL::FrameBuffer::FrameBufferData; diff --git a/xtoskrnl/hl/x86/cpu.cc b/xtoskrnl/hl/x86/cpu.cc index 10b41f9b2..f82d7a643 100644 --- a/xtoskrnl/hl/x86/cpu.cc +++ b/xtoskrnl/hl/x86/cpu.cc @@ -24,7 +24,7 @@ VOID HL::Cpu::InitializeProcessor(VOID) { PKPROCESSOR_BLOCK ProcessorBlock; - KAFFINITY Affinity; + ULONG BlockIndex, BitIndex; /* Get current processor block */ ProcessorBlock = KE::Processor::GetCurrentProcessorBlock(); @@ -33,17 +33,18 @@ HL::Cpu::InitializeProcessor(VOID) ProcessorBlock->StallScaleFactor = INITIAL_STALL_FACTOR; ProcessorBlock->Idr = 0xFFFFFFFF; - /* Set processor affinity */ - Affinity = (KAFFINITY) 1 << ProcessorBlock->CpuNumber; + /* Calculate the precise block and bit index for the affinity map */ + BlockIndex = ProcessorBlock->CpuNumber / 64; + BitIndex = ProcessorBlock->CpuNumber % 64; /* Apply affinity to a set of processors */ - ActiveProcessors |= Affinity; + RTL::Atomic::Or64((PLONG_PTR)&ActiveProcessors.Bitmap[BlockIndex], ((KAFFINITY)1 << BitIndex)); /* Initialize APIC for this processor */ HL::Pic::InitializePic(); /* Set the APIC running level */ - HL::RunLevel::SetRunLevel(KE::Processor::GetCurrentProcessorBlock()->RunLevel); + HL::RunLevel::SetRunLevel(ProcessorBlock->RunLevel); } /** diff --git a/xtoskrnl/includes/hl/cpu.hh b/xtoskrnl/includes/hl/cpu.hh index e75d01168..bc39fbe64 100644 --- a/xtoskrnl/includes/hl/cpu.hh +++ b/xtoskrnl/includes/hl/cpu.hh @@ -18,7 +18,7 @@ namespace HL class Cpu { private: - STATIC KAFFINITY ActiveProcessors; + STATIC KAFFINITY_MAP ActiveProcessors; public: STATIC XTAPI VOID InitializeProcessor(VOID);