power_model.cc revision 11800
112396SRiken.Gohil@arm.com/* 212811Sandreas.sandberg@arm.com * Copyright (c) 2016 ARM Limited 312396SRiken.Gohil@arm.com * All rights reserved 412396SRiken.Gohil@arm.com * 512396SRiken.Gohil@arm.com * The license below extends only to copyright in the software and shall 612396SRiken.Gohil@arm.com * not be construed as granting a license to any other intellectual 712396SRiken.Gohil@arm.com * property including but not limited to intellectual property relating 812396SRiken.Gohil@arm.com * to a hardware implementation of the functionality of the software 912396SRiken.Gohil@arm.com * licensed hereunder. You may use the software subject to the license 1012396SRiken.Gohil@arm.com * terms below provided that you ensure that this notice is replicated 1112396SRiken.Gohil@arm.com * unmodified and in its entirety in all distributions of the software, 1212396SRiken.Gohil@arm.com * modified or unmodified, in source code or in binary form. 1312396SRiken.Gohil@arm.com * 1412396SRiken.Gohil@arm.com * Redistribution and use in source and binary forms, with or without 1512396SRiken.Gohil@arm.com * modification, are permitted provided that the following conditions are 1612396SRiken.Gohil@arm.com * met: redistributions of source code must retain the above copyright 1712396SRiken.Gohil@arm.com * notice, this list of conditions and the following disclaimer; 1812396SRiken.Gohil@arm.com * redistributions in binary form must reproduce the above copyright 1912396SRiken.Gohil@arm.com * notice, this list of conditions and the following disclaimer in the 2012396SRiken.Gohil@arm.com * documentation and/or other materials provided with the distribution; 2112396SRiken.Gohil@arm.com * neither the name of the copyright holders nor the names of its 2212396SRiken.Gohil@arm.com * contributors may be used to endorse or promote products derived from 2312396SRiken.Gohil@arm.com * this software without specific prior written permission. 2412396SRiken.Gohil@arm.com * 2512396SRiken.Gohil@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2612396SRiken.Gohil@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2712396SRiken.Gohil@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2812396SRiken.Gohil@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2912396SRiken.Gohil@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3012396SRiken.Gohil@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3112396SRiken.Gohil@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3212396SRiken.Gohil@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3312396SRiken.Gohil@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3412396SRiken.Gohil@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3512396SRiken.Gohil@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3612396SRiken.Gohil@arm.com * 3712396SRiken.Gohil@arm.com * Authors: David Guillen Fandos 3812396SRiken.Gohil@arm.com */ 3912396SRiken.Gohil@arm.com 4012396SRiken.Gohil@arm.com#include "sim/power/power_model.hh" 4112396SRiken.Gohil@arm.com 4212396SRiken.Gohil@arm.com#include "base/statistics.hh" 4312396SRiken.Gohil@arm.com#include "params/PowerModel.hh" 4412396SRiken.Gohil@arm.com#include "params/PowerModelState.hh" 4512396SRiken.Gohil@arm.com#include "sim/clocked_object.hh" 4612396SRiken.Gohil@arm.com#include "sim/sub_system.hh" 4712396SRiken.Gohil@arm.com 4812396SRiken.Gohil@arm.comPowerModelState::PowerModelState(const Params *p) 4912396SRiken.Gohil@arm.com : SimObject(p), _temp(0), clocked_object(NULL) 5012396SRiken.Gohil@arm.com{ 5112396SRiken.Gohil@arm.com} 5212396SRiken.Gohil@arm.com 5312396SRiken.Gohil@arm.comPowerModel::PowerModel(const Params *p) 5412396SRiken.Gohil@arm.com : SimObject(p), states_pm(p->pm), subsystem(p->subsystem), 5512396SRiken.Gohil@arm.com clocked_object(NULL) 5612396SRiken.Gohil@arm.com{ 5712396SRiken.Gohil@arm.com panic_if(subsystem == NULL, 5812396SRiken.Gohil@arm.com "Subsystem is NULL! This is not acceptable for a PowerModel!\n"); 5912396SRiken.Gohil@arm.com subsystem->registerPowerProducer(this); 6012396SRiken.Gohil@arm.com} 6112396SRiken.Gohil@arm.com 6212396SRiken.Gohil@arm.comvoid 6312396SRiken.Gohil@arm.comPowerModel::setClockedObject(ClockedObject * clkobj) 6412844Sgiacomo.travaglini@arm.com{ 6512844Sgiacomo.travaglini@arm.com this->clocked_object = clkobj; 6612396SRiken.Gohil@arm.com 6712396SRiken.Gohil@arm.com for (auto & pms: states_pm) 6812396SRiken.Gohil@arm.com pms->setClockedObject(clkobj); 6912396SRiken.Gohil@arm.com} 7012396SRiken.Gohil@arm.com 7112396SRiken.Gohil@arm.comvoid 7212396SRiken.Gohil@arm.comPowerModel::thermalUpdateCallback(const double & temp) 7312396SRiken.Gohil@arm.com{ 7412396SRiken.Gohil@arm.com for (auto & pms: states_pm) 7512396SRiken.Gohil@arm.com pms->setTemperature(temp); 76} 77 78void 79PowerModel::regProbePoints() 80{ 81 thermalListener.reset(new ThermalProbeListener ( 82 *this, this->subsystem->getProbeManager(), "thermalUpdate" 83 )); 84} 85 86PowerModel* 87PowerModelParams::create() 88{ 89 return new PowerModel(this); 90} 91 92double 93PowerModel::getDynamicPower() const 94{ 95 assert(clocked_object); 96 97 std::vector<double> w = clocked_object->pwrStateWeights(); 98 99 // Same number of states (excluding UNDEFINED) 100 assert(w.size() - 1 == states_pm.size()); 101 102 // Make sure we have no UNDEFINED state 103 warn_if(w[Enums::PwrState::UNDEFINED] > 0, 104 "SimObject in UNDEFINED power state! Power figures might be wrong!\n"); 105 106 double power = 0; 107 for (unsigned i = 0; i < states_pm.size(); i++) 108 if (w[i + 1] > 0.0f) 109 power += states_pm[i]->getDynamicPower() * w[i + 1]; 110 111 return power; 112} 113 114double 115PowerModel::getStaticPower() const 116{ 117 assert(clocked_object); 118 119 std::vector<double> w = clocked_object->pwrStateWeights(); 120 121 // Same number of states (excluding UNDEFINED) 122 assert(w.size() - 1 == states_pm.size()); 123 124 // Make sure we have no UNDEFINED state 125 if (w[0] > 0) 126 warn("SimObject in UNDEFINED power state! " 127 "Power figures might be wrong!\n"); 128 129 // We have N+1 states, being state #0 the default 'UNDEFINED' state 130 double power = 0; 131 for (unsigned i = 0; i < states_pm.size(); i++) 132 // Don't evaluate power if the object hasn't been in that state 133 // This fixes issues with NaNs and similar. 134 if (w[i + 1] > 0.0f) 135 power += states_pm[i]->getStaticPower() * w[i + 1]; 136 137 return power; 138} 139