voltage_domain.cc revision 10249
19827Sakash.bagdia@arm.com/* 210249Sstephan.diestelhorst@arm.com * Copyright (c) 2012-2014 ARM Limited 39827Sakash.bagdia@arm.com * All rights reserved 49827Sakash.bagdia@arm.com * 59827Sakash.bagdia@arm.com * The license below extends only to copyright in the software and shall 69827Sakash.bagdia@arm.com * not be construed as granting a license to any other intellectual 79827Sakash.bagdia@arm.com * property including but not limited to intellectual property relating 89827Sakash.bagdia@arm.com * to a hardware implementation of the functionality of the software 99827Sakash.bagdia@arm.com * licensed hereunder. You may use the software subject to the license 109827Sakash.bagdia@arm.com * terms below provided that you ensure that this notice is replicated 119827Sakash.bagdia@arm.com * unmodified and in its entirety in all distributions of the software, 129827Sakash.bagdia@arm.com * modified or unmodified, in source code or in binary form. 139827Sakash.bagdia@arm.com * 149827Sakash.bagdia@arm.com * Redistribution and use in source and binary forms, with or without 159827Sakash.bagdia@arm.com * modification, are permitted provided that the following conditions are 169827Sakash.bagdia@arm.com * met: redistributions of source code must retain the above copyright 179827Sakash.bagdia@arm.com * notice, this list of conditions and the following disclaimer; 189827Sakash.bagdia@arm.com * redistributions in binary form must reproduce the above copyright 199827Sakash.bagdia@arm.com * notice, this list of conditions and the following disclaimer in the 209827Sakash.bagdia@arm.com * documentation and/or other materials provided with the distribution; 219827Sakash.bagdia@arm.com * neither the name of the copyright holders nor the names of its 229827Sakash.bagdia@arm.com * contributors may be used to endorse or promote products derived from 239827Sakash.bagdia@arm.com * this software without specific prior written permission. 249827Sakash.bagdia@arm.com * 259827Sakash.bagdia@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 269827Sakash.bagdia@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 279827Sakash.bagdia@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 289827Sakash.bagdia@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 299827Sakash.bagdia@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 309827Sakash.bagdia@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 319827Sakash.bagdia@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 329827Sakash.bagdia@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 339827Sakash.bagdia@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 349827Sakash.bagdia@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 359827Sakash.bagdia@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 369827Sakash.bagdia@arm.com * 379827Sakash.bagdia@arm.com * Authors: Vasileios Spiliopoulos 389827Sakash.bagdia@arm.com * Akash Bagdia 399827Sakash.bagdia@arm.com */ 409827Sakash.bagdia@arm.com 4110249Sstephan.diestelhorst@arm.com#include <algorithm> 4210249Sstephan.diestelhorst@arm.com 4310249Sstephan.diestelhorst@arm.com#include "base/statistics.hh" 449827Sakash.bagdia@arm.com#include "debug/VoltageDomain.hh" 459827Sakash.bagdia@arm.com#include "params/VoltageDomain.hh" 469827Sakash.bagdia@arm.com#include "sim/sim_object.hh" 479827Sakash.bagdia@arm.com#include "sim/voltage_domain.hh" 489827Sakash.bagdia@arm.com 499827Sakash.bagdia@arm.comVoltageDomain::VoltageDomain(const Params *p) 5010249Sstephan.diestelhorst@arm.com : SimObject(p), voltageOpPoints(p->voltage), _perfLevel(0) 519827Sakash.bagdia@arm.com{ 5210249Sstephan.diestelhorst@arm.com fatal_if(voltageOpPoints.empty(), "DVFS: Empty set of voltages for "\ 5310249Sstephan.diestelhorst@arm.com "voltage domain %s\n", name()); 5410249Sstephan.diestelhorst@arm.com 5510249Sstephan.diestelhorst@arm.com // Voltages must be sorted in descending order. 5610249Sstephan.diestelhorst@arm.com fatal_if(!std::is_sorted(voltageOpPoints.begin(), voltageOpPoints.end(), 5710249Sstephan.diestelhorst@arm.com std::greater_equal<Voltages::value_type>()), "DVFS: Voltage "\ 5810249Sstephan.diestelhorst@arm.com "operation points not in descending order for voltage domain "\ 5910249Sstephan.diestelhorst@arm.com "%s\n", name()); 609827Sakash.bagdia@arm.com} 619827Sakash.bagdia@arm.com 629827Sakash.bagdia@arm.comvoid 6310249Sstephan.diestelhorst@arm.comVoltageDomain::perfLevel(PerfLevel perf_level) 649827Sakash.bagdia@arm.com{ 6510249Sstephan.diestelhorst@arm.com chatty_assert(perf_level < voltageOpPoints.size(), 6610249Sstephan.diestelhorst@arm.com "DVFS: Requested voltage ID %d is outside the known "\ 6710249Sstephan.diestelhorst@arm.com "range for domain %s.\n", perf_level, name()); 6810249Sstephan.diestelhorst@arm.com 6910249Sstephan.diestelhorst@arm.com _perfLevel = perf_level; 7010249Sstephan.diestelhorst@arm.com 7110249Sstephan.diestelhorst@arm.com DPRINTF(VoltageDomain, "Setting voltage to %.3fV idx: %d for domain %s\n", 7210249Sstephan.diestelhorst@arm.com voltage(), perf_level, name()); 7310249Sstephan.diestelhorst@arm.com} 7410249Sstephan.diestelhorst@arm.com 7510249Sstephan.diestelhorst@arm.combool 7610249Sstephan.diestelhorst@arm.comVoltageDomain::sanitiseVoltages() 7710249Sstephan.diestelhorst@arm.com{ 7810249Sstephan.diestelhorst@arm.com if (numVoltages() == 1) 7910249Sstephan.diestelhorst@arm.com return false; 8010249Sstephan.diestelhorst@arm.com 8110249Sstephan.diestelhorst@arm.com // Find the highest requested performance level and update the voltage 8210249Sstephan.diestelhorst@arm.com // domain with it 8310249Sstephan.diestelhorst@arm.com PerfLevel perf_max = (PerfLevel)-1; 8410249Sstephan.diestelhorst@arm.com for (auto dit = srcClockChildren.begin(); dit != srcClockChildren.end(); ++dit) { 8510249Sstephan.diestelhorst@arm.com SrcClockDomain* d = *dit; 8610249Sstephan.diestelhorst@arm.com chatty_assert(d->voltageDomain() == this, "DVFS: Clock domain %s "\ 8710249Sstephan.diestelhorst@arm.com "(id: %d) should not be registered with voltage domain "\ 8810249Sstephan.diestelhorst@arm.com "%s\n", d->name(), d->domainID(), name()); 8910249Sstephan.diestelhorst@arm.com 9010249Sstephan.diestelhorst@arm.com PerfLevel perf = d->perfLevel(); 9110249Sstephan.diestelhorst@arm.com 9210249Sstephan.diestelhorst@arm.com DPRINTF(VoltageDomain, "DVFS: Clock domain %s (id: %d) requests perf "\ 9310249Sstephan.diestelhorst@arm.com "level %d\n", d->name(), d->domainID(), perf); 9410249Sstephan.diestelhorst@arm.com 9510249Sstephan.diestelhorst@arm.com // NOTE: Descending sort of performance levels: 0 - fast, 5 - slow 9610249Sstephan.diestelhorst@arm.com if (perf < perf_max) { 9710249Sstephan.diestelhorst@arm.com DPRINTF(VoltageDomain, "DVFS: Updating max perf level %d -> %d\n", 9810249Sstephan.diestelhorst@arm.com perf_max, perf); 9910249Sstephan.diestelhorst@arm.com perf_max = perf; 10010249Sstephan.diestelhorst@arm.com } 1019827Sakash.bagdia@arm.com } 10210249Sstephan.diestelhorst@arm.com DPRINTF(VoltageDomain, "DVFS: Setting perf level of voltage domain %s "\ 10310249Sstephan.diestelhorst@arm.com "from %d to %d.\n", name(), perfLevel(), perf_max); 1049827Sakash.bagdia@arm.com 10510249Sstephan.diestelhorst@arm.com // Set the performance level 10610249Sstephan.diestelhorst@arm.com if (perf_max != perfLevel()) { 10710249Sstephan.diestelhorst@arm.com perfLevel(perf_max); 10810249Sstephan.diestelhorst@arm.com return true; 10910249Sstephan.diestelhorst@arm.com } else { 11010249Sstephan.diestelhorst@arm.com return false; 11110249Sstephan.diestelhorst@arm.com } 11210249Sstephan.diestelhorst@arm.com} 11310249Sstephan.diestelhorst@arm.com 11410249Sstephan.diestelhorst@arm.comvoid 11510249Sstephan.diestelhorst@arm.comVoltageDomain::startup() { 11610249Sstephan.diestelhorst@arm.com bool changed = sanitiseVoltages(); 11710249Sstephan.diestelhorst@arm.com if (changed) { 11810249Sstephan.diestelhorst@arm.com warn("DVFS: Perf level for voltage domain %s adapted to "\ 11910249Sstephan.diestelhorst@arm.com "requested perf levels from source clock domains.\n", name()); 12010249Sstephan.diestelhorst@arm.com } 1219827Sakash.bagdia@arm.com} 1229827Sakash.bagdia@arm.com 12310022SAndreas.Hansson@ARM.comvoid 12410022SAndreas.Hansson@ARM.comVoltageDomain::regStats() 12510022SAndreas.Hansson@ARM.com{ 12610022SAndreas.Hansson@ARM.com currentVoltage 12710249Sstephan.diestelhorst@arm.com .method(this, &VoltageDomain::voltage) 12810022SAndreas.Hansson@ARM.com .name(params()->name + ".voltage") 12910022SAndreas.Hansson@ARM.com .desc("Voltage in Volts") 13010022SAndreas.Hansson@ARM.com ; 13110022SAndreas.Hansson@ARM.com} 13210022SAndreas.Hansson@ARM.com 1339827Sakash.bagdia@arm.comVoltageDomain * 1349827Sakash.bagdia@arm.comVoltageDomainParams::create() 1359827Sakash.bagdia@arm.com{ 1369827Sakash.bagdia@arm.com return new VoltageDomain(this); 1379827Sakash.bagdia@arm.com} 13810249Sstephan.diestelhorst@arm.com 13910249Sstephan.diestelhorst@arm.comvoid 14010249Sstephan.diestelhorst@arm.comVoltageDomain::serialize(std::ostream &os) { 14110249Sstephan.diestelhorst@arm.com SERIALIZE_SCALAR(_perfLevel); 14210249Sstephan.diestelhorst@arm.com} 14310249Sstephan.diestelhorst@arm.com 14410249Sstephan.diestelhorst@arm.comvoid 14510249Sstephan.diestelhorst@arm.comVoltageDomain::unserialize(Checkpoint *cp, const std::string §ion) { 14610249Sstephan.diestelhorst@arm.com UNSERIALIZE_SCALAR(_perfLevel); 14710249Sstephan.diestelhorst@arm.com perfLevel(_perfLevel); 14810249Sstephan.diestelhorst@arm.com} 149