gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
power_model.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2018, 2021 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 
38 #include "sim/power/power_model.hh"
39 
40 #include "base/statistics.hh"
41 #include "params/PowerModel.hh"
42 #include "params/PowerModelState.hh"
43 #include "sim/clocked_object.hh"
44 #include "sim/sub_system.hh"
45 
47  : SimObject(p), _temp(0), clocked_object(NULL),
48  ADD_STAT(dynamicPower, UNIT_WATT,
49  "Dynamic power for this object (Watts)"),
50  ADD_STAT(staticPower, UNIT_WATT, "Static power for this object (Watts)")
51 {
56 }
57 
59  : SimObject(p), states_pm(p.pm), subsystem(p.subsystem),
60  clocked_object(NULL), power_model_type(p.pm_type),
61  ADD_STAT(dynamicPower, UNIT_WATT,
62  "Dynamic power for this power state"),
63  ADD_STAT(staticPower, UNIT_WATT,
64  "Static power for this power state")
65 {
66  panic_if(subsystem == NULL,
67  "Subsystem is NULL! This is not acceptable for a PowerModel!\n");
69  // The temperature passed here will be overwritten, if there is
70  // a thermal model present
71  for (auto & pms: states_pm){
72  pms->setTemperature(p.ambient_temp);
73  }
74 
79 
80 }
81 
82 void
84 {
85  this->clocked_object = clkobj;
86 
87  for (auto & pms: states_pm)
88  pms->setClockedObject(clkobj);
89 }
90 
91 void
93 {
94  for (auto & pms: states_pm)
95  pms->setTemperature(temp);
96 }
97 
98 void
100 {
102  *this, this->subsystem->getProbeManager(), "thermalUpdate"
103  ));
104 }
105 
106 double
108 {
109  assert(clocked_object);
110 
111  if (power_model_type == Enums::PMType::Static) {
112  // This power model only collects static data
113  return 0;
114  }
116 
117  // Same number of states (excluding UNDEFINED)
118  assert(w.size() - 1 == states_pm.size());
119 
120  // Make sure we have no UNDEFINED state
121  warn_if(w[Enums::PwrState::UNDEFINED] > 0,
122  "SimObject in UNDEFINED power state! Power figures might be wrong!\n");
123 
124  double power = 0;
125  for (unsigned i = 0; i < states_pm.size(); i++)
126  if (w[i + 1] > 0.0f)
127  power += states_pm[i]->getDynamicPower() * w[i + 1];
128 
129  return power;
130 }
131 
132 double
134 {
135  assert(clocked_object);
136 
138 
139  if (power_model_type == Enums::PMType::Dynamic) {
140  // This power model only collects dynamic data
141  return 0;
142  }
143 
144  // Same number of states (excluding UNDEFINED)
145  assert(w.size() - 1 == states_pm.size());
146 
147  // Make sure we have no UNDEFINED state
148  if (w[0] > 0)
149  warn("SimObject in UNDEFINED power state! "
150  "Power figures might be wrong!\n");
151 
152  // We have N+1 states, being state #0 the default 'UNDEFINED' state
153  double power = 0;
154  for (unsigned i = 0; i < states_pm.size(); i++)
155  // Don't evaluate power if the object hasn't been in that state
156  // This fixes issues with NaNs and similar.
157  if (w[i + 1] > 0.0f)
158  power += states_pm[i]->getStaticPower() * w[i + 1];
159 
160  return power;
161 }
PowerModel::dynamicPower
Stats::Value dynamicPower
Definition: power_model.hh:164
warn
#define warn(...)
Definition: logging.hh:239
Stats::ValueBase::method
Derived & method(T *obj, V(T::*method)() const)
Extended functor that calls the specified method of the provided object.
Definition: statistics.hh:747
power_model.hh
PowerModel::clocked_object
ClockedObject * clocked_object
The clocked object we belong to.
Definition: power_model.hh:159
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
PowerModelState::Params
PowerModelStateParams Params
Definition: power_model.hh:59
std::vector< double >
PowerModel::getDynamicPower
double getDynamicPower() const
Get the dynamic power consumption.
Definition: power_model.cc:107
PowerModel::setClockedObject
void setClockedObject(ClockedObject *clkobj)
Definition: power_model.cc:83
PowerModel::PowerModel
PowerModel(const Params &p)
Definition: power_model.cc:58
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
Temperature
The class stores temperatures in Kelvin and provides helper methods to convert to/from Celsius.
Definition: temperature.hh:47
PowerModel::thermalListener
std::unique_ptr< ThermalProbeListener > thermalListener
Listener to catch temperature changes in the SubSystem.
Definition: power_model.hh:153
PowerState::getWeights
std::vector< double > getWeights() const
Returns the percentage residency for each power state.
Definition: power_state.cc:201
PowerModel::ThermalProbeListener
Listener class to catch thermal events.
Definition: power_model.hh:133
UNIT_WATT
#define UNIT_WATT
Definition: units.hh:50
MipsISA::w
Bitfield< 0 > w
Definition: pra_constants.hh:278
ADD_STAT
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:71
statistics.hh
PowerModelState::staticPower
Stats::Value staticPower
Definition: power_model.hh:95
PowerModelState::getStaticPower
virtual double getStaticPower() const =0
Get the static power consumption.
SimObject::getProbeManager
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:114
ClockedObject::powerState
PowerState * powerState
Definition: clocked_object.hh:242
warn_if
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition: logging.hh:263
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
PowerModelState::PowerModelState
PowerModelState(const Params &p)
Definition: power_model.cc:46
sub_system.hh
PowerModel::power_model_type
Enums::PMType power_model_type
The type of power model - collects all power, static or dynamic only.
Definition: power_model.hh:162
SubSystem::registerPowerProducer
void registerPowerProducer(PowerModel *pm)
Definition: sub_system.hh:67
clocked_object.hh
PowerModelState::getDynamicPower
virtual double getDynamicPower() const =0
Get the dynamic power consumption.
PowerModel::Params
PowerModelParams Params
Definition: power_model.hh:108
PowerModel::states_pm
std::vector< PowerModelState * > states_pm
Actual power models (one per power state)
Definition: power_model.hh:150
PowerModel::staticPower
Stats::Value staticPower
Definition: power_model.hh:164
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
PowerModel::getStaticPower
double getStaticPower() const
Get the static power consumption.
Definition: power_model.cc:133
power
uint64_t power(uint32_t n, uint32_t e)
Definition: intmath.hh:43
PowerModelState::dynamicPower
Stats::Value dynamicPower
Definition: power_model.hh:95
PowerModel::regProbePoints
virtual void regProbePoints()
Register probe points for this object.
Definition: power_model.cc:99
PowerModel::thermalUpdateCallback
void thermalUpdateCallback(const Temperature &temp)
Definition: power_model.cc:92
PowerModel::subsystem
SubSystem * subsystem
The subsystem this power model belongs to.
Definition: power_model.hh:156
ArmISA::f
Bitfield< 6 > f
Definition: miscregs_types.hh:64
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:141

Generated on Tue Mar 23 2021 19:41:28 for gem5 by doxygen 1.8.17