Daniel Carvalho has uploaded this change for review. (
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 <[email protected]>
---
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(+), 33 deletions(-)
diff --git a/src/python/pybind11/core.cc b/src/python/pybind11/core.cc
index 8655d73..6e725d8 100644
--- a/src/python/pybind11/core.cc
+++ b/src/python/pybind11/core.cc
@@ -277,7 +277,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 e502d9a..1908d73 100644
--- a/src/sim/serialize.cc
+++ b/src/sim/serialize.cc
@@ -266,8 +266,8 @@
return currentDirectory;
}
-CheckpointIn::CheckpointIn(const string &cpt_dir, SimObjectResolver
&resolver)
- : db(new IniFile), objNameResolver(resolver), _cptDir(setDir(cpt_dir))
+CheckpointIn::CheckpointIn(const string &cpt_dir)
+ : db(new IniFile), _cptDir(setDir(cpt_dir))
{
string filename = getCptDir() + "/" + CheckpointIn::baseFilename;
if (!db->load(filename)) {
@@ -308,28 +308,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 string §ion, const string &entry,
- SimObject *&value)
-{
- string path;
-
- if (!db->find(section, entry, path))
- return false;
-
- value = objNameResolver.resolveSimObject(path);
- return true;
-}
bool
CheckpointIn::sectionExists(const string §ion)
@@ -341,9 +319,11 @@
objParamIn(CheckpointIn &cp, const string &name, SimObject * ¶m)
{
const string §ion(Serializable::currentSection());
- if (!cp.findObj(section, name, param)) {
+ 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 9e25d09..57d8fb3 100644
--- a/src/sim/serialize.hh
+++ b/src/sim/serialize.hh
@@ -60,7 +60,6 @@
class IniFile;
class SimObject;
-class SimObjectResolver;
typedef std::ostream CheckpointOut;
@@ -70,12 +69,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();
/**
@@ -89,9 +86,6 @@
bool find(const std::string §ion, const std::string &entry,
std::string &value);
- bool findObj(const std::string §ion, const std::string &entry,
- SimObject *&value);
-
bool entryExists(const std::string §ion, const std::string &entry);
bool sectionExists(const std::string §ion);
/** @}*/ //end of api_checkout group
diff --git a/src/sim/sim_object.cc b/src/sim/sim_object.cc
index 58780b2..49b0715 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"
@@ -48,6 +50,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
@@ -181,3 +184,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 a75f8dd..719f5a5 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
@@ -127,6 +128,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;
@@ -312,6 +316,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();
};
/**
--
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: 1
Gerrit-Owner: Daniel Carvalho <[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