ThermalModel.py revision 11420:b48c0ba4f524
12929Sktlim@umich.edu# Copyright (c) 2015 ARM Limited
22929Sktlim@umich.edu# All rights reserved.
32932Sktlim@umich.edu#
42929Sktlim@umich.edu# The license below extends only to copyright in the software and shall
52929Sktlim@umich.edu# not be construed as granting a license to any other intellectual
62929Sktlim@umich.edu# property including but not limited to intellectual property relating
72929Sktlim@umich.edu# to a hardware implementation of the functionality of the software
82929Sktlim@umich.edu# licensed hereunder.  You may use the software subject to the license
92929Sktlim@umich.edu# terms below provided that you ensure that this notice is replicated
102929Sktlim@umich.edu# unmodified and in its entirety in all distributions of the software,
112929Sktlim@umich.edu# modified or unmodified, in source code or in binary form.
122929Sktlim@umich.edu#
132929Sktlim@umich.edu# Redistribution and use in source and binary forms, with or without
142929Sktlim@umich.edu# modification, are permitted provided that the following conditions are
152929Sktlim@umich.edu# met: redistributions of source code must retain the above copyright
162929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer;
172929Sktlim@umich.edu# redistributions in binary form must reproduce the above copyright
182929Sktlim@umich.edu# notice, this list of conditions and the following disclaimer in the
192929Sktlim@umich.edu# documentation and/or other materials provided with the distribution;
202929Sktlim@umich.edu# neither the name of the copyright holders nor the names of its
212929Sktlim@umich.edu# contributors may be used to endorse or promote products derived from
222929Sktlim@umich.edu# this software without specific prior written permission.
232929Sktlim@umich.edu#
242929Sktlim@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
252929Sktlim@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
262929Sktlim@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
272929Sktlim@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
282932Sktlim@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
292932Sktlim@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
302932Sktlim@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
312929Sktlim@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
326007Ssteve.reinhardt@amd.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
332929Sktlim@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
342929Sktlim@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
352929Sktlim@umich.edu#
362929Sktlim@umich.edu# Authors: David Guillen Fandos
372929Sktlim@umich.edu
382929Sktlim@umich.edufrom m5.SimObject import SimObject
392929Sktlim@umich.edufrom ClockedObject import ClockedObject
402929Sktlim@umich.edu
412929Sktlim@umich.edufrom m5.params import *
422929Sktlim@umich.edufrom m5.objects import ThermalDomain
432929Sktlim@umich.edu
442929Sktlim@umich.edu
452929Sktlim@umich.edu# Represents a thermal node
462929Sktlim@umich.educlass ThermalNode(SimObject):
476007Ssteve.reinhardt@amd.com    type = 'ThermalNode'
486007Ssteve.reinhardt@amd.com    cxx_header = "sim/power/thermal_model.hh"
496007Ssteve.reinhardt@amd.com
506007Ssteve.reinhardt@amd.com# Represents a thermal resistor
516007Ssteve.reinhardt@amd.comclass ThermalResistor(SimObject):
526007Ssteve.reinhardt@amd.com    type = 'ThermalResistor'
536007Ssteve.reinhardt@amd.com    cxx_header = "sim/power/thermal_model.hh"
546007Ssteve.reinhardt@amd.com
556007Ssteve.reinhardt@amd.com    @classmethod
566007Ssteve.reinhardt@amd.com    def export_methods(cls, code):
576007Ssteve.reinhardt@amd.com        code('''
586007Ssteve.reinhardt@amd.com      void setNodes(ThermalNode * node1, ThermalNode * node2);
596007Ssteve.reinhardt@amd.com''')
606007Ssteve.reinhardt@amd.com
616007Ssteve.reinhardt@amd.com    resistance = Param.Float(1.0, "Thermal resistance, expressed in Kelvin per Watt")
626007Ssteve.reinhardt@amd.com
636007Ssteve.reinhardt@amd.com# Represents a thermal capacitor
646007Ssteve.reinhardt@amd.comclass ThermalCapacitor(SimObject):
656007Ssteve.reinhardt@amd.com    type = 'ThermalCapacitor'
666007Ssteve.reinhardt@amd.com    cxx_header = "sim/power/thermal_model.hh"
676007Ssteve.reinhardt@amd.com
686007Ssteve.reinhardt@amd.com    @classmethod
696007Ssteve.reinhardt@amd.com    def export_methods(cls, code):
706007Ssteve.reinhardt@amd.com        code('''
716007Ssteve.reinhardt@amd.com      void setNodes(ThermalNode * node1, ThermalNode * node2);
726007Ssteve.reinhardt@amd.com''')
736007Ssteve.reinhardt@amd.com
746007Ssteve.reinhardt@amd.com    capacitance = Param.Float(1.0, "Thermal capacitance, expressed in Joules per Kelvin")
756007Ssteve.reinhardt@amd.com
762929Sktlim@umich.edu# Represents a fixed temperature node (ie. air)
772929Sktlim@umich.educlass ThermalReference(SimObject, object):
782929Sktlim@umich.edu    type = 'ThermalReference'
796007Ssteve.reinhardt@amd.com    cxx_header = "sim/power/thermal_model.hh"
806007Ssteve.reinhardt@amd.com
816007Ssteve.reinhardt@amd.com    @classmethod
826007Ssteve.reinhardt@amd.com    def export_methods(cls, code):
836007Ssteve.reinhardt@amd.com        code('''
846007Ssteve.reinhardt@amd.com      void setNode(ThermalNode * node);
852929Sktlim@umich.edu''')
862929Sktlim@umich.edu
872929Sktlim@umich.edu    # Static temperature which may change over time
882929Sktlim@umich.edu    temperature = Param.Float(25.0, "Operational temperature in Celsius")
892929Sktlim@umich.edu
906011Ssteve.reinhardt@amd.com
916007Ssteve.reinhardt@amd.com# Represents a thermal capacitor
926007Ssteve.reinhardt@amd.comclass ThermalModel(ClockedObject):
936007Ssteve.reinhardt@amd.com    type = 'ThermalModel'
946007Ssteve.reinhardt@amd.com    cxx_header = "sim/power/thermal_model.hh"
956007Ssteve.reinhardt@amd.com
966007Ssteve.reinhardt@amd.com    @classmethod
976007Ssteve.reinhardt@amd.com    def export_methods(cls, code):
986007Ssteve.reinhardt@amd.com        code('''
996007Ssteve.reinhardt@amd.com      void addCapacitor(ThermalCapacitor *obj);
1006007Ssteve.reinhardt@amd.com      void addResistor(ThermalResistor *obj);
1016007Ssteve.reinhardt@amd.com      void addReference(ThermalReference *obj);
1026007Ssteve.reinhardt@amd.com      void addDomain(ThermalDomain *obj);
1036007Ssteve.reinhardt@amd.com      void addNode(ThermalNode *obj);
1046007Ssteve.reinhardt@amd.com      void doStep();
1056011Ssteve.reinhardt@amd.com''')
1066007Ssteve.reinhardt@amd.com
1076007Ssteve.reinhardt@amd.com    step = Param.Float(0.01, "Simulation step (in seconds) for thermal simulation")
1086007Ssteve.reinhardt@amd.com
1096007Ssteve.reinhardt@amd.com    def populate(self):
1106007Ssteve.reinhardt@amd.com        if not hasattr(self,"_capacitors"): self._capacitors = []
1116007Ssteve.reinhardt@amd.com        if not hasattr(self,"_resistors"): self._resistors = []
1126007Ssteve.reinhardt@amd.com        if not hasattr(self,"_domains"): self._domains = []
1136011Ssteve.reinhardt@amd.com        if not hasattr(self,"_references"): self._references = []
1146007Ssteve.reinhardt@amd.com        if not hasattr(self,"_nodes"): self._nodes = []
1156007Ssteve.reinhardt@amd.com
1166007Ssteve.reinhardt@amd.com    def init(self):
1176007Ssteve.reinhardt@amd.com        self.populate()
1186007Ssteve.reinhardt@amd.com
1196007Ssteve.reinhardt@amd.com        for ref, node in self._references:
1206007Ssteve.reinhardt@amd.com            ref.getCCObject().setNode(node.getCCObject())
1216011Ssteve.reinhardt@amd.com            self.getCCObject().addReference(ref.getCCObject())
1226007Ssteve.reinhardt@amd.com
1236007Ssteve.reinhardt@amd.com        for dom, node in self._domains:
1246007Ssteve.reinhardt@amd.com            dom.getCCObject().setNode(node.getCCObject())
1256007Ssteve.reinhardt@amd.com            self.getCCObject().addDomain(dom.getCCObject())
1266007Ssteve.reinhardt@amd.com
1276008Ssteve.reinhardt@amd.com        for cap, node1, node2 in self._capacitors:
1286007Ssteve.reinhardt@amd.com            cap.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject())
1296008Ssteve.reinhardt@amd.com            self.getCCObject().addCapacitor(cap.getCCObject())
1306008Ssteve.reinhardt@amd.com
1316008Ssteve.reinhardt@amd.com        for res, node1, node2 in self._resistors:
1326008Ssteve.reinhardt@amd.com            res.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject())
1336008Ssteve.reinhardt@amd.com            self.getCCObject().addResistor(res.getCCObject())
1346008Ssteve.reinhardt@amd.com
1356008Ssteve.reinhardt@amd.com        for node in self._nodes:
1366007Ssteve.reinhardt@amd.com            self.getCCObject().addNode(node.getCCObject())
1376007Ssteve.reinhardt@amd.com
1386007Ssteve.reinhardt@amd.com    def addCapacitor(self, cap, node1, node2):
1396007Ssteve.reinhardt@amd.com        self.populate()
1406007Ssteve.reinhardt@amd.com        self._capacitors.append( (cap, node1, node2) )
1412929Sktlim@umich.edu        self._parent.thermal_components.append(cap)
1422929Sktlim@umich.edu        self.addNodes(node1,node2)
1432929Sktlim@umich.edu
1442929Sktlim@umich.edu    def addResistor(self, res, node1, node2):
1456007Ssteve.reinhardt@amd.com        self.populate()
1466007Ssteve.reinhardt@amd.com        self._resistors.append( (res, node1, node2) )
1472929Sktlim@umich.edu        self._parent.thermal_components.append(res)
1482929Sktlim@umich.edu        self.addNodes(node1,node2)
1492929Sktlim@umich.edu
1502929Sktlim@umich.edu    def addReference(self, ref, node):
1516007Ssteve.reinhardt@amd.com        self.populate()
1526007Ssteve.reinhardt@amd.com        self._references.append( (ref, node) )
1532929Sktlim@umich.edu        self._parent.thermal_components.append(ref)
1542929Sktlim@umich.edu        self.addNodes(node)
1556007Ssteve.reinhardt@amd.com
1562929Sktlim@umich.edu    def addDomain(self, dom, node):
1572929Sktlim@umich.edu        self.populate()
1582929Sktlim@umich.edu        self._domains.append( (dom, node) )
1592929Sktlim@umich.edu        self.addNodes(node)
1602929Sktlim@umich.edu
1612929Sktlim@umich.edu    def addNodes(self, *nodes):
1622929Sktlim@umich.edu        for node in nodes:
1634937Sstever@gmail.com            if node not in self._nodes:
1644937Sstever@gmail.com                self._nodes.append(node)
1654937Sstever@gmail.com                self._parent.thermal_components.append(node)
1664937Sstever@gmail.com
1674937Sstever@gmail.com    def doStep(self):
1684937Sstever@gmail.com        self.getCCObject().doStep()
1694937Sstever@gmail.com