Free affinity maps on allocation failure and remove redundant idle process affinity loop
This commit is contained in:
@@ -33,6 +33,7 @@ namespace KE
|
|||||||
IN PKAFFINITY_MAP Source);
|
IN PKAFFINITY_MAP Source);
|
||||||
STATIC XTAPI XTSTATUS CreateAffinityMap(IN ULONG CpuCount,
|
STATIC XTAPI XTSTATUS CreateAffinityMap(IN ULONG CpuCount,
|
||||||
OUT PKAFFINITY_MAP* AffinityMap);
|
OUT PKAFFINITY_MAP* AffinityMap);
|
||||||
|
STATIC XTAPI VOID DestroyAffinityMap(IN PKAFFINITY_MAP AffinityMap);
|
||||||
STATIC XTAPI ULONG FindNextLeftSetProcessor(IN ULONG ThreadSeed,
|
STATIC XTAPI ULONG FindNextLeftSetProcessor(IN ULONG ThreadSeed,
|
||||||
IN PKAFFINITY_MAP AffinityMap);
|
IN PKAFFINITY_MAP AffinityMap);
|
||||||
STATIC XTAPI ULONG FindNextRightSetProcessor(IN ULONG ThreadSeed,
|
STATIC XTAPI ULONG FindNextRightSetProcessor(IN ULONG ThreadSeed,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace KE
|
|||||||
public:
|
public:
|
||||||
STATIC XTAPI PKPROCESS GetIdleProcess(VOID);
|
STATIC XTAPI PKPROCESS GetIdleProcess(VOID);
|
||||||
STATIC XTAPI PEPROCESS GetInitialProcess(VOID);
|
STATIC XTAPI PEPROCESS GetInitialProcess(VOID);
|
||||||
STATIC XTAPI XTSTATUS InitializeIdleProcess(IN OUT PKPROCESS Process,
|
STATIC XTAPI XTSTATUS InitializeIdleProcess(IN OUT PKPROCESS IdleProcess,
|
||||||
IN PULONG_PTR DirectoryTable);
|
IN PULONG_PTR DirectoryTable);
|
||||||
STATIC XTAPI VOID InitializeProcess(IN OUT PKPROCESS Process,
|
STATIC XTAPI VOID InitializeProcess(IN OUT PKPROCESS Process,
|
||||||
IN KPRIORITY Priority,
|
IN KPRIORITY Priority,
|
||||||
|
|||||||
@@ -238,6 +238,28 @@ KE::Affinity::CreateAffinityMap(IN ULONG CpuCount,
|
|||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees a previously allocated affinity map and returns its memory to the pool.
|
||||||
|
*
|
||||||
|
* @param AffinityMap
|
||||||
|
* Supplies a pointer to the affinity map to be freed and destroyed.
|
||||||
|
*
|
||||||
|
* @return This routine does not return any value.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
VOID
|
||||||
|
KE::Affinity::DestroyAffinityMap(IN PKAFFINITY_MAP AffinityMap)
|
||||||
|
{
|
||||||
|
/* Ensure the map pointer is valid */
|
||||||
|
if(AffinityMap != NULLPTR)
|
||||||
|
{
|
||||||
|
/* Free the memory block back to the kernel pool */
|
||||||
|
MM::Allocator::FreePool((PVOID)AffinityMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locates the next available logical processor to the left (higher topological index) of a specified seed.
|
* Locates the next available logical processor to the left (higher topological index) of a specified seed.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -53,17 +53,17 @@ KE::KProcess::GetInitialProcess(VOID)
|
|||||||
*/
|
*/
|
||||||
XTAPI
|
XTAPI
|
||||||
XTSTATUS
|
XTSTATUS
|
||||||
KE::KProcess::InitializeIdleProcess(IN OUT PKPROCESS Process,
|
KE::KProcess::InitializeIdleProcess(IN OUT PKPROCESS IdleProcess,
|
||||||
IN PULONG_PTR DirectoryTable)
|
IN PULONG_PTR DirectoryTable)
|
||||||
{
|
{
|
||||||
ULONG Cpus, Index;
|
|
||||||
XTSTATUS Status;
|
XTSTATUS Status;
|
||||||
|
ULONG Cpus;
|
||||||
|
|
||||||
/* Get the number of natively installed CPUs */
|
/* Get the number of natively installed CPUs */
|
||||||
Cpus = KE::Processor::GetInstalledCpus();
|
Cpus = KE::Processor::GetInstalledCpus();
|
||||||
|
|
||||||
/* Allocate and initialize the baseline affinity map for the process */
|
/* Allocate and initialize the baseline affinity map for the process */
|
||||||
Status = KE::Affinity::CreateAffinityMap(Cpus, &Process->Affinity);
|
Status = KE::Affinity::CreateAffinityMap(Cpus, &IdleProcess->Affinity);
|
||||||
if(Status != STATUS_SUCCESS)
|
if(Status != STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
/* Affinity map allocation failed, return status code */
|
/* Affinity map allocation failed, return status code */
|
||||||
@@ -71,26 +71,20 @@ KE::KProcess::InitializeIdleProcess(IN OUT PKPROCESS Process,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate and initialize the dynamic map used to track actively running CPUs */
|
/* Allocate and initialize the dynamic map used to track actively running CPUs */
|
||||||
Status = KE::Affinity::CreateAffinityMap(Cpus, &Process->ActiveProcessors);
|
Status = KE::Affinity::CreateAffinityMap(Cpus, &IdleProcess->ActiveProcessors);
|
||||||
if(Status != STATUS_SUCCESS)
|
if(Status != STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
/* Affinity map allocation failed, return status code */
|
/* Affinity map allocation failed, free affinity map and return status code */
|
||||||
|
KE::Affinity::DestroyAffinityMap(IdleProcess->Affinity);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set Idle Process affinity */
|
/* Set Idle Process affinity */
|
||||||
KE::Affinity::SetAllProcessorsAffinity(Process->Affinity);
|
KE::Affinity::SetAllProcessorsAffinity(IdleProcess->Affinity);
|
||||||
|
|
||||||
/* Initialize Idle process */
|
/* Initialize Idle process */
|
||||||
KE::KProcess::InitializeProcess(Process, 0, NULLPTR, DirectoryTable, FALSE);
|
KE::KProcess::InitializeProcess(IdleProcess, 0, NULLPTR, DirectoryTable, FALSE);
|
||||||
Process->Quantum = MAXCHAR;
|
IdleProcess->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;
|
||||||
|
|||||||
@@ -63,11 +63,12 @@ KE::KThread::InitializeIdleThread(IN PKPROCESS IdleProcess,
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate and initialize the primary affinity map for the thread */
|
/* Allocate and initialize the user-mode affinity map for the thread */
|
||||||
Status = KE::Affinity::CreateAffinityMap(Cpus, &IdleThread->UserAffinity);
|
Status = KE::Affinity::CreateAffinityMap(Cpus, &IdleThread->UserAffinity);
|
||||||
if(Status != STATUS_SUCCESS)
|
if(Status != STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
/* Affinity map allocation failed, return status code */
|
/* Affinity map allocation failed, free affinity map and return status code */
|
||||||
|
KE::Affinity::DestroyAffinityMap(IdleThread->Affinity);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user