Commit 0f73456d authored by jochen@chromium.org's avatar jochen@chromium.org

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
parent 4fd78904
...@@ -496,16 +496,4 @@ CPU::CPU() : stepping_(0), ...@@ -496,16 +496,4 @@ CPU::CPU() : stepping_(0),
#endif #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 } } // namespace v8::internal
...@@ -77,9 +77,6 @@ class CPU V8_FINAL BASE_EMBEDDED { ...@@ -77,9 +77,6 @@ class CPU V8_FINAL BASE_EMBEDDED {
bool has_vfp3() const { return has_vfp3_; } bool has_vfp3() const { return has_vfp3_; }
bool has_vfp3_d32() const { return has_vfp3_d32_; } bool has_vfp3_d32() const { return has_vfp3_d32_; }
// Returns the number of processors online.
static int NumberOfProcessorsOnline();
// Flush instruction cache. // Flush instruction cache.
static void FlushICache(void* start, size_t size); static void FlushICache(void* start, size_t size);
......
...@@ -1476,7 +1476,7 @@ int Shell::Main(int argc, char* argv[]) { ...@@ -1476,7 +1476,7 @@ int Shell::Main(int argc, char* argv[]) {
v8::ResourceConstraints constraints; v8::ResourceConstraints constraints;
constraints.ConfigureDefaults(i::OS::TotalPhysicalMemory(), constraints.ConfigureDefaults(i::OS::TotalPhysicalMemory(),
i::OS::MaxVirtualMemory(), i::OS::MaxVirtualMemory(),
i::CPU::NumberOfProcessorsOnline()); i::OS::NumberOfProcessorsOnline());
v8::SetResourceConstraints(isolate, &constraints); v8::SetResourceConstraints(isolate, &constraints);
#endif #endif
DumbLineEditor dumb_line_editor(isolate); DumbLineEditor dumb_line_editor(isolate);
......
...@@ -1900,7 +1900,7 @@ bool Isolate::Init(Deserializer* des) { ...@@ -1900,7 +1900,7 @@ bool Isolate::Init(Deserializer* des) {
// once ResourceConstraints becomes an argument to the Isolate constructor. // once ResourceConstraints becomes an argument to the Isolate constructor.
if (max_available_threads_ < 1) { if (max_available_threads_ < 1) {
// Choose the default between 1 and 4. // 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) { if (!FLAG_job_based_sweeping) {
......
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
// TODO(jochen): We should have our own version of checks.h. // TODO(jochen): We should have our own version of checks.h.
#include "../checks.h" #include "../checks.h"
// TODO(jochen): Why is cpu.h not in platform/? #include "../platform.h"
#include "../cpu.h"
#include "worker-thread.h" #include "worker-thread.h"
namespace v8 { namespace v8 {
...@@ -40,7 +39,7 @@ void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) { ...@@ -40,7 +39,7 @@ void DefaultPlatform::SetThreadPoolSize(int thread_pool_size) {
LockGuard<Mutex> guard(&lock_); LockGuard<Mutex> guard(&lock_);
ASSERT(thread_pool_size >= 0); ASSERT(thread_pool_size >= 0);
if (thread_pool_size < 1) if (thread_pool_size < 1)
thread_pool_size = CPU::NumberOfProcessorsOnline(); thread_pool_size = OS::NumberOfProcessorsOnline();
thread_pool_size_ = thread_pool_size_ =
std::max(std::min(thread_pool_size, kMaxThreadPoolSize), 1); std::max(std::min(thread_pool_size, kMaxThreadPoolSize), 1);
} }
......
...@@ -57,6 +57,11 @@ unsigned OS::CpuFeaturesImpliedByPlatform() { ...@@ -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 // Maximum size of the virtual memory. 0 means there is no artificial
// limit. // limit.
......
...@@ -1196,6 +1196,13 @@ unsigned OS::CpuFeaturesImpliedByPlatform() { ...@@ -1196,6 +1196,13 @@ unsigned OS::CpuFeaturesImpliedByPlatform() {
} }
int OS::NumberOfProcessorsOnline() {
SYSTEM_INFO info;
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
}
double OS::nan_value() { double OS::nan_value() {
#ifdef _MSC_VER #ifdef _MSC_VER
// Positive Quiet NaN with no payload (aka. Indeterminate) has all bits // Positive Quiet NaN with no payload (aka. Indeterminate) has all bits
......
...@@ -274,6 +274,9 @@ class OS { ...@@ -274,6 +274,9 @@ class OS {
// positions indicated by the members of the CpuFeature enum from globals.h // positions indicated by the members of the CpuFeature enum from globals.h
static unsigned CpuFeaturesImpliedByPlatform(); static unsigned CpuFeaturesImpliedByPlatform();
// Returns the number of processors online.
static int NumberOfProcessorsOnline();
// The total amount of physical memory available on the current system. // The total amount of physical memory available on the current system.
static uint64_t TotalPhysicalMemory(); static uint64_t TotalPhysicalMemory();
......
...@@ -51,5 +51,5 @@ TEST(FeatureImplications) { ...@@ -51,5 +51,5 @@ TEST(FeatureImplications) {
TEST(NumberOfProcessorsOnline) { TEST(NumberOfProcessorsOnline) {
CHECK_GT(CPU::NumberOfProcessorsOnline(), 0); CHECK_GT(OS::NumberOfProcessorsOnline(), 0);
} }
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