From 9e7c30cb06a7736fde7d7b81d4027d142b84fbc9 Mon Sep 17 00:00:00 2001 From: "Jablonski, Mateusz" Date: Tue, 19 Feb 2019 16:14:18 +0100 Subject: [PATCH] Choose Standard or Standard64 heap depending on 64KB suitablity of resource Change-Id: I633b1bef1cdef2c5149909c997adc85434bcaf73 Signed-off-by: Jablonski, Mateusz --- runtime/gmm_helper/resource_info.h | 2 ++ runtime/memory_manager/memory_manager.cpp | 2 +- .../memory_manager/memory_manager_tests.cpp | 32 ++++++++++--------- unit_tests/mocks/mock_gmm_resource_info.h | 3 ++ 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/runtime/gmm_helper/resource_info.h b/runtime/gmm_helper/resource_info.h index 7220873ad9..a22b9791e6 100644 --- a/runtime/gmm_helper/resource_info.h +++ b/runtime/gmm_helper/resource_info.h @@ -65,6 +65,8 @@ class GmmResourceInfo { MOCKABLE_VIRTUAL uint64_t getUnifiedAuxSurfaceOffset(GMM_UNIFIED_AUX_TYPE auxType) { return resourceInfo->GetUnifiedAuxSurfaceOffset(auxType); } + MOCKABLE_VIRTUAL bool is64KBPageSuitable() const { return resourceInfo->Is64KBPageSuitable(); } + MOCKABLE_VIRTUAL GMM_RESOURCE_INFO *peekHandle() const { return resourceInfo.get(); } protected: diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 50dcf1f6e8..432cb084f6 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -388,7 +388,7 @@ HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, const if (ptr) { return HeapIndex::HEAP_SVM; } - if (allocation && GraphicsAllocation::isCpuAccessRequired(allocation->getAllocationType())) { + if (allocation && allocation->gmm->gmmResourceInfo->is64KBPageSuitable()) { return HeapIndex::HEAP_STANDARD64Kb; } return HeapIndex::HEAP_STANDARD; diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 2ec342ed27..f2c3be8284 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -1618,28 +1618,28 @@ TEST(OsContextTest, givenOsContextWithNumberOfSupportedDevicesWhenConstructingTh EXPECT_EQ(7u, osContext.getNumDevicesSupported()); } -TEST(MemoryManagerTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) { +TEST(HeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) { GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; allocation.is32BitAllocation = true; allocation.origin = AllocationOrigin::INTERNAL_ALLOCATION; EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); } -TEST(MemoryManagerTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) { +TEST(HeapSelectorTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) { GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; allocation.is32BitAllocation = false; allocation.origin = AllocationOrigin::INTERNAL_ALLOCATION; EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); } -TEST(MemoryManagerTest, given32bitExternalAllocationWhenSelectingHeapThenExternalHeapIsUsed) { +TEST(HeapSelectorTest, given32bitExternalAllocationWhenSelectingHeapThenExternalHeapIsUsed) { GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; allocation.is32BitAllocation = true; allocation.origin = AllocationOrigin::EXTERNAL_ALLOCATION; EXPECT_EQ(HeapIndex::HEAP_EXTERNAL, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); } -TEST(MemoryManagerTest, givenLimitedAddressSpaceWhenSelectingHeapForExternalAllocationThenLimitedHeapIsUsed) { +TEST(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForExternalAllocationThenLimitedHeapIsUsed) { GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; EXPECT_EQ(AllocationOrigin::EXTERNAL_ALLOCATION, allocation.origin); if (platformDevices[0]->capabilityTable.gpuAddressSpace == MemoryConstants::max48BitAddress) { @@ -1648,7 +1648,7 @@ TEST(MemoryManagerTest, givenLimitedAddressSpaceWhenSelectingHeapForExternalAllo EXPECT_EQ(HeapIndex::HEAP_LIMITED, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); } -TEST(MemoryManagerTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithPtrThenSvmHeapIsUsed) { +TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithPtrThenSvmHeapIsUsed) { GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; EXPECT_EQ(AllocationOrigin::EXTERNAL_ALLOCATION, allocation.origin); if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) { @@ -1657,38 +1657,40 @@ TEST(MemoryManagerTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocat EXPECT_EQ(HeapIndex::HEAP_SVM, MemoryManager::selectHeap(&allocation, &allocation, *platformDevices[0])); } -TEST(MemoryManagerTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndCpuAccessIsRequiredThenStandard64kHeapIsUsed) { +TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIs64KSuitableThenStandard64kHeapIsUsed) { GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; EXPECT_EQ(AllocationOrigin::EXTERNAL_ALLOCATION, allocation.origin); - auto allocationType = GraphicsAllocation::AllocationType::LINEAR_STREAM; - allocation.setAllocationType(allocationType); - EXPECT_TRUE(GraphicsAllocation::isCpuAccessRequired(allocationType)); + auto gmm = std::make_unique(nullptr, 0, false); + auto resourceInfo = static_cast(gmm->gmmResourceInfo.get()); + resourceInfo->is64KBPageSuitableValue = true; + allocation.gmm = gmm.get(); if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) { return; } EXPECT_EQ(HeapIndex::HEAP_STANDARD64Kb, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); } -TEST(MemoryManagerTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndCpuAccessIsNotRequiredThenStandardHeapIsUsed) { +TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForExternalAllocationWithoutPtrAndResourceIsNot64KSuitableThenStandardHeapIsUsed) { GraphicsAllocation allocation{nullptr, 0, 0, 0, false}; EXPECT_EQ(AllocationOrigin::EXTERNAL_ALLOCATION, allocation.origin); - auto allocationType = GraphicsAllocation::AllocationType::UNDECIDED; - allocation.setAllocationType(allocationType); - EXPECT_FALSE(GraphicsAllocation::isCpuAccessRequired(allocationType)); + auto gmm = std::make_unique(nullptr, 0, false); + auto resourceInfo = static_cast(gmm->gmmResourceInfo.get()); + resourceInfo->is64KBPageSuitableValue = false; + allocation.gmm = gmm.get(); if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) { return; } EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0])); } -TEST(MemoryManagerTest, givenFullAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) { +TEST(HeapSelectorTest, givenFullAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenStandardHeapIsUsed) { if (platformDevices[0]->capabilityTable.gpuAddressSpace != MemoryConstants::max48BitAddress) { return; } EXPECT_EQ(HeapIndex::HEAP_STANDARD, MemoryManager::selectHeap(nullptr, nullptr, *platformDevices[0])); } -TEST(MemoryManagerTest, givenLimitedAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenLimitedHeapIsUsed) { +TEST(HeapSelectorTest, givenLimitedAddressSpaceWhenSelectingHeapForNullAllocationWithoutPtrThenLimitedHeapIsUsed) { auto hwInfo = *platformDevices[0]; hwInfo.capabilityTable.gpuAddressSpace = MemoryConstants::max32BitAddress; EXPECT_EQ(HeapIndex::HEAP_LIMITED, MemoryManager::selectHeap(nullptr, nullptr, hwInfo)); diff --git a/unit_tests/mocks/mock_gmm_resource_info.h b/unit_tests/mocks/mock_gmm_resource_info.h index 1af61a4320..c96a9ebe93 100644 --- a/unit_tests/mocks/mock_gmm_resource_info.h +++ b/unit_tests/mocks/mock_gmm_resource_info.h @@ -72,6 +72,8 @@ class MockGmmResourceInfo : public GmmResourceInfo { MOCK_METHOD1(getUnifiedAuxSurfaceOffset, uint64_t(GMM_UNIFIED_AUX_TYPE auxType)); + bool is64KBPageSuitable() const override { return is64KBPageSuitableValue; } + GMM_RESOURCE_INFO *peekHandle() const override { return mockResourceInfoHandle; } GMM_RESOURCE_INFO *mockResourceInfoHandle = (GMM_RESOURCE_INFO *)this; @@ -89,6 +91,7 @@ class MockGmmResourceInfo : public GmmResourceInfo { uint32_t getOffsetCalled = 0u; uint32_t arrayIndexPassedToGetOffset = 0; SurfaceFormatInfo tempSurface{}; + bool is64KBPageSuitableValue = true; protected: MockGmmResourceInfo();