111420Sdavid.guillen@arm.com# Copyright (c) 2015 ARM Limited
211420Sdavid.guillen@arm.com# All rights reserved.
311420Sdavid.guillen@arm.com#
411420Sdavid.guillen@arm.com# The license below extends only to copyright in the software and shall
511420Sdavid.guillen@arm.com# not be construed as granting a license to any other intellectual
611420Sdavid.guillen@arm.com# property including but not limited to intellectual property relating
711420Sdavid.guillen@arm.com# to a hardware implementation of the functionality of the software
811420Sdavid.guillen@arm.com# licensed hereunder.  You may use the software subject to the license
911420Sdavid.guillen@arm.com# terms below provided that you ensure that this notice is replicated
1011420Sdavid.guillen@arm.com# unmodified and in its entirety in all distributions of the software,
1111420Sdavid.guillen@arm.com# modified or unmodified, in source code or in binary form.
1211420Sdavid.guillen@arm.com#
1311420Sdavid.guillen@arm.com# Redistribution and use in source and binary forms, with or without
1411420Sdavid.guillen@arm.com# modification, are permitted provided that the following conditions are
1511420Sdavid.guillen@arm.com# met: redistributions of source code must retain the above copyright
1611420Sdavid.guillen@arm.com# notice, this list of conditions and the following disclaimer;
1711420Sdavid.guillen@arm.com# redistributions in binary form must reproduce the above copyright
1811420Sdavid.guillen@arm.com# notice, this list of conditions and the following disclaimer in the
1911420Sdavid.guillen@arm.com# documentation and/or other materials provided with the distribution;
2011420Sdavid.guillen@arm.com# neither the name of the copyright holders nor the names of its
2111420Sdavid.guillen@arm.com# contributors may be used to endorse or promote products derived from
2211420Sdavid.guillen@arm.com# this software without specific prior written permission.
2311420Sdavid.guillen@arm.com#
2411420Sdavid.guillen@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2511420Sdavid.guillen@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2611420Sdavid.guillen@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2711420Sdavid.guillen@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2811420Sdavid.guillen@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2911420Sdavid.guillen@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3011420Sdavid.guillen@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3111420Sdavid.guillen@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3211420Sdavid.guillen@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3311420Sdavid.guillen@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3411420Sdavid.guillen@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3511420Sdavid.guillen@arm.com#
3611420Sdavid.guillen@arm.com# Authors: David Guillen Fandos
3711420Sdavid.guillen@arm.com
3811988Sandreas.sandberg@arm.comfrom m5.SimObject import *
3913665Sandreas.sandberg@arm.comfrom m5.objects.ClockedObject import ClockedObject
4011420Sdavid.guillen@arm.com
4111420Sdavid.guillen@arm.comfrom m5.params import *
4211420Sdavid.guillen@arm.comfrom m5.objects import ThermalDomain
4311420Sdavid.guillen@arm.com
4411420Sdavid.guillen@arm.com
4511420Sdavid.guillen@arm.com# Represents a thermal node
4611420Sdavid.guillen@arm.comclass ThermalNode(SimObject):
4711420Sdavid.guillen@arm.com    type = 'ThermalNode'
4811899Sandreas.sandberg@arm.com    cxx_header = "sim/power/thermal_node.hh"
4911420Sdavid.guillen@arm.com
5011420Sdavid.guillen@arm.com# Represents a thermal resistor
5111420Sdavid.guillen@arm.comclass ThermalResistor(SimObject):
5211420Sdavid.guillen@arm.com    type = 'ThermalResistor'
5311420Sdavid.guillen@arm.com    cxx_header = "sim/power/thermal_model.hh"
5411420Sdavid.guillen@arm.com
5511988Sandreas.sandberg@arm.com    cxx_exports = [
5611988Sandreas.sandberg@arm.com        PyBindMethod("setNodes"),
5711988Sandreas.sandberg@arm.com    ]
5811420Sdavid.guillen@arm.com
5911420Sdavid.guillen@arm.com    resistance = Param.Float(1.0, "Thermal resistance, expressed in Kelvin per Watt")
6011420Sdavid.guillen@arm.com
6111420Sdavid.guillen@arm.com# Represents a thermal capacitor
6211420Sdavid.guillen@arm.comclass ThermalCapacitor(SimObject):
6311420Sdavid.guillen@arm.com    type = 'ThermalCapacitor'
6411420Sdavid.guillen@arm.com    cxx_header = "sim/power/thermal_model.hh"
6511420Sdavid.guillen@arm.com
6611988Sandreas.sandberg@arm.com    cxx_exports = [
6711988Sandreas.sandberg@arm.com        PyBindMethod("setNodes"),
6811988Sandreas.sandberg@arm.com    ]
6911420Sdavid.guillen@arm.com
7011420Sdavid.guillen@arm.com    capacitance = Param.Float(1.0, "Thermal capacitance, expressed in Joules per Kelvin")
7111420Sdavid.guillen@arm.com
7211420Sdavid.guillen@arm.com# Represents a fixed temperature node (ie. air)
7311420Sdavid.guillen@arm.comclass ThermalReference(SimObject, object):
7411420Sdavid.guillen@arm.com    type = 'ThermalReference'
7511420Sdavid.guillen@arm.com    cxx_header = "sim/power/thermal_model.hh"
7611420Sdavid.guillen@arm.com
7711988Sandreas.sandberg@arm.com    cxx_exports = [
7811988Sandreas.sandberg@arm.com        PyBindMethod("setNode"),
7911988Sandreas.sandberg@arm.com    ]
8011420Sdavid.guillen@arm.com
8111420Sdavid.guillen@arm.com    # Static temperature which may change over time
8211420Sdavid.guillen@arm.com    temperature = Param.Float(25.0, "Operational temperature in Celsius")
8311420Sdavid.guillen@arm.com
8411420Sdavid.guillen@arm.com
8511420Sdavid.guillen@arm.com# Represents a thermal capacitor
8611420Sdavid.guillen@arm.comclass ThermalModel(ClockedObject):
8711420Sdavid.guillen@arm.com    type = 'ThermalModel'
8811420Sdavid.guillen@arm.com    cxx_header = "sim/power/thermal_model.hh"
8911420Sdavid.guillen@arm.com
9011988Sandreas.sandberg@arm.com    cxx_exports = [
9111988Sandreas.sandberg@arm.com        PyBindMethod("addCapacitor"),
9211988Sandreas.sandberg@arm.com        PyBindMethod("addResistor"),
9311988Sandreas.sandberg@arm.com        PyBindMethod("addReference"),
9411988Sandreas.sandberg@arm.com        PyBindMethod("addDomain"),
9511988Sandreas.sandberg@arm.com        PyBindMethod("addNode"),
9611988Sandreas.sandberg@arm.com        PyBindMethod("doStep"),
9711988Sandreas.sandberg@arm.com    ]
9811420Sdavid.guillen@arm.com
9911420Sdavid.guillen@arm.com    step = Param.Float(0.01, "Simulation step (in seconds) for thermal simulation")
10011420Sdavid.guillen@arm.com
10111420Sdavid.guillen@arm.com    def populate(self):
10211420Sdavid.guillen@arm.com        if not hasattr(self,"_capacitors"): self._capacitors = []
10311420Sdavid.guillen@arm.com        if not hasattr(self,"_resistors"): self._resistors = []
10411420Sdavid.guillen@arm.com        if not hasattr(self,"_domains"): self._domains = []
10511420Sdavid.guillen@arm.com        if not hasattr(self,"_references"): self._references = []
10611420Sdavid.guillen@arm.com        if not hasattr(self,"_nodes"): self._nodes = []
10711420Sdavid.guillen@arm.com
10811420Sdavid.guillen@arm.com    def init(self):
10911420Sdavid.guillen@arm.com        self.populate()
11011420Sdavid.guillen@arm.com
11111420Sdavid.guillen@arm.com        for ref, node in self._references:
11211420Sdavid.guillen@arm.com            ref.getCCObject().setNode(node.getCCObject())
11311420Sdavid.guillen@arm.com            self.getCCObject().addReference(ref.getCCObject())
11411420Sdavid.guillen@arm.com
11511420Sdavid.guillen@arm.com        for dom, node in self._domains:
11611420Sdavid.guillen@arm.com            dom.getCCObject().setNode(node.getCCObject())
11711420Sdavid.guillen@arm.com            self.getCCObject().addDomain(dom.getCCObject())
11811420Sdavid.guillen@arm.com
11911420Sdavid.guillen@arm.com        for cap, node1, node2 in self._capacitors:
12011420Sdavid.guillen@arm.com            cap.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject())
12111420Sdavid.guillen@arm.com            self.getCCObject().addCapacitor(cap.getCCObject())
12211420Sdavid.guillen@arm.com
12311420Sdavid.guillen@arm.com        for res, node1, node2 in self._resistors:
12411420Sdavid.guillen@arm.com            res.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject())
12511420Sdavid.guillen@arm.com            self.getCCObject().addResistor(res.getCCObject())
12611420Sdavid.guillen@arm.com
12711420Sdavid.guillen@arm.com        for node in self._nodes:
12811420Sdavid.guillen@arm.com            self.getCCObject().addNode(node.getCCObject())
12911420Sdavid.guillen@arm.com
13011420Sdavid.guillen@arm.com    def addCapacitor(self, cap, node1, node2):
13111420Sdavid.guillen@arm.com        self.populate()
13211420Sdavid.guillen@arm.com        self._capacitors.append( (cap, node1, node2) )
13311420Sdavid.guillen@arm.com        self._parent.thermal_components.append(cap)
13411420Sdavid.guillen@arm.com        self.addNodes(node1,node2)
13511420Sdavid.guillen@arm.com
13611420Sdavid.guillen@arm.com    def addResistor(self, res, node1, node2):
13711420Sdavid.guillen@arm.com        self.populate()
13811420Sdavid.guillen@arm.com        self._resistors.append( (res, node1, node2) )
13911420Sdavid.guillen@arm.com        self._parent.thermal_components.append(res)
14011420Sdavid.guillen@arm.com        self.addNodes(node1,node2)
14111420Sdavid.guillen@arm.com
14211420Sdavid.guillen@arm.com    def addReference(self, ref, node):
14311420Sdavid.guillen@arm.com        self.populate()
14411420Sdavid.guillen@arm.com        self._references.append( (ref, node) )
14511420Sdavid.guillen@arm.com        self._parent.thermal_components.append(ref)
14611420Sdavid.guillen@arm.com        self.addNodes(node)
14711420Sdavid.guillen@arm.com
14811420Sdavid.guillen@arm.com    def addDomain(self, dom, node):
14911420Sdavid.guillen@arm.com        self.populate()
15011420Sdavid.guillen@arm.com        self._domains.append( (dom, node) )
15111420Sdavid.guillen@arm.com        self.addNodes(node)
15211420Sdavid.guillen@arm.com
15311420Sdavid.guillen@arm.com    def addNodes(self, *nodes):
15411420Sdavid.guillen@arm.com        for node in nodes:
15511420Sdavid.guillen@arm.com            if node not in self._nodes:
15611420Sdavid.guillen@arm.com                self._nodes.append(node)
15711420Sdavid.guillen@arm.com                self._parent.thermal_components.append(node)
15811420Sdavid.guillen@arm.com
15911420Sdavid.guillen@arm.com    def doStep(self):
16011420Sdavid.guillen@arm.com        self.getCCObject().doStep()
161