cpuidle-powernv: Allow Deep stop states that don't stop time
authorGautham R. Shenoy <ego@linux.vnet.ibm.com>
Tue, 16 May 2017 08:49:48 +0000 (14:19 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 30 May 2017 04:59:51 +0000 (14:59 +1000)
The current code in the cpuidle-powernv intialization only allows deep
stop states (indicated by OPAL_PM_STOP_INST_DEEP) which lose timebase
(indicated by OPAL_PM_TIMEBASE_STOP). This assumption goes back to
POWER8 time where deep states used to lose the timebase. However, on
POWER9, we do have stop states that are deep (they lose hypervisor
state) but retain the timebase.

Fix the initialization code in the cpuidle-powernv driver to allow
such deep states.

Further, there is a bug in cpuidle-powernv driver with
CONFIG_TICK_ONESHOT=n where we end up incrementing the nr_idle_states
even if a platform idle state which loses time base was not added to
the cpuidle table.

Fix this by ensuring that the nr_idle_states variable gets incremented
only when the platform idle state was added to the cpuidle table.

Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
drivers/cpuidle/cpuidle-powernv.c

index 12409a519cc5c42d2acad1af4577329448a156be..45eaf06462aeddc611961bb1ab648390f277a076 100644 (file)
@@ -354,6 +354,7 @@ static int powernv_add_idle_states(void)
 
        for (i = 0; i < dt_idle_states; i++) {
                unsigned int exit_latency, target_residency;
+               bool stops_timebase = false;
                /*
                 * If an idle state has exit latency beyond
                 * POWERNV_THRESHOLD_LATENCY_NS then don't use it
@@ -381,6 +382,9 @@ static int powernv_add_idle_states(void)
                        }
                }
 
+               if (flags[i] & OPAL_PM_TIMEBASE_STOP)
+                       stops_timebase = true;
+
                /*
                 * For nap and fastsleep, use default target_residency
                 * values if f/w does not expose it.
@@ -392,8 +396,7 @@ static int powernv_add_idle_states(void)
                        add_powernv_state(nr_idle_states, "Nap",
                                          CPUIDLE_FLAG_NONE, nap_loop,
                                          target_residency, exit_latency, 0, 0);
-               } else if ((flags[i] & OPAL_PM_STOP_INST_FAST) &&
-                               !(flags[i] & OPAL_PM_TIMEBASE_STOP)) {
+               } else if (has_stop_states && !stops_timebase) {
                        add_powernv_state(nr_idle_states, names[i],
                                          CPUIDLE_FLAG_NONE, stop_loop,
                                          target_residency, exit_latency,
@@ -405,8 +408,8 @@ static int powernv_add_idle_states(void)
                 * within this config dependency check.
                 */
 #ifdef CONFIG_TICK_ONESHOT
-               if (flags[i] & OPAL_PM_SLEEP_ENABLED ||
-                       flags[i] & OPAL_PM_SLEEP_ENABLED_ER1) {
+               else if (flags[i] & OPAL_PM_SLEEP_ENABLED ||
+                        flags[i] & OPAL_PM_SLEEP_ENABLED_ER1) {
                        if (!rc)
                                target_residency = 300000;
                        /* Add FASTSLEEP state */
@@ -414,14 +417,15 @@ static int powernv_add_idle_states(void)
                                          CPUIDLE_FLAG_TIMER_STOP,
                                          fastsleep_loop,
                                          target_residency, exit_latency, 0, 0);
-               } else if ((flags[i] & OPAL_PM_STOP_INST_DEEP) &&
-                               (flags[i] & OPAL_PM_TIMEBASE_STOP)) {
+               } else if (has_stop_states && stops_timebase) {
                        add_powernv_state(nr_idle_states, names[i],
                                          CPUIDLE_FLAG_TIMER_STOP, stop_loop,
                                          target_residency, exit_latency,
                                          psscr_val[i], psscr_mask[i]);
                }
 #endif
+               else
+                       continue;
                nr_idle_states++;
        }
 out: