1/* |
2 * Copyright (c) 2012, 2015, 2017 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 --- 42 unchanged lines hidden (view full) --- 53 * An object starts out in the Running state. When the simulator 54 * prepares to take a snapshot or prepares a CPU for handover, it 55 * calls the drain() method to transfer the object into the Draining 56 * or Drained state. If any object enters the Draining state 57 * (Drainable::drain() returning >0), simulation continues until it 58 * all objects have entered the Drained state. 59 * 60 * Before resuming simulation, the simulator calls resume() to |
61 * transfer the object to the Running state. This in turn results in a 62 * call to drainResume() for all Drainable objects in the 63 * simulator. New Drainable objects may be created while resuming. In 64 * such cases, the new objects will be created in the Resuming state 65 * and later resumed. |
66 * 67 * \note Even though the state of an object (visible to the rest of 68 * the world through Drainable::getState()) could be used to determine 69 * if all objects have entered the Drained state, the protocol is 70 * actually a bit more elaborate. See Drainable::drain() for details. 71 */ 72enum class DrainState { 73 Running, /** Running normally */ 74 Draining, /** Draining buffers pending serialization/handover */ |
75 Drained, /** Buffers drained, ready for serialization/handover */ 76 Resuming, /** Transient state while the simulator is resuming */ |
77}; 78#endif 79 80/** 81 * This class coordinates draining of a System. 82 * 83 * When draining the simulator, we need to make sure that all 84 * Drainable objects within the system have ended up in the drained --- 68 unchanged lines hidden (view full) --- 153 void signalDrainDone(); 154 155 public: 156 void registerDrainable(Drainable *obj); 157 void unregisterDrainable(Drainable *obj); 158 159 private: 160 /** |
161 * Helper function to check if all Drainable objects are in a 162 * specific state. 163 */ 164 bool allInState(DrainState state) const; 165 166 /** |
167 * Thread-safe helper function to get the number of Drainable 168 * objects in a system. 169 */ 170 size_t drainableCount() const; 171 172 /** Lock protecting the set of drainable objects */ 173 mutable std::mutex globalLock; 174 --- 92 unchanged lines hidden (view full) --- 267 * into a state where it is ready to be drained. The method is 268 * safe to call multiple times and there is no need to check that 269 * draining has been requested before calling this method. 270 */ 271 void signalDrainDone() const { 272 switch (_drainState) { 273 case DrainState::Running: 274 case DrainState::Drained: |
275 case DrainState::Resuming: |
276 return; 277 case DrainState::Draining: 278 _drainState = DrainState::Drained; 279 _drainManager.signalDrainDone(); 280 return; 281 } 282 } 283 --- 36 unchanged lines hidden --- |