gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
50namespace gem5
51{
52
57 : SimObject(p), _temperature(p.temperature), node(NULL)
58{
59}
60
63 double step) const {
64 // Just return an empty equation
65 return LinearEquation(nnodes);
66}
67
72 : SimObject(p), _resistance(p.resistance), node1(NULL), node2(NULL)
73{
74}
75
78 double step) const
79{
80 // i[n] = (Vn2 - Vn1)/R
81 LinearEquation eq(nnodes);
82
83 if (n != node1 && n != node2)
84 return eq;
85
86 if (node1->isref)
87 eq[eq.cnt()] += -node1->temp.toKelvin() / _resistance;
88 else
89 eq[node1->id] += -1.0f / _resistance;
90
91 if (node2->isref)
92 eq[eq.cnt()] += node2->temp.toKelvin() / _resistance;
93 else
94 eq[node2->id] += 1.0f / _resistance;
95
96 // We've assumed n was node1, reverse if necessary
97 if (n == node2)
98 eq *= -1.0f;
99
100 return eq;
101}
102
107 : SimObject(p), _capacitance(p.capacitance), node1(NULL), node2(NULL)
108{
109}
110
113 double step) const
114{
115 // i(t) = C * d(Vn2 - Vn1)/dt
116 // i[n] = C/step * (Vn2 - Vn1 - Vn2[n-1] + Vn1[n-1])
117 LinearEquation eq(nnodes);
118
119 if (n != node1 && n != node2)
120 return eq;
121
122 eq[eq.cnt()] += _capacitance / step *
123 (node1->temp - node2->temp).toKelvin();
124
125 if (node1->isref)
126 eq[eq.cnt()] += _capacitance / step * (-node1->temp.toKelvin());
127 else
128 eq[node1->id] += -1.0f * _capacitance / step;
129
130 if (node2->isref)
131 eq[eq.cnt()] += _capacitance / step * (node2->temp.toKelvin());
132 else
133 eq[node2->id] += 1.0f * _capacitance / step;
134
135 // We've assumed n was node1, reverse if necessary
136 if (n == node2)
137 eq *= -1.0f;
138
139 return eq;
140}
141
146 : ClockedObject(p), stepEvent([this]{ doStep(); }, name()), _step(p.step)
147{
148}
149
150void
152{
153 // Calculate new temperatures!
154 // For each node in the system, create the kirchhoff nodal equation
155 LinearSystem ls(eq_nodes.size());
156 for (unsigned i = 0; i < eq_nodes.size(); i++) {
157 auto n = eq_nodes[i];
158 LinearEquation node_equation (eq_nodes.size());
159 for (auto e : entities) {
160 LinearEquation eq = e->getEquation(n, eq_nodes.size(), _step);
161 node_equation = node_equation + eq;
162 }
163 ls[i] = node_equation;
164 }
165
166 // Get temperatures for this iteration
167 std::vector <double> temps = ls.solve();
168 for (unsigned i = 0; i < eq_nodes.size(); i++)
169 eq_nodes[i]->temp = Temperature::fromKelvin(temps[i]);
170
171 // Schedule next computation
173
174 // Notify everybody
175 for (auto dom : domains)
176 dom->emitUpdate();
177}
178
179void
181{
182 // Look for nodes connected to voltage references, these
183 // can be just set to the reference value (no nodal equation)
184 for (auto ref : references) {
185 ref->node->temp = ref->_temperature;
186 ref->node->isref = true;
187 }
188 // Setup the initial temperatures
189 for (auto dom : domains)
190 dom->getNode()->temp = dom->initialTemperature();
191
192 // Create a list of unknown temperature nodes
193 for (auto n : nodes) {
194 bool found = false;
195 for (auto ref : references)
196 if (ref->node == n) {
197 found = true;
198 break;
199 }
200 if (!found)
201 eq_nodes.push_back(n);
202 }
203
204 // Assign each node an ID
205 for (unsigned i = 0; i < eq_nodes.size(); i++)
206 eq_nodes[i]->id = i;
207
208 // Schedule first thermal update
210}
211
212void
214{
215 domains.push_back(d);
216 entities.push_back(d);
217}
218
219void
221{
222 references.push_back(r);
223 entities.push_back(r);
224}
225
226void
228{
229 capacitors.push_back(c);
230 entities.push_back(c);
231}
232
233void
235{
236 resistors.push_back(r);
237 entities.push_back(r);
238}
239
242{
243 // Just pick the highest temperature
245 for (auto & n : eq_nodes)
246 temp = std::max(temp, n->temp);
247 return temp;
248}
249
250} // namespace gem5
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
This class describes a linear equation with constant coefficients.
std::vector< double > solve() const
Abstract superclass for simulation objects.
The class stores temperatures in Kelvin and provides helper methods to convert to/from Celsius.
constexpr double toKelvin() const
static Temperature fromKelvin(double _value)
A ThermalCapacitor is used to model a thermal capacitance between two thermal domains.
ThermalCapacitor(const Params &p)
ThermalCapacitor.
LinearEquation getEquation(ThermalNode *tn, unsigned n, double step) const override
ThermalCapacitorParams Params
A ThermalDomain is used to group objects under that operate under the same temperature.
void addResistor(ThermalResistor *r)
std::vector< ThermalDomain * > domains
std::vector< ThermalEntity * > entities
void addReference(ThermalReference *r)
std::vector< ThermalNode * > nodes
std::vector< ThermalResistor * > resistors
void startup() override
startup() is the final initialization call before simulation.
std::vector< ThermalCapacitor * > capacitors
std::vector< ThermalNode * > eq_nodes
ThermalModelParams Params
void addDomain(ThermalDomain *d)
ThermalModel(const Params &p)
ThermalModel.
Temperature getTemperature() const
const double _step
Step in seconds for thermal updates.
void addCapacitor(ThermalCapacitor *c)
EventFunctionWrapper stepEvent
Stepping event to update the model values.
std::vector< ThermalReference * > references
A ThermalNode is used to connect thermal entities, such as resistors, capacitors, references and doma...
A ThermalReference is a thermal domain with fixed temperature.
ThermalReference(const Params &p)
ThermalReference.
ThermalReferenceParams Params
LinearEquation getEquation(ThermalNode *tn, unsigned n, double step) const override
A ThermalResistor is used to model a thermal resistance between two thermal domains.
ThermalResistor(const Params &p)
ThermalResistor.
LinearEquation getEquation(ThermalNode *tn, unsigned n, double step) const override
ThermalResistorParams Params
ClockedObject declaration and implementation.
void schedule(Event &event, Tick when)
Definition eventq.hh:1012
Bitfield< 31 > n
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 9 > e
Definition misc_types.hh:65
Bitfield< 29 > c
Definition misc_types.hh:53
Bitfield< 9 > d
Definition misc_types.hh:64
Bitfield< 0 > p
Bitfield< 29 > eq
Definition misc.hh:58
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
Declaration of Statistics objects.
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0