From 5afc63df9307ed9a24f46fc12d7eae6e522976aa Mon Sep 17 00:00:00 2001 From: Jaroslaw Warchulski Date: Fri, 18 Oct 2024 16:46:00 +0000 Subject: [PATCH] fix: use full size for HEAP_EXTENDED initialization Related-To: GSD-8948 Signed-off-by: Jaroslaw Warchulski --- shared/source/memory_manager/gfx_partition.cpp | 7 ++++--- shared/source/memory_manager/gfx_partition.h | 6 +++--- shared/test/common/mocks/mock_gfx_partition.h | 2 +- ...ry_manager_allocate_in_device_pool_tests.cpp | 17 ++++------------- .../linux/drm_memory_manager_tests.cpp | 2 +- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/shared/source/memory_manager/gfx_partition.cpp b/shared/source/memory_manager/gfx_partition.cpp index 13aba39425..b1d078594c 100644 --- a/shared/source/memory_manager/gfx_partition.cpp +++ b/shared/source/memory_manager/gfx_partition.cpp @@ -102,14 +102,15 @@ GfxPartition::~GfxPartition() { osMemory->releaseCpuAddressRange(reservedCpuAddressRangeForHeapExtended); } -void GfxPartition::Heap::init(uint64_t base, uint64_t size, size_t allocationAlignment) { +void GfxPartition::Heap::init(HeapIndex heapIndex, uint64_t base, uint64_t size, size_t allocationAlignment) { this->base = base; this->size = size; auto heapGranularity = GfxPartition::heapGranularity; - if (allocationAlignment > heapGranularity) { + if (heapIndex == HeapIndex::heapExtended) + heapGranularity = 0; + else if (allocationAlignment > heapGranularity) heapGranularity = GfxPartition::heapGranularity2MB; - } // Exclude very first and very last 64K from GPU address range allocation if (size > 2 * heapGranularity) { diff --git a/shared/source/memory_manager/gfx_partition.h b/shared/source/memory_manager/gfx_partition.h index 6a96b6a321..f35e29cde7 100644 --- a/shared/source/memory_manager/gfx_partition.h +++ b/shared/source/memory_manager/gfx_partition.h @@ -42,11 +42,11 @@ class GfxPartition { MOCKABLE_VIRTUAL bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useExternalFrontWindowPool, uint64_t systemMemorySize, uint64_t gfxTop); void heapInit(HeapIndex heapIndex, uint64_t base, uint64_t size) { - getHeap(heapIndex).init(base, size, MemoryConstants::pageSize); + getHeap(heapIndex).init(heapIndex, base, size, MemoryConstants::pageSize); } void heapInitWithAllocationAlignment(HeapIndex heapIndex, uint64_t base, uint64_t size, size_t allocationAlignment) { - getHeap(heapIndex).init(base, size, allocationAlignment); + getHeap(heapIndex).init(heapIndex, base, size, allocationAlignment); } void heapInitExternalWithFrontWindow(HeapIndex heapIndex, uint64_t base, uint64_t size) { @@ -109,7 +109,7 @@ class GfxPartition { class Heap { public: Heap() = default; - void init(uint64_t base, uint64_t size, size_t allocationAlignment); + void init(HeapIndex heapIndex, uint64_t base, uint64_t size, size_t allocationAlignment); void initExternalWithFrontWindow(uint64_t base, uint64_t size); void initWithFrontWindow(uint64_t base, uint64_t size, uint64_t frontWindowSize); void initFrontWindow(uint64_t base, uint64_t size); diff --git a/shared/test/common/mocks/mock_gfx_partition.h b/shared/test/common/mocks/mock_gfx_partition.h index d2581ee783..e48aea4ad1 100644 --- a/shared/test/common/mocks/mock_gfx_partition.h +++ b/shared/test/common/mocks/mock_gfx_partition.h @@ -68,7 +68,7 @@ class MockGfxPartition : public GfxPartition { } } void initHeap(HeapIndex heapIndex, uint64_t base, uint64_t size, size_t allocationAlignment) { - getHeap(heapIndex).init(base, size, allocationAlignment); + getHeap(heapIndex).init(heapIndex, base, size, allocationAlignment); } uint32_t freeGpuAddressRangeCalled = 0u; diff --git a/shared/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp b/shared/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp index ae8bb1ff97..7f24cd6158 100644 --- a/shared/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp +++ b/shared/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp @@ -876,7 +876,7 @@ HWTEST2_F(MemoryManagerDirectSubmissionImplicitScalingTest, givenDirectSubmissio } } -TEST(MemoryManagerTest, givenDebugVariableToToggleGpuVaBitsWhenAllocatingResourceInHeapExtendedThenSpecificBitIsToggled) { +TEST(MemoryManagerTest, givenDebugVariableToToggleGpuVaBitsWhenAllocatingResourceInHeapExtendedThenCorrectGpuVaIsSet) { if (defaultHwInfo->capabilityTable.gpuAddressSpace < maxNBitValue(57)) { GTEST_SKIP(); } @@ -905,10 +905,7 @@ TEST(MemoryManagerTest, givenDebugVariableToToggleGpuVaBitsWhenAllocatingResourc ASSERT_NE(nullptr, allocation); auto gpuVA = allocation->getGpuAddress(); - - EXPECT_TRUE(isBitSet(gpuVA, 56)); - EXPECT_FALSE(isBitSet(gpuVA, 55)); - EXPECT_TRUE(isBitSet(gpuVA, 32)); + EXPECT_EQ(gpuVA, 0xff0000ffffff0000); memoryManager.freeGraphicsMemory(allocation); } @@ -919,10 +916,7 @@ TEST(MemoryManagerTest, givenDebugVariableToToggleGpuVaBitsWhenAllocatingResourc ASSERT_NE(nullptr, allocation); auto gpuVA = allocation->getGpuAddress(); - - EXPECT_TRUE(isBitSet(gpuVA, 56)); - EXPECT_TRUE(isBitSet(gpuVA, 55)); - EXPECT_TRUE(isBitSet(gpuVA, 32)); + EXPECT_EQ(gpuVA, 0xff8000fffffe0000); memoryManager.freeGraphicsMemory(allocation); } @@ -934,10 +928,7 @@ TEST(MemoryManagerTest, givenDebugVariableToToggleGpuVaBitsWhenAllocatingResourc ASSERT_NE(nullptr, allocation); auto gpuVA = allocation->getGpuAddress(); - - EXPECT_TRUE(isBitSet(gpuVA, 56)); - EXPECT_FALSE(isBitSet(gpuVA, 55)); - EXPECT_FALSE(isBitSet(gpuVA, 32)); + EXPECT_EQ(gpuVA, 0xff0000fefffd0000); memoryManager.freeGraphicsMemory(allocation); } diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index eda9ad94b5..c563fbc47c 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -6717,7 +6717,7 @@ struct DrmMemoryManagerLocalMemoryAlignmentTest : DrmMemoryManagerWithLocalMemor bool isAllocationWithinHeap(MemoryManager &memoryManager, const GraphicsAllocation &allocation, HeapIndex heap) { const auto allocationStart = allocation.getGpuAddress(); - const auto allocationEnd = allocationStart + allocation.getUnderlyingBufferSize(); + const auto allocationEnd = allocationStart + allocation.getUnderlyingBufferSize() - 1; const auto gmmHelper = device->getGmmHelper(); const auto heapStart = gmmHelper->canonize(memoryManager.getGfxPartition(rootDeviceIndex)->getHeapBase(heap)); const auto heapEnd = gmmHelper->canonize(memoryManager.getGfxPartition(rootDeviceIndex)->getHeapLimit(heap));