summaryrefslogtreecommitdiff
path: root/src/dev/virtio
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2015-07-07 09:51:03 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2015-07-07 09:51:03 +0100
commit76cd4393c08b83fa9006ee7bce1fb62457e053c1 (patch)
treef1d2d109f77a8cf31365143d6eb127b610d924f5 /src/dev/virtio
parentd7a56ee524c976a41fa40e5382a28462de799645 (diff)
downloadgem5-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/virtio')
-rw-r--r--src/dev/virtio/base.cc24
-rw-r--r--src/dev/virtio/base.hh13
-rw-r--r--src/dev/virtio/fs9p.cc4
-rw-r--r--src/dev/virtio/fs9p.hh4
4 files changed, 19 insertions, 26 deletions
diff --git a/src/dev/virtio/base.cc b/src/dev/virtio/base.cc
index a65fe7fa4..ad97de99c 100644
--- a/src/dev/virtio/base.cc
+++ b/src/dev/virtio/base.cc
@@ -233,18 +233,18 @@ VirtQueue::VirtQueue(PortProxy &proxy, uint16_t size)
}
void
-VirtQueue::serialize(std::ostream &os)
+VirtQueue::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(_address);
SERIALIZE_SCALAR(_last_avail);
}
void
-VirtQueue::unserialize(Checkpoint *cp, const std::string &section)
+VirtQueue::unserialize(CheckpointIn &cp)
{
Addr addr_in;
- paramIn(cp, section, "_address", addr_in);
+ paramIn(cp, "_address", addr_in);
UNSERIALIZE_SCALAR(_last_avail);
// Use the address setter to ensure that the ring buffer addresses
@@ -336,27 +336,23 @@ VirtIODeviceBase::~VirtIODeviceBase()
}
void
-VirtIODeviceBase::serialize(std::ostream &os)
+VirtIODeviceBase::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(guestFeatures);
- paramOut(os, "_deviceStatus", (uint8_t)_deviceStatus);
+ SERIALIZE_SCALAR(_deviceStatus);
SERIALIZE_SCALAR(_queueSelect);
- for (QueueID i = 0; i < _queues.size(); ++i) {
- nameOut(os, csprintf("%s._queues.%i", name(), i));
- _queues[i]->serialize(os);
- }
+ for (QueueID i = 0; i < _queues.size(); ++i)
+ _queues[i]->serializeSection(cp, csprintf("_queues.%i", i));
}
void
-VirtIODeviceBase::unserialize(Checkpoint *cp, const std::string &section)
+VirtIODeviceBase::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(guestFeatures);
- uint8_t status;
- paramIn(cp, section, "_deviceStatus", status);
- _deviceStatus = status;
+ UNSERIALIZE_SCALAR(_deviceStatus);
UNSERIALIZE_SCALAR(_queueSelect);
for (QueueID i = 0; i < _queues.size(); ++i)
- _queues[i]->unserialize(cp, csprintf("%s._queues.%i", section, i));
+ _queues[i]->unserializeSection(cp, csprintf("_queues.%i", i));
}
void
diff --git a/src/dev/virtio/base.hh b/src/dev/virtio/base.hh
index fe1685767..de68f92e1 100644
--- a/src/dev/virtio/base.hh
+++ b/src/dev/virtio/base.hh
@@ -312,16 +312,15 @@ class VirtDescriptor
* @note Queues must be registered with
* VirtIODeviceBase::registerQueue() to be active.
*/
-class VirtQueue {
+class VirtQueue : public Serializable {
public:
virtual ~VirtQueue() {};
/** @{
* @name Checkpointing Interface
*/
- virtual void serialize(std::ostream &os);
- virtual void unserialize(Checkpoint *cp, const std::string &section);
- /** @} */
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
/** @{
* @name Low-level Device Interface
@@ -596,10 +595,8 @@ class VirtIODeviceBase : public SimObject
/** @{
* @name SimObject Interfaces
*/
-
- void serialize(std::ostream &os);
- void unserialize(Checkpoint *cp, const std::string &section);
-
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
/** @} */
diff --git a/src/dev/virtio/fs9p.cc b/src/dev/virtio/fs9p.cc
index 4861821d7..336757bb9 100644
--- a/src/dev/virtio/fs9p.cc
+++ b/src/dev/virtio/fs9p.cc
@@ -214,13 +214,13 @@ VirtIO9PProxy::~VirtIO9PProxy()
void
-VirtIO9PProxy::VirtIO9PProxy::serialize(std::ostream &os)
+VirtIO9PProxy::VirtIO9PProxy::serialize(CheckpointOut &cp) const
{
fatal("Can't checkpoint a system with a VirtIO 9p proxy!\n");
}
void
-VirtIO9PProxy::unserialize(Checkpoint *cp, const std::string &section)
+VirtIO9PProxy::unserialize(CheckpointIn &cp)
{
fatal("Can't checkpoint a system with a VirtIO 9p proxy!\n");
}
diff --git a/src/dev/virtio/fs9p.hh b/src/dev/virtio/fs9p.hh
index 2cbdbc9eb..a7fb780aa 100644
--- a/src/dev/virtio/fs9p.hh
+++ b/src/dev/virtio/fs9p.hh
@@ -216,8 +216,8 @@ class VirtIO9PProxy : public VirtIO9PBase
VirtIO9PProxy(Params *params);
virtual ~VirtIO9PProxy();
- void serialize(std::ostream &os);
- void unserialize(Checkpoint *cp, const std::string &section);
+ void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE;
protected:
void recvTMsg(const P9MsgHeader &header, const uint8_t *data, size_t size);