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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.cc

Issue 2258133002: [scheduler] Implement time-based cpu throttling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed Enable/Disable to Enable/DisableThrottling. Created 4 years, 3 months 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/base/task_queue_impl.h" 5 #include "platform/scheduler/base/task_queue_impl.h"
6 6
7 #include "base/trace_event/blame_context.h" 7 #include "base/trace_event/blame_context.h"
8 #include "platform/scheduler/base/task_queue_manager.h" 8 #include "platform/scheduler/base/task_queue_manager.h"
9 #include "platform/scheduler/base/task_queue_manager_delegate.h" 9 #include "platform/scheduler/base/task_queue_manager_delegate.h"
10 #include "platform/scheduler/base/time_domain.h" 10 #include "platform/scheduler/base/time_domain.h"
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 !main_thread_only().immediate_work_queue->Empty()) { 507 !main_thread_only().immediate_work_queue->Empty()) {
508 return false; 508 return false;
509 } 509 }
510 510
511 base::AutoLock lock(any_thread_lock_); 511 base::AutoLock lock(any_thread_lock_);
512 return any_thread().immediate_incoming_queue.empty() && 512 return any_thread().immediate_incoming_queue.empty() &&
513 main_thread_only().delayed_incoming_queue.empty(); 513 main_thread_only().delayed_incoming_queue.empty();
514 } 514 }
515 515
516 bool TaskQueueImpl::HasPendingImmediateWork() const { 516 bool TaskQueueImpl::HasPendingImmediateWork() const {
517 LazyNow lazy_now = main_thread_only().time_domain->CreateLazyNow();
alex clarke (OOO till 29th) 2016/09/15 12:19:34 nit: revert this and change on line 529
altimin 2016/09/15 15:52:10 Done.
518
517 // Any work queue tasks count as immediate work. 519 // Any work queue tasks count as immediate work.
518 if (!main_thread_only().delayed_work_queue->Empty() || 520 if (!main_thread_only().delayed_work_queue->Empty() ||
519 !main_thread_only().immediate_work_queue->Empty()) { 521 !main_thread_only().immediate_work_queue->Empty()) {
520 return true; 522 return true;
521 } 523 }
522 524
523 // Tasks on |delayed_incoming_queue| that could run now, count as 525 // Tasks on |delayed_incoming_queue| that could run now, count as
524 // immediate work. 526 // immediate work.
525 if (!main_thread_only().delayed_incoming_queue.empty() && 527 if (!main_thread_only().delayed_incoming_queue.empty() &&
526 main_thread_only().delayed_incoming_queue.begin()->delayed_run_time <= 528 main_thread_only().delayed_incoming_queue.begin()->delayed_run_time <=
527 main_thread_only().time_domain->CreateLazyNow().Now()) { 529 lazy_now.Now()) {
528 return true; 530 return true;
529 } 531 }
530 532
531 // Finally tasks on |immediate_incoming_queue| count as immediate work. 533 // Finally tasks on |immediate_incoming_queue| count as immediate work.
532 base::AutoLock lock(any_thread_lock_); 534 base::AutoLock lock(any_thread_lock_);
533 return !any_thread().immediate_incoming_queue.empty(); 535 return !any_thread().immediate_incoming_queue.empty();
534 } 536 }
535 537
538 base::Optional<base::TimeTicks> TaskQueueImpl::GetNextScheduledWakeUp() {
539 if (main_thread_only().delayed_incoming_queue.empty())
540 return base::nullopt;
541
542 return main_thread_only().delayed_incoming_queue.begin()->delayed_run_time;
543 }
544
536 void TaskQueueImpl::MoveReadyDelayedTasksToDelayedWorkQueue(LazyNow* lazy_now) { 545 void TaskQueueImpl::MoveReadyDelayedTasksToDelayedWorkQueue(LazyNow* lazy_now) {
537 // Enqueue all delayed tasks that should be running now. 546 // Enqueue all delayed tasks that should be running now.
538 while (!main_thread_only().delayed_incoming_queue.empty()) { 547 while (!main_thread_only().delayed_incoming_queue.empty()) {
539 DelayedRunTimeQueue::iterator next_task = 548 DelayedRunTimeQueue::iterator next_task =
540 main_thread_only().delayed_incoming_queue.begin(); 549 main_thread_only().delayed_incoming_queue.begin();
541 if (next_task->delayed_run_time > lazy_now->Now()) 550 if (next_task->delayed_run_time > lazy_now->Now())
542 break; 551 break;
543 // TODO(alexclarke): Use extract() when C++17 is allowed. 552 // TODO(alexclarke): Use extract() when C++17 is allowed.
544 Task& task = const_cast<Task&>(*next_task); 553 Task& task = const_cast<Task&>(*next_task);
545 task.set_enqueue_order( 554 task.set_enqueue_order(
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 const base::PendingTask& pending_task) { 706 const base::PendingTask& pending_task) {
698 DCHECK(should_notify_observers_); 707 DCHECK(should_notify_observers_);
699 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, 708 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver,
700 main_thread_only().task_observers, 709 main_thread_only().task_observers,
701 DidProcessTask(pending_task)); 710 DidProcessTask(pending_task));
702 if (main_thread_only().blame_context) 711 if (main_thread_only().blame_context)
703 main_thread_only().blame_context->Leave(); 712 main_thread_only().blame_context->Leave();
704 } 713 }
705 714
706 void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) { 715 void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) {
707 base::AutoLock lock(any_thread_lock_); 716 {
708 DCHECK(time_domain); 717 base::AutoLock lock(any_thread_lock_);
709 // NOTE this is similar to checking |any_thread().task_queue_manager| but the 718 DCHECK(time_domain);
710 // TaskQueueSelectorTests constructs TaskQueueImpl directly with a null 719 // NOTE this is similar to checking |any_thread().task_queue_manager| but
711 // task_queue_manager. Instead we check |any_thread().time_domain| which is 720 // the
alex clarke (OOO till 29th) 2016/09/15 12:19:34 reformat please.
altimin 2016/09/15 15:52:10 Done.
712 // another way of asserting that UnregisterTaskQueue has not been called. 721 // TaskQueueSelectorTests constructs TaskQueueImpl directly with a null
713 DCHECK(any_thread().time_domain); 722 // task_queue_manager. Instead we check |any_thread().time_domain| which is
714 if (!any_thread().time_domain) 723 // another way of asserting that UnregisterTaskQueue has not been called.
715 return; 724 DCHECK(any_thread().time_domain);
716 DCHECK(main_thread_checker_.CalledOnValidThread()); 725 if (!any_thread().time_domain)
717 if (time_domain == main_thread_only().time_domain) 726 return;
718 return; 727 DCHECK(main_thread_checker_.CalledOnValidThread());
728 if (time_domain == main_thread_only().time_domain)
729 return;
719 730
731 any_thread().time_domain = time_domain;
732 }
733 // We rely here on TimeDomain::Register/UnregisterAsUpdatableTaskQueue being
Sami 2016/09/15 16:30:29 nit: really we're relying on TimeDomain::MigrateQu
altimin 2016/09/16 13:38:48 It's more tricky. TimeDomain::MigrateQueue is main
734 // thread-safe.
720 main_thread_only().time_domain->MigrateQueue(this, time_domain); 735 main_thread_only().time_domain->MigrateQueue(this, time_domain);
721 main_thread_only().time_domain = time_domain; 736 main_thread_only().time_domain = time_domain;
722 any_thread().time_domain = time_domain;
723 } 737 }
724 738
725 TimeDomain* TaskQueueImpl::GetTimeDomain() const { 739 TimeDomain* TaskQueueImpl::GetTimeDomain() const {
726 if (base::PlatformThread::CurrentId() == thread_id_) 740 if (base::PlatformThread::CurrentId() == thread_id_)
727 return main_thread_only().time_domain; 741 return main_thread_only().time_domain;
728 742
729 base::AutoLock lock(any_thread_lock_); 743 base::AutoLock lock(any_thread_lock_);
730 return any_thread().time_domain; 744 return any_thread().time_domain;
731 } 745 }
732 746
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 state->SetBoolean("is_high_res", task.is_high_res); 871 state->SetBoolean("is_high_res", task.is_high_res);
858 state->SetDouble( 872 state->SetDouble(
859 "delayed_run_time", 873 "delayed_run_time",
860 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); 874 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L);
861 state->EndDictionary(); 875 state->EndDictionary();
862 } 876 }
863 877
864 } // namespace internal 878 } // namespace internal
865 } // namespace scheduler 879 } // namespace scheduler
866 } // namespace blink 880 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698