From 7827501b91831f1b6c47f28cc0684c03c060a3cb Mon Sep 17 00:00:00 2001 From: Maciej Plewka Date: Thu, 29 Aug 2019 13:46:49 +0200 Subject: [PATCH] Add returned status to MemoryOperationsHandler Change-Id: Ic8685e3711cec03d8f83d371fa7152ee095a47a0 Signed-off-by: Maciej Plewka --- core/memory_manager/CMakeLists.txt | 1 + .../memory_operations_handler.h | 7 +++-- .../memory_manager/memory_operations_status.h | 22 ++++++++++++++ .../aub_memory_operations_handler.cpp | 18 +++++------ .../aub_memory_operations_handler.h | 6 ++-- .../aub_memory_operations_handler_tests.cpp | 24 +++++++-------- .../linux/drm_memory_operations_handler.cpp | 12 ++++---- .../linux/drm_memory_operations_handler.h | 6 ++-- runtime/os_interface/windows/wddm/wddm.h | 1 - .../windows/wddm_memory_manager.cpp | 2 +- .../wddm_memory_operations_handler.cpp | 9 +++--- .../windows/wddm_memory_operations_handler.h | 6 ++-- .../wddm_residency_allocations_container.cpp | 30 +++++++++---------- .../wddm_residency_allocations_container.h | 14 ++++----- .../windows/wddm_residency_controller.cpp | 4 +-- .../mocks/mock_memory_operations_handler.h | 6 ++-- ...ock_wddm_residency_allocations_container.h | 29 +++++++++--------- unit_tests/mocks/wddm_mock_helpers.h | 6 ++-- .../linux/drm_residency_handler_tests.cpp | 10 +++---- .../os_interface/windows/wddm20_tests.cpp | 14 ++++----- .../windows/wddm_residency_handler_tests.cpp | 10 +++---- 21 files changed, 130 insertions(+), 107 deletions(-) create mode 100644 core/memory_manager/memory_operations_status.h diff --git a/core/memory_manager/CMakeLists.txt b/core/memory_manager/CMakeLists.txt index 780f5dbb63..526e51c402 100644 --- a/core/memory_manager/CMakeLists.txt +++ b/core/memory_manager/CMakeLists.txt @@ -8,6 +8,7 @@ set(NEO_CORE_MEMORY_MANAGER ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/eviction_status.h ${CMAKE_CURRENT_SOURCE_DIR}/memory_operations_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/memory_operations_status.h ) set_property(GLOBAL PROPERTY NEO_CORE_MEMORY_MANAGER ${NEO_CORE_MEMORY_MANAGER}) diff --git a/core/memory_manager/memory_operations_handler.h b/core/memory_manager/memory_operations_handler.h index 15ce967c8e..fd238667d0 100644 --- a/core/memory_manager/memory_operations_handler.h +++ b/core/memory_manager/memory_operations_handler.h @@ -6,6 +6,7 @@ */ #pragma once +#include "core/memory_manager/memory_operations_status.h" namespace NEO { @@ -16,8 +17,8 @@ class MemoryOperationsHandler { MemoryOperationsHandler() = default; virtual ~MemoryOperationsHandler() = default; - virtual bool makeResident(GraphicsAllocation &gfxAllocation) = 0; - virtual bool evict(GraphicsAllocation &gfxAllocation) = 0; - virtual bool isResident(GraphicsAllocation &gfxAllocation) = 0; + virtual MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) = 0; + virtual MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) = 0; + virtual MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) = 0; }; } // namespace NEO diff --git a/core/memory_manager/memory_operations_status.h b/core/memory_manager/memory_operations_status.h new file mode 100644 index 0000000000..e68f58d889 --- /dev/null +++ b/core/memory_manager/memory_operations_status.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include + +namespace NEO { + +enum class MemoryOperationsStatus : uint32_t { + SUCCESS = 0, + FAILED, + MEMORY_NOT_FOUND, + OUT_OF_MEMORY, + UNSUPPORTED, + DEVICE_UNINITIALIZED, +}; + +} // namespace NEO diff --git a/core/os_interface/aub_memory_operations_handler.cpp b/core/os_interface/aub_memory_operations_handler.cpp index 3d398b1b65..efb48913a4 100644 --- a/core/os_interface/aub_memory_operations_handler.cpp +++ b/core/os_interface/aub_memory_operations_handler.cpp @@ -18,35 +18,35 @@ AubMemoryOperationsHandler::AubMemoryOperationsHandler(aub_stream::AubManager *a this->aubManager = aubManager; } -bool AubMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { +MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { if (!aubManager) { - return false; + return MemoryOperationsStatus::DEVICE_UNINITIALIZED; } auto lock = acquireLock(resourcesLock); int hint = AubMemDump::DataTypeHintValues::TraceNotype; aubManager->writeMemory(gfxAllocation.getGpuAddress(), gfxAllocation.getUnderlyingBuffer(), gfxAllocation.getUnderlyingBufferSize(), gfxAllocation.storageInfo.getMemoryBanks(), hint, gfxAllocation.getUsedPageSize()); residentAllocations.push_back(&gfxAllocation); - return true; + return MemoryOperationsStatus::SUCCESS; } -bool AubMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) { +MemoryOperationsStatus AubMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) { auto lock = acquireLock(resourcesLock); auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation); if (itor == residentAllocations.end()) { - return false; + return MemoryOperationsStatus::MEMORY_NOT_FOUND; } else { residentAllocations.erase(itor, itor + 1); - return true; + return MemoryOperationsStatus::SUCCESS; } } -bool AubMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) { +MemoryOperationsStatus AubMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) { auto lock = acquireLock(resourcesLock); auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation); if (itor == residentAllocations.end()) { - return false; + return MemoryOperationsStatus::MEMORY_NOT_FOUND; } else { - return true; + return MemoryOperationsStatus::SUCCESS; } } void AubMemoryOperationsHandler::setAubManager(aub_stream::AubManager *aubManager) { diff --git a/core/os_interface/aub_memory_operations_handler.h b/core/os_interface/aub_memory_operations_handler.h index bbaf5bb43e..22f1fcd41b 100644 --- a/core/os_interface/aub_memory_operations_handler.h +++ b/core/os_interface/aub_memory_operations_handler.h @@ -21,9 +21,9 @@ class AubMemoryOperationsHandler : public MemoryOperationsHandler { AubMemoryOperationsHandler(aub_stream::AubManager *aubManager); ~AubMemoryOperationsHandler() override = default; - bool makeResident(GraphicsAllocation &gfxAllocation) override; - bool evict(GraphicsAllocation &gfxAllocation) override; - bool isResident(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override; void setAubManager(aub_stream::AubManager *aubManager); protected: diff --git a/core/unit_tests/os_interface/aub_memory_operations_handler_tests.cpp b/core/unit_tests/os_interface/aub_memory_operations_handler_tests.cpp index a40bca1585..2c13ffa911 100644 --- a/core/unit_tests/os_interface/aub_memory_operations_handler_tests.cpp +++ b/core/unit_tests/os_interface/aub_memory_operations_handler_tests.cpp @@ -13,16 +13,16 @@ TEST_F(AubMemoryOperationsHandlerTests, givenNullPtrAsAubManagerWhenMakeResidentCalledThenFalseReturned) { getMemoryOperationsHandler()->setAubManager(nullptr); auto memoryOperationsInterface = getMemoryOperationsHandler(); - bool result = memoryOperationsInterface->makeResident(allocation); - EXPECT_FALSE(result); + auto result = memoryOperationsInterface->makeResident(allocation); + EXPECT_EQ(result, MemoryOperationsStatus::DEVICE_UNINITIALIZED); } TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledThenTrueReturnedAndWriteCalled) { MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - bool result = memoryOperationsInterface->makeResident(allocation); - EXPECT_TRUE(result); + auto result = memoryOperationsInterface->makeResident(allocation); + EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS); EXPECT_TRUE(aubManager.writeMemoryCalled); } @@ -37,29 +37,29 @@ TEST_F(AubMemoryOperationsHandlerTests, givenNonResidentAllocationWhenIsResident MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - bool result = memoryOperationsInterface->isResident(allocation); - EXPECT_FALSE(result); + auto result = memoryOperationsInterface->isResident(allocation); + EXPECT_EQ(result, MemoryOperationsStatus::MEMORY_NOT_FOUND); } TEST_F(AubMemoryOperationsHandlerTests, givenResidentAllocationWhenIsResidentCalledThenTrueReturned) { MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); memoryOperationsInterface->makeResident(allocation); - bool result = memoryOperationsInterface->isResident(allocation); - EXPECT_TRUE(result); + auto result = memoryOperationsInterface->isResident(allocation); + EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS); } TEST_F(AubMemoryOperationsHandlerTests, givenNonResidentAllocationWhenEvictCalledThenFalseReturned) { MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - bool result = memoryOperationsInterface->evict(allocation); - EXPECT_FALSE(result); + auto result = memoryOperationsInterface->evict(allocation); + EXPECT_EQ(result, MemoryOperationsStatus::MEMORY_NOT_FOUND); } TEST_F(AubMemoryOperationsHandlerTests, givenResidentAllocationWhenEvictCalledThenTrueReturned) { MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); memoryOperationsInterface->makeResident(allocation); - bool result = memoryOperationsInterface->evict(allocation); - EXPECT_TRUE(result); + auto result = memoryOperationsInterface->evict(allocation); + EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS); } \ No newline at end of file diff --git a/runtime/os_interface/linux/drm_memory_operations_handler.cpp b/runtime/os_interface/linux/drm_memory_operations_handler.cpp index 94fdfbe4c6..2d9c25b379 100644 --- a/runtime/os_interface/linux/drm_memory_operations_handler.cpp +++ b/runtime/os_interface/linux/drm_memory_operations_handler.cpp @@ -12,16 +12,16 @@ namespace NEO { DrmMemoryOperationsHandler::DrmMemoryOperationsHandler() { } -bool DrmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { - return false; +MemoryOperationsStatus DrmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { + return MemoryOperationsStatus::UNSUPPORTED; } -bool DrmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) { - return false; +MemoryOperationsStatus DrmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) { + return MemoryOperationsStatus::UNSUPPORTED; } -bool DrmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) { - return false; +MemoryOperationsStatus DrmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) { + return MemoryOperationsStatus::UNSUPPORTED; } } // namespace NEO diff --git a/runtime/os_interface/linux/drm_memory_operations_handler.h b/runtime/os_interface/linux/drm_memory_operations_handler.h index fac0d585e5..8f60ad1f93 100644 --- a/runtime/os_interface/linux/drm_memory_operations_handler.h +++ b/runtime/os_interface/linux/drm_memory_operations_handler.h @@ -15,8 +15,8 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler { DrmMemoryOperationsHandler(); ~DrmMemoryOperationsHandler() override = default; - bool makeResident(GraphicsAllocation &gfxAllocation) override; - bool evict(GraphicsAllocation &gfxAllocation) override; - bool isResident(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override; }; } // namespace NEO diff --git a/runtime/os_interface/windows/wddm/wddm.h b/runtime/os_interface/windows/wddm/wddm.h index deeda72d0d..5be16b1a7e 100644 --- a/runtime/os_interface/windows/wddm/wddm.h +++ b/runtime/os_interface/windows/wddm/wddm.h @@ -7,7 +7,6 @@ #pragma once #include "core/command_stream/preemption_mode.h" -#include "core/memory_manager/eviction_status.h" #include "core/utilities/spinlock.h" #include "runtime/gmm_helper/gmm_lib.h" #include "runtime/helpers/debug_helpers.h" diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index fd0401ce0f..a88959c8ce 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -292,7 +292,7 @@ void WddmMemoryManager::unlockResourceImpl(GraphicsAllocation &graphicsAllocatio wddm->unlockResource(wddmAllocation.getDefaultHandle()); if (wddmAllocation.needsMakeResidentBeforeLock) { auto evictionStatus = wddm->getTemporaryResourcesContainer()->evictResource(wddmAllocation.getDefaultHandle()); - DEBUG_BREAK_IF(evictionStatus == EvictionStatus::FAILED); + DEBUG_BREAK_IF(evictionStatus == MemoryOperationsStatus::FAILED); } } void WddmMemoryManager::freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) { diff --git a/runtime/os_interface/windows/wddm_memory_operations_handler.cpp b/runtime/os_interface/windows/wddm_memory_operations_handler.cpp index 0f92741714..e5211a9673 100644 --- a/runtime/os_interface/windows/wddm_memory_operations_handler.cpp +++ b/runtime/os_interface/windows/wddm_memory_operations_handler.cpp @@ -19,18 +19,17 @@ WddmMemoryOperationsHandler::WddmMemoryOperationsHandler(Wddm *wddm) : wddm(wddm residentAllocations = std::make_unique(wddm); } -bool WddmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { +MemoryOperationsStatus WddmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { WddmAllocation &wddmAllocation = reinterpret_cast(gfxAllocation); return residentAllocations->makeResidentResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles()); } -bool WddmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) { +MemoryOperationsStatus WddmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) { WddmAllocation &wddmAllocation = reinterpret_cast(gfxAllocation); - auto result = residentAllocations->evictResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles()); - return result == EvictionStatus::SUCCESS; + return residentAllocations->evictResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles()); } -bool WddmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) { +MemoryOperationsStatus WddmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) { WddmAllocation &wddmAllocation = reinterpret_cast(gfxAllocation); return residentAllocations->isAllocationResident(wddmAllocation.getDefaultHandle()); } diff --git a/runtime/os_interface/windows/wddm_memory_operations_handler.h b/runtime/os_interface/windows/wddm_memory_operations_handler.h index ffc5056455..22dd00c4e2 100644 --- a/runtime/os_interface/windows/wddm_memory_operations_handler.h +++ b/runtime/os_interface/windows/wddm_memory_operations_handler.h @@ -20,9 +20,9 @@ class WddmMemoryOperationsHandler : public MemoryOperationsHandler { WddmMemoryOperationsHandler(Wddm *wddm); ~WddmMemoryOperationsHandler() override = default; - bool makeResident(GraphicsAllocation &gfxAllocation) override; - bool evict(GraphicsAllocation &gfxAllocation) override; - bool isResident(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override; protected: Wddm *wddm; diff --git a/runtime/os_interface/windows/wddm_residency_allocations_container.cpp b/runtime/os_interface/windows/wddm_residency_allocations_container.cpp index 38e9a4d0fd..017214588e 100644 --- a/runtime/os_interface/windows/wddm_residency_allocations_container.cpp +++ b/runtime/os_interface/windows/wddm_residency_allocations_container.cpp @@ -17,58 +17,58 @@ WddmResidentAllocationsContainer::~WddmResidentAllocationsContainer() { evictAllResources(); } -bool WddmResidentAllocationsContainer::isAllocationResident(const D3DKMT_HANDLE &handle) { +MemoryOperationsStatus WddmResidentAllocationsContainer::isAllocationResident(const D3DKMT_HANDLE &handle) { auto lock = acquireLock(resourcesLock); auto position = std::find(resourceHandles.begin(), resourceHandles.end(), handle); - return position != resourceHandles.end(); + return position != resourceHandles.end() ? MemoryOperationsStatus::SUCCESS : MemoryOperationsStatus::MEMORY_NOT_FOUND; } -EvictionStatus WddmResidentAllocationsContainer::evictAllResources() { +MemoryOperationsStatus WddmResidentAllocationsContainer::evictAllResources() { decltype(resourceHandles) resourcesToEvict; auto lock = acquireLock(resourcesLock); resourceHandles.swap(resourcesToEvict); if (resourcesToEvict.empty()) { - return EvictionStatus::NOT_APPLIED; + return MemoryOperationsStatus::MEMORY_NOT_FOUND; } uint64_t sizeToTrim = 0; uint32_t evictedResources = static_cast(resourcesToEvict.size()); bool success = wddm->evict(resourcesToEvict.data(), evictedResources, sizeToTrim); - return success ? EvictionStatus::SUCCESS : EvictionStatus::FAILED; + return success ? MemoryOperationsStatus::SUCCESS : MemoryOperationsStatus::FAILED; } -EvictionStatus WddmResidentAllocationsContainer::evictResource(const D3DKMT_HANDLE &handle) { +MemoryOperationsStatus WddmResidentAllocationsContainer::evictResource(const D3DKMT_HANDLE &handle) { return evictResources(&handle, 1u); } -EvictionStatus WddmResidentAllocationsContainer::evictResources(const D3DKMT_HANDLE *handles, const uint32_t count) { +MemoryOperationsStatus WddmResidentAllocationsContainer::evictResources(const D3DKMT_HANDLE *handles, const uint32_t count) { auto lock = acquireLock(resourcesLock); auto position = std::find(resourceHandles.begin(), resourceHandles.end(), handles[0]); if (position == resourceHandles.end()) { - return EvictionStatus::NOT_APPLIED; + return MemoryOperationsStatus::MEMORY_NOT_FOUND; } auto distance = static_cast(std::distance(resourceHandles.begin(), position)); UNRECOVERABLE_IF(distance + count > resourceHandles.size()); resourceHandles.erase(position, position + count); uint64_t sizeToTrim = 0; if (!wddm->evict(handles, count, sizeToTrim)) { - return EvictionStatus::FAILED; + return MemoryOperationsStatus::FAILED; } - return EvictionStatus::SUCCESS; + return MemoryOperationsStatus::SUCCESS; } -bool WddmResidentAllocationsContainer::makeResidentResource(const D3DKMT_HANDLE &handle) { +MemoryOperationsStatus WddmResidentAllocationsContainer::makeResidentResource(const D3DKMT_HANDLE &handle) { return makeResidentResources(&handle, 1u); } -bool WddmResidentAllocationsContainer::makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count) { +MemoryOperationsStatus WddmResidentAllocationsContainer::makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count) { bool madeResident = false; while (!(madeResident = wddm->makeResident(handles, count, false, nullptr))) { - if (evictAllResources() == EvictionStatus::SUCCESS) { + if (evictAllResources() == MemoryOperationsStatus::SUCCESS) { continue; } if (!wddm->makeResident(handles, count, false, nullptr)) { DEBUG_BREAK_IF(true); - return false; + return MemoryOperationsStatus::OUT_OF_MEMORY; }; break; } @@ -79,7 +79,7 @@ bool WddmResidentAllocationsContainer::makeResidentResources(const D3DKMT_HANDLE } lock.unlock(); wddm->waitOnPagingFenceFromCpu(); - return madeResident; + return madeResident ? MemoryOperationsStatus::SUCCESS : MemoryOperationsStatus::FAILED; } void WddmResidentAllocationsContainer::removeResource(const D3DKMT_HANDLE &handle) { diff --git a/runtime/os_interface/windows/wddm_residency_allocations_container.h b/runtime/os_interface/windows/wddm_residency_allocations_container.h index ad5a1f9ea2..24a0547948 100644 --- a/runtime/os_interface/windows/wddm_residency_allocations_container.h +++ b/runtime/os_interface/windows/wddm_residency_allocations_container.h @@ -6,7 +6,7 @@ */ #pragma once -#include "core/memory_manager/eviction_status.h" +#include "core/memory_manager/memory_operations_status.h" #include "core/utilities/spinlock.h" #include "runtime/os_interface/windows/windows_defs.h" @@ -21,12 +21,12 @@ class WddmResidentAllocationsContainer { WddmResidentAllocationsContainer(Wddm *wddm) : wddm(wddm) {} virtual ~WddmResidentAllocationsContainer(); - bool isAllocationResident(const D3DKMT_HANDLE &handle); - MOCKABLE_VIRTUAL EvictionStatus evictAllResources(); - MOCKABLE_VIRTUAL EvictionStatus evictResource(const D3DKMT_HANDLE &handle); - EvictionStatus evictResources(const D3DKMT_HANDLE *handles, const uint32_t count); - MOCKABLE_VIRTUAL bool makeResidentResource(const D3DKMT_HANDLE &handle); - bool makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count); + MemoryOperationsStatus isAllocationResident(const D3DKMT_HANDLE &handle); + MOCKABLE_VIRTUAL MemoryOperationsStatus evictAllResources(); + MOCKABLE_VIRTUAL MemoryOperationsStatus evictResource(const D3DKMT_HANDLE &handle); + MemoryOperationsStatus evictResources(const D3DKMT_HANDLE *handles, const uint32_t count); + MOCKABLE_VIRTUAL MemoryOperationsStatus makeResidentResource(const D3DKMT_HANDLE &handle); + MemoryOperationsStatus makeResidentResources(const D3DKMT_HANDLE *handles, const uint32_t count); MOCKABLE_VIRTUAL void removeResource(const D3DKMT_HANDLE &handle); protected: diff --git a/runtime/os_interface/windows/wddm_residency_controller.cpp b/runtime/os_interface/windows/wddm_residency_controller.cpp index 364e85623c..2a95386518 100644 --- a/runtime/os_interface/windows/wddm_residency_controller.cpp +++ b/runtime/os_interface/windows/wddm_residency_controller.cpp @@ -343,10 +343,10 @@ bool WddmResidencyController::makeResidentResidencyAllocations(ResidencyContaine const bool trimmingDone = this->trimResidencyToBudget(bytesToTrim); if (!trimmingDone) { auto evictionStatus = wddm.getTemporaryResourcesContainer()->evictAllResources(); - if (evictionStatus == EvictionStatus::SUCCESS) { + if (evictionStatus == MemoryOperationsStatus::SUCCESS) { continue; } - DEBUG_BREAK_IF(evictionStatus != EvictionStatus::NOT_APPLIED); + DEBUG_BREAK_IF(evictionStatus != MemoryOperationsStatus::MEMORY_NOT_FOUND); result = wddm.makeResident(handlesForResidency.get(), totalHandlesCount, true, &bytesToTrim); break; } diff --git a/unit_tests/mocks/mock_memory_operations_handler.h b/unit_tests/mocks/mock_memory_operations_handler.h index 42d6017fcd..a3203800d2 100644 --- a/unit_tests/mocks/mock_memory_operations_handler.h +++ b/unit_tests/mocks/mock_memory_operations_handler.h @@ -16,8 +16,8 @@ class MockMemoryOperationsHandler : public MemoryOperationsHandler { public: MockMemoryOperationsHandler() {} virtual ~MockMemoryOperationsHandler() {} - bool makeResident(GraphicsAllocation &gfxAllocation) { return false; } - bool evict(GraphicsAllocation &gfxAllocation) { return false; } - bool isResident(GraphicsAllocation &gfxAllocation) { return false; } + MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) { return MemoryOperationsStatus::UNSUPPORTED; } + MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) { return MemoryOperationsStatus::UNSUPPORTED; } + MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) { return MemoryOperationsStatus::UNSUPPORTED; } }; } // namespace NEO \ No newline at end of file diff --git a/unit_tests/mocks/mock_wddm_residency_allocations_container.h b/unit_tests/mocks/mock_wddm_residency_allocations_container.h index 367e157459..c8350a3b7b 100644 --- a/unit_tests/mocks/mock_wddm_residency_allocations_container.h +++ b/unit_tests/mocks/mock_wddm_residency_allocations_container.h @@ -6,6 +6,7 @@ */ #pragma once +#include "core/memory_manager/memory_operations_status.h" #include "runtime/os_interface/windows/wddm_residency_allocations_container.h" #include "unit_tests/mocks/wddm_mock_helpers.h" @@ -20,22 +21,22 @@ class MockWddmResidentAllocationsContainer : public WddmResidentAllocationsConta MockWddmResidentAllocationsContainer(Wddm *wddm) : WddmResidentAllocationsContainer(wddm) {} virtual ~MockWddmResidentAllocationsContainer() = default; - bool makeResidentResource(const D3DKMT_HANDLE &handle) override { + MemoryOperationsStatus makeResidentResource(const D3DKMT_HANDLE &handle) override { makeResidentResult.called++; - makeResidentResult.success = WddmResidentAllocationsContainer::makeResidentResource(handle); - return makeResidentResult.success; + makeResidentResult.operationSuccess = WddmResidentAllocationsContainer::makeResidentResource(handle); + return makeResidentResult.operationSuccess; } - EvictionStatus evictAllResources() override { + MemoryOperationsStatus evictAllResources() override { evictAllResourcesResult.called++; - evictAllResourcesResult.status = WddmResidentAllocationsContainer::evictAllResources(); - return evictAllResourcesResult.status; + evictAllResourcesResult.operationSuccess = WddmResidentAllocationsContainer::evictAllResources(); + return evictAllResourcesResult.operationSuccess; } - EvictionStatus evictResource(const D3DKMT_HANDLE &handle) override { + MemoryOperationsStatus evictResource(const D3DKMT_HANDLE &handle) override { evictResourceResult.called++; - evictResourceResult.status = WddmResidentAllocationsContainer::evictResource(handle); - return evictResourceResult.status; + evictResourceResult.operationSuccess = WddmResidentAllocationsContainer::evictResource(handle); + return evictResourceResult.operationSuccess; } std::unique_lock acquireLock(SpinLock &lock) override { @@ -49,11 +50,11 @@ class MockWddmResidentAllocationsContainer : public WddmResidentAllocationsConta WddmResidentAllocationsContainer::removeResource(handle); } - WddmMockHelpers::CallResult makeResidentResult; - WddmMockHelpers::CallResult acquireLockResult; - WddmMockHelpers::CallResult removeResourceResult; - WddmMockHelpers::EvictCallResult evictAllResourcesResult; - WddmMockHelpers::EvictCallResult evictResourceResult; + WddmMockHelpers::MemoryOperationResult makeResidentResult; + WddmMockHelpers::MemoryOperationResult acquireLockResult; + WddmMockHelpers::MemoryOperationResult removeResourceResult; + WddmMockHelpers::MemoryOperationResult evictAllResourcesResult; + WddmMockHelpers::MemoryOperationResult evictResourceResult; }; } // namespace NEO diff --git a/unit_tests/mocks/wddm_mock_helpers.h b/unit_tests/mocks/wddm_mock_helpers.h index 38d8a77192..25aaaf17a1 100644 --- a/unit_tests/mocks/wddm_mock_helpers.h +++ b/unit_tests/mocks/wddm_mock_helpers.h @@ -27,9 +27,6 @@ struct MakeResidentCall : CallResult { std::vector handlePack; uint32_t handleCount = 0; }; -struct EvictCallResult : CallResult { - EvictionStatus status = EvictionStatus::UNKNOWN; -}; struct KmDafLockCall : CallResult { std::vector lockedAllocations; }; @@ -39,6 +36,9 @@ struct WaitFromCpuResult : CallResult { struct FreeGpuVirtualAddressCall : CallResult { uint64_t sizePassed = -1; }; +struct MemoryOperationResult : CallResult { + MemoryOperationsStatus operationSuccess = MemoryOperationsStatus::UNSUPPORTED; +}; } // namespace WddmMockHelpers } // namespace NEO diff --git a/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp b/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp index b9471249cc..4d184f8e40 100644 --- a/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp +++ b/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp @@ -23,12 +23,12 @@ struct DrmMemoryOperationsHandlerTest : public ::testing::Test { }; TEST_F(DrmMemoryOperationsHandlerTest, whenMakingResidentAllocaionExpectMakeResidentFail) { - EXPECT_FALSE(drmMemoryOperationsHandler->makeResident(graphicsAllocation)); - EXPECT_FALSE(drmMemoryOperationsHandler->isResident(graphicsAllocation)); + EXPECT_EQ(drmMemoryOperationsHandler->makeResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); } TEST_F(DrmMemoryOperationsHandlerTest, whenEvictingResidentAllocationExpectEvictFalse) { - EXPECT_FALSE(drmMemoryOperationsHandler->makeResident(graphicsAllocation)); - EXPECT_FALSE(drmMemoryOperationsHandler->evict(graphicsAllocation)); - EXPECT_FALSE(drmMemoryOperationsHandler->isResident(graphicsAllocation)); + EXPECT_EQ(drmMemoryOperationsHandler->makeResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); + EXPECT_EQ(drmMemoryOperationsHandler->evict(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); + EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); } diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 50b8feed71..d5e43b8355 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -844,7 +844,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeReside } TEST_F(WddmLockWithMakeResidentTests, givenNoTemporaryResourcesWhenEvictingAllTemporaryResourcesThenEvictionIsNotApplied) { wddm->getTemporaryResourcesContainer()->evictAllResources(); - EXPECT_EQ(EvictionStatus::NOT_APPLIED, mockTemporaryResources->evictAllResourcesResult.status); + EXPECT_EQ(MemoryOperationsStatus::MEMORY_NOT_FOUND, mockTemporaryResources->evictAllResourcesResult.operationSuccess); } TEST_F(WddmLockWithMakeResidentTests, whenEvictingAllTemporaryResourcesThenAcquireTemporaryResourcesLock) { wddm->getTemporaryResourcesContainer()->evictAllResources(); @@ -859,7 +859,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingAllTemporaryResourcesAndAllEvi EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); gmockWddm.getTemporaryResourcesContainer()->evictAllResources(); EXPECT_EQ(1u, mockTemporaryResources->evictAllResourcesResult.called); - EXPECT_EQ(EvictionStatus::SUCCESS, mockTemporaryResources->evictAllResourcesResult.status); + EXPECT_EQ(MemoryOperationsStatus::SUCCESS, mockTemporaryResources->evictAllResourcesResult.operationSuccess); } TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesThenCallEvictForEachAllocationAndCleanList) { GmockWddm gmockWddm; @@ -881,11 +881,11 @@ TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTempor } EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(false)); gmockWddm.getTemporaryResourcesContainer()->evictAllResources(); - EXPECT_EQ(EvictionStatus::FAILED, mockTemporaryResources->evictAllResourcesResult.status); + EXPECT_EQ(MemoryOperationsStatus::FAILED, mockTemporaryResources->evictAllResourcesResult.operationSuccess); } TEST_F(WddmLockWithMakeResidentTests, givenNoTemporaryResourcesWhenEvictingTemporaryResourceThenEvictionIsNotApplied) { wddm->getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE); - EXPECT_EQ(EvictionStatus::NOT_APPLIED, mockTemporaryResources->evictResourceResult.status); + EXPECT_EQ(MemoryOperationsStatus::MEMORY_NOT_FOUND, mockTemporaryResources->evictResourceResult.operationSuccess); } TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceThenAcquireTemporaryResourcesLock) { wddm->getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE); @@ -897,7 +897,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingNonExistingTemporaryResourceTh EXPECT_FALSE(mockTemporaryResources->resourceHandles.empty()); wddm->getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE + 1); EXPECT_FALSE(mockTemporaryResources->resourceHandles.empty()); - EXPECT_EQ(EvictionStatus::NOT_APPLIED, mockTemporaryResources->evictResourceResult.status); + EXPECT_EQ(MemoryOperationsStatus::MEMORY_NOT_FOUND, mockTemporaryResources->evictResourceResult.operationSuccess); } TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictFailsThenReturnFail) { GmockWddm gmockWddm; @@ -906,7 +906,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictFails EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(false)); gmockWddm.getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE); EXPECT_TRUE(mockTemporaryResources->resourceHandles.empty()); - EXPECT_EQ(EvictionStatus::FAILED, mockTemporaryResources->evictResourceResult.status); + EXPECT_EQ(MemoryOperationsStatus::FAILED, mockTemporaryResources->evictResourceResult.operationSuccess); } TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictSucceedThenReturnSuccess) { GmockWddm gmockWddm; @@ -915,7 +915,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictSucce EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); gmockWddm.getTemporaryResourcesContainer()->evictResource(ALLOCATION_HANDLE); EXPECT_TRUE(mockTemporaryResources->resourceHandles.empty()); - EXPECT_EQ(EvictionStatus::SUCCESS, mockTemporaryResources->evictResourceResult.status); + EXPECT_EQ(MemoryOperationsStatus::SUCCESS, mockTemporaryResources->evictResourceResult.operationSuccess); } TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceThenOtherResourcesRemainOnTheList) { mockTemporaryResources->resourceHandles.push_back(0x1); diff --git a/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp b/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp index 979a15d72f..aace714bbf 100644 --- a/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp @@ -26,12 +26,12 @@ struct WddmMemoryOperationsHandlerTest : public WddmTest { }; TEST_F(WddmMemoryOperationsHandlerTest, whenMakingResidentAllocaionExpectMakeResidentCalled) { - EXPECT_TRUE(wddmMemoryOperationsHandler->makeResident(wddmAllocation)); - EXPECT_TRUE(wddmMemoryOperationsHandler->isResident(wddmAllocation)); + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(wddmAllocation), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::SUCCESS); } TEST_F(WddmMemoryOperationsHandlerTest, whenEvictingResidentAllocationExpectEvictCalled) { - EXPECT_TRUE(wddmMemoryOperationsHandler->makeResident(wddmAllocation)); - EXPECT_TRUE(wddmMemoryOperationsHandler->evict(wddmAllocation)); - EXPECT_FALSE(wddmMemoryOperationsHandler->isResident(wddmAllocation)); + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(wddmAllocation), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(wddmMemoryOperationsHandler->evict(wddmAllocation), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND); }