Skip to content

Commit

Permalink
Clean up code for CPU_Group_Info structs (#69533)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLapounov authored May 19, 2022
1 parent 7f9ed8f commit 04d5bbc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 72 deletions.
40 changes: 8 additions & 32 deletions src/coreclr/gc/windows/gcenv.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ class GroupProcNo

struct CPU_Group_Info
{
WORD nr_active; // at most 64
WORD reserved[1];
WORD begin;
WORD end;
DWORD_PTR active_mask;
DWORD groupWeight;
DWORD activeThreadWeight;
WORD nr_active; // at most 64
WORD begin;
DWORD groupWeight;
DWORD activeThreadWeight;
};

static bool g_fEnableGCCPUGroups;
static bool g_fHadSingleProcessorAtStartup;
static DWORD g_nGroups;
static DWORD g_nGroups;
static DWORD g_nProcessors;
static CPU_Group_Info *g_CPUGroupInfoArray;

Expand Down Expand Up @@ -154,8 +152,8 @@ bool InitCPUGroupInfoArray()
DWORD dwNumElements = 0;
DWORD dwWeight = 1;

if (GetLogicalProcessorInformationEx(RelationGroup, pSLPIEx, &cbSLPIEx) &&
GetLastError() != ERROR_INSUFFICIENT_BUFFER)
if (GetLogicalProcessorInformationEx(RelationGroup, pSLPIEx, &cbSLPIEx) ||
GetLastError() != ERROR_INSUFFICIENT_BUFFER)
return false;

assert(cbSLPIEx);
Expand Down Expand Up @@ -195,6 +193,7 @@ bool InitCPUGroupInfoArray()
{
g_CPUGroupInfoArray[i].nr_active = (WORD)pRecord->Group.GroupInfo[i].ActiveProcessorCount;
g_CPUGroupInfoArray[i].active_mask = pRecord->Group.GroupInfo[i].ActiveProcessorMask;
g_CPUGroupInfoArray[i].begin = (WORD)g_nProcessors;
g_nProcessors += g_CPUGroupInfoArray[i].nr_active;
dwWeight = LCM(dwWeight, (DWORD)g_CPUGroupInfoArray[i].nr_active);
}
Expand All @@ -216,26 +215,6 @@ bool InitCPUGroupInfoArray()
#endif
}

bool InitCPUGroupInfoRange()
{
#if (defined(TARGET_AMD64) || defined(TARGET_ARM64))
WORD begin = 0;
WORD nr_proc = 0;

for (WORD i = 0; i < g_nGroups; i++)
{
nr_proc += g_CPUGroupInfoArray[i].nr_active;
g_CPUGroupInfoArray[i].begin = begin;
g_CPUGroupInfoArray[i].end = nr_proc - 1;
begin = nr_proc;
}

return true;
#else
return false;
#endif
}

void InitCPUGroupInfo()
{
g_fEnableGCCPUGroups = false;
Expand All @@ -247,9 +226,6 @@ void InitCPUGroupInfo()
if (!InitCPUGroupInfoArray())
return;

if (!InitCPUGroupInfoRange())
return;

// only enable CPU groups if more than one group exists
g_fEnableGCCPUGroups = g_nGroups > 1;
#endif // TARGET_AMD64 || TARGET_ARM64
Expand Down
13 changes: 5 additions & 8 deletions src/coreclr/inc/utilcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1004,13 +1004,11 @@ class NumaNodeInfo

struct CPU_Group_Info
{
WORD nr_active; // at most 64
WORD reserved[1];
WORD begin;
WORD end;
DWORD_PTR active_mask;
DWORD groupWeight;
DWORD activeThreadWeight;
DWORD_PTR active_mask;
WORD nr_active; // at most 64
WORD begin;
DWORD groupWeight;
DWORD activeThreadWeight;
};

class CPUGroupInfo
Expand All @@ -1026,7 +1024,6 @@ class CPUGroupInfo
static CPU_Group_Info *m_CPUGroupInfoArray;

static BOOL InitCPUGroupInfoArray();
static BOOL InitCPUGroupInfoRange();
static void InitCPUGroupInfo();
static BOOL IsInitialized();

Expand Down
41 changes: 9 additions & 32 deletions src/coreclr/utilcode/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,8 @@ DWORD LCM(DWORD u, DWORD v)
DWORD dwNumElements = 0;
DWORD dwWeight = 1;

if (CPUGroupInfo::GetLogicalProcessorInformationEx(RelationGroup, pSLPIEx, &cbSLPIEx) &&
GetLastError() != ERROR_INSUFFICIENT_BUFFER)
if (CPUGroupInfo::GetLogicalProcessorInformationEx(RelationGroup, pSLPIEx, &cbSLPIEx) ||
GetLastError() != ERROR_INSUFFICIENT_BUFFER)
return FALSE;

_ASSERTE(cbSLPIEx);
Expand Down Expand Up @@ -721,6 +721,7 @@ DWORD LCM(DWORD u, DWORD v)
{
m_CPUGroupInfoArray[i].nr_active = (WORD)pRecord->Group.GroupInfo[i].ActiveProcessorCount;
m_CPUGroupInfoArray[i].active_mask = pRecord->Group.GroupInfo[i].ActiveProcessorMask;
m_CPUGroupInfoArray[i].begin = m_nProcessors;
m_nProcessors += m_CPUGroupInfoArray[i].nr_active;
dwWeight = LCM(dwWeight, (DWORD)m_CPUGroupInfoArray[i].nr_active);
}
Expand All @@ -742,27 +743,6 @@ DWORD LCM(DWORD u, DWORD v)
#endif
}

/*static*/ BOOL CPUGroupInfo::InitCPUGroupInfoRange()
{
LIMITED_METHOD_CONTRACT;

#if !defined(FEATURE_REDHAWK) && (defined(TARGET_AMD64) || defined(TARGET_ARM64))
WORD begin = 0;
WORD nr_proc = 0;

for (WORD i = 0; i < m_nGroups; i++)
{
nr_proc += m_CPUGroupInfoArray[i].nr_active;
m_CPUGroupInfoArray[i].begin = begin;
m_CPUGroupInfoArray[i].end = nr_proc - 1;
begin = nr_proc;
}
return TRUE;
#else
return FALSE;
#endif
}

/*static*/ void CPUGroupInfo::InitCPUGroupInfo()
{
CONTRACTL
Expand All @@ -781,20 +761,17 @@ DWORD LCM(DWORD u, DWORD v)
if (!InitCPUGroupInfoArray())
return;

if (!InitCPUGroupInfoRange())
return;

// initalGroup is whatever the CPU group that the main thread is running on
GROUP_AFFINITY groupAffinity;
CPUGroupInfo::GetThreadGroupAffinity(GetCurrentThread(), &groupAffinity);
m_initialGroup = groupAffinity.Group;

// only enable CPU groups if more than one group exists
// Enable processor groups only if more than one group exists
if (m_nGroups > 1)
{
m_enableGCCPUGroups = TRUE;
m_threadUseAllCpuGroups = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Thread_UseAllCpuGroups) != 0;
m_threadAssignCpuGroups = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_Thread_AssignCpuGroups) != 0;

// Save the processor group affinity of the initial thread
GROUP_AFFINITY groupAffinity;
CPUGroupInfo::GetThreadGroupAffinity(GetCurrentThread(), &groupAffinity);
m_initialGroup = groupAffinity.Group;
}
#endif
}
Expand Down

0 comments on commit 04d5bbc

Please sign in to comment.