mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-22 10:17:01 +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
@@ -101,8 +101,9 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverHw<GfxFamily> {
|
||||
uint32_t aubDeviceId;
|
||||
bool standalone;
|
||||
|
||||
PhysicalAddressAllocator physicalAddressAllocator;
|
||||
std::unique_ptr<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type> ppgtt;
|
||||
PDPE ggtt;
|
||||
std::unique_ptr<PDPE> ggtt;
|
||||
// remap CPU VA -> GGTT VA
|
||||
AddressMapper gttRemap;
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@ AUBCommandStreamReceiverHw<GfxFamily>::AUBCommandStreamReceiverHw(const Hardware
|
||||
stream(std::make_unique<AUBCommandStreamReceiver::AubFileStream>()),
|
||||
subCaptureManager(std::make_unique<AubSubCaptureManager>(fileName)),
|
||||
standalone(standalone),
|
||||
ppgtt(std::make_unique<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type>()) {
|
||||
ppgtt(std::make_unique<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type>(&physicalAddressAllocator)),
|
||||
ggtt(std::make_unique<PDPE>(&physicalAddressAllocator)) {
|
||||
this->dispatchMode = DispatchMode::BatchedDispatch;
|
||||
if (DebugManager.flags.CsrDispatchMode.get()) {
|
||||
this->dispatchMode = (DispatchMode)DebugManager.flags.CsrDispatchMode.get();
|
||||
@@ -138,7 +139,7 @@ void AUBCommandStreamReceiverHw<GfxFamily>::initializeEngine(EngineType engineTy
|
||||
const size_t alignHWSP = 0x1000;
|
||||
engineInfo.pGlobalHWStatusPage = alignedMalloc(sizeHWSP, alignHWSP);
|
||||
engineInfo.ggttHWSP = gttRemap.map(engineInfo.pGlobalHWStatusPage, sizeHWSP);
|
||||
auto physHWSP = ggtt.map(engineInfo.ggttHWSP, sizeHWSP);
|
||||
auto physHWSP = ggtt->map(engineInfo.ggttHWSP, sizeHWSP, PageTableHelper::memoryBankNotSpecified);
|
||||
|
||||
// Write our GHWSP
|
||||
{
|
||||
@@ -169,7 +170,7 @@ void AUBCommandStreamReceiverHw<GfxFamily>::initializeEngine(EngineType engineTy
|
||||
const size_t alignRingBuffer = 0x1000;
|
||||
engineInfo.pRingBuffer = alignedMalloc(engineInfo.sizeRingBuffer, alignRingBuffer);
|
||||
engineInfo.ggttRingBuffer = gttRemap.map(engineInfo.pRingBuffer, engineInfo.sizeRingBuffer);
|
||||
auto physRingBuffer = ggtt.map(engineInfo.ggttRingBuffer, engineInfo.sizeRingBuffer);
|
||||
auto physRingBuffer = ggtt->map(engineInfo.ggttRingBuffer, engineInfo.sizeRingBuffer, PageTableHelper::memoryBankNotSpecified);
|
||||
|
||||
{
|
||||
std::ostringstream str;
|
||||
@@ -197,7 +198,7 @@ void AUBCommandStreamReceiverHw<GfxFamily>::initializeEngine(EngineType engineTy
|
||||
// Write our LRCA
|
||||
{
|
||||
engineInfo.ggttLRCA = gttRemap.map(engineInfo.pLRCA, sizeLRCA);
|
||||
auto lrcAddressPhys = ggtt.map(engineInfo.ggttLRCA, sizeLRCA);
|
||||
auto lrcAddressPhys = ggtt->map(engineInfo.ggttLRCA, sizeLRCA, PageTableHelper::memoryBankNotSpecified);
|
||||
|
||||
{
|
||||
std::ostringstream str;
|
||||
@@ -292,7 +293,7 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
|
||||
stream->addComment(str.str().c_str());
|
||||
}
|
||||
|
||||
auto physBatchBuffer = ppgtt->map(static_cast<uintptr_t>(batchBufferGpuAddress), sizeBatchBuffer);
|
||||
auto physBatchBuffer = ppgtt->map(static_cast<uintptr_t>(batchBufferGpuAddress), sizeBatchBuffer, PageTableHelper::getMemoryBankIndex(*batchBuffer.commandBufferAllocation));
|
||||
AUB::reserveAddressPPGTT(*stream, static_cast<uintptr_t>(batchBufferGpuAddress), sizeBatchBuffer, physBatchBuffer,
|
||||
getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation));
|
||||
|
||||
@@ -343,7 +344,7 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
|
||||
auto sizeToWrap = engineInfo.sizeRingBuffer - engineInfo.tailRingBuffer;
|
||||
memset(pTail, 0, sizeToWrap);
|
||||
// write remaining ring
|
||||
auto physDumpStart = ggtt.map(ggttTail, sizeToWrap);
|
||||
auto physDumpStart = ggtt->map(ggttTail, sizeToWrap, PageTableHelper::memoryBankNotSpecified);
|
||||
AUB::addMemoryWrite(
|
||||
*stream,
|
||||
physDumpStart,
|
||||
@@ -393,7 +394,7 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
|
||||
stream->addComment(str.str().c_str());
|
||||
}
|
||||
|
||||
auto physDumpStart = ggtt.map(ggttDumpStart, dumpLength);
|
||||
auto physDumpStart = ggtt->map(ggttDumpStart, dumpLength, PageTableHelper::memoryBankNotSpecified);
|
||||
AUB::addMemoryWrite(
|
||||
*stream,
|
||||
physDumpStart,
|
||||
@@ -409,7 +410,7 @@ FlushStamp AUBCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
|
||||
stream->addComment(str.str().c_str());
|
||||
}
|
||||
|
||||
auto physLRCA = ggtt.map(engineInfo.ggttLRCA, sizeof(engineInfo.tailRingBuffer));
|
||||
auto physLRCA = ggtt->map(engineInfo.ggttLRCA, sizeof(engineInfo.tailRingBuffer), PageTableHelper::memoryBankNotSpecified);
|
||||
AUB::addMemoryWrite(
|
||||
*stream,
|
||||
physLRCA + 0x101c,
|
||||
@@ -469,12 +470,12 @@ bool AUBCommandStreamReceiverHw<GfxFamily>::addPatchInfoComments() {
|
||||
|
||||
if (patchInfoData.sourceAllocation) {
|
||||
allocationsMap.insert(std::pair<uint64_t, uint64_t>(patchInfoData.sourceAllocation,
|
||||
ppgtt->map(static_cast<uintptr_t>(patchInfoData.sourceAllocation), 1)));
|
||||
ppgtt->map(static_cast<uintptr_t>(patchInfoData.sourceAllocation), 1, PageTableHelper::memoryBankNotSpecified)));
|
||||
}
|
||||
|
||||
if (patchInfoData.targetAllocation) {
|
||||
allocationsMap.insert(std::pair<uint64_t, uintptr_t>(patchInfoData.targetAllocation,
|
||||
ppgtt->map(static_cast<uintptr_t>(patchInfoData.targetAllocation), 1)));
|
||||
ppgtt->map(static_cast<uintptr_t>(patchInfoData.targetAllocation), 1, PageTableHelper::memoryBankNotSpecified)));
|
||||
}
|
||||
}
|
||||
bool result = stream->addComment(str.str().c_str());
|
||||
@@ -560,7 +561,8 @@ bool AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(GraphicsAllocation &gfxA
|
||||
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset) {
|
||||
AUB::reserveAddressGGTTAndWriteMmeory(*stream, static_cast<uintptr_t>(gpuAddress), cpuAddress, physAddress, size, offset, getPPGTTAdditionalBits(&gfxAllocation));
|
||||
};
|
||||
ppgtt->pageWalk(static_cast<uintptr_t>(gpuAddress), size, 0, walker);
|
||||
|
||||
ppgtt->pageWalk(static_cast<uintptr_t>(gpuAddress), size, 0, walker, PageTableHelper::getMemoryBankIndex(gfxAllocation));
|
||||
|
||||
if (gfxAllocation.isLocked()) {
|
||||
this->getMemoryManager()->unlockResource(&gfxAllocation);
|
||||
@@ -665,7 +667,7 @@ void AUBCommandStreamReceiverHw<GfxFamily>::addGUCStartMessage(uint64_t batchBuf
|
||||
miBatchBufferStart->setBatchBufferStartAddressGraphicsaddress472(AUB::ptrToPPGTT(buffer.get()));
|
||||
miBatchBufferStart->setAddressSpaceIndicator(MI_BATCH_BUFFER_START::ADDRESS_SPACE_INDICATOR_PPGTT);
|
||||
|
||||
auto physBufferAddres = ppgtt->map(reinterpret_cast<uintptr_t>(buffer.get()), bufferSize);
|
||||
auto physBufferAddres = ppgtt->map(reinterpret_cast<uintptr_t>(buffer.get()), bufferSize, PageTableHelper::memoryBankNotSpecified);
|
||||
AUB::reserveAddressPPGTT(*stream, reinterpret_cast<uintptr_t>(buffer.get()), bufferSize, physBufferAddres, getPPGTTAdditionalBits(linearStream.getGraphicsAllocation()));
|
||||
|
||||
AUB::addMemoryWrite(
|
||||
|
||||
@@ -93,8 +93,9 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverHw<GfxFamily> {
|
||||
uint32_t aubDeviceId;
|
||||
bool streamInitialized = false;
|
||||
|
||||
TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type ppgtt;
|
||||
PDPE ggtt;
|
||||
PhysicalAddressAllocator physicalAddressAllocator;
|
||||
std::unique_ptr<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type> ppgtt;
|
||||
std::unique_ptr<PDPE> ggtt;
|
||||
// remap CPU VA -> GGTT VA
|
||||
AddressMapper gttRemap;
|
||||
|
||||
|
||||
@@ -35,7 +35,9 @@ namespace OCLRT {
|
||||
template <typename GfxFamily>
|
||||
TbxCommandStreamReceiverHw<GfxFamily>::TbxCommandStreamReceiverHw(const HardwareInfo &hwInfoIn,
|
||||
ExecutionEnvironment &executionEnvironment)
|
||||
: BaseClass(hwInfoIn, executionEnvironment) {
|
||||
: BaseClass(hwInfoIn, executionEnvironment),
|
||||
ppgtt(std::make_unique<TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type>(&physicalAddressAllocator)),
|
||||
ggtt(std::make_unique<PDPE>(&physicalAddressAllocator)) {
|
||||
for (auto &engineInfo : engineInfoTable) {
|
||||
engineInfo.pLRCA = nullptr;
|
||||
engineInfo.ggttLRCA = 0u;
|
||||
@@ -109,7 +111,7 @@ void TbxCommandStreamReceiverHw<GfxFamily>::initializeEngine(EngineType engineTy
|
||||
const size_t alignHWSP = 0x1000;
|
||||
engineInfo.pGlobalHWStatusPage = alignedMalloc(sizeHWSP, alignHWSP);
|
||||
engineInfo.ggttHWSP = gttRemap.map(engineInfo.pGlobalHWStatusPage, sizeHWSP);
|
||||
auto physHWSP = ggtt.map(engineInfo.ggttHWSP, sizeHWSP);
|
||||
auto physHWSP = ggtt->map(engineInfo.ggttHWSP, sizeHWSP, PageTableHelper::memoryBankNotSpecified);
|
||||
|
||||
// Write our GHWSP
|
||||
AubGTTData data = {0};
|
||||
@@ -134,7 +136,7 @@ void TbxCommandStreamReceiverHw<GfxFamily>::initializeEngine(EngineType engineTy
|
||||
const size_t alignRCS = 0x1000;
|
||||
engineInfo.pRCS = alignedMalloc(engineInfo.sizeRCS, alignRCS);
|
||||
engineInfo.ggttRCS = gttRemap.map(engineInfo.pRCS, engineInfo.sizeRCS);
|
||||
auto physRCS = ggtt.map(engineInfo.ggttRCS, engineInfo.sizeRCS);
|
||||
auto physRCS = ggtt->map(engineInfo.ggttRCS, engineInfo.sizeRCS, PageTableHelper::memoryBankNotSpecified);
|
||||
|
||||
AubGTTData data = {0};
|
||||
getGTTData(reinterpret_cast<void *>(physRCS), data);
|
||||
@@ -156,7 +158,7 @@ void TbxCommandStreamReceiverHw<GfxFamily>::initializeEngine(EngineType engineTy
|
||||
// Write our LRCA
|
||||
{
|
||||
engineInfo.ggttLRCA = gttRemap.map(engineInfo.pLRCA, sizeLRCA);
|
||||
auto lrcAddressPhys = ggtt.map(engineInfo.ggttLRCA, sizeLRCA);
|
||||
auto lrcAddressPhys = ggtt->map(engineInfo.ggttLRCA, sizeLRCA, PageTableHelper::memoryBankNotSpecified);
|
||||
|
||||
AubGTTData data = {0};
|
||||
getGTTData(reinterpret_cast<void *>(lrcAddressPhys), data);
|
||||
@@ -206,7 +208,7 @@ FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
|
||||
DEBUG_BREAK_IF(currentOffset < batchBuffer.startOffset);
|
||||
auto sizeBatchBuffer = currentOffset - batchBuffer.startOffset;
|
||||
{
|
||||
auto physBatchBuffer = ppgtt.map(reinterpret_cast<uintptr_t>(pBatchBuffer), sizeBatchBuffer);
|
||||
auto physBatchBuffer = ppgtt->map(reinterpret_cast<uintptr_t>(pBatchBuffer), sizeBatchBuffer, PageTableHelper::getMemoryBankIndex(*batchBuffer.commandBufferAllocation));
|
||||
AUB::reserveAddressPPGTT(stream, reinterpret_cast<uintptr_t>(pBatchBuffer), sizeBatchBuffer, physBatchBuffer, getPPGTTAdditionalBits(batchBuffer.commandBufferAllocation));
|
||||
|
||||
AUB::addMemoryWrite(
|
||||
@@ -240,7 +242,7 @@ FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
|
||||
auto sizeToWrap = engineInfo.sizeRCS - engineInfo.tailRCS;
|
||||
memset(pTail, 0, sizeToWrap);
|
||||
// write remaining ring
|
||||
auto physDumpStart = ggtt.map(ggttTail, sizeToWrap);
|
||||
auto physDumpStart = ggtt->map(ggttTail, sizeToWrap, PageTableHelper::memoryBankNotSpecified);
|
||||
AUB::addMemoryWrite(
|
||||
stream,
|
||||
physDumpStart,
|
||||
@@ -280,7 +282,7 @@ FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
|
||||
auto dumpLength = engineInfo.tailRCS - previousTail;
|
||||
|
||||
// write RCS
|
||||
auto physDumpStart = ggtt.map(ggttDumpStart, dumpLength);
|
||||
auto physDumpStart = ggtt->map(ggttDumpStart, dumpLength, PageTableHelper::memoryBankNotSpecified);
|
||||
AUB::addMemoryWrite(
|
||||
stream,
|
||||
physDumpStart,
|
||||
@@ -290,7 +292,7 @@ FlushStamp TbxCommandStreamReceiverHw<GfxFamily>::flush(BatchBuffer &batchBuffer
|
||||
AubMemDump::DataTypeHintValues::TraceCommandBuffer);
|
||||
|
||||
// update the RCS mmio tail in the LRCA
|
||||
auto physLRCA = ggtt.map(engineInfo.ggttLRCA, sizeof(engineInfo.tailRCS));
|
||||
auto physLRCA = ggtt->map(engineInfo.ggttLRCA, sizeof(engineInfo.tailRCS), PageTableHelper::memoryBankNotSpecified);
|
||||
AUB::addMemoryWrite(
|
||||
stream,
|
||||
physLRCA + 0x101c,
|
||||
@@ -359,8 +361,8 @@ bool TbxCommandStreamReceiverHw<GfxFamily>::writeMemory(GraphicsAllocation &gfxA
|
||||
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset) {
|
||||
AUB::reserveAddressGGTTAndWriteMmeory(stream, static_cast<uintptr_t>(gpuAddress), cpuAddress, physAddress, size, offset, getPPGTTAdditionalBits(&gfxAllocation));
|
||||
};
|
||||
ppgtt.pageWalk(static_cast<uintptr_t>(gpuAddress), size, 0, walker);
|
||||
|
||||
ppgtt->pageWalk(static_cast<uintptr_t>(gpuAddress), size, 0, walker, PageTableHelper::getMemoryBankIndex(gfxAllocation));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -386,8 +388,7 @@ void TbxCommandStreamReceiverHw<GfxFamily>::makeCoherent(GraphicsAllocation &gfx
|
||||
DEBUG_BREAK_IF(offset > length);
|
||||
stream.readMemory(physAddress, ptrOffset(cpuAddress, offset), size);
|
||||
};
|
||||
|
||||
ppgtt.pageWalk(static_cast<uintptr_t>(gpuAddress), length, 0, walker);
|
||||
ppgtt->pageWalk(static_cast<uintptr_t>(gpuAddress), length, 0, walker, PageTableHelper::getMemoryBankIndex(gfxAllocation));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ set(RUNTIME_SRCS_MEMORY_MANAGER
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/page_table.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/page_table.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/page_table.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/physical_address_allocator.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/residency.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/residency.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/residency_container.h
|
||||
|
||||
@@ -25,10 +25,7 @@
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
const uint32_t PTE::initialPage = 1;
|
||||
std::atomic<uint32_t> PTE::nextPage(PTE::initialPage);
|
||||
|
||||
uintptr_t PTE::map(uintptr_t vm, size_t size) {
|
||||
uintptr_t PTE::map(uintptr_t vm, size_t size, uint32_t memoryBank) {
|
||||
const size_t shift = 12;
|
||||
const uint32_t mask = (1 << bits) - 1;
|
||||
size_t indexStart = (vm >> shift) & mask;
|
||||
@@ -37,15 +34,15 @@ uintptr_t PTE::map(uintptr_t vm, size_t size) {
|
||||
|
||||
for (size_t index = indexStart; index <= indexEnd; index++) {
|
||||
if (entries[index] == 0x0) {
|
||||
uint64_t tmp = nextPage.fetch_add(1);
|
||||
entries[index] = reinterpret_cast<void *>(tmp * pageSize | 0x1);
|
||||
uint64_t tmp = allocator->reservePage(memoryBank);
|
||||
entries[index] = reinterpret_cast<void *>(tmp | 0x1);
|
||||
}
|
||||
res = std::min(reinterpret_cast<uintptr_t>(entries[index]) & 0xfffffffeu, res);
|
||||
}
|
||||
return (res & ~0x1) + (vm & (pageSize - 1));
|
||||
}
|
||||
|
||||
void PTE::pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker) {
|
||||
void PTE::pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker, uint32_t memoryBank) {
|
||||
static const uint32_t bits = 9;
|
||||
const size_t shift = 12;
|
||||
const uint32_t mask = (1 << bits) - 1;
|
||||
@@ -56,8 +53,8 @@ void PTE::pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWal
|
||||
|
||||
for (size_t index = indexStart; index <= indexEnd; index++) {
|
||||
if (entries[index] == 0x0) {
|
||||
uint64_t tmp = nextPage.fetch_add(1);
|
||||
entries[index] = reinterpret_cast<void *>(tmp * pageSize | 0x1);
|
||||
uint64_t tmp = allocator->reservePage(memoryBank);
|
||||
entries[index] = reinterpret_cast<void *>(tmp | 0x1);
|
||||
}
|
||||
res = reinterpret_cast<uintptr_t>(entries[index]) & 0xfffffffeu;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "runtime/helpers/basic_math.h"
|
||||
#include "runtime/memory_manager/physical_address_allocator.h"
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
@@ -32,17 +33,32 @@
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
class GraphicsAllocation;
|
||||
|
||||
class PageTableHelper {
|
||||
public:
|
||||
static uint32_t getMemoryBankIndex(GraphicsAllocation &allocation) {
|
||||
return memoryBankNotSpecified;
|
||||
}
|
||||
|
||||
static const uint32_t memoryBankNotSpecified = 0;
|
||||
};
|
||||
|
||||
typedef std::function<void(uint64_t addr, size_t size, size_t offset)> PageWalker;
|
||||
template <class T, uint32_t level, uint32_t bits = 9>
|
||||
class PageTable {
|
||||
public:
|
||||
PageTable() {
|
||||
PageTable(PhysicalAddressAllocator *physicalAddressAllocator) : allocator(physicalAddressAllocator) {
|
||||
entries.fill(nullptr);
|
||||
};
|
||||
virtual ~PageTable();
|
||||
|
||||
virtual uintptr_t map(uintptr_t vm, size_t size);
|
||||
virtual void pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker);
|
||||
virtual ~PageTable() {
|
||||
for (auto &e : entries)
|
||||
delete e;
|
||||
}
|
||||
|
||||
virtual uintptr_t map(uintptr_t vm, size_t size, uint32_t memoryBank);
|
||||
virtual void pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker, uint32_t memoryBank);
|
||||
|
||||
static const size_t pageSize = 1 << 12;
|
||||
static size_t getBits() {
|
||||
@@ -51,26 +67,45 @@ class PageTable {
|
||||
|
||||
protected:
|
||||
std::array<T *, 1 << bits> entries;
|
||||
PhysicalAddressAllocator *allocator = nullptr;
|
||||
};
|
||||
|
||||
template <>
|
||||
inline PageTable<void, 0, 9>::~PageTable() {
|
||||
}
|
||||
|
||||
class PTE : public PageTable<void, 0u> {
|
||||
public:
|
||||
uintptr_t map(uintptr_t vm, size_t size) override;
|
||||
void pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker) override;
|
||||
PTE(PhysicalAddressAllocator *physicalAddressAllocator) : PageTable<void, 0u>(physicalAddressAllocator) {}
|
||||
|
||||
uintptr_t map(uintptr_t vm, size_t size, uint32_t memoryBank) override;
|
||||
void pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker, uint32_t memoryBank) override;
|
||||
|
||||
static const uint32_t level = 0;
|
||||
static const uint32_t bits = 9;
|
||||
static const uint32_t initialPage;
|
||||
};
|
||||
|
||||
protected:
|
||||
static std::atomic<uint32_t> nextPage;
|
||||
};
|
||||
class PDE : public PageTable<class PTE, 1> {
|
||||
public:
|
||||
PDE(PhysicalAddressAllocator *physicalAddressAllocator) : PageTable<class PTE, 1>(physicalAddressAllocator) {
|
||||
}
|
||||
};
|
||||
|
||||
class PDP : public PageTable<class PDE, 2> {
|
||||
public:
|
||||
PDP(PhysicalAddressAllocator *physicalAddressAllocator) : PageTable<class PDE, 2>(physicalAddressAllocator) {
|
||||
}
|
||||
};
|
||||
|
||||
class PML4 : public PageTable<class PDP, 3> {
|
||||
public:
|
||||
PML4(PhysicalAddressAllocator *physicalAddressAllocator) : PageTable<class PDP, 3>(physicalAddressAllocator) {
|
||||
}
|
||||
};
|
||||
|
||||
class PDPE : public PageTable<class PDE, 2, 2> {
|
||||
public:
|
||||
PDPE(PhysicalAddressAllocator *physicalAddressAllocator) : PageTable<class PDE, 2, 2>(physicalAddressAllocator) {
|
||||
}
|
||||
};
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
namespace OCLRT {
|
||||
|
||||
template <>
|
||||
inline uintptr_t PageTable<void, 0, 9>::map(uintptr_t vm, size_t size) {
|
||||
inline uintptr_t PageTable<void, 0, 9>::map(uintptr_t vm, size_t size, uint32_t memoryBank) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -33,15 +33,11 @@ inline size_t PageTable<void, 0, 9>::getBits() {
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void PageTable<void, 0, 9>::pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker) {
|
||||
}
|
||||
|
||||
template <>
|
||||
inline PageTable<void, 0, 9>::~PageTable() {
|
||||
inline void PageTable<void, 0, 9>::pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker, uint32_t memoryBank) {
|
||||
}
|
||||
|
||||
template <class T, uint32_t level, uint32_t bits>
|
||||
inline uintptr_t PageTable<T, level, bits>::map(uintptr_t vm, size_t size) {
|
||||
inline uintptr_t PageTable<T, level, bits>::map(uintptr_t vm, size_t size, uint32_t memoryBank) {
|
||||
const size_t shift = T::getBits() + 12;
|
||||
const uintptr_t mask = (1 << bits) - 1;
|
||||
size_t indexStart = (vm >> shift) & mask;
|
||||
@@ -57,15 +53,15 @@ inline uintptr_t PageTable<T, level, bits>::map(uintptr_t vm, size_t size) {
|
||||
vmEnd = std::min(vmEnd, maskedVm + size - 1);
|
||||
|
||||
if (entries[index] == nullptr) {
|
||||
entries[index] = new T;
|
||||
entries[index] = new T(allocator);
|
||||
}
|
||||
res = std::min((entries[index])->map(vmStart, vmEnd - vmStart + 1), res);
|
||||
res = std::min((entries[index])->map(vmStart, vmEnd - vmStart + 1, memoryBank), res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
template <class T, uint32_t level, uint32_t bits>
|
||||
inline void PageTable<T, level, bits>::pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker) {
|
||||
inline void PageTable<T, level, bits>::pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker, uint32_t memoryBank) {
|
||||
const size_t shift = T::getBits() + 12;
|
||||
const uintptr_t mask = (1 << bits) - 1;
|
||||
size_t indexStart = (vm >> shift) & mask;
|
||||
@@ -80,18 +76,11 @@ inline void PageTable<T, level, bits>::pageWalk(uintptr_t vm, size_t size, size_
|
||||
vmEnd = std::min(vmEnd, maskedVm + size - 1);
|
||||
|
||||
if (entries[index] == nullptr) {
|
||||
entries[index] = new T;
|
||||
entries[index] = new T(allocator);
|
||||
}
|
||||
entries[index]->pageWalk(vmStart, vmEnd - vmStart + 1, offset, pageWalker);
|
||||
entries[index]->pageWalk(vmStart, vmEnd - vmStart + 1, offset, pageWalker, memoryBank);
|
||||
|
||||
offset += (vmEnd - vmStart + 1);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T, uint32_t level, uint32_t bits>
|
||||
inline PageTable<T, level, bits>::~PageTable() {
|
||||
for (auto &e : entries)
|
||||
delete e;
|
||||
}
|
||||
|
||||
} // namespace OCLRT
|
||||
|
||||
46
runtime/memory_manager/physical_address_allocator.h
Normal file
46
runtime/memory_manager/physical_address_allocator.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "runtime/memory_manager/memory_constants.h"
|
||||
#include <atomic>
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
class PhysicalAddressAllocator {
|
||||
public:
|
||||
PhysicalAddressAllocator() {
|
||||
nextPageAddress.store(initialPageAddress);
|
||||
};
|
||||
~PhysicalAddressAllocator() = default;
|
||||
|
||||
uint64_t reservePage(uint32_t memoryBank) {
|
||||
auto address = nextPageAddress.fetch_add(MemoryConstants::pageSize);
|
||||
return address;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::atomic<uint64_t> nextPageAddress;
|
||||
const uint64_t initialPageAddress = 0x1000;
|
||||
};
|
||||
|
||||
} // namespace OCLRT
|
||||
@@ -67,7 +67,7 @@ class AUBCommandStreamFixture : public CommandStreamFixture {
|
||||
size);
|
||||
};
|
||||
|
||||
aubCsr->ppgtt->pageWalk(reinterpret_cast<uintptr_t>(gfxAddress), length, 0, walker);
|
||||
aubCsr->ppgtt->pageWalk(reinterpret_cast<uintptr_t>(gfxAddress), length, 0, walker, PageTableHelper::memoryBankNotSpecified);
|
||||
}
|
||||
|
||||
CommandStreamReceiver *pCommandStreamReceiver = nullptr;
|
||||
|
||||
@@ -1909,13 +1909,16 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe
|
||||
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(*platformDevices[0], "", false, *pDevice->executionEnvironment);
|
||||
memoryManager.reset(aubCsr->createMemoryManager(false, false));
|
||||
|
||||
PhysicalAddressAllocator allocator;
|
||||
struct PpgttMock : TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type {
|
||||
void pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker) override {
|
||||
PpgttMock(PhysicalAddressAllocator *allocator) : TypeSelector<PML4, PDPE, sizeof(void *) == 8>::type(allocator) {}
|
||||
|
||||
void pageWalk(uintptr_t vm, size_t size, size_t offset, PageWalker &pageWalker, uint32_t memoryBank) override {
|
||||
receivedSize = size;
|
||||
}
|
||||
size_t receivedSize = 0;
|
||||
};
|
||||
auto ppgttMock = new PpgttMock();
|
||||
auto ppgttMock = new PpgttMock(&allocator);
|
||||
|
||||
aubCsr->ppgtt.reset(ppgttMock);
|
||||
|
||||
@@ -1940,6 +1943,19 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe
|
||||
memoryManager->freeGraphicsMemory(gfxAllocation);
|
||||
}
|
||||
|
||||
HWTEST_F(AubCommandStreamReceiverTests, whenAubCommandStreamReceiverIsCreatedThenPPGTTAndGGTTCreatedHavePhysicalAddressAllocatorSet) {
|
||||
auto aubCsr = std::make_unique<AUBCommandStreamReceiverHw<FamilyType>>(*platformDevices[0], "", false, *pDevice->executionEnvironment);
|
||||
ASSERT_NE(nullptr, aubCsr->ppgtt.get());
|
||||
ASSERT_NE(nullptr, aubCsr->ggtt.get());
|
||||
|
||||
uintptr_t address = 0x20000;
|
||||
auto physicalAddress = aubCsr->ppgtt->map(address, MemoryConstants::pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(0u, physicalAddress);
|
||||
|
||||
physicalAddress = aubCsr->ggtt->map(address, MemoryConstants::pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(0u, physicalAddress);
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
@@ -333,3 +333,14 @@ HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCsrWhenWaitBeforeMakeNonResidentWhen
|
||||
EXPECT_TRUE(tbxCsr.makeCoherentCalled);
|
||||
EXPECT_EQ(6u, tag);
|
||||
}
|
||||
|
||||
HWTEST_F(TbxCommandSteamSimpleTest, whenTbxCommandStreamReceiverIsCreatedThenPPGTTAndGGTTCreatedHavePhysicalAddressAllocatorSet) {
|
||||
MockTbxCsr<FamilyType> tbxCsr(*platformDevices[0], *pDevice->executionEnvironment);
|
||||
|
||||
uintptr_t address = 0x20000;
|
||||
auto physicalAddress = tbxCsr.ppgtt->map(address, MemoryConstants::pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(0u, physicalAddress);
|
||||
|
||||
physicalAddress = tbxCsr.ggtt->map(address, MemoryConstants::pageSize, PageTableHelper::memoryBankNotSpecified);
|
||||
EXPECT_NE(0u, physicalAddress);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -60,6 +60,7 @@ set(IGDRCL_SRCS_tests_mocks
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_ostime.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_physical_address_allocator.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_program.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_program.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_sampler.h
|
||||
|
||||
32
unit_tests/mocks/mock_physical_address_allocator.h
Normal file
32
unit_tests/mocks/mock_physical_address_allocator.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "runtime/memory_manager/physical_address_allocator.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
class MockPhysicalAddressAllocator : public PhysicalAddressAllocator {
|
||||
public:
|
||||
using PhysicalAddressAllocator::initialPageAddress;
|
||||
using PhysicalAddressAllocator::nextPageAddress;
|
||||
};
|
||||
Reference in New Issue
Block a user