summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/process.cc9
-rw-r--r--src/sim/process.hh5
-rw-r--r--src/sim/serialize.cc15
-rw-r--r--src/sim/serialize.hh1
-rw-r--r--src/sim/sim_object.cc12
-rw-r--r--src/sim/sim_object.hh39
6 files changed, 53 insertions, 28 deletions
diff --git a/src/sim/process.cc b/src/sim/process.cc
index f11fdcac8..d4b1fba90 100644
--- a/src/sim/process.cc
+++ b/src/sim/process.cc
@@ -100,8 +100,8 @@ template class AuxVector<uint32_t>;
template class AuxVector<uint64_t>;
Process::Process(ProcessParams * params)
- : SimObject(params), system(params->system), checkpointRestored(false),
- max_stack_size(params->max_stack_size)
+ : SimObject(params), system(params->system),
+ max_stack_size(params->max_stack_size)
{
string in = params->input;
string out = params->output;
@@ -233,7 +233,7 @@ Process::findFreeContext()
}
void
-Process::startup()
+Process::initState()
{
if (contextIds.empty())
fatal("Process %s is not associated with any HW contexts!\n", name());
@@ -537,9 +537,6 @@ Process::unserialize(Checkpoint *cp, const std::string &section)
// find the param in the checkpoint if you wanted to, like set a default
// but in this case we'll just stick with the instantianted value if not
// found.
-
- checkpointRestored = true;
-
}
diff --git a/src/sim/process.hh b/src/sim/process.hh
index e73f93fa5..3b78cb001 100644
--- a/src/sim/process.hh
+++ b/src/sim/process.hh
@@ -79,8 +79,6 @@ class Process : public SimObject
/// running on.
System *system;
- bool checkpointRestored;
-
// thread contexts associated with this process
std::vector<int> contextIds;
@@ -130,8 +128,7 @@ class Process : public SimObject
// constructor
Process(ProcessParams * params);
- // post initialization startup
- virtual void startup();
+ virtual void initState();
protected:
/// Memory object for initialization (image loading)
diff --git a/src/sim/serialize.cc b/src/sim/serialize.cc
index d95092629..d6d5ac094 100644
--- a/src/sim/serialize.cc
+++ b/src/sim/serialize.cc
@@ -452,17 +452,6 @@ Serializable::serializeAll(const string &cpt_dir)
}
void
-Serializable::unserializeAll(const string &cpt_dir)
-{
- string dir = Checkpoint::setDir(cpt_dir);
-
- DPRINTFR(Config, "Loading checkpoint dir '%s'\n", dir);
- Checkpoint *cp = new Checkpoint(dir);
- unserializeGlobals(cp);
- SimObject::unserializeAll(cp);
-}
-
-void
Serializable::unserializeGlobals(Checkpoint *cp)
{
globals.unserialize(cp);
@@ -561,9 +550,9 @@ Checkpoint::dir()
Checkpoint::Checkpoint(const string &cpt_dir)
- : db(new IniFile), cptDir(cpt_dir)
+ : db(new IniFile), cptDir(setDir(cpt_dir))
{
- string filename = cpt_dir + "/" + Checkpoint::baseFilename;
+ string filename = cptDir + "/" + Checkpoint::baseFilename;
if (!db->load(filename)) {
fatal("Can't load checkpoint file '%s'\n", filename);
}
diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh
index 677a3fd92..d785605f3 100644
--- a/src/sim/serialize.hh
+++ b/src/sim/serialize.hh
@@ -141,7 +141,6 @@ class Serializable
static int ckptMaxCount;
static int ckptPrevCount;
static void serializeAll(const std::string &cpt_dir);
- static void unserializeAll(const std::string &cpt_dir);
static void unserializeGlobals(Checkpoint *cp);
};
diff --git a/src/sim/sim_object.cc b/src/sim/sim_object.cc
index 157bf1395..503ac5650 100644
--- a/src/sim/sim_object.cc
+++ b/src/sim/sim_object.cc
@@ -74,6 +74,18 @@ SimObject::init()
}
void
+SimObject::loadState(Checkpoint *cp)
+{
+ if (cp->sectionExists(name()))
+ unserialize(cp, name());
+}
+
+void
+SimObject::initState()
+{
+}
+
+void
SimObject::startup()
{
}
diff --git a/src/sim/sim_object.hh b/src/sim/sim_object.hh
index 1b22c5825..876501be2 100644
--- a/src/sim/sim_object.hh
+++ b/src/sim/sim_object.hh
@@ -91,17 +91,48 @@ class SimObject : public EventManager, public Serializable
virtual const std::string name() const { return params()->name; }
- // initialization pass of all objects.
- // Gets invoked after construction, before unserialize.
+ // The following SimObject initialization methods are called from
+ // the instantiate() method in src/python/m5/simulate.py. See
+ // that function for details on how/when these methods are
+ // invoked.
+
+ /**
+ * init() is called after all C++ SimObjects have been created and
+ * all ports are connected. Initializations that are independent
+ * of unserialization but rely on a fully instantiated and
+ * connected SimObject graph should be done here.
+ */
virtual void init();
+ /**
+ * loadState() is called on each SimObject when restoring from a
+ * checkpoint. The default implementation simply calls
+ * unserialize() if there is a corresponding section in the
+ * checkpoint. However, objects can override loadState() to get
+ * other behaviors, e.g., doing other programmed initializations
+ * after unserialize(), or complaining if no checkpoint section is
+ * found.
+ */
+ virtual void loadState(Checkpoint *cp);
+
+ /**
+ * initState() is called on each SimObject when *not* restoring
+ * from a checkpoint. This provides a hook for state
+ * initializations that are only required for a "cold start".
+ */
+ virtual void initState();
+
// register statistics for this object
virtual void regStats();
virtual void regFormulas();
virtual void resetStats();
- // final initialization before simulation
- // all state is unserialized so
+ /**
+ * startup() is the final initialization call before simulation.
+ * All state is initialized (including unserialized state, if any,
+ * such as the curTick value), so this is the appropriate place to
+ * schedule initial event(s) for objects that need them.
+ */
virtual void startup();
// static: call nameOut() & serialize() on all SimObjects