Replace OS::NumberOfCores() with CPU::NumberOfProcessorsOnline().
authorbmeurer@chromium.org <bmeurer@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 28 Aug 2013 12:32:56 +0000 (12:32 +0000)
committerbmeurer@chromium.org <bmeurer@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 28 Aug 2013 12:32:56 +0000 (12:32 +0000)
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

src/cpu.cc
src/cpu.h
src/isolate.cc
src/platform-posix.cc
src/platform-win32.cc
src/platform.h
test/cctest/test-cpu.cc
test/cctest/test-platform.cc

index 06a0311..26eca61 100644 (file)
 #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 {
@@ -444,4 +451,16 @@ CPU::CPU() : stepping_(0),
 #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
index ef58b4c..58c7f5d 100644 (file)
--- a/src/cpu.h
+++ b/src/cpu.h
@@ -99,6 +99,9 @@ class CPU V8_FINAL BASE_EMBEDDED {
   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();
 
index 774ad5c..54329b7 100644 (file)
@@ -137,7 +137,7 @@ v8::TryCatch* ThreadLocalTop::TryCatchHandler() {
 
 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;
index 1244493..58d0a24 100644 (file)
@@ -219,11 +219,6 @@ void OS::Sleep(int milliseconds) {
 }
 
 
-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) {
index f52bb43..c136631 100644 (file)
@@ -991,13 +991,6 @@ void OS::Sleep(int milliseconds) {
 }
 
 
-int OS::NumberOfCores() {
-  SYSTEM_INFO info;
-  GetSystemInfo(&info);
-  return info.dwNumberOfProcessors;
-}
-
-
 void OS::Abort() {
   if (IsDebuggerPresent() || FLAG_break_on_abort) {
     DebugBreak();
index 3576d83..a42bb5a 100644 (file)
@@ -273,8 +273,6 @@ class OS {
   // Sleep for a number of milliseconds.
   static void Sleep(const int milliseconds);
 
-  static int NumberOfCores();
-
   // Abort the current process.
   static void Abort();
 
index 1c61ab1..06966c6 100644 (file)
@@ -48,3 +48,8 @@ TEST(FeatureImplications) {
   // arm features
   CHECK(!cpu.has_vfp3_d32() || cpu.has_vfp3());
 }
+
+
+TEST(NumberOfProcessorsOnline) {
+  CHECK_GT(CPU::NumberOfProcessorsOnline(), 0);
+}
index 2d8eb20..079cbd1 100644 (file)
 
 using namespace ::v8::internal;
 
-TEST(NumberOfCores) {
-  CHECK_GT(OS::NumberOfCores(), 0);
-}
-
-
 #ifdef __GNUC__
 #define ASM __asm__ __volatile__