power_model.hh revision 11424:e07fd01651f3
1/* 2 * Copyright (c) 2015 ARM Limited 3 * All rights reserved 4 * 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. 13 * 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. 24 * 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. 36 * 37 * Authors: David Guillen Fandos 38 */ 39 40#ifndef __SIM_POWER_POWER_MODEL_HH__ 41#define __SIM_POWER_POWER_MODEL_HH__ 42 43#include "base/statistics.hh" 44#include "params/PowerModel.hh" 45#include "params/PowerModelState.hh" 46#include "sim/power/thermal_model.hh" 47#include "sim/probe/probe.hh" 48#include "sim/sim_object.hh" 49 50/** 51 * A PowerModelState is an abstract class used as interface to get power 52 * figures out of SimObjects 53 */ 54class PowerModelState : public SimObject 55{ 56 public: 57 58 typedef PowerModelStateParams Params; 59 PowerModelState(const Params *p); 60 61 /** 62 * Get the dynamic power consumption. 63 * 64 * @return Power (Watts) consumed by this object (dynamic component) 65 */ 66 virtual double getDynamicPower() const = 0; 67 68 /** 69 * Get the static power consumption. 70 * 71 * @return Power (Watts) consumed by this object (static component) 72 */ 73 virtual double getStaticPower() const = 0; 74 75 /** 76 * Temperature update. 77 * 78 * @param temp Current temperature of the HW part (Celsius) 79 */ 80 virtual void setTemperature(double temp) { _temp = temp; } 81 82 void setClockedObject(ClockedObject * clkobj) { 83 clocked_object = clkobj; 84 } 85 86 void regStats() { 87 dynamicPower 88 .method(this, &PowerModelState::getDynamicPower) 89 .name(params()->name + ".dynamic_power") 90 .desc("Dynamic power for this object (Watts)") 91 ; 92 93 staticPower 94 .method(this, &PowerModelState::getStaticPower) 95 .name(params()->name + ".static_power") 96 .desc("Static power for this object (Watts)") 97 ; 98 } 99 100 protected: 101 Stats::Value dynamicPower, staticPower; 102 103 /** Current temperature */ 104 double _temp; 105 106 /** The clocked object we belong to */ 107 ClockedObject * clocked_object; 108}; 109 110/** 111 * A PowerModel is a class containing a power model for a SimObject. 112 * The PM describes the power consumption for every power state. 113 */ 114class PowerModel : public SimObject 115{ 116 public: 117 118 typedef PowerModelParams Params; 119 PowerModel(const Params *p); 120 121 /** 122 * Get the dynamic power consumption. 123 * 124 * @return Power (Watts) consumed by this object (dynamic component) 125 */ 126 double getDynamicPower() const; 127 128 /** 129 * Get the static power consumption. 130 * 131 * @return Power (Watts) consumed by this object (static component) 132 */ 133 double getStaticPower() const; 134 135 void regStats() { 136 dynamicPower 137 .method(this, &PowerModel::getDynamicPower) 138 .name(params()->name + ".dynamic_power") 139 .desc("Dynamic power for this power state") 140 ; 141 142 staticPower 143 .method(this, &PowerModel::getStaticPower) 144 .name(params()->name + ".static_power") 145 .desc("Static power for this power state") 146 ; 147 } 148 149 void setClockedObject(ClockedObject *clkobj); 150 151 virtual void regProbePoints(); 152 153 void thermalUpdateCallback(const double & temp); 154 155 protected: 156 /** Listener class to catch thermal events */ 157 class ThermalProbeListener : public ProbeListenerArgBase<double> 158 { 159 public: 160 ThermalProbeListener(PowerModel &_pm, ProbeManager *pm, 161 const std::string &name) 162 : ProbeListenerArgBase(pm, name), pm(_pm) {} 163 164 void notify(const double &temp) 165 { 166 pm.thermalUpdateCallback(temp); 167 } 168 169 protected: 170 PowerModel ± 171 }; 172 173 Stats::Value dynamicPower, staticPower; 174 175 /** Actual power models (one per power state) */ 176 std::vector<PowerModelState*> states_pm; 177 178 /** Listener to catch temperature changes in the SubSystem */ 179 std::unique_ptr<ThermalProbeListener> thermalListener; 180 181 /** The subsystem this power model belongs to */ 182 SubSystem * subsystem; 183 184 /** The clocked object we belong to */ 185 ClockedObject * clocked_object; 186}; 187 188#endif 189