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

Side by Side Diff: cc/resources/one_copy_raster_worker_pool.cc

Issue 683263004: cc: Detect miss-behaving fence extensions when using 1-copy rasterizer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@one-copy-throttling
Patch Set: rebase Created 6 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
« no previous file with comments | « cc/resources/one_copy_raster_worker_pool.h ('k') | cc/resources/resource_pool.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "cc/resources/one_copy_raster_worker_pool.h" 5 #include "cc/resources/one_copy_raster_worker_pool.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 // Flush interval when performing copy operations. 81 // Flush interval when performing copy operations.
82 const int kCopyFlushPeriod = 4; 82 const int kCopyFlushPeriod = 4;
83 83
84 // Number of in-flight copy operations to allow. 84 // Number of in-flight copy operations to allow.
85 const int kMaxCopyOperations = 16; 85 const int kMaxCopyOperations = 16;
86 86
87 // Delay been checking for copy operations to complete. 87 // Delay been checking for copy operations to complete.
88 const int kCheckForCompletedCopyOperationsTickRateMs = 1; 88 const int kCheckForCompletedCopyOperationsTickRateMs = 1;
89 89
90 // Number of failed attempts to allow before we perform a check that will
91 // wait for copy operations to complete if needed.
92 const int kFailedAttemptsBeforeWaitIfNeeded = 256;
vmpstr 2014/10/29 17:36:25 Is there any way we can eliminate some of these co
reveman 2014/10/29 18:42:48 Not sure. This last constant is just to detect dri
93
90 } // namespace 94 } // namespace
91 95
92 OneCopyRasterWorkerPool::CopyOperation::CopyOperation( 96 OneCopyRasterWorkerPool::CopyOperation::CopyOperation(
93 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, 97 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock,
94 scoped_ptr<ScopedResource> src, 98 scoped_ptr<ScopedResource> src,
95 const Resource* dst) 99 const Resource* dst)
96 : write_lock(write_lock.Pass()), src(src.Pass()), dst(dst) { 100 : write_lock(write_lock.Pass()), src(src.Pass()), dst(dst) {
97 } 101 }
98 102
99 OneCopyRasterWorkerPool::CopyOperation::~CopyOperation() { 103 OneCopyRasterWorkerPool::CopyOperation::~CopyOperation() {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 size_t task_count[kNumberOfTaskSets] = {0}; 192 size_t task_count[kNumberOfTaskSets] = {0};
189 193
190 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { 194 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
191 new_raster_finished_tasks[task_set] = CreateRasterFinishedTask( 195 new_raster_finished_tasks[task_set] = CreateRasterFinishedTask(
192 task_runner_.get(), 196 task_runner_.get(),
193 base::Bind(&OneCopyRasterWorkerPool::OnRasterFinished, 197 base::Bind(&OneCopyRasterWorkerPool::OnRasterFinished,
194 raster_finished_weak_ptr_factory_.GetWeakPtr(), 198 raster_finished_weak_ptr_factory_.GetWeakPtr(),
195 task_set)); 199 task_set));
196 } 200 }
197 201
198 resource_pool_->CheckBusyResources(); 202 resource_pool_->CheckBusyResources(false);
199 203
200 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); 204 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin();
201 it != queue->items.end(); 205 it != queue->items.end();
202 ++it) { 206 ++it) {
203 const RasterTaskQueue::Item& item = *it; 207 const RasterTaskQueue::Item& item = *it;
204 RasterTask* task = item.task; 208 RasterTask* task = item.task;
205 DCHECK(!task->HasCompleted()); 209 DCHECK(!task->HasCompleted());
206 210
207 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { 211 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
208 if (!item.task_sets[task_set]) 212 if (!item.task_sets[task_set])
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 const Resource* dst, 280 const Resource* dst,
277 const RasterSource* raster_source, 281 const RasterSource* raster_source,
278 const gfx::Rect& rect, 282 const gfx::Rect& rect,
279 float scale, 283 float scale,
280 RenderingStatsInstrumentation* stats) { 284 RenderingStatsInstrumentation* stats) {
281 CopySequenceNumber sequence; 285 CopySequenceNumber sequence;
282 286
283 { 287 {
284 base::AutoLock lock(lock_); 288 base::AutoLock lock(lock_);
285 289
290 int failed_attempts = 0;
286 while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >= 291 while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >=
287 kMaxCopyOperations) { 292 kMaxCopyOperations) {
288 // Ignore limit when shutdown is set. 293 // Ignore limit when shutdown is set.
289 if (shutdown_) 294 if (shutdown_)
290 break; 295 break;
291 296
297 ++failed_attempts;
298
299 // Schedule a check that will also wait for operations to complete
300 // after too many failed attempts.
301 bool wait_if_needed = failed_attempts > kFailedAttemptsBeforeWaitIfNeeded;
302
292 // Schedule a check for completed copy operations if too many operations 303 // Schedule a check for completed copy operations if too many operations
293 // are currently in-flight. 304 // are currently in-flight.
294 ScheduleCheckForCompletedCopyOperationsWithLockAcquired(); 305 ScheduleCheckForCompletedCopyOperationsWithLockAcquired(wait_if_needed);
295 306
296 { 307 {
297 TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete"); 308 TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete");
298 309
299 // Wait for in-flight copy operations to drop below limit. 310 // Wait for in-flight copy operations to drop below limit.
300 copy_operation_count_cv_.Wait(); 311 copy_operation_count_cv_.Wait();
301 } 312 }
302 } 313 }
303 314
304 // Increment |scheduled_copy_operation_count_| before releasing |lock_|. 315 // Increment |scheduled_copy_operation_count_| before releasing |lock_|.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 } 393 }
383 394
384 void OneCopyRasterWorkerPool::IssueCopyOperations(int64 count) { 395 void OneCopyRasterWorkerPool::IssueCopyOperations(int64 count) {
385 TRACE_EVENT1( 396 TRACE_EVENT1(
386 "cc", "OneCopyRasterWorkerPool::IssueCopyOperations", "count", count); 397 "cc", "OneCopyRasterWorkerPool::IssueCopyOperations", "count", count);
387 398
388 CopyOperation::Deque copy_operations; 399 CopyOperation::Deque copy_operations;
389 400
390 // This is a good time to check for completed copy operations as 401 // This is a good time to check for completed copy operations as
391 // |issued_copy_operation_count_| need to be updated below. 402 // |issued_copy_operation_count_| need to be updated below.
392 resource_pool_->CheckBusyResources(); 403 resource_pool_->CheckBusyResources(false);
393 404
394 { 405 {
395 base::AutoLock lock(lock_); 406 base::AutoLock lock(lock_);
396 407
397 for (int64 i = 0; i < count; ++i) { 408 for (int64 i = 0; i < count; ++i) {
398 DCHECK(!pending_copy_operations_.empty()); 409 DCHECK(!pending_copy_operations_.empty());
399 copy_operations.push_back(pending_copy_operations_.take_front()); 410 copy_operations.push_back(pending_copy_operations_.take_front());
400 } 411 }
401 412
402 // Decrement |scheduled_copy_operation_count_| and increment 413 // Decrement |scheduled_copy_operation_count_| and increment
(...skipping 16 matching lines...) Expand all
419 resource_provider_->CopyResource(copy_operation->src->id(), 430 resource_provider_->CopyResource(copy_operation->src->id(),
420 copy_operation->dst->id()); 431 copy_operation->dst->id());
421 432
422 // Return source resource to pool where it can be reused once copy 433 // Return source resource to pool where it can be reused once copy
423 // operation has completed and resource is no longer busy. 434 // operation has completed and resource is no longer busy.
424 resource_pool_->ReleaseResource(copy_operation->src.Pass()); 435 resource_pool_->ReleaseResource(copy_operation->src.Pass());
425 } 436 }
426 } 437 }
427 438
428 void OneCopyRasterWorkerPool:: 439 void OneCopyRasterWorkerPool::
429 ScheduleCheckForCompletedCopyOperationsWithLockAcquired() { 440 ScheduleCheckForCompletedCopyOperationsWithLockAcquired(
441 bool wait_if_needed) {
430 lock_.AssertAcquired(); 442 lock_.AssertAcquired();
431 443
432 if (check_for_completed_copy_operations_pending_) 444 if (check_for_completed_copy_operations_pending_)
433 return; 445 return;
434 446
435 base::TimeTicks now = base::TimeTicks::Now(); 447 base::TimeTicks now = base::TimeTicks::Now();
436 448
437 // Schedule a check for completed copy operations as soon as possible but 449 // Schedule a check for completed copy operations as soon as possible but
438 // don't allow two consecutive checks to be scheduled to run less than the 450 // don't allow two consecutive checks to be scheduled to run less than the
439 // tick rate apart. 451 // tick rate apart.
440 base::TimeTicks next_check_for_completed_copy_operations_time = 452 base::TimeTicks next_check_for_completed_copy_operations_time =
441 std::max(last_check_for_completed_copy_operations_time_ + 453 std::max(last_check_for_completed_copy_operations_time_ +
442 base::TimeDelta::FromMilliseconds( 454 base::TimeDelta::FromMilliseconds(
443 kCheckForCompletedCopyOperationsTickRateMs), 455 kCheckForCompletedCopyOperationsTickRateMs),
444 now); 456 now);
445 457
446 task_runner_->PostDelayedTask( 458 task_runner_->PostDelayedTask(
447 FROM_HERE, 459 FROM_HERE,
448 base::Bind(&OneCopyRasterWorkerPool::CheckForCompletedCopyOperations, 460 base::Bind(&OneCopyRasterWorkerPool::CheckForCompletedCopyOperations,
449 weak_ptr_factory_.GetWeakPtr()), 461 weak_ptr_factory_.GetWeakPtr(),
462 wait_if_needed),
450 next_check_for_completed_copy_operations_time - now); 463 next_check_for_completed_copy_operations_time - now);
451 464
452 last_check_for_completed_copy_operations_time_ = 465 last_check_for_completed_copy_operations_time_ =
453 next_check_for_completed_copy_operations_time; 466 next_check_for_completed_copy_operations_time;
454 check_for_completed_copy_operations_pending_ = true; 467 check_for_completed_copy_operations_pending_ = true;
455 } 468 }
456 469
457 void OneCopyRasterWorkerPool::CheckForCompletedCopyOperations() { 470 void OneCopyRasterWorkerPool::CheckForCompletedCopyOperations(
458 TRACE_EVENT0("cc", 471 bool wait_if_needed) {
459 "OneCopyRasterWorkerPool::CheckForCompletedCopyOperations"); 472 TRACE_EVENT1("cc",
473 "OneCopyRasterWorkerPool::CheckForCompletedCopyOperations",
474 "wait_if_needed",
475 wait_if_needed);
460 476
461 resource_pool_->CheckBusyResources(); 477 resource_pool_->CheckBusyResources(wait_if_needed);
462 478
463 { 479 {
464 base::AutoLock lock(lock_); 480 base::AutoLock lock(lock_);
465 481
466 DCHECK(check_for_completed_copy_operations_pending_); 482 DCHECK(check_for_completed_copy_operations_pending_);
467 check_for_completed_copy_operations_pending_ = false; 483 check_for_completed_copy_operations_pending_ = false;
468 484
469 // The number of busy resources in the pool reflects the number of issued 485 // The number of busy resources in the pool reflects the number of issued
470 // copy operations that have not yet completed. 486 // copy operations that have not yet completed.
471 issued_copy_operation_count_ = resource_pool_->busy_resource_count(); 487 issued_copy_operation_count_ = resource_pool_->busy_resource_count();
(...skipping 28 matching lines...) Expand all
500 resource_pool_->total_memory_usage_bytes()); 516 resource_pool_->total_memory_usage_bytes());
501 staging_state->SetInteger("pending_copy_count", 517 staging_state->SetInteger("pending_copy_count",
502 resource_pool_->total_resource_count() - 518 resource_pool_->total_resource_count() -
503 resource_pool_->acquired_resource_count()); 519 resource_pool_->acquired_resource_count());
504 staging_state->SetInteger("bytes_pending_copy", 520 staging_state->SetInteger("bytes_pending_copy",
505 resource_pool_->total_memory_usage_bytes() - 521 resource_pool_->total_memory_usage_bytes() -
506 resource_pool_->acquired_memory_usage_bytes()); 522 resource_pool_->acquired_memory_usage_bytes());
507 } 523 }
508 524
509 } // namespace cc 525 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/one_copy_raster_worker_pool.h ('k') | cc/resources/resource_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698