sim_object.hh (7534:c76a14014c27) sim_object.hh (7823:dac01f14f20f)
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 * Authors: Steve Reinhardt
30 * Nathan Binkert
31 */
32
33/* @file
34 * User Console Definitions
35 */
36
37#ifndef __SIM_OBJECT_HH__
38#define __SIM_OBJECT_HH__
39
40#include <iostream>
41#include <list>
42#include <map>
43#include <string>
44#include <vector>
45
46#include "params/SimObject.hh"
47#include "sim/eventq.hh"
48#include "sim/serialize.hh"
49
50class BaseCPU;
51class Event;
52
53/*
54 * Abstract superclass for simulation objects. Represents things that
55 * correspond to physical components and can be specified via the
56 * config file (CPUs, caches, etc.).
57 */
58class SimObject : public EventManager, public Serializable
59{
60 public:
61 enum State {
62 Running,
63 Draining,
64 Drained
65 };
66
67 private:
68 State state;
69
70 protected:
71 void changeState(State new_state) { state = new_state; }
72
73 public:
74 State getState() { return state; }
75
76 private:
77 typedef std::vector<SimObject *> SimObjectList;
78
79 // list of all instantiated simulation objects
80 static SimObjectList simObjectList;
81
82 protected:
83 const SimObjectParams *_params;
84
85 public:
86 typedef SimObjectParams Params;
87 const Params *params() const { return _params; }
88 SimObject(const Params *_params);
89 virtual ~SimObject() {}
90
91 public:
92
93 virtual const std::string name() const { return params()->name; }
94
95 // The following SimObject initialization methods are called from
96 // the instantiate() method in src/python/m5/simulate.py. See
97 // that function for details on how/when these methods are
98 // invoked.
99
100 /**
101 * init() is called after all C++ SimObjects have been created and
102 * all ports are connected. Initializations that are independent
103 * of unserialization but rely on a fully instantiated and
104 * connected SimObject graph should be done here.
105 */
106 virtual void init();
107
108 /**
109 * loadState() is called on each SimObject when restoring from a
110 * checkpoint. The default implementation simply calls
111 * unserialize() if there is a corresponding section in the
112 * checkpoint. However, objects can override loadState() to get
113 * other behaviors, e.g., doing other programmed initializations
114 * after unserialize(), or complaining if no checkpoint section is
115 * found.
116 */
117 virtual void loadState(Checkpoint *cp);
118
119 /**
120 * initState() is called on each SimObject when *not* restoring
121 * from a checkpoint. This provides a hook for state
122 * initializations that are only required for a "cold start".
123 */
124 virtual void initState();
125
126 // register statistics for this object
127 virtual void regStats();
128 virtual void regFormulas();
129 virtual void resetStats();
130
131 /**
132 * startup() is the final initialization call before simulation.
133 * All state is initialized (including unserialized state, if any,
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 * Authors: Steve Reinhardt
30 * Nathan Binkert
31 */
32
33/* @file
34 * User Console Definitions
35 */
36
37#ifndef __SIM_OBJECT_HH__
38#define __SIM_OBJECT_HH__
39
40#include <iostream>
41#include <list>
42#include <map>
43#include <string>
44#include <vector>
45
46#include "params/SimObject.hh"
47#include "sim/eventq.hh"
48#include "sim/serialize.hh"
49
50class BaseCPU;
51class Event;
52
53/*
54 * Abstract superclass for simulation objects. Represents things that
55 * correspond to physical components and can be specified via the
56 * config file (CPUs, caches, etc.).
57 */
58class SimObject : public EventManager, public Serializable
59{
60 public:
61 enum State {
62 Running,
63 Draining,
64 Drained
65 };
66
67 private:
68 State state;
69
70 protected:
71 void changeState(State new_state) { state = new_state; }
72
73 public:
74 State getState() { return state; }
75
76 private:
77 typedef std::vector<SimObject *> SimObjectList;
78
79 // list of all instantiated simulation objects
80 static SimObjectList simObjectList;
81
82 protected:
83 const SimObjectParams *_params;
84
85 public:
86 typedef SimObjectParams Params;
87 const Params *params() const { return _params; }
88 SimObject(const Params *_params);
89 virtual ~SimObject() {}
90
91 public:
92
93 virtual const std::string name() const { return params()->name; }
94
95 // The following SimObject initialization methods are called from
96 // the instantiate() method in src/python/m5/simulate.py. See
97 // that function for details on how/when these methods are
98 // invoked.
99
100 /**
101 * init() is called after all C++ SimObjects have been created and
102 * all ports are connected. Initializations that are independent
103 * of unserialization but rely on a fully instantiated and
104 * connected SimObject graph should be done here.
105 */
106 virtual void init();
107
108 /**
109 * loadState() is called on each SimObject when restoring from a
110 * checkpoint. The default implementation simply calls
111 * unserialize() if there is a corresponding section in the
112 * checkpoint. However, objects can override loadState() to get
113 * other behaviors, e.g., doing other programmed initializations
114 * after unserialize(), or complaining if no checkpoint section is
115 * found.
116 */
117 virtual void loadState(Checkpoint *cp);
118
119 /**
120 * initState() is called on each SimObject when *not* restoring
121 * from a checkpoint. This provides a hook for state
122 * initializations that are only required for a "cold start".
123 */
124 virtual void initState();
125
126 // register statistics for this object
127 virtual void regStats();
128 virtual void regFormulas();
129 virtual void resetStats();
130
131 /**
132 * startup() is the final initialization call before simulation.
133 * All state is initialized (including unserialized state, if any,
134 * such as the curTick value), so this is the appropriate place to
134 * such as the curTick() value), so this is the appropriate place to
135 * schedule initial event(s) for objects that need them.
136 */
137 virtual void startup();
138
139 // static: call nameOut() & serialize() on all SimObjects
140 static void serializeAll(std::ostream &);
141 static void unserializeAll(Checkpoint *cp);
142
143 // Methods to drain objects in order to take checkpoints
144 // Or switch from timing -> atomic memory model
145 // Drain returns 0 if the simobject can drain immediately or
146 // the number of times the drain_event's process function will be called
147 // before the object will be done draining. Normally this should be 1
148 virtual unsigned int drain(Event *drain_event);
149 virtual void resume();
150 virtual void setMemoryMode(State new_mode);
151 virtual void switchOut();
152 virtual void takeOverFrom(BaseCPU *cpu);
153
154#ifdef DEBUG
155 public:
156 bool doDebugBreak;
157 static void debugObjectBreak(const std::string &objs);
158#endif
159
160 /**
161 * Find the SimObject with the given name and return a pointer to
162 * it. Primarily used for interactive debugging. Argument is
163 * char* rather than std::string to make it callable from gdb.
164 */
165 static SimObject *find(const char *name);
166};
167
168#endif // __SIM_OBJECT_HH__
135 * schedule initial event(s) for objects that need them.
136 */
137 virtual void startup();
138
139 // static: call nameOut() & serialize() on all SimObjects
140 static void serializeAll(std::ostream &);
141 static void unserializeAll(Checkpoint *cp);
142
143 // Methods to drain objects in order to take checkpoints
144 // Or switch from timing -> atomic memory model
145 // Drain returns 0 if the simobject can drain immediately or
146 // the number of times the drain_event's process function will be called
147 // before the object will be done draining. Normally this should be 1
148 virtual unsigned int drain(Event *drain_event);
149 virtual void resume();
150 virtual void setMemoryMode(State new_mode);
151 virtual void switchOut();
152 virtual void takeOverFrom(BaseCPU *cpu);
153
154#ifdef DEBUG
155 public:
156 bool doDebugBreak;
157 static void debugObjectBreak(const std::string &objs);
158#endif
159
160 /**
161 * Find the SimObject with the given name and return a pointer to
162 * it. Primarily used for interactive debugging. Argument is
163 * char* rather than std::string to make it callable from gdb.
164 */
165 static SimObject *find(const char *name);
166};
167
168#endif // __SIM_OBJECT_HH__