gem5  v20.1.0.0
thermal_model.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 
39 
40 #include "base/statistics.hh"
41 #include "params/ThermalCapacitor.hh"
42 #include "params/ThermalReference.hh"
43 #include "params/ThermalResistor.hh"
44 #include "sim/clocked_object.hh"
45 #include "sim/linear_solver.hh"
47 #include "sim/sim_object.hh"
48 
53  : SimObject(p), _temperature(p->temperature), node(NULL)
54 {
55 }
56 
58 ThermalReferenceParams::create()
59 {
60  return new ThermalReference(this);
61 }
62 
63 void
65 {
67 }
68 
69 void
71 {
73 }
74 
77  double step) const {
78  // Just return an empty equation
79  return LinearEquation(nnodes);
80 }
81 
86  : SimObject(p), _resistance(p->resistance), node1(NULL), node2(NULL)
87 {
88 }
89 
91 ThermalResistorParams::create()
92 {
93  return new ThermalResistor(this);
94 }
95 
96 void
98 {
100 }
101 
102 void
104 {
106 }
107 
110  double step) const
111 {
112  // i[n] = (Vn2 - Vn1)/R
113  LinearEquation eq(nnodes);
114 
115  if (n != node1 && n != node2)
116  return eq;
117 
118  if (node1->isref)
119  eq[eq.cnt()] += -node1->temp / _resistance;
120  else
121  eq[node1->id] += -1.0f / _resistance;
122 
123  if (node2->isref)
124  eq[eq.cnt()] += node2->temp / _resistance;
125  else
126  eq[node2->id] += 1.0f / _resistance;
127 
128  // We've assumed n was node1, reverse if necessary
129  if (n == node2)
130  eq *= -1.0f;
131 
132  return eq;
133 }
134 
139  : SimObject(p), _capacitance(p->capacitance), node1(NULL), node2(NULL)
140 {
141 }
142 
144 ThermalCapacitorParams::create()
145 {
146  return new ThermalCapacitor(this);
147 }
148 
149 void
151 {
153 }
154 
155 void
157 {
159 }
160 
163  double step) const
164 {
165  // i(t) = C * d(Vn2 - Vn1)/dt
166  // i[n] = C/step * (Vn2 - Vn1 - Vn2[n-1] + Vn1[n-1])
167  LinearEquation eq(nnodes);
168 
169  if (n != node1 && n != node2)
170  return eq;
171 
172  eq[eq.cnt()] += _capacitance / step * (node1->temp - node2->temp);
173 
174  if (node1->isref)
175  eq[eq.cnt()] += _capacitance / step * (-node1->temp);
176  else
177  eq[node1->id] += -1.0f * _capacitance / step;
178 
179  if (node2->isref)
180  eq[eq.cnt()] += _capacitance / step * (node2->temp);
181  else
182  eq[node2->id] += 1.0f * _capacitance / step;
183 
184  // We've assumed n was node1, reverse if necessary
185  if (n == node2)
186  eq *= -1.0f;
187 
188  return eq;
189 }
190 
195  : ClockedObject(p), stepEvent([this]{ doStep(); }, name()), _step(p->step)
196 {
197 }
198 
199 ThermalModel *
200 ThermalModelParams::create()
201 {
202  return new ThermalModel(this);
203 }
204 
205 void
207 {
209 }
210 
211 void
213 {
215 }
216 
217 void
219 {
220  // Calculate new temperatures!
221  // For each node in the system, create the kirchhoff nodal equation
222  LinearSystem ls(eq_nodes.size());
223  for (unsigned i = 0; i < eq_nodes.size(); i++) {
224  auto n = eq_nodes[i];
225  LinearEquation node_equation (eq_nodes.size());
226  for (auto e : entities) {
227  LinearEquation eq = e->getEquation(n, eq_nodes.size(), _step);
228  node_equation = node_equation + eq;
229  }
230  ls[i] = node_equation;
231  }
232 
233  // Get temperatures for this iteration
234  std::vector <double> temps = ls.solve();
235  for (unsigned i = 0; i < eq_nodes.size(); i++)
236  eq_nodes[i]->temp = temps[i];
237 
238  // Schedule next computation
240 
241  // Notify everybody
242  for (auto dom : domains)
243  dom->emitUpdate();
244 }
245 
246 void
248 {
249  // Look for nodes connected to voltage references, these
250  // can be just set to the reference value (no nodal equation)
251  for (auto ref : references) {
252  ref->node->temp = ref->_temperature;
253  ref->node->isref = true;
254  }
255  // Setup the initial temperatures
256  for (auto dom : domains)
257  dom->getNode()->temp = dom->initialTemperature();
258 
259  // Create a list of unknown temperature nodes
260  for (auto n : nodes) {
261  bool found = false;
262  for (auto ref : references)
263  if (ref->node == n) {
264  found = true;
265  break;
266  }
267  if (!found)
268  eq_nodes.push_back(n);
269  }
270 
271  // Assign each node an ID
272  for (unsigned i = 0; i < eq_nodes.size(); i++)
273  eq_nodes[i]->id = i;
274 
275  // Schedule first thermal update
277 }
278 
280  domains.push_back(d);
281  entities.push_back(d);
282 }
284  references.push_back(r);
285  entities.push_back(r);
286 }
288  capacitors.push_back(c);
289  entities.push_back(c);
290 }
292  resistors.push_back(r);
293  entities.push_back(r);
294 }
295 
296 double ThermalModel::getTemp() const {
297  // Just pick the highest temperature
298  double temp = 0;
299  for (auto & n : eq_nodes)
300  temp = std::max(temp, n->temp);
301  return temp;
302 }
ThermalResistor::Params
ThermalResistorParams Params
Definition: thermal_model.hh:62
ThermalDomain
A ThermalDomain is used to group objects under that operate under the same temperature.
Definition: thermal_domain.hh:57
ThermalModel
Definition: thermal_model.hh:147
LinearSystem
Definition: linear_solver.hh:107
ThermalCapacitor::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: thermal_model.cc:150
ThermalModel::capacitors
std::vector< ThermalCapacitor * > capacitors
Definition: thermal_model.hh:172
ThermalModel::domains
std::vector< ThermalDomain * > domains
Definition: thermal_model.hh:170
ThermalResistor::node2
ThermalNode * node2
Definition: thermal_model.hh:80
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
ThermalCapacitor::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: thermal_model.cc:156
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
ThermalNode
A ThermalNode is used to connect thermal entities, such as resistors, capacitors, references and doma...
Definition: thermal_node.hh:50
ThermalModel::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: thermal_model.cc:206
ThermalNode::isref
bool isref
Definition: thermal_node.hh:56
ThermalReference::_temperature
double _temperature
Definition: thermal_model.hh:133
ThermalCapacitor::node1
ThermalNode * node1
Definition: thermal_model.hh:109
ThermalNode::temp
double temp
Definition: thermal_node.hh:57
ThermalModel::addReference
void addReference(ThermalReference *r)
Definition: thermal_model.cc:283
ThermalResistor::_resistance
double _resistance
Definition: thermal_model.hh:78
LinearEquation
This class describes a linear equation with constant coefficients.
Definition: linear_solver.hh:52
LinearSystem::solve
std::vector< double > solve() const
Definition: linear_solver.cc:41
std::vector< double >
thermal_model.hh
ThermalReference
A ThermalReference is a thermal domain with fixed temperature.
Definition: thermal_model.hh:116
ThermalCapacitor::Params
ThermalCapacitorParams Params
Definition: thermal_model.hh:91
ThermalResistor::getEquation
LinearEquation getEquation(ThermalNode *tn, unsigned n, double step) const override
Definition: thermal_model.cc:109
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
ThermalResistor::ThermalResistor
ThermalResistor(const Params *p)
ThermalResistor.
Definition: thermal_model.cc:85
ArmISA::n
Bitfield< 31 > n
Definition: miscregs_types.hh:450
ThermalModel::resistors
std::vector< ThermalResistor * > resistors
Definition: thermal_model.hh:173
cp
Definition: cprintf.cc:40
EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1005
ThermalResistor::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: thermal_model.cc:97
ThermalReference::getEquation
LinearEquation getEquation(ThermalNode *tn, unsigned n, double step) const override
Definition: thermal_model.cc:76
sim_object.hh
ThermalReference::ThermalReference
ThermalReference(const Params *p)
ThermalReference.
Definition: thermal_model.cc:52
ArmISA::d
Bitfield< 9 > d
Definition: miscregs_types.hh:60
statistics.hh
ThermalCapacitor::getEquation
LinearEquation getEquation(ThermalNode *tn, unsigned n, double step) const override
Definition: thermal_model.cc:162
ThermalModel::_step
double _step
Step in seconds for thermal updates.
Definition: thermal_model.hh:185
MipsISA::r
r
Definition: pra_constants.hh:95
SimClock::Int::s
Tick s
second
Definition: core.cc:62
ThermalResistor
A ThermalResistor is used to model a thermal resistance between two thermal domains.
Definition: thermal_model.hh:59
ThermalModel::getTemp
double getTemp() const
Definition: thermal_model.cc:296
ThermalReference::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: thermal_model.cc:64
ThermalModel::nodes
std::vector< ThermalNode * > nodes
Definition: thermal_model.hh:178
ThermalCapacitor
A ThermalCapacitor is used to model a thermal capacitance between two thermal domains.
Definition: thermal_model.hh:88
thermal_domain.hh
name
const std::string & name()
Definition: trace.cc:50
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
ThermalResistor::node1
ThermalNode * node1
Definition: thermal_model.hh:80
ArmISA::e
Bitfield< 9 > e
Definition: miscregs_types.hh:61
ThermalModel::eq_nodes
std::vector< ThermalNode * > eq_nodes
Definition: thermal_model.hh:179
ThermalModel::addDomain
void addDomain(ThermalDomain *d)
Definition: thermal_model.cc:279
linear_solver.hh
PowerISA::eq
Bitfield< 29 > eq
Definition: miscregs.hh:48
ThermalModel::stepEvent
EventFunctionWrapper stepEvent
Stepping event to update the model values.
Definition: thermal_model.hh:182
ThermalCapacitor::node2
ThermalNode * node2
Definition: thermal_model.hh:109
ClockedObject::Params
ClockedObjectParams Params
Parameters of ClockedObject.
Definition: clocked_object.hh:237
clocked_object.hh
ThermalModel::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: thermal_model.cc:212
ThermalModel::doStep
void doStep()
Definition: thermal_model.cc:218
ThermalModel::addCapacitor
void addCapacitor(ThermalCapacitor *c)
Definition: thermal_model.cc:287
ThermalReference::Params
ThermalReferenceParams Params
Definition: thermal_model.hh:119
ThermalCapacitor::_capacitance
double _capacitance
Definition: thermal_model.hh:107
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
ThermalModel::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: thermal_model.cc:247
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
ThermalResistor::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: thermal_model.cc:103
CheckpointIn
Definition: serialize.hh:67
ThermalModel::addResistor
void addResistor(ThermalResistor *r)
Definition: thermal_model.cc:291
ThermalCapacitor::ThermalCapacitor
ThermalCapacitor(const Params *p)
ThermalCapacitor.
Definition: thermal_model.cc:138
ThermalReference::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: thermal_model.cc:70
ThermalNode::id
int id
Definition: thermal_node.hh:55
ThermalModel::references
std::vector< ThermalReference * > references
Definition: thermal_model.hh:171
ThermalModel::entities
std::vector< ThermalEntity * > entities
Definition: thermal_model.hh:175
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92
ThermalModel::ThermalModel
ThermalModel(const Params *p)
ThermalModel.
Definition: thermal_model.cc:194

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17