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

Generated on Fri Jul 3 2020 15:53:01 for gem5 by doxygen 1.8.13