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

Side by Side Diff: components/task_scheduler_util/initialization/browser_util.cc

Issue 2553953002: Split initialization_util into a Hermetic Library and a Variations Library (Closed)
Patch Set: 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/task_scheduler_util/initialization/browser_util.h"
6
7 #include <map>
8 #include <string>
9 #include <vector>
fdoray 2016/12/06 17:22:23 <vector> already included in .h file
robliao 2016/12/07 00:03:54 Done.
10
11 #include "base/task_scheduler/initialization_util.h"
12 #include "base/task_scheduler/switches.h"
13 #include "base/task_scheduler/task_traits.h"
14 #include "base/threading/sequenced_worker_pool.h"
15 #include "build/build_config.h"
16
17 namespace task_scheduler_util {
18 namespace initialization {
19
20 namespace {
21
22 using StandbyThreadPolicy =
23 base::SchedulerWorkerPoolParams::StandbyThreadPolicy;
24 using ThreadPriority = base::ThreadPriority;
25
26 struct SchedulerWorkerPoolPredefinedParams {
27 const char* name;
28 ThreadPriority priority_hint;
29 };
30
31 } // namespace
32
33 std::vector<base::SchedulerWorkerPoolParams>
34 BrowserWorkerPoolConfigurationToSchedulerWorkerPoolParams(
35 const BrowserWorkerPoolsConfiguration& config) {
36 constexpr SchedulerWorkerPoolPredefinedParams kAllPredefinedParams[] = {
fdoray 2016/12/06 17:22:23 You could add a SingleWorkerPoolConfiguration* mem
gab 2016/12/06 19:16:07 static per https://groups.google.com/a/chromium.or
robliao 2016/12/07 00:03:54 This can't be static with the array inclusion chan
robliao 2016/12/07 00:03:54 I can live with that. Done.
37 {"Background", ThreadPriority::BACKGROUND},
38 {"BackgroundFileIO", ThreadPriority::BACKGROUND},
39 {"Foreground", ThreadPriority::NORMAL},
40 {"ForegroundFileIO", ThreadPriority::NORMAL},
41 };
42 static_assert(arraysize(kAllPredefinedParams) == WORKER_POOL_COUNT,
43 "Mismatched Worker Pool Types and Predefined Parameters");
44 constexpr size_t worker_pool_total_size =
45 sizeof(BrowserWorkerPoolsConfiguration);
46 constexpr size_t single_worker_pool_size =
47 sizeof(SingleWorkerPoolConfiguration);
fdoray 2016/12/06 17:22:23 Compute this the same way as in BrowserWorkerPools
robliao 2016/12/07 00:03:54 Done
48 static_assert(arraysize(kAllPredefinedParams) ==
49 worker_pool_total_size / single_worker_pool_size,
50 "Mismatched Predefined Parameters and Browser Worker Pools");
51 const SingleWorkerPoolConfiguration* const all_pools[]{
52 &config.background, &config.background_file_io, &config.foreground,
53 &config.foreground_file_io,
54 };
55 static_assert(arraysize(kAllPredefinedParams) == arraysize(all_pools),
fdoray 2016/12/06 17:22:23 Since most of the code in this file can be reused
robliao 2016/12/07 00:03:54 We can't do the rename because initialization/util
56 "Mismatched Prefined Parameters and All Pools Array");
57 std::vector<base::SchedulerWorkerPoolParams> params_vector;
58 for (size_t i = 0; i < arraysize(kAllPredefinedParams); ++i) {
59 const auto& predefined_param = kAllPredefinedParams[i];
60 const auto& pool_config = all_pools[i];
gab 2016/12/06 19:16:07 s/&/*/
robliao 2016/12/07 00:03:54 Done.
61 params_vector.emplace_back(
62 predefined_param.name, predefined_param.priority_hint,
63 pool_config->standby_thread_policy, pool_config->threads,
64 pool_config->detach_period);
65 }
66 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size());
67 return params_vector;
68 }
69
70 // Returns the worker pool index for |traits| defaulting to
71 // FOREGROUND or FOREGROUND_FILE_IO on unknown
fdoray 2016/12/06 17:22:23 wrap
gab 2016/12/06 19:16:07 "unknown priorities"? "non-background" priorities"
robliao 2016/12/07 00:03:54 Went with "any other" priorities.
robliao 2016/12/07 00:03:54 Done.
72 // priorities.
73 size_t BrowserWorkerPoolIndexForTraits(const base::TaskTraits& traits) {
74 const bool is_background =
75 traits.priority() == base::TaskPriority::BACKGROUND;
76 if (traits.with_file_io()) {
fdoray 2016/12/06 17:22:23 no braces
gab 2016/12/06 19:16:07 nit: no {}
robliao 2016/12/07 00:03:54 Done.
robliao 2016/12/07 00:03:54 Done.
77 return is_background ? BACKGROUND_FILE_IO : FOREGROUND_FILE_IO;
78 }
79 return is_background ? BACKGROUND : FOREGROUND;
80 }
81
82 std::vector<base::SchedulerWorkerPoolParams>
83 GetDefaultBrowserSchedulerWorkerPoolParams() {
84 constexpr size_t kNumWorkerPoolsDefined =
85 sizeof(BrowserWorkerPoolsConfiguration) /
86 sizeof(SingleWorkerPoolConfiguration);
87 static_assert(kNumWorkerPoolsDefined == 4,
88 "Expected 4 worker pools in BrowserWorkerPoolsConfiguration");
89 BrowserWorkerPoolsConfiguration config;
90 #if defined(OS_ANDROID) || defined(OS_IOS)
91 config.background.standby_thread_policy = StandbyThreadPolicy::ONE;
92 config.background.threads =
93 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0);
94 config.background.detach_period = base::TimeDelta::FromSeconds(30);
95
96 config.background_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
97 config.background_file_io.threads =
98 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0);
99 config.background_file_io.detach_period = base::TimeDelta::FromSeconds(30);
100
101 config.foreground.standby_thread_policy = StandbyThreadPolicy::ONE;
102 config.foreground.threads =
103 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0);
104 config.foreground.detach_period = base::TimeDelta::FromSeconds(30);
105
106 config.foreground_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
107 config.foreground_file_io.threads =
108 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0);
109 config.foreground_file_io.detach_period = base::TimeDelta::FromSeconds(30);
110 #else
111 config.background.standby_thread_policy = StandbyThreadPolicy::ONE;
112 config.background.threads =
113 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0);
114 config.background.detach_period = base::TimeDelta::FromSeconds(30);
115
116 config.background_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
117 config.background_file_io.threads =
118 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0);
119 config.background_file_io.detach_period = base::TimeDelta::FromSeconds(30);
120
121 config.foreground.standby_thread_policy = StandbyThreadPolicy::ONE;
122 config.foreground.threads =
123 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0);
124 config.foreground.detach_period = base::TimeDelta::FromSeconds(30);
125
126 config.foreground_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
127 config.foreground_file_io.threads =
128 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0);
129 config.foreground_file_io.detach_period = base::TimeDelta::FromSeconds(30);
130 #endif
131 return BrowserWorkerPoolConfigurationToSchedulerWorkerPoolParams(config);
132 }
133
134 } // namespace initialization
135 } // namespace task_scheduler_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698