The name NumberOfCores is misleading, as it does not return the
actual number of cores. While NumberOfProcessorsOnline is also
not a great name, it's at least consistent with the operating
system terminology.
R=verwaest@chromium.org
Review URL: https://codereview.chromium.org/
23655004
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16392
ce2b1a6d-e550-0410-aec6-
3dcde31c8c00
#if V8_CC_MSVC
#include <intrin.h> // __cpuid()
#endif
+#if V8_OS_POSIX
+#include <unistd.h> // sysconf()
+#endif
#include <algorithm>
#include <cctype>
+#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "checks.h"
+#if V8_OS_WIN
+#include "win32-headers.h"
+#endif
namespace v8 {
namespace internal {
#endif
}
+
+// static
+int CPU::NumberOfProcessorsOnline() {
+#if V8_OS_WIN
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+ return info.dwNumberOfProcessors;
+#else
+ return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
+#endif
+}
+
} } // namespace v8::internal
bool has_vfp3() const { return has_vfp3_; }
bool has_vfp3_d32() const { return has_vfp3_d32_; }
+ // Returns the number of processors online.
+ static int NumberOfProcessorsOnline() V8_WARN_UNUSED_RESULT;
+
// Initializes the cpu architecture support. Called once at VM startup.
static void SetUp();
int SystemThreadManager::NumberOfParallelSystemThreads(
ParallelSystemComponent type) {
- int number_of_threads = Min(OS::NumberOfCores(), kMaxThreads);
+ int number_of_threads = Min(CPU::NumberOfProcessorsOnline(), kMaxThreads);
ASSERT(number_of_threads > 0);
if (number_of_threads == 1) {
return 0;
}
-int OS::NumberOfCores() {
- return sysconf(_SC_NPROCESSORS_ONLN);
-}
-
-
void OS::Abort() {
// Redirect to std abort to signal abnormal program termination.
if (FLAG_break_on_abort) {
}
-int OS::NumberOfCores() {
- SYSTEM_INFO info;
- GetSystemInfo(&info);
- return info.dwNumberOfProcessors;
-}
-
-
void OS::Abort() {
if (IsDebuggerPresent() || FLAG_break_on_abort) {
DebugBreak();
// Sleep for a number of milliseconds.
static void Sleep(const int milliseconds);
- static int NumberOfCores();
-
// Abort the current process.
static void Abort();
// arm features
CHECK(!cpu.has_vfp3_d32() || cpu.has_vfp3());
}
+
+
+TEST(NumberOfProcessorsOnline) {
+ CHECK_GT(CPU::NumberOfProcessorsOnline(), 0);
+}
using namespace ::v8::internal;
-TEST(NumberOfCores) {
- CHECK_GT(OS::NumberOfCores(), 0);
-}
-
-
#ifdef __GNUC__
#define ASM __asm__ __volatile__