From ae7e9b3c394166212d1806709cb618580c903fac Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Fri, 8 May 2020 10:04:06 +0200 Subject: [PATCH] Add implementation of memory operation handler on Linux Related-To: NEO-4302 Change-Id: Ic2b0eb9dde67d0c672914764592c8326f5bdd9c1 Signed-off-by: Lukasz Jobczyk --- .../os_interface/linux/drm_command_stream.inl | 4 ++ .../linux/drm_memory_manager_mt_tests.cpp | 3 ++ .../linux/drm_command_stream_fixture.h | 3 ++ .../linux/drm_command_stream_tests.cpp | 39 +++++++++++++++++++ ..._manager_allocate_in_device_pool_tests.cpp | 4 ++ .../linux/drm_memory_manager_tests.cpp | 2 + .../linux/drm_memory_manager_tests.h | 2 + .../linux/drm_residency_handler_tests.cpp | 34 ++++++++++++---- ...te_command_queue_with_properties_tests.cpp | 2 + .../os_interface/linux/drm_memory_manager.cpp | 3 ++ .../linux/drm_memory_operations_handler.cpp | 31 ++++++++++++--- .../linux/drm_memory_operations_handler.h | 13 ++++++- 12 files changed, 126 insertions(+), 14 deletions(-) diff --git a/opencl/source/os_interface/linux/drm_command_stream.inl b/opencl/source/os_interface/linux/drm_command_stream.inl index dcd376994b..b30744b5bb 100644 --- a/opencl/source/os_interface/linux/drm_command_stream.inl +++ b/opencl/source/os_interface/linux/drm_command_stream.inl @@ -17,6 +17,7 @@ #include "shared/source/os_interface/linux/drm_buffer_object.h" #include "shared/source/os_interface/linux/drm_engine_mapper.h" #include "shared/source/os_interface/linux/drm_memory_manager.h" +#include "shared/source/os_interface/linux/drm_memory_operations_handler.h" #include "shared/source/os_interface/linux/drm_neo.h" #include "shared/source/os_interface/linux/os_context_linux.h" #include "shared/source/os_interface/linux/os_interface.h" @@ -54,6 +55,9 @@ bool DrmCommandStreamReceiver::flush(BatchBuffer &batchBuffer, Reside } } + auto memoryOperationsInterface = this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get(); + static_cast(memoryOperationsInterface)->mergeWithResidencyContainer(allocationsForResidency); + this->flushStamp->setStamp(bb->peekHandle()); this->flushInternal(batchBuffer, allocationsForResidency); diff --git a/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp b/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp index aa1481967c..1106a97ebf 100644 --- a/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp +++ b/opencl/test/unit_test/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp @@ -7,6 +7,7 @@ #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/os_interface/linux/drm_memory_manager.h" +#include "shared/source/os_interface/linux/drm_memory_operations_handler.h" #include "shared/source/os_interface/linux/os_interface.h" #include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h" @@ -36,6 +37,7 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro }; MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); auto mock = new MockDrm(0, *executionEnvironment.rootDeviceEnvironments[0]); executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock); auto memoryManager = std::make_unique(executionEnvironment); @@ -101,6 +103,7 @@ TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThen MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); auto mock = new MockDrm(0, *executionEnvironment.rootDeviceEnvironments[0]); executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock); auto memoryManager = std::make_unique(executionEnvironment); diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h b/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h index 993eaa4dcc..32baf5d54b 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h @@ -7,6 +7,7 @@ #pragma once #include "shared/source/command_stream/preemption.h" +#include "shared/source/os_interface/linux/drm_memory_operations_handler.h" #include "shared/source/os_interface/linux/os_context_linux.h" #include "shared/source/os_interface/linux/os_interface.h" #include "shared/test/unit_test/helpers/debug_manager_state_restore.h" @@ -34,6 +35,7 @@ class DrmCommandStreamTest : public ::testing::Test { executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(mock); + executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); auto hwInfo = executionEnvironment.rootDeviceEnvironments[0]->getHardwareInfo(); osContext = std::make_unique(*mock, 0u, 1, HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0], @@ -102,6 +104,7 @@ class DrmCommandStreamEnhancedTest : public ::testing::Test { mock = new DrmMockCustom(); executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique(); executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->setDrm(mock); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique(); csr = new TestedDrmCommandStreamReceiver(*executionEnvironment, rootDeviceIndex); ASSERT_NE(nullptr, csr); diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp index ab261164af..a171e14be6 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp @@ -592,6 +592,45 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenGemCloseWorkerInactiveMode mm->freeGraphicsMemory(dummyAllocation); } +HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocInMemoryOperationsInterfaceWhenFlushThenAllocIsResident) { + auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); + LinearStream cs(commandBuffer); + CommandStreamReceiverHw::addBatchBufferEnd(cs, nullptr); + CommandStreamReceiverHw::alignToCacheLine(cs); + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr}; + + auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); + executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(ArrayRef(&allocation, 1)); + + csr->flush(batchBuffer, csr->getResidencyAllocations()); + + const auto boRequirments = [&allocation](const auto &bo) { + return (static_cast(bo.handle) == static_cast(allocation)->getBO()->peekHandle() && + bo.offset == static_cast(allocation)->getBO()->peekAddress()); + }; + + auto &residency = static_cast *>(csr)->getExecStorage(); + EXPECT_TRUE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end()); + EXPECT_EQ(residency.size(), 2u); + residency.clear(); + + csr->flush(batchBuffer, csr->getResidencyAllocations()); + EXPECT_TRUE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end()); + EXPECT_EQ(residency.size(), 2u); + residency.clear(); + + csr->getResidencyAllocations().clear(); + executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->evict(*allocation); + + csr->flush(batchBuffer, csr->getResidencyAllocations()); + + EXPECT_FALSE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end()); + EXPECT_EQ(residency.size(), 1u); + + mm->freeGraphicsMemory(allocation); + mm->freeGraphicsMemory(commandBuffer); +} + HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, GivenTwoAllocationsWhenBackingStorageIsDifferentThenMakeResidentShouldAddTwoLocations) { auto allocation = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize})); auto allocation2 = static_cast(mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize})); diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp index 2a9203dc43..b746a1808f 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests.cpp @@ -7,6 +7,7 @@ #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/os_interface/linux/drm_memory_manager.h" +#include "shared/source/os_interface/linux/drm_memory_operations_handler.h" #include "shared/source/os_interface/linux/os_interface.h" #include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h" @@ -23,6 +24,7 @@ using AllocationData = TestedDrmMemoryManager::AllocationData; TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIsCalledThenNullptrAndStatusRetryIsReturned) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0])); TestedDrmMemoryManager memoryManager(executionEnvironment); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; @@ -39,6 +41,7 @@ TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIs TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenLockResourceIsCalledOnNullBufferObjectThenReturnNullPtr) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); TestedDrmMemoryManager memoryManager(executionEnvironment); DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); @@ -51,6 +54,7 @@ TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenLockResourceIsCalledOn TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenFreeGraphicsMemoryIsCalledOnAllocationWithNullBufferObjectThenEarlyReturn) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); TestedDrmMemoryManager memoryManager(executionEnvironment); auto drmAllocation = new DrmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index 932af127fe..8de165eca3 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -3474,6 +3474,7 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryCallSequenceTest, givenDrmMemoryManagerAn MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->setDrm(Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0])); + executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique(); GMockDrmMemoryManager gmockDrmMemoryManager(executionEnvironment); AllocationProperties properties{0, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}; @@ -3493,6 +3494,7 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryCallSequenceTest, givenDrmMemoryManagerAn TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, givenDrmMemoryManagerAndFreeGraphicsMemoryIsCalledForSharedAllocationThenUnreferenceBufferObjectIsCalledWithSynchronousDestroySetToFalse) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); const uint32_t rootDeviceIndex = 0u; + executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface = std::make_unique(); executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->setDrm(Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex])); ::testing::NiceMock gmockDrmMemoryManager(executionEnvironment); diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h index 3e44159617..98b1cc6ebf 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h @@ -61,6 +61,7 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { auto rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[i].get(); rootDeviceEnvironment->osInterface = std::make_unique(); rootDeviceEnvironment->osInterface->get()->setDrm(new DrmMockCustom()); + rootDeviceEnvironment->memoryOperationsInterface = std::make_unique(); } rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex].get(); @@ -133,6 +134,7 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation { rootDeviceEnvironment->setHwInfo(defaultHwInfo.get()); rootDeviceEnvironment->osInterface = std::make_unique(); rootDeviceEnvironment->osInterface->get()->setDrm(new DrmMockCustom); + rootDeviceEnvironment->memoryOperationsInterface = std::make_unique(); } mock = static_cast(executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface->get()->getDrm()); memoryManager.reset(new TestedDrmMemoryManager(*executionEnvironment)); diff --git a/opencl/test/unit_test/os_interface/linux/drm_residency_handler_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_residency_handler_tests.cpp index 6ba6e5af17..e9214ddcac 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_residency_handler_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_residency_handler_tests.cpp @@ -14,25 +14,45 @@ using namespace NEO; +#include "shared/source/os_interface/linux/drm_memory_operations_handler.h" + +#include "opencl/test/unit_test/mocks/mock_graphics_allocation.h" +#include "test.h" + +#include + +using namespace NEO; + +struct MockDrmMemoryOperationsHandler : public DrmMemoryOperationsHandler { + using DrmMemoryOperationsHandler::residency; +}; + struct DrmMemoryOperationsHandlerTest : public ::testing::Test { void SetUp() override { - drmMemoryOperationsHandler = std::make_unique(); + drmMemoryOperationsHandler = std::make_unique(); allocationPtr = &graphicsAllocation; } MockGraphicsAllocation graphicsAllocation; GraphicsAllocation *allocationPtr; - std::unique_ptr drmMemoryOperationsHandler; + std::unique_ptr drmMemoryOperationsHandler; }; TEST_F(DrmMemoryOperationsHandlerTest, whenMakingResidentAllocaionExpectMakeResidentFail) { - EXPECT_EQ(drmMemoryOperationsHandler->makeResident(ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::UNSUPPORTED); - EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); + EXPECT_EQ(drmMemoryOperationsHandler->makeResident(ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); + EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end()); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::SUCCESS); } TEST_F(DrmMemoryOperationsHandlerTest, whenEvictingResidentAllocationExpectEvictFalse) { - EXPECT_EQ(drmMemoryOperationsHandler->makeResident(ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::UNSUPPORTED); - EXPECT_EQ(drmMemoryOperationsHandler->evict(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); - EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); + EXPECT_EQ(drmMemoryOperationsHandler->makeResident(ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 1u); + EXPECT_TRUE(drmMemoryOperationsHandler->residency.find(allocationPtr) != drmMemoryOperationsHandler->residency.end()); + EXPECT_EQ(drmMemoryOperationsHandler->evict(graphicsAllocation), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND); + EXPECT_EQ(drmMemoryOperationsHandler->residency.size(), 0u); } diff --git a/opencl/test/unit_test/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp b/opencl/test/unit_test/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp index 5c8f593746..bb560826f8 100644 --- a/opencl/test/unit_test/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/linux_create_command_queue_with_properties_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "shared/source/os_interface/linux/drm_memory_operations_handler.h" #include "shared/source/os_interface/linux/os_interface.h" #include "opencl/source/command_queue/command_queue_hw.h" @@ -25,6 +26,7 @@ struct clCreateCommandQueueWithPropertiesLinux : public UltCommandStreamReceiver auto osInterface = new OSInterface(); osInterface->get()->setDrm(drm); executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->osInterface.reset(osInterface); + executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique(); executionEnvironment->memoryManager.reset(new TestedDrmMemoryManager(*executionEnvironment)); mdevice = std::make_unique(MockDevice::create(executionEnvironment, rootDeviceIndex)); diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 28bfa409fd..c6120194b9 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -19,6 +19,7 @@ #include "shared/source/memory_manager/host_ptr_manager.h" #include "shared/source/memory_manager/residency.h" #include "shared/source/os_interface/linux/allocator_helper.h" +#include "shared/source/os_interface/linux/drm_memory_operations_handler.h" #include "shared/source/os_interface/linux/os_context_linux.h" #include "shared/source/os_interface/linux/os_interface.h" @@ -545,6 +546,8 @@ void DrmMemoryManager::removeAllocationFromHostPtrManager(GraphicsAllocation *gf } void DrmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) { + executionEnvironment.rootDeviceEnvironments[gfxAllocation->getRootDeviceIndex()]->memoryOperationsInterface->evict(*gfxAllocation); + for (auto handleId = 0u; handleId < EngineLimits::maxHandleCount; handleId++) { if (gfxAllocation->getGmm(handleId)) { delete gfxAllocation->getGmm(handleId); diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler.cpp b/shared/source/os_interface/linux/drm_memory_operations_handler.cpp index 8084dd5a9d..37747130fd 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler.cpp +++ b/shared/source/os_interface/linux/drm_memory_operations_handler.cpp @@ -7,21 +7,42 @@ #include "shared/source/os_interface/linux/drm_memory_operations_handler.h" +#include + namespace NEO { -DrmMemoryOperationsHandler::DrmMemoryOperationsHandler() { -} +DrmMemoryOperationsHandler::DrmMemoryOperationsHandler() = default; +DrmMemoryOperationsHandler::~DrmMemoryOperationsHandler() = default; MemoryOperationsStatus DrmMemoryOperationsHandler::makeResident(ArrayRef gfxAllocations) { - return MemoryOperationsStatus::UNSUPPORTED; + std::lock_guard lock(mutex); + this->residency.insert(gfxAllocations.begin(), gfxAllocations.end()); + return MemoryOperationsStatus::SUCCESS; } MemoryOperationsStatus DrmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) { - return MemoryOperationsStatus::UNSUPPORTED; + std::lock_guard lock(mutex); + this->residency.erase(&gfxAllocation); + return MemoryOperationsStatus::SUCCESS; } MemoryOperationsStatus DrmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) { - return MemoryOperationsStatus::UNSUPPORTED; + std::lock_guard lock(mutex); + auto ret = this->residency.find(&gfxAllocation); + if (ret == this->residency.end()) { + return MemoryOperationsStatus::MEMORY_NOT_FOUND; + } + return MemoryOperationsStatus::SUCCESS; +} + +void DrmMemoryOperationsHandler::mergeWithResidencyContainer(ResidencyContainer &residencyContainer) { + std::lock_guard lock(mutex); + for (auto gfxAllocation = this->residency.begin(); gfxAllocation != this->residency.end(); gfxAllocation++) { + auto ret = std::find(residencyContainer.begin(), residencyContainer.end(), *gfxAllocation); + if (ret == residencyContainer.end()) { + residencyContainer.push_back(*gfxAllocation); + } + } } } // namespace NEO diff --git a/shared/source/os_interface/linux/drm_memory_operations_handler.h b/shared/source/os_interface/linux/drm_memory_operations_handler.h index bde6dfdcee..32f5b80895 100644 --- a/shared/source/os_interface/linux/drm_memory_operations_handler.h +++ b/shared/source/os_interface/linux/drm_memory_operations_handler.h @@ -7,16 +7,25 @@ #pragma once #include "shared/source/memory_manager/memory_operations_handler.h" +#include "shared/source/memory_manager/residency_container.h" + +#include +#include namespace NEO { - class DrmMemoryOperationsHandler : public MemoryOperationsHandler { public: DrmMemoryOperationsHandler(); - ~DrmMemoryOperationsHandler() override = default; + ~DrmMemoryOperationsHandler() override; MemoryOperationsStatus makeResident(ArrayRef gfxAllocations) override; MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override; + + void mergeWithResidencyContainer(ResidencyContainer &residencyContainer); + + protected: + std::unordered_set residency; + std::mutex mutex; }; } // namespace NEO