Gabe Black has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/50757 )
Change subject: sim: Align process memory allocations.
......................................................................
sim: Align process memory allocations.
Align allocation requests in Process::allocateMem to page boundaries,
rather than assume that they already are. This frees the caller from
having to know what boundary to align things to. The older version would
make the caller more aware of the extent of the allocation in theory,
but in reality the caller would just blindly perform the alignment like
this function is anyway.
Change-Id: I897714d4481d961255a9e44ae080135e507be199
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/50757
Reviewed-by: Matthew Poremba <[email protected]>
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/sim/process.cc
M src/sim/process.hh
2 files changed, 42 insertions(+), 5 deletions(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
Matthew Poremba: Looks good to me, but someone else must approve
kokoro: Regressions pass
diff --git a/src/sim/process.cc b/src/sim/process.cc
index 71bb494..3a631a5 100644
--- a/src/sim/process.cc
+++ b/src/sim/process.cc
@@ -316,6 +316,10 @@
void
Process::allocateMem(Addr vaddr, int64_t size, bool clobber)
{
+ const auto page_size = pTable->pageSize();
+
+ const Addr page_addr = roundDown(vaddr, page_size);
+
// Check if the page has been mapped by other cores if not to clobber.
// When running multithreaded programs in SE-mode with DerivO3CPU
model,
// there are cases where two or more cores have page faults on the same
@@ -324,16 +328,17 @@
// a physical page frame to map with the virtual page. Other cores can
// return if the page has been mapped and `!clobber`.
if (!clobber) {
- const EmulationPageTable::Entry *pte = pTable->lookup(vaddr);
+ const EmulationPageTable::Entry *pte = pTable->lookup(page_addr);
if (pte) {
warn("Process::allocateMem: addr %#x already mapped\n", vaddr);
return;
}
}
- int npages = divCeil(size, pTable->pageSize());
- Addr paddr = seWorkload->allocPhysPages(npages);
- pTable->map(vaddr, paddr, size,
+ const int npages = divCeil(size, page_size);
+ const Addr paddr = seWorkload->allocPhysPages(npages);
+ const Addr pages_size = npages * page_size;
+ pTable->map(page_addr, paddr, pages_size,
clobber ? EmulationPageTable::Clobber :
EmulationPageTable::MappingFlags(0));
}
diff --git a/src/sim/process.hh b/src/sim/process.hh
index 880b34b..cece212 100644
--- a/src/sim/process.hh
+++ b/src/sim/process.hh
@@ -108,7 +108,18 @@
Addr getStartPC();
loader::ObjectFile *getInterpreter();
- void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
+ // This function allocates physical memory as backing store, and then
maps
+ // it into the virtual address space of the process. The range of
virtual
+ // addresses being configured starts at the address "vaddr" and is of
size
+ // "size" bytes. If some part of this range of virtual addresses is
already
+ // configured, this function will error out unless "clobber" is set. If
+ // clobber is set, then those existing mappings will be replaced.
+ //
+ // If the beginning or end of the virtual address range does not
perfectly
+ // align to page boundaries, it will be expanded in either direction
until
+ // it does. This function will therefore set up *at least* the range
+ // requested, and may configure more if necessary.
+ void allocateMem(Addr vaddr, int64_t size, bool clobber=false);
/// Attempt to fix up a fault at vaddr by allocating a page on the
stack.
/// @return Whether the fault has been fixed.
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/50757
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I897714d4481d961255a9e44ae080135e507be199
Gerrit-Change-Number: 50757
Gerrit-PatchSet: 8
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Matthew Poremba <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s