diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index 01f51c275c8a..543058d69600 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -34202,7 +34202,10 @@ HRESULT GCHeap::Initialize() #ifdef MULTIPLE_HEAPS nhp_from_config = static_cast(GCConfig::GetHeapCount()); - uint32_t nhp_from_process = GCToOSInterface::GetCurrentProcessCpuCount(); + // GetCurrentProcessCpuCount only returns up to 64 procs. + uint32_t nhp_from_process = GCToOSInterface::CanEnableGCCPUGroups() ? + GCToOSInterface::GetTotalProcessorCount(): + GCToOSInterface::GetCurrentProcessCpuCount(); if (nhp_from_config) { @@ -34233,6 +34236,20 @@ HRESULT GCHeap::Initialize() { pmask &= smask; +#ifdef FEATURE_PAL + // GetCurrentProcessAffinityMask can return pmask=0 and smask=0 on + // systems with more than 1 NUMA node. The pmask decides the + // number of GC heaps to be used and the processors they are + // affinitized with. So pmask is now set to reflect that 64 + // processors are available to begin with. The actual processors in + // the system may be lower and are taken into account before + // finalizing the number of heaps. + if (!pmask) + { + pmask = SIZE_T_MAX; + } +#endif // FEATURE_PAL + if (gc_thread_affinity_mask) { pmask &= gc_thread_affinity_mask; @@ -34249,6 +34266,11 @@ HRESULT GCHeap::Initialize() } nhp = min (nhp, set_bits_in_pmask); + +#ifdef FEATURE_PAL + // Limit the GC heaps to the number of processors available in the system. + nhp = min (nhp, GCToOSInterface::GetTotalProcessorCount()); +#endif // FEATURE_PAL } else { diff --git a/src/inc/utilcode.h b/src/inc/utilcode.h index a647d0c8d469..899195f1ae9f 100644 --- a/src/inc/utilcode.h +++ b/src/inc/utilcode.h @@ -1355,31 +1355,10 @@ class NumaNodeInfo static void InitNumaNodeInfo(); #if !defined(FEATURE_REDHAWK) -private: // apis types - - //GetNumaHighestNodeNumber() - typedef BOOL - (WINAPI *PGNHNN)(PULONG); - //VirtualAllocExNuma() - typedef LPVOID - (WINAPI *PVAExN)(HANDLE,LPVOID,SIZE_T,DWORD,DWORD,DWORD); - - // api pfns and members - static PGNHNN m_pGetNumaHighestNodeNumber; - static PVAExN m_pVirtualAllocExNuma; - public: // functions static LPVOID VirtualAllocExNuma(HANDLE hProc, LPVOID lpAddr, SIZE_T size, DWORD allocType, DWORD prot, DWORD node); - -private: - //GetNumaProcessorNodeEx() - typedef BOOL - (WINAPI *PGNPNEx)(PPROCESSOR_NUMBER, PUSHORT); - static PGNPNEx m_pGetNumaProcessorNodeEx; - -public: static BOOL GetNumaProcessorNodeEx(PPROCESSOR_NUMBER proc_no, PUSHORT node_no); #endif }; @@ -1407,7 +1386,6 @@ class CPUGroupInfo static CPU_Group_Info *m_CPUGroupInfoArray; static bool s_hadSingleProcessorAtStartup; - static BOOL InitCPUGroupInfoAPI(); static BOOL InitCPUGroupInfoArray(); static BOOL InitCPUGroupInfoRange(); static void InitCPUGroupInfo(); @@ -1424,34 +1402,8 @@ class CPUGroupInfo //static void PopulateCPUUsageArray(void * infoBuffer, ULONG infoSize); #if !defined(FEATURE_REDHAWK) -private: - //GetLogicalProcessorInforomationEx() - typedef BOOL - (WINAPI *PGLPIEx)(DWORD, SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *, PDWORD); - //SetThreadGroupAffinity() - typedef BOOL - (WINAPI *PSTGA)(HANDLE, GROUP_AFFINITY *, GROUP_AFFINITY *); - //GetThreadGroupAffinity() - typedef BOOL - (WINAPI *PGTGA)(HANDLE, GROUP_AFFINITY *); - //GetCurrentProcessorNumberEx() - typedef void - (WINAPI *PGCPNEx)(PROCESSOR_NUMBER *); - //GetSystemTimes() - typedef BOOL - (WINAPI *PGST)(FILETIME *, FILETIME *, FILETIME *); - //NtQuerySystemInformationEx() - //typedef int - //(WINAPI *PNTQSIEx)(SYSTEM_INFORMATION_CLASS, PULONG, ULONG, PVOID, ULONG, PULONG); - static PGLPIEx m_pGetLogicalProcessorInformationEx; - static PSTGA m_pSetThreadGroupAffinity; - static PGTGA m_pGetThreadGroupAffinity; - static PGCPNEx m_pGetCurrentProcessorNumberEx; - static PGST m_pGetSystemTimes; - //static PNTQSIEx m_pNtQuerySystemInformationEx; - public: - static BOOL GetLogicalProcessorInformationEx(DWORD relationship, + static BOOL GetLogicalProcessorInformationEx(LOGICAL_PROCESSOR_RELATIONSHIP relationship, SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *slpiex, PDWORD count); static BOOL SetThreadGroupAffinity(HANDLE h, GROUP_AFFINITY *groupAffinity, GROUP_AFFINITY *previousGroupAffinity); diff --git a/src/utilcode/staticnohost/CMakeLists.txt b/src/utilcode/staticnohost/CMakeLists.txt index eea4d60785be..f4b7909f1742 100644 --- a/src/utilcode/staticnohost/CMakeLists.txt +++ b/src/utilcode/staticnohost/CMakeLists.txt @@ -9,4 +9,7 @@ add_library_clr(utilcodestaticnohost STATIC ${UTILCODE_STATICNOHOST_SOURCES}) if(CLR_CMAKE_PLATFORM_UNIX) target_link_libraries(utilcodestaticnohost nativeresourcestring) + if(CLR_CMAKE_PLATFORM_DARWIN) + target_link_libraries(utilcodestaticnohost coreclrpal) + endif(CLR_CMAKE_PLATFORM_DARWIN) endif(CLR_CMAKE_PLATFORM_UNIX) diff --git a/src/utilcode/util.cpp b/src/utilcode/util.cpp index 980761172c81..9ebc401db4ae 100644 --- a/src/utilcode/util.cpp +++ b/src/utilcode/util.cpp @@ -743,19 +743,16 @@ BYTE * ClrVirtualAllocWithinRange(const BYTE *pMinAddr, // NumaNodeInfo //****************************************************************************** #if !defined(FEATURE_REDHAWK) -/*static*/ NumaNodeInfo::PGNHNN NumaNodeInfo::m_pGetNumaHighestNodeNumber = NULL; -/*static*/ NumaNodeInfo::PVAExN NumaNodeInfo::m_pVirtualAllocExNuma = NULL; /*static*/ LPVOID NumaNodeInfo::VirtualAllocExNuma(HANDLE hProc, LPVOID lpAddr, SIZE_T dwSize, DWORD allocType, DWORD prot, DWORD node) { - return (*m_pVirtualAllocExNuma)(hProc, lpAddr, dwSize, allocType, prot, node); + return ::VirtualAllocExNuma(hProc, lpAddr, dwSize, allocType, prot, node); } -/*static*/ NumaNodeInfo::PGNPNEx NumaNodeInfo::m_pGetNumaProcessorNodeEx = NULL; /*static*/ BOOL NumaNodeInfo::GetNumaProcessorNodeEx(PPROCESSOR_NUMBER proc_no, PUSHORT node_no) { - return (*m_pGetNumaProcessorNodeEx)(proc_no, node_no); + return ::GetNumaProcessorNodeEx(proc_no, node_no); } #endif @@ -778,20 +775,8 @@ BYTE * ClrVirtualAllocWithinRange(const BYTE *pMinAddr, if (hMod == NULL) return FALSE; - m_pGetNumaHighestNodeNumber = (PGNHNN) GetProcAddress(hMod, "GetNumaHighestNodeNumber"); - if (m_pGetNumaHighestNodeNumber == NULL) - return FALSE; - // fail to get the highest numa node number - if (!m_pGetNumaHighestNodeNumber(&highest) || (highest == 0)) - return FALSE; - - m_pGetNumaProcessorNodeEx = (PGNPNEx) GetProcAddress(hMod, "GetNumaProcessorNodeEx"); - if (m_pGetNumaProcessorNodeEx == NULL) - return FALSE; - - m_pVirtualAllocExNuma = (PVAExN) GetProcAddress(hMod, "VirtualAllocExNuma"); - if (m_pVirtualAllocExNuma == NULL) + if (!::GetNumaHighestNodeNumber(&highest) || (highest == 0)) return FALSE; return TRUE; @@ -814,37 +799,37 @@ BYTE * ClrVirtualAllocWithinRange(const BYTE *pMinAddr, // NumaNodeInfo //****************************************************************************** #if !defined(FEATURE_REDHAWK) -/*static*/ CPUGroupInfo::PGLPIEx CPUGroupInfo::m_pGetLogicalProcessorInformationEx = NULL; -/*static*/ CPUGroupInfo::PSTGA CPUGroupInfo::m_pSetThreadGroupAffinity = NULL; -/*static*/ CPUGroupInfo::PGTGA CPUGroupInfo::m_pGetThreadGroupAffinity = NULL; -/*static*/ CPUGroupInfo::PGCPNEx CPUGroupInfo::m_pGetCurrentProcessorNumberEx = NULL; -/*static*/ CPUGroupInfo::PGST CPUGroupInfo::m_pGetSystemTimes = NULL; /*static*/ //CPUGroupInfo::PNTQSIEx CPUGroupInfo::m_pNtQuerySystemInformationEx = NULL; -/*static*/ BOOL CPUGroupInfo::GetLogicalProcessorInformationEx(DWORD relationship, +/*static*/ BOOL CPUGroupInfo::GetLogicalProcessorInformationEx(LOGICAL_PROCESSOR_RELATIONSHIP relationship, SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *slpiex, PDWORD count) { LIMITED_METHOD_CONTRACT; - return (*m_pGetLogicalProcessorInformationEx)(relationship, slpiex, count); + return ::GetLogicalProcessorInformationEx(relationship, slpiex, count); } /*static*/ BOOL CPUGroupInfo::SetThreadGroupAffinity(HANDLE h, GROUP_AFFINITY *groupAffinity, GROUP_AFFINITY *previousGroupAffinity) { LIMITED_METHOD_CONTRACT; - return (*m_pSetThreadGroupAffinity)(h, groupAffinity, previousGroupAffinity); + return ::SetThreadGroupAffinity(h, groupAffinity, previousGroupAffinity); } /*static*/ BOOL CPUGroupInfo::GetThreadGroupAffinity(HANDLE h, GROUP_AFFINITY *groupAffinity) { LIMITED_METHOD_CONTRACT; - return (*m_pGetThreadGroupAffinity)(h, groupAffinity); + return ::GetThreadGroupAffinity(h, groupAffinity); } /*static*/ BOOL CPUGroupInfo::GetSystemTimes(FILETIME *idleTime, FILETIME *kernelTime, FILETIME *userTime) { LIMITED_METHOD_CONTRACT; - return (*m_pGetSystemTimes)(idleTime, kernelTime, userTime); + +#ifndef FEATURE_PAL + return ::GetSystemTimes(idleTime, kernelTime, userTime); +#else + return FALSE; +#endif } #endif @@ -857,53 +842,6 @@ BYTE * ClrVirtualAllocWithinRange(const BYTE *pMinAddr, /*static*/ LONG CPUGroupInfo::m_initialization = 0; /*static*/ bool CPUGroupInfo::s_hadSingleProcessorAtStartup = false; -// Check and setup function pointers for >64 LP Support -/*static*/ BOOL CPUGroupInfo::InitCPUGroupInfoAPI() -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - -#if !defined(FEATURE_REDHAWK) && (defined(_TARGET_AMD64_) || defined(_TARGET_ARM64_)) -#ifndef FEATURE_PAL - HMODULE hMod = GetModuleHandleW(WINDOWS_KERNEL32_DLLNAME_W); -#else - HMODULE hMod = GetCLRModule(); -#endif - if (hMod == NULL) - return FALSE; - - m_pGetLogicalProcessorInformationEx = (PGLPIEx)GetProcAddress(hMod, "GetLogicalProcessorInformationEx"); - if (m_pGetLogicalProcessorInformationEx == NULL) - return FALSE; - - m_pSetThreadGroupAffinity = (PSTGA)GetProcAddress(hMod, "SetThreadGroupAffinity"); - if (m_pSetThreadGroupAffinity == NULL) - return FALSE; - - m_pGetThreadGroupAffinity = (PGTGA)GetProcAddress(hMod, "GetThreadGroupAffinity"); - if (m_pGetThreadGroupAffinity == NULL) - return FALSE; - - m_pGetCurrentProcessorNumberEx = (PGCPNEx)GetProcAddress(hMod, "GetCurrentProcessorNumberEx"); - if (m_pGetCurrentProcessorNumberEx == NULL) - return FALSE; - -#ifndef FEATURE_PAL - m_pGetSystemTimes = (PGST)GetProcAddress(hMod, "GetSystemTimes"); - if (m_pGetSystemTimes == NULL) - return FALSE; -#endif - - return TRUE; -#else - return FALSE; -#endif -} - #if !defined(FEATURE_REDHAWK) && (defined(_TARGET_AMD64_) || defined(_TARGET_ARM64_)) // Calculate greatest common divisor DWORD GCD(DWORD u, DWORD v) @@ -955,7 +893,7 @@ DWORD LCM(DWORD u, DWORD v) return FALSE; pSLPIEx = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)bBuffer; - if (!m_pGetLogicalProcessorInformationEx(RelationGroup, pSLPIEx, &cbSLPIEx)) + if (!::GetLogicalProcessorInformationEx(RelationGroup, pSLPIEx, &cbSLPIEx)) { delete[] bBuffer; return FALSE; @@ -1042,9 +980,6 @@ DWORD LCM(DWORD u, DWORD v) if (!enableGCCPUGroups) return; - if (!InitCPUGroupInfoAPI()) - return; - if (!InitCPUGroupInfoArray()) return; @@ -1167,7 +1102,7 @@ DWORD LCM(DWORD u, DWORD v) proc_no.Group=0; proc_no.Number=0; proc_no.Reserved=0; - (*m_pGetCurrentProcessorNumberEx)(&proc_no); + ::GetCurrentProcessorNumberEx(&proc_no); DWORD fullNumber = 0; for (WORD i = 0; i < proc_no.Group; i++)