sim_object.hh (9254:f1b35c618252) | sim_object.hh (9342:6fec8f26e56d) |
---|---|
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 --- 31 unchanged lines hidden (view full) --- 40#include <iostream> 41#include <list> 42#include <map> 43#include <string> 44#include <vector> 45 46#include "enums/MemoryMode.hh" 47#include "params/SimObject.hh" | 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 --- 31 unchanged lines hidden (view full) --- 40#include <iostream> 41#include <list> 42#include <map> 43#include <string> 44#include <vector> 45 46#include "enums/MemoryMode.hh" 47#include "params/SimObject.hh" |
48#include "sim/drain.hh" |
|
48#include "sim/eventq.hh" 49#include "sim/serialize.hh" 50 51class BaseCPU; 52class Event; 53 54/** 55 * Abstract superclass for simulation objects. Represents things that --- 11 unchanged lines hidden (view full) --- 67 * <li>SimObject::init() 68 * <li>SimObject::regStats() 69 * <li><ul> 70 * <li>SimObject::initState() if starting afresh. 71 * <li>SimObject::loadState() if restoring from a checkpoint. 72 * </ul> 73 * <li>SimObject::resetStats() 74 * <li>SimObject::startup() | 49#include "sim/eventq.hh" 50#include "sim/serialize.hh" 51 52class BaseCPU; 53class Event; 54 55/** 56 * Abstract superclass for simulation objects. Represents things that --- 11 unchanged lines hidden (view full) --- 68 * <li>SimObject::init() 69 * <li>SimObject::regStats() 70 * <li><ul> 71 * <li>SimObject::initState() if starting afresh. 72 * <li>SimObject::loadState() if restoring from a checkpoint. 73 * </ul> 74 * <li>SimObject::resetStats() 75 * <li>SimObject::startup() |
75 * <li>SimObject::resume() if resuming from a checkpoint. | 76 * <li>Drainable::drainResume() if resuming from a checkpoint. |
76 * </ol> 77 * | 77 * </ol> 78 * |
78 * An object's internal state needs to be drained when creating a 79 * checkpoint, switching between CPU models, or switching between 80 * timing models. Once the internal state has been drained from 81 * <i>all</i> objects in the system, the objects are serialized to 82 * disc or the configuration change takes place. The process works as 83 * follows (see simulate.py for details): 84 * 85 * <ol> 86 * <li>An instance of a CountedDrainEvent is created to keep track of 87 * how many objects need to be drained. The object maintains an 88 * internal counter that is decreased every time its 89 * CountedDrainEvent::process() method is called. When the counter 90 * reaches zero, the simulation is stopped. 91 * 92 * <li>Call SimObject::drain() for every object in the 93 * system. Draining has completed if all of them return 94 * zero. Otherwise, the sum of the return values is loaded into 95 * the counter of the CountedDrainEvent. A pointer of the drain 96 * event is passed as an argument to the drain() method. 97 * 98 * <li>Continue simulation. When an object has finished draining its 99 * internal state, it calls CountedDrainEvent::process() on the 100 * CountedDrainEvent. When counter in the CountedDrainEvent reaches 101 * zero, the simulation stops. 102 * 103 * <li>Check if any object still needs draining, if so repeat the 104 * process above. 105 * 106 * <li>Serialize objects, switch CPU model, or change timing model. 107 * 108 * <li>Call SimObject::resume() and continue the simulation. 109 * </ol> 110 * | |
111 * @note Whenever a method is called on all objects in the simulator's 112 * object tree (e.g., init(), startup(), or loadState()), a pre-order 113 * depth-first traversal is performed (see descendants() in 114 * SimObject.py). This has the effect of calling the method on the 115 * parent node <i>before</i> its children. 116 */ | 79 * @note Whenever a method is called on all objects in the simulator's 80 * object tree (e.g., init(), startup(), or loadState()), a pre-order 81 * depth-first traversal is performed (see descendants() in 82 * SimObject.py). This has the effect of calling the method on the 83 * parent node <i>before</i> its children. 84 */ |
117class SimObject : public EventManager, public Serializable | 85class SimObject : public EventManager, public Serializable, public Drainable |
118{ | 86{ |
119 public: 120 /** 121 * Object drain/handover states 122 * 123 * An object starts out in the Running state. When the simulator 124 * prepares to take a snapshot or prepares a CPU for handover, it 125 * calls the drain() method to transfer the object into the 126 * Draining or Drained state. If any object enters the Draining 127 * state (drain() returning >0), simulation continues until it all 128 * objects have entered the Drained. 129 * 130 * The before resuming simulation, the simulator calls resume() to 131 * transfer the object to the Running state. 132 * 133 * \note Even though the state of an object (visible to the rest 134 * of the world through getState()) could be used to determine if 135 * all objects have entered the Drained state, the protocol is 136 * actually a bit more elaborate. See drain() for details. 137 */ 138 enum State { 139 Running, /** Running normally */ 140 Draining, /** Draining buffers pending serialization/handover */ 141 Drained /** Buffers drained, ready for serialization/handover */ 142 }; 143 | |
144 private: | 87 private: |
145 State state; 146 147 protected: 148 void changeState(State new_state) { state = new_state; } 149 150 public: 151 State getState() { return state; } 152 153 private: | |
154 typedef std::vector<SimObject *> SimObjectList; 155 156 /** List of all instantiated simulation objects. */ 157 static SimObjectList simObjectList; 158 159 protected: 160 /** Cached copy of the object parameters. */ 161 const SimObjectParams *_params; --- 50 unchanged lines hidden (view full) --- 212 * startup() is the final initialization call before simulation. 213 * All state is initialized (including unserialized state, if any, 214 * such as the curTick() value), so this is the appropriate place to 215 * schedule initial event(s) for objects that need them. 216 */ 217 virtual void startup(); 218 219 /** | 88 typedef std::vector<SimObject *> SimObjectList; 89 90 /** List of all instantiated simulation objects. */ 91 static SimObjectList simObjectList; 92 93 protected: 94 /** Cached copy of the object parameters. */ 95 const SimObjectParams *_params; --- 50 unchanged lines hidden (view full) --- 146 * startup() is the final initialization call before simulation. 147 * All state is initialized (including unserialized state, if any, 148 * such as the curTick() value), so this is the appropriate place to 149 * schedule initial event(s) for objects that need them. 150 */ 151 virtual void startup(); 152 153 /** |
220 * Serialize all SimObjects in the system. | 154 * Provide a default implementation of the drain interface that 155 * simply returns 0 (draining completed) and sets the drain state 156 * to Drained. |
221 */ | 157 */ |
222 static void serializeAll(std::ostream &os); | 158 unsigned int drain(DrainManager *drainManger); |
223 224 /** | 159 160 /** |
225 * Determine if an object needs draining and register a drain 226 * event. 227 * 228 * When draining the state of an object, the simulator calls drain 229 * with a pointer to a drain event. If the object does not need 230 * further simulation to drain internal buffers, it switched to 231 * the Drained state and returns 0, otherwise it switches to the 232 * Draining state and returns the number of times that it will 233 * call Event::process() on the drain event. Most objects are 234 * expected to return either 0 or 1. 235 * 236 * The default implementation simply switches to the Drained state 237 * and returns 0. 238 * 239 * @note An object that has entered the Drained state can be 240 * disturbed by other objects in the system and consequently be 241 * forced to enter the Draining state again. The simulator 242 * therefore repeats the draining process until all objects return 243 * 0 on the first call to drain(). 244 * 245 * @param drain_event Event to use to inform the simulator when 246 * the draining has completed. 247 * 248 * @return 0 if the object is ready for serialization now, >0 if 249 * it needs further simulation. | 161 * Serialize all SimObjects in the system. |
250 */ | 162 */ |
251 virtual unsigned int drain(Event *drain_event); | 163 static void serializeAll(std::ostream &os); |
252 | 164 |
253 /** 254 * Switch an object in the Drained stated into the Running state. 255 */ 256 virtual void resume(); 257 | |
258#ifdef DEBUG 259 public: 260 bool doDebugBreak; 261 static void debugObjectBreak(const std::string &objs); 262#endif 263 264 /** 265 * Find the SimObject with the given name and return a pointer to 266 * it. Primarily used for interactive debugging. Argument is 267 * char* rather than std::string to make it callable from gdb. 268 */ 269 static SimObject *find(const char *name); 270}; 271 272#endif // __SIM_OBJECT_HH__ | 165#ifdef DEBUG 166 public: 167 bool doDebugBreak; 168 static void debugObjectBreak(const std::string &objs); 169#endif 170 171 /** 172 * Find the SimObject with the given name and return a pointer to 173 * it. Primarily used for interactive debugging. Argument is 174 * char* rather than std::string to make it callable from gdb. 175 */ 176 static SimObject *find(const char *name); 177}; 178 179#endif // __SIM_OBJECT_HH__ |