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

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: Quick Wording Fix 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
10 #include "base/task_scheduler/initialization_util.h"
11 #include "base/task_scheduler/switches.h"
12 #include "base/task_scheduler/task_traits.h"
13 #include "base/threading/sequenced_worker_pool.h"
14 #include "build/build_config.h"
15
16 namespace task_scheduler_util {
17 namespace initialization {
18
19 namespace {
20
21 using StandbyThreadPolicy =
22 base::SchedulerWorkerPoolParams::StandbyThreadPolicy;
23 using ThreadPriority = base::ThreadPriority;
24
25 struct SchedulerWorkerPoolConfiguration {
26 const char* name;
27 ThreadPriority priority_hint;
28 const SingleWorkerPoolConfiguration& config;
fdoray 2016/12/07 13:34:11 SchedulerWorkerPoolConfiguration vs. SingleWorkerP
robliao 2016/12/07 18:39:19 Done.
29
30 SchedulerWorkerPoolConfiguration(
gab 2016/12/07 15:53:06 constructors go before members in style-guide for
robliao 2016/12/07 18:39:19 Done.
31 const char* name,
32 ThreadPriority priority_hint,
33 const SingleWorkerPoolConfiguration& config)
gab 2016/12/07 15:53:06 To avoid name clash since structs to use _ suffixe
robliao 2016/12/07 18:39:19 Done.
34 : name(name),
35 priority_hint(priority_hint),
36 config(config) {}
37 };
38
39 } // namespace
40
41 std::vector<base::SchedulerWorkerPoolParams>
42 BrowserWorkerPoolConfigurationToSchedulerWorkerPoolParams(
43 const BrowserWorkerPoolsConfiguration& config) {
44 const SchedulerWorkerPoolConfiguration worker_pool_config[] = {
45 SchedulerWorkerPoolConfiguration("Background",
46 ThreadPriority::BACKGROUND,
47 config.background),
48 SchedulerWorkerPoolConfiguration("BackgroundFileIO",
49 ThreadPriority::BACKGROUND,
50 config.background_file_io),
51 SchedulerWorkerPoolConfiguration("Foreground",
52 ThreadPriority::NORMAL,
53 config.foreground),
54 SchedulerWorkerPoolConfiguration("ForegroundFileIO",
55 ThreadPriority::NORMAL,
56 config.foreground_file_io),
57
58 };
59 static_assert(arraysize(worker_pool_config) == WORKER_POOL_COUNT,
60 "Mismatched Worker Pool Types and Predefined Parameters");
61 constexpr size_t kNumWorkerPoolsDefined = sizeof(config) /
62 sizeof(config.background);
63 static_assert(arraysize(worker_pool_config) == kNumWorkerPoolsDefined,
64 "Mismatch in predefined parameters and worker pools.");
65 std::vector<base::SchedulerWorkerPoolParams> params_vector;
66 for (size_t i = 0; i < arraysize(worker_pool_config); ++i) {
fdoray 2016/12/07 13:34:11 for (const auto& config : worker_pool_config) {
robliao 2016/12/07 18:39:19 Done.
67 const auto* const config = &worker_pool_config[i];
gab 2016/12/07 15:53:06 const auto& is fine (and prefered) in general, wha
robliao 2016/12/07 18:39:19 Acknowledged.
68 params_vector.emplace_back(
69 config->name, config->priority_hint,
70 config->config.standby_thread_policy, config->config.threads,
gab 2016/12/07 15:53:06 config->config is weird, can we change the name of
robliao 2016/12/07 18:39:19 config.config -> config.single_worker_pool_config
71 config->config.detach_period);
72 }
73 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size());
74 return params_vector;
75 }
76
77 // Returns the worker pool index for |traits| defaulting to FOREGROUND or
78 // FOREGROUND_FILE_IO on any other priorities.
79 size_t BrowserWorkerPoolIndexForTraits(const base::TaskTraits& traits) {
80 const bool is_background =
81 traits.priority() == base::TaskPriority::BACKGROUND;
82 if (traits.with_file_io())
83 return is_background ? BACKGROUND_FILE_IO : FOREGROUND_FILE_IO;
84
85 return is_background ? BACKGROUND : FOREGROUND;
86 }
87
88 std::vector<base::SchedulerWorkerPoolParams>
89 GetDefaultBrowserSchedulerWorkerPoolParams() {
90 constexpr size_t kNumWorkerPoolsDefined =
91 sizeof(BrowserWorkerPoolsConfiguration) /
92 sizeof(SingleWorkerPoolConfiguration);
93 static_assert(kNumWorkerPoolsDefined == 4,
94 "Expected 4 worker pools in BrowserWorkerPoolsConfiguration");
95 BrowserWorkerPoolsConfiguration config;
96 constexpr size_t kSizeAssignedFields =
97 sizeof(config.background.threads) +
98 sizeof(config.background.detach_period) +
99 sizeof(config.background.standby_thread_policy);
100 static_assert(kSizeAssignedFields == sizeof(config.background),
gab 2016/12/07 15:53:06 Does this work if the struct is padded by the comp
robliao 2016/12/07 18:39:19 Padding does make this go out the window. I guess
101 "Not all fields were assigned");
102 #if defined(OS_ANDROID) || defined(OS_IOS)
103 config.background.standby_thread_policy = StandbyThreadPolicy::ONE;
104 config.background.threads =
105 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0);
106 config.background.detach_period = base::TimeDelta::FromSeconds(30);
107
108 config.background_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
109 config.background_file_io.threads =
110 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0);
111 config.background_file_io.detach_period = base::TimeDelta::FromSeconds(30);
112
113 config.foreground.standby_thread_policy = StandbyThreadPolicy::ONE;
114 config.foreground.threads =
115 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0);
116 config.foreground.detach_period = base::TimeDelta::FromSeconds(30);
117
118 config.foreground_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
119 config.foreground_file_io.threads =
120 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0);
121 config.foreground_file_io.detach_period = base::TimeDelta::FromSeconds(30);
122 #else
123 config.background.standby_thread_policy = StandbyThreadPolicy::ONE;
124 config.background.threads =
125 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0);
126 config.background.detach_period = base::TimeDelta::FromSeconds(30);
127
128 config.background_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
129 config.background_file_io.threads =
130 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0);
131 config.background_file_io.detach_period = base::TimeDelta::FromSeconds(30);
132
133 config.foreground.standby_thread_policy = StandbyThreadPolicy::ONE;
134 config.foreground.threads =
135 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0);
136 config.foreground.detach_period = base::TimeDelta::FromSeconds(30);
137
138 config.foreground_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
139 config.foreground_file_io.threads =
140 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0);
141 config.foreground_file_io.detach_period = base::TimeDelta::FromSeconds(30);
142 #endif
143 return BrowserWorkerPoolConfigurationToSchedulerWorkerPoolParams(config);
144 }
145
146 } // namespace initialization
147 } // namespace task_scheduler_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698