OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/renderer/scheduler/renderer_task_queue_selector.h" | 5 #include "content/renderer/scheduler/renderer_task_queue_selector.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/pending_task.h" | 8 #include "base/pending_task.h" |
9 #include "base/trace_event/trace_event_argument.h" | 9 #include "base/trace_event/trace_event_argument.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 RendererTaskQueueSelector::RendererTaskQueueSelector() : starvation_count_(0) { | 13 RendererTaskQueueSelector::RendererTaskQueueSelector() : starvation_count_(0) { |
14 } | 14 } |
15 | 15 |
16 RendererTaskQueueSelector::~RendererTaskQueueSelector() { | 16 RendererTaskQueueSelector::~RendererTaskQueueSelector() { |
17 } | 17 } |
18 | 18 |
19 void RendererTaskQueueSelector::RegisterWorkQueues( | 19 void RendererTaskQueueSelector::RegisterWorkQueues( |
20 const std::vector<const base::TaskQueue*>& work_queues) { | 20 const std::vector<const base::TaskQueue*>& work_queues) { |
21 main_thread_checker_.CalledOnValidThread(); | 21 DCHECK(main_thread_checker_.CalledOnValidThread()); |
22 work_queues_ = work_queues; | 22 work_queues_ = work_queues; |
23 for (QueuePriority priority = FIRST_QUEUE_PRIORITY; | 23 for (QueuePriority priority = FIRST_QUEUE_PRIORITY; |
24 priority < QUEUE_PRIORITY_COUNT; | 24 priority < QUEUE_PRIORITY_COUNT; |
25 priority = NextPriority(priority)) { | 25 priority = NextPriority(priority)) { |
26 queue_priorities_[priority].clear(); | 26 queue_priorities_[priority].clear(); |
27 } | 27 } |
28 // By default, all work queues are set to normal priority. | 28 // By default, all work queues are set to normal priority. |
29 for (size_t i = 0; i < work_queues.size(); i++) { | 29 for (size_t i = 0; i < work_queues.size(); i++) { |
30 queue_priorities_[NORMAL_PRIORITY].insert(i); | 30 queue_priorities_[NORMAL_PRIORITY].insert(i); |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 void RendererTaskQueueSelector::SetQueuePriority(size_t queue_index, | 34 void RendererTaskQueueSelector::SetQueuePriority(size_t queue_index, |
35 QueuePriority priority) { | 35 QueuePriority priority) { |
36 main_thread_checker_.CalledOnValidThread(); | 36 DCHECK(main_thread_checker_.CalledOnValidThread()); |
37 DCHECK_LT(queue_index, work_queues_.size()); | 37 DCHECK_LT(queue_index, work_queues_.size()); |
38 DCHECK_LT(priority, QUEUE_PRIORITY_COUNT); | 38 DCHECK_LT(priority, QUEUE_PRIORITY_COUNT); |
39 DisableQueue(queue_index); | 39 DisableQueue(queue_index); |
40 queue_priorities_[priority].insert(queue_index); | 40 queue_priorities_[priority].insert(queue_index); |
41 } | 41 } |
42 | 42 |
43 void RendererTaskQueueSelector::EnableQueue(size_t queue_index, | 43 void RendererTaskQueueSelector::EnableQueue(size_t queue_index, |
44 QueuePriority priority) { | 44 QueuePriority priority) { |
45 SetQueuePriority(queue_index, priority); | 45 SetQueuePriority(queue_index, priority); |
46 } | 46 } |
47 | 47 |
48 void RendererTaskQueueSelector::DisableQueue(size_t queue_index) { | 48 void RendererTaskQueueSelector::DisableQueue(size_t queue_index) { |
49 main_thread_checker_.CalledOnValidThread(); | 49 DCHECK(main_thread_checker_.CalledOnValidThread()); |
50 DCHECK_LT(queue_index, work_queues_.size()); | 50 DCHECK_LT(queue_index, work_queues_.size()); |
51 for (QueuePriority priority = FIRST_QUEUE_PRIORITY; | 51 for (QueuePriority priority = FIRST_QUEUE_PRIORITY; |
52 priority < QUEUE_PRIORITY_COUNT; | 52 priority < QUEUE_PRIORITY_COUNT; |
53 priority = NextPriority(priority)) { | 53 priority = NextPriority(priority)) { |
54 queue_priorities_[priority].erase(queue_index); | 54 queue_priorities_[priority].erase(queue_index); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 bool RendererTaskQueueSelector::IsOlder(const base::TaskQueue* queueA, | 58 bool RendererTaskQueueSelector::IsOlder(const base::TaskQueue* queueA, |
59 const base::TaskQueue* queueB) { | 59 const base::TaskQueue* queueB) { |
(...skipping 26 matching lines...) Expand all Loading... |
86 } | 86 } |
87 | 87 |
88 if (found_non_empty_queue) { | 88 if (found_non_empty_queue) { |
89 *out_queue_index = chosen_queue; | 89 *out_queue_index = chosen_queue; |
90 } | 90 } |
91 return found_non_empty_queue; | 91 return found_non_empty_queue; |
92 } | 92 } |
93 | 93 |
94 bool RendererTaskQueueSelector::SelectWorkQueueToService( | 94 bool RendererTaskQueueSelector::SelectWorkQueueToService( |
95 size_t* out_queue_index) { | 95 size_t* out_queue_index) { |
96 main_thread_checker_.CalledOnValidThread(); | 96 DCHECK(main_thread_checker_.CalledOnValidThread()); |
97 DCHECK(work_queues_.size()); | 97 DCHECK(work_queues_.size()); |
98 // Always service the control queue if it has any work. | 98 // Always service the control queue if it has any work. |
99 if (ChooseOldestWithPriority(CONTROL_PRIORITY, out_queue_index)) { | 99 if (ChooseOldestWithPriority(CONTROL_PRIORITY, out_queue_index)) { |
100 DidSelectQueueWithPriority(CONTROL_PRIORITY); | 100 DidSelectQueueWithPriority(CONTROL_PRIORITY); |
101 return true; | 101 return true; |
102 } | 102 } |
103 // Select from the normal priority queue if we are starving it. | 103 // Select from the normal priority queue if we are starving it. |
104 if (starvation_count_ >= kMaxStarvationTasks && | 104 if (starvation_count_ >= kMaxStarvationTasks && |
105 ChooseOldestWithPriority(NORMAL_PRIORITY, out_queue_index)) { | 105 ChooseOldestWithPriority(NORMAL_PRIORITY, out_queue_index)) { |
106 DidSelectQueueWithPriority(NORMAL_PRIORITY); | 106 DidSelectQueueWithPriority(NORMAL_PRIORITY); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 case BEST_EFFORT_PRIORITY: | 147 case BEST_EFFORT_PRIORITY: |
148 return "best_effort"; | 148 return "best_effort"; |
149 default: | 149 default: |
150 NOTREACHED(); | 150 NOTREACHED(); |
151 return nullptr; | 151 return nullptr; |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 void RendererTaskQueueSelector::AsValueInto( | 155 void RendererTaskQueueSelector::AsValueInto( |
156 base::debug::TracedValue* state) const { | 156 base::debug::TracedValue* state) const { |
157 main_thread_checker_.CalledOnValidThread(); | 157 DCHECK(main_thread_checker_.CalledOnValidThread()); |
158 state->BeginDictionary("priorities"); | 158 state->BeginDictionary("priorities"); |
159 for (QueuePriority priority = FIRST_QUEUE_PRIORITY; | 159 for (QueuePriority priority = FIRST_QUEUE_PRIORITY; |
160 priority < QUEUE_PRIORITY_COUNT; priority = NextPriority(priority)) { | 160 priority < QUEUE_PRIORITY_COUNT; priority = NextPriority(priority)) { |
161 state->BeginArray(PriorityToString(priority)); | 161 state->BeginArray(PriorityToString(priority)); |
162 for (size_t queue_index : queue_priorities_[priority]) | 162 for (size_t queue_index : queue_priorities_[priority]) |
163 state->AppendInteger(queue_index); | 163 state->AppendInteger(queue_index); |
164 state->EndArray(); | 164 state->EndArray(); |
165 } | 165 } |
166 state->EndDictionary(); | 166 state->EndDictionary(); |
167 state->SetInteger("starvation_count", starvation_count_); | 167 state->SetInteger("starvation_count", starvation_count_); |
168 } | 168 } |
169 | 169 |
170 } // namespace content | 170 } // namespace content |
OLD | NEW |