gem5 v24.0.0.0
Loading...
Searching...
No Matches
gem5::CxxConfigManager Class Reference

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 CxxConfigDirectoryEntryfindObjectType (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.
 
SimObjectfindObject (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.
 
CxxConfigParamsfindObjectParams (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.
 
SimObjectResolvergetSimObjectResolver ()
 Get the resolver used to map SimObject names to SimObjects for checkpoint restore.
 
void 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.
 
void setParamVector (const std::string &object_name, const std::string &param_name, const std::vector< std::string > &param_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

CxxConfigFileBaseconfigFile
 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< Renamingrenamings
 All the renamings applicable when instantiating objects.
 
SimObjectResolver simObjectResolver
 Singleton instance of SimObjectResolver.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ CxxConfigManager()

gem5::CxxConfigManager::CxxConfigManager ( CxxConfigFileBase & configFile_)

Definition at line 52 of file cxx_manager.cc.

Member Function Documentation

◆ addRenaming()

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.

◆ bindAllPorts()

void gem5::CxxConfigManager::bindAllPorts ( )
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().

◆ bindObjectPorts()

◆ bindPort()

void gem5::CxxConfigManager::bindPort ( SimObject * requestorObject,
const std::string & requestPort,
PortID requestPortIndex,
SimObject * responderObject,
const std::string & responsePort,
PortID responsePortIndex )
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().

◆ bindRequestPort()

void gem5::CxxConfigManager::bindRequestPort ( SimObject * object,
const CxxConfigDirectoryEntry::PortDesc & port,
const std::vector< std::string > & peers )
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().

◆ deleteObjects()

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.

◆ drain()

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().

◆ drainResume()

void gem5::CxxConfigManager::drainResume ( )

Resume from drain.

Definition at line 636 of file cxx_manager.cc.

References gem5::DrainManager::instance(), and gem5::DrainManager::resume().

◆ findAllObjects()

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().

◆ findObject()

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:

  • Calling findObjectParams to make the ...Params object If findObjectParams has already been called for this object, the ...Params object generated by that called (stored in (objectParamsByName[object_name] will be used)
  • Populating the ...Params object references to other SimObjects by recursively descending into the trees formed by SimObject references
  • Building the final SimObject and adding it to objectsByName
  • If visit_children is true, recursively visit all this object's children and build/find them too

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().

◆ findObjectParams()

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:

  • parameter values from the configuration file
  • port connection connection counts from the connection counts indicated by the number of peer ports in the configuration file
  • nulled (or vector<>::clear'ed) SimObject references for SimObject-values parameters

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().

◆ findObjectType()

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().

◆ findTraversalOrder()

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().

◆ forEachObject()

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().

◆ getObject()

template<typename SimObjectType >
SimObjectType & gem5::CxxConfigManager::getObject ( const std::string & object_name)
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().

◆ getSimObjectResolver()

SimObjectResolver & gem5::CxxConfigManager::getSimObjectResolver ( )
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.

◆ initState()

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().

◆ instantiate()

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().

◆ loadState()

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.

◆ parsePort()

void gem5::CxxConfigManager::parsePort ( const std::string & inp,
std::string & path,
std::string & port,
unsigned int & index )
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().

◆ rename()

std::string gem5::CxxConfigManager::rename ( const std::string & from_name)
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().

◆ serialize()

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.

◆ setParam()

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().

◆ setParamVector()

void gem5::CxxConfigManager::setParamVector ( const std::string & object_name,
const std::string & param_name,
const std::vector< std::string > & param_values )

◆ startup()

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().

◆ unRename()

std::string gem5::CxxConfigManager::unRename ( const std::string & to_name)
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().

Member Data Documentation

◆ configFile

CxxConfigFileBase& gem5::CxxConfigManager::configFile
protected

Configuration file being read.

Definition at line 73 of file cxx_manager.hh.

Referenced by bindObjectPorts(), findAllObjects(), findObject(), findObjectParams(), findObjectType(), and findTraversalOrder().

◆ flags

CxxConfigParams::Flags gem5::CxxConfigManager::flags
protected

Flags to pass to affect param setting.

Definition at line 76 of file cxx_manager.hh.

Referenced by findObjectParams(), setParam(), and setParamVector().

◆ inVisit

std::set<std::string> gem5::CxxConfigManager::inVisit
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().

◆ objectParamsByName

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().

◆ objectsByName

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().

◆ objectsInOrder

std::list<SimObject *> gem5::CxxConfigManager::objectsInOrder

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().

◆ renamings

std::list<Renaming> gem5::CxxConfigManager::renamings
protected

All the renamings applicable when instantiating objects.

Definition at line 129 of file cxx_manager.hh.

Referenced by addRenaming(), rename(), and unRename().

◆ simObjectResolver

SimObjectResolver gem5::CxxConfigManager::simObjectResolver
protected

Singleton instance of SimObjectResolver.

Definition at line 172 of file cxx_manager.hh.

Referenced by getSimObjectResolver().


The documentation for this class was generated from the following files:

Generated on Tue Jun 18 2024 16:24:10 for gem5 by doxygen 1.11.0