Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: content/renderer/render_process_impl.cc

Issue 2491823005: Initialize TaskScheduler in renderers. (Closed)
Patch Set: self-review Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/public/renderer/content_renderer_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/render_process_impl.h" 5 #include "content/renderer/render_process_impl.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
11 #include <objidl.h> 11 #include <objidl.h>
12 #include <mlang.h> 12 #include <mlang.h>
13 #endif 13 #endif
14 14
15 #include <stddef.h>
16
17 #include <vector>
18
19 #include "base/bind.h"
15 #include "base/command_line.h" 20 #include "base/command_line.h"
16 #include "base/compiler_specific.h" 21 #include "base/compiler_specific.h"
17 #include "base/feature_list.h" 22 #include "base/feature_list.h"
18 #include "base/sys_info.h" 23 #include "base/sys_info.h"
24 #include "base/task_scheduler/initialization_util.h"
25 #include "base/task_scheduler/scheduler_worker_pool_params.h"
26 #include "base/task_scheduler/task_scheduler.h"
27 #include "base/task_scheduler/task_traits.h"
28 #include "base/threading/platform_thread.h"
29 #include "base/time/time.h"
19 #include "content/child/site_isolation_stats_gatherer.h" 30 #include "content/child/site_isolation_stats_gatherer.h"
20 #include "content/public/common/content_features.h" 31 #include "content/public/common/content_features.h"
21 #include "content/public/common/content_switches.h" 32 #include "content/public/common/content_switches.h"
22 #include "content/public/renderer/content_renderer_client.h" 33 #include "content/public/renderer/content_renderer_client.h"
23 #include "third_party/WebKit/public/web/WebFrame.h" 34 #include "third_party/WebKit/public/web/WebFrame.h"
24 #include "v8/include/v8.h" 35 #include "v8/include/v8.h"
25 36
26 namespace { 37 namespace {
27 38
39 enum WorkerPoolType : size_t {
40 BACKGROUND = 0,
41 BACKGROUND_FILE_IO,
42 FOREGROUND,
43 FOREGROUND_FILE_IO,
44 WORKER_POOL_COUNT // Always last.
45 };
46
28 const base::Feature kV8_ES2015_TailCalls_Feature { 47 const base::Feature kV8_ES2015_TailCalls_Feature {
29 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT 48 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT
30 }; 49 };
31 50
32 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{ 51 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{
33 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT}; 52 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT};
34 53
35 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager", 54 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager",
36 base::FEATURE_DISABLED_BY_DEFAULT}; 55 base::FEATURE_DISABLED_BY_DEFAULT};
37 56
38 const base::Feature kV8SerializeAgeCodeFeature{ 57 const base::Feature kV8SerializeAgeCodeFeature{
39 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT}; 58 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT};
40 59
41 void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) { 60 void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) {
42 if (base::FeatureList::IsEnabled(feature)) { 61 if (base::FeatureList::IsEnabled(feature)) {
43 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); 62 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
44 } 63 }
45 } 64 }
46 65
47 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) { 66 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) {
48 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { 67 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) {
49 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); 68 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
50 } 69 }
51 } 70 }
52 71
72 std::vector<base::SchedulerWorkerPoolParams>
73 GetDefaultSchedulerWorkerPoolParams() {
74 using StandbyThreadPolicy =
75 base::SchedulerWorkerPoolParams::StandbyThreadPolicy;
76 using ThreadPriority = base::ThreadPriority;
77 std::vector<base::SchedulerWorkerPoolParams> params_vector;
78 #if defined(OS_ANDROID)
79 params_vector.emplace_back(
80 "RendererBackground", ThreadPriority::BACKGROUND,
81 StandbyThreadPolicy::LAZY,
82 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0),
83 base::TimeDelta::FromSeconds(30));
84 params_vector.emplace_back(
85 "RendererBackgroundFileIO", ThreadPriority::BACKGROUND,
86 StandbyThreadPolicy::LAZY,
87 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0),
88 base::TimeDelta::FromSeconds(30));
89 params_vector.emplace_back(
90 "RendererForeground", ThreadPriority::NORMAL, StandbyThreadPolicy::LAZY,
91 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0),
92 base::TimeDelta::FromSeconds(30));
93 params_vector.emplace_back(
94 "RendererForegroundFileIO", ThreadPriority::NORMAL,
95 StandbyThreadPolicy::LAZY,
96 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0),
97 base::TimeDelta::FromSeconds(30));
98 #else
99 params_vector.emplace_back(
100 "RendererBackground", ThreadPriority::BACKGROUND,
101 StandbyThreadPolicy::LAZY,
102 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0),
103 base::TimeDelta::FromSeconds(30));
104 params_vector.emplace_back(
105 "RendererBackgroundFileIO", ThreadPriority::BACKGROUND,
106 StandbyThreadPolicy::LAZY,
107 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0),
108 base::TimeDelta::FromSeconds(30));
109 params_vector.emplace_back(
110 "RendererForeground", ThreadPriority::NORMAL, StandbyThreadPolicy::LAZY,
111 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0),
112 base::TimeDelta::FromSeconds(30));
113 params_vector.emplace_back(
114 "RendererForegroundFileIO", ThreadPriority::NORMAL,
115 StandbyThreadPolicy::LAZY,
116 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0),
gab 2016/12/09 20:20:55 Don't think we want nearly that many threads. Let'
117 base::TimeDelta::FromSeconds(30));
118 #endif
119 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size());
120 return params_vector;
121 }
122
123 // Returns the worker pool index for |traits| based off of worker pools defined
124 // in GetDefaultSchedulerWorkerPoolParams(). Defaults to FOREGROUND.
125 size_t DefaultRendererWorkerPoolIndexForTraits(const base::TaskTraits& traits) {
126 const bool is_background =
127 traits.priority() == base::TaskPriority::BACKGROUND;
128 if (traits.with_file_io())
129 return is_background ? BACKGROUND_FILE_IO : FOREGROUND_FILE_IO;
130
131 return is_background ? BACKGROUND : FOREGROUND;
132 }
133
134 bool IsSingleProcess() {
135 return base::CommandLine::ForCurrentProcess()->HasSwitch(
136 switches::kSingleProcess);
137 }
138
139 void InitializeTaskScheduler() {
140 if (IsSingleProcess()) {
141 // There should already be a TaskScheduler when the renderer runs inside the
142 // browser process.
143 DCHECK(base::TaskScheduler::GetInstance());
144 return;
145 }
146 DCHECK(!base::TaskScheduler::GetInstance());
147
148 std::vector<base::SchedulerWorkerPoolParams> params_vector;
149 base::TaskScheduler::WorkerPoolIndexForTraitsCallback
150 index_to_traits_callback;
151 GetContentClient()->renderer()->GetTaskSchedulerInitializationParams(
152 &params_vector, &index_to_traits_callback);
153
154 if (params_vector.empty()) {
155 params_vector = GetDefaultSchedulerWorkerPoolParams();
156 index_to_traits_callback =
157 base::Bind(&DefaultRendererWorkerPoolIndexForTraits);
158 }
159 DCHECK(index_to_traits_callback);
160
161 base::TaskScheduler::CreateAndSetDefaultTaskScheduler(
162 params_vector, index_to_traits_callback);
163 }
164
53 } // namespace 165 } // namespace
54 166
55 namespace content { 167 namespace content {
56 168
57 RenderProcessImpl::RenderProcessImpl() 169 RenderProcessImpl::RenderProcessImpl()
58 : enabled_bindings_(0) { 170 : enabled_bindings_(0) {
59 #if defined(OS_WIN) 171 #if defined(OS_WIN)
60 // HACK: See http://b/issue?id=1024307 for rationale. 172 // HACK: See http://b/issue?id=1024307 for rationale.
61 if (GetModuleHandle(L"LPK.DLL") == NULL) { 173 if (GetModuleHandle(L"LPK.DLL") == NULL) {
62 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works 174 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 *base::CommandLine::ForCurrentProcess(); 208 *base::CommandLine::ForCurrentProcess();
97 209
98 if (command_line.HasSwitch(switches::kJavaScriptFlags)) { 210 if (command_line.HasSwitch(switches::kJavaScriptFlags)) {
99 std::string flags( 211 std::string flags(
100 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); 212 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags));
101 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); 213 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size()));
102 } 214 }
103 215
104 SiteIsolationStatsGatherer::SetEnabled( 216 SiteIsolationStatsGatherer::SetEnabled(
105 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats()); 217 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats());
218
219 InitializeTaskScheduler();
106 } 220 }
107 221
108 RenderProcessImpl::~RenderProcessImpl() { 222 RenderProcessImpl::~RenderProcessImpl() {
109 #ifndef NDEBUG 223 #ifndef NDEBUG
110 int count = blink::WebFrame::instanceCount(); 224 int count = blink::WebFrame::instanceCount();
111 if (count) 225 if (count)
112 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; 226 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES";
113 #endif 227 #endif
114 228
229 if (!IsSingleProcess()) {
230 DCHECK(base::TaskScheduler::GetInstance());
231 base::TaskScheduler::GetInstance()->Shutdown();
232 }
233
115 GetShutDownEvent()->Signal(); 234 GetShutDownEvent()->Signal();
116 } 235 }
117 236
118 void RenderProcessImpl::AddBindings(int bindings) { 237 void RenderProcessImpl::AddBindings(int bindings) {
119 enabled_bindings_ |= bindings; 238 enabled_bindings_ |= bindings;
120 } 239 }
121 240
122 int RenderProcessImpl::GetEnabledBindings() const { 241 int RenderProcessImpl::GetEnabledBindings() const {
123 return enabled_bindings_; 242 return enabled_bindings_;
124 } 243 }
125 244
126 } // namespace content 245 } // namespace content
OLDNEW
« no previous file with comments | « content/public/renderer/content_renderer_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698