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().
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -52,8 +52,14 @@ serializeAll(const std::string &cpt_dir)
|
||||
Serializable::serializeAll(cpt_dir);
|
||||
}
|
||||
|
||||
inline void
|
||||
unserializeAll(const std::string &cpt_dir)
|
||||
inline Checkpoint *
|
||||
getCheckpoint(const std::string &cpt_dir)
|
||||
{
|
||||
Serializable::unserializeAll(cpt_dir);
|
||||
return new Checkpoint(cpt_dir);
|
||||
}
|
||||
|
||||
inline void
|
||||
unserializeGlobals(Checkpoint *cp)
|
||||
{
|
||||
Serializable::unserializeGlobals(cp);
|
||||
}
|
||||
|
||||
@@ -51,6 +51,8 @@ class SimObject {
|
||||
};
|
||||
|
||||
void init();
|
||||
void loadState(Checkpoint *cp);
|
||||
void initState();
|
||||
void regStats();
|
||||
void regFormulas();
|
||||
void resetStats();
|
||||
|
||||
Reference in New Issue
Block a user