Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1 | /* |
Srinivas Pandruvada | d1b6848 | 2013-04-09 22:38:18 +0000 | [diff] [blame] | 2 | * intel_pstate.c: Native P state management for Intel processors |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 3 | * |
| 4 | * (C) Copyright 2012 Intel Corporation |
| 5 | * Author: Dirk Brandewie <dirk.j.brandewie@intel.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; version 2 |
| 10 | * of the License. |
| 11 | */ |
| 12 | |
Joe Perches | 4836df1 | 2016-04-05 13:28:23 -0700 | [diff] [blame] | 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 14 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/kernel_stat.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/ktime.h> |
| 19 | #include <linux/hrtimer.h> |
| 20 | #include <linux/tick.h> |
| 21 | #include <linux/slab.h> |
Ingo Molnar | 55687da | 2017-02-08 18:51:31 +0100 | [diff] [blame] | 22 | #include <linux/sched/cpufreq.h> |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 23 | #include <linux/list.h> |
| 24 | #include <linux/cpu.h> |
| 25 | #include <linux/cpufreq.h> |
| 26 | #include <linux/sysfs.h> |
| 27 | #include <linux/types.h> |
| 28 | #include <linux/fs.h> |
| 29 | #include <linux/debugfs.h> |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 30 | #include <linux/acpi.h> |
Stephen Rothwell | d647230 | 2015-06-02 19:01:38 +1000 | [diff] [blame] | 31 | #include <linux/vmalloc.h> |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 32 | #include <trace/events/power.h> |
| 33 | |
| 34 | #include <asm/div64.h> |
| 35 | #include <asm/msr.h> |
| 36 | #include <asm/cpu_device_id.h> |
Borislav Petkov | 64df1fd | 2015-04-03 15:19:53 +0200 | [diff] [blame] | 37 | #include <asm/cpufeature.h> |
Dave Hansen | 5b20c94 | 2016-06-02 17:19:45 -0700 | [diff] [blame] | 38 | #include <asm/intel-family.h> |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 39 | |
Rafael J. Wysocki | eabd22c | 2017-03-28 00:15:37 +0200 | [diff] [blame] | 40 | #define INTEL_PSTATE_DEFAULT_SAMPLING_INTERVAL (10 * NSEC_PER_MSEC) |
| 41 | #define INTEL_PSTATE_HWP_SAMPLING_INTERVAL (50 * NSEC_PER_MSEC) |
| 42 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 43 | #define INTEL_CPUFREQ_TRANSITION_LATENCY 20000 |
| 44 | |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 45 | #ifdef CONFIG_ACPI |
| 46 | #include <acpi/processor.h> |
Rafael J. Wysocki | 1766900 | 2016-11-22 12:24:00 -0800 | [diff] [blame] | 47 | #include <acpi/cppc_acpi.h> |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 48 | #endif |
| 49 | |
Dirk Brandewie | f0fe3cd | 2014-05-29 09:32:23 -0700 | [diff] [blame] | 50 | #define FRAC_BITS 8 |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 51 | #define int_tofp(X) ((int64_t)(X) << FRAC_BITS) |
| 52 | #define fp_toint(X) ((X) >> FRAC_BITS) |
Dirk Brandewie | f0fe3cd | 2014-05-29 09:32:23 -0700 | [diff] [blame] | 53 | |
Rafael J. Wysocki | a1c9787 | 2016-05-11 19:09:12 +0200 | [diff] [blame] | 54 | #define EXT_BITS 6 |
| 55 | #define EXT_FRAC_BITS (EXT_BITS + FRAC_BITS) |
Srinivas Pandruvada | d5dd33d | 2016-11-21 16:33:20 -0800 | [diff] [blame] | 56 | #define fp_ext_toint(X) ((X) >> EXT_FRAC_BITS) |
| 57 | #define int_ext_tofp(X) ((int64_t)(X) << EXT_FRAC_BITS) |
Rafael J. Wysocki | a1c9787 | 2016-05-11 19:09:12 +0200 | [diff] [blame] | 58 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 59 | static inline int32_t mul_fp(int32_t x, int32_t y) |
| 60 | { |
| 61 | return ((int64_t)x * (int64_t)y) >> FRAC_BITS; |
| 62 | } |
| 63 | |
Prarit Bhargava | 7180ddd | 2015-06-15 13:43:29 -0400 | [diff] [blame] | 64 | static inline int32_t div_fp(s64 x, s64 y) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 65 | { |
Prarit Bhargava | 7180ddd | 2015-06-15 13:43:29 -0400 | [diff] [blame] | 66 | return div64_s64((int64_t)x << FRAC_BITS, y); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Dirk Brandewie | d022a65 | 2014-10-13 08:37:44 -0700 | [diff] [blame] | 69 | static inline int ceiling_fp(int32_t x) |
| 70 | { |
| 71 | int mask, ret; |
| 72 | |
| 73 | ret = fp_toint(x); |
| 74 | mask = (1 << FRAC_BITS) - 1; |
| 75 | if (x & mask) |
| 76 | ret += 1; |
| 77 | return ret; |
| 78 | } |
| 79 | |
Rafael J. Wysocki | ff35f02 | 2017-03-28 00:09:18 +0200 | [diff] [blame] | 80 | static inline int32_t percent_fp(int percent) |
| 81 | { |
| 82 | return div_fp(percent, 100); |
| 83 | } |
| 84 | |
Rafael J. Wysocki | a1c9787 | 2016-05-11 19:09:12 +0200 | [diff] [blame] | 85 | static inline u64 mul_ext_fp(u64 x, u64 y) |
| 86 | { |
| 87 | return (x * y) >> EXT_FRAC_BITS; |
| 88 | } |
| 89 | |
| 90 | static inline u64 div_ext_fp(u64 x, u64 y) |
| 91 | { |
| 92 | return div64_u64(x << EXT_FRAC_BITS, y); |
| 93 | } |
| 94 | |
Rafael J. Wysocki | e4c204c | 2017-03-14 16:18:34 +0100 | [diff] [blame] | 95 | static inline int32_t percent_ext_fp(int percent) |
| 96 | { |
| 97 | return div_ext_fp(percent, 100); |
| 98 | } |
| 99 | |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 100 | /** |
| 101 | * struct sample - Store performance sample |
Rafael J. Wysocki | a1c9787 | 2016-05-11 19:09:12 +0200 | [diff] [blame] | 102 | * @core_avg_perf: Ratio of APERF/MPERF which is the actual average |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 103 | * performance during last sample period |
| 104 | * @busy_scaled: Scaled busy value which is used to calculate next |
Rafael J. Wysocki | a1c9787 | 2016-05-11 19:09:12 +0200 | [diff] [blame] | 105 | * P state. This can be different than core_avg_perf |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 106 | * to account for cpu idle period |
| 107 | * @aperf: Difference of actual performance frequency clock count |
| 108 | * read from APERF MSR between last and current sample |
| 109 | * @mperf: Difference of maximum performance frequency clock count |
| 110 | * read from MPERF MSR between last and current sample |
| 111 | * @tsc: Difference of time stamp counter between last and |
| 112 | * current sample |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 113 | * @time: Current time from scheduler |
| 114 | * |
| 115 | * This structure is used in the cpudata structure to store performance sample |
| 116 | * data for choosing next P State. |
| 117 | */ |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 118 | struct sample { |
Rafael J. Wysocki | a1c9787 | 2016-05-11 19:09:12 +0200 | [diff] [blame] | 119 | int32_t core_avg_perf; |
Philippe Longepe | 157386b | 2015-12-04 17:40:30 +0100 | [diff] [blame] | 120 | int32_t busy_scaled; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 121 | u64 aperf; |
| 122 | u64 mperf; |
Doug Smythies | 4055fad | 2015-04-11 21:10:26 -0700 | [diff] [blame] | 123 | u64 tsc; |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 124 | u64 time; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 125 | }; |
| 126 | |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 127 | /** |
| 128 | * struct pstate_data - Store P state data |
| 129 | * @current_pstate: Current requested P state |
| 130 | * @min_pstate: Min P state possible for this platform |
| 131 | * @max_pstate: Max P state possible for this platform |
| 132 | * @max_pstate_physical:This is physical Max P state for a processor |
| 133 | * This can be higher than the max_pstate which can |
| 134 | * be limited by platform thermal design power limits |
| 135 | * @scaling: Scaling factor to convert frequency to cpufreq |
| 136 | * frequency units |
| 137 | * @turbo_pstate: Max Turbo P state possible for this platform |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 138 | * @max_freq: @max_pstate frequency in cpufreq units |
| 139 | * @turbo_freq: @turbo_pstate frequency in cpufreq units |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 140 | * |
| 141 | * Stores the per cpu model P state limits and current P state. |
| 142 | */ |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 143 | struct pstate_data { |
| 144 | int current_pstate; |
| 145 | int min_pstate; |
| 146 | int max_pstate; |
Srinivas Pandruvada | 3bcc6fa | 2015-10-14 16:12:00 -0700 | [diff] [blame] | 147 | int max_pstate_physical; |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 148 | int scaling; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 149 | int turbo_pstate; |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 150 | unsigned int max_freq; |
| 151 | unsigned int turbo_freq; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 152 | }; |
| 153 | |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 154 | /** |
| 155 | * struct vid_data - Stores voltage information data |
| 156 | * @min: VID data for this platform corresponding to |
| 157 | * the lowest P state |
| 158 | * @max: VID data corresponding to the highest P State. |
| 159 | * @turbo: VID data for turbo P state |
| 160 | * @ratio: Ratio of (vid max - vid min) / |
| 161 | * (max P state - Min P State) |
| 162 | * |
| 163 | * Stores the voltage data for DVFS (Dynamic Voltage and Frequency Scaling) |
| 164 | * This data is used in Atom platforms, where in addition to target P state, |
| 165 | * the voltage data needs to be specified to select next P State. |
| 166 | */ |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 167 | struct vid_data { |
Dirk Brandewie | 21855ff | 2014-05-08 12:57:23 -0700 | [diff] [blame] | 168 | int min; |
| 169 | int max; |
| 170 | int turbo; |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 171 | int32_t ratio; |
| 172 | }; |
| 173 | |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 174 | /** |
| 175 | * struct _pid - Stores PID data |
| 176 | * @setpoint: Target set point for busyness or performance |
| 177 | * @integral: Storage for accumulated error values |
| 178 | * @p_gain: PID proportional gain |
| 179 | * @i_gain: PID integral gain |
| 180 | * @d_gain: PID derivative gain |
| 181 | * @deadband: PID deadband |
| 182 | * @last_err: Last error storage for integral part of PID calculation |
| 183 | * |
| 184 | * Stores PID coefficients and last error for PID controller. |
| 185 | */ |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 186 | struct _pid { |
| 187 | int setpoint; |
| 188 | int32_t integral; |
| 189 | int32_t p_gain; |
| 190 | int32_t i_gain; |
| 191 | int32_t d_gain; |
| 192 | int deadband; |
Brennan Shacklett | d253d2a | 2013-10-21 09:20:32 -0700 | [diff] [blame] | 193 | int32_t last_err; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 194 | }; |
| 195 | |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 196 | /** |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 197 | * struct global_params - Global parameters, mostly tunable via sysfs. |
| 198 | * @no_turbo: Whether or not to use turbo P-states. |
| 199 | * @turbo_disabled: Whethet or not turbo P-states are available at all, |
| 200 | * based on the MSR_IA32_MISC_ENABLE value and whether or |
| 201 | * not the maximum reported turbo P-state is different from |
| 202 | * the maximum reported non-turbo one. |
| 203 | * @min_perf_pct: Minimum capacity limit in percent of the maximum turbo |
| 204 | * P-state capacity. |
| 205 | * @max_perf_pct: Maximum capacity limit in percent of the maximum turbo |
| 206 | * P-state capacity. |
| 207 | */ |
| 208 | struct global_params { |
| 209 | bool no_turbo; |
| 210 | bool turbo_disabled; |
| 211 | int max_perf_pct; |
| 212 | int min_perf_pct; |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | /** |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 216 | * struct cpudata - Per CPU instance data storage |
| 217 | * @cpu: CPU number for this instance data |
Rafael J. Wysocki | 2f1d407 | 2016-10-24 23:20:25 +0200 | [diff] [blame] | 218 | * @policy: CPUFreq policy value |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 219 | * @update_util: CPUFreq utility callback information |
Chen Yu | 4578ee7e | 2016-05-11 14:33:08 +0800 | [diff] [blame] | 220 | * @update_util_set: CPUFreq utility callback is set |
Rafael J. Wysocki | 09c448d | 2016-09-14 02:28:13 +0200 | [diff] [blame] | 221 | * @iowait_boost: iowait-related boost fraction |
| 222 | * @last_update: Time of the last update. |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 223 | * @pstate: Stores P state limits for this CPU |
| 224 | * @vid: Stores VID limits for this CPU |
| 225 | * @pid: Stores PID parameters for this CPU |
| 226 | * @last_sample_time: Last Sample time |
| 227 | * @prev_aperf: Last APERF value read from APERF MSR |
| 228 | * @prev_mperf: Last MPERF value read from MPERF MSR |
| 229 | * @prev_tsc: Last timestamp counter (TSC) value |
| 230 | * @prev_cummulative_iowait: IO Wait time difference from last and |
| 231 | * current sample |
| 232 | * @sample: Storage for storing last Sample data |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 233 | * @min_perf: Minimum capacity limit as a fraction of the maximum |
| 234 | * turbo P-state capacity. |
| 235 | * @max_perf: Maximum capacity limit as a fraction of the maximum |
| 236 | * turbo P-state capacity. |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 237 | * @acpi_perf_data: Stores ACPI perf information read from _PSS |
| 238 | * @valid_pss_table: Set to true for valid ACPI _PSS entries found |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 239 | * @epp_powersave: Last saved HWP energy performance preference |
| 240 | * (EPP) or energy performance bias (EPB), |
| 241 | * when policy switched to performance |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 242 | * @epp_policy: Last saved policy used to set EPP/EPB |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 243 | * @epp_default: Power on default HWP energy performance |
| 244 | * preference/bias |
| 245 | * @epp_saved: Saved EPP/EPB during system suspend or CPU offline |
| 246 | * operation |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 247 | * |
| 248 | * This structure stores per CPU instance data for all CPUs. |
| 249 | */ |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 250 | struct cpudata { |
| 251 | int cpu; |
| 252 | |
Rafael J. Wysocki | 2f1d407 | 2016-10-24 23:20:25 +0200 | [diff] [blame] | 253 | unsigned int policy; |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 254 | struct update_util_data update_util; |
Chen Yu | 4578ee7e | 2016-05-11 14:33:08 +0800 | [diff] [blame] | 255 | bool update_util_set; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 256 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 257 | struct pstate_data pstate; |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 258 | struct vid_data vid; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 259 | struct _pid pid; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 260 | |
Rafael J. Wysocki | 09c448d | 2016-09-14 02:28:13 +0200 | [diff] [blame] | 261 | u64 last_update; |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 262 | u64 last_sample_time; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 263 | u64 prev_aperf; |
| 264 | u64 prev_mperf; |
Doug Smythies | 4055fad | 2015-04-11 21:10:26 -0700 | [diff] [blame] | 265 | u64 prev_tsc; |
Philippe Longepe | 63d1d65 | 2015-12-04 17:40:35 +0100 | [diff] [blame] | 266 | u64 prev_cummulative_iowait; |
Dirk Brandewie | d37e2b7 | 2014-02-12 10:01:04 -0800 | [diff] [blame] | 267 | struct sample sample; |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 268 | int32_t min_perf; |
| 269 | int32_t max_perf; |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 270 | #ifdef CONFIG_ACPI |
| 271 | struct acpi_processor_performance acpi_perf_data; |
| 272 | bool valid_pss_table; |
| 273 | #endif |
Rafael J. Wysocki | 09c448d | 2016-09-14 02:28:13 +0200 | [diff] [blame] | 274 | unsigned int iowait_boost; |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 275 | s16 epp_powersave; |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 276 | s16 epp_policy; |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 277 | s16 epp_default; |
| 278 | s16 epp_saved; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 279 | }; |
| 280 | |
| 281 | static struct cpudata **all_cpu_data; |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 282 | |
| 283 | /** |
Rafael J. Wysocki | 3954517 | 2016-10-11 23:07:38 +0200 | [diff] [blame] | 284 | * struct pstate_adjust_policy - Stores static PID configuration data |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 285 | * @sample_rate_ms: PID calculation sample rate in ms |
| 286 | * @sample_rate_ns: Sample rate calculation in ns |
| 287 | * @deadband: PID deadband |
| 288 | * @setpoint: PID Setpoint |
| 289 | * @p_gain_pct: PID proportional gain |
| 290 | * @i_gain_pct: PID integral gain |
| 291 | * @d_gain_pct: PID derivative gain |
| 292 | * |
| 293 | * Stores per CPU model static PID configuration data. |
| 294 | */ |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 295 | struct pstate_adjust_policy { |
| 296 | int sample_rate_ms; |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 297 | s64 sample_rate_ns; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 298 | int deadband; |
| 299 | int setpoint; |
| 300 | int p_gain_pct; |
| 301 | int d_gain_pct; |
| 302 | int i_gain_pct; |
| 303 | }; |
| 304 | |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 305 | /** |
| 306 | * struct pstate_funcs - Per CPU model specific callbacks |
| 307 | * @get_max: Callback to get maximum non turbo effective P state |
| 308 | * @get_max_physical: Callback to get maximum non turbo physical P state |
| 309 | * @get_min: Callback to get minimum P state |
| 310 | * @get_turbo: Callback to get turbo P state |
| 311 | * @get_scaling: Callback to get frequency scaling factor |
| 312 | * @get_val: Callback to convert P state to actual MSR write value |
| 313 | * @get_vid: Callback to get VID data for Atom platforms |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 314 | * @update_util: Active mode utilization update callback. |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 315 | * |
| 316 | * Core and Atom CPU models have different way to get P State limits. This |
| 317 | * structure is used to store those callbacks. |
| 318 | */ |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 319 | struct pstate_funcs { |
| 320 | int (*get_max)(void); |
Srinivas Pandruvada | 3bcc6fa | 2015-10-14 16:12:00 -0700 | [diff] [blame] | 321 | int (*get_max_physical)(void); |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 322 | int (*get_min)(void); |
| 323 | int (*get_turbo)(void); |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 324 | int (*get_scaling)(void); |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 325 | u64 (*get_val)(struct cpudata*, int pstate); |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 326 | void (*get_vid)(struct cpudata *); |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 327 | void (*update_util)(struct update_util_data *data, u64 time, |
| 328 | unsigned int flags); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 329 | }; |
| 330 | |
Jisheng Zhang | 4a7cb7a | 2016-06-27 18:07:18 +0800 | [diff] [blame] | 331 | static struct pstate_funcs pstate_funcs __read_mostly; |
Rafael J. Wysocki | 5c43905 | 2017-03-28 00:05:44 +0200 | [diff] [blame] | 332 | static struct pstate_adjust_policy pid_params __read_mostly = { |
| 333 | .sample_rate_ms = 10, |
| 334 | .sample_rate_ns = 10 * NSEC_PER_MSEC, |
| 335 | .deadband = 0, |
| 336 | .setpoint = 97, |
| 337 | .p_gain_pct = 20, |
| 338 | .d_gain_pct = 0, |
| 339 | .i_gain_pct = 0, |
| 340 | }; |
| 341 | |
Jisheng Zhang | 4a7cb7a | 2016-06-27 18:07:18 +0800 | [diff] [blame] | 342 | static int hwp_active __read_mostly; |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 343 | static bool per_cpu_limits __read_mostly; |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 344 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 345 | static struct cpufreq_driver *intel_pstate_driver __read_mostly; |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 346 | |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 347 | #ifdef CONFIG_ACPI |
| 348 | static bool acpi_ppc; |
| 349 | #endif |
Srinivas Pandruvada | 13ad770 | 2016-04-03 13:06:46 -0700 | [diff] [blame] | 350 | |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 351 | static struct global_params global; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 352 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 353 | static DEFINE_MUTEX(intel_pstate_driver_lock); |
Srinivas Pandruvada | a410c03 | 2016-10-28 10:44:52 -0700 | [diff] [blame] | 354 | static DEFINE_MUTEX(intel_pstate_limits_lock); |
| 355 | |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 356 | #ifdef CONFIG_ACPI |
Srinivas Pandruvada | 2b3ec76 | 2016-04-27 15:48:08 -0700 | [diff] [blame] | 357 | |
| 358 | static bool intel_pstate_get_ppc_enable_status(void) |
| 359 | { |
| 360 | if (acpi_gbl_FADT.preferred_profile == PM_ENTERPRISE_SERVER || |
| 361 | acpi_gbl_FADT.preferred_profile == PM_PERFORMANCE_SERVER) |
| 362 | return true; |
| 363 | |
| 364 | return acpi_ppc; |
| 365 | } |
| 366 | |
Rafael J. Wysocki | 1766900 | 2016-11-22 12:24:00 -0800 | [diff] [blame] | 367 | #ifdef CONFIG_ACPI_CPPC_LIB |
| 368 | |
| 369 | /* The work item is needed to avoid CPU hotplug locking issues */ |
| 370 | static void intel_pstste_sched_itmt_work_fn(struct work_struct *work) |
| 371 | { |
| 372 | sched_set_itmt_support(); |
| 373 | } |
| 374 | |
| 375 | static DECLARE_WORK(sched_itmt_work, intel_pstste_sched_itmt_work_fn); |
| 376 | |
| 377 | static void intel_pstate_set_itmt_prio(int cpu) |
| 378 | { |
| 379 | struct cppc_perf_caps cppc_perf; |
| 380 | static u32 max_highest_perf = 0, min_highest_perf = U32_MAX; |
| 381 | int ret; |
| 382 | |
| 383 | ret = cppc_get_perf_caps(cpu, &cppc_perf); |
| 384 | if (ret) |
| 385 | return; |
| 386 | |
| 387 | /* |
| 388 | * The priorities can be set regardless of whether or not |
| 389 | * sched_set_itmt_support(true) has been called and it is valid to |
| 390 | * update them at any time after it has been called. |
| 391 | */ |
| 392 | sched_set_itmt_core_prio(cppc_perf.highest_perf, cpu); |
| 393 | |
| 394 | if (max_highest_perf <= min_highest_perf) { |
| 395 | if (cppc_perf.highest_perf > max_highest_perf) |
| 396 | max_highest_perf = cppc_perf.highest_perf; |
| 397 | |
| 398 | if (cppc_perf.highest_perf < min_highest_perf) |
| 399 | min_highest_perf = cppc_perf.highest_perf; |
| 400 | |
| 401 | if (max_highest_perf > min_highest_perf) { |
| 402 | /* |
| 403 | * This code can be run during CPU online under the |
| 404 | * CPU hotplug locks, so sched_set_itmt_support() |
| 405 | * cannot be called from here. Queue up a work item |
| 406 | * to invoke it. |
| 407 | */ |
| 408 | schedule_work(&sched_itmt_work); |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | #else |
| 413 | static void intel_pstate_set_itmt_prio(int cpu) |
| 414 | { |
| 415 | } |
| 416 | #endif |
| 417 | |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 418 | static void intel_pstate_init_acpi_perf_limits(struct cpufreq_policy *policy) |
| 419 | { |
| 420 | struct cpudata *cpu; |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 421 | int ret; |
| 422 | int i; |
| 423 | |
Rafael J. Wysocki | 1766900 | 2016-11-22 12:24:00 -0800 | [diff] [blame] | 424 | if (hwp_active) { |
| 425 | intel_pstate_set_itmt_prio(policy->cpu); |
Srinivas Pandruvada | e59a8f7 | 2016-05-04 15:07:34 -0700 | [diff] [blame] | 426 | return; |
Rafael J. Wysocki | 1766900 | 2016-11-22 12:24:00 -0800 | [diff] [blame] | 427 | } |
Srinivas Pandruvada | e59a8f7 | 2016-05-04 15:07:34 -0700 | [diff] [blame] | 428 | |
Srinivas Pandruvada | 2b3ec76 | 2016-04-27 15:48:08 -0700 | [diff] [blame] | 429 | if (!intel_pstate_get_ppc_enable_status()) |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 430 | return; |
| 431 | |
| 432 | cpu = all_cpu_data[policy->cpu]; |
| 433 | |
| 434 | ret = acpi_processor_register_performance(&cpu->acpi_perf_data, |
| 435 | policy->cpu); |
| 436 | if (ret) |
| 437 | return; |
| 438 | |
| 439 | /* |
| 440 | * Check if the control value in _PSS is for PERF_CTL MSR, which should |
| 441 | * guarantee that the states returned by it map to the states in our |
| 442 | * list directly. |
| 443 | */ |
| 444 | if (cpu->acpi_perf_data.control_register.space_id != |
| 445 | ACPI_ADR_SPACE_FIXED_HARDWARE) |
| 446 | goto err; |
| 447 | |
| 448 | /* |
| 449 | * If there is only one entry _PSS, simply ignore _PSS and continue as |
| 450 | * usual without taking _PSS into account |
| 451 | */ |
| 452 | if (cpu->acpi_perf_data.state_count < 2) |
| 453 | goto err; |
| 454 | |
| 455 | pr_debug("CPU%u - ACPI _PSS perf data\n", policy->cpu); |
| 456 | for (i = 0; i < cpu->acpi_perf_data.state_count; i++) { |
| 457 | pr_debug(" %cP%d: %u MHz, %u mW, 0x%x\n", |
| 458 | (i == cpu->acpi_perf_data.state ? '*' : ' '), i, |
| 459 | (u32) cpu->acpi_perf_data.states[i].core_frequency, |
| 460 | (u32) cpu->acpi_perf_data.states[i].power, |
| 461 | (u32) cpu->acpi_perf_data.states[i].control); |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * The _PSS table doesn't contain whole turbo frequency range. |
| 466 | * This just contains +1 MHZ above the max non turbo frequency, |
| 467 | * with control value corresponding to max turbo ratio. But |
| 468 | * when cpufreq set policy is called, it will call with this |
| 469 | * max frequency, which will cause a reduced performance as |
| 470 | * this driver uses real max turbo frequency as the max |
| 471 | * frequency. So correct this frequency in _PSS table to |
Srinivas Pandruvada | b00345d | 2016-06-14 23:12:59 -0700 | [diff] [blame] | 472 | * correct max turbo frequency based on the turbo state. |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 473 | * Also need to convert to MHz as _PSS freq is in MHz. |
| 474 | */ |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 475 | if (!global.turbo_disabled) |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 476 | cpu->acpi_perf_data.states[0].core_frequency = |
| 477 | policy->cpuinfo.max_freq / 1000; |
| 478 | cpu->valid_pss_table = true; |
Srinivas Pandruvada | 6cacd11 | 2016-05-29 23:31:23 -0700 | [diff] [blame] | 479 | pr_debug("_PPC limits will be enforced\n"); |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 480 | |
| 481 | return; |
| 482 | |
| 483 | err: |
| 484 | cpu->valid_pss_table = false; |
| 485 | acpi_processor_unregister_performance(policy->cpu); |
| 486 | } |
| 487 | |
| 488 | static void intel_pstate_exit_perf_limits(struct cpufreq_policy *policy) |
| 489 | { |
| 490 | struct cpudata *cpu; |
| 491 | |
| 492 | cpu = all_cpu_data[policy->cpu]; |
| 493 | if (!cpu->valid_pss_table) |
| 494 | return; |
| 495 | |
| 496 | acpi_processor_unregister_performance(policy->cpu); |
| 497 | } |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 498 | #else |
Arnd Bergmann | 7a3ba76 | 2016-11-25 17:50:20 +0100 | [diff] [blame] | 499 | static inline void intel_pstate_init_acpi_perf_limits(struct cpufreq_policy *policy) |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 500 | { |
| 501 | } |
| 502 | |
Arnd Bergmann | 7a3ba76 | 2016-11-25 17:50:20 +0100 | [diff] [blame] | 503 | static inline void intel_pstate_exit_perf_limits(struct cpufreq_policy *policy) |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 504 | { |
| 505 | } |
| 506 | #endif |
| 507 | |
Brennan Shacklett | d253d2a | 2013-10-21 09:20:32 -0700 | [diff] [blame] | 508 | static signed int pid_calc(struct _pid *pid, int32_t busy) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 509 | { |
Brennan Shacklett | d253d2a | 2013-10-21 09:20:32 -0700 | [diff] [blame] | 510 | signed int result; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 511 | int32_t pterm, dterm, fp_error; |
| 512 | int32_t integral_limit; |
| 513 | |
Philippe Longepe | b54a0df | 2016-03-08 10:31:14 +0100 | [diff] [blame] | 514 | fp_error = pid->setpoint - busy; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 515 | |
Philippe Longepe | b54a0df | 2016-03-08 10:31:14 +0100 | [diff] [blame] | 516 | if (abs(fp_error) <= pid->deadband) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 517 | return 0; |
| 518 | |
| 519 | pterm = mul_fp(pid->p_gain, fp_error); |
| 520 | |
| 521 | pid->integral += fp_error; |
| 522 | |
Kristen Carlson Accardi | e0d4c8f | 2014-12-10 12:39:38 -0800 | [diff] [blame] | 523 | /* |
| 524 | * We limit the integral here so that it will never |
| 525 | * get higher than 30. This prevents it from becoming |
| 526 | * too large an input over long periods of time and allows |
| 527 | * it to get factored out sooner. |
| 528 | * |
| 529 | * The value of 30 was chosen through experimentation. |
| 530 | */ |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 531 | integral_limit = int_tofp(30); |
| 532 | if (pid->integral > integral_limit) |
| 533 | pid->integral = integral_limit; |
| 534 | if (pid->integral < -integral_limit) |
| 535 | pid->integral = -integral_limit; |
| 536 | |
Brennan Shacklett | d253d2a | 2013-10-21 09:20:32 -0700 | [diff] [blame] | 537 | dterm = mul_fp(pid->d_gain, fp_error - pid->last_err); |
| 538 | pid->last_err = fp_error; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 539 | |
| 540 | result = pterm + mul_fp(pid->integral, pid->i_gain) + dterm; |
Doug Smythies | 51d211e | 2014-06-17 13:36:10 -0700 | [diff] [blame] | 541 | result = result + (1 << (FRAC_BITS-1)); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 542 | return (signed int)fp_toint(result); |
| 543 | } |
| 544 | |
Rafael J. Wysocki | ff35f02 | 2017-03-28 00:09:18 +0200 | [diff] [blame] | 545 | static inline void intel_pstate_pid_reset(struct cpudata *cpu) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 546 | { |
Rafael J. Wysocki | ff35f02 | 2017-03-28 00:09:18 +0200 | [diff] [blame] | 547 | struct _pid *pid = &cpu->pid; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 548 | |
Rafael J. Wysocki | ff35f02 | 2017-03-28 00:09:18 +0200 | [diff] [blame] | 549 | pid->p_gain = percent_fp(pid_params.p_gain_pct); |
| 550 | pid->d_gain = percent_fp(pid_params.d_gain_pct); |
| 551 | pid->i_gain = percent_fp(pid_params.i_gain_pct); |
| 552 | pid->setpoint = int_tofp(pid_params.setpoint); |
| 553 | pid->last_err = pid->setpoint - int_tofp(100); |
| 554 | pid->deadband = int_tofp(pid_params.deadband); |
| 555 | pid->integral = 0; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Gabriele Mazzotta | 4521e1a0 | 2014-10-13 08:37:41 -0700 | [diff] [blame] | 558 | static inline void update_turbo_state(void) |
| 559 | { |
| 560 | u64 misc_en; |
| 561 | struct cpudata *cpu; |
| 562 | |
| 563 | cpu = all_cpu_data[0]; |
| 564 | rdmsrl(MSR_IA32_MISC_ENABLE, misc_en); |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 565 | global.turbo_disabled = |
Gabriele Mazzotta | 4521e1a0 | 2014-10-13 08:37:41 -0700 | [diff] [blame] | 566 | (misc_en & MSR_IA32_MISC_ENABLE_TURBO_DISABLE || |
| 567 | cpu->pstate.max_pstate == cpu->pstate.turbo_pstate); |
| 568 | } |
| 569 | |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 570 | static int min_perf_pct_min(void) |
| 571 | { |
| 572 | struct cpudata *cpu = all_cpu_data[0]; |
| 573 | |
| 574 | return DIV_ROUND_UP(cpu->pstate.min_pstate * 100, |
| 575 | cpu->pstate.turbo_pstate); |
| 576 | } |
| 577 | |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 578 | static s16 intel_pstate_get_epb(struct cpudata *cpu_data) |
| 579 | { |
| 580 | u64 epb; |
| 581 | int ret; |
| 582 | |
| 583 | if (!static_cpu_has(X86_FEATURE_EPB)) |
| 584 | return -ENXIO; |
| 585 | |
| 586 | ret = rdmsrl_on_cpu(cpu_data->cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); |
| 587 | if (ret) |
| 588 | return (s16)ret; |
| 589 | |
| 590 | return (s16)(epb & 0x0f); |
| 591 | } |
| 592 | |
| 593 | static s16 intel_pstate_get_epp(struct cpudata *cpu_data, u64 hwp_req_data) |
| 594 | { |
| 595 | s16 epp; |
| 596 | |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 597 | if (static_cpu_has(X86_FEATURE_HWP_EPP)) { |
| 598 | /* |
| 599 | * When hwp_req_data is 0, means that caller didn't read |
| 600 | * MSR_HWP_REQUEST, so need to read and get EPP. |
| 601 | */ |
| 602 | if (!hwp_req_data) { |
| 603 | epp = rdmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, |
| 604 | &hwp_req_data); |
| 605 | if (epp) |
| 606 | return epp; |
| 607 | } |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 608 | epp = (hwp_req_data >> 24) & 0xff; |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 609 | } else { |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 610 | /* When there is no EPP present, HWP uses EPB settings */ |
| 611 | epp = intel_pstate_get_epb(cpu_data); |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 612 | } |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 613 | |
| 614 | return epp; |
| 615 | } |
| 616 | |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 617 | static int intel_pstate_set_epb(int cpu, s16 pref) |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 618 | { |
| 619 | u64 epb; |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 620 | int ret; |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 621 | |
| 622 | if (!static_cpu_has(X86_FEATURE_EPB)) |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 623 | return -ENXIO; |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 624 | |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 625 | ret = rdmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, &epb); |
| 626 | if (ret) |
| 627 | return ret; |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 628 | |
| 629 | epb = (epb & ~0x0f) | pref; |
| 630 | wrmsrl_on_cpu(cpu, MSR_IA32_ENERGY_PERF_BIAS, epb); |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 631 | |
| 632 | return 0; |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 633 | } |
| 634 | |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 635 | /* |
| 636 | * EPP/EPB display strings corresponding to EPP index in the |
| 637 | * energy_perf_strings[] |
| 638 | * index String |
| 639 | *------------------------------------- |
| 640 | * 0 default |
| 641 | * 1 performance |
| 642 | * 2 balance_performance |
| 643 | * 3 balance_power |
| 644 | * 4 power |
| 645 | */ |
| 646 | static const char * const energy_perf_strings[] = { |
| 647 | "default", |
| 648 | "performance", |
| 649 | "balance_performance", |
| 650 | "balance_power", |
| 651 | "power", |
| 652 | NULL |
| 653 | }; |
| 654 | |
| 655 | static int intel_pstate_get_energy_pref_index(struct cpudata *cpu_data) |
| 656 | { |
| 657 | s16 epp; |
| 658 | int index = -EINVAL; |
| 659 | |
| 660 | epp = intel_pstate_get_epp(cpu_data, 0); |
| 661 | if (epp < 0) |
| 662 | return epp; |
| 663 | |
| 664 | if (static_cpu_has(X86_FEATURE_HWP_EPP)) { |
| 665 | /* |
| 666 | * Range: |
| 667 | * 0x00-0x3F : Performance |
| 668 | * 0x40-0x7F : Balance performance |
| 669 | * 0x80-0xBF : Balance power |
| 670 | * 0xC0-0xFF : Power |
| 671 | * The EPP is a 8 bit value, but our ranges restrict the |
| 672 | * value which can be set. Here only using top two bits |
| 673 | * effectively. |
| 674 | */ |
| 675 | index = (epp >> 6) + 1; |
| 676 | } else if (static_cpu_has(X86_FEATURE_EPB)) { |
| 677 | /* |
| 678 | * Range: |
| 679 | * 0x00-0x03 : Performance |
| 680 | * 0x04-0x07 : Balance performance |
| 681 | * 0x08-0x0B : Balance power |
| 682 | * 0x0C-0x0F : Power |
| 683 | * The EPB is a 4 bit value, but our ranges restrict the |
| 684 | * value which can be set. Here only using top two bits |
| 685 | * effectively. |
| 686 | */ |
| 687 | index = (epp >> 2) + 1; |
| 688 | } |
| 689 | |
| 690 | return index; |
| 691 | } |
| 692 | |
| 693 | static int intel_pstate_set_energy_pref_index(struct cpudata *cpu_data, |
| 694 | int pref_index) |
| 695 | { |
| 696 | int epp = -EINVAL; |
| 697 | int ret; |
| 698 | |
| 699 | if (!pref_index) |
| 700 | epp = cpu_data->epp_default; |
| 701 | |
| 702 | mutex_lock(&intel_pstate_limits_lock); |
| 703 | |
| 704 | if (static_cpu_has(X86_FEATURE_HWP_EPP)) { |
| 705 | u64 value; |
| 706 | |
| 707 | ret = rdmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, &value); |
| 708 | if (ret) |
| 709 | goto return_pref; |
| 710 | |
| 711 | value &= ~GENMASK_ULL(31, 24); |
| 712 | |
| 713 | /* |
| 714 | * If epp is not default, convert from index into |
| 715 | * energy_perf_strings to epp value, by shifting 6 |
| 716 | * bits left to use only top two bits in epp. |
| 717 | * The resultant epp need to shifted by 24 bits to |
| 718 | * epp position in MSR_HWP_REQUEST. |
| 719 | */ |
| 720 | if (epp == -EINVAL) |
| 721 | epp = (pref_index - 1) << 6; |
| 722 | |
| 723 | value |= (u64)epp << 24; |
| 724 | ret = wrmsrl_on_cpu(cpu_data->cpu, MSR_HWP_REQUEST, value); |
| 725 | } else { |
| 726 | if (epp == -EINVAL) |
| 727 | epp = (pref_index - 1) << 2; |
| 728 | ret = intel_pstate_set_epb(cpu_data->cpu, epp); |
| 729 | } |
| 730 | return_pref: |
| 731 | mutex_unlock(&intel_pstate_limits_lock); |
| 732 | |
| 733 | return ret; |
| 734 | } |
| 735 | |
| 736 | static ssize_t show_energy_performance_available_preferences( |
| 737 | struct cpufreq_policy *policy, char *buf) |
| 738 | { |
| 739 | int i = 0; |
| 740 | int ret = 0; |
| 741 | |
| 742 | while (energy_perf_strings[i] != NULL) |
| 743 | ret += sprintf(&buf[ret], "%s ", energy_perf_strings[i++]); |
| 744 | |
| 745 | ret += sprintf(&buf[ret], "\n"); |
| 746 | |
| 747 | return ret; |
| 748 | } |
| 749 | |
| 750 | cpufreq_freq_attr_ro(energy_performance_available_preferences); |
| 751 | |
| 752 | static ssize_t store_energy_performance_preference( |
| 753 | struct cpufreq_policy *policy, const char *buf, size_t count) |
| 754 | { |
| 755 | struct cpudata *cpu_data = all_cpu_data[policy->cpu]; |
| 756 | char str_preference[21]; |
| 757 | int ret, i = 0; |
| 758 | |
| 759 | ret = sscanf(buf, "%20s", str_preference); |
| 760 | if (ret != 1) |
| 761 | return -EINVAL; |
| 762 | |
| 763 | while (energy_perf_strings[i] != NULL) { |
| 764 | if (!strcmp(str_preference, energy_perf_strings[i])) { |
| 765 | intel_pstate_set_energy_pref_index(cpu_data, i); |
| 766 | return count; |
| 767 | } |
| 768 | ++i; |
| 769 | } |
| 770 | |
| 771 | return -EINVAL; |
| 772 | } |
| 773 | |
| 774 | static ssize_t show_energy_performance_preference( |
| 775 | struct cpufreq_policy *policy, char *buf) |
| 776 | { |
| 777 | struct cpudata *cpu_data = all_cpu_data[policy->cpu]; |
| 778 | int preference; |
| 779 | |
| 780 | preference = intel_pstate_get_energy_pref_index(cpu_data); |
| 781 | if (preference < 0) |
| 782 | return preference; |
| 783 | |
| 784 | return sprintf(buf, "%s\n", energy_perf_strings[preference]); |
| 785 | } |
| 786 | |
| 787 | cpufreq_freq_attr_rw(energy_performance_preference); |
| 788 | |
| 789 | static struct freq_attr *hwp_cpufreq_attrs[] = { |
| 790 | &energy_performance_preference, |
| 791 | &energy_performance_available_preferences, |
| 792 | NULL, |
| 793 | }; |
| 794 | |
Rafael J. Wysocki | 111b8b3 | 2016-12-30 15:58:21 +0100 | [diff] [blame] | 795 | static void intel_pstate_hwp_set(struct cpufreq_policy *policy) |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 796 | { |
Srinivas Pandruvada | 3f8ed54 | 2017-03-13 18:30:12 -0700 | [diff] [blame] | 797 | int min, hw_min, max, hw_max, cpu; |
Kristen Carlson Accardi | 74da56c | 2015-09-09 11:41:22 -0700 | [diff] [blame] | 798 | u64 value, cap; |
| 799 | |
Rafael J. Wysocki | 111b8b3 | 2016-12-30 15:58:21 +0100 | [diff] [blame] | 800 | for_each_cpu(cpu, policy->cpus) { |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 801 | struct cpudata *cpu_data = all_cpu_data[cpu]; |
| 802 | s16 epp; |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 803 | |
Srinivas Pandruvada | f9f4872 | 2016-10-08 12:42:38 -0700 | [diff] [blame] | 804 | rdmsrl_on_cpu(cpu, MSR_HWP_CAPABILITIES, &cap); |
| 805 | hw_min = HWP_LOWEST_PERF(cap); |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 806 | if (global.no_turbo) |
Srinivas Pandruvada | 4e5d3f7 | 2017-01-18 10:48:24 -0800 | [diff] [blame] | 807 | hw_max = HWP_GUARANTEED_PERF(cap); |
| 808 | else |
| 809 | hw_max = HWP_HIGHEST_PERF(cap); |
Srinivas Pandruvada | f9f4872 | 2016-10-08 12:42:38 -0700 | [diff] [blame] | 810 | |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 811 | max = fp_ext_toint(hw_max * cpu_data->max_perf); |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 812 | if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE) |
| 813 | min = max; |
| 814 | else |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 815 | min = fp_ext_toint(hw_max * cpu_data->min_perf); |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 816 | |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 817 | rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value); |
Srinivas Pandruvada | 3f8ed54 | 2017-03-13 18:30:12 -0700 | [diff] [blame] | 818 | |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 819 | value &= ~HWP_MIN_PERF(~0L); |
| 820 | value |= HWP_MIN_PERF(min); |
| 821 | |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 822 | value &= ~HWP_MAX_PERF(~0L); |
| 823 | value |= HWP_MAX_PERF(max); |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 824 | |
| 825 | if (cpu_data->epp_policy == cpu_data->policy) |
| 826 | goto skip_epp; |
| 827 | |
| 828 | cpu_data->epp_policy = cpu_data->policy; |
| 829 | |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 830 | if (cpu_data->epp_saved >= 0) { |
| 831 | epp = cpu_data->epp_saved; |
| 832 | cpu_data->epp_saved = -EINVAL; |
| 833 | goto update_epp; |
| 834 | } |
| 835 | |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 836 | if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE) { |
| 837 | epp = intel_pstate_get_epp(cpu_data, value); |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 838 | cpu_data->epp_powersave = epp; |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 839 | /* If EPP read was failed, then don't try to write */ |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 840 | if (epp < 0) |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 841 | goto skip_epp; |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 842 | |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 843 | |
| 844 | epp = 0; |
| 845 | } else { |
| 846 | /* skip setting EPP, when saved value is invalid */ |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 847 | if (cpu_data->epp_powersave < 0) |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 848 | goto skip_epp; |
| 849 | |
| 850 | /* |
| 851 | * No need to restore EPP when it is not zero. This |
| 852 | * means: |
| 853 | * - Policy is not changed |
| 854 | * - user has manually changed |
| 855 | * - Error reading EPB |
| 856 | */ |
| 857 | epp = intel_pstate_get_epp(cpu_data, value); |
| 858 | if (epp) |
| 859 | goto skip_epp; |
| 860 | |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 861 | epp = cpu_data->epp_powersave; |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 862 | } |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 863 | update_epp: |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 864 | if (static_cpu_has(X86_FEATURE_HWP_EPP)) { |
| 865 | value &= ~GENMASK_ULL(31, 24); |
| 866 | value |= (u64)epp << 24; |
| 867 | } else { |
| 868 | intel_pstate_set_epb(cpu, epp); |
| 869 | } |
| 870 | skip_epp: |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 871 | wrmsrl_on_cpu(cpu, MSR_HWP_REQUEST, value); |
| 872 | } |
Viresh Kumar | 41cfd64 | 2016-02-22 10:27:46 +0530 | [diff] [blame] | 873 | } |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 874 | |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 875 | static int intel_pstate_hwp_save_state(struct cpufreq_policy *policy) |
| 876 | { |
| 877 | struct cpudata *cpu_data = all_cpu_data[policy->cpu]; |
| 878 | |
| 879 | if (!hwp_active) |
| 880 | return 0; |
| 881 | |
| 882 | cpu_data->epp_saved = intel_pstate_get_epp(cpu_data, 0); |
| 883 | |
| 884 | return 0; |
| 885 | } |
| 886 | |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 887 | static int intel_pstate_resume(struct cpufreq_policy *policy) |
| 888 | { |
| 889 | if (!hwp_active) |
| 890 | return 0; |
| 891 | |
Rafael J. Wysocki | aa43924 | 2016-12-30 15:56:14 +0100 | [diff] [blame] | 892 | mutex_lock(&intel_pstate_limits_lock); |
| 893 | |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 894 | all_cpu_data[policy->cpu]->epp_policy = 0; |
Rafael J. Wysocki | 5f98ced | 2017-03-09 16:30:38 +0100 | [diff] [blame] | 895 | intel_pstate_hwp_set(policy); |
Rafael J. Wysocki | aa43924 | 2016-12-30 15:56:14 +0100 | [diff] [blame] | 896 | |
| 897 | mutex_unlock(&intel_pstate_limits_lock); |
| 898 | |
Rafael J. Wysocki | 5f98ced | 2017-03-09 16:30:38 +0100 | [diff] [blame] | 899 | return 0; |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 900 | } |
| 901 | |
Rafael J. Wysocki | 111b8b3 | 2016-12-30 15:58:21 +0100 | [diff] [blame] | 902 | static void intel_pstate_update_policies(void) |
Viresh Kumar | 41cfd64 | 2016-02-22 10:27:46 +0530 | [diff] [blame] | 903 | { |
Rafael J. Wysocki | 111b8b3 | 2016-12-30 15:58:21 +0100 | [diff] [blame] | 904 | int cpu; |
| 905 | |
| 906 | for_each_possible_cpu(cpu) |
| 907 | cpufreq_update_policy(cpu); |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 908 | } |
| 909 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 910 | /************************** debugfs begin ************************/ |
| 911 | static int pid_param_set(void *data, u64 val) |
| 912 | { |
Rafael J. Wysocki | 4ddd014 | 2017-03-28 00:07:15 +0200 | [diff] [blame] | 913 | unsigned int cpu; |
| 914 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 915 | *(u32 *)data = val; |
Rafael J. Wysocki | 6e7408a | 2017-03-12 18:12:56 +0100 | [diff] [blame] | 916 | pid_params.sample_rate_ns = pid_params.sample_rate_ms * NSEC_PER_MSEC; |
Rafael J. Wysocki | 4ddd014 | 2017-03-28 00:07:15 +0200 | [diff] [blame] | 917 | for_each_possible_cpu(cpu) |
| 918 | if (all_cpu_data[cpu]) |
Rafael J. Wysocki | ff35f02 | 2017-03-28 00:09:18 +0200 | [diff] [blame] | 919 | intel_pstate_pid_reset(all_cpu_data[cpu]); |
Rafael J. Wysocki | 4ddd014 | 2017-03-28 00:07:15 +0200 | [diff] [blame] | 920 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 921 | return 0; |
| 922 | } |
Stratos Karafotis | 845c1cb | 2014-07-18 08:37:19 -0700 | [diff] [blame] | 923 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 924 | static int pid_param_get(void *data, u64 *val) |
| 925 | { |
| 926 | *val = *(u32 *)data; |
| 927 | return 0; |
| 928 | } |
Stratos Karafotis | 2d8d1f1 | 2014-07-18 08:37:20 -0700 | [diff] [blame] | 929 | DEFINE_SIMPLE_ATTRIBUTE(fops_pid_param, pid_param_get, pid_param_set, "%llu\n"); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 930 | |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 931 | static struct dentry *debugfs_parent; |
| 932 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 933 | struct pid_param { |
| 934 | char *name; |
| 935 | void *value; |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 936 | struct dentry *dentry; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 937 | }; |
| 938 | |
| 939 | static struct pid_param pid_files[] = { |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 940 | {"sample_rate_ms", &pid_params.sample_rate_ms, }, |
| 941 | {"d_gain_pct", &pid_params.d_gain_pct, }, |
| 942 | {"i_gain_pct", &pid_params.i_gain_pct, }, |
| 943 | {"deadband", &pid_params.deadband, }, |
| 944 | {"setpoint", &pid_params.setpoint, }, |
| 945 | {"p_gain_pct", &pid_params.p_gain_pct, }, |
| 946 | {NULL, NULL, } |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 947 | }; |
| 948 | |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 949 | static void intel_pstate_debug_expose_params(void) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 950 | { |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 951 | int i; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 952 | |
| 953 | debugfs_parent = debugfs_create_dir("pstate_snb", NULL); |
| 954 | if (IS_ERR_OR_NULL(debugfs_parent)) |
| 955 | return; |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 956 | |
| 957 | for (i = 0; pid_files[i].name; i++) { |
| 958 | struct dentry *dentry; |
| 959 | |
| 960 | dentry = debugfs_create_file(pid_files[i].name, 0660, |
| 961 | debugfs_parent, pid_files[i].value, |
| 962 | &fops_pid_param); |
| 963 | if (!IS_ERR(dentry)) |
| 964 | pid_files[i].dentry = dentry; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 968 | static void intel_pstate_debug_hide_params(void) |
| 969 | { |
| 970 | int i; |
| 971 | |
| 972 | if (IS_ERR_OR_NULL(debugfs_parent)) |
| 973 | return; |
| 974 | |
| 975 | for (i = 0; pid_files[i].name; i++) { |
| 976 | debugfs_remove(pid_files[i].dentry); |
| 977 | pid_files[i].dentry = NULL; |
| 978 | } |
| 979 | |
| 980 | debugfs_remove(debugfs_parent); |
| 981 | debugfs_parent = NULL; |
| 982 | } |
| 983 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 984 | /************************** debugfs end ************************/ |
| 985 | |
| 986 | /************************** sysfs begin ************************/ |
| 987 | #define show_one(file_name, object) \ |
| 988 | static ssize_t show_##file_name \ |
| 989 | (struct kobject *kobj, struct attribute *attr, char *buf) \ |
| 990 | { \ |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 991 | return sprintf(buf, "%u\n", global.object); \ |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 992 | } |
| 993 | |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 994 | static ssize_t intel_pstate_show_status(char *buf); |
| 995 | static int intel_pstate_update_status(const char *buf, size_t size); |
| 996 | |
| 997 | static ssize_t show_status(struct kobject *kobj, |
| 998 | struct attribute *attr, char *buf) |
| 999 | { |
| 1000 | ssize_t ret; |
| 1001 | |
| 1002 | mutex_lock(&intel_pstate_driver_lock); |
| 1003 | ret = intel_pstate_show_status(buf); |
| 1004 | mutex_unlock(&intel_pstate_driver_lock); |
| 1005 | |
| 1006 | return ret; |
| 1007 | } |
| 1008 | |
| 1009 | static ssize_t store_status(struct kobject *a, struct attribute *b, |
| 1010 | const char *buf, size_t count) |
| 1011 | { |
| 1012 | char *p = memchr(buf, '\n', count); |
| 1013 | int ret; |
| 1014 | |
| 1015 | mutex_lock(&intel_pstate_driver_lock); |
| 1016 | ret = intel_pstate_update_status(buf, p ? p - buf : count); |
| 1017 | mutex_unlock(&intel_pstate_driver_lock); |
| 1018 | |
| 1019 | return ret < 0 ? ret : count; |
| 1020 | } |
| 1021 | |
Kristen Carlson Accardi | d01b1f4 | 2015-01-28 15:03:27 -0800 | [diff] [blame] | 1022 | static ssize_t show_turbo_pct(struct kobject *kobj, |
| 1023 | struct attribute *attr, char *buf) |
| 1024 | { |
| 1025 | struct cpudata *cpu; |
| 1026 | int total, no_turbo, turbo_pct; |
| 1027 | uint32_t turbo_fp; |
| 1028 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1029 | mutex_lock(&intel_pstate_driver_lock); |
| 1030 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 1031 | if (!intel_pstate_driver) { |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1032 | mutex_unlock(&intel_pstate_driver_lock); |
| 1033 | return -EAGAIN; |
| 1034 | } |
| 1035 | |
Kristen Carlson Accardi | d01b1f4 | 2015-01-28 15:03:27 -0800 | [diff] [blame] | 1036 | cpu = all_cpu_data[0]; |
| 1037 | |
| 1038 | total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1; |
| 1039 | no_turbo = cpu->pstate.max_pstate - cpu->pstate.min_pstate + 1; |
Rafael J. Wysocki | 22590ef | 2016-04-09 01:25:58 +0200 | [diff] [blame] | 1040 | turbo_fp = div_fp(no_turbo, total); |
Kristen Carlson Accardi | d01b1f4 | 2015-01-28 15:03:27 -0800 | [diff] [blame] | 1041 | turbo_pct = 100 - fp_toint(mul_fp(turbo_fp, int_tofp(100))); |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1042 | |
| 1043 | mutex_unlock(&intel_pstate_driver_lock); |
| 1044 | |
Kristen Carlson Accardi | d01b1f4 | 2015-01-28 15:03:27 -0800 | [diff] [blame] | 1045 | return sprintf(buf, "%u\n", turbo_pct); |
| 1046 | } |
| 1047 | |
Kristen Carlson Accardi | 0522424 | 2015-01-28 15:03:28 -0800 | [diff] [blame] | 1048 | static ssize_t show_num_pstates(struct kobject *kobj, |
| 1049 | struct attribute *attr, char *buf) |
| 1050 | { |
| 1051 | struct cpudata *cpu; |
| 1052 | int total; |
| 1053 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1054 | mutex_lock(&intel_pstate_driver_lock); |
| 1055 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 1056 | if (!intel_pstate_driver) { |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1057 | mutex_unlock(&intel_pstate_driver_lock); |
| 1058 | return -EAGAIN; |
| 1059 | } |
| 1060 | |
Kristen Carlson Accardi | 0522424 | 2015-01-28 15:03:28 -0800 | [diff] [blame] | 1061 | cpu = all_cpu_data[0]; |
| 1062 | total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1; |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1063 | |
| 1064 | mutex_unlock(&intel_pstate_driver_lock); |
| 1065 | |
Kristen Carlson Accardi | 0522424 | 2015-01-28 15:03:28 -0800 | [diff] [blame] | 1066 | return sprintf(buf, "%u\n", total); |
| 1067 | } |
| 1068 | |
Gabriele Mazzotta | 4521e1a0 | 2014-10-13 08:37:41 -0700 | [diff] [blame] | 1069 | static ssize_t show_no_turbo(struct kobject *kobj, |
| 1070 | struct attribute *attr, char *buf) |
| 1071 | { |
| 1072 | ssize_t ret; |
| 1073 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1074 | mutex_lock(&intel_pstate_driver_lock); |
| 1075 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 1076 | if (!intel_pstate_driver) { |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1077 | mutex_unlock(&intel_pstate_driver_lock); |
| 1078 | return -EAGAIN; |
| 1079 | } |
| 1080 | |
Gabriele Mazzotta | 4521e1a0 | 2014-10-13 08:37:41 -0700 | [diff] [blame] | 1081 | update_turbo_state(); |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 1082 | if (global.turbo_disabled) |
| 1083 | ret = sprintf(buf, "%u\n", global.turbo_disabled); |
Gabriele Mazzotta | 4521e1a0 | 2014-10-13 08:37:41 -0700 | [diff] [blame] | 1084 | else |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 1085 | ret = sprintf(buf, "%u\n", global.no_turbo); |
Gabriele Mazzotta | 4521e1a0 | 2014-10-13 08:37:41 -0700 | [diff] [blame] | 1086 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1087 | mutex_unlock(&intel_pstate_driver_lock); |
| 1088 | |
Gabriele Mazzotta | 4521e1a0 | 2014-10-13 08:37:41 -0700 | [diff] [blame] | 1089 | return ret; |
| 1090 | } |
| 1091 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1092 | static ssize_t store_no_turbo(struct kobject *a, struct attribute *b, |
Stratos Karafotis | c410833 | 2014-07-18 08:37:23 -0700 | [diff] [blame] | 1093 | const char *buf, size_t count) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1094 | { |
| 1095 | unsigned int input; |
| 1096 | int ret; |
Stratos Karafotis | 845c1cb | 2014-07-18 08:37:19 -0700 | [diff] [blame] | 1097 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1098 | ret = sscanf(buf, "%u", &input); |
| 1099 | if (ret != 1) |
| 1100 | return -EINVAL; |
Gabriele Mazzotta | 4521e1a0 | 2014-10-13 08:37:41 -0700 | [diff] [blame] | 1101 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1102 | mutex_lock(&intel_pstate_driver_lock); |
| 1103 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 1104 | if (!intel_pstate_driver) { |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1105 | mutex_unlock(&intel_pstate_driver_lock); |
| 1106 | return -EAGAIN; |
| 1107 | } |
| 1108 | |
Srinivas Pandruvada | a410c03 | 2016-10-28 10:44:52 -0700 | [diff] [blame] | 1109 | mutex_lock(&intel_pstate_limits_lock); |
| 1110 | |
Gabriele Mazzotta | 4521e1a0 | 2014-10-13 08:37:41 -0700 | [diff] [blame] | 1111 | update_turbo_state(); |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 1112 | if (global.turbo_disabled) { |
Joe Perches | 4836df1 | 2016-04-05 13:28:23 -0700 | [diff] [blame] | 1113 | pr_warn("Turbo disabled by BIOS or unavailable on processor\n"); |
Srinivas Pandruvada | a410c03 | 2016-10-28 10:44:52 -0700 | [diff] [blame] | 1114 | mutex_unlock(&intel_pstate_limits_lock); |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1115 | mutex_unlock(&intel_pstate_driver_lock); |
Gabriele Mazzotta | 4521e1a0 | 2014-10-13 08:37:41 -0700 | [diff] [blame] | 1116 | return -EPERM; |
Dirk Brandewie | dd5fbf7 | 2014-06-20 07:27:59 -0700 | [diff] [blame] | 1117 | } |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 1118 | |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 1119 | global.no_turbo = clamp_t(int, input, 0, 1); |
Rafael J. Wysocki | 111b8b3 | 2016-12-30 15:58:21 +0100 | [diff] [blame] | 1120 | |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 1121 | if (global.no_turbo) { |
| 1122 | struct cpudata *cpu = all_cpu_data[0]; |
| 1123 | int pct = cpu->pstate.max_pstate * 100 / cpu->pstate.turbo_pstate; |
| 1124 | |
| 1125 | /* Squash the global minimum into the permitted range. */ |
| 1126 | if (global.min_perf_pct > pct) |
| 1127 | global.min_perf_pct = pct; |
| 1128 | } |
| 1129 | |
Rafael J. Wysocki | cd59b4be | 2017-03-01 00:07:36 +0100 | [diff] [blame] | 1130 | mutex_unlock(&intel_pstate_limits_lock); |
| 1131 | |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 1132 | intel_pstate_update_policies(); |
| 1133 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1134 | mutex_unlock(&intel_pstate_driver_lock); |
| 1135 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1136 | return count; |
| 1137 | } |
| 1138 | |
| 1139 | static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b, |
Stratos Karafotis | c410833 | 2014-07-18 08:37:23 -0700 | [diff] [blame] | 1140 | const char *buf, size_t count) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1141 | { |
| 1142 | unsigned int input; |
| 1143 | int ret; |
Stratos Karafotis | 845c1cb | 2014-07-18 08:37:19 -0700 | [diff] [blame] | 1144 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1145 | ret = sscanf(buf, "%u", &input); |
| 1146 | if (ret != 1) |
| 1147 | return -EINVAL; |
| 1148 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1149 | mutex_lock(&intel_pstate_driver_lock); |
| 1150 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 1151 | if (!intel_pstate_driver) { |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1152 | mutex_unlock(&intel_pstate_driver_lock); |
| 1153 | return -EAGAIN; |
| 1154 | } |
| 1155 | |
Srinivas Pandruvada | a410c03 | 2016-10-28 10:44:52 -0700 | [diff] [blame] | 1156 | mutex_lock(&intel_pstate_limits_lock); |
| 1157 | |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 1158 | global.max_perf_pct = clamp_t(int, input, global.min_perf_pct, 100); |
Rafael J. Wysocki | 111b8b3 | 2016-12-30 15:58:21 +0100 | [diff] [blame] | 1159 | |
Rafael J. Wysocki | cd59b4be | 2017-03-01 00:07:36 +0100 | [diff] [blame] | 1160 | mutex_unlock(&intel_pstate_limits_lock); |
| 1161 | |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 1162 | intel_pstate_update_policies(); |
| 1163 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1164 | mutex_unlock(&intel_pstate_driver_lock); |
| 1165 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1166 | return count; |
| 1167 | } |
| 1168 | |
| 1169 | static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b, |
Stratos Karafotis | c410833 | 2014-07-18 08:37:23 -0700 | [diff] [blame] | 1170 | const char *buf, size_t count) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1171 | { |
| 1172 | unsigned int input; |
| 1173 | int ret; |
Stratos Karafotis | 845c1cb | 2014-07-18 08:37:19 -0700 | [diff] [blame] | 1174 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1175 | ret = sscanf(buf, "%u", &input); |
| 1176 | if (ret != 1) |
| 1177 | return -EINVAL; |
Kristen Carlson Accardi | a047599 | 2015-01-29 13:03:52 -0800 | [diff] [blame] | 1178 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1179 | mutex_lock(&intel_pstate_driver_lock); |
| 1180 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 1181 | if (!intel_pstate_driver) { |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1182 | mutex_unlock(&intel_pstate_driver_lock); |
| 1183 | return -EAGAIN; |
| 1184 | } |
| 1185 | |
Srinivas Pandruvada | a410c03 | 2016-10-28 10:44:52 -0700 | [diff] [blame] | 1186 | mutex_lock(&intel_pstate_limits_lock); |
| 1187 | |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 1188 | global.min_perf_pct = clamp_t(int, input, |
| 1189 | min_perf_pct_min(), global.max_perf_pct); |
Rafael J. Wysocki | 111b8b3 | 2016-12-30 15:58:21 +0100 | [diff] [blame] | 1190 | |
Rafael J. Wysocki | cd59b4be | 2017-03-01 00:07:36 +0100 | [diff] [blame] | 1191 | mutex_unlock(&intel_pstate_limits_lock); |
| 1192 | |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 1193 | intel_pstate_update_policies(); |
| 1194 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 1195 | mutex_unlock(&intel_pstate_driver_lock); |
| 1196 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1197 | return count; |
| 1198 | } |
| 1199 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1200 | show_one(max_perf_pct, max_perf_pct); |
| 1201 | show_one(min_perf_pct, min_perf_pct); |
| 1202 | |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 1203 | define_one_global_rw(status); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1204 | define_one_global_rw(no_turbo); |
| 1205 | define_one_global_rw(max_perf_pct); |
| 1206 | define_one_global_rw(min_perf_pct); |
Kristen Carlson Accardi | d01b1f4 | 2015-01-28 15:03:27 -0800 | [diff] [blame] | 1207 | define_one_global_ro(turbo_pct); |
Kristen Carlson Accardi | 0522424 | 2015-01-28 15:03:28 -0800 | [diff] [blame] | 1208 | define_one_global_ro(num_pstates); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1209 | |
| 1210 | static struct attribute *intel_pstate_attributes[] = { |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 1211 | &status.attr, |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1212 | &no_turbo.attr, |
Kristen Carlson Accardi | d01b1f4 | 2015-01-28 15:03:27 -0800 | [diff] [blame] | 1213 | &turbo_pct.attr, |
Kristen Carlson Accardi | 0522424 | 2015-01-28 15:03:28 -0800 | [diff] [blame] | 1214 | &num_pstates.attr, |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1215 | NULL |
| 1216 | }; |
| 1217 | |
| 1218 | static struct attribute_group intel_pstate_attr_group = { |
| 1219 | .attrs = intel_pstate_attributes, |
| 1220 | }; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1221 | |
Stratos Karafotis | 317dd50 | 2014-07-18 08:37:17 -0700 | [diff] [blame] | 1222 | static void __init intel_pstate_sysfs_expose_params(void) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1223 | { |
Stratos Karafotis | 317dd50 | 2014-07-18 08:37:17 -0700 | [diff] [blame] | 1224 | struct kobject *intel_pstate_kobject; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1225 | int rc; |
| 1226 | |
| 1227 | intel_pstate_kobject = kobject_create_and_add("intel_pstate", |
| 1228 | &cpu_subsys.dev_root->kobj); |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 1229 | if (WARN_ON(!intel_pstate_kobject)) |
| 1230 | return; |
| 1231 | |
Stratos Karafotis | 2d8d1f1 | 2014-07-18 08:37:20 -0700 | [diff] [blame] | 1232 | rc = sysfs_create_group(intel_pstate_kobject, &intel_pstate_attr_group); |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 1233 | if (WARN_ON(rc)) |
| 1234 | return; |
| 1235 | |
| 1236 | /* |
| 1237 | * If per cpu limits are enforced there are no global limits, so |
| 1238 | * return without creating max/min_perf_pct attributes |
| 1239 | */ |
| 1240 | if (per_cpu_limits) |
| 1241 | return; |
| 1242 | |
| 1243 | rc = sysfs_create_file(intel_pstate_kobject, &max_perf_pct.attr); |
| 1244 | WARN_ON(rc); |
| 1245 | |
| 1246 | rc = sysfs_create_file(intel_pstate_kobject, &min_perf_pct.attr); |
| 1247 | WARN_ON(rc); |
| 1248 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1249 | } |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1250 | /************************** sysfs end ************************/ |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 1251 | |
Kristen Carlson Accardi | ba88d43 | 2015-07-14 09:46:23 -0700 | [diff] [blame] | 1252 | static void intel_pstate_hwp_enable(struct cpudata *cpudata) |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 1253 | { |
Srinivas Pandruvada | f05c966 | 2016-02-25 15:09:31 -0800 | [diff] [blame] | 1254 | /* First disable HWP notification interrupt as we don't process them */ |
Srinivas Pandruvada | da7de91 | 2016-07-19 16:52:01 -0700 | [diff] [blame] | 1255 | if (static_cpu_has(X86_FEATURE_HWP_NOTIFY)) |
| 1256 | wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x00); |
Srinivas Pandruvada | f05c966 | 2016-02-25 15:09:31 -0800 | [diff] [blame] | 1257 | |
Kristen Carlson Accardi | ba88d43 | 2015-07-14 09:46:23 -0700 | [diff] [blame] | 1258 | wrmsrl_on_cpu(cpudata->cpu, MSR_PM_ENABLE, 0x1); |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 1259 | cpudata->epp_policy = 0; |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 1260 | if (cpudata->epp_default == -EINVAL) |
| 1261 | cpudata->epp_default = intel_pstate_get_epp(cpudata, 0); |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 1262 | } |
| 1263 | |
Srinivas Pandruvada | 6e978b2 | 2017-02-03 14:18:39 -0800 | [diff] [blame] | 1264 | #define MSR_IA32_POWER_CTL_BIT_EE 19 |
| 1265 | |
| 1266 | /* Disable energy efficiency optimization */ |
| 1267 | static void intel_pstate_disable_ee(int cpu) |
| 1268 | { |
| 1269 | u64 power_ctl; |
| 1270 | int ret; |
| 1271 | |
| 1272 | ret = rdmsrl_on_cpu(cpu, MSR_IA32_POWER_CTL, &power_ctl); |
| 1273 | if (ret) |
| 1274 | return; |
| 1275 | |
| 1276 | if (!(power_ctl & BIT(MSR_IA32_POWER_CTL_BIT_EE))) { |
| 1277 | pr_info("Disabling energy efficiency optimization\n"); |
| 1278 | power_ctl |= BIT(MSR_IA32_POWER_CTL_BIT_EE); |
| 1279 | wrmsrl_on_cpu(cpu, MSR_IA32_POWER_CTL, power_ctl); |
| 1280 | } |
| 1281 | } |
| 1282 | |
Philippe Longepe | 938d21a | 2015-11-09 17:40:46 -0800 | [diff] [blame] | 1283 | static int atom_get_min_pstate(void) |
Dirk Brandewie | 19e77c2 | 2013-10-21 09:20:35 -0700 | [diff] [blame] | 1284 | { |
| 1285 | u64 value; |
Stratos Karafotis | 845c1cb | 2014-07-18 08:37:19 -0700 | [diff] [blame] | 1286 | |
Len Brown | 92134bd | 2017-02-25 16:55:17 -0500 | [diff] [blame] | 1287 | rdmsrl(MSR_ATOM_CORE_RATIOS, value); |
Dirk Brandewie | c16ed06 | 2014-06-20 07:27:58 -0700 | [diff] [blame] | 1288 | return (value >> 8) & 0x7F; |
Dirk Brandewie | 19e77c2 | 2013-10-21 09:20:35 -0700 | [diff] [blame] | 1289 | } |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1290 | |
Philippe Longepe | 938d21a | 2015-11-09 17:40:46 -0800 | [diff] [blame] | 1291 | static int atom_get_max_pstate(void) |
Dirk Brandewie | 19e77c2 | 2013-10-21 09:20:35 -0700 | [diff] [blame] | 1292 | { |
| 1293 | u64 value; |
Stratos Karafotis | 845c1cb | 2014-07-18 08:37:19 -0700 | [diff] [blame] | 1294 | |
Len Brown | 92134bd | 2017-02-25 16:55:17 -0500 | [diff] [blame] | 1295 | rdmsrl(MSR_ATOM_CORE_RATIOS, value); |
Dirk Brandewie | c16ed06 | 2014-06-20 07:27:58 -0700 | [diff] [blame] | 1296 | return (value >> 16) & 0x7F; |
Dirk Brandewie | 19e77c2 | 2013-10-21 09:20:35 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
Philippe Longepe | 938d21a | 2015-11-09 17:40:46 -0800 | [diff] [blame] | 1299 | static int atom_get_turbo_pstate(void) |
Dirk Brandewie | 61d8d2a | 2014-02-12 10:01:07 -0800 | [diff] [blame] | 1300 | { |
| 1301 | u64 value; |
Stratos Karafotis | 845c1cb | 2014-07-18 08:37:19 -0700 | [diff] [blame] | 1302 | |
Len Brown | 92134bd | 2017-02-25 16:55:17 -0500 | [diff] [blame] | 1303 | rdmsrl(MSR_ATOM_CORE_TURBO_RATIOS, value); |
Dirk Brandewie | c16ed06 | 2014-06-20 07:27:58 -0700 | [diff] [blame] | 1304 | return value & 0x7F; |
Dirk Brandewie | 61d8d2a | 2014-02-12 10:01:07 -0800 | [diff] [blame] | 1305 | } |
| 1306 | |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1307 | static u64 atom_get_val(struct cpudata *cpudata, int pstate) |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 1308 | { |
| 1309 | u64 val; |
| 1310 | int32_t vid_fp; |
| 1311 | u32 vid; |
| 1312 | |
Chen Yu | 144c8e1 | 2015-07-29 23:53:10 +0800 | [diff] [blame] | 1313 | val = (u64)pstate << 8; |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 1314 | if (global.no_turbo && !global.turbo_disabled) |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 1315 | val |= (u64)1 << 32; |
| 1316 | |
| 1317 | vid_fp = cpudata->vid.min + mul_fp( |
| 1318 | int_tofp(pstate - cpudata->pstate.min_pstate), |
| 1319 | cpudata->vid.ratio); |
| 1320 | |
| 1321 | vid_fp = clamp_t(int32_t, vid_fp, cpudata->vid.min, cpudata->vid.max); |
Dirk Brandewie | d022a65 | 2014-10-13 08:37:44 -0700 | [diff] [blame] | 1322 | vid = ceiling_fp(vid_fp); |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 1323 | |
Dirk Brandewie | 21855ff | 2014-05-08 12:57:23 -0700 | [diff] [blame] | 1324 | if (pstate > cpudata->pstate.max_pstate) |
| 1325 | vid = cpudata->vid.turbo; |
| 1326 | |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1327 | return val | vid; |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 1328 | } |
| 1329 | |
Philippe Longepe | 1421df6 | 2015-11-09 17:40:47 -0800 | [diff] [blame] | 1330 | static int silvermont_get_scaling(void) |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 1331 | { |
| 1332 | u64 value; |
| 1333 | int i; |
Philippe Longepe | 1421df6 | 2015-11-09 17:40:47 -0800 | [diff] [blame] | 1334 | /* Defined in Table 35-6 from SDM (Sept 2015) */ |
| 1335 | static int silvermont_freq_table[] = { |
| 1336 | 83300, 100000, 133300, 116700, 80000}; |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 1337 | |
| 1338 | rdmsrl(MSR_FSB_FREQ, value); |
Philippe Longepe | 1421df6 | 2015-11-09 17:40:47 -0800 | [diff] [blame] | 1339 | i = value & 0x7; |
| 1340 | WARN_ON(i > 4); |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 1341 | |
Philippe Longepe | 1421df6 | 2015-11-09 17:40:47 -0800 | [diff] [blame] | 1342 | return silvermont_freq_table[i]; |
| 1343 | } |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 1344 | |
Philippe Longepe | 1421df6 | 2015-11-09 17:40:47 -0800 | [diff] [blame] | 1345 | static int airmont_get_scaling(void) |
| 1346 | { |
| 1347 | u64 value; |
| 1348 | int i; |
| 1349 | /* Defined in Table 35-10 from SDM (Sept 2015) */ |
| 1350 | static int airmont_freq_table[] = { |
| 1351 | 83300, 100000, 133300, 116700, 80000, |
| 1352 | 93300, 90000, 88900, 87500}; |
| 1353 | |
| 1354 | rdmsrl(MSR_FSB_FREQ, value); |
| 1355 | i = value & 0xF; |
| 1356 | WARN_ON(i > 8); |
| 1357 | |
| 1358 | return airmont_freq_table[i]; |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
Philippe Longepe | 938d21a | 2015-11-09 17:40:46 -0800 | [diff] [blame] | 1361 | static void atom_get_vid(struct cpudata *cpudata) |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 1362 | { |
| 1363 | u64 value; |
| 1364 | |
Len Brown | 92134bd | 2017-02-25 16:55:17 -0500 | [diff] [blame] | 1365 | rdmsrl(MSR_ATOM_CORE_VIDS, value); |
Dirk Brandewie | c16ed06 | 2014-06-20 07:27:58 -0700 | [diff] [blame] | 1366 | cpudata->vid.min = int_tofp((value >> 8) & 0x7f); |
| 1367 | cpudata->vid.max = int_tofp((value >> 16) & 0x7f); |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 1368 | cpudata->vid.ratio = div_fp( |
| 1369 | cpudata->vid.max - cpudata->vid.min, |
| 1370 | int_tofp(cpudata->pstate.max_pstate - |
| 1371 | cpudata->pstate.min_pstate)); |
Dirk Brandewie | 21855ff | 2014-05-08 12:57:23 -0700 | [diff] [blame] | 1372 | |
Len Brown | 92134bd | 2017-02-25 16:55:17 -0500 | [diff] [blame] | 1373 | rdmsrl(MSR_ATOM_CORE_TURBO_VIDS, value); |
Dirk Brandewie | 21855ff | 2014-05-08 12:57:23 -0700 | [diff] [blame] | 1374 | cpudata->vid.turbo = value & 0x7f; |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 1375 | } |
| 1376 | |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 1377 | static int core_get_min_pstate(void) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1378 | { |
| 1379 | u64 value; |
Stratos Karafotis | 845c1cb | 2014-07-18 08:37:19 -0700 | [diff] [blame] | 1380 | |
Konrad Rzeszutek Wilk | 05e99c8cf | 2013-03-20 14:21:10 +0000 | [diff] [blame] | 1381 | rdmsrl(MSR_PLATFORM_INFO, value); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1382 | return (value >> 40) & 0xFF; |
| 1383 | } |
| 1384 | |
Srinivas Pandruvada | 3bcc6fa | 2015-10-14 16:12:00 -0700 | [diff] [blame] | 1385 | static int core_get_max_pstate_physical(void) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1386 | { |
| 1387 | u64 value; |
Stratos Karafotis | 845c1cb | 2014-07-18 08:37:19 -0700 | [diff] [blame] | 1388 | |
Konrad Rzeszutek Wilk | 05e99c8cf | 2013-03-20 14:21:10 +0000 | [diff] [blame] | 1389 | rdmsrl(MSR_PLATFORM_INFO, value); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1390 | return (value >> 8) & 0xFF; |
| 1391 | } |
| 1392 | |
Srinivas Pandruvada | 8fc7554 | 2017-01-19 15:03:14 -0800 | [diff] [blame] | 1393 | static int core_get_tdp_ratio(u64 plat_info) |
| 1394 | { |
| 1395 | /* Check how many TDP levels present */ |
| 1396 | if (plat_info & 0x600000000) { |
| 1397 | u64 tdp_ctrl; |
| 1398 | u64 tdp_ratio; |
| 1399 | int tdp_msr; |
| 1400 | int err; |
| 1401 | |
| 1402 | /* Get the TDP level (0, 1, 2) to get ratios */ |
| 1403 | err = rdmsrl_safe(MSR_CONFIG_TDP_CONTROL, &tdp_ctrl); |
| 1404 | if (err) |
| 1405 | return err; |
| 1406 | |
| 1407 | /* TDP MSR are continuous starting at 0x648 */ |
| 1408 | tdp_msr = MSR_CONFIG_TDP_NOMINAL + (tdp_ctrl & 0x03); |
| 1409 | err = rdmsrl_safe(tdp_msr, &tdp_ratio); |
| 1410 | if (err) |
| 1411 | return err; |
| 1412 | |
| 1413 | /* For level 1 and 2, bits[23:16] contain the ratio */ |
| 1414 | if (tdp_ctrl & 0x03) |
| 1415 | tdp_ratio >>= 16; |
| 1416 | |
| 1417 | tdp_ratio &= 0xff; /* ratios are only 8 bits long */ |
| 1418 | pr_debug("tdp_ratio %x\n", (int)tdp_ratio); |
| 1419 | |
| 1420 | return (int)tdp_ratio; |
| 1421 | } |
| 1422 | |
| 1423 | return -ENXIO; |
| 1424 | } |
| 1425 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1426 | static int core_get_max_pstate(void) |
| 1427 | { |
Srinivas Pandruvada | 6a35fc2 | 2015-10-14 16:11:59 -0700 | [diff] [blame] | 1428 | u64 tar; |
| 1429 | u64 plat_info; |
| 1430 | int max_pstate; |
Srinivas Pandruvada | 8fc7554 | 2017-01-19 15:03:14 -0800 | [diff] [blame] | 1431 | int tdp_ratio; |
Srinivas Pandruvada | 6a35fc2 | 2015-10-14 16:11:59 -0700 | [diff] [blame] | 1432 | int err; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1433 | |
Srinivas Pandruvada | 6a35fc2 | 2015-10-14 16:11:59 -0700 | [diff] [blame] | 1434 | rdmsrl(MSR_PLATFORM_INFO, plat_info); |
| 1435 | max_pstate = (plat_info >> 8) & 0xFF; |
| 1436 | |
Srinivas Pandruvada | 8fc7554 | 2017-01-19 15:03:14 -0800 | [diff] [blame] | 1437 | tdp_ratio = core_get_tdp_ratio(plat_info); |
| 1438 | if (tdp_ratio <= 0) |
| 1439 | return max_pstate; |
| 1440 | |
| 1441 | if (hwp_active) { |
| 1442 | /* Turbo activation ratio is not used on HWP platforms */ |
| 1443 | return tdp_ratio; |
| 1444 | } |
| 1445 | |
Srinivas Pandruvada | 6a35fc2 | 2015-10-14 16:11:59 -0700 | [diff] [blame] | 1446 | err = rdmsrl_safe(MSR_TURBO_ACTIVATION_RATIO, &tar); |
| 1447 | if (!err) { |
Srinivas Pandruvada | 8fc7554 | 2017-01-19 15:03:14 -0800 | [diff] [blame] | 1448 | int tar_levels; |
| 1449 | |
Srinivas Pandruvada | 6a35fc2 | 2015-10-14 16:11:59 -0700 | [diff] [blame] | 1450 | /* Do some sanity checking for safety */ |
Srinivas Pandruvada | 8fc7554 | 2017-01-19 15:03:14 -0800 | [diff] [blame] | 1451 | tar_levels = tar & 0xff; |
| 1452 | if (tdp_ratio - 1 == tar_levels) { |
| 1453 | max_pstate = tar_levels; |
| 1454 | pr_debug("max_pstate=TAC %x\n", max_pstate); |
Srinivas Pandruvada | 6a35fc2 | 2015-10-14 16:11:59 -0700 | [diff] [blame] | 1455 | } |
| 1456 | } |
| 1457 | |
Srinivas Pandruvada | 6a35fc2 | 2015-10-14 16:11:59 -0700 | [diff] [blame] | 1458 | return max_pstate; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1459 | } |
| 1460 | |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 1461 | static int core_get_turbo_pstate(void) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1462 | { |
| 1463 | u64 value; |
| 1464 | int nont, ret; |
Stratos Karafotis | 845c1cb | 2014-07-18 08:37:19 -0700 | [diff] [blame] | 1465 | |
Srinivas Pandruvada | 100cf6f | 2016-07-06 16:07:55 -0700 | [diff] [blame] | 1466 | rdmsrl(MSR_TURBO_RATIO_LIMIT, value); |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 1467 | nont = core_get_max_pstate(); |
Stratos Karafotis | 285cb99 | 2014-07-18 08:37:21 -0700 | [diff] [blame] | 1468 | ret = (value) & 255; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1469 | if (ret <= nont) |
| 1470 | ret = nont; |
| 1471 | return ret; |
| 1472 | } |
| 1473 | |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 1474 | static inline int core_get_scaling(void) |
| 1475 | { |
| 1476 | return 100000; |
| 1477 | } |
| 1478 | |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1479 | static u64 core_get_val(struct cpudata *cpudata, int pstate) |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 1480 | { |
| 1481 | u64 val; |
| 1482 | |
Chen Yu | 144c8e1 | 2015-07-29 23:53:10 +0800 | [diff] [blame] | 1483 | val = (u64)pstate << 8; |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 1484 | if (global.no_turbo && !global.turbo_disabled) |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 1485 | val |= (u64)1 << 32; |
| 1486 | |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1487 | return val; |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Dasaratharaman Chandramouli | b34ef93 | 2015-04-10 10:22:18 -0700 | [diff] [blame] | 1490 | static int knl_get_turbo_pstate(void) |
| 1491 | { |
| 1492 | u64 value; |
| 1493 | int nont, ret; |
| 1494 | |
Srinivas Pandruvada | 100cf6f | 2016-07-06 16:07:55 -0700 | [diff] [blame] | 1495 | rdmsrl(MSR_TURBO_RATIO_LIMIT, value); |
Dasaratharaman Chandramouli | b34ef93 | 2015-04-10 10:22:18 -0700 | [diff] [blame] | 1496 | nont = core_get_max_pstate(); |
| 1497 | ret = (((value) >> 8) & 0xFF); |
| 1498 | if (ret <= nont) |
| 1499 | ret = nont; |
| 1500 | return ret; |
| 1501 | } |
| 1502 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1503 | static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max) |
| 1504 | { |
| 1505 | int max_perf = cpu->pstate.turbo_pstate; |
Dirk Brandewie | 7244cb6 | 2013-10-21 09:20:33 -0700 | [diff] [blame] | 1506 | int max_perf_adj; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1507 | int min_perf; |
Stratos Karafotis | 845c1cb | 2014-07-18 08:37:19 -0700 | [diff] [blame] | 1508 | |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 1509 | if (global.no_turbo || global.turbo_disabled) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1510 | max_perf = cpu->pstate.max_pstate; |
| 1511 | |
Kristen Carlson Accardi | e0d4c8f | 2014-12-10 12:39:38 -0800 | [diff] [blame] | 1512 | /* |
| 1513 | * performance can be limited by user through sysfs, by cpufreq |
| 1514 | * policy, or by cpu specific default values determined through |
| 1515 | * experimentation. |
| 1516 | */ |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 1517 | max_perf_adj = fp_ext_toint(max_perf * cpu->max_perf); |
Rafael J. Wysocki | 799281a | 2015-11-18 23:29:56 +0100 | [diff] [blame] | 1518 | *max = clamp_t(int, max_perf_adj, |
| 1519 | cpu->pstate.min_pstate, cpu->pstate.turbo_pstate); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1520 | |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 1521 | min_perf = fp_ext_toint(max_perf * cpu->min_perf); |
Rafael J. Wysocki | 799281a | 2015-11-18 23:29:56 +0100 | [diff] [blame] | 1522 | *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1523 | } |
| 1524 | |
Rafael J. Wysocki | a6c6ead | 2016-10-19 02:57:22 +0200 | [diff] [blame] | 1525 | static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate) |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1526 | { |
Rafael J. Wysocki | bc95a45 | 2016-07-19 15:10:37 +0200 | [diff] [blame] | 1527 | trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu); |
| 1528 | cpu->pstate.current_pstate = pstate; |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1529 | /* |
| 1530 | * Generally, there is no guarantee that this code will always run on |
| 1531 | * the CPU being updated, so force the register update to run on the |
| 1532 | * right CPU. |
| 1533 | */ |
| 1534 | wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL, |
| 1535 | pstate_funcs.get_val(cpu, pstate)); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1536 | } |
| 1537 | |
Rafael J. Wysocki | a6c6ead | 2016-10-19 02:57:22 +0200 | [diff] [blame] | 1538 | static void intel_pstate_set_min_pstate(struct cpudata *cpu) |
| 1539 | { |
| 1540 | intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); |
| 1541 | } |
| 1542 | |
| 1543 | static void intel_pstate_max_within_limits(struct cpudata *cpu) |
| 1544 | { |
| 1545 | int min_pstate, max_pstate; |
| 1546 | |
| 1547 | update_turbo_state(); |
| 1548 | intel_pstate_get_min_max(cpu, &min_pstate, &max_pstate); |
| 1549 | intel_pstate_set_pstate(cpu, max_pstate); |
| 1550 | } |
| 1551 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1552 | static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) |
| 1553 | { |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 1554 | cpu->pstate.min_pstate = pstate_funcs.get_min(); |
| 1555 | cpu->pstate.max_pstate = pstate_funcs.get_max(); |
Srinivas Pandruvada | 3bcc6fa | 2015-10-14 16:12:00 -0700 | [diff] [blame] | 1556 | cpu->pstate.max_pstate_physical = pstate_funcs.get_max_physical(); |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 1557 | cpu->pstate.turbo_pstate = pstate_funcs.get_turbo(); |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 1558 | cpu->pstate.scaling = pstate_funcs.get_scaling(); |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 1559 | cpu->pstate.max_freq = cpu->pstate.max_pstate * cpu->pstate.scaling; |
| 1560 | cpu->pstate.turbo_freq = cpu->pstate.turbo_pstate * cpu->pstate.scaling; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1561 | |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 1562 | if (pstate_funcs.get_vid) |
| 1563 | pstate_funcs.get_vid(cpu); |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1564 | |
| 1565 | intel_pstate_set_min_pstate(cpu); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1566 | } |
| 1567 | |
Rafael J. Wysocki | a1c9787 | 2016-05-11 19:09:12 +0200 | [diff] [blame] | 1568 | static inline void intel_pstate_calc_avg_perf(struct cpudata *cpu) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1569 | { |
Stratos Karafotis | 6b17ddb | 2014-04-29 20:53:49 +0300 | [diff] [blame] | 1570 | struct sample *sample = &cpu->sample; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1571 | |
Rafael J. Wysocki | a1c9787 | 2016-05-11 19:09:12 +0200 | [diff] [blame] | 1572 | sample->core_avg_perf = div_ext_fp(sample->aperf, sample->mperf); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1573 | } |
| 1574 | |
Rafael J. Wysocki | 4fec7ad | 2016-03-10 23:45:19 +0100 | [diff] [blame] | 1575 | static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1576 | { |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1577 | u64 aperf, mperf; |
Stratos Karafotis | 4ab60c3 | 2014-07-18 08:37:24 -0700 | [diff] [blame] | 1578 | unsigned long flags; |
Doug Smythies | 4055fad | 2015-04-11 21:10:26 -0700 | [diff] [blame] | 1579 | u64 tsc; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1580 | |
Stratos Karafotis | 4ab60c3 | 2014-07-18 08:37:24 -0700 | [diff] [blame] | 1581 | local_irq_save(flags); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1582 | rdmsrl(MSR_IA32_APERF, aperf); |
| 1583 | rdmsrl(MSR_IA32_MPERF, mperf); |
Philippe Longepe | e70eed2 | 2015-12-04 17:40:32 +0100 | [diff] [blame] | 1584 | tsc = rdtsc(); |
Rafael J. Wysocki | 4fec7ad | 2016-03-10 23:45:19 +0100 | [diff] [blame] | 1585 | if (cpu->prev_mperf == mperf || cpu->prev_tsc == tsc) { |
Srinivas Pandruvada | 8e601a9 | 2015-10-15 12:34:21 -0700 | [diff] [blame] | 1586 | local_irq_restore(flags); |
Rafael J. Wysocki | 4fec7ad | 2016-03-10 23:45:19 +0100 | [diff] [blame] | 1587 | return false; |
Srinivas Pandruvada | 8e601a9 | 2015-10-15 12:34:21 -0700 | [diff] [blame] | 1588 | } |
Stratos Karafotis | 4ab60c3 | 2014-07-18 08:37:24 -0700 | [diff] [blame] | 1589 | local_irq_restore(flags); |
Dirk Brandewie | b69880f | 2014-01-16 10:32:25 -0800 | [diff] [blame] | 1590 | |
Dirk Brandewie | c4ee841 | 2014-05-29 09:32:24 -0700 | [diff] [blame] | 1591 | cpu->last_sample_time = cpu->sample.time; |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 1592 | cpu->sample.time = time; |
Dirk Brandewie | d37e2b7 | 2014-02-12 10:01:04 -0800 | [diff] [blame] | 1593 | cpu->sample.aperf = aperf; |
| 1594 | cpu->sample.mperf = mperf; |
Doug Smythies | 4055fad | 2015-04-11 21:10:26 -0700 | [diff] [blame] | 1595 | cpu->sample.tsc = tsc; |
Dirk Brandewie | d37e2b7 | 2014-02-12 10:01:04 -0800 | [diff] [blame] | 1596 | cpu->sample.aperf -= cpu->prev_aperf; |
| 1597 | cpu->sample.mperf -= cpu->prev_mperf; |
Doug Smythies | 4055fad | 2015-04-11 21:10:26 -0700 | [diff] [blame] | 1598 | cpu->sample.tsc -= cpu->prev_tsc; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1599 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1600 | cpu->prev_aperf = aperf; |
| 1601 | cpu->prev_mperf = mperf; |
Doug Smythies | 4055fad | 2015-04-11 21:10:26 -0700 | [diff] [blame] | 1602 | cpu->prev_tsc = tsc; |
Rafael J. Wysocki | febce40 | 2016-04-02 01:06:21 +0200 | [diff] [blame] | 1603 | /* |
| 1604 | * First time this function is invoked in a given cycle, all of the |
| 1605 | * previous sample data fields are equal to zero or stale and they must |
| 1606 | * be populated with meaningful numbers for things to work, so assume |
| 1607 | * that sample.time will always be reset before setting the utilization |
| 1608 | * update hook and make the caller skip the sample then. |
| 1609 | */ |
Rafael J. Wysocki | eabd22c | 2017-03-28 00:15:37 +0200 | [diff] [blame] | 1610 | if (cpu->last_sample_time) { |
| 1611 | intel_pstate_calc_avg_perf(cpu); |
| 1612 | return true; |
| 1613 | } |
| 1614 | return false; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1615 | } |
| 1616 | |
Philippe Longepe | 8fa520a | 2016-03-06 08:34:06 +0100 | [diff] [blame] | 1617 | static inline int32_t get_avg_frequency(struct cpudata *cpu) |
| 1618 | { |
Rafael J. Wysocki | a1c9787 | 2016-05-11 19:09:12 +0200 | [diff] [blame] | 1619 | return mul_ext_fp(cpu->sample.core_avg_perf, |
| 1620 | cpu->pstate.max_pstate_physical * cpu->pstate.scaling); |
Philippe Longepe | 8fa520a | 2016-03-06 08:34:06 +0100 | [diff] [blame] | 1621 | } |
| 1622 | |
Philippe Longepe | bdcaa23 | 2016-04-22 11:46:09 -0700 | [diff] [blame] | 1623 | static inline int32_t get_avg_pstate(struct cpudata *cpu) |
| 1624 | { |
Rafael J. Wysocki | 8edb0a6 | 2016-05-11 19:10:42 +0200 | [diff] [blame] | 1625 | return mul_ext_fp(cpu->pstate.max_pstate_physical, |
| 1626 | cpu->sample.core_avg_perf); |
Philippe Longepe | bdcaa23 | 2016-04-22 11:46:09 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
Philippe Longepe | e70eed2 | 2015-12-04 17:40:32 +0100 | [diff] [blame] | 1629 | static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu) |
| 1630 | { |
| 1631 | struct sample *sample = &cpu->sample; |
Rafael J. Wysocki | 09c448d | 2016-09-14 02:28:13 +0200 | [diff] [blame] | 1632 | int32_t busy_frac, boost; |
Rafael J. Wysocki | 0843e83 | 2016-10-06 14:07:51 +0200 | [diff] [blame] | 1633 | int target, avg_pstate; |
Philippe Longepe | e70eed2 | 2015-12-04 17:40:32 +0100 | [diff] [blame] | 1634 | |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 1635 | if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) |
| 1636 | return cpu->pstate.turbo_pstate; |
| 1637 | |
Rafael J. Wysocki | 09c448d | 2016-09-14 02:28:13 +0200 | [diff] [blame] | 1638 | busy_frac = div_fp(sample->mperf, sample->tsc); |
Philippe Longepe | 63d1d65 | 2015-12-04 17:40:35 +0100 | [diff] [blame] | 1639 | |
Rafael J. Wysocki | 09c448d | 2016-09-14 02:28:13 +0200 | [diff] [blame] | 1640 | boost = cpu->iowait_boost; |
| 1641 | cpu->iowait_boost >>= 1; |
Philippe Longepe | 63d1d65 | 2015-12-04 17:40:35 +0100 | [diff] [blame] | 1642 | |
Rafael J. Wysocki | 09c448d | 2016-09-14 02:28:13 +0200 | [diff] [blame] | 1643 | if (busy_frac < boost) |
| 1644 | busy_frac = boost; |
Philippe Longepe | 63d1d65 | 2015-12-04 17:40:35 +0100 | [diff] [blame] | 1645 | |
Rafael J. Wysocki | 09c448d | 2016-09-14 02:28:13 +0200 | [diff] [blame] | 1646 | sample->busy_scaled = busy_frac * 100; |
Rafael J. Wysocki | 0843e83 | 2016-10-06 14:07:51 +0200 | [diff] [blame] | 1647 | |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 1648 | target = global.no_turbo || global.turbo_disabled ? |
Rafael J. Wysocki | 0843e83 | 2016-10-06 14:07:51 +0200 | [diff] [blame] | 1649 | cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; |
| 1650 | target += target >> 2; |
| 1651 | target = mul_fp(target, busy_frac); |
| 1652 | if (target < cpu->pstate.min_pstate) |
| 1653 | target = cpu->pstate.min_pstate; |
| 1654 | |
| 1655 | /* |
| 1656 | * If the average P-state during the previous cycle was higher than the |
| 1657 | * current target, add 50% of the difference to the target to reduce |
| 1658 | * possible performance oscillations and offset possible performance |
| 1659 | * loss related to moving the workload from one CPU to another within |
| 1660 | * a package/module. |
| 1661 | */ |
| 1662 | avg_pstate = get_avg_pstate(cpu); |
| 1663 | if (avg_pstate > target) |
| 1664 | target += (avg_pstate - target) >> 1; |
| 1665 | |
| 1666 | return target; |
Philippe Longepe | e70eed2 | 2015-12-04 17:40:32 +0100 | [diff] [blame] | 1667 | } |
| 1668 | |
Philippe Longepe | 157386b | 2015-12-04 17:40:30 +0100 | [diff] [blame] | 1669 | static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1670 | { |
Rafael J. Wysocki | 1aa7a6e | 2016-05-11 19:11:26 +0200 | [diff] [blame] | 1671 | int32_t perf_scaled, max_pstate, current_pstate, sample_ratio; |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 1672 | u64 duration_ns; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1673 | |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 1674 | if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) |
| 1675 | return cpu->pstate.turbo_pstate; |
| 1676 | |
Kristen Carlson Accardi | e0d4c8f | 2014-12-10 12:39:38 -0800 | [diff] [blame] | 1677 | /* |
Rafael J. Wysocki | f00593a | 2016-09-30 03:13:34 +0200 | [diff] [blame] | 1678 | * perf_scaled is the ratio of the average P-state during the last |
| 1679 | * sampling period to the P-state requested last time (in percent). |
| 1680 | * |
| 1681 | * That measures the system's response to the previous P-state |
| 1682 | * selection. |
Kristen Carlson Accardi | e0d4c8f | 2014-12-10 12:39:38 -0800 | [diff] [blame] | 1683 | */ |
Rafael J. Wysocki | 22590ef | 2016-04-09 01:25:58 +0200 | [diff] [blame] | 1684 | max_pstate = cpu->pstate.max_pstate_physical; |
| 1685 | current_pstate = cpu->pstate.current_pstate; |
Rafael J. Wysocki | 1aa7a6e | 2016-05-11 19:11:26 +0200 | [diff] [blame] | 1686 | perf_scaled = mul_ext_fp(cpu->sample.core_avg_perf, |
Rafael J. Wysocki | a1c9787 | 2016-05-11 19:09:12 +0200 | [diff] [blame] | 1687 | div_fp(100 * max_pstate, current_pstate)); |
Dirk Brandewie | c4ee841 | 2014-05-29 09:32:24 -0700 | [diff] [blame] | 1688 | |
Kristen Carlson Accardi | e0d4c8f | 2014-12-10 12:39:38 -0800 | [diff] [blame] | 1689 | /* |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 1690 | * Since our utilization update callback will not run unless we are |
| 1691 | * in C0, check if the actual elapsed time is significantly greater (3x) |
| 1692 | * than our sample interval. If it is, then we were idle for a long |
Rafael J. Wysocki | 1aa7a6e | 2016-05-11 19:11:26 +0200 | [diff] [blame] | 1693 | * enough period of time to adjust our performance metric. |
Kristen Carlson Accardi | e0d4c8f | 2014-12-10 12:39:38 -0800 | [diff] [blame] | 1694 | */ |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 1695 | duration_ns = cpu->sample.time - cpu->last_sample_time; |
Rafael J. Wysocki | febce40 | 2016-04-02 01:06:21 +0200 | [diff] [blame] | 1696 | if ((s64)duration_ns > pid_params.sample_rate_ns * 3) { |
Rafael J. Wysocki | 22590ef | 2016-04-09 01:25:58 +0200 | [diff] [blame] | 1697 | sample_ratio = div_fp(pid_params.sample_rate_ns, duration_ns); |
Rafael J. Wysocki | 1aa7a6e | 2016-05-11 19:11:26 +0200 | [diff] [blame] | 1698 | perf_scaled = mul_fp(perf_scaled, sample_ratio); |
Rafael J. Wysocki | ffb8105 | 2016-04-10 05:59:10 +0200 | [diff] [blame] | 1699 | } else { |
| 1700 | sample_ratio = div_fp(100 * cpu->sample.mperf, cpu->sample.tsc); |
| 1701 | if (sample_ratio < int_tofp(1)) |
Rafael J. Wysocki | 1aa7a6e | 2016-05-11 19:11:26 +0200 | [diff] [blame] | 1702 | perf_scaled = 0; |
Dirk Brandewie | c4ee841 | 2014-05-29 09:32:24 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
Rafael J. Wysocki | 1aa7a6e | 2016-05-11 19:11:26 +0200 | [diff] [blame] | 1705 | cpu->sample.busy_scaled = perf_scaled; |
| 1706 | return cpu->pstate.current_pstate - pid_calc(&cpu->pid, perf_scaled); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1707 | } |
| 1708 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 1709 | static int intel_pstate_prepare_request(struct cpudata *cpu, int pstate) |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1710 | { |
| 1711 | int max_perf, min_perf; |
| 1712 | |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1713 | intel_pstate_get_min_max(cpu, &min_perf, &max_perf); |
| 1714 | pstate = clamp_t(int, pstate, min_perf, max_perf); |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 1715 | return pstate; |
| 1716 | } |
| 1717 | |
| 1718 | static void intel_pstate_update_pstate(struct cpudata *cpu, int pstate) |
| 1719 | { |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1720 | if (pstate == cpu->pstate.current_pstate) |
| 1721 | return; |
| 1722 | |
Rafael J. Wysocki | bc95a45 | 2016-07-19 15:10:37 +0200 | [diff] [blame] | 1723 | cpu->pstate.current_pstate = pstate; |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1724 | wrmsrl(MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, pstate)); |
| 1725 | } |
| 1726 | |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 1727 | static void intel_pstate_adjust_pstate(struct cpudata *cpu, int target_pstate) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1728 | { |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 1729 | int from = cpu->pstate.current_pstate; |
Doug Smythies | 4055fad | 2015-04-11 21:10:26 -0700 | [diff] [blame] | 1730 | struct sample *sample; |
| 1731 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 1732 | update_turbo_state(); |
| 1733 | |
Rafael J. Wysocki | 6407829 | 2017-03-03 23:51:31 +0100 | [diff] [blame] | 1734 | target_pstate = intel_pstate_prepare_request(cpu, target_pstate); |
| 1735 | trace_cpu_frequency(target_pstate * cpu->pstate.scaling, cpu->cpu); |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 1736 | intel_pstate_update_pstate(cpu, target_pstate); |
Doug Smythies | 4055fad | 2015-04-11 21:10:26 -0700 | [diff] [blame] | 1737 | |
| 1738 | sample = &cpu->sample; |
Rafael J. Wysocki | a1c9787 | 2016-05-11 19:09:12 +0200 | [diff] [blame] | 1739 | trace_pstate_sample(mul_ext_fp(100, sample->core_avg_perf), |
Philippe Longepe | 157386b | 2015-12-04 17:40:30 +0100 | [diff] [blame] | 1740 | fp_toint(sample->busy_scaled), |
Doug Smythies | 4055fad | 2015-04-11 21:10:26 -0700 | [diff] [blame] | 1741 | from, |
| 1742 | cpu->pstate.current_pstate, |
| 1743 | sample->mperf, |
| 1744 | sample->aperf, |
| 1745 | sample->tsc, |
Srinivas Pandruvada | 3ba7bca | 2016-09-13 17:41:33 -0700 | [diff] [blame] | 1746 | get_avg_frequency(cpu), |
| 1747 | fp_toint(cpu->iowait_boost * 100)); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1748 | } |
| 1749 | |
Rafael J. Wysocki | eabd22c | 2017-03-28 00:15:37 +0200 | [diff] [blame] | 1750 | static void intel_pstate_update_util_hwp(struct update_util_data *data, |
| 1751 | u64 time, unsigned int flags) |
| 1752 | { |
| 1753 | struct cpudata *cpu = container_of(data, struct cpudata, update_util); |
| 1754 | u64 delta_ns = time - cpu->sample.time; |
| 1755 | |
| 1756 | if ((s64)delta_ns >= INTEL_PSTATE_HWP_SAMPLING_INTERVAL) |
| 1757 | intel_pstate_sample(cpu, time); |
| 1758 | } |
| 1759 | |
| 1760 | static void intel_pstate_update_util_pid(struct update_util_data *data, |
| 1761 | u64 time, unsigned int flags) |
| 1762 | { |
| 1763 | struct cpudata *cpu = container_of(data, struct cpudata, update_util); |
| 1764 | u64 delta_ns = time - cpu->sample.time; |
| 1765 | |
| 1766 | if ((s64)delta_ns < pid_params.sample_rate_ns) |
| 1767 | return; |
| 1768 | |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 1769 | if (intel_pstate_sample(cpu, time)) { |
| 1770 | int target_pstate; |
| 1771 | |
| 1772 | target_pstate = get_target_pstate_use_performance(cpu); |
| 1773 | intel_pstate_adjust_pstate(cpu, target_pstate); |
| 1774 | } |
Rafael J. Wysocki | eabd22c | 2017-03-28 00:15:37 +0200 | [diff] [blame] | 1775 | } |
| 1776 | |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 1777 | static void intel_pstate_update_util(struct update_util_data *data, u64 time, |
Rafael J. Wysocki | 58919e8 | 2016-08-16 22:14:55 +0200 | [diff] [blame] | 1778 | unsigned int flags) |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 1779 | { |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 1780 | struct cpudata *cpu = container_of(data, struct cpudata, update_util); |
Rafael J. Wysocki | 09c448d | 2016-09-14 02:28:13 +0200 | [diff] [blame] | 1781 | u64 delta_ns; |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 1782 | |
Rafael J. Wysocki | eabd22c | 2017-03-28 00:15:37 +0200 | [diff] [blame] | 1783 | if (flags & SCHED_CPUFREQ_IOWAIT) { |
| 1784 | cpu->iowait_boost = int_tofp(1); |
| 1785 | } else if (cpu->iowait_boost) { |
| 1786 | /* Clear iowait_boost if the CPU may have been idle. */ |
| 1787 | delta_ns = time - cpu->last_update; |
| 1788 | if (delta_ns > TICK_NSEC) |
| 1789 | cpu->iowait_boost = 0; |
Rafael J. Wysocki | 09c448d | 2016-09-14 02:28:13 +0200 | [diff] [blame] | 1790 | } |
Rafael J. Wysocki | eabd22c | 2017-03-28 00:15:37 +0200 | [diff] [blame] | 1791 | cpu->last_update = time; |
Rafael J. Wysocki | 09c448d | 2016-09-14 02:28:13 +0200 | [diff] [blame] | 1792 | delta_ns = time - cpu->sample.time; |
Rafael J. Wysocki | eabd22c | 2017-03-28 00:15:37 +0200 | [diff] [blame] | 1793 | if ((s64)delta_ns < INTEL_PSTATE_DEFAULT_SAMPLING_INTERVAL) |
| 1794 | return; |
Rafael J. Wysocki | 4fec7ad | 2016-03-10 23:45:19 +0100 | [diff] [blame] | 1795 | |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 1796 | if (intel_pstate_sample(cpu, time)) { |
| 1797 | int target_pstate; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1798 | |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 1799 | target_pstate = get_target_pstate_use_cpu_load(cpu); |
| 1800 | intel_pstate_adjust_pstate(cpu, target_pstate); |
| 1801 | } |
| 1802 | } |
Rafael J. Wysocki | eabd22c | 2017-03-28 00:15:37 +0200 | [diff] [blame] | 1803 | |
Rafael J. Wysocki | 2f49afc | 2017-03-28 00:19:03 +0200 | [diff] [blame] | 1804 | static struct pstate_funcs core_funcs = { |
| 1805 | .get_max = core_get_max_pstate, |
| 1806 | .get_max_physical = core_get_max_pstate_physical, |
| 1807 | .get_min = core_get_min_pstate, |
| 1808 | .get_turbo = core_get_turbo_pstate, |
| 1809 | .get_scaling = core_get_scaling, |
| 1810 | .get_val = core_get_val, |
| 1811 | .update_util = intel_pstate_update_util_pid, |
Rafael J. Wysocki | de4a76c | 2017-03-28 00:18:02 +0200 | [diff] [blame] | 1812 | }; |
| 1813 | |
Rafael J. Wysocki | 2f49afc | 2017-03-28 00:19:03 +0200 | [diff] [blame] | 1814 | static const struct pstate_funcs silvermont_funcs = { |
| 1815 | .get_max = atom_get_max_pstate, |
| 1816 | .get_max_physical = atom_get_max_pstate, |
| 1817 | .get_min = atom_get_min_pstate, |
| 1818 | .get_turbo = atom_get_turbo_pstate, |
| 1819 | .get_val = atom_get_val, |
| 1820 | .get_scaling = silvermont_get_scaling, |
| 1821 | .get_vid = atom_get_vid, |
| 1822 | .update_util = intel_pstate_update_util, |
Rafael J. Wysocki | de4a76c | 2017-03-28 00:18:02 +0200 | [diff] [blame] | 1823 | }; |
| 1824 | |
Rafael J. Wysocki | 2f49afc | 2017-03-28 00:19:03 +0200 | [diff] [blame] | 1825 | static const struct pstate_funcs airmont_funcs = { |
| 1826 | .get_max = atom_get_max_pstate, |
| 1827 | .get_max_physical = atom_get_max_pstate, |
| 1828 | .get_min = atom_get_min_pstate, |
| 1829 | .get_turbo = atom_get_turbo_pstate, |
| 1830 | .get_val = atom_get_val, |
| 1831 | .get_scaling = airmont_get_scaling, |
| 1832 | .get_vid = atom_get_vid, |
| 1833 | .update_util = intel_pstate_update_util, |
Rafael J. Wysocki | de4a76c | 2017-03-28 00:18:02 +0200 | [diff] [blame] | 1834 | }; |
| 1835 | |
Rafael J. Wysocki | 2f49afc | 2017-03-28 00:19:03 +0200 | [diff] [blame] | 1836 | static const struct pstate_funcs knl_funcs = { |
| 1837 | .get_max = core_get_max_pstate, |
| 1838 | .get_max_physical = core_get_max_pstate_physical, |
| 1839 | .get_min = core_get_min_pstate, |
| 1840 | .get_turbo = knl_get_turbo_pstate, |
| 1841 | .get_scaling = core_get_scaling, |
| 1842 | .get_val = core_get_val, |
| 1843 | .update_util = intel_pstate_update_util_pid, |
Rafael J. Wysocki | de4a76c | 2017-03-28 00:18:02 +0200 | [diff] [blame] | 1844 | }; |
| 1845 | |
Rafael J. Wysocki | 2f49afc | 2017-03-28 00:19:03 +0200 | [diff] [blame] | 1846 | static const struct pstate_funcs bxt_funcs = { |
| 1847 | .get_max = core_get_max_pstate, |
| 1848 | .get_max_physical = core_get_max_pstate_physical, |
| 1849 | .get_min = core_get_min_pstate, |
| 1850 | .get_turbo = core_get_turbo_pstate, |
| 1851 | .get_scaling = core_get_scaling, |
| 1852 | .get_val = core_get_val, |
| 1853 | .update_util = intel_pstate_update_util, |
Rafael J. Wysocki | de4a76c | 2017-03-28 00:18:02 +0200 | [diff] [blame] | 1854 | }; |
| 1855 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1856 | #define ICPU(model, policy) \ |
Dirk Brandewie | 6cbd7ee | 2014-01-06 10:59:16 -0800 | [diff] [blame] | 1857 | { X86_VENDOR_INTEL, 6, model, X86_FEATURE_APERFMPERF,\ |
| 1858 | (unsigned long)&policy } |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1859 | |
| 1860 | static const struct x86_cpu_id intel_pstate_cpu_ids[] = { |
Rafael J. Wysocki | 2f49afc | 2017-03-28 00:19:03 +0200 | [diff] [blame] | 1861 | ICPU(INTEL_FAM6_SANDYBRIDGE, core_funcs), |
| 1862 | ICPU(INTEL_FAM6_SANDYBRIDGE_X, core_funcs), |
| 1863 | ICPU(INTEL_FAM6_ATOM_SILVERMONT1, silvermont_funcs), |
| 1864 | ICPU(INTEL_FAM6_IVYBRIDGE, core_funcs), |
| 1865 | ICPU(INTEL_FAM6_HASWELL_CORE, core_funcs), |
| 1866 | ICPU(INTEL_FAM6_BROADWELL_CORE, core_funcs), |
| 1867 | ICPU(INTEL_FAM6_IVYBRIDGE_X, core_funcs), |
| 1868 | ICPU(INTEL_FAM6_HASWELL_X, core_funcs), |
| 1869 | ICPU(INTEL_FAM6_HASWELL_ULT, core_funcs), |
| 1870 | ICPU(INTEL_FAM6_HASWELL_GT3E, core_funcs), |
| 1871 | ICPU(INTEL_FAM6_BROADWELL_GT3E, core_funcs), |
| 1872 | ICPU(INTEL_FAM6_ATOM_AIRMONT, airmont_funcs), |
| 1873 | ICPU(INTEL_FAM6_SKYLAKE_MOBILE, core_funcs), |
| 1874 | ICPU(INTEL_FAM6_BROADWELL_X, core_funcs), |
| 1875 | ICPU(INTEL_FAM6_SKYLAKE_DESKTOP, core_funcs), |
| 1876 | ICPU(INTEL_FAM6_BROADWELL_XEON_D, core_funcs), |
| 1877 | ICPU(INTEL_FAM6_XEON_PHI_KNL, knl_funcs), |
| 1878 | ICPU(INTEL_FAM6_XEON_PHI_KNM, knl_funcs), |
| 1879 | ICPU(INTEL_FAM6_ATOM_GOLDMONT, bxt_funcs), |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1880 | {} |
| 1881 | }; |
| 1882 | MODULE_DEVICE_TABLE(x86cpu, intel_pstate_cpu_ids); |
| 1883 | |
Jisheng Zhang | 29327c8 | 2016-06-27 18:07:17 +0800 | [diff] [blame] | 1884 | static const struct x86_cpu_id intel_pstate_cpu_oob_ids[] __initconst = { |
Rafael J. Wysocki | 2f49afc | 2017-03-28 00:19:03 +0200 | [diff] [blame] | 1885 | ICPU(INTEL_FAM6_BROADWELL_XEON_D, core_funcs), |
| 1886 | ICPU(INTEL_FAM6_BROADWELL_X, core_funcs), |
| 1887 | ICPU(INTEL_FAM6_SKYLAKE_X, core_funcs), |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 1888 | {} |
| 1889 | }; |
| 1890 | |
Srinivas Pandruvada | 6e978b2 | 2017-02-03 14:18:39 -0800 | [diff] [blame] | 1891 | static const struct x86_cpu_id intel_pstate_cpu_ee_disable_ids[] = { |
Rafael J. Wysocki | 2f49afc | 2017-03-28 00:19:03 +0200 | [diff] [blame] | 1892 | ICPU(INTEL_FAM6_KABYLAKE_DESKTOP, core_funcs), |
Srinivas Pandruvada | 6e978b2 | 2017-02-03 14:18:39 -0800 | [diff] [blame] | 1893 | {} |
| 1894 | }; |
| 1895 | |
Rafael J. Wysocki | 8ca6ce3 | 2017-03-28 00:20:13 +0200 | [diff] [blame^] | 1896 | static bool pid_in_use(void); |
| 1897 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1898 | static int intel_pstate_init_cpu(unsigned int cpunum) |
| 1899 | { |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1900 | struct cpudata *cpu; |
| 1901 | |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 1902 | cpu = all_cpu_data[cpunum]; |
| 1903 | |
| 1904 | if (!cpu) { |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 1905 | cpu = kzalloc(sizeof(*cpu), GFP_KERNEL); |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 1906 | if (!cpu) |
| 1907 | return -ENOMEM; |
| 1908 | |
| 1909 | all_cpu_data[cpunum] = cpu; |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 1910 | |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 1911 | cpu->epp_default = -EINVAL; |
| 1912 | cpu->epp_powersave = -EINVAL; |
| 1913 | cpu->epp_saved = -EINVAL; |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 1914 | } |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1915 | |
| 1916 | cpu = all_cpu_data[cpunum]; |
| 1917 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1918 | cpu->cpu = cpunum; |
Kristen Carlson Accardi | ba88d43 | 2015-07-14 09:46:23 -0700 | [diff] [blame] | 1919 | |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 1920 | if (hwp_active) { |
Srinivas Pandruvada | 6e978b2 | 2017-02-03 14:18:39 -0800 | [diff] [blame] | 1921 | const struct x86_cpu_id *id; |
| 1922 | |
| 1923 | id = x86_match_cpu(intel_pstate_cpu_ee_disable_ids); |
| 1924 | if (id) |
| 1925 | intel_pstate_disable_ee(cpunum); |
| 1926 | |
Kristen Carlson Accardi | ba88d43 | 2015-07-14 09:46:23 -0700 | [diff] [blame] | 1927 | intel_pstate_hwp_enable(cpu); |
Rafael J. Wysocki | 8ca6ce3 | 2017-03-28 00:20:13 +0200 | [diff] [blame^] | 1928 | } else if (pid_in_use()) { |
Rafael J. Wysocki | 694cb17 | 2017-03-28 00:11:53 +0200 | [diff] [blame] | 1929 | intel_pstate_pid_reset(cpu); |
Rafael J. Wysocki | a4675fb | 2016-02-05 01:45:30 +0100 | [diff] [blame] | 1930 | } |
Kristen Carlson Accardi | ba88d43 | 2015-07-14 09:46:23 -0700 | [diff] [blame] | 1931 | |
Vincent Minet | 179e847 | 2014-07-05 01:51:33 +0200 | [diff] [blame] | 1932 | intel_pstate_get_cpu_pstates(cpu); |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 1933 | |
Joe Perches | 4836df1 | 2016-04-05 13:28:23 -0700 | [diff] [blame] | 1934 | pr_debug("controlling: cpu %d\n", cpunum); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1935 | |
| 1936 | return 0; |
| 1937 | } |
| 1938 | |
| 1939 | static unsigned int intel_pstate_get(unsigned int cpu_num) |
| 1940 | { |
Rafael J. Wysocki | f96fd0c | 2016-05-07 02:24:48 +0200 | [diff] [blame] | 1941 | struct cpudata *cpu = all_cpu_data[cpu_num]; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1942 | |
Rafael J. Wysocki | f96fd0c | 2016-05-07 02:24:48 +0200 | [diff] [blame] | 1943 | return cpu ? get_avg_frequency(cpu) : 0; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1944 | } |
| 1945 | |
Rafael J. Wysocki | febce40 | 2016-04-02 01:06:21 +0200 | [diff] [blame] | 1946 | static void intel_pstate_set_update_util_hook(unsigned int cpu_num) |
Rafael J. Wysocki | bb6ab52 | 2016-03-31 17:42:15 +0200 | [diff] [blame] | 1947 | { |
Rafael J. Wysocki | febce40 | 2016-04-02 01:06:21 +0200 | [diff] [blame] | 1948 | struct cpudata *cpu = all_cpu_data[cpu_num]; |
| 1949 | |
Rafael J. Wysocki | 5ab666e | 2016-06-27 23:47:15 +0200 | [diff] [blame] | 1950 | if (cpu->update_util_set) |
| 1951 | return; |
| 1952 | |
Rafael J. Wysocki | febce40 | 2016-04-02 01:06:21 +0200 | [diff] [blame] | 1953 | /* Prevent intel_pstate_update_util() from using stale data. */ |
| 1954 | cpu->sample.time = 0; |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 1955 | cpufreq_add_update_util_hook(cpu_num, &cpu->update_util, |
| 1956 | pstate_funcs.update_util); |
Chen Yu | 4578ee7e | 2016-05-11 14:33:08 +0800 | [diff] [blame] | 1957 | cpu->update_util_set = true; |
Rafael J. Wysocki | bb6ab52 | 2016-03-31 17:42:15 +0200 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | static void intel_pstate_clear_update_util_hook(unsigned int cpu) |
| 1961 | { |
Chen Yu | 4578ee7e | 2016-05-11 14:33:08 +0800 | [diff] [blame] | 1962 | struct cpudata *cpu_data = all_cpu_data[cpu]; |
| 1963 | |
| 1964 | if (!cpu_data->update_util_set) |
| 1965 | return; |
| 1966 | |
Rafael J. Wysocki | 0bed612 | 2016-04-02 01:08:43 +0200 | [diff] [blame] | 1967 | cpufreq_remove_update_util_hook(cpu); |
Chen Yu | 4578ee7e | 2016-05-11 14:33:08 +0800 | [diff] [blame] | 1968 | cpu_data->update_util_set = false; |
Rafael J. Wysocki | bb6ab52 | 2016-03-31 17:42:15 +0200 | [diff] [blame] | 1969 | synchronize_sched(); |
| 1970 | } |
| 1971 | |
Rafael J. Wysocki | 80b120c | 2017-03-23 00:00:47 +0100 | [diff] [blame] | 1972 | static int intel_pstate_get_max_freq(struct cpudata *cpu) |
| 1973 | { |
| 1974 | return global.turbo_disabled || global.no_turbo ? |
| 1975 | cpu->pstate.max_freq : cpu->pstate.turbo_freq; |
| 1976 | } |
| 1977 | |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 1978 | static void intel_pstate_update_perf_limits(struct cpufreq_policy *policy, |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 1979 | struct cpudata *cpu) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 1980 | { |
Rafael J. Wysocki | 80b120c | 2017-03-23 00:00:47 +0100 | [diff] [blame] | 1981 | int max_freq = intel_pstate_get_max_freq(cpu); |
Rafael J. Wysocki | e4c204c | 2017-03-14 16:18:34 +0100 | [diff] [blame] | 1982 | int32_t max_policy_perf, min_policy_perf; |
Srinivas Pandruvada | a410c03 | 2016-10-28 10:44:52 -0700 | [diff] [blame] | 1983 | |
Rafael J. Wysocki | 80b120c | 2017-03-23 00:00:47 +0100 | [diff] [blame] | 1984 | max_policy_perf = div_ext_fp(policy->max, max_freq); |
Rafael J. Wysocki | e4c204c | 2017-03-14 16:18:34 +0100 | [diff] [blame] | 1985 | max_policy_perf = clamp_t(int32_t, max_policy_perf, 0, int_ext_tofp(1)); |
Srinivas Pandruvada | 5879f87 | 2016-10-25 13:20:41 -0700 | [diff] [blame] | 1986 | if (policy->max == policy->min) { |
Rafael J. Wysocki | e4c204c | 2017-03-14 16:18:34 +0100 | [diff] [blame] | 1987 | min_policy_perf = max_policy_perf; |
Srinivas Pandruvada | 5879f87 | 2016-10-25 13:20:41 -0700 | [diff] [blame] | 1988 | } else { |
Rafael J. Wysocki | 80b120c | 2017-03-23 00:00:47 +0100 | [diff] [blame] | 1989 | min_policy_perf = div_ext_fp(policy->min, max_freq); |
Rafael J. Wysocki | e4c204c | 2017-03-14 16:18:34 +0100 | [diff] [blame] | 1990 | min_policy_perf = clamp_t(int32_t, min_policy_perf, |
| 1991 | 0, max_policy_perf); |
Srinivas Pandruvada | 5879f87 | 2016-10-25 13:20:41 -0700 | [diff] [blame] | 1992 | } |
Chen Yu | 43717aa | 2015-09-09 18:27:31 +0800 | [diff] [blame] | 1993 | |
Rafael J. Wysocki | e4c204c | 2017-03-14 16:18:34 +0100 | [diff] [blame] | 1994 | /* Normalize user input to [min_perf, max_perf] */ |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 1995 | if (per_cpu_limits) { |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 1996 | cpu->min_perf = min_policy_perf; |
| 1997 | cpu->max_perf = max_policy_perf; |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 1998 | } else { |
| 1999 | int32_t global_min, global_max; |
Chen Yu | 43717aa | 2015-09-09 18:27:31 +0800 | [diff] [blame] | 2000 | |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 2001 | /* Global limits are in percent of the maximum turbo P-state. */ |
| 2002 | global_max = percent_ext_fp(global.max_perf_pct); |
| 2003 | global_min = percent_ext_fp(global.min_perf_pct); |
Rafael J. Wysocki | 80b120c | 2017-03-23 00:00:47 +0100 | [diff] [blame] | 2004 | if (max_freq != cpu->pstate.turbo_freq) { |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 2005 | int32_t turbo_factor; |
| 2006 | |
| 2007 | turbo_factor = div_ext_fp(cpu->pstate.turbo_pstate, |
| 2008 | cpu->pstate.max_pstate); |
| 2009 | global_min = mul_ext_fp(global_min, turbo_factor); |
| 2010 | global_max = mul_ext_fp(global_max, turbo_factor); |
| 2011 | } |
| 2012 | global_min = clamp_t(int32_t, global_min, 0, global_max); |
| 2013 | |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 2014 | cpu->min_perf = max(min_policy_perf, global_min); |
| 2015 | cpu->min_perf = min(cpu->min_perf, max_policy_perf); |
| 2016 | cpu->max_perf = min(max_policy_perf, global_max); |
| 2017 | cpu->max_perf = max(min_policy_perf, cpu->max_perf); |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 2018 | |
| 2019 | /* Make sure min_perf <= max_perf */ |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 2020 | cpu->min_perf = min(cpu->min_perf, cpu->max_perf); |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 2021 | } |
Chen Yu | 43717aa | 2015-09-09 18:27:31 +0800 | [diff] [blame] | 2022 | |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 2023 | cpu->max_perf = round_up(cpu->max_perf, EXT_FRAC_BITS); |
| 2024 | cpu->min_perf = round_up(cpu->min_perf, EXT_FRAC_BITS); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2025 | |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 2026 | pr_debug("cpu:%d max_perf_pct:%d min_perf_pct:%d\n", policy->cpu, |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 2027 | fp_ext_toint(cpu->max_perf * 100), |
| 2028 | fp_ext_toint(cpu->min_perf * 100)); |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2031 | static int intel_pstate_set_policy(struct cpufreq_policy *policy) |
| 2032 | { |
| 2033 | struct cpudata *cpu; |
| 2034 | |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 2035 | if (!policy->cpuinfo.max_freq) |
| 2036 | return -ENODEV; |
| 2037 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2038 | pr_debug("set_policy cpuinfo.max %u policy->max %u\n", |
| 2039 | policy->cpuinfo.max_freq, policy->max); |
| 2040 | |
| 2041 | cpu = all_cpu_data[policy->cpu]; |
| 2042 | cpu->policy = policy->policy; |
Viresh Kumar | be49e34 | 2013-10-02 14:13:19 +0530 | [diff] [blame] | 2043 | |
Srinivas Pandruvada | b59fe54 | 2016-12-06 13:32:15 -0800 | [diff] [blame] | 2044 | mutex_lock(&intel_pstate_limits_lock); |
| 2045 | |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 2046 | intel_pstate_update_perf_limits(policy, cpu); |
Rafael J. Wysocki | a240c4a | 2017-03-02 23:29:12 +0100 | [diff] [blame] | 2047 | |
Rafael J. Wysocki | 2f1d407 | 2016-10-24 23:20:25 +0200 | [diff] [blame] | 2048 | if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) { |
Rafael J. Wysocki | a6c6ead | 2016-10-19 02:57:22 +0200 | [diff] [blame] | 2049 | /* |
| 2050 | * NOHZ_FULL CPUs need this as the governor callback may not |
| 2051 | * be invoked on them. |
| 2052 | */ |
| 2053 | intel_pstate_clear_update_util_hook(policy->cpu); |
| 2054 | intel_pstate_max_within_limits(cpu); |
| 2055 | } |
| 2056 | |
Rafael J. Wysocki | bb6ab52 | 2016-03-31 17:42:15 +0200 | [diff] [blame] | 2057 | intel_pstate_set_update_util_hook(policy->cpu); |
| 2058 | |
Rafael J. Wysocki | 5f98ced | 2017-03-09 16:30:38 +0100 | [diff] [blame] | 2059 | if (hwp_active) |
| 2060 | intel_pstate_hwp_set(policy); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2061 | |
Srinivas Pandruvada | b59fe54 | 2016-12-06 13:32:15 -0800 | [diff] [blame] | 2062 | mutex_unlock(&intel_pstate_limits_lock); |
| 2063 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2064 | return 0; |
| 2065 | } |
| 2066 | |
Rafael J. Wysocki | 80b120c | 2017-03-23 00:00:47 +0100 | [diff] [blame] | 2067 | static void intel_pstate_adjust_policy_max(struct cpufreq_policy *policy, |
| 2068 | struct cpudata *cpu) |
| 2069 | { |
| 2070 | if (cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate && |
| 2071 | policy->max < policy->cpuinfo.max_freq && |
| 2072 | policy->max > cpu->pstate.max_freq) { |
| 2073 | pr_debug("policy->max > max non turbo frequency\n"); |
| 2074 | policy->max = policy->cpuinfo.max_freq; |
| 2075 | } |
| 2076 | } |
| 2077 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2078 | static int intel_pstate_verify_policy(struct cpufreq_policy *policy) |
| 2079 | { |
Srinivas Pandruvada | 7d9a8a9 | 2017-01-18 10:48:23 -0800 | [diff] [blame] | 2080 | struct cpudata *cpu = all_cpu_data[policy->cpu]; |
Srinivas Pandruvada | 7d9a8a9 | 2017-01-18 10:48:23 -0800 | [diff] [blame] | 2081 | |
| 2082 | update_turbo_state(); |
Rafael J. Wysocki | 80b120c | 2017-03-23 00:00:47 +0100 | [diff] [blame] | 2083 | cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, |
| 2084 | intel_pstate_get_max_freq(cpu)); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2085 | |
Stratos Karafotis | 285cb99 | 2014-07-18 08:37:21 -0700 | [diff] [blame] | 2086 | if (policy->policy != CPUFREQ_POLICY_POWERSAVE && |
Stratos Karafotis | c410833 | 2014-07-18 08:37:23 -0700 | [diff] [blame] | 2087 | policy->policy != CPUFREQ_POLICY_PERFORMANCE) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2088 | return -EINVAL; |
| 2089 | |
Rafael J. Wysocki | 80b120c | 2017-03-23 00:00:47 +0100 | [diff] [blame] | 2090 | intel_pstate_adjust_policy_max(policy, cpu); |
| 2091 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2092 | return 0; |
| 2093 | } |
| 2094 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2095 | static void intel_cpufreq_stop_cpu(struct cpufreq_policy *policy) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2096 | { |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2097 | intel_pstate_set_min_pstate(all_cpu_data[policy->cpu]); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2098 | } |
| 2099 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2100 | static void intel_pstate_stop_cpu(struct cpufreq_policy *policy) |
| 2101 | { |
| 2102 | pr_debug("CPU %d exiting\n", policy->cpu); |
| 2103 | |
| 2104 | intel_pstate_clear_update_util_hook(policy->cpu); |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 2105 | if (hwp_active) |
| 2106 | intel_pstate_hwp_save_state(policy); |
| 2107 | else |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2108 | intel_cpufreq_stop_cpu(policy); |
| 2109 | } |
| 2110 | |
| 2111 | static int intel_pstate_cpu_exit(struct cpufreq_policy *policy) |
| 2112 | { |
| 2113 | intel_pstate_exit_perf_limits(policy); |
| 2114 | |
| 2115 | policy->fast_switch_possible = false; |
| 2116 | |
| 2117 | return 0; |
| 2118 | } |
| 2119 | |
| 2120 | static int __intel_pstate_cpu_init(struct cpufreq_policy *policy) |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2121 | { |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2122 | struct cpudata *cpu; |
Dirk Brandewie | 52e0a50 | 2013-10-15 11:06:14 -0700 | [diff] [blame] | 2123 | int rc; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2124 | |
| 2125 | rc = intel_pstate_init_cpu(policy->cpu); |
| 2126 | if (rc) |
| 2127 | return rc; |
| 2128 | |
| 2129 | cpu = all_cpu_data[policy->cpu]; |
| 2130 | |
Rafael J. Wysocki | e14cf88 | 2017-03-28 00:03:20 +0200 | [diff] [blame] | 2131 | cpu->max_perf = int_ext_tofp(1); |
| 2132 | cpu->min_perf = 0; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2133 | |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 2134 | policy->min = cpu->pstate.min_pstate * cpu->pstate.scaling; |
| 2135 | policy->max = cpu->pstate.turbo_pstate * cpu->pstate.scaling; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2136 | |
| 2137 | /* cpuinfo and default policy values */ |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 2138 | policy->cpuinfo.min_freq = cpu->pstate.min_pstate * cpu->pstate.scaling; |
Srinivas Pandruvada | 983e600 | 2016-06-07 17:38:53 -0700 | [diff] [blame] | 2139 | update_turbo_state(); |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 2140 | policy->cpuinfo.max_freq = global.turbo_disabled ? |
Srinivas Pandruvada | 983e600 | 2016-06-07 17:38:53 -0700 | [diff] [blame] | 2141 | cpu->pstate.max_pstate : cpu->pstate.turbo_pstate; |
| 2142 | policy->cpuinfo.max_freq *= cpu->pstate.scaling; |
| 2143 | |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 2144 | intel_pstate_init_acpi_perf_limits(policy); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2145 | cpumask_set_cpu(policy->cpu, policy->cpus); |
| 2146 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2147 | policy->fast_switch_possible = true; |
| 2148 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2149 | return 0; |
| 2150 | } |
| 2151 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2152 | static int intel_pstate_cpu_init(struct cpufreq_policy *policy) |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 2153 | { |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2154 | int ret = __intel_pstate_cpu_init(policy); |
| 2155 | |
| 2156 | if (ret) |
| 2157 | return ret; |
| 2158 | |
| 2159 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; |
Rafael J. Wysocki | 7de3255 | 2017-03-18 00:57:39 +0100 | [diff] [blame] | 2160 | if (IS_ENABLED(CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE)) |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2161 | policy->policy = CPUFREQ_POLICY_PERFORMANCE; |
| 2162 | else |
| 2163 | policy->policy = CPUFREQ_POLICY_POWERSAVE; |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 2164 | |
| 2165 | return 0; |
| 2166 | } |
| 2167 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2168 | static struct cpufreq_driver intel_pstate = { |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2169 | .flags = CPUFREQ_CONST_LOOPS, |
| 2170 | .verify = intel_pstate_verify_policy, |
| 2171 | .setpolicy = intel_pstate_set_policy, |
Srinivas Pandruvada | 984edbd | 2016-12-06 13:32:16 -0800 | [diff] [blame] | 2172 | .suspend = intel_pstate_hwp_save_state, |
Srinivas Pandruvada | 8442885 | 2016-11-24 16:07:10 -0800 | [diff] [blame] | 2173 | .resume = intel_pstate_resume, |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2174 | .get = intel_pstate_get, |
| 2175 | .init = intel_pstate_cpu_init, |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 2176 | .exit = intel_pstate_cpu_exit, |
Dirk Brandewie | bb18008 | 2014-03-19 08:45:54 -0700 | [diff] [blame] | 2177 | .stop_cpu = intel_pstate_stop_cpu, |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2178 | .name = "intel_pstate", |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2179 | }; |
| 2180 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2181 | static int intel_cpufreq_verify_policy(struct cpufreq_policy *policy) |
| 2182 | { |
| 2183 | struct cpudata *cpu = all_cpu_data[policy->cpu]; |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2184 | |
| 2185 | update_turbo_state(); |
Rafael J. Wysocki | 80b120c | 2017-03-23 00:00:47 +0100 | [diff] [blame] | 2186 | cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, |
| 2187 | intel_pstate_get_max_freq(cpu)); |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2188 | |
Rafael J. Wysocki | 80b120c | 2017-03-23 00:00:47 +0100 | [diff] [blame] | 2189 | intel_pstate_adjust_policy_max(policy, cpu); |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2190 | |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 2191 | intel_pstate_update_perf_limits(policy, cpu); |
| 2192 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2193 | return 0; |
| 2194 | } |
| 2195 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2196 | static int intel_cpufreq_target(struct cpufreq_policy *policy, |
| 2197 | unsigned int target_freq, |
| 2198 | unsigned int relation) |
| 2199 | { |
| 2200 | struct cpudata *cpu = all_cpu_data[policy->cpu]; |
| 2201 | struct cpufreq_freqs freqs; |
| 2202 | int target_pstate; |
| 2203 | |
Rafael J. Wysocki | 64897b2 | 2017-03-21 22:19:07 +0100 | [diff] [blame] | 2204 | update_turbo_state(); |
| 2205 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2206 | freqs.old = policy->cur; |
Rafael J. Wysocki | 64897b2 | 2017-03-21 22:19:07 +0100 | [diff] [blame] | 2207 | freqs.new = target_freq; |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2208 | |
| 2209 | cpufreq_freq_transition_begin(policy, &freqs); |
| 2210 | switch (relation) { |
| 2211 | case CPUFREQ_RELATION_L: |
| 2212 | target_pstate = DIV_ROUND_UP(freqs.new, cpu->pstate.scaling); |
| 2213 | break; |
| 2214 | case CPUFREQ_RELATION_H: |
| 2215 | target_pstate = freqs.new / cpu->pstate.scaling; |
| 2216 | break; |
| 2217 | default: |
| 2218 | target_pstate = DIV_ROUND_CLOSEST(freqs.new, cpu->pstate.scaling); |
| 2219 | break; |
| 2220 | } |
| 2221 | target_pstate = intel_pstate_prepare_request(cpu, target_pstate); |
| 2222 | if (target_pstate != cpu->pstate.current_pstate) { |
| 2223 | cpu->pstate.current_pstate = target_pstate; |
| 2224 | wrmsrl_on_cpu(policy->cpu, MSR_IA32_PERF_CTL, |
| 2225 | pstate_funcs.get_val(cpu, target_pstate)); |
| 2226 | } |
Rafael J. Wysocki | 6407829 | 2017-03-03 23:51:31 +0100 | [diff] [blame] | 2227 | freqs.new = target_pstate * cpu->pstate.scaling; |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2228 | cpufreq_freq_transition_end(policy, &freqs, false); |
| 2229 | |
| 2230 | return 0; |
| 2231 | } |
| 2232 | |
| 2233 | static unsigned int intel_cpufreq_fast_switch(struct cpufreq_policy *policy, |
| 2234 | unsigned int target_freq) |
| 2235 | { |
| 2236 | struct cpudata *cpu = all_cpu_data[policy->cpu]; |
| 2237 | int target_pstate; |
| 2238 | |
Rafael J. Wysocki | 64897b2 | 2017-03-21 22:19:07 +0100 | [diff] [blame] | 2239 | update_turbo_state(); |
| 2240 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2241 | target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling); |
Rafael J. Wysocki | 6407829 | 2017-03-03 23:51:31 +0100 | [diff] [blame] | 2242 | target_pstate = intel_pstate_prepare_request(cpu, target_pstate); |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2243 | intel_pstate_update_pstate(cpu, target_pstate); |
Rafael J. Wysocki | 6407829 | 2017-03-03 23:51:31 +0100 | [diff] [blame] | 2244 | return target_pstate * cpu->pstate.scaling; |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | static int intel_cpufreq_cpu_init(struct cpufreq_policy *policy) |
| 2248 | { |
| 2249 | int ret = __intel_pstate_cpu_init(policy); |
| 2250 | |
| 2251 | if (ret) |
| 2252 | return ret; |
| 2253 | |
| 2254 | policy->cpuinfo.transition_latency = INTEL_CPUFREQ_TRANSITION_LATENCY; |
| 2255 | /* This reflects the intel_pstate_get_cpu_pstates() setting. */ |
| 2256 | policy->cur = policy->cpuinfo.min_freq; |
| 2257 | |
| 2258 | return 0; |
| 2259 | } |
| 2260 | |
| 2261 | static struct cpufreq_driver intel_cpufreq = { |
| 2262 | .flags = CPUFREQ_CONST_LOOPS, |
| 2263 | .verify = intel_cpufreq_verify_policy, |
| 2264 | .target = intel_cpufreq_target, |
| 2265 | .fast_switch = intel_cpufreq_fast_switch, |
| 2266 | .init = intel_cpufreq_cpu_init, |
| 2267 | .exit = intel_pstate_cpu_exit, |
| 2268 | .stop_cpu = intel_cpufreq_stop_cpu, |
| 2269 | .name = "intel_cpufreq", |
| 2270 | }; |
| 2271 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2272 | static struct cpufreq_driver *default_driver = &intel_pstate; |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2273 | |
Rafael J. Wysocki | 8ca6ce3 | 2017-03-28 00:20:13 +0200 | [diff] [blame^] | 2274 | static bool pid_in_use(void) |
| 2275 | { |
| 2276 | return intel_pstate_driver == &intel_pstate && |
| 2277 | pstate_funcs.update_util == intel_pstate_update_util_pid; |
| 2278 | } |
| 2279 | |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2280 | static void intel_pstate_driver_cleanup(void) |
| 2281 | { |
| 2282 | unsigned int cpu; |
| 2283 | |
| 2284 | get_online_cpus(); |
| 2285 | for_each_online_cpu(cpu) { |
| 2286 | if (all_cpu_data[cpu]) { |
| 2287 | if (intel_pstate_driver == &intel_pstate) |
| 2288 | intel_pstate_clear_update_util_hook(cpu); |
| 2289 | |
| 2290 | kfree(all_cpu_data[cpu]); |
| 2291 | all_cpu_data[cpu] = NULL; |
| 2292 | } |
| 2293 | } |
| 2294 | put_online_cpus(); |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2295 | intel_pstate_driver = NULL; |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2296 | } |
| 2297 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2298 | static int intel_pstate_register_driver(struct cpufreq_driver *driver) |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2299 | { |
| 2300 | int ret; |
| 2301 | |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 2302 | memset(&global, 0, sizeof(global)); |
| 2303 | global.max_perf_pct = 100; |
Rafael J. Wysocki | c3a49c8 | 2017-02-28 00:05:01 +0100 | [diff] [blame] | 2304 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2305 | intel_pstate_driver = driver; |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2306 | ret = cpufreq_register_driver(intel_pstate_driver); |
| 2307 | if (ret) { |
| 2308 | intel_pstate_driver_cleanup(); |
| 2309 | return ret; |
| 2310 | } |
| 2311 | |
Rafael J. Wysocki | c5a2ee7 | 2017-03-22 23:58:57 +0100 | [diff] [blame] | 2312 | global.min_perf_pct = min_perf_pct_min(); |
| 2313 | |
Rafael J. Wysocki | 8ca6ce3 | 2017-03-28 00:20:13 +0200 | [diff] [blame^] | 2314 | if (pid_in_use()) |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2315 | intel_pstate_debug_expose_params(); |
| 2316 | |
| 2317 | return 0; |
| 2318 | } |
| 2319 | |
| 2320 | static int intel_pstate_unregister_driver(void) |
| 2321 | { |
| 2322 | if (hwp_active) |
| 2323 | return -EBUSY; |
| 2324 | |
Rafael J. Wysocki | 8ca6ce3 | 2017-03-28 00:20:13 +0200 | [diff] [blame^] | 2325 | if (pid_in_use()) |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2326 | intel_pstate_debug_hide_params(); |
| 2327 | |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2328 | cpufreq_unregister_driver(intel_pstate_driver); |
| 2329 | intel_pstate_driver_cleanup(); |
| 2330 | |
| 2331 | return 0; |
| 2332 | } |
| 2333 | |
| 2334 | static ssize_t intel_pstate_show_status(char *buf) |
| 2335 | { |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2336 | if (!intel_pstate_driver) |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2337 | return sprintf(buf, "off\n"); |
| 2338 | |
| 2339 | return sprintf(buf, "%s\n", intel_pstate_driver == &intel_pstate ? |
| 2340 | "active" : "passive"); |
| 2341 | } |
| 2342 | |
| 2343 | static int intel_pstate_update_status(const char *buf, size_t size) |
| 2344 | { |
| 2345 | int ret; |
| 2346 | |
| 2347 | if (size == 3 && !strncmp(buf, "off", size)) |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2348 | return intel_pstate_driver ? |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2349 | intel_pstate_unregister_driver() : -EINVAL; |
| 2350 | |
| 2351 | if (size == 6 && !strncmp(buf, "active", size)) { |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2352 | if (intel_pstate_driver) { |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2353 | if (intel_pstate_driver == &intel_pstate) |
| 2354 | return 0; |
| 2355 | |
| 2356 | ret = intel_pstate_unregister_driver(); |
| 2357 | if (ret) |
| 2358 | return ret; |
| 2359 | } |
| 2360 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2361 | return intel_pstate_register_driver(&intel_pstate); |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | if (size == 7 && !strncmp(buf, "passive", size)) { |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2365 | if (intel_pstate_driver) { |
Rafael J. Wysocki | 0042b2c | 2017-03-28 00:14:08 +0200 | [diff] [blame] | 2366 | if (intel_pstate_driver == &intel_cpufreq) |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2367 | return 0; |
| 2368 | |
| 2369 | ret = intel_pstate_unregister_driver(); |
| 2370 | if (ret) |
| 2371 | return ret; |
| 2372 | } |
| 2373 | |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2374 | return intel_pstate_register_driver(&intel_cpufreq); |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | return -EINVAL; |
| 2378 | } |
| 2379 | |
Jisheng Zhang | eed4360 | 2016-06-27 18:07:16 +0800 | [diff] [blame] | 2380 | static int no_load __initdata; |
| 2381 | static int no_hwp __initdata; |
| 2382 | static int hwp_only __initdata; |
Jisheng Zhang | 29327c8 | 2016-06-27 18:07:17 +0800 | [diff] [blame] | 2383 | static unsigned int force_load __initdata; |
Dirk Brandewie | 6be2649 | 2013-02-15 22:55:10 +0100 | [diff] [blame] | 2384 | |
Jisheng Zhang | 29327c8 | 2016-06-27 18:07:17 +0800 | [diff] [blame] | 2385 | static int __init intel_pstate_msrs_not_valid(void) |
Dirk Brandewie | b563b4e | 2013-03-22 01:29:28 +0100 | [diff] [blame] | 2386 | { |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 2387 | if (!pstate_funcs.get_max() || |
Stratos Karafotis | c410833 | 2014-07-18 08:37:23 -0700 | [diff] [blame] | 2388 | !pstate_funcs.get_min() || |
| 2389 | !pstate_funcs.get_turbo()) |
Dirk Brandewie | b563b4e | 2013-03-22 01:29:28 +0100 | [diff] [blame] | 2390 | return -ENODEV; |
| 2391 | |
Dirk Brandewie | b563b4e | 2013-03-22 01:29:28 +0100 | [diff] [blame] | 2392 | return 0; |
| 2393 | } |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 2394 | |
Srinivas Pandruvada | 7f7a516 | 2016-11-14 10:31:11 -0800 | [diff] [blame] | 2395 | #ifdef CONFIG_ACPI |
| 2396 | static void intel_pstate_use_acpi_profile(void) |
| 2397 | { |
Rafael J. Wysocki | 5539534 | 2017-03-22 23:53:54 +0100 | [diff] [blame] | 2398 | switch (acpi_gbl_FADT.preferred_profile) { |
| 2399 | case PM_MOBILE: |
| 2400 | case PM_TABLET: |
| 2401 | case PM_APPLIANCE_PC: |
| 2402 | case PM_DESKTOP: |
| 2403 | case PM_WORKSTATION: |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 2404 | pstate_funcs.update_util = intel_pstate_update_util; |
Rafael J. Wysocki | 5539534 | 2017-03-22 23:53:54 +0100 | [diff] [blame] | 2405 | } |
Srinivas Pandruvada | 7f7a516 | 2016-11-14 10:31:11 -0800 | [diff] [blame] | 2406 | } |
| 2407 | #else |
| 2408 | static void intel_pstate_use_acpi_profile(void) |
| 2409 | { |
| 2410 | } |
| 2411 | #endif |
| 2412 | |
Jisheng Zhang | 29327c8 | 2016-06-27 18:07:17 +0800 | [diff] [blame] | 2413 | static void __init copy_cpu_funcs(struct pstate_funcs *funcs) |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 2414 | { |
| 2415 | pstate_funcs.get_max = funcs->get_max; |
Srinivas Pandruvada | 3bcc6fa | 2015-10-14 16:12:00 -0700 | [diff] [blame] | 2416 | pstate_funcs.get_max_physical = funcs->get_max_physical; |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 2417 | pstate_funcs.get_min = funcs->get_min; |
| 2418 | pstate_funcs.get_turbo = funcs->get_turbo; |
Dirk Brandewie | b27580b | 2014-10-13 08:37:43 -0700 | [diff] [blame] | 2419 | pstate_funcs.get_scaling = funcs->get_scaling; |
Rafael J. Wysocki | fdfdb2b | 2016-03-18 23:20:02 +0100 | [diff] [blame] | 2420 | pstate_funcs.get_val = funcs->get_val; |
Dirk Brandewie | 007bea0 | 2013-12-18 10:32:39 -0800 | [diff] [blame] | 2421 | pstate_funcs.get_vid = funcs->get_vid; |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 2422 | pstate_funcs.update_util = funcs->update_util; |
Philippe Longepe | 157386b | 2015-12-04 17:40:30 +0100 | [diff] [blame] | 2423 | |
Srinivas Pandruvada | 7f7a516 | 2016-11-14 10:31:11 -0800 | [diff] [blame] | 2424 | intel_pstate_use_acpi_profile(); |
Dirk Brandewie | 016c815 | 2013-10-21 09:20:34 -0700 | [diff] [blame] | 2425 | } |
| 2426 | |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 2427 | #ifdef CONFIG_ACPI |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 2428 | |
Jisheng Zhang | 29327c8 | 2016-06-27 18:07:17 +0800 | [diff] [blame] | 2429 | static bool __init intel_pstate_no_acpi_pss(void) |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 2430 | { |
| 2431 | int i; |
| 2432 | |
| 2433 | for_each_possible_cpu(i) { |
| 2434 | acpi_status status; |
| 2435 | union acpi_object *pss; |
| 2436 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 2437 | struct acpi_processor *pr = per_cpu(processors, i); |
| 2438 | |
| 2439 | if (!pr) |
| 2440 | continue; |
| 2441 | |
| 2442 | status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer); |
| 2443 | if (ACPI_FAILURE(status)) |
| 2444 | continue; |
| 2445 | |
| 2446 | pss = buffer.pointer; |
| 2447 | if (pss && pss->type == ACPI_TYPE_PACKAGE) { |
| 2448 | kfree(pss); |
| 2449 | return false; |
| 2450 | } |
| 2451 | |
| 2452 | kfree(pss); |
| 2453 | } |
| 2454 | |
| 2455 | return true; |
| 2456 | } |
| 2457 | |
Jisheng Zhang | 29327c8 | 2016-06-27 18:07:17 +0800 | [diff] [blame] | 2458 | static bool __init intel_pstate_has_acpi_ppc(void) |
ethan zhao | 966916e | 2014-12-01 11:32:08 +0900 | [diff] [blame] | 2459 | { |
| 2460 | int i; |
| 2461 | |
| 2462 | for_each_possible_cpu(i) { |
| 2463 | struct acpi_processor *pr = per_cpu(processors, i); |
| 2464 | |
| 2465 | if (!pr) |
| 2466 | continue; |
| 2467 | if (acpi_has_method(pr->handle, "_PPC")) |
| 2468 | return true; |
| 2469 | } |
| 2470 | return false; |
| 2471 | } |
| 2472 | |
| 2473 | enum { |
| 2474 | PSS, |
| 2475 | PPC, |
| 2476 | }; |
| 2477 | |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 2478 | struct hw_vendor_info { |
| 2479 | u16 valid; |
| 2480 | char oem_id[ACPI_OEM_ID_SIZE]; |
| 2481 | char oem_table_id[ACPI_OEM_TABLE_ID_SIZE]; |
ethan zhao | 966916e | 2014-12-01 11:32:08 +0900 | [diff] [blame] | 2482 | int oem_pwr_table; |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 2483 | }; |
| 2484 | |
| 2485 | /* Hardware vendor-specific info that has its own power management modes */ |
Jisheng Zhang | 29327c8 | 2016-06-27 18:07:17 +0800 | [diff] [blame] | 2486 | static struct hw_vendor_info vendor_info[] __initdata = { |
ethan zhao | 966916e | 2014-12-01 11:32:08 +0900 | [diff] [blame] | 2487 | {1, "HP ", "ProLiant", PSS}, |
| 2488 | {1, "ORACLE", "X4-2 ", PPC}, |
| 2489 | {1, "ORACLE", "X4-2L ", PPC}, |
| 2490 | {1, "ORACLE", "X4-2B ", PPC}, |
| 2491 | {1, "ORACLE", "X3-2 ", PPC}, |
| 2492 | {1, "ORACLE", "X3-2L ", PPC}, |
| 2493 | {1, "ORACLE", "X3-2B ", PPC}, |
| 2494 | {1, "ORACLE", "X4470M2 ", PPC}, |
| 2495 | {1, "ORACLE", "X4270M3 ", PPC}, |
| 2496 | {1, "ORACLE", "X4270M2 ", PPC}, |
| 2497 | {1, "ORACLE", "X4170M2 ", PPC}, |
Ethan Zhao | 5aecc3c | 2015-08-05 09:28:50 +0900 | [diff] [blame] | 2498 | {1, "ORACLE", "X4170 M3", PPC}, |
| 2499 | {1, "ORACLE", "X4275 M3", PPC}, |
| 2500 | {1, "ORACLE", "X6-2 ", PPC}, |
| 2501 | {1, "ORACLE", "Sudbury ", PPC}, |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 2502 | {0, "", ""}, |
| 2503 | }; |
| 2504 | |
Jisheng Zhang | 29327c8 | 2016-06-27 18:07:17 +0800 | [diff] [blame] | 2505 | static bool __init intel_pstate_platform_pwr_mgmt_exists(void) |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 2506 | { |
| 2507 | struct acpi_table_header hdr; |
| 2508 | struct hw_vendor_info *v_info; |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 2509 | const struct x86_cpu_id *id; |
| 2510 | u64 misc_pwr; |
| 2511 | |
| 2512 | id = x86_match_cpu(intel_pstate_cpu_oob_ids); |
| 2513 | if (id) { |
| 2514 | rdmsrl(MSR_MISC_PWR_MGMT, misc_pwr); |
| 2515 | if ( misc_pwr & (1 << 8)) |
| 2516 | return true; |
| 2517 | } |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 2518 | |
Stratos Karafotis | c410833 | 2014-07-18 08:37:23 -0700 | [diff] [blame] | 2519 | if (acpi_disabled || |
| 2520 | ACPI_FAILURE(acpi_get_table_header(ACPI_SIG_FADT, 0, &hdr))) |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 2521 | return false; |
| 2522 | |
| 2523 | for (v_info = vendor_info; v_info->valid; v_info++) { |
Stratos Karafotis | c410833 | 2014-07-18 08:37:23 -0700 | [diff] [blame] | 2524 | if (!strncmp(hdr.oem_id, v_info->oem_id, ACPI_OEM_ID_SIZE) && |
ethan zhao | 966916e | 2014-12-01 11:32:08 +0900 | [diff] [blame] | 2525 | !strncmp(hdr.oem_table_id, v_info->oem_table_id, |
| 2526 | ACPI_OEM_TABLE_ID_SIZE)) |
| 2527 | switch (v_info->oem_pwr_table) { |
| 2528 | case PSS: |
| 2529 | return intel_pstate_no_acpi_pss(); |
| 2530 | case PPC: |
Ethan Zhao | aa4ea34 | 2014-12-09 10:43:19 +0900 | [diff] [blame] | 2531 | return intel_pstate_has_acpi_ppc() && |
| 2532 | (!force_load); |
ethan zhao | 966916e | 2014-12-01 11:32:08 +0900 | [diff] [blame] | 2533 | } |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | return false; |
| 2537 | } |
Rafael J. Wysocki | d0ea59e | 2016-11-17 22:47:47 +0100 | [diff] [blame] | 2538 | |
| 2539 | static void intel_pstate_request_control_from_smm(void) |
| 2540 | { |
| 2541 | /* |
| 2542 | * It may be unsafe to request P-states control from SMM if _PPC support |
| 2543 | * has not been enabled. |
| 2544 | */ |
| 2545 | if (acpi_ppc) |
| 2546 | acpi_processor_pstate_control(); |
| 2547 | } |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 2548 | #else /* CONFIG_ACPI not enabled */ |
| 2549 | static inline bool intel_pstate_platform_pwr_mgmt_exists(void) { return false; } |
ethan zhao | 966916e | 2014-12-01 11:32:08 +0900 | [diff] [blame] | 2550 | static inline bool intel_pstate_has_acpi_ppc(void) { return false; } |
Rafael J. Wysocki | d0ea59e | 2016-11-17 22:47:47 +0100 | [diff] [blame] | 2551 | static inline void intel_pstate_request_control_from_smm(void) {} |
Adrian Huang | fbbcdc0 | 2013-10-31 23:24:05 +0800 | [diff] [blame] | 2552 | #endif /* CONFIG_ACPI */ |
| 2553 | |
Srinivas Pandruvada | 7791e4a | 2016-02-25 15:09:19 -0800 | [diff] [blame] | 2554 | static const struct x86_cpu_id hwp_support_ids[] __initconst = { |
| 2555 | { X86_VENDOR_INTEL, 6, X86_MODEL_ANY, X86_FEATURE_HWP }, |
| 2556 | {} |
| 2557 | }; |
| 2558 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2559 | static int __init intel_pstate_init(void) |
| 2560 | { |
Rafael J. Wysocki | eb5139d | 2017-03-22 23:52:18 +0100 | [diff] [blame] | 2561 | int rc; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2562 | |
Dirk Brandewie | 6be2649 | 2013-02-15 22:55:10 +0100 | [diff] [blame] | 2563 | if (no_load) |
| 2564 | return -ENODEV; |
| 2565 | |
Rafael J. Wysocki | eb5139d | 2017-03-22 23:52:18 +0100 | [diff] [blame] | 2566 | if (x86_match_cpu(hwp_support_ids)) { |
Rafael J. Wysocki | 2f49afc | 2017-03-28 00:19:03 +0200 | [diff] [blame] | 2567 | copy_cpu_funcs(&core_funcs); |
Rafael J. Wysocki | eb5139d | 2017-03-22 23:52:18 +0100 | [diff] [blame] | 2568 | if (no_hwp) { |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 2569 | pstate_funcs.update_util = intel_pstate_update_util; |
Rafael J. Wysocki | eb5139d | 2017-03-22 23:52:18 +0100 | [diff] [blame] | 2570 | } else { |
| 2571 | hwp_active++; |
| 2572 | intel_pstate.attr = hwp_cpufreq_attrs; |
Rafael J. Wysocki | 67dd9bf | 2017-03-28 00:17:10 +0200 | [diff] [blame] | 2573 | pstate_funcs.update_util = intel_pstate_update_util_hwp; |
Rafael J. Wysocki | eb5139d | 2017-03-22 23:52:18 +0100 | [diff] [blame] | 2574 | goto hwp_cpu_matched; |
| 2575 | } |
| 2576 | } else { |
| 2577 | const struct x86_cpu_id *id; |
Rafael J. Wysocki | eb5139d | 2017-03-22 23:52:18 +0100 | [diff] [blame] | 2578 | |
| 2579 | id = x86_match_cpu(intel_pstate_cpu_ids); |
| 2580 | if (!id) |
| 2581 | return -ENODEV; |
| 2582 | |
Rafael J. Wysocki | 2f49afc | 2017-03-28 00:19:03 +0200 | [diff] [blame] | 2583 | copy_cpu_funcs((struct pstate_funcs *)id->driver_data); |
Srinivas Pandruvada | 7791e4a | 2016-02-25 15:09:19 -0800 | [diff] [blame] | 2584 | } |
| 2585 | |
Dirk Brandewie | b563b4e | 2013-03-22 01:29:28 +0100 | [diff] [blame] | 2586 | if (intel_pstate_msrs_not_valid()) |
| 2587 | return -ENODEV; |
| 2588 | |
Srinivas Pandruvada | 7791e4a | 2016-02-25 15:09:19 -0800 | [diff] [blame] | 2589 | hwp_cpu_matched: |
| 2590 | /* |
| 2591 | * The Intel pstate driver will be ignored if the platform |
| 2592 | * firmware has its own power management modes. |
| 2593 | */ |
| 2594 | if (intel_pstate_platform_pwr_mgmt_exists()) |
| 2595 | return -ENODEV; |
| 2596 | |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2597 | if (!hwp_active && hwp_only) |
| 2598 | return -ENOTSUPP; |
| 2599 | |
Joe Perches | 4836df1 | 2016-04-05 13:28:23 -0700 | [diff] [blame] | 2600 | pr_info("Intel P-state driver initializing\n"); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2601 | |
Wei Yongjun | b57ffac | 2013-05-13 08:03:43 +0000 | [diff] [blame] | 2602 | all_cpu_data = vzalloc(sizeof(void *) * num_possible_cpus()); |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2603 | if (!all_cpu_data) |
| 2604 | return -ENOMEM; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2605 | |
Rafael J. Wysocki | d0ea59e | 2016-11-17 22:47:47 +0100 | [diff] [blame] | 2606 | intel_pstate_request_control_from_smm(); |
| 2607 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2608 | intel_pstate_sysfs_expose_params(); |
Dirk Brandewie | b69880f | 2014-01-16 10:32:25 -0800 | [diff] [blame] | 2609 | |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 2610 | mutex_lock(&intel_pstate_driver_lock); |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2611 | rc = intel_pstate_register_driver(default_driver); |
Rafael J. Wysocki | 0c30b65 | 2017-01-11 04:12:16 +0100 | [diff] [blame] | 2612 | mutex_unlock(&intel_pstate_driver_lock); |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2613 | if (rc) |
| 2614 | return rc; |
Dirk Brandewie | 907cc90 | 2013-03-05 14:15:27 -0800 | [diff] [blame] | 2615 | |
Dirk Brandewie | 907cc90 | 2013-03-05 14:15:27 -0800 | [diff] [blame] | 2616 | if (hwp_active) |
| 2617 | pr_info("HWP enabled\n"); |
| 2618 | |
Rafael J. Wysocki | fb1fe10 | 2017-01-05 02:53:12 +0100 | [diff] [blame] | 2619 | return 0; |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2620 | } |
| 2621 | device_initcall(intel_pstate_init); |
| 2622 | |
Dirk Brandewie | 6be2649 | 2013-02-15 22:55:10 +0100 | [diff] [blame] | 2623 | static int __init intel_pstate_setup(char *str) |
| 2624 | { |
| 2625 | if (!str) |
| 2626 | return -EINVAL; |
| 2627 | |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2628 | if (!strcmp(str, "disable")) { |
Dirk Brandewie | 6be2649 | 2013-02-15 22:55:10 +0100 | [diff] [blame] | 2629 | no_load = 1; |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2630 | } else if (!strcmp(str, "passive")) { |
| 2631 | pr_info("Passive mode enabled\n"); |
Rafael J. Wysocki | ee8df89 | 2017-03-28 00:13:00 +0200 | [diff] [blame] | 2632 | default_driver = &intel_cpufreq; |
Rafael J. Wysocki | 001c76f | 2016-11-17 23:34:17 +0100 | [diff] [blame] | 2633 | no_hwp = 1; |
| 2634 | } |
Prarit Bhargava | 539342f | 2015-10-22 09:43:31 -0400 | [diff] [blame] | 2635 | if (!strcmp(str, "no_hwp")) { |
Joe Perches | 4836df1 | 2016-04-05 13:28:23 -0700 | [diff] [blame] | 2636 | pr_info("HWP disabled\n"); |
Dirk Brandewie | 2f86dc4 | 2014-11-06 09:40:47 -0800 | [diff] [blame] | 2637 | no_hwp = 1; |
Prarit Bhargava | 539342f | 2015-10-22 09:43:31 -0400 | [diff] [blame] | 2638 | } |
Ethan Zhao | aa4ea34 | 2014-12-09 10:43:19 +0900 | [diff] [blame] | 2639 | if (!strcmp(str, "force")) |
| 2640 | force_load = 1; |
Kristen Carlson Accardi | d64c3b0 | 2015-02-06 13:41:55 -0800 | [diff] [blame] | 2641 | if (!strcmp(str, "hwp_only")) |
| 2642 | hwp_only = 1; |
Srinivas Pandruvada | eae48f0 | 2016-10-25 13:20:40 -0700 | [diff] [blame] | 2643 | if (!strcmp(str, "per_cpu_perf_limits")) |
| 2644 | per_cpu_limits = true; |
Srinivas Pandruvada | 9522a2f | 2016-04-27 15:48:06 -0700 | [diff] [blame] | 2645 | |
| 2646 | #ifdef CONFIG_ACPI |
| 2647 | if (!strcmp(str, "support_acpi_ppc")) |
| 2648 | acpi_ppc = true; |
| 2649 | #endif |
| 2650 | |
Dirk Brandewie | 6be2649 | 2013-02-15 22:55:10 +0100 | [diff] [blame] | 2651 | return 0; |
| 2652 | } |
| 2653 | early_param("intel_pstate", intel_pstate_setup); |
| 2654 | |
Dirk Brandewie | 93f0822 | 2013-02-06 09:02:13 -0800 | [diff] [blame] | 2655 | MODULE_AUTHOR("Dirk Brandewie <dirk.j.brandewie@intel.com>"); |
| 2656 | MODULE_DESCRIPTION("'intel_pstate' - P state driver Intel Core processors"); |
| 2657 | MODULE_LICENSE("GPL"); |