OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "tools/gn/scheduler.h" | 5 #include "tools/gn/scheduler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 return result; | 47 return result; |
48 | 48 |
49 // Base the default number of worker threads on number of cores in the | 49 // Base the default number of worker threads on number of cores in the |
50 // system. When building large projects, the speed can be limited by how fast | 50 // system. When building large projects, the speed can be limited by how fast |
51 // the main thread can dispatch work and connect the dependency graph. If | 51 // the main thread can dispatch work and connect the dependency graph. If |
52 // there are too many worker threads, the main thread can be starved and it | 52 // there are too many worker threads, the main thread can be starved and it |
53 // will run slower overall. | 53 // will run slower overall. |
54 // | 54 // |
55 // One less worker thread than the number of physical CPUs seems to be a | 55 // One less worker thread than the number of physical CPUs seems to be a |
56 // good value, both theoretically and experimentally. But always use at | 56 // good value, both theoretically and experimentally. But always use at |
57 // least three workers to prevent us from being too sensitive to I/O latency | 57 // least some workers to prevent us from being too sensitive to I/O latency |
58 // on low-end systems. | 58 // on low-end systems. |
| 59 // |
| 60 // The minimum thread count is based on measuring the optimal threads for the |
| 61 // Chrome build on a several-year-old 4-core MacBook. |
59 int num_cores = GetCPUCount() / 2; // Almost all CPUs now are hyperthreaded. | 62 int num_cores = GetCPUCount() / 2; // Almost all CPUs now are hyperthreaded. |
60 return std::max(num_cores - 1, 3); | 63 return std::max(num_cores - 1, 8); |
61 } | 64 } |
62 | 65 |
63 } // namespace | 66 } // namespace |
64 | 67 |
65 Scheduler::Scheduler() | 68 Scheduler::Scheduler() |
66 : pool_(new base::SequencedWorkerPool(GetThreadCount(), "worker_")), | 69 : pool_(new base::SequencedWorkerPool(GetThreadCount(), "worker_")), |
67 input_file_manager_(new InputFileManager), | 70 input_file_manager_(new InputFileManager), |
68 verbose_logging_(false), | 71 verbose_logging_(false), |
69 work_count_(0), | 72 work_count_(0), |
70 is_failed_(false), | 73 is_failed_(false), |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 void Scheduler::DoWork(const base::Closure& closure) { | 231 void Scheduler::DoWork(const base::Closure& closure) { |
229 closure.Run(); | 232 closure.Run(); |
230 DecrementWorkCount(); | 233 DecrementWorkCount(); |
231 } | 234 } |
232 | 235 |
233 void Scheduler::OnComplete() { | 236 void Scheduler::OnComplete() { |
234 // Should be called on the main thread. | 237 // Should be called on the main thread. |
235 DCHECK(base::MessageLoop::current() == main_loop()); | 238 DCHECK(base::MessageLoop::current() == main_loop()); |
236 runner_.Quit(); | 239 runner_.Quit(); |
237 } | 240 } |
OLD | NEW |