gem5  v22.1.0.0
sim_object.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, 2021 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2001-2005 The Regents of The University of Michigan
15  * Copyright (c) 2010 Advanced Micro Devices, Inc.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
42 /* @file
43  * User Console Definitions
44  */
45 
46 #ifndef __SIM_OBJECT_HH__
47 #define __SIM_OBJECT_HH__
48 
49 #include <string>
50 #include <vector>
51 
52 #include "base/named.hh"
53 #include "base/stats/group.hh"
54 #include "params/SimObject.hh"
55 #include "sim/drain.hh"
56 #include "sim/eventq.hh"
57 #include "sim/port.hh"
58 #include "sim/serialize.hh"
59 
60 namespace gem5
61 {
62 
63 class EventManager;
64 class ProbeManager;
65 class SimObjectResolver;
66 
146 class SimObject : public EventManager, public Serializable, public Drainable,
147  public statistics::Group, public Named
148 {
149  private:
151 
154 
157 
160 
161  protected:
167  const SimObjectParams &_params;
168 
169  public:
170  typedef SimObjectParams Params;
176  const Params &params() const { return _params; }
177 
181  SimObject(const Params &p);
182 
183  virtual ~SimObject();
184 
185  public:
194  virtual void init();
195 
209  virtual void loadState(CheckpointIn &cp);
210 
218  virtual void initState();
219 
225  virtual void regProbePoints();
226 
232  virtual void regProbeListeners();
233 
245 
269  virtual Port &getPort(const std::string &if_name,
270  PortID idx=InvalidPortID);
271 
280  virtual void startup();
281 
286  DrainState drain() override { return DrainState::Drained; }
287 
298  virtual void memWriteback() {};
299 
313  virtual void memInvalidate() {};
314 
315  void serialize(CheckpointOut &cp) const override {};
316  void unserialize(CheckpointIn &cp) override {};
317 
330  static void serializeAll(const std::string &cpt_dir);
331 
332 #ifdef DEBUG
333  public:
334  bool doDebugBreak;
335  static void debugObjectBreak(const std::string &objs);
336 #endif
337 
345  static SimObject *find(const char *name);
346 
353  static void setSimObjectResolver(SimObjectResolver *resolver);
354 
362 };
363 
364 /* Add PARAMS(ClassName) to every descendant of SimObject that needs
365  * params.
366  *
367  * Strictly speaking, we need static_cast here, because the types are
368  * related by inheritance, but since the target type may be
369  * incomplete, the compiler does not know the relation.
370  */
371 #define PARAMS(type) \
372  using Params = type ## Params; \
373  const Params & \
374  params() const \
375  { \
376  return reinterpret_cast<const Params&>(_params); \
377  }
378 
386 {
387  public:
388  virtual ~SimObjectResolver() { }
389 
395  virtual SimObject *resolveSimObject(const std::string &name) = 0;
396 };
397 
398 #ifdef DEBUG
399 void debugObjectBreak(const char *objs);
400 #endif
401 
408 void objParamIn(CheckpointIn &cp, const std::string &name, SimObject * &param);
409 
410 void debug_serialize(const std::string &cpt_dir);
411 
412 } // namespace gem5
413 
414 #endif // __SIM_OBJECT_HH__
Interface for objects that might require draining before checkpointing.
Definition: drain.hh:235
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
Basic support for object serialization.
Definition: serialize.hh:170
Base class to wrap object resolving functionality.
Definition: sim_object.hh:386
virtual ~SimObjectResolver()
Definition: sim_object.hh:388
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: sim_object.hh:316
virtual ~SimObject()
Definition: sim_object.cc:70
static SimObjectResolver * _objNameResolver
Helper to resolve an object given its name.
Definition: sim_object.hh:156
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: sim_object.hh:315
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
DrainState drain() override
Provide a default implementation of the drain interface for objects that don't need draining.
Definition: sim_object.hh:286
Statistics container.
Definition: group.hh:94
STL vector class.
Definition: stl.hh:37
DrainState
Object drain/handover states.
Definition: drain.hh:75
@ Drained
Buffers drained, ready for serialization/handover.
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
virtual void loadState(CheckpointIn &cp)
loadState() is called on each SimObject when restoring from a checkpoint.
Definition: sim_object.cc:81
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
virtual void regProbeListeners()
Register probe listeners for this object.
Definition: sim_object.cc:115
virtual void memWriteback()
Write back dirty buffers to memory using functional writes.
Definition: sim_object.hh:298
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
const Params & params() const
Definition: sim_object.hh:176
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:120
const SimObjectParams & _params
Cached copy of the object parameters.
Definition: sim_object.hh:167
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
virtual void memInvalidate()
Invalidate the contents of memory buffers.
Definition: sim_object.hh:313
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
const PortID InvalidPortID
Definition: types.hh:246
std::ostream CheckpointOut
Definition: serialize.hh:66
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
Port Object Declaration.
const std::string & name()
Definition: trace.cc:49

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