Skip to content

Commit b908ecf

Browse files
Account for availability of multiple processor groups on Windows 11+ (#68639)
1 parent 856ac5d commit b908ecf

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

src/coreclr/inc/configuration.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class Configuration
3333
// Unfortunately our traditional config system insists on interpreting numbers as 32-bit so interpret the config
3434
// in the traditional way separately if you need to.
3535
//
36-
// Returns value for name if found in config.
36+
// Returns (in priority order):
37+
// - The value of the ConfigurationKnob (searched by name) if it's set (performs a _wcstoui64)
38+
// - The default value passed in
3739
static ULONGLONG GetKnobULONGLONGValue(LPCWSTR name, ULONGLONG defaultValue);
3840

3941
// Returns (in priority order):
@@ -48,11 +50,17 @@ class Configuration
4850
static LPCWSTR GetKnobStringValue(LPCWSTR name);
4951

5052
// Returns (in priority order):
51-
// - The value of the ConfigDWORDInfo if it's set (1 is true, anything else is false)
53+
// - The value of the ConfigDWORDInfo if it's set (0 is false, anything else is true)
5254
// - The value of the ConfigurationKnob (searched by name) if it's set (performs a wcscmp with "true").
53-
// - The default set in the ConfigDWORDInfo (1 is true, anything else is false)
55+
// - The default set in the ConfigDWORDInfo (0 is false, anything else is true)
5456
static bool GetKnobBooleanValue(LPCWSTR name, const CLRConfig::ConfigDWORDInfo& dwordInfo);
5557

58+
// Returns (in priority order):
59+
// - The value of the ConfigDWORDInfo if it's set (0 is false, anything else is true)
60+
// - The value of the ConfigurationKnob (searched by name) if it's set (performs a wcscmp with "true").
61+
// - The default value passed in
62+
static bool GetKnobBooleanValue(LPCWSTR name, const CLRConfig::ConfigDWORDInfo& dwordInfo, bool defaultValue);
63+
5664
// Returns (in priority order):
5765
// - The value of the ConfigurationKnob (searched by name) if it's set (performs a wcscmp with "true").
5866
// - The default value passed in

src/coreclr/utilcode/configuration.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ bool Configuration::GetKnobBooleanValue(LPCWSTR name, const CLRConfig::ConfigDWO
123123
return (legacyValue != 0);
124124
}
125125

126+
bool Configuration::GetKnobBooleanValue(LPCWSTR name, const CLRConfig::ConfigDWORDInfo& dwordInfo, bool defaultValue)
127+
{
128+
bool returnedDefaultValue;
129+
DWORD legacyValue = CLRConfig::GetConfigValue(dwordInfo, &returnedDefaultValue);
130+
if (!returnedDefaultValue)
131+
{
132+
return (legacyValue != 0);
133+
}
134+
135+
return GetKnobBooleanValue(name, defaultValue);
136+
}
137+
126138
bool Configuration::GetKnobBooleanValue(LPCWSTR name, bool defaultValue)
127139
{
128140
LPCWSTR knobValue = GetConfigurationValue(name);

src/coreclr/utilcode/util.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,16 @@ DWORD LCM(DWORD u, DWORD v)
760760
CONTRACTL_END;
761761

762762
#if !defined(FEATURE_NATIVEAOT) && (defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64))
763-
BOOL enableGCCPUGroups = Configuration::GetKnobBooleanValue(W("System.GC.CpuGroup"), CLRConfig::EXTERNAL_GCCpuGroup);
763+
USHORT groupCount = 0;
764+
765+
// On Windows 11+ and Windows Server 2022+, a process is no longer restricted to a single processor group by default.
766+
// If more than one processor group is available to the process (a non-affinitized process on Windows 11+),
767+
// default to using multiple processor groups; otherwise, default to using a single processor group. This default
768+
// behavior may be overridden by the configuration values below.
769+
if (GetProcessGroupAffinity(GetCurrentProcess(), &groupCount, NULL) || GetLastError() != ERROR_INSUFFICIENT_BUFFER)
770+
groupCount = 1;
771+
772+
BOOL enableGCCPUGroups = Configuration::GetKnobBooleanValue(W("System.GC.CpuGroup"), CLRConfig::EXTERNAL_GCCpuGroup, groupCount > 1);
764773

765774
if (!enableGCCPUGroups)
766775
return;
@@ -772,7 +781,7 @@ DWORD LCM(DWORD u, DWORD v)
772781
if (m_nGroups > 1)
773782
{
774783
m_enableGCCPUGroups = TRUE;
775-
m_threadUseAllCpuGroups = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Thread_UseAllCpuGroups) != 0;
784+
m_threadUseAllCpuGroups = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Thread_UseAllCpuGroups, groupCount > 1) != 0;
776785
m_threadAssignCpuGroups = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Thread_AssignCpuGroups) != 0;
777786

778787
// Save the processor group affinity of the initial thread

0 commit comments

Comments
 (0)