gem5  v22.1.0.0
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
#define DPRINTF(x,...)
Definition: trace.hh:186
Interface for things with names.
Definition: named.hh:39
virtual std::string name() const
Definition: named.hh:47
ObjectMatch contains a vector of expressions.
Definition: match.hh:57
Ports are used to interface objects to each other.
Definition: port.hh:62
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:164
Base class to wrap object resolving functionality.
Definition: sim_object.hh:386
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
virtual ~SimObject()
Definition: sim_object.cc:70
static SimObjectResolver * _objNameResolver
Helper to resolve an object given its name.
Definition: sim_object.hh:156
SimObjectParams Params
Definition: sim_object.hh:170
static void serializeAll(const std::string &cpt_dir)
Create a checkpoint by serializing all SimObjects in the system.
Definition: sim_object.cc:135
std::vector< SimObject * > SimObjectList
Definition: sim_object.hh:150
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
ProbeManager * probeManager
Manager coordinates hooking up probe points with listeners.
Definition: sim_object.hh:159
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
static SimObjectList simObjectList
List of all instantiated simulation objects.
Definition: sim_object.hh:153
Statistics container.
Definition: group.hh:94
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:190
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
bool find(const std::string &section, const std::string &entry, std::string &value)
Definition: serialize.cc:193
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
Definition: serialize.cc:74
static const std::string & currentSection()
Gets the fully-qualified name of the active section.
Definition: serialize.cc:130
virtual void loadState(CheckpointIn &cp)
loadState() is called on each SimObject when restoring from a checkpoint.
Definition: sim_object.cc:81
bool sectionExists(const std::string &section)
Definition: serialize.cc:200
virtual SimObject * resolveSimObject(const std::string &name)=0
Find a SimObject given a full path name.
virtual void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: sim_object.cc:94
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
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Definition: serialize.cc:81
virtual void regProbeListeners()
Register probe listeners for this object.
Definition: sim_object.cc:115
SimObject(const Params &p)
Definition: sim_object.cc:58
virtual void startup()
startup() is the final initialization call before simulation.
Definition: sim_object.cc:99
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:120
virtual void regProbePoints()
Register probe points for this object.
Definition: sim_object.cc:107
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
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: sim_object.cc:76
static SimObject * find(const char *name)
Find the SimObject with the given name and return a pointer to it.
Definition: sim_object.cc:176
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 1 > ri
Definition: misc.hh:125
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:245
void debug_serialize(const std::string &cpt_dir)
Definition: sim_object.cc:216
EventQueue * getEventQueue(uint32_t index)
Function for returning eventq queue for the provided index.
Definition: eventq.cc:62
const std::string & name()
Definition: trace.cc:49

Generated on Wed Dec 21 2022 10:22:40 for gem5 by doxygen 1.9.1