ThermalModel.py revision 11420
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 3811420Sdavid.guillen@arm.comfrom m5.SimObject import SimObject 3911420Sdavid.guillen@arm.comfrom 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' 4811420Sdavid.guillen@arm.com cxx_header = "sim/power/thermal_model.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 5511420Sdavid.guillen@arm.com @classmethod 5611420Sdavid.guillen@arm.com def export_methods(cls, code): 5711420Sdavid.guillen@arm.com code(''' 5811420Sdavid.guillen@arm.com void setNodes(ThermalNode * node1, ThermalNode * node2); 5911420Sdavid.guillen@arm.com''') 6011420Sdavid.guillen@arm.com 6111420Sdavid.guillen@arm.com resistance = Param.Float(1.0, "Thermal resistance, expressed in Kelvin per Watt") 6211420Sdavid.guillen@arm.com 6311420Sdavid.guillen@arm.com# Represents a thermal capacitor 6411420Sdavid.guillen@arm.comclass ThermalCapacitor(SimObject): 6511420Sdavid.guillen@arm.com type = 'ThermalCapacitor' 6611420Sdavid.guillen@arm.com cxx_header = "sim/power/thermal_model.hh" 6711420Sdavid.guillen@arm.com 6811420Sdavid.guillen@arm.com @classmethod 6911420Sdavid.guillen@arm.com def export_methods(cls, code): 7011420Sdavid.guillen@arm.com code(''' 7111420Sdavid.guillen@arm.com void setNodes(ThermalNode * node1, ThermalNode * node2); 7211420Sdavid.guillen@arm.com''') 7311420Sdavid.guillen@arm.com 7411420Sdavid.guillen@arm.com capacitance = Param.Float(1.0, "Thermal capacitance, expressed in Joules per Kelvin") 7511420Sdavid.guillen@arm.com 7611420Sdavid.guillen@arm.com# Represents a fixed temperature node (ie. air) 7711420Sdavid.guillen@arm.comclass ThermalReference(SimObject, object): 7811420Sdavid.guillen@arm.com type = 'ThermalReference' 7911420Sdavid.guillen@arm.com cxx_header = "sim/power/thermal_model.hh" 8011420Sdavid.guillen@arm.com 8111420Sdavid.guillen@arm.com @classmethod 8211420Sdavid.guillen@arm.com def export_methods(cls, code): 8311420Sdavid.guillen@arm.com code(''' 8411420Sdavid.guillen@arm.com void setNode(ThermalNode * node); 8511420Sdavid.guillen@arm.com''') 8611420Sdavid.guillen@arm.com 8711420Sdavid.guillen@arm.com # Static temperature which may change over time 8811420Sdavid.guillen@arm.com temperature = Param.Float(25.0, "Operational temperature in Celsius") 8911420Sdavid.guillen@arm.com 9011420Sdavid.guillen@arm.com 9111420Sdavid.guillen@arm.com# Represents a thermal capacitor 9211420Sdavid.guillen@arm.comclass ThermalModel(ClockedObject): 9311420Sdavid.guillen@arm.com type = 'ThermalModel' 9411420Sdavid.guillen@arm.com cxx_header = "sim/power/thermal_model.hh" 9511420Sdavid.guillen@arm.com 9611420Sdavid.guillen@arm.com @classmethod 9711420Sdavid.guillen@arm.com def export_methods(cls, code): 9811420Sdavid.guillen@arm.com code(''' 9911420Sdavid.guillen@arm.com void addCapacitor(ThermalCapacitor *obj); 10011420Sdavid.guillen@arm.com void addResistor(ThermalResistor *obj); 10111420Sdavid.guillen@arm.com void addReference(ThermalReference *obj); 10211420Sdavid.guillen@arm.com void addDomain(ThermalDomain *obj); 10311420Sdavid.guillen@arm.com void addNode(ThermalNode *obj); 10411420Sdavid.guillen@arm.com void doStep(); 10511420Sdavid.guillen@arm.com''') 10611420Sdavid.guillen@arm.com 10711420Sdavid.guillen@arm.com step = Param.Float(0.01, "Simulation step (in seconds) for thermal simulation") 10811420Sdavid.guillen@arm.com 10911420Sdavid.guillen@arm.com def populate(self): 11011420Sdavid.guillen@arm.com if not hasattr(self,"_capacitors"): self._capacitors = [] 11111420Sdavid.guillen@arm.com if not hasattr(self,"_resistors"): self._resistors = [] 11211420Sdavid.guillen@arm.com if not hasattr(self,"_domains"): self._domains = [] 11311420Sdavid.guillen@arm.com if not hasattr(self,"_references"): self._references = [] 11411420Sdavid.guillen@arm.com if not hasattr(self,"_nodes"): self._nodes = [] 11511420Sdavid.guillen@arm.com 11611420Sdavid.guillen@arm.com def init(self): 11711420Sdavid.guillen@arm.com self.populate() 11811420Sdavid.guillen@arm.com 11911420Sdavid.guillen@arm.com for ref, node in self._references: 12011420Sdavid.guillen@arm.com ref.getCCObject().setNode(node.getCCObject()) 12111420Sdavid.guillen@arm.com self.getCCObject().addReference(ref.getCCObject()) 12211420Sdavid.guillen@arm.com 12311420Sdavid.guillen@arm.com for dom, node in self._domains: 12411420Sdavid.guillen@arm.com dom.getCCObject().setNode(node.getCCObject()) 12511420Sdavid.guillen@arm.com self.getCCObject().addDomain(dom.getCCObject()) 12611420Sdavid.guillen@arm.com 12711420Sdavid.guillen@arm.com for cap, node1, node2 in self._capacitors: 12811420Sdavid.guillen@arm.com cap.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject()) 12911420Sdavid.guillen@arm.com self.getCCObject().addCapacitor(cap.getCCObject()) 13011420Sdavid.guillen@arm.com 13111420Sdavid.guillen@arm.com for res, node1, node2 in self._resistors: 13211420Sdavid.guillen@arm.com res.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject()) 13311420Sdavid.guillen@arm.com self.getCCObject().addResistor(res.getCCObject()) 13411420Sdavid.guillen@arm.com 13511420Sdavid.guillen@arm.com for node in self._nodes: 13611420Sdavid.guillen@arm.com self.getCCObject().addNode(node.getCCObject()) 13711420Sdavid.guillen@arm.com 13811420Sdavid.guillen@arm.com def addCapacitor(self, cap, node1, node2): 13911420Sdavid.guillen@arm.com self.populate() 14011420Sdavid.guillen@arm.com self._capacitors.append( (cap, node1, node2) ) 14111420Sdavid.guillen@arm.com self._parent.thermal_components.append(cap) 14211420Sdavid.guillen@arm.com self.addNodes(node1,node2) 14311420Sdavid.guillen@arm.com 14411420Sdavid.guillen@arm.com def addResistor(self, res, node1, node2): 14511420Sdavid.guillen@arm.com self.populate() 14611420Sdavid.guillen@arm.com self._resistors.append( (res, node1, node2) ) 14711420Sdavid.guillen@arm.com self._parent.thermal_components.append(res) 14811420Sdavid.guillen@arm.com self.addNodes(node1,node2) 14911420Sdavid.guillen@arm.com 15011420Sdavid.guillen@arm.com def addReference(self, ref, node): 15111420Sdavid.guillen@arm.com self.populate() 15211420Sdavid.guillen@arm.com self._references.append( (ref, node) ) 15311420Sdavid.guillen@arm.com self._parent.thermal_components.append(ref) 15411420Sdavid.guillen@arm.com self.addNodes(node) 15511420Sdavid.guillen@arm.com 15611420Sdavid.guillen@arm.com def addDomain(self, dom, node): 15711420Sdavid.guillen@arm.com self.populate() 15811420Sdavid.guillen@arm.com self._domains.append( (dom, node) ) 15911420Sdavid.guillen@arm.com self.addNodes(node) 16011420Sdavid.guillen@arm.com 16111420Sdavid.guillen@arm.com def addNodes(self, *nodes): 16211420Sdavid.guillen@arm.com for node in nodes: 16311420Sdavid.guillen@arm.com if node not in self._nodes: 16411420Sdavid.guillen@arm.com self._nodes.append(node) 16511420Sdavid.guillen@arm.com self._parent.thermal_components.append(node) 16611420Sdavid.guillen@arm.com 16711420Sdavid.guillen@arm.com def doStep(self): 16811420Sdavid.guillen@arm.com self.getCCObject().doStep() 169