gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
40namespace gem5
41{
42
44//
45// SimObject member definitions
46//
48
49//
50// static list of all SimObjects, used for initialization etc.
51//
53SimObjectResolver *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
71
72void
76
77void
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.
85 } else {
86 DPRINTF(Checkpoint, "no checkpoint section found\n");
87 }
88}
89
90void
94
95void
99
103void
107
111void
115
121
122Port &
123SimObject::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//
131void
132SimObject::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
148SimObject *
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
163void
169
176
177void
178objParamIn(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
188void
189debug_serialize(const std::string &cpt_dir)
190{
192}
193
194} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
Interface for things with names.
Definition named.hh:39
virtual std::string name() const
Definition named.hh:47
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.
Abstract superclass for simulation objects.
virtual ~SimObject()
Definition sim_object.cc:67
static SimObjectResolver * _objNameResolver
Helper to resolve an object given its name.
SimObjectParams Params
static void serializeAll(const std::string &cpt_dir)
Create a checkpoint by serializing all SimObjects in the system.
std::vector< SimObject * > SimObjectList
static void setSimObjectResolver(SimObjectResolver *resolver)
There is a single object name resolver, and it is only set when simulation is restoring from checkpoi...
ProbeManager * probeManager
Manager coordinates hooking up probe points with listeners.
static SimObjectResolver * getSimObjectResolver()
There is a single object name resolver, and it is only set when simulation is restoring from checkpoi...
static SimObjectList simObjectList
List of all instantiated simulation objects.
Statistics container.
Definition group.hh:93
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
void objParamIn(CheckpointIn &cp, const std::string &name, SimObject *&param)
To avoid circular dependencies the unserialization of SimObjects must be implemented here.
bool find(const std::string &section, const std::string &entry, std::string &value)
Definition serialize.cc:196
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:78
virtual SimObject * resolveSimObject(const std::string &name)=0
Find a SimObject given a full path name.
bool sectionExists(const std::string &section)
Definition serialize.cc:203
virtual void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
Definition sim_object.cc:91
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.
SimObject(const Params &p)
Definition sim_object.cc:58
virtual void startup()
startup() is the final initialization call before simulation.
Definition sim_object.cc:96
ProbeManager * getProbeManager()
Get the probe manager for this object.
virtual void regProbePoints()
Register probe points for this object.
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition sim_object.cc:73
static SimObject * find(const char *name)
Find the SimObject with the given name and return a pointer to it.
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0 > p
Bitfield< 1 > ri
Definition misc.hh:125
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
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)
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:48

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