gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
thermal_model.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, 2021 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/ThermalModel.hh"
43 #include "params/ThermalReference.hh"
44 #include "params/ThermalResistor.hh"
45 #include "sim/clocked_object.hh"
46 #include "sim/linear_solver.hh"
48 #include "sim/sim_object.hh"
49 
54  : SimObject(p), _temperature(p.temperature), node(NULL)
55 {
56 }
57 
60  double step) const {
61  // Just return an empty equation
62  return LinearEquation(nnodes);
63 }
64 
69  : SimObject(p), _resistance(p.resistance), node1(NULL), node2(NULL)
70 {
71 }
72 
75  double step) const
76 {
77  // i[n] = (Vn2 - Vn1)/R
78  LinearEquation eq(nnodes);
79 
80  if (n != node1 && n != node2)
81  return eq;
82 
83  if (node1->isref)
84  eq[eq.cnt()] += -node1->temp.toKelvin() / _resistance;
85  else
86  eq[node1->id] += -1.0f / _resistance;
87 
88  if (node2->isref)
89  eq[eq.cnt()] += node2->temp.toKelvin() / _resistance;
90  else
91  eq[node2->id] += 1.0f / _resistance;
92 
93  // We've assumed n was node1, reverse if necessary
94  if (n == node2)
95  eq *= -1.0f;
96 
97  return eq;
98 }
99 
104  : SimObject(p), _capacitance(p.capacitance), node1(NULL), node2(NULL)
105 {
106 }
107 
110  double step) const
111 {
112  // i(t) = C * d(Vn2 - Vn1)/dt
113  // i[n] = C/step * (Vn2 - Vn1 - Vn2[n-1] + Vn1[n-1])
114  LinearEquation eq(nnodes);
115 
116  if (n != node1 && n != node2)
117  return eq;
118 
119  eq[eq.cnt()] += _capacitance / step *
120  (node1->temp - node2->temp).toKelvin();
121 
122  if (node1->isref)
123  eq[eq.cnt()] += _capacitance / step * (-node1->temp.toKelvin());
124  else
125  eq[node1->id] += -1.0f * _capacitance / step;
126 
127  if (node2->isref)
128  eq[eq.cnt()] += _capacitance / step * (node2->temp.toKelvin());
129  else
130  eq[node2->id] += 1.0f * _capacitance / step;
131 
132  // We've assumed n was node1, reverse if necessary
133  if (n == node2)
134  eq *= -1.0f;
135 
136  return eq;
137 }
138 
143  : ClockedObject(p), stepEvent([this]{ doStep(); }, name()), _step(p.step)
144 {
145 }
146 
147 void
149 {
150  // Calculate new temperatures!
151  // For each node in the system, create the kirchhoff nodal equation
152  LinearSystem ls(eq_nodes.size());
153  for (unsigned i = 0; i < eq_nodes.size(); i++) {
154  auto n = eq_nodes[i];
155  LinearEquation node_equation (eq_nodes.size());
156  for (auto e : entities) {
157  LinearEquation eq = e->getEquation(n, eq_nodes.size(), _step);
158  node_equation = node_equation + eq;
159  }
160  ls[i] = node_equation;
161  }
162 
163  // Get temperatures for this iteration
164  std::vector <double> temps = ls.solve();
165  for (unsigned i = 0; i < eq_nodes.size(); i++)
166  eq_nodes[i]->temp = Temperature::fromKelvin(temps[i]);
167 
168  // Schedule next computation
170 
171  // Notify everybody
172  for (auto dom : domains)
173  dom->emitUpdate();
174 }
175 
176 void
178 {
179  // Look for nodes connected to voltage references, these
180  // can be just set to the reference value (no nodal equation)
181  for (auto ref : references) {
182  ref->node->temp = ref->_temperature;
183  ref->node->isref = true;
184  }
185  // Setup the initial temperatures
186  for (auto dom : domains)
187  dom->getNode()->temp = dom->initialTemperature();
188 
189  // Create a list of unknown temperature nodes
190  for (auto n : nodes) {
191  bool found = false;
192  for (auto ref : references)
193  if (ref->node == n) {
194  found = true;
195  break;
196  }
197  if (!found)
198  eq_nodes.push_back(n);
199  }
200 
201  // Assign each node an ID
202  for (unsigned i = 0; i < eq_nodes.size(); i++)
203  eq_nodes[i]->id = i;
204 
205  // Schedule first thermal update
207 }
208 
209 void
211 {
212  domains.push_back(d);
213  entities.push_back(d);
214 }
215 
216 void
218 {
219  references.push_back(r);
220  entities.push_back(r);
221 }
222 
223 void
225 {
226  capacitors.push_back(c);
227  entities.push_back(c);
228 }
229 
230 void
232 {
233  resistors.push_back(r);
234  entities.push_back(r);
235 }
236 
239 {
240  // Just pick the highest temperature
242  for (auto & n : eq_nodes)
243  temp = std::max(temp, n->temp);
244  return temp;
245 }
ThermalResistor::Params
ThermalResistorParams Params
Definition: thermal_model.hh:63
ThermalDomain
A ThermalDomain is used to group objects under that operate under the same temperature.
Definition: thermal_domain.hh:58
LinearSystem
Definition: linear_solver.hh:107
ThermalModel::capacitors
std::vector< ThermalCapacitor * > capacitors
Definition: thermal_model.hh:164
ThermalModel::domains
std::vector< ThermalDomain * > domains
Definition: thermal_model.hh:162
ThermalResistor::node2
ThermalNode * node2
Definition: thermal_model.hh:78
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:51
ThermalNode::isref
bool isref
Definition: thermal_node.hh:57
ThermalCapacitor::node1
ThermalNode * node1
Definition: thermal_model.hh:104
ThermalModel::addReference
void addReference(ThermalReference *r)
Definition: thermal_model.cc:217
LinearEquation
This class describes a linear equation with constant coefficients.
Definition: linear_solver.hh:52
ThermalResistor::_resistance
const double _resistance
Definition: thermal_model.hh:76
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:111
ThermalResistor::ThermalResistor
ThermalResistor(const Params &p)
ThermalResistor.
Definition: thermal_model.cc:68
ThermalCapacitor::Params
ThermalCapacitorParams Params
Definition: thermal_model.hh:89
ThermalResistor::getEquation
LinearEquation getEquation(ThermalNode *tn, unsigned n, double step) const override
Definition: thermal_model.cc:74
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
Temperature
The class stores temperatures in Kelvin and provides helper methods to convert to/from Celsius.
Definition: temperature.hh:47
Temperature::toKelvin
constexpr double toKelvin() const
Definition: temperature.hh:65
ArmISA::n
Bitfield< 31 > n
Definition: miscregs_types.hh:450
ThermalModel::resistors
std::vector< ThermalResistor * > resistors
Definition: thermal_model.hh:165
ThermalCapacitor::ThermalCapacitor
ThermalCapacitor(const Params &p)
ThermalCapacitor.
Definition: thermal_model.cc:103
ThermalNode::temp
Temperature temp
Definition: thermal_node.hh:58
EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1016
ClockedObject::Params
ClockedObjectParams Params
Parameters of ClockedObject.
Definition: clocked_object.hh:237
ThermalReference::getEquation
LinearEquation getEquation(ThermalNode *tn, unsigned n, double step) const override
Definition: thermal_model.cc:59
ThermalCapacitor::_capacitance
const double _capacitance
Definition: thermal_model.hh:102
sim_object.hh
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:109
MipsISA::r
r
Definition: pra_constants.hh:95
SimClock::Int::s
Tick s
second
Definition: core.cc:59
ThermalResistor
A ThermalResistor is used to model a thermal resistance between two thermal domains.
Definition: thermal_model.hh:60
ThermalModel::nodes
std::vector< ThermalNode * > nodes
Definition: thermal_model.hh:170
ThermalCapacitor
A ThermalCapacitor is used to model a thermal capacitance between two thermal domains.
Definition: thermal_model.hh:86
thermal_domain.hh
name
const std::string & name()
Definition: trace.cc:48
ThermalResistor::node1
ThermalNode * node1
Definition: thermal_model.hh:78
ArmISA::e
Bitfield< 9 > e
Definition: miscregs_types.hh:61
ThermalModel::eq_nodes
std::vector< ThermalNode * > eq_nodes
Definition: thermal_model.hh:171
ThermalModel::addDomain
void addDomain(ThermalDomain *d)
Definition: thermal_model.cc:210
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:174
ThermalCapacitor::node2
ThermalNode * node2
Definition: thermal_model.hh:104
clocked_object.hh
ThermalModel::doStep
void doStep()
Definition: thermal_model.cc:148
ThermalModel::addCapacitor
void addCapacitor(ThermalCapacitor *c)
Definition: thermal_model.cc:224
ThermalReference::Params
ThermalReferenceParams Params
Definition: thermal_model.hh:114
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:177
ThermalReference::ThermalReference
ThermalReference(const Params &p)
ThermalReference.
Definition: thermal_model.cc:53
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
ThermalModel::ThermalModel
ThermalModel(const Params &p)
ThermalModel.
Definition: thermal_model.cc:142
ThermalModel::addResistor
void addResistor(ThermalResistor *r)
Definition: thermal_model.cc:231
ThermalModel::_step
const double _step
Step in seconds for thermal updates.
Definition: thermal_model.hh:177
ThermalNode::id
int id
Definition: thermal_node.hh:56
ThermalModel::getTemperature
Temperature getTemperature() const
Definition: thermal_model.cc:238
ThermalModel::references
std::vector< ThermalReference * > references
Definition: thermal_model.hh:163
ThermalModel::entities
std::vector< ThermalEntity * > entities
Definition: thermal_model.hh:167
Temperature::fromKelvin
static Temperature fromKelvin(double _value)
Definition: temperature.cc:41
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:141

Generated on Tue Mar 23 2021 19:41:28 for gem5 by doxygen 1.8.17