summaryrefslogtreecommitdiff
path: root/src/sim/power
diff options
context:
space:
mode:
authorDavid Guillen Fandos <david.guillen@arm.com>2015-05-12 10:26:47 +0100
committerDavid Guillen Fandos <david.guillen@arm.com>2015-05-12 10:26:47 +0100
commit75c82f1fe3e654ca7d472d8f824424ff450c01d1 (patch)
treeb07198404e3647302cc66e800fb7bf1fcdad01fa /src/sim/power
parent85dadcd38133252652686b92c52cc6a38c90331c (diff)
downloadgem5-75c82f1fe3e654ca7d472d8f824424ff450c01d1.tar.xz
sim: Adding thermal model support
This patch adds basic thermal support to gem5. It models energy dissipation through a circuital equivalent, which allows us to use RC networks. This lays down the basic infrastructure to do so, but it does not "work" due to the lack of power models. For now some hardcoded number is used as a PoC. The solver is embedded in the patch.
Diffstat (limited to 'src/sim/power')
-rw-r--r--src/sim/power/SConscript39
-rw-r--r--src/sim/power/ThermalDomain.py53
-rw-r--r--src/sim/power/ThermalModel.py168
-rw-r--r--src/sim/power/thermal_domain.cc114
-rw-r--r--src/sim/power/thermal_domain.hh115
-rw-r--r--src/sim/power/thermal_entity.hh61
-rw-r--r--src/sim/power/thermal_model.cc319
-rw-r--r--src/sim/power/thermal_model.hh206
8 files changed, 1075 insertions, 0 deletions
diff --git a/src/sim/power/SConscript b/src/sim/power/SConscript
new file mode 100644
index 000000000..8ec65519c
--- /dev/null
+++ b/src/sim/power/SConscript
@@ -0,0 +1,39 @@
+# -*- mode:python -*-
+
+# Copyright (c) 2015 ARM Limited
+# All rights reserved
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: David Guillen Fandos
+
+Import('*')
+
+SimObject('ThermalDomain.py')
+SimObject('ThermalModel.py')
+
+Source('thermal_domain.cc')
+Source('thermal_model.cc')
+
+DebugFlag('ThermalDomain')
diff --git a/src/sim/power/ThermalDomain.py b/src/sim/power/ThermalDomain.py
new file mode 100644
index 000000000..215d0863f
--- /dev/null
+++ b/src/sim/power/ThermalDomain.py
@@ -0,0 +1,53 @@
+# Copyright (c) 2015 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: David Guillen Fandos
+
+from m5.SimObject import SimObject
+from m5.params import *
+
+# Represents a group of simobj which produce heat
+class ThermalDomain(SimObject):
+ type = 'ThermalDomain'
+ cxx_header = "sim/power/thermal_domain.hh"
+
+ @classmethod
+ def export_methods(cls, code):
+ code('''
+ void setNode(ThermalNode * node);
+''')
+
+ # Static temperature which may change over time
+ initial_temperature = Param.Float(25.0, "Initial temperature")
diff --git a/src/sim/power/ThermalModel.py b/src/sim/power/ThermalModel.py
new file mode 100644
index 000000000..4a2f5d931
--- /dev/null
+++ b/src/sim/power/ThermalModel.py
@@ -0,0 +1,168 @@
+# Copyright (c) 2015 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: David Guillen Fandos
+
+from m5.SimObject import SimObject
+from ClockedObject import ClockedObject
+
+from m5.params import *
+from m5.objects import ThermalDomain
+
+
+# Represents a thermal node
+class ThermalNode(SimObject):
+ type = 'ThermalNode'
+ cxx_header = "sim/power/thermal_model.hh"
+
+# Represents a thermal resistor
+class ThermalResistor(SimObject):
+ type = 'ThermalResistor'
+ cxx_header = "sim/power/thermal_model.hh"
+
+ @classmethod
+ def export_methods(cls, code):
+ code('''
+ void setNodes(ThermalNode * node1, ThermalNode * node2);
+''')
+
+ resistance = Param.Float(1.0, "Thermal resistance, expressed in Kelvin per Watt")
+
+# Represents a thermal capacitor
+class ThermalCapacitor(SimObject):
+ type = 'ThermalCapacitor'
+ cxx_header = "sim/power/thermal_model.hh"
+
+ @classmethod
+ def export_methods(cls, code):
+ code('''
+ void setNodes(ThermalNode * node1, ThermalNode * node2);
+''')
+
+ capacitance = Param.Float(1.0, "Thermal capacitance, expressed in Joules per Kelvin")
+
+# Represents a fixed temperature node (ie. air)
+class ThermalReference(SimObject, object):
+ type = 'ThermalReference'
+ cxx_header = "sim/power/thermal_model.hh"
+
+ @classmethod
+ def export_methods(cls, code):
+ code('''
+ void setNode(ThermalNode * node);
+''')
+
+ # Static temperature which may change over time
+ temperature = Param.Float(25.0, "Operational temperature in Celsius")
+
+
+# Represents a thermal capacitor
+class ThermalModel(ClockedObject):
+ type = 'ThermalModel'
+ cxx_header = "sim/power/thermal_model.hh"
+
+ @classmethod
+ def export_methods(cls, code):
+ code('''
+ void addCapacitor(ThermalCapacitor *obj);
+ void addResistor(ThermalResistor *obj);
+ void addReference(ThermalReference *obj);
+ void addDomain(ThermalDomain *obj);
+ void addNode(ThermalNode *obj);
+ void doStep();
+''')
+
+ step = Param.Float(0.01, "Simulation step (in seconds) for thermal simulation")
+
+ def populate(self):
+ if not hasattr(self,"_capacitors"): self._capacitors = []
+ if not hasattr(self,"_resistors"): self._resistors = []
+ if not hasattr(self,"_domains"): self._domains = []
+ if not hasattr(self,"_references"): self._references = []
+ if not hasattr(self,"_nodes"): self._nodes = []
+
+ def init(self):
+ self.populate()
+
+ for ref, node in self._references:
+ ref.getCCObject().setNode(node.getCCObject())
+ self.getCCObject().addReference(ref.getCCObject())
+
+ for dom, node in self._domains:
+ dom.getCCObject().setNode(node.getCCObject())
+ self.getCCObject().addDomain(dom.getCCObject())
+
+ for cap, node1, node2 in self._capacitors:
+ cap.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject())
+ self.getCCObject().addCapacitor(cap.getCCObject())
+
+ for res, node1, node2 in self._resistors:
+ res.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject())
+ self.getCCObject().addResistor(res.getCCObject())
+
+ for node in self._nodes:
+ self.getCCObject().addNode(node.getCCObject())
+
+ def addCapacitor(self, cap, node1, node2):
+ self.populate()
+ self._capacitors.append( (cap, node1, node2) )
+ self._parent.thermal_components.append(cap)
+ self.addNodes(node1,node2)
+
+ def addResistor(self, res, node1, node2):
+ self.populate()
+ self._resistors.append( (res, node1, node2) )
+ self._parent.thermal_components.append(res)
+ self.addNodes(node1,node2)
+
+ def addReference(self, ref, node):
+ self.populate()
+ self._references.append( (ref, node) )
+ self._parent.thermal_components.append(ref)
+ self.addNodes(node)
+
+ def addDomain(self, dom, node):
+ self.populate()
+ self._domains.append( (dom, node) )
+ self.addNodes(node)
+
+ def addNodes(self, *nodes):
+ for node in nodes:
+ if node not in self._nodes:
+ self._nodes.append(node)
+ self._parent.thermal_components.append(node)
+
+ def doStep(self):
+ self.getCCObject().doStep()
diff --git a/src/sim/power/thermal_domain.cc b/src/sim/power/thermal_domain.cc
new file mode 100644
index 000000000..4b840670d
--- /dev/null
+++ b/src/sim/power/thermal_domain.cc
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2015 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: David Guillen Fandos
+ */
+
+#include "sim/power/thermal_domain.hh"
+
+#include <algorithm>
+
+#include "base/statistics.hh"
+#include "debug/ThermalDomain.hh"
+#include "params/ThermalDomain.hh"
+#include "sim/power/thermal_model.hh"
+#include "sim/sim_object.hh"
+
+ThermalDomain::ThermalDomain(const Params *p)
+ : SimObject(p), _initTemperature(p->initial_temperature),
+ node(NULL), subsystem(NULL)
+{
+}
+
+double
+ThermalDomain::currentTemperature() const
+{
+ return node->temp;
+}
+
+void
+ThermalDomain::setSubSystem(SubSystem * ss)
+{
+ assert(!this->subsystem);
+ this->subsystem = ss;
+
+ ppThermalUpdate = new ProbePointArg<double>(subsystem->getProbeManager(),
+ "thermalUpdate");
+}
+
+void
+ThermalDomain::regStats()
+{
+ currentTemp
+ .method(this, &ThermalDomain::currentTemperature)
+ .name(params()->name + ".temp")
+ .desc("Temperature in centigrate degrees")
+ ;
+}
+
+void
+ThermalDomain::emitUpdate()
+{
+ ppThermalUpdate->notify(node->temp);
+}
+
+ThermalDomain *
+ThermalDomainParams::create()
+{
+ return new ThermalDomain(this);
+}
+
+void
+ThermalDomain::serialize(CheckpointOut &cp) const
+{
+ SERIALIZE_SCALAR(_initTemperature);
+}
+
+void
+ThermalDomain::unserialize(CheckpointIn &cp)
+{
+ UNSERIALIZE_SCALAR(_initTemperature);
+}
+
+
+LinearEquation
+ThermalDomain::getEquation(ThermalNode * tn, unsigned n, double step) const
+{
+ LinearEquation eq(n);
+ if (tn == node)
+ eq[eq.cnt()] = 1.75f; // Fake 1.75 Watts for now, to be changed to PM
+ return eq;
+}
diff --git a/src/sim/power/thermal_domain.hh b/src/sim/power/thermal_domain.hh
new file mode 100644
index 000000000..dc0e30cfa
--- /dev/null
+++ b/src/sim/power/thermal_domain.hh
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2015 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: David Guillen Fandos
+ */
+
+#ifndef __SIM_THERMAL_DOMAIN_HH__
+#define __SIM_THERMAL_DOMAIN_HH__
+
+#include <vector>
+
+#include "base/statistics.hh"
+#include "params/ThermalDomain.hh"
+#include "sim/power/thermal_entity.hh"
+#include "sim/probe/probe.hh"
+#include "sim/sim_object.hh"
+#include "sim/sub_system.hh"
+
+class ThermalNode;
+
+/**
+ * A ThermalDomain is used to group objects under that operate under
+ * the same temperature. Theses domains can be tied together using thermal
+ * models (such as RC) to model temperature across components.
+ */
+class ThermalDomain : public SimObject, public ThermalEntity
+{
+ public:
+
+ typedef ThermalDomainParams Params;
+ ThermalDomain(const Params *p);
+
+ /**
+ * Get the startup temperature.
+ *
+ * @return Initial temperature of the domain
+ */
+ double initialTemperature() const { return _initTemperature; }
+
+ /**
+ * Get the current temperature.
+ *
+ * @return Initial temperature of the domain
+ */
+ double currentTemperature() const;
+
+ /** Set/Get circuit node associated with this domain */
+ void setNode(ThermalNode * n) { node = n; }
+ ThermalNode * getNode() const { return node; }
+
+ /** Get nodal equation imposed by this node */
+ LinearEquation getEquation(ThermalNode * tn, unsigned n,
+ double step) const;
+
+ /**
+ * Emit a temperature update through probe points interface
+ */
+ void emitUpdate();
+
+ /**
+ * Set the SubSystem reference we belong to
+ */
+ void setSubSystem(SubSystem * ss);
+
+ void regStats();
+ void serialize(CheckpointOut &cp) const override;
+ void unserialize(CheckpointIn &cp) override;
+
+ private:
+ double _initTemperature;
+ ThermalNode * node;
+ SubSystem * subsystem;
+
+ /** Stat for reporting voltage of the domain */
+ Stats::Value currentTemp;
+
+ /** Probe to signal for temperature changes in this domain */
+ ProbePointArg<double> *ppThermalUpdate;
+
+};
+
+#endif
diff --git a/src/sim/power/thermal_entity.hh b/src/sim/power/thermal_entity.hh
new file mode 100644
index 000000000..77846b67a
--- /dev/null
+++ b/src/sim/power/thermal_entity.hh
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: David Guillen Fandos
+ */
+
+#ifndef __SIM_THERMAL_ENTITY_HH__
+#define __SIM_THERMAL_ENTITY_HH__
+
+#include "sim/linear_solver.hh"
+
+class ThermalNode;
+
+/**
+ * An abstract class that represents any thermal entity which is used
+ * in the circuital thermal equivalent model. It is necessary for
+ * ThermalModel to be able to solve the circuit.
+ */
+class ThermalEntity
+{
+ public:
+ // Get the equation given a node and a step in seconds (assuming N nodes)
+ virtual LinearEquation getEquation(ThermalNode *tn, unsigned n,
+ double step) const = 0;
+};
+
+
+#endif
diff --git a/src/sim/power/thermal_model.cc b/src/sim/power/thermal_model.cc
new file mode 100644
index 000000000..13242f666
--- /dev/null
+++ b/src/sim/power/thermal_model.cc
@@ -0,0 +1,319 @@
+/*
+ * Copyright (c) 2015 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: David Guillen Fandos
+ */
+
+#include "sim/power/thermal_model.hh"
+
+#include "base/statistics.hh"
+#include "params/ThermalCapacitor.hh"
+#include "params/ThermalNode.hh"
+#include "params/ThermalReference.hh"
+#include "params/ThermalResistor.hh"
+#include "sim/clocked_object.hh"
+#include "sim/linear_solver.hh"
+#include "sim/power/thermal_domain.hh"
+#include "sim/sim_object.hh"
+
+/**
+ * ThermalNode
+ */
+ThermalNode::ThermalNode(const Params *p)
+ : SimObject(p), id(-1), isref(false), temp(0.0f)
+{
+}
+
+ThermalNode *
+ThermalNodeParams::create()
+{
+ return new ThermalNode(this);
+}
+
+/**
+ * ThermalReference
+ */
+ThermalReference::ThermalReference(const Params *p)
+ : SimObject(p), _temperature(p->temperature), node(NULL)
+{
+}
+
+ThermalReference *
+ThermalReferenceParams::create()
+{
+ return new ThermalReference(this);
+}
+
+void
+ThermalReference::serialize(CheckpointOut &cp) const
+{
+ SERIALIZE_SCALAR(_temperature);
+}
+
+void
+ThermalReference::unserialize(CheckpointIn &cp)
+{
+ UNSERIALIZE_SCALAR(_temperature);
+}
+
+LinearEquation
+ThermalReference::getEquation(ThermalNode * n, unsigned nnodes,
+ double step) const {
+ // Just return an empty equation
+ return LinearEquation(nnodes);
+}
+
+/**
+ * ThermalResistor
+ */
+ThermalResistor::ThermalResistor(const Params *p)
+ : SimObject(p), _resistance(p->resistance), node1(NULL), node2(NULL)
+{
+}
+
+ThermalResistor *
+ThermalResistorParams::create()
+{
+ return new ThermalResistor(this);
+}
+
+void
+ThermalResistor::serialize(CheckpointOut &cp) const
+{
+ SERIALIZE_SCALAR(_resistance);
+}
+
+void
+ThermalResistor::unserialize(CheckpointIn &cp)
+{
+ UNSERIALIZE_SCALAR(_resistance);
+}
+
+LinearEquation
+ThermalResistor::getEquation(ThermalNode * n, unsigned nnodes,
+ double step) const
+{
+ // i[n] = (Vn2 - Vn1)/R
+ LinearEquation eq(nnodes);
+
+ if (n != node1 && n != node2)
+ return eq;
+
+ if (node1->isref)
+ eq[eq.cnt()] += -node1->temp / _resistance;
+ else
+ eq[node1->id] += -1.0f / _resistance;
+
+ if (node2->isref)
+ eq[eq.cnt()] += node2->temp / _resistance;
+ else
+ eq[node2->id] += 1.0f / _resistance;
+
+ // We've assumed n was node1, reverse if necessary
+ if (n == node2)
+ eq *= -1.0f;
+
+ return eq;
+}
+
+/**
+ * ThermalCapacitor
+ */
+ThermalCapacitor::ThermalCapacitor(const Params *p)
+ : SimObject(p), _capacitance(p->capacitance), node1(NULL), node2(NULL)
+{
+}
+
+ThermalCapacitor *
+ThermalCapacitorParams::create()
+{
+ return new ThermalCapacitor(this);
+}
+
+void
+ThermalCapacitor::serialize(CheckpointOut &cp) const
+{
+ SERIALIZE_SCALAR(_capacitance);
+}
+
+void
+ThermalCapacitor::unserialize(CheckpointIn &cp)
+{
+ UNSERIALIZE_SCALAR(_capacitance);
+}
+
+LinearEquation
+ThermalCapacitor::getEquation(ThermalNode * n, unsigned nnodes,
+ double step) const
+{
+ // i(t) = C * d(Vn2 - Vn1)/dt
+ // i[n] = C/step * (Vn2 - Vn1 - Vn2[n-1] + Vn1[n-1])
+ LinearEquation eq(nnodes);
+
+ if (n != node1 && n != node2)
+ return eq;
+
+ eq[eq.cnt()] += _capacitance / step * (node1->temp - node2->temp);
+
+ if (node1->isref)
+ eq[eq.cnt()] += _capacitance / step * (-node1->temp);
+ else
+ eq[node1->id] += -1.0f * _capacitance / step;
+
+ if (node2->isref)
+ eq[eq.cnt()] += _capacitance / step * (node2->temp);
+ else
+ eq[node2->id] += 1.0f * _capacitance / step;
+
+ // We've assumed n was node1, reverse if necessary
+ if (n == node2)
+ eq *= -1.0f;
+
+ return eq;
+}
+
+/**
+ * ThermalModel
+ */
+ThermalModel::ThermalModel(const Params *p)
+ : ClockedObject(p), stepEvent(this), _step(p->step)
+{
+}
+
+ThermalModel *
+ThermalModelParams::create()
+{
+ return new ThermalModel(this);
+}
+
+void
+ThermalModel::serialize(CheckpointOut &cp) const
+{
+ SERIALIZE_SCALAR(_step);
+}
+
+void
+ThermalModel::unserialize(CheckpointIn &cp)
+{
+ UNSERIALIZE_SCALAR(_step);
+}
+
+void
+ThermalModel::doStep()
+{
+ // Calculate new temperatures!
+ // For each node in the system, create the kirchhoff nodal equation
+ LinearSystem ls(eq_nodes.size());
+ for (unsigned i = 0; i < eq_nodes.size(); i++) {
+ auto n = eq_nodes[i];
+ LinearEquation node_equation (eq_nodes.size());
+ for (auto e : entities) {
+ LinearEquation eq = e->getEquation(n, eq_nodes.size(), _step);
+ node_equation = node_equation + eq;
+ }
+ ls[i] = node_equation;
+ }
+
+ // Get temperatures for this iteration
+ std::vector <double> temps = ls.solve();
+ for (unsigned i = 0; i < eq_nodes.size(); i++)
+ eq_nodes[i]->temp = temps[i];
+
+ // Schedule next computation
+ schedule(stepEvent, curTick() + SimClock::Int::s * _step);
+
+ // Notify everybody
+ for (auto dom : domains)
+ dom->emitUpdate();
+}
+
+void
+ThermalModel::startup()
+{
+ // Look for nodes connected to voltage references, these
+ // can be just set to the reference value (no nodal equation)
+ for (auto ref : references) {
+ ref->node->temp = ref->_temperature;
+ ref->node->isref = true;
+ }
+ // Setup the initial temperatures
+ for (auto dom : domains)
+ dom->getNode()->temp = dom->initialTemperature();
+
+ // Create a list of unknown temperature nodes
+ for (auto n : nodes) {
+ bool found = false;
+ for (auto ref : references)
+ if (ref->node == n) {
+ found = true;
+ break;
+ }
+ if (!found)
+ eq_nodes.push_back(n);
+ }
+
+ // Assign each node an ID
+ for (unsigned i = 0; i < eq_nodes.size(); i++)
+ eq_nodes[i]->id = i;
+
+ // Schedule first thermal update
+ schedule(stepEvent, curTick() + SimClock::Int::s * _step);
+}
+
+void ThermalModel::addDomain(ThermalDomain * d) {
+ domains.push_back(d);
+ entities.push_back(d);
+}
+void ThermalModel::addReference(ThermalReference * r) {
+ references.push_back(r);
+ entities.push_back(r);
+}
+void ThermalModel::addCapacitor(ThermalCapacitor * c) {
+ capacitors.push_back(c);
+ entities.push_back(c);
+}
+void ThermalModel::addResistor(ThermalResistor * r) {
+ resistors.push_back(r);
+ entities.push_back(r);
+}
+
+double ThermalModel::getTemp() const {
+ // Just pick the highest temperature
+ double temp = 0;
+ for (auto & n : eq_nodes)
+ temp = std::max(temp, n->temp);
+ return temp;
+}
diff --git a/src/sim/power/thermal_model.hh b/src/sim/power/thermal_model.hh
new file mode 100644
index 000000000..3cf44c55b
--- /dev/null
+++ b/src/sim/power/thermal_model.hh
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2015 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: David Guillen Fandos
+ */
+
+#ifndef __SIM_THERMAL_MODEL_HH__
+#define __SIM_THERMAL_MODEL_HH__
+
+#include <vector>
+
+#include "base/statistics.hh"
+#include "params/ThermalCapacitor.hh"
+#include "params/ThermalModel.hh"
+#include "params/ThermalReference.hh"
+#include "params/ThermalResistor.hh"
+#include "sim/clocked_object.hh"
+#include "sim/power/thermal_entity.hh"
+#include "sim/sim_object.hh"
+
+class ThermalDomain;
+
+
+/**
+ * A ThermalNode is used to connect thermal entities, such as
+ * resistors, capacitors, references and domains. It is the circuital
+ * equivalent to a voltage node.
+ */
+class ThermalNode : public SimObject
+{
+ public:
+ typedef SimObjectParams Params;
+ ThermalNode(const Params *p);
+
+ int id;
+ bool isref;
+ double temp;
+};
+
+/**
+ * A ThermalResistor is used to model a thermal resistance between two
+ * thermal domains. This domains can be either a reference (fixed temp.) or
+ * a heat producer (power source).
+ */
+class ThermalResistor : public SimObject, public ThermalEntity
+{
+ public:
+ typedef ThermalResistorParams Params;
+ ThermalResistor(const Params *p);
+
+ void serialize(CheckpointOut &cp) const override;
+ void unserialize(CheckpointIn &cp) override;
+
+ void setNodes(ThermalNode * n1, ThermalNode * n2) {
+ node1 = n1;
+ node2 = n2;
+ }
+
+ LinearEquation getEquation(ThermalNode * tn, unsigned n,
+ double step) const;
+
+ private:
+ /* Resistance value in K/W */
+ double _resistance;
+ /* Nodes connected to the resistor */
+ ThermalNode * node1, * node2;
+};
+
+/**
+ * A ThermalCapacitor is used to model a thermal capacitance between two
+ * thermal domains. This domains can be either a reference (fixed temp.) or
+ * a heat producer (power source).
+ */
+class ThermalCapacitor : public SimObject, public ThermalEntity
+{
+ public:
+ typedef ThermalCapacitorParams Params;
+ ThermalCapacitor(const Params *p);
+
+ void serialize(CheckpointOut &cp) const override;
+ void unserialize(CheckpointIn &cp) override;
+
+ LinearEquation getEquation(ThermalNode * tn, unsigned n,
+ double step) const;
+
+ void setNodes(ThermalNode * n1, ThermalNode * n2) {
+ node1 = n1;
+ node2 = n2;
+ }
+
+ private:
+ /* Capacitance value in J/K */
+ double _capacitance;
+ /* Nodes connected to the resistor */
+ ThermalNode * node1, * node2;
+};
+
+/**
+ * A ThermalReference is a thermal domain with fixed temperature.
+ * It's the homologue to the voltage source in a circuit.
+ */
+class ThermalReference : public SimObject, public ThermalEntity
+{
+ public:
+ typedef ThermalReferenceParams Params;
+ ThermalReference(const Params *p);
+
+ void setNode(ThermalNode * n) {
+ node = n;
+ }
+
+ LinearEquation getEquation(ThermalNode * tn, unsigned n,
+ double step) const;
+
+ void serialize(CheckpointOut &cp) const override;
+ void unserialize(CheckpointIn &cp) override;
+
+ /* Fixed temperature value in centigrate degrees */
+ double _temperature;
+ /* Nodes connected to the resistor */
+ ThermalNode * node;
+};
+
+
+/**
+ * A ThermalModel is the element which ties all thermal objects
+ * together and provides the thermal solver to the system.
+ * It is reponsible for updating temperature for all Thermal
+ * Domains over time by reading power from simobjects.
+ */
+class ThermalModel : public ClockedObject
+{
+ public:
+ typedef ThermalModelParams Params;
+ ThermalModel(const Params *p);
+
+ void addDomain(ThermalDomain * d);
+ void addReference(ThermalReference * r);
+ void addCapacitor(ThermalCapacitor * c);
+ void addResistor(ThermalResistor * r);
+
+ void addNode(ThermalNode * n) { nodes.push_back(n); }
+
+ double getTemp() const;
+
+ void startup();
+ void doStep();
+
+ void serialize(CheckpointOut &cp) const override;
+ void unserialize(CheckpointIn &cp) override;
+ private:
+
+ /* Keep track of all components used for the thermal model */
+ std::vector <ThermalDomain *> domains;
+ std::vector <ThermalReference *> references;
+ std::vector <ThermalCapacitor *> capacitors;
+ std::vector <ThermalResistor *> resistors;
+
+ std::vector <ThermalEntity *> entities;
+
+ /* Keep a list of the instantiated nodes */
+ std::vector <ThermalNode*> nodes;
+ std::vector <ThermalNode*> eq_nodes;
+
+ /** Stepping event to update the model values */
+ EventWrapper<ThermalModel, &ThermalModel::doStep> stepEvent;
+
+ /** Step in seconds for thermal updates */
+ double _step;
+
+};
+
+#endif