Support multiple processor groups for NativeAOT #75165
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At present, NativeAOT does not account for availability of multiple processor groups on Windows 11+. For instance,
Environment.ProcessorCount
returns either64
or16
on an 80 core Ampere machine. Furthermore, settingDOTNET_GCCpuGroup=1
has no effect, because we access that setting (RhInitialize
⭢PalInit
⭢GCToOSInterface::Initialize
⭢InitCPUGroupInfo
⭢GCConfig::GetGCCpuGroup
) before it is initialized (RhInitialize
⭢InitDLL
⭢RedhawkGCInterface::InitializeSubsystems
⭢GCHeapUtilities::InitializeDefaultGC
⭢GC_Initialize
⭢GCConfig::Initialize
).This PR changes the NativeAOT runtime to use the same logic regarding multiple processor groups as in CoreCLR. Namely, it allows the
DOTNET_GCCpuGroup
configuration setting to control whether the runtime may use all processor groups. If the setting is not provided, it defaults totrue
for a non-affinitized process on Windows 11+ with multiple processor groups and tofalse
otherwise (see related #68639 for CoreCLR).To fix the issue with accessing
GCConfig
before it is initialized, we now callGCConfig::Initialize
before doingGCToOSInterface::Initialize
. That makes the behavior of NativeAOT consistent with that of CoreCLR and the standalone GC case.However, that means that
GCConfig::Initialize
can no longer check thePalGetProcessCpuCount() > 1
condition to choose theServerGC
configuration value (since the CPU count depends onGCToOSInterface::Initialize
, which has not been called yet). Arguably, that wasn't good design, and this PR avoids this circular dependency by keeping theServerGC
configuration value intact and choosing betweenSVR
andWKS
modes when we actually initialize the GC.This PR also removes the unused
g_fHadSingleProcessorAtStartup
flag and enables theGetGroupForProcessor
function for NativeAOT.