mathexpr_powermodel.cc revision 11527
12810SN/A/* 210764Sandreas.hansson@arm.com * Copyright (c) 2016 ARM Limited 39663Suri.wiener@arm.com * All rights reserved 49663Suri.wiener@arm.com * 59663Suri.wiener@arm.com * The license below extends only to copyright in the software and shall 69663Suri.wiener@arm.com * not be construed as granting a license to any other intellectual 79663Suri.wiener@arm.com * property including but not limited to intellectual property relating 89663Suri.wiener@arm.com * to a hardware implementation of the functionality of the software 99663Suri.wiener@arm.com * licensed hereunder. You may use the software subject to the license 109663Suri.wiener@arm.com * terms below provided that you ensure that this notice is replicated 119663Suri.wiener@arm.com * unmodified and in its entirety in all distributions of the software, 129663Suri.wiener@arm.com * modified or unmodified, in source code or in binary form. 139663Suri.wiener@arm.com * 142810SN/A * Redistribution and use in source and binary forms, with or without 157636Ssteve.reinhardt@amd.com * modification, are permitted provided that the following conditions are 162810SN/A * met: redistributions of source code must retain the above copyright 172810SN/A * notice, this list of conditions and the following disclaimer; 182810SN/A * redistributions in binary form must reproduce the above copyright 192810SN/A * notice, this list of conditions and the following disclaimer in the 202810SN/A * documentation and/or other materials provided with the distribution; 212810SN/A * neither the name of the copyright holders nor the names of its 222810SN/A * contributors may be used to endorse or promote products derived from 232810SN/A * this software without specific prior written permission. 242810SN/A * 252810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 262810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 272810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 282810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 292810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 302810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 312810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 322810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 332810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 342810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 352810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 362810SN/A * 372810SN/A * Authors: David Guillen Fandos 382810SN/A */ 392810SN/A 402810SN/A#include "sim/power/mathexpr_powermodel.hh" 412810SN/A 422810SN/A#include "base/statistics.hh" 432810SN/A#include "params/MathExprPowerModel.hh" 442810SN/A#include "sim/mathexpr.hh" 452810SN/A#include "sim/power/thermal_model.hh" 462810SN/A#include "sim/sim_object.hh" 472810SN/A 482810SN/AMathExprPowerModel::MathExprPowerModel(const Params *p) 492810SN/A : PowerModelState(p), dyn_expr(p->dyn), st_expr(p->st) 506216Snate@binkert.org{ 516216Snate@binkert.org // Calculate the name of the object we belong to 522810SN/A std::vector<std::string> path; 532810SN/A tokenize(path, name(), '.', true); 542810SN/A // It's something like xyz.power_model.pm2 556216Snate@binkert.org assert(path.size() > 2); 566216Snate@binkert.org for (unsigned i = 0; i < path.size() - 2; i++) 578232Snate@binkert.org basename += path[i] + "."; 586216Snate@binkert.org} 595338Sstever@gmail.com 606216Snate@binkert.orgvoid 612810SN/AMathExprPowerModel::startup() 622810SN/A{ 632810SN/A // Create a map with stats and pointers for quick access 649725Sandreas.hansson@arm.com // Has to be done here, since we need access to the statsList 6510582SCurtis.Dunham@arm.com for (auto & i: Stats::statsList()) 6610503SCurtis.Dunham@arm.com if (i->name.find(basename) == 0) 6710764Sandreas.hansson@arm.com stats_map[i->name.substr(basename.size())] = i; 6810764Sandreas.hansson@arm.com} 6911197Sandreas.hansson@arm.com 7011278Sandreas.hansson@arm.comdouble 712810SN/AMathExprPowerModel::getStatValue(const std::string &name) const 722810SN/A{ 732810SN/A using namespace Stats; 744903SN/A 754903SN/A // Automatic variables: 764903SN/A if (name == "temp") 774903SN/A return _temp; 784903SN/A 794903SN/A // Try to cast the stat, only these are supported right now 804903SN/A Info *info = stats_map.at(name); 814908SN/A 825875Ssteve.reinhardt@amd.com ScalarInfo *si = dynamic_cast<ScalarInfo*>(info); 834903SN/A if (si) 845875Ssteve.reinhardt@amd.com return si->value(); 854903SN/A FormulaInfo *fi = dynamic_cast<FormulaInfo*>(info); 864903SN/A if (fi) 874903SN/A return fi->total(); 884903SN/A 897669Ssteve.reinhardt@amd.com panic("Unknown stat type!\n"); 907669Ssteve.reinhardt@amd.com} 917669Ssteve.reinhardt@amd.com 927669Ssteve.reinhardt@amd.comvoid 934903SN/AMathExprPowerModel::regStats() 944903SN/A{ 955318SN/A PowerModelState::regStats(); 964908SN/A} 975318SN/A 989543Ssascha.bischoff@arm.comMathExprPowerModel* 999543Ssascha.bischoff@arm.comMathExprPowerModelParams::create() 1009543Ssascha.bischoff@arm.com{ 1019543Ssascha.bischoff@arm.com return new MathExprPowerModel(this); 1024908SN/A} 1034908SN/A