Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for availability of multiple processor groups on Windows 11+ #68639

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/coreclr/inc/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class Configuration
// Unfortunately our traditional config system insists on interpreting numbers as 32-bit so interpret the config
// in the traditional way separately if you need to.
//
// Returns value for name if found in config.
// Returns (in priority order):
// - The value of the ConfigurationKnob (searched by name) if it's set (performs a _wcstoui64)
// - The default value passed in
static ULONGLONG GetKnobULONGLONGValue(LPCWSTR name, ULONGLONG defaultValue);

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

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

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

// Returns (in priority order):
// - The value of the ConfigurationKnob (searched by name) if it's set (performs a wcscmp with "true").
// - The default value passed in
Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/utilcode/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ bool Configuration::GetKnobBooleanValue(LPCWSTR name, const CLRConfig::ConfigDWO
return (legacyValue != 0);
}

bool Configuration::GetKnobBooleanValue(LPCWSTR name, const CLRConfig::ConfigDWORDInfo& dwordInfo, bool defaultValue)
{
bool returnedDefaultValue;
DWORD legacyValue = CLRConfig::GetConfigValue(dwordInfo, &returnedDefaultValue);
if (!returnedDefaultValue)
{
return (legacyValue != 0);
}

return GetKnobBooleanValue(name, defaultValue);
}

bool Configuration::GetKnobBooleanValue(LPCWSTR name, bool defaultValue)
{
LPCWSTR knobValue = GetConfigurationValue(name);
Expand Down
13 changes: 11 additions & 2 deletions src/coreclr/utilcode/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,16 @@ DWORD LCM(DWORD u, DWORD v)
CONTRACTL_END;

#if !defined(FEATURE_NATIVEAOT) && (defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64))
BOOL enableGCCPUGroups = Configuration::GetKnobBooleanValue(W("System.GC.CpuGroup"), CLRConfig::EXTERNAL_GCCpuGroup);
USHORT groupCount = 0;

// On Windows 11+ and Windows Server 2022+, a process is no longer restricted to a single processor group by default.
// If more than one processor group is available to the process (a non-affinitized process on Windows 11+),
// default to using multiple processor groups; otherwise, default to using a single processor group. This default
// behavior may be overridden by the configuration values below.
if (GetProcessGroupAffinity(GetCurrentProcess(), &groupCount, NULL) || GetLastError() != ERROR_INSUFFICIENT_BUFFER)
AntonLapounov marked this conversation as resolved.
Show resolved Hide resolved
groupCount = 1;

BOOL enableGCCPUGroups = Configuration::GetKnobBooleanValue(W("System.GC.CpuGroup"), CLRConfig::EXTERNAL_GCCpuGroup, groupCount > 1);

if (!enableGCCPUGroups)
return;
Expand All @@ -772,7 +781,7 @@ DWORD LCM(DWORD u, DWORD v)
if (m_nGroups > 1)
{
m_enableGCCPUGroups = TRUE;
m_threadUseAllCpuGroups = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Thread_UseAllCpuGroups) != 0;
m_threadUseAllCpuGroups = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Thread_UseAllCpuGroups, groupCount > 1) != 0;
m_threadAssignCpuGroups = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Thread_AssignCpuGroups) != 0;

// Save the processor group affinity of the initial thread
Expand Down