111527Sdavid.guillen@arm.com/*
211967Sandreas.sandberg@arm.com * Copyright (c) 2016-2017 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_MATHEXPR_POWERMODEL_PM_HH__
4111527Sdavid.guillen@arm.com#define __SIM_MATHEXPR_POWERMODEL_PM_HH__
4211527Sdavid.guillen@arm.com
4311527Sdavid.guillen@arm.com#include <unordered_map>
4411527Sdavid.guillen@arm.com
4511527Sdavid.guillen@arm.com#include "params/MathExprPowerModel.hh"
4611527Sdavid.guillen@arm.com#include "sim/mathexpr.hh"
4711527Sdavid.guillen@arm.com#include "sim/power/power_model.hh"
4811800Sbrandon.potter@amd.com
4911800Sbrandon.potter@amd.comnamespace Stats {
5011800Sbrandon.potter@amd.com    class Info;
5111800Sbrandon.potter@amd.com}
5211527Sdavid.guillen@arm.com
5311527Sdavid.guillen@arm.com/**
5411527Sdavid.guillen@arm.com * A Equation power model. The power is represented as a combination
5511527Sdavid.guillen@arm.com * of some stats and automatic variables (like temperature).
5611527Sdavid.guillen@arm.com */
5711527Sdavid.guillen@arm.comclass MathExprPowerModel : public PowerModelState
5811527Sdavid.guillen@arm.com{
5911527Sdavid.guillen@arm.com  public:
6011527Sdavid.guillen@arm.com
6111527Sdavid.guillen@arm.com    typedef MathExprPowerModelParams Params;
6211527Sdavid.guillen@arm.com    MathExprPowerModel(const Params *p);
6311527Sdavid.guillen@arm.com
6411527Sdavid.guillen@arm.com    /**
6511527Sdavid.guillen@arm.com     * Get the dynamic power consumption.
6611527Sdavid.guillen@arm.com     *
6711527Sdavid.guillen@arm.com     * @return Power (Watts) consumed by this object (dynamic component)
6811527Sdavid.guillen@arm.com     */
6911967Sandreas.sandberg@arm.com    double getDynamicPower() const { return eval(dyn_expr); }
7011527Sdavid.guillen@arm.com
7111527Sdavid.guillen@arm.com    /**
7211527Sdavid.guillen@arm.com     * Get the static power consumption.
7311527Sdavid.guillen@arm.com     *
7411527Sdavid.guillen@arm.com     * @return Power (Watts) consumed by this object (static component)
7511527Sdavid.guillen@arm.com     */
7611967Sandreas.sandberg@arm.com    double getStaticPower() const { return eval(st_expr); }
7711527Sdavid.guillen@arm.com
7811527Sdavid.guillen@arm.com    /**
7911527Sdavid.guillen@arm.com     * Get the value for a variable (maps to a stat)
8011527Sdavid.guillen@arm.com     *
8111527Sdavid.guillen@arm.com     * @param name Name of the variable to retrieve the value from
8211527Sdavid.guillen@arm.com     *
8311527Sdavid.guillen@arm.com     * @return Power (Watts) consumed by this object (static component)
8411527Sdavid.guillen@arm.com     */
8511527Sdavid.guillen@arm.com    double getStatValue(const std::string & name) const;
8611527Sdavid.guillen@arm.com
8711527Sdavid.guillen@arm.com    void startup();
8811527Sdavid.guillen@arm.com
8911527Sdavid.guillen@arm.com    void regStats();
9011527Sdavid.guillen@arm.com
9111527Sdavid.guillen@arm.com  private:
9211967Sandreas.sandberg@arm.com    /**
9311967Sandreas.sandberg@arm.com     * Evaluate an expression in the context of this object, fatal if
9411967Sandreas.sandberg@arm.com     * evaluation fails.
9511967Sandreas.sandberg@arm.com     *
9611967Sandreas.sandberg@arm.com     * @param expr Expression to evaluate
9711967Sandreas.sandberg@arm.com     * @return Value of expression.
9811967Sandreas.sandberg@arm.com     */
9911967Sandreas.sandberg@arm.com    double eval(const MathExpr &expr) const;
10011967Sandreas.sandberg@arm.com
10111967Sandreas.sandberg@arm.com    /**
10211967Sandreas.sandberg@arm.com     * Evaluate an expression in the context of this object, set
10311967Sandreas.sandberg@arm.com     * failed if evaluation failed.
10411967Sandreas.sandberg@arm.com     *
10511967Sandreas.sandberg@arm.com     * @param expr Expression to evaluate
10611967Sandreas.sandberg@arm.com     * @return Value of expression.
10711967Sandreas.sandberg@arm.com     */
10811967Sandreas.sandberg@arm.com    double tryEval(const MathExpr &expr) const;
10911527Sdavid.guillen@arm.com
11011527Sdavid.guillen@arm.com    // Math expressions for dynamic and static power
11111527Sdavid.guillen@arm.com    MathExpr dyn_expr, st_expr;
11211527Sdavid.guillen@arm.com
11311527Sdavid.guillen@arm.com    // Basename of the object in the gem5 stats hierachy
11411527Sdavid.guillen@arm.com    std::string basename;
11511527Sdavid.guillen@arm.com
11611527Sdavid.guillen@arm.com    // Map that contains relevant stats for this power model
11711527Sdavid.guillen@arm.com    std::unordered_map<std::string, Stats::Info*> stats_map;
11811967Sandreas.sandberg@arm.com
11911967Sandreas.sandberg@arm.com    // Did the expression fail to evaluate (e.g., because a stat value
12011967Sandreas.sandberg@arm.com    // can't be resolved)
12111967Sandreas.sandberg@arm.com    mutable bool failed;
12211527Sdavid.guillen@arm.com};
12311527Sdavid.guillen@arm.com
12411527Sdavid.guillen@arm.com#endif
125