Avoid deadlock when evicting unused allocations

Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
Jaime Arteaga
2021-10-06 00:37:16 +00:00
committed by Compute-Runtime-Automation
parent 48f01f28f5
commit dc9bcb99c9
6 changed files with 12 additions and 8 deletions

View File

@@ -151,12 +151,12 @@ int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bo
int ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
if (ret != 0) {
static_cast<DrmMemoryOperationsHandler *>(this->drm->getRootDeviceEnvironment().memoryOperationsInterface.get())->evictUnusedAllocations(false);
static_cast<DrmMemoryOperationsHandler *>(this->drm->getRootDeviceEnvironment().memoryOperationsInterface.get())->evictUnusedAllocations(false, true);
ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
}
if (ret != 0) {
static_cast<DrmMemoryOperationsHandler *>(this->drm->getRootDeviceEnvironment().memoryOperationsInterface.get())->evictUnusedAllocations(true);
static_cast<DrmMemoryOperationsHandler *>(this->drm->getRootDeviceEnvironment().memoryOperationsInterface.get())->evictUnusedAllocations(true, true);
ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
}

View File

@@ -23,7 +23,7 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler {
virtual void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) = 0;
virtual std::unique_lock<std::mutex> lockHandlerIfUsed() = 0;
virtual void evictUnusedAllocations(bool waitForCompletion) = 0;
virtual void evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) = 0;
static std::unique_ptr<DrmMemoryOperationsHandler> create(Drm &drm, uint32_t rootDeviceIndex);

View File

@@ -110,10 +110,14 @@ std::unique_lock<std::mutex> DrmMemoryOperationsHandlerBind::lockHandlerIfUsed()
return std::unique_lock<std::mutex>();
}
void DrmMemoryOperationsHandlerBind::evictUnusedAllocations(bool waitForCompletion) {
void DrmMemoryOperationsHandlerBind::evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) {
auto memoryManager = static_cast<DrmMemoryManager *>(this->rootDeviceEnvironment.executionEnvironment.memoryManager.get());
std::lock_guard<std::mutex> lock(mutex);
std::unique_lock<std::mutex> evictLock(mutex, std::defer_lock);
if (isLockNeeded) {
evictLock.lock();
}
auto allocLock = memoryManager->acquireAllocLock();
this->evictUnusedAllocationsImpl(memoryManager->getSysMemAllocs(), waitForCompletion);

View File

@@ -25,7 +25,7 @@ class DrmMemoryOperationsHandlerBind : public DrmMemoryOperationsHandler {
void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override;
std::unique_lock<std::mutex> lockHandlerIfUsed() override;
void evictUnusedAllocations(bool waitForCompletion) override;
void evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) override;
protected:
void evictImpl(OsContext *osContext, GraphicsAllocation &gfxAllocation, DeviceBitfield deviceBitfield);

View File

@@ -64,7 +64,7 @@ std::unique_lock<std::mutex> DrmMemoryOperationsHandlerDefault::lockHandlerIfUse
return std::unique_lock<std::mutex>();
}
void DrmMemoryOperationsHandlerDefault::evictUnusedAllocations(bool waitForCompletion) {
void DrmMemoryOperationsHandlerDefault::evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) {
}
} // namespace NEO

View File

@@ -26,7 +26,7 @@ class DrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandler {
void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override;
std::unique_lock<std::mutex> lockHandlerIfUsed() override;
void evictUnusedAllocations(bool waitForCompletion) override;
void evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) override;
protected:
std::unordered_set<GraphicsAllocation *> residency;