Ciro Santilli has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/36116 )

Change subject: arch-arm: serialize miscregs as a map
......................................................................

arch-arm: serialize miscregs as a map

This will prevent checkpoints from breaking on every miscreg addition.

Before this commit, miscregs were stored as an array:

[system.cpu.isa]
miscRegs=965 0 0 0 0 0 0 0 0 0 0 0 17895697 ...

and after this commit they are stored as a map:

[system.cpu.isa]
miscRegs.cpsr=965
miscRegs.spsr=0
miscRegs.spsr_fiq=0
miscRegs.spsr_irq=0
miscRegs.spsr_svc=0
miscRegs.spsr_mon=0
miscRegs.spsr_abt=0
miscRegs.spsr_hyp=0
miscRegs.spsr_und=0
miscRegs.elr_hyp=0
miscRegs.fpsid=0
miscRegs.fpscr=0
miscRegs.mvfr1=17895697

This follows a similar pattern to what was in use for the symbol table:

[system.workload]
symtab.size=10
symtab.addr_0=0
symtab.symbol_0=/tmp/ccPFSHJm.o
symtab.binding_0=1

Change-Id: I49999c7206bd9ac1cfb81297d45c8117ff8ae675
---
M src/arch/arm/isa.cc
M src/sim/serialize.hh
2 files changed, 60 insertions(+), 2 deletions(-)



diff --git a/src/arch/arm/isa.cc b/src/arch/arm/isa.cc
index 4e90dc8..788c549 100644
--- a/src/arch/arm/isa.cc
+++ b/src/arch/arm/isa.cc
@@ -2352,14 +2352,15 @@
 ISA::serialize(CheckpointOut &cp) const
 {
     DPRINTF(Checkpoint, "Serializing Arm Misc Registers\n");
-    SERIALIZE_ARRAY(miscRegs, NUM_PHYS_MISCREGS);
+    SERIALIZE_MAP(miscRegs, miscRegName, NUM_PHYS_MISCREGS);
+    mapParamOut(cp, "miscRegs", miscRegName, miscRegs, NUM_PHYS_MISCREGS);
 }

 void
 ISA::unserialize(CheckpointIn &cp)
 {
     DPRINTF(Checkpoint, "Unserializing Arm Misc Registers\n");
-    UNSERIALIZE_ARRAY(miscRegs, NUM_PHYS_MISCREGS);
+    UNSERIALIZE_MAP(miscRegs, miscRegName, NUM_PHYS_MISCREGS);
     CPSR tmp_cpsr = miscRegs[MISCREG_CPSR];
     updateRegMap(tmp_cpsr);
 }
diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh
index bbc91d7..6a78e05 100644
--- a/src/sim/serialize.hh
+++ b/src/sim/serialize.hh
@@ -52,6 +52,7 @@
 #include <map>
 #include <stack>
 #include <set>
+#include <unordered_map>
 #include <vector>

 #include "base/bitunion.hh"
@@ -776,6 +777,46 @@
 void
 objParamIn(CheckpointIn &cp, const std::string &name, SimObject * &param);

+/**
+ * @param names array of keys
+ * @param param array of values
+ * @param size size o fthe names and param arrays
+ *
+ * @ingroup api_serialize
+ */
+template <class T>
+void
+mapParamOut(CheckpointOut &os, const char* base,
+    const char* const names[], const T *param, unsigned size)
+{
+    for (unsigned i = 0; i < size; ++i) {
+        paramOut(os, csprintf("%s.%d", base, names[i]), param[i]);
+    }
+}
+
+/**
+ * Restore a map structure. Keys missing from the checkpoint are ignored.
+ *
+ * @ingroup api_serialize
+ */
+template <class T>
+void
+mapParamIn(CheckpointIn &os, const char* base,
+    const char* const names[], T *param, unsigned size)
+{
+    std::unordered_map<std::string, size_t> name_to_index;
+    for (size_t i = 0; i < size; i++) {
+        name_to_index[names[i]] = i;
+    }
+    for (size_t i = 0; i < size; i++) {
+        auto& key = names[i];
+        T value;
+        if (optParamIn(os, csprintf("%s.%s", base, key), value)) {
+            param[name_to_index[key]] = value;
+        }
+    }
+}
+
 //
 // These macros are streamlined to use in serialize/unserialize
 // functions.  It's assumed that serialize() has a parameter 'os' for
@@ -907,4 +948,20 @@
         objptr = dynamic_cast<decltype(objptr)>(sptr);  \
     } while (0)

+/**
+ * \def SERIALIZE_MAP(member, names, size)
+ *
+ * @ingroup api_serialize
+ */
+#define SERIALIZE_MAP(member, names, size) \
+        mapParamOut(cp, #member, names, member, size)
+
+/**
+ * \def UNSERIALIZE_MAP(member, names, size)
+ *
+ * @ingroup api_serialize
+ */
+#define UNSERIALIZE_MAP(member, names, size) \
+        mapParamIn(cp, #member, names, member, size)
+
 #endif // __SERIALIZE_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/36116
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I49999c7206bd9ac1cfb81297d45c8117ff8ae675
Gerrit-Change-Number: 36116
Gerrit-PatchSet: 1
Gerrit-Owner: Ciro Santilli <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to