Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/50340 )

Change subject: sim: Move serialization logic for MemPools out of System.
......................................................................

sim: Move serialization logic for MemPools out of System.

And move it into the MemPools class itself. The MemPools class should be
self contained, and be able to manage its own state. That should not be
the responsibility of another containing class.

Change-Id: Ib0bf70b57e92698f15bea0cc217dd98ee816d57b
---
M src/sim/mem_pool.cc
M src/sim/mem_pool.hh
M src/sim/system.cc
3 files changed, 39 insertions(+), 21 deletions(-)



diff --git a/src/sim/mem_pool.cc b/src/sim/mem_pool.cc
index f568e28..ad68a6b 100644
--- a/src/sim/mem_pool.cc
+++ b/src/sim/mem_pool.cc
@@ -110,4 +110,20 @@
     return return_addr;
 }

+void
+MemPool::serialize(CheckpointOut &cp) const
+{
+    paramOut(cp, "page_shift", pageShift);
+    paramOut(cp, "free_page_num", freePageNum);
+    paramOut(cp, "total_pages", _totalPages);
+}
+
+void
+MemPool::unserialize(CheckpointIn &cp)
+{
+    paramIn(cp, "page_shift", pageShift);
+    paramIn(cp, "free_page_num", freePageNum);
+    paramIn(cp, "total_pages", _totalPages);
+}
+
 } // namespace gem5
diff --git a/src/sim/mem_pool.hh b/src/sim/mem_pool.hh
index 49523f4..2402d74 100644
--- a/src/sim/mem_pool.hh
+++ b/src/sim/mem_pool.hh
@@ -35,6 +35,7 @@
 #define __MEM_POOL_HH__

 #include "base/types.hh"
+#include "sim/serialize.hh"

 namespace gem5
 {
@@ -42,18 +43,20 @@
 class System;

 /** Class for handling allocation of physical pages in SE mode. */
-class MemPool
+class MemPool : public Serializable
 {
   private:
-    Addr pageShift;
+    Addr pageShift = 0;

     /** Page number to free memory. */
-    Counter freePageNum;
+    Counter freePageNum = 0;

     /** The size of the pool, in number of pages. */
-    Counter _totalPages;
+    Counter _totalPages = 0;

   public:
+    MemPool() {}
+
     MemPool(Addr page_shift, Addr ptr, Addr limit);

     Counter freePage() const;
@@ -69,6 +72,9 @@
     Addr totalBytes() const;

     Addr allocate(Addr npages);
+
+    void serialize(CheckpointOut &cp) const override;
+    void unserialize(CheckpointIn &cp) override;
 };

 } // namespace gem5
diff --git a/src/sim/system.cc b/src/sim/system.cc
index 3895276..5196c71 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -44,6 +44,7 @@
 #include <algorithm>

 #include "base/compiler.hh"
+#include "base/cprintf.hh"
 #include "base/loader/object_file.hh"
 #include "base/loader/symtab.hh"
 #include "base/str.hh"
@@ -68,6 +69,7 @@
 #include "sim/debug.hh"
 #include "sim/full_system.hh"
 #include "sim/redirect_path.hh"
+#include "sim/serialize_handlers.hh"

 namespace gem5
 {
@@ -430,16 +432,11 @@
         paramOut(cp, csprintf("quiesceEndTick_%d", id), when);
     }

-    std::vector<Addr> ptrs;
-    std::vector<Addr> limits;
+    int num_mem_pools = memPools.size();
+    SERIALIZE_SCALAR(num_mem_pools);

-    for (const auto& memPool : memPools) {
-        ptrs.push_back(memPool.freePageAddr());
-        limits.push_back(memPool.totalBytes());
-    }
-
-    SERIALIZE_CONTAINER(ptrs);
-    SERIALIZE_CONTAINER(limits);
+    for (int i = 0; i < num_mem_pools; i++)
+        memPools[i].serializeSection(cp, csprintf("memPool%d", i));

     // also serialize the memories in the system
     physmem.serializeSection(cp, "physmem");
@@ -461,15 +458,14 @@
 #       endif
     }

-    std::vector<Addr> ptrs;
-    std::vector<Addr> limits;
+    int num_mem_pools = 0;
+    UNSERIALIZE_SCALAR(num_mem_pools);

-    UNSERIALIZE_CONTAINER(ptrs);
-    UNSERIALIZE_CONTAINER(limits);
-
-    assert(ptrs.size() == limits.size());
-    for (size_t i = 0; i < ptrs.size(); i++)
-        memPools.emplace_back(getPageShift(), ptrs[i], limits[i]);
+    for (int i = 0; i < num_mem_pools; i++) {
+        MemPool pool;
+        pool.unserializeSection(cp, csprintf("memPool%d", i));
+        memPools.push_back(pool);
+    }

     // also unserialize the memories in the system
     physmem.unserializeSection(cp, "physmem");

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/50340
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: Ib0bf70b57e92698f15bea0cc217dd98ee816d57b
Gerrit-Change-Number: 50340
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to