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
R=yangguo@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/300713002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21501 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
jochen@chromium.org 2014-05-26 15:18:45 +00:00
parent 4fd78904be
commit 0f73456d3f
9 changed files with 20 additions and 21 deletions

View File

@ -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

View File

@ -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);

View File

@ -1476,7 +1476,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);

View File

@ -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) {

View File

@ -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);
}

View File

@ -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.

View File

@ -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

View File

@ -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();

View File

@ -51,5 +51,5 @@ TEST(FeatureImplications) {
TEST(NumberOfProcessorsOnline) {
CHECK_GT(CPU::NumberOfProcessorsOnline(), 0);
CHECK_GT(OS::NumberOfProcessorsOnline(), 0);
}