]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
cpufreq: powernv: Use PMCR to verify global and local pstate
authorAkshay Adiga <akshay.adiga@linux.vnet.ibm.com>
Tue, 8 Nov 2016 13:33:28 +0000 (19:03 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 11 Nov 2016 00:41:02 +0000 (01:41 +0100)
As fast_switch() may get called with interrupt disable mode, we cannot
hold a mutex to update the global_pstate_info. So currently, fast_switch()
does not update the global_pstate_info and it will end up with stale data
whenever pstate is updated through fast_switch().

As the gpstate_timer can fire after fast_switch() has updated the pstates,
the timer handler cannot rely on the cached values of local and global
pstate and needs to read it from the PMCR.

Only gpstate_timer_handler() is affected by the stale cached pstate data
beacause either fast_switch() or target_index() routines will be called
for a given govenor, but gpstate_timer can fire after the governor has
changed to schedutil.

Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
Reviewed-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/powernv-cpufreq.c

index 4a4380d728ad347760e59e4f2007dedc5d5299a4..c82304b7a4c004c9271aafc5181b27144b9d113d 100644 (file)
 #define PMSR_PSAFE_ENABLE      (1UL << 30)
 #define PMSR_SPR_EM_DISABLE    (1UL << 31)
 #define PMSR_MAX(x)            ((x >> 32) & 0xFF)
+#define LPSTATE_SHIFT          48
+#define GPSTATE_SHIFT          56
+#define GET_LPSTATE(x)         (((x) >> LPSTATE_SHIFT) & 0xFF)
+#define GET_GPSTATE(x)         (((x) >> GPSTATE_SHIFT) & 0xFF)
 
 #define MAX_RAMP_DOWN_TIME                             5120
 /*
@@ -592,7 +596,8 @@ void gpstate_timer_handler(unsigned long data)
 {
        struct cpufreq_policy *policy = (struct cpufreq_policy *)data;
        struct global_pstate_info *gpstates = policy->driver_data;
-       int gpstate_idx;
+       int gpstate_idx, lpstate_idx;
+       unsigned long val;
        unsigned int time_diff = jiffies_to_msecs(jiffies)
                                        - gpstates->last_sampled_time;
        struct powernv_smp_call_data freq_data;
@@ -600,21 +605,36 @@ void gpstate_timer_handler(unsigned long data)
        if (!spin_trylock(&gpstates->gpstate_lock))
                return;
 
+       /*
+        * If PMCR was last updated was using fast_swtich then
+        * We may have wrong in gpstate->last_lpstate_idx
+        * value. Hence, read from PMCR to get correct data.
+        */
+       val = get_pmspr(SPRN_PMCR);
+       freq_data.gpstate_id = (s8)GET_GPSTATE(val);
+       freq_data.pstate_id = (s8)GET_LPSTATE(val);
+       if (freq_data.gpstate_id  == freq_data.pstate_id) {
+               reset_gpstates(policy);
+               spin_unlock(&gpstates->gpstate_lock);
+               return;
+       }
+
        gpstates->last_sampled_time += time_diff;
        gpstates->elapsed_time += time_diff;
-       freq_data.pstate_id = idx_to_pstate(gpstates->last_lpstate_idx);
 
-       if ((gpstates->last_gpstate_idx == gpstates->last_lpstate_idx) ||
-           (gpstates->elapsed_time > MAX_RAMP_DOWN_TIME)) {
+       if (gpstates->elapsed_time > MAX_RAMP_DOWN_TIME) {
                gpstate_idx = pstate_to_idx(freq_data.pstate_id);
                reset_gpstates(policy);
                gpstates->highest_lpstate_idx = gpstate_idx;
        } else {
+               lpstate_idx = pstate_to_idx(freq_data.pstate_id);
                gpstate_idx = calc_global_pstate(gpstates->elapsed_time,
                                                 gpstates->highest_lpstate_idx,
-                                                gpstates->last_lpstate_idx);
+                                                lpstate_idx);
        }
-
+       freq_data.gpstate_id = idx_to_pstate(gpstate_idx);
+       gpstates->last_gpstate_idx = gpstate_idx;
+       gpstates->last_lpstate_idx = lpstate_idx;
        /*
         * If local pstate is equal to global pstate, rampdown is over
         * So timer is not required to be queued.
@@ -622,10 +642,6 @@ void gpstate_timer_handler(unsigned long data)
        if (gpstate_idx != gpstates->last_lpstate_idx)
                queue_gpstate_timer(gpstates);
 
-       freq_data.gpstate_id = idx_to_pstate(gpstate_idx);
-       gpstates->last_gpstate_idx = pstate_to_idx(freq_data.gpstate_id);
-       gpstates->last_lpstate_idx = pstate_to_idx(freq_data.pstate_id);
-
        spin_unlock(&gpstates->gpstate_lock);
 
        /* Timer may get migrated to a different cpu on cpu hot unplug */