sim: Adding thermal model support

This patch adds basic thermal support to gem5. It models energy dissipation
through a circuital equivalent, which allows us to use RC networks.
This lays down the basic infrastructure to do so, but it does not "work" due
to the lack of power models. For now some hardcoded number is used as a PoC.
The solver is embedded in the patch.
This commit is contained in:
David Guillen Fandos 2015-05-12 10:26:47 +01:00
parent 85dadcd381
commit 75c82f1fe3
17 changed files with 1327 additions and 3 deletions

View file

@ -66,6 +66,7 @@ Source('stat_control.cc')
Source('stat_register.cc', skip_no_python=True)
Source('clock_domain.cc')
Source('voltage_domain.cc')
Source('linear_solver.cc')
Source('system.cc')
Source('dvfs_handler.cc')

View file

@ -37,6 +37,7 @@
#
from m5.SimObject import SimObject
from m5.params import *
# An empty simobject. Used for organizing simobjects
# into logical groups as subsystems of a larger
@ -50,3 +51,7 @@ class SubSystem(SimObject):
type = 'SubSystem'
cxx_header = "sim/sub_system.hh"
abstract = False
# Thermal doamin associated to this object, inheriting the parent's
# clock domain by default
thermal_domain = Param.ThermalDomain(NULL, "Thermal domain")

View file

@ -59,6 +59,10 @@ class System(MemObject):
"All memories in the system")
mem_mode = Param.MemoryMode('atomic', "The mode the memory system is in")
thermal_model = Param.ThermalModel(NULL, "Thermal model")
thermal_components = VectorParam.SimObject([],
"A collection of all thermal components in the system.")
# When reserving memory on the host, we have the option of
# reserving swap space or not (by passing MAP_NORESERVE to
# mmap). By enabling this flag, we accomodate cases where a large

87
src/sim/linear_solver.cc Normal file
View file

@ -0,0 +1,87 @@
/*
* Copyright (c) 2015 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: David Guillen Fandos
*/
#include "sim/linear_solver.hh"
std::vector <double>
LinearSystem::solve() const
{
// Solve using gauss elimination, not ideal for big matrices
std::vector < LinearEquation > smatrix = this->matrix;
unsigned order = smatrix.size();
for (unsigned row = 0; row < order - 1; row++) {
// Look for a non-zero row, and swap
for (unsigned i = row; i < order; i++) {
if (smatrix[i][row] != 0.0f) {
if (i != row) {
LinearEquation tmp = smatrix[i];
smatrix[i] = smatrix[row];
smatrix[row] = tmp;
}
break;
}
}
// Divide row by leading number to make it 1.0
smatrix[row] *= (1.0f / smatrix[row][row]);
// Add it (properly scaled) to the rows below
for (unsigned i = row + 1; i < order; i++) {
LinearEquation t = smatrix[row];
t *= -1.0f * smatrix[i][row];
smatrix[i] = smatrix[i] + t;
}
}
// smatrix is now a triangular matrix with diagonal being 1
// Just backproagate variable values from order-1 till 0
std::vector <double> ret(order, 0.0f);
for (int row = order - 1; row >= 0; row--) {
// Unknown value
ret[row] = -smatrix[row][smatrix[row].cnt()] / smatrix[row][row];
// Propagate variable in the cnt term
for (int i = row - 1; i >= 0; i--) {
smatrix[i][smatrix[i].cnt()] += ret[row] * smatrix[i][row];
smatrix[i][row] = 0.0f;
}
}
return ret;
}

134
src/sim/linear_solver.hh Normal file
View file

