@@ -172,7 +172,6 @@ struct vid_data {
172172 * based on the MSR_IA32_MISC_ENABLE value and whether or
173173 * not the maximum reported turbo P-state is different from
174174 * the maximum reported non-turbo one.
175- * @turbo_disabled_mf: The @turbo_disabled value reflected by cpuinfo.max_freq.
176175 * @min_perf_pct: Minimum capacity limit in percent of the maximum turbo
177176 * P-state capacity.
178177 * @max_perf_pct: Maximum capacity limit in percent of the maximum turbo
@@ -181,7 +180,6 @@ struct vid_data {
181180struct global_params {
182181 bool no_turbo ;
183182 bool turbo_disabled ;
184- bool turbo_disabled_mf ;
185183 int max_perf_pct ;
186184 int min_perf_pct ;
187185};
@@ -559,16 +557,16 @@ static void intel_pstate_hybrid_hwp_adjust(struct cpudata *cpu)
559557 cpu -> pstate .min_pstate = intel_pstate_freq_to_hwp (cpu , freq );
560558}
561559
562- static inline void update_turbo_state (void )
560+ static bool turbo_is_disabled (void )
563561{
564562 u64 misc_en ;
565- struct cpudata * cpu ;
566563
567- cpu = all_cpu_data [0 ];
564+ if (!cpu_feature_enabled (X86_FEATURE_IDA ))
565+ return true;
566+
568567 rdmsrl (MSR_IA32_MISC_ENABLE , misc_en );
569- global .turbo_disabled =
570- (misc_en & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ||
571- cpu -> pstate .max_pstate == cpu -> pstate .turbo_pstate );
568+
569+ return !!(misc_en & MSR_IA32_MISC_ENABLE_TURBO_DISABLE );
572570}
573571
574572static int min_perf_pct_min (void )
@@ -1123,40 +1121,16 @@ static void intel_pstate_update_policies(void)
11231121static void __intel_pstate_update_max_freq (struct cpudata * cpudata ,
11241122 struct cpufreq_policy * policy )
11251123{
1126- policy -> cpuinfo .max_freq = global .turbo_disabled_mf ?
1124+ policy -> cpuinfo .max_freq = global .turbo_disabled ?
11271125 cpudata -> pstate .max_freq : cpudata -> pstate .turbo_freq ;
11281126 refresh_frequency_limits (policy );
11291127}
11301128
1131- static void intel_pstate_update_max_freq (unsigned int cpu )
1132- {
1133- struct cpufreq_policy * policy = cpufreq_cpu_acquire (cpu );
1134-
1135- if (!policy )
1136- return ;
1137-
1138- __intel_pstate_update_max_freq (all_cpu_data [cpu ], policy );
1139-
1140- cpufreq_cpu_release (policy );
1141- }
1142-
11431129static void intel_pstate_update_limits (unsigned int cpu )
11441130{
11451131 mutex_lock (& intel_pstate_driver_lock );
11461132
1147- update_turbo_state ();
1148- /*
1149- * If turbo has been turned on or off globally, policy limits for
1150- * all CPUs need to be updated to reflect that.
1151- */
1152- if (global .turbo_disabled_mf != global .turbo_disabled ) {
1153- global .turbo_disabled_mf = global .turbo_disabled ;
1154- arch_set_max_freq_ratio (global .turbo_disabled );
1155- for_each_possible_cpu (cpu )
1156- intel_pstate_update_max_freq (cpu );
1157- } else {
1158- cpufreq_update_policy (cpu );
1159- }
1133+ cpufreq_update_policy (cpu );
11601134
11611135 mutex_unlock (& intel_pstate_driver_lock );
11621136}
@@ -1256,11 +1230,7 @@ static ssize_t show_no_turbo(struct kobject *kobj,
12561230 return - EAGAIN ;
12571231 }
12581232
1259- update_turbo_state ();
1260- if (global .turbo_disabled )
1261- ret = sprintf (buf , "%u\n" , global .turbo_disabled );
1262- else
1263- ret = sprintf (buf , "%u\n" , global .no_turbo );
1233+ ret = sprintf (buf , "%u\n" , global .no_turbo );
12641234
12651235 mutex_unlock (& intel_pstate_driver_lock );
12661236
@@ -1271,32 +1241,39 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
12711241 const char * buf , size_t count )
12721242{
12731243 unsigned int input ;
1274- int ret ;
1244+ bool no_turbo ;
12751245
1276- ret = sscanf (buf , "%u" , & input );
1277- if (ret != 1 )
1246+ if (sscanf (buf , "%u" , & input ) != 1 )
12781247 return - EINVAL ;
12791248
12801249 mutex_lock (& intel_pstate_driver_lock );
12811250
12821251 if (!intel_pstate_driver ) {
1283- mutex_unlock ( & intel_pstate_driver_lock ) ;
1284- return - EAGAIN ;
1252+ count = - EAGAIN ;
1253+ goto unlock_driver ;
12851254 }
12861255
1287- mutex_lock ( & intel_pstate_limits_lock );
1256+ no_turbo = !! clamp_t ( int , input , 0 , 1 );
12881257
1289- update_turbo_state ();
1290- if (global .turbo_disabled ) {
1291- pr_notice_once ("Turbo disabled by BIOS or unavailable on processor\n" );
1292- mutex_unlock (& intel_pstate_limits_lock );
1293- mutex_unlock (& intel_pstate_driver_lock );
1294- return - EPERM ;
1258+ WRITE_ONCE (global .turbo_disabled , turbo_is_disabled ());
1259+ if (global .turbo_disabled && !no_turbo ) {
1260+ pr_notice ("Turbo disabled by BIOS or unavailable on processor\n" );
1261+ count = - EPERM ;
1262+ if (global .no_turbo )
1263+ goto unlock_driver ;
1264+ else
1265+ no_turbo = 1 ;
12951266 }
12961267
1297- global .no_turbo = clamp_t (int , input , 0 , 1 );
1268+ if (no_turbo == global .no_turbo ) {
1269+ goto unlock_driver ;
1270+ }
12981271
1299- if (global .no_turbo ) {
1272+ WRITE_ONCE (global .no_turbo , no_turbo );
1273+
1274+ mutex_lock (& intel_pstate_limits_lock );
1275+
1276+ if (no_turbo ) {
13001277 struct cpudata * cpu = all_cpu_data [0 ];
13011278 int pct = cpu -> pstate .max_pstate * 100 / cpu -> pstate .turbo_pstate ;
13021279
@@ -1308,8 +1285,9 @@ static ssize_t store_no_turbo(struct kobject *a, struct kobj_attribute *b,
13081285 mutex_unlock (& intel_pstate_limits_lock );
13091286
13101287 intel_pstate_update_policies ();
1311- arch_set_max_freq_ratio (global . no_turbo );
1288+ arch_set_max_freq_ratio (no_turbo );
13121289
1290+ unlock_driver :
13131291 mutex_unlock (& intel_pstate_driver_lock );
13141292
13151293 return count ;
@@ -1757,7 +1735,7 @@ static u64 atom_get_val(struct cpudata *cpudata, int pstate)
17571735 u32 vid ;
17581736
17591737 val = (u64 )pstate << 8 ;
1760- if (global .no_turbo && !global .turbo_disabled )
1738+ if (READ_ONCE ( global .no_turbo ) && !READ_ONCE ( global .turbo_disabled ) )
17611739 val |= (u64 )1 << 32 ;
17621740
17631741 vid_fp = cpudata -> vid .min + mul_fp (
@@ -1927,7 +1905,7 @@ static u64 core_get_val(struct cpudata *cpudata, int pstate)
19271905 u64 val ;
19281906
19291907 val = (u64 )pstate << 8 ;
1930- if (global .no_turbo && !global .turbo_disabled )
1908+ if (READ_ONCE ( global .no_turbo ) && !READ_ONCE ( global .turbo_disabled ) )
19311909 val |= (u64 )1 << 32 ;
19321910
19331911 return val ;
@@ -1988,14 +1966,6 @@ static void intel_pstate_set_min_pstate(struct cpudata *cpu)
19881966 intel_pstate_set_pstate (cpu , cpu -> pstate .min_pstate );
19891967}
19901968
1991- static void intel_pstate_max_within_limits (struct cpudata * cpu )
1992- {
1993- int pstate = max (cpu -> pstate .min_pstate , cpu -> max_perf_ratio );
1994-
1995- update_turbo_state ();
1996- intel_pstate_set_pstate (cpu , pstate );
1997- }
1998-
19991969static void intel_pstate_get_cpu_pstates (struct cpudata * cpu )
20001970{
20011971 int perf_ctl_max_phys = pstate_funcs .get_max_physical (cpu -> cpu );
@@ -2221,7 +2191,7 @@ static inline int32_t get_target_pstate(struct cpudata *cpu)
22212191
22222192 sample -> busy_scaled = busy_frac * 100 ;
22232193
2224- target = global .no_turbo || global . turbo_disabled ?
2194+ target = READ_ONCE ( global .no_turbo ) ?
22252195 cpu -> pstate .max_pstate : cpu -> pstate .turbo_pstate ;
22262196 target += target >> 2 ;
22272197 target = mul_fp (target , busy_frac );
@@ -2265,8 +2235,6 @@ static void intel_pstate_adjust_pstate(struct cpudata *cpu)
22652235 struct sample * sample ;
22662236 int target_pstate ;
22672237
2268- update_turbo_state ();
2269-
22702238 target_pstate = get_target_pstate (cpu );
22712239 target_pstate = intel_pstate_prepare_request (cpu , target_pstate );
22722240 trace_cpu_frequency (target_pstate * cpu -> pstate .scaling , cpu -> cpu );
@@ -2492,7 +2460,7 @@ static void intel_pstate_clear_update_util_hook(unsigned int cpu)
24922460
24932461static int intel_pstate_get_max_freq (struct cpudata * cpu )
24942462{
2495- return global .turbo_disabled || global . no_turbo ?
2463+ return READ_ONCE ( global .no_turbo ) ?
24962464 cpu -> pstate .max_freq : cpu -> pstate .turbo_freq ;
24972465}
24982466
@@ -2577,12 +2545,14 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
25772545 intel_pstate_update_perf_limits (cpu , policy -> min , policy -> max );
25782546
25792547 if (cpu -> policy == CPUFREQ_POLICY_PERFORMANCE ) {
2548+ int pstate = max (cpu -> pstate .min_pstate , cpu -> max_perf_ratio );
2549+
25802550 /*
25812551 * NOHZ_FULL CPUs need this as the governor callback may not
25822552 * be invoked on them.
25832553 */
25842554 intel_pstate_clear_update_util_hook (policy -> cpu );
2585- intel_pstate_max_within_limits (cpu );
2555+ intel_pstate_set_pstate (cpu , pstate );
25862556 } else {
25872557 intel_pstate_set_update_util_hook (policy -> cpu );
25882558 }
@@ -2625,10 +2595,9 @@ static void intel_pstate_verify_cpu_policy(struct cpudata *cpu,
26252595{
26262596 int max_freq ;
26272597
2628- update_turbo_state ();
26292598 if (hwp_active ) {
26302599 intel_pstate_get_hwp_cap (cpu );
2631- max_freq = global .no_turbo || global . turbo_disabled ?
2600+ max_freq = READ_ONCE ( global .no_turbo ) ?
26322601 cpu -> pstate .max_freq : cpu -> pstate .turbo_freq ;
26332602 } else {
26342603 max_freq = intel_pstate_get_max_freq (cpu );
@@ -2722,8 +2691,6 @@ static int __intel_pstate_cpu_init(struct cpufreq_policy *policy)
27222691
27232692 /* cpuinfo and default policy values */
27242693 policy -> cpuinfo .min_freq = cpu -> pstate .min_freq ;
2725- update_turbo_state ();
2726- global .turbo_disabled_mf = global .turbo_disabled ;
27272694 policy -> cpuinfo .max_freq = global .turbo_disabled ?
27282695 cpu -> pstate .max_freq : cpu -> pstate .turbo_freq ;
27292696
@@ -2889,8 +2856,6 @@ static int intel_cpufreq_target(struct cpufreq_policy *policy,
28892856 struct cpufreq_freqs freqs ;
28902857 int target_pstate ;
28912858
2892- update_turbo_state ();
2893-
28942859 freqs .old = policy -> cur ;
28952860 freqs .new = target_freq ;
28962861
@@ -2912,8 +2877,6 @@ static unsigned int intel_cpufreq_fast_switch(struct cpufreq_policy *policy,
29122877 struct cpudata * cpu = all_cpu_data [policy -> cpu ];
29132878 int target_pstate ;
29142879
2915- update_turbo_state ();
2916-
29172880 target_pstate = intel_pstate_freq_to_hwp (cpu , target_freq );
29182881
29192882 target_pstate = intel_cpufreq_update_pstate (policy , target_pstate , true);
@@ -2931,7 +2894,6 @@ static void intel_cpufreq_adjust_perf(unsigned int cpunum,
29312894 int old_pstate = cpu -> pstate .current_pstate ;
29322895 int cap_pstate , min_pstate , max_pstate , target_pstate ;
29332896
2934- update_turbo_state ();
29352897 cap_pstate = global .turbo_disabled ? HWP_GUARANTEED_PERF (hwp_cap ) :
29362898 HWP_HIGHEST_PERF (hwp_cap );
29372899
@@ -3121,6 +3083,10 @@ static int intel_pstate_register_driver(struct cpufreq_driver *driver)
31213083
31223084 memset (& global , 0 , sizeof (global ));
31233085 global .max_perf_pct = 100 ;
3086+ global .turbo_disabled = turbo_is_disabled ();
3087+ global .no_turbo = global .turbo_disabled ;
3088+
3089+ arch_set_max_freq_ratio (global .turbo_disabled );
31243090
31253091 intel_pstate_driver = driver ;
31263092 ret = cpufreq_register_driver (intel_pstate_driver );
0 commit comments