Ciro Santilli has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/36135 )

Change subject: sim: create SERIALIZE_MAPPING and UNSERIALIZE_MAPPING
......................................................................

sim: create SERIALIZE_MAPPING and UNSERIALIZE_MAPPING

The motivation for those new methods is to prevent checkpoints from
breaking when new map entries are added.

Change-Id: I0ff8681498bcf669492e6b876ad385fda4673d77
JIRA: https://gem5.atlassian.net/browse/GEM5-661
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/36135
Reviewed-by: Richard Cooper <[email protected]>
Reviewed-by: Daniel Carvalho <[email protected]>
Reviewed-by: Andreas Sandberg <[email protected]>
Maintainer: Bobby R. Bruce <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/sim/serialize.hh
1 file changed, 56 insertions(+), 1 deletion(-)

Approvals:
  Andreas Sandberg: Looks good to me, approved
  Daniel Carvalho: Looks good to me, approved
  Richard Cooper: Looks good to me, but someone else must approve
  Bobby R. Bruce: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh
index 51313a4..987bee2 100644
--- a/src/sim/serialize.hh
+++ b/src/sim/serialize.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2018 ARM Limited
+ * Copyright (c) 2015, 2018, 2020 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -50,7 +50,9 @@
 #include <iostream>
 #include <iterator>
 #include <stack>
+#include <set>
 #include <type_traits>
+#include <unordered_map>
 #include <vector>

 #include "base/logging.hh"
@@ -515,6 +517,47 @@
 void
 objParamIn(CheckpointIn &cp, const std::string &name, SimObject * &param);

+/**
+ * Serialize a mapping represented as two arrays: one containing names
+ * and the other containing values.
+ *
+ * @param names array of keys
+ * @param param array of values
+ * @param size size of the names and param arrays
+ */
+template <class T>
+void
+mappingParamOut(CheckpointOut &os, const char* sectionName,
+    const char* const names[], const T *param, unsigned size)
+{
+    Serializable::ScopedCheckpointSection sec(os, sectionName);
+    for (unsigned i = 0; i < size; ++i) {
+        paramOut(os, names[i], param[i]);
+    }
+}
+
+/**
+ * Restore mappingParamOut. Keys missing from the checkpoint are ignored.
+ */
+template <class T>
+void
+mappingParamIn(CheckpointIn &cp, const char* sectionName,
+    const char* const names[], T *param, unsigned size)
+{
+    Serializable::ScopedCheckpointSection sec(cp, sectionName);
+    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(cp, 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
@@ -646,4 +689,16 @@
         objptr = dynamic_cast<decltype(objptr)>(sptr);  \
     } while (0)

+/**
+ * \def SERIALIZE_MAPPING(member, names, size)
+ */
+#define SERIALIZE_MAPPING(member, names, size) \
+        mappingParamOut(cp, #member, names, member, size)
+
+/**
+ * \def UNSERIALIZE_MAPPING(member, names, size)
+ */
+#define UNSERIALIZE_MAPPING(member, names, size) \
+        mappingParamIn(cp, #member, names, member, size)
+
 #endif // __SERIALIZE_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/36135
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: I0ff8681498bcf669492e6b876ad385fda4673d77
Gerrit-Change-Number: 36135
Gerrit-PatchSet: 8
Gerrit-Owner: Ciro Santilli <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Ciro Santilli <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Richard Cooper <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
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