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

Side by Side Diff: components/task_scheduler_util/initialization_util.cc

Issue 2501763002: Add Thread Standby Policy SchedulerWorkerPoolImpl (Closed)
Patch Set: Rebase to edc7bea Created 4 years, 1 month 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 | « base/threading/sequenced_worker_pool_unittest.cc ('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 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 <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/task_scheduler/initialization_util.h" 14 #include "base/task_scheduler/initialization_util.h"
15 #include "base/task_scheduler/scheduler_worker_pool_params.h" 15 #include "base/task_scheduler/scheduler_worker_pool_params.h"
16 #include "base/task_scheduler/task_scheduler.h" 16 #include "base/task_scheduler/task_scheduler.h"
17 #include "base/task_scheduler/task_traits.h" 17 #include "base/task_scheduler/task_traits.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 19
20 namespace task_scheduler_util { 20 namespace task_scheduler_util {
21 21
22 namespace { 22 namespace {
23 23
24 using StandbyThreadPolicy =
25 base::SchedulerWorkerPoolParams::StandbyThreadPolicy;
26
24 enum WorkerPoolType : size_t { 27 enum WorkerPoolType : size_t {
25 BACKGROUND_WORKER_POOL = 0, 28 BACKGROUND_WORKER_POOL = 0,
26 BACKGROUND_FILE_IO_WORKER_POOL, 29 BACKGROUND_FILE_IO_WORKER_POOL,
27 FOREGROUND_WORKER_POOL, 30 FOREGROUND_WORKER_POOL,
28 FOREGROUND_FILE_IO_WORKER_POOL, 31 FOREGROUND_FILE_IO_WORKER_POOL,
29 WORKER_POOL_COUNT // Always last. 32 WORKER_POOL_COUNT // Always last.
30 }; 33 };
31 34
32 struct WorkerPoolVariationValues { 35 struct WorkerPoolVariationValues {
36 StandbyThreadPolicy standby_thread_policy;
33 int threads = 0; 37 int threads = 0;
34 base::TimeDelta detach_period; 38 base::TimeDelta detach_period;
35 }; 39 };
36 40
37 // Converts |pool_descriptor| to a WorkerPoolVariationValues. Returns a default 41 // Converts |pool_descriptor| to a WorkerPoolVariationValues. Returns a default
38 // WorkerPoolVariationValues on failure. 42 // WorkerPoolVariationValues on failure.
39 // 43 //
40 // |pool_descriptor| is a semi-colon separated value string with the following 44 // |pool_descriptor| is a semi-colon separated value string with the following
41 // items: 45 // items:
42 // 1. Minimum Thread Count (int) 46 // 0. Minimum Thread Count (int)
43 // 2. Maximum Thread Count (int) 47 // 1. Maximum Thread Count (int)
44 // 3. Thread Count Multiplier (double) 48 // 2. Thread Count Multiplier (double)
45 // 4. Thread Count Offset (int) 49 // 3. Thread Count Offset (int)
46 // 5. Detach Time in Milliseconds (milliseconds) 50 // 4. Detach Time in Milliseconds (milliseconds)
51 // 5. Standby Thread Policy (string)
47 // Additional values may appear as necessary and will be ignored. 52 // Additional values may appear as necessary and will be ignored.
48 WorkerPoolVariationValues StringToWorkerPoolVariationValues( 53 WorkerPoolVariationValues StringToWorkerPoolVariationValues(
49 const base::StringPiece pool_descriptor) { 54 const base::StringPiece pool_descriptor) {
50 const std::vector<std::string> tokens = 55 const std::vector<std::string> tokens =
51 SplitString(pool_descriptor, ";", 56 SplitString(pool_descriptor, ";",
52 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 57 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
53 int min; 58 int min;
54 int max; 59 int max;
55 double cores_multiplier; 60 double cores_multiplier;
56 int offset; 61 int offset;
57 int detach_milliseconds; 62 int detach_milliseconds;
58 // Checking for a size greater than the expected amount allows us to be 63 // Checking for a size greater than the expected amount allows us to be
59 // forward compatible if we add more variation values. 64 // forward compatible if we add more variation values.
60 if (tokens.size() >= 5 && base::StringToInt(tokens[0], &min) && 65 if (tokens.size() >= 5 && base::StringToInt(tokens[0], &min) &&
61 base::StringToInt(tokens[1], &max) && 66 base::StringToInt(tokens[1], &max) &&
62 base::StringToDouble(tokens[2], &cores_multiplier) && 67 base::StringToDouble(tokens[2], &cores_multiplier) &&
63 base::StringToInt(tokens[3], &offset) && 68 base::StringToInt(tokens[3], &offset) &&
64 base::StringToInt(tokens[4], &detach_milliseconds)) { 69 base::StringToInt(tokens[4], &detach_milliseconds)) {
65 WorkerPoolVariationValues values; 70 WorkerPoolVariationValues values;
66 values.threads = base::RecommendedMaxNumberOfThreadsInPool( 71 values.threads = base::RecommendedMaxNumberOfThreadsInPool(
67 min, max, cores_multiplier, offset); 72 min, max, cores_multiplier, offset);
68 values.detach_period = 73 values.detach_period =
69 base::TimeDelta::FromMilliseconds(detach_milliseconds); 74 base::TimeDelta::FromMilliseconds(detach_milliseconds);
75 values.standby_thread_policy =
76 (tokens.size() >= 6 && tokens[5] == "lazy")
77 ? StandbyThreadPolicy::LAZY
78 : StandbyThreadPolicy::ONE;
70 return values; 79 return values;
71 } 80 }
72 DLOG(ERROR) << "Invalid Worker Pool Descriptor: " << pool_descriptor; 81 DLOG(ERROR) << "Invalid Worker Pool Descriptor: " << pool_descriptor;
73 return WorkerPoolVariationValues(); 82 return WorkerPoolVariationValues();
74 } 83 }
75 84
76 // Returns the worker pool index for |traits| defaulting to 85 // Returns the worker pool index for |traits| defaulting to
77 // FOREGROUND_WORKER_POOL or FOREGROUND_FILE_IO_WORKER_POOL on unknown 86 // FOREGROUND_WORKER_POOL or FOREGROUND_FILE_IO_WORKER_POOL on unknown
78 // priorities. 87 // priorities.
79 size_t WorkerPoolIndexForTraits(const base::TaskTraits& traits) { 88 size_t WorkerPoolIndexForTraits(const base::TaskTraits& traits) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 if (variation_values.threads <= 0 || 130 if (variation_values.threads <= 0 ||
122 variation_values.detach_period.is_zero()) { 131 variation_values.detach_period.is_zero()) {
123 DLOG(ERROR) << "Invalid Worker Pool Configuration: " << 132 DLOG(ERROR) << "Invalid Worker Pool Configuration: " <<
124 predefined_params.name << " [" << pair->second << "]"; 133 predefined_params.name << " [" << pair->second << "]";
125 return false; 134 return false;
126 } 135 }
127 136
128 params_vector.emplace_back(predefined_params.name, 137 params_vector.emplace_back(predefined_params.name,
129 predefined_params.priority_hint, 138 predefined_params.priority_hint,
130 predefined_params.io_restriction, 139 predefined_params.io_restriction,
140 variation_values.standby_thread_policy,
131 variation_values.threads, 141 variation_values.threads,
132 variation_values.detach_period); 142 variation_values.detach_period);
133 } 143 }
134 144
135 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); 145 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size());
136 146
137 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( 147 base::TaskScheduler::CreateAndSetDefaultTaskScheduler(
138 params_vector, base::Bind(WorkerPoolIndexForTraits)); 148 params_vector, base::Bind(WorkerPoolIndexForTraits));
139 149
140 return true; 150 return true;
141 } 151 }
142 152
143 } // namespace task_scheduler_util 153 } // namespace task_scheduler_util
OLDNEW
« no previous file with comments | « base/threading/sequenced_worker_pool_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698