Reviewers: Yang,

Description:
Move NumberOfProcessorsOnline from CPU to OS

It's really more an OS-level information, and this way the default
platform doesn't depend on CPU-level details

BUG=none
[email protected]
LOG=n

Please review this at https://codereview.chromium.org/300713002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+20, -21 lines):
  M src/cpu.h
  M src/cpu.cc
  M src/d8.cc
  M src/isolate.cc
  M src/libplatform/default-platform.cc
  M src/platform.h
  M src/platform-posix.cc
  M src/platform-win32.cc
  M test/cctest/test-cpu.cc


Index: src/cpu.cc
diff --git a/src/cpu.cc b/src/cpu.cc
index 8d9afd84ae444c1288d7ad3205ea51293932638a..fe004d10ffdde57dd75b64cebf513df8c93e73f1 100644
--- a/src/cpu.cc
+++ b/src/cpu.cc
@@ -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: src/cpu.h
diff --git a/src/cpu.h b/src/cpu.h
index df34d3c82a896f842938631c5e2deb2ee097e63a..a8725851b19cbeab2a64d977be3657acdaac7d06 100644
--- 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: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index ffc58e6478377f592210946e292b1a72d9337dfe..198d5b7981c935d60fc57b372c87717454cfcf50 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1478,7 +1478,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: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 86e60e2c7939241c2be32f475ebba7397c293321..d204726f8b0a8d2c19be2b36c08ace15c53a9864 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -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: src/libplatform/default-platform.cc
diff --git a/src/libplatform/default-platform.cc b/src/libplatform/default-platform.cc index 6ff8830fb26870a266005e296ff042ef1c79c4b0..1bd7b0f25ae200514add2448c84700c34067135f 100644
--- a/src/libplatform/default-platform.cc
+++ b/src/libplatform/default-platform.cc
@@ -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: src/platform-posix.cc
diff --git a/src/platform-posix.cc b/src/platform-posix.cc
index be1ace1d628000512082718bcc3c368efc76c3c9..1972505565eef5c7dff7cb0a282a750547d7bdf0 100644
--- a/src/platform-posix.cc
+++ b/src/platform-posix.cc
@@ -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: src/platform-win32.cc
diff --git a/src/platform-win32.cc b/src/platform-win32.cc
index df0ec2ebaf88447deef2e30fd5615629e680e050..9c7f5a9b4f521477117e56447f354ff20273fb5e 100644
--- a/src/platform-win32.cc
+++ b/src/platform-win32.cc
@@ -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: src/platform.h
diff --git a/src/platform.h b/src/platform.h
index 2fa3561d7dea18f2b73df474a8c70e6c0fa47332..7d857cc0dfd8042a91dfd11c461edce3c80885e7 100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -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: test/cctest/test-cpu.cc
diff --git a/test/cctest/test-cpu.cc b/test/cctest/test-cpu.cc
index 06966c68c86296e510edb8899f4d7deb0343f108..07ba64db1ada9142ff525e5638ae664be9e5cd2e 100644
--- a/test/cctest/test-cpu.cc
+++ b/test/cctest/test-cpu.cc
@@ -51,5 +51,5 @@ TEST(FeatureImplications) {


 TEST(NumberOfProcessorsOnline) {
-  CHECK_GT(CPU::NumberOfProcessorsOnline(), 0);
+  CHECK_GT(OS::NumberOfProcessorsOnline(), 0);
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to