clock_domain.cc revision 11416
15450Sgblack@eecs.umich.edu/* 25450Sgblack@eecs.umich.edu * Copyright (c) 2013-2014 ARM Limited 35450Sgblack@eecs.umich.edu * Copyright (c) 2013 Cornell University 45450Sgblack@eecs.umich.edu * All rights reserved 57087Snate@binkert.org * 67087Snate@binkert.org * The license below extends only to copyright in the software and shall 77087Snate@binkert.org * not be construed as granting a license to any other intellectual 87087Snate@binkert.org * property including but not limited to intellectual property relating 97087Snate@binkert.org * to a hardware implementation of the functionality of the software 107087Snate@binkert.org * licensed hereunder. You may use the software subject to the license 117087Snate@binkert.org * terms below provided that you ensure that this notice is replicated 127087Snate@binkert.org * unmodified and in its entirety in all distributions of the software, 135450Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form. 147087Snate@binkert.org * 157087Snate@binkert.org * Redistribution and use in source and binary forms, with or without 167087Snate@binkert.org * modification, are permitted provided that the following conditions are 177087Snate@binkert.org * met: redistributions of source code must retain the above copyright 187087Snate@binkert.org * notice, this list of conditions and the following disclaimer; 197087Snate@binkert.org * redistributions in binary form must reproduce the above copyright 207087Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 217087Snate@binkert.org * documentation and/or other materials provided with the distribution; 225450Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 237087Snate@binkert.org * contributors may be used to endorse or promote products derived from 245450Sgblack@eecs.umich.edu * this software without specific prior written permission. 255450Sgblack@eecs.umich.edu * 265450Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 275450Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 285450Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 295450Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 305450Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 315450Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 325450Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 335450Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 345450Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 355450Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 365450Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 375450Sgblack@eecs.umich.edu * 385450Sgblack@eecs.umich.edu * Authors: Vasileios Spiliopoulos 395450Sgblack@eecs.umich.edu * Akash Bagdia 405450Sgblack@eecs.umich.edu * Andreas Hansson 4111793Sbrandon.potter@amd.com * Christopher Torng 425450Sgblack@eecs.umich.edu * Stephan Diestelhorst 438852Sandreas.hansson@arm.com */ 445450Sgblack@eecs.umich.edu 455450Sgblack@eecs.umich.edu#include <algorithm> 465450Sgblack@eecs.umich.edu#include <functional> 475450Sgblack@eecs.umich.edu 485450Sgblack@eecs.umich.edu#include "debug/ClockDomain.hh" 495450Sgblack@eecs.umich.edu#include "params/ClockDomain.hh" 508852Sandreas.hansson@arm.com#include "params/DerivedClockDomain.hh" 515450Sgblack@eecs.umich.edu#include "params/SrcClockDomain.hh" 525450Sgblack@eecs.umich.edu#include "sim/clock_domain.hh" 5314010Sgabeblack@google.com#include "sim/voltage_domain.hh" 545450Sgblack@eecs.umich.edu#include "sim/clocked_object.hh" 555450Sgblack@eecs.umich.edu 565450Sgblack@eecs.umich.eduvoid 578852Sandreas.hansson@arm.comClockDomain::regStats() 585450Sgblack@eecs.umich.edu{ 595450Sgblack@eecs.umich.edu using namespace Stats; 605450Sgblack@eecs.umich.edu 615450Sgblack@eecs.umich.edu // Expose the current clock period as a stat for observability in 625450Sgblack@eecs.umich.edu // the dumps 635450Sgblack@eecs.umich.edu currentClock 645450Sgblack@eecs.umich.edu .scalar(_clockPeriod) 655450Sgblack@eecs.umich.edu .name(params()->name + ".clock") 665450Sgblack@eecs.umich.edu .desc("Clock period in ticks") 6714010Sgabeblack@google.com ; 685450Sgblack@eecs.umich.edu} 695450Sgblack@eecs.umich.edu 708852Sandreas.hansson@arm.comdouble 718852Sandreas.hansson@arm.comClockDomain::voltage() const 728852Sandreas.hansson@arm.com{ 735450Sgblack@eecs.umich.edu return _voltageDomain->voltage(); 745450Sgblack@eecs.umich.edu} 755450Sgblack@eecs.umich.edu 765450Sgblack@eecs.umich.eduSrcClockDomain::SrcClockDomain(const Params *p) : 775450Sgblack@eecs.umich.edu ClockDomain(p, p->voltage_domain), 785450Sgblack@eecs.umich.edu freqOpPoints(p->clock), 795450Sgblack@eecs.umich.edu _domainID(p->domain_id), 805450Sgblack@eecs.umich.edu _perfLevel(p->init_perf_level) 815450Sgblack@eecs.umich.edu{ 825450Sgblack@eecs.umich.edu VoltageDomain *vdom = p->voltage_domain; 835450Sgblack@eecs.umich.edu 845450Sgblack@eecs.umich.edu fatal_if(freqOpPoints.empty(), "DVFS: Empty set of frequencies for "\ 855450Sgblack@eecs.umich.edu "domain %d %s\n", _domainID, name()); 865450Sgblack@eecs.umich.edu 87 fatal_if(!vdom, "DVFS: Empty voltage domain specified for "\ 88 "domain %d %s\n", _domainID, name()); 89 90 fatal_if((vdom->numVoltages() > 1) && 91 (vdom->numVoltages() != freqOpPoints.size()), 92 "DVFS: Number of frequency and voltage scaling points do "\ 93 "not match: %d:%d ID: %d %s.\n", vdom->numVoltages(), 94 freqOpPoints.size(), _domainID, name()); 95 96 // Frequency (& voltage) points should be declared in descending order, 97 // NOTE: Frequency is inverted to ticks, so checking for ascending ticks 98 fatal_if(!std::is_sorted(freqOpPoints.begin(), freqOpPoints.end()), 99 "DVFS: Frequency operation points not in descending order for "\ 100 "domain with ID %d\n", _domainID); 101 102 fatal_if(_perfLevel >= freqOpPoints.size(), "DVFS: Initial DVFS point %d "\ 103 "is outside of list for Domain ID: %d\n", _perfLevel, _domainID); 104 105 clockPeriod(freqOpPoints[_perfLevel]); 106 107 vdom->registerSrcClockDom(this); 108} 109 110void 111SrcClockDomain::clockPeriod(Tick clock_period) 112{ 113 if (clock_period == 0) { 114 fatal("%s has a clock period of zero\n", name()); 115 } 116 117 // Align all members to the current tick 118 for (auto m = members.begin(); m != members.end(); ++m) { 119 (*m)->updateClockPeriod(); 120 } 121 122 _clockPeriod = clock_period; 123 124 DPRINTF(ClockDomain, 125 "Setting clock period to %d ticks for source clock %s\n", 126 _clockPeriod, name()); 127 128 // inform any derived clocks they need to updated their period 129 for (auto c = children.begin(); c != children.end(); ++c) { 130 (*c)->updateClockPeriod(); 131 } 132} 133 134void 135SrcClockDomain::perfLevel(PerfLevel perf_level) 136{ 137 assert(validPerfLevel(perf_level)); 138 139 if (perf_level == _perfLevel) { 140 // Silently ignore identical overwrites 141 return; 142 } 143 144 DPRINTF(ClockDomain, "DVFS: Switching performance level of domain %s "\ 145 "(id: %d) from %d to %d\n", name(), domainID(), _perfLevel, 146 perf_level); 147 148 _perfLevel = perf_level; 149 150 signalPerfLevelUpdate(); 151} 152 153void SrcClockDomain::signalPerfLevelUpdate() 154{ 155 // Signal the voltage domain that we have changed our perf level so that the 156 // voltage domain can recompute its performance level 157 voltageDomain()->sanitiseVoltages(); 158 159 // Integrated switching of the actual clock value, too 160 clockPeriod(clkPeriodAtPerfLevel()); 161} 162 163void 164SrcClockDomain::serialize(CheckpointOut &cp) const 165{ 166 SERIALIZE_SCALAR(_perfLevel); 167 ClockDomain::serialize(cp); 168} 169 170void 171SrcClockDomain::unserialize(CheckpointIn &cp) 172{ 173 ClockDomain::unserialize(cp); 174 UNSERIALIZE_SCALAR(_perfLevel); 175} 176 177void 178SrcClockDomain::startup() 179{ 180 // Perform proper clock update when all related components have been 181 // created (i.e. after unserialization / object creation) 182 signalPerfLevelUpdate(); 183} 184 185SrcClockDomain * 186SrcClockDomainParams::create() 187{ 188 return new SrcClockDomain(this); 189} 190 191DerivedClockDomain::DerivedClockDomain(const Params *p) : 192 ClockDomain(p, p->clk_domain->voltageDomain()), 193 parent(*p->clk_domain), 194 clockDivider(p->clk_divider) 195{ 196 // Ensure that clock divider setting works as frequency divider and never 197 // work as frequency multiplier 198 if (clockDivider < 1) { 199 fatal("Clock divider param cannot be less than 1"); 200 } 201 202 // let the parent keep track of this derived domain so that it can 203 // propagate changes 204 parent.addDerivedDomain(this); 205 206 // update our clock period based on the parents clock 207 updateClockPeriod(); 208} 209 210void 211DerivedClockDomain::updateClockPeriod() 212{ 213 // Align all members to the current tick 214 for (auto m = members.begin(); m != members.end(); ++m) { 215 (*m)->updateClockPeriod(); 216 } 217 218 // recalculate the clock period, relying on the fact that changes 219 // propagate downwards in the tree 220 _clockPeriod = parent.clockPeriod() * clockDivider; 221 222 DPRINTF(ClockDomain, 223 "Setting clock period to %d ticks for derived clock %s\n", 224 _clockPeriod, name()); 225 226 // inform any derived clocks 227 for (auto c = children.begin(); c != children.end(); ++c) { 228 (*c)->updateClockPeriod(); 229 } 230} 231 232DerivedClockDomain * 233DerivedClockDomainParams::create() 234{ 235 return new DerivedClockDomain(this); 236} 237