summaryrefslogtreecommitdiff
path: root/sim/serialize.cc
diff options
context:
space:
mode:
authorSteve Reinhardt <stever@eecs.umich.edu>2003-12-11 00:16:46 -0800
committerSteve Reinhardt <stever@eecs.umich.edu>2003-12-11 00:16:46 -0800
commit777c1ebfab0318d4b98834b0f2ef48a2de16b8dd (patch)
tree448b7f195d862ca9398e296d1b18e1cae33f49d5 /sim/serialize.cc
parent7e6dcd812c18060a76d5a73a97e4aa05bcb0d516 (diff)
downloadgem5-777c1ebfab0318d4b98834b0f2ef48a2de16b8dd.tar.xz
Stats & serialization tweaks & cleanup. Unserializing from
a checkpoint now gives identical results to running from scratch and doing at switchover at the same cycle! - CPUs start at cycle 0 again, not cycle 1. - curTick is now serialized & unserialized. - Stats get reset in main (before event loop). Since this is done after curTick is unserialized, simTicks gets set correctly for running from a checkpoint. - Simplify serialization to happen in a single pass. - s/Serializeable/Serializable/ arch/alpha/isa_traits.hh: dev/etherlink.hh: sim/eventq.cc: sim/eventq.hh: s/Serializeable/Serializable/ kern/tru64/tru64_system.cc: sim/process.cc: Make initial CPU activation on cycle 0 again (not 1). sim/main.cc: Reset stats before getting started. Make error message on falling out of event loop more meaningful. sim/serialize.cc: sim/serialize.hh: Get rid of now-useless initial pass; serialization is done in a single pass now. Serialize & unserialize curTick. Wrap curTick and mainEventQueue in a "globals" Serializable object. s/Serializeable/Serializable/ sim/sim_object.cc: Add static function to serialize all SimObjects. sim/sim_object.hh: Add static function to serialize all SimObjects. s/Serializeable/Serializable/ --HG-- extra : convert_revision : 9dcc411d0009b54b8eb61c3a509680b81b9f6f68
Diffstat (limited to 'sim/serialize.cc')
-rw-r--r--sim/serialize.cc153
1 files changed, 57 insertions, 96 deletions
diff --git a/sim/serialize.cc b/sim/serialize.cc
index 9738029c2..82d295384 100644
--- a/sim/serialize.cc
+++ b/sim/serialize.cc
@@ -48,25 +48,14 @@
using namespace std;
-Serializer *Serializeable::serializer = NULL;
-
-void
-Serializeable::mark()
-{
- if (!serialized)
- serializer->add_object(this);
-
- serialized = true;
-}
-
void
-Serializeable::nameOut(ostream &os)
+Serializable::nameOut(ostream &os)
{
os << "\n[" << name() << "]\n";
}
void
-Serializeable::nameOut(ostream &os, const string &_name)
+Serializable::nameOut(ostream &os, const string &_name)
{
os << "\n[" << _name << "]\n";
}
@@ -156,7 +145,7 @@ arrayParamIn(Checkpoint *cp, const std::string &section,
void
objParamIn(Checkpoint *cp, const std::string &section,
- const std::string &name, Serializeable * &param)
+ const std::string &name, Serializable * &param)
{
if (!cp->findObj(section, name, param)) {
fatal("Can't unserialize '%s:%s'\n", section, name);
@@ -190,94 +179,70 @@ INSTANTIATE_PARAM_TEMPLATES(bool)
INSTANTIATE_PARAM_TEMPLATES(string)
-#if 0
-// unneeded?
-void
-Serializeable::childOut(const string &name, Serializeable *child)
-{
- child->mark();
- if (child->name() == "")
- panic("child is unnamed");
+/////////////////////////////
- out() << name << "=" << child->name() << "\n";
-}
-#endif
-
-Serializer::Serializer()
-{ }
+/// Container for serializing global variables (not associated with
+/// any serialized object).
+class Globals : public Serializable
+{
+ public:
+ string name() const;
+ void serialize(ostream& os);
+ void unserialize(Checkpoint *cp);
+};
-Serializer::~Serializer()
-{ }
+/// The one and only instance of the Globals class.
+Globals globals;
-ostream &
-Serializer::out() const
+string
+Globals::name() const
{
- if (!output)
- panic("must set output before serializing");
-
- return *output;
+ return "Globals";
}
void
-Serializer::add_object(Serializeable *obj)
+Globals::serialize(ostream& os)
{
- objects.push_back(obj);
+ nameOut(os);
+ SERIALIZE_SCALAR(curTick);
+
+ nameOut(os, "MainEventQueue");
+ mainEventQueue.serialize(os);
}
void
-Serializer::add_objects()
+Globals::unserialize(Checkpoint *cp)
{
- mainEventQueue.mark();
-
- SimObject::SimObjectList::iterator i = SimObject::simObjectList.begin();
- SimObject::SimObjectList::iterator end = SimObject::simObjectList.end();
+ const string &section = name();
+ UNSERIALIZE_SCALAR(curTick);
- while (i != end) {
- (*i)->mark();
- ++i;
- }
+ mainEventQueue.unserialize(cp, "MainEventQueue");
}
void
-Serializer::serialize()
+Serializable::serializeAll()
{
- if (Serializeable::serializer != NULL)
- panic("in process of serializing!");
-
- Serializeable::serializer = this;
-
string dir = CheckpointDir();
if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST)
warn("could mkdir %s\n", dir);
string cpt_file = dir + "m5.cpt";
- output = new ofstream(cpt_file.c_str());
+ ofstream outstream(cpt_file.c_str());
time_t t = time(NULL);
- *output << "// checkpoint generated: " << ctime(&t);
-
- serlist_t list;
-
- add_objects();
- while (!objects.empty()) {
- Serializeable *obj = objects.front();
- DPRINTF(Serialize, "Serializing %s\n", obj->name());
- obj->nameOut(out());
- obj->serialize(out());
- objects.pop_front();
- list.push_back(obj);
- }
+ outstream << "// checkpoint generated: " << ctime(&t);
- while (!list.empty()) {
- list.front()->serialized = false;
- list.pop_front();
- }
+ globals.serialize(outstream);
+ SimObject::serializeAll(outstream);
+}
- Serializeable::serializer = NULL;
- delete output;
- output = NULL;
+void
+Serializable::unserializeGlobals(Checkpoint *cp)
+{
+ globals.unserialize(cp);
}
+
class SerializeEvent : public Event
{
protected:
@@ -303,8 +268,7 @@ SerializeEvent::SerializeEvent(Tick _when, Tick _repeat)
void
SerializeEvent::process()
{
- Serializer serial;
- serial.serialize();
+ Serializable::serializeAll();
if (repeat)
schedule(curTick + repeat);
}
@@ -374,8 +338,7 @@ SerializeParamContext::checkParams()
void
debug_serialize()
{
- Serializer serial;
- serial.serialize();
+ Serializable::serializeAll();
}
void
@@ -386,22 +349,22 @@ debug_serialize(Tick when)
////////////////////////////////////////////////////////////////////////
//
-// SerializeableClass member definitions
+// SerializableClass member definitions
//
////////////////////////////////////////////////////////////////////////
-// Map of class names to SerializeableBuilder creation functions.
+// Map of class names to SerializableBuilder creation functions.
// Need to make this a pointer so we can force initialization on the
-// first reference; otherwise, some SerializeableClass constructors
+// first reference; otherwise, some SerializableClass constructors
// may be invoked before the classMap constructor.
-map<string,SerializeableClass::CreateFunc> *SerializeableClass::classMap = 0;
+map<string,SerializableClass::CreateFunc> *SerializableClass::classMap = 0;
-// SerializeableClass constructor: add mapping to classMap
-SerializeableClass::SerializeableClass(const string &className,
+// SerializableClass constructor: add mapping to classMap
+SerializableClass::SerializableClass(const string &className,
CreateFunc createFunc)
{
if (classMap == NULL)
- classMap = new map<string,SerializeableClass::CreateFunc>();
+ classMap = new map<string,SerializableClass::CreateFunc>();
if ((*classMap)[className])
{
@@ -417,25 +380,25 @@ SerializeableClass::SerializeableClass(const string &className,
//
//
-Serializeable *
-SerializeableClass::createObject(Checkpoint *cp,
+Serializable *
+SerializableClass::createObject(Checkpoint *cp,
const std::string &section)
{
string className;
if (!cp->find(section, "type", className)) {
- fatal("Serializeable::create: no 'type' entry in section '%s'.\n",
+ fatal("Serializable::create: no 'type' entry in section '%s'.\n",
section);
}
CreateFunc createFunc = (*classMap)[className];
if (createFunc == NULL) {
- fatal("Serializeable::create: no create function for class '%s'.\n",
+ fatal("Serializable::create: no create function for class '%s'.\n",
className);
}
- Serializeable *object = createFunc(cp, section);
+ Serializable *object = createFunc(cp, section);
assert(object != NULL);
@@ -443,10 +406,10 @@ SerializeableClass::createObject(Checkpoint *cp,
}
-Serializeable *
-Serializeable::create(Checkpoint *cp, const std::string &section)
+Serializable *
+Serializable::create(Checkpoint *cp, const std::string &section)
{
- Serializeable *object = SerializeableClass::createObject(cp, section);
+ Serializable *object = SerializableClass::createObject(cp, section);
object->unserialize(cp, section);
return object;
}
@@ -459,8 +422,6 @@ Checkpoint::Checkpoint(const std::string &filename, const std::string &path,
if (!db->load(filename)) {
fatal("Can't load checkpoint file '%s'\n", filename);
}
-
- mainEventQueue.unserialize(this, "MainEventQueue");
}
@@ -474,7 +435,7 @@ Checkpoint::find(const std::string &section, const std::string &entry,
bool
Checkpoint::findObj(const std::string &section, const std::string &entry,
- Serializeable *&value)
+ Serializable *&value)
{
string path;