summaryrefslogtreecommitdiff
path: root/src/mem/physical.cc
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2015-07-07 09:51:03 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2015-07-07 09:51:03 +0100
commit76cd4393c08b83fa9006ee7bce1fb62457e053c1 (patch)
treef1d2d109f77a8cf31365143d6eb127b610d924f5 /src/mem/physical.cc
parentd7a56ee524c976a41fa40e5382a28462de799645 (diff)
downloadgem5-76cd4393c08b83fa9006ee7bce1fb62457e053c1.tar.xz
sim: Refactor the serialization base class
Objects that are can be serialized are supposed to inherit from the Serializable class. This class is meant to provide a unified API for such objects. However, so far it has mainly been used by SimObjects due to some fundamental design limitations. This changeset redesigns to the serialization interface to make it more generic and hide the underlying checkpoint storage. Specifically: * Add a set of APIs to serialize into a subsection of the current object. Previously, objects that needed this functionality would use ad-hoc solutions using nameOut() and section name generation. In the new world, an object that implements the interface has the methods serializeSection() and unserializeSection() that serialize into a named /subsection/ of the current object. Calling serialize() serializes an object into the current section. * Move the name() method from Serializable to SimObject as it is no longer needed for serialization. The fully qualified section name is generated by the main serialization code on the fly as objects serialize sub-objects. * Add a scoped ScopedCheckpointSection helper class. Some objects need to serialize data structures, that are not deriving from Serializable, into subsections. Previously, this was done using nameOut() and manual section name generation. To simplify this, this changeset introduces a ScopedCheckpointSection() helper class. When this class is instantiated, it adds a new /subsection/ and subsequent serialization calls during the lifetime of this helper class happen inside this section (or a subsection in case of nested sections). * The serialize() call is now const which prevents accidental state manipulation during serialization. Objects that rely on modifying state can use the serializeOld() call instead. The default implementation simply calls serialize(). Note: The old-style calls need to be explicitly called using the serializeOld()/serializeSectionOld() style APIs. These are used by default when serializing SimObjects. * Both the input and output checkpoints now use their own named types. This hides underlying checkpoint implementation from objects that need checkpointing and makes it easier to change the underlying checkpoint storage code.
Diffstat (limited to 'src/mem/physical.cc')
-rw-r--r--src/mem/physical.cc29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/mem/physical.cc b/src/mem/physical.cc
index e6d682624..d757b8c5d 100644
--- a/src/mem/physical.cc
+++ b/src/mem/physical.cc
@@ -289,7 +289,7 @@ PhysicalMemory::functionalAccess(PacketPtr pkt)
}
void
-PhysicalMemory::serialize(ostream& os)
+PhysicalMemory::serialize(CheckpointOut &cp) const
{
// serialize all the locked addresses and their context ids
vector<Addr> lal_addr;
@@ -303,8 +303,8 @@ PhysicalMemory::serialize(ostream& os)
}
}
- arrayParamOut(os, "lal_addr", lal_addr);
- arrayParamOut(os, "lal_cid", lal_cid);
+ SERIALIZE_CONTAINER(lal_addr);
+ SERIALIZE_CONTAINER(lal_cid);
// serialize the backing stores
unsigned int nbr_of_stores = backingStore.size();
@@ -313,14 +313,14 @@ PhysicalMemory::serialize(ostream& os)
unsigned int store_id = 0;
// store each backing store memory segment in a file
for (auto& s : backingStore) {
- nameOut(os, csprintf("%s.store%d", name(), store_id));
- serializeStore(os, store_id++, s.first, s.second);
+ ScopedCheckpointSection sec(cp, csprintf("store%d", store_id));
+ serializeStore(cp, store_id++, s.first, s.second);
}
}
void
-PhysicalMemory::serializeStore(ostream& os, unsigned int store_id,
- AddrRange range, uint8_t* pmem)
+PhysicalMemory::serializeStore(CheckpointOut &cp, unsigned int store_id,
+ AddrRange range, uint8_t* pmem) const
{
// we cannot use the address range for the name as the
// memories that are not part of the address map can overlap
@@ -335,7 +335,7 @@ PhysicalMemory::serializeStore(ostream& os, unsigned int store_id,
SERIALIZE_SCALAR(range_size);
// write memory file
- string filepath = Checkpoint::dir() + "/" + filename.c_str();
+ string filepath = CheckpointIn::dir() + "/" + filename.c_str();
gzFile compressed_mem = gzopen(filepath.c_str(), "wb");
if (compressed_mem == NULL)
fatal("Can't open physical memory checkpoint file '%s'\n",
@@ -365,14 +365,14 @@ PhysicalMemory::serializeStore(ostream& os, unsigned int store_id,
}
void
-PhysicalMemory::unserialize(Checkpoint* cp, const string& section)
+PhysicalMemory::unserialize(CheckpointIn &cp)
{
// unserialize the locked addresses and map them to the
// appropriate memory controller
vector<Addr> lal_addr;
vector<int> lal_cid;
- arrayParamIn(cp, section, "lal_addr", lal_addr);
- arrayParamIn(cp, section, "lal_cid", lal_cid);
+ UNSERIALIZE_CONTAINER(lal_addr);
+ UNSERIALIZE_CONTAINER(lal_cid);
for(size_t i = 0; i < lal_addr.size(); ++i) {
const auto& m = addrMap.find(lal_addr[i]);
m->second->addLockedAddr(LockedAddr(lal_addr[i], lal_cid[i]));
@@ -383,13 +383,14 @@ PhysicalMemory::unserialize(Checkpoint* cp, const string& section)
UNSERIALIZE_SCALAR(nbr_of_stores);
for (unsigned int i = 0; i < nbr_of_stores; ++i) {
- unserializeStore(cp, csprintf("%s.store%d", section, i));
+ ScopedCheckpointSection sec(cp, csprintf("store%d", i));
+ unserializeStore(cp);
}
}
void
-PhysicalMemory::unserializeStore(Checkpoint* cp, const string& section)
+PhysicalMemory::unserializeStore(CheckpointIn &cp)
{
const uint32_t chunk_size = 16384;
@@ -398,7 +399,7 @@ PhysicalMemory::unserializeStore(Checkpoint* cp, const string& section)
string filename;
UNSERIALIZE_SCALAR(filename);
- string filepath = cp->cptDir + "/" + filename;
+ string filepath = cp.cptDir + "/" + filename;
// mmap memoryfile
gzFile compressed_mem = gzopen(filepath.c_str(), "rb");