From: bmeurer@chromium.org Date: Wed, 28 Aug 2013 12:32:56 +0000 (+0000) Subject: Replace OS::NumberOfCores() with CPU::NumberOfProcessorsOnline(). X-Git-Tag: upstream/4.7.83~12776 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=caca2b32cf6853a37ad354c075f393dee82811dd;p=platform%2Fupstream%2Fv8.git 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. 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 --- diff --git a/src/cpu.cc b/src/cpu.cc index 06a0311..26eca61 100644 --- a/src/cpu.cc +++ b/src/cpu.cc @@ -30,14 +30,21 @@ #if V8_CC_MSVC #include // __cpuid() #endif +#if V8_OS_POSIX +#include // sysconf() +#endif #include #include +#include #include #include #include #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(sysconf(_SC_NPROCESSORS_ONLN)); +#endif +} + } } // namespace v8::internal diff --git a/src/cpu.h b/src/cpu.h index ef58b4c..58c7f5d 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(); diff --git a/src/isolate.cc b/src/isolate.cc index 774ad5c..54329b7 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; diff --git a/src/platform-posix.cc b/src/platform-posix.cc index 1244493..58d0a24 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) { diff --git a/src/platform-win32.cc b/src/platform-win32.cc index f52bb43..c136631 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(); diff --git a/src/platform.h b/src/platform.h index 3576d83..a42bb5a 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(); diff --git a/test/cctest/test-cpu.cc b/test/cctest/test-cpu.cc index 1c61ab1..06966c6 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); +} diff --git a/test/cctest/test-platform.cc b/test/cctest/test-platform.cc index 2d8eb20..079cbd1 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__