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

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: Rebased Created 4 years, 2 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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 main_thread_only().delayed_incoming_queue.top().delayed_run_time <= 334 main_thread_only().delayed_incoming_queue.top().delayed_run_time <=
335 main_thread_only().time_domain->CreateLazyNow().Now()) { 335 main_thread_only().time_domain->CreateLazyNow().Now()) {
336 return true; 336 return true;
337 } 337 }
338 338
339 // Finally tasks on |immediate_incoming_queue| count as immediate work. 339 // Finally tasks on |immediate_incoming_queue| count as immediate work.
340 base::AutoLock lock(any_thread_lock_); 340 base::AutoLock lock(any_thread_lock_);
341 return !any_thread().immediate_incoming_queue.empty(); 341 return !any_thread().immediate_incoming_queue.empty();
342 } 342 }
343 343
344 base::Optional<base::TimeTicks> TaskQueueImpl::GetNextScheduledWakeUp() {
345 if (main_thread_only().delayed_incoming_queue.empty())
346 return base::nullopt;
347
348 return main_thread_only().delayed_incoming_queue.top().delayed_run_time;
349 }
350
344 void TaskQueueImpl::WakeUpForDelayedWork(LazyNow* lazy_now) { 351 void TaskQueueImpl::WakeUpForDelayedWork(LazyNow* lazy_now) {
345 // Enqueue all delayed tasks that should be running now, skipping any that 352 // Enqueue all delayed tasks that should be running now, skipping any that
346 // have been canceled. 353 // have been canceled.
347 while (!main_thread_only().delayed_incoming_queue.empty()) { 354 while (!main_thread_only().delayed_incoming_queue.empty()) {
348 Task& task = 355 Task& task =
349 const_cast<Task&>(main_thread_only().delayed_incoming_queue.top()); 356 const_cast<Task&>(main_thread_only().delayed_incoming_queue.top());
350 if (task.task.IsCancelled()) { 357 if (task.task.IsCancelled()) {
351 main_thread_only().delayed_incoming_queue.pop(); 358 main_thread_only().delayed_incoming_queue.pop();
352 continue; 359 continue;
353 } 360 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 const base::PendingTask& pending_task) { 516 const base::PendingTask& pending_task) {
510 DCHECK(should_notify_observers_); 517 DCHECK(should_notify_observers_);
511 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, 518 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver,
512 main_thread_only().task_observers, 519 main_thread_only().task_observers,
513 DidProcessTask(pending_task)); 520 DidProcessTask(pending_task));
514 if (main_thread_only().blame_context) 521 if (main_thread_only().blame_context)
515 main_thread_only().blame_context->Leave(); 522 main_thread_only().blame_context->Leave();
516 } 523 }
517 524
518 void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) { 525 void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) {
519 base::AutoLock lock(any_thread_lock_); 526 {
520 DCHECK(time_domain); 527 base::AutoLock lock(any_thread_lock_);
521 // NOTE this is similar to checking |any_thread().task_queue_manager| but the 528 DCHECK(time_domain);
522 // TaskQueueSelectorTests constructs TaskQueueImpl directly with a null 529 // NOTE this is similar to checking |any_thread().task_queue_manager| but
523 // task_queue_manager. Instead we check |any_thread().time_domain| which is 530 // the TaskQueueSelectorTests constructs TaskQueueImpl directly with a null
524 // another way of asserting that UnregisterTaskQueue has not been called. 531 // task_queue_manager. Instead we check |any_thread().time_domain| which is
525 DCHECK(any_thread().time_domain); 532 // another way of asserting that UnregisterTaskQueue has not been called.
526 if (!any_thread().time_domain) 533 DCHECK(any_thread().time_domain);
527 return; 534 if (!any_thread().time_domain)
528 DCHECK(main_thread_checker_.CalledOnValidThread()); 535 return;
529 if (time_domain == main_thread_only().time_domain) 536 DCHECK(main_thread_checker_.CalledOnValidThread());
530 return; 537 if (time_domain == main_thread_only().time_domain)
538 return;
531 539
540 any_thread().time_domain = time_domain;
541 }
542 // We rely here on TimeDomain::MigrateQueue being thread-safe to use with
543 // TimeDomain::Register/UnregisterAsUpdatableTaskQueue.
532 main_thread_only().time_domain->MigrateQueue(this, time_domain); 544 main_thread_only().time_domain->MigrateQueue(this, time_domain);
533 main_thread_only().time_domain = time_domain; 545 main_thread_only().time_domain = time_domain;
534 any_thread().time_domain = time_domain;
535 } 546 }
536 547
537 TimeDomain* TaskQueueImpl::GetTimeDomain() const { 548 TimeDomain* TaskQueueImpl::GetTimeDomain() const {
538 if (base::PlatformThread::CurrentId() == thread_id_) 549 if (base::PlatformThread::CurrentId() == thread_id_)
539 return main_thread_only().time_domain; 550 return main_thread_only().time_domain;
540 551
541 base::AutoLock lock(any_thread_lock_); 552 base::AutoLock lock(any_thread_lock_);
542 return any_thread().time_domain; 553 return any_thread().time_domain;
543 } 554 }
544 555
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 state->SetBoolean("is_cancelled", task.task.IsCancelled()); 696 state->SetBoolean("is_cancelled", task.task.IsCancelled());
686 state->SetDouble( 697 state->SetDouble(
687 "delayed_run_time", 698 "delayed_run_time",
688 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); 699 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L);
689 state->EndDictionary(); 700 state->EndDictionary();
690 } 701 }
691 702
692 } // namespace internal 703 } // namespace internal
693 } // namespace scheduler 704 } // namespace scheduler
694 } // namespace blink 705 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698