@@ -364,9 +364,7 @@ static bool driver_registered __read_mostly;
364
364
static bool acpi_ppc ;
365
365
#endif
366
366
367
- static struct perf_limits performance_limits ;
368
- static struct perf_limits powersave_limits ;
369
- static struct perf_limits * limits ;
367
+ static struct perf_limits global ;
370
368
371
369
static void intel_pstate_init_limits (struct perf_limits * limits )
372
370
{
@@ -377,14 +375,6 @@ static void intel_pstate_init_limits(struct perf_limits *limits)
377
375
limits -> max_sysfs_pct = 100 ;
378
376
}
379
377
380
- static void intel_pstate_set_performance_limits (struct perf_limits * limits )
381
- {
382
- intel_pstate_init_limits (limits );
383
- limits -> min_perf_pct = 100 ;
384
- limits -> min_perf = int_ext_tofp (1 );
385
- limits -> min_sysfs_pct = 100 ;
386
- }
387
-
388
378
static DEFINE_MUTEX (intel_pstate_driver_lock );
389
379
static DEFINE_MUTEX (intel_pstate_limits_lock );
390
380
@@ -507,7 +497,7 @@ static void intel_pstate_init_acpi_perf_limits(struct cpufreq_policy *policy)
507
497
* correct max turbo frequency based on the turbo state.
508
498
* Also need to convert to MHz as _PSS freq is in MHz.
509
499
*/
510
- if (!limits -> turbo_disabled )
500
+ if (!global . turbo_disabled )
511
501
cpu -> acpi_perf_data .states [0 ].core_frequency =
512
502
policy -> cpuinfo .max_freq / 1000 ;
513
503
cpu -> valid_pss_table = true;
@@ -626,7 +616,7 @@ static inline void update_turbo_state(void)
626
616
627
617
cpu = all_cpu_data [0 ];
628
618
rdmsrl (MSR_IA32_MISC_ENABLE , misc_en );
629
- limits -> turbo_disabled =
619
+ global . turbo_disabled =
630
620
(misc_en & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ||
631
621
cpu -> pstate .max_pstate == cpu -> pstate .turbo_pstate );
632
622
}
@@ -851,7 +841,7 @@ static struct freq_attr *hwp_cpufreq_attrs[] = {
851
841
static void intel_pstate_hwp_set (struct cpufreq_policy * policy )
852
842
{
853
843
int min , hw_min , max , hw_max , cpu ;
854
- struct perf_limits * perf_limits = limits ;
844
+ struct perf_limits * perf_limits = & global ;
855
845
u64 value , cap ;
856
846
857
847
for_each_cpu (cpu , policy -> cpus ) {
@@ -863,19 +853,22 @@ static void intel_pstate_hwp_set(struct cpufreq_policy *policy)
863
853
864
854
rdmsrl_on_cpu (cpu , MSR_HWP_CAPABILITIES , & cap );
865
855
hw_min = HWP_LOWEST_PERF (cap );
866
- if (limits -> no_turbo )
856
+ if (global . no_turbo )
867
857
hw_max = HWP_GUARANTEED_PERF (cap );
868
858
else
869
859
hw_max = HWP_HIGHEST_PERF (cap );
870
860
871
- min = fp_ext_toint (hw_max * perf_limits -> min_perf );
861
+ max = fp_ext_toint (hw_max * perf_limits -> max_perf );
862
+ if (cpu_data -> policy == CPUFREQ_POLICY_PERFORMANCE )
863
+ min = max ;
864
+ else
865
+ min = fp_ext_toint (hw_max * perf_limits -> min_perf );
872
866
873
867
rdmsrl_on_cpu (cpu , MSR_HWP_REQUEST , & value );
874
868
875
869
value &= ~HWP_MIN_PERF (~0L );
876
870
value |= HWP_MIN_PERF (min );
877
871
878
- max = fp_ext_toint (hw_max * perf_limits -> max_perf );
879
872
value &= ~HWP_MAX_PERF (~0L );
880
873
value |= HWP_MAX_PERF (max );
881
874
@@ -968,20 +961,11 @@ static int intel_pstate_resume(struct cpufreq_policy *policy)
968
961
}
969
962
970
963
static void intel_pstate_update_policies (void )
971
- __releases (& intel_pstate_limits_lock )
972
- __acquires (& intel_pstate_limits_lock )
973
964
{
974
- struct perf_limits * saved_limits = limits ;
975
965
int cpu ;
976
966
977
- mutex_unlock (& intel_pstate_limits_lock );
978
-
979
967
for_each_possible_cpu (cpu )
980
968
cpufreq_update_policy (cpu );
981
-
982
- mutex_lock (& intel_pstate_limits_lock );
983
-
984
- limits = saved_limits ;
985
969
}
986
970
987
971
/************************** debugfs begin ************************/
@@ -1060,7 +1044,7 @@ static void intel_pstate_debug_hide_params(void)
1060
1044
static ssize_t show_##file_name \
1061
1045
(struct kobject *kobj, struct attribute *attr, char *buf) \
1062
1046
{ \
1063
- return sprintf(buf, "%u\n", limits-> object); \
1047
+ return sprintf(buf, "%u\n", global. object); \
1064
1048
}
1065
1049
1066
1050
static ssize_t intel_pstate_show_status (char * buf );
@@ -1151,10 +1135,10 @@ static ssize_t show_no_turbo(struct kobject *kobj,
1151
1135
}
1152
1136
1153
1137
update_turbo_state ();
1154
- if (limits -> turbo_disabled )
1155
- ret = sprintf (buf , "%u\n" , limits -> turbo_disabled );
1138
+ if (global . turbo_disabled )
1139
+ ret = sprintf (buf , "%u\n" , global . turbo_disabled );
1156
1140
else
1157
- ret = sprintf (buf , "%u\n" , limits -> no_turbo );
1141
+ ret = sprintf (buf , "%u\n" , global . no_turbo );
1158
1142
1159
1143
mutex_unlock (& intel_pstate_driver_lock );
1160
1144
@@ -1181,19 +1165,19 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
1181
1165
mutex_lock (& intel_pstate_limits_lock );
1182
1166
1183
1167
update_turbo_state ();
1184
- if (limits -> turbo_disabled ) {
1168
+ if (global . turbo_disabled ) {
1185
1169
pr_warn ("Turbo disabled by BIOS or unavailable on processor\n" );
1186
1170
mutex_unlock (& intel_pstate_limits_lock );
1187
1171
mutex_unlock (& intel_pstate_driver_lock );
1188
1172
return - EPERM ;
1189
1173
}
1190
1174
1191
- limits -> no_turbo = clamp_t (int , input , 0 , 1 );
1192
-
1193
- intel_pstate_update_policies ();
1175
+ global .no_turbo = clamp_t (int , input , 0 , 1 );
1194
1176
1195
1177
mutex_unlock (& intel_pstate_limits_lock );
1196
1178
1179
+ intel_pstate_update_policies ();
1180
+
1197
1181
mutex_unlock (& intel_pstate_driver_lock );
1198
1182
1199
1183
return count ;
@@ -1218,19 +1202,16 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
1218
1202
1219
1203
mutex_lock (& intel_pstate_limits_lock );
1220
1204
1221
- limits -> max_sysfs_pct = clamp_t (int , input , 0 , 100 );
1222
- limits -> max_perf_pct = min (limits -> max_policy_pct ,
1223
- limits -> max_sysfs_pct );
1224
- limits -> max_perf_pct = max (limits -> min_policy_pct ,
1225
- limits -> max_perf_pct );
1226
- limits -> max_perf_pct = max (limits -> min_perf_pct ,
1227
- limits -> max_perf_pct );
1228
- limits -> max_perf = percent_ext_fp (limits -> max_perf_pct );
1229
-
1230
- intel_pstate_update_policies ();
1205
+ global .max_sysfs_pct = clamp_t (int , input , 0 , 100 );
1206
+ global .max_perf_pct = min (global .max_policy_pct , global .max_sysfs_pct );
1207
+ global .max_perf_pct = max (global .min_policy_pct , global .max_perf_pct );
1208
+ global .max_perf_pct = max (global .min_perf_pct , global .max_perf_pct );
1209
+ global .max_perf = percent_ext_fp (global .max_perf_pct );
1231
1210
1232
1211
mutex_unlock (& intel_pstate_limits_lock );
1233
1212
1213
+ intel_pstate_update_policies ();
1214
+
1234
1215
mutex_unlock (& intel_pstate_driver_lock );
1235
1216
1236
1217
return count ;
@@ -1255,19 +1236,16 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
1255
1236
1256
1237
mutex_lock (& intel_pstate_limits_lock );
1257
1238
1258
- limits -> min_sysfs_pct = clamp_t (int , input , 0 , 100 );
1259
- limits -> min_perf_pct = max (limits -> min_policy_pct ,
1260
- limits -> min_sysfs_pct );
1261
- limits -> min_perf_pct = min (limits -> max_policy_pct ,
1262
- limits -> min_perf_pct );
1263
- limits -> min_perf_pct = min (limits -> max_perf_pct ,
1264
- limits -> min_perf_pct );
1265
- limits -> min_perf = percent_ext_fp (limits -> min_perf_pct );
1266
-
1267
- intel_pstate_update_policies ();
1239
+ global .min_sysfs_pct = clamp_t (int , input , 0 , 100 );
1240
+ global .min_perf_pct = max (global .min_policy_pct , global .min_sysfs_pct );
1241
+ global .min_perf_pct = min (global .max_policy_pct , global .min_perf_pct );
1242
+ global .min_perf_pct = min (global .max_perf_pct , global .min_perf_pct );
1243
+ global .min_perf = percent_ext_fp (global .min_perf_pct );
1268
1244
1269
1245
mutex_unlock (& intel_pstate_limits_lock );
1270
1246
1247
+ intel_pstate_update_policies ();
1248
+
1271
1249
mutex_unlock (& intel_pstate_driver_lock );
1272
1250
1273
1251
return count ;
@@ -1387,7 +1365,7 @@ static u64 atom_get_val(struct cpudata *cpudata, int pstate)
1387
1365
u32 vid ;
1388
1366
1389
1367
val = (u64 )pstate << 8 ;
1390
- if (limits -> no_turbo && !limits -> turbo_disabled )
1368
+ if (global . no_turbo && !global . turbo_disabled )
1391
1369
val |= (u64 )1 << 32 ;
1392
1370
1393
1371
vid_fp = cpudata -> vid .min + mul_fp (
@@ -1557,7 +1535,7 @@ static u64 core_get_val(struct cpudata *cpudata, int pstate)
1557
1535
u64 val ;
1558
1536
1559
1537
val = (u64 )pstate << 8 ;
1560
- if (limits -> no_turbo && !limits -> turbo_disabled )
1538
+ if (global . no_turbo && !global . turbo_disabled )
1561
1539
val |= (u64 )1 << 32 ;
1562
1540
1563
1541
return val ;
@@ -1683,9 +1661,9 @@ static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
1683
1661
int max_perf = cpu -> pstate .turbo_pstate ;
1684
1662
int max_perf_adj ;
1685
1663
int min_perf ;
1686
- struct perf_limits * perf_limits = limits ;
1664
+ struct perf_limits * perf_limits = & global ;
1687
1665
1688
- if (limits -> no_turbo || limits -> turbo_disabled )
1666
+ if (global . no_turbo || global . turbo_disabled )
1689
1667
max_perf = cpu -> pstate .max_pstate ;
1690
1668
1691
1669
if (per_cpu_limits )
@@ -1820,7 +1798,7 @@ static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu)
1820
1798
1821
1799
sample -> busy_scaled = busy_frac * 100 ;
1822
1800
1823
- target = limits -> no_turbo || limits -> turbo_disabled ?
1801
+ target = global . no_turbo || global . turbo_disabled ?
1824
1802
cpu -> pstate .max_pstate : cpu -> pstate .turbo_pstate ;
1825
1803
target += target >> 2 ;
1826
1804
target = mul_fp (target , busy_frac );
@@ -2116,7 +2094,7 @@ static void intel_pstate_update_perf_limits(struct cpufreq_policy *policy,
2116
2094
static int intel_pstate_set_policy (struct cpufreq_policy * policy )
2117
2095
{
2118
2096
struct cpudata * cpu ;
2119
- struct perf_limits * perf_limits = NULL ;
2097
+ struct perf_limits * perf_limits = & global ;
2120
2098
2121
2099
if (!policy -> cpuinfo .max_freq )
2122
2100
return - ENODEV ;
@@ -2139,21 +2117,6 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
2139
2117
2140
2118
mutex_lock (& intel_pstate_limits_lock );
2141
2119
2142
- if (policy -> policy == CPUFREQ_POLICY_PERFORMANCE ) {
2143
- pr_debug ("set performance\n" );
2144
- if (!perf_limits ) {
2145
- limits = & performance_limits ;
2146
- perf_limits = limits ;
2147
- }
2148
- } else {
2149
- pr_debug ("set powersave\n" );
2150
- if (!perf_limits ) {
2151
- limits = & powersave_limits ;
2152
- perf_limits = limits ;
2153
- }
2154
-
2155
- }
2156
-
2157
2120
intel_pstate_update_perf_limits (policy , perf_limits );
2158
2121
2159
2122
if (cpu -> policy == CPUFREQ_POLICY_PERFORMANCE ) {
@@ -2177,16 +2140,9 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
2177
2140
static int intel_pstate_verify_policy (struct cpufreq_policy * policy )
2178
2141
{
2179
2142
struct cpudata * cpu = all_cpu_data [policy -> cpu ];
2180
- struct perf_limits * perf_limits ;
2181
-
2182
- if (policy -> policy == CPUFREQ_POLICY_PERFORMANCE )
2183
- perf_limits = & performance_limits ;
2184
- else
2185
- perf_limits = & powersave_limits ;
2186
2143
2187
2144
update_turbo_state ();
2188
- policy -> cpuinfo .max_freq = perf_limits -> turbo_disabled ||
2189
- perf_limits -> no_turbo ?
2145
+ policy -> cpuinfo .max_freq = global .turbo_disabled || global .no_turbo ?
2190
2146
cpu -> pstate .max_freq :
2191
2147
cpu -> pstate .turbo_freq ;
2192
2148
@@ -2201,9 +2157,9 @@ static int intel_pstate_verify_policy(struct cpufreq_policy *policy)
2201
2157
unsigned int max_freq , min_freq ;
2202
2158
2203
2159
max_freq = policy -> cpuinfo .max_freq *
2204
- perf_limits -> max_sysfs_pct / 100 ;
2160
+ global . max_sysfs_pct / 100 ;
2205
2161
min_freq = policy -> cpuinfo .max_freq *
2206
- perf_limits -> min_sysfs_pct / 100 ;
2162
+ global . min_sysfs_pct / 100 ;
2207
2163
cpufreq_verify_within_limits (policy , min_freq , max_freq );
2208
2164
}
2209
2165
@@ -2255,7 +2211,7 @@ static int __intel_pstate_cpu_init(struct cpufreq_policy *policy)
2255
2211
/* cpuinfo and default policy values */
2256
2212
policy -> cpuinfo .min_freq = cpu -> pstate .min_pstate * cpu -> pstate .scaling ;
2257
2213
update_turbo_state ();
2258
- policy -> cpuinfo .max_freq = limits -> turbo_disabled ?
2214
+ policy -> cpuinfo .max_freq = global . turbo_disabled ?
2259
2215
cpu -> pstate .max_pstate : cpu -> pstate .turbo_pstate ;
2260
2216
policy -> cpuinfo .max_freq *= cpu -> pstate .scaling ;
2261
2217
@@ -2275,7 +2231,7 @@ static int intel_pstate_cpu_init(struct cpufreq_policy *policy)
2275
2231
return ret ;
2276
2232
2277
2233
policy -> cpuinfo .transition_latency = CPUFREQ_ETERNAL ;
2278
- if (limits -> min_perf_pct == 100 && limits -> max_perf_pct == 100 )
2234
+ if (IS_ENABLED ( CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE ) )
2279
2235
policy -> policy = CPUFREQ_POLICY_PERFORMANCE ;
2280
2236
else
2281
2237
policy -> policy = CPUFREQ_POLICY_POWERSAVE ;
@@ -2301,7 +2257,7 @@ static int intel_cpufreq_verify_policy(struct cpufreq_policy *policy)
2301
2257
struct cpudata * cpu = all_cpu_data [policy -> cpu ];
2302
2258
2303
2259
update_turbo_state ();
2304
- policy -> cpuinfo .max_freq = limits -> turbo_disabled ?
2260
+ policy -> cpuinfo .max_freq = global . turbo_disabled ?
2305
2261
cpu -> pstate .max_freq : cpu -> pstate .turbo_freq ;
2306
2262
2307
2263
cpufreq_verify_within_cpu_limits (policy );
@@ -2317,7 +2273,7 @@ static unsigned int intel_cpufreq_turbo_update(struct cpudata *cpu,
2317
2273
2318
2274
update_turbo_state ();
2319
2275
2320
- max_freq = limits -> no_turbo || limits -> turbo_disabled ?
2276
+ max_freq = global . no_turbo || global . turbo_disabled ?
2321
2277
cpu -> pstate .max_freq : cpu -> pstate .turbo_freq ;
2322
2278
policy -> cpuinfo .max_freq = max_freq ;
2323
2279
if (policy -> max > max_freq )
@@ -2425,13 +2381,7 @@ static int intel_pstate_register_driver(void)
2425
2381
{
2426
2382
int ret ;
2427
2383
2428
- intel_pstate_init_limits (& powersave_limits );
2429
- intel_pstate_set_performance_limits (& performance_limits );
2430
- if (IS_ENABLED (CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE ) &&
2431
- intel_pstate_driver == & intel_pstate )
2432
- limits = & performance_limits ;
2433
- else
2434
- limits = & powersave_limits ;
2384
+ intel_pstate_init_limits (& global );
2435
2385
2436
2386
ret = cpufreq_register_driver (intel_pstate_driver );
2437
2387
if (ret ) {
0 commit comments