#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_ONLN
#endif
-// The cached number of logical CPUs observed.
-static uint32_t g_logicalCpuCount = 0;
+// The cached total number of CPUs that can be used in the OS.
+static uint32_t g_totalCpuCount = 0;
// The cached number of CPUs available for the current process.
static uint32_t g_currentProcessCpuCount = 0;
return false;
}
- g_logicalCpuCount = cpuCount;
+ g_totalCpuCount = cpuCount;
//
// support for FlusProcessWriteBuffers
if (st == 0)
{
- for (size_t i = 0; i < g_logicalCpuCount; i++)
+ for (size_t i = 0; i < g_totalCpuCount; i++)
{
if (CPU_ISSET(i, &cpuSet))
{
#else // HAVE_SCHED_GETAFFINITY
- g_currentProcessCpuCount = g_logicalCpuCount;
+ g_currentProcessCpuCount = g_totalCpuCount;
- for (size_t i = 0; i < g_logicalCpuCount; i++)
+ for (size_t i = 0; i < g_totalCpuCount; i++)
{
g_processAffinitySet.Add(i);
}
#endif // HAVE_SCHED_GETAFFINITY
+ uint32_t cpuLimit;
+ if (GetCpuLimit(&cpuLimit) && cpuLimit < g_currentProcessCpuCount)
+ {
+ g_currentProcessCpuCount = cpuLimit;
+ }
+
NUMASupportInitialize();
return true;
{
// Calculated in GCToOSInterface::Initialize using
// sysconf(_SC_NPROCESSORS_ONLN)
- return g_logicalCpuCount;
+ return g_totalCpuCount;
}
bool GCToOSInterface::CanEnableGCNumaAware()
bool success = false;
uint16_t availableProcNumber = 0;
- for (size_t procNumber = 0; procNumber < g_logicalCpuCount; procNumber++)
+ for (size_t procNumber = 0; procNumber < g_totalCpuCount; procNumber++)
{
if (g_processAffinitySet.Contains(procNumber))
{
static AffinitySet g_processAffinitySet;
-#ifdef FEATURE_PAL
-static uint32_t g_currentProcessCpuCount;
-#endif // FEATURE_PAL
-
class GroupProcNo
{
uint16_t m_groupProc;
#ifdef FEATURE_PAL
g_pageSizeUnixInl = GetOsPageSize();
- g_currentProcessCpuCount = PAL_GetLogicalCpuCountFromOS();
+ uint32_t currentProcessCpuCount = PAL_GetLogicalCpuCountFromOS();
if (PAL_GetCurrentThreadAffinitySet(AffinitySet::BitsetDataSize, g_processAffinitySet.GetBitsetData()))
{
- assert(g_currentProcessCpuCount == g_processAffinitySet.Count());
+ assert(currentProcessCpuCount == g_processAffinitySet.Count());
}
else
{
// There is no way to get affinity on the current OS, set the affinity set to reflect all processors
- for (size_t i = 0; i < g_currentProcessCpuCount; i++)
+ for (size_t i = 0; i < currentProcessCpuCount; i++)
{
g_processAffinitySet.Add(i);
}
GCToOSInterface::GetTotalProcessorCount():
::GetCurrentProcessCpuCount();
#else // !FEATURE_PAL
- return g_currentProcessCpuCount;
+ return ::GetCurrentProcessCpuCount();
#endif // !FEATURE_PAL
}