Reviewers: Toon Verwaest,
Message:
Hey Toon,
Another method moved out of the platform files. PTAL
-- Benedikt
Description:
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.
Please review this at https://codereview.chromium.org/23655004/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/cpu.h
M src/cpu.cc
M src/isolate.cc
M src/platform-posix.cc
M src/platform-win32.cc
M src/platform.h
M test/cctest/test-cpu.cc
M test/cctest/test-platform.cc
Index: src/cpu.cc
diff --git a/src/cpu.cc b/src/cpu.cc
index
06a03115bbe8692d4d56e8298d423f8b3b647b44..26eca616e347e7175b94bb0ab1eeca3270d61da9
100644
--- a/src/cpu.cc
+++ b/src/cpu.cc
@@ -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 {
@@ -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: src/cpu.h
diff --git a/src/cpu.h b/src/cpu.h
index
ef58b4cdd2f126f2fd4feeb8a822ba90aeb0a454..58c7f5d9d4a8b8610eaca8c00e7c8866c3d99931
100644
--- 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: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index
774ad5ca5647271853a94320bb8be2d58b887765..54329b7b98e583acf32548d974a3a66334d8cb3c
100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -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: src/platform-posix.cc
diff --git a/src/platform-posix.cc b/src/platform-posix.cc
index
1244493593b4db44aa67ab9def68b1e433a88d07..58d0a2478dbf564effd2b81403fd5455ce262c52
100644
--- a/src/platform-posix.cc
+++ b/src/platform-posix.cc
@@ -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: src/platform-win32.cc
diff --git a/src/platform-win32.cc b/src/platform-win32.cc
index
f52bb43d9c0ca8696c49cf4b8efe886fdba618b5..c136631f00272659ed76f845ca8fd59c965ddd4d
100644
--- a/src/platform-win32.cc
+++ b/src/platform-win32.cc
@@ -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: src/platform.h
diff --git a/src/platform.h b/src/platform.h
index
3576d8348416056ed229e25c2d4f5c37315799a8..a42bb5a20e33759cd7690c2909bb0f1d16e7efc8
100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -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: test/cctest/test-cpu.cc
diff --git a/test/cctest/test-cpu.cc b/test/cctest/test-cpu.cc
index
1c61ab1c46fd151068caa40bdae559f7332efcb1..06966c68c86296e510edb8899f4d7deb0343f108
100644
--- a/test/cctest/test-cpu.cc
+++ b/test/cctest/test-cpu.cc
@@ -48,3 +48,8 @@ TEST(FeatureImplications) {
// arm features
CHECK(!cpu.has_vfp3_d32() || cpu.has_vfp3());
}
+
+
+TEST(NumberOfProcessorsOnline) {
+ CHECK_GT(CPU::NumberOfProcessorsOnline(), 0);
+}
Index: test/cctest/test-platform.cc
diff --git a/test/cctest/test-platform.cc b/test/cctest/test-platform.cc
index
2d8eb201e88a39eb6380e1de8a2ce1bd6541f899..079cbd121be2fefd5ab6ff4dbb24fb935c5bc790
100644
--- a/test/cctest/test-platform.cc
+++ b/test/cctest/test-platform.cc
@@ -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.