SWDEV-322620 - Virtual Memory Management

Introducing a VirtualMemObj map as it is needed to differentiate
between virtual address ranges and actual physical memory
This is because a whole VA range can have several physical memories
as chunks.

Change-Id: Ie2a972b4faf3f7d552cfa53e77898f80ad75740a
This commit is contained in:
Christophe Paquot
2022-06-06 11:05:33 -07:00
parent 58aaa8472e
commit 905088e4e7
4 changed files with 60 additions and 4 deletions
+37
View File
@@ -264,6 +264,7 @@ Memory* Device::p2p_stage_ = nullptr;
Monitor MemObjMap::AllocatedLock_ ROCCLR_INIT_PRIORITY(101) ("Guards MemObjMap allocation list");
std::map<uintptr_t, amd::Memory*> MemObjMap::MemObjMap_ ROCCLR_INIT_PRIORITY(101);
std::map<uintptr_t, amd::Memory*> MemObjMap::VirtualMemObjMap_ ROCCLR_INIT_PRIORITY(101);
size_t MemObjMap::size() {
amd::ScopedLock lock(AllocatedLock_);
@@ -306,6 +307,42 @@ amd::Memory* MemObjMap::FindMemObj(const void* k) {
return nullptr;
}
}
void MemObjMap::AddVirtualMemObj(const void* k, amd::Memory* v) {
amd::ScopedLock lock(AllocatedLock_);
auto rval = VirtualMemObjMap_.insert({ reinterpret_cast<uintptr_t>(k), v });
if (!rval.second) {
DevLogPrintfError("Virtual Memobj map already has an entry for ptr: 0x%x",
reinterpret_cast<uintptr_t>(k));
}
}
void MemObjMap::RemoveVirtualMemObj(const void* k) {
amd::ScopedLock lock(AllocatedLock_);
auto rval = VirtualMemObjMap_.erase(reinterpret_cast<uintptr_t>(k));
if (rval != 1) {
DevLogPrintfError("Virtual Memobj map does not have ptr: 0x%x",
reinterpret_cast<uintptr_t>(k));
guarantee(false, "VirtualMemobj map does not have ptr");
}
}
amd::Memory* MemObjMap::FindVirtualMemObj(const void* k) {
amd::ScopedLock lock(AllocatedLock_);
uintptr_t key = reinterpret_cast<uintptr_t>(k);
auto it = VirtualMemObjMap_.upper_bound(key);
if (it == VirtualMemObjMap_.begin()) {
return nullptr;
}
--it;
amd::Memory* mem = it->second;
if (key >= it->first && key < (it->first + mem->getSize())) {
// the k is in the range
return mem;
} else {
return nullptr;
}
}
void MemObjMap::UpdateAccess(amd::Device *peerDev) {
if (peerDev == nullptr) {