Skip to content

Commit

Permalink
[VTA] improved virtual memory mapping (apache#4545)
Browse files Browse the repository at this point in the history
* [VTA] improved virtual memory mapping

* Update virtual_memory.cc
  • Loading branch information
liangfu authored and zhiics committed Jan 11, 2020
1 parent 832eae0 commit 20fa792
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions vta/src/vmem/virtual_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,19 @@ void* VirtualMemoryManager::GetAddr(uint64_t phy_addr) {
vta_phy_addr_t VirtualMemoryManager::GetPhyAddr(void* buf) {
std::lock_guard<std::mutex> lock(mutex_);
auto it = pmap_.find(buf);
CHECK(it != pmap_.end());
uint64_t offset = 0;
if (it == pmap_.end()) {
for (it = pmap_.begin(); it != pmap_.end(); it++) {
uint64_t bytes = it->second->num_pages << kPageBits;
if ((buf >= it->first) && (buf < static_cast<char*>(it->first) + bytes)) {
offset = static_cast<char*>(buf) - static_cast<char*>(it->first);
break;
}
}
CHECK(it != pmap_.end());
}
Page* p = it->second.get();
return (p->ptable_begin + 1) << kPageBits;
return ((p->ptable_begin + 1) << kPageBits) + offset;
}

/*!
Expand Down

0 comments on commit 20fa792

Please sign in to comment.