gem5 v24.0.0.0
Loading...
Searching...
No Matches
energy_ctrl.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2014 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
39
40#include "base/trace.hh"
41#include "debug/EnergyCtrl.hh"
42#include "mem/packet.hh"
43#include "mem/packet_access.hh"
44#include "params/EnergyCtrl.hh"
45#include "sim/dvfs_handler.hh"
46#include "sim/serialize.hh"
47
48namespace gem5
49{
50
52 : BasicPioDevice(p, PIO_NUM_FIELDS * 4), // each field is 32 bit
53 dvfsHandler(p.dvfs_handler),
54 domainID(0),
55 domainIDIndexToRead(0),
56 perfLevelAck(0),
57 perfLevelToRead(0),
58 updateAckEvent([this]{ updatePLAck(); }, name())
59{
60 fatal_if(!p.dvfs_handler, "EnergyCtrl: Needs a DVFSHandler for a "
61 "functioning system.\n");
62}
63
64Tick
66{
67 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
68 assert(pkt->getSize() == 4);
69
70 Addr daddr = pkt->getAddr() - pioAddr;
71 assert((daddr & 3) == 0);
72 Registers reg = Registers(daddr / 4);
73
74 if (!dvfsHandler->isEnabled()) {
75 // NB: Zero is a good response if the handler is disabled
76 pkt->setLE<uint32_t>(0);
77 warn_once("EnergyCtrl: Disabled handler, ignoring read from reg %i\n",
78 reg);
79 DPRINTF(EnergyCtrl, "dvfs handler disabled, return 0 for read from "\
80 "reg %i\n", reg);
81 pkt->makeAtomicResponse();
82 return pioDelay;
83 }
84
85 uint32_t result = 0;
86 Tick period;
87 double voltage;
88
89 switch(reg) {
91 result = 1;
92 DPRINTF(EnergyCtrl, "dvfs handler enabled\n");
93 break;
95 result = dvfsHandler->numDomains();
96 DPRINTF(EnergyCtrl, "reading number of domains %d\n", result);
97 break;
100 DPRINTF(EnergyCtrl, "reading domain id at index %d as %d\n",
101 domainIDIndexToRead, result);
102 break;
104 // Return transition latency in nanoseconds
106 DPRINTF(EnergyCtrl, "reading dvfs handler trans latency %d ns\n",
107 result);
108 break;
109 case DOMAIN_ID:
110 result = domainID;
111 DPRINTF(EnergyCtrl, "reading domain id:%d\n", result);
112 break;
113 case PERF_LEVEL:
114 result = dvfsHandler->perfLevel(domainID);
115 DPRINTF(EnergyCtrl, "reading domain %d perf level: %d\n",
116 domainID, result);
117 break;
118 case PERF_LEVEL_ACK:
119 result = perfLevelAck;
120 DPRINTF(EnergyCtrl, "reading ack:%d\n", result);
121 // Signal is set for a single read only
122 if (result == 1)
123 perfLevelAck = 0;
124 break;
127 DPRINTF(EnergyCtrl, "reading num of perf level:%d\n", result);
128 break;
131 result = ticksTokHz(period);
132 DPRINTF(EnergyCtrl, "reading freq %d KHz at perf level: %d\n",
133 result, perfLevelToRead);
134 break;
137 result = toMicroVolt(voltage);
138 DPRINTF(EnergyCtrl, "reading voltage %d u-volt at perf level: %d\n",
139 result, perfLevelToRead);
140 break;
141 default:
142 panic("Tried to read EnergyCtrl at offset %#x / reg %i\n", daddr,
143 reg);
144 }
145 pkt->setLE<uint32_t>(result);
146 pkt->makeAtomicResponse();
147 return pioDelay;
148}
149
150Tick
152{
153 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
154 assert(pkt->getSize() == 4);
155
156 uint32_t data;
157 data = pkt->getLE<uint32_t>();
158
159 Addr daddr = pkt->getAddr() - pioAddr;
160 assert((daddr & 3) == 0);
161 Registers reg = Registers(daddr / 4);
162
163 if (!dvfsHandler->isEnabled()) {
164 // Ignore writes to a disabled controller
165 warn_once("EnergyCtrl: Disabled handler, ignoring write %u to "\
166 "reg %i\n", data, reg);
167 DPRINTF(EnergyCtrl, "dvfs handler disabled, ignoring write %u to "\
168 "reg %i\n", data, reg);
169 pkt->makeAtomicResponse();
170 return pioDelay;
171 }
172
173 switch(reg) {
176 DPRINTF(EnergyCtrl, "writing domain id index:%d\n",
178 break;
179 case DOMAIN_ID:
180 // Extra check to ensure that a valid domain ID is being queried
182 domainID = data;
183 DPRINTF(EnergyCtrl, "writing domain id:%d\n", domainID);
184 } else {
185 DPRINTF(EnergyCtrl, "invalid domain id:%d\n", domainID);
186 }
187 break;
188 case PERF_LEVEL:
191 // The OS driver is trying to change the perf level while
192 // another change is in flight. This is fine, but only a
193 // single acknowledgment will be sent.
194 DPRINTF(EnergyCtrl, "descheduling previous pending ack "\
195 "event\n");
197 }
199 DPRINTF(EnergyCtrl, "writing domain %d perf level: %d\n",
200 domainID, data);
201 } else {
202 DPRINTF(EnergyCtrl, "invalid / ineffective perf level:%d for "\
203 "domain:%d\n", data, domainID);
204 }
205 break;
208 DPRINTF(EnergyCtrl, "writing perf level to read opp at: %d\n",
209 data);
210 break;
211 default:
212 panic("Tried to write EnergyCtrl at offset %#x\n", daddr);
213 break;
214 }
215
216 pkt->makeAtomicResponse();
217 return pioDelay;
218}
219
220void
231
232void
234{
239 Tick next_event = 0;
240 UNSERIALIZE_SCALAR(next_event);
241
242 // restore scheduled events
243 if (next_event != 0) {
244 schedule(updateAckEvent, next_event);
245 }
246}
247
248void
250{
251 if (!dvfsHandler->isEnabled()) {
252 warn("Existing EnergyCtrl, but no enabled DVFSHandler found.\n");
253 }
254}
255
256void
261
262} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
const char data[]
Addr pioAddr
Address that the device listens to.
Definition io_device.hh:151
Tick pioDelay
Delay that the device experinces on an access.
Definition io_device.hh:157
Addr pioSize
Size that the device's address range.
Definition io_device.hh:154
double voltage() const
Tick transLatency() const
Get transition latency to switch between performance levels.
Tick clkPeriodAtPerfLevel(DomainID domain_id, PerfLevel perf_level) const
Read the clock period of the specified domain at the specified performance level.
bool perfLevel(DomainID domain_id, PerfLevel perf_level)
Set a new performance level for the specified domain.
bool isEnabled() const
Check enable status of the DVFS handler, when the handler is disabled, no request should be sent to t...
DomainID domainID(uint32_t index) const
Get the n-th domain ID, from the domains managed by this handler.
double voltageAtPerfLevel(DomainID domain_id, PerfLevel perf_level) const
Read the voltage of the specified domain at the specified performance level.
uint32_t numDomains() const
Get the number of domains assigned to this DVFS handler.
PerfLevel numPerfLevels(PerfLevel domain_id) const
Get the total number of available performance levels.
bool validDomainID(DomainID domain_id) const
Check whether a domain ID is known to the handler or not.
static uint32_t toMicroVolt(double voltage)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
static uint32_t ticksTokHz(Tick period)
Tick read(PacketPtr pkt) override
Read command sent to the device.
void startup() override
startup() is the final initialization call before simulation.
DVFSHandler * dvfsHandler
EventFunctionWrapper updateAckEvent
EnergyCtrl(const Params &p)
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
EnergyCtrlParams Params
Tick write(PacketPtr pkt) override
Write command sent to the device.
void updatePLAck()
Update the acknowledgment that is read back by the software to confirm newly requested performance le...
void serialize(CheckpointOut &cp) const override
Serialize an object.
uint32_t perfLevelAck
Acknowledgment (PERF_LEVEL_ACK) RO register, software polls this register to read back the status of ...
uint32_t perfLevelToRead
uint32_t domainIDIndexToRead
Index for getting the domain ID from the domain ID list available with the DVFS handler.
uint32_t domainID
Cluster ID (DOMAIN_ID) R/W register, programmed to ID of the domain for which the set/get performance...
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Addr getAddr() const
Definition packet.hh:807
void setLE(T v)
Set the value in the data pointer to v as little endian.
unsigned getSize() const
Definition packet.hh:817
void makeAtomicResponse()
Definition packet.hh:1074
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition io_device.cc:59
DVFSHandler and DomainConfig class declaration used for managing voltage and frequency scaling of the...
The energy controller is a device being used to manage power and energy related control operations wi...
void deschedule(Event &event)
Definition eventq.hh:1021
bool scheduled() const
Determine if the current event is scheduled.
Definition eventq.hh:458
void schedule(Event &event, Tick when)
Definition eventq.hh:1012
Tick when() const
Get the time that the event is scheduled.
Definition eventq.hh:501
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:236
#define warn(...)
Definition logging.hh:256
#define warn_once(...)
Definition logging.hh:260
Bitfield< 0 > p
Bitfield< 5, 3 > reg
Definition types.hh:92
Tick ns
nanosecond
Definition core.cc:68
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
Declaration of the Packet class.
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0