ThermalModel.py revision 13665:9c7fe3811b88
113955Sgiacomo.gabrielli@arm.com# Copyright (c) 2015 ARM Limited
213955Sgiacomo.gabrielli@arm.com# All rights reserved.
313955Sgiacomo.gabrielli@arm.com#
413955Sgiacomo.gabrielli@arm.com# The license below extends only to copyright in the software and shall
513955Sgiacomo.gabrielli@arm.com# not be construed as granting a license to any other intellectual
613955Sgiacomo.gabrielli@arm.com# property including but not limited to intellectual property relating
713955Sgiacomo.gabrielli@arm.com# to a hardware implementation of the functionality of the software
813955Sgiacomo.gabrielli@arm.com# licensed hereunder.  You may use the software subject to the license
913955Sgiacomo.gabrielli@arm.com# terms below provided that you ensure that this notice is replicated
1013955Sgiacomo.gabrielli@arm.com# unmodified and in its entirety in all distributions of the software,
1113955Sgiacomo.gabrielli@arm.com# modified or unmodified, in source code or in binary form.
1213955Sgiacomo.gabrielli@arm.com#
1313955Sgiacomo.gabrielli@arm.com# Redistribution and use in source and binary forms, with or without
1413955Sgiacomo.gabrielli@arm.com# modification, are permitted provided that the following conditions are
1513955Sgiacomo.gabrielli@arm.com# met: redistributions of source code must retain the above copyright
1613955Sgiacomo.gabrielli@arm.com# notice, this list of conditions and the following disclaimer;
1713955Sgiacomo.gabrielli@arm.com# redistributions in binary form must reproduce the above copyright
1813955Sgiacomo.gabrielli@arm.com# notice, this list of conditions and the following disclaimer in the
1913955Sgiacomo.gabrielli@arm.com# documentation and/or other materials provided with the distribution;
2013955Sgiacomo.gabrielli@arm.com# neither the name of the copyright holders nor the names of its
2113955Sgiacomo.gabrielli@arm.com# contributors may be used to endorse or promote products derived from
2213955Sgiacomo.gabrielli@arm.com# this software without specific prior written permission.
2313955Sgiacomo.gabrielli@arm.com#
2413955Sgiacomo.gabrielli@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2513955Sgiacomo.gabrielli@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2613955Sgiacomo.gabrielli@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2713955Sgiacomo.gabrielli@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2813955Sgiacomo.gabrielli@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2913955Sgiacomo.gabrielli@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3013955Sgiacomo.gabrielli@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3113955Sgiacomo.gabrielli@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3213955Sgiacomo.gabrielli@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3313955Sgiacomo.gabrielli@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3413955Sgiacomo.gabrielli@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3513955Sgiacomo.gabrielli@arm.com#
3613955Sgiacomo.gabrielli@arm.com# Authors: David Guillen Fandos
3713955Sgiacomo.gabrielli@arm.com
3813955Sgiacomo.gabrielli@arm.comfrom m5.SimObject import *
3913955Sgiacomo.gabrielli@arm.comfrom m5.objects.ClockedObject import ClockedObject
4013955Sgiacomo.gabrielli@arm.com
4113955Sgiacomo.gabrielli@arm.comfrom m5.params import *
4213955Sgiacomo.gabrielli@arm.comfrom m5.objects import ThermalDomain
4313955Sgiacomo.gabrielli@arm.com
4413955Sgiacomo.gabrielli@arm.com
4513955Sgiacomo.gabrielli@arm.com# Represents a thermal node
4613955Sgiacomo.gabrielli@arm.comclass ThermalNode(SimObject):
4713955Sgiacomo.gabrielli@arm.com    type = 'ThermalNode'
4813955Sgiacomo.gabrielli@arm.com    cxx_header = "sim/power/thermal_node.hh"
4913955Sgiacomo.gabrielli@arm.com
5013955Sgiacomo.gabrielli@arm.com# Represents a thermal resistor
5113955Sgiacomo.gabrielli@arm.comclass ThermalResistor(SimObject):
5213955Sgiacomo.gabrielli@arm.com    type = 'ThermalResistor'
5313955Sgiacomo.gabrielli@arm.com    cxx_header = "sim/power/thermal_model.hh"
5413955Sgiacomo.gabrielli@arm.com
5513955Sgiacomo.gabrielli@arm.com    cxx_exports = [
5613955Sgiacomo.gabrielli@arm.com        PyBindMethod("setNodes"),
5713955Sgiacomo.gabrielli@arm.com    ]
5813955Sgiacomo.gabrielli@arm.com
5913955Sgiacomo.gabrielli@arm.com    resistance = Param.Float(1.0, "Thermal resistance, expressed in Kelvin per Watt")
6013955Sgiacomo.gabrielli@arm.com
6113955Sgiacomo.gabrielli@arm.com# Represents a thermal capacitor
6213955Sgiacomo.gabrielli@arm.comclass ThermalCapacitor(SimObject):
6313955Sgiacomo.gabrielli@arm.com    type = 'ThermalCapacitor'
6413955Sgiacomo.gabrielli@arm.com    cxx_header = "sim/power/thermal_model.hh"
6513955Sgiacomo.gabrielli@arm.com
6613955Sgiacomo.gabrielli@arm.com    cxx_exports = [
6713955Sgiacomo.gabrielli@arm.com        PyBindMethod("setNodes"),
6813955Sgiacomo.gabrielli@arm.com    ]
6913955Sgiacomo.gabrielli@arm.com
7013955Sgiacomo.gabrielli@arm.com    capacitance = Param.Float(1.0, "Thermal capacitance, expressed in Joules per Kelvin")
7113955Sgiacomo.gabrielli@arm.com
7213955Sgiacomo.gabrielli@arm.com# Represents a fixed temperature node (ie. air)
7313955Sgiacomo.gabrielli@arm.comclass ThermalReference(SimObject, object):
7413955Sgiacomo.gabrielli@arm.com    type = 'ThermalReference'
7513955Sgiacomo.gabrielli@arm.com    cxx_header = "sim/power/thermal_model.hh"
7613955Sgiacomo.gabrielli@arm.com
7713955Sgiacomo.gabrielli@arm.com    cxx_exports = [
7813955Sgiacomo.gabrielli@arm.com        PyBindMethod("setNode"),
7913955Sgiacomo.gabrielli@arm.com    ]
8013955Sgiacomo.gabrielli@arm.com
8113955Sgiacomo.gabrielli@arm.com    # Static temperature which may change over time
8213955Sgiacomo.gabrielli@arm.com    temperature = Param.Float(25.0, "Operational temperature in Celsius")
8313955Sgiacomo.gabrielli@arm.com
8413955Sgiacomo.gabrielli@arm.com
8513955Sgiacomo.gabrielli@arm.com# Represents a thermal capacitor
8613955Sgiacomo.gabrielli@arm.comclass ThermalModel(ClockedObject):
8713955Sgiacomo.gabrielli@arm.com    type = 'ThermalModel'
8813955Sgiacomo.gabrielli@arm.com    cxx_header = "sim/power/thermal_model.hh"
8913955Sgiacomo.gabrielli@arm.com
9013955Sgiacomo.gabrielli@arm.com    cxx_exports = [
9113955Sgiacomo.gabrielli@arm.com        PyBindMethod("addCapacitor"),
9213955Sgiacomo.gabrielli@arm.com        PyBindMethod("addResistor"),
9313955Sgiacomo.gabrielli@arm.com        PyBindMethod("addReference"),
9413955Sgiacomo.gabrielli@arm.com        PyBindMethod("addDomain"),
9513955Sgiacomo.gabrielli@arm.com        PyBindMethod("addNode"),
9613955Sgiacomo.gabrielli@arm.com        PyBindMethod("doStep"),
9713955Sgiacomo.gabrielli@arm.com    ]
9813955Sgiacomo.gabrielli@arm.com
9913955Sgiacomo.gabrielli@arm.com    step = Param.Float(0.01, "Simulation step (in seconds) for thermal simulation")
10013955Sgiacomo.gabrielli@arm.com
10113955Sgiacomo.gabrielli@arm.com    def populate(self):
10213955Sgiacomo.gabrielli@arm.com        if not hasattr(self,"_capacitors"): self._capacitors = []
10313955Sgiacomo.gabrielli@arm.com        if not hasattr(self,"_resistors"): self._resistors = []
10413955Sgiacomo.gabrielli@arm.com        if not hasattr(self,"_domains"): self._domains = []
10513955Sgiacomo.gabrielli@arm.com        if not hasattr(self,"_references"): self._references = []
10613955Sgiacomo.gabrielli@arm.com        if not hasattr(self,"_nodes"): self._nodes = []
10713955Sgiacomo.gabrielli@arm.com
10813955Sgiacomo.gabrielli@arm.com    def init(self):
10913955Sgiacomo.gabrielli@arm.com        self.populate()
11013955Sgiacomo.gabrielli@arm.com
11113955Sgiacomo.gabrielli@arm.com        for ref, node in self._references:
11213955Sgiacomo.gabrielli@arm.com            ref.getCCObject().setNode(node.getCCObject())
11313955Sgiacomo.gabrielli@arm.com            self.getCCObject().addReference(ref.getCCObject())
11413955Sgiacomo.gabrielli@arm.com
11513955Sgiacomo.gabrielli@arm.com        for dom, node in self._domains:
11613955Sgiacomo.gabrielli@arm.com            dom.getCCObject().setNode(node.getCCObject())
117            self.getCCObject().addDomain(dom.getCCObject())
118
119        for cap, node1, node2 in self._capacitors:
120            cap.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject())
121            self.getCCObject().addCapacitor(cap.getCCObject())
122
123        for res, node1, node2 in self._resistors:
124            res.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject())
125            self.getCCObject().addResistor(res.getCCObject())
126
127        for node in self._nodes:
128            self.getCCObject().addNode(node.getCCObject())
129
130    def addCapacitor(self, cap, node1, node2):
131        self.populate()
132        self._capacitors.append( (cap, node1, node2) )
133        self._parent.thermal_components.append(cap)
134        self.addNodes(node1,node2)
135
136    def addResistor(self, res, node1, node2):
137        self.populate()
138        self._resistors.append( (res, node1, node2) )
139        self._parent.thermal_components.append(res)
140        self.addNodes(node1,node2)
141
142    def addReference(self, ref, node):
143        self.populate()
144        self._references.append( (ref, node) )
145        self._parent.thermal_components.append(ref)
146        self.addNodes(node)
147
148    def addDomain(self, dom, node):
149        self.populate()
150        self._domains.append( (dom, node) )
151        self.addNodes(node)
152
153    def addNodes(self, *nodes):
154        for node in nodes:
155            if node not in self._nodes:
156                self._nodes.append(node)
157                self._parent.thermal_components.append(node)
158
159    def doStep(self):
160        self.getCCObject().doStep()
161