27
27
#include <linux/pm_qos.h>
28
28
#include <trace/events/power.h>
29
29
30
+ #include <asm/cpu.h>
30
31
#include <asm/div64.h>
31
32
#include <asm/msr.h>
32
33
#include <asm/cpu_device_id.h>
@@ -280,10 +281,10 @@ static struct cpudata **all_cpu_data;
280
281
* structure is used to store those callbacks.
281
282
*/
282
283
struct pstate_funcs {
283
- int (* get_max )(void );
284
- int (* get_max_physical )(void );
285
- int (* get_min )(void );
286
- int (* get_turbo )(void );
284
+ int (* get_max )(int cpu );
285
+ int (* get_max_physical )(int cpu );
286
+ int (* get_min )(int cpu );
287
+ int (* get_turbo )(int cpu );
287
288
int (* get_scaling )(void );
288
289
int (* get_cpu_scaling )(int cpu );
289
290
int (* get_aperf_mperf_shift )(void );
@@ -398,16 +399,6 @@ static int intel_pstate_get_cppc_guaranteed(int cpu)
398
399
399
400
return cppc_perf .nominal_perf ;
400
401
}
401
-
402
- static u32 intel_pstate_cppc_nominal (int cpu )
403
- {
404
- u64 nominal_perf ;
405
-
406
- if (cppc_get_nominal_perf (cpu , & nominal_perf ))
407
- return 0 ;
408
-
409
- return nominal_perf ;
410
- }
411
402
#else /* CONFIG_ACPI_CPPC_LIB */
412
403
static inline void intel_pstate_set_itmt_prio (int cpu )
413
404
{
@@ -531,35 +522,18 @@ static void intel_pstate_hybrid_hwp_adjust(struct cpudata *cpu)
531
522
{
532
523
int perf_ctl_max_phys = cpu -> pstate .max_pstate_physical ;
533
524
int perf_ctl_scaling = cpu -> pstate .perf_ctl_scaling ;
534
- int perf_ctl_turbo = pstate_funcs .get_turbo ();
535
- int turbo_freq = perf_ctl_turbo * perf_ctl_scaling ;
525
+ int perf_ctl_turbo = pstate_funcs .get_turbo (cpu -> cpu );
536
526
int scaling = cpu -> pstate .scaling ;
537
527
538
528
pr_debug ("CPU%d: perf_ctl_max_phys = %d\n" , cpu -> cpu , perf_ctl_max_phys );
539
- pr_debug ("CPU%d: perf_ctl_max = %d\n" , cpu -> cpu , pstate_funcs .get_max ());
540
529
pr_debug ("CPU%d: perf_ctl_turbo = %d\n" , cpu -> cpu , perf_ctl_turbo );
541
530
pr_debug ("CPU%d: perf_ctl_scaling = %d\n" , cpu -> cpu , perf_ctl_scaling );
542
531
pr_debug ("CPU%d: HWP_CAP guaranteed = %d\n" , cpu -> cpu , cpu -> pstate .max_pstate );
543
532
pr_debug ("CPU%d: HWP_CAP highest = %d\n" , cpu -> cpu , cpu -> pstate .turbo_pstate );
544
533
pr_debug ("CPU%d: HWP-to-frequency scaling factor: %d\n" , cpu -> cpu , scaling );
545
534
546
- /*
547
- * If the product of the HWP performance scaling factor and the HWP_CAP
548
- * highest performance is greater than the maximum turbo frequency
549
- * corresponding to the pstate_funcs.get_turbo() return value, the
550
- * scaling factor is too high, so recompute it to make the HWP_CAP
551
- * highest performance correspond to the maximum turbo frequency.
552
- */
553
- cpu -> pstate .turbo_freq = cpu -> pstate .turbo_pstate * scaling ;
554
- if (turbo_freq < cpu -> pstate .turbo_freq ) {
555
- cpu -> pstate .turbo_freq = turbo_freq ;
556
- scaling = DIV_ROUND_UP (turbo_freq , cpu -> pstate .turbo_pstate );
557
- cpu -> pstate .scaling = scaling ;
558
-
559
- pr_debug ("CPU%d: refined HWP-to-frequency scaling factor: %d\n" ,
560
- cpu -> cpu , scaling );
561
- }
562
-
535
+ cpu -> pstate .turbo_freq = rounddown (cpu -> pstate .turbo_pstate * scaling ,
536
+ perf_ctl_scaling );
563
537
cpu -> pstate .max_freq = rounddown (cpu -> pstate .max_pstate * scaling ,
564
538
perf_ctl_scaling );
565
539
@@ -1740,23 +1714,23 @@ static void intel_pstate_hwp_enable(struct cpudata *cpudata)
1740
1714
intel_pstate_update_epp_defaults (cpudata );
1741
1715
}
1742
1716
1743
- static int atom_get_min_pstate (void )
1717
+ static int atom_get_min_pstate (int not_used )
1744
1718
{
1745
1719
u64 value ;
1746
1720
1747
1721
rdmsrl (MSR_ATOM_CORE_RATIOS , value );
1748
1722
return (value >> 8 ) & 0x7F ;
1749
1723
}
1750
1724
1751
- static int atom_get_max_pstate (void )
1725
+ static int atom_get_max_pstate (int not_used )
1752
1726
{
1753
1727
u64 value ;
1754
1728
1755
1729
rdmsrl (MSR_ATOM_CORE_RATIOS , value );
1756
1730
return (value >> 16 ) & 0x7F ;
1757
1731
}
1758
1732
1759
- static int atom_get_turbo_pstate (void )
1733
+ static int atom_get_turbo_pstate (int not_used )
1760
1734
{
1761
1735
u64 value ;
1762
1736
@@ -1834,23 +1808,23 @@ static void atom_get_vid(struct cpudata *cpudata)
1834
1808
cpudata -> vid .turbo = value & 0x7f ;
1835
1809
}
1836
1810
1837
- static int core_get_min_pstate (void )
1811
+ static int core_get_min_pstate (int cpu )
1838
1812
{
1839
1813
u64 value ;
1840
1814
1841
- rdmsrl ( MSR_PLATFORM_INFO , value );
1815
+ rdmsrl_on_cpu ( cpu , MSR_PLATFORM_INFO , & value );
1842
1816
return (value >> 40 ) & 0xFF ;
1843
1817
}
1844
1818
1845
- static int core_get_max_pstate_physical (void )
1819
+ static int core_get_max_pstate_physical (int cpu )
1846
1820
{
1847
1821
u64 value ;
1848
1822
1849
- rdmsrl ( MSR_PLATFORM_INFO , value );
1823
+ rdmsrl_on_cpu ( cpu , MSR_PLATFORM_INFO , & value );
1850
1824
return (value >> 8 ) & 0xFF ;
1851
1825
}
1852
1826
1853
- static int core_get_tdp_ratio (u64 plat_info )
1827
+ static int core_get_tdp_ratio (int cpu , u64 plat_info )
1854
1828
{
1855
1829
/* Check how many TDP levels present */
1856
1830
if (plat_info & 0x600000000 ) {
@@ -1860,13 +1834,13 @@ static int core_get_tdp_ratio(u64 plat_info)
1860
1834
int err ;
1861
1835
1862
1836
/* Get the TDP level (0, 1, 2) to get ratios */
1863
- err = rdmsrl_safe ( MSR_CONFIG_TDP_CONTROL , & tdp_ctrl );
1837
+ err = rdmsrl_safe_on_cpu ( cpu , MSR_CONFIG_TDP_CONTROL , & tdp_ctrl );
1864
1838
if (err )
1865
1839
return err ;
1866
1840
1867
1841
/* TDP MSR are continuous starting at 0x648 */
1868
1842
tdp_msr = MSR_CONFIG_TDP_NOMINAL + (tdp_ctrl & 0x03 );
1869
- err = rdmsrl_safe ( tdp_msr , & tdp_ratio );
1843
+ err = rdmsrl_safe_on_cpu ( cpu , tdp_msr , & tdp_ratio );
1870
1844
if (err )
1871
1845
return err ;
1872
1846
@@ -1883,18 +1857,18 @@ static int core_get_tdp_ratio(u64 plat_info)
1883
1857
return - ENXIO ;
1884
1858
}
1885
1859
1886
- static int core_get_max_pstate (void )
1860
+ static int core_get_max_pstate (int cpu )
1887
1861
{
1888
1862
u64 tar ;
1889
1863
u64 plat_info ;
1890
1864
int max_pstate ;
1891
1865
int tdp_ratio ;
1892
1866
int err ;
1893
1867
1894
- rdmsrl ( MSR_PLATFORM_INFO , plat_info );
1868
+ rdmsrl_on_cpu ( cpu , MSR_PLATFORM_INFO , & plat_info );
1895
1869
max_pstate = (plat_info >> 8 ) & 0xFF ;
1896
1870
1897
- tdp_ratio = core_get_tdp_ratio (plat_info );
1871
+ tdp_ratio = core_get_tdp_ratio (cpu , plat_info );
1898
1872
if (tdp_ratio <= 0 )
1899
1873
return max_pstate ;
1900
1874
@@ -1903,7 +1877,7 @@ static int core_get_max_pstate(void)
1903
1877
return tdp_ratio ;
1904
1878
}
1905
1879
1906
- err = rdmsrl_safe ( MSR_TURBO_ACTIVATION_RATIO , & tar );
1880
+ err = rdmsrl_safe_on_cpu ( cpu , MSR_TURBO_ACTIVATION_RATIO , & tar );
1907
1881
if (!err ) {
1908
1882
int tar_levels ;
1909
1883
@@ -1918,13 +1892,13 @@ static int core_get_max_pstate(void)
1918
1892
return max_pstate ;
1919
1893
}
1920
1894
1921
- static int core_get_turbo_pstate (void )
1895
+ static int core_get_turbo_pstate (int cpu )
1922
1896
{
1923
1897
u64 value ;
1924
1898
int nont , ret ;
1925
1899
1926
- rdmsrl ( MSR_TURBO_RATIO_LIMIT , value );
1927
- nont = core_get_max_pstate ();
1900
+ rdmsrl_on_cpu ( cpu , MSR_TURBO_RATIO_LIMIT , & value );
1901
+ nont = core_get_max_pstate (cpu );
1928
1902
ret = (value ) & 255 ;
1929
1903
if (ret <= nont )
1930
1904
ret = nont ;
@@ -1952,50 +1926,37 @@ static int knl_get_aperf_mperf_shift(void)
1952
1926
return 10 ;
1953
1927
}
1954
1928
1955
- static int knl_get_turbo_pstate (void )
1929
+ static int knl_get_turbo_pstate (int cpu )
1956
1930
{
1957
1931
u64 value ;
1958
1932
int nont , ret ;
1959
1933
1960
- rdmsrl ( MSR_TURBO_RATIO_LIMIT , value );
1961
- nont = core_get_max_pstate ();
1934
+ rdmsrl_on_cpu ( cpu , MSR_TURBO_RATIO_LIMIT , & value );
1935
+ nont = core_get_max_pstate (cpu );
1962
1936
ret = (((value ) >> 8 ) & 0xFF );
1963
1937
if (ret <= nont )
1964
1938
ret = nont ;
1965
1939
return ret ;
1966
1940
}
1967
1941
1968
- #ifdef CONFIG_ACPI_CPPC_LIB
1969
- static u32 hybrid_ref_perf ;
1970
-
1971
- static int hybrid_get_cpu_scaling (int cpu )
1942
+ static void hybrid_get_type (void * data )
1972
1943
{
1973
- return DIV_ROUND_UP (core_get_scaling () * hybrid_ref_perf ,
1974
- intel_pstate_cppc_nominal (cpu ));
1944
+ u8 * cpu_type = data ;
1945
+
1946
+ * cpu_type = get_this_hybrid_cpu_type ();
1975
1947
}
1976
1948
1977
- static void intel_pstate_cppc_set_cpu_scaling ( void )
1949
+ static int hybrid_get_cpu_scaling ( int cpu )
1978
1950
{
1979
- u32 min_nominal_perf = U32_MAX ;
1980
- int cpu ;
1951
+ u8 cpu_type = 0 ;
1981
1952
1982
- for_each_present_cpu (cpu ) {
1983
- u32 nominal_perf = intel_pstate_cppc_nominal (cpu );
1953
+ smp_call_function_single (cpu , hybrid_get_type , & cpu_type , 1 );
1954
+ /* P-cores have a smaller perf level-to-freqency scaling factor. */
1955
+ if (cpu_type == 0x40 )
1956
+ return 78741 ;
1984
1957
1985
- if (nominal_perf && nominal_perf < min_nominal_perf )
1986
- min_nominal_perf = nominal_perf ;
1987
- }
1988
-
1989
- if (min_nominal_perf < U32_MAX ) {
1990
- hybrid_ref_perf = min_nominal_perf ;
1991
- pstate_funcs .get_cpu_scaling = hybrid_get_cpu_scaling ;
1992
- }
1958
+ return core_get_scaling ();
1993
1959
}
1994
- #else
1995
- static inline void intel_pstate_cppc_set_cpu_scaling (void )
1996
- {
1997
- }
1998
- #endif /* CONFIG_ACPI_CPPC_LIB */
1999
1960
2000
1961
static void intel_pstate_set_pstate (struct cpudata * cpu , int pstate )
2001
1962
{
@@ -2025,10 +1986,10 @@ static void intel_pstate_max_within_limits(struct cpudata *cpu)
2025
1986
2026
1987
static void intel_pstate_get_cpu_pstates (struct cpudata * cpu )
2027
1988
{
2028
- int perf_ctl_max_phys = pstate_funcs .get_max_physical ();
1989
+ int perf_ctl_max_phys = pstate_funcs .get_max_physical (cpu -> cpu );
2029
1990
int perf_ctl_scaling = pstate_funcs .get_scaling ();
2030
1991
2031
- cpu -> pstate .min_pstate = pstate_funcs .get_min ();
1992
+ cpu -> pstate .min_pstate = pstate_funcs .get_min (cpu -> cpu );
2032
1993
cpu -> pstate .max_pstate_physical = perf_ctl_max_phys ;
2033
1994
cpu -> pstate .perf_ctl_scaling = perf_ctl_scaling ;
2034
1995
@@ -2044,8 +2005,8 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
2044
2005
}
2045
2006
} else {
2046
2007
cpu -> pstate .scaling = perf_ctl_scaling ;
2047
- cpu -> pstate .max_pstate = pstate_funcs .get_max ();
2048
- cpu -> pstate .turbo_pstate = pstate_funcs .get_turbo ();
2008
+ cpu -> pstate .max_pstate = pstate_funcs .get_max (cpu -> cpu );
2009
+ cpu -> pstate .turbo_pstate = pstate_funcs .get_turbo (cpu -> cpu );
2049
2010
}
2050
2011
2051
2012
if (cpu -> pstate .scaling == perf_ctl_scaling ) {
@@ -3221,9 +3182,9 @@ static unsigned int force_load __initdata;
3221
3182
3222
3183
static int __init intel_pstate_msrs_not_valid (void )
3223
3184
{
3224
- if (!pstate_funcs .get_max () ||
3225
- !pstate_funcs .get_min () ||
3226
- !pstate_funcs .get_turbo ())
3185
+ if (!pstate_funcs .get_max (0 ) ||
3186
+ !pstate_funcs .get_min (0 ) ||
3187
+ !pstate_funcs .get_turbo (0 ))
3227
3188
return - ENODEV ;
3228
3189
3229
3190
return 0 ;
@@ -3450,7 +3411,7 @@ static int __init intel_pstate_init(void)
3450
3411
default_driver = & intel_pstate ;
3451
3412
3452
3413
if (boot_cpu_has (X86_FEATURE_HYBRID_CPU ))
3453
- intel_pstate_cppc_set_cpu_scaling () ;
3414
+ pstate_funcs . get_cpu_scaling = hybrid_get_cpu_scaling ;
3454
3415
3455
3416
goto hwp_cpu_matched ;
3456
3417
}
0 commit comments