From d5d06cfaab4b0bce0a94c760efc8992f4eb18cbf Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 9 Jun 2018 07:20:58 -0700 Subject: [PATCH] Use sysconf(_SC_NPROCESSORS_CONF) in PAL and GC ONLY on ARM and ARM64 (#5919) Port https://github.com/dotnet/coreclr/pull/18289 --- src/Native/Runtime/unix/PalRedhawkUnix.cpp | 29 +++++++++------------- src/Native/gc/unix/gcenv.unix.cpp | 15 ++++++----- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/Native/Runtime/unix/PalRedhawkUnix.cpp b/src/Native/Runtime/unix/PalRedhawkUnix.cpp index d65007052ae..de3d296aeef 100644 --- a/src/Native/Runtime/unix/PalRedhawkUnix.cpp +++ b/src/Native/Runtime/unix/PalRedhawkUnix.cpp @@ -94,6 +94,14 @@ using std::nullptr_t; #endif #endif // __APPLE__ +#if defined(_ARM_) || defined(_ARM64_) +#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_CONF +#define SYSCONF_GET_NUMPROCS_NAME "_SC_NPROCESSORS_CONF" +#else +#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_ONLN +#define SYSCONF_GET_NUMPROCS_NAME "_SC_NPROCESSORS_ONLN" +#endif + #define PalRaiseFailFastException RaiseFailFastException #define FATAL_ASSERT(e, msg) \ @@ -834,17 +842,10 @@ bool QueryCacheSize() bool QueryLogicalProcessorCount() { #if HAVE_SYSCONF - int sysConfName; -#if defined(_WASM_) - sysConfName = _SC_NPROCESSORS_ONLN; -#else - sysConfName = _SC_NPROCESSORS_CONF; -#endif - - g_cLogicalCpus = sysconf(sysConfName); + g_cLogicalCpus = sysconf(SYSCONF_GET_NUMPROCS); if (g_cLogicalCpus < 1) { - ASSERT_UNCONDITIONALLY("sysconf failed for _SC_NPROCESSORS_CONF\n"); + ASSERT_UNCONDITIONALLY("sysconf failed for " SYSCONF_GET_NUMPROCS_NAME "\n"); return false; } #elif HAVE_SYSCTL @@ -1275,16 +1276,10 @@ bool InitializeSystemInfo() int nrcpus = 0; #if HAVE_SYSCONF - int sysConfName; -#if defined(_WASM_) - sysConfName = _SC_NPROCESSORS_ONLN; -#else - sysConfName = _SC_NPROCESSORS_CONF; -#endif - nrcpus = sysconf(sysConfName); + nrcpus = sysconf(SYSCONF_GET_NUMPROCS); if (nrcpus < 1) { - ASSERT_UNCONDITIONALLY("sysconf failed for _SC_NPROCESSORS_CONF\n"); + ASSERT_UNCONDITIONALLY("sysconf failed for " SYSCONF_GET_NUMPROCS_NAME "\n"); return false; } #elif HAVE_SYSCTL diff --git a/src/Native/gc/unix/gcenv.unix.cpp b/src/Native/gc/unix/gcenv.unix.cpp index dfddbaba3a8..819049b4269 100644 --- a/src/Native/gc/unix/gcenv.unix.cpp +++ b/src/Native/gc/unix/gcenv.unix.cpp @@ -57,6 +57,12 @@ static_assert(sizeof(uint64_t) == 8, "unsigned long isn't 8 bytes"); #include #include // sysconf +#if defined(_ARM_) || defined(_ARM64_) +#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_CONF +#else +#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_ONLN +#endif + // The number of milliseconds in a second. static const int tccSecondsToMilliSeconds = 1000; @@ -84,14 +90,7 @@ static pthread_mutex_t g_flushProcessWriteBuffersMutex; bool GCToOSInterface::Initialize() { // Calculate and cache the number of processors on this machine - int sysConfName; -#if defined(_TARGET_WASM_) - sysConfName = _SC_NPROCESSORS_ONLN; -#else - sysConfName = _SC_NPROCESSORS_CONF; -#endif - - int cpuCount = sysconf(sysConfName); + int cpuCount = sysconf(SYSCONF_GET_NUMPROCS); if (cpuCount == -1) { return false;