summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Vorlicek <janvorli@microsoft.com>2019-04-17 10:59:41 -0700
committerJan Vorlicek <janvorli@microsoft.com>2019-04-17 10:59:41 -0700
commit0d9114b1f5d0b125f04f1ec17064a761fb26ba66 (patch)
tree819db8a187f08973770d91d3f6c30c1e0317bb37
parentdf2f4c4feb273545e91fd8d7d170dc424b741f19 (diff)
downloadcoreclr-0d9114b1f5d0b125f04f1ec17064a761fb26ba66.tar.gz
coreclr-0d9114b1f5d0b125f04f1ec17064a761fb26ba66.tar.bz2
coreclr-0d9114b1f5d0b125f04f1ec17064a761fb26ba66.zip
Put back the CPU limiting in GC
The CPU limiting was accidentally removed during refactoring of the CPU groups support in GC. This change puts them back.
-rw-r--r--src/gc/unix/gcenv.unix.cpp22
-rw-r--r--src/vm/gcenv.os.cpp12
2 files changed, 18 insertions, 16 deletions
diff --git a/src/gc/unix/gcenv.unix.cpp b/src/gc/unix/gcenv.unix.cpp
index 65a20d82f7..edddee16ce 100644
--- a/src/gc/unix/gcenv.unix.cpp
+++ b/src/gc/unix/gcenv.unix.cpp
@@ -88,8 +88,8 @@ FOR_ALL_NUMA_FUNCTIONS
#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;
@@ -220,7 +220,7 @@ bool GCToOSInterface::Initialize()
return false;
}
- g_logicalCpuCount = cpuCount;
+ g_totalCpuCount = cpuCount;
//
// support for FlusProcessWriteBuffers
@@ -289,7 +289,7 @@ bool GCToOSInterface::Initialize()
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))
{
@@ -307,15 +307,21 @@ bool GCToOSInterface::Initialize()
#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;
@@ -889,7 +895,7 @@ uint32_t GCToOSInterface::GetTotalProcessorCount()
{
// Calculated in GCToOSInterface::Initialize using
// sysconf(_SC_NPROCESSORS_ONLN)
- return g_logicalCpuCount;
+ return g_totalCpuCount;
}
bool GCToOSInterface::CanEnableGCNumaAware()
@@ -909,7 +915,7 @@ bool GCToOSInterface::GetProcessorForHeap(uint16_t heap_number, uint16_t* proc_n
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))
{
diff --git a/src/vm/gcenv.os.cpp b/src/vm/gcenv.os.cpp
index e20c36e48f..6e3f775660 100644
--- a/src/vm/gcenv.os.cpp
+++ b/src/vm/gcenv.os.cpp
@@ -32,10 +32,6 @@ uint32_t g_pageSizeUnixInl = 0;
static AffinitySet g_processAffinitySet;
-#ifdef FEATURE_PAL
-static uint32_t g_currentProcessCpuCount;
-#endif // FEATURE_PAL
-
class GroupProcNo
{
uint16_t m_groupProc;
@@ -111,15 +107,15 @@ bool GCToOSInterface::Initialize()
#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);
}
@@ -582,7 +578,7 @@ uint32_t GCToOSInterface::GetCurrentProcessCpuCount()
GCToOSInterface::GetTotalProcessorCount():
::GetCurrentProcessCpuCount();
#else // !FEATURE_PAL
- return g_currentProcessCpuCount;
+ return ::GetCurrentProcessCpuCount();
#endif // !FEATURE_PAL
}