@@ -147,7 +147,7 @@ static inline void smpboot_restore_warm_reset_vector(void)
147
147
* ((volatile u32 * )phys_to_virt (TRAMPOLINE_PHYS_LOW )) = 0 ;
148
148
}
149
149
150
- static void init_freq_invariance (void );
150
+ static void init_freq_invariance (bool secondary );
151
151
152
152
/*
153
153
* Report back to the Boot Processor during boot time or to the caller processor
@@ -185,7 +185,7 @@ static void smp_callin(void)
185
185
*/
186
186
set_cpu_sibling_map (raw_smp_processor_id ());
187
187
188
- init_freq_invariance ();
188
+ init_freq_invariance (true );
189
189
190
190
/*
191
191
* Get our bogomips.
@@ -1341,7 +1341,7 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
1341
1341
set_sched_topology (x86_topology );
1342
1342
1343
1343
set_cpu_sibling_map (0 );
1344
- init_freq_invariance ();
1344
+ init_freq_invariance (false );
1345
1345
smp_sanity_check ();
1346
1346
1347
1347
switch (apic_intr_mode ) {
@@ -1877,9 +1877,6 @@ static bool knl_set_max_freq_ratio(u64 *base_freq, u64 *turbo_freq,
1877
1877
int err , i ;
1878
1878
u64 msr ;
1879
1879
1880
- if (!x86_match_cpu (has_knl_turbo_ratio_limits ))
1881
- return false;
1882
-
1883
1880
err = rdmsrl_safe (MSR_PLATFORM_INFO , base_freq );
1884
1881
if (err )
1885
1882
return false;
@@ -1945,18 +1942,23 @@ static bool skx_set_max_freq_ratio(u64 *base_freq, u64 *turbo_freq, int size)
1945
1942
1946
1943
static bool core_set_max_freq_ratio (u64 * base_freq , u64 * turbo_freq )
1947
1944
{
1945
+ u64 msr ;
1948
1946
int err ;
1949
1947
1950
1948
err = rdmsrl_safe (MSR_PLATFORM_INFO , base_freq );
1951
1949
if (err )
1952
1950
return false;
1953
1951
1954
- err = rdmsrl_safe (MSR_TURBO_RATIO_LIMIT , turbo_freq );
1952
+ err = rdmsrl_safe (MSR_TURBO_RATIO_LIMIT , & msr );
1955
1953
if (err )
1956
1954
return false;
1957
1955
1958
- * base_freq = (* base_freq >> 8 ) & 0xFF ; /* max P state */
1959
- * turbo_freq = (* turbo_freq >> 24 ) & 0xFF ; /* 4C turbo */
1956
+ * base_freq = (* base_freq >> 8 ) & 0xFF ; /* max P state */
1957
+ * turbo_freq = (msr >> 24 ) & 0xFF ; /* 4C turbo */
1958
+
1959
+ /* The CPU may have less than 4 cores */
1960
+ if (!* turbo_freq )
1961
+ * turbo_freq = msr & 0xFF ; /* 1C turbo */
1960
1962
1961
1963
return true;
1962
1964
}
@@ -1972,7 +1974,8 @@ static bool intel_set_max_freq_ratio(void)
1972
1974
skx_set_max_freq_ratio (& base_freq , & turbo_freq , 1 ))
1973
1975
goto out ;
1974
1976
1975
- if (knl_set_max_freq_ratio (& base_freq , & turbo_freq , 1 ))
1977
+ if (x86_match_cpu (has_knl_turbo_ratio_limits ) &&
1978
+ knl_set_max_freq_ratio (& base_freq , & turbo_freq , 1 ))
1976
1979
goto out ;
1977
1980
1978
1981
if (x86_match_cpu (has_skx_turbo_ratio_limits ) &&
@@ -1985,13 +1988,22 @@ static bool intel_set_max_freq_ratio(void)
1985
1988
return false;
1986
1989
1987
1990
out :
1991
+ /*
1992
+ * Some hypervisors advertise X86_FEATURE_APERFMPERF
1993
+ * but then fill all MSR's with zeroes.
1994
+ */
1995
+ if (!base_freq ) {
1996
+ pr_debug ("Couldn't determine cpu base frequency, necessary for scale-invariant accounting.\n" );
1997
+ return false;
1998
+ }
1999
+
1988
2000
arch_turbo_freq_ratio = div_u64 (turbo_freq * SCHED_CAPACITY_SCALE ,
1989
2001
base_freq );
1990
2002
arch_set_max_freq_ratio (turbo_disabled ());
1991
2003
return true;
1992
2004
}
1993
2005
1994
- static void init_counter_refs (void * arg )
2006
+ static void init_counter_refs (void )
1995
2007
{
1996
2008
u64 aperf , mperf ;
1997
2009
@@ -2002,18 +2014,25 @@ static void init_counter_refs(void *arg)
2002
2014
this_cpu_write (arch_prev_mperf , mperf );
2003
2015
}
2004
2016
2005
- static void init_freq_invariance (void )
2017
+ static void init_freq_invariance (bool secondary )
2006
2018
{
2007
2019
bool ret = false;
2008
2020
2009
- if (smp_processor_id () != 0 || !boot_cpu_has (X86_FEATURE_APERFMPERF ))
2021
+ if (!boot_cpu_has (X86_FEATURE_APERFMPERF ))
2010
2022
return ;
2011
2023
2024
+ if (secondary ) {
2025
+ if (static_branch_likely (& arch_scale_freq_key )) {
2026
+ init_counter_refs ();
2027
+ }
2028
+ return ;
2029
+ }
2030
+
2012
2031
if (boot_cpu_data .x86_vendor == X86_VENDOR_INTEL )
2013
2032
ret = intel_set_max_freq_ratio ();
2014
2033
2015
2034
if (ret ) {
2016
- on_each_cpu ( init_counter_refs , NULL , 1 );
2035
+ init_counter_refs ( );
2017
2036
static_branch_enable (& arch_scale_freq_key );
2018
2037
} else {
2019
2038
pr_debug ("Couldn't determine max cpu frequency, necessary for scale-invariant accounting.\n" );
0 commit comments