| 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 "components/scheduler/renderer/renderer_scheduler_impl.h" | 5 #include "components/scheduler/renderer/renderer_scheduler_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/stack_trace.h" | 8 #include "base/debug/stack_trace.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "base/trace_event/trace_event_argument.h" | 11 #include "base/trace_event/trace_event_argument.h" |
| 12 #include "cc/output/begin_frame_args.h" | 12 #include "cc/output/begin_frame_args.h" |
| 13 #include "components/scheduler/base/task_queue_impl.h" | 13 #include "components/scheduler/base/task_queue_impl.h" |
| 14 #include "components/scheduler/base/task_queue_selector.h" | 14 #include "components/scheduler/base/task_queue_selector.h" |
| 15 #include "components/scheduler/base/virtual_time_domain.h" |
| 15 #include "components/scheduler/child/scheduler_tqm_delegate.h" | 16 #include "components/scheduler/child/scheduler_tqm_delegate.h" |
| 16 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" | 17 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" |
| 17 | 18 |
| 18 namespace scheduler { | 19 namespace scheduler { |
| 19 namespace { | 20 namespace { |
| 20 // The run time of loading tasks is strongly bimodal. The vast majority are | 21 // The run time of loading tasks is strongly bimodal. The vast majority are |
| 21 // very cheap, but there are usually a handful of very expensive tasks (e.g ~1 | 22 // very cheap, but there are usually a handful of very expensive tasks (e.g ~1 |
| 22 // second on a mobile device) so we take a very pesimistic view when estimating | 23 // second on a mobile device) so we take a very pesimistic view when estimating |
| 23 // the cost of loading tasks. | 24 // the cost of loading tasks. |
| 24 const int kLoadingTaskEstimationSampleCount = 1000; | 25 const int kLoadingTaskEstimationSampleCount = 1000; |
| 25 const double kLoadingTaskEstimationPercentile = 98; | 26 const double kLoadingTaskEstimationPercentile = 98; |
| 26 const int kTimerTaskEstimationSampleCount = 200; | 27 const int kTimerTaskEstimationSampleCount = 200; |
| 27 const double kTimerTaskEstimationPercentile = 90; | 28 const double kTimerTaskEstimationPercentile = 90; |
| 28 const int kShortIdlePeriodDurationSampleCount = 10; | 29 const int kShortIdlePeriodDurationSampleCount = 10; |
| 29 const double kShortIdlePeriodDurationPercentile = 50; | 30 const double kShortIdlePeriodDurationPercentile = 50; |
| 30 } | 31 } |
| 31 | 32 |
| 32 RendererSchedulerImpl::RendererSchedulerImpl( | 33 RendererSchedulerImpl::RendererSchedulerImpl( |
| 33 scoped_refptr<SchedulerTqmDelegate> main_task_runner) | 34 scoped_refptr<SchedulerTqmDelegate> main_task_runner) |
| 34 : helper_(main_task_runner, | 35 : helper_(main_task_runner, |
| 35 "renderer.scheduler", | 36 "renderer.scheduler", |
| 36 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 37 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
| 37 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler.debug")), | 38 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler.debug")), |
| 38 idle_helper_(&helper_, | 39 idle_helper_(&helper_, |
| 39 this, | 40 this, |
| 40 "renderer.scheduler", | 41 "renderer.scheduler", |
| 41 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 42 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
| 42 "RendererSchedulerIdlePeriod", | 43 "RendererSchedulerIdlePeriod", |
| 43 base::TimeDelta()), | 44 base::TimeDelta()), |
| 45 throttling_helper_(this, "renderer.scheduler"), |
| 44 render_widget_scheduler_signals_(this), | 46 render_widget_scheduler_signals_(this), |
| 45 control_task_runner_(helper_.ControlTaskRunner()), | 47 control_task_runner_(helper_.ControlTaskRunner()), |
| 46 compositor_task_runner_( | 48 compositor_task_runner_( |
| 47 helper_.NewTaskQueue(TaskQueue::Spec("compositor_tq") | 49 helper_.NewTaskQueue(TaskQueue::Spec("compositor_tq") |
| 48 .SetShouldMonitorQuiescence(true))), | 50 .SetShouldMonitorQuiescence(true))), |
| 49 delayed_update_policy_runner_( | 51 delayed_update_policy_runner_( |
| 50 base::Bind(&RendererSchedulerImpl::UpdatePolicy, | 52 base::Bind(&RendererSchedulerImpl::UpdatePolicy, |
| 51 base::Unretained(this)), | 53 base::Unretained(this)), |
| 52 helper_.ControlTaskRunner()), | 54 helper_.ControlTaskRunner()), |
| 53 main_thread_only_(compositor_task_runner_, | 55 main_thread_only_(compositor_task_runner_, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 RendererSchedulerImpl::LoadingTaskRunner() { | 171 RendererSchedulerImpl::LoadingTaskRunner() { |
| 170 helper_.CheckOnValidThread(); | 172 helper_.CheckOnValidThread(); |
| 171 return default_loading_task_runner_; | 173 return default_loading_task_runner_; |
| 172 } | 174 } |
| 173 | 175 |
| 174 scoped_refptr<TaskQueue> RendererSchedulerImpl::TimerTaskRunner() { | 176 scoped_refptr<TaskQueue> RendererSchedulerImpl::TimerTaskRunner() { |
| 175 helper_.CheckOnValidThread(); | 177 helper_.CheckOnValidThread(); |
| 176 return default_timer_task_runner_; | 178 return default_timer_task_runner_; |
| 177 } | 179 } |
| 178 | 180 |
| 181 scoped_refptr<TaskQueue> RendererSchedulerImpl::ControlTaskRunner() { |
| 182 helper_.CheckOnValidThread(); |
| 183 return helper_.ControlTaskRunner(); |
| 184 } |
| 185 |
| 179 scoped_refptr<TaskQueue> RendererSchedulerImpl::NewLoadingTaskRunner( | 186 scoped_refptr<TaskQueue> RendererSchedulerImpl::NewLoadingTaskRunner( |
| 180 const char* name) { | 187 const char* name) { |
| 181 helper_.CheckOnValidThread(); | 188 helper_.CheckOnValidThread(); |
| 182 scoped_refptr<TaskQueue> loading_task_queue(helper_.NewTaskQueue( | 189 scoped_refptr<TaskQueue> loading_task_queue(helper_.NewTaskQueue( |
| 183 TaskQueue::Spec(name).SetShouldMonitorQuiescence(true))); | 190 TaskQueue::Spec(name).SetShouldMonitorQuiescence(true))); |
| 184 loading_task_runners_.insert(loading_task_queue); | 191 loading_task_runners_.insert(loading_task_queue); |
| 185 loading_task_queue->SetQueuePriority( | 192 loading_task_queue->SetQueuePriority( |
| 186 MainThreadOnly().current_policy.loading_queue_priority); | 193 MainThreadOnly().current_policy.loading_queue_priority); |
| 187 loading_task_queue->AddTaskObserver( | 194 loading_task_queue->AddTaskObserver( |
| 188 &MainThreadOnly().loading_task_cost_estimator); | 195 &MainThreadOnly().loading_task_cost_estimator); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 // Note: even though the control queue has the highest priority we don't yield | 535 // Note: even though the control queue has the highest priority we don't yield |
| 529 // for it since these tasks are not user-provided work and they are only | 536 // for it since these tasks are not user-provided work and they are only |
| 530 // intended to run before the next task, not interrupt the tasks. | 537 // intended to run before the next task, not interrupt the tasks. |
| 531 switch (MainThreadOnly().current_use_case) { | 538 switch (MainThreadOnly().current_use_case) { |
| 532 case UseCase::COMPOSITOR_GESTURE: | 539 case UseCase::COMPOSITOR_GESTURE: |
| 533 case UseCase::NONE: | 540 case UseCase::NONE: |
| 534 return MainThreadOnly().touchstart_expected_soon; | 541 return MainThreadOnly().touchstart_expected_soon; |
| 535 | 542 |
| 536 case UseCase::MAIN_THREAD_GESTURE: | 543 case UseCase::MAIN_THREAD_GESTURE: |
| 537 case UseCase::SYNCHRONIZED_GESTURE: | 544 case UseCase::SYNCHRONIZED_GESTURE: |
| 538 return !compositor_task_runner_->IsQueueEmpty() || | 545 return compositor_task_runner_->HasPendingImmediateTask() || |
| 539 MainThreadOnly().touchstart_expected_soon; | 546 MainThreadOnly().touchstart_expected_soon; |
| 540 | 547 |
| 541 case UseCase::TOUCHSTART: | 548 case UseCase::TOUCHSTART: |
| 542 return true; | 549 return true; |
| 543 | 550 |
| 544 case UseCase::LOADING: | 551 case UseCase::LOADING: |
| 545 return false; | 552 return false; |
| 546 | 553 |
| 547 default: | 554 default: |
| 548 NOTREACHED(); | 555 NOTREACHED(); |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 | 1046 |
| 1040 double RendererSchedulerImpl::CurrentTimeSeconds() const { | 1047 double RendererSchedulerImpl::CurrentTimeSeconds() const { |
| 1041 return helper_.scheduler_tqm_delegate()->CurrentTimeSeconds(); | 1048 return helper_.scheduler_tqm_delegate()->CurrentTimeSeconds(); |
| 1042 } | 1049 } |
| 1043 | 1050 |
| 1044 double RendererSchedulerImpl::MonotonicallyIncreasingTimeSeconds() const { | 1051 double RendererSchedulerImpl::MonotonicallyIncreasingTimeSeconds() const { |
| 1045 return helper_.scheduler_tqm_delegate()->NowTicks().ToInternalValue() / | 1052 return helper_.scheduler_tqm_delegate()->NowTicks().ToInternalValue() / |
| 1046 static_cast<double>(base::Time::kMicrosecondsPerSecond); | 1053 static_cast<double>(base::Time::kMicrosecondsPerSecond); |
| 1047 } | 1054 } |
| 1048 | 1055 |
| 1056 void RendererSchedulerImpl::RegisterTimeDomain(TimeDomain* time_domain) { |
| 1057 helper_.RegisterTimeDomain(time_domain); |
| 1058 } |
| 1059 |
| 1060 void RendererSchedulerImpl::UnregisterTimeDomain(TimeDomain* time_domain) { |
| 1061 helper_.UnregisterTimeDomain(time_domain); |
| 1062 } |
| 1063 |
| 1064 base::TickClock* RendererSchedulerImpl::tick_clock() const { |
| 1065 return helper_.scheduler_tqm_delegate().get(); |
| 1066 } |
| 1067 |
| 1049 } // namespace scheduler | 1068 } // namespace scheduler |
| OLD | NEW |