2 * Copyright (c) 2013-2014 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.
37 * Authors: Vasileios Spiliopoulos
39 * Stephan Diestelhorst
44 * DVFSHandler and DomainConfig class declaration used for managing voltage
45 * and frequency scaling of the various DVFS domains in the system (with each
46 * domain having their independent domain configuration information)
50 #ifndef __SIM_DVFS_HANDLER_HH__
51 #define __SIM_DVFS_HANDLER_HH__
55 #include "debug/DVFS.hh"
56 #include "params/DVFSHandler.hh"
57 #include "sim/clock_domain.hh"
58 #include "sim/eventq.hh"
59 #include "sim/sim_object.hh"
62 * DVFS Handler class, maintains a list of all the domains it can handle.
63 * Each entry of that list is an object of the DomainConfig class, and the
64 * handler uses the methods provided by that class to get access to the
65 * configuration of each domain. The handler is responsible for setting/getting
66 * clock periods and voltages from clock/voltage domains.
67 * The handler acts the bridge between software configurable information
68 * for each domain as provided to the controller and the hardware
69 * implementation details for those domains.
71 class DVFSHandler : public SimObject
74 typedef DVFSHandlerParams Params;
75 DVFSHandler(const Params *p);
77 typedef SrcClockDomain::DomainID DomainID;
78 typedef SrcClockDomain::PerfLevel PerfLevel;
81 * Get the number of domains assigned to this DVFS handler.
82 * @return Number of domains
84 uint32_t numDomains() const { return domainIDList.size(); }
87 * Get the n-th domain ID, from the domains managed by this handler.
90 DomainID domainID(uint32_t index) const;
93 * Check whether a domain ID is known to the handler or not.
94 * @param domain_id Domain ID to check
95 * @return Domain ID known to handler?
97 bool validDomainID(DomainID domain_id) const;
100 * Get transition latency to switch between performance levels.
101 * @return Transition latency
103 Tick transLatency() const { return _transLatency; }
106 * Set a new performance level for the specified domain. The actual update
107 * will be delayed by transLatency().
109 * @param domain_id Software visible ID of the domain to be configured
110 * @param perf_level Requested performance level (0 - fast, >0 slower)
111 * @return status whether the setting was successful
113 bool perfLevel(DomainID domain_id, PerfLevel perf_level);
116 * Get the current performance level of a domain. While a change request is
117 * in-flight, will return the current (i.e. old, unmodified) value.
119 * @param domain_id Domain ID to query
120 * @return Current performance level of the specified domain
122 PerfLevel perfLevel(DomainID domain_id) const {
124 return findDomain(domain_id)->perfLevel();
128 * Read the clock period of the specified domain at the specified
130 * @param domain_id Domain ID to query
131 * @param perf_level Performance level of interest
132 * @return Clock period in ticks for the requested performance level of
133 * the respective domain
135 Tick clkPeriodAtPerfLevel(DomainID domain_id, PerfLevel perf_level) const
137 SrcClockDomain *d = findDomain(domain_id);
139 PerfLevel n = d->numPerfLevels();
141 return d->clkPeriodAtPerfLevel(perf_level);
143 warn("DVFSHandler %s reads illegal frequency level %u from "\
144 "SrcClockDomain %s. Returning 0\n", name(), perf_level, d->name());
149 * Read the voltage of the specified domain at the specified
151 * @param domain_id Domain ID to query
152 * @param perf_level Performance level of interest
153 * @return Voltage for the requested performance level of the respective
156 double voltageAtPerfLevel(DomainID domain_id, PerfLevel perf_level) const;
159 * Get the total number of available performance levels.
161 * @param domain_id Domain ID to query
162 * @return Number of performance levels that where configured for the
165 PerfLevel numPerfLevels(PerfLevel domain_id) const
167 return findDomain(domain_id)->numPerfLevels();
171 * Check enable status of the DVFS handler, when the handler is disabled, no
172 * request should be sent to the handler.
173 * @return True, if the handler is enabled
175 bool isEnabled() const { return enableHandler; }
177 void serialize(CheckpointOut &cp) const override;
178 void unserialize(CheckpointIn &cp) override;
181 typedef std::map<DomainID, SrcClockDomain*> Domains;
185 * List of IDs avaiable in the domain list
187 std::vector<DomainID> domainIDList;
190 * Clock domain of the system the handler is instantiated.
192 SrcClockDomain* sysClkDomain;
195 * Search for a domain based on the domain ID.
197 * @param domain_id Domain ID to search for
198 * @return Pointer to the source clock domain with matching ID.
200 SrcClockDomain *findDomain(DomainID domain_id) const {
201 auto it = domains.find(domain_id);
202 panic_if(it == domains.end(),
203 "DVFS: Could not find a domain for ID %d.\n",domain_id );
204 return domains.find(domain_id)->second;
208 * Disabling the DVFS handler ensures that all the DVFS migration requests
209 * are ignored. Domains remain at their default frequency and voltage.
215 * This corresponds to the maximum transition latency associated with the
216 * hardware transitioning from a particular performance level to the other
218 const Tick _transLatency;
223 * Update performance level event, encapsulates all the required information
224 * for a future call to change a domain's performance level.
226 struct UpdateEvent : public Event {
227 UpdateEvent() : Event(DVFS_Update_Pri), domainIDToSet(0),
231 * Static pointer to the single DVFS hander for all the update events
233 static DVFSHandler *dvfsHandler;
236 * ID of the domain that will be changed by the in-flight event
238 DomainID domainIDToSet;
241 * Target performance level of the in-flight event
243 PerfLevel perfLevelToSet;
246 * Updates the performance level by modifying the clock and the voltage
247 * of the associated clocked objects. Gets information from
248 * domainIDToSet and perfLevelToSet for easier calling through an
251 void updatePerfLevel();
253 void process() { updatePerfLevel(); }
256 typedef std::map<DomainID, UpdateEvent> UpdatePerfLevelEvents;
258 * Map from domain IDs -> perf level update events, records in-flight change
259 * requests per domain ID.
261 UpdatePerfLevelEvents updatePerfLevelEvents;
264 #endif // __SIM_DVFS_HANDLER_HH__