Move NumberOfProcessorsOnline from CPU to OS
authorjochen@chromium.org <jochen@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 26 May 2014 15:18:45 +0000 (15:18 +0000)
committerjochen@chromium.org <jochen@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 26 May 2014 15:18:45 +0000 (15:18 +0000)
It's really more an OS-level information, and this way the default
platform doesn't depend on CPU-level details

BUG=none
R=yangguo@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/300713002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21501 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

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

index 8d9afd8..fe004d1 100644 (file)
@@ -496,16 +496,4 @@ 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 df34d3c..a872585 100644 (file)
--- a/src/cpu.h
+++ b/src/cpu.h
@@ -77,9 +77,6 @@ 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();
-
   // Flush instruction cache.
   static void FlushICache(void* start, size_t size);
 
index b04fa71..d0ef477 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1476,7 +1476,7 @@ int Shell::Main(int argc, char* argv[]) {
   v8::ResourceConstraints constraints;
   constraints.ConfigureDefaults(i::OS::TotalPhysicalMemory(),
                                 i::OS::MaxVirtualMemory(),
-                                i::CPU::NumberOfProcessorsOnline());
+                                i::OS::NumberOfProcessorsOnline());
   v8::SetResourceConstraints(isolate, &constraints);
 #endif
   DumbLineEditor dumb_line_editor(isolate);
index 86e60e2..d204726 100644 (file)
@@ -1900,7 +1900,7 @@ bool Isolate::Init(Deserializer* des) {
   // once ResourceConstraints becomes an argument to the Isolate constructor.
   if (max_available_threads_ < 1) {
     // Choose the default between 1 and 4.
-    max_available_threads_ = Max(Min(CPU::NumberOfProcessorsOnline(), 4), 1);
+    max_available_threads_ = Max(Min(OS::NumberOfProcessorsOnline(), 4), 1);
   }
 
   if (!FLAG_job_based_sweeping) {
index 6ff8830..1bd7b0f 100644 (file)
@@ -9,8 +9,7 @@
 
 // TODO(jochen): We should have our own version of checks.h.
 #include "../checks.h"
-// TODO(jochen): Why is cpu.h not in platform/?
-#include "../cpu.h"
+#include "../platform.h"
 #include "worker-thread.h"
 
 namespace v8 {
@@ -40,7 +39,7 @@ void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) {
   LockGuard<Mutex> guard(&lock_);
   ASSERT(thread_pool_size >= 0);
   if (thread_pool_size < 1)
-    thread_pool_size = CPU::NumberOfProcessorsOnline();
+    thread_pool_size = OS::NumberOfProcessorsOnline();
   thread_pool_size_ =
       std::max(std::min(thread_pool_size, kMaxThreadPoolSize), 1);
 }
index be1ace1..1972505 100644 (file)
@@ -57,6 +57,11 @@ unsigned OS::CpuFeaturesImpliedByPlatform() {
 }
 
 
+int OS::NumberOfProcessorsOnline() {
+  return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
+}
+
+
 // Maximum size of the virtual memory.  0 means there is no artificial
 // limit.
 
index df0ec2e..9c7f5a9 100644 (file)
@@ -1196,6 +1196,13 @@ unsigned OS::CpuFeaturesImpliedByPlatform() {
 }
 
 
+int OS::NumberOfProcessorsOnline() {
+  SYSTEM_INFO info;
+  GetSystemInfo(&info);
+  return info.dwNumberOfProcessors;
+}
+
+
 double OS::nan_value() {
 #ifdef _MSC_VER
   // Positive Quiet NaN with no payload (aka. Indeterminate) has all bits
index 2fa3561..7d857cc 100644 (file)
@@ -274,6 +274,9 @@ class OS {
   // positions indicated by the members of the CpuFeature enum from globals.h
   static unsigned CpuFeaturesImpliedByPlatform();
 
+  // Returns the number of processors online.
+  static int NumberOfProcessorsOnline();
+
   // The total amount of physical memory available on the current system.
   static uint64_t TotalPhysicalMemory();
 
index 06966c6..07ba64d 100644 (file)
@@ -51,5 +51,5 @@ TEST(FeatureImplications) {
 
 
 TEST(NumberOfProcessorsOnline) {
-  CHECK_GT(CPU::NumberOfProcessorsOnline(), 0);
+  CHECK_GT(OS::NumberOfProcessorsOnline(), 0);
 }