@ -0,0 +1,134 @@
/*
* Copyright (c) 2015 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: David Guillen Fandos
*/
#ifndef __SIM_LINEAR_SOLVER_HH__
#define __SIM_LINEAR_SOLVER_HH__
#include <cassert>
#include <sstream>
#include <string>
#include <vector>
/**
* This class describes a linear equation with constant coefficients.
* The equation has a certain (variable) number of unkowns and it can hold
* N+1 coefficients.
*/
class LinearEquation {
public:
LinearEquation(unsigned unknowns) {
eq = std::vector <double> (unknowns + 1, 0);
}
// Add two equations
LinearEquation operator+ (const LinearEquation& rhs) {
assert(this->eq.size() == rhs.eq.size());
LinearEquation res(this->eq.size() - 1);
for (unsigned i = 0; i < res.eq.size(); i++)
res.eq[i] = this->eq[i] + rhs.eq[i];
return res;
}
// Multiply the equation by a constant
LinearEquation & operator*= (const double cnt) {
for (auto & c: eq)
c *= cnt;
return *this;
}
// Access a certain equation coefficient
double & operator[] (unsigned unkw) {
assert(unkw < eq.size());
return eq[unkw];
}
// Get a string representation
std::string toStr() const {
std::ostringstream oss;
for (unsigned i = 0; i < eq.size(); i++) {
if (i)
oss << " + ";
oss << eq[i];
if (i != eq.size() - 1)
oss << "*x" << i;
}
oss << " = 0";
return oss.str();
}
// Index for the constant term
unsigned cnt() const { return eq.size() - 1; }
private:
/** Coefficients */
std::vector <double> eq;
};
class LinearSystem {
public:
LinearSystem(unsigned unknowns) {
for (unsigned i = 0; i < unknowns; i++)
matrix.push_back(LinearEquation(unknowns));
}
LinearEquation & operator[] (unsigned eq) {
assert(eq < matrix.size());
return matrix[eq];
}
std::string toStr() const {
std::string r;
for (auto & eq: matrix)
r += eq.toStr() + "\n";
return r;
}
std::vector <double> solve() const;
private:
std::vector < LinearEquation > matrix;
};
#endif

39
src/sim/power/SConscript Normal file
View file

@ -0,0 +1,39 @@
# -*- mode:python -*-
# Copyright (c) 2015 ARM Limited
# All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: David Guillen Fandos
Import('*')
SimObject('ThermalDomain.py')
SimObject('ThermalModel.py')
Source('thermal_domain.cc')
Source('thermal_model.cc')
DebugFlag('ThermalDomain')

View file

@ -0,0 +1,53 @@
# Copyright (c) 2015 ARM Limited
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
# not be construed as granting a license to any other intellectual
# property including but not limited to intellectual property relating
# to a hardware implementation of the functionality of the software
# licensed hereunder. You may use the software subject to the license
# terms below provided that you ensure that this notice is replicated
# unmodified and in its entirety in all distributions of the software,
# modified or unmodified, in source code or in binary form.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: David Guillen Fandos
from m5.SimObject import SimObject
from m5.params import *
# Represents a group of simobj which produce heat
class ThermalDomain(SimObject):
type = 'ThermalDomain'
cxx_header = "sim/power/thermal_domain.hh"
@classmethod
def export_methods(cls, code):
code('''
void setNode(ThermalNode * node);
''')
# Static temperature which may change over time
initial_temperature = Param.Float(25.0, "Initial temperature")

View file

