gem5
v20.1.0.0
|
This class allows a config file to be read into gem5 (generating the appropriate SimObjects) from C++. More...
#include <cxx_manager.hh>
Classes | |
class | Exception |
Exception for instantiate/post-instantiate errors. More... | |
struct | Renaming |
Name substitution when instantiating any object whose name starts with fromPrefix. More... | |
class | SimObjectResolver |
Class for resolving SimObject names to SimObjects usable by the checkpoint restore mechanism. More... | |
Public Member Functions | |
CxxConfigManager (CxxConfigFileBase &configFile_) | |
const CxxConfigDirectoryEntry & | findObjectType (const std::string &object_name, std::string &object_type) |
Find the type field for a named object and return both the name of the type to object_type and the object's directory entry as the return value. More... | |
void | addRenaming (const Renaming &renaming) |
Add a name prefix renaming to those currently applied. More... | |
void | bindObjectPorts (SimObject *object) |
Bind the ports of a single SimObject. More... | |
SimObject * | findObject (const std::string &object_name, bool visit_children=false) |
Walk the configuration starting with object object_name and fill in all the elements of this object on the way. More... | |
CxxConfigParams * | findObjectParams (const std::string &object_name) |
Find the parameters for the named object. More... | |
void | findTraversalOrder (const std::string &object_name) |
Populate objectsInOrder with a preorder, depth first traversal from the given object name down through all its children. More... | |
template<typename SimObjectType > | |
SimObjectType & | getObject (const std::string &object_name) |
Find an object from objectsByName with a type-checking cast. More... | |
void | forEachObject (void(SimObject::*mem_func)()) |
Perform mem_func on each SimObject. More... | |
void | findAllObjects () |
Find all objects by iterating over the object names in the config file with findObject. More... | |
void | instantiate (bool build_all=true) |
Build all objects (if build_all is true, otherwise objects must have been individually findObject-ed and added to the traversal order) and perform all the configuration specific actions up to, but not including initState. More... | |
void | initState () |
Call initState on all objects. More... | |
void | startup () |
Call startup on all objects. More... | |
unsigned int | drain () |
Drain all objects. More... | |
void | drainResume () |
Resume from drain. More... | |
void | serialize (std::ostream &os) |
Serialize (checkpoint) all objects to the given stream. More... | |
void | loadState (CheckpointIn &checkpoint) |
Load all objects' state from the given Checkpoint. More... | |
void | deleteObjects () |
Delete all objects and clear objectsByName and objectsByOrder. More... | |
SimObjectResolver & | getSimObjectResolver () |
Get the resolver used to map SimObject names to SimObjects for checkpoint restore. More... | |
void | setParam (const std::string &object_name, const std::string ¶m_name, const std::string ¶m_value) |
Convenience functions for calling set... More... | |
void | setParamVector (const std::string &object_name, const std::string ¶m_name, const std::vector< std::string > ¶m_values) |
Static Public Member Functions | |
static void | parsePort (const std::string &inp, std::string &path, std::string &port, unsigned int &index) |
Parse a port string of the form 'path(.path)*.port[index]' into path, port and index. More... | |
Public Attributes | |
std::map< std::string, SimObject * > | objectsByName |
SimObject indexed by name. More... | |
std::map< std::string, CxxConfigParams * > | objectParamsByName |
...Params objects created by this manager More... | |
std::list< SimObject * > | objectsInOrder |
SimObjects in order. More... | |
Protected Member Functions | |
void | bindPort (SimObject *requestorObject, const std::string &requestPort, PortID requestPortIndex, SimObject *responderObject, const std::string &responsePort, PortID responsePortIndex) |
Bind a single connection between two objects' ports. More... | |
void | bindRequestPort (SimObject *object, const CxxConfigDirectoryEntry::PortDesc &port, const std::vector< std::string > &peers) |
Bind a single (possibly vectored) request port to peers from the unparsed list peers with elements in the .ini connection format: path(.path)*.port[index]. More... | |
std::string | rename (const std::string &from_name) |
Apply the first matching renaming in renamings to the given name. More... | |
std::string | unRename (const std::string &to_name) |
Apply the first matching renaming in reverse (toPrefix -> fromPrefix for the given name. More... | |
void | bindAllPorts () |
Bind the ports of all the objects in objectInOrder order. More... | |
Protected Attributes | |
CxxConfigFileBase & | configFile |
Configuration file being read. More... | |
CxxConfigParams::Flags | flags |
Flags to pass to affect param setting. More... | |
std::set< std::string > | inVisit |
While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk. More... | |
std::list< Renaming > | renamings |
All the renamings applicable when instantiating objects. More... | |
SimObjectResolver | simObjectResolver |
Singleton instance of SimObjectResolver. More... | |
This class allows a config file to be read into gem5 (generating the appropriate SimObjects) from C++.
Definition at line 66 of file cxx_manager.hh.
CxxConfigManager::CxxConfigManager | ( | CxxConfigFileBase & | configFile_ | ) |
Definition at line 49 of file cxx_manager.cc.
void CxxConfigManager::addRenaming | ( | const Renaming & | renaming | ) |
Add a name prefix renaming to those currently applied.
Call this before trying to instantiate any object as the name mappings are not applied to the config tree read from the config file but are applied while processing instantiations
Definition at line 712 of file cxx_manager.cc.
References renamings.
|
protected |
Bind the ports of all the objects in objectInOrder order.
Also
Definition at line 439 of file cxx_manager.cc.
References bindObjectPorts(), ArmISA::i, and objectsInOrder.
Referenced by instantiate().
void CxxConfigManager::bindObjectPorts | ( | SimObject * | object | ) |
Bind the ports of a single SimObject.
Definition at line 519 of file cxx_manager.cc.
References bindRequestPort(), configFile, csprintf(), DPRINTF, findObjectType(), CxxConfigFileBase::getPortPeers(), ArmISA::i, CxxConfigDirectoryEntry::PortDesc::isRequestor, CxxConfigDirectoryEntry::PortDesc::isVector, CxxConfigDirectoryEntry::PortDesc::name, CxxConfigDirectoryEntry::ports, and unRename().
Referenced by bindAllPorts().
|
protected |
Bind a single connection between two objects' ports.
Definition at line 446 of file cxx_manager.cc.
References Port::bind(), csprintf(), DPRINTF, SimObject::getPort(), Port::isConnected(), and SimObject::name().
Referenced by bindRequestPort().
|
protected |
Bind a single (possibly vectored) request port to peers from the unparsed list peers with elements in the .ini connection format: path(.path)*.port[index].
Definition at line 483 of file cxx_manager.cc.
References bindPort(), csprintf(), CxxConfigDirectoryEntry::PortDesc::name, SimObject::name(), objectsByName, parsePort(), and rename().
Referenced by bindObjectPorts().
void CxxConfigManager::deleteObjects | ( | ) |
Delete all objects and clear objectsByName and objectsByOrder.
Definition at line 656 of file cxx_manager.cc.
References DPRINTF, CxxConfigParams::getName(), ArmISA::i, objectParamsByName, objectsByName, and objectsInOrder.
unsigned int CxxConfigManager::drain | ( | ) |
Drain all objects.
Definition at line 627 of file cxx_manager.cc.
References DrainManager::instance(), and DrainManager::tryDrain().
void CxxConfigManager::drainResume | ( | ) |
Resume from drain.
Definition at line 633 of file cxx_manager.cc.
References DrainManager::instance(), and DrainManager::resume().
void CxxConfigManager::findAllObjects | ( | ) |
Find all objects by iterating over the object names in the config file with findObject.
Also populate the traversal order
Definition at line 411 of file cxx_manager.cc.
References configFile, findTraversalOrder(), CxxConfigFileBase::getAllObjectNames(), and objectsInOrder.
Referenced by instantiate().
SimObject * CxxConfigManager::findObject | ( | const std::string & | object_name, |
bool | visit_children = false |
||
) |
Walk the configuration starting with object object_name and fill in all the elements of this object on the way.
This involves:
After the first call, this function will return objectsByName[object_name]
Definition at line 129 of file cxx_manager.cc.
References configFile, csprintf(), DPRINTF, findObjectParams(), findObjectType(), formatParamList(), CxxConfigFileBase::getObjectChildren(), CxxConfigFileBase::getParam(), CxxConfigFileBase::getParamVector(), ArmISA::i, inVisit, CxxConfigDirectoryEntry::ParamDesc::isSimObject, CxxConfigDirectoryEntry::ParamDesc::isVector, ArmISA::n, CxxConfigDirectoryEntry::ParamDesc::name, objectParamsByName, objectsByName, CxxConfigDirectoryEntry::parameters, rename(), CxxConfigParams::setSimObject(), CxxConfigParams::setSimObjectVector(), and CxxConfigParams::simObjectCreate().
Referenced by findTraversalOrder().
CxxConfigParams * CxxConfigManager::findObjectParams | ( | const std::string & | object_name | ) |
Find the parameters for the named object.
Returns NULL if the object isn't in the configuration. For the first call with a particular object name, a new CxxConfigParams descended object is made with the configuration file contents for this object. This involves populating that ...Params object with:
The ...Params object is then added to objectParamsByName After the first call, this function will return objectParamsByName[object_name]
Definition at line 263 of file cxx_manager.cc.
References configFile, csprintf(), DPRINTF, findObjectType(), flags, formatParamList(), CxxConfigFileBase::getParam(), CxxConfigFileBase::getParamVector(), CxxConfigFileBase::getPortPeers(), ArmISA::i, CxxConfigDirectoryEntry::ParamDesc::isSimObject, CxxConfigDirectoryEntry::ParamDesc::isVector, CxxConfigDirectoryEntry::makeParamsObject(), CxxConfigDirectoryEntry::ParamDesc::name, CxxConfigDirectoryEntry::PortDesc::name, objectParamsByName, CxxConfigDirectoryEntry::parameters, CxxConfigDirectoryEntry::ports, rename(), CxxConfigParams::setName(), CxxConfigParams::setParam(), CxxConfigParams::setParamVector(), CxxConfigParams::setPortConnectionCount(), CxxConfigParams::setSimObject(), and CxxConfigParams::setSimObjectVector().
Referenced by findObject(), setParam(), and setParamVector().
const CxxConfigDirectoryEntry & CxxConfigManager::findObjectType | ( | const std::string & | object_name, |
std::string & | object_type | ||
) |
Find the type field for a named object and return both the name of the type to object_type and the object's directory entry as the return value.
Definition at line 56 of file cxx_manager.cc.
References configFile, csprintf(), cxx_config_directory, CxxConfigFileBase::getParam(), and CxxConfigFileBase::objectExists().
Referenced by bindObjectPorts(), findObject(), and findObjectParams().
void CxxConfigManager::findTraversalOrder | ( | const std::string & | object_name | ) |
Populate objectsInOrder with a preorder, depth first traversal from the given object name down through all its children.
Definition at line 422 of file cxx_manager.cc.
References configFile, findObject(), CxxConfigFileBase::getObjectChildren(), ArmISA::i, and objectsInOrder.
Referenced by findAllObjects().
void CxxConfigManager::forEachObject | ( | void(SimObject::*)() | mem_func | ) |
Perform mem_func on each SimObject.
Definition at line 585 of file cxx_manager.cc.
References ArmISA::i, and objectsInOrder.
Referenced by initState(), instantiate(), and startup().
|
inline |
Find an object from objectsByName with a type-checking cast.
This function is provided for manipulating objects after instantiate as it assumes the named object exists.
Definition at line 237 of file cxx_manager.hh.
References csprintf(), and objectsByName.
Referenced by CxxConfigManager::SimObjectResolver::resolveSimObject().
|
inline |
Get the resolver used to map SimObject names to SimObjects for checkpoint restore.
Definition at line 300 of file cxx_manager.hh.
References simObjectResolver.
void CxxConfigManager::initState | ( | ) |
Call initState on all objects.
Definition at line 613 of file cxx_manager.cc.
References DPRINTF, forEachObject(), and SimObject::initState().
void CxxConfigManager::instantiate | ( | bool | build_all = true | ) |
Build all objects (if build_all is true, otherwise objects must have been individually findObject-ed and added to the traversal order) and perform all the configuration specific actions up to, but not including initState.
If you want to set some parameters before completing instantiation, call findObjectParams on the objects you want to modify, then call instantiate
Definition at line 592 of file cxx_manager.cc.
References bindAllPorts(), DPRINTF, findAllObjects(), forEachObject(), SimObject::init(), SimObject::regProbeListeners(), SimObject::regProbePoints(), and Stats::Group::regStats().
void CxxConfigManager::loadState | ( | CheckpointIn & | checkpoint | ) |
Load all objects' state from the given Checkpoint.
Definition at line 649 of file cxx_manager.cc.
References ArmISA::i, and objectsInOrder.
|
static |
Parse a port string of the form 'path(.path)*.port[index]' into path, port and index.
Definition at line 558 of file cxx_manager.cc.
References DPRINTF, and MipsISA::index.
Referenced by bindRequestPort().
|
protected |
Apply the first matching renaming in renamings to the given name.
Definition at line 78 of file cxx_manager.cc.
References CxxConfigManager::Renaming::fromPrefix, ArmISA::i, renamings, and CxxConfigManager::Renaming::toPrefix.
Referenced by bindRequestPort(), findObject(), findObjectParams(), setParam(), and setParamVector().
void CxxConfigManager::serialize | ( | std::ostream & | os | ) |
Serialize (checkpoint) all objects to the given stream.
Definition at line 639 of file cxx_manager.cc.
References ArmISA::i, objectsInOrder, and X86ISA::os.
void CxxConfigManager::setParam | ( | const std::string & | object_name, |
const std::string & | param_name, | ||
const std::string & | param_value | ||
) |
Convenience functions for calling set...
member functions on a CxxConfigParams for an object. These functions throw Exception rather than return a bool on failure
Definition at line 678 of file cxx_manager.cc.
References csprintf(), DPRINTF, findObjectParams(), flags, rename(), and CxxConfigParams::setParam().
void CxxConfigManager::setParamVector | ( | const std::string & | object_name, |
const std::string & | param_name, | ||
const std::vector< std::string > & | param_values | ||
) |
Definition at line 695 of file cxx_manager.cc.
References csprintf(), DPRINTF, findObjectParams(), flags, formatParamList(), rename(), and CxxConfigParams::setParamVector().
void CxxConfigManager::startup | ( | ) |
Call startup on all objects.
Definition at line 620 of file cxx_manager.cc.
References DPRINTF, forEachObject(), and SimObject::startup().
|
protected |
Apply the first matching renaming in reverse (toPrefix -> fromPrefix for the given name.
Definition at line 93 of file cxx_manager.cc.
References CxxConfigManager::Renaming::fromPrefix, ArmISA::i, renamings, and CxxConfigManager::Renaming::toPrefix.
Referenced by bindObjectPorts().
|
protected |
Configuration file being read.
Definition at line 70 of file cxx_manager.hh.
Referenced by bindObjectPorts(), findAllObjects(), findObject(), findObjectParams(), findObjectType(), and findTraversalOrder().
|
protected |
Flags to pass to affect param setting.
Definition at line 73 of file cxx_manager.hh.
Referenced by findObjectParams(), setParam(), and setParamVector().
|
protected |
While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk.
Definition at line 123 of file cxx_manager.hh.
Referenced by findObject().
std::map<std::string, CxxConfigParams *> CxxConfigManager::objectParamsByName |
...Params objects created by this manager
Definition at line 115 of file cxx_manager.hh.
Referenced by deleteObjects(), findObject(), and findObjectParams().
std::map<std::string, SimObject *> CxxConfigManager::objectsByName |
SimObject indexed by name.
Definition at line 112 of file cxx_manager.hh.
Referenced by bindRequestPort(), deleteObjects(), findObject(), and getObject().
SimObjects in order.
This is populated by findAllObjects
Definition at line 118 of file cxx_manager.hh.
Referenced by bindAllPorts(), deleteObjects(), findAllObjects(), findTraversalOrder(), forEachObject(), loadState(), and serialize().
All the renamings applicable when instantiating objects.
Definition at line 126 of file cxx_manager.hh.
Referenced by addRenaming(), rename(), and unRename().
|
protected |
Singleton instance of SimObjectResolver.
Definition at line 169 of file cxx_manager.hh.
Referenced by getSimObjectResolver().