gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
clocked_object.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-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: Akash Bagdia
38  * David Guillen Fandos
39  */
40 
41 #include "sim/clocked_object.hh"
42 
43 #include "base/logging.hh"
44 #include "sim/power/power_model.hh"
45 
46 ClockedObject::ClockedObject(const ClockedObjectParams *p) :
47  SimObject(p), Clocked(*p->clk_domain),
48  _currPwrState(p->default_p_state),
49  prvEvalTick(0),
50  stats(*this)
51 {
52  // Register the power_model with the object
53  for (auto & power_model: p->power_model)
54  power_model->setClockedObject(this);
55 }
56 
57 void
59 {
60  unsigned int currPwrState = (unsigned int)_currPwrState;
61 
62  SERIALIZE_SCALAR(currPwrState);
64 }
65 
66 void
68 {
69  unsigned int currPwrState;
70 
71  UNSERIALIZE_SCALAR(currPwrState);
73 
74  _currPwrState = Enums::PwrState(currPwrState);
75 }
76 
77 void
78 ClockedObject::pwrState(Enums::PwrState p)
79 {
80  // Function should ideally be called only when there is a state change
81  if (_currPwrState == p) {
82  warn_once("ClockedObject: Already in the requested power state, " \
83  "request ignored");
84  return;
85  }
86 
87  // No need to compute stats if in the same tick, update state though. This
88  // can happen in cases like a) during start of the simulation multiple
89  // state changes happens in init/startup phase, b) one takes a decision to
90  // migrate state but decides to reverts back to the original state in the
91  // same tick if other conditions are not met elsewhere.
92  // Any state change related stats would have been recorded on previous call
93  // to the pwrState() function.
94  if (prvEvalTick == curTick() && curTick() != 0) {
95  warn("ClockedObject %s: More than one power state change request "\
96  "encountered within the same simulation tick %d",
97  name(), prvEvalTick);
98  _currPwrState = p;
99  return;
100  }
101 
102  // Record stats for previous state.
103  computeStats();
104 
105  _currPwrState = p;
106 
108 }
109 
110 void
112 {
113  // Calculate time elapsed from last (valid) state change
114  Tick elapsed_time = curTick() - prvEvalTick;
115 
116  stats.pwrStateResidencyTicks[_currPwrState] += elapsed_time;
117 
118  // Time spent in CLK_GATED state, this might change depending on
119  // transition to other low power states in respective simulation
120  // objects.
121  if (_currPwrState == Enums::PwrState::CLK_GATED) {
122  stats.pwrStateClkGateDist.sample(elapsed_time);
123  }
124 
125  prvEvalTick = curTick();
126 }
127 
130 {
131  // Get residency stats
133  Stats::VCounter residencies;
134  stats.pwrStateResidencyTicks.value(residencies);
135 
136  // Account for current state too!
137  Tick elapsed_time = curTick() - prvEvalTick;
138  residencies[_currPwrState] += elapsed_time;
139 
140  ret.resize(Enums::PwrState::Num_PwrState);
141  for (unsigned i = 0; i < Enums::PwrState::Num_PwrState; i++)
142  ret[i] = residencies[i] / \
143  (stats.pwrStateResidencyTicks.total() + elapsed_time);
144 
145  return ret;
146 }
147 
148 
150  : Stats::Group(&co),
151  clockedObject(co),
152  ADD_STAT(numPwrStateTransitions,
153  "Number of power state transitions"),
154  ADD_STAT(pwrStateClkGateDist,
155  "Distribution of time spent in the clock gated state"),
156  ADD_STAT(pwrStateResidencyTicks,
157  "Cumulative time (in ticks) in various power states")
158 {
159 }
160 
161 void
163 {
165 
166  using namespace Stats;
167 
168  const ClockedObjectParams *p = clockedObject.params();
169 
171 
172  // Each sample is time in ticks
173  unsigned num_bins = std::max(p->p_state_clk_gate_bins, 10U);
175  .init(p->p_state_clk_gate_min, p->p_state_clk_gate_max,
176  (p->p_state_clk_gate_max / num_bins))
177  .flags(pdf | nozero | nonan)
178  ;
179 
181  .init(Enums::PwrState::Num_PwrState)
182  .flags(nozero)
183  ;
184  for (int i = 0; i < Enums::PwrState::Num_PwrState; i++) {
185  pwrStateResidencyTicks.subname(i, Enums::PwrStateStrings[i]);
186  }
187 
189 }
190 
191 void
193 {
195 
205 }
const FlagsType pdf
Print the percent of the total that this entry represents.
Definition: info.hh:53
std::vector< double > pwrStateWeights() const
Returns the percentage residency for each power state.
Derived & subname(off_type index, const std::string &name)
Set the subfield name for the given index, and marks this stat to print at the end of simulation...
Definition: statistics.hh:379
void computeStats()
Record stats values like state residency by computing the time difference from previous update...
Bitfield< 7 > i
const FlagsType nonan
Don&#39;t print if this is NAN.
Definition: info.hh:61
void preDumpStats() override
Callback before stats are dumped.
Result total() const
Return a total of all entries in this vector.
Definition: statistics.hh:1102
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:66
void value(VCounter &vec) const
Definition: statistics.hh:1078
ClockedObject::ClockedObjectStats stats
Definition: cprintf.cc:42
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:336
const Params * params() const
Derived & init(size_type size)
Set this vector to have the given size.
Definition: statistics.hh:1152
void unserialize(CheckpointIn &cp) override
Unserialize an object.
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:645
Tick curTick()
The current simulated tick.
Definition: core.hh:47
Stats::Distribution pwrStateClkGateDist
uint64_t Tick
Tick count type.
Definition: types.hh:63
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Group()=delete
virtual void preDumpStats()
Callback before stats are dumped.
Definition: group.cc:97
void serialize(CheckpointOut &cp) const override
Serialize an object.
ClockedObject declaration and implementation.
void regStats() override
Callback to set stat parameters.
Distribution & init(Counter min, Counter max, Counter bkt)
Set the parameters of this distribution.
Definition: statistics.hh:2609
Helper class for objects that need to be clocked.
virtual const std::string name() const
Definition: sim_object.hh:120
#define warn_once(...)
Definition: logging.hh:216
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:643
Enums::PwrState pwrState() const
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:69
std::ostream CheckpointOut
Definition: serialize.hh:68
#define warn(...)
Definition: logging.hh:212
const FlagsType nozero
Don&#39;t print if this is zero.
Definition: info.hh:59
Bitfield< 0 > p
Enums::PwrState _currPwrState
To keep track of the current power state.
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
Definition: statistics.hh:1899
ClockedObject(const ClockedObjectParams *p)

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