@ -0,0 +1,168 @@
# Copyright (c) 2015 ARM Limited
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
# not be construed as granting a license to any other intellectual
# property including but not limited to intellectual property relating
# to a hardware implementation of the functionality of the software
# licensed hereunder. You may use the software subject to the license
# terms below provided that you ensure that this notice is replicated
# unmodified and in its entirety in all distributions of the software,
# modified or unmodified, in source code or in binary form.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: David Guillen Fandos
from m5.SimObject import SimObject
from ClockedObject import ClockedObject
from m5.params import *
from m5.objects import ThermalDomain
# Represents a thermal node
class ThermalNode(SimObject):
type = 'ThermalNode'
cxx_header = "sim/power/thermal_model.hh"
# Represents a thermal resistor
class ThermalResistor(SimObject):
type = 'ThermalResistor'
cxx_header = "sim/power/thermal_model.hh"
@classmethod
def export_methods(cls, code):
code('''
void setNodes(ThermalNode * node1, ThermalNode * node2);
''')
resistance = Param.Float(1.0, "Thermal resistance, expressed in Kelvin per Watt")
# Represents a thermal capacitor
class ThermalCapacitor(SimObject):
type = 'ThermalCapacitor'
cxx_header = "sim/power/thermal_model.hh"
@classmethod
def export_methods(cls, code):
code('''
void setNodes(ThermalNode * node1, ThermalNode * node2);
''')
capacitance = Param.Float(1.0, "Thermal capacitance, expressed in Joules per Kelvin")
# Represents a fixed temperature node (ie. air)
class ThermalReference(SimObject, object):
type = 'ThermalReference'
cxx_header = "sim/power/thermal_model.hh"
@classmethod
def export_methods(cls, code):
code('''
void setNode(ThermalNode * node);
''')
# Static temperature which may change over time
temperature = Param.Float(25.0, "Operational temperature in Celsius")
# Represents a thermal capacitor
class ThermalModel(ClockedObject):
type = 'ThermalModel'
cxx_header = "sim/power/thermal_model.hh"
@classmethod
def export_methods(cls, code):
code('''
void addCapacitor(ThermalCapacitor *obj);
void addResistor(ThermalResistor *obj);
void addReference(ThermalReference *obj);
void addDomain(ThermalDomain *obj);
void addNode(ThermalNode *obj);
void doStep();
''')
step = Param.Float(0.01, "Simulation step (in seconds) for thermal simulation")
def populate(self):
if not hasattr(self,"_capacitors"): self._capacitors = []
if not hasattr(self,"_resistors"): self._resistors = []
if not hasattr(self,"_domains"): self._domains = []
if not hasattr(self,"_references"): self._references = []
if not hasattr(self,"_nodes"): self._nodes = []
def init(self):
self.populate()
for ref, node in self._references:
ref.getCCObject().setNode(node.getCCObject())
self.getCCObject().addReference(ref.getCCObject())
for dom, node in self._domains:
dom.getCCObject().setNode(node.getCCObject())
self.getCCObject().addDomain(dom.getCCObject())
for cap, node1, node2 in self._capacitors:
cap.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject())
self.getCCObject().addCapacitor(cap.getCCObject())
for res, node1, node2 in self._resistors:
res.getCCObject().setNodes(node1.getCCObject(), node2.getCCObject())
self.getCCObject().addResistor(res.getCCObject())
for node in self._nodes:
self.getCCObject().addNode(node.getCCObject())
def addCapacitor(self, cap, node1, node2):
self.populate()
self._capacitors.append( (cap, node1, node2) )
self._parent.thermal_components.append(cap)
self.addNodes(node1,node2)
def addResistor(self, res, node1, node2):
self.populate()
self._resistors.append( (res, node1, node2) )
self._parent.thermal_components.append(res)
self.addNodes(node1,node2)
def addReference(self, ref, node):
self.populate()
self._references.append( (ref, node) )
self._parent.thermal_components.append(ref)
self.addNodes(node)
def addDomain(self, dom, node):
self.populate()
self._domains.append( (dom, node) )
self.addNodes(node)
def addNodes(self, *nodes):
for node in nodes:
if node not in self._nodes:
self._nodes.append(node)
self._parent.thermal_components.append(node)
def doStep(self):
self.getCCObject().doStep()

View file

@ -0,0 +1,114 @@
/*
* Copyright (c) 2015 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: David Guillen Fandos
*/
#include "sim/power/thermal_domain.hh"
#include <algorithm>
#include "base/statistics.hh"
#include "debug/ThermalDomain.hh"
#include "params/ThermalDomain.hh"
#include "sim/power/thermal_model.hh"
#include "sim/sim_object.hh"
ThermalDomain::ThermalDomain(const Params *p)
: SimObject(p), _initTemperature(p->initial_temperature),
node(NULL), subsystem(NULL)
{
}
double
ThermalDomain::currentTemperature() const
{
return node->temp;
}
void
ThermalDomain::setSubSystem(SubSystem * ss)
{
assert(!this->subsystem);
this->subsystem = ss;
ppThermalUpdate = new ProbePointArg<double>(subsystem->getProbeManager(),
"thermalUpdate");
}
void
ThermalDomain::regStats()
{
currentTemp
.method(this, &ThermalDomain::currentTemperature)
.name(params()->name + ".temp")
.desc("Temperature in centigrate degrees")
;
}
void
ThermalDomain::emitUpdate()
{
ppThermalUpdate->notify(node->temp);
}
ThermalDomain *
ThermalDomainParams::create()
{
return new ThermalDomain(this);
}
void
ThermalDomain::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(_initTemperature);
}
void
ThermalDomain::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(_initTemperature);
}
LinearEquation
ThermalDomain::getEquation(ThermalNode * tn, unsigned n, double step) const
{
LinearEquation eq(n);
if (tn == node)
eq[eq.cnt()] = 1.75f; // Fake 1.75 Watts for now, to be changed to PM
return eq;
}

View file

@ -0,0 +1,115 @@
/*
* Copyright (c) 2015 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: David Guillen Fandos
*/
#ifndef __SIM_THERMAL_DOMAIN_HH__
#define __SIM_THERMAL_DOMAIN_HH__
#include <vector>
#include "base/statistics.hh"
#include "params/ThermalDomain.hh"
#include "sim/power/thermal_entity.hh"
#include "sim/probe/probe.hh"
#include "sim/sim_object.hh"
#include "sim/sub_system.hh"
class ThermalNode;
/**
* A ThermalDomain is used to group objects under that operate under
* the same temperature. Theses domains can be tied together using thermal
* models (such as RC) to model temperature across components.
*/
class ThermalDomain : public SimObject, public ThermalEntity
{
public:
typedef ThermalDomainParams Params;
ThermalDomain(const Params *p);
/**
* Get the startup temperature.
*
* @return Initial temperature of the domain
*/
double initialTemperature() const { return _initTemperature; }
/**
* Get the current temperature.
*
* @return Initial temperature of the domain
*/
double currentTemperature() const;
/** Set/Get circuit node associated with this domain */
void setNode(ThermalNode * n) { node = n; }
ThermalNode * getNode() const { return node; }
/** Get nodal equation imposed by this node */
LinearEquation getEquation(ThermalNode * tn, unsigned n,
double step) const;
/**
* Emit a temperature update through probe points interface
*/
void emitUpdate();
/**
* Set the SubSystem reference we belong to
*/
void setSubSystem(SubSystem * ss);
void regStats();
void serialize(CheckpointOut &cp) const override;
void unserialize(CheckpointIn &cp) override;
private:
double _initTemperature;
ThermalNode * node;
SubSystem * subsystem;
/** Stat for reporting voltage of the domain */
Stats::Value currentTemp;
/** Probe to signal for temperature changes in this domain */
ProbePointArg<double> *ppThermalUpdate;
};
#endif

View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2015 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: David Guillen Fandos
*/
#ifndef __SIM_THERMAL_ENTITY_HH__
#define __SIM_THERMAL_ENTITY_HH__
#include "sim/linear_solver.hh"
class ThermalNode;
/**
* An abstract class that represents any thermal entity which is used
* in the circuital thermal equivalent model. It is necessary for
* ThermalModel to be able to solve the circuit.
*/
class ThermalEntity
{
public:
// Get the equation given a node and a step in seconds (assuming N nodes)
virtual LinearEquation getEquation(ThermalNode *tn, unsigned n,
double step) const = 0;
};
#endif

View file

@ -0,0 +1,319 @@
/*
* Copyright (c) 2015 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: David Guillen Fandos
*/
#include "sim/power/thermal_model.hh"
#include "base/statistics.hh"
#include "params/ThermalCapacitor.hh"
#include "params/ThermalNode.hh"
#include "params/ThermalReference.hh"
#include "params/ThermalResistor.hh"
#include "sim/clocked_object.hh"
#include "sim/linear_solver.hh"
#include "sim/power/thermal_domain.hh"
#include "sim/sim_object.hh"
/**
* ThermalNode
*/
ThermalNode::ThermalNode(const Params *p)
: SimObject(p), id(-1), isref(false), temp(0.0f)
{
}
ThermalNode *
ThermalNodeParams::create()
{
return new ThermalNode(this);
}
/**
* ThermalReference
*/
ThermalReference::ThermalReference(const Params *p)
: SimObject(p), _temperature(p->temperature), node(NULL)
{
}
ThermalReference *
ThermalReferenceParams::create()
{
return new ThermalReference(this);
}
void
ThermalReference::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(_temperature);
}
void
ThermalReference::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(_temperature);
}
LinearEquation
ThermalReference::getEquation(ThermalNode * n, unsigned nnodes,
double step) const {
// Just return an empty equation
return LinearEquation(nnodes);
}
/**
* ThermalResistor
*/
ThermalResistor::ThermalResistor(const Params *p)
: SimObject(p), _resistance(p->resistance), node1(NULL), node2(NULL)
{
}
ThermalResistor *
ThermalResistorParams::create()
{
return new ThermalResistor(this);
}
void
ThermalResistor::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(_resistance);
}
void
ThermalResistor::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(_resistance);
}
LinearEquation
ThermalResistor::getEquation(ThermalNode * n, unsigned nnodes,
double step) const
{
// i[n] = (Vn2 - Vn1)/R
LinearEquation eq(nnodes);
if (n != node1 && n != node2)
return eq;
if (node1->isref)
eq[eq.cnt()] += -node1->temp / _resistance;
else
eq[node1->id] += -1.0f / _resistance;
if (node2->isref)
eq[eq.cnt()] += node2->temp / _resistance;
else
eq[node2->id] += 1.0f / _resistance;
// We've assumed n was node1, reverse if necessary
if (n == node2)
eq *= -1.0f;
return eq;
}
/**
* ThermalCapacitor
*/
ThermalCapacitor::ThermalCapacitor(const Params *p)
: SimObject(p), _capacitance(p->capacitance), node1(NULL), node2(NULL)
{
}
ThermalCapacitor *
ThermalCapacitorParams::create()
{
return new ThermalCapacitor(this);
}
void
ThermalCapacitor::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(_capacitance);
}
void
ThermalCapacitor::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(_capacitance);
}
LinearEquation
ThermalCapacitor::getEquation(ThermalNode * n, unsigned nnodes,
double step) const
{
// i(t) = C * d(Vn2 - Vn1)/dt
// i[n] = C/step * (Vn2 - Vn1 - Vn2[n-1] + Vn1[n-1])
LinearEquation eq(nnodes);
if (n != node1 && n != node2)
return eq;
eq[eq.cnt()] += _capacitance / step * (node1->temp - node2->temp);
if (node1->isref)
eq[eq.cnt()] += _capacitance / step * (-node1->temp);
else
eq[node1->id] += -1.0f * _capacitance / step;
if (node2->isref)
eq[eq.cnt()] += _capacitance / step * (node2->temp);
else
eq[node2->id] += 1.0f * _capacitance / step;
// We've assumed n was node1, reverse if necessary
if (n == node2)
eq *= -1.0f;
return eq;
}
/**
* ThermalModel
*/
ThermalModel::ThermalModel(const Params *p)
: ClockedObject(p), stepEvent(this), _step(p->step)
{
}
ThermalModel *
ThermalModelParams::create()
{
return new ThermalModel(this);
}
void
ThermalModel::serialize(CheckpointOut &cp) const
{
SERIALIZE_SCALAR(_step);
}
void
ThermalModel::unserialize(CheckpointIn &cp)
{
UNSERIALIZE_SCALAR(_step);
}
void
ThermalModel::doStep()
{
// Calculate new temperatures!
// For each node in the system, create the kirchhoff nodal equation
LinearSystem ls(eq_nodes.size());
for (unsigned i = 0; i < eq_nodes.size(); i++) {
auto n = eq_nodes[i];
LinearEquation node_equation (eq_nodes.size());
for (auto e : entities) {
LinearEquation eq = e->getEquation(n, eq_nodes.size(), _step);
node_equation = node_equation + eq;
}
ls[i] = node_equation;
}
// Get temperatures for this iteration
std::vector <double> temps = ls.solve();
for (unsigned i = 0; i < eq_nodes.size(); i++)
eq_nodes[i]->temp = temps[i];
// Schedule next computation
schedule(stepEvent, curTick() + SimClock::Int::s * _step);
// Notify everybody
for (auto dom : domains)
dom->emitUpdate();
}
void
ThermalModel::startup()
{
// Look for nodes connected to voltage references, these
// can be just set to the reference value (no nodal equation)
for (auto ref : references) {
ref->node->temp = ref->_temperature;
ref->node->isref = true;
}
// Setup the initial temperatures
for (auto dom : domains)
dom->getNode()->temp = dom->initialTemperature();
// Create a list of unknown temperature nodes
for (auto n : nodes) {
bool found = false;
for (auto ref : references)
if (ref->node == n) {
found = true;
break;
}
if (!found)
eq_nodes.push_back(n);
}
// Assign each node an ID
for (unsigned i = 0; i < eq_nodes.size(); i++)
eq_nodes[i]->id = i;
// Schedule first thermal update
schedule(stepEvent, curTick() + SimClock::Int::s * _step);
}
void ThermalModel::addDomain(ThermalDomain * d) {
domains.push_back(d);
entities.push_back(d);
}
void ThermalModel::addReference(ThermalReference * r) {
references.push_back(r);
entities.push_back(r);
}
void ThermalModel::addCapacitor(ThermalCapacitor * c) {
capacitors.push_back(c);
entities.push_back(c);
}
void ThermalModel::addResistor(ThermalResistor * r) {
resistors.push_back(r);
entities.push_back(r);
}
double ThermalModel::getTemp() const {
// Just pick the highest temperature
double temp = 0;
for (auto & n : eq_nodes)
temp = std::max(temp, n->temp);
return temp;
}

View file

@ -0,0 +1,206 @@
/*
* Copyright (c) 2015 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: David Guillen Fandos
*/
#ifndef __SIM_THERMAL_MODEL_HH__
#define __SIM_THERMAL_MODEL_HH__
#include <vector>
#include "base/statistics.hh"
#include "params/ThermalCapacitor.hh"
#include "params/ThermalModel.hh"
#include "params/ThermalReference.hh"
#include "params/ThermalResistor.hh"
#include "sim/clocked_object.hh"
#include "sim/power/thermal_entity.hh"
#include "sim/sim_object.hh"
class ThermalDomain;
/**
* A ThermalNode is used to connect thermal entities, such as
* resistors, capacitors, references and domains. It is the circuital
* equivalent to a voltage node.
*/
class ThermalNode : public SimObject
{
public:
typedef SimObjectParams Params;
ThermalNode(const Params *p);
int id;
bool isref;
double temp;
};
/**
* A ThermalResistor is used to model a thermal resistance between two
* thermal domains. This domains can be either a reference (fixed temp.) or
* a heat producer (power source).
*/
class ThermalResistor : public SimObject, public ThermalEntity
{
public:
typedef ThermalResistorParams Params;
ThermalResistor(const Params *p);
void serialize(CheckpointOut &cp) const override;
void unserialize(CheckpointIn &cp) override;
void setNodes(ThermalNode * n1, ThermalNode * n2) {
node1 = n1;
node2 = n2;
}
LinearEquation getEquation(ThermalNode * tn, unsigned n,
double step) const;
private:
/* Resistance value in K/W */
double _resistance;
/* Nodes connected to the resistor */
ThermalNode * node1, * node2;
};
/**
* A ThermalCapacitor is used to model a thermal capacitance between two
* thermal domains. This domains can be either a reference (fixed temp.) or
* a heat producer (power source).
*/
class ThermalCapacitor : public SimObject, public ThermalEntity
{
public:
typedef ThermalCapacitorParams Params;
ThermalCapacitor(const Params *p);
void serialize(CheckpointOut &cp) const override;
void unserialize(CheckpointIn &cp) override;
LinearEquation getEquation(ThermalNode * tn, unsigned n,
double step) const;
void setNodes(ThermalNode * n1, ThermalNode * n2) {
node1 = n1;
node2 = n2;
}
private:
/* Capacitance value in J/K */
double _capacitance;
/* Nodes connected to the resistor */
ThermalNode * node1, * node2;
};
/**
* A ThermalReference is a thermal domain with fixed temperature.
* It's the homologue to the voltage source in a circuit.
*/
class ThermalReference : public SimObject, public ThermalEntity
{
public:
typedef ThermalReferenceParams Params;
ThermalReference(const Params *p);
void setNode(ThermalNode * n) {
node = n;
}
LinearEquation getEquation(ThermalNode * tn, unsigned n,
double step) const;
void serialize(CheckpointOut &cp) const override;
void unserialize(CheckpointIn &cp) override;
/* Fixed temperature value in centigrate degrees */
double _temperature;
/* Nodes connected to the resistor */
ThermalNode * node;
};
/**
* A ThermalModel is the element which ties all thermal objects
* together and provides the thermal solver to the system.
* It is reponsible for updating temperature for all Thermal
* Domains over time by reading power from simobjects.
*/
class ThermalModel : public ClockedObject
{
public:
typedef ThermalModelParams Params;
ThermalModel(const Params *p);
void addDomain(ThermalDomain * d);
void addReference(ThermalReference * r);
void addCapacitor(ThermalCapacitor * c);
void addResistor(ThermalResistor * r);
void addNode(ThermalNode * n) { nodes.push_back(n); }
double getTemp() const;
void startup();
void doStep();
void serialize(CheckpointOut &cp) const override;
void unserialize(CheckpointIn &cp) override;
private:
/* Keep track of all components used for the thermal model */
std::vector <ThermalDomain *> domains;
std::vector <ThermalReference *> references;
std::vector <ThermalCapacitor *> capacitors;
std::vector <ThermalResistor *> resistors;
std::vector <ThermalEntity *> entities;
/* Keep a list of the instantiated nodes */
std::vector <ThermalNode*> nodes;
std::vector <ThermalNode*> eq_nodes;
/** Stepping event to update the model values */
EventWrapper<ThermalModel, &ThermalModel::doStep> stepEvent;
/** Step in seconds for thermal updates */
double _step;
};
#endif

