gem5  v21.1.0.2
drain.hh
Go to the documentation of this file.
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
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  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __SIM_DRAIN_HH__
39 #define __SIM_DRAIN_HH__
40 
41 #include <atomic>
42 #include <mutex>
43 #include <vector>
44 
45 namespace gem5
46 {
47 
48 class Drainable;
49 
74 enum class DrainState
75 {
76  Running,
77  Draining,
78  Drained,
79  Resuming,
80 };
81 
83 {
84  private:
85  DrainManager();
86  DrainManager(DrainManager &) = delete;
87  ~DrainManager();
88 
89  public:
91  static DrainManager &instance() { return _instance; }
92 
109  bool tryDrain();
110 
116  void resume();
117 
138  void preCheckpointRestore();
139 
145  bool isDrained() const { return _state == DrainState::Drained; }
146 
152  DrainState state() const { return _state; }
153 
160  void signalDrainDone();
161 
162  public:
163  void registerDrainable(Drainable *obj);
164  void unregisterDrainable(Drainable *obj);
165 
166  private:
171  bool allInState(DrainState state) const;
172 
177  size_t drainableCount() const;
178 
180  mutable std::mutex globalLock;
181 
184 
190  std::atomic_uint _count;
191 
194 
197 };
198 
235 {
252  friend class DrainManager;
253 
254  protected:
255  Drainable();
256  virtual ~Drainable();
257 
286  virtual DrainState drain() = 0;
287 
293  virtual void drainResume() {};
294 
305  void signalDrainDone() const {
306  switch (_drainState) {
307  case DrainState::Running:
308  case DrainState::Drained:
310  return;
314  return;
315  }
316  }
317 
318  public:
324  DrainState drainState() const { return _drainState; }
325 
344  virtual void notifyFork() {};
345 
346  private:
350  void dmDrainResume();
351 
354 
361 };
362 
363 } // namespace gem5
364 
365 #endif
gem5::DrainManager::instance
static DrainManager & instance()
Get the singleton DrainManager instance.
Definition: drain.hh:91
gem5::Drainable::_drainState
DrainState _drainState
Current drain state of the object.
Definition: drain.hh:360
gem5::DrainState::Resuming
@ Resuming
Transient state while the simulator is resuming.
gem5::DrainManager::_allDrainable
std::vector< Drainable * > _allDrainable
Set of all drainable objects.
Definition: drain.hh:183
gem5::Drainable::drainState
DrainState drainState() const
Return the current drain state of an object.
Definition: drain.hh:324
gem5::DrainManager::_count
std::atomic_uint _count
Number of objects still draining.
Definition: drain.hh:190
gem5::Drainable::~Drainable
virtual ~Drainable()
Definition: drain.cc:204
gem5::DrainManager::unregisterDrainable
void unregisterDrainable(Drainable *obj)
Definition: drain.cc:169
gem5::Drainable::Drainable
Drainable()
Definition: drain.cc:197
gem5::DrainManager::drainableCount
size_t drainableCount() const
Thread-safe helper function to get the number of Drainable objects in a system.
Definition: drain.cc:189
std::vector
STL vector class.
Definition: stl.hh:37
gem5::Drainable::notifyFork
virtual void notifyFork()
Notify a child process of a fork.
Definition: drain.hh:344
gem5::DrainManager::_state
DrainState _state
Global simulator drain state.
Definition: drain.hh:193
gem5::DrainManager::allInState
bool allInState(DrainState state) const
Helper function to check if all Drainable objects are in a specific state.
Definition: drain.cc:178
gem5::DrainManager::preCheckpointRestore
void preCheckpointRestore()
Run state fixups before a checkpoint restore operation.
Definition: drain.cc:135
gem5::DrainState
DrainState
Object drain/handover states.
Definition: drain.hh:74
gem5::Drainable::dmDrainResume
void dmDrainResume()
DrainManager interface to request a resume operation.
Definition: drain.cc:221
gem5::DrainManager::~DrainManager
~DrainManager()
Definition: drain.cc:59
gem5::Drainable::dmDrain
DrainState dmDrain()
DrainManager interface to request a drain operation.
Definition: drain.cc:210
gem5::Drainable::_drainManager
DrainManager & _drainManager
Convenience reference to the drain manager.
Definition: drain.hh:353
gem5::DrainManager
Definition: drain.hh:82
gem5::DrainState::Drained
@ Drained
Buffers drained, ready for serialization/handover.
gem5::Drainable::signalDrainDone
void signalDrainDone() const
Signal that an object is drained.
Definition: drain.hh:305
gem5::DrainManager::tryDrain
bool tryDrain()
Try to drain the system.
Definition: drain.cc:64
gem5::DrainManager::resume
void resume()
Resume normal simulation in a Drained system.
Definition: drain.cc:96
gem5::Drainable::drainResume
virtual void drainResume()
Resume execution after a successful drain.
Definition: drain.hh:293
gem5::DrainManager::isDrained
bool isDrained() const
Check if the system is drained.
Definition: drain.hh:145
gem5::Drainable
Interface for objects that might require draining before checkpointing.
Definition: drain.hh:234
gem5::DrainManager::state
DrainState state() const
Get the simulators global drain state.
Definition: drain.hh:152
gem5::DrainManager::signalDrainDone
void signalDrainDone()
Notify the DrainManager that a Drainable object has finished draining.
Definition: drain.cc:149
gem5::DrainState::Running
@ Running
Running normally.
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::DrainManager::_instance
static DrainManager _instance
Singleton instance of the drain manager.
Definition: drain.hh:196
gem5::DrainManager::registerDrainable
void registerDrainable(Drainable *obj)
Definition: drain.cc:160
gem5::Drainable::drain
virtual DrainState drain()=0
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
gem5::DrainState::Draining
@ Draining
Draining buffers pending serialization/handover.
gem5::DrainManager::DrainManager
DrainManager()
Definition: drain.cc:53
gem5::DrainManager::globalLock
std::mutex globalLock
Lock protecting the set of drainable objects.
Definition: drain.hh:180

Generated on Tue Sep 21 2021 12:25:47 for gem5 by doxygen 1.8.17