Skip to content

Allow overriding processor count via configuration setting #52492

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

Merged
merged 8 commits into from
May 11, 2021
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
16 changes: 1 addition & 15 deletions src/coreclr/classlibnative/bcltype/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,7 @@ INT32 QCALLTYPE SystemNative::GetProcessorCount()

BEGIN_QCALL;

#ifndef TARGET_UNIX
CPUGroupInfo::EnsureInitialized();

if (CPUGroupInfo::CanEnableThreadUseAllCpuGroups())
{
processorCount = CPUGroupInfo::GetNumActiveProcessors();
}
else
#endif // !TARGET_UNIX
{
// This similar to GetSystemInfo() + dwNumberOfProcessors except:
// - GetCurrentProcessCpuCount() tries to take into account the processor affinity mask where applicable
// - GetCurrentProcessCpuCount() on Unixes tries to take into account cgroups CPU quota limits where applicable
processorCount = GetCurrentProcessCpuCount();
}
processorCount = GetCurrentProcessCpuCount();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and elsewhere the CanEnableThreadUseAllCpuGroups check is moved inside GetCurrentProcessCpuCount().


END_QCALL;

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/dlls/mscordac/mscordac_unixexports.src
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ nativeStringResourceTable_mscorrc
#PAL_free
#PAL_fwprintf
#PAL_GetLogicalCpuCountFromOS
#PAL_GetTotalCpuCount
#PAL_GetNumaProcessorNode
#PAL_get_stdout
#PAL_get_stderr
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/gc/env/gcenv.ee.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class GCToEEInterface
static void VerifySyncTableEntry();
static void UpdateGCEventStatus(int publicLevel, int publicKeywords, int privateLevel, int privateKeywords);
static void LogStressMsg(unsigned level, unsigned facility, const StressLogMsg &msg);
static uint32_t GetCurrentProcessCpuCount();
};

#endif // __GCENV_EE_H__
5 changes: 0 additions & 5 deletions src/coreclr/gc/env/gcenv.os.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,6 @@ class GCToOSInterface
// Size of the cache
static size_t GetCacheSizePerLogicalCpu(bool trueSize = true);

// Get number of processors assigned to the current process
// Return:
// The number of processors
static uint32_t GetCurrentProcessCpuCount();

// Sets the calling thread's affinity to only run on the processor specified.
// Parameters:
// procNo - The requested affinity for the calling thread.
Expand Down
9 changes: 2 additions & 7 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41280,7 +41280,7 @@ HRESULT GCHeap::Initialize()

nhp_from_config = static_cast<uint32_t>(GCConfig::GetHeapCount());

g_num_active_processors = GCToOSInterface::GetCurrentProcessCpuCount();
g_num_active_processors = GCToEEInterface::GetCurrentProcessCpuCount();

if (nhp_from_config)
{
Expand All @@ -41292,7 +41292,7 @@ HRESULT GCHeap::Initialize()
nhp = ((nhp_from_config == 0) ? g_num_active_processors : nhp_from_config);

nhp = min (nhp, MAX_SUPPORTED_CPUS);
#ifndef FEATURE_REDHAWK

gc_heap::gc_thread_no_affinitize_p = (gc_heap::heap_hard_limit ?
!affinity_config_specified_p : (GCConfig::GetNoAffinitize() != 0));

Expand All @@ -41304,12 +41304,7 @@ HRESULT GCHeap::Initialize()
{
nhp = min(nhp, num_affinitized_processors);
}
#ifndef TARGET_WINDOWS
// Limit the GC heaps to the number of processors available in the system.
nhp = min (nhp, GCToOSInterface::GetTotalProcessorCount());
#endif // !TARGET_WINDOWS
}
#endif //!FEATURE_REDHAWK
#endif //MULTIPLE_HEAPS

size_t seg_size = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/gc/gcenv.ee.standalone.inl
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,9 @@ inline void GCToEEInterface::LogStressMsg(unsigned level, unsigned facility, con
g_theGCToCLR->LogStressMsg(level, facility, msg);
}

inline uint32_t GCToEEInterface::GetCurrentProcessCpuCount()
{
return g_theGCToCLR->GetCurrentProcessCpuCount();
}

#endif // __GCTOENV_EE_STANDALONE_INL__
3 changes: 3 additions & 0 deletions src/coreclr/gc/gcinterface.ee.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ class IGCToCLR {

virtual
void LogStressMsg(unsigned level, unsigned facility, const StressLogMsg& msg) = 0;

virtual
uint32_t GetCurrentProcessCpuCount() = 0;
};

#endif // _GCINTERFACE_EE_H_
4 changes: 2 additions & 2 deletions src/coreclr/gc/handletablecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#undef Sleep
#endif // Sleep

#include "env/gcenv.os.h"
#include "gc.h"

#include "handletablepriv.h"

Expand Down Expand Up @@ -56,7 +56,7 @@ void SpinUntil(void *pCond, BOOL fNonZero)
#endif //_DEBUG

// on MP machines, allow ourselves some spin time before sleeping
static uint32_t uNonSleepSpins = 8 * (GCToOSInterface::GetCurrentProcessCpuCount() - 1);
static uint32_t uNonSleepSpins = 8 * (GCToEEInterface::GetCurrentProcessCpuCount() - 1);

// spin until the specificed condition is met
while ((*(uintptr_t *)pCond != 0) != (fNonZero != 0))
Expand Down
7 changes: 5 additions & 2 deletions src/coreclr/gc/sample/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ bool GCToEEInterface::GetStringConfigValue(const char* privateKey, const char* p

void GCToEEInterface::FreeStringConfigValue(const char *value)
{

}

bool GCToEEInterface::IsGCThread()
Expand Down Expand Up @@ -341,7 +340,6 @@ inline bool GCToEEInterface::AnalyzeSurvivorsRequested(int condemnedGeneration)

inline void GCToEEInterface::AnalyzeSurvivorsFinished(size_t gcIndex, int condemnedGeneration, uint64_t promoted_bytes, void (*reportGenerationBounds)())
{

}

void GCToEEInterface::VerifySyncTableEntry()
Expand All @@ -351,3 +349,8 @@ void GCToEEInterface::VerifySyncTableEntry()
void GCToEEInterface::UpdateGCEventStatus(int currentPublicLevel, int currentPublicKeywords, int currentPrivateLevel, int currentPrivateKeywords)
{
}

uint32_t GCToEEInterface::GetCurrentProcessCpuCount()
{
return GCToOSInterface::GetTotalProcessorCount();
}
Loading