Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

AntonLapounov
Copy link
Member

At present, NativeAOT does not account for availability of multiple processor groups on Windows 11+. For instance, Environment.ProcessorCount returns either 64 or 16 on an 80 core Ampere machine. Furthermore, setting DOTNET_GCCpuGroup=1 has no effect, because we access that setting (RhInitializePalInitGCToOSInterface::InitializeInitCPUGroupInfoGCConfig::GetGCCpuGroup) before it is initialized (RhInitializeInitDLLRedhawkGCInterface::InitializeSubsystemsGCHeapUtilities::InitializeDefaultGCGC_InitializeGCConfig::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 to true for a non-affinitized process on Windows 11+ with multiple processor groups and to false otherwise (see related #68639 for CoreCLR).

To fix the issue with accessing GCConfig before it is initialized, we now call GCConfig::Initialize before doing GCToOSInterface::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 the PalGetProcessCpuCount() > 1 condition to choose the ServerGC configuration value (since the CPU count depends on GCToOSInterface::Initialize, which has not been called yet). Arguably, that wasn't good design, and this PR avoids this circular dependency by keeping the ServerGC configuration value intact and choosing between SVR and WKS modes when we actually initialize the GC.

This PR also removes the unused g_fHadSingleProcessorAtStartup flag and enables the GetGroupForProcessor function for NativeAOT.

@jkotas
Copy link
Member

jkotas commented Sep 7, 2022

Is this also fixing behavior of local GC with CPU groups?

cc @dotnet/gc

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@AntonLapounov
Copy link
Member Author

Is this also fixing behavior of local GC with CPU groups?

The standalone GC uses the same gcenv.windows.cpp file, so it will also start to use all CPU groups by default on Windows 11+. Without this PR, one would have to set DOTNET_GCCpuGroup=1 for that effect. (The GCConfig initialization issue was specific to NativeAOT.)

Is this worth backporting?

@jkotas
Copy link
Member

jkotas commented Sep 7, 2022

Yes, I think this meets the bar for backport.

@AntonLapounov AntonLapounov merged commit 71adfb0 into dotnet:main Sep 7, 2022
@AntonLapounov AntonLapounov deleted the CpuCountForNativeAot branch September 7, 2022 01:53
@AntonLapounov
Copy link
Member Author

/backport to release/7.0

@github-actions
Copy link
Contributor

github-actions bot commented Sep 7, 2022

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3004566804

@ghost ghost locked as resolved and limited conversation to collaborators Oct 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants