gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Authors: David Guillen Fandos
38  */
39 
41 
42 #include "base/statistics.hh"
43 #include "params/ThermalCapacitor.hh"
44 #include "params/ThermalReference.hh"
45 #include "params/ThermalResistor.hh"
46 #include "sim/clocked_object.hh"
47 #include "sim/linear_solver.hh"
49 #include "sim/sim_object.hh"
50 
55  : SimObject(p), _temperature(p->temperature), node(NULL)
56 {
57 }
58 
60 ThermalReferenceParams::create()
61 {
62  return new ThermalReference(this);
63 }
64 
65 void
67 {
69 }
70 
71 void
73 {
75 }
76 
79  double step) const {
80  // Just return an empty equation
81  return LinearEquation(nnodes);
82 }
83 
88  : SimObject(p), _resistance(p->resistance), node1(NULL), node2(NULL)
89 {
90 }
91 
93 ThermalResistorParams::create()
94 {
95  return new ThermalResistor(this);
96 }
97 
98 void
100 {
102 }
103 
104 void
106 {
108 }
109 
112  double step) const
113 {
114  // i[n] = (Vn2 - Vn1)/R
115  LinearEquation eq(nnodes);
116 
117  if (n != node1 && n != node2)
118  return eq;
119 
120  if (node1->isref)
121  eq[eq.cnt()] += -node1->temp / _resistance;
122  else
123  eq[node1->id] += -1.0f / _resistance;
124 
125  if (node2->isref)
126  eq[eq.cnt()] += node2->temp / _resistance;
127  else
128  eq[node2->id] += 1.0f / _resistance;
129 
130  // We've assumed n was node1, reverse if necessary
131  if (n == node2)
132  eq *= -1.0f;
133 
134  return eq;
135 }
136 
141  : SimObject(p), _capacitance(p->capacitance), node1(NULL), node2(NULL)
142 {
143 }
144 
146 ThermalCapacitorParams::create()
147 {
148  return new ThermalCapacitor(this);
149 }
150 
151 void
153 {
155 }
156 
157 void
159 {
161 }
162 
165  double step) const
166 {
167  // i(t) = C * d(Vn2 - Vn1)/dt
168  // i[n] = C/step * (Vn2 - Vn1 - Vn2[n-1] + Vn1[n-1])
169  LinearEquation eq(nnodes);
170 
171  if (n != node1 && n != node2)
172  return eq;
173 
174  eq[eq.cnt()] += _capacitance / step * (node1->temp - node2->temp);
175 
176  if (node1->isref)
177  eq[eq.cnt()] += _capacitance / step * (-node1->temp);
178  else
179  eq[node1->id] += -1.0f * _capacitance / step;
180 
181  if (node2->isref)
182  eq[eq.cnt()] += _capacitance / step * (node2->temp);
183  else
184  eq[node2->id] += 1.0f * _capacitance / step;
185 
186  // We've assumed n was node1, reverse if necessary
187  if (n == node2)
188  eq *= -1.0f;
189 
190  return eq;
191 }
192 
197  : ClockedObject(p), stepEvent(this), _step(p->step)
198 {
199 }
200 
201 ThermalModel *
202 ThermalModelParams::create()
203 {
204  return new ThermalModel(this);
205 }
206 
207 void
209 {
211 }
212 
213 void
215 {
217 }
218 
219 void
221 {
222  // Calculate new temperatures!
223  // For each node in the system, create the kirchhoff nodal equation
224  LinearSystem ls(eq_nodes.size());
225  for (unsigned i = 0; i < eq_nodes.size(); i++) {
226  auto n = eq_nodes[i];
227  LinearEquation node_equation (eq_nodes.size());
228  for (auto e : entities) {
229  LinearEquation eq = e->getEquation(n, eq_nodes.size(), _step);
230  node_equation = node_equation + eq;
231  }
232  ls[i] = node_equation;
233  }
234 
235  // Get temperatures for this iteration
236  std::vector <double> temps = ls.solve();
237  for (unsigned i = 0; i < eq_nodes.size(); i++)
238  eq_nodes[i]->temp = temps[i];
239 
240  // Schedule next computation
242 
243  // Notify everybody
244  for (auto dom : domains)
245  dom->emitUpdate();
246 }
247 
248 void
250 {
251  // Look for nodes connected to voltage references, these
252  // can be just set to the reference value (no nodal equation)
253  for (auto ref : references) {
254  ref->node->temp = ref->_temperature;
255  ref->node->isref = true;
256  }
257  // Setup the initial temperatures
258  for (auto dom : domains)
259  dom->getNode()->temp = dom->initialTemperature();
260 
261  // Create a list of unknown temperature nodes
262  for (auto n : nodes) {
263  bool found = false;
264  for (auto ref : references)
265  if (ref->node == n) {
266  found = true;
267  break;
268  }
269  if (!found)
270  eq_nodes.push_back(n);
271  }
272 
273  // Assign each node an ID
274  for (unsigned i = 0; i < eq_nodes.size(); i++)
275  eq_nodes[i]->id = i;
276 
277  // Schedule first thermal update
279 }
280 
282  domains.push_back(d);
283  entities.push_back(d);
284 }
286  references.push_back(r);
287  entities.push_back(r);
288 }
290  capacitors.push_back(c);
291  entities.push_back(c);
292 }
294  resistors.push_back(r);
295  entities.push_back(r);
296 }
297 
298 double ThermalModel::getTemp() const {
299  // Just pick the highest temperature
300  double temp = 0;
301  for (auto & n : eq_nodes)
302  temp = std::max(temp, n->temp);
303  return temp;
304 }
LinearEquation getEquation(ThermalNode *tn, unsigned n, double step) const override
void unserialize(CheckpointIn &cp) override
Unserialize an object.
ThermalReference(const Params *p)
ThermalReference.
Bitfield< 29 > eq
Definition: miscregs.hh:50
void addReference(ThermalReference *r)
ThermalResistorParams Params
void addDomain(ThermalDomain *d)
void serialize(CheckpointOut &cp) const override
Serialize an object.
Bitfield< 7 > i
Definition: miscregs.hh:1378
ThermalCapacitorParams Params
unsigned cnt() const
ClockedObjectParams Params
Parameters of ClockedObject.
ThermalNode * node2
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void serialize(CheckpointOut &cp) const override
Serialize an object.
LinearEquation getEquation(ThermalNode *tn, unsigned n, double step) const override
Declaration of Statistics objects.
ThermalModel(const Params *p)
ThermalModel.
Bitfield< 31 > n
Definition: miscregs.hh:1636
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:145
ThermalNode * node1
Tick curTick()
The current simulated tick.
Definition: core.hh:47
A ThermalCapacitor is used to model a thermal capacitance between two thermal domains.
EventWrapper< ThermalModel,&ThermalModel::doStep > stepEvent
Stepping event to update the model values.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
std::vector< ThermalNode * > eq_nodes
Bitfield< 9 > d
Definition: miscregs.hh:1375
ClockedObject declaration and implementation.
ThermalNode * node2
A ThermalDomain is used to group objects under that operate under the same temperature.
std::vector< ThermalNode * > nodes
std::vector< ThermalDomain * > domains
LinearEquation getEquation(ThermalNode *tn, unsigned n, double step) const override
ThermalNode * node1
void serialize(CheckpointOut &cp) const override
Serialize an object.
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:143
Tick s
second
Definition: core.cc:63
Bitfield< 9 > e
Definition: miscregs.hh:1376
A ThermalNode is used to connect thermal entities, such as resistors, capacitors, references and doma...
Definition: thermal_node.hh:52
void addResistor(ThermalResistor *r)
Bitfield< 29 > c
Definition: miscregs.hh:1365
std::vector< ThermalReference * > references
std::ostream CheckpointOut
Definition: serialize.hh:67
A ThermalReference is a thermal domain with fixed temperature.
std::vector< ThermalResistor * > resistors
This class describes a linear equation with constant coefficients.
void addCapacitor(ThermalCapacitor *c)
ThermalCapacitor(const Params *p)
ThermalCapacitor.
double _step
Step in seconds for thermal updates.
void schedule(Event &event, Tick when)
Definition: eventq.hh:728
double getTemp() const
A ThermalResistor is used to model a thermal resistance between two thermal domains.
void startup() override
startup() is the final initialization call before simulation.
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::vector< ThermalEntity * > entities
Bitfield< 0 > p
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
std::vector< ThermalCapacitor * > capacitors
ThermalReferenceParams Params
A ThermalModel is the element which ties all thermal objects together and provides the thermal solver...
ThermalResistor(const Params *p)
ThermalResistor.

Generated on Fri Jun 9 2017 13:03:51 for gem5 by doxygen 1.8.6