Revision: 16392
Author:   [email protected]
Date:     Wed Aug 28 12:32:56 2013 UTC
Log:      Replace OS::NumberOfCores() with CPU::NumberOfProcessorsOnline().

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.

[email protected]

Review URL: https://codereview.chromium.org/23655004
http://code.google.com/p/v8/source/detail?r=16392

Modified:
 /branches/bleeding_edge/src/cpu.cc
 /branches/bleeding_edge/src/cpu.h
 /branches/bleeding_edge/src/isolate.cc
 /branches/bleeding_edge/src/platform-posix.cc
 /branches/bleeding_edge/src/platform-win32.cc
 /branches/bleeding_edge/src/platform.h
 /branches/bleeding_edge/test/cctest/test-cpu.cc
 /branches/bleeding_edge/test/cctest/test-platform.cc

=======================================
--- /branches/bleeding_edge/src/cpu.cc  Wed Aug 28 09:53:13 2013 UTC
+++ /branches/bleeding_edge/src/cpu.cc  Wed Aug 28 12:32:56 2013 UTC
@@ -30,14 +30,21 @@
 #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 {
@@ -443,5 +450,17 @@
   delete[] cpu_model;
 #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
=======================================
--- /branches/bleeding_edge/src/cpu.h   Mon Aug 26 09:37:39 2013 UTC
+++ /branches/bleeding_edge/src/cpu.h   Wed Aug 28 12:32:56 2013 UTC
@@ -98,6 +98,9 @@
   bool has_vfp() const { return has_vfp_; }
   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();
=======================================
--- /branches/bleeding_edge/src/isolate.cc      Tue Aug 27 11:55:08 2013 UTC
+++ /branches/bleeding_edge/src/isolate.cc      Wed Aug 28 12:32:56 2013 UTC
@@ -137,7 +137,7 @@

 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;
=======================================
--- /branches/bleeding_edge/src/platform-posix.cc Wed Aug 28 11:38:20 2013 UTC +++ /branches/bleeding_edge/src/platform-posix.cc Wed Aug 28 12:32:56 2013 UTC
@@ -217,11 +217,6 @@
   useconds_t ms = static_cast<useconds_t>(milliseconds);
   usleep(1000 * ms);
 }
-
-
-int OS::NumberOfCores() {
-  return sysconf(_SC_NPROCESSORS_ONLN);
-}


 void OS::Abort() {
=======================================
--- /branches/bleeding_edge/src/platform-win32.cc Wed Aug 28 11:38:20 2013 UTC +++ /branches/bleeding_edge/src/platform-win32.cc Wed Aug 28 12:32:56 2013 UTC
@@ -989,13 +989,6 @@
 void OS::Sleep(int milliseconds) {
   ::Sleep(milliseconds);
 }
-
-
-int OS::NumberOfCores() {
-  SYSTEM_INFO info;
-  GetSystemInfo(&info);
-  return info.dwNumberOfProcessors;
-}


 void OS::Abort() {
=======================================
--- /branches/bleeding_edge/src/platform.h      Wed Aug 28 11:38:20 2013 UTC
+++ /branches/bleeding_edge/src/platform.h      Wed Aug 28 12:32:56 2013 UTC
@@ -273,8 +273,6 @@
   // Sleep for a number of milliseconds.
   static void Sleep(const int milliseconds);

-  static int NumberOfCores();
-
   // Abort the current process.
   static void Abort();

=======================================
--- /branches/bleeding_edge/test/cctest/test-cpu.cc Mon Aug 26 09:37:39 2013 UTC +++ /branches/bleeding_edge/test/cctest/test-cpu.cc Wed Aug 28 12:32:56 2013 UTC
@@ -48,3 +48,8 @@
   // arm features
   CHECK(!cpu.has_vfp3_d32() || cpu.has_vfp3());
 }
+
+
+TEST(NumberOfProcessorsOnline) {
+  CHECK_GT(CPU::NumberOfProcessorsOnline(), 0);
+}
=======================================
--- /branches/bleeding_edge/test/cctest/test-platform.cc Fri Jul 5 09:52:11 2013 UTC +++ /branches/bleeding_edge/test/cctest/test-platform.cc Wed Aug 28 12:32:56 2013 UTC
@@ -32,11 +32,6 @@

 using namespace ::v8::internal;

-TEST(NumberOfCores) {
-  CHECK_GT(OS::NumberOfCores(), 0);
-}
-
-
 #ifdef __GNUC__
 #define ASM __asm__ __volatile__

--
--
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/groups/opt_out.

Reply via email to