2 * Copyright (c) 2015-2017, 2020 ARM Limited
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.
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.
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.
40 * PowerState declaration and implementation.
43 #ifndef __SIM_POWER_STATE_HH__
44 #define __SIM_POWER_STATE_HH__
49 #include "base/callback.hh"
50 #include "base/statistics.hh"
51 #include "enums/PwrState.hh"
52 #include "params/PowerState.hh"
53 #include "sim/core.hh"
54 #include "sim/sim_object.hh"
59 * Helper class for objects that have power states. This class provides the
60 * basic functionality to change between power states.
62 class PowerState : public SimObject
65 PowerState(const PowerStateParams &p);
67 /** Parameters of PowerState object */
68 typedef PowerStateParams Params;
72 return reinterpret_cast<const Params &>(_params);
75 virtual void addFollower(PowerState* pwr_obj) {};
76 void setControlledDomain(PowerDomain* pwr_dom);
78 void serialize(CheckpointOut &cp) const override;
79 void unserialize(CheckpointIn &cp) override;
82 * Change the power state of this object to the power state p
84 void set(Enums::PwrState p);
87 inline Enums::PwrState get() const
92 inline std::string getName() const
94 return Enums::PwrStateStrings[_currState];
97 /** Returns the percentage residency for each power state */
98 std::vector<double> getWeights() const;
101 * Record stats values like state residency by computing the time
102 * difference from previous update. Also, updates the previous evaluation
103 * tick once all stats are recorded.
104 * Usually called on power state change and stats dump callback.
109 * Change the power state of this object to a power state equal to OR more
110 * performant than p. Returns the power state the object actually went to.
112 Enums::PwrState matchPwrState(Enums::PwrState p);
115 * Return the power states this object can be in
117 std::set<Enums::PwrState> getPossibleStates() const
119 return possibleStates;
124 /** To keep track of the current power state */
125 Enums::PwrState _currState;
127 /** The possible power states this object can be in */
128 std::set<Enums::PwrState> possibleStates;
130 /** Last tick the power stats were calculated */
131 Tick prvEvalTick = 0;
134 * The power domain that this power state leads, nullptr if it
137 PowerDomain* controlledDomain = nullptr;
139 struct PowerStateStats : public Stats::Group
141 PowerStateStats(PowerState &ps);
143 void regStats() override;
144 void preDumpStats() override;
146 PowerState &powerState;
148 Stats::Scalar numTransitions;
149 Stats::Scalar numPwrMatchStateTransitions;
150 Stats::Distribution ticksClkGated;
151 /** Tracks the time spent in each of the power states */
152 Stats::Vector pwrStateResidencyTicks;
156 #endif //__SIM_POWER_STATE_HH__