Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Use sysconf(_SC_NPROCESSORS_CONF) in PAL and GC ONLY on ARM and ARM64 (
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas authored Jun 9, 2018
1 parent 27feaa3 commit d5d06cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
29 changes: 12 additions & 17 deletions src/Native/Runtime/unix/PalRedhawkUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions src/Native/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ static_assert(sizeof(uint64_t) == 8, "unsigned long isn't 8 bytes");
#include <errno.h>
#include <unistd.h> // 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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d5d06cf

Please sign in to comment.