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

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: One more fix 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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 main_thread_only().delayed_incoming_queue.top().delayed_run_time <= 343 main_thread_only().delayed_incoming_queue.top().delayed_run_time <=
344 main_thread_only().time_domain->CreateLazyNow().Now()) { 344 main_thread_only().time_domain->CreateLazyNow().Now()) {
345 return true; 345 return true;
346 } 346 }
347 347
348 // Finally tasks on |immediate_incoming_queue| count as immediate work. 348 // Finally tasks on |immediate_incoming_queue| count as immediate work.
349 base::AutoLock lock(any_thread_lock_); 349 base::AutoLock lock(any_thread_lock_);
350 return !any_thread().immediate_incoming_queue.empty(); 350 return !any_thread().immediate_incoming_queue.empty();
351 } 351 }
352 352
353 base::Optional<base::TimeTicks> TaskQueueImpl::GetNextScheduledWakeUp() {
354 if (main_thread_only().delayed_incoming_queue.empty())
355 return base::nullopt;
356
357 return main_thread_only().delayed_incoming_queue.top().delayed_run_time;
358 }
359
353 void TaskQueueImpl::WakeUpForDelayedWork(LazyNow* lazy_now) { 360 void TaskQueueImpl::WakeUpForDelayedWork(LazyNow* lazy_now) {
354 // Enqueue all delayed tasks that should be running now, skipping any that 361 // Enqueue all delayed tasks that should be running now, skipping any that
355 // have been canceled. 362 // have been canceled.
356 while (!main_thread_only().delayed_incoming_queue.empty()) { 363 while (!main_thread_only().delayed_incoming_queue.empty()) {
357 // TODO(alexclarke): Use extract() when C++17 is allowed. 364 // TODO(alexclarke): Use extract() when C++17 is allowed.
358 Task& task = 365 Task& task =
359 const_cast<Task&>(main_thread_only().delayed_incoming_queue.top()); 366 const_cast<Task&>(main_thread_only().delayed_incoming_queue.top());
360 if (task.task.IsCancelled()) { 367 if (task.task.IsCancelled()) {
361 main_thread_only().delayed_incoming_queue.pop(); 368 main_thread_only().delayed_incoming_queue.pop();
362 continue; 369 continue;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 const base::PendingTask& pending_task) { 526 const base::PendingTask& pending_task) {
520 DCHECK(should_notify_observers_); 527 DCHECK(should_notify_observers_);
521 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver, 528 FOR_EACH_OBSERVER(base::MessageLoop::TaskObserver,
522 main_thread_only().task_observers, 529 main_thread_only().task_observers,
523 DidProcessTask(pending_task)); 530 DidProcessTask(pending_task));
524 if (main_thread_only().blame_context) 531 if (main_thread_only().blame_context)
525 main_thread_only().blame_context->Leave(); 532 main_thread_only().blame_context->Leave();
526 } 533 }
527 534
528 void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) { 535 void TaskQueueImpl::SetTimeDomain(TimeDomain* time_domain) {
529 base::AutoLock lock(any_thread_lock_); 536 {
530 DCHECK(time_domain); 537 base::AutoLock lock(any_thread_lock_);
531 // NOTE this is similar to checking |any_thread().task_queue_manager| but the 538 DCHECK(time_domain);
532 // TaskQueueSelectorTests constructs TaskQueueImpl directly with a null 539 // NOTE this is similar to checking |any_thread().task_queue_manager| but
533 // task_queue_manager. Instead we check |any_thread().time_domain| which is 540 // the TaskQueueSelectorTests constructs TaskQueueImpl directly with a null
534 // another way of asserting that UnregisterTaskQueue has not been called. 541 // task_queue_manager. Instead we check |any_thread().time_domain| which is
535 DCHECK(any_thread().time_domain); 542 // another way of asserting that UnregisterTaskQueue has not been called.
536 if (!any_thread().time_domain) 543 DCHECK(any_thread().time_domain);
537 return; 544 if (!any_thread().time_domain)
538 DCHECK(main_thread_checker_.CalledOnValidThread()); 545 return;
539 if (time_domain == main_thread_only().time_domain) 546 DCHECK(main_thread_checker_.CalledOnValidThread());
540 return; 547 if (time_domain == main_thread_only().time_domain)
548 return;
541 549
550 any_thread().time_domain = time_domain;
551 }
552 // We rely here on TimeDomain::MigrateQueue being thread-safe to use with
553 // TimeDomain::Register/UnregisterAsUpdatableTaskQueue.
542 main_thread_only().time_domain->MigrateQueue(this, time_domain); 554 main_thread_only().time_domain->MigrateQueue(this, time_domain);
543 main_thread_only().time_domain = time_domain; 555 main_thread_only().time_domain = time_domain;
544 any_thread().time_domain = time_domain;
545 } 556 }
546 557
547 TimeDomain* TaskQueueImpl::GetTimeDomain() const { 558 TimeDomain* TaskQueueImpl::GetTimeDomain() const {
548 if (base::PlatformThread::CurrentId() == thread_id_) 559 if (base::PlatformThread::CurrentId() == thread_id_)
549 return main_thread_only().time_domain; 560 return main_thread_only().time_domain;
550 561
551 base::AutoLock lock(any_thread_lock_); 562 base::AutoLock lock(any_thread_lock_);
552 return any_thread().time_domain; 563 return any_thread().time_domain;
553 } 564 }
554 565
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 state->SetBoolean("is_cancelled", task.task.IsCancelled()); 706 state->SetBoolean("is_cancelled", task.task.IsCancelled());
696 state->SetDouble( 707 state->SetDouble(
697 "delayed_run_time", 708 "delayed_run_time",
698 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); 709 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L);
699 state->EndDictionary(); 710 state->EndDictionary();
700 } 711 }
701 712
702 } // namespace internal 713 } // namespace internal
703 } // namespace scheduler 714 } // namespace scheduler
704 } // namespace blink 715 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698