sim: Refactor the serialization base class
Review Request #2861 - Created May 28, 2015 and submitted
| Information | |
|---|---|
| Andreas Sandberg | |
| gem5 | |
| default | |
| Reviewers | |
| Default | |
Changeset 10904:d7cb76341887
---------------------------
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.
Quick regressions pass for all platforms, including checkpoint regressions on ARM. Generated full-system checkpoint for X86, Alpha, and ARM. Compared checkpoints before and after patch (checkpoints are identical).
Note to reviewers: I'm really sorry about the size of this patch. :(
I like that this aims to remove some of the less common checkpoint writing functions. This is a useful step, and I'm largely ok with this change.
I've always wondered why we don't explicitly pass Checkpoint to both serialize and unserialize functions. My only real comment is that if we're doing such substantial refactoring in that direction, why not make Checkpoint a more complete object that "contains" all the serialized/unserialized state? Specifically, it would make more sense to move the paramIn/paramOut functions inside Checkpoint. Details below.
-
src/sim/serialize.hh (Diff revision 1) -
Could we move the ostream inside of Checkpoint and either (1) overload operator<<() there, or (2) better yet, move the paramIn/paramOut functions inside of Checkpoint? That way we could pass the same Checkpoint reference to all the serialize and unserialize functions, and we wouldn't have to distinguish these types (CheckpointIn vs. CheckpointOut). We'd have to modify the same code that this patch does, so changing this in a separate patch would require another broad merge.
-
src/sim/serialize.hh (Diff revision 1) -
Just a note: If we were to move paramIn/paramOut functions inside of Checkpoint, these #defines would change to cp.paramOut(...) and cp.paramIn(...).
To me, this would make more conceptual sense: Checkpoint would be an object containing the serialized/unserialized state.
Ship It!
-
src/sim/serialize.hh (Diff revision 1) -
Is there a plan in place to change the objects that use this? If not (i.e., if there's a legitimate need for some objects to modify their state when chackpointing) then we shouldn't be so adamant about calling this serializeOld() and saying "don't ever use this". Why not call it something like serializeNonConst() and just say "it's desirable to avoid this when possible"?
Description: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Diff: |
Revision 2 (+1787 -1773) |
