Skip to content

Commit dc9bcb9

Browse files
Jaime ArteagaCompute-Runtime-Automation
authored andcommitted
Avoid deadlock when evicting unused allocations
Signed-off-by: Jaime Arteaga <[email protected]>
1 parent 48f01f2 commit dc9bcb9

6 files changed

+12
-8
lines changed

shared/source/os_interface/linux/drm_buffer_object.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bo
151151
int ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
152152

153153
if (ret != 0) {
154-
static_cast<DrmMemoryOperationsHandler *>(this->drm->getRootDeviceEnvironment().memoryOperationsInterface.get())->evictUnusedAllocations(false);
154+
static_cast<DrmMemoryOperationsHandler *>(this->drm->getRootDeviceEnvironment().memoryOperationsInterface.get())->evictUnusedAllocations(false, true);
155155
ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
156156
}
157157

158158
if (ret != 0) {
159-
static_cast<DrmMemoryOperationsHandler *>(this->drm->getRootDeviceEnvironment().memoryOperationsInterface.get())->evictUnusedAllocations(true);
159+
static_cast<DrmMemoryOperationsHandler *>(this->drm->getRootDeviceEnvironment().memoryOperationsInterface.get())->evictUnusedAllocations(true, true);
160160
ret = this->drm->ioctl(DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
161161
}
162162

shared/source/os_interface/linux/drm_memory_operations_handler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler {
2323
virtual void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) = 0;
2424
virtual std::unique_lock<std::mutex> lockHandlerIfUsed() = 0;
2525

26-
virtual void evictUnusedAllocations(bool waitForCompletion) = 0;
26+
virtual void evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) = 0;
2727

2828
static std::unique_ptr<DrmMemoryOperationsHandler> create(Drm &drm, uint32_t rootDeviceIndex);
2929

shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,14 @@ std::unique_lock<std::mutex> DrmMemoryOperationsHandlerBind::lockHandlerIfUsed()
110110
return std::unique_lock<std::mutex>();
111111
}
112112

113-
void DrmMemoryOperationsHandlerBind::evictUnusedAllocations(bool waitForCompletion) {
113+
void DrmMemoryOperationsHandlerBind::evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) {
114114
auto memoryManager = static_cast<DrmMemoryManager *>(this->rootDeviceEnvironment.executionEnvironment.memoryManager.get());
115115

116-
std::lock_guard<std::mutex> lock(mutex);
116+
std::unique_lock<std::mutex> evictLock(mutex, std::defer_lock);
117+
if (isLockNeeded) {
118+
evictLock.lock();
119+
}
120+
117121
auto allocLock = memoryManager->acquireAllocLock();
118122

119123
this->evictUnusedAllocationsImpl(memoryManager->getSysMemAllocs(), waitForCompletion);

shared/source/os_interface/linux/drm_memory_operations_handler_bind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DrmMemoryOperationsHandlerBind : public DrmMemoryOperationsHandler {
2525
void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override;
2626
std::unique_lock<std::mutex> lockHandlerIfUsed() override;
2727

28-
void evictUnusedAllocations(bool waitForCompletion) override;
28+
void evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) override;
2929

3030
protected:
3131
void evictImpl(OsContext *osContext, GraphicsAllocation &gfxAllocation, DeviceBitfield deviceBitfield);

shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ std::unique_lock<std::mutex> DrmMemoryOperationsHandlerDefault::lockHandlerIfUse
6464
return std::unique_lock<std::mutex>();
6565
}
6666

67-
void DrmMemoryOperationsHandlerDefault::evictUnusedAllocations(bool waitForCompletion) {
67+
void DrmMemoryOperationsHandlerDefault::evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) {
6868
}
6969

7070
} // namespace NEO

shared/source/os_interface/linux/drm_memory_operations_handler_default.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandler {
2626
void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override;
2727
std::unique_lock<std::mutex> lockHandlerIfUsed() override;
2828

29-
void evictUnusedAllocations(bool waitForCompletion) override;
29+
void evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) override;
3030

3131
protected:
3232
std::unordered_set<GraphicsAllocation *> residency;

0 commit comments

Comments
 (0)