tests: arch-power: Add 64-bit hello binaries
[gem5.git] / src / sim / power_state.hh
1 /*
2 * Copyright (c) 2015-2017, 2020 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
38 /**
39 * @file
40 * PowerState declaration and implementation.
41 */
42
43 #ifndef __SIM_POWER_STATE_HH__
44 #define __SIM_POWER_STATE_HH__
45
46 #include <set>
47 #include <vector>
48
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"
55
56 class PowerDomain;
57
58 /**
59 * Helper class for objects that have power states. This class provides the
60 * basic functionality to change between power states.
61 */
62 class PowerState : public SimObject
63 {
64 public:
65 PowerState(const PowerStateParams &p);
66
67 /** Parameters of PowerState object */
68 typedef PowerStateParams Params;
69 const Params &
70 params() const
71 {
72 return reinterpret_cast<const Params &>(_params);
73 }
74
75 virtual void addFollower(PowerState* pwr_obj) {};
76 void setControlledDomain(PowerDomain* pwr_dom);
77
78 void serialize(CheckpointOut &cp) const override;
79 void unserialize(CheckpointIn &cp) override;
80
81 /**
82 * Change the power state of this object to the power state p
83 */
84 void set(Enums::PwrState p);
85
86
87 inline Enums::PwrState get() const
88 {
89 return _currState;
90 }
91
92 inline std::string getName() const
93 {
94 return Enums::PwrStateStrings[_currState];
95 }
96
97 /** Returns the percentage residency for each power state */
98 std::vector<double> getWeights() const;
99
100 /**
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.
105 */
106 void computeStats();
107
108 /**
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.
111 */
112 Enums::PwrState matchPwrState(Enums::PwrState p);
113
114 /**
115 * Return the power states this object can be in
116 */
117 std::set<Enums::PwrState> getPossibleStates() const
118 {
119 return possibleStates;
120 }
121
122 protected:
123
124 /** To keep track of the current power state */
125 Enums::PwrState _currState;
126
127 /** The possible power states this object can be in */
128 std::set<Enums::PwrState> possibleStates;
129
130 /** Last tick the power stats were calculated */
131 Tick prvEvalTick = 0;
132
133 /**
134 * The power domain that this power state leads, nullptr if it
135 * doesn't lead any.
136 */
137 PowerDomain* controlledDomain = nullptr;
138
139 struct PowerStateStats : public Stats::Group
140 {
141 PowerStateStats(PowerState &ps);
142
143 void regStats() override;
144 void preDumpStats() override;
145
146 PowerState &powerState;
147
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;
153 } stats;
154 };
155
156 #endif //__SIM_POWER_STATE_HH__