diff options
author | Andreas Sandberg <andreas.sandberg@arm.com> | 2015-07-07 09:51:03 +0100 |
---|---|---|
committer | Andreas Sandberg <andreas.sandberg@arm.com> | 2015-07-07 09:51:03 +0100 |
commit | 76cd4393c08b83fa9006ee7bce1fb62457e053c1 (patch) | |
tree | f1d2d109f77a8cf31365143d6eb127b610d924f5 /src/dev/sparc | |
parent | d7a56ee524c976a41fa40e5382a28462de799645 (diff) | |
download | gem5-76cd4393c08b83fa9006ee7bce1fb62457e053c1.tar.xz |
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.
Diffstat (limited to 'src/dev/sparc')
-rw-r--r-- | src/dev/sparc/dtod.cc | 4 | ||||
-rw-r--r-- | src/dev/sparc/dtod.hh | 16 | ||||
-rw-r--r-- | src/dev/sparc/iob.cc | 34 | ||||
-rw-r--r-- | src/dev/sparc/iob.hh | 5 | ||||
-rw-r--r-- | src/dev/sparc/mm_disk.cc | 2 | ||||
-rw-r--r-- | src/dev/sparc/mm_disk.hh | 2 |
6 files changed, 26 insertions, 37 deletions
diff --git a/src/dev/sparc/dtod.cc b/src/dev/sparc/dtod.cc index 3853abb16..5b74bbcb7 100644 --- a/src/dev/sparc/dtod.cc +++ b/src/dev/sparc/dtod.cc @@ -79,13 +79,13 @@ DumbTOD::write(PacketPtr pkt) } void -DumbTOD::serialize(std::ostream &os) +DumbTOD::serialize(CheckpointOut &cp) const { SERIALIZE_SCALAR(todTime); } void -DumbTOD::unserialize(Checkpoint *cp, const std::string §ion) +DumbTOD::unserialize(CheckpointIn &cp) { UNSERIALIZE_SCALAR(todTime); } diff --git a/src/dev/sparc/dtod.hh b/src/dev/sparc/dtod.hh index a5b2dfaff..a7b451364 100644 --- a/src/dev/sparc/dtod.hh +++ b/src/dev/sparc/dtod.hh @@ -63,20 +63,8 @@ class DumbTOD : public BasicPioDevice virtual Tick read(PacketPtr pkt); virtual Tick write(PacketPtr pkt); - /** - * Serialize this object to the given output stream. - * @param os The stream to serialize to. - */ - virtual void serialize(std::ostream &os); - - /** - * Reconstruct the state of this object from a checkpoint. - * @param cp The checkpoint use. - * @param section The section name of this object - */ - virtual void unserialize(Checkpoint *cp, const std::string §ion); - - + void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; + void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE; }; #endif // __DEV_BADDEV_HH__ diff --git a/src/dev/sparc/iob.cc b/src/dev/sparc/iob.cc index c71edd9f0..bee0323c8 100644 --- a/src/dev/sparc/iob.cc +++ b/src/dev/sparc/iob.cc @@ -334,41 +334,43 @@ Iob::getAddrRanges() const void -Iob::serialize(std::ostream &os) +Iob::serialize(CheckpointOut &cp) const { SERIALIZE_SCALAR(jIntVec); SERIALIZE_ARRAY(jBusData0, MaxNiagaraProcs); SERIALIZE_ARRAY(jBusData1, MaxNiagaraProcs); for (int x = 0; x < NumDeviceIds; x++) { - nameOut(os, csprintf("%s.Int%d", name(), x)); - paramOut(os, "cpu", intMan[x].cpu); - paramOut(os, "vector", intMan[x].vector); - paramOut(os, "mask", intCtl[x].mask); - paramOut(os, "pend", intCtl[x].pend); + ScopedCheckpointSection sec(cp, csprintf("Int%d", x)); + paramOut(cp, "cpu", intMan[x].cpu); + paramOut(cp, "vector", intMan[x].vector); + paramOut(cp, "mask", intCtl[x].mask); + paramOut(cp, "pend", intCtl[x].pend); }; for (int x = 0; x < MaxNiagaraProcs; x++) { - nameOut(os, csprintf("%s.jIntBusy%d", name(), x)); - paramOut(os, "busy", jIntBusy[x].busy); - paramOut(os, "source", jIntBusy[x].source); + ScopedCheckpointSection sec(cp, csprintf("jIntBusy%d", x)); + paramOut(cp, "busy", jIntBusy[x].busy); + paramOut(cp, "source", jIntBusy[x].source); }; } void -Iob::unserialize(Checkpoint *cp, const std::string §ion) +Iob::unserialize(CheckpointIn &cp) { UNSERIALIZE_SCALAR(jIntVec); UNSERIALIZE_ARRAY(jBusData0, MaxNiagaraProcs); UNSERIALIZE_ARRAY(jBusData1, MaxNiagaraProcs); for (int x = 0; x < NumDeviceIds; x++) { - paramIn(cp, csprintf("%s.Int%d", name(), x), "cpu", intMan[x].cpu); - paramIn(cp, csprintf("%s.Int%d", name(), x), "vector", intMan[x].vector); - paramIn(cp, csprintf("%s.Int%d", name(), x), "mask", intCtl[x].mask); - paramIn(cp, csprintf("%s.Int%d", name(), x), "pend", intCtl[x].pend); + ScopedCheckpointSection sec(cp, csprintf("Int%d", x)); + paramIn(cp, "cpu", intMan[x].cpu); + paramIn(cp, "vector", intMan[x].vector); + paramIn(cp, "mask", intCtl[x].mask); + paramIn(cp, "pend", intCtl[x].pend); }; for (int x = 0; x < MaxNiagaraProcs; x++) { - paramIn(cp, csprintf("%s.jIntBusy%d", name(), x), "busy", jIntBusy[x].busy); - paramIn(cp, csprintf("%s.jIntBusy%d", name(), x), "source", jIntBusy[x].source); + ScopedCheckpointSection sec(cp, csprintf("jIntBusy%d", x)); + paramIn(cp, "busy", jIntBusy[x].busy); + paramIn(cp, "source", jIntBusy[x].source); }; } diff --git a/src/dev/sparc/iob.hh b/src/dev/sparc/iob.hh index fc5e61092..033ee3867 100644 --- a/src/dev/sparc/iob.hh +++ b/src/dev/sparc/iob.hh @@ -142,9 +142,8 @@ class Iob : public PioDevice AddrRangeList getAddrRanges() const; - virtual void serialize(std::ostream &os); - virtual void unserialize(Checkpoint *cp, const std::string §ion); - + void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; + void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE; }; #endif //__DEV_SPARC_IOB_HH__ diff --git a/src/dev/sparc/mm_disk.cc b/src/dev/sparc/mm_disk.cc index 0a6d14445..5fe9157bc 100644 --- a/src/dev/sparc/mm_disk.cc +++ b/src/dev/sparc/mm_disk.cc @@ -170,7 +170,7 @@ MmDisk::write(PacketPtr pkt) } void -MmDisk::serialize(std::ostream &os) +MmDisk::serialize(CheckpointOut &cp) const { // just write any dirty changes to the cow layer it will take care of // serialization diff --git a/src/dev/sparc/mm_disk.hh b/src/dev/sparc/mm_disk.hh index d14e1d4a4..2de3cac7d 100644 --- a/src/dev/sparc/mm_disk.hh +++ b/src/dev/sparc/mm_disk.hh @@ -61,7 +61,7 @@ class MmDisk : public BasicPioDevice virtual Tick read(PacketPtr pkt); virtual Tick write(PacketPtr pkt); - virtual void serialize(std::ostream &os); + void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; }; #endif //__DEV_SPARC_MM_DISK_HH__ |