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/arch/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/arch/alpha')
-rw-r--r-- | src/arch/alpha/interrupts.hh | 4 | ||||
-rw-r--r-- | src/arch/alpha/isa.cc | 4 | ||||
-rw-r--r-- | src/arch/alpha/isa.hh | 4 | ||||
-rw-r--r-- | src/arch/alpha/kernel_stats.cc | 8 | ||||
-rw-r--r-- | src/arch/alpha/kernel_stats.hh | 4 | ||||
-rw-r--r-- | src/arch/alpha/pagetable.cc | 4 | ||||
-rw-r--r-- | src/arch/alpha/pagetable.hh | 11 | ||||
-rw-r--r-- | src/arch/alpha/process.cc | 2 | ||||
-rw-r--r-- | src/arch/alpha/process.hh | 2 | ||||
-rw-r--r-- | src/arch/alpha/system.cc | 12 | ||||
-rw-r--r-- | src/arch/alpha/system.hh | 4 | ||||
-rw-r--r-- | src/arch/alpha/tlb.cc | 27 | ||||
-rw-r--r-- | src/arch/alpha/tlb.hh | 11 |
13 files changed, 49 insertions, 48 deletions
diff --git a/src/arch/alpha/interrupts.hh b/src/arch/alpha/interrupts.hh index 3e9c90381..1e67f54b5 100644 --- a/src/arch/alpha/interrupts.hh +++ b/src/arch/alpha/interrupts.hh @@ -121,14 +121,14 @@ class Interrupts : public SimObject } void - serialize(std::ostream &os) + serialize(CheckpointOut &cp) const { SERIALIZE_ARRAY(interrupts, NumInterruptLevels); SERIALIZE_SCALAR(intstatus); } void - unserialize(Checkpoint *cp, const std::string §ion) + unserialize(CheckpointIn &cp) { UNSERIALIZE_ARRAY(interrupts, NumInterruptLevels); UNSERIALIZE_SCALAR(intstatus); diff --git a/src/arch/alpha/isa.cc b/src/arch/alpha/isa.cc index 20f039166..8240037cc 100644 --- a/src/arch/alpha/isa.cc +++ b/src/arch/alpha/isa.cc @@ -53,7 +53,7 @@ ISA::params() const } void -ISA::serialize(std::ostream &os) +ISA::serialize(CheckpointOut &cp) const { SERIALIZE_SCALAR(fpcr); SERIALIZE_SCALAR(uniq); @@ -63,7 +63,7 @@ ISA::serialize(std::ostream &os) } void -ISA::unserialize(Checkpoint *cp, const std::string §ion) +ISA::unserialize(CheckpointIn &cp) { UNSERIALIZE_SCALAR(fpcr); UNSERIALIZE_SCALAR(uniq); diff --git a/src/arch/alpha/isa.hh b/src/arch/alpha/isa.hh index 52e4e98be..6a88ee40b 100644 --- a/src/arch/alpha/isa.hh +++ b/src/arch/alpha/isa.hh @@ -92,8 +92,8 @@ namespace AlphaISA memset(ipr, 0, sizeof(ipr)); } - 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; int flattenIntIndex(int reg) const diff --git a/src/arch/alpha/kernel_stats.cc b/src/arch/alpha/kernel_stats.cc index bac5d26cd..94142a031 100644 --- a/src/arch/alpha/kernel_stats.cc +++ b/src/arch/alpha/kernel_stats.cc @@ -194,9 +194,9 @@ Statistics::callpal(int code, ThreadContext *tc) } void -Statistics::serialize(ostream &os) +Statistics::serialize(CheckpointOut &cp) const { - ::Kernel::Statistics::serialize(os); + ::Kernel::Statistics::serialize(cp); int exemode = themode; SERIALIZE_SCALAR(exemode); SERIALIZE_SCALAR(idleProcess); @@ -204,9 +204,9 @@ Statistics::serialize(ostream &os) } void -Statistics::unserialize(Checkpoint *cp, const string §ion) +Statistics::unserialize(CheckpointIn &cp) { - ::Kernel::Statistics::unserialize(cp, section); + ::Kernel::Statistics::unserialize(cp); int exemode; UNSERIALIZE_SCALAR(exemode); UNSERIALIZE_SCALAR(idleProcess); diff --git a/src/arch/alpha/kernel_stats.hh b/src/arch/alpha/kernel_stats.hh index 837269309..188d3ec4b 100644 --- a/src/arch/alpha/kernel_stats.hh +++ b/src/arch/alpha/kernel_stats.hh @@ -86,8 +86,8 @@ class Statistics : public ::Kernel::Statistics void setIdleProcess(Addr idle, ThreadContext *tc); public: - 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; }; } // namespace Kernel diff --git a/src/arch/alpha/pagetable.cc b/src/arch/alpha/pagetable.cc index 4dff04777..f2b1147f7 100644 --- a/src/arch/alpha/pagetable.cc +++ b/src/arch/alpha/pagetable.cc @@ -34,7 +34,7 @@ namespace AlphaISA { void -TlbEntry::serialize(std::ostream &os) +TlbEntry::serialize(CheckpointOut &cp) const { SERIALIZE_SCALAR(tag); SERIALIZE_SCALAR(ppn); @@ -48,7 +48,7 @@ TlbEntry::serialize(std::ostream &os) } void -TlbEntry::unserialize(Checkpoint *cp, const std::string §ion) +TlbEntry::unserialize(CheckpointIn &cp) { UNSERIALIZE_SCALAR(tag); UNSERIALIZE_SCALAR(ppn); diff --git a/src/arch/alpha/pagetable.hh b/src/arch/alpha/pagetable.hh index ca44de7fa..0b6524043 100644 --- a/src/arch/alpha/pagetable.hh +++ b/src/arch/alpha/pagetable.hh @@ -90,7 +90,7 @@ struct PageTableEntry }; // ITB/DTB table entry -struct TlbEntry +struct TlbEntry : public Serializable { Addr tag; // virtual page number tag Addr ppn; // physical page number @@ -124,7 +124,10 @@ struct TlbEntry } TlbEntry() - {} + : tag(0), ppn(0), xre(0), xwe(0), asn(0), + asma(false), fonr(0), fonw(0), valid(0) + { + } void updateVaddr(Addr new_vaddr) @@ -139,8 +142,8 @@ struct TlbEntry return ppn << PageShift; } - 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; }; } // namespace AlphaISA diff --git a/src/arch/alpha/process.cc b/src/arch/alpha/process.cc index f50131be0..e214c8874 100644 --- a/src/arch/alpha/process.cc +++ b/src/arch/alpha/process.cc @@ -175,7 +175,7 @@ AlphaLiveProcess::setupASNReg() void -AlphaLiveProcess::loadState(Checkpoint *cp) +AlphaLiveProcess::loadState(CheckpointIn &cp) { LiveProcess::loadState(cp); // need to set up ASN after unserialization since M5_pid value may diff --git a/src/arch/alpha/process.hh b/src/arch/alpha/process.hh index d3f9fdfc3..6701017e0 100644 --- a/src/arch/alpha/process.hh +++ b/src/arch/alpha/process.hh @@ -42,7 +42,7 @@ class AlphaLiveProcess : public LiveProcess protected: AlphaLiveProcess(LiveProcessParams *params, ObjectFile *objFile); - void loadState(Checkpoint *cp); + void loadState(CheckpointIn &cp) M5_ATTR_OVERRIDE; void initState(); void argsInit(int intSize, int pageSize); diff --git a/src/arch/alpha/system.cc b/src/arch/alpha/system.cc index 3ebc02b64..d2be5492f 100644 --- a/src/arch/alpha/system.cc +++ b/src/arch/alpha/system.cc @@ -218,17 +218,17 @@ AlphaSystem::setAlphaAccess(Addr access) } void -AlphaSystem::serializeSymtab(std::ostream &os) +AlphaSystem::serializeSymtab(CheckpointOut &cp) const { - consoleSymtab->serialize("console_symtab", os); - palSymtab->serialize("pal_symtab", os); + consoleSymtab->serialize("console_symtab", cp); + palSymtab->serialize("pal_symtab", cp); } void -AlphaSystem::unserializeSymtab(Checkpoint *cp, const std::string §ion) +AlphaSystem::unserializeSymtab(CheckpointIn &cp) { - consoleSymtab->unserialize("console_symtab", cp, section); - palSymtab->unserialize("pal_symtab", cp, section); + consoleSymtab->unserialize("console_symtab", cp); + palSymtab->unserialize("pal_symtab", cp); } AlphaSystem * diff --git a/src/arch/alpha/system.hh b/src/arch/alpha/system.hh index 11a5e90a4..3f4a2367e 100644 --- a/src/arch/alpha/system.hh +++ b/src/arch/alpha/system.hh @@ -60,8 +60,8 @@ class AlphaSystem : public System /** * Serialization stuff */ - virtual void serializeSymtab(std::ostream &os); - virtual void unserializeSymtab(Checkpoint *cp, const std::string §ion); + void serializeSymtab(CheckpointOut &cp) const M5_ATTR_OVERRIDE; + void unserializeSymtab(CheckpointIn &cp) M5_ATTR_OVERRIDE; /** Override startup() to provide a path to call setupFuncEvents() */ diff --git a/src/arch/alpha/tlb.cc b/src/arch/alpha/tlb.cc index a740da388..5f0ed85db 100644 --- a/src/arch/alpha/tlb.cc +++ b/src/arch/alpha/tlb.cc @@ -30,13 +30,15 @@ * Andrew Schultz */ +#include "arch/alpha/tlb.hh" + +#include <algorithm> #include <memory> #include <string> #include <vector> #include "arch/alpha/faults.hh" #include "arch/alpha/pagetable.hh" -#include "arch/alpha/tlb.hh" #include "arch/generic/debugfaults.hh" #include "base/inifile.hh" #include "base/str.hh" @@ -62,17 +64,13 @@ bool uncacheBit40 = false; #define MODE2MASK(X) (1 << (X)) TLB::TLB(const Params *p) - : BaseTLB(p), size(p->size), nlu(0) + : BaseTLB(p), table(p->size), nlu(0) { - table = new TlbEntry[size]; - memset(table, 0, sizeof(TlbEntry) * size); flushCache(); } TLB::~TLB() { - if (table) - delete [] table; } void @@ -283,7 +281,7 @@ void TLB::flushAll() { DPRINTF(TLB, "flushAll\n"); - memset(table, 0, sizeof(TlbEntry) * size); + std::fill(table.begin(), table.end(), TlbEntry()); flushCache(); lookupTable.clear(); nlu = 0; @@ -345,25 +343,26 @@ TLB::flushAddr(Addr addr, uint8_t asn) void -TLB::serialize(ostream &os) +TLB::serialize(CheckpointOut &cp) const { + const unsigned size(table.size()); SERIALIZE_SCALAR(size); SERIALIZE_SCALAR(nlu); - for (int i = 0; i < size; i++) { - nameOut(os, csprintf("%s.Entry%d", name(), i)); - table[i].serialize(os); - } + for (int i = 0; i < size; i++) + table[i].serializeSection(cp, csprintf("Entry%d", i)); } void -TLB::unserialize(Checkpoint *cp, const string §ion) +TLB::unserialize(CheckpointIn &cp) { + unsigned size(0); UNSERIALIZE_SCALAR(size); UNSERIALIZE_SCALAR(nlu); + table.resize(size); for (int i = 0; i < size; i++) { - table[i].unserialize(cp, csprintf("%s.Entry%d", section, i)); + table[i].unserializeSection(cp, csprintf("Entry%d", i)); if (table[i].valid) { lookupTable.insert(make_pair(table[i].tag, i)); } diff --git a/src/arch/alpha/tlb.hh b/src/arch/alpha/tlb.hh index ccd4362d3..73ffda1f6 100644 --- a/src/arch/alpha/tlb.hh +++ b/src/arch/alpha/tlb.hh @@ -74,11 +74,10 @@ class TLB : public BaseTLB typedef std::multimap<Addr, int> PageTable; PageTable lookupTable; // Quick lookup into page table - TlbEntry *table; // the Page Table - int size; // TLB Size + std::vector<TlbEntry> table; // the Page Table int nlu; // not last used entry (for replacement) - void nextnlu() { if (++nlu >= size) nlu = 0; } + void nextnlu() { if (++nlu >= table.size()) nlu = 0; } TlbEntry *lookup(Addr vpn, uint8_t asn); public: @@ -90,7 +89,7 @@ class TLB : public BaseTLB virtual void regStats(); - int getsize() const { return size; } + int getsize() const { return table.size(); } TlbEntry &index(bool advance = true); void insert(Addr vaddr, TlbEntry &entry); @@ -118,8 +117,8 @@ class TLB : public BaseTLB static Fault checkCacheability(RequestPtr &req, bool itb = false); // 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; // Most recently used page table entries TlbEntry *EntryCache[3]; |