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

Commit 0ea5fc4

Browse files
echesakovRussKeldorph
authored andcommitted
Use sysconf(_SC_NPROCESSORS_CONF) instead of sysconf(_SC_NPROCESSORS_ONLN) in PAL and GC on ARM and ARM64
1 parent 9550fc8 commit 0ea5fc4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/gc/unix/gcenv.unix.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
#include <unistd.h> // sysconf
4141
#include "globals.h"
4242

43+
#if defined(_ARM_) || defined(_ARM64_)
44+
#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_CONF
45+
#else
46+
#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_ONLN
47+
#endif
48+
4349
// The cachced number of logical CPUs observed.
4450
static uint32_t g_logicalCpuCount = 0;
4551

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

6975
// Calculate and cache the number of processors on this machine
70-
int cpuCount = sysconf(_SC_NPROCESSORS_ONLN);
76+
int cpuCount = sysconf(SYSCONF_GET_NUMPROCS);
7177
if (cpuCount == -1)
7278
{
7379
return false;

src/pal/src/misc/sysinfo.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,18 @@ PAL_GetLogicalCpuCountFromOS()
103103
int nrcpus = 0;
104104

105105
#if HAVE_SYSCONF
106-
nrcpus = sysconf(_SC_NPROCESSORS_ONLN);
106+
107+
#if defined(_ARM_) || defined(_ARM64_)
108+
#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_CONF
109+
#define SYSCONF_GET_NUMPROCS_NAME "_SC_NPROCESSORS_CONF"
110+
#else
111+
#define SYSCONF_GET_NUMPROCS _SC_NPROCESSORS_ONLN
112+
#define SYSCONF_GET_NUMPROCS_NAME "_SC_NPROCESSORS_ONLN"
113+
#endif
114+
nrcpus = sysconf(SYSCONF_GET_NUMPROCS);
107115
if (nrcpus < 1)
108116
{
109-
ASSERT("sysconf failed for _SC_NPROCESSORS_ONLN (%d)\n", errno);
117+
ASSERT("sysconf failed for %s (%d)\n", SYSCONF_GET_NUMPROCS_NAME, errno);
110118
}
111119
#elif HAVE_SYSCTL
112120
int rc;

0 commit comments

Comments
 (0)