summaryrefslogtreecommitdiff
path: root/src/base
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/base
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/base')
-rw-r--r--src/base/cp_annotate.cc97
-rw-r--r--src/base/cp_annotate.hh12
-rw-r--r--src/base/loader/symtab.cc17
-rw-r--r--src/base/loader/symtab.hh7
-rw-r--r--src/base/pollevent.cc4
-rw-r--r--src/base/pollevent.hh6
-rw-r--r--src/base/random.cc8
-rw-r--r--src/base/random.hh8
-rw-r--r--src/base/time.cc13
-rw-r--r--src/base/time.hh8
10 files changed, 85 insertions, 95 deletions
diff --git a/src/base/cp_annotate.cc b/src/base/cp_annotate.cc
index 4904949b4..5c421a5cf 100644
--- a/src/base/cp_annotate.cc
+++ b/src/base/cp_annotate.cc
@@ -1063,7 +1063,7 @@ CPA::doDq(System *sys, int flags, int cpuid, int sm,
void
-CPA::serialize(std::ostream &os)
+CPA::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(numSm);
@@ -1077,8 +1077,6 @@ CPA::serialize(std::ostream &os)
arrayParamOut(os, "qSize", qSize);
arrayParamOut(os, "qBytes", qBytes);
- std::list<AnnDataPtr>::iterator ai;
-
SCache::iterator i;
int x = 0, y = 0;
@@ -1211,36 +1209,33 @@ CPA::serialize(std::ostream &os)
if (!qData[x].size())
continue;
y = 0;
- ai = qData[x].begin();
- while (ai != qData[x].end()) {
- nameOut(os, csprintf("%s.Q%d_%d", name(), x, y));
- (*ai)->serialize(os);
- ai++;
+ for (auto &ann : qData[x]) {
+ ann->serializeSection(os, csprintf("Q%d_%d", x, y));
y++;
}
}
}
void
-CPA::unserialize(Checkpoint *cp, const std::string &section)
+CPA::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(numSm);
UNSERIALIZE_SCALAR(numSmt);
- arrayParamIn(cp, section, "numSt", numSt);
- arrayParamIn(cp, section, "numQ", numQ);
+ UNSERIALIZE_CONTAINER(numSt);
+ UNSERIALIZE_CONTAINER(numQ);
UNSERIALIZE_SCALAR(numSys);
UNSERIALIZE_SCALAR(numQs);
UNSERIALIZE_SCALAR(conId);
- arrayParamIn(cp, section, "qSize", qSize);
- arrayParamIn(cp, section, "qBytes", qBytes);
+ UNSERIALIZE_CONTAINER(qSize);
+ UNSERIALIZE_CONTAINER(qBytes);
// smtCache (SCache
string str;
int smi;
for (int x = 0; x < numSmt; x++) {
- paramIn(cp, section, csprintf("smtCache%d.str", x), str);
- paramIn(cp, section, csprintf("smtCache%d.int", x), smi);
+ paramIn(cp, csprintf("smtCache%d.str", x), str);
+ paramIn(cp, csprintf("smtCache%d.int", x), smi);
smtCache[str] = smi;
}
@@ -1248,8 +1243,8 @@ CPA::unserialize(Checkpoint *cp, const std::string &section)
stCache.resize(numSmt);
for (int x = 0; x < numSmt; x++) {
for (int y = 0; y < numSt[x]; y++) {
- paramIn(cp, section, csprintf("stCache%d_%d.str", x,y), str);
- paramIn(cp, section, csprintf("stCache%d_%d.int", x,y), smi);
+ paramIn(cp, csprintf("stCache%d_%d.str", x,y), str);
+ paramIn(cp, csprintf("stCache%d_%d.int", x,y), smi);
stCache[x][str] = smi;
}
}
@@ -1259,9 +1254,9 @@ CPA::unserialize(Checkpoint *cp, const std::string &section)
qCache.resize(numSys);
for (int x = 0; x < numSys; x++) {
for (int y = 0; y < numQ[x]; y++) {
- paramIn(cp, section, csprintf("qCache%d_%d.str", x,y), str);
- paramIn(cp, section, csprintf("qCache%d_%d.id", x,y), id);
- paramIn(cp, section, csprintf("qCache%d_%d.int", x,y), smi);
+ paramIn(cp, csprintf("qCache%d_%d.str", x,y), str);
+ paramIn(cp, csprintf("qCache%d_%d.id", x,y), id);
+ paramIn(cp, csprintf("qCache%d_%d.int", x,y), smi);
qCache[x][Id(str,id)] = smi;
}
}
@@ -1270,11 +1265,11 @@ CPA::unserialize(Checkpoint *cp, const std::string &section)
smCache.resize(numSys);
for (int x = 0; x < numSys; x++) {
int size;
- paramIn(cp, section, csprintf("smCache%d", x), size);
+ paramIn(cp, csprintf("smCache%d", x), size);
for (int y = 0; y < size; y++) {
- paramIn(cp, section, csprintf("smCache%d_%d.str", x,y), str);
- paramIn(cp, section, csprintf("smCache%d_%d.id", x,y), id);
- paramIn(cp, section, csprintf("smCache%d_%d.int", x,y), smi);
+ paramIn(cp, csprintf("smCache%d_%d.str", x,y), str);
+ paramIn(cp, csprintf("smCache%d_%d.id", x,y), id);
+ paramIn(cp, csprintf("smCache%d_%d.int", x,y), smi);
smCache[x][Id(str,id)] = smi;
}
}
@@ -1290,27 +1285,27 @@ CPA::unserialize(Checkpoint *cp, const std::string &section)
string str;
int sysi;
- objParamIn(cp, section, csprintf("nameCache%d.name", x), sptr);
+ objParamIn(cp, csprintf("nameCache%d.name", x), sptr);
sys = dynamic_cast<System*>(sptr);
- paramIn(cp, section, csprintf("nameCache%d.str", x), str);
- paramIn(cp, section, csprintf("nameCache%d.int", x), sysi);
+ paramIn(cp, csprintf("nameCache%d.str", x), str);
+ paramIn(cp, csprintf("nameCache%d.int", x), sysi);
nameCache[sys] = std::make_pair(str, sysi);
}
//smStack (SmStack)
int smStack_size;
- paramIn(cp, section, "smStackIdCount", smStack_size);
+ paramIn(cp, "smStackIdCount", smStack_size);
for (int x = 0; x < smStack_size; x++) {
int sysi;
uint64_t frame;
int count;
- paramIn(cp, section, csprintf("smStackId%d.sys", x), sysi);
- paramIn(cp, section, csprintf("smStackId%d.frame", x), frame);
- paramIn(cp, section, csprintf("smStackId%d.count", x), count);
+ paramIn(cp, csprintf("smStackId%d.sys", x), sysi);
+ paramIn(cp, csprintf("smStackId%d.frame", x), frame);
+ paramIn(cp, csprintf("smStackId%d.count", x), count);
StackId sid = StackId(sysi, frame);
for (int y = 0; y < count; y++) {
- paramIn(cp, section, csprintf("smStackId%d_%d", x, y), smi);
+ paramIn(cp, csprintf("smStackId%d_%d", x, y), smi);
smStack[sid].push_back(smi);
}
}
@@ -1318,23 +1313,23 @@ CPA::unserialize(Checkpoint *cp, const std::string &section)
// lnMap (LinkMap)
int lsmi;
int lnMap_size;
- paramIn(cp, section, "lnMapSize", lnMap_size);
+ paramIn(cp, "lnMapSize", lnMap_size);
for (int x = 0; x < lnMap_size; x++) {
- paramIn(cp, section, csprintf("lnMap%d.smi", x), smi);
- paramIn(cp, section, csprintf("lnMap%d.lsmi", x), lsmi);
+ paramIn(cp, csprintf("lnMap%d.smi", x), smi);
+ paramIn(cp, csprintf("lnMap%d.lsmi", x), lsmi);
lnMap[smi] = lsmi;
}
// swExpl (vector)
int swExpl_size;
- paramIn(cp, section, "swExplCount", swExpl_size);
+ paramIn(cp, "swExplCount", swExpl_size);
for (int x = 0; x < swExpl_size; x++) {
int sysi;
uint64_t frame;
bool b;
- paramIn(cp, section, csprintf("swExpl%d.sys", x), sysi);
- paramIn(cp, section, csprintf("swExpl%d.frame", x), frame);
- paramIn(cp, section, csprintf("swExpl%d.swexpl", x), b);
+ paramIn(cp, csprintf("swExpl%d.sys", x), sysi);
+ paramIn(cp, csprintf("swExpl%d.frame", x), frame);
+ paramIn(cp, csprintf("swExpl%d.swexpl", x), b);
StackId sid = StackId(sysi, frame);
swExpl[sid] = b;
}
@@ -1342,10 +1337,10 @@ CPA::unserialize(Checkpoint *cp, const std::string &section)
// lastState (IMap)
int sti;
int lastState_size;
- paramIn(cp, section, "lastStateSize", lastState_size);
+ paramIn(cp, "lastStateSize", lastState_size);
for (int x = 0; x < lastState_size; x++) {
- paramIn(cp, section, csprintf("lastState%d.smi", x), smi);
- paramIn(cp, section, csprintf("lastState%d.sti", x), sti);
+ paramIn(cp, csprintf("lastState%d.smi", x), smi);
+ paramIn(cp, csprintf("lastState%d.sti", x), sti);
lastState[smi] = sti;
}
@@ -1353,17 +1348,17 @@ CPA::unserialize(Checkpoint *cp, const std::string &section)
//smMap (IdMap)
smMap.resize(numSm);
for (int x = 0; x < smMap.size(); x++) {
- paramIn(cp, section, csprintf("smMap%d.sys", x), smMap[x].first);
- paramIn(cp, section, csprintf("smMap%d.smname", x), smMap[x].second.first);
- paramIn(cp, section, csprintf("smMap%d.id", x), smMap[x].second.second);
+ paramIn(cp, csprintf("smMap%d.sys", x), smMap[x].first);
+ paramIn(cp, csprintf("smMap%d.smname", x), smMap[x].second.first);
+ paramIn(cp, csprintf("smMap%d.id", x), smMap[x].second.second);
}
//qMap (IdMap)
qMap.resize(numQs);
for (int x = 0; x < qMap.size(); x++) {
- paramIn(cp, section, csprintf("qMap%d.sys", x), qMap[x].first);
- paramIn(cp, section, csprintf("qMap%d.qname", x), qMap[x].second.first);
- paramIn(cp, section, csprintf("qMap%d.id", x), qMap[x].second.second);
+ paramIn(cp, csprintf("qMap%d.sys", x), qMap[x].first);
+ paramIn(cp, csprintf("qMap%d.qname", x), qMap[x].second.first);
+ paramIn(cp, csprintf("qMap%d.id", x), qMap[x].second.second);
}
@@ -1374,7 +1369,7 @@ CPA::unserialize(Checkpoint *cp, const std::string &section)
continue;
for (int y = 0; y < qSize[x]; y++) {
AnnDataPtr a = std::make_shared<AnnotateData>();
- a->unserialize(cp, csprintf("%s.Q%d_%d", section, x, y));
+ a->unserializeSection(cp, csprintf("Q%d_%d", x, y));
data.push_back(a);
qData[x].push_back(a);
}
@@ -1382,7 +1377,7 @@ CPA::unserialize(Checkpoint *cp, const std::string &section)
}
void
-CPA::AnnotateData::serialize(std::ostream &os)
+CPA::AnnotateData::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(time);
SERIALIZE_SCALAR(data);
@@ -1394,7 +1389,7 @@ CPA::AnnotateData::serialize(std::ostream &os)
}
void
-CPA::AnnotateData::unserialize(Checkpoint *cp, const std::string &section)
+CPA::AnnotateData::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(time);
UNSERIALIZE_SCALAR(data);
diff --git a/src/base/cp_annotate.hh b/src/base/cp_annotate.hh
index 5d554aa73..a57d9bc79 100644
--- a/src/base/cp_annotate.hh
+++ b/src/base/cp_annotate.hh
@@ -190,7 +190,7 @@ class CPA : SimObject
}
/* struct that is written to the annotation output file */
- struct AnnotateData {
+ struct AnnotateData : public Serializable {
Tick time;
uint32_t data;
@@ -202,9 +202,8 @@ class CPA : SimObject
uint8_t cpu;
bool dump;
- void serialize(std::ostream &os);
- void unserialize(Checkpoint *cp, const std::string &section);
-
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
};
typedef std::shared_ptr<AnnotateData> AnnDataPtr;
@@ -541,9 +540,8 @@ class CPA : SimObject
void dump(bool all);
void dumpKey();
- void serialize(std::ostream &os);
- void unserialize(Checkpoint *cp, const std::string &section);
-
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
};
#endif // !CP_ANNOTATE
diff --git a/src/base/loader/symtab.cc b/src/base/loader/symtab.cc
index 2c868a9b1..439394852 100644
--- a/src/base/loader/symtab.cc
+++ b/src/base/loader/symtab.cc
@@ -108,32 +108,31 @@ SymbolTable::load(const string &filename)
}
void
-SymbolTable::serialize(const string &base, ostream &os)
+SymbolTable::serialize(const string &base, CheckpointOut &cp) const
{
- paramOut(os, base + ".size", addrTable.size());
+ paramOut(cp, base + ".size", addrTable.size());
int i = 0;
ATable::const_iterator p, end = addrTable.end();
for (p = addrTable.begin(); p != end; ++p) {
- paramOut(os, csprintf("%s.addr_%d", base, i), p->first);
- paramOut(os, csprintf("%s.symbol_%d", base, i), p->second);
+ paramOut(cp, csprintf("%s.addr_%d", base, i), p->first);
+ paramOut(cp, csprintf("%s.symbol_%d", base, i), p->second);
++i;
}
}
void
-SymbolTable::unserialize(const string &base, Checkpoint *cp,
- const string &section)
+SymbolTable::unserialize(const string &base, CheckpointIn &cp)
{
clear();
int size;
- paramIn(cp, section, base + ".size", size);
+ paramIn(cp, base + ".size", size);
for (int i = 0; i < size; ++i) {
Addr addr;
std::string symbol;
- paramIn(cp, section, csprintf("%s.addr_%d", base, i), addr);
- paramIn(cp, section, csprintf("%s.symbol_%d", base, i), symbol);
+ paramIn(cp, csprintf("%s.addr_%d", base, i), addr);
+ paramIn(cp, csprintf("%s.symbol_%d", base, i), symbol);
insert(addr, symbol);
}
}
diff --git a/src/base/loader/symtab.hh b/src/base/loader/symtab.hh
index 2a2fd068e..403cb13ac 100644
--- a/src/base/loader/symtab.hh
+++ b/src/base/loader/symtab.hh
@@ -37,8 +37,8 @@
#include <string>
#include "base/types.hh"
+#include "sim/serialize.hh"
-class Checkpoint;
class SymbolTable
{
public:
@@ -76,9 +76,8 @@ class SymbolTable
const STable &getSymbolTable() const { return symbolTable; }
public:
- void serialize(const std::string &base, std::ostream &os);
- void unserialize(const std::string &base, Checkpoint *cp,
- const std::string &section);
+ void serialize(const std::string &base, CheckpointOut &cp) const;
+ void unserialize(const std::string &base, CheckpointIn &cp);
public:
bool
diff --git a/src/base/pollevent.cc b/src/base/pollevent.cc
index ea4d632d0..a6c93c1f3 100644
--- a/src/base/pollevent.cc
+++ b/src/base/pollevent.cc
@@ -88,7 +88,7 @@ PollEvent::enable()
}
void
-PollEvent::serialize(ostream &os)
+PollEvent::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(pfd.fd);
SERIALIZE_SCALAR(pfd.events);
@@ -96,7 +96,7 @@ PollEvent::serialize(ostream &os)
}
void
-PollEvent::unserialize(Checkpoint *cp, const std::string &section)
+PollEvent::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(pfd.fd);
UNSERIALIZE_SCALAR(pfd.events);
diff --git a/src/base/pollevent.hh b/src/base/pollevent.hh
index 5e0faa729..632239e08 100644
--- a/src/base/pollevent.hh
+++ b/src/base/pollevent.hh
@@ -40,7 +40,7 @@
class Checkpoint;
class PollQueue;
-class PollEvent
+class PollEvent : public Serializable
{
private:
friend class PollQueue;
@@ -60,8 +60,8 @@ class PollEvent
bool queued() { return queue != 0; }
- virtual void serialize(std::ostream &os);
- virtual void unserialize(Checkpoint *cp, const std::string &section);
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
};
class PollQueue
diff --git a/src/base/random.cc b/src/base/random.cc
index ced9a8f45..2eb60c6e5 100644
--- a/src/base/random.cc
+++ b/src/base/random.cc
@@ -70,7 +70,7 @@ Random::init(uint32_t s)
}
void
-Random::serialize(std::ostream &os)
+Random::serialize(CheckpointOut &cp) const
{
panic("Currently not used anywhere.\n");
@@ -78,11 +78,11 @@ Random::serialize(std::ostream &os)
std::ostringstream oss;
oss << gen;
std::string state = oss.str();
- paramOut(os, "mt_state", state);
+ paramOut(cp, "mt_state", state);
}
void
-Random::unserialize(Checkpoint *cp, const std::string &section)
+Random::unserialize(CheckpointIn &cp)
{
panic("Currently not used anywhere.\n");
@@ -90,7 +90,7 @@ Random::unserialize(Checkpoint *cp, const std::string &section)
// checkpoint state, so be forgiving in the unserialization and
// keep on going if the parameter is not there
std::string state;
- if (optParamIn(cp, section, "mt_state", state)) {
+ if (optParamIn(cp, "mt_state", state)) {
std::istringstream iss(state);
iss >> gen;
}
diff --git a/src/base/random.hh b/src/base/random.hh
index cedbd6bd4..dca956306 100644
--- a/src/base/random.hh
+++ b/src/base/random.hh
@@ -53,11 +53,13 @@
#include <string>
#include <type_traits>
+#include "base/compiler.hh"
#include "base/types.hh"
+#include "sim/serialize.hh"
class Checkpoint;
-class Random
+class Random : public Serializable
{
private:
@@ -102,8 +104,8 @@ class Random
return dist(gen);
}
- void serialize(std::ostream &os);
- void unserialize(Checkpoint *cp, const std::string &section);
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
};
extern Random random_mt;
diff --git a/src/base/time.cc b/src/base/time.cc
index a0ae9bb82..86a31156c 100644
--- a/src/base/time.cc
+++ b/src/base/time.cc
@@ -117,20 +117,19 @@ Time::time() const
}
void
-Time::serialize(const std::string &base, ostream &os)
+Time::serialize(const std::string &base, CheckpointOut &cp) const
{
- paramOut(os, base + ".sec", sec());
- paramOut(os, base + ".nsec", nsec());
+ paramOut(cp, base + ".sec", sec());
+ paramOut(cp, base + ".nsec", nsec());
}
void
-Time::unserialize(const std::string &base, Checkpoint *cp,
- const string &section)
+Time::unserialize(const std::string &base, CheckpointIn &cp)
{
time_t secs;
time_t nsecs;
- paramIn(cp, section, base + ".sec", secs);
- paramIn(cp, section, base + ".nsec", nsecs);
+ paramIn(cp, base + ".sec", secs);
+ paramIn(cp, base + ".nsec", nsecs);
sec(secs);
nsec(nsecs);
}
diff --git a/src/base/time.hh b/src/base/time.hh
index 734a86fa9..41d454a65 100644
--- a/src/base/time.hh
+++ b/src/base/time.hh
@@ -43,8 +43,7 @@
#include <string>
#include "base/types.hh"
-
-class Checkpoint;
+#include "sim/serialize.hh"
class Time
{
@@ -198,9 +197,8 @@ class Time
std::string date(const std::string &format = "") const;
std::string time() const;
- void serialize(const std::string &base, std::ostream &os);
- void unserialize(const std::string &base, Checkpoint *cp,
- const std::string &section);
+ void serialize(const std::string &base, CheckpointOut &cp) const;
+ void unserialize(const std::string &base, CheckpointIn &cp);
};
void sleep(const Time &time);