Commit caca2b32 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

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
parent 1d3f6815
......@@ -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
......@@ -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();
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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();
......
......@@ -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();
......
......@@ -48,3 +48,8 @@ TEST(FeatureImplications) {
// arm features
CHECK(!cpu.has_vfp3_d32() || cpu.has_vfp3());
}
TEST(NumberOfProcessorsOnline) {
CHECK_GT(CPU::NumberOfProcessorsOnline(), 0);
}
......@@ -32,11 +32,6 @@
using namespace ::v8::internal;
TEST(NumberOfCores) {
CHECK_GT(OS::NumberOfCores(), 0);
}
#ifdef __GNUC__
#define ASM __asm__ __volatile__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment