diff options
Diffstat (limited to 'drivers/cpufreq/intel_pstate.c')
-rw-r--r-- | drivers/cpufreq/intel_pstate.c | 101 |
1 files changed, 99 insertions, 2 deletions
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index 27bb6d3877ed..ab2e100a1807 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c | |||
@@ -137,6 +137,7 @@ struct cpu_defaults { | |||
137 | 137 | ||
138 | static struct pstate_adjust_policy pid_params; | 138 | static struct pstate_adjust_policy pid_params; |
139 | static struct pstate_funcs pstate_funcs; | 139 | static struct pstate_funcs pstate_funcs; |
140 | static int hwp_active; | ||
140 | 141 | ||
141 | struct perf_limits { | 142 | struct perf_limits { |
142 | int no_turbo; | 143 | int no_turbo; |
@@ -244,6 +245,34 @@ static inline void update_turbo_state(void) | |||
244 | cpu->pstate.max_pstate == cpu->pstate.turbo_pstate); | 245 | cpu->pstate.max_pstate == cpu->pstate.turbo_pstate); |
245 | } | 246 | } |
246 | 247 | ||
248 | #define PCT_TO_HWP(x) (x * 255 / 100) | ||
249 | static void intel_pstate_hwp_set(void) | ||
250 | { | ||
251 | int min, max, cpu; | ||
252 | u64 value, freq; | ||
253 | |||
254 | get_online_cpus(); | ||
255 | |||
256 | for_each_online_cpu(cpu) { | ||
257 | rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value); | ||
258 | min = PCT_TO_HWP(limits.min_perf_pct); | ||
259 | value &= ~HWP_MIN_PERF(~0L); | ||
260 | value |= HWP_MIN_PERF(min); | ||
261 | |||
262 | max = PCT_TO_HWP(limits.max_perf_pct); | ||
263 | if (limits.no_turbo) { | ||
264 | rdmsrl( MSR_HWP_CAPABILITIES, freq); | ||
265 | max = HWP_GUARANTEED_PERF(freq); | ||
266 | } | ||
267 | |||
268 | value &= ~HWP_MAX_PERF(~0L); | ||
269 | value |= HWP_MAX_PERF(max); | ||
270 | wrmsrl_on_cpu(cpu, MSR_HWP_REQUEST, value); | ||
271 | } | ||
272 | |||
273 | put_online_cpus(); | ||
274 | } | ||
275 | |||
247 | /************************** debugfs begin ************************/ | 276 | /************************** debugfs begin ************************/ |
248 | static int pid_param_set(void *data, u64 val) | 277 | static int pid_param_set(void *data, u64 val) |
249 | { | 278 | { |
@@ -279,6 +308,8 @@ static void __init intel_pstate_debug_expose_params(void) | |||
279 | struct dentry *debugfs_parent; | 308 | struct dentry *debugfs_parent; |
280 | int i = 0; | 309 | int i = 0; |
281 | 310 | ||
311 | if (hwp_active) | ||
312 | return; | ||
282 | debugfs_parent = debugfs_create_dir("pstate_snb", NULL); | 313 | debugfs_parent = debugfs_create_dir("pstate_snb", NULL); |
283 | if (IS_ERR_OR_NULL(debugfs_parent)) | 314 | if (IS_ERR_OR_NULL(debugfs_parent)) |
284 | return; | 315 | return; |
@@ -329,8 +360,12 @@ static ssize_t store_no_turbo(struct kobject *a, struct attribute *b, | |||
329 | pr_warn("Turbo disabled by BIOS or unavailable on processor\n"); | 360 | pr_warn("Turbo disabled by BIOS or unavailable on processor\n"); |
330 | return -EPERM; | 361 | return -EPERM; |
331 | } | 362 | } |
363 | |||
332 | limits.no_turbo = clamp_t(int, input, 0, 1); | 364 | limits.no_turbo = clamp_t(int, input, 0, 1); |
333 | 365 | ||
366 | if (hwp_active) | ||
367 | intel_pstate_hwp_set(); | ||
368 | |||
334 | return count; | 369 | return count; |
335 | } | 370 | } |
336 | 371 | ||
@@ -348,6 +383,8 @@ static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b, | |||
348 | limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct); | 383 | limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct); |
349 | limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100)); | 384 | limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100)); |
350 | 385 | ||
386 | if (hwp_active) | ||
387 | intel_pstate_hwp_set(); | ||
351 | return count; | 388 | return count; |
352 | } | 389 | } |
353 | 390 | ||
@@ -363,6 +400,8 @@ static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b, | |||
363 | limits.min_perf_pct = clamp_t(int, input, 0 , 100); | 400 | limits.min_perf_pct = clamp_t(int, input, 0 , 100); |
364 | limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100)); | 401 | limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100)); |
365 | 402 | ||
403 | if (hwp_active) | ||
404 | intel_pstate_hwp_set(); | ||
366 | return count; | 405 | return count; |
367 | } | 406 | } |
368 | 407 | ||
@@ -395,8 +434,16 @@ static void __init intel_pstate_sysfs_expose_params(void) | |||
395 | rc = sysfs_create_group(intel_pstate_kobject, &intel_pstate_attr_group); | 434 | rc = sysfs_create_group(intel_pstate_kobject, &intel_pstate_attr_group); |
396 | BUG_ON(rc); | 435 | BUG_ON(rc); |
397 | } | 436 | } |
398 | |||
399 | /************************** sysfs end ************************/ | 437 | /************************** sysfs end ************************/ |
438 | |||
439 | static void intel_pstate_hwp_enable(void) | ||
440 | { | ||
441 | hwp_active++; | ||
442 | pr_info("intel_pstate HWP enabled\n"); | ||
443 | |||
444 | wrmsrl( MSR_PM_ENABLE, 0x1); | ||
445 | } | ||
446 | |||
400 | static int byt_get_min_pstate(void) | 447 | static int byt_get_min_pstate(void) |
401 | { | 448 | { |
402 | u64 value; | 449 | u64 value; |
@@ -648,6 +695,14 @@ static inline void intel_pstate_sample(struct cpudata *cpu) | |||
648 | cpu->prev_mperf = mperf; | 695 | cpu->prev_mperf = mperf; |
649 | } | 696 | } |
650 | 697 | ||
698 | static inline void intel_hwp_set_sample_time(struct cpudata *cpu) | ||
699 | { | ||
700 | int delay; | ||
701 | |||
702 | delay = msecs_to_jiffies(50); | ||
703 | mod_timer_pinned(&cpu->timer, jiffies + delay); | ||
704 | } | ||
705 | |||
651 | static inline void intel_pstate_set_sample_time(struct cpudata *cpu) | 706 | static inline void intel_pstate_set_sample_time(struct cpudata *cpu) |
652 | { | 707 | { |
653 | int delay; | 708 | int delay; |
@@ -694,6 +749,14 @@ static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu) | |||
694 | intel_pstate_set_pstate(cpu, cpu->pstate.current_pstate - ctl); | 749 | intel_pstate_set_pstate(cpu, cpu->pstate.current_pstate - ctl); |
695 | } | 750 | } |
696 | 751 | ||
752 | static void intel_hwp_timer_func(unsigned long __data) | ||
753 | { | ||
754 | struct cpudata *cpu = (struct cpudata *) __data; | ||
755 | |||
756 | intel_pstate_sample(cpu); | ||
757 | intel_hwp_set_sample_time(cpu); | ||
758 | } | ||
759 | |||
697 | static void intel_pstate_timer_func(unsigned long __data) | 760 | static void intel_pstate_timer_func(unsigned long __data) |
698 | { | 761 | { |
699 | struct cpudata *cpu = (struct cpudata *) __data; | 762 | struct cpudata *cpu = (struct cpudata *) __data; |
@@ -730,6 +793,7 @@ static const struct x86_cpu_id intel_pstate_cpu_ids[] = { | |||
730 | ICPU(0x3f, core_params), | 793 | ICPU(0x3f, core_params), |
731 | ICPU(0x45, core_params), | 794 | ICPU(0x45, core_params), |
732 | ICPU(0x46, core_params), | 795 | ICPU(0x46, core_params), |
796 | ICPU(0x47, core_params), | ||
733 | ICPU(0x4c, byt_params), | 797 | ICPU(0x4c, byt_params), |
734 | ICPU(0x4f, core_params), | 798 | ICPU(0x4f, core_params), |
735 | ICPU(0x56, core_params), | 799 | ICPU(0x56, core_params), |
@@ -737,6 +801,11 @@ static const struct x86_cpu_id intel_pstate_cpu_ids[] = { | |||
737 | }; | 801 | }; |
738 | MODULE_DEVICE_TABLE(x86cpu, intel_pstate_cpu_ids); | 802 | MODULE_DEVICE_TABLE(x86cpu, intel_pstate_cpu_ids); |
739 | 803 | ||
804 | static const struct x86_cpu_id intel_pstate_cpu_oob_ids[] = { | ||
805 | ICPU(0x56, core_params), | ||
806 | {} | ||
807 | }; | ||
808 | |||
740 | static int intel_pstate_init_cpu(unsigned int cpunum) | 809 | static int intel_pstate_init_cpu(unsigned int cpunum) |
741 | { | 810 | { |
742 | struct cpudata *cpu; | 811 | struct cpudata *cpu; |
@@ -753,9 +822,14 @@ static int intel_pstate_init_cpu(unsigned int cpunum) | |||
753 | intel_pstate_get_cpu_pstates(cpu); | 822 | intel_pstate_get_cpu_pstates(cpu); |
754 | 823 | ||
755 | init_timer_deferrable(&cpu->timer); | 824 | init_timer_deferrable(&cpu->timer); |
756 | cpu->timer.function = intel_pstate_timer_func; | ||
757 | cpu->timer.data = (unsigned long)cpu; | 825 | cpu->timer.data = (unsigned long)cpu; |
758 | cpu->timer.expires = jiffies + HZ/100; | 826 | cpu->timer.expires = jiffies + HZ/100; |
827 | |||
828 | if (!hwp_active) | ||
829 | cpu->timer.function = intel_pstate_timer_func; | ||
830 | else | ||
831 | cpu->timer.function = intel_hwp_timer_func; | ||
832 | |||
759 | intel_pstate_busy_pid_reset(cpu); | 833 | intel_pstate_busy_pid_reset(cpu); |
760 | intel_pstate_sample(cpu); | 834 | intel_pstate_sample(cpu); |
761 | 835 | ||
@@ -792,6 +866,7 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy) | |||
792 | limits.no_turbo = 0; | 866 | limits.no_turbo = 0; |
793 | return 0; | 867 | return 0; |
794 | } | 868 | } |
869 | |||
795 | limits.min_perf_pct = (policy->min * 100) / policy->cpuinfo.max_freq; | 870 | limits.min_perf_pct = (policy->min * 100) / policy->cpuinfo.max_freq; |
796 | limits.min_perf_pct = clamp_t(int, limits.min_perf_pct, 0 , 100); | 871 | limits.min_perf_pct = clamp_t(int, limits.min_perf_pct, 0 , 100); |
797 | limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100)); | 872 | limits.min_perf = div_fp(int_tofp(limits.min_perf_pct), int_tofp(100)); |
@@ -801,6 +876,9 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy) | |||
801 | limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct); | 876 | limits.max_perf_pct = min(limits.max_policy_pct, limits.max_sysfs_pct); |
802 | limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100)); | 877 | limits.max_perf = div_fp(int_tofp(limits.max_perf_pct), int_tofp(100)); |
803 | 878 | ||
879 | if (hwp_active) | ||
880 | intel_pstate_hwp_set(); | ||
881 | |||
804 | return 0; | 882 | return 0; |
805 | } | 883 | } |
806 | 884 | ||
@@ -823,6 +901,9 @@ static void intel_pstate_stop_cpu(struct cpufreq_policy *policy) | |||
823 | pr_info("intel_pstate CPU %d exiting\n", cpu_num); | 901 | pr_info("intel_pstate CPU %d exiting\n", cpu_num); |
824 | 902 | ||
825 | del_timer_sync(&all_cpu_data[cpu_num]->timer); | 903 | del_timer_sync(&all_cpu_data[cpu_num]->timer); |
904 | if (hwp_active) | ||
905 | return; | ||
906 | |||
826 | intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); | 907 | intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); |
827 | } | 908 | } |
828 | 909 | ||
@@ -866,6 +947,7 @@ static struct cpufreq_driver intel_pstate_driver = { | |||
866 | }; | 947 | }; |
867 | 948 | ||
868 | static int __initdata no_load; | 949 | static int __initdata no_load; |
950 | static int __initdata no_hwp; | ||
869 | 951 | ||
870 | static int intel_pstate_msrs_not_valid(void) | 952 | static int intel_pstate_msrs_not_valid(void) |
871 | { | 953 | { |
@@ -959,6 +1041,15 @@ static bool intel_pstate_platform_pwr_mgmt_exists(void) | |||
959 | { | 1041 | { |
960 | struct acpi_table_header hdr; | 1042 | struct acpi_table_header hdr; |
961 | struct hw_vendor_info *v_info; | 1043 | struct hw_vendor_info *v_info; |
1044 | const struct x86_cpu_id *id; | ||
1045 | u64 misc_pwr; | ||
1046 | |||
1047 | id = x86_match_cpu(intel_pstate_cpu_oob_ids); | ||
1048 | if (id) { | ||
1049 | rdmsrl(MSR_MISC_PWR_MGMT, misc_pwr); | ||
1050 | if ( misc_pwr & (1 << 8)) | ||
1051 | return true; | ||
1052 | } | ||
962 | 1053 | ||
963 | if (acpi_disabled || | 1054 | if (acpi_disabled || |
964 | ACPI_FAILURE(acpi_get_table_header(ACPI_SIG_FADT, 0, &hdr))) | 1055 | ACPI_FAILURE(acpi_get_table_header(ACPI_SIG_FADT, 0, &hdr))) |
@@ -982,6 +1073,7 @@ static int __init intel_pstate_init(void) | |||
982 | int cpu, rc = 0; | 1073 | int cpu, rc = 0; |
983 | const struct x86_cpu_id *id; | 1074 | const struct x86_cpu_id *id; |
984 | struct cpu_defaults *cpu_info; | 1075 | struct cpu_defaults *cpu_info; |
1076 | struct cpuinfo_x86 *c = &boot_cpu_data; | ||
985 | 1077 | ||
986 | if (no_load) | 1078 | if (no_load) |
987 | return -ENODEV; | 1079 | return -ENODEV; |
@@ -1011,6 +1103,9 @@ static int __init intel_pstate_init(void) | |||
1011 | if (!all_cpu_data) | 1103 | if (!all_cpu_data) |
1012 | return -ENOMEM; | 1104 | return -ENOMEM; |
1013 | 1105 | ||
1106 | if (cpu_has(c,X86_FEATURE_HWP) && !no_hwp) | ||
1107 | intel_pstate_hwp_enable(); | ||
1108 | |||
1014 | rc = cpufreq_register_driver(&intel_pstate_driver); | 1109 | rc = cpufreq_register_driver(&intel_pstate_driver); |
1015 | if (rc) | 1110 | if (rc) |
1016 | goto out; | 1111 | goto out; |
@@ -1041,6 +1136,8 @@ static int __init intel_pstate_setup(char *str) | |||
1041 | 1136 | ||
1042 | if (!strcmp(str, "disable")) | 1137 | if (!strcmp(str, "disable")) |
1043 | no_load = 1; | 1138 | no_load = 1; |
1139 | if (!strcmp(str, "no_hwp")) | ||
1140 | no_hwp = 1; | ||
1044 | return 0; | 1141 | return 0; |
1045 | } | 1142 | } |
1046 | early_param("intel_pstate", intel_pstate_setup); | 1143 | early_param("intel_pstate", intel_pstate_setup); |