Daniel Carvalho has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/38739 )

Change subject: sim: Move SimObjectResolver dependency to SimObject
......................................................................

sim: Move SimObjectResolver dependency to SimObject

Move SimObjectResolver dependency from CheckpointIn to
SimObject to reduce serialization tangling.

Change-Id: I9973bea0e3c6cabb0051a55dbf9aebef8a50fba8
Signed-off-by: Daniel R. Carvalho <oda...@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38739
Reviewed-by: Giacomo Travaglini <giacomo.travagl...@arm.com>
Maintainer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/python/pybind11/core.cc
M src/sim/serialize.cc
M src/sim/serialize.hh
M src/sim/sim_object.cc
M src/sim/sim_object.hh
5 files changed, 45 insertions(+), 34 deletions(-)

Approvals:
  Giacomo Travaglini: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/python/pybind11/core.cc b/src/python/pybind11/core.cc
index 17a6271..8eac65c 100644
--- a/src/python/pybind11/core.cc
+++ b/src/python/pybind11/core.cc
@@ -310,7 +310,8 @@
         .def("serializeAll", &Serializable::serializeAll)
         .def("unserializeGlobals", &Serializable::unserializeGlobals)
         .def("getCheckpoint", [](const std::string &cpt_dir) {
-            return new CheckpointIn(cpt_dir, pybindSimObjectResolver);
+            SimObject::setSimObjectResolver(&pybindSimObjectResolver);
+            return new CheckpointIn(cpt_dir);
         })

         ;
diff --git a/src/sim/serialize.cc b/src/sim/serialize.cc
index e81f49d..0b1faa2 100644
--- a/src/sim/serialize.cc
+++ b/src/sim/serialize.cc
@@ -264,9 +264,8 @@
     return currentDirectory;
 }

-CheckpointIn::CheckpointIn(const std::string &cpt_dir,
-        SimObjectResolver &resolver)
-    : db(new IniFile), objNameResolver(resolver), _cptDir(setDir(cpt_dir))
+CheckpointIn::CheckpointIn(const std::string &cpt_dir)
+    : db(new IniFile), _cptDir(setDir(cpt_dir))
 {
     std::string filename = getCptDir() + "/" + CheckpointIn::baseFilename;
     if (!db->load(filename)) {
@@ -308,28 +307,6 @@
 {
     return db->find(section, entry, value);
 }
-/**
- * @param section Here we mention the section we are looking for
- * (example: currentsection).
- * @param entry Mention the SimObject we are looking for (example:
- * interruput time) in the section.
- * @param value Give the value at the said entry.
- *
- * @return Returns true if a SimObject exists in the section.
- *
- */
-bool
-CheckpointIn::findObj(const std::string &section, const std::string &entry,
-                    SimObject *&value)
-{
-    std::string path;
-
-    if (!db->find(section, entry, path))
-        return false;
-
-    value = objNameResolver.resolveSimObject(path);
-    return true;
-}

 bool
 CheckpointIn::sectionExists(const std::string &section)
@@ -348,9 +325,11 @@
 objParamIn(CheckpointIn &cp, const std::string &name, SimObject * &param)
 {
     const std::string &section(Serializable::currentSection());
-    if (!cp.findObj(section, name, param)) {
+    std::string path;
+    if (!cp.find(section, name, path)) {
         fatal("Can't unserialize '%s:%s'\n", section, name);
     }
+    param = SimObject::getSimObjectResolver()->resolveSimObject(path);
 }

 void
diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh
index 80fac66..82bfd2e 100644
--- a/src/sim/serialize.hh
+++ b/src/sim/serialize.hh
@@ -61,7 +61,6 @@

 class IniFile;
 class SimObject;
-class SimObjectResolver;

 typedef std::ostream CheckpointOut;

@@ -71,12 +70,10 @@

     IniFile *db;

-    SimObjectResolver &objNameResolver;
-
     const std::string _cptDir;

   public:
-    CheckpointIn(const std::string &cpt_dir, SimObjectResolver &resolver);
+    CheckpointIn(const std::string &cpt_dir);
     ~CheckpointIn();

     /**
@@ -90,9 +87,6 @@
     bool find(const std::string &section, const std::string &entry,
               std::string &value);

-    bool findObj(const std::string &section, const std::string &entry,
-                 SimObject *&value);
-
     bool entryExists(const std::string &section, const std::string &entry);
     bool sectionExists(const std::string &section);
     void visitSection(const std::string &section,
diff --git a/src/sim/sim_object.cc b/src/sim/sim_object.cc
index 28a0863..b6bc532 100644
--- a/src/sim/sim_object.cc
+++ b/src/sim/sim_object.cc
@@ -29,6 +29,8 @@

 #include "sim/sim_object.hh"

+#include <cassert>
+
 #include "base/logging.hh"
 #include "base/match.hh"
 #include "base/trace.hh"
@@ -45,6 +47,7 @@
 // static list of all SimObjects, used for initialization etc.
 //
 SimObject::SimObjectList SimObject::simObjectList;
+SimObjectResolver *SimObject::_objNameResolver = NULL;

 //
 // SimObject constructor: used to maintain static simObjectList
@@ -178,3 +181,17 @@

     return NULL;
 }
+
+void
+SimObject::setSimObjectResolver(SimObjectResolver *resolver)
+{
+    assert(!_objNameResolver);
+    _objNameResolver = resolver;
+}
+
+SimObjectResolver *
+SimObject::getSimObjectResolver()
+{
+    assert(_objNameResolver);
+    return _objNameResolver;
+}
diff --git a/src/sim/sim_object.hh b/src/sim/sim_object.hh
index 75e2d37..cad6870 100644
--- a/src/sim/sim_object.hh
+++ b/src/sim/sim_object.hh
@@ -58,6 +58,7 @@

 class EventManager;
 class ProbeManager;
+class SimObjectResolver;

 /**
  * Abstract superclass for simulation objects.  Represents things that
@@ -147,6 +148,9 @@
     /** List of all instantiated simulation objects. */
     static SimObjectList simObjectList;

+    /** Helper to resolve an object given its name. */
+    static SimObjectResolver *_objNameResolver;
+
     /** Manager coordinates hooking up probe points with listeners. */
     ProbeManager *probeManager;

@@ -332,6 +336,22 @@
      * @ingroup api_simobject
      */
     static SimObject *find(const char *name);
+
+    /**
+     * There is a single object name resolver, and it is only set when
+     * simulation is restoring from checkpoints.
+     *
+     * @param Pointer to the single sim object name resolver.
+     */
+    static void setSimObjectResolver(SimObjectResolver *resolver);
+
+    /**
+     * There is a single object name resolver, and it is only set when
+     * simulation is restoring from checkpoints.
+     *
+     * @return Pointer to the single sim object name resolver.
+     */
+    static SimObjectResolver *getSimObjectResolver();
 };

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



11 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/+/38739
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: I9973bea0e3c6cabb0051a55dbf9aebef8a50fba8
Gerrit-Change-Number: 38739
Gerrit-PatchSet: 14
Gerrit-Owner: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-CC: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: merged
_______________________________________________
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