power_model.cc revision 11424:e07fd01651f3
12SN/A/*
21762SN/A * Copyright (c) 2015 ARM Limited
35502Snate@binkert.org * All rights reserved
42SN/A *
52SN/A * The license below extends only to copyright in the software and shall
62SN/A * not be construed as granting a license to any other intellectual
72SN/A * property including but not limited to intellectual property relating
82SN/A * to a hardware implementation of the functionality of the software
92SN/A * licensed hereunder.  You may use the software subject to the license
102SN/A * terms below provided that you ensure that this notice is replicated
112SN/A * unmodified and in its entirety in all distributions of the software,
122SN/A * modified or unmodified, in source code or in binary form.
132SN/A *
142SN/A * Redistribution and use in source and binary forms, with or without
152SN/A * modification, are permitted provided that the following conditions are
162SN/A * met: redistributions of source code must retain the above copyright
172SN/A * notice, this list of conditions and the following disclaimer;
182SN/A * redistributions in binary form must reproduce the above copyright
192SN/A * notice, this list of conditions and the following disclaimer in the
202SN/A * documentation and/or other materials provided with the distribution;
212SN/A * neither the name of the copyright holders nor the names of its
222SN/A * contributors may be used to endorse or promote products derived from
232SN/A * this software without specific prior written permission.
242SN/A *
252SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
262SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
272SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
282665Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
292665Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
302665Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
312665Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
322SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
332SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
345501Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
352SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
362SN/A *
372SN/A * Authors: David Guillen Fandos
382SN/A */
395502Snate@binkert.org
405501Snate@binkert.org#include "sim/power/power_model.hh"
415501Snate@binkert.org
421717SN/A#include "base/statistics.hh"
438232Snate@binkert.org#include "params/PowerModel.hh"
445501Snate@binkert.org#include "params/PowerModelState.hh"
4556SN/A#include "sim/sim_object.hh"
462SN/A#include "sim/sub_system.hh"
472SN/A
482SN/APowerModelState::PowerModelState(const Params *p)
492SN/A    : SimObject(p), _temp(0), clocked_object(NULL)
502SN/A{
512SN/A}
522SN/A
532SN/APowerModel::PowerModel(const Params *p)
542SN/A    : SimObject(p), states_pm(p->pm), subsystem(p->subsystem),
555605Snate@binkert.org      clocked_object(NULL)
562SN/A{
574017Sstever@eecs.umich.edu    panic_if(subsystem == NULL,
584016Sstever@eecs.umich.edu             "Subsystem is NULL! This is not acceptable for a PowerModel!\n");
594017Sstever@eecs.umich.edu    subsystem->registerPowerProducer(this);
604016Sstever@eecs.umich.edu}
615768Snate@binkert.org
625768Snate@binkert.orgvoid
635774Snate@binkert.orgPowerModel::setClockedObject(ClockedObject * clkobj)
647059Snate@binkert.org{
655768Snate@binkert.org    this->clocked_object = clkobj;
665768Snate@binkert.org
675768Snate@binkert.org    for (auto & pms: states_pm)
685768Snate@binkert.org        pms->setClockedObject(clkobj);
695768Snate@binkert.org}
705768Snate@binkert.org
715768Snate@binkert.orgvoid
725768Snate@binkert.orgPowerModel::thermalUpdateCallback(const double & temp)
735768Snate@binkert.org{
745768Snate@binkert.org    for (auto & pms: states_pm)
755768Snate@binkert.org        pms->setTemperature(temp);
765768Snate@binkert.org}
775768Snate@binkert.org
785602Snate@binkert.orgvoid
795602Snate@binkert.orgPowerModel::regProbePoints()
805502Snate@binkert.org{
815503Snate@binkert.org    thermalListener.reset(new ThermalProbeListener (
825502Snate@binkert.org        *this, this->subsystem->getProbeManager(), "thermalUpdate"
835502Snate@binkert.org    ));
845502Snate@binkert.org}
855502Snate@binkert.org
865502Snate@binkert.orgPowerModel*
875503Snate@binkert.orgPowerModelParams::create()
885502Snate@binkert.org{
895502Snate@binkert.org    return new PowerModel(this);
905502Snate@binkert.org}
915502Snate@binkert.org
925503Snate@binkert.orgdouble
935503Snate@binkert.orgPowerModel::getDynamicPower() const
945503Snate@binkert.org{
955502Snate@binkert.org    assert(clocked_object);
965503Snate@binkert.org
975502Snate@binkert.org    std::vector<double> w = clocked_object->pwrStateWeights();
985502Snate@binkert.org
992SN/A    // Same number of states (excluding UNDEFINED)
1002SN/A    assert(w.size() - 1 == states_pm.size());
1012SN/A
1025502Snate@binkert.org    // Make sure we have no UNDEFINED state
1035502Snate@binkert.org    warn_if(w[Enums::PwrState::UNDEFINED] > 0,
1045602Snate@binkert.org        "SimObject in UNDEFINED power state! Power figures might be wrong!\n");
1055502Snate@binkert.org
1065502Snate@binkert.org    double power = 0;
1072SN/A    for (unsigned i = 0; i < states_pm.size(); i++)
1085502Snate@binkert.org        if (w[i + 1] > 0.0f)
1095502Snate@binkert.org            power += states_pm[i]->getDynamicPower() * w[i + 1];
1105503Snate@binkert.org
1115503Snate@binkert.org    return power;
1125503Snate@binkert.org}
1135503Snate@binkert.org
1145503Snate@binkert.orgdouble
1155502Snate@binkert.orgPowerModel::getStaticPower() const
1162SN/A{
1175503Snate@binkert.org    assert(clocked_object);
1185503Snate@binkert.org
1195602Snate@binkert.org    std::vector<double> w = clocked_object->pwrStateWeights();
1205502Snate@binkert.org
1212SN/A    // Same number of states (excluding UNDEFINED)
1225602Snate@binkert.org    assert(w.size() - 1 == states_pm.size());
1235602Snate@binkert.org
1245502Snate@binkert.org    // Make sure we have no UNDEFINED state
1255503Snate@binkert.org    if (w[0] > 0)
1265503Snate@binkert.org        warn("SimObject in UNDEFINED power state! "
1275502Snate@binkert.org             "Power figures might be wrong!\n");
1285503Snate@binkert.org
1295503Snate@binkert.org    // We have N+1 states, being state #0 the default 'UNDEFINED' state
1305503Snate@binkert.org    double power = 0;
1315503Snate@binkert.org    for (unsigned i = 0; i < states_pm.size(); i++)
1325503Snate@binkert.org        // Don't evaluate power if the object hasn't been in that state
1335503Snate@binkert.org        // This fixes issues with NaNs and similar.
1345503Snate@binkert.org        if (w[i + 1] > 0.0f)
1355503Snate@binkert.org            power += states_pm[i]->getStaticPower() * w[i + 1];
1365503Snate@binkert.org
1375503Snate@binkert.org    return power;
1385503Snate@binkert.org}
1395503Snate@binkert.org