From f124d8128b4fb8a0d9eaba9e9358eab523b0d5fc Mon Sep 17 00:00:00 2001 From: "Zdunowski, Piotr" Date: Wed, 25 Sep 2019 14:09:32 +0200 Subject: [PATCH] Fix deadlock in allocation list cleanup. Resolves: NEO-3582 Change-Id: Ia871adc38a9737dc57c187557573b02cc321b3e5 Signed-off-by: Zdunowski, Piotr --- runtime/memory_manager/allocations_list.h | 3 --- runtime/memory_manager/host_ptr_manager.cpp | 4 ++++ runtime/memory_manager/host_ptr_manager.h | 1 + runtime/memory_manager/internal_allocation_storage.cpp | 8 +++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/memory_manager/allocations_list.h b/runtime/memory_manager/allocations_list.h index afd1eb3c77..95d369e35a 100644 --- a/runtime/memory_manager/allocations_list.h +++ b/runtime/memory_manager/allocations_list.h @@ -17,10 +17,7 @@ class AllocationsList : public IDList { public: std::unique_ptr detachAllocation(size_t requiredMinimalSize, CommandStreamReceiver &commandStreamReceiver, GraphicsAllocation::AllocationType allocationType); - std::unique_lock obtainUniqueOwnership(); - private: GraphicsAllocation *detachAllocationImpl(GraphicsAllocation *, void *); - std::mutex mutex; }; } // namespace NEO diff --git a/runtime/memory_manager/host_ptr_manager.cpp b/runtime/memory_manager/host_ptr_manager.cpp index b87ff152f7..512becca75 100644 --- a/runtime/memory_manager/host_ptr_manager.cpp +++ b/runtime/memory_manager/host_ptr_manager.cpp @@ -142,6 +142,10 @@ void HostPtrManager::storeFragment(AllocationStorageData &storageData) { storeFragment(fragment); } +std::unique_lock HostPtrManager::obtainOwnership() { + return std::unique_lock(allocationsMutex); +} + void HostPtrManager::releaseHandleStorage(OsHandleStorage &fragments) { for (int i = 0; i < maxFragmentsCount; i++) { if (fragments.fragmentStorageData[i].fragmentSize || fragments.fragmentStorageData[i].cpuPtr) { diff --git a/runtime/memory_manager/host_ptr_manager.h b/runtime/memory_manager/host_ptr_manager.h index f4dd107e08..204a7af759 100644 --- a/runtime/memory_manager/host_ptr_manager.h +++ b/runtime/memory_manager/host_ptr_manager.h @@ -23,6 +23,7 @@ class HostPtrManager { bool releaseHostPtr(const void *ptr); void storeFragment(AllocationStorageData &storageData); void storeFragment(FragmentStorage &fragment); + std::unique_lock obtainOwnership(); protected: static AllocationRequirements getAllocationRequirements(const void *inputPtr, size_t size); diff --git a/runtime/memory_manager/internal_allocation_storage.cpp b/runtime/memory_manager/internal_allocation_storage.cpp index eebb45c9d2..1d8ace9d75 100644 --- a/runtime/memory_manager/internal_allocation_storage.cpp +++ b/runtime/memory_manager/internal_allocation_storage.cpp @@ -8,6 +8,7 @@ #include "runtime/memory_manager/internal_allocation_storage.h" #include "runtime/command_stream/command_stream_receiver.h" +#include "runtime/memory_manager/host_ptr_manager.h" #include "runtime/memory_manager/memory_manager.h" #include "runtime/os_interface/os_context.h" @@ -39,8 +40,9 @@ void InternalAllocationStorage::cleanAllocationList(uint32_t waitTaskCount, uint } void InternalAllocationStorage::freeAllocationsList(uint32_t waitTaskCount, AllocationsList &allocationsList) { - auto lock = allocationsList.obtainUniqueOwnership(); auto memoryManager = commandStreamReceiver.getMemoryManager(); + auto lock = memoryManager->getHostPtrManager()->obtainOwnership(); + GraphicsAllocation *curr = allocationsList.detachNodes(); IDList allocationsLeft; @@ -97,8 +99,4 @@ GraphicsAllocation *AllocationsList::detachAllocationImpl(GraphicsAllocation *, return nullptr; } -std::unique_lock AllocationsList::obtainUniqueOwnership() { - return std::unique_lock(mutex); -} - } // namespace NEO