gem5  v19.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 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/clocked_object.hh"
46 #include "sim/sub_system.hh"
47 
49  : SimObject(p), _temp(0), clocked_object(NULL)
50 {
51 }
52 
54  : SimObject(p), states_pm(p->pm), subsystem(p->subsystem),
55  clocked_object(NULL), power_model_type(p->pm_type)
56 {
57  panic_if(subsystem == NULL,
58  "Subsystem is NULL! This is not acceptable for a PowerModel!\n");
60  // The temperature passed here will be overwritten, if there is
61  // a thermal model present
62  for (auto & pms: states_pm){
63  pms->setTemperature(p->ambient_temp);
64  }
65 
66 }
67 
68 void
70 {
71  this->clocked_object = clkobj;
72 
73  for (auto & pms: states_pm)
74  pms->setClockedObject(clkobj);
75 }
76 
77 void
79 {
80  for (auto & pms: states_pm)
81  pms->setTemperature(temp);
82 }
83 
84 void
86 {
88  *this, this->subsystem->getProbeManager(), "thermalUpdate"
89  ));
90 }
91 
93 PowerModelParams::create()
94 {
95  return new PowerModel(this);
96 }
97 
98 double
100 {
101  assert(clocked_object);
102 
103  if (power_model_type == Enums::PMType::Static) {
104  // This power model only collects static data
105  return 0;
106  }
108 
109  // Same number of states (excluding UNDEFINED)
110  assert(w.size() - 1 == states_pm.size());
111 
112  // Make sure we have no UNDEFINED state
113  warn_if(w[Enums::PwrState::UNDEFINED] > 0,
114  "SimObject in UNDEFINED power state! Power figures might be wrong!\n");
115 
116  double power = 0;
117  for (unsigned i = 0; i < states_pm.size(); i++)
118  if (w[i + 1] > 0.0f)
119  power += states_pm[i]->getDynamicPower() * w[i + 1];
120 
121  return power;
122 }
123 
124 double
126 {
127  assert(clocked_object);
128 
130 
131  if (power_model_type == Enums::PMType::Dynamic) {
132  // This power model only collects dynamic data
133  return 0;
134  }
135 
136  // Same number of states (excluding UNDEFINED)
137  assert(w.size() - 1 == states_pm.size());
138 
139  // Make sure we have no UNDEFINED state
140  if (w[0] > 0)
141  warn("SimObject in UNDEFINED power state! "
142  "Power figures might be wrong!\n");
143 
144  // We have N+1 states, being state #0 the default 'UNDEFINED' state
145  double power = 0;
146  for (unsigned i = 0; i < states_pm.size(); i++)
147  // Don't evaluate power if the object hasn't been in that state
148  // This fixes issues with NaNs and similar.
149  if (w[i + 1] > 0.0f)
150  power += states_pm[i]->getStaticPower() * w[i + 1];
151 
152  return power;
153 }
std::vector< double > pwrStateWeights() const
Returns the percentage residency for each power state.
Bitfield< 7 > i
Enums::PMType power_model_type
The type of power model - collects all power, static or dynamic only.
Definition: power_model.hh:192
Listener class to catch thermal events.
Definition: power_model.hh:161
void registerPowerProducer(PowerModel *pm)
Definition: sub_system.hh:69
Declaration of Statistics objects.
Bitfield< 6 > f
PowerModelParams Params
Definition: power_model.hh:122
std::vector< PowerModelState * > states_pm
Actual power models (one per power state)
Definition: power_model.hh:180
double getStaticPower() const
Get the static power consumption.
Definition: power_model.cc:125
PowerModelStateParams Params
Definition: power_model.hh:60
uint64_t power(uint32_t n, uint32_t e)
Definition: intmath.hh:40
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
ClockedObject declaration and implementation.
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition: logging.hh:228
virtual void regProbePoints()
Register probe points for this object.
Definition: power_model.cc:85
SubSystem * subsystem
The subsystem this power model belongs to.
Definition: power_model.hh:186
ClockedObject * clocked_object
The clocked object we belong to.
Definition: power_model.hh:109
ClockedObject * clocked_object
The clocked object we belong to.
Definition: power_model.hh:189
Bitfield< 0 > w
PowerModelState(const Params *p)
Definition: power_model.cc:48
double getDynamicPower() const
Get the dynamic power consumption.
Definition: power_model.cc:99
PowerModel(const Params *p)
Definition: power_model.cc:53
void thermalUpdateCallback(const double &temp)
Definition: power_model.cc:78
SubSystem declarations.
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:120
void setClockedObject(ClockedObject *clkobj)
Definition: power_model.cc:69
#define warn(...)
Definition: logging.hh:212
std::unique_ptr< ThermalProbeListener > thermalListener
Listener to catch temperature changes in the SubSystem.
Definition: power_model.hh:183
Bitfield< 0 > p
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:185
Abstract superclass for simulation objects.
Definition: sim_object.hh:96

Generated on Fri Feb 28 2020 16:27:03 for gem5 by doxygen 1.8.13