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