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 <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38739
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Daniel R. Carvalho
2020-12-26 22:58:26 -03:00
committed by Daniel Carvalho
parent 6bbee0fbce
commit 6a7403f1a2
5 changed files with 45 additions and 34 deletions

View File

@@ -310,7 +310,8 @@ pybind_init_core(py::module_ &m_native)
.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);
})
;

View File

@@ -264,9 +264,8 @@ CheckpointIn::dir()
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 @@ CheckpointIn::find(const std::string &section, const std::string &entry,
{
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 @@ void
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

View File

@@ -61,7 +61,6 @@
class IniFile;
class SimObject;
class SimObjectResolver;
typedef std::ostream CheckpointOut;
@@ -71,12 +70,10 @@ class CheckpointIn
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 @@ class CheckpointIn
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,

View File

@@ -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 @@ SimObject::find(const char *name)
return NULL;
}
void
SimObject::setSimObjectResolver(SimObjectResolver *resolver)
{
assert(!_objNameResolver);
_objNameResolver = resolver;
}
SimObjectResolver *
SimObject::getSimObjectResolver()
{
assert(_objNameResolver);
return _objNameResolver;
}

View File

@@ -58,6 +58,7 @@
class EventManager;
class ProbeManager;
class SimObjectResolver;
/**
* Abstract superclass for simulation objects. Represents things that
@@ -147,6 +148,9 @@ class SimObject : public EventManager, public Serializable, public Drainable,
/** 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 @@ class SimObject : public EventManager, public Serializable, public Drainable,
* @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