gem5  v20.1.0.0
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
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. 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...
 
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. More...
 
CxxConfigParamsfindObjectParams (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...
 
SimObjectResolvergetSimObjectResolver ()
 Get the resolver used to map SimObject names to SimObjects for checkpoint restore. More...
 
void setParam (const std::string &object_name, const std::string &param_name, const std::string &param_value)
 Convenience functions for calling set... More...
 
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. 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

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ CxxConfigManager()

CxxConfigManager::CxxConfigManager ( CxxConfigFileBase configFile_)

Definition at line 49 of file cxx_manager.cc.

Member Function Documentation

◆ addRenaming()

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.

◆ bindAllPorts()

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

◆ bindObjectPorts()

void CxxConfigManager::bindObjectPorts ( SimObject object)

◆ bindPort()

void 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 446 of file cxx_manager.cc.

References Port::bind(), csprintf(), DPRINTF, SimObject::getPort(), Port::isConnected(), and SimObject::name().

Referenced by bindRequestPort().

◆ bindRequestPort()

void 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 483 of file cxx_manager.cc.

References bindPort(), csprintf(), CxxConfigDirectoryEntry::PortDesc::name, SimObject::name(), objectsByName, parsePort(), and rename().

Referenced by bindObjectPorts().

◆ deleteObjects()

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.

◆ drain()

unsigned int CxxConfigManager::drain ( )

Drain all objects.

Definition at line 627 of file cxx_manager.cc.

References DrainManager::instance(), and DrainManager::tryDrain().

◆ drainResume()

void CxxConfigManager::drainResume ( )

Resume from drain.

Definition at line 633 of file cxx_manager.cc.

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

◆ findAllObjects()

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

◆ findObject()

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:

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

◆ findObjectParams()

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:

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

◆ findObjectType()

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

◆ findTraversalOrder()

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

◆ forEachObject()

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

◆ getObject()

template<typename SimObjectType >
SimObjectType& 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 237 of file cxx_manager.hh.

References csprintf(), and objectsByName.

Referenced by CxxConfigManager::SimObjectResolver::resolveSimObject().

◆ getSimObjectResolver()

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

◆ initState()

void CxxConfigManager::initState ( )

Call initState on all objects.

Definition at line 613 of file cxx_manager.cc.

References DPRINTF, forEachObject(), and SimObject::initState().

◆ instantiate()

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

◆ loadState()

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.

◆ parsePort()

void 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 558 of file cxx_manager.cc.

References DPRINTF, and MipsISA::index.

Referenced by bindRequestPort().

◆ rename()

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

◆ serialize()

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.

◆ setParam()

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

◆ setParamVector()

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

◆ startup()

void CxxConfigManager::startup ( )

Call startup on all objects.

Definition at line 620 of file cxx_manager.cc.

References DPRINTF, forEachObject(), and SimObject::startup().

◆ unRename()

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

Member Data Documentation

◆ configFile

CxxConfigFileBase& CxxConfigManager::configFile
protected

Configuration file being read.

Definition at line 70 of file cxx_manager.hh.

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

◆ flags

CxxConfigParams::Flags CxxConfigManager::flags
protected

Flags to pass to affect param setting.

Definition at line 73 of file cxx_manager.hh.

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

◆ inVisit

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

◆ objectParamsByName

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

◆ objectsByName

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

◆ objectsInOrder

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

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

◆ renamings

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

All the renamings applicable when instantiating objects.

Definition at line 126 of file cxx_manager.hh.

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

◆ simObjectResolver

SimObjectResolver CxxConfigManager::simObjectResolver
protected

Singleton instance of SimObjectResolver.

Definition at line 169 of file cxx_manager.hh.

Referenced by getSimObjectResolver().


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

Generated on Wed Sep 30 2020 14:02:23 for gem5 by doxygen 1.8.17