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

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: CR Feedback 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 SchedulerWorkerPoolCustomizableConfiguration {
26 SchedulerWorkerPoolCustomizableConfiguration(
27 const char* name_in,
28 ThreadPriority priority_hint_in,
29 const SingleWorkerPoolConfiguration& single_worker_pool_config_in)
30 : name(name_in),
31 priority_hint(priority_hint_in),
32 single_worker_pool_config(single_worker_pool_config_in) {}
33
34 const char* name;
35 ThreadPriority priority_hint;
36 const SingleWorkerPoolConfiguration& single_worker_pool_config;
37 };
38
39 } // namespace
40
41 std::vector<base::SchedulerWorkerPoolParams>
42 BrowserWorkerPoolConfigurationToSchedulerWorkerPoolParams(
43 const BrowserWorkerPoolsConfiguration& config) {
44 const SchedulerWorkerPoolCustomizableConfiguration worker_pool_config[] = {
45 SchedulerWorkerPoolCustomizableConfiguration("Background",
46 ThreadPriority::BACKGROUND,
47 config.background),
48 SchedulerWorkerPoolCustomizableConfiguration("BackgroundFileIO",
49 ThreadPriority::BACKGROUND,
50 config.background_file_io),
51 SchedulerWorkerPoolCustomizableConfiguration("Foreground",
52 ThreadPriority::NORMAL,
53 config.foreground),
54 SchedulerWorkerPoolCustomizableConfiguration("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 (const auto& config : worker_pool_config) {
67 params_vector.emplace_back(
68 config.name, config.priority_hint,
69 config.single_worker_pool_config.standby_thread_policy,
70 config.single_worker_pool_config.threads,
71 config.single_worker_pool_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.
gab 2016/12/07 20:17:22 "other" than what?
robliao 2016/12/07 21:55:37 Done. // Returns the worker pool index for |traits
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 #if defined(OS_ANDROID) || defined(OS_IOS)
97 config.background.standby_thread_policy = StandbyThreadPolicy::ONE;
98 config.background.threads =
99 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0);
100 config.background.detach_period = base::TimeDelta::FromSeconds(30);
101
102 config.background_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
103 config.background_file_io.threads =
104 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0);
105 config.background_file_io.detach_period = base::TimeDelta::FromSeconds(30);
106
107 config.foreground.standby_thread_policy = StandbyThreadPolicy::ONE;
108 config.foreground.threads =
109 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0);
110 config.foreground.detach_period = base::TimeDelta::FromSeconds(30);
111
112 config.foreground_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
113 config.foreground_file_io.threads =
114 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0);
115 config.foreground_file_io.detach_period = base::TimeDelta::FromSeconds(30);
116 #else
117 config.background.standby_thread_policy = StandbyThreadPolicy::ONE;
118 config.background.threads =
119 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0);
120 config.background.detach_period = base::TimeDelta::FromSeconds(30);
121
122 config.background_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
123 config.background_file_io.threads =
124 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0);
125 config.background_file_io.detach_period = base::TimeDelta::FromSeconds(30);
126
127 config.foreground.standby_thread_policy = StandbyThreadPolicy::ONE;
128 config.foreground.threads =
129 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0);
130 config.foreground.detach_period = base::TimeDelta::FromSeconds(30);
131
132 config.foreground_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
133 config.foreground_file_io.threads =
134 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0);
135 config.foreground_file_io.detach_period = base::TimeDelta::FromSeconds(30);
136 #endif
137 return BrowserWorkerPoolConfigurationToSchedulerWorkerPoolParams(config);
138 }
139
140 } // namespace initialization
141 } // namespace task_scheduler_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698