Skip to content

Commit 9d37e7b

Browse files
fix: Adjust standard heaps when on 57 bit address space
Resolves: GSD-10871 Signed-off-by: Lukasz Jobczyk <[email protected]> Source: 1b5519a
1 parent 5d81f3a commit 9d37e7b

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

shared/source/memory_manager/gfx_partition.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 Intel Corporation
2+
* Copyright (C) 2019-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -296,6 +296,14 @@ bool GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe
296296

297297
gfxBase = alignUp(gfxBase, maxStandardHeapGranularity);
298298
uint64_t maxStandardHeapSize = alignDown((gfxTop - gfxBase) / numStandardHeaps, maxStandardHeapGranularity);
299+
uint64_t maxStandard64HeapSize = maxStandardHeapSize;
300+
uint64_t maxStandard2MBHeapSize = maxStandardHeapSize;
301+
302+
if (gpuAddressSpace == maxNBitValue(57)) {
303+
maxStandardHeapSize *= 2;
304+
maxStandard64HeapSize /= 2;
305+
maxStandard2MBHeapSize /= 2;
306+
}
299307

300308
auto gfxStandardSize = maxStandardHeapSize;
301309
heapInit(HeapIndex::heapStandard, gfxBase, gfxStandardSize);
@@ -304,14 +312,14 @@ bool GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe
304312
gfxBase += maxStandardHeapSize;
305313

306314
// Split HEAP_STANDARD64K among root devices
307-
auto gfxStandard64KBSize = alignDown(maxStandardHeapSize / numRootDevices, GfxPartition::heapGranularity);
315+
auto gfxStandard64KBSize = alignDown(maxStandard64HeapSize / numRootDevices, GfxPartition::heapGranularity);
308316
heapInitWithAllocationAlignment(HeapIndex::heapStandard64KB, gfxBase + rootDeviceIndex * gfxStandard64KBSize, gfxStandard64KBSize, MemoryConstants::pageSize64k);
309317
DEBUG_BREAK_IF(!isAligned<GfxPartition::heapGranularity>(getHeapBase(HeapIndex::heapStandard64KB)));
310318

311-
gfxBase += maxStandardHeapSize;
319+
gfxBase += maxStandard64HeapSize;
312320

313321
// Split HEAP_STANDARD2MB among root devices
314-
auto gfxStandard2MBSize = alignDown(maxStandardHeapSize / numRootDevices, GfxPartition::heapGranularity2MB);
322+
auto gfxStandard2MBSize = alignDown(maxStandard2MBHeapSize / numRootDevices, GfxPartition::heapGranularity2MB);
315323
heapInitWithAllocationAlignment(HeapIndex::heapStandard2MB, gfxBase + rootDeviceIndex * gfxStandard2MBSize, gfxStandard2MBSize, 2 * MemoryConstants::megaByte);
316324
DEBUG_BREAK_IF(!isAligned<GfxPartition::heapGranularity2MB>(getHeapBase(HeapIndex::heapStandard2MB)));
317325

shared/test/unit_test/memory_manager/gfx_partition_tests.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 Intel Corporation
2+
* Copyright (C) 2019-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -557,14 +557,20 @@ struct GfxPartitionOn57bTest : public ::testing::Test {
557557

558558
gfxBase = alignUp(gfxBase, maxStandardHeapGranularity);
559559
uint64_t maxStandardHeapSize = alignDown((gfxTop - gfxBase) / numStandardHeaps, maxStandardHeapGranularity);
560+
uint64_t maxStandard64HeapSize = maxStandardHeapSize;
561+
562+
if (expectHeapExtendedInitialized) {
563+
maxStandardHeapSize *= 2;
564+
maxStandard64HeapSize /= 2;
565+
}
560566

561567
EXPECT_EQ(gfxBase, gfxPartition->getHeapBase(HeapIndex::heapStandard));
562568
EXPECT_EQ(gfxBase + maxStandardHeapSize - 1, gfxPartition->getHeapLimit(HeapIndex::heapStandard));
563569

564570
gfxBase += maxStandardHeapSize;
565571

566572
EXPECT_EQ(gfxBase, gfxPartition->getHeapBase(HeapIndex::heapStandard64KB));
567-
EXPECT_EQ(gfxBase + maxStandardHeapSize - 1, gfxPartition->getHeapLimit(HeapIndex::heapStandard64KB));
573+
EXPECT_EQ(gfxBase + maxStandard64HeapSize - 1, gfxPartition->getHeapLimit(HeapIndex::heapStandard64KB));
568574

569575
if (expectHeapExtendedInitialized) {
570576
EXPECT_TRUE(gfxPartition->heapInitialized(HeapIndex::heapExtended));
@@ -832,6 +838,23 @@ TEST_F(GfxPartitionOn57bTest, given57bitCpuAddressWidthAndLa57IsPresentWhenIniti
832838
EXPECT_FALSE(gfxPartition->init(maxNBitValue(gpuAddressSpace), 0, 0, 1, false, 0u, gfxTop));
833839
}
834840

841+
TEST_F(GfxPartitionOn57bTest, whenInitGfxPartitionThenDoubleHeapStandardAtTheCostOfStandard64AndStandard2MB) {
842+
if (is32bit) {
843+
GTEST_SKIP();
844+
}
845+
846+
auto gpuAddressSpace = 57;
847+
uint64_t gfxTop = maxNBitValue(gpuAddressSpace) + 1;
848+
OSMemory::ReservedCpuAddressRange reservedCpuAddressRange;
849+
std::vector<std::unique_ptr<MockGfxPartition>> gfxPartitions;
850+
gfxPartitions.push_back(std::make_unique<MockGfxPartition>(reservedCpuAddressRange));
851+
gfxPartitions[0]->osMemory.reset(new MockOsMemory);
852+
EXPECT_TRUE(gfxPartitions[0]->init(maxNBitValue(gpuAddressSpace), 0, 0, 1, false, 0u, gfxTop));
853+
854+
EXPECT_EQ(gfxPartitions[0]->getHeapSize(HeapIndex::heapStandard), 4 * gfxPartitions[0]->getHeapSize(HeapIndex::heapStandard64KB));
855+
EXPECT_EQ(gfxPartitions[0]->getHeapSize(HeapIndex::heapStandard), 4 * gfxPartitions[0]->getHeapSize(HeapIndex::heapStandard2MB));
856+
}
857+
835858
TEST_F(GfxPartitionOn57bTest, given48bitGpuAddressSpaceAnd57bitCpuAddressWidthWhenInitializingMultipleGfxPartitionsThenReserveSpaceForSvmHeapOnlyOnce) {
836859
if (is32bit) {
837860
GTEST_SKIP();

0 commit comments

Comments
 (0)