From deca36fd32276609b441227793012bfc17542680 Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Wed, 2 Apr 2025 13:11:56 +0000 Subject: [PATCH] fix: Stop ULLS light when evict resource Related-To: NEO-14406 Signed-off-by: Lukasz Jobczyk --- .../linux/drm_direct_submission.inl | 5 ++++- .../os_interface/linux/drm_memory_manager.cpp | 6 ++++++ ...emory_operations_handler_default_tests.cpp | 20 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/shared/source/direct_submission/linux/drm_direct_submission.inl b/shared/source/direct_submission/linux/drm_direct_submission.inl index 2de373671d..06bcf29c3e 100644 --- a/shared/source/direct_submission/linux/drm_direct_submission.inl +++ b/shared/source/direct_submission/linux/drm_direct_submission.inl @@ -98,6 +98,7 @@ inline DrmDirectSubmission::~DrmDirectSubmission() { if (this->ringStart) { this->stopRingBuffer(true); } + this->tagAddress = nullptr; if (this->isCompletionFenceSupported()) { auto osContextLinux = static_cast(&this->osContext); auto &drm = osContextLinux->getDrm(); @@ -120,7 +121,9 @@ TaskCountType *DrmDirectSubmission::getCompletionValuePoi template void DrmDirectSubmission::ensureRingCompletion() { - this->wait(static_cast(this->currentTagData.tagValue)); + if (this->tagAddress) { + this->wait(static_cast(this->currentTagData.tagValue)); + } } template diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index fa9b4c7e52..eedbe79f1f 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -1363,6 +1363,12 @@ void DrmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, } auto rootDeviceIndex = gfxAllocation->getRootDeviceIndex(); for (auto &engine : getRegisteredEngines(rootDeviceIndex)) { + std::unique_lock lock; + if (engine.osContext->isDirectSubmissionLightActive()) { + lock = engine.commandStreamReceiver->obtainUniqueOwnership(); + engine.commandStreamReceiver->stopDirectSubmission(true, false); + } + auto memoryOperationsInterface = static_cast(executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface.get()); memoryOperationsInterface->evictWithinOsContext(engine.osContext, *gfxAllocation); } diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp index 8e6f5aa9f3..f86c2aef21 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_operations_handler_default_tests.cpp @@ -7,14 +7,19 @@ #include "shared/source/os_interface/linux/drm_memory_operations_handler_default.h" #include "shared/test/common/libult/linux/drm_query_mock.h" +#include "shared/test/common/libult/ult_command_stream_receiver.h" #include "shared/test/common/mocks/linux/mock_drm_allocation.h" #include "shared/test/common/mocks/linux/mock_drm_memory_manager.h" +#include "shared/test/common/mocks/mock_allocation_properties.h" #include "shared/test/common/mocks/mock_command_stream_receiver.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" +#include "shared/test/common/test_macros/hw_test.h" #include "shared/test/common/test_macros/test.h" +#include "gtest/gtest.h" + #include using namespace NEO; @@ -267,4 +272,19 @@ TEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenOperationsHandlerW pMemManager->emitPinningRequestForBoContainerResult = SubmissionStatus::outOfMemory; auto ret = drmMemoryOperationsHandler->flushDummyExec(device.get(), ArrayRef(&allocationPtr, 1)); EXPECT_EQ(ret, MemoryOperationsStatus::outOfMemory); +} + +HWTEST_F(DrmMemoryOperationsHandlerBaseTestFlushDummyExec, givenDirectSubmissionLightWhenFreeGraphicsMemoryThenStopDirectSubmission) { + drmMemoryOperationsHandler->makeResidentWithinOsContextCallBase = true; + drmMemoryOperationsHandler->evictWithinOsContextCallBase = true; + auto allocation = pMemManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{0u, MemoryConstants::pageSize}); + EXPECT_EQ(drmMemoryOperationsHandler->makeResident(nullptr, ArrayRef(&allocation, 1), false, false), MemoryOperationsStatus::success); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); + EXPECT_TRUE(std::find(drmMemoryOperationsHandler->residency.begin(), drmMemoryOperationsHandler->residency.end(), allocation) != drmMemoryOperationsHandler->residency.end()); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(nullptr, *allocation), MemoryOperationsStatus::success); + pMemManager->getRegisteredEngines(0u)[0].osContext->setDirectSubmissionActive(); + + pMemManager->freeGraphicsMemoryImpl(allocation); + + EXPECT_TRUE(static_cast *>(pMemManager->getRegisteredEngines(0u)[0].commandStreamReceiver)->stopDirectSubmissionCalled); } \ No newline at end of file