sim-power: Specify the states a PowerState object can be in
authorAnouk Van Laer <anouk.vanlaer@arm.com>
Wed, 4 Oct 2017 13:15:36 +0000 (14:15 +0100)
committerNikos Nikoleris <nikos.nikoleris@arm.com>
Wed, 29 Apr 2020 21:03:31 +0000 (21:03 +0000)
This commit adds the concept of possible power states to the
PowerState SimObject. This is a list of the power states a specific
object can be in. Before transitioning to a power state, a PowerState
object will first check if the requested power states is actually an
allowed state. The user can restricted the power states a
ClockedObject can go to during configuration. In addition, this change
sets the power states, a CPU can be in.

Change-Id: Ida414a87554a14f09767a272b54b5d19bfc8e911
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/28050
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/cpu/BaseCPU.py
src/sim/PowerState.py
src/sim/power_state.cc
src/sim/power_state.hh

index 67d95d0f43c87c7a726c61fe849b4bd6bd17979f..ab70d1d7f9a851ddd3d5e49493b737582deca61f 100644 (file)
@@ -303,3 +303,7 @@ class BaseCPU(ClockedObject):
             cpus_node.append(node)
 
         yield cpus_node
+
+    def __init__(self, **kwargs):
+        super(BaseCPU, self).__init__(**kwargs)
+        self.power_state.possible_states=['ON', 'CLK_GATED', 'OFF']
index 59491ec152f08d1623b4997a90c33561e213d1f8..bfa53e2689393cc24001342edafa1e60d33d5325 100644 (file)
@@ -62,6 +62,11 @@ class PowerState(SimObject):
     # routine
     default_state = Param.PwrState("UNDEFINED", "Default Power State")
 
+    # Possible power states this object can be in sorted from the most
+    # to the least performant
+    possible_states = VectorParam.PwrState(
+        [], "Power states this object can be in")
+
     clk_gate_min = Param.Latency('1ns',"Min value of the distribution")
     clk_gate_max = Param.Latency('1s',"Max value of the distribution")
     clk_gate_bins = Param.Unsigned('20', "# bins in clk gated distribution")
index 28b0b83dee28ec8b45ce53c7f9046f21ef12edcc..a2ed7fe282a6cadf8a2e598a340886bba9cc33bd 100644 (file)
@@ -41,7 +41,9 @@
 
 PowerState::PowerState(const PowerStateParams *p) :
     SimObject(p), _currState(p->default_state),
-    stats(*this)
+    possibleStates(p->possible_states.begin(),
+                   p->possible_states.end()),
+    prvEvalTick(0), stats(*this)
 {
 }
 
@@ -68,6 +70,11 @@ PowerState::unserialize(CheckpointIn &cp)
 void
 PowerState::set(Enums::PwrState p)
 {
+    // Check if this power state is actually allowed by checking whether it is
+    // present in pwrStateToIndex-dictionary
+    panic_if(possibleStates.find(p) == possibleStates.end(),
+             "Cannot go to %s in %s \n", Enums::PwrStateStrings[p], name());
+
     // Function should ideally be called only when there is a state change
     if (_currState == p) {
         warn_once("PowerState: Already in the requested power state, "
index 8b93b450b78fc53ae12085af06981300f2d7eee9..4565c2b1f66a91bdc9e9fa85b8110fb13327ed45 100644 (file)
@@ -98,11 +98,22 @@ class PowerState : public SimObject
      */
     void computeStats();
 
+    /**
+     * Return the power states this object can be in
+     */
+    std::set<Enums::PwrState> getPossibleStates() const
+    {
+        return possibleStates;
+    }
+
   protected:
 
     /** To keep track of the current power state */
     Enums::PwrState _currState;
 
+    /** The possible power states this object can be in */
+    const std::set<Enums::PwrState> possibleStates;
+
     /** Last tick the power stats were calculated */
     Tick prvEvalTick = 0;