Gabe Black has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/50687 )
Change subject: sim: Fix a faulty assumption in MemPool.
......................................................................
sim: Fix a faulty assumption in MemPool.
In the MemPool object, the idea of a limit of the pool (largest page)
and the total number of pages were conflated, as was the page number of
the next "free" page and the total number of pages allocated. Both of
those would only be equivalent if the memory pool starts at address
zero, which is not generally true and could be true for at most one pool
at a time even when it is occasionally true.
Instead, this change fixes up MemPool to keep tree values, a starting
page number, the page number of the next free page, and the total number
of pages in the pool, both allocated and unallocated.
With those three values, we can accurately report the number of
allocated pages (not just the number of pages of any kind below the next
free one), the total number of free pages, and the total number of pages
in general (not the largest numbered page in the pool).
The value serialized by the System class was adjusted so that it will
stay compatible with previous checkpoints. The value unserialized by the
system class is passed to the MemPool as a limit, which has not changed
and so doesn't need to be updated. It gets translated into the total
number of pages in the MemPool constructor.
Change-Id: I8268ef410b41bf757df9ee5585ec2f6b0d8499e1
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/50687
Reviewed-by: Giacomo Travaglini <[email protected]>
Maintainer: Giacomo Travaglini <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/sim/mem_pool.cc
M src/sim/mem_pool.hh
M src/sim/system.cc
3 files changed, 60 insertions(+), 6 deletions(-)
Approvals:
Giacomo Travaglini: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/sim/mem_pool.cc b/src/sim/mem_pool.cc
index f568e28..bde3e67 100644
--- a/src/sim/mem_pool.cc
+++ b/src/sim/mem_pool.cc
@@ -39,9 +39,17 @@
{
MemPool::MemPool(Addr page_shift, Addr ptr, Addr limit)
- : pageShift(page_shift), freePageNum(ptr >> page_shift),
- _totalPages(limit >> page_shift)
+ : pageShift(page_shift), startPageNum(ptr >> page_shift),
+ freePageNum(ptr >> page_shift),
+ _totalPages((limit - ptr) >> page_shift)
{
+ gem5_assert(_totalPages > 0);
+}
+
+Counter
+MemPool::startPage() const
+{
+ return startPageNum;
}
Counter
@@ -71,13 +79,19 @@
Counter
MemPool::allocatedPages() const
{
- return freePageNum;
+ return freePageNum - startPageNum;
}
Counter
MemPool::freePages() const
{
- return _totalPages - freePageNum;
+ return _totalPages - allocatedPages();
+}
+
+Addr
+MemPool::startAddr() const
+{
+ return startPage() << pageShift;
}
Addr
diff --git a/src/sim/mem_pool.hh b/src/sim/mem_pool.hh
index 49523f4..3cba3b6 100644
--- a/src/sim/mem_pool.hh
+++ b/src/sim/mem_pool.hh
@@ -47,7 +47,10 @@
private:
Addr pageShift;
- /** Page number to free memory. */
+ /** Start page of pool. */
+ Counter startPageNum;
+
+ /** Page number of free memory. */
Counter freePageNum;
/** The size of the pool, in number of pages. */
@@ -56,6 +59,7 @@
public:
MemPool(Addr page_shift, Addr ptr, Addr limit);
+ Counter startPage() const;
Counter freePage() const;
void setFreePage(Counter value);
Addr freePageAddr() const;
@@ -64,6 +68,7 @@
Counter allocatedPages() const;
Counter freePages() const;
+ Addr startAddr() const;
Addr allocatedBytes() const;
Addr freeBytes() const;
Addr totalBytes() const;
diff --git a/src/sim/system.cc b/src/sim/system.cc
index 3895276..225262a 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -435,7 +435,7 @@
for (const auto& memPool : memPools) {
ptrs.push_back(memPool.freePageAddr());
- limits.push_back(memPool.totalBytes());
+ limits.push_back(memPool.totalBytes() + memPool.startAddr());
}
SERIALIZE_CONTAINER(ptrs);
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/50687
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: I8268ef410b41bf757df9ee5585ec2f6b0d8499e1
Gerrit-Change-Number: 50687
Gerrit-PatchSet: 4
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Alex Dutu <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Hoa Nguyen <[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