diff options
| author | mlippautz <mlippautz@chromium.org> | 2016-03-07 13:06:50 -0800 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-03-07 21:08:16 +0000 |
| commit | 40dfecc9eb4badcaa2f826f6562a5b6d45a637c8 (patch) | |
| tree | c6b0acced23577cd4fc83f2d85f0ace6f62df90e | |
| parent | 364f4ef0f205967019fbb0b55f0bbb96ab76ad7d (diff) | |
| download | chromium_src-40dfecc9eb4badcaa2f826f6562a5b6d45a637c8.zip chromium_src-40dfecc9eb4badcaa2f826f6562a5b6d45a637c8.tar.gz chromium_src-40dfecc9eb4badcaa2f826f6562a5b6d45a637c8.tar.bz2 | |
[gin] Provide number of available cores to V8
Provide V8 with the number of processors (-1) available to
avoid posting too many tasks to Chromium.
BUG=
Review URL: https://codereview.chromium.org/1677963003
Cr-Commit-Position: refs/heads/master@{#379640}
| -rw-r--r-- | gin/public/v8_platform.h | 1 | ||||
| -rw-r--r-- | gin/v8_platform.cc | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/gin/public/v8_platform.h b/gin/public/v8_platform.h index d1e703e..ad37a5c 100644 --- a/gin/public/v8_platform.h +++ b/gin/public/v8_platform.h @@ -19,6 +19,7 @@ class GIN_EXPORT V8Platform : public NON_EXPORTED_BASE(v8::Platform) { static V8Platform* Get(); // v8::Platform implementation. + size_t NumberOfAvailableBackgroundThreads() override; void CallOnBackgroundThread( v8::Task* task, v8::Platform::ExpectedRuntime expected_runtime) override; diff --git a/gin/v8_platform.cc b/gin/v8_platform.cc index be7f5c2..556f7fc 100644 --- a/gin/v8_platform.cc +++ b/gin/v8_platform.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/location.h" +#include "base/sys_info.h" #include "base/threading/worker_pool.h" #include "base/trace_event/trace_event.h" #include "gin/per_isolate_data.h" @@ -25,6 +26,19 @@ V8Platform::V8Platform() {} V8Platform::~V8Platform() {} +size_t V8Platform::NumberOfAvailableBackgroundThreads() { + // WorkerPool will currently always create additional threads for posted + // background tasks, unless there are threads sitting idle (on posix). + // Indicate that V8 should create no more than the number of cores available, + // reserving one core for the main thread. + const size_t available_cores = + static_cast<size_t>(base::SysInfo::NumberOfProcessors()); + if (available_cores > 1) { + return available_cores - 1; + } + return 1; +} + void V8Platform::CallOnBackgroundThread( v8::Task* task, v8::Platform::ExpectedRuntime expected_runtime) { |
