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 <giacomo.travaglini@arm.com> Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
@@ -39,9 +39,17 @@ namespace gem5
|
||||
{
|
||||
|
||||
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 @@ MemPool::totalPages() const
|
||||
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
|
||||
|
||||
@@ -47,7 +47,10 @@ class MemPool
|
||||
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 @@ class MemPool
|
||||
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 @@ class MemPool
|
||||
Counter allocatedPages() const;
|
||||
Counter freePages() const;
|
||||
|
||||
Addr startAddr() const;
|
||||
Addr allocatedBytes() const;
|
||||
Addr freeBytes() const;
|
||||
Addr totalBytes() const;
|
||||
|
||||
@@ -435,7 +435,7 @@ System::serialize(CheckpointOut &cp) const
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user