diff options
Diffstat (limited to 'drivers/cpufreq/intel_pstate.c')
-rw-r--r-- | drivers/cpufreq/intel_pstate.c | 67 |
1 files changed, 31 insertions, 36 deletions
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index b1fbaa30ae04..3d37219a0dd7 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c | |||
@@ -377,6 +377,7 @@ static void intel_pstate_set_performance_limits(struct perf_limits *limits) | |||
377 | intel_pstate_init_limits(limits); | 377 | intel_pstate_init_limits(limits); |
378 | limits->min_perf_pct = 100; | 378 | limits->min_perf_pct = 100; |
379 | limits->min_perf = int_ext_tofp(1); | 379 | limits->min_perf = int_ext_tofp(1); |
380 | limits->min_sysfs_pct = 100; | ||
380 | } | 381 | } |
381 | 382 | ||
382 | static DEFINE_MUTEX(intel_pstate_driver_lock); | 383 | static DEFINE_MUTEX(intel_pstate_driver_lock); |
@@ -968,11 +969,20 @@ static int intel_pstate_resume(struct cpufreq_policy *policy) | |||
968 | } | 969 | } |
969 | 970 | ||
970 | static void intel_pstate_update_policies(void) | 971 | static void intel_pstate_update_policies(void) |
972 | __releases(&intel_pstate_limits_lock) | ||
973 | __acquires(&intel_pstate_limits_lock) | ||
971 | { | 974 | { |
975 | struct perf_limits *saved_limits = limits; | ||
972 | int cpu; | 976 | int cpu; |
973 | 977 | ||
978 | mutex_unlock(&intel_pstate_limits_lock); | ||
979 | |||
974 | for_each_possible_cpu(cpu) | 980 | for_each_possible_cpu(cpu) |
975 | cpufreq_update_policy(cpu); | 981 | cpufreq_update_policy(cpu); |
982 | |||
983 | mutex_lock(&intel_pstate_limits_lock); | ||
984 | |||
985 | limits = saved_limits; | ||
976 | } | 986 | } |
977 | 987 | ||
978 | /************************** debugfs begin ************************/ | 988 | /************************** debugfs begin ************************/ |
@@ -1180,10 +1190,10 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b, | |||
1180 | 1190 | ||
1181 | limits->no_turbo = clamp_t(int, input, 0, 1); | 1191 | limits->no_turbo = clamp_t(int, input, 0, 1); |
1182 | 1192 | ||
1183 | mutex_unlock(&intel_pstate_limits_lock); | ||
1184 | |||
1185 | intel_pstate_update_policies(); | 1193 | intel_pstate_update_policies(); |
1186 | 1194 | ||
1195 | mutex_unlock(&intel_pstate_limits_lock); | ||
1196 | |||
1187 | mutex_unlock(&intel_pstate_driver_lock); | 1197 | mutex_unlock(&intel_pstate_driver_lock); |
1188 | 1198 | ||
1189 | return count; | 1199 | return count; |
@@ -1217,10 +1227,10 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b, | |||
1217 | limits->max_perf_pct); | 1227 | limits->max_perf_pct); |
1218 | limits->max_perf = div_ext_fp(limits->max_perf_pct, 100); | 1228 | limits->max_perf = div_ext_fp(limits->max_perf_pct, 100); |
1219 | 1229 | ||
1220 | mutex_unlock(&intel_pstate_limits_lock); | ||
1221 | |||
1222 | intel_pstate_update_policies(); | 1230 | intel_pstate_update_policies(); |
1223 | 1231 | ||
1232 | mutex_unlock(&intel_pstate_limits_lock); | ||
1233 | |||
1224 | mutex_unlock(&intel_pstate_driver_lock); | 1234 | mutex_unlock(&intel_pstate_driver_lock); |
1225 | 1235 | ||
1226 | return count; | 1236 | return count; |
@@ -1254,10 +1264,10 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b, | |||
1254 | limits->min_perf_pct); | 1264 | limits->min_perf_pct); |
1255 | limits->min_perf = div_ext_fp(limits->min_perf_pct, 100); | 1265 | limits->min_perf = div_ext_fp(limits->min_perf_pct, 100); |
1256 | 1266 | ||
1257 | mutex_unlock(&intel_pstate_limits_lock); | ||
1258 | |||
1259 | intel_pstate_update_policies(); | 1267 | intel_pstate_update_policies(); |
1260 | 1268 | ||
1269 | mutex_unlock(&intel_pstate_limits_lock); | ||
1270 | |||
1261 | mutex_unlock(&intel_pstate_driver_lock); | 1271 | mutex_unlock(&intel_pstate_driver_lock); |
1262 | 1272 | ||
1263 | return count; | 1273 | return count; |
@@ -1874,13 +1884,11 @@ static int intel_pstate_prepare_request(struct cpudata *cpu, int pstate) | |||
1874 | 1884 | ||
1875 | intel_pstate_get_min_max(cpu, &min_perf, &max_perf); | 1885 | intel_pstate_get_min_max(cpu, &min_perf, &max_perf); |
1876 | pstate = clamp_t(int, pstate, min_perf, max_perf); | 1886 | pstate = clamp_t(int, pstate, min_perf, max_perf); |
1877 | trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu); | ||
1878 | return pstate; | 1887 | return pstate; |
1879 | } | 1888 | } |
1880 | 1889 | ||
1881 | static void intel_pstate_update_pstate(struct cpudata *cpu, int pstate) | 1890 | static void intel_pstate_update_pstate(struct cpudata *cpu, int pstate) |
1882 | { | 1891 | { |
1883 | pstate = intel_pstate_prepare_request(cpu, pstate); | ||
1884 | if (pstate == cpu->pstate.current_pstate) | 1892 | if (pstate == cpu->pstate.current_pstate) |
1885 | return; | 1893 | return; |
1886 | 1894 | ||
@@ -1900,6 +1908,8 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu) | |||
1900 | 1908 | ||
1901 | update_turbo_state(); | 1909 | update_turbo_state(); |
1902 | 1910 | ||
1911 | target_pstate = intel_pstate_prepare_request(cpu, target_pstate); | ||
1912 | trace_cpu_frequency(target_pstate * cpu->pstate.scaling, cpu->cpu); | ||
1903 | intel_pstate_update_pstate(cpu, target_pstate); | 1913 | intel_pstate_update_pstate(cpu, target_pstate); |
1904 | 1914 | ||
1905 | sample = &cpu->sample; | 1915 | sample = &cpu->sample; |
@@ -2132,16 +2142,11 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy) | |||
2132 | mutex_lock(&intel_pstate_limits_lock); | 2142 | mutex_lock(&intel_pstate_limits_lock); |
2133 | 2143 | ||
2134 | if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) { | 2144 | if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) { |
2145 | pr_debug("set performance\n"); | ||
2135 | if (!perf_limits) { | 2146 | if (!perf_limits) { |
2136 | limits = &performance_limits; | 2147 | limits = &performance_limits; |
2137 | perf_limits = limits; | 2148 | perf_limits = limits; |
2138 | } | 2149 | } |
2139 | if (policy->max >= policy->cpuinfo.max_freq && | ||
2140 | !limits->no_turbo) { | ||
2141 | pr_debug("set performance\n"); | ||
2142 | intel_pstate_set_performance_limits(perf_limits); | ||
2143 | goto out; | ||
2144 | } | ||
2145 | } else { | 2150 | } else { |
2146 | pr_debug("set powersave\n"); | 2151 | pr_debug("set powersave\n"); |
2147 | if (!perf_limits) { | 2152 | if (!perf_limits) { |
@@ -2152,7 +2157,7 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy) | |||
2152 | } | 2157 | } |
2153 | 2158 | ||
2154 | intel_pstate_update_perf_limits(policy, perf_limits); | 2159 | intel_pstate_update_perf_limits(policy, perf_limits); |
2155 | out: | 2160 | |
2156 | if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) { | 2161 | if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) { |
2157 | /* | 2162 | /* |
2158 | * NOHZ_FULL CPUs need this as the governor callback may not | 2163 | * NOHZ_FULL CPUs need this as the governor callback may not |
@@ -2198,9 +2203,9 @@ static int intel_pstate_verify_policy(struct cpufreq_policy *policy) | |||
2198 | unsigned int max_freq, min_freq; | 2203 | unsigned int max_freq, min_freq; |
2199 | 2204 | ||
2200 | max_freq = policy->cpuinfo.max_freq * | 2205 | max_freq = policy->cpuinfo.max_freq * |
2201 | limits->max_sysfs_pct / 100; | 2206 | perf_limits->max_sysfs_pct / 100; |
2202 | min_freq = policy->cpuinfo.max_freq * | 2207 | min_freq = policy->cpuinfo.max_freq * |
2203 | limits->min_sysfs_pct / 100; | 2208 | perf_limits->min_sysfs_pct / 100; |
2204 | cpufreq_verify_within_limits(policy, min_freq, max_freq); | 2209 | cpufreq_verify_within_limits(policy, min_freq, max_freq); |
2205 | } | 2210 | } |
2206 | 2211 | ||
@@ -2243,13 +2248,8 @@ static int __intel_pstate_cpu_init(struct cpufreq_policy *policy) | |||
2243 | 2248 | ||
2244 | cpu = all_cpu_data[policy->cpu]; | 2249 | cpu = all_cpu_data[policy->cpu]; |
2245 | 2250 | ||
2246 | /* | ||
2247 | * We need sane value in the cpu->perf_limits, so inherit from global | ||
2248 | * perf_limits limits, which are seeded with values based on the | ||
2249 | * CONFIG_CPU_FREQ_DEFAULT_GOV_*, during boot up. | ||
2250 | */ | ||
2251 | if (per_cpu_limits) | 2251 | if (per_cpu_limits) |
2252 | memcpy(cpu->perf_limits, limits, sizeof(struct perf_limits)); | 2252 | intel_pstate_init_limits(cpu->perf_limits); |
2253 | 2253 | ||
2254 | policy->min = cpu->pstate.min_pstate * cpu->pstate.scaling; | 2254 | policy->min = cpu->pstate.min_pstate * cpu->pstate.scaling; |
2255 | policy->max = cpu->pstate.turbo_pstate * cpu->pstate.scaling; | 2255 | policy->max = cpu->pstate.turbo_pstate * cpu->pstate.scaling; |
@@ -2301,7 +2301,6 @@ static struct cpufreq_driver intel_pstate = { | |||
2301 | static int intel_cpufreq_verify_policy(struct cpufreq_policy *policy) | 2301 | static int intel_cpufreq_verify_policy(struct cpufreq_policy *policy) |
2302 | { | 2302 | { |
2303 | struct cpudata *cpu = all_cpu_data[policy->cpu]; | 2303 | struct cpudata *cpu = all_cpu_data[policy->cpu]; |
2304 | struct perf_limits *perf_limits = limits; | ||
2305 | 2304 | ||
2306 | update_turbo_state(); | 2305 | update_turbo_state(); |
2307 | policy->cpuinfo.max_freq = limits->turbo_disabled ? | 2306 | policy->cpuinfo.max_freq = limits->turbo_disabled ? |
@@ -2309,15 +2308,6 @@ static int intel_cpufreq_verify_policy(struct cpufreq_policy *policy) | |||
2309 | 2308 | ||
2310 | cpufreq_verify_within_cpu_limits(policy); | 2309 | cpufreq_verify_within_cpu_limits(policy); |
2311 | 2310 | ||
2312 | if (per_cpu_limits) | ||
2313 | perf_limits = cpu->perf_limits; | ||
2314 | |||
2315 | mutex_lock(&intel_pstate_limits_lock); | ||
2316 | |||
2317 | intel_pstate_update_perf_limits(policy, perf_limits); | ||
2318 | |||
2319 | mutex_unlock(&intel_pstate_limits_lock); | ||
2320 | |||
2321 | return 0; | 2311 | return 0; |
2322 | } | 2312 | } |
2323 | 2313 | ||
@@ -2370,6 +2360,7 @@ static int intel_cpufreq_target(struct cpufreq_policy *policy, | |||
2370 | wrmsrl_on_cpu(policy->cpu, MSR_IA32_PERF_CTL, | 2360 | wrmsrl_on_cpu(policy->cpu, MSR_IA32_PERF_CTL, |
2371 | pstate_funcs.get_val(cpu, target_pstate)); | 2361 | pstate_funcs.get_val(cpu, target_pstate)); |
2372 | } | 2362 | } |
2363 | freqs.new = target_pstate * cpu->pstate.scaling; | ||
2373 | cpufreq_freq_transition_end(policy, &freqs, false); | 2364 | cpufreq_freq_transition_end(policy, &freqs, false); |
2374 | 2365 | ||
2375 | return 0; | 2366 | return 0; |
@@ -2383,8 +2374,9 @@ static unsigned int intel_cpufreq_fast_switch(struct cpufreq_policy *policy, | |||
2383 | 2374 | ||
2384 | target_freq = intel_cpufreq_turbo_update(cpu, policy, target_freq); | 2375 | target_freq = intel_cpufreq_turbo_update(cpu, policy, target_freq); |
2385 | target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling); | 2376 | target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling); |
2377 | target_pstate = intel_pstate_prepare_request(cpu, target_pstate); | ||
2386 | intel_pstate_update_pstate(cpu, target_pstate); | 2378 | intel_pstate_update_pstate(cpu, target_pstate); |
2387 | return target_freq; | 2379 | return target_pstate * cpu->pstate.scaling; |
2388 | } | 2380 | } |
2389 | 2381 | ||
2390 | static int intel_cpufreq_cpu_init(struct cpufreq_policy *policy) | 2382 | static int intel_cpufreq_cpu_init(struct cpufreq_policy *policy) |
@@ -2437,8 +2429,11 @@ static int intel_pstate_register_driver(void) | |||
2437 | 2429 | ||
2438 | intel_pstate_init_limits(&powersave_limits); | 2430 | intel_pstate_init_limits(&powersave_limits); |
2439 | intel_pstate_set_performance_limits(&performance_limits); | 2431 | intel_pstate_set_performance_limits(&performance_limits); |
2440 | limits = IS_ENABLED(CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE) ? | 2432 | if (IS_ENABLED(CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE) && |
2441 | &performance_limits : &powersave_limits; | 2433 | intel_pstate_driver == &intel_pstate) |
2434 | limits = &performance_limits; | ||
2435 | else | ||
2436 | limits = &powersave_limits; | ||
2442 | 2437 | ||
2443 | ret = cpufreq_register_driver(intel_pstate_driver); | 2438 | ret = cpufreq_register_driver(intel_pstate_driver); |
2444 | if (ret) { | 2439 | if (ret) { |