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 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ | 5 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ |
6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ | 6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | |
10 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
11 #include "content/renderer/scheduler/task_queue_selector.h" | 12 #include "content/renderer/scheduler/task_queue_selector.h" |
12 | 13 |
14 namespace base { | |
15 namespace debug { | |
16 class ConvertableToTraceFormat; | |
17 class TracedValue; | |
18 } | |
19 } | |
20 | |
13 namespace content { | 21 namespace content { |
14 | 22 |
15 // A RendererSchedulerSelector is a TaskQueueSelector which is used by the | 23 // A RendererSchedulerSelector is a TaskQueueSelector which is used by the |
16 // RendererScheduler to enable prioritization of particular queues depending on | 24 // RendererScheduler to enable prioritization of particular queues depending on |
17 // circumstances. | 25 // circumstances. |
18 class RendererSchedulerSelector : public TaskQueueSelector { | 26 class RendererSchedulerSelector : public TaskQueueSelector { |
19 public: | 27 public: |
20 enum QueuePriority { | 28 enum QueuePriority { |
21 // Queues with control priority will run before any other queue, and will | 29 // Queues with control priority will run before any other queue, and will |
22 // explicitly starve other queues. Typically this should only be used for | 30 // explicitly starve other queues. Typically this should only be used for |
(...skipping 24 matching lines...) Expand all Loading... | |
47 void EnableQueue(size_t queue_index, QueuePriority priority); | 55 void EnableQueue(size_t queue_index, QueuePriority priority); |
48 | 56 |
49 // Disable the |queue_index|. | 57 // Disable the |queue_index|. |
50 void DisableQueue(size_t queue_index); | 58 void DisableQueue(size_t queue_index); |
51 | 59 |
52 // TaskQueueSelector implementation: | 60 // TaskQueueSelector implementation: |
53 void RegisterWorkQueues( | 61 void RegisterWorkQueues( |
54 const std::vector<const base::TaskQueue*>& work_queues) override; | 62 const std::vector<const base::TaskQueue*>& work_queues) override; |
55 bool SelectWorkQueueToService(size_t* out_queue_index) override; | 63 bool SelectWorkQueueToService(size_t* out_queue_index) override; |
56 | 64 |
65 // Serialize the selector state into the given state dictionary for tracing. | |
66 void AsValueInto(base::debug::TracedValue* state) const; | |
67 | |
picksi1
2014/10/28 11:01:40
"AsValueInto" means nothing to me! Is there some i
Sami
2014/10/28 12:57:47
Agreed that it isn't very descriptive, but it's pr
| |
68 // Set the name |queue_index| for tracing purposes. |name| must be a pointer | |
69 // to a static string. | |
70 void SetQueueName(size_t queue_index, const char* name); | |
71 | |
57 private: | 72 private: |
58 // Returns true if queueA contains an older task than queueB. | 73 // Returns true if queueA contains an older task than queueB. |
59 static bool IsOlder(const base::TaskQueue* queueA, | 74 static bool IsOlder(const base::TaskQueue* queueA, |
60 const base::TaskQueue* queueB); | 75 const base::TaskQueue* queueB); |
61 | 76 |
62 // Returns the priority which is next after |priority|. | 77 // Returns the priority which is next after |priority|. |
63 static QueuePriority NextPriority(QueuePriority priority); | 78 static QueuePriority NextPriority(QueuePriority priority); |
64 | 79 |
65 // Return true if |out_queue_index| indicates the index of the queue with | 80 // Return true if |out_queue_index| indicates the index of the queue with |
66 // the oldest pending task from the set of queues of |priority|, or | 81 // the oldest pending task from the set of queues of |priority|, or |
67 // false if all queues of that priority are empty. | 82 // false if all queues of that priority are empty. |
68 bool ChooseOldestWithPriority(QueuePriority priority, | 83 bool ChooseOldestWithPriority(QueuePriority priority, |
69 size_t* out_queue_index) const; | 84 size_t* out_queue_index) const; |
70 | 85 |
71 // Returns true if |queue_index| is enabled with the given |priority|. | 86 // Returns true if |queue_index| is enabled with the given |priority|. |
72 bool QueueEnabledWithPriority(size_t queue_index, | 87 bool QueueEnabledWithPriority(size_t queue_index, |
73 QueuePriority priority) const; | 88 QueuePriority priority) const; |
74 | 89 |
90 void DidSelectQueue(size_t selected_queue, QueuePriority priority); | |
rmcilroy
2014/10/27 17:51:28
nit - comment when to call this.
Sami
2014/10/28 12:57:47
Done.
| |
91 | |
picksi1
2014/10/28 11:01:40
Possibly the ship has sailed, but it should the se
Sami
2014/10/28 12:57:47
I think we went back and forth with this a couple
| |
92 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValueWithSelectedQueue( | |
93 size_t selected_queue) const; | |
94 static const char* PriorityToString(QueuePriority priority); | |
95 | |
75 // Number of high priority tasks which can be run before a normal priority | 96 // Number of high priority tasks which can be run before a normal priority |
76 // task should be selected to prevent starvation. | 97 // task should be selected to prevent starvation. |
77 // TODO(rmcilroy): Check if this is a good value. | 98 // TODO(rmcilroy): Check if this is a good value. |
78 static const size_t kMaxStarvationTasks = 5; | 99 static const size_t kMaxStarvationTasks = 5; |
79 | 100 |
101 struct Queue { | |
102 Queue(); | |
103 | |
104 const base::TaskQueue* work_queue; | |
105 const char* name; | |
106 }; | |
picksi1
2014/10/28 11:01:40
Does this structure need to hold a work_queue poin
Sami
2014/10/28 12:57:47
Yes, the work queues are not owned by this class s
| |
107 | |
80 base::ThreadChecker main_thread_checker_; | 108 base::ThreadChecker main_thread_checker_; |
81 std::vector<const base::TaskQueue*> work_queues_; | 109 std::vector<Queue> queues_; |
82 std::set<size_t> queue_priorities_[kQueuePriorityCount]; | 110 std::set<size_t> queue_priorities_[kQueuePriorityCount]; |
83 size_t starvation_count_; | 111 size_t starvation_count_; |
84 }; | 112 }; |
85 | 113 |
86 } // namespace content | 114 } // namespace content |
87 | 115 |
88 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ | 116 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_POLICY_H_ |
OLD | NEW |