Daniel Carvalho has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/43586 )
Change subject: sim,util: Remove event dependencies from serialize.hh
......................................................................
sim,util: Remove event dependencies from serialize.hh
With this change serialize.hh is no longer responsible
for the (un)serialization of events. As a general rule,
rules to (un)serialize non-basic types should be defined
at the file that introduces that type. Therefore,
(UN)SERIALIZE_EVENT have been moved to eventq.hh.
Globals has a single instance which must be serialized
and unserialized. Instead of having a stray global
variable handled by Serialization, we pass its management
to Root. As a side effect, Globals is assigned its own
files: sim/globals.(cc/hh).
Finally, 'unserializeGlobals()' is removed, so that
Root can fully handle Globals' serialization. This
breaks checkpoint compatibility, so a checkpoint
upgrader is added.
Change-Id: I9c8e57306f83f9cc30ab2b745a4972755191bec4
Signed-off-by: Daniel R. Carvalho <[email protected]>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/43586
Tested-by: kokoro <[email protected]>
Maintainer: Bobby R. Bruce <[email protected]>
Reviewed-by: Giacomo Travaglini <[email protected]>
---
M src/python/m5/simulate.py
M src/python/pybind11/core.cc
M src/sim/SConscript
M src/sim/eventq.hh
A src/sim/globals.cc
A src/sim/globals.hh
M src/sim/root.cc
M src/sim/root.hh
M src/sim/serialize.cc
M src/sim/serialize.hh
M src/sim/sim_object.cc
M util/cpt_upgrader.py
A util/cpt_upgraders/globals-to-root.py
13 files changed, 234 insertions(+), 127 deletions(-)
Approvals:
Giacomo Travaglini: Looks good to me, approved
Bobby R. Bruce: Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/python/m5/simulate.py b/src/python/m5/simulate.py
index a1a05dc..4a05095 100644
--- a/src/python/m5/simulate.py
+++ b/src/python/m5/simulate.py
@@ -142,7 +142,6 @@
if ckpt_dir:
_drain_manager.preCheckpointRestore()
ckpt = _m5.core.getCheckpoint(ckpt_dir)
- _m5.core.unserializeGlobals(ckpt);
for obj in root.descendants(): obj.loadState(ckpt)
else:
for obj in root.descendants(): obj.initState()
diff --git a/src/python/pybind11/core.cc b/src/python/pybind11/core.cc
index 883a7bf..3b99ede 100644
--- a/src/python/pybind11/core.cc
+++ b/src/python/pybind11/core.cc
@@ -308,7 +308,6 @@
*/
m_core
.def("serializeAll", &Serializable::serializeAll)
- .def("unserializeGlobals", &Serializable::unserializeGlobals)
.def("getCheckpoint", [](const std::string &cpt_dir) {
SimObject::setSimObjectResolver(&pybindSimObjectResolver);
return new CheckpointIn(cpt_dir);
diff --git a/src/sim/SConscript b/src/sim/SConscript
index 700f702..a560d3b 100644
--- a/src/sim/SConscript
+++ b/src/sim/SConscript
@@ -54,6 +54,7 @@
Source('eventq.cc')
Source('futex_map.cc')
Source('global_event.cc')
+Source('globals.cc')
Source('init.cc', add_tags='python')
Source('init_signals.cc')
Source('main.cc', tags='main')
diff --git a/src/sim/eventq.hh b/src/sim/eventq.hh
index 5c8813a..774881b 100644
--- a/src/sim/eventq.hh
+++ b/src/sim/eventq.hh
@@ -1152,4 +1152,22 @@
const char *description() const { return "EventFunctionWrapped"; }
};
+/**
+ * \def SERIALIZE_EVENT(event)
+ *
+ * @ingroup api_serialize
+ */
+#define SERIALIZE_EVENT(event) event.serializeSection(cp, #event);
+
+/**
+ * \def UNSERIALIZE_EVENT(event)
+ *
+ * @ingroup api_serialize
+ */
+#define UNSERIALIZE_EVENT(event) \
+ do { \
+ event.unserializeSection(cp, #event); \
+ eventQueue()->checkpointReschedule(&event); \
+ } while (0)
+
#endif // __SIM_EVENTQ_HH__
diff --git a/src/sim/globals.cc b/src/sim/globals.cc
new file mode 100644
index 0000000..e3f0c21
--- /dev/null
+++ b/src/sim/globals.cc
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2015 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Copyright (c) 2002-2005 The Regents of The University of Michigan
+ * Copyright (c) 2013 Advanced Micro Devices, Inc.
+ * Copyright (c) 2013 Mark D. Hill and David A. Wood
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "sim/globals.hh"
+
+#include <set>
+#include <string>
+
+#include "base/logging.hh"
+#include "sim/cur_tick.hh"
+
+/// The version tags for this build of the simulator, to be stored in the
+/// Globals section during serialization and compared upon unserialization.
+extern std::set<std::string> version_tags;
+
+void
+Globals::serialize(CheckpointOut &cp) const
+{
+ paramOut(cp, "curTick", curTick());
+ SERIALIZE_CONTAINER(version_tags);
+}
+
+void
+Globals::unserialize(CheckpointIn &cp)
+{
+ paramIn(cp, "curTick", unserializedCurTick);
+
+ const std::string divider =
+ "**********************************************************\n";
+ const std::string §ion(Serializable::currentSection());
+ std::string str;
+ if (!cp.find(section, "version_tags", str)) {
+ warn(divider);
+ warn("!!!! Checkpoint uses an old versioning
scheme. !!!!\n");
+ warn("Run the checkpoint upgrader (util/cpt_upgrader.py) on your "
+ "checkpoint\n");
+ warn(divider);
+ return;
+ }
+
+ std::set<std::string> cpt_tags;
+ arrayParamIn(cp, "version_tags", cpt_tags); // UNSERIALIZE_CONTAINER
+
+ bool err = false;
+ for (const auto& t : version_tags) {
+ if (cpt_tags.find(t) == cpt_tags.end()) {
+ // checkpoint is missing tag that this binary has
+ if (!err) {
+ warn(divider);
+ warn(
+ "!!! Checkpoint is missing the following version
tags:\n");
+ err = true;
+ }
+ warn(" %s\n", t);
+ }
+ }
+ if (err) {
+ warn("You might experience some issues when restoring and should
run "
+ "the checkpoint upgrader (util/cpt_upgrader.py) on your "
+ "checkpoint\n");
+ warn(divider);
+ }
+
+ err = false;
+ for (const auto& t : cpt_tags) {
+ if (version_tags.find(t) == version_tags.end()) {
+ // gem5 binary is missing tag that this checkpoint has
+ if (!err) {
+ warn(divider);
+ warn("!!!! gem5 is missing the following version tags:\n");
+ err = true;
+ }
+ warn(" %s\n", t);
+ }
+ }
+ if (err) {
+ warn("Running a checkpoint with incompatible version tags is not "
+ "supported. While it might work, you may experience
incorrect "
+ "behavior or crashes.\n");
+ warn(divider);
+ }
+}
diff --git a/src/sim/globals.hh b/src/sim/globals.hh
new file mode 100644
index 0000000..8aca7d9
--- /dev/null
+++ b/src/sim/globals.hh
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2015 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Copyright (c) 2002-2005 The Regents of The University of Michigan
+ * Copyright (c) 2013 Advanced Micro Devices, Inc.
+ * Copyright (c) 2013 Mark D. Hill and David A. Wood
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __SIM_GLOBALS_HH__
+#define __SIM_GLOBALS_HH__
+
+#include "base/types.hh"
+#include "sim/serialize.hh"
+
+/// Container for serializing global variables (not associated with
+/// any serialized object).
+class Globals : public Serializable
+{
+ public:
+ Globals() : unserializedCurTick(0) {}
+ ~Globals() = default;
+
+ void serialize(CheckpointOut &cp) const override;
+ void unserialize(CheckpointIn &cp) override;
+
+ Tick unserializedCurTick;
+};
+
+#endif // __SIM_GLOBALS_HH__
diff --git a/src/sim/root.cc b/src/sim/root.cc
index 72c2fba..6750341 100644
--- a/src/sim/root.cc
+++ b/src/sim/root.cc
@@ -203,8 +203,17 @@
SERIALIZE_SCALAR(FullSystem);
std::string isa = THE_ISA_STR;
SERIALIZE_SCALAR(isa);
+
+ globals.serializeSection(cp, "globals");
}
+void
+Root::unserialize(CheckpointIn &cp)
+{
+ globals.unserializeSection(cp, "globals");
+ for (uint32_t i = 0; i < numMainEventQueues; ++i)
+ mainEventQueue[i]->setCurTick(globals.unserializedCurTick);
+}
bool FullSystem;
unsigned int FullSystemInt;
diff --git a/src/sim/root.hh b/src/sim/root.hh
index b795746..14861d4 100644
--- a/src/sim/root.hh
+++ b/src/sim/root.hh
@@ -56,6 +56,7 @@
#include "base/types.hh"
#include "params/Root.hh"
#include "sim/eventq.hh"
+#include "sim/globals.hh"
#include "sim/sim_object.hh"
class Root : public SimObject
@@ -71,6 +72,8 @@
Time lastTime;
+ Globals globals;
+
void timeSync();
EventFunctionWrapper syncEvent;
@@ -143,6 +146,7 @@
void startup() override;
void serialize(CheckpointOut &cp) const override;
+ void unserialize(CheckpointIn &cp) override;
};
/**
diff --git a/src/sim/serialize.cc b/src/sim/serialize.cc
index 0b1faa2..86aaecb 100644
--- a/src/sim/serialize.cc
+++ b/src/sim/serialize.cc
@@ -57,9 +57,6 @@
#include "base/output.hh"
#include "base/trace.hh"
#include "debug/Checkpoint.hh"
-#include "sim/eventq.hh"
-#include "sim/sim_events.hh"
-#include "sim/sim_exit.hh"
#include "sim/sim_object.hh"
// For stat reset hack
@@ -72,92 +69,6 @@
/////////////////////////////
-/// Container for serializing global variables (not associated with
-/// any serialized object).
-class Globals : public Serializable
-{
- public:
- Globals()
- : unserializedCurTick(0) {}
-
- void serialize(CheckpointOut &cp) const override;
- void unserialize(CheckpointIn &cp) override;
-
- Tick unserializedCurTick;
-};
-
-/// The one and only instance of the Globals class.
-Globals globals;
-
-/// The version tags for this build of the simulator, to be stored in the
-/// Globals section during serialization and compared upon unserialization.
-extern std::set<std::string> version_tags;
-
-void
-Globals::serialize(CheckpointOut &cp) const
-{
- paramOut(cp, "curTick", curTick());
- SERIALIZE_CONTAINER(version_tags);
-}
-
-void
-Globals::unserialize(CheckpointIn &cp)
-{
- paramIn(cp, "curTick", unserializedCurTick);
-
- const std::string §ion(Serializable::currentSection());
- std::string str;
- if (!cp.find(section, "version_tags", str)) {
-
warn("**********************************************************\n");
- warn("!!!! Checkpoint uses an old versioning
scheme. !!!!\n");
- warn("Run the checkpoint upgrader (util/cpt_upgrader.py) on your "
- "checkpoint\n");
-
warn("**********************************************************\n");
- return;
- }
-
- std::set<std::string> cpt_tags;
- arrayParamIn(cp, "version_tags", cpt_tags); // UNSERIALIZE_CONTAINER
-
- bool err = false;
- for (const auto& t : version_tags) {
- if (cpt_tags.find(t) == cpt_tags.end()) {
- // checkpoint is missing tag that this binary has
- if (!err) {
-
warn("*****************************************************\n");
- warn("!!!! Checkpoint is missing the following version
tags:\n");
- err = true;
- }
- warn(" %s\n", t);
- }
- }
- if (err) {
- warn("You might experience some issues when restoring and should
run "
- "the checkpoint upgrader (util/cpt_upgrader.py) on your "
- "checkpoint\n");
-
warn("**********************************************************\n");
- }
-
- err = false;
- for (const auto& t : cpt_tags) {
- if (version_tags.find(t) == version_tags.end()) {
- // gem5 binary is missing tag that this checkpoint has
- if (!err) {
-
warn("*****************************************************\n");
- warn("!!!! gem5 is missing the following version tags:\n");
- err = true;
- }
- warn(" %s\n", t);
- }
- }
- if (err) {
- warn("Running a checkpoint with incompatible version tags is not "
- "supported. While it might work, you may experience
incorrect "
- "behavior or crashes.\n");
-
warn("**********************************************************\n");
- }
-}
-
Serializable::Serializable()
{
}
@@ -194,20 +105,9 @@
fatal("Unable to open file %s for writing\n", cpt_file.c_str());
outstream << "## checkpoint generated: " << ctime(&t);
- globals.serializeSection(outstream, "Globals");
-
SimObject::serializeAll(outstream);
}
-void
-Serializable::unserializeGlobals(CheckpointIn &cp)
-{
- globals.unserializeSection(cp, "Globals");
-
- for (uint32_t i = 0; i < numMainEventQueues; ++i)
- mainEventQueue[i]->setCurTick(globals.unserializedCurTick);
-}
-
Serializable::ScopedCheckpointSection::~ScopedCheckpointSection()
{
assert(!path.empty());
diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh
index 25a6e8d..ebf260a 100644
--- a/src/sim/serialize.hh
+++ b/src/sim/serialize.hh
@@ -307,11 +307,6 @@
*/
static void serializeAll(const std::string &cpt_dir);
- /**
- * @ingroup api_serialize
- */
- static void unserializeGlobals(CheckpointIn &cp);
-
private:
static std::stack<std::string> path;
};
@@ -646,24 +641,6 @@
arrayParamIn(cp, #member, member)
/**
- * \def SERIALIZE_EVENT(event)
- *
- * @ingroup api_serialize
- */
-#define SERIALIZE_EVENT(event) event.serializeSection(cp, #event);
-
-/**
- * \def UNSERIALIZE_EVENT(event)
- *
- * @ingroup api_serialize
- */
-#define UNSERIALIZE_EVENT(event) \
- do { \
- event.unserializeSection(cp, #event); \
- eventQueue()->checkpointReschedule(&event); \
- } while (0)
-
-/**
* \def SERIALIZE_OBJ(obj)
*
* @ingroup api_serialize
diff --git a/src/sim/sim_object.cc b/src/sim/sim_object.cc
index 13d279d..4c8d87b 100644
--- a/src/sim/sim_object.cc
+++ b/src/sim/sim_object.cc
@@ -142,7 +142,6 @@
}
}
-
#ifdef DEBUG
//
// static function: flag which objects should have the debugger break
diff --git a/util/cpt_upgrader.py b/util/cpt_upgrader.py
index 0639dc1..6629806 100755
--- a/util/cpt_upgrader.py
+++ b/util/cpt_upgrader.py
@@ -218,8 +218,12 @@
change = True
cpt.remove_option('root', 'cpt_ver')
+ # @todo The 'Globals' option is deprecated, and should be removed in
the
+ # future
elif cpt.has_option('Globals','version_tags'):
tags = set((''.join(cpt.get('Globals','version_tags'))).split())
+ elif cpt.has_option('root.globals','version_tags'):
+ tags =
set((''.join(cpt.get('root.globals','version_tags'))).split())
else:
print("fatal: no version information in checkpoint")
exit(1)
@@ -253,7 +257,7 @@
verboseprint("...nothing to do")
return
- cpt.set('Globals', 'version_tags', ' '.join(tags))
+ cpt.set('root.globals', 'version_tags', ' '.join(tags))
# Write the old data back
verboseprint("...completed")
diff --git a/util/cpt_upgraders/globals-to-root.py
b/util/cpt_upgraders/globals-to-root.py
new file mode 100644
index 0000000..3452def
--- /dev/null
+++ b/util/cpt_upgraders/globals-to-root.py
@@ -0,0 +1,13 @@
+# This upgrader renames section "Globals" as "root.globals".
+def upgrader(cpt):
+ import re
+ for sec in cpt.sections():
+ if re.match('Globals', sec):
+ # rename the section
+ items = cpt.items(sec)
+ cpt.add_section('root.globals')
+ for item in items:
+ cpt.set('root.globals', item[0], item[1])
+ cpt.remove_section(sec)
+
+legacy_version = 16
4 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the
submitted one.
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/43586
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: I9c8e57306f83f9cc30ab2b745a4972755191bec4
Gerrit-Change-Number: 43586
Gerrit-PatchSet: 7
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-CC: Jason Lowe-Power <[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