power_model.cc (11527:9007a9729815) power_model.cc (11800:54436a1784dc)
1/*
2 * Copyright (c) 2016 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: David Guillen Fandos
38 */
39
40#include "sim/power/power_model.hh"
41
42#include "base/statistics.hh"
43#include "params/PowerModel.hh"
44#include "params/PowerModelState.hh"
1/*
2 * Copyright (c) 2016 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * Authors: David Guillen Fandos
38 */
39
40#include "sim/power/power_model.hh"
41
42#include "base/statistics.hh"
43#include "params/PowerModel.hh"
44#include "params/PowerModelState.hh"
45#include "sim/sim_object.hh"
45#include "sim/clocked_object.hh"
46#include "sim/sub_system.hh"
47
48PowerModelState::PowerModelState(const Params *p)
49 : SimObject(p), _temp(0), clocked_object(NULL)
50{
51}
52
53PowerModel::PowerModel(const Params *p)
54 : SimObject(p), states_pm(p->pm), subsystem(p->subsystem),
55 clocked_object(NULL)
56{
57 panic_if(subsystem == NULL,
58 "Subsystem is NULL! This is not acceptable for a PowerModel!\n");
59 subsystem->registerPowerProducer(this);
60}
61
62void
63PowerModel::setClockedObject(ClockedObject * clkobj)
64{
65 this->clocked_object = clkobj;
66
67 for (auto & pms: states_pm)
68 pms->setClockedObject(clkobj);
69}
70
71void
72PowerModel::thermalUpdateCallback(const double & temp)
73{
74 for (auto & pms: states_pm)
75 pms->setTemperature(temp);
76}
77
78void
79PowerModel::regProbePoints()
80{
81 thermalListener.reset(new ThermalProbeListener (
82 *this, this->subsystem->getProbeManager(), "thermalUpdate"
83 ));
84}
85
86PowerModel*
87PowerModelParams::create()
88{
89 return new PowerModel(this);
90}
91
92double
93PowerModel::getDynamicPower() const
94{
95 assert(clocked_object);
96
97 std::vector<double> w = clocked_object->pwrStateWeights();
98
99 // Same number of states (excluding UNDEFINED)
100 assert(w.size() - 1 == states_pm.size());
101
102 // Make sure we have no UNDEFINED state
103 warn_if(w[Enums::PwrState::UNDEFINED] > 0,
104 "SimObject in UNDEFINED power state! Power figures might be wrong!\n");
105
106 double power = 0;
107 for (unsigned i = 0; i < states_pm.size(); i++)
108 if (w[i + 1] > 0.0f)
109 power += states_pm[i]->getDynamicPower() * w[i + 1];
110
111 return power;
112}
113
114double
115PowerModel::getStaticPower() const
116{
117 assert(clocked_object);
118
119 std::vector<double> w = clocked_object->pwrStateWeights();
120
121 // Same number of states (excluding UNDEFINED)
122 assert(w.size() - 1 == states_pm.size());
123
124 // Make sure we have no UNDEFINED state
125 if (w[0] > 0)
126 warn("SimObject in UNDEFINED power state! "
127 "Power figures might be wrong!\n");
128
129 // We have N+1 states, being state #0 the default 'UNDEFINED' state
130 double power = 0;
131 for (unsigned i = 0; i < states_pm.size(); i++)
132 // Don't evaluate power if the object hasn't been in that state
133 // This fixes issues with NaNs and similar.
134 if (w[i + 1] > 0.0f)
135 power += states_pm[i]->getStaticPower() * w[i + 1];
136
137 return power;
138}
46#include "sim/sub_system.hh"
47
48PowerModelState::PowerModelState(const Params *p)
49 : SimObject(p), _temp(0), clocked_object(NULL)
50{
51}
52
53PowerModel::PowerModel(const Params *p)
54 : SimObject(p), states_pm(p->pm), subsystem(p->subsystem),
55 clocked_object(NULL)
56{
57 panic_if(subsystem == NULL,
58 "Subsystem is NULL! This is not acceptable for a PowerModel!\n");
59 subsystem->registerPowerProducer(this);
60}
61
62void
63PowerModel::setClockedObject(ClockedObject * clkobj)
64{
65 this->clocked_object = clkobj;
66
67 for (auto & pms: states_pm)
68 pms->setClockedObject(clkobj);
69}
70
71void
72PowerModel::thermalUpdateCallback(const double & temp)
73{
74 for (auto & pms: states_pm)
75 pms->setTemperature(temp);
76}
77
78void
79PowerModel::regProbePoints()
80{
81 thermalListener.reset(new ThermalProbeListener (
82 *this, this->subsystem->getProbeManager(), "thermalUpdate"
83 ));
84}
85
86PowerModel*
87PowerModelParams::create()
88{
89 return new PowerModel(this);
90}
91
92double
93PowerModel::getDynamicPower() const
94{
95 assert(clocked_object);
96
97 std::vector<double> w = clocked_object->pwrStateWeights();
98
99 // Same number of states (excluding UNDEFINED)
100 assert(w.size() - 1 == states_pm.size());
101
102 // Make sure we have no UNDEFINED state
103 warn_if(w[Enums::PwrState::UNDEFINED] > 0,
104 "SimObject in UNDEFINED power state! Power figures might be wrong!\n");
105
106 double power = 0;
107 for (unsigned i = 0; i < states_pm.size(); i++)
108 if (w[i + 1] > 0.0f)
109 power += states_pm[i]->getDynamicPower() * w[i + 1];
110
111 return power;
112}
113
114double
115PowerModel::getStaticPower() const
116{
117 assert(clocked_object);
118
119 std::vector<double> w = clocked_object->pwrStateWeights();
120
121 // Same number of states (excluding UNDEFINED)
122 assert(w.size() - 1 == states_pm.size());
123
124 // Make sure we have no UNDEFINED state
125 if (w[0] > 0)
126 warn("SimObject in UNDEFINED power state! "
127 "Power figures might be wrong!\n");
128
129 // We have N+1 states, being state #0 the default 'UNDEFINED' state
130 double power = 0;
131 for (unsigned i = 0; i < states_pm.size(); i++)
132 // Don't evaluate power if the object hasn't been in that state
133 // This fixes issues with NaNs and similar.
134 if (w[i + 1] > 0.0f)
135 power += states_pm[i]->getStaticPower() * w[i + 1];
136
137 return power;
138}