gem5 v24.0.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. | |
void | addRenaming (const Renaming &renaming) |
Add a name prefix renaming to those currently applied. | |
void | bindObjectPorts (SimObject *object) |
Bind the ports of a single SimObject. | |
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. | |
CxxConfigParams * | findObjectParams (const std::string &object_name) |
Find the parameters for the named object. | |
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. | |
template<typename SimObjectType > | |
SimObjectType & | getObject (const std::string &object_name) |
Find an object from objectsByName with a type-checking cast. | |
void | forEachObject (void(SimObject::*mem_func)()) |
Perform mem_func on each SimObject. | |
void | findAllObjects () |
Find all objects by iterating over the object names in the config file with findObject. | |
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. | |
void | initState () |
Call initState on all objects. | |
void | startup () |
Call startup on all objects. | |
unsigned int | drain () |
Drain all objects. | |
void | drainResume () |
Resume from drain. | |
void | serialize (std::ostream &os) |
Serialize (checkpoint) all objects to the given stream. | |
void | loadState (CheckpointIn &checkpoint) |
Load all objects' state from the given Checkpoint. | |
void | deleteObjects () |
Delete all objects and clear objectsByName and objectsByOrder. | |
SimObjectResolver & | getSimObjectResolver () |
Get the resolver used to map SimObject names to SimObjects for checkpoint restore. | |
void | setParam (const std::string &object_name, const std::string ¶m_name, const std::string ¶m_value) |
Convenience functions for calling set... member functions on a CxxConfigParams for an object. | |
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. | |
Public Attributes | |
std::map< std::string, SimObject * > | objectsByName |
SimObject indexed by name. | |
std::map< std::string, CxxConfigParams * > | objectParamsByName |
...Params objects created by this manager | |
std::list< SimObject * > | objectsInOrder |
SimObjects in order. | |
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. | |
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]. | |
std::string | rename (const std::string &from_name) |
Apply the first matching renaming in renamings to the given name. | |
std::string | unRename (const std::string &to_name) |
Apply the first matching renaming in reverse (toPrefix -> fromPrefix for the given name. | |
void | bindAllPorts () |
Bind the ports of all the objects in objectInOrder order. | |
Protected Attributes | |
CxxConfigFileBase & | configFile |
Configuration file being read. | |
CxxConfigParams::Flags | flags |
Flags to pass to affect param setting. | |
std::set< std::string > | inVisit |
While configuring, inVisit contains names of SimObjects visited in this recursive configuration walk. | |
std::list< Renaming > | renamings |
All the renamings applicable when instantiating objects. | |
SimObjectResolver | simObjectResolver |
Singleton instance of SimObjectResolver. | |
This class allows a config file to be read into gem5 (generating the appropriate SimObjects) from C++.
Definition at line 69 of file cxx_manager.hh.
gem5::CxxConfigManager::CxxConfigManager | ( | CxxConfigFileBase & | configFile_ | ) |
Definition at line 52 of file cxx_manager.cc.
void gem5::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 715 of file cxx_manager.cc.
References renamings.
|
protected |
Bind the ports of all the objects in objectInOrder order.
Also
Definition at line 442 of file cxx_manager.cc.
References bindObjectPorts(), gem5::ArmISA::i, and objectsInOrder.
Referenced by instantiate().
void gem5::CxxConfigManager::bindObjectPorts | ( | SimObject * | object | ) |
Bind the ports of a single SimObject.
Definition at line 522 of file cxx_manager.cc.
References bindRequestPort(), configFile, gem5::csprintf(), DPRINTF, findObjectType(), gem5::CxxConfigFileBase::getPortPeers(), gem5::ArmISA::i, gem5::CxxConfigDirectoryEntry::PortDesc::isRequestor, gem5::CxxConfigDirectoryEntry::PortDesc::isVector, gem5::CxxConfigDirectoryEntry::PortDesc::name, gem5::CxxConfigDirectoryEntry::ports, and unRename().
Referenced by bindAllPorts().
|
protected |
Bind a single connection between two objects' ports.
Definition at line 449 of file cxx_manager.cc.
References gem5::Port::bind(), gem5::csprintf(), DPRINTF, gem5::SimObject::getPort(), gem5::Port::isConnected(), and gem5::Named::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 486 of file cxx_manager.cc.
References bindPort(), gem5::csprintf(), gem5::CxxConfigDirectoryEntry::PortDesc::name, gem5::Named::name(), objectsByName, parsePort(), and rename().
Referenced by bindObjectPorts().
void gem5::CxxConfigManager::deleteObjects | ( | ) |
Delete all objects and clear objectsByName and objectsByOrder.
Definition at line 659 of file cxx_manager.cc.
References DPRINTF, gem5::CxxConfigParams::getName(), gem5::ArmISA::i, objectParamsByName, objectsByName, and objectsInOrder.
unsigned int gem5::CxxConfigManager::drain | ( | ) |
Drain all objects.
Definition at line 630 of file cxx_manager.cc.
References gem5::DrainManager::instance(), and gem5::DrainManager::tryDrain().
void gem5::CxxConfigManager::drainResume | ( | ) |
Resume from drain.
Definition at line 636 of file cxx_manager.cc.
References gem5::DrainManager::instance(), and gem5::DrainManager::resume().
void gem5::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 414 of file cxx_manager.cc.
References configFile, findTraversalOrder(), gem5::CxxConfigFileBase::getAllObjectNames(), and objectsInOrder.
Referenced by instantiate().
SimObject * gem5::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 132 of file cxx_manager.cc.
References configFile, gem5::csprintf(), DPRINTF, findObject(), findObjectParams(), findObjectType(), gem5::formatParamList(), gem5::CxxConfigFileBase::getObjectChildren(), gem5::CxxConfigFileBase::getParam(), gem5::CxxConfigFileBase::getParamVector(), gem5::ArmISA::i, inVisit, gem5::CxxConfigDirectoryEntry::ParamDesc::isSimObject, gem5::CxxConfigDirectoryEntry::ParamDesc::isVector, gem5::ArmISA::n, gem5::CxxConfigDirectoryEntry::ParamDesc::name, objectParamsByName, objectsByName, gem5::CxxConfigDirectoryEntry::parameters, rename(), gem5::CxxConfigParams::setSimObject(), gem5::CxxConfigParams::setSimObjectVector(), and gem5::CxxConfigParams::simObjectCreate().
Referenced by findObject(), and findTraversalOrder().
CxxConfigParams * gem5::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 266 of file cxx_manager.cc.
References configFile, gem5::csprintf(), DPRINTF, findObjectType(), flags, gem5::formatParamList(), gem5::CxxConfigFileBase::getParam(), gem5::CxxConfigFileBase::getParamVector(), gem5::CxxConfigFileBase::getPortPeers(), gem5::ArmISA::i, gem5::CxxConfigDirectoryEntry::ParamDesc::isSimObject, gem5::CxxConfigDirectoryEntry::ParamDesc::isVector, gem5::CxxConfigDirectoryEntry::makeParamsObject(), gem5::CxxConfigDirectoryEntry::ParamDesc::name, gem5::CxxConfigDirectoryEntry::PortDesc::name, objectParamsByName, gem5::CxxConfigDirectoryEntry::parameters, gem5::CxxConfigDirectoryEntry::ports, rename(), gem5::CxxConfigParams::setName(), gem5::CxxConfigParams::setParam(), gem5::CxxConfigParams::setParamVector(), gem5::CxxConfigParams::setPortConnectionCount(), gem5::CxxConfigParams::setSimObject(), and gem5::CxxConfigParams::setSimObjectVector().
Referenced by findObject(), setParam(), and setParamVector().
const CxxConfigDirectoryEntry & gem5::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 59 of file cxx_manager.cc.
References configFile, gem5::csprintf(), gem5::cxxConfigDirectory(), gem5::CxxConfigFileBase::getParam(), and gem5::CxxConfigFileBase::objectExists().
Referenced by bindObjectPorts(), findObject(), and findObjectParams().
void gem5::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 425 of file cxx_manager.cc.
References configFile, findObject(), findTraversalOrder(), gem5::CxxConfigFileBase::getObjectChildren(), gem5::ArmISA::i, and objectsInOrder.
Referenced by findAllObjects(), and findTraversalOrder().
void gem5::CxxConfigManager::forEachObject | ( | void(SimObject::* | mem_func )() | ) |
Perform mem_func on each SimObject.
Definition at line 588 of file cxx_manager.cc.
References gem5::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 240 of file cxx_manager.hh.
References gem5::csprintf(), and objectsByName.
Referenced by gem5::CxxConfigManager::SimObjectResolver::resolveSimObject().
|
inline |
Get the resolver used to map SimObject names to SimObjects for checkpoint restore.
Definition at line 303 of file cxx_manager.hh.
References simObjectResolver.
void gem5::CxxConfigManager::initState | ( | ) |
Call initState on all objects.
Definition at line 616 of file cxx_manager.cc.
References DPRINTF, forEachObject(), and gem5::SimObject::initState().
void gem5::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 595 of file cxx_manager.cc.
References bindAllPorts(), DPRINTF, findAllObjects(), forEachObject(), gem5::SimObject::init(), gem5::SimObject::regProbeListeners(), gem5::SimObject::regProbePoints(), and gem5::statistics::Group::regStats().
void gem5::CxxConfigManager::loadState | ( | CheckpointIn & | checkpoint | ) |
Load all objects' state from the given Checkpoint.
Definition at line 652 of file cxx_manager.cc.
References gem5::ArmISA::i, and objectsInOrder.
|
static |
Parse a port string of the form 'path(.path)*.port[index]' into path, port and index.
Definition at line 561 of file cxx_manager.cc.
References DPRINTF, and gem5::MipsISA::index.
Referenced by bindRequestPort().
|
protected |
Apply the first matching renaming in renamings to the given name.
Definition at line 81 of file cxx_manager.cc.
References gem5::CxxConfigManager::Renaming::fromPrefix, gem5::ArmISA::i, renamings, and gem5::CxxConfigManager::Renaming::toPrefix.
Referenced by bindRequestPort(), findObject(), findObjectParams(), setParam(), and setParamVector().
void gem5::CxxConfigManager::serialize | ( | std::ostream & | os | ) |
Serialize (checkpoint) all objects to the given stream.
Definition at line 642 of file cxx_manager.cc.
References gem5::ArmISA::i, objectsInOrder, and gem5::X86ISA::os.
void gem5::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 681 of file cxx_manager.cc.
References gem5::csprintf(), DPRINTF, findObjectParams(), flags, rename(), and gem5::CxxConfigParams::setParam().
void gem5::CxxConfigManager::setParamVector | ( | const std::string & | object_name, |
const std::string & | param_name, | ||
const std::vector< std::string > & | param_values ) |
Definition at line 698 of file cxx_manager.cc.
References gem5::csprintf(), DPRINTF, findObjectParams(), flags, gem5::formatParamList(), rename(), and gem5::CxxConfigParams::setParamVector().
void gem5::CxxConfigManager::startup | ( | ) |
Call startup on all objects.
Definition at line 623 of file cxx_manager.cc.
References DPRINTF, forEachObject(), and gem5::SimObject::startup().
|
protected |
Apply the first matching renaming in reverse (toPrefix -> fromPrefix for the given name.
Definition at line 96 of file cxx_manager.cc.
References gem5::CxxConfigManager::Renaming::fromPrefix, gem5::ArmISA::i, renamings, and gem5::CxxConfigManager::Renaming::toPrefix.
Referenced by bindObjectPorts().
|
protected |
Configuration file being read.
Definition at line 73 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 76 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 126 of file cxx_manager.hh.
Referenced by findObject().
std::map<std::string, CxxConfigParams *> gem5::CxxConfigManager::objectParamsByName |
...Params objects created by this manager
Definition at line 118 of file cxx_manager.hh.
Referenced by deleteObjects(), findObject(), and findObjectParams().
std::map<std::string, SimObject *> gem5::CxxConfigManager::objectsByName |
SimObject indexed by name.
Definition at line 115 of file cxx_manager.hh.
Referenced by bindRequestPort(), deleteObjects(), findObject(), and getObject().
SimObjects in order.
This is populated by findAllObjects
Definition at line 121 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 129 of file cxx_manager.hh.
Referenced by addRenaming(), rename(), and unRename().
|
protected |
Singleton instance of SimObjectResolver.
Definition at line 172 of file cxx_manager.hh.
Referenced by getSimObjectResolver().