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

Side by Side Diff: gpu/command_buffer/service/sync_point_manager.cc

Issue 1339203002: Added global order numbers to in process command buffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "gpu/command_buffer/service/sync_point_manager.h" 5 #include "gpu/command_buffer/service/sync_point_manager.h"
6 6
7 #include <climits> 7 #include <climits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
11 #include "base/sequence_checker.h" 11 #include "base/sequence_checker.h"
12 12
13 namespace gpu { 13 namespace gpu {
14 14
15 static const int kMaxSyncBase = INT_MAX; 15 static const int kMaxSyncBase = INT_MAX;
16 16
17 SyncPointClient::SyncPointClient(SyncPointManager* sync_point_manager,
18 SyncPointNamespace namespace_id,
19 uint64_t client_id)
20 : sync_point_manager_(sync_point_manager),
21 namespace_id_(namespace_id),
22 client_id_(client_id),
23 current_order_num_(0),
24 processed_order_num_(0) {
25 }
26
27 SyncPointClient::~SyncPointClient() {
28 sync_point_manager_->RemoveSyncPointClient(namespace_id_, client_id_);
29 }
30
17 SyncPointManager::SyncPointManager(bool allow_threaded_wait) 31 SyncPointManager::SyncPointManager(bool allow_threaded_wait)
18 : allow_threaded_wait_(allow_threaded_wait), 32 : allow_threaded_wait_(allow_threaded_wait),
19 // To reduce the risk that a sync point created in a previous GPU process 33 // To reduce the risk that a sync point created in a previous GPU process
20 // will be in flight in the next GPU process, randomize the starting sync 34 // will be in flight in the next GPU process, randomize the starting sync
21 // point number. http://crbug.com/373452 35 // point number. http://crbug.com/373452
22 next_sync_point_(base::RandInt(1, kMaxSyncBase)), 36 next_sync_point_(base::RandInt(1, kMaxSyncBase)),
23 retire_cond_var_(&lock_) {} 37 retire_cond_var_(&lock_) {
38 global_order_num_.GetNext();
39 }
24 40
25 SyncPointManager::~SyncPointManager() {} 41 SyncPointManager::~SyncPointManager() {}
piman 2015/09/14 23:43:53 Can you DCHECK that all client maps are empty? Oth
David Yen 2015/09/15 18:09:31 I was going to do this, must have forgotten. Done
26 42
43 scoped_refptr<SyncPointClient> SyncPointManager::CreateSyncPointClient(
44 SyncPointNamespace namespace_id, uint64_t client_id) {
45 DCHECK(namespace_id >= 0 && namespace_id < NUM_SYNC_POINT_NAMESPACES);
46 base::AutoLock auto_lock(client_maps_lock_[namespace_id]);
47
48 ClientMap& client_map = client_maps_[namespace_id];
49 std::pair<ClientMap::iterator, bool> result = client_map.insert(
50 std::make_pair(client_id, new SyncPointClient(this,
51 namespace_id,
52 client_id)));
53 DCHECK(result.second);
54
55 return result.first->second;
56 }
57
58 scoped_refptr<SyncPointClient> SyncPointManager::GetSyncPointClient(
59 SyncPointNamespace namespace_id, uint64_t client_id) {
60 DCHECK(namespace_id >= 0 && namespace_id < NUM_SYNC_POINT_NAMESPACES);
61 base::AutoLock auto_lock(client_maps_lock_[namespace_id]);
62
63 ClientMap& client_map = client_maps_[namespace_id];
64 ClientMap::iterator it = client_map.find(client_id);
65 if (it != client_map.end()) {
66 return it->second;
67 }
68 return nullptr;
69 }
70
71 uint32_t SyncPointManager::GenerateOrderNumber() {
72 return global_order_num_.GetNext();
73 }
74
27 uint32 SyncPointManager::GenerateSyncPoint() { 75 uint32 SyncPointManager::GenerateSyncPoint() {
28 base::AutoLock lock(lock_); 76 base::AutoLock lock(lock_);
29 uint32 sync_point = next_sync_point_++; 77 uint32 sync_point = next_sync_point_++;
30 // When an integer overflow occurs, don't return 0. 78 // When an integer overflow occurs, don't return 0.
31 if (!sync_point) 79 if (!sync_point)
32 sync_point = next_sync_point_++; 80 sync_point = next_sync_point_++;
33 81
34 // Note: wrapping would take days for a buggy/compromized renderer that would 82 // Note: wrapping would take days for a buggy/compromized renderer that would
35 // insert sync points in a loop, but if that were to happen, better explicitly 83 // insert sync points in a loop, but if that were to happen, better explicitly
36 // crash the GPU process than risk worse. 84 // crash the GPU process than risk worse.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 while (!IsSyncPointRetiredLocked(sync_point)) { 136 while (!IsSyncPointRetiredLocked(sync_point)) {
89 retire_cond_var_.Wait(); 137 retire_cond_var_.Wait();
90 } 138 }
91 } 139 }
92 140
93 bool SyncPointManager::IsSyncPointRetiredLocked(uint32 sync_point) { 141 bool SyncPointManager::IsSyncPointRetiredLocked(uint32 sync_point) {
94 lock_.AssertAcquired(); 142 lock_.AssertAcquired();
95 return sync_point_map_.find(sync_point) == sync_point_map_.end(); 143 return sync_point_map_.find(sync_point) == sync_point_map_.end();
96 } 144 }
97 145
146 void SyncPointManager::RemoveSyncPointClient(SyncPointNamespace namespace_id,
147 uint64_t client_id) {
148 DCHECK(namespace_id >= 0 && namespace_id < NUM_SYNC_POINT_NAMESPACES);
149 base::AutoLock auto_lock(client_maps_lock_[namespace_id]);
150 ClientMap& client_map = client_maps_[namespace_id];
151 ClientMap::iterator it = client_map.find(client_id);
152 DCHECK(it != client_map.end());
153 client_map.erase(it);
154 }
155
98 } // namespace gpu 156 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698