Skip to content

Commit 0ca1b42

Browse files
committed
xplat: get physical processor count + fix test build ch help
Multi purpose PR - Implement dwNumberOf PhysicalProcessors support xplat (was xplat-todo) - Fix xplat build under fusion machine (ifdef SSE_4_2) - Fix ch flag argument help output for test build
1 parent adaf96f commit 0ca1b42

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

bin/ChakraCore/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ target_include_directories (
2020
# pthread: For threading
2121
# stdc++/gcc_s: C++ runtime code
2222
# dl: For shared library loading related functions
23-
# icuuc: For the ICU (xplat-todo: Make this optional)
2423
#
2524
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
2625
set(LINKER_START_GROUP

bin/ch/ch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void __stdcall PrintUsageFormat()
6969

7070
void __stdcall PrintUsage()
7171
{
72-
#ifndef DEBUG
72+
#if !defined(ENABLE_DEBUG_CONFIG_OPTIONS)
7373
wprintf(_u("\nUsage: %s <source file> %s"), hostName,
7474
_u("\n[flaglist] is not supported for Release mode\n"));
7575
#else

lib/Backend/Encoder.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,6 @@ uint Encoder::CalculateCRC(uint bufferCRC, size_t data)
953953
}
954954
#endif
955955
#endif
956-
957956
return CalculateCRC32(bufferCRC, data);
958957
}
959958

lib/Common/Core/SysInfo.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#endif
99
#include <wincrypt.h>
1010
#include <VersionHelpers.h>
11-
11+
#ifdef __APPLE__
12+
#include <sys/sysctl.h> // sysctl*
13+
#elif defined(__linux__)
14+
#include <unistd.h> // sysconf
15+
#endif
1216
// Initialization order
1317
// AB AutoSystemInfo
1418
// AD PerfCounter
@@ -119,9 +123,9 @@ AutoSystemInfo::Initialize()
119123
bool
120124
AutoSystemInfo::InitPhysicalProcessorCount()
121125
{
126+
DWORD countPhysicalProcessor = 0;
122127
#ifdef _WIN32
123128
DWORD size = 0;
124-
DWORD countPhysicalProcessor = 0;
125129
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pBufferCurrent;
126130
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pBufferStart;
127131
BOOL bResult;
@@ -133,8 +137,7 @@ AutoSystemInfo::InitPhysicalProcessorCount()
133137

134138
this->dwNumberOfPhysicalProcessors = this->dwNumberOfProcessors;
135139

136-
// xplat-todo: figure out #physical_cores
137-
#ifdef _WIN32
140+
#if defined(_WIN32)
138141
bResult = GetLogicalProcessorInformation(NULL, &size);
139142

140143
if (bResult || GetLastError() != ERROR_INSUFFICIENT_BUFFER || !size)
@@ -143,7 +146,6 @@ AutoSystemInfo::InitPhysicalProcessorCount()
143146
}
144147

145148
DWORD count = (size) / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
146-
147149
if (size != count * sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION))
148150
{
149151
Assert(false);
@@ -172,9 +174,29 @@ AutoSystemInfo::InitPhysicalProcessorCount()
172174
}
173175

174176
NoCheckHeapDeleteArray(count, pBufferStart);
177+
#elif defined(__APPLE__)
178+
std::size_t szCount = sizeof(countPhysicalProcessor);
179+
sysctlbyname("hw.physicalcpu", &countPhysicalProcessor, &szCount, nullptr, 0);
175180

181+
if (countPhysicalProcessor < 1)
182+
{
183+
int nMIB[2] = {CTL_HW, HW_NCPU}; // fallback. Depracated on latest OS
184+
sysctl(nMIB, 2, &countPhysicalProcessor, &szCount, nullptr, 0);
185+
if (countPhysicalProcessor < 1)
186+
{
187+
countPhysicalProcessor = 1;
188+
}
189+
}
190+
#elif defined(__linux__)
191+
countPhysicalProcessor = sysconf(_SC_NPROCESSORS_ONLN);
192+
#else
193+
// implementation for __linux__ should work for some others.
194+
// same applies to __APPLE__ implementation
195+
// instead of reimplementing, add corresponding preprocessors above
196+
#error "NOT Implemented"
197+
#endif
176198
this->dwNumberOfPhysicalProcessors = countPhysicalProcessor;
177-
#endif // _WIN32
199+
178200
return true;
179201
}
180202

0 commit comments

Comments
 (0)