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/alpha | |
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/alpha')
-rw-r--r-- | src/dev/alpha/backdoor.cc | 12 | ||||
-rw-r--r-- | src/dev/alpha/backdoor.hh | 10 | ||||
-rw-r--r-- | src/dev/alpha/tsunami.cc | 4 | ||||
-rw-r--r-- | src/dev/alpha/tsunami.hh | 14 | ||||
-rw-r--r-- | src/dev/alpha/tsunami_cchip.cc | 4 | ||||
-rw-r--r-- | src/dev/alpha/tsunami_cchip.hh | 16 | ||||
-rw-r--r-- | src/dev/alpha/tsunami_io.cc | 12 | ||||
-rw-r--r-- | src/dev/alpha/tsunami_io.hh | 14 | ||||
-rw-r--r-- | src/dev/alpha/tsunami_pchip.cc | 4 | ||||
-rw-r--r-- | src/dev/alpha/tsunami_pchip.hh | 14 |
10 files changed, 31 insertions, 73 deletions
diff --git a/src/dev/alpha/backdoor.cc b/src/dev/alpha/backdoor.cc index 598620893..ec5765673 100644 --- a/src/dev/alpha/backdoor.cc +++ b/src/dev/alpha/backdoor.cc @@ -252,7 +252,7 @@ AlphaBackdoor::write(PacketPtr pkt) } void -AlphaBackdoor::Access::serialize(ostream &os) +AlphaBackdoor::Access::serialize(CheckpointOut &cp) const { SERIALIZE_SCALAR(last_offset); SERIALIZE_SCALAR(version); @@ -274,7 +274,7 @@ AlphaBackdoor::Access::serialize(ostream &os) } void -AlphaBackdoor::Access::unserialize(Checkpoint *cp, const std::string §ion) +AlphaBackdoor::Access::unserialize(CheckpointIn &cp) { UNSERIALIZE_SCALAR(last_offset); UNSERIALIZE_SCALAR(version); @@ -296,15 +296,15 @@ AlphaBackdoor::Access::unserialize(Checkpoint *cp, const std::string §ion) } void -AlphaBackdoor::serialize(ostream &os) +AlphaBackdoor::serialize(CheckpointOut &cp) const { - alphaAccess->serialize(os); + alphaAccess->serialize(cp); } void -AlphaBackdoor::unserialize(Checkpoint *cp, const std::string §ion) +AlphaBackdoor::unserialize(CheckpointIn &cp) { - alphaAccess->unserialize(cp, section); + alphaAccess->unserialize(cp); } AlphaBackdoor * diff --git a/src/dev/alpha/backdoor.hh b/src/dev/alpha/backdoor.hh index b9d04c7c0..da6201059 100644 --- a/src/dev/alpha/backdoor.hh +++ b/src/dev/alpha/backdoor.hh @@ -74,10 +74,10 @@ class SimpleDisk; class AlphaBackdoor : public BasicPioDevice { protected: - struct Access : public AlphaAccess + struct Access : public AlphaAccess, public Serializable { - void serialize(std::ostream &os); - void unserialize(Checkpoint *cp, const std::string §ion); + void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; + void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE; }; union { @@ -118,8 +118,8 @@ class AlphaBackdoor : public BasicPioDevice /** * standard serialization routines for checkpointing */ - 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_ALPHA_BACKDOOR_HH__ diff --git a/src/dev/alpha/tsunami.cc b/src/dev/alpha/tsunami.cc index 41a2fef0c..36b1a9ded 100644 --- a/src/dev/alpha/tsunami.cc +++ b/src/dev/alpha/tsunami.cc @@ -114,13 +114,13 @@ Tsunami::calcPciMemAddr(Addr addr) } void -Tsunami::serialize(std::ostream &os) +Tsunami::serialize(CheckpointOut &cp) const { SERIALIZE_ARRAY(intr_sum_type, Tsunami::Max_CPUs); } void -Tsunami::unserialize(Checkpoint *cp, const std::string §ion) +Tsunami::unserialize(CheckpointIn &cp) { UNSERIALIZE_ARRAY(intr_sum_type, Tsunami::Max_CPUs); } diff --git a/src/dev/alpha/tsunami.hh b/src/dev/alpha/tsunami.hh index 9380864b0..19df8093e 100644 --- a/src/dev/alpha/tsunami.hh +++ b/src/dev/alpha/tsunami.hh @@ -124,18 +124,8 @@ class Tsunami : public Platform */ virtual Addr calcPciMemAddr(Addr addr); - /** - * 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_TSUNAMI_HH__ diff --git a/src/dev/alpha/tsunami_cchip.cc b/src/dev/alpha/tsunami_cchip.cc index 7416de403..d67f4e3fb 100644 --- a/src/dev/alpha/tsunami_cchip.cc +++ b/src/dev/alpha/tsunami_cchip.cc @@ -507,7 +507,7 @@ TsunamiCChip::clearDRIR(uint32_t interrupt) void -TsunamiCChip::serialize(std::ostream &os) +TsunamiCChip::serialize(CheckpointOut &cp) const { SERIALIZE_ARRAY(dim, Tsunami::Max_CPUs); SERIALIZE_ARRAY(dir, Tsunami::Max_CPUs); @@ -517,7 +517,7 @@ TsunamiCChip::serialize(std::ostream &os) } void -TsunamiCChip::unserialize(Checkpoint *cp, const std::string §ion) +TsunamiCChip::unserialize(CheckpointIn &cp) { UNSERIALIZE_ARRAY(dim, Tsunami::Max_CPUs); UNSERIALIZE_ARRAY(dir, Tsunami::Max_CPUs); diff --git a/src/dev/alpha/tsunami_cchip.hh b/src/dev/alpha/tsunami_cchip.hh index e9aca5d5c..fdbe64ef1 100644 --- a/src/dev/alpha/tsunami_cchip.hh +++ b/src/dev/alpha/tsunami_cchip.hh @@ -131,20 +131,8 @@ class TsunamiCChip : public BasicPioDevice */ void reqIPI(uint64_t ipreq); - - /** - * 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 // __TSUNAMI_CCHIP_HH__ diff --git a/src/dev/alpha/tsunami_io.cc b/src/dev/alpha/tsunami_io.cc index 2236546fc..8015ec2fe 100644 --- a/src/dev/alpha/tsunami_io.cc +++ b/src/dev/alpha/tsunami_io.cc @@ -251,7 +251,7 @@ TsunamiIO::clearPIC(uint8_t bitvector) } void -TsunamiIO::serialize(ostream &os) +TsunamiIO::serialize(CheckpointOut &cp) const { SERIALIZE_SCALAR(rtcAddr); SERIALIZE_SCALAR(timerData); @@ -263,12 +263,12 @@ TsunamiIO::serialize(ostream &os) SERIALIZE_SCALAR(picInterrupting); // Serialize the timers - pitimer.serialize("pitimer", os); - rtc.serialize("rtc", os); + pitimer.serialize("pitimer", cp); + rtc.serialize("rtc", cp); } void -TsunamiIO::unserialize(Checkpoint *cp, const string §ion) +TsunamiIO::unserialize(CheckpointIn &cp) { UNSERIALIZE_SCALAR(rtcAddr); UNSERIALIZE_SCALAR(timerData); @@ -280,8 +280,8 @@ TsunamiIO::unserialize(Checkpoint *cp, const string §ion) UNSERIALIZE_SCALAR(picInterrupting); // Unserialize the timers - pitimer.unserialize("pitimer", cp, section); - rtc.unserialize("rtc", cp, section); + pitimer.unserialize("pitimer", cp); + rtc.unserialize("rtc", cp); } void diff --git a/src/dev/alpha/tsunami_io.hh b/src/dev/alpha/tsunami_io.hh index f242c9e2a..2b7f5484e 100644 --- a/src/dev/alpha/tsunami_io.hh +++ b/src/dev/alpha/tsunami_io.hh @@ -138,18 +138,8 @@ class TsunamiIO : public BasicPioDevice */ void clearPIC(uint8_t bitvector); - /** - * 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; /** * Start running. diff --git a/src/dev/alpha/tsunami_pchip.cc b/src/dev/alpha/tsunami_pchip.cc index 328699f9f..cfd1e69e4 100644 --- a/src/dev/alpha/tsunami_pchip.cc +++ b/src/dev/alpha/tsunami_pchip.cc @@ -324,7 +324,7 @@ TsunamiPChip::calcMemAddr(Addr addr) } void -TsunamiPChip::serialize(std::ostream &os) +TsunamiPChip::serialize(CheckpointOut &cp) const { SERIALIZE_SCALAR(pctl); SERIALIZE_ARRAY(wsba, 4); @@ -333,7 +333,7 @@ TsunamiPChip::serialize(std::ostream &os) } void -TsunamiPChip::unserialize(Checkpoint *cp, const std::string §ion) +TsunamiPChip::unserialize(CheckpointIn &cp) { UNSERIALIZE_SCALAR(pctl); UNSERIALIZE_ARRAY(wsba, 4); diff --git a/src/dev/alpha/tsunami_pchip.hh b/src/dev/alpha/tsunami_pchip.hh index 3e32db989..0eb992131 100644 --- a/src/dev/alpha/tsunami_pchip.hh +++ b/src/dev/alpha/tsunami_pchip.hh @@ -89,18 +89,8 @@ class TsunamiPChip : 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 // __TSUNAMI_PCHIP_HH__ |