gem5  v21.1.0.2
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 #ifdef DEBUG
64  doDebugBreak = false;
65 #endif
66  simObjectList.push_back(this);
67  probeManager = new ProbeManager(this);
68 }
69 
71 {
72  delete probeManager;
73 }
74 
75 void
77 {
78 }
79 
80 void
82 {
83  if (cp.sectionExists(name())) {
84  DPRINTF(Checkpoint, "unserializing\n");
85  // This works despite name() returning a fully qualified name
86  // since we are at the top level.
87  unserializeSection(cp, name());
88  } else {
89  DPRINTF(Checkpoint, "no checkpoint section found\n");
90  }
91 }
92 
93 void
95 {
96 }
97 
98 void
100 {
101 }
102 
106 void
108 {
109 }
110 
114 void
116 {
117 }
118 
119 ProbeManager *
121 {
122  return probeManager;
123 }
124 
125 Port &
126 SimObject::getPort(const std::string &if_name, PortID idx)
127 {
128  fatal("%s does not have any port named %s\n", name(), if_name);
129 }
130 
131 //
132 // static function: serialize all SimObjects.
133 //
134 void
135 SimObject::serializeAll(const std::string &cpt_dir)
136 {
137  std::ofstream cp;
139 
140  SimObjectList::reverse_iterator ri = simObjectList.rbegin();
141  SimObjectList::reverse_iterator rend = simObjectList.rend();
142 
143  for (; ri != rend; ++ri) {
144  SimObject *obj = *ri;
145  // This works despite name() returning a fully qualified name
146  // since we are at the top level.
147  obj->serializeSection(cp, obj->name());
148  }
149 }
150 
151 #ifdef DEBUG
152 //
153 // static function: flag which objects should have the debugger break
154 //
155 void
156 SimObject::debugObjectBreak(const std::string &objs)
157 {
158  SimObjectList::const_iterator i = simObjectList.begin();
159  SimObjectList::const_iterator end = simObjectList.end();
160 
161  ObjectMatch match(objs);
162  for (; i != end; ++i) {
163  SimObject *obj = *i;
164  obj->doDebugBreak = match.match(obj->name());
165  }
166 }
167 
168 void
169 debugObjectBreak(const char *objs)
170 {
171  SimObject::debugObjectBreak(std::string(objs));
172 }
173 #endif
174 
175 SimObject *
176 SimObject::find(const char *name)
177 {
178  SimObjectList::const_iterator i = simObjectList.begin();
179  SimObjectList::const_iterator end = simObjectList.end();
180 
181  for (; i != end; ++i) {
182  SimObject *obj = *i;
183  if (obj->name() == name)
184  return obj;
185  }
186 
187  return NULL;
188 }
189 
190 void
192 {
193  assert(!_objNameResolver);
194  _objNameResolver = resolver;
195 }
196 
199 {
200  assert(_objNameResolver);
201  return _objNameResolver;
202 }
203 
204 void
205 objParamIn(CheckpointIn &cp, const std::string &name, SimObject * &param)
206 {
207  const std::string &section(Serializable::currentSection());
208  std::string path;
209  if (!cp.find(section, name, path)) {
210  fatal("Can't unserialize '%s:%s'\n", section, name);
211  }
213 }
214 
215 void
216 debug_serialize(const std::string &cpt_dir)
217 {
218  SimObject::serializeAll(cpt_dir);
219 }
220 
221 } // namespace gem5
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:189
gem5::PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:252
gem5::ObjectMatch
ObjectMatch contains a vector of expressions.
Definition: match.hh:56
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:126
gem5::SimObject::initState
virtual void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: sim_object.cc:94
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:135
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:176
gem5::SimObject::loadState
virtual void loadState(CheckpointIn &cp)
loadState() is called on each SimObject when restoring from a checkpoint.
Definition: sim_object.cc:81
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:76
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
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:198
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:216
gem5::SimObject::Params
SimObjectParams Params
Definition: sim_object.hh:170
gem5::EventManager
Definition: eventq.hh:987
gem5::SimObject::~SimObject
virtual ~SimObject()
Definition: sim_object.cc:70
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:205
gem5::PowerISA::ri
Bitfield< 1 > ri
Definition: misc.hh:120
sim_object.hh
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
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:49
gem5::ProbeManager
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:163
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:120
gem5::SimObject::regProbeListeners
virtual void regProbeListeners()
Register probe listeners for this object.
Definition: sim_object.cc:115
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:99
gem5::SimObjectResolver
Base class to wrap object resolving functionality.
Definition: sim_object.hh:385
logging.hh
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
trace.hh
gem5::SimObject::regProbePoints
virtual void regProbePoints()
Register probe points for this object.
Definition: sim_object.cc:107
probe.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
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:191

Generated on Tue Sep 21 2021 12:25:48 for gem5 by doxygen 1.8.17