fix: Avoid mutex deadlock when switch ulls light ring buffer

Related-To: NEO-14406

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2025-03-19 10:14:24 +00:00
committed by Compute-Runtime-Automation
parent dda7876d3a
commit 6cb52f71b4
17 changed files with 61 additions and 54 deletions

View File

@@ -36,9 +36,9 @@ struct MockAubMemoryOperationsHandler : public AubMemoryOperationsHandler {
return AubMemoryOperationsHandler::isResident(device, gfxAllocation);
}
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence) override {
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence, const bool acquireLock) override {
makeResidentWithinOsContextCalled = true;
return AubMemoryOperationsHandler::makeResidentWithinOsContext(osContext, gfxAllocations, evictable, forcePagingFence);
return AubMemoryOperationsHandler::makeResidentWithinOsContext(osContext, gfxAllocations, evictable, forcePagingFence, acquireLock);
}
MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override {

View File

@@ -24,7 +24,7 @@ class MockMemoryOperationsHandler : public MemoryOperationsHandler {
MemoryOperationsStatus lock(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) override { return MemoryOperationsStatus::unsupported; }
MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override { return MemoryOperationsStatus::unsupported; }
MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override { return MemoryOperationsStatus::unsupported; }
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence) override { return MemoryOperationsStatus::unsupported; }
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence, const bool acquireLock) override { return MemoryOperationsStatus::unsupported; }
MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override { return MemoryOperationsStatus::unsupported; }
};
@@ -35,7 +35,7 @@ class MockMemoryOperationsHandlerTests : public MemoryOperationsHandler {
ADDMETHOD_NOBASE(lock, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, ArrayRef<GraphicsAllocation *> gfxAllocations));
ADDMETHOD_NOBASE(evict, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, GraphicsAllocation &gfxAllocation));
ADDMETHOD_NOBASE(isResident, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (Device * device, GraphicsAllocation &gfxAllocation));
ADDMETHOD_NOBASE(makeResidentWithinOsContext, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (OsContext * osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence));
ADDMETHOD_NOBASE(makeResidentWithinOsContext, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (OsContext * osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence, const bool acquireLock));
ADDMETHOD_NOBASE(evictWithinOsContext, MemoryOperationsStatus, MemoryOperationsStatus::unsupported, (OsContext * osContext, GraphicsAllocation &gfxAllocation));
};
@@ -85,7 +85,7 @@ class MockMemoryOperations : public MemoryOperationsHandler {
return MemoryOperationsStatus::success;
}
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence) override {
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence, const bool acquireLock) override {
makeResidentCalledCount++;
if (osContext) {
makeResidentContextId = osContext->getContextId();

View File

@@ -1428,7 +1428,7 @@ struct MockMergeResidencyContainerMemoryOperationsHandler : public DrmMemoryOper
(OsContext * osContext, ResidencyContainer &residencyContainer));
ADDMETHOD_NOBASE(makeResidentWithinOsContext, NEO::MemoryOperationsStatus, NEO::MemoryOperationsStatus::success,
(OsContext * osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence));
(OsContext * osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence, const bool acquireLock));
};
HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenMergeWithResidencyContainerFailsThenFlushReturnsError) {

View File

@@ -309,17 +309,17 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenObjectAlwaysResidentAndNotUsedWh
for (auto &engine : device->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 10;
allocation->updateTaskCount(GraphicsAllocation::objectNotUsed, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
for (auto &engine : device->getSubDevice(0u)->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 10;
allocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
for (auto &engine : device->getSubDevice(1u)->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 10;
allocation->updateTaskCount(GraphicsAllocation::objectNotUsed, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
EXPECT_EQ(mock->context.vmBindCalled, 2u);
@@ -375,17 +375,17 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, whenEvictUnusedResourcesWithWaitFor
for (auto &engine : device->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 10;
allocation->updateTaskCount(8u, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
for (auto &engine : device->getSubDevice(0u)->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 10;
allocation->updateTaskCount(8u, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
for (auto &engine : device->getSubDevice(1u)->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 10;
allocation->updateTaskCount(8u, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
*device->getSubDevice(1u)->getDefaultEngine().commandStreamReceiver->getTagAddress() = 5;
@@ -420,17 +420,17 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, whenRunningOutOfMemoryThenUnusedAlloc
for (auto &engine : device->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 10;
allocation->updateTaskCount(8u, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
for (auto &engine : device->getSubDevice(0u)->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 10;
allocation->updateTaskCount(8u, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
for (auto &engine : device->getSubDevice(1u)->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 10;
allocation->updateTaskCount(8u, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
*device->getSubDevice(1u)->getDefaultEngine().commandStreamReceiver->getTagAddress() = 5;
@@ -450,17 +450,17 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenUsedAllocationInBothSubdevicesWh
for (auto &engine : device->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 5;
allocation->updateTaskCount(8u, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
for (auto &engine : device->getSubDevice(0u)->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 5;
allocation->updateTaskCount(8u, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
for (auto &engine : device->getSubDevice(1u)->getAllEngines()) {
*engine.commandStreamReceiver->getTagAddress() = 5;
allocation->updateTaskCount(8u, engine.osContext->getContextId());
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(engine.osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
}
EXPECT_EQ(mock->context.vmBindCalled, 2u);
@@ -478,7 +478,7 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenResidencyWithinOsContextFailsThe
MockDrmMemoryOperationsHandlerBindResidencyFail(RootDeviceEnvironment &rootDeviceEnvironment, uint32_t rootDeviceIndex)
: DrmMemoryOperationsHandlerBind(rootDeviceEnvironment, rootDeviceIndex) {}
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence) override {
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence, const bool acquireLock) override {
return NEO::MemoryOperationsStatus::failed;
}
};
@@ -552,7 +552,7 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenMakeBOsResidentFailsThenMakeResi
auto allocation = new MockDrmAllocationBOsResident(0, AllocationType::unknown, bos, nullptr, 0u, size, MemoryPool::localMemory);
auto graphicsAllocation = static_cast<GraphicsAllocation *>(allocation);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&graphicsAllocation, 1), false, false), MemoryOperationsStatus::outOfMemory);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&graphicsAllocation, 1), false, false, true), MemoryOperationsStatus::outOfMemory);
delete allocation;
}
@@ -581,19 +581,19 @@ TEST_F(DrmMemoryOperationsHandlerBindTest,
allocation->storageInfo.subDeviceBitfield = 0b0011;
auto graphicsAllocation = static_cast<GraphicsAllocation *>(allocation);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&graphicsAllocation, 1), false, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&graphicsAllocation, 1), false, false, true), MemoryOperationsStatus::success);
delete allocation;
}
TEST_F(DrmMemoryOperationsHandlerBindTest, givenDrmMemoryOperationBindWhenMakeResidentWithinOsContextEvictableAllocationThenAllocationIsNotMarkedAsAlwaysResident) {
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize});
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), false, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), false, false, true), MemoryOperationsStatus::success);
EXPECT_TRUE(allocation->isAlwaysResident(device->getDefaultEngine().osContext->getContextId()));
EXPECT_EQ(operationHandler->evict(device, *allocation), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
EXPECT_FALSE(allocation->isAlwaysResident(device->getDefaultEngine().osContext->getContextId()));
memoryManager->freeGraphicsMemory(allocation);
@@ -603,12 +603,12 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenDrmMemoryOperationBindWhenMakeRe
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize});
allocation->storageInfo.isChunked = true;
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), false, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), false, false, true), MemoryOperationsStatus::success);
EXPECT_TRUE(allocation->isAlwaysResident(device->getDefaultEngine().osContext->getContextId()));
EXPECT_EQ(operationHandler->evict(device, *allocation), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
EXPECT_FALSE(allocation->isAlwaysResident(device->getDefaultEngine().osContext->getContextId()));
memoryManager->freeGraphicsMemory(allocation);
@@ -619,12 +619,12 @@ TEST_F(DrmMemoryOperationsHandlerBindTest, givenDrmMemoryOperationBindWhenMakeRe
allocation->storageInfo.isChunked = true;
allocation->storageInfo.memoryBanks = 0x5;
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), false, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), false, false, true), MemoryOperationsStatus::success);
EXPECT_TRUE(allocation->isAlwaysResident(device->getDefaultEngine().osContext->getContextId()));
EXPECT_EQ(operationHandler->evict(device, *allocation), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false), MemoryOperationsStatus::success);
EXPECT_EQ(operationHandler->makeResidentWithinOsContext(device->getDefaultEngine().osContext, ArrayRef<GraphicsAllocation *>(&allocation, 1), true, false, true), MemoryOperationsStatus::success);
EXPECT_FALSE(allocation->isAlwaysResident(device->getDefaultEngine().osContext->getContextId()));
memoryManager->freeGraphicsMemory(allocation);

View File

@@ -23,7 +23,7 @@ struct MockDrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandler
using BaseClass = DrmMemoryOperationsHandlerDefault;
using DrmMemoryOperationsHandlerDefault::DrmMemoryOperationsHandlerDefault;
using DrmMemoryOperationsHandlerDefault::residency;
ADDMETHOD(makeResidentWithinOsContext, MemoryOperationsStatus, true, MemoryOperationsStatus::success, (OsContext * osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence), (osContext, gfxAllocations, evictable, forcePagingFence));
ADDMETHOD(makeResidentWithinOsContext, MemoryOperationsStatus, true, MemoryOperationsStatus::success, (OsContext * osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable, const bool forcePagingFence, const bool acquireLock), (osContext, gfxAllocations, evictable, forcePagingFence, acquireLock));
ADDMETHOD(flushDummyExec, MemoryOperationsStatus, true, MemoryOperationsStatus::success, (Device * device, ArrayRef<GraphicsAllocation *> gfxAllocations), (device, gfxAllocations));
ADDMETHOD(evictWithinOsContext, MemoryOperationsStatus, true, MemoryOperationsStatus::success, (OsContext * osContext, GraphicsAllocation &gfxAllocation), (osContext, gfxAllocation));
};