Refactor idle process initialization

This commit is contained in:
2026-06-09 23:17:03 +02:00
parent a9202f5b57
commit 6a2a35c008

View File

@@ -56,50 +56,39 @@ XTSTATUS
KE::KProcess::InitializeIdleProcess(IN OUT PKPROCESS Process, KE::KProcess::InitializeIdleProcess(IN OUT PKPROCESS Process,
IN PULONG_PTR DirectoryTable) IN PULONG_PTR DirectoryTable)
{ {
ULONG AffinitySize, MapSize; ULONG Cpus, Index;
PACPI_SYSTEM_INFO SysInfo;
XTSTATUS Status; XTSTATUS Status;
/* Retrieve hardware topology from ACPI */ /* Get the number of natively installed CPUs */
HL::Acpi::GetSystemInformation(&SysInfo); Cpus = KE::Processor::GetInstalledCpus();
/* Calculate the required size for KAFFINITY_MAP structures */ /* Allocate and initialize the baseline affinity map for the process */
AffinitySize = (SysInfo->CpuCount + 63) / 64; Status = KE::Affinity::CreateAffinityMap(Cpus, &Process->Affinity);
MapSize = sizeof(KAFFINITY_MAP) + (AffinitySize * sizeof(KAFFINITY));
/* Align size to the 8-byte boundary */
MapSize = (MapSize + 7) & ~7;
/* Allocate the process-level affinity structure */
Status = MM::Allocator::AllocatePool(NonPagedPool, MapSize, (PVOID*)&Process->Affinity);
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* Memory allocation failed, return the status code */ /* Affinity map allocation failed, return status code */
return Status; return Status;
} }
/* Allocate the process-level active processors structure */ /* Allocate and initialize the dynamic map used to track actively running CPUs */
Status = MM::Allocator::AllocatePool(NonPagedPool, MapSize, (PVOID*)&Process->ActiveProcessors); Status = KE::Affinity::CreateAffinityMap(Cpus, &Process->ActiveProcessors);
if(Status != STATUS_SUCCESS) if(Status != STATUS_SUCCESS)
{ {
/* Memory allocation failed, free previously allocated memory and return the status code */ /* Affinity map allocation failed, return status code */
MM::Allocator::FreePool((PVOID)Process->Affinity);
return Status; return Status;
} }
/* Zero the process-level affinity structures */
RTL::Memory::ZeroMemory(Process->Affinity, MapSize);
RTL::Memory::ZeroMemory(Process->ActiveProcessors, MapSize);
/* Initialize size metadata */
Process->Affinity->Count = (USHORT)AffinitySize;
Process->Affinity->Size = (USHORT)AffinitySize;
Process->ActiveProcessors->Size = (USHORT)AffinitySize;
/* Initialize Idle process */ /* Initialize Idle process */
KE::KProcess::InitializeProcess(Process, 0, DirectoryTable, FALSE); KE::KProcess::InitializeProcess(Process, 0, DirectoryTable, FALSE);
Process->Quantum = MAXCHAR; Process->Quantum = MAXCHAR;
/* Populate the global Idle Process affinity */
for(Index = 0; Index < Cpus; Index++)
{
/* Include every installed hardware thread in the base affinity map */
KE::Affinity::SetProcessorAffinity(Process->Affinity, Index);
}
/* Return success */ /* Return success */
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }