drain.cc (11859:76c36516e0ae) drain.cc (11937:e6621fafa62d)
1/*
1/*
2 * Copyright (c) 2012, 2015 ARM Limited
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

--- 85 unchanged lines hidden (view full) ---

96{
97 panic_if(_state == DrainState::Running,
98 "Trying to resume a system that is already running\n");
99
100 warn_if(_state == DrainState::Draining,
101 "Resuming a system that isn't fully drained, this is untested and "
102 "likely to break\n");
103
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

--- 85 unchanged lines hidden (view full) ---

96{
97 panic_if(_state == DrainState::Running,
98 "Trying to resume a system that is already running\n");
99
100 warn_if(_state == DrainState::Draining,
101 "Resuming a system that isn't fully drained, this is untested and "
102 "likely to break\n");
103
104 panic_if(_state == DrainState::Resuming,
105 "Resuming a system that is already trying to resume. This should "
106 "never happen.\n");
107
104 panic_if(_count != 0,
105 "Resume called in the middle of a drain cycle. %u objects "
106 "left to drain.\n", _count);
107
108 panic_if(_count != 0,
109 "Resume called in the middle of a drain cycle. %u objects "
110 "left to drain.\n", _count);
111
108 DPRINTF(Drain, "Resuming %u objects.\n", drainableCount());
112 // At this point in time the DrainManager and all objects will be
113 // in the the Drained state. New objects (i.e., objects created
114 // while resuming) will inherit the Resuming state from the
115 // DrainManager, which means we have to resume objects until all
116 // objects are in the Running state.
117 _state = DrainState::Resuming;
118
119 do {
120 DPRINTF(Drain, "Resuming %u objects.\n", drainableCount());
121 for (auto *obj : _allDrainable) {
122 if (obj->drainState() != DrainState::Running) {
123 assert(obj->drainState() == DrainState::Drained ||
124 obj->drainState() == DrainState::Resuming);
125 obj->dmDrainResume();
126 }
127 }
128 } while (!allInState(DrainState::Running));
129
109 _state = DrainState::Running;
130 _state = DrainState::Running;
110 for (auto *obj : _allDrainable)
111 obj->dmDrainResume();
112}
113
114void
115DrainManager::preCheckpointRestore()
116{
117 panic_if(_state != DrainState::Running,
118 "preCheckpointRestore() called on a system that isn't in the "
119 "Running state.\n");

--- 29 unchanged lines hidden (view full) ---

149DrainManager::unregisterDrainable(Drainable *obj)
150{
151 std::lock_guard<std::mutex> lock(globalLock);
152 auto o = std::find(_allDrainable.begin(), _allDrainable.end(), obj);
153 assert(o != _allDrainable.end());
154 _allDrainable.erase(o);
155}
156
131}
132
133void
134DrainManager::preCheckpointRestore()
135{
136 panic_if(_state != DrainState::Running,
137 "preCheckpointRestore() called on a system that isn't in the "
138 "Running state.\n");

--- 29 unchanged lines hidden (view full) ---

168DrainManager::unregisterDrainable(Drainable *obj)
169{
170 std::lock_guard<std::mutex> lock(globalLock);
171 auto o = std::find(_allDrainable.begin(), _allDrainable.end(), obj);
172 assert(o != _allDrainable.end());
173 _allDrainable.erase(o);
174}
175
176bool
177DrainManager::allInState(DrainState state) const
178{
179 for (const auto *obj : _allDrainable) {
180 if (obj->drainState() != state)
181 return false;
182 }
183
184 return true;
185}
186
157size_t
158DrainManager::drainableCount() const
159{
160 std::lock_guard<std::mutex> lock(globalLock);
161 return _allDrainable.size();
162}
163
164

--- 19 unchanged lines hidden (view full) ---

184 _drainState == DrainState::Drained);
185
186 return _drainState;
187}
188
189void
190Drainable::dmDrainResume()
191{
187size_t
188DrainManager::drainableCount() const
189{
190 std::lock_guard<std::mutex> lock(globalLock);
191 return _allDrainable.size();
192}
193
194

--- 19 unchanged lines hidden (view full) ---

214 _drainState == DrainState::Drained);
215
216 return _drainState;
217}
218
219void
220Drainable::dmDrainResume()
221{
192 panic_if(_drainState != DrainState::Drained,
222 panic_if(_drainState != DrainState::Drained &&
223 _drainState != DrainState::Resuming,
193 "Trying to resume an object that hasn't been drained\n");
194
195 _drainState = DrainState::Running;
196 drainResume();
197}
224 "Trying to resume an object that hasn't been drained\n");
225
226 _drainState = DrainState::Running;
227 drainResume();
228}