gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sim_object.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2005 The Regents of The University of Michigan
3  * Copyright (c) 2010 Advanced Micro Devices, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "sim/sim_object.hh"
31 
32 #include <cassert>
33 
34 #include "base/logging.hh"
35 #include "base/match.hh"
36 #include "base/trace.hh"
37 #include "debug/Checkpoint.hh"
38 #include "sim/probe/probe.hh"
39 
40 namespace gem5
41 {
42 
44 //
45 // SimObject member definitions
46 //
48 
49 //
50 // static list of all SimObjects, used for initialization etc.
51 //
53 SimObjectResolver *SimObject::_objNameResolver = NULL;
54 
55 //
56 // SimObject constructor: used to maintain static simObjectList
57 //
59  : EventManager(getEventQueue(p.eventq_index)),
60  statistics::Group(nullptr), Named(p.name),
61  _params(p)
62 {
63  simObjectList.push_back(this);
64  probeManager = new ProbeManager(this);
65 }
66 
68 {
69  delete probeManager;
70 }
71 
72 void
74 {
75 }
76 
77 void
79 {
80  if (cp.sectionExists(name())) {
81  DPRINTF(Checkpoint, "unserializing\n");
82  // This works despite name() returning a fully qualified name
83  // since we are at the top level.
84  unserializeSection(cp, name());
85  } else {
86  DPRINTF(Checkpoint, "no checkpoint section found\n");
87  }
88 }
89 
90 void
92 {
93 }
94 
95 void
97 {
98 }
99 
103 void
105 {
106 }
107 
111 void
113 {
114 }
115 
116 ProbeManager *
118 {
119  return probeManager;
120 }
121 
122 Port &
123 SimObject::getPort(const std::string &if_name, PortID idx)
124 {
125  fatal("%s does not have any port named %s\n", name(), if_name);
126 }
127 
128 //
129 // static function: serialize all SimObjects.
130 //
131 void
132 SimObject::serializeAll(const std::string &cpt_dir)
133 {
134  std::ofstream cp;
136 
137  SimObjectList::reverse_iterator ri = simObjectList.rbegin();
138  SimObjectList::reverse_iterator rend = simObjectList.rend();
139 
140  for (; ri != rend; ++ri) {
141  SimObject *obj = *ri;
142  // This works despite name() returning a fully qualified name
143  // since we are at the top level.
144  obj->serializeSection(cp, obj->name());
145  }
146 }
147 
148 SimObject *
149 SimObject::find(const char *name)
150 {
151  SimObjectList::const_iterator i = simObjectList.begin();
152  SimObjectList::const_iterator end = simObjectList.end();
153 
154  for (; i != end; ++i) {
155  SimObject *obj = *i;
156  if (obj->name() == name)
157  return obj;
158  }
159 
160  return NULL;
161 }
162 
163 void
165 {
166  assert(!_objNameResolver);
167  _objNameResolver = resolver;
168 }
169 
172 {
173  assert(_objNameResolver);
174  return _objNameResolver;
175 }
176 
177 void
178 objParamIn(CheckpointIn &cp, const std::string &name, SimObject * &param)
179 {
180  const std::string &section(Serializable::currentSection());
181  std::string path;
182  if (!cp.find(section, name, path)) {
183  fatal("Can't unserialize '%s:%s'\n", section, name);
184  }
186 }
187 
188 void
189 debug_serialize(const std::string &cpt_dir)
190 {
191  SimObject::serializeAll(cpt_dir);
192 }
193 
194 } // namespace gem5
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:200
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
gem5::SimObject::getPort
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:123
gem5::SimObject::initState
virtual void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: sim_object.cc:91
gem5::SimObject::_objNameResolver
static SimObjectResolver * _objNameResolver
Helper to resolve an object given its name.
Definition: sim_object.hh:156
gem5::SimObject::serializeAll
static void serializeAll(const std::string &cpt_dir)
Create a checkpoint by serializing all SimObjects in the system.
Definition: sim_object.cc:132
gem5::SimObject::probeManager
ProbeManager * probeManager
Manager coordinates hooking up probe points with listeners.
Definition: sim_object.hh:159
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::getEventQueue
EventQueue * getEventQueue(uint32_t index)
Function for returning eventq queue for the provided index.
Definition: eventq.cc:62
gem5::Serializable::serializeSection
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
Definition: serialize.cc:74
gem5::SimObject::find
static SimObject * find(const char *name)
Find the SimObject with the given name and return a pointer to it.
Definition: sim_object.cc:149
gem5::SimObject::loadState
virtual void loadState(CheckpointIn &cp)
loadState() is called on each SimObject when restoring from a checkpoint.
Definition: sim_object.cc:78
gem5::SimObject::init
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: sim_object.cc:73
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::SimObject::getSimObjectResolver
static SimObjectResolver * getSimObjectResolver()
There is a single object name resolver, and it is only set when simulation is restoring from checkpoi...
Definition: sim_object.cc:171
gem5::SimObject::SimObjectList
std::vector< SimObject * > SimObjectList
Definition: sim_object.hh:150
gem5::Named
Interface for things with names.
Definition: named.hh:38
gem5::SimObject::simObjectList
static SimObjectList simObjectList
List of all instantiated simulation objects.
Definition: sim_object.hh:153
gem5::debug_serialize
void debug_serialize(const std::string &cpt_dir)
Definition: sim_object.cc:189
gem5::SimObject::Params
SimObjectParams Params
Definition: sim_object.hh:170
gem5::EventManager
Definition: eventq.hh:980
gem5::SimObject::~SimObject
virtual ~SimObject()
Definition: sim_object.cc:67
match.hh
gem5::Named::name
virtual std::string name() const
Definition: named.hh:47
gem5::Serializable::unserializeSection
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Definition: serialize.cc:81
gem5::objParamIn
void objParamIn(CheckpointIn &cp, const std::string &name, SimObject *&param)
To avoid circular dependencies the unserialization of SimObjects must be implemented here.
Definition: sim_object.cc:178
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::PowerISA::ri
Bitfield< 1 > ri
Definition: misc.hh:125
sim_object.hh
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:210
gem5::Serializable::generateCheckpointOut
static void generateCheckpointOut(const std::string &cpt_dir, std::ofstream &outstream)
Generate a checkpoint file so that the serialization can be routed to it.
Definition: serialize.cc:88
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
name
const std::string & name()
Definition: trace.cc:48
gem5::ProbeManager
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:162
gem5::Serializable::currentSection
static const std::string & currentSection()
Gets the fully-qualified name of the active section.
Definition: serialize.cc:130
gem5::SimObject::getProbeManager
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:117
gem5::SimObject::regProbeListeners
virtual void regProbeListeners()
Register probe listeners for this object.
Definition: sim_object.cc:112
gem5::SimObject::SimObject
SimObject(const Params &p)
Definition: sim_object.cc:58
gem5::CheckpointIn::sectionExists
bool sectionExists(const std::string &section)
Definition: serialize.cc:200
gem5::CheckpointIn::find
bool find(const std::string &section, const std::string &entry, std::string &value)
Definition: serialize.cc:193
gem5::Port
Ports are used to interface objects to each other.
Definition: port.hh:61
gem5::SimObject::startup
virtual void startup()
startup() is the final initialization call before simulation.
Definition: sim_object.cc:96
gem5::SimObjectResolver
Base class to wrap object resolving functionality.
Definition: sim_object.hh:379
logging.hh
gem5::statistics::Group
Statistics container.
Definition: group.hh:92
trace.hh
gem5::SimObject::regProbePoints
virtual void regProbePoints()
Register probe points for this object.
Definition: sim_object.cc:104
probe.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::SimObjectResolver::resolveSimObject
virtual SimObject * resolveSimObject(const std::string &name)=0
Find a SimObject given a full path name.
gem5::SimObject::setSimObjectResolver
static void setSimObjectResolver(SimObjectResolver *resolver)
There is a single object name resolver, and it is only set when simulation is restoring from checkpoi...
Definition: sim_object.cc:164

Generated on Sun Jul 30 2023 01:57:00 for gem5 by doxygen 1.8.17