View file

@ -39,6 +39,15 @@
#include "params/SubSystem.hh"
#include "sim/sub_system.hh"
#include "sim/power/thermal_domain.hh"
SubSystem::SubSystem(const Params *p)
: SimObject(p)
{
// Link thermalDomain <-> SubSystem
if (p->thermal_domain)
p->thermal_domain->setSubSystem(this);
}
SubSystem *
SubSystemParams::create()

View file

@ -45,6 +45,8 @@
#ifndef __SIM_SUB_SYSTEM_HH__
#define __SIM_SUB_SYSTEM_HH__
#include "params/SubSystem.hh"
#include "sim/power/thermal_domain.hh"
#include "sim/sim_object.hh"
/**
@ -54,9 +56,8 @@
class SubSystem : public SimObject
{
public:
SubSystem(const Params *p) :
SimObject(p)
{}
typedef SubSystemParams Params;
SubSystem(const Params *p);
};
#endif

View file

@ -95,6 +95,7 @@ System::System(Params *p)
workItemsBegin(0),
workItemsEnd(0),
numWorkIds(p->num_work_ids),
thermalModel(p->thermal_model),
_params(p),
totalNumInsts(0),
instEventQueue("system instruction-based event queue")

View file

@ -293,6 +293,11 @@ class System : public MemObject
*/
Addr getPageShift() const { return TheISA::PageShift; }
/**
* The thermal model used for this system (if any).
*/
ThermalModel * getThermalModel() const { return thermalModel; }
protected:
PhysicalMemory physmem;
@ -313,6 +318,8 @@ class System : public MemObject
*/
std::vector<std::string> masterIds;
ThermalModel * thermalModel;
public:
/** Request an id used to create a request object in the system. All objects