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 "platform/scheduler/renderer/renderer_scheduler_impl.h" | 5 #include "platform/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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 rail_mode_observer(nullptr) {} | 188 rail_mode_observer(nullptr) {} |
189 | 189 |
190 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {} | 190 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {} |
191 | 191 |
192 RendererSchedulerImpl::AnyThread::AnyThread() | 192 RendererSchedulerImpl::AnyThread::AnyThread() |
193 : awaiting_touch_start_response(false), | 193 : awaiting_touch_start_response(false), |
194 in_idle_period(false), | 194 in_idle_period(false), |
195 begin_main_frame_on_critical_path(false), | 195 begin_main_frame_on_critical_path(false), |
196 last_gesture_was_compositor_driven(false), | 196 last_gesture_was_compositor_driven(false), |
197 default_gesture_prevented(true), | 197 default_gesture_prevented(true), |
198 have_seen_touchstart(false) {} | 198 have_seen_touchstart(false), |
199 waiting_for_meaningful_paint(false) {} | |
199 | 200 |
200 RendererSchedulerImpl::AnyThread::~AnyThread() {} | 201 RendererSchedulerImpl::AnyThread::~AnyThread() {} |
201 | 202 |
202 RendererSchedulerImpl::CompositorThreadOnly::CompositorThreadOnly() | 203 RendererSchedulerImpl::CompositorThreadOnly::CompositorThreadOnly() |
203 : last_input_type(blink::WebInputEvent::Undefined) {} | 204 : last_input_type(blink::WebInputEvent::Undefined) {} |
204 | 205 |
205 RendererSchedulerImpl::CompositorThreadOnly::~CompositorThreadOnly() {} | 206 RendererSchedulerImpl::CompositorThreadOnly::~CompositorThreadOnly() {} |
206 | 207 |
207 void RendererSchedulerImpl::Shutdown() { | 208 void RendererSchedulerImpl::Shutdown() { |
208 base::TimeTicks now = tick_clock()->NowTicks(); | 209 base::TimeTicks now = tick_clock()->NowTicks(); |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
900 // driven gesture. | 901 // driven gesture. |
901 if (touchstart_expected_soon && | 902 if (touchstart_expected_soon && |
902 AnyThread().last_gesture_was_compositor_driven) { | 903 AnyThread().last_gesture_was_compositor_driven) { |
903 new_policy.rail_mode = v8::PERFORMANCE_RESPONSE; | 904 new_policy.rail_mode = v8::PERFORMANCE_RESPONSE; |
904 expensive_task_policy = ExpensiveTaskPolicy::BLOCK; | 905 expensive_task_policy = ExpensiveTaskPolicy::BLOCK; |
905 } | 906 } |
906 break; | 907 break; |
907 | 908 |
908 case UseCase::LOADING: | 909 case UseCase::LOADING: |
909 new_policy.rail_mode = v8::PERFORMANCE_LOAD; | 910 new_policy.rail_mode = v8::PERFORMANCE_LOAD; |
910 new_policy.loading_queue_policy.priority = TaskQueue::HIGH_PRIORITY; | 911 // TODO(skyostil): Experiment with increasing loading and default queue |
911 new_policy.default_queue_policy.priority = TaskQueue::HIGH_PRIORITY; | 912 // priorities. |
alex clarke (OOO till 29th)
2016/10/11 10:32:50
This is probably sensible for now. Presumably we'd
Sami
2016/10/12 04:21:40
Yeah, something like that might be interesting. Al
| |
912 break; | 913 break; |
913 | 914 |
914 default: | 915 default: |
915 NOTREACHED(); | 916 NOTREACHED(); |
916 } | 917 } |
917 | 918 |
918 // TODO(skyostil): Add an idle state for foreground tabs too. | 919 // TODO(skyostil): Add an idle state for foreground tabs too. |
919 if (MainThreadOnly().renderer_hidden) | 920 if (MainThreadOnly().renderer_hidden) |
920 new_policy.rail_mode = v8::PERFORMANCE_IDLE; | 921 new_policy.rail_mode = v8::PERFORMANCE_IDLE; |
921 | 922 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1094 return UseCase::COMPOSITOR_GESTURE; | 1095 return UseCase::COMPOSITOR_GESTURE; |
1095 } | 1096 } |
1096 } | 1097 } |
1097 if (AnyThread().default_gesture_prevented) { | 1098 if (AnyThread().default_gesture_prevented) { |
1098 return UseCase::MAIN_THREAD_CUSTOM_INPUT_HANDLING; | 1099 return UseCase::MAIN_THREAD_CUSTOM_INPUT_HANDLING; |
1099 } else { | 1100 } else { |
1100 return UseCase::MAIN_THREAD_GESTURE; | 1101 return UseCase::MAIN_THREAD_GESTURE; |
1101 } | 1102 } |
1102 } | 1103 } |
1103 | 1104 |
1104 // TODO(alexclarke): return UseCase::LOADING if signals suggest the system is | 1105 if (AnyThread().waiting_for_meaningful_paint) |
alex clarke (OOO till 29th)
2016/10/11 10:32:50
So until first meaningful paint, if the user isn't
Sami
2016/10/12 04:21:40
Right, this implementation of 'L' is very greedy i
| |
1105 // in the initial 1s of RAIL loading. | 1106 return UseCase::LOADING; |
1106 return UseCase::NONE; | 1107 return UseCase::NONE; |
1107 } | 1108 } |
1108 | 1109 |
1109 base::TimeDelta RendererSchedulerImpl::EstimateLongestJankFreeTaskDuration() | 1110 base::TimeDelta RendererSchedulerImpl::EstimateLongestJankFreeTaskDuration() |
1110 const { | 1111 const { |
1111 switch (MainThreadOnly().current_use_case) { | 1112 switch (MainThreadOnly().current_use_case) { |
1112 case UseCase::TOUCHSTART: | 1113 case UseCase::TOUCHSTART: |
1113 case UseCase::COMPOSITOR_GESTURE: | 1114 case UseCase::COMPOSITOR_GESTURE: |
1114 case UseCase::LOADING: | 1115 case UseCase::LOADING: |
1115 case UseCase::NONE: | 1116 case UseCase::NONE: |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1242 state->SetBoolean("begin_frame_not_expected_soon", | 1243 state->SetBoolean("begin_frame_not_expected_soon", |
1243 MainThreadOnly().begin_frame_not_expected_soon); | 1244 MainThreadOnly().begin_frame_not_expected_soon); |
1244 state->SetBoolean("touchstart_expected_soon", | 1245 state->SetBoolean("touchstart_expected_soon", |
1245 MainThreadOnly().touchstart_expected_soon); | 1246 MainThreadOnly().touchstart_expected_soon); |
1246 state->SetString("idle_period_state", | 1247 state->SetString("idle_period_state", |
1247 IdleHelper::IdlePeriodStateToString( | 1248 IdleHelper::IdlePeriodStateToString( |
1248 idle_helper_.SchedulerIdlePeriodState())); | 1249 idle_helper_.SchedulerIdlePeriodState())); |
1249 state->SetBoolean("renderer_hidden", MainThreadOnly().renderer_hidden); | 1250 state->SetBoolean("renderer_hidden", MainThreadOnly().renderer_hidden); |
1250 state->SetBoolean("have_seen_a_begin_main_frame", | 1251 state->SetBoolean("have_seen_a_begin_main_frame", |
1251 MainThreadOnly().have_seen_a_begin_main_frame); | 1252 MainThreadOnly().have_seen_a_begin_main_frame); |
1253 state->SetBoolean("waiting_for_meaningful_paint", | |
1254 AnyThread().waiting_for_meaningful_paint); | |
1252 state->SetBoolean( | 1255 state->SetBoolean( |
1253 "have_reported_blocking_intervention_in_current_policy", | 1256 "have_reported_blocking_intervention_in_current_policy", |
1254 MainThreadOnly().have_reported_blocking_intervention_in_current_policy); | 1257 MainThreadOnly().have_reported_blocking_intervention_in_current_policy); |
1255 state->SetBoolean( | 1258 state->SetBoolean( |
1256 "have_reported_blocking_intervention_since_navigation", | 1259 "have_reported_blocking_intervention_since_navigation", |
1257 MainThreadOnly().have_reported_blocking_intervention_since_navigation); | 1260 MainThreadOnly().have_reported_blocking_intervention_since_navigation); |
1258 state->SetBoolean("renderer_backgrounded", | 1261 state->SetBoolean("renderer_backgrounded", |
1259 MainThreadOnly().renderer_backgrounded); | 1262 MainThreadOnly().renderer_backgrounded); |
1260 state->SetBoolean("timer_queue_suspended_when_backgrounded", | 1263 state->SetBoolean("timer_queue_suspended_when_backgrounded", |
1261 MainThreadOnly().timer_queue_suspended_when_backgrounded); | 1264 MainThreadOnly().timer_queue_suspended_when_backgrounded); |
1262 state->SetInteger("timer_queue_suspend_count", | 1265 state->SetInteger("timer_queue_suspend_count", |
1263 MainThreadOnly().timer_queue_suspend_count); | 1266 MainThreadOnly().timer_queue_suspend_count); |
1264 state->SetDouble("now", (optional_now - base::TimeTicks()).InMillisecondsF()); | 1267 state->SetDouble("now", (optional_now - base::TimeTicks()).InMillisecondsF()); |
1265 state->SetDouble( | 1268 state->SetDouble( |
1266 "rails_loading_priority_deadline", | |
1267 (AnyThread().rails_loading_priority_deadline - base::TimeTicks()) | |
1268 .InMillisecondsF()); | |
1269 state->SetDouble( | |
1270 "fling_compositor_escalation_deadline", | 1269 "fling_compositor_escalation_deadline", |
1271 (AnyThread().fling_compositor_escalation_deadline - base::TimeTicks()) | 1270 (AnyThread().fling_compositor_escalation_deadline - base::TimeTicks()) |
1272 .InMillisecondsF()); | 1271 .InMillisecondsF()); |
1273 state->SetInteger("navigation_task_expected_count", | 1272 state->SetInteger("navigation_task_expected_count", |
1274 MainThreadOnly().navigation_task_expected_count); | 1273 MainThreadOnly().navigation_task_expected_count); |
1275 state->SetDouble("last_idle_period_end_time", | 1274 state->SetDouble("last_idle_period_end_time", |
1276 (AnyThread().last_idle_period_end_time - base::TimeTicks()) | 1275 (AnyThread().last_idle_period_end_time - base::TimeTicks()) |
1277 .InMillisecondsF()); | 1276 .InMillisecondsF()); |
1278 state->SetBoolean("awaiting_touch_start_response", | 1277 state->SetBoolean("awaiting_touch_start_response", |
1279 AnyThread().awaiting_touch_start_response); | 1278 AnyThread().awaiting_touch_start_response); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1349 MainThreadOnly().navigation_task_expected_count > 0) { | 1348 MainThreadOnly().navigation_task_expected_count > 0) { |
1350 MainThreadOnly().navigation_task_expected_count--; | 1349 MainThreadOnly().navigation_task_expected_count--; |
1351 UpdatePolicy(); | 1350 UpdatePolicy(); |
1352 } | 1351 } |
1353 } | 1352 } |
1354 | 1353 |
1355 void RendererSchedulerImpl::OnNavigationStarted() { | 1354 void RendererSchedulerImpl::OnNavigationStarted() { |
1356 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 1355 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
1357 "RendererSchedulerImpl::OnNavigationStarted"); | 1356 "RendererSchedulerImpl::OnNavigationStarted"); |
1358 base::AutoLock lock(any_thread_lock_); | 1357 base::AutoLock lock(any_thread_lock_); |
1359 AnyThread().rails_loading_priority_deadline = | |
1360 helper_.scheduler_tqm_delegate()->NowTicks() + | |
1361 base::TimeDelta::FromMilliseconds( | |
1362 kRailsInitialLoadingPrioritizationMillis); | |
1363 ResetForNavigationLocked(); | 1358 ResetForNavigationLocked(); |
1364 } | 1359 } |
1365 | 1360 |
1361 void RendererSchedulerImpl::OnFirstMeaningfulPaint() { | |
1362 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | |
1363 "RendererSchedulerImpl::OnFirstMeaningfulPaint"); | |
1364 { | |
1365 base::AutoLock lock(any_thread_lock_); | |
1366 AnyThread().waiting_for_meaningful_paint = false; | |
1367 } | |
1368 UpdatePolicy(); | |
1369 } | |
1370 | |
1366 void RendererSchedulerImpl::SuspendTimerQueueWhenBackgrounded() { | 1371 void RendererSchedulerImpl::SuspendTimerQueueWhenBackgrounded() { |
1367 DCHECK(MainThreadOnly().renderer_backgrounded); | 1372 DCHECK(MainThreadOnly().renderer_backgrounded); |
1368 if (MainThreadOnly().timer_queue_suspended_when_backgrounded) | 1373 if (MainThreadOnly().timer_queue_suspended_when_backgrounded) |
1369 return; | 1374 return; |
1370 | 1375 |
1371 MainThreadOnly().timer_queue_suspended_when_backgrounded = true; | 1376 MainThreadOnly().timer_queue_suspended_when_backgrounded = true; |
1372 ForceUpdatePolicy(); | 1377 ForceUpdatePolicy(); |
1373 } | 1378 } |
1374 | 1379 |
1375 void RendererSchedulerImpl::ResumeTimerQueueWhenForegrounded() { | 1380 void RendererSchedulerImpl::ResumeTimerQueueWhenForegrounded() { |
1376 DCHECK(!MainThreadOnly().renderer_backgrounded); | 1381 DCHECK(!MainThreadOnly().renderer_backgrounded); |
1377 if (!MainThreadOnly().timer_queue_suspended_when_backgrounded) | 1382 if (!MainThreadOnly().timer_queue_suspended_when_backgrounded) |
1378 return; | 1383 return; |
1379 | 1384 |
1380 MainThreadOnly().timer_queue_suspended_when_backgrounded = false; | 1385 MainThreadOnly().timer_queue_suspended_when_backgrounded = false; |
1381 ForceUpdatePolicy(); | 1386 ForceUpdatePolicy(); |
1382 } | 1387 } |
1383 | 1388 |
1384 void RendererSchedulerImpl::ResetForNavigationLocked() { | 1389 void RendererSchedulerImpl::ResetForNavigationLocked() { |
1385 helper_.CheckOnValidThread(); | 1390 helper_.CheckOnValidThread(); |
1386 any_thread_lock_.AssertAcquired(); | 1391 any_thread_lock_.AssertAcquired(); |
1387 AnyThread().user_model.Reset(helper_.scheduler_tqm_delegate()->NowTicks()); | 1392 AnyThread().user_model.Reset(helper_.scheduler_tqm_delegate()->NowTicks()); |
1388 AnyThread().have_seen_touchstart = false; | 1393 AnyThread().have_seen_touchstart = false; |
1394 AnyThread().waiting_for_meaningful_paint = true; | |
1389 MainThreadOnly().loading_task_cost_estimator.Clear(); | 1395 MainThreadOnly().loading_task_cost_estimator.Clear(); |
1390 MainThreadOnly().timer_task_cost_estimator.Clear(); | 1396 MainThreadOnly().timer_task_cost_estimator.Clear(); |
1391 MainThreadOnly().idle_time_estimator.Clear(); | 1397 MainThreadOnly().idle_time_estimator.Clear(); |
1392 MainThreadOnly().have_seen_a_begin_main_frame = false; | 1398 MainThreadOnly().have_seen_a_begin_main_frame = false; |
1393 MainThreadOnly().have_reported_blocking_intervention_since_navigation = false; | 1399 MainThreadOnly().have_reported_blocking_intervention_since_navigation = false; |
1394 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); | 1400 UpdatePolicyLocked(UpdateType::MAY_EARLY_OUT_IF_POLICY_UNCHANGED); |
1395 } | 1401 } |
1396 | 1402 |
1397 void RendererSchedulerImpl::SetTopLevelBlameContext( | 1403 void RendererSchedulerImpl::SetTopLevelBlameContext( |
1398 base::trace_event::BlameContext* blame_context) { | 1404 base::trace_event::BlameContext* blame_context) { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1586 case v8::PERFORMANCE_LOAD: | 1592 case v8::PERFORMANCE_LOAD: |
1587 return "load"; | 1593 return "load"; |
1588 default: | 1594 default: |
1589 NOTREACHED(); | 1595 NOTREACHED(); |
1590 return nullptr; | 1596 return nullptr; |
1591 } | 1597 } |
1592 } | 1598 } |
1593 | 1599 |
1594 } // namespace scheduler | 1600 } // namespace scheduler |
1595 } // namespace blink | 1601 } // namespace blink |
OLD | NEW |