gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
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 <cstddef>
43#include <mutex>
44#include <vector>
45
46namespace gem5
47{
48
49class Drainable;
50
82
84{
85 private:
89
90 public:
92 static DrainManager &
94 {
97 static DrainManager _instance;
98 return _instance;
99 }
100
117 bool tryDrain();
118
124 void resume();
125
147
153 bool isDrained() const { return _state == DrainState::Drained; }
154
160 DrainState state() const { return _state; }
161
168 void signalDrainDone();
169
170 public:
171 void registerDrainable(Drainable *obj);
173
174 private:
179 bool allInState(DrainState state) const;
180
185 size_t drainableCount() const;
186
188 mutable std::mutex globalLock;
189
192
198 std::atomic_uint _count;
199
202};
203
240{
257 friend class DrainManager;
258
259 protected:
260 Drainable();
261 virtual ~Drainable();
262
291 virtual DrainState drain() = 0;
292
298 virtual void drainResume() {};
299
310 void signalDrainDone() const {
311 switch (_drainState) {
315 return;
318 _drainManager.signalDrainDone();
319 return;
320 }
321 }
322
323 public:
330
349 virtual void notifyFork() {};
350
351 private:
355 void dmDrainResume();
356
359
366};
367
368} // namespace gem5
369
370#endif
void unregisterDrainable(Drainable *obj)
Definition drain.cc:167
std::mutex globalLock
Lock protecting the set of drainable objects.
Definition drain.hh:188
void registerDrainable(Drainable *obj)
Definition drain.cc:158
static DrainManager & instance()
Get the singleton DrainManager instance.
Definition drain.hh:93
DrainState _state
Global simulator drain state.
Definition drain.hh:201
size_t drainableCount() const
Thread-safe helper function to get the number of Drainable objects in a system.
Definition drain.cc:187
bool allInState(DrainState state) const
Helper function to check if all Drainable objects are in a specific state.
Definition drain.cc:176
std::atomic_uint _count
Number of objects still draining.
Definition drain.hh:198
std::vector< Drainable * > _allDrainable
Set of all drainable objects.
Definition drain.hh:191
DrainManager(DrainManager &)=delete
Interface for objects that might require draining before checkpointing.
Definition drain.hh:240
virtual ~Drainable()
Definition drain.cc:202
DrainState dmDrain()
DrainManager interface to request a drain operation.
Definition drain.cc:208
friend class DrainManager
This class coordinates draining of a System.
Definition drain.hh:257
void dmDrainResume()
DrainManager interface to request a resume operation.
Definition drain.cc:219
DrainState _drainState
Current drain state of the object.
Definition drain.hh:365
DrainManager & _drainManager
Convenience reference to the drain manager.
Definition drain.hh:358
STL vector class.
Definition stl.hh:37
void preCheckpointRestore()
Run state fixups before a checkpoint restore operation.
Definition drain.cc:133
virtual void drainResume()
Resume execution after a successful drain.
Definition drain.hh:298
DrainState state() const
Get the simulators global drain state.
Definition drain.hh:160
void signalDrainDone()
Notify the DrainManager that a Drainable object has finished draining.
Definition drain.cc:147
void signalDrainDone() const
Signal that an object is drained.
Definition drain.hh:310
virtual void notifyFork()
Notify a child process of a fork.
Definition drain.hh:349
void resume()
Resume normal simulation in a Drained system.
Definition drain.cc:94
virtual DrainState drain()=0
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
DrainState drainState() const
Return the current drain state of an object.
Definition drain.hh:329
bool isDrained() const
Check if the system is drained.
Definition drain.hh:153
DrainState
Object drain/handover states.
Definition drain.hh:76
bool tryDrain()
Try to drain the system.
Definition drain.cc:62
@ Draining
Draining buffers pending serialization/handover.
Definition drain.hh:78
@ Running
Running normally.
Definition drain.hh:77
@ Resuming
Transient state while the simulator is resuming.
Definition drain.hh:80
@ Drained
Buffers drained, ready for serialization/handover.
Definition drain.hh:79
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36

Generated on Mon Oct 27 2025 04:13:04 for gem5 by doxygen 1.14.0