clocked_object.cc (11424:e07fd01651f3) clocked_object.cc (11524:3101ce98c55c)
1/*
1/*
2 * Copyright (c) 2015 ARM Limited
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/misc.hh"
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/misc.hh"
44#include "sim/power/power_model.hh"
45
44
46ClockedObject::ClockedObject(const ClockedObjectParams *p) :
47 SimObject(p), Clocked(*p->clk_domain),
48 _currPwrState(p->default_p_state),
49 prvEvalTick(0)
50{
51 // Register the power_model with the object
52 if (p->power_model)
53 p->power_model->setClockedObject(this);
54}
55
56void
57ClockedObject::serialize(CheckpointOut &cp) const
58{
59 unsigned int currPwrState = (unsigned int)_currPwrState;
60
61 SERIALIZE_SCALAR(currPwrState);
62 SERIALIZE_SCALAR(prvEvalTick);
63}
64
65void
66ClockedObject::unserialize(CheckpointIn &cp)
67{
68 unsigned int currPwrState;
69
70 UNSERIALIZE_SCALAR(currPwrState);
71 UNSERIALIZE_SCALAR(prvEvalTick);
72
73 _currPwrState = Enums::PwrState(currPwrState);
74}
75
76void
77ClockedObject::pwrState(Enums::PwrState p)
78{
79 // Function should ideally be called only when there is a state change
80 if (_currPwrState == p) {
81 warn("ClockedObject: Already in the requested power state, request "\
82 "ignored");
83 return;
84 }
85
45void
46ClockedObject::serialize(CheckpointOut &cp) const
47{
48 unsigned int currPwrState = (unsigned int)_currPwrState;
49
50 SERIALIZE_SCALAR(currPwrState);
51 SERIALIZE_SCALAR(prvEvalTick);
52}
53
54void
55ClockedObject::unserialize(CheckpointIn &cp)
56{
57 unsigned int currPwrState;
58
59 UNSERIALIZE_SCALAR(currPwrState);
60 UNSERIALIZE_SCALAR(prvEvalTick);
61
62 _currPwrState = Enums::PwrState(currPwrState);
63}
64
65void
66ClockedObject::pwrState(Enums::PwrState p)
67{
68 // Function should ideally be called only when there is a state change
69 if (_currPwrState == p) {
70 warn("ClockedObject: Already in the requested power state, request "\
71 "ignored");
72 return;
73 }
74
86 // No need to compute stats if in the same tick, update state
87 // though. This can happen in cases like a) during start of the
88 // simulation multiple state changes happens in init/startup phase,
89 // b) one takes a decision to migrate state but decides to reverts
90 // back to the original state in the same tick if other conditions
91 // are not met elsewhere. Any state change related stats would have
92 // been recorded on previous call to the pwrState() function.
75 // No need to compute stats if in the same tick, update state though. This
76 // can happen in cases like a) during start of the simulation multiple
77 // state changes happens in init/startup phase, b) one takes a decision to
78 // migrate state but decides to reverts back to the original state in the
79 // same tick if other conditions are not met elsewhere.
80 // Any state change related stats would have been recorded on previous call
81 // to the pwrState() function.
93 if (prvEvalTick == curTick()) {
94 warn("ClockedObject: More than one power state change request "\
95 "encountered within the same simulation tick");
96 _currPwrState = p;
97 return;
98 }
99
100 // Record stats for previous state.
101 computeStats();
102
103 _currPwrState = p;
104
105 numPwrStateTransitions++;
106}
107
108void
109ClockedObject::computeStats()
110{
111 // Calculate time elapsed from last (valid) state change
112 Tick elapsed_time = curTick() - prvEvalTick;
113
114 pwrStateResidencyTicks[_currPwrState] += elapsed_time;
115
116 // Time spent in CLK_GATED state, this might change depending on
117 // transition to other low power states in respective simulation
118 // objects.
119 if (_currPwrState == Enums::PwrState::CLK_GATED) {
120 pwrStateClkGateDist.sample(elapsed_time);
121 }
122
123 prvEvalTick = curTick();
124}
125
126std::vector<double>
127ClockedObject::pwrStateWeights() const
128{
129 // Get residency stats
130 std::vector<double> ret;
131 Stats::VCounter residencies;
132 pwrStateResidencyTicks.value(residencies);
133
134 // Account for current state too!
135 Tick elapsed_time = curTick() - prvEvalTick;
136 residencies[_currPwrState] += elapsed_time;
137
138 ret.resize(Enums::PwrState::Num_PwrState);
139 for (unsigned i = 0; i < Enums::PwrState::Num_PwrState; i++)
82 if (prvEvalTick == curTick()) {
83 warn("ClockedObject: More than one power state change request "\
84 "encountered within the same simulation tick");
85 _currPwrState = p;
86 return;
87 }
88
89 // Record stats for previous state.
90 computeStats();
91
92 _currPwrState = p;
93
94 numPwrStateTransitions++;
95}
96
97void
98ClockedObject::computeStats()
99{
100 // Calculate time elapsed from last (valid) state change
101 Tick elapsed_time = curTick() - prvEvalTick;
102
103 pwrStateResidencyTicks[_currPwrState] += elapsed_time;
104
105 // Time spent in CLK_GATED state, this might change depending on
106 // transition to other low power states in respective simulation
107 // objects.
108 if (_currPwrState == Enums::PwrState::CLK_GATED) {
109 pwrStateClkGateDist.sample(elapsed_time);
110 }
111
112 prvEvalTick = curTick();
113}
114
115std::vector<double>
116ClockedObject::pwrStateWeights() const
117{
118 // Get residency stats
119 std::vector<double> ret;
120 Stats::VCounter residencies;
121 pwrStateResidencyTicks.value(residencies);
122
123 // Account for current state too!
124 Tick elapsed_time = curTick() - prvEvalTick;
125 residencies[_currPwrState] += elapsed_time;
126
127 ret.resize(Enums::PwrState::Num_PwrState);
128 for (unsigned i = 0; i < Enums::PwrState::Num_PwrState; i++)
140 ret[i] = residencies[i] /
129 ret[i] = residencies[i] / \
141 (pwrStateResidencyTicks.total() + elapsed_time);
142
143 return ret;
144}
145
146void
147ClockedObject::regStats()
148{
149 SimObject::regStats();
150
151 using namespace Stats;
152
153 numPwrStateTransitions
154 .name(params()->name + ".numPwrStateTransitions")
155 .desc("Number of power state transitions")
156 ;
157
158 // Each sample is time in ticks
159 unsigned num_bins = std::max(params()->p_state_clk_gate_bins, 10U);
160 pwrStateClkGateDist
161 .init(params()->p_state_clk_gate_min, params()->p_state_clk_gate_max,
162 (params()->p_state_clk_gate_max / num_bins))
163 .name(params()->name + ".pwrStateClkGateDist")
164 .desc("Distribution of time spent in the clock gated state")
165 .flags(pdf)
166 ;
167
168 pwrStateResidencyTicks
169 .init(Enums::PwrState::Num_PwrState)
170 .name(params()->name + ".pwrStateResidencyTicks")
171 .desc("Cumulative time (in ticks) in various power states")
172 ;
173 for (int i = 0; i < Enums::PwrState::Num_PwrState; i++) {
174 pwrStateResidencyTicks.subname(i, Enums::PwrStateStrings[i]);
175 }
176
177 numPwrStateTransitions = 0;
178
179 /**
180 * For every stats dump, the power state residency and other distribution
181 * stats should be computed just before the dump to ensure correct stats
182 * value being reported for current dump window. It avoids things like
183 * having any unreported time spent in a power state to be forwarded to the
184 * next dump window which might have rather unpleasant effects (like
185 * perturbing the distribution stats).
186 */
187 registerDumpCallback(new ClockedObjectDumpCallback(this));
188}
130 (pwrStateResidencyTicks.total() + elapsed_time);
131
132 return ret;
133}
134
135void
136ClockedObject::regStats()
137{
138 SimObject::regStats();
139
140 using namespace Stats;
141
142 numPwrStateTransitions
143 .name(params()->name + ".numPwrStateTransitions")
144 .desc("Number of power state transitions")
145 ;
146
147 // Each sample is time in ticks
148 unsigned num_bins = std::max(params()->p_state_clk_gate_bins, 10U);
149 pwrStateClkGateDist
150 .init(params()->p_state_clk_gate_min, params()->p_state_clk_gate_max,
151 (params()->p_state_clk_gate_max / num_bins))
152 .name(params()->name + ".pwrStateClkGateDist")
153 .desc("Distribution of time spent in the clock gated state")
154 .flags(pdf)
155 ;
156
157 pwrStateResidencyTicks
158 .init(Enums::PwrState::Num_PwrState)
159 .name(params()->name + ".pwrStateResidencyTicks")
160 .desc("Cumulative time (in ticks) in various power states")
161 ;
162 for (int i = 0; i < Enums::PwrState::Num_PwrState; i++) {
163 pwrStateResidencyTicks.subname(i, Enums::PwrStateStrings[i]);
164 }
165
166 numPwrStateTransitions = 0;
167
168 /**
169 * For every stats dump, the power state residency and other distribution
170 * stats should be computed just before the dump to ensure correct stats
171 * value being reported for current dump window. It avoids things like
172 * having any unreported time spent in a power state to be forwarded to the
173 * next dump window which might have rather unpleasant effects (like
174 * perturbing the distribution stats).
175 */
176 registerDumpCallback(new ClockedObjectDumpCallback(this));
177}