Daniel Carvalho has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/43586 )

Change subject: sim: Remove event dependencies from serialize.hh
......................................................................

sim: 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
SimObject. To do so, Globals is assigned its own files,
sim/globals.(cc/hh).

Change-Id: I9c8e57306f83f9cc30ab2b745a4972755191bec4
Signed-off-by: Daniel R. Carvalho <oda...@yahoo.com.br>
---
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/serialize.cc
M src/sim/serialize.hh
M src/sim/sim_object.cc
M src/sim/sim_object.hh
9 files changed, 230 insertions(+), 129 deletions(-)



diff --git a/src/python/pybind11/core.cc b/src/python/pybind11/core.cc
index 8eac65c..8bddfb4 100644
--- a/src/python/pybind11/core.cc
+++ b/src/python/pybind11/core.cc
@@ -308,7 +308,7 @@
      */
     m_core
         .def("serializeAll", &Serializable::serializeAll)
-        .def("unserializeGlobals", &Serializable::unserializeGlobals)
+        .def("unserializeGlobals", &SimObject::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 fe18d24..1f2bfa2 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 a9ab29b..0b8b9e4 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 &section(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/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 &section(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 b6bc532..9cbbe71 100644
--- a/src/sim/sim_object.cc
+++ b/src/sim/sim_object.cc
@@ -48,6 +48,7 @@
 //
 SimObject::SimObjectList SimObject::simObjectList;
 SimObjectResolver *SimObject::_objNameResolver = NULL;
+Globals SimObject::globals;

 //
 // SimObject constructor: used to maintain static simObjectList
@@ -131,6 +132,8 @@
 void
 SimObject::serializeAll(CheckpointOut &cp)
 {
+    globals.serializeSection(cp, "Globals");
+
     SimObjectList::reverse_iterator ri = simObjectList.rbegin();
     SimObjectList::reverse_iterator rend = simObjectList.rend();

@@ -142,6 +145,13 @@
    }
 }

+void
+SimObject::unserializeGlobals(CheckpointIn &cp)
+{
+    globals.unserializeSection(cp, "Globals");
+    for (uint32_t i = 0; i < numMainEventQueues; ++i)
+        mainEventQueue[i]->setCurTick(globals.unserializedCurTick);
+}

 #ifdef DEBUG
 //
diff --git a/src/sim/sim_object.hh b/src/sim/sim_object.hh
index cad6870..31409a4 100644
--- a/src/sim/sim_object.hh
+++ b/src/sim/sim_object.hh
@@ -53,6 +53,7 @@
 #include "params/SimObject.hh"
 #include "sim/drain.hh"
 #include "sim/eventq.hh"
+#include "sim/globals.hh"
 #include "sim/port.hh"
 #include "sim/serialize.hh"

@@ -151,6 +152,9 @@
     /** Helper to resolve an object given its name. */
     static SimObjectResolver *_objNameResolver;

+    /** The one and only instance of the Globals class. */
+    static Globals globals;
+
     /** Manager coordinates hooking up probe points with listeners. */
     ProbeManager *probeManager;

@@ -322,11 +326,12 @@
      */
     static void serializeAll(CheckpointOut &cp);

-#ifdef DEBUG
-  public:
-    bool doDebugBreak;
-    static void debugObjectBreak(const std::string &objs);
-#endif
+    /**
+     * Unserialize globals.
+     *
+     * @ingroup api_serialize
+     */
+    void unserializeGlobals(CheckpointIn &cp);

     /**
      * Find the SimObject with the given name and return a pointer to
@@ -352,6 +357,12 @@
      * @return Pointer to the single sim object name resolver.
      */
     static SimObjectResolver *getSimObjectResolver();
+
+#ifdef DEBUG
+  public:
+    bool doDebugBreak;
+    static void debugObjectBreak(const std::string &objs);
+#endif
 };

 /* Add PARAMS(ClassName) to every descendant of SimObject that needs

--
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: 1
Gerrit-Owner: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to