Skip to content

Commit 8d5c624

Browse files
fix: If dummy exec failed call evict from outside the lock
Related-To: NEO-12849, HSD-18040201135 Signed-off-by: Maciej Plewka <maciej.plewka@intel.com> Source: e73e865
1 parent cc57044 commit 8d5c624

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

shared/source/os_interface/linux/drm_memory_operations_handler_default.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::makeResident(Device *d
3535
if (!isDummyExecNeeded || ret != MemoryOperationsStatus::success) {
3636
return ret;
3737
}
38-
return flushDummyExec(device, gfxAllocations);
38+
ret = flushDummyExec(device, gfxAllocations);
39+
if (ret != MemoryOperationsStatus::success) {
40+
for (auto &alloc : gfxAllocations) {
41+
evictWithinOsContext(osContext, *alloc);
42+
}
43+
}
44+
return ret;
3945
}
4046

4147
MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::lock(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) {
@@ -104,7 +110,6 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::evictUnusedAllocations
104110

105111
MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::flushDummyExec(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) {
106112
std::lock_guard<std::mutex> lock(mutex);
107-
OsContext *osContext = nullptr;
108113
auto memoryManager = reinterpret_cast<DrmMemoryManager *>(device->getMemoryManager());
109114

110115
std::vector<BufferObject *> boArray;
@@ -120,9 +125,6 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerDefault::flushDummyExec(Device
120125

121126
auto submissionStatus = memoryManager->emitPinningRequestForBoContainer(boArray.data(), boCount, rootDeviceIndex);
122127
if (submissionStatus != SubmissionStatus::success) {
123-
for (auto &alloc : gfxAllocations) {
124-
evictWithinOsContext(osContext, *alloc);
125-
}
126128
return MemoryOperationsStatus::outOfMemory;
127129
}
128130
return MemoryOperationsStatus::success;

shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,27 @@ TEST_F(DrmMemoryOperationsHandlerBaseTest, givenOperationsHandlerWhenCallingMake
195195
drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1), true);
196196
EXPECT_EQ(drmMemoryOperationsHandler->flushDummyExecCalled, 1u);
197197
}
198+
199+
TEST_F(DrmMemoryOperationsHandlerBaseTest, givenOperationsHandlerWhenFlushReturnedOOMThenEvictCalled) {
200+
drmMemoryOperationsHandler->flushDummyExecCallBase = false;
201+
drmMemoryOperationsHandler->flushDummyExecResult = MemoryOperationsStatus::outOfMemory;
202+
drmMemoryOperationsHandler->makeResidentWithinOsContextCallBase = false;
203+
204+
initializeAllocation(1);
205+
drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1), true);
206+
EXPECT_EQ(drmMemoryOperationsHandler->evictWithinOsContextCalled, 1u);
207+
}
208+
209+
TEST_F(DrmMemoryOperationsHandlerBaseTest, givenOperationsHandlerWhenFlushReturnedSuccessThenEvictNotcalled) {
210+
drmMemoryOperationsHandler->flushDummyExecCallBase = false;
211+
drmMemoryOperationsHandler->flushDummyExecResult = MemoryOperationsStatus::success;
212+
drmMemoryOperationsHandler->makeResidentWithinOsContextCallBase = false;
213+
214+
initializeAllocation(1);
215+
drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1), true);
216+
EXPECT_EQ(drmMemoryOperationsHandler->evictWithinOsContextCalled, 0u);
217+
}
218+
198219
struct DrmMemoryOperationsHandlerBaseTestFlushDummyExec : public DrmMemoryOperationsHandlerBaseTest {
199220
using BaseClass = DrmMemoryOperationsHandlerBaseTest;
200221
void SetUp() override {
@@ -236,19 +257,14 @@ TEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenOperationsHandlerW
236257
EXPECT_EQ(ret, MemoryOperationsStatus::outOfMemory);
237258
}
238259

239-
TEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenOperationsHandlerWhenEmitPiningRequestReturnFailThenEvictWithinOsContextCalled) {
240-
pMemManager->emitPinningRequestForBoContainerResult = SubmissionStatus::outOfMemory;
241-
drmMemoryOperationsHandler->flushDummyExec(device.get(), ArrayRef<GraphicsAllocation *>(&allocationPtr, 1));
242-
EXPECT_EQ(drmMemoryOperationsHandler->evictWithinOsContextCalled, 1u);
243-
}
244-
245260
TEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenOperationsHandlerWhenEmitPiningRequestReturnSuccessThenSuccessReturned) {
246261
pMemManager->emitPinningRequestForBoContainerResult = SubmissionStatus::success;
247262
auto ret = drmMemoryOperationsHandler->flushDummyExec(device.get(), ArrayRef<GraphicsAllocation *>(&allocationPtr, 1));
248263
EXPECT_EQ(ret, MemoryOperationsStatus::success);
249264
}
250-
TEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenOperationsHandlerWhenEmitPiningRequestReturnSuccessThenEvictWithinOsContextNotCalled) {
251-
pMemManager->emitPinningRequestForBoContainerResult = SubmissionStatus::success;
252-
drmMemoryOperationsHandler->flushDummyExec(device.get(), ArrayRef<GraphicsAllocation *>(&allocationPtr, 1));
253-
EXPECT_EQ(drmMemoryOperationsHandler->evictWithinOsContextCalled, 0u);
265+
266+
TEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenOperationsHandlerWhenEmitPiningRequestReturnOOMThenOOMReturned) {
267+
pMemManager->emitPinningRequestForBoContainerResult = SubmissionStatus::outOfMemory;
268+
auto ret = drmMemoryOperationsHandler->flushDummyExec(device.get(), ArrayRef<GraphicsAllocation *>(&allocationPtr, 1));
269+
EXPECT_EQ(ret, MemoryOperationsStatus::outOfMemory);
254270
}

0 commit comments

Comments
 (0)