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

Side by Side Diff: cc/scheduler/scheduler.cc

Issue 1425973003: cc: Don't attempt main thread synchronization if it is slow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new tests Created 5 years, 1 month 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
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/scheduler/scheduler.h" 5 #include "cc/scheduler/scheduler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 211 }
212 } 212 }
213 213
214 void Scheduler::DidSwapBuffersComplete() { 214 void Scheduler::DidSwapBuffersComplete() {
215 DCHECK_GT(state_machine_.pending_swaps(), 0) << AsValue()->ToString(); 215 DCHECK_GT(state_machine_.pending_swaps(), 0) << AsValue()->ToString();
216 compositor_timing_history_->DidSwapBuffersComplete(); 216 compositor_timing_history_->DidSwapBuffersComplete();
217 state_machine_.DidSwapBuffersComplete(); 217 state_machine_.DidSwapBuffersComplete();
218 ProcessScheduledActions(); 218 ProcessScheduledActions();
219 } 219 }
220 220
221 void Scheduler::SetImplLatencyTakesPriority(bool impl_latency_takes_priority) { 221 void Scheduler::SetSmoothnessMode(TreePriority tree_priority,
brianderson 2015/11/17 23:01:45 Note: I ended up keeping this a single function so
Sami 2015/11/18 19:46:04 Ok, the enums do make the call sites easier to rea
222 state_machine_.SetImplLatencyTakesPriority(impl_latency_takes_priority); 222 ScrollHandlerState scroll_handler_state) {
223 state_machine_.SetSmoothnessMode(tree_priority, scroll_handler_state);
223 ProcessScheduledActions(); 224 ProcessScheduledActions();
224 } 225 }
225 226
226 void Scheduler::NotifyReadyToCommit() { 227 void Scheduler::NotifyReadyToCommit() {
227 TRACE_EVENT0("cc", "Scheduler::NotifyReadyToCommit"); 228 TRACE_EVENT0("cc", "Scheduler::NotifyReadyToCommit");
228 state_machine_.NotifyReadyToCommit(); 229 state_machine_.NotifyReadyToCommit();
229 ProcessScheduledActions(); 230 ProcessScheduledActions();
230 } 231 }
231 232
232 void Scheduler::DidCommit() { 233 void Scheduler::DidCommit() {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue()); 311 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginFrame", "args", args.AsValue());
311 312
312 // Trace this begin frame time through the Chrome stack 313 // Trace this begin frame time through the Chrome stack
313 TRACE_EVENT_FLOW_BEGIN0( 314 TRACE_EVENT_FLOW_BEGIN0(
314 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs", 315 TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), "BeginFrameArgs",
315 args.frame_time.ToInternalValue()); 316 args.frame_time.ToInternalValue());
316 317
317 // TODO(brianderson): Adjust deadline in the DisplayScheduler. 318 // TODO(brianderson): Adjust deadline in the DisplayScheduler.
318 BeginFrameArgs adjusted_args(args); 319 BeginFrameArgs adjusted_args(args);
319 adjusted_args.deadline -= EstimatedParentDrawTime(); 320 adjusted_args.deadline -= EstimatedParentDrawTime();
320 adjusted_args.on_critical_path = !ImplLatencyTakesPriority();
321 321
322 // Deliver BeginFrames to children. 322 // Deliver BeginFrames to children.
323 // TODO(brianderson): Move this responsibility to the DisplayScheduler. 323 // TODO(brianderson): Move this responsibility to the DisplayScheduler.
324 if (state_machine_.children_need_begin_frames()) 324 if (state_machine_.children_need_begin_frames())
325 client_->SendBeginFramesToChildren(adjusted_args); 325 client_->SendBeginFramesToChildren(adjusted_args);
326 326
327 if (settings_.using_synchronous_renderer_compositor) { 327 if (settings_.using_synchronous_renderer_compositor) {
328 BeginImplFrameSynchronous(adjusted_args); 328 BeginImplFrameSynchronous(adjusted_args);
329 return true; 329 return true;
330 } 330 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args", 467 TRACE_EVENT2("cc,benchmark", "Scheduler::BeginImplFrame", "args",
468 args.AsValue(), "main_thread_missed_last_deadline", 468 args.AsValue(), "main_thread_missed_last_deadline",
469 main_thread_is_in_high_latency_mode); 469 main_thread_is_in_high_latency_mode);
470 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"), 470 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler"),
471 "MainThreadLatency", main_thread_is_in_high_latency_mode); 471 "MainThreadLatency", main_thread_is_in_high_latency_mode);
472 472
473 BeginFrameArgs adjusted_args = args; 473 BeginFrameArgs adjusted_args = args;
474 adjusted_args.deadline -= compositor_timing_history_->DrawDurationEstimate(); 474 adjusted_args.deadline -= compositor_timing_history_->DrawDurationEstimate();
475 adjusted_args.deadline -= kDeadlineFudgeFactor; 475 adjusted_args.deadline -= kDeadlineFudgeFactor;
476 476
477 if (ShouldRecoverMainLatency(adjusted_args)) { 477 base::TimeDelta bmf_start_to_activate =
478 compositor_timing_history_
479 ->BeginMainFrameStartToCommitDurationEstimate() +
480 compositor_timing_history_->CommitToReadyToActivateDurationEstimate() +
481 compositor_timing_history_->ActivateDurationEstimate();
482
483 base::TimeDelta bmf_to_activate_estimate_if_critical =
484 bmf_start_to_activate +
485 compositor_timing_history_->BeginMainFrameQueueDurationCriticalEstimate();
486
487 bool can_activate_before_deadline_if_critical =
488 CanBeginMainFrameAndActivateBeforeDeadline(
489 adjusted_args, bmf_to_activate_estimate_if_critical);
490 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(
491 can_activate_before_deadline_if_critical);
492
493 // Update the BeginMainFrame args now that we know whether the main
494 // thread will be on the critical path or not.
495 begin_main_frame_args_ = adjusted_args;
496 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority();
497
498 bool can_activate_before_deadline = can_activate_before_deadline_if_critical;
499 if (!begin_main_frame_args_.on_critical_path) {
500 base::TimeDelta bmf_to_activate_estimate =
501 bmf_start_to_activate +
502 compositor_timing_history_
503 ->BeginMainFrameQueueDurationNotCriticalEstimate();
504
505 can_activate_before_deadline = CanBeginMainFrameAndActivateBeforeDeadline(
506 adjusted_args, bmf_to_activate_estimate);
507 }
508
509 if (ShouldRecoverMainLatency(adjusted_args, can_activate_before_deadline)) {
478 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency", 510 TRACE_EVENT_INSTANT0("cc", "SkipBeginMainFrameToReduceLatency",
479 TRACE_EVENT_SCOPE_THREAD); 511 TRACE_EVENT_SCOPE_THREAD);
480 state_machine_.SetSkipNextBeginMainFrameToReduceLatency(); 512 state_machine_.SetSkipNextBeginMainFrameToReduceLatency();
481 } else if (ShouldRecoverImplLatency(adjusted_args)) { 513 } else if (ShouldRecoverImplLatency(adjusted_args,
514 can_activate_before_deadline)) {
482 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency", 515 TRACE_EVENT_INSTANT0("cc", "SkipBeginImplFrameToReduceLatency",
483 TRACE_EVENT_SCOPE_THREAD); 516 TRACE_EVENT_SCOPE_THREAD);
484 frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); 517 frame_source_->DidFinishFrame(begin_retro_frame_args_.size());
485 return; 518 return;
486 } 519 }
487 520
488 BeginImplFrame(adjusted_args); 521 BeginImplFrame(adjusted_args);
489 522
490 // The deadline will be scheduled in ProcessScheduledActions. 523 // The deadline will be scheduled in ProcessScheduledActions.
491 state_machine_.OnBeginImplFrameDeadlinePending(); 524 state_machine_.OnBeginImplFrameDeadlinePending();
492 ProcessScheduledActions(); 525 ProcessScheduledActions();
493 } 526 }
494 527
495 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) { 528 void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) {
496 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args", 529 TRACE_EVENT1("cc,benchmark", "Scheduler::BeginImplFrame", "args",
497 args.AsValue()); 530 args.AsValue());
531
532 // The main thread currently can't commit before we draw with the
533 // synchronous compositor, so never consider the BeginMainFrame fast.
534 state_machine_.SetCriticalBeginMainFrameToActivateIsFast(false);
535 begin_main_frame_args_ = args;
536 begin_main_frame_args_.on_critical_path = !ImplLatencyTakesPriority();
537
498 BeginImplFrame(args); 538 BeginImplFrame(args);
499 FinishImplFrame(); 539 FinishImplFrame();
500 } 540 }
501 541
502 void Scheduler::FinishImplFrame() { 542 void Scheduler::FinishImplFrame() {
503 state_machine_.OnBeginImplFrameIdle(); 543 state_machine_.OnBeginImplFrameIdle();
504 ProcessScheduledActions(); 544 ProcessScheduledActions();
505 545
506 client_->DidFinishImplFrame(); 546 client_->DidFinishImplFrame();
507 frame_source_->DidFinishFrame(begin_retro_frame_args_.size()); 547 frame_source_->DidFinishFrame(begin_retro_frame_args_.size());
508 begin_impl_frame_tracker_.Finish(); 548 begin_impl_frame_tracker_.Finish();
509 } 549 }
510 550
511 // BeginImplFrame starts a compositor frame that will wait up until a deadline 551 // BeginImplFrame starts a compositor frame that will wait up until a deadline
512 // for a BeginMainFrame+activation to complete before it times out and draws 552 // for a BeginMainFrame+activation to complete before it times out and draws
513 // any asynchronous animation and scroll/pinch updates. 553 // any asynchronous animation and scroll/pinch updates.
514 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) { 554 void Scheduler::BeginImplFrame(const BeginFrameArgs& args) {
515 DCHECK_EQ(state_machine_.begin_impl_frame_state(), 555 DCHECK_EQ(state_machine_.begin_impl_frame_state(),
516 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE); 556 SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
517 DCHECK(!BeginImplFrameDeadlinePending()); 557 DCHECK(!BeginImplFrameDeadlinePending());
518 DCHECK(state_machine_.HasInitializedOutputSurface()); 558 DCHECK(state_machine_.HasInitializedOutputSurface());
519 559
520 begin_impl_frame_tracker_.Start(args); 560 begin_impl_frame_tracker_.Start(args);
521 begin_main_frame_args_ = args;
522 state_machine_.OnBeginImplFrame(); 561 state_machine_.OnBeginImplFrame();
523 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_); 562 devtools_instrumentation::DidBeginFrame(layer_tree_host_id_);
524 client_->WillBeginImplFrame(begin_impl_frame_tracker_.Current()); 563 client_->WillBeginImplFrame(begin_impl_frame_tracker_.Current());
525 564
526 ProcessScheduledActions(); 565 ProcessScheduledActions();
527 } 566 }
528 567
529 void Scheduler::ScheduleBeginImplFrameDeadline() { 568 void Scheduler::ScheduleBeginImplFrameDeadline() {
530 // The synchronous compositor does not post a deadline task. 569 // The synchronous compositor does not post a deadline task.
531 DCHECK(!settings_.using_synchronous_renderer_compositor); 570 DCHECK(!settings_.using_synchronous_renderer_compositor);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 state->BeginDictionary("compositor_timing_history"); 822 state->BeginDictionary("compositor_timing_history");
784 compositor_timing_history_->AsValueInto(state); 823 compositor_timing_history_->AsValueInto(state);
785 state->EndDictionary(); 824 state->EndDictionary();
786 } 825 }
787 826
788 void Scheduler::UpdateCompositorTimingHistoryRecordingEnabled() { 827 void Scheduler::UpdateCompositorTimingHistoryRecordingEnabled() {
789 compositor_timing_history_->SetRecordingEnabled( 828 compositor_timing_history_->SetRecordingEnabled(
790 state_machine_.HasInitializedOutputSurface() && state_machine_.visible()); 829 state_machine_.HasInitializedOutputSurface() && state_machine_.visible());
791 } 830 }
792 831
793 bool Scheduler::ShouldRecoverMainLatency(const BeginFrameArgs& args) const { 832 bool Scheduler::ShouldRecoverMainLatency(
833 const BeginFrameArgs& args,
834 bool can_activate_before_deadline) const {
794 DCHECK(!settings_.using_synchronous_renderer_compositor); 835 DCHECK(!settings_.using_synchronous_renderer_compositor);
795 836
796 if (!state_machine_.main_thread_missed_last_deadline()) 837 if (!state_machine_.main_thread_missed_last_deadline())
797 return false; 838 return false;
798 839
799 // When prioritizing impl thread latency, we currently put the 840 // When prioritizing impl thread latency, we currently put the
800 // main thread in a high latency mode. Don't try to fight it. 841 // main thread in a high latency mode. Don't try to fight it.
801 if (state_machine_.impl_latency_takes_priority()) 842 if (state_machine_.ImplLatencyTakesPriority())
802 return false; 843 return false;
803 844
804 return CanCommitAndActivateBeforeDeadline(args); 845 return can_activate_before_deadline;
805 } 846 }
806 847
807 bool Scheduler::ShouldRecoverImplLatency(const BeginFrameArgs& args) const { 848 bool Scheduler::ShouldRecoverImplLatency(
849 const BeginFrameArgs& args,
850 bool can_activate_before_deadline) const {
808 DCHECK(!settings_.using_synchronous_renderer_compositor); 851 DCHECK(!settings_.using_synchronous_renderer_compositor);
809 852
810 // Disable impl thread latency recovery when using the unthrottled 853 // Disable impl thread latency recovery when using the unthrottled
811 // begin frame source since we will always get a BeginFrame before 854 // begin frame source since we will always get a BeginFrame before
812 // the swap ack and our heuristics below will not work. 855 // the swap ack and our heuristics below will not work.
813 if (!throttle_frame_production_) 856 if (!throttle_frame_production_)
814 return false; 857 return false;
815 858
816 // If we are swap throttled at the BeginFrame, that means the impl thread is 859 // If we are swap throttled at the BeginFrame, that means the impl thread is
817 // very likely in a high latency mode. 860 // very likely in a high latency mode.
818 bool impl_thread_is_likely_high_latency = state_machine_.SwapThrottled(); 861 bool impl_thread_is_likely_high_latency = state_machine_.SwapThrottled();
819 if (!impl_thread_is_likely_high_latency) 862 if (!impl_thread_is_likely_high_latency)
820 return false; 863 return false;
821 864
822 // The deadline may be in the past if our draw time is too long. 865 // The deadline may be in the past if our draw time is too long.
823 bool can_draw_before_deadline = args.frame_time < args.deadline; 866 bool can_draw_before_deadline = args.frame_time < args.deadline;
824 867
825 // When prioritizing impl thread latency, the deadline doesn't wait 868 // When prioritizing impl thread latency, the deadline doesn't wait
826 // for the main thread. 869 // for the main thread.
827 if (state_machine_.impl_latency_takes_priority()) 870 if (state_machine_.ImplLatencyTakesPriority())
828 return can_draw_before_deadline; 871 return can_draw_before_deadline;
829 872
830 // If we only have impl-side updates, the deadline doesn't wait for 873 // If we only have impl-side updates, the deadline doesn't wait for
831 // the main thread. 874 // the main thread.
832 if (state_machine_.OnlyImplSideUpdatesExpected()) 875 if (state_machine_.OnlyImplSideUpdatesExpected())
833 return can_draw_before_deadline; 876 return can_draw_before_deadline;
834 877
835 // If we get here, we know the main thread is in a low-latency mode relative 878 // If we get here, we know the main thread is in a low-latency mode relative
836 // to the impl thread. In this case, only try to also recover impl thread 879 // to the impl thread. In this case, only try to also recover impl thread
837 // latency if both the main and impl threads can run serially before the 880 // latency if both the main and impl threads can run serially before the
838 // deadline. 881 // deadline.
839 return CanCommitAndActivateBeforeDeadline(args); 882 return can_activate_before_deadline;
840 } 883 }
841 884
842 bool Scheduler::CanCommitAndActivateBeforeDeadline( 885 bool Scheduler::CanBeginMainFrameAndActivateBeforeDeadline(
843 const BeginFrameArgs& args) const { 886 const BeginFrameArgs& args,
887 base::TimeDelta bmf_to_activate_estimate) const {
844 // Check if the main thread computation and commit can be finished before the 888 // Check if the main thread computation and commit can be finished before the
845 // impl thread's deadline. 889 // impl thread's deadline.
846 base::TimeTicks estimated_draw_time = 890 base::TimeTicks estimated_draw_time =
847 args.frame_time + 891 args.frame_time + bmf_to_activate_estimate;
848 compositor_timing_history_->BeginMainFrameToCommitDurationEstimate() +
849 compositor_timing_history_->CommitToReadyToActivateDurationEstimate() +
850 compositor_timing_history_->ActivateDurationEstimate();
851 892
852 return estimated_draw_time < args.deadline; 893 return estimated_draw_time < args.deadline;
853 } 894 }
854 895
855 bool Scheduler::IsBeginMainFrameSentOrStarted() const { 896 bool Scheduler::IsBeginMainFrameSentOrStarted() const {
856 return (state_machine_.begin_main_frame_state() == 897 return (state_machine_.begin_main_frame_state() ==
857 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT || 898 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_SENT ||
858 state_machine_.begin_main_frame_state() == 899 state_machine_.begin_main_frame_state() ==
859 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED); 900 SchedulerStateMachine::BEGIN_MAIN_FRAME_STATE_STARTED);
860 } 901 }
861 902
862 } // namespace cc 903 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698