gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
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
46namespace gem5
47{
48
50 : SimObject(p), _temp(0), clocked_object(NULL),
51 ADD_STAT(dynamicPower, statistics::units::Watt::get(),
52 "Dynamic power for this object (Watts)"),
53 ADD_STAT(staticPower, statistics::units::Watt::get(),
54 "Static power for this object (Watts)")
55{
60}
61
63 : SimObject(p), states_pm(p.pm), subsystem(p.subsystem),
64 clocked_object(NULL), power_model_type(p.pm_type),
65 ADD_STAT(dynamicPower, statistics::units::Watt::get(),
66 "Dynamic power for this power state"),
67 ADD_STAT(staticPower, statistics::units::Watt::get(),
68 "Static power for this power state")
69{
70 panic_if(subsystem == NULL,
71 "Subsystem is NULL! This is not acceptable for a PowerModel!\n");
73 // The temperature passed here will be overwritten, if there is
74 // a thermal model present
75 for (auto & pms: states_pm){
76 pms->setTemperature(p.ambient_temp);
77 }
78
83
84}
85
86void
88{
89 this->clocked_object = clkobj;
90
91 for (auto & pms: states_pm)
92 pms->setClockedObject(clkobj);
93}
94
95void
97{
98 for (auto & pms: states_pm)
99 pms->setTemperature(temp);
100}
101
102void
104{
106 *this, this->subsystem->getProbeManager(), "thermalUpdate"
107 ));
108}
109
110double
112{
113 assert(clocked_object);
114
115 if (power_model_type == enums::PMType::Static) {
116 // This power model only collects static data
117 return 0;
118 }
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 warn_if(w[enums::PwrState::UNDEFINED] > 0,
126 "SimObject in UNDEFINED power state! Power figures might be wrong!\n");
127
128 double power = 0;
129 for (unsigned i = 0; i < states_pm.size(); i++)
130 if (w[i + 1] > 0.0f)
131 power += states_pm[i]->getDynamicPower() * w[i + 1];
132
133 return power;
134}
135
136double
138{
139 assert(clocked_object);
140
142
143 if (power_model_type == enums::PMType::Dynamic) {
144 // This power model only collects dynamic data
145 return 0;
146 }
147
148 // Same number of states (excluding UNDEFINED)
149 assert(w.size() - 1 == states_pm.size());
150
151 // Make sure we have no UNDEFINED state
152 if (w[0] > 0)
153 warn("SimObject in UNDEFINED power state! "
154 "Power figures might be wrong!\n");
155
156 // We have N+1 states, being state #0 the default 'UNDEFINED' state
157 double power = 0;
158 for (unsigned i = 0; i < states_pm.size(); i++)
159 // Don't evaluate power if the object hasn't been in that state
160 // This fixes issues with NaNs and similar.
161 if (w[i + 1] > 0.0f)
162 power += states_pm[i]->getStaticPower() * w[i + 1];
163
164 return power;
165}
166
167} // namespace gem5
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
PowerModelStateParams Params
statistics::Value dynamicPower
PowerModelState(const Params &p)
virtual double getDynamicPower() const =0
Get the dynamic power consumption.
virtual double getStaticPower() const =0
Get the static power consumption.
statistics::Value staticPower
Listener class to catch thermal events.
virtual void regProbePoints()
Register probe points for this object.
enums::PMType power_model_type
The type of power model - collects all power, static or dynamic only.
statistics::Value staticPower
double getStaticPower() const
Get the static power consumption.
void setClockedObject(ClockedObject *clkobj)
ClockedObject * clocked_object
The clocked object we belong to.
PowerModel(const Params &p)
PowerModelParams Params
SubSystem * subsystem
The subsystem this power model belongs to.
void thermalUpdateCallback(const Temperature &temp)
std::vector< PowerModelState * > states_pm
Actual power models (one per power state)
double getDynamicPower() const
Get the dynamic power consumption.
statistics::Value dynamicPower
std::unique_ptr< ThermalProbeListener > thermalListener
Listener to catch temperature changes in the SubSystem.
std::vector< double > getWeights() const
Returns the percentage residency for each power state.
Abstract superclass for simulation objects.
void registerPowerProducer(PowerModel *pm)
Definition sub_system.hh:70
The class stores temperatures in Kelvin and provides helper methods to convert to/from Celsius.
Derived & method(T *obj, V(T::*method)() const)
Extended functor that calls the specified method of the provided object.
STL vector class.
Definition stl.hh:37
ClockedObject declaration and implementation.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition group.hh:75
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
ProbeManager * getProbeManager()
Get the probe manager for this object.
#define warn(...)
Definition logging.hh:256
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition logging.hh:283
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0 > p
Bitfield< 0 > w
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
Declaration of Statistics objects.
SubSystem declarations.

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0