@@ -73,7 +73,7 @@ SvmMapOperation *SVMAllocsManager::MapOperationsTracker::get(const void *regionP
7373void SVMAllocsManager::addInternalAllocationsToResidencyContainer (uint32_t rootDeviceIndex,
7474 ResidencyContainer &residencyContainer,
7575 uint32_t requestedTypesMask) {
76- std::unique_lock<SpinLock > lock (mtx);
76+ std::shared_lock<std::shared_mutex > lock (mtx);
7777 for (auto &allocation : this ->SVMAllocs .allocations ) {
7878 if (rootDeviceIndex >= allocation.second .gpuAllocations .getGraphicsAllocations ().size ()) {
7979 continue ;
@@ -90,7 +90,7 @@ void SVMAllocsManager::addInternalAllocationsToResidencyContainer(uint32_t rootD
9090}
9191
9292void SVMAllocsManager::makeInternalAllocationsResident (CommandStreamReceiver &commandStreamReceiver, uint32_t requestedTypesMask) {
93- std::unique_lock<SpinLock > lock (mtx);
93+ std::shared_lock<std::shared_mutex > lock (mtx);
9494 for (auto &allocation : this ->SVMAllocs .allocations ) {
9595 if (allocation.second .memoryType & requestedTypesMask) {
9696 auto gpuAllocation = allocation.second .gpuAllocations .getGraphicsAllocation (commandStreamReceiver.getRootDeviceIndex ());
@@ -163,7 +163,7 @@ void *SVMAllocsManager::createHostUnifiedMemoryAllocation(size_t size,
163163 allocData.pageSizeForAlignment = pageSizeForAlignment;
164164 allocData.setAllocId (this ->allocationsCounter ++);
165165
166- std::unique_lock<SpinLock > lock (mtx);
166+ std::unique_lock<std::shared_mutex > lock (mtx);
167167 this ->SVMAllocs .insert (allocData);
168168
169169 return usmPtr;
@@ -227,7 +227,7 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size,
227227 allocData.device = memoryProperties.device ;
228228 allocData.setAllocId (this ->allocationsCounter ++);
229229
230- std::unique_lock<SpinLock > lock (mtx);
230+ std::unique_lock<std::shared_mutex > lock (mtx);
231231 this ->SVMAllocs .insert (allocData);
232232 return reinterpret_cast <void *>(unifiedMemoryAllocation->getGpuAddress ());
233233}
@@ -309,7 +309,7 @@ void *SVMAllocsManager::createUnifiedKmdMigratedAllocation(size_t size, const Sv
309309 allocData.pageSizeForAlignment = pageSizeForAlignment;
310310 allocData.setAllocId (this ->allocationsCounter ++);
311311
312- std::unique_lock<SpinLock > lock (mtx);
312+ std::unique_lock<std::shared_mutex > lock (mtx);
313313 this ->SVMAllocs .insert (allocData);
314314 return allocationGpu->getUnderlyingBuffer ();
315315}
@@ -320,17 +320,17 @@ void SVMAllocsManager::setUnifiedAllocationProperties(GraphicsAllocation *alloca
320320}
321321
322322SvmAllocationData *SVMAllocsManager::getSVMAlloc (const void *ptr) {
323- std::unique_lock<SpinLock > lock (mtx);
323+ std::shared_lock<std::shared_mutex > lock (mtx);
324324 return SVMAllocs.get (ptr);
325325}
326326
327327void SVMAllocsManager::insertSVMAlloc (const SvmAllocationData &svmAllocData) {
328- std::unique_lock<SpinLock > lock (mtx);
328+ std::unique_lock<std::shared_mutex > lock (mtx);
329329 SVMAllocs.insert (svmAllocData);
330330}
331331
332332void SVMAllocsManager::removeSVMAlloc (const SvmAllocationData &svmAllocData) {
333- std::unique_lock<SpinLock > lock (mtx);
333+ std::unique_lock<std::shared_mutex > lock (mtx);
334334 SVMAllocs.remove (svmAllocData);
335335}
336336
@@ -355,7 +355,7 @@ bool SVMAllocsManager::freeSVMAlloc(void *ptr, bool blocking) {
355355 if (pageFaultManager) {
356356 pageFaultManager->removeAllocation (ptr);
357357 }
358- std::unique_lock<SpinLock > lock (mtx);
358+ std::unique_lock<std::shared_mutex > lock (mtx);
359359 if (svmData->gpuAllocations .getAllocationType () == AllocationType::SVM_ZERO_COPY) {
360360 freeZeroCopySvmAllocation (svmData);
361361 } else {
@@ -396,7 +396,7 @@ void *SVMAllocsManager::createZeroCopySvmAllocation(size_t size, const SvmAlloca
396396 }
397397 allocData.size = size;
398398
399- std::unique_lock<SpinLock > lock (mtx);
399+ std::unique_lock<std::shared_mutex > lock (mtx);
400400 this ->SVMAllocs .insert (allocData);
401401 return usmPtr;
402402}
@@ -460,7 +460,7 @@ void *SVMAllocsManager::createUnifiedAllocationWithDeviceStorage(size_t size, co
460460 allocData.size = size;
461461 allocData.setAllocId (this ->allocationsCounter ++);
462462
463- std::unique_lock<SpinLock > lock (mtx);
463+ std::unique_lock<std::shared_mutex > lock (mtx);
464464 this ->SVMAllocs .insert (allocData);
465465 return svmPtr;
466466}
@@ -485,7 +485,7 @@ void SVMAllocsManager::freeSvmAllocationWithDeviceStorage(SvmAllocationData *svm
485485}
486486
487487bool SVMAllocsManager::hasHostAllocations () {
488- std::unique_lock<SpinLock > lock (mtx);
488+ std::shared_lock<std::shared_mutex > lock (mtx);
489489 for (auto &allocation : this ->SVMAllocs .allocations ) {
490490 if (allocation.second .memoryType == InternalMemoryType::HOST_UNIFIED_MEMORY) {
491491 return true ;
@@ -495,7 +495,7 @@ bool SVMAllocsManager::hasHostAllocations() {
495495}
496496
497497void SVMAllocsManager::makeIndirectAllocationsResident (CommandStreamReceiver &commandStreamReceiver, uint32_t taskCount) {
498- std::unique_lock<SpinLock > lock (mtx);
498+ std::unique_lock<std::shared_mutex > lock (mtx);
499499 bool parseAllAllocations = false ;
500500 auto entry = indirectAllocationsResidency.find (&commandStreamReceiver);
501501
@@ -527,7 +527,7 @@ void SVMAllocsManager::makeIndirectAllocationsResident(CommandStreamReceiver &co
527527}
528528
529529void SVMAllocsManager::prepareIndirectAllocationForDestruction (SvmAllocationData *allocationData) {
530- std::unique_lock<SpinLock > lock (mtx);
530+ std::unique_lock<std::shared_mutex > lock (mtx);
531531 if (this ->indirectAllocationsResidency .size () > 0u ) {
532532 for (auto &internalAllocationsHandling : this ->indirectAllocationsResidency ) {
533533 auto commandStreamReceiver = internalAllocationsHandling.first ;
@@ -543,7 +543,7 @@ void SVMAllocsManager::prepareIndirectAllocationForDestruction(SvmAllocationData
543543}
544544
545545SvmMapOperation *SVMAllocsManager::getSvmMapOperation (const void *ptr) {
546- std::unique_lock<SpinLock > lock (mtx);
546+ std::shared_lock<std::shared_mutex > lock (mtx);
547547 return svmMapOperations.get (ptr);
548548}
549549
@@ -554,12 +554,12 @@ void SVMAllocsManager::insertSvmMapOperation(void *regionSvmPtr, size_t regionSi
554554 svmMapOperation.offset = offset;
555555 svmMapOperation.regionSize = regionSize;
556556 svmMapOperation.readOnlyMap = readOnlyMap;
557- std::unique_lock<SpinLock > lock (mtx);
557+ std::unique_lock<std::shared_mutex > lock (mtx);
558558 svmMapOperations.insert (svmMapOperation);
559559}
560560
561561void SVMAllocsManager::removeSvmMapOperation (const void *regionSvmPtr) {
562- std::unique_lock<SpinLock > lock (mtx);
562+ std::unique_lock<std::shared_mutex > lock (mtx);
563563 svmMapOperations.remove (regionSvmPtr);
564564}
565565
0 commit comments