diff options
author | Steve Reinhardt <steve.reinhardt@amd.com> | 2010-08-17 05:17:06 -0700 |
---|---|---|
committer | Steve Reinhardt <steve.reinhardt@amd.com> | 2010-08-17 05:17:06 -0700 |
commit | f064aa306061ecc468efd8cf148ed08398ca824d (patch) | |
tree | d78548dc953bb621d9154249d07022dabf2f6e2c /src/python | |
parent | 2519d116c9171ed4bf220d5049f244b333aa0842 (diff) | |
download | gem5-f064aa306061ecc468efd8cf148ed08398ca824d.tar.xz |
sim: revamp unserialization procedure
Replace direct call to unserialize() on each SimObject with a pair of
calls for better control over initialization in both ckpt and non-ckpt
cases.
If restoring from a checkpoint, loadState(ckpt) is called on each
SimObject. The default implementation simply calls unserialize() if
there is a corresponding checkpoint section, so we get backward
compatibility for existing objects. 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. (Note that the default warning for a missing
checkpoint section is now gone.)
If not restoring from a checkpoint, we call the new initState() method
on each SimObject instead. This provides a hook for state
initializations that are only required when *not* restoring from a
checkpoint.
Given this new framework, do some cleanup of LiveProcess subclasses
and X86System, which were (in some cases) emulating initState()
behavior in startup via a local flag or (in other cases) erroneously
doing initializations in startup() that clobbered state loaded earlier
by unserialize().
Diffstat (limited to 'src/python')
-rw-r--r-- | src/python/m5/simulate.py | 6 | ||||
-rw-r--r-- | src/python/swig/core.i | 5 | ||||
-rw-r--r-- | src/python/swig/pyobject.hh | 10 | ||||
-rw-r--r-- | src/python/swig/sim_object.i | 2 |
4 files changed, 19 insertions, 4 deletions
diff --git a/src/python/m5/simulate.py b/src/python/m5/simulate.py index 0cf0a254e..cd2f8bb64 100644 --- a/src/python/m5/simulate.py +++ b/src/python/m5/simulate.py @@ -88,8 +88,12 @@ def instantiate(ckpt_dir=None): # Restore checkpoint (if any) if ckpt_dir: - internal.core.unserializeAll(ckpt_dir) + ckpt = internal.core.getCheckpoint(ckpt_dir) + internal.core.unserializeGlobals(ckpt); + for obj in root.descendants(): obj.loadState(ckpt) need_resume.append(root) + else: + for obj in root.descendants(): obj.initState() # Reset to put the stats in a consistent state. stats.reset() diff --git a/src/python/swig/core.i b/src/python/swig/core.i index 81085dd06..f48fe9590 100644 --- a/src/python/swig/core.i +++ b/src/python/swig/core.i @@ -75,8 +75,11 @@ void setClockFrequency(Tick ticksPerSecond); %immutable curTick; Tick curTick; +class Checkpoint; + void serializeAll(const std::string &cpt_dir); -void unserializeAll(const std::string &cpt_dir); +Checkpoint *getCheckpoint(const std::string &cpt_dir); +void unserializeGlobals(Checkpoint *cp); bool want_warn, warn_verbose; bool want_info, info_verbose; diff --git a/src/python/swig/pyobject.hh b/src/python/swig/pyobject.hh index a27080d08..b18a2a76c 100644 --- a/src/python/swig/pyobject.hh +++ b/src/python/swig/pyobject.hh @@ -52,8 +52,14 @@ serializeAll(const std::string &cpt_dir) Serializable::serializeAll(cpt_dir); } +inline Checkpoint * +getCheckpoint(const std::string &cpt_dir) +{ + return new Checkpoint(cpt_dir); +} + inline void -unserializeAll(const std::string &cpt_dir) +unserializeGlobals(Checkpoint *cp) { - Serializable::unserializeAll(cpt_dir); + Serializable::unserializeGlobals(cp); } diff --git a/src/python/swig/sim_object.i b/src/python/swig/sim_object.i index 8cd8e8beb..af9afd057 100644 --- a/src/python/swig/sim_object.i +++ b/src/python/swig/sim_object.i @@ -51,6 +51,8 @@ class SimObject { }; void init(); + void loadState(Checkpoint *cp); + void initState(); void regStats(); void regFormulas(); void resetStats(); |