summaryrefslogtreecommitdiff
path: root/src/arch/sparc
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/arch/sparc
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/arch/sparc')
-rw-r--r--src/arch/sparc/interrupts.hh4
-rw-r--r--src/arch/sparc/isa.cc4
-rw-r--r--src/arch/sparc/isa.hh5
-rw-r--r--src/arch/sparc/pagetable.cc4
-rw-r--r--src/arch/sparc/pagetable.hh4
-rw-r--r--src/arch/sparc/system.cc28
-rw-r--r--src/arch/sparc/system.hh4
-rw-r--r--src/arch/sparc/tlb.cc39
-rw-r--r--src/arch/sparc/tlb.hh4
9 files changed, 44 insertions, 52 deletions
diff --git a/src/arch/sparc/interrupts.hh b/src/arch/sparc/interrupts.hh
index 56cbbf0eb..432132f66 100644
--- a/src/arch/sparc/interrupts.hh
+++ b/src/arch/sparc/interrupts.hh
@@ -191,14 +191,14 @@ class Interrupts : public SimObject
}
void
- serialize(std::ostream &os)
+ serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE
{
SERIALIZE_ARRAY(interrupts,NumInterruptTypes);
SERIALIZE_SCALAR(intStatus);
}
void
- unserialize(Checkpoint *cp, const std::string &section)
+ unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE
{
UNSERIALIZE_ARRAY(interrupts,NumInterruptTypes);
UNSERIALIZE_SCALAR(intStatus);
diff --git a/src/arch/sparc/isa.cc b/src/arch/sparc/isa.cc
index c9a3a33b4..a588eaf66 100644
--- a/src/arch/sparc/isa.cc
+++ b/src/arch/sparc/isa.cc
@@ -638,7 +638,7 @@ ISA::setMiscReg(int miscReg, MiscReg val, ThreadContext * tc)
}
void
-ISA::serialize(std::ostream &os)
+ISA::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(asi);
SERIALIZE_SCALAR(tick);
@@ -714,7 +714,7 @@ ISA::serialize(std::ostream &os)
}
void
-ISA::unserialize(Checkpoint *cp, const std::string &section)
+ISA::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(asi);
UNSERIALIZE_SCALAR(tick);
diff --git a/src/arch/sparc/isa.hh b/src/arch/sparc/isa.hh
index 4551cf3c1..1d2a457d2 100644
--- a/src/arch/sparc/isa.hh
+++ b/src/arch/sparc/isa.hh
@@ -167,9 +167,8 @@ class ISA : public SimObject
void clear();
- 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;
void startup(ThreadContext *tc) {}
diff --git a/src/arch/sparc/pagetable.cc b/src/arch/sparc/pagetable.cc
index bdd3e97fe..f0d2c10cf 100644
--- a/src/arch/sparc/pagetable.cc
+++ b/src/arch/sparc/pagetable.cc
@@ -35,7 +35,7 @@ namespace SparcISA
{
void
-TlbEntry::serialize(std::ostream &os)
+TlbEntry::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(range.va);
SERIALIZE_SCALAR(range.size);
@@ -52,7 +52,7 @@ TlbEntry::serialize(std::ostream &os)
void
-TlbEntry::unserialize(Checkpoint *cp, const std::string &section)
+TlbEntry::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(range.va);
UNSERIALIZE_SCALAR(range.size);
diff --git a/src/arch/sparc/pagetable.hh b/src/arch/sparc/pagetable.hh
index 727727f95..79b4d3cc5 100644
--- a/src/arch/sparc/pagetable.hh
+++ b/src/arch/sparc/pagetable.hh
@@ -277,8 +277,8 @@ struct TlbEntry
range.va = new_vaddr;
}
- void serialize(std::ostream &os);
- void unserialize(Checkpoint *cp, const std::string &section);
+ void serialize(CheckpointOut &cp) const;
+ void unserialize(CheckpointIn &cp);
};
} // namespace SparcISA
diff --git a/src/arch/sparc/system.cc b/src/arch/sparc/system.cc
index 0b36df9ca..b6fa645ce 100644
--- a/src/arch/sparc/system.cc
+++ b/src/arch/sparc/system.cc
@@ -177,26 +177,26 @@ SparcSystem::~SparcSystem()
}
void
-SparcSystem::serializeSymtab(std::ostream &os)
+SparcSystem::serializeSymtab(CheckpointOut &cp) const
{
- resetSymtab->serialize("reset_symtab", os);
- hypervisorSymtab->serialize("hypervisor_symtab", os);
- openbootSymtab->serialize("openboot_symtab", os);
- nvramSymtab->serialize("nvram_symtab", os);
- hypervisorDescSymtab->serialize("hypervisor_desc_symtab", os);
- partitionDescSymtab->serialize("partition_desc_symtab", os);
+ resetSymtab->serialize("reset_symtab", cp);
+ hypervisorSymtab->serialize("hypervisor_symtab", cp);
+ openbootSymtab->serialize("openboot_symtab", cp);
+ nvramSymtab->serialize("nvram_symtab", cp);
+ hypervisorDescSymtab->serialize("hypervisor_desc_symtab", cp);
+ partitionDescSymtab->serialize("partition_desc_symtab", cp);
}
void
-SparcSystem::unserializeSymtab(Checkpoint *cp, const std::string &section)
+SparcSystem::unserializeSymtab(CheckpointIn &cp)
{
- resetSymtab->unserialize("reset_symtab", cp, section);
- hypervisorSymtab->unserialize("hypervisor_symtab", cp, section);
- openbootSymtab->unserialize("openboot_symtab", cp, section);
- nvramSymtab->unserialize("nvram_symtab", cp, section);
- hypervisorDescSymtab->unserialize("hypervisor_desc_symtab", cp, section);
- partitionDescSymtab->unserialize("partition_desc_symtab", cp, section);
+ resetSymtab->unserialize("reset_symtab", cp);
+ hypervisorSymtab->unserialize("hypervisor_symtab", cp);
+ openbootSymtab->unserialize("openboot_symtab", cp);
+ nvramSymtab->unserialize("nvram_symtab", cp);
+ hypervisorDescSymtab->unserialize("hypervisor_desc_symtab", cp);
+ partitionDescSymtab->unserialize("partition_desc_symtab", cp);
}
SparcSystem *
diff --git a/src/arch/sparc/system.hh b/src/arch/sparc/system.hh
index a4bd64aa5..68688cc1f 100644
--- a/src/arch/sparc/system.hh
+++ b/src/arch/sparc/system.hh
@@ -54,8 +54,8 @@ class SparcSystem : public System
* Serialization stuff
*/
public:
- virtual void serializeSymtab(std::ostream &os);
- virtual void unserializeSymtab(Checkpoint *cp, const std::string &section);
+ void serializeSymtab(CheckpointOut &cp) const M5_ATTR_OVERRIDE;
+ void unserializeSymtab(CheckpointIn &cp) M5_ATTR_OVERRIDE;
/** reset binary symbol table */
SymbolTable *resetSymtab;
diff --git a/src/arch/sparc/tlb.cc b/src/arch/sparc/tlb.cc
index 84d748dd3..c0c28f952 100644
--- a/src/arch/sparc/tlb.cc
+++ b/src/arch/sparc/tlb.cc
@@ -1353,23 +1353,18 @@ TLB::MakeTsbPtr(TsbPageSize ps, uint64_t tag_access, uint64_t c0_tsb,
}
void
-TLB::serialize(std::ostream &os)
+TLB::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(size);
SERIALIZE_SCALAR(usedEntries);
SERIALIZE_SCALAR(lastReplaced);
// convert the pointer based free list into an index based one
- int *free_list = (int*)malloc(sizeof(int) * size);
- int cntr = 0;
- std::list<TlbEntry*>::iterator i;
- i = freeList.begin();
- while (i != freeList.end()) {
- free_list[cntr++] = ((size_t)*i - (size_t)tlb)/ sizeof(TlbEntry);
- i++;
- }
- SERIALIZE_SCALAR(cntr);
- SERIALIZE_ARRAY(free_list, cntr);
+ std::vector<int> free_list;
+ for (const TlbEntry *entry : freeList)
+ free_list.push_back(entry - tlb);
+
+ SERIALIZE_CONTAINER(free_list);
SERIALIZE_SCALAR(c0_tsb_ps0);
SERIALIZE_SCALAR(c0_tsb_ps1);
@@ -1381,31 +1376,28 @@ TLB::serialize(std::ostream &os)
SERIALIZE_SCALAR(tag_access);
for (int x = 0; x < size; x++) {
- nameOut(os, csprintf("%s.PTE%d", name(), x));
- tlb[x].serialize(os);
+ ScopedCheckpointSection sec(cp, csprintf("PTE%d", x));
+ tlb[x].serialize(cp);
}
SERIALIZE_SCALAR(sfar);
}
void
-TLB::unserialize(Checkpoint *cp, const std::string &section)
+TLB::unserialize(CheckpointIn &cp)
{
int oldSize;
- paramIn(cp, section, "size", oldSize);
+ paramIn(cp, "size", oldSize);
if (oldSize != size)
panic("Don't support unserializing different sized TLBs\n");
UNSERIALIZE_SCALAR(usedEntries);
UNSERIALIZE_SCALAR(lastReplaced);
- int cntr;
- UNSERIALIZE_SCALAR(cntr);
-
- int *free_list = (int*)malloc(sizeof(int) * cntr);
+ std::vector<int> free_list;
+ UNSERIALIZE_CONTAINER(free_list);
freeList.clear();
- UNSERIALIZE_ARRAY(free_list, cntr);
- for (int x = 0; x < cntr; x++)
- freeList.push_back(&tlb[free_list[x]]);
+ for (int idx : free_list)
+ freeList.push_back(&tlb[idx]);
UNSERIALIZE_SCALAR(c0_tsb_ps0);
UNSERIALIZE_SCALAR(c0_tsb_ps1);
@@ -1418,7 +1410,8 @@ TLB::unserialize(Checkpoint *cp, const std::string &section)
lookupTable.clear();
for (int x = 0; x < size; x++) {
- tlb[x].unserialize(cp, csprintf("%s.PTE%d", section, x));
+ ScopedCheckpointSection sec(cp, csprintf("PTE%d", x));
+ tlb[x].unserialize(cp);
if (tlb[x].valid)
lookupTable.insert(tlb[x].range, &tlb[x]);
diff --git a/src/arch/sparc/tlb.hh b/src/arch/sparc/tlb.hh
index 1d229fba7..e64d3f1b4 100644
--- a/src/arch/sparc/tlb.hh
+++ b/src/arch/sparc/tlb.hh
@@ -176,8 +176,8 @@ class TLB : public BaseTLB
void GetTsbPtr(ThreadContext *tc, Addr addr, int ctx, Addr *ptrs);
// Checkpointing
- 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;
/** Give an entry id, read that tlb entries' tte */
uint64_t TteRead(int entry);