Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Use sysconf(_SC_NPROCESSORS_CONF) instead of sysconf(_SC_NPROCESSORS_…
Browse files Browse the repository at this point in the history
…ONLN) in PAL and GC ONLY on ARM and ARM64 (#18289)
  • Loading branch information
echesakov authored Jun 5, 2018
1 parent 071902e commit 79aadb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
#include <unistd.h> // sysconf
#include "globals.h"

#if defined(_ARM_) || defined(_ARM64_)
#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_CONF
#else
#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_ONLN
#endif

// The cachced number of logical CPUs observed.
static uint32_t g_logicalCpuCount = 0;

Expand Down Expand Up @@ -67,7 +73,7 @@ bool GCToOSInterface::Initialize()
g_pageSizeUnixInl = uint32_t((pageSize > 0) ? pageSize : 0x1000);

// Calculate and cache the number of processors on this machine
int cpuCount = sysconf(_SC_NPROCESSORS_CONF);
int cpuCount = sysconf(SYSCONF_GET_NUMPROCS);
if (cpuCount == -1)
{
return false;
Expand Down
12 changes: 10 additions & 2 deletions src/pal/src/misc/sysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,18 @@ PAL_GetLogicalCpuCountFromOS()
int nrcpus = 0;

#if HAVE_SYSCONF
nrcpus = sysconf(_SC_NPROCESSORS_CONF);

#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
nrcpus = sysconf(SYSCONF_GET_NUMPROCS);
if (nrcpus < 1)
{
ASSERT("sysconf failed for _SC_NPROCESSORS_CONF (%d)\n", errno);
ASSERT("sysconf failed for %s (%d)\n", SYSCONF_GET_NUMPROCS_NAME, errno);
}
#elif HAVE_SYSCTL
int rc;
Expand Down

0 comments on commit 79aadb8

Please sign in to comment.