mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-09 22:43:00 +08:00
Add PhysicalAddressAllocator to PageTables
- Allocator is responsible for physical pages allocation Change-Id: I3a9034c87292484da8f4f0eb1d1e0cc5122a4d8a
This commit is contained in:
committed by
sys_ocldev
parent
8df30ceac1
commit
610eda5ad1
@@ -29,6 +29,7 @@ set(IGDRCL_SRCS_tests_memory_manager
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_manager_allocate_in_preferred_pool_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_pool_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/page_table_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/physical_address_allocator_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/surface_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/svm_memory_manager.cpp
|
||||
)
|
||||
|
||||
@@ -20,12 +20,14 @@
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "runtime/helpers/ptr_math.h"
|
||||
#include "runtime/helpers/selectors.h"
|
||||
#include "runtime/memory_manager/page_table.h"
|
||||
#include "runtime/memory_manager/page_table.inl"
|
||||
#include "test.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "unit_tests/helpers/memory_management.h"
|
||||
#include "unit_tests/mocks/mock_physical_address_allocator.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -33,32 +35,6 @@ using namespace OCLRT;
|
||||
|
||||
static const bool is64Bit = (sizeof(void *) == 8);
|
||||
|
||||
class PTEFixture : public PTE {
|
||||
public:
|
||||
const size_t pageSize = 1 << 12;
|
||||
|
||||
void SetUp() {
|
||||
PTE::nextPage.store(PTE::initialPage);
|
||||
startAddress = PTE::initialPage * pageSize;
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
PTE::nextPage.store(PTE::initialPage);
|
||||
}
|
||||
|
||||
uint32_t getNextPage() {
|
||||
return nextPage.load();
|
||||
}
|
||||
|
||||
uint64_t startAddress;
|
||||
};
|
||||
|
||||
typedef Test<PTEFixture> PTETest;
|
||||
TEST_F(PTETest, physicalAddressesInAUBCantStartAt0) {
|
||||
auto physAddress = nextPage.load();
|
||||
EXPECT_NE(0u, physAddress);
|
||||
}
|
||||
|
||||
template <class T, uint32_t level, uint32_t bits = 9>
|
||||
class MockPageTable : public PageTable<T, level, bits> {
|
||||
public:
|
||||
@@ -70,33 +46,43 @@ class MockPTE : public PTE {
|
||||
public:
|
||||
using PTE::entries;
|
||||
|
||||
uintptr_t map(uintptr_t vm, size_t size) override {
|
||||
return PTE::map(vm, size);
|
||||
MockPTE(PhysicalAddressAllocator *physicalAddressAllocator) : PTE(physicalAddressAllocator) {}
|
||||
|
||||
uintptr_t map(uintptr_t vm, size_t size, uint32_t memoryBank) override {
|
||||
return PTE::map(vm, size, memoryBank);
|
||||
}
|
||||
void pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker) override {
|
||||
return PTE::pageWalk(vm, size, offset, pageWalker);
|
||||
void pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker, uint32_t memoryBank) override {
|
||||
return PTE::pageWalk(vm, size, offset, pageWalker, memoryBank);
|
||||
}
|
||||
};
|
||||
|
||||
class MockPDE : public MockPageTable<MockPTE, 1> {
|
||||
public:
|
||||
using MockPageTable<MockPTE, 1>::entries;
|
||||
MockPDE(PhysicalAddressAllocator *physicalAddressAllocator) : MockPageTable<MockPTE, 1>(physicalAddressAllocator) {
|
||||
}
|
||||
};
|
||||
|
||||
class MockPDP : public MockPageTable<MockPDE, 2> {
|
||||
public:
|
||||
using MockPageTable<MockPDE, 2>::entries;
|
||||
MockPDP(PhysicalAddressAllocator *physicalAddressAllocator) : MockPageTable<MockPDE, 2>(physicalAddressAllocator) {
|
||||
}
|
||||
};
|
||||
|
||||
class MockPML4 : public MockPageTable<MockPDP, 3> {
|
||||
public:
|
||||
using MockPageTable<MockPDP, 3>::entries;
|
||||
using PageTable<MockPDP, 3>::allocator;
|
||||
|
||||
MockPML4(PhysicalAddressAllocator *physicalAddressAllocator) : MockPageTable<MockPDP, 3>(physicalAddressAllocator) {
|
||||
}
|
||||
};
|
||||
|
||||
class PPGTTPageTable : public TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type {
|
||||
public:
|
||||
const size_t ppgttEntries = IntSelector<512u, 4u, sizeof(void *) == 8>::value;
|
||||
PPGTTPageTable() {
|
||||
PPGTTPageTable(PhysicalAddressAllocator *allocator) : TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type(allocator) {
|
||||
EXPECT_EQ(ppgttEntries, entries.size());
|
||||
}
|
||||
bool isEmpty() {
|
||||
@@ -109,7 +95,7 @@ class PPGTTPageTable : public TypeSelector<PML4, PDPE, sizeof(void *) == 8>::typ
|
||||
|
||||
class GGTTPageTable : public PDPE {
|
||||
public:
|
||||
GGTTPageTable() {
|
||||
GGTTPageTable(PhysicalAddressAllocator *allocator) : PDPE(allocator) {
|
||||
EXPECT_EQ(4u, entries.size());
|
||||
}
|
||||
bool isEmpty() {
|
||||
@@ -120,17 +106,19 @@ class GGTTPageTable : public PDPE {
|
||||
}
|
||||
};
|
||||
|
||||
class PageTableFixture : public PTEFixture {
|
||||
class PageTableFixture {
|
||||
protected:
|
||||
const size_t pageSize = 1 << 12;
|
||||
const uintptr_t refAddr = (uintptr_t(1) << IntSelector<46, 31, is64Bit>::value);
|
||||
MockPhysicalAddressAllocator allocator;
|
||||
uint64_t startAddress = 0x1000;
|
||||
|
||||
public:
|
||||
void SetUp() {
|
||||
PTEFixture::SetUp();
|
||||
startAddress = 0x1000;
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
PTEFixture::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -140,32 +128,50 @@ typedef Test<PageTableFixture> PageTableTests48;
|
||||
typedef Test<PageTableFixture> PageTableTestsGPU;
|
||||
|
||||
TEST_F(PageTableTests48, dummy) {
|
||||
PageTable<void, 0, 9> pt;
|
||||
PageTable<void, 0, 9> pt(&allocator);
|
||||
|
||||
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset) {
|
||||
};
|
||||
|
||||
pt.pageWalk(0, pageSize, 0, walker);
|
||||
pt.pageWalk(0, pageSize, 0, walker, PageTableHelper::memoryBankNotSpecified);
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests48, newIsEmpty) {
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable);
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable(&allocator));
|
||||
EXPECT_TRUE(pageTable->isEmpty());
|
||||
EXPECT_EQ(PTE::initialPage, this->getNextPage());
|
||||
EXPECT_EQ(allocator.initialPageAddress, allocator.nextPageAddress);
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests48, DISABLED_mapSizeZero) {
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable);
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable(&allocator));
|
||||
EXPECT_TRUE(pageTable->isEmpty());
|
||||
EXPECT_EQ(PTE::initialPage, this->getNextPage());
|
||||
EXPECT_EQ(allocator.initialPageAddress, allocator.nextPageAddress);
|
||||
|
||||
auto phys1 = pageTable->map(0x0, 0x0);
|
||||
auto phys1 = pageTable->map(0x0, 0x0, PageTableHelper::memoryBankNotSpecified);
|
||||
std::cerr << phys1 << std::endl;
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests48, pageWalkSimple) {
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable(&allocator));
|
||||
uintptr_t addr1 = refAddr + (510 * pageSize) + 0x10;
|
||||
size_t lSize = 8 * pageSize;
|
||||
|
||||
size_t walked = 0u;
|
||||
size_t lastOffset = 0;
|
||||
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset) {
|
||||
EXPECT_EQ(lastOffset, offset);
|
||||
EXPECT_GE(pageSize, size);
|
||||
|
||||
walked += size;
|
||||
lastOffset += size;
|
||||
};
|
||||
pageTable->pageWalk(addr1, lSize, 0, walker, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(lSize, walked);
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests48, givenReservedPhysicalAddressWhenPageWalkIsCalledThenPageTablesAreFilledWithProperAddresses) {
|
||||
if (is64Bit) {
|
||||
std::unique_ptr<MockPML4> pageTable(std::make_unique<MockPML4>());
|
||||
std::unique_ptr<MockPML4> pageTable(std::make_unique<MockPML4>(&allocator));
|
||||
|
||||
int shiftPML4 = is64Bit ? (9 + 9 + 9 + 12) : 0;
|
||||
int shiftPDP = is64Bit ? (9 + 9 + 12) : 0;
|
||||
@@ -175,12 +181,12 @@ TEST_F(PageTableTests48, givenReservedPhysicalAddressWhenPageWalkIsCalledThenPag
|
||||
size_t size = 10 * pageSize;
|
||||
|
||||
size_t walked = 0u;
|
||||
auto address = this->getNextPage() * pageSize;
|
||||
auto address = allocator.nextPageAddress.load();
|
||||
|
||||
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset) {
|
||||
walked += size;
|
||||
};
|
||||
pageTable->pageWalk(gpuVa, size, 0, walker);
|
||||
pageTable->pageWalk(gpuVa, size, 0, walker, PageTableHelper::memoryBankNotSpecified);
|
||||
|
||||
EXPECT_EQ(size, walked);
|
||||
|
||||
@@ -195,171 +201,175 @@ TEST_F(PageTableTests48, givenReservedPhysicalAddressWhenPageWalkIsCalledThenPag
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests48, pageWalkSimple) {
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable);
|
||||
uintptr_t addr1 = refAddr + (510 * pageSize) + 0x10;
|
||||
size_t lSize = 8 * pageSize;
|
||||
TEST_F(PageTableTests48, givenPageTableWhenMappingTheSameAddressMultipleTimesThenNumberOfPagesReservedInAllocatorMatchPagesMapped) {
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable(&allocator));
|
||||
uintptr_t address = refAddr;
|
||||
|
||||
size_t walked = 0u;
|
||||
size_t lastOffset = 0;
|
||||
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset) {
|
||||
EXPECT_EQ(lastOffset, offset);
|
||||
EXPECT_GE(pageSize, size);
|
||||
auto initialAddress = allocator.initialPageAddress;
|
||||
|
||||
walked += size;
|
||||
lastOffset += size;
|
||||
};
|
||||
pageTable->pageWalk(addr1, lSize, 0, walker);
|
||||
EXPECT_EQ(lSize, walked);
|
||||
auto phys1 = pageTable->map(address, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress, phys1);
|
||||
|
||||
auto phys1_1 = pageTable->map(address, 1, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress, phys1_1);
|
||||
|
||||
auto phys2 = pageTable->map(address, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(phys1, phys2);
|
||||
|
||||
address = ptrOffset(address, pageSize);
|
||||
auto phys3 = pageTable->map(address, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(phys1, phys3);
|
||||
|
||||
address = ptrOffset(address, pageSize);
|
||||
auto phys4 = pageTable->map(address, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(phys3, phys4);
|
||||
|
||||
auto nextFreeAddress = initialAddress + ptrDiff(phys4 + pageSize, initialAddress);
|
||||
|
||||
EXPECT_EQ(nextFreeAddress, allocator.nextPageAddress.load());
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests48, physicalAddressesInAUBCantStartAt0) {
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable(&allocator));
|
||||
uintptr_t addr1 = refAddr;
|
||||
|
||||
auto phys1 = pageTable->map(addr1, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(0u, phys1);
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests48, mapPageMapByteInMapped) {
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable);
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable(&allocator));
|
||||
uintptr_t addr1 = refAddr;
|
||||
|
||||
auto phys1 = pageTable->map(addr1, pageSize);
|
||||
auto phys1 = pageTable->map(addr1, pageSize, 0);
|
||||
EXPECT_EQ(startAddress, phys1);
|
||||
EXPECT_EQ(PTE::initialPage + 1u, this->getNextPage());
|
||||
EXPECT_EQ(allocator.initialPageAddress + pageSize, allocator.nextPageAddress);
|
||||
|
||||
auto phys1_1 = pageTable->map(addr1, 1);
|
||||
auto phys1_1 = pageTable->map(addr1, 1, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress, phys1_1);
|
||||
EXPECT_EQ(PTE::initialPage + 1u, this->getNextPage());
|
||||
EXPECT_EQ(allocator.initialPageAddress + pageSize, allocator.nextPageAddress);
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests48, mapsCorrectlyEvenMultipleCalls) {
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable);
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable(&allocator));
|
||||
uintptr_t addr1 = refAddr;
|
||||
|
||||
auto phys1 = pageTable->map(addr1, pageSize);
|
||||
auto phys1 = pageTable->map(addr1, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress, phys1);
|
||||
EXPECT_EQ(PTE::initialPage + 1u, this->getNextPage());
|
||||
EXPECT_EQ(allocator.initialPageAddress + pageSize, allocator.nextPageAddress);
|
||||
|
||||
auto phys1_1 = pageTable->map(addr1, 1);
|
||||
auto phys1_1 = pageTable->map(addr1, 1, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress, phys1_1);
|
||||
EXPECT_EQ(PTE::initialPage + 1u, this->getNextPage());
|
||||
EXPECT_EQ(allocator.initialPageAddress + pageSize, allocator.nextPageAddress);
|
||||
|
||||
auto phys2 = pageTable->map(addr1, pageSize);
|
||||
auto phys2 = pageTable->map(addr1, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(phys1, phys2);
|
||||
EXPECT_EQ(PTE::initialPage + 1u, this->getNextPage());
|
||||
EXPECT_EQ(allocator.initialPageAddress + pageSize, allocator.nextPageAddress);
|
||||
|
||||
auto phys3 = pageTable->map(addr1 + pageSize, pageSize);
|
||||
auto phys3 = pageTable->map(addr1 + pageSize, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(phys1, phys3);
|
||||
EXPECT_EQ(PTE::initialPage + 2u, this->getNextPage());
|
||||
EXPECT_EQ(allocator.initialPageAddress + 2 * pageSize, allocator.nextPageAddress);
|
||||
|
||||
auto phys4 = pageTable->map(addr1 + pageSize, pageSize);
|
||||
auto phys4 = pageTable->map(addr1 + pageSize, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(phys1, phys3);
|
||||
EXPECT_EQ(phys3, phys4);
|
||||
EXPECT_EQ(PTE::initialPage + 2u, this->getNextPage());
|
||||
|
||||
auto addr2 = addr1 + pageSize + pageSize;
|
||||
auto phys5 = pageTable->map(addr2, 2 * pageSize);
|
||||
auto phys5 = pageTable->map(addr2, 2 * pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(phys1, phys5);
|
||||
EXPECT_NE(phys3, phys5);
|
||||
EXPECT_EQ(PTE::initialPage + 4u, this->getNextPage());
|
||||
|
||||
auto phys6 = pageTable->map(addr2, 2 * pageSize);
|
||||
auto phys6 = pageTable->map(addr2, 2 * pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(phys1, phys6);
|
||||
EXPECT_NE(phys3, phys6);
|
||||
EXPECT_EQ(phys5, phys6);
|
||||
EXPECT_EQ(PTE::initialPage + 4u, this->getNextPage());
|
||||
|
||||
auto phys7 = pageTable->map(addr2 + pageSize, pageSize);
|
||||
auto phys7 = pageTable->map(addr2 + pageSize, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(0u, phys7);
|
||||
EXPECT_NE(phys1, phys7);
|
||||
EXPECT_NE(phys3, phys7);
|
||||
EXPECT_NE(phys5, phys7);
|
||||
EXPECT_NE(phys6, phys7);
|
||||
EXPECT_EQ(phys6 + pageSize, phys7);
|
||||
EXPECT_EQ(PTE::initialPage + 4u, this->getNextPage());
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests48, mapsPagesOnTableBoundary) {
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable);
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable(&allocator));
|
||||
uintptr_t addr1 = refAddr + pageSize * 16;
|
||||
size_t pages = (1 << 9) * 2;
|
||||
size_t size = pages * pageSize;
|
||||
|
||||
auto phys1 = pageTable->map(addr1, size);
|
||||
auto phys1 = pageTable->map(addr1, size, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress, phys1);
|
||||
EXPECT_EQ(PTE::initialPage + 1024u, this->getNextPage());
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests48, mapsPagesOnTableBoundary2ndAllocation) {
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable);
|
||||
std::unique_ptr<PPGTTPageTable> pageTable(new PPGTTPageTable(&allocator));
|
||||
uintptr_t addr1 = refAddr + pageSize * 16;
|
||||
size_t pages = (1 << 9) * 2;
|
||||
size_t size = pages * pageSize;
|
||||
|
||||
auto phys1 = pageTable->map(0x0, pageSize);
|
||||
auto phys1 = pageTable->map(0x0, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress, phys1);
|
||||
EXPECT_EQ(PTE::initialPage + 1u, this->getNextPage());
|
||||
|
||||
auto phys2 = pageTable->map(addr1, size);
|
||||
auto phys2 = pageTable->map(addr1, size, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress + pageSize, phys2);
|
||||
EXPECT_EQ(PTE::initialPage + 1025u, this->getNextPage());
|
||||
}
|
||||
|
||||
TEST_F(PageTableTestsGPU, mapsPagesOnTableBoundary) {
|
||||
std::unique_ptr<GGTTPageTable> ggtt(new GGTTPageTable);
|
||||
std::unique_ptr<PPGTTPageTable> ppgtt(new PPGTTPageTable);
|
||||
std::unique_ptr<GGTTPageTable> ggtt(new GGTTPageTable(&allocator));
|
||||
std::unique_ptr<PPGTTPageTable> ppgtt(new PPGTTPageTable(&allocator));
|
||||
uintptr_t addrGGTT = 0x70000000 + pageSize * 16;
|
||||
uintptr_t addrPPGTT = refAddr + pageSize * 16;
|
||||
|
||||
size_t pages = (1 << 9) * 2;
|
||||
size_t size = pages * pageSize;
|
||||
|
||||
auto phys32 = ggtt->map(addrGGTT, size);
|
||||
auto phys32 = ggtt->map(addrGGTT, size, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress, phys32);
|
||||
EXPECT_EQ(PTE::initialPage + 1024u, this->getNextPage());
|
||||
|
||||
auto phys48 = ppgtt->map(addrPPGTT, size);
|
||||
auto phys48 = ppgtt->map(addrPPGTT, size, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress + size, phys48);
|
||||
EXPECT_EQ(PTE::initialPage + 2048u, this->getNextPage());
|
||||
}
|
||||
|
||||
TEST_F(PageTableTestsGPU, newIsEmpty) {
|
||||
std::unique_ptr<GGTTPageTable> ggtt(new GGTTPageTable);
|
||||
std::unique_ptr<GGTTPageTable> ggtt(new GGTTPageTable(&allocator));
|
||||
EXPECT_TRUE(ggtt->isEmpty());
|
||||
EXPECT_EQ(PTE::initialPage, this->getNextPage());
|
||||
std::unique_ptr<PPGTTPageTable> ppgtt(new PPGTTPageTable);
|
||||
|
||||
std::unique_ptr<PPGTTPageTable> ppgtt(new PPGTTPageTable(&allocator));
|
||||
EXPECT_TRUE(ppgtt->isEmpty());
|
||||
EXPECT_EQ(PTE::initialPage, this->getNextPage());
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests32, level0) {
|
||||
std::unique_ptr<PageTable<void, 0, 9>> pt(new PageTable<void, 0, 9>());
|
||||
auto phys = pt->map(0x10000, pageSize);
|
||||
std::unique_ptr<PageTable<void, 0, 9>> pt(new PageTable<void, 0, 9>(&allocator));
|
||||
auto phys = pt->map(0x10000, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(0u, phys);
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests32, newIsEmpty) {
|
||||
std::unique_ptr<GGTTPageTable> pageTable(new GGTTPageTable);
|
||||
std::unique_ptr<GGTTPageTable> pageTable(new GGTTPageTable(&allocator));
|
||||
EXPECT_TRUE(pageTable->isEmpty());
|
||||
EXPECT_EQ(PTE::initialPage, this->getNextPage());
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests32, mapsPagesOnTableBoundary) {
|
||||
std::unique_ptr<GGTTPageTable> pageTable(new GGTTPageTable);
|
||||
std::unique_ptr<GGTTPageTable> pageTable(new GGTTPageTable(&allocator));
|
||||
uintptr_t addr1 = 0x70000000 + pageSize * 16;
|
||||
size_t pages = (1 << 9) * 2;
|
||||
size_t size = pages * pageSize;
|
||||
|
||||
auto phys1 = pageTable->map(addr1, size);
|
||||
auto phys1 = pageTable->map(addr1, size, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress, phys1);
|
||||
EXPECT_EQ(PTE::initialPage + 1024u, this->getNextPage());
|
||||
}
|
||||
|
||||
TEST_F(PageTableTests32, mapsPagesOnTableBoundary2ndAllocation) {
|
||||
std::unique_ptr<GGTTPageTable> pageTable(new GGTTPageTable);
|
||||
std::unique_ptr<GGTTPageTable> pageTable(new GGTTPageTable(&allocator));
|
||||
uintptr_t addr1 = 0x70000000 + pageSize * 16;
|
||||
size_t pages = (1 << 9) * 2;
|
||||
size_t size = pages * pageSize;
|
||||
|
||||
auto phys1 = pageTable->map(0x0, pageSize);
|
||||
auto phys1 = pageTable->map(0x0, pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress, phys1);
|
||||
EXPECT_EQ(PTE::initialPage + 1u, this->getNextPage());
|
||||
|
||||
auto phys2 = pageTable->map(addr1, size);
|
||||
auto phys2 = pageTable->map(addr1, size, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_EQ(startAddress + pageSize, phys2);
|
||||
EXPECT_EQ(PTE::initialPage + 1025u, this->getNextPage());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "runtime/memory_manager/page_table.h"
|
||||
#include "unit_tests/mocks/mock_physical_address_allocator.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
TEST(PhysicalAddressAllocator, givenPhysicalAddressesAllocatorWhenReservingFirstPageThenNonZeroAddressIsReturned) {
|
||||
MockPhysicalAddressAllocator allocator;
|
||||
auto physAddress = allocator.reservePage(PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(0u, physAddress);
|
||||
}
|
||||
|
||||
TEST(PhysicalAddressAllocator, givenPhysicalAddressesAllocatorWhenReservingConsecutivePagesThenReturnedAddressesAreDifferent) {
|
||||
MockPhysicalAddressAllocator allocator;
|
||||
|
||||
auto physAddress = allocator.reservePage(PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(0u, physAddress);
|
||||
auto physAddress1 = allocator.reservePage(PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(physAddress, physAddress1);
|
||||
auto physAddress2 = allocator.reservePage(PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(physAddress1, physAddress2);
|
||||
}
|
||||
Reference in New Issue
Block a user