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

Side by Side Diff: content/renderer/scheduler/renderer_scheduler_selector.cc

Issue 664963002: content: Add RendererScheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/renderer/scheduler/renderer_scheduler_selector.h"
6
7 #include "base/logging.h"
8 #include "base/pending_task.h"
9
10 namespace content {
11
12 namespace {
13 int kBitsInByte = 8;
Sami 2014/10/20 13:31:08 nit: const int. Generally things in namespaces are
petrcermak 2014/10/20 17:43:36 Is there any reason why we don't use CHAR_BIT from
14 }
15
16 RendererSchedulerSelector::RendererSchedulerSelector() { }
17
18 RendererSchedulerSelector::~RendererSchedulerSelector() { }
19
20 void RendererSchedulerSelector::RegisterWorkQueues(
21 const std::vector<const base::TaskQueue*>& work_queues) {
22 main_thread_checker_.CalledOnValidThread();
23 DCHECK(work_queues.size() < queue_priorities_[kNormalPriority] * kBitsInByte);
Sami 2014/10/20 13:31:09 What are we checking for here? It seems like we'd
petrcermak 2014/10/20 17:43:35 I think that it should be "sizeof(queue_priorities
24 work_queues_ = work_queues;
25 // By default, all work queues are set to normal priority.
26 queue_priorities_[kControlPriority] = 0;
27 queue_priorities_[kHighPriority] = 0;
28 queue_priorities_[kNormalPriority] = (1 << work_queues.size()) - 1;
29 queue_priorities_[kBestEffortPriority] = 0;
30 }
31
32 RendererSchedulerSelector::QueuePriority RendererSchedulerSelector::NextPriorty(
33 QueuePriority priority) {
34 DCHECK(priority < kQueuePriorityCount);
35 return static_cast<QueuePriority>(static_cast<int>(priority) + 1);
36 }
37
38 void RendererSchedulerSelector::SetQueuePriority(
39 size_t queue_id, QueuePriority set_priority) {
40 main_thread_checker_.CalledOnValidThread();
41 DCHECK(queue_id < work_queues_.size());
petrcermak 2014/10/20 17:43:36 DCHECK_LT (twice)
42 DCHECK(set_priority < kQueuePriorityCount);
43 int64_t queue_id_mask_ = 1 << queue_id;
Sami 2014/10/20 13:31:09 size_t? Also the RHS has only 32 bits. Also no und
44 for (QueuePriority priority = kControlPriority;
45 priority < kQueuePriorityCount;
46 priority = NextPriorty(priority)) {
47 if (priority == set_priority) {
48 queue_priorities_[priority] |= queue_id_mask_;
49 } else {
50 queue_priorities_[priority] &= ~queue_id_mask_;
51 }
52 }
53 }
54
55 void RendererSchedulerSelector::EnableQueue(
56 size_t queue_id, QueuePriority priority) {
57 SetQueuePriority(queue_id, priority);
58 }
59
60 void RendererSchedulerSelector::DisableQueue(size_t queue_id) {
61 main_thread_checker_.CalledOnValidThread();
62 DCHECK(queue_id < work_queues_.size());
63 int64_t queue_id_mask_ = 1 << queue_id;
petrcermak 2014/10/20 17:43:35 Why don't you calculate the inverse mask straighta
64 for (QueuePriority priority = kControlPriority;
65 priority < kQueuePriorityCount;
66 priority = NextPriorty(priority)) {
67 queue_priorities_[priority] &= ~queue_id_mask_;
68 }
69 }
70
71 bool RendererSchedulerSelector::QueueEnabledWithPriority(
72 size_t queue_id, QueuePriority priority) {
73 DCHECK(queue_id < work_queues_.size());
74 DCHECK(priority < kQueuePriorityCount);
75 return queue_priorities_[priority] & (1 << queue_id);
76 }
77
78 bool RendererSchedulerSelector::ChooseOldestWithPriority(
79 QueuePriority priority, size_t* out_queue_index) {
80 bool found_non_empty_queue = false;
81 size_t chosen_queue = 0;
82 for (size_t queue_id = 0; queue_id < work_queues_.size(); queue_id++) {
83 if (!QueueEnabledWithPriority(queue_id, priority) ||
84 work_queues_[queue_id]->empty()) {
85 continue;
86 }
87 if (!found_non_empty_queue ||
88 work_queues_[queue_id]->front() < work_queues_[chosen_queue]->front()) {
89 found_non_empty_queue = true;
90 chosen_queue = queue_id;
91 }
92 }
93
94 if (found_non_empty_queue) {
95 *out_queue_index = chosen_queue;
96 }
97 return found_non_empty_queue;
98 }
99
100 bool RendererSchedulerSelector::SelectWorkQueueToService(
101 size_t* out_queue_index) {
102 main_thread_checker_.CalledOnValidThread();
103 DCHECK(work_queues_.size());
104 for (QueuePriority priority = kControlPriority;
Sami 2014/10/20 13:31:09 It seems like this prioritizes the high priority s
105 priority < kQueuePriorityCount;
106 priority = NextPriorty(priority)) {
107 if (ChooseOldestWithPriority(priority, out_queue_index)) {
108 return true;
109 }
110 }
111 return false;
112 }
113
114
115 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698