cpufreq: intel_pstate: get P1 from TAR when available
authorSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Wed, 14 Oct 2015 23:11:59 +0000 (16:11 -0700)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 14 Oct 2015 23:53:18 +0000 (01:53 +0200)
After Ivybridge, the max non turbo ratio obtained from platform info msr
is not always guaranteed P1 on client platforms. The max non turbo
activation ratio (TAR), determines the max for the current level of TDP.
The ratio in platform info is physical max. The TAR MSR can be locked,
so updating this value is not possible on all platforms.
This change gets this ratio from MSR TURBO_ACTIVATION_RATIO if
available,
but also do some sanity checking to make sure that this value is
correct.
The sanity check involves reading the TDP ratio for the current tdp
control value when platform has configurable TDP present and matching
TAC
with this.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Acked-by: Kristen Carlson Accardi <kristen@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
arch/x86/include/asm/msr-index.h
drivers/cpufreq/intel_pstate.c

index b8c14bb7fc8f37ee004dc10342a99c8579110e1d..9f3905697f123200eb1f7ecc749239dc5d5e1b2d 100644 (file)
 #define MSR_GFX_PERF_LIMIT_REASONS     0x000006B0
 #define MSR_RING_PERF_LIMIT_REASONS    0x000006B1
 
+/* Config TDP MSRs */
+#define MSR_CONFIG_TDP_NOMINAL         0x00000648
+#define MSR_CONFIG_TDP_LEVEL1          0x00000649
+#define MSR_CONFIG_TDP_LEVEL2          0x0000064A
+#define MSR_CONFIG_TDP_CONTROL         0x0000064B
+#define MSR_TURBO_ACTIVATION_RATIO     0x0000064C
+
 /* Hardware P state interface */
 #define MSR_PPERF                      0x0000064e
 #define MSR_PERF_LIMIT_REASONS         0x0000064f
index 3af9dd7332e6927d8dd860b5af410fba738bff4a..da92d0201d529d09114cf77b0e41ebde29aaecd3 100644 (file)
@@ -43,7 +43,6 @@
 #define int_tofp(X) ((int64_t)(X) << FRAC_BITS)
 #define fp_toint(X) ((X) >> FRAC_BITS)
 
-
 static inline int32_t mul_fp(int32_t x, int32_t y)
 {
        return ((int64_t)x * (int64_t)y) >> FRAC_BITS;
@@ -593,10 +592,42 @@ static int core_get_min_pstate(void)
 
 static int core_get_max_pstate(void)
 {
-       u64 value;
+       u64 tar;
+       u64 plat_info;
+       int max_pstate;
+       int err;
+
+       rdmsrl(MSR_PLATFORM_INFO, plat_info);
+       max_pstate = (plat_info >> 8) & 0xFF;
+
+       err = rdmsrl_safe(MSR_TURBO_ACTIVATION_RATIO, &tar);
+       if (!err) {
+               /* Do some sanity checking for safety */
+               if (plat_info & 0x600000000) {
+                       u64 tdp_ctrl;
+                       u64 tdp_ratio;
+                       int tdp_msr;
+
+                       err = rdmsrl_safe(MSR_CONFIG_TDP_CONTROL, &tdp_ctrl);
+                       if (err)
+                               goto skip_tar;
+
+                       tdp_msr = MSR_CONFIG_TDP_NOMINAL + tdp_ctrl;
+                       err = rdmsrl_safe(tdp_msr, &tdp_ratio);
+                       if (err)
+                               goto skip_tar;
+
+                       if (tdp_ratio - 1 == tar) {
+                               max_pstate = tar;
+                               pr_debug("max_pstate=TAC %x\n", max_pstate);
+                       } else {
+                               goto skip_tar;
+                       }
+               }
+       }
 
-       rdmsrl(MSR_PLATFORM_INFO, value);
-       return (value >> 8) & 0xFF;
+skip_tar:
+       return max_pstate;
 }
 
 static int core_get_turbo_pstate(void)