OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "components/task_scheduler_util/initialization_util.h" | 5 #include "components/task_scheduler_util/initialization_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
16 #include "base/task_scheduler/scheduler_worker_pool_params.h" | 16 #include "base/task_scheduler/scheduler_worker_pool_params.h" |
17 #include "base/task_scheduler/task_scheduler.h" | 17 #include "base/task_scheduler/task_scheduler.h" |
18 #include "base/task_scheduler/task_traits.h" | 18 #include "base/task_scheduler/task_traits.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 | 20 |
21 namespace task_scheduler_util { | 21 namespace task_scheduler_util { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 using StandbyThreadPolicy = | |
26 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; | |
27 | |
25 enum WorkerPoolType : size_t { | 28 enum WorkerPoolType : size_t { |
26 BACKGROUND_WORKER_POOL = 0, | 29 BACKGROUND_WORKER_POOL = 0, |
27 BACKGROUND_FILE_IO_WORKER_POOL, | 30 BACKGROUND_FILE_IO_WORKER_POOL, |
28 FOREGROUND_WORKER_POOL, | 31 FOREGROUND_WORKER_POOL, |
29 FOREGROUND_FILE_IO_WORKER_POOL, | 32 FOREGROUND_FILE_IO_WORKER_POOL, |
30 WORKER_POOL_COUNT // Always last. | 33 WORKER_POOL_COUNT // Always last. |
31 }; | 34 }; |
32 | 35 |
33 struct WorkerPoolVariationValues { | 36 struct WorkerPoolVariationValues { |
37 StandbyThreadPolicy standby_thread_policy; | |
34 int threads = 0; | 38 int threads = 0; |
35 base::TimeDelta detach_period; | 39 base::TimeDelta detach_period; |
36 }; | 40 }; |
37 | 41 |
38 // Converts |pool_descriptor| to a WorkerPoolVariationValues. Returns a default | 42 // Converts |pool_descriptor| to a WorkerPoolVariationValues. Returns a default |
39 // WorkerPoolVariationValues on failure. | 43 // WorkerPoolVariationValues on failure. |
40 // | 44 // |
41 // |pool_descriptor| is a semi-colon separated value string with the following | 45 // |pool_descriptor| is a semi-colon separated value string with the following |
42 // items: | 46 // items: |
43 // 1. Minimum Thread Count (int) | 47 // 1. Minimum Thread Count (int) |
(...skipping 19 matching lines...) Expand all Loading... | |
63 base::StringToInt(tokens[1], &maximum) && | 67 base::StringToInt(tokens[1], &maximum) && |
64 base::StringToDouble(tokens[2], &multiplier) && | 68 base::StringToDouble(tokens[2], &multiplier) && |
65 base::StringToInt(tokens[3], &offset) && | 69 base::StringToInt(tokens[3], &offset) && |
66 base::StringToInt(tokens[4], &detach_milliseconds)) { | 70 base::StringToInt(tokens[4], &detach_milliseconds)) { |
67 const int num_of_cores = base::SysInfo::NumberOfProcessors(); | 71 const int num_of_cores = base::SysInfo::NumberOfProcessors(); |
68 const int threads = std::ceil<int>(num_of_cores * multiplier) + offset; | 72 const int threads = std::ceil<int>(num_of_cores * multiplier) + offset; |
69 WorkerPoolVariationValues values; | 73 WorkerPoolVariationValues values; |
70 values.threads = std::min(maximum, std::max(minimum, threads)); | 74 values.threads = std::min(maximum, std::max(minimum, threads)); |
71 values.detach_period = | 75 values.detach_period = |
72 base::TimeDelta::FromMilliseconds(detach_milliseconds); | 76 base::TimeDelta::FromMilliseconds(detach_milliseconds); |
77 values.standby_thread_policy = StandbyThreadPolicy::ONE; | |
fdoray
2016/11/15 15:27:02
values.standby_thread_policy =
(tokens.size()
robliao
2016/11/15 15:57:19
Done.
| |
78 if (tokens.size() >= 6) { | |
79 values.standby_thread_policy = | |
80 tokens[5] == "lazy" | |
81 ? StandbyThreadPolicy::LAZY | |
82 : StandbyThreadPolicy::ONE; | |
83 } | |
73 return values; | 84 return values; |
74 } | 85 } |
75 DLOG(ERROR) << "Invalid Worker Pool Descriptor: " << pool_descriptor; | 86 DLOG(ERROR) << "Invalid Worker Pool Descriptor: " << pool_descriptor; |
76 return WorkerPoolVariationValues(); | 87 return WorkerPoolVariationValues(); |
77 } | 88 } |
78 | 89 |
79 // Returns the worker pool index for |traits| defaulting to | 90 // Returns the worker pool index for |traits| defaulting to |
80 // FOREGROUND_WORKER_POOL or FOREGROUND_FILE_IO_WORKER_POOL on unknown | 91 // FOREGROUND_WORKER_POOL or FOREGROUND_FILE_IO_WORKER_POOL on unknown |
81 // priorities. | 92 // priorities. |
82 size_t WorkerPoolIndexForTraits(const base::TaskTraits& traits) { | 93 size_t WorkerPoolIndexForTraits(const base::TaskTraits& traits) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 if (variation_values.threads <= 0 || | 135 if (variation_values.threads <= 0 || |
125 variation_values.detach_period.is_zero()) { | 136 variation_values.detach_period.is_zero()) { |
126 DLOG(ERROR) << "Invalid Worker Pool Configuration: " << | 137 DLOG(ERROR) << "Invalid Worker Pool Configuration: " << |
127 predefined_params.name << " [" << pair->second << "]"; | 138 predefined_params.name << " [" << pair->second << "]"; |
128 return false; | 139 return false; |
129 } | 140 } |
130 | 141 |
131 params_vector.emplace_back(predefined_params.name, | 142 params_vector.emplace_back(predefined_params.name, |
132 predefined_params.priority_hint, | 143 predefined_params.priority_hint, |
133 predefined_params.io_restriction, | 144 predefined_params.io_restriction, |
145 variation_values.standby_thread_policy, | |
134 variation_values.threads, | 146 variation_values.threads, |
135 variation_values.detach_period); | 147 variation_values.detach_period); |
136 } | 148 } |
137 | 149 |
138 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); | 150 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); |
139 | 151 |
140 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | 152 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( |
141 params_vector, base::Bind(WorkerPoolIndexForTraits)); | 153 params_vector, base::Bind(WorkerPoolIndexForTraits)); |
142 | 154 |
143 return true; | 155 return true; |
144 } | 156 } |
145 | 157 |
146 } // namespace task_scheduler_util | 158 } // namespace task_scheduler_util |
OLD | NEW |