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/debug/trace_event_argument.h" | |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "base/pending_task.h" | 9 #include "base/pending_task.h" |
9 | 10 |
10 namespace content { | 11 namespace content { |
11 | 12 |
12 RendererTaskQueueSelector::RendererTaskQueueSelector() : starvation_count_(0) { | 13 RendererTaskQueueSelector::RendererTaskQueueSelector() : starvation_count_(0) { |
13 } | 14 } |
14 | 15 |
15 RendererTaskQueueSelector::~RendererTaskQueueSelector() { | 16 RendererTaskQueueSelector::~RendererTaskQueueSelector() { |
16 } | 17 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 } | 90 } |
90 return found_non_empty_queue; | 91 return found_non_empty_queue; |
91 } | 92 } |
92 | 93 |
93 bool RendererTaskQueueSelector::SelectWorkQueueToService( | 94 bool RendererTaskQueueSelector::SelectWorkQueueToService( |
94 size_t* out_queue_index) { | 95 size_t* out_queue_index) { |
95 main_thread_checker_.CalledOnValidThread(); | 96 main_thread_checker_.CalledOnValidThread(); |
96 DCHECK(work_queues_.size()); | 97 DCHECK(work_queues_.size()); |
97 // Always service the control queue if it has any work. | 98 // Always service the control queue if it has any work. |
98 if (ChooseOldestWithPriority(CONTROL_PRIORITY, out_queue_index)) { | 99 if (ChooseOldestWithPriority(CONTROL_PRIORITY, out_queue_index)) { |
100 DidSelectQueueWithPriority(CONTROL_PRIORITY); | |
99 return true; | 101 return true; |
100 } | 102 } |
101 // Select from the normal priority queue if we are starving it. | 103 // Select from the normal priority queue if we are starving it. |
102 if (starvation_count_ >= kMaxStarvationTasks && | 104 if (starvation_count_ >= kMaxStarvationTasks && |
103 ChooseOldestWithPriority(NORMAL_PRIORITY, out_queue_index)) { | 105 ChooseOldestWithPriority(NORMAL_PRIORITY, out_queue_index)) { |
104 starvation_count_ = 0; | 106 DidSelectQueueWithPriority(NORMAL_PRIORITY); |
105 return true; | 107 return true; |
106 } | 108 } |
107 // Otherwise choose in priority order. | 109 // Otherwise choose in priority order. |
108 for (QueuePriority priority = HIGH_PRIORITY; priority < QUEUE_PRIORITY_COUNT; | 110 for (QueuePriority priority = HIGH_PRIORITY; priority < QUEUE_PRIORITY_COUNT; |
109 priority = NextPriority(priority)) { | 111 priority = NextPriority(priority)) { |
110 if (ChooseOldestWithPriority(priority, out_queue_index)) { | 112 if (ChooseOldestWithPriority(priority, out_queue_index)) { |
111 if (priority == HIGH_PRIORITY) { | 113 DidSelectQueueWithPriority(priority); |
112 starvation_count_++; | |
113 } else { | |
114 starvation_count_ = 0; | |
115 } | |
116 return true; | 114 return true; |
117 } | 115 } |
118 } | 116 } |
119 return false; | 117 return false; |
120 } | 118 } |
121 | 119 |
120 void RendererTaskQueueSelector::DidSelectQueueWithPriority( | |
121 QueuePriority priority) { | |
122 switch (priority) { | |
123 case CONTROL_PRIORITY: | |
124 break; | |
125 case HIGH_PRIORITY: | |
126 starvation_count_++; | |
127 break; | |
128 case NORMAL_PRIORITY: | |
129 case BEST_EFFORT_PRIORITY: | |
130 starvation_count_ = 0; | |
131 break; | |
132 default: | |
133 NOTREACHED(); | |
134 } | |
135 } | |
rmcilroy
2014/11/07 18:21:57
indentation
Sami
2014/11/10 14:35:01
Whoops, fixed :)
| |
136 | |
137 // static | |
138 const char* RendererTaskQueueSelector::PriorityToString( | |
139 QueuePriority priority) { | |
140 switch (priority) { | |
141 case CONTROL_PRIORITY: | |
142 return "control"; | |
143 case HIGH_PRIORITY: | |
144 return "high"; | |
145 case NORMAL_PRIORITY: | |
146 return "normal"; | |
147 case BEST_EFFORT_PRIORITY: | |
148 return "best_effort"; | |
149 default: | |
150 NOTREACHED(); | |
151 return nullptr; | |
152 } | |
153 } | |
154 | |
155 void RendererTaskQueueSelector::AsValueInto( | |
156 base::debug::TracedValue* state) const { | |
157 main_thread_checker_.CalledOnValidThread(); | |
158 state->BeginDictionary("priorities"); | |
159 for (QueuePriority priority = FIRST_QUEUE_PRIORITY; | |
160 priority < QUEUE_PRIORITY_COUNT; | |
161 priority = NextPriority(priority)) { | |
162 state->BeginArray(PriorityToString(priority)); | |
163 for (size_t queue_index : queue_priorities_[priority]) | |
164 state->AppendInteger(queue_index); | |
165 state->EndArray(); | |
166 } | |
167 state->EndDictionary(); | |
168 state->SetInteger("starvation_count", starvation_count_); | |
169 } | |
170 | |
122 } // namespace content | 171 } // namespace content |
OLD | NEW |