thermal_model.hh revision 11442
18981Sandreas.hansson@arm.com/* 210744SGeoffrey.Blake@arm.com * Copyright (c) 2015 ARM Limited 311804Srjthakur@google.com * All rights reserved 411804Srjthakur@google.com * 58981Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68981Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78981Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88981Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98981Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108981Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118981Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128981Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138981Sandreas.hansson@arm.com * 148981Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 158981Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 168981Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 178981Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 188981Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 198981Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 208981Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 218981Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 228981Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 238981Sandreas.hansson@arm.com * this software without specific prior written permission. 248981Sandreas.hansson@arm.com * 258981Sandreas.hansson@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 268981Sandreas.hansson@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 278981Sandreas.hansson@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 288981Sandreas.hansson@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 298981Sandreas.hansson@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 308981Sandreas.hansson@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 318981Sandreas.hansson@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 328981Sandreas.hansson@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 338981Sandreas.hansson@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 348981Sandreas.hansson@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 358981Sandreas.hansson@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 368981Sandreas.hansson@arm.com * 378981Sandreas.hansson@arm.com * Authors: David Guillen Fandos 388981Sandreas.hansson@arm.com */ 398981Sandreas.hansson@arm.com 4011804Srjthakur@google.com#ifndef __SIM_THERMAL_MODEL_HH__ 418981Sandreas.hansson@arm.com#define __SIM_THERMAL_MODEL_HH__ 428981Sandreas.hansson@arm.com 4311793Sbrandon.potter@amd.com#include <vector> 4411793Sbrandon.potter@amd.com 459356Snilay@cs.wisc.edu#include "base/statistics.hh" 468981Sandreas.hansson@arm.com#include "params/ThermalCapacitor.hh" 478981Sandreas.hansson@arm.com#include "params/ThermalModel.hh" 488981Sandreas.hansson@arm.com#include "params/ThermalReference.hh" 498981Sandreas.hansson@arm.com#include "params/ThermalResistor.hh" 508981Sandreas.hansson@arm.com#include "sim/clocked_object.hh" 518981Sandreas.hansson@arm.com#include "sim/power/thermal_entity.hh" 528981Sandreas.hansson@arm.com#include "sim/sim_object.hh" 538981Sandreas.hansson@arm.com 548981Sandreas.hansson@arm.comclass ThermalDomain; 5510902Sandreas.sandberg@arm.com 5610902Sandreas.sandberg@arm.com 578981Sandreas.hansson@arm.com/** 588981Sandreas.hansson@arm.com * A ThermalNode is used to connect thermal entities, such as 5910064Sandreas.hansson@arm.com * resistors, capacitors, references and domains. It is the circuital 6010902Sandreas.sandberg@arm.com * equivalent to a voltage node. 618981Sandreas.hansson@arm.com */ 628981Sandreas.hansson@arm.comclass ThermalNode : public SimObject 638981Sandreas.hansson@arm.com{ 648981Sandreas.hansson@arm.com public: 658981Sandreas.hansson@arm.com typedef SimObjectParams Params; 668981Sandreas.hansson@arm.com ThermalNode(const Params *p); 678981Sandreas.hansson@arm.com 688981Sandreas.hansson@arm.com int id; 698981Sandreas.hansson@arm.com bool isref; 708981Sandreas.hansson@arm.com double temp; 718981Sandreas.hansson@arm.com}; 728981Sandreas.hansson@arm.com 738981Sandreas.hansson@arm.com/** 748981Sandreas.hansson@arm.com * A ThermalResistor is used to model a thermal resistance between two 758981Sandreas.hansson@arm.com * thermal domains. This domains can be either a reference (fixed temp.) or 768981Sandreas.hansson@arm.com * a heat producer (power source). 7710994Sandreas.sandberg@arm.com */ 7810994Sandreas.sandberg@arm.comclass ThermalResistor : public SimObject, public ThermalEntity 7910994Sandreas.sandberg@arm.com{ 8010994Sandreas.sandberg@arm.com public: 8110994Sandreas.sandberg@arm.com typedef ThermalResistorParams Params; 8210994Sandreas.sandberg@arm.com ThermalResistor(const Params *p); 8310994Sandreas.sandberg@arm.com 849294Sandreas.hansson@arm.com void serialize(CheckpointOut &cp) const override; 859294Sandreas.hansson@arm.com void unserialize(CheckpointIn &cp) override; 868981Sandreas.hansson@arm.com 878981Sandreas.hansson@arm.com void setNodes(ThermalNode * n1, ThermalNode * n2) { 888981Sandreas.hansson@arm.com node1 = n1; 898981Sandreas.hansson@arm.com node2 = n2; 908981Sandreas.hansson@arm.com } 918981Sandreas.hansson@arm.com 928981Sandreas.hansson@arm.com LinearEquation getEquation(ThermalNode * tn, unsigned n, 938981Sandreas.hansson@arm.com double step) const override; 949294Sandreas.hansson@arm.com 959294Sandreas.hansson@arm.com private: 968981Sandreas.hansson@arm.com /* Resistance value in K/W */ 978981Sandreas.hansson@arm.com double _resistance; 988981Sandreas.hansson@arm.com /* Nodes connected to the resistor */ 998981Sandreas.hansson@arm.com ThermalNode * node1, * node2; 1008981Sandreas.hansson@arm.com}; 1018981Sandreas.hansson@arm.com 1028981Sandreas.hansson@arm.com/** 1038981Sandreas.hansson@arm.com * A ThermalCapacitor is used to model a thermal capacitance between two 1048981Sandreas.hansson@arm.com * thermal domains. This domains can be either a reference (fixed temp.) or 1058981Sandreas.hansson@arm.com * a heat producer (power source). 1068981Sandreas.hansson@arm.com */ 1078981Sandreas.hansson@arm.comclass ThermalCapacitor : public SimObject, public ThermalEntity 1088981Sandreas.hansson@arm.com{ 1098981Sandreas.hansson@arm.com public: 1108981Sandreas.hansson@arm.com typedef ThermalCapacitorParams Params; 1118981Sandreas.hansson@arm.com ThermalCapacitor(const Params *p); 1128981Sandreas.hansson@arm.com 1138981Sandreas.hansson@arm.com void serialize(CheckpointOut &cp) const override; 1148981Sandreas.hansson@arm.com void unserialize(CheckpointIn &cp) override; 1158981Sandreas.hansson@arm.com 11611804Srjthakur@google.com LinearEquation getEquation(ThermalNode * tn, unsigned n, 11711804Srjthakur@google.com double step) const override; 11811804Srjthakur@google.com 11911804Srjthakur@google.com void setNodes(ThermalNode * n1, ThermalNode * n2) { 12011804Srjthakur@google.com node1 = n1; 12111804Srjthakur@google.com node2 = n2; 12211804Srjthakur@google.com } 12311804Srjthakur@google.com 12411804Srjthakur@google.com private: 12511804Srjthakur@google.com /* Capacitance value in J/K */ 12611804Srjthakur@google.com double _capacitance; 12711804Srjthakur@google.com /* Nodes connected to the resistor */ 12811804Srjthakur@google.com ThermalNode * node1, * node2; 12911804Srjthakur@google.com}; 13011804Srjthakur@google.com 13111804Srjthakur@google.com/** 13211804Srjthakur@google.com * A ThermalReference is a thermal domain with fixed temperature. 13311804Srjthakur@google.com * It's the homologue to the voltage source in a circuit. 13411804Srjthakur@google.com */ 13511804Srjthakur@google.comclass ThermalReference : public SimObject, public ThermalEntity 13611804Srjthakur@google.com{ 13711804Srjthakur@google.com public: 13811804Srjthakur@google.com typedef ThermalReferenceParams Params; 13911804Srjthakur@google.com ThermalReference(const Params *p); 14011804Srjthakur@google.com 14111804Srjthakur@google.com void setNode(ThermalNode * n) { 14211804Srjthakur@google.com node = n; 14311804Srjthakur@google.com } 14411804Srjthakur@google.com 14511804Srjthakur@google.com LinearEquation getEquation(ThermalNode * tn, unsigned n, 14611804Srjthakur@google.com double step) const override; 14711804Srjthakur@google.com 14811804Srjthakur@google.com void serialize(CheckpointOut &cp) const override; 14911804Srjthakur@google.com void unserialize(CheckpointIn &cp) override; 15011804Srjthakur@google.com 15111804Srjthakur@google.com /* Fixed temperature value in centigrate degrees */ 15211804Srjthakur@google.com double _temperature; 15311804Srjthakur@google.com /* Nodes connected to the resistor */ 15411804Srjthakur@google.com ThermalNode * node; 15511804Srjthakur@google.com}; 15611804Srjthakur@google.com 15711804Srjthakur@google.com 15811804Srjthakur@google.com/** 15911804Srjthakur@google.com * A ThermalModel is the element which ties all thermal objects 16011804Srjthakur@google.com * together and provides the thermal solver to the system. 16111804Srjthakur@google.com * It is reponsible for updating temperature for all Thermal 16211804Srjthakur@google.com * Domains over time by reading power from simobjects. 16311804Srjthakur@google.com */ 16411804Srjthakur@google.comclass ThermalModel : public ClockedObject 16511804Srjthakur@google.com{ 16611804Srjthakur@google.com public: 16711804Srjthakur@google.com typedef ThermalModelParams Params; 16811804Srjthakur@google.com ThermalModel(const Params *p); 16911804Srjthakur@google.com 17011804Srjthakur@google.com void addDomain(ThermalDomain * d); 17111804Srjthakur@google.com void addReference(ThermalReference * r); 17211804Srjthakur@google.com void addCapacitor(ThermalCapacitor * c); 17311804Srjthakur@google.com void addResistor(ThermalResistor * r); 17411804Srjthakur@google.com 17511804Srjthakur@google.com void addNode(ThermalNode * n) { nodes.push_back(n); } 17611804Srjthakur@google.com 17711804Srjthakur@google.com double getTemp() const; 17811804Srjthakur@google.com 17911804Srjthakur@google.com void startup() override; 18011804Srjthakur@google.com void doStep(); 18111804Srjthakur@google.com 18211804Srjthakur@google.com void serialize(CheckpointOut &cp) const override; 18311804Srjthakur@google.com void unserialize(CheckpointIn &cp) override; 18411804Srjthakur@google.com private: 18511804Srjthakur@google.com 18611804Srjthakur@google.com /* Keep track of all components used for the thermal model */ 18711804Srjthakur@google.com std::vector <ThermalDomain *> domains; 18811804Srjthakur@google.com std::vector <ThermalReference *> references; 18911804Srjthakur@google.com std::vector <ThermalCapacitor *> capacitors; 19011804Srjthakur@google.com std::vector <ThermalResistor *> resistors; 19111804Srjthakur@google.com 19211804Srjthakur@google.com std::vector <ThermalEntity *> entities; 19311804Srjthakur@google.com 19411804Srjthakur@google.com /* Keep a list of the instantiated nodes */ 19511804Srjthakur@google.com std::vector <ThermalNode*> nodes; 19611804Srjthakur@google.com std::vector <ThermalNode*> eq_nodes; 19711804Srjthakur@google.com 19811804Srjthakur@google.com /** Stepping event to update the model values */ 19911804Srjthakur@google.com EventWrapper<ThermalModel, &ThermalModel::doStep> stepEvent; 20011804Srjthakur@google.com 20111804Srjthakur@google.com /** Step in seconds for thermal updates */ 20211804Srjthakur@google.com double _step; 20311804Srjthakur@google.com 20411804Srjthakur@google.com}; 20511804Srjthakur@google.com 20611804Srjthakur@google.com#endif 20711804Srjthakur@google.com