111527Sdavid.guillen@arm.com/* 212546Sanouk.vanlaer@arm.com * Copyright (c) 2016, 2018 ARM Limited 311527Sdavid.guillen@arm.com * All rights reserved 411527Sdavid.guillen@arm.com * 511527Sdavid.guillen@arm.com * The license below extends only to copyright in the software and shall 611527Sdavid.guillen@arm.com * not be construed as granting a license to any other intellectual 711527Sdavid.guillen@arm.com * property including but not limited to intellectual property relating 811527Sdavid.guillen@arm.com * to a hardware implementation of the functionality of the software 911527Sdavid.guillen@arm.com * licensed hereunder. You may use the software subject to the license 1011527Sdavid.guillen@arm.com * terms below provided that you ensure that this notice is replicated 1111527Sdavid.guillen@arm.com * unmodified and in its entirety in all distributions of the software, 1211527Sdavid.guillen@arm.com * modified or unmodified, in source code or in binary form. 1311527Sdavid.guillen@arm.com * 1411527Sdavid.guillen@arm.com * Redistribution and use in source and binary forms, with or without 1511527Sdavid.guillen@arm.com * modification, are permitted provided that the following conditions are 1611527Sdavid.guillen@arm.com * met: redistributions of source code must retain the above copyright 1711527Sdavid.guillen@arm.com * notice, this list of conditions and the following disclaimer; 1811527Sdavid.guillen@arm.com * redistributions in binary form must reproduce the above copyright 1911527Sdavid.guillen@arm.com * notice, this list of conditions and the following disclaimer in the 2011527Sdavid.guillen@arm.com * documentation and/or other materials provided with the distribution; 2111527Sdavid.guillen@arm.com * neither the name of the copyright holders nor the names of its 2211527Sdavid.guillen@arm.com * contributors may be used to endorse or promote products derived from 2311527Sdavid.guillen@arm.com * this software without specific prior written permission. 2411527Sdavid.guillen@arm.com * 2511527Sdavid.guillen@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2611527Sdavid.guillen@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2711527Sdavid.guillen@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2811527Sdavid.guillen@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2911527Sdavid.guillen@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3011527Sdavid.guillen@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3111527Sdavid.guillen@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3211527Sdavid.guillen@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3311527Sdavid.guillen@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3411527Sdavid.guillen@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3511527Sdavid.guillen@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3611527Sdavid.guillen@arm.com * 3711527Sdavid.guillen@arm.com * Authors: David Guillen Fandos 3811527Sdavid.guillen@arm.com */ 3911527Sdavid.guillen@arm.com 4011527Sdavid.guillen@arm.com#ifndef __SIM_POWER_POWER_MODEL_HH__ 4111527Sdavid.guillen@arm.com#define __SIM_POWER_POWER_MODEL_HH__ 4211527Sdavid.guillen@arm.com 4311527Sdavid.guillen@arm.com#include "base/statistics.hh" 4412546Sanouk.vanlaer@arm.com#include "enums/PMType.hh" 4511527Sdavid.guillen@arm.com#include "params/PowerModel.hh" 4611527Sdavid.guillen@arm.com#include "params/PowerModelState.hh" 4711527Sdavid.guillen@arm.com#include "sim/probe/probe.hh" 4811800Sbrandon.potter@amd.com 4911800Sbrandon.potter@amd.comclass SimObject; 5011800Sbrandon.potter@amd.comclass ClockedObject; 5111527Sdavid.guillen@arm.com 5211527Sdavid.guillen@arm.com/** 5311527Sdavid.guillen@arm.com * A PowerModelState is an abstract class used as interface to get power 5411527Sdavid.guillen@arm.com * figures out of SimObjects 5511527Sdavid.guillen@arm.com */ 5611527Sdavid.guillen@arm.comclass PowerModelState : public SimObject 5711527Sdavid.guillen@arm.com{ 5811527Sdavid.guillen@arm.com public: 5911527Sdavid.guillen@arm.com 6011527Sdavid.guillen@arm.com typedef PowerModelStateParams Params; 6111527Sdavid.guillen@arm.com PowerModelState(const Params *p); 6211527Sdavid.guillen@arm.com 6311527Sdavid.guillen@arm.com /** 6411527Sdavid.guillen@arm.com * Get the dynamic power consumption. 6511527Sdavid.guillen@arm.com * 6611527Sdavid.guillen@arm.com * @return Power (Watts) consumed by this object (dynamic component) 6711527Sdavid.guillen@arm.com */ 6811527Sdavid.guillen@arm.com virtual double getDynamicPower() const = 0; 6911527Sdavid.guillen@arm.com 7011527Sdavid.guillen@arm.com /** 7111527Sdavid.guillen@arm.com * Get the static power consumption. 7211527Sdavid.guillen@arm.com * 7311527Sdavid.guillen@arm.com * @return Power (Watts) consumed by this object (static component) 7411527Sdavid.guillen@arm.com */ 7511527Sdavid.guillen@arm.com virtual double getStaticPower() const = 0; 7611527Sdavid.guillen@arm.com 7711527Sdavid.guillen@arm.com /** 7811527Sdavid.guillen@arm.com * Temperature update. 7911527Sdavid.guillen@arm.com * 8011527Sdavid.guillen@arm.com * @param temp Current temperature of the HW part (Celsius) 8111527Sdavid.guillen@arm.com */ 8211527Sdavid.guillen@arm.com virtual void setTemperature(double temp) { _temp = temp; } 8311527Sdavid.guillen@arm.com 8411527Sdavid.guillen@arm.com void setClockedObject(ClockedObject * clkobj) { 8511527Sdavid.guillen@arm.com clocked_object = clkobj; 8611527Sdavid.guillen@arm.com } 8711527Sdavid.guillen@arm.com 8811527Sdavid.guillen@arm.com void regStats() { 8911527Sdavid.guillen@arm.com dynamicPower 9011527Sdavid.guillen@arm.com .method(this, &PowerModelState::getDynamicPower) 9111527Sdavid.guillen@arm.com .name(params()->name + ".dynamic_power") 9211527Sdavid.guillen@arm.com .desc("Dynamic power for this object (Watts)") 9311527Sdavid.guillen@arm.com ; 9411527Sdavid.guillen@arm.com 9511527Sdavid.guillen@arm.com staticPower 9611527Sdavid.guillen@arm.com .method(this, &PowerModelState::getStaticPower) 9711527Sdavid.guillen@arm.com .name(params()->name + ".static_power") 9811527Sdavid.guillen@arm.com .desc("Static power for this object (Watts)") 9911527Sdavid.guillen@arm.com ; 10011527Sdavid.guillen@arm.com } 10111527Sdavid.guillen@arm.com 10211527Sdavid.guillen@arm.com protected: 10311527Sdavid.guillen@arm.com Stats::Value dynamicPower, staticPower; 10411527Sdavid.guillen@arm.com 10511527Sdavid.guillen@arm.com /** Current temperature */ 10611527Sdavid.guillen@arm.com double _temp; 10711527Sdavid.guillen@arm.com 10811527Sdavid.guillen@arm.com /** The clocked object we belong to */ 10911527Sdavid.guillen@arm.com ClockedObject * clocked_object; 11011527Sdavid.guillen@arm.com}; 11111527Sdavid.guillen@arm.com 11211527Sdavid.guillen@arm.com/** 11312678Sjason@lowepower.com * @sa \ref gem5PowerModel "gem5 Power Model" 11412678Sjason@lowepower.com * 11511527Sdavid.guillen@arm.com * A PowerModel is a class containing a power model for a SimObject. 11611527Sdavid.guillen@arm.com * The PM describes the power consumption for every power state. 11711527Sdavid.guillen@arm.com */ 11811527Sdavid.guillen@arm.comclass PowerModel : public SimObject 11911527Sdavid.guillen@arm.com{ 12011527Sdavid.guillen@arm.com public: 12111527Sdavid.guillen@arm.com 12211527Sdavid.guillen@arm.com typedef PowerModelParams Params; 12311527Sdavid.guillen@arm.com PowerModel(const Params *p); 12411527Sdavid.guillen@arm.com 12511527Sdavid.guillen@arm.com /** 12611527Sdavid.guillen@arm.com * Get the dynamic power consumption. 12711527Sdavid.guillen@arm.com * 12811527Sdavid.guillen@arm.com * @return Power (Watts) consumed by this object (dynamic component) 12911527Sdavid.guillen@arm.com */ 13011527Sdavid.guillen@arm.com double getDynamicPower() const; 13111527Sdavid.guillen@arm.com 13211527Sdavid.guillen@arm.com /** 13311527Sdavid.guillen@arm.com * Get the static power consumption. 13411527Sdavid.guillen@arm.com * 13511527Sdavid.guillen@arm.com * @return Power (Watts) consumed by this object (static component) 13611527Sdavid.guillen@arm.com */ 13711527Sdavid.guillen@arm.com double getStaticPower() const; 13811527Sdavid.guillen@arm.com 13911527Sdavid.guillen@arm.com void regStats() { 14011527Sdavid.guillen@arm.com dynamicPower 14111527Sdavid.guillen@arm.com .method(this, &PowerModel::getDynamicPower) 14211527Sdavid.guillen@arm.com .name(params()->name + ".dynamic_power") 14311527Sdavid.guillen@arm.com .desc("Dynamic power for this power state") 14411527Sdavid.guillen@arm.com ; 14511527Sdavid.guillen@arm.com 14611527Sdavid.guillen@arm.com staticPower 14711527Sdavid.guillen@arm.com .method(this, &PowerModel::getStaticPower) 14811527Sdavid.guillen@arm.com .name(params()->name + ".static_power") 14911527Sdavid.guillen@arm.com .desc("Static power for this power state") 15011527Sdavid.guillen@arm.com ; 15111527Sdavid.guillen@arm.com } 15211527Sdavid.guillen@arm.com 15311527Sdavid.guillen@arm.com void setClockedObject(ClockedObject *clkobj); 15411527Sdavid.guillen@arm.com 15511527Sdavid.guillen@arm.com virtual void regProbePoints(); 15611527Sdavid.guillen@arm.com 15711527Sdavid.guillen@arm.com void thermalUpdateCallback(const double & temp); 15811527Sdavid.guillen@arm.com 15911527Sdavid.guillen@arm.com protected: 16011527Sdavid.guillen@arm.com /** Listener class to catch thermal events */ 16111527Sdavid.guillen@arm.com class ThermalProbeListener : public ProbeListenerArgBase<double> 16211527Sdavid.guillen@arm.com { 16311527Sdavid.guillen@arm.com public: 16411527Sdavid.guillen@arm.com ThermalProbeListener(PowerModel &_pm, ProbeManager *pm, 16511527Sdavid.guillen@arm.com const std::string &name) 16611527Sdavid.guillen@arm.com : ProbeListenerArgBase(pm, name), pm(_pm) {} 16711527Sdavid.guillen@arm.com 16811527Sdavid.guillen@arm.com void notify(const double &temp) 16911527Sdavid.guillen@arm.com { 17011527Sdavid.guillen@arm.com pm.thermalUpdateCallback(temp); 17111527Sdavid.guillen@arm.com } 17211527Sdavid.guillen@arm.com 17311527Sdavid.guillen@arm.com protected: 17411527Sdavid.guillen@arm.com PowerModel ± 17511527Sdavid.guillen@arm.com }; 17611527Sdavid.guillen@arm.com 17711527Sdavid.guillen@arm.com Stats::Value dynamicPower, staticPower; 17811527Sdavid.guillen@arm.com 17911527Sdavid.guillen@arm.com /** Actual power models (one per power state) */ 18011527Sdavid.guillen@arm.com std::vector<PowerModelState*> states_pm; 18111527Sdavid.guillen@arm.com 18211527Sdavid.guillen@arm.com /** Listener to catch temperature changes in the SubSystem */ 18311527Sdavid.guillen@arm.com std::unique_ptr<ThermalProbeListener> thermalListener; 18411527Sdavid.guillen@arm.com 18511527Sdavid.guillen@arm.com /** The subsystem this power model belongs to */ 18611527Sdavid.guillen@arm.com SubSystem * subsystem; 18711527Sdavid.guillen@arm.com 18811527Sdavid.guillen@arm.com /** The clocked object we belong to */ 18911527Sdavid.guillen@arm.com ClockedObject * clocked_object; 19012546Sanouk.vanlaer@arm.com 19112546Sanouk.vanlaer@arm.com /** The type of power model - collects all power, static or dynamic only */ 19212546Sanouk.vanlaer@arm.com Enums::PMType power_model_type; 19311527Sdavid.guillen@arm.com}; 19411527Sdavid.guillen@arm.com 19511527Sdavid.guillen@arm.com#endif 196