blob: 0837175395b90420440efc126129aeba46408828 [file] [log] [blame]
Dirk Brandewie93f08222013-02-06 09:02:13 -08001/*
Srinivas Pandruvadad1b68482013-04-09 22:38:18 +00002 * intel_pstate.c: Native P state management for Intel processors
Dirk Brandewie93f08222013-02-06 09:02:13 -08003 *
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 Perches4836df12016-04-05 13:28:23 -070013#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
Dirk Brandewie93f08222013-02-06 09:02:13 -080015#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>
22#include <linux/sched.h>
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 Huangfbbcdc02013-10-31 23:24:05 +080030#include <linux/acpi.h>
Stephen Rothwelld6472302015-06-02 19:01:38 +100031#include <linux/vmalloc.h>
Dirk Brandewie93f08222013-02-06 09:02:13 -080032#include <trace/events/power.h>
33
34#include <asm/div64.h>
35#include <asm/msr.h>
36#include <asm/cpu_device_id.h>
Borislav Petkov64df1fd2015-04-03 15:19:53 +020037#include <asm/cpufeature.h>
Dave Hansen5b20c942016-06-02 17:19:45 -070038#include <asm/intel-family.h>
Dirk Brandewie93f08222013-02-06 09:02:13 -080039
Philippe Longepe938d21a2015-11-09 17:40:46 -080040#define ATOM_RATIOS 0x66a
41#define ATOM_VIDS 0x66b
42#define ATOM_TURBO_RATIOS 0x66c
43#define ATOM_TURBO_VIDS 0x66d
Dirk Brandewie61d8d2a2014-02-12 10:01:07 -080044
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -070045#ifdef CONFIG_ACPI
46#include <acpi/processor.h>
47#endif
48
Dirk Brandewief0fe3cd2014-05-29 09:32:23 -070049#define FRAC_BITS 8
Dirk Brandewie93f08222013-02-06 09:02:13 -080050#define int_tofp(X) ((int64_t)(X) << FRAC_BITS)
51#define fp_toint(X) ((X) >> FRAC_BITS)
Dirk Brandewief0fe3cd2014-05-29 09:32:23 -070052
Rafael J. Wysockia1c97872016-05-11 19:09:12 +020053#define EXT_BITS 6
54#define EXT_FRAC_BITS (EXT_BITS + FRAC_BITS)
55
Dirk Brandewie93f08222013-02-06 09:02:13 -080056static inline int32_t mul_fp(int32_t x, int32_t y)
57{
58 return ((int64_t)x * (int64_t)y) >> FRAC_BITS;
59}
60
Prarit Bhargava7180ddd2015-06-15 13:43:29 -040061static inline int32_t div_fp(s64 x, s64 y)
Dirk Brandewie93f08222013-02-06 09:02:13 -080062{
Prarit Bhargava7180ddd2015-06-15 13:43:29 -040063 return div64_s64((int64_t)x << FRAC_BITS, y);
Dirk Brandewie93f08222013-02-06 09:02:13 -080064}
65
Dirk Brandewied022a652014-10-13 08:37:44 -070066static inline int ceiling_fp(int32_t x)
67{
68 int mask, ret;
69
70 ret = fp_toint(x);
71 mask = (1 << FRAC_BITS) - 1;
72 if (x & mask)
73 ret += 1;
74 return ret;
75}
76
Rafael J. Wysockia1c97872016-05-11 19:09:12 +020077static inline u64 mul_ext_fp(u64 x, u64 y)
78{
79 return (x * y) >> EXT_FRAC_BITS;
80}
81
82static inline u64 div_ext_fp(u64 x, u64 y)
83{
84 return div64_u64(x << EXT_FRAC_BITS, y);
85}
86
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -070087/**
88 * struct sample - Store performance sample
Rafael J. Wysockia1c97872016-05-11 19:09:12 +020089 * @core_avg_perf: Ratio of APERF/MPERF which is the actual average
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -070090 * performance during last sample period
91 * @busy_scaled: Scaled busy value which is used to calculate next
Rafael J. Wysockia1c97872016-05-11 19:09:12 +020092 * P state. This can be different than core_avg_perf
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -070093 * to account for cpu idle period
94 * @aperf: Difference of actual performance frequency clock count
95 * read from APERF MSR between last and current sample
96 * @mperf: Difference of maximum performance frequency clock count
97 * read from MPERF MSR between last and current sample
98 * @tsc: Difference of time stamp counter between last and
99 * current sample
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700100 * @time: Current time from scheduler
101 *
102 * This structure is used in the cpudata structure to store performance sample
103 * data for choosing next P State.
104 */
Dirk Brandewie93f08222013-02-06 09:02:13 -0800105struct sample {
Rafael J. Wysockia1c97872016-05-11 19:09:12 +0200106 int32_t core_avg_perf;
Philippe Longepe157386b2015-12-04 17:40:30 +0100107 int32_t busy_scaled;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800108 u64 aperf;
109 u64 mperf;
Doug Smythies4055fad2015-04-11 21:10:26 -0700110 u64 tsc;
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +0100111 u64 time;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800112};
113
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700114/**
115 * struct pstate_data - Store P state data
116 * @current_pstate: Current requested P state
117 * @min_pstate: Min P state possible for this platform
118 * @max_pstate: Max P state possible for this platform
119 * @max_pstate_physical:This is physical Max P state for a processor
120 * This can be higher than the max_pstate which can
121 * be limited by platform thermal design power limits
122 * @scaling: Scaling factor to convert frequency to cpufreq
123 * frequency units
124 * @turbo_pstate: Max Turbo P state possible for this platform
125 *
126 * Stores the per cpu model P state limits and current P state.
127 */
Dirk Brandewie93f08222013-02-06 09:02:13 -0800128struct pstate_data {
129 int current_pstate;
130 int min_pstate;
131 int max_pstate;
Srinivas Pandruvada3bcc6fa2015-10-14 16:12:00 -0700132 int max_pstate_physical;
Dirk Brandewieb27580b2014-10-13 08:37:43 -0700133 int scaling;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800134 int turbo_pstate;
135};
136
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700137/**
138 * struct vid_data - Stores voltage information data
139 * @min: VID data for this platform corresponding to
140 * the lowest P state
141 * @max: VID data corresponding to the highest P State.
142 * @turbo: VID data for turbo P state
143 * @ratio: Ratio of (vid max - vid min) /
144 * (max P state - Min P State)
145 *
146 * Stores the voltage data for DVFS (Dynamic Voltage and Frequency Scaling)
147 * This data is used in Atom platforms, where in addition to target P state,
148 * the voltage data needs to be specified to select next P State.
149 */
Dirk Brandewie007bea02013-12-18 10:32:39 -0800150struct vid_data {
Dirk Brandewie21855ff2014-05-08 12:57:23 -0700151 int min;
152 int max;
153 int turbo;
Dirk Brandewie007bea02013-12-18 10:32:39 -0800154 int32_t ratio;
155};
156
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700157/**
158 * struct _pid - Stores PID data
159 * @setpoint: Target set point for busyness or performance
160 * @integral: Storage for accumulated error values
161 * @p_gain: PID proportional gain
162 * @i_gain: PID integral gain
163 * @d_gain: PID derivative gain
164 * @deadband: PID deadband
165 * @last_err: Last error storage for integral part of PID calculation
166 *
167 * Stores PID coefficients and last error for PID controller.
168 */
Dirk Brandewie93f08222013-02-06 09:02:13 -0800169struct _pid {
170 int setpoint;
171 int32_t integral;
172 int32_t p_gain;
173 int32_t i_gain;
174 int32_t d_gain;
175 int deadband;
Brennan Shacklettd253d2a2013-10-21 09:20:32 -0700176 int32_t last_err;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800177};
178
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700179/**
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -0700180 * struct perf_limits - Store user and policy limits
181 * @no_turbo: User requested turbo state from intel_pstate sysfs
182 * @turbo_disabled: Platform turbo status either from msr
183 * MSR_IA32_MISC_ENABLE or when maximum available pstate
184 * matches the maximum turbo pstate
185 * @max_perf_pct: Effective maximum performance limit in percentage, this
186 * is minimum of either limits enforced by cpufreq policy
187 * or limits from user set limits via intel_pstate sysfs
188 * @min_perf_pct: Effective minimum performance limit in percentage, this
189 * is maximum of either limits enforced by cpufreq policy
190 * or limits from user set limits via intel_pstate sysfs
191 * @max_perf: This is a scaled value between 0 to 255 for max_perf_pct
192 * This value is used to limit max pstate
193 * @min_perf: This is a scaled value between 0 to 255 for min_perf_pct
194 * This value is used to limit min pstate
195 * @max_policy_pct: The maximum performance in percentage enforced by
196 * cpufreq setpolicy interface
197 * @max_sysfs_pct: The maximum performance in percentage enforced by
198 * intel pstate sysfs interface, unused when per cpu
199 * controls are enforced
200 * @min_policy_pct: The minimum performance in percentage enforced by
201 * cpufreq setpolicy interface
202 * @min_sysfs_pct: The minimum performance in percentage enforced by
203 * intel pstate sysfs interface, unused when per cpu
204 * controls are enforced
205 *
206 * Storage for user and policy defined limits.
207 */
208struct perf_limits {
209 int no_turbo;
210 int turbo_disabled;
211 int max_perf_pct;
212 int min_perf_pct;
213 int32_t max_perf;
214 int32_t min_perf;
215 int max_policy_pct;
216 int max_sysfs_pct;
217 int min_policy_pct;
218 int min_sysfs_pct;
219};
220
221/**
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700222 * struct cpudata - Per CPU instance data storage
223 * @cpu: CPU number for this instance data
Rafael J. Wysocki2f1d4072016-10-24 23:20:25 +0200224 * @policy: CPUFreq policy value
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700225 * @update_util: CPUFreq utility callback information
Chen Yu4578ee7e2016-05-11 14:33:08 +0800226 * @update_util_set: CPUFreq utility callback is set
Rafael J. Wysocki09c448d2016-09-14 02:28:13 +0200227 * @iowait_boost: iowait-related boost fraction
228 * @last_update: Time of the last update.
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700229 * @pstate: Stores P state limits for this CPU
230 * @vid: Stores VID limits for this CPU
231 * @pid: Stores PID parameters for this CPU
232 * @last_sample_time: Last Sample time
233 * @prev_aperf: Last APERF value read from APERF MSR
234 * @prev_mperf: Last MPERF value read from MPERF MSR
235 * @prev_tsc: Last timestamp counter (TSC) value
236 * @prev_cummulative_iowait: IO Wait time difference from last and
237 * current sample
238 * @sample: Storage for storing last Sample data
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -0700239 * @perf_limits: Pointer to perf_limit unique to this CPU
240 * Not all field in the structure are applicable
241 * when per cpu controls are enforced
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -0700242 * @acpi_perf_data: Stores ACPI perf information read from _PSS
243 * @valid_pss_table: Set to true for valid ACPI _PSS entries found
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700244 *
245 * This structure stores per CPU instance data for all CPUs.
246 */
Dirk Brandewie93f08222013-02-06 09:02:13 -0800247struct cpudata {
248 int cpu;
249
Rafael J. Wysocki2f1d4072016-10-24 23:20:25 +0200250 unsigned int policy;
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +0100251 struct update_util_data update_util;
Chen Yu4578ee7e2016-05-11 14:33:08 +0800252 bool update_util_set;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800253
Dirk Brandewie93f08222013-02-06 09:02:13 -0800254 struct pstate_data pstate;
Dirk Brandewie007bea02013-12-18 10:32:39 -0800255 struct vid_data vid;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800256 struct _pid pid;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800257
Rafael J. Wysocki09c448d2016-09-14 02:28:13 +0200258 u64 last_update;
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +0100259 u64 last_sample_time;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800260 u64 prev_aperf;
261 u64 prev_mperf;
Doug Smythies4055fad2015-04-11 21:10:26 -0700262 u64 prev_tsc;
Philippe Longepe63d1d652015-12-04 17:40:35 +0100263 u64 prev_cummulative_iowait;
Dirk Brandewied37e2b72014-02-12 10:01:04 -0800264 struct sample sample;
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -0700265 struct perf_limits *perf_limits;
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -0700266#ifdef CONFIG_ACPI
267 struct acpi_processor_performance acpi_perf_data;
268 bool valid_pss_table;
269#endif
Rafael J. Wysocki09c448d2016-09-14 02:28:13 +0200270 unsigned int iowait_boost;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800271};
272
273static struct cpudata **all_cpu_data;
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700274
275/**
Rafael J. Wysocki39545172016-10-11 23:07:38 +0200276 * struct pstate_adjust_policy - Stores static PID configuration data
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700277 * @sample_rate_ms: PID calculation sample rate in ms
278 * @sample_rate_ns: Sample rate calculation in ns
279 * @deadband: PID deadband
280 * @setpoint: PID Setpoint
281 * @p_gain_pct: PID proportional gain
282 * @i_gain_pct: PID integral gain
283 * @d_gain_pct: PID derivative gain
284 *
285 * Stores per CPU model static PID configuration data.
286 */
Dirk Brandewie93f08222013-02-06 09:02:13 -0800287struct pstate_adjust_policy {
288 int sample_rate_ms;
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +0100289 s64 sample_rate_ns;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800290 int deadband;
291 int setpoint;
292 int p_gain_pct;
293 int d_gain_pct;
294 int i_gain_pct;
295};
296
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700297/**
298 * struct pstate_funcs - Per CPU model specific callbacks
299 * @get_max: Callback to get maximum non turbo effective P state
300 * @get_max_physical: Callback to get maximum non turbo physical P state
301 * @get_min: Callback to get minimum P state
302 * @get_turbo: Callback to get turbo P state
303 * @get_scaling: Callback to get frequency scaling factor
304 * @get_val: Callback to convert P state to actual MSR write value
305 * @get_vid: Callback to get VID data for Atom platforms
306 * @get_target_pstate: Callback to a function to calculate next P state to use
307 *
308 * Core and Atom CPU models have different way to get P State limits. This
309 * structure is used to store those callbacks.
310 */
Dirk Brandewie016c8152013-10-21 09:20:34 -0700311struct pstate_funcs {
312 int (*get_max)(void);
Srinivas Pandruvada3bcc6fa2015-10-14 16:12:00 -0700313 int (*get_max_physical)(void);
Dirk Brandewie016c8152013-10-21 09:20:34 -0700314 int (*get_min)(void);
315 int (*get_turbo)(void);
Dirk Brandewieb27580b2014-10-13 08:37:43 -0700316 int (*get_scaling)(void);
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +0100317 u64 (*get_val)(struct cpudata*, int pstate);
Dirk Brandewie007bea02013-12-18 10:32:39 -0800318 void (*get_vid)(struct cpudata *);
Philippe Longepe157386b2015-12-04 17:40:30 +0100319 int32_t (*get_target_pstate)(struct cpudata *);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800320};
321
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700322/**
323 * struct cpu_defaults- Per CPU model default config data
324 * @pid_policy: PID config data
325 * @funcs: Callback function data
326 */
Dirk Brandewie016c8152013-10-21 09:20:34 -0700327struct cpu_defaults {
328 struct pstate_adjust_policy pid_policy;
329 struct pstate_funcs funcs;
330};
331
Philippe Longepe157386b2015-12-04 17:40:30 +0100332static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu);
Philippe Longepee70eed22015-12-04 17:40:32 +0100333static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu);
Philippe Longepe157386b2015-12-04 17:40:30 +0100334
Jisheng Zhang4a7cb7a2016-06-27 18:07:18 +0800335static struct pstate_adjust_policy pid_params __read_mostly;
336static struct pstate_funcs pstate_funcs __read_mostly;
337static int hwp_active __read_mostly;
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -0700338static bool per_cpu_limits __read_mostly;
Dirk Brandewie016c8152013-10-21 09:20:34 -0700339
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -0700340#ifdef CONFIG_ACPI
341static bool acpi_ppc;
342#endif
Srinivas Pandruvada13ad7702016-04-03 13:06:46 -0700343
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400344static struct perf_limits performance_limits = {
345 .no_turbo = 0,
346 .turbo_disabled = 0,
347 .max_perf_pct = 100,
348 .max_perf = int_tofp(1),
349 .min_perf_pct = 100,
350 .min_perf = int_tofp(1),
351 .max_policy_pct = 100,
352 .max_sysfs_pct = 100,
353 .min_policy_pct = 0,
354 .min_sysfs_pct = 0,
355};
356
357static struct perf_limits powersave_limits = {
Dirk Brandewie93f08222013-02-06 09:02:13 -0800358 .no_turbo = 0,
Gabriele Mazzotta4521e1a02014-10-13 08:37:41 -0700359 .turbo_disabled = 0,
Dirk Brandewie93f08222013-02-06 09:02:13 -0800360 .max_perf_pct = 100,
361 .max_perf = int_tofp(1),
362 .min_perf_pct = 0,
363 .min_perf = 0,
Dirk Brandewied8f469e2013-05-07 08:20:26 -0700364 .max_policy_pct = 100,
365 .max_sysfs_pct = 100,
Kristen Carlson Accardia0475992015-01-29 13:03:52 -0800366 .min_policy_pct = 0,
367 .min_sysfs_pct = 0,
Dirk Brandewie93f08222013-02-06 09:02:13 -0800368};
369
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400370#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
371static struct perf_limits *limits = &performance_limits;
372#else
373static struct perf_limits *limits = &powersave_limits;
374#endif
375
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -0700376static DEFINE_MUTEX(intel_pstate_limits_lock);
377
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -0700378#ifdef CONFIG_ACPI
Srinivas Pandruvada2b3ec762016-04-27 15:48:08 -0700379
380static bool intel_pstate_get_ppc_enable_status(void)
381{
382 if (acpi_gbl_FADT.preferred_profile == PM_ENTERPRISE_SERVER ||
383 acpi_gbl_FADT.preferred_profile == PM_PERFORMANCE_SERVER)
384 return true;
385
386 return acpi_ppc;
387}
388
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -0700389static void intel_pstate_init_acpi_perf_limits(struct cpufreq_policy *policy)
390{
391 struct cpudata *cpu;
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -0700392 int ret;
393 int i;
394
Srinivas Pandruvadae59a8f72016-05-04 15:07:34 -0700395 if (hwp_active)
396 return;
397
Srinivas Pandruvada2b3ec762016-04-27 15:48:08 -0700398 if (!intel_pstate_get_ppc_enable_status())
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -0700399 return;
400
401 cpu = all_cpu_data[policy->cpu];
402
403 ret = acpi_processor_register_performance(&cpu->acpi_perf_data,
404 policy->cpu);
405 if (ret)
406 return;
407
408 /*
409 * Check if the control value in _PSS is for PERF_CTL MSR, which should
410 * guarantee that the states returned by it map to the states in our
411 * list directly.
412 */
413 if (cpu->acpi_perf_data.control_register.space_id !=
414 ACPI_ADR_SPACE_FIXED_HARDWARE)
415 goto err;
416
417 /*
418 * If there is only one entry _PSS, simply ignore _PSS and continue as
419 * usual without taking _PSS into account
420 */
421 if (cpu->acpi_perf_data.state_count < 2)
422 goto err;
423
424 pr_debug("CPU%u - ACPI _PSS perf data\n", policy->cpu);
425 for (i = 0; i < cpu->acpi_perf_data.state_count; i++) {
426 pr_debug(" %cP%d: %u MHz, %u mW, 0x%x\n",
427 (i == cpu->acpi_perf_data.state ? '*' : ' '), i,
428 (u32) cpu->acpi_perf_data.states[i].core_frequency,
429 (u32) cpu->acpi_perf_data.states[i].power,
430 (u32) cpu->acpi_perf_data.states[i].control);
431 }
432
433 /*
434 * The _PSS table doesn't contain whole turbo frequency range.
435 * This just contains +1 MHZ above the max non turbo frequency,
436 * with control value corresponding to max turbo ratio. But
437 * when cpufreq set policy is called, it will call with this
438 * max frequency, which will cause a reduced performance as
439 * this driver uses real max turbo frequency as the max
440 * frequency. So correct this frequency in _PSS table to
Srinivas Pandruvadab00345d2016-06-14 23:12:59 -0700441 * correct max turbo frequency based on the turbo state.
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -0700442 * Also need to convert to MHz as _PSS freq is in MHz.
443 */
Srinivas Pandruvadab00345d2016-06-14 23:12:59 -0700444 if (!limits->turbo_disabled)
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -0700445 cpu->acpi_perf_data.states[0].core_frequency =
446 policy->cpuinfo.max_freq / 1000;
447 cpu->valid_pss_table = true;
Srinivas Pandruvada6cacd112016-05-29 23:31:23 -0700448 pr_debug("_PPC limits will be enforced\n");
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -0700449
450 return;
451
452 err:
453 cpu->valid_pss_table = false;
454 acpi_processor_unregister_performance(policy->cpu);
455}
456
457static void intel_pstate_exit_perf_limits(struct cpufreq_policy *policy)
458{
459 struct cpudata *cpu;
460
461 cpu = all_cpu_data[policy->cpu];
462 if (!cpu->valid_pss_table)
463 return;
464
465 acpi_processor_unregister_performance(policy->cpu);
466}
467
468#else
469static void intel_pstate_init_acpi_perf_limits(struct cpufreq_policy *policy)
470{
471}
472
473static void intel_pstate_exit_perf_limits(struct cpufreq_policy *policy)
474{
475}
476#endif
477
Dirk Brandewie93f08222013-02-06 09:02:13 -0800478static inline void pid_reset(struct _pid *pid, int setpoint, int busy,
Stratos Karafotisc4108332014-07-18 08:37:23 -0700479 int deadband, int integral) {
Philippe Longepeb54a0df2016-03-08 10:31:14 +0100480 pid->setpoint = int_tofp(setpoint);
481 pid->deadband = int_tofp(deadband);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800482 pid->integral = int_tofp(integral);
Dirk Brandewied98d0992014-02-12 10:01:05 -0800483 pid->last_err = int_tofp(setpoint) - int_tofp(busy);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800484}
485
486static inline void pid_p_gain_set(struct _pid *pid, int percent)
487{
Rafael J. Wysocki22590ef2016-04-09 01:25:58 +0200488 pid->p_gain = div_fp(percent, 100);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800489}
490
491static inline void pid_i_gain_set(struct _pid *pid, int percent)
492{
Rafael J. Wysocki22590ef2016-04-09 01:25:58 +0200493 pid->i_gain = div_fp(percent, 100);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800494}
495
496static inline void pid_d_gain_set(struct _pid *pid, int percent)
497{
Rafael J. Wysocki22590ef2016-04-09 01:25:58 +0200498 pid->d_gain = div_fp(percent, 100);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800499}
500
Brennan Shacklettd253d2a2013-10-21 09:20:32 -0700501static signed int pid_calc(struct _pid *pid, int32_t busy)
Dirk Brandewie93f08222013-02-06 09:02:13 -0800502{
Brennan Shacklettd253d2a2013-10-21 09:20:32 -0700503 signed int result;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800504 int32_t pterm, dterm, fp_error;
505 int32_t integral_limit;
506
Philippe Longepeb54a0df2016-03-08 10:31:14 +0100507 fp_error = pid->setpoint - busy;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800508
Philippe Longepeb54a0df2016-03-08 10:31:14 +0100509 if (abs(fp_error) <= pid->deadband)
Dirk Brandewie93f08222013-02-06 09:02:13 -0800510 return 0;
511
512 pterm = mul_fp(pid->p_gain, fp_error);
513
514 pid->integral += fp_error;
515
Kristen Carlson Accardie0d4c8f2014-12-10 12:39:38 -0800516 /*
517 * We limit the integral here so that it will never
518 * get higher than 30. This prevents it from becoming
519 * too large an input over long periods of time and allows
520 * it to get factored out sooner.
521 *
522 * The value of 30 was chosen through experimentation.
523 */
Dirk Brandewie93f08222013-02-06 09:02:13 -0800524 integral_limit = int_tofp(30);
525 if (pid->integral > integral_limit)
526 pid->integral = integral_limit;
527 if (pid->integral < -integral_limit)
528 pid->integral = -integral_limit;
529
Brennan Shacklettd253d2a2013-10-21 09:20:32 -0700530 dterm = mul_fp(pid->d_gain, fp_error - pid->last_err);
531 pid->last_err = fp_error;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800532
533 result = pterm + mul_fp(pid->integral, pid->i_gain) + dterm;
Doug Smythies51d211e2014-06-17 13:36:10 -0700534 result = result + (1 << (FRAC_BITS-1));
Dirk Brandewie93f08222013-02-06 09:02:13 -0800535 return (signed int)fp_toint(result);
536}
537
538static inline void intel_pstate_busy_pid_reset(struct cpudata *cpu)
539{
Dirk Brandewie016c8152013-10-21 09:20:34 -0700540 pid_p_gain_set(&cpu->pid, pid_params.p_gain_pct);
541 pid_d_gain_set(&cpu->pid, pid_params.d_gain_pct);
542 pid_i_gain_set(&cpu->pid, pid_params.i_gain_pct);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800543
Stratos Karafotis2d8d1f12014-07-18 08:37:20 -0700544 pid_reset(&cpu->pid, pid_params.setpoint, 100, pid_params.deadband, 0);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800545}
546
Dirk Brandewie93f08222013-02-06 09:02:13 -0800547static inline void intel_pstate_reset_all_pid(void)
548{
549 unsigned int cpu;
Stratos Karafotis845c1cb2014-07-18 08:37:19 -0700550
Dirk Brandewie93f08222013-02-06 09:02:13 -0800551 for_each_online_cpu(cpu) {
552 if (all_cpu_data[cpu])
553 intel_pstate_busy_pid_reset(all_cpu_data[cpu]);
554 }
555}
556
Gabriele Mazzotta4521e1a02014-10-13 08:37:41 -0700557static inline void update_turbo_state(void)
558{
559 u64 misc_en;
560 struct cpudata *cpu;
561
562 cpu = all_cpu_data[0];
563 rdmsrl(MSR_IA32_MISC_ENABLE, misc_en);
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400564 limits->turbo_disabled =
Gabriele Mazzotta4521e1a02014-10-13 08:37:41 -0700565 (misc_en & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ||
566 cpu->pstate.max_pstate == cpu->pstate.turbo_pstate);
567}
568
Viresh Kumar41cfd642016-02-22 10:27:46 +0530569static void intel_pstate_hwp_set(const struct cpumask *cpumask)
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800570{
Kristen Carlson Accardi74da56c2015-09-09 11:41:22 -0700571 int min, hw_min, max, hw_max, cpu, range, adj_range;
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -0700572 struct perf_limits *perf_limits = limits;
Kristen Carlson Accardi74da56c2015-09-09 11:41:22 -0700573 u64 value, cap;
574
Viresh Kumar41cfd642016-02-22 10:27:46 +0530575 for_each_cpu(cpu, cpumask) {
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -0700576 int max_perf_pct, min_perf_pct;
577
578 if (per_cpu_limits)
579 perf_limits = all_cpu_data[cpu]->perf_limits;
580
Srinivas Pandruvadaf9f48722016-10-08 12:42:38 -0700581 rdmsrl_on_cpu(cpu, MSR_HWP_CAPABILITIES, &cap);
582 hw_min = HWP_LOWEST_PERF(cap);
583 hw_max = HWP_HIGHEST_PERF(cap);
584 range = hw_max - hw_min;
585
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -0700586 max_perf_pct = perf_limits->max_perf_pct;
587 min_perf_pct = perf_limits->min_perf_pct;
588
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800589 rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value);
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -0700590 adj_range = min_perf_pct * range / 100;
Kristen Carlson Accardi74da56c2015-09-09 11:41:22 -0700591 min = hw_min + adj_range;
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800592 value &= ~HWP_MIN_PERF(~0L);
593 value |= HWP_MIN_PERF(min);
594
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -0700595 adj_range = max_perf_pct * range / 100;
Kristen Carlson Accardi74da56c2015-09-09 11:41:22 -0700596 max = hw_min + adj_range;
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400597 if (limits->no_turbo) {
Kristen Carlson Accardi74da56c2015-09-09 11:41:22 -0700598 hw_max = HWP_GUARANTEED_PERF(cap);
599 if (hw_max < max)
600 max = hw_max;
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800601 }
602
603 value &= ~HWP_MAX_PERF(~0L);
604 value |= HWP_MAX_PERF(max);
605 wrmsrl_on_cpu(cpu, MSR_HWP_REQUEST, value);
606 }
Viresh Kumar41cfd642016-02-22 10:27:46 +0530607}
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800608
Rafael J. Wysockiba41e1b2016-05-02 02:27:19 +0200609static int intel_pstate_hwp_set_policy(struct cpufreq_policy *policy)
610{
611 if (hwp_active)
612 intel_pstate_hwp_set(policy->cpus);
613
614 return 0;
615}
616
Viresh Kumar41cfd642016-02-22 10:27:46 +0530617static void intel_pstate_hwp_set_online_cpus(void)
618{
619 get_online_cpus();
620 intel_pstate_hwp_set(cpu_online_mask);
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800621 put_online_cpus();
622}
623
Dirk Brandewie93f08222013-02-06 09:02:13 -0800624/************************** debugfs begin ************************/
625static int pid_param_set(void *data, u64 val)
626{
627 *(u32 *)data = val;
628 intel_pstate_reset_all_pid();
629 return 0;
630}
Stratos Karafotis845c1cb2014-07-18 08:37:19 -0700631
Dirk Brandewie93f08222013-02-06 09:02:13 -0800632static int pid_param_get(void *data, u64 *val)
633{
634 *val = *(u32 *)data;
635 return 0;
636}
Stratos Karafotis2d8d1f12014-07-18 08:37:20 -0700637DEFINE_SIMPLE_ATTRIBUTE(fops_pid_param, pid_param_get, pid_param_set, "%llu\n");
Dirk Brandewie93f08222013-02-06 09:02:13 -0800638
639struct pid_param {
640 char *name;
641 void *value;
642};
643
644static struct pid_param pid_files[] = {
Dirk Brandewie016c8152013-10-21 09:20:34 -0700645 {"sample_rate_ms", &pid_params.sample_rate_ms},
646 {"d_gain_pct", &pid_params.d_gain_pct},
647 {"i_gain_pct", &pid_params.i_gain_pct},
648 {"deadband", &pid_params.deadband},
649 {"setpoint", &pid_params.setpoint},
650 {"p_gain_pct", &pid_params.p_gain_pct},
Dirk Brandewie93f08222013-02-06 09:02:13 -0800651 {NULL, NULL}
652};
653
Stratos Karafotis317dd502014-07-18 08:37:17 -0700654static void __init intel_pstate_debug_expose_params(void)
Dirk Brandewie93f08222013-02-06 09:02:13 -0800655{
Stratos Karafotis317dd502014-07-18 08:37:17 -0700656 struct dentry *debugfs_parent;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800657 int i = 0;
658
Srinivas Pandruvada185d8242016-10-21 09:38:20 -0700659 if (hwp_active ||
660 pstate_funcs.get_target_pstate == get_target_pstate_use_cpu_load)
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800661 return;
Srinivas Pandruvada185d8242016-10-21 09:38:20 -0700662
Dirk Brandewie93f08222013-02-06 09:02:13 -0800663 debugfs_parent = debugfs_create_dir("pstate_snb", NULL);
664 if (IS_ERR_OR_NULL(debugfs_parent))
665 return;
666 while (pid_files[i].name) {
667 debugfs_create_file(pid_files[i].name, 0660,
Stratos Karafotisc4108332014-07-18 08:37:23 -0700668 debugfs_parent, pid_files[i].value,
669 &fops_pid_param);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800670 i++;
671 }
672}
673
674/************************** debugfs end ************************/
675
676/************************** sysfs begin ************************/
677#define show_one(file_name, object) \
678 static ssize_t show_##file_name \
679 (struct kobject *kobj, struct attribute *attr, char *buf) \
680 { \
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400681 return sprintf(buf, "%u\n", limits->object); \
Dirk Brandewie93f08222013-02-06 09:02:13 -0800682 }
683
Kristen Carlson Accardid01b1f42015-01-28 15:03:27 -0800684static ssize_t show_turbo_pct(struct kobject *kobj,
685 struct attribute *attr, char *buf)
686{
687 struct cpudata *cpu;
688 int total, no_turbo, turbo_pct;
689 uint32_t turbo_fp;
690
691 cpu = all_cpu_data[0];
692
693 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1;
694 no_turbo = cpu->pstate.max_pstate - cpu->pstate.min_pstate + 1;
Rafael J. Wysocki22590ef2016-04-09 01:25:58 +0200695 turbo_fp = div_fp(no_turbo, total);
Kristen Carlson Accardid01b1f42015-01-28 15:03:27 -0800696 turbo_pct = 100 - fp_toint(mul_fp(turbo_fp, int_tofp(100)));
697 return sprintf(buf, "%u\n", turbo_pct);
698}
699
Kristen Carlson Accardi05224242015-01-28 15:03:28 -0800700static ssize_t show_num_pstates(struct kobject *kobj,
701 struct attribute *attr, char *buf)
702{
703 struct cpudata *cpu;
704 int total;
705
706 cpu = all_cpu_data[0];
707 total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1;
708 return sprintf(buf, "%u\n", total);
709}
710
Gabriele Mazzotta4521e1a02014-10-13 08:37:41 -0700711static ssize_t show_no_turbo(struct kobject *kobj,
712 struct attribute *attr, char *buf)
713{
714 ssize_t ret;
715
716 update_turbo_state();
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400717 if (limits->turbo_disabled)
718 ret = sprintf(buf, "%u\n", limits->turbo_disabled);
Gabriele Mazzotta4521e1a02014-10-13 08:37:41 -0700719 else
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400720 ret = sprintf(buf, "%u\n", limits->no_turbo);
Gabriele Mazzotta4521e1a02014-10-13 08:37:41 -0700721
722 return ret;
723}
724
Dirk Brandewie93f08222013-02-06 09:02:13 -0800725static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
Stratos Karafotisc4108332014-07-18 08:37:23 -0700726 const char *buf, size_t count)
Dirk Brandewie93f08222013-02-06 09:02:13 -0800727{
728 unsigned int input;
729 int ret;
Stratos Karafotis845c1cb2014-07-18 08:37:19 -0700730
Dirk Brandewie93f08222013-02-06 09:02:13 -0800731 ret = sscanf(buf, "%u", &input);
732 if (ret != 1)
733 return -EINVAL;
Gabriele Mazzotta4521e1a02014-10-13 08:37:41 -0700734
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -0700735 mutex_lock(&intel_pstate_limits_lock);
736
Gabriele Mazzotta4521e1a02014-10-13 08:37:41 -0700737 update_turbo_state();
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400738 if (limits->turbo_disabled) {
Joe Perches4836df12016-04-05 13:28:23 -0700739 pr_warn("Turbo disabled by BIOS or unavailable on processor\n");
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -0700740 mutex_unlock(&intel_pstate_limits_lock);
Gabriele Mazzotta4521e1a02014-10-13 08:37:41 -0700741 return -EPERM;
Dirk Brandewiedd5fbf72014-06-20 07:27:59 -0700742 }
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800743
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400744 limits->no_turbo = clamp_t(int, input, 0, 1);
Gabriele Mazzotta4521e1a02014-10-13 08:37:41 -0700745
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -0700746 mutex_unlock(&intel_pstate_limits_lock);
747
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800748 if (hwp_active)
Viresh Kumar41cfd642016-02-22 10:27:46 +0530749 intel_pstate_hwp_set_online_cpus();
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800750
Dirk Brandewie93f08222013-02-06 09:02:13 -0800751 return count;
752}
753
754static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
Stratos Karafotisc4108332014-07-18 08:37:23 -0700755 const char *buf, size_t count)
Dirk Brandewie93f08222013-02-06 09:02:13 -0800756{
757 unsigned int input;
758 int ret;
Stratos Karafotis845c1cb2014-07-18 08:37:19 -0700759
Dirk Brandewie93f08222013-02-06 09:02:13 -0800760 ret = sscanf(buf, "%u", &input);
761 if (ret != 1)
762 return -EINVAL;
763
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -0700764 mutex_lock(&intel_pstate_limits_lock);
765
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400766 limits->max_sysfs_pct = clamp_t(int, input, 0 , 100);
767 limits->max_perf_pct = min(limits->max_policy_pct,
768 limits->max_sysfs_pct);
769 limits->max_perf_pct = max(limits->min_policy_pct,
770 limits->max_perf_pct);
771 limits->max_perf_pct = max(limits->min_perf_pct,
772 limits->max_perf_pct);
Rafael J. Wysocki22590ef2016-04-09 01:25:58 +0200773 limits->max_perf = div_fp(limits->max_perf_pct, 100);
Stratos Karafotis845c1cb2014-07-18 08:37:19 -0700774
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -0700775 mutex_unlock(&intel_pstate_limits_lock);
776
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800777 if (hwp_active)
Viresh Kumar41cfd642016-02-22 10:27:46 +0530778 intel_pstate_hwp_set_online_cpus();
Dirk Brandewie93f08222013-02-06 09:02:13 -0800779 return count;
780}
781
782static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
Stratos Karafotisc4108332014-07-18 08:37:23 -0700783 const char *buf, size_t count)
Dirk Brandewie93f08222013-02-06 09:02:13 -0800784{
785 unsigned int input;
786 int ret;
Stratos Karafotis845c1cb2014-07-18 08:37:19 -0700787
Dirk Brandewie93f08222013-02-06 09:02:13 -0800788 ret = sscanf(buf, "%u", &input);
789 if (ret != 1)
790 return -EINVAL;
Kristen Carlson Accardia0475992015-01-29 13:03:52 -0800791
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -0700792 mutex_lock(&intel_pstate_limits_lock);
793
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400794 limits->min_sysfs_pct = clamp_t(int, input, 0 , 100);
795 limits->min_perf_pct = max(limits->min_policy_pct,
796 limits->min_sysfs_pct);
797 limits->min_perf_pct = min(limits->max_policy_pct,
798 limits->min_perf_pct);
799 limits->min_perf_pct = min(limits->max_perf_pct,
800 limits->min_perf_pct);
Rafael J. Wysocki22590ef2016-04-09 01:25:58 +0200801 limits->min_perf = div_fp(limits->min_perf_pct, 100);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800802
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -0700803 mutex_unlock(&intel_pstate_limits_lock);
804
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800805 if (hwp_active)
Viresh Kumar41cfd642016-02-22 10:27:46 +0530806 intel_pstate_hwp_set_online_cpus();
Dirk Brandewie93f08222013-02-06 09:02:13 -0800807 return count;
808}
809
Dirk Brandewie93f08222013-02-06 09:02:13 -0800810show_one(max_perf_pct, max_perf_pct);
811show_one(min_perf_pct, min_perf_pct);
812
813define_one_global_rw(no_turbo);
814define_one_global_rw(max_perf_pct);
815define_one_global_rw(min_perf_pct);
Kristen Carlson Accardid01b1f42015-01-28 15:03:27 -0800816define_one_global_ro(turbo_pct);
Kristen Carlson Accardi05224242015-01-28 15:03:28 -0800817define_one_global_ro(num_pstates);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800818
819static struct attribute *intel_pstate_attributes[] = {
820 &no_turbo.attr,
Kristen Carlson Accardid01b1f42015-01-28 15:03:27 -0800821 &turbo_pct.attr,
Kristen Carlson Accardi05224242015-01-28 15:03:28 -0800822 &num_pstates.attr,
Dirk Brandewie93f08222013-02-06 09:02:13 -0800823 NULL
824};
825
826static struct attribute_group intel_pstate_attr_group = {
827 .attrs = intel_pstate_attributes,
828};
Dirk Brandewie93f08222013-02-06 09:02:13 -0800829
Stratos Karafotis317dd502014-07-18 08:37:17 -0700830static void __init intel_pstate_sysfs_expose_params(void)
Dirk Brandewie93f08222013-02-06 09:02:13 -0800831{
Stratos Karafotis317dd502014-07-18 08:37:17 -0700832 struct kobject *intel_pstate_kobject;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800833 int rc;
834
835 intel_pstate_kobject = kobject_create_and_add("intel_pstate",
836 &cpu_subsys.dev_root->kobj);
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -0700837 if (WARN_ON(!intel_pstate_kobject))
838 return;
839
Stratos Karafotis2d8d1f12014-07-18 08:37:20 -0700840 rc = sysfs_create_group(intel_pstate_kobject, &intel_pstate_attr_group);
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -0700841 if (WARN_ON(rc))
842 return;
843
844 /*
845 * If per cpu limits are enforced there are no global limits, so
846 * return without creating max/min_perf_pct attributes
847 */
848 if (per_cpu_limits)
849 return;
850
851 rc = sysfs_create_file(intel_pstate_kobject, &max_perf_pct.attr);
852 WARN_ON(rc);
853
854 rc = sysfs_create_file(intel_pstate_kobject, &min_perf_pct.attr);
855 WARN_ON(rc);
856
Dirk Brandewie93f08222013-02-06 09:02:13 -0800857}
Dirk Brandewie93f08222013-02-06 09:02:13 -0800858/************************** sysfs end ************************/
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800859
Kristen Carlson Accardiba88d432015-07-14 09:46:23 -0700860static void intel_pstate_hwp_enable(struct cpudata *cpudata)
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800861{
Srinivas Pandruvadaf05c9662016-02-25 15:09:31 -0800862 /* First disable HWP notification interrupt as we don't process them */
Srinivas Pandruvadada7de912016-07-19 16:52:01 -0700863 if (static_cpu_has(X86_FEATURE_HWP_NOTIFY))
864 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x00);
Srinivas Pandruvadaf05c9662016-02-25 15:09:31 -0800865
Kristen Carlson Accardiba88d432015-07-14 09:46:23 -0700866 wrmsrl_on_cpu(cpudata->cpu, MSR_PM_ENABLE, 0x1);
Dirk Brandewie2f86dc42014-11-06 09:40:47 -0800867}
868
Philippe Longepe938d21a2015-11-09 17:40:46 -0800869static int atom_get_min_pstate(void)
Dirk Brandewie19e77c22013-10-21 09:20:35 -0700870{
871 u64 value;
Stratos Karafotis845c1cb2014-07-18 08:37:19 -0700872
Philippe Longepe938d21a2015-11-09 17:40:46 -0800873 rdmsrl(ATOM_RATIOS, value);
Dirk Brandewiec16ed062014-06-20 07:27:58 -0700874 return (value >> 8) & 0x7F;
Dirk Brandewie19e77c22013-10-21 09:20:35 -0700875}
Dirk Brandewie93f08222013-02-06 09:02:13 -0800876
Philippe Longepe938d21a2015-11-09 17:40:46 -0800877static int atom_get_max_pstate(void)
Dirk Brandewie19e77c22013-10-21 09:20:35 -0700878{
879 u64 value;
Stratos Karafotis845c1cb2014-07-18 08:37:19 -0700880
Philippe Longepe938d21a2015-11-09 17:40:46 -0800881 rdmsrl(ATOM_RATIOS, value);
Dirk Brandewiec16ed062014-06-20 07:27:58 -0700882 return (value >> 16) & 0x7F;
Dirk Brandewie19e77c22013-10-21 09:20:35 -0700883}
884
Philippe Longepe938d21a2015-11-09 17:40:46 -0800885static int atom_get_turbo_pstate(void)
Dirk Brandewie61d8d2a2014-02-12 10:01:07 -0800886{
887 u64 value;
Stratos Karafotis845c1cb2014-07-18 08:37:19 -0700888
Philippe Longepe938d21a2015-11-09 17:40:46 -0800889 rdmsrl(ATOM_TURBO_RATIOS, value);
Dirk Brandewiec16ed062014-06-20 07:27:58 -0700890 return value & 0x7F;
Dirk Brandewie61d8d2a2014-02-12 10:01:07 -0800891}
892
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +0100893static u64 atom_get_val(struct cpudata *cpudata, int pstate)
Dirk Brandewie007bea02013-12-18 10:32:39 -0800894{
895 u64 val;
896 int32_t vid_fp;
897 u32 vid;
898
Chen Yu144c8e12015-07-29 23:53:10 +0800899 val = (u64)pstate << 8;
Prarit Bhargava51443fb2015-10-15 07:34:15 -0400900 if (limits->no_turbo && !limits->turbo_disabled)
Dirk Brandewie007bea02013-12-18 10:32:39 -0800901 val |= (u64)1 << 32;
902
903 vid_fp = cpudata->vid.min + mul_fp(
904 int_tofp(pstate - cpudata->pstate.min_pstate),
905 cpudata->vid.ratio);
906
907 vid_fp = clamp_t(int32_t, vid_fp, cpudata->vid.min, cpudata->vid.max);
Dirk Brandewied022a652014-10-13 08:37:44 -0700908 vid = ceiling_fp(vid_fp);
Dirk Brandewie007bea02013-12-18 10:32:39 -0800909
Dirk Brandewie21855ff2014-05-08 12:57:23 -0700910 if (pstate > cpudata->pstate.max_pstate)
911 vid = cpudata->vid.turbo;
912
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +0100913 return val | vid;
Dirk Brandewie007bea02013-12-18 10:32:39 -0800914}
915
Philippe Longepe1421df62015-11-09 17:40:47 -0800916static int silvermont_get_scaling(void)
Dirk Brandewieb27580b2014-10-13 08:37:43 -0700917{
918 u64 value;
919 int i;
Philippe Longepe1421df62015-11-09 17:40:47 -0800920 /* Defined in Table 35-6 from SDM (Sept 2015) */
921 static int silvermont_freq_table[] = {
922 83300, 100000, 133300, 116700, 80000};
Dirk Brandewieb27580b2014-10-13 08:37:43 -0700923
924 rdmsrl(MSR_FSB_FREQ, value);
Philippe Longepe1421df62015-11-09 17:40:47 -0800925 i = value & 0x7;
926 WARN_ON(i > 4);
Dirk Brandewieb27580b2014-10-13 08:37:43 -0700927
Philippe Longepe1421df62015-11-09 17:40:47 -0800928 return silvermont_freq_table[i];
929}
Dirk Brandewieb27580b2014-10-13 08:37:43 -0700930
Philippe Longepe1421df62015-11-09 17:40:47 -0800931static int airmont_get_scaling(void)
932{
933 u64 value;
934 int i;
935 /* Defined in Table 35-10 from SDM (Sept 2015) */
936 static int airmont_freq_table[] = {
937 83300, 100000, 133300, 116700, 80000,
938 93300, 90000, 88900, 87500};
939
940 rdmsrl(MSR_FSB_FREQ, value);
941 i = value & 0xF;
942 WARN_ON(i > 8);
943
944 return airmont_freq_table[i];
Dirk Brandewieb27580b2014-10-13 08:37:43 -0700945}
946
Philippe Longepe938d21a2015-11-09 17:40:46 -0800947static void atom_get_vid(struct cpudata *cpudata)
Dirk Brandewie007bea02013-12-18 10:32:39 -0800948{
949 u64 value;
950
Philippe Longepe938d21a2015-11-09 17:40:46 -0800951 rdmsrl(ATOM_VIDS, value);
Dirk Brandewiec16ed062014-06-20 07:27:58 -0700952 cpudata->vid.min = int_tofp((value >> 8) & 0x7f);
953 cpudata->vid.max = int_tofp((value >> 16) & 0x7f);
Dirk Brandewie007bea02013-12-18 10:32:39 -0800954 cpudata->vid.ratio = div_fp(
955 cpudata->vid.max - cpudata->vid.min,
956 int_tofp(cpudata->pstate.max_pstate -
957 cpudata->pstate.min_pstate));
Dirk Brandewie21855ff2014-05-08 12:57:23 -0700958
Philippe Longepe938d21a2015-11-09 17:40:46 -0800959 rdmsrl(ATOM_TURBO_VIDS, value);
Dirk Brandewie21855ff2014-05-08 12:57:23 -0700960 cpudata->vid.turbo = value & 0x7f;
Dirk Brandewie007bea02013-12-18 10:32:39 -0800961}
962
Dirk Brandewie016c8152013-10-21 09:20:34 -0700963static int core_get_min_pstate(void)
Dirk Brandewie93f08222013-02-06 09:02:13 -0800964{
965 u64 value;
Stratos Karafotis845c1cb2014-07-18 08:37:19 -0700966
Konrad Rzeszutek Wilk05e99c8cf2013-03-20 14:21:10 +0000967 rdmsrl(MSR_PLATFORM_INFO, value);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800968 return (value >> 40) & 0xFF;
969}
970
Srinivas Pandruvada3bcc6fa2015-10-14 16:12:00 -0700971static int core_get_max_pstate_physical(void)
Dirk Brandewie93f08222013-02-06 09:02:13 -0800972{
973 u64 value;
Stratos Karafotis845c1cb2014-07-18 08:37:19 -0700974
Konrad Rzeszutek Wilk05e99c8cf2013-03-20 14:21:10 +0000975 rdmsrl(MSR_PLATFORM_INFO, value);
Dirk Brandewie93f08222013-02-06 09:02:13 -0800976 return (value >> 8) & 0xFF;
977}
978
Dirk Brandewie93f08222013-02-06 09:02:13 -0800979static int core_get_max_pstate(void)
980{
Srinivas Pandruvada6a35fc22015-10-14 16:11:59 -0700981 u64 tar;
982 u64 plat_info;
983 int max_pstate;
984 int err;
Dirk Brandewie93f08222013-02-06 09:02:13 -0800985
Srinivas Pandruvada6a35fc22015-10-14 16:11:59 -0700986 rdmsrl(MSR_PLATFORM_INFO, plat_info);
987 max_pstate = (plat_info >> 8) & 0xFF;
988
989 err = rdmsrl_safe(MSR_TURBO_ACTIVATION_RATIO, &tar);
990 if (!err) {
991 /* Do some sanity checking for safety */
992 if (plat_info & 0x600000000) {
993 u64 tdp_ctrl;
994 u64 tdp_ratio;
995 int tdp_msr;
996
997 err = rdmsrl_safe(MSR_CONFIG_TDP_CONTROL, &tdp_ctrl);
998 if (err)
999 goto skip_tar;
1000
Jan Kiszka5fc8f7072016-07-08 20:42:04 +02001001 tdp_msr = MSR_CONFIG_TDP_NOMINAL + (tdp_ctrl & 0x3);
Srinivas Pandruvada6a35fc22015-10-14 16:11:59 -07001002 err = rdmsrl_safe(tdp_msr, &tdp_ratio);
1003 if (err)
1004 goto skip_tar;
1005
Srinivas Pandruvada1becf032016-04-22 19:53:59 -07001006 /* For level 1 and 2, bits[23:16] contain the ratio */
1007 if (tdp_ctrl)
1008 tdp_ratio >>= 16;
1009
1010 tdp_ratio &= 0xff; /* ratios are only 8 bits long */
Srinivas Pandruvada6a35fc22015-10-14 16:11:59 -07001011 if (tdp_ratio - 1 == tar) {
1012 max_pstate = tar;
1013 pr_debug("max_pstate=TAC %x\n", max_pstate);
1014 } else {
1015 goto skip_tar;
1016 }
1017 }
1018 }
1019
1020skip_tar:
1021 return max_pstate;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001022}
1023
Dirk Brandewie016c8152013-10-21 09:20:34 -07001024static int core_get_turbo_pstate(void)
Dirk Brandewie93f08222013-02-06 09:02:13 -08001025{
1026 u64 value;
1027 int nont, ret;
Stratos Karafotis845c1cb2014-07-18 08:37:19 -07001028
Srinivas Pandruvada100cf6f2016-07-06 16:07:55 -07001029 rdmsrl(MSR_TURBO_RATIO_LIMIT, value);
Dirk Brandewie016c8152013-10-21 09:20:34 -07001030 nont = core_get_max_pstate();
Stratos Karafotis285cb992014-07-18 08:37:21 -07001031 ret = (value) & 255;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001032 if (ret <= nont)
1033 ret = nont;
1034 return ret;
1035}
1036
Dirk Brandewieb27580b2014-10-13 08:37:43 -07001037static inline int core_get_scaling(void)
1038{
1039 return 100000;
1040}
1041
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001042static u64 core_get_val(struct cpudata *cpudata, int pstate)
Dirk Brandewie016c8152013-10-21 09:20:34 -07001043{
1044 u64 val;
1045
Chen Yu144c8e12015-07-29 23:53:10 +08001046 val = (u64)pstate << 8;
Prarit Bhargava51443fb2015-10-15 07:34:15 -04001047 if (limits->no_turbo && !limits->turbo_disabled)
Dirk Brandewie016c8152013-10-21 09:20:34 -07001048 val |= (u64)1 << 32;
1049
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001050 return val;
Dirk Brandewie016c8152013-10-21 09:20:34 -07001051}
1052
Dasaratharaman Chandramoulib34ef932015-04-10 10:22:18 -07001053static int knl_get_turbo_pstate(void)
1054{
1055 u64 value;
1056 int nont, ret;
1057
Srinivas Pandruvada100cf6f2016-07-06 16:07:55 -07001058 rdmsrl(MSR_TURBO_RATIO_LIMIT, value);
Dasaratharaman Chandramoulib34ef932015-04-10 10:22:18 -07001059 nont = core_get_max_pstate();
1060 ret = (((value) >> 8) & 0xFF);
1061 if (ret <= nont)
1062 ret = nont;
1063 return ret;
1064}
1065
Dirk Brandewie016c8152013-10-21 09:20:34 -07001066static struct cpu_defaults core_params = {
1067 .pid_policy = {
1068 .sample_rate_ms = 10,
1069 .deadband = 0,
1070 .setpoint = 97,
1071 .p_gain_pct = 20,
1072 .d_gain_pct = 0,
1073 .i_gain_pct = 0,
1074 },
1075 .funcs = {
1076 .get_max = core_get_max_pstate,
Srinivas Pandruvada3bcc6fa2015-10-14 16:12:00 -07001077 .get_max_physical = core_get_max_pstate_physical,
Dirk Brandewie016c8152013-10-21 09:20:34 -07001078 .get_min = core_get_min_pstate,
1079 .get_turbo = core_get_turbo_pstate,
Dirk Brandewieb27580b2014-10-13 08:37:43 -07001080 .get_scaling = core_get_scaling,
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001081 .get_val = core_get_val,
Philippe Longepe157386b2015-12-04 17:40:30 +01001082 .get_target_pstate = get_target_pstate_use_performance,
Dirk Brandewie016c8152013-10-21 09:20:34 -07001083 },
1084};
1085
Julia Lawall42ce8922016-09-11 15:06:01 +02001086static const struct cpu_defaults silvermont_params = {
Dirk Brandewie19e77c22013-10-21 09:20:35 -07001087 .pid_policy = {
1088 .sample_rate_ms = 10,
1089 .deadband = 0,
Kristen Carlson Accardi6a82ba62015-04-10 11:06:43 -07001090 .setpoint = 60,
Dirk Brandewie19e77c22013-10-21 09:20:35 -07001091 .p_gain_pct = 14,
1092 .d_gain_pct = 0,
1093 .i_gain_pct = 4,
1094 },
1095 .funcs = {
Philippe Longepe938d21a2015-11-09 17:40:46 -08001096 .get_max = atom_get_max_pstate,
1097 .get_max_physical = atom_get_max_pstate,
1098 .get_min = atom_get_min_pstate,
1099 .get_turbo = atom_get_turbo_pstate,
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001100 .get_val = atom_get_val,
Philippe Longepe1421df62015-11-09 17:40:47 -08001101 .get_scaling = silvermont_get_scaling,
1102 .get_vid = atom_get_vid,
Philippe Longepee70eed22015-12-04 17:40:32 +01001103 .get_target_pstate = get_target_pstate_use_cpu_load,
Philippe Longepe1421df62015-11-09 17:40:47 -08001104 },
1105};
1106
Julia Lawall42ce8922016-09-11 15:06:01 +02001107static const struct cpu_defaults airmont_params = {
Philippe Longepe1421df62015-11-09 17:40:47 -08001108 .pid_policy = {
1109 .sample_rate_ms = 10,
1110 .deadband = 0,
1111 .setpoint = 60,
1112 .p_gain_pct = 14,
1113 .d_gain_pct = 0,
1114 .i_gain_pct = 4,
1115 },
1116 .funcs = {
1117 .get_max = atom_get_max_pstate,
1118 .get_max_physical = atom_get_max_pstate,
1119 .get_min = atom_get_min_pstate,
1120 .get_turbo = atom_get_turbo_pstate,
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001121 .get_val = atom_get_val,
Philippe Longepe1421df62015-11-09 17:40:47 -08001122 .get_scaling = airmont_get_scaling,
Philippe Longepe938d21a2015-11-09 17:40:46 -08001123 .get_vid = atom_get_vid,
Philippe Longepee70eed22015-12-04 17:40:32 +01001124 .get_target_pstate = get_target_pstate_use_cpu_load,
Dirk Brandewie19e77c22013-10-21 09:20:35 -07001125 },
1126};
1127
Julia Lawall42ce8922016-09-11 15:06:01 +02001128static const struct cpu_defaults knl_params = {
Dasaratharaman Chandramoulib34ef932015-04-10 10:22:18 -07001129 .pid_policy = {
1130 .sample_rate_ms = 10,
1131 .deadband = 0,
1132 .setpoint = 97,
1133 .p_gain_pct = 20,
1134 .d_gain_pct = 0,
1135 .i_gain_pct = 0,
1136 },
1137 .funcs = {
1138 .get_max = core_get_max_pstate,
Srinivas Pandruvada3bcc6fa2015-10-14 16:12:00 -07001139 .get_max_physical = core_get_max_pstate_physical,
Dasaratharaman Chandramoulib34ef932015-04-10 10:22:18 -07001140 .get_min = core_get_min_pstate,
1141 .get_turbo = knl_get_turbo_pstate,
Lukasz Anaczkowski69cefc22015-07-21 10:41:13 +02001142 .get_scaling = core_get_scaling,
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001143 .get_val = core_get_val,
Philippe Longepe157386b2015-12-04 17:40:30 +01001144 .get_target_pstate = get_target_pstate_use_performance,
Dasaratharaman Chandramoulib34ef932015-04-10 10:22:18 -07001145 },
1146};
1147
Julia Lawall42ce8922016-09-11 15:06:01 +02001148static const struct cpu_defaults bxt_params = {
Srinivas Pandruvada41bad472016-06-09 15:34:41 -07001149 .pid_policy = {
1150 .sample_rate_ms = 10,
1151 .deadband = 0,
1152 .setpoint = 60,
1153 .p_gain_pct = 14,
1154 .d_gain_pct = 0,
1155 .i_gain_pct = 4,
1156 },
1157 .funcs = {
1158 .get_max = core_get_max_pstate,
1159 .get_max_physical = core_get_max_pstate_physical,
1160 .get_min = core_get_min_pstate,
1161 .get_turbo = core_get_turbo_pstate,
1162 .get_scaling = core_get_scaling,
1163 .get_val = core_get_val,
1164 .get_target_pstate = get_target_pstate_use_cpu_load,
1165 },
1166};
1167
Dirk Brandewie93f08222013-02-06 09:02:13 -08001168static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
1169{
1170 int max_perf = cpu->pstate.turbo_pstate;
Dirk Brandewie7244cb62013-10-21 09:20:33 -07001171 int max_perf_adj;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001172 int min_perf;
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -07001173 struct perf_limits *perf_limits = limits;
Stratos Karafotis845c1cb2014-07-18 08:37:19 -07001174
Prarit Bhargava51443fb2015-10-15 07:34:15 -04001175 if (limits->no_turbo || limits->turbo_disabled)
Dirk Brandewie93f08222013-02-06 09:02:13 -08001176 max_perf = cpu->pstate.max_pstate;
1177
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -07001178 if (per_cpu_limits)
1179 perf_limits = cpu->perf_limits;
1180
Kristen Carlson Accardie0d4c8f2014-12-10 12:39:38 -08001181 /*
1182 * performance can be limited by user through sysfs, by cpufreq
1183 * policy, or by cpu specific default values determined through
1184 * experimentation.
1185 */
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -07001186 max_perf_adj = fp_toint(max_perf * perf_limits->max_perf);
Rafael J. Wysocki799281a2015-11-18 23:29:56 +01001187 *max = clamp_t(int, max_perf_adj,
1188 cpu->pstate.min_pstate, cpu->pstate.turbo_pstate);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001189
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -07001190 min_perf = fp_toint(max_perf * perf_limits->min_perf);
Rafael J. Wysocki799281a2015-11-18 23:29:56 +01001191 *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001192}
1193
Rafael J. Wysockia6c6ead2016-10-19 02:57:22 +02001194static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001195{
Rafael J. Wysockibc95a452016-07-19 15:10:37 +02001196 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu);
1197 cpu->pstate.current_pstate = pstate;
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001198 /*
1199 * Generally, there is no guarantee that this code will always run on
1200 * the CPU being updated, so force the register update to run on the
1201 * right CPU.
1202 */
1203 wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL,
1204 pstate_funcs.get_val(cpu, pstate));
Dirk Brandewie93f08222013-02-06 09:02:13 -08001205}
1206
Rafael J. Wysockia6c6ead2016-10-19 02:57:22 +02001207static void intel_pstate_set_min_pstate(struct cpudata *cpu)
1208{
1209 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
1210}
1211
1212static void intel_pstate_max_within_limits(struct cpudata *cpu)
1213{
1214 int min_pstate, max_pstate;
1215
1216 update_turbo_state();
1217 intel_pstate_get_min_max(cpu, &min_pstate, &max_pstate);
1218 intel_pstate_set_pstate(cpu, max_pstate);
1219}
1220
Dirk Brandewie93f08222013-02-06 09:02:13 -08001221static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
1222{
Dirk Brandewie016c8152013-10-21 09:20:34 -07001223 cpu->pstate.min_pstate = pstate_funcs.get_min();
1224 cpu->pstate.max_pstate = pstate_funcs.get_max();
Srinivas Pandruvada3bcc6fa2015-10-14 16:12:00 -07001225 cpu->pstate.max_pstate_physical = pstate_funcs.get_max_physical();
Dirk Brandewie016c8152013-10-21 09:20:34 -07001226 cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
Dirk Brandewieb27580b2014-10-13 08:37:43 -07001227 cpu->pstate.scaling = pstate_funcs.get_scaling();
Dirk Brandewie93f08222013-02-06 09:02:13 -08001228
Dirk Brandewie007bea02013-12-18 10:32:39 -08001229 if (pstate_funcs.get_vid)
1230 pstate_funcs.get_vid(cpu);
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001231
1232 intel_pstate_set_min_pstate(cpu);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001233}
1234
Rafael J. Wysockia1c97872016-05-11 19:09:12 +02001235static inline void intel_pstate_calc_avg_perf(struct cpudata *cpu)
Dirk Brandewie93f08222013-02-06 09:02:13 -08001236{
Stratos Karafotis6b17ddb2014-04-29 20:53:49 +03001237 struct sample *sample = &cpu->sample;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001238
Rafael J. Wysockia1c97872016-05-11 19:09:12 +02001239 sample->core_avg_perf = div_ext_fp(sample->aperf, sample->mperf);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001240}
1241
Rafael J. Wysocki4fec7ad2016-03-10 23:45:19 +01001242static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time)
Dirk Brandewie93f08222013-02-06 09:02:13 -08001243{
Dirk Brandewie93f08222013-02-06 09:02:13 -08001244 u64 aperf, mperf;
Stratos Karafotis4ab60c32014-07-18 08:37:24 -07001245 unsigned long flags;
Doug Smythies4055fad2015-04-11 21:10:26 -07001246 u64 tsc;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001247
Stratos Karafotis4ab60c32014-07-18 08:37:24 -07001248 local_irq_save(flags);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001249 rdmsrl(MSR_IA32_APERF, aperf);
1250 rdmsrl(MSR_IA32_MPERF, mperf);
Philippe Longepee70eed22015-12-04 17:40:32 +01001251 tsc = rdtsc();
Rafael J. Wysocki4fec7ad2016-03-10 23:45:19 +01001252 if (cpu->prev_mperf == mperf || cpu->prev_tsc == tsc) {
Srinivas Pandruvada8e601a92015-10-15 12:34:21 -07001253 local_irq_restore(flags);
Rafael J. Wysocki4fec7ad2016-03-10 23:45:19 +01001254 return false;
Srinivas Pandruvada8e601a92015-10-15 12:34:21 -07001255 }
Stratos Karafotis4ab60c32014-07-18 08:37:24 -07001256 local_irq_restore(flags);
Dirk Brandewieb69880f2014-01-16 10:32:25 -08001257
Dirk Brandewiec4ee8412014-05-29 09:32:24 -07001258 cpu->last_sample_time = cpu->sample.time;
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001259 cpu->sample.time = time;
Dirk Brandewied37e2b72014-02-12 10:01:04 -08001260 cpu->sample.aperf = aperf;
1261 cpu->sample.mperf = mperf;
Doug Smythies4055fad2015-04-11 21:10:26 -07001262 cpu->sample.tsc = tsc;
Dirk Brandewied37e2b72014-02-12 10:01:04 -08001263 cpu->sample.aperf -= cpu->prev_aperf;
1264 cpu->sample.mperf -= cpu->prev_mperf;
Doug Smythies4055fad2015-04-11 21:10:26 -07001265 cpu->sample.tsc -= cpu->prev_tsc;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001266
Dirk Brandewie93f08222013-02-06 09:02:13 -08001267 cpu->prev_aperf = aperf;
1268 cpu->prev_mperf = mperf;
Doug Smythies4055fad2015-04-11 21:10:26 -07001269 cpu->prev_tsc = tsc;
Rafael J. Wysockifebce402016-04-02 01:06:21 +02001270 /*
1271 * First time this function is invoked in a given cycle, all of the
1272 * previous sample data fields are equal to zero or stale and they must
1273 * be populated with meaningful numbers for things to work, so assume
1274 * that sample.time will always be reset before setting the utilization
1275 * update hook and make the caller skip the sample then.
1276 */
1277 return !!cpu->last_sample_time;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001278}
1279
Philippe Longepe8fa520a2016-03-06 08:34:06 +01001280static inline int32_t get_avg_frequency(struct cpudata *cpu)
1281{
Rafael J. Wysockia1c97872016-05-11 19:09:12 +02001282 return mul_ext_fp(cpu->sample.core_avg_perf,
1283 cpu->pstate.max_pstate_physical * cpu->pstate.scaling);
Philippe Longepe8fa520a2016-03-06 08:34:06 +01001284}
1285
Philippe Longepebdcaa232016-04-22 11:46:09 -07001286static inline int32_t get_avg_pstate(struct cpudata *cpu)
1287{
Rafael J. Wysocki8edb0a62016-05-11 19:10:42 +02001288 return mul_ext_fp(cpu->pstate.max_pstate_physical,
1289 cpu->sample.core_avg_perf);
Philippe Longepebdcaa232016-04-22 11:46:09 -07001290}
1291
Philippe Longepee70eed22015-12-04 17:40:32 +01001292static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu)
1293{
1294 struct sample *sample = &cpu->sample;
Rafael J. Wysocki09c448d2016-09-14 02:28:13 +02001295 int32_t busy_frac, boost;
Rafael J. Wysocki0843e832016-10-06 14:07:51 +02001296 int target, avg_pstate;
Philippe Longepee70eed22015-12-04 17:40:32 +01001297
Rafael J. Wysocki09c448d2016-09-14 02:28:13 +02001298 busy_frac = div_fp(sample->mperf, sample->tsc);
Philippe Longepe63d1d652015-12-04 17:40:35 +01001299
Rafael J. Wysocki09c448d2016-09-14 02:28:13 +02001300 boost = cpu->iowait_boost;
1301 cpu->iowait_boost >>= 1;
Philippe Longepe63d1d652015-12-04 17:40:35 +01001302
Rafael J. Wysocki09c448d2016-09-14 02:28:13 +02001303 if (busy_frac < boost)
1304 busy_frac = boost;
Philippe Longepe63d1d652015-12-04 17:40:35 +01001305
Rafael J. Wysocki09c448d2016-09-14 02:28:13 +02001306 sample->busy_scaled = busy_frac * 100;
Rafael J. Wysocki0843e832016-10-06 14:07:51 +02001307
1308 target = limits->no_turbo || limits->turbo_disabled ?
1309 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate;
1310 target += target >> 2;
1311 target = mul_fp(target, busy_frac);
1312 if (target < cpu->pstate.min_pstate)
1313 target = cpu->pstate.min_pstate;
1314
1315 /*
1316 * If the average P-state during the previous cycle was higher than the
1317 * current target, add 50% of the difference to the target to reduce
1318 * possible performance oscillations and offset possible performance
1319 * loss related to moving the workload from one CPU to another within
1320 * a package/module.
1321 */
1322 avg_pstate = get_avg_pstate(cpu);
1323 if (avg_pstate > target)
1324 target += (avg_pstate - target) >> 1;
1325
1326 return target;
Philippe Longepee70eed22015-12-04 17:40:32 +01001327}
1328
Philippe Longepe157386b2015-12-04 17:40:30 +01001329static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu)
Dirk Brandewie93f08222013-02-06 09:02:13 -08001330{
Rafael J. Wysocki1aa7a6e2016-05-11 19:11:26 +02001331 int32_t perf_scaled, max_pstate, current_pstate, sample_ratio;
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001332 u64 duration_ns;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001333
Kristen Carlson Accardie0d4c8f2014-12-10 12:39:38 -08001334 /*
Rafael J. Wysockif00593a2016-09-30 03:13:34 +02001335 * perf_scaled is the ratio of the average P-state during the last
1336 * sampling period to the P-state requested last time (in percent).
1337 *
1338 * That measures the system's response to the previous P-state
1339 * selection.
Kristen Carlson Accardie0d4c8f2014-12-10 12:39:38 -08001340 */
Rafael J. Wysocki22590ef2016-04-09 01:25:58 +02001341 max_pstate = cpu->pstate.max_pstate_physical;
1342 current_pstate = cpu->pstate.current_pstate;
Rafael J. Wysocki1aa7a6e2016-05-11 19:11:26 +02001343 perf_scaled = mul_ext_fp(cpu->sample.core_avg_perf,
Rafael J. Wysockia1c97872016-05-11 19:09:12 +02001344 div_fp(100 * max_pstate, current_pstate));
Dirk Brandewiec4ee8412014-05-29 09:32:24 -07001345
Kristen Carlson Accardie0d4c8f2014-12-10 12:39:38 -08001346 /*
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001347 * Since our utilization update callback will not run unless we are
1348 * in C0, check if the actual elapsed time is significantly greater (3x)
1349 * than our sample interval. If it is, then we were idle for a long
Rafael J. Wysocki1aa7a6e2016-05-11 19:11:26 +02001350 * enough period of time to adjust our performance metric.
Kristen Carlson Accardie0d4c8f2014-12-10 12:39:38 -08001351 */
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001352 duration_ns = cpu->sample.time - cpu->last_sample_time;
Rafael J. Wysockifebce402016-04-02 01:06:21 +02001353 if ((s64)duration_ns > pid_params.sample_rate_ns * 3) {
Rafael J. Wysocki22590ef2016-04-09 01:25:58 +02001354 sample_ratio = div_fp(pid_params.sample_rate_ns, duration_ns);
Rafael J. Wysocki1aa7a6e2016-05-11 19:11:26 +02001355 perf_scaled = mul_fp(perf_scaled, sample_ratio);
Rafael J. Wysockiffb81052016-04-10 05:59:10 +02001356 } else {
1357 sample_ratio = div_fp(100 * cpu->sample.mperf, cpu->sample.tsc);
1358 if (sample_ratio < int_tofp(1))
Rafael J. Wysocki1aa7a6e2016-05-11 19:11:26 +02001359 perf_scaled = 0;
Dirk Brandewiec4ee8412014-05-29 09:32:24 -07001360 }
1361
Rafael J. Wysocki1aa7a6e2016-05-11 19:11:26 +02001362 cpu->sample.busy_scaled = perf_scaled;
1363 return cpu->pstate.current_pstate - pid_calc(&cpu->pid, perf_scaled);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001364}
1365
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001366static inline void intel_pstate_update_pstate(struct cpudata *cpu, int pstate)
1367{
1368 int max_perf, min_perf;
1369
1370 update_turbo_state();
1371
1372 intel_pstate_get_min_max(cpu, &min_perf, &max_perf);
1373 pstate = clamp_t(int, pstate, min_perf, max_perf);
Rafael J. Wysockibc95a452016-07-19 15:10:37 +02001374 trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu);
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001375 if (pstate == cpu->pstate.current_pstate)
1376 return;
1377
Rafael J. Wysockibc95a452016-07-19 15:10:37 +02001378 cpu->pstate.current_pstate = pstate;
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001379 wrmsrl(MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, pstate));
1380}
1381
Dirk Brandewie93f08222013-02-06 09:02:13 -08001382static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
1383{
Philippe Longepe157386b2015-12-04 17:40:30 +01001384 int from, target_pstate;
Doug Smythies4055fad2015-04-11 21:10:26 -07001385 struct sample *sample;
1386
1387 from = cpu->pstate.current_pstate;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001388
Rafael J. Wysocki2f1d4072016-10-24 23:20:25 +02001389 target_pstate = cpu->policy == CPUFREQ_POLICY_PERFORMANCE ?
1390 cpu->pstate.turbo_pstate : pstate_funcs.get_target_pstate(cpu);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001391
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001392 intel_pstate_update_pstate(cpu, target_pstate);
Doug Smythies4055fad2015-04-11 21:10:26 -07001393
1394 sample = &cpu->sample;
Rafael J. Wysockia1c97872016-05-11 19:09:12 +02001395 trace_pstate_sample(mul_ext_fp(100, sample->core_avg_perf),
Philippe Longepe157386b2015-12-04 17:40:30 +01001396 fp_toint(sample->busy_scaled),
Doug Smythies4055fad2015-04-11 21:10:26 -07001397 from,
1398 cpu->pstate.current_pstate,
1399 sample->mperf,
1400 sample->aperf,
1401 sample->tsc,
Srinivas Pandruvada3ba7bca2016-09-13 17:41:33 -07001402 get_avg_frequency(cpu),
1403 fp_toint(cpu->iowait_boost * 100));
Dirk Brandewie93f08222013-02-06 09:02:13 -08001404}
1405
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001406static void intel_pstate_update_util(struct update_util_data *data, u64 time,
Rafael J. Wysocki58919e82016-08-16 22:14:55 +02001407 unsigned int flags)
Dirk Brandewie2f86dc42014-11-06 09:40:47 -08001408{
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001409 struct cpudata *cpu = container_of(data, struct cpudata, update_util);
Rafael J. Wysocki09c448d2016-09-14 02:28:13 +02001410 u64 delta_ns;
Dirk Brandewie2f86dc42014-11-06 09:40:47 -08001411
Rafael J. Wysocki1d298152016-10-19 02:53:26 +02001412 if (pstate_funcs.get_target_pstate == get_target_pstate_use_cpu_load) {
Rafael J. Wysocki09c448d2016-09-14 02:28:13 +02001413 if (flags & SCHED_CPUFREQ_IOWAIT) {
1414 cpu->iowait_boost = int_tofp(1);
1415 } else if (cpu->iowait_boost) {
1416 /* Clear iowait_boost if the CPU may have been idle. */
1417 delta_ns = time - cpu->last_update;
1418 if (delta_ns > TICK_NSEC)
1419 cpu->iowait_boost = 0;
1420 }
1421 cpu->last_update = time;
1422 }
1423
1424 delta_ns = time - cpu->sample.time;
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001425 if ((s64)delta_ns >= pid_params.sample_rate_ns) {
Rafael J. Wysocki4fec7ad2016-03-10 23:45:19 +01001426 bool sample_taken = intel_pstate_sample(cpu, time);
1427
Rafael J. Wysocki6d45b712016-05-04 14:01:10 +02001428 if (sample_taken) {
Rafael J. Wysockia1c97872016-05-11 19:09:12 +02001429 intel_pstate_calc_avg_perf(cpu);
Rafael J. Wysocki6d45b712016-05-04 14:01:10 +02001430 if (!hwp_active)
1431 intel_pstate_adjust_busy_pstate(cpu);
1432 }
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001433 }
Dirk Brandewie93f08222013-02-06 09:02:13 -08001434}
1435
1436#define ICPU(model, policy) \
Dirk Brandewie6cbd7ee2014-01-06 10:59:16 -08001437 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_APERFMPERF,\
1438 (unsigned long)&policy }
Dirk Brandewie93f08222013-02-06 09:02:13 -08001439
1440static const struct x86_cpu_id intel_pstate_cpu_ids[] = {
Dave Hansen5b20c942016-06-02 17:19:45 -07001441 ICPU(INTEL_FAM6_SANDYBRIDGE, core_params),
1442 ICPU(INTEL_FAM6_SANDYBRIDGE_X, core_params),
1443 ICPU(INTEL_FAM6_ATOM_SILVERMONT1, silvermont_params),
1444 ICPU(INTEL_FAM6_IVYBRIDGE, core_params),
1445 ICPU(INTEL_FAM6_HASWELL_CORE, core_params),
1446 ICPU(INTEL_FAM6_BROADWELL_CORE, core_params),
1447 ICPU(INTEL_FAM6_IVYBRIDGE_X, core_params),
1448 ICPU(INTEL_FAM6_HASWELL_X, core_params),
1449 ICPU(INTEL_FAM6_HASWELL_ULT, core_params),
1450 ICPU(INTEL_FAM6_HASWELL_GT3E, core_params),
1451 ICPU(INTEL_FAM6_BROADWELL_GT3E, core_params),
1452 ICPU(INTEL_FAM6_ATOM_AIRMONT, airmont_params),
1453 ICPU(INTEL_FAM6_SKYLAKE_MOBILE, core_params),
1454 ICPU(INTEL_FAM6_BROADWELL_X, core_params),
1455 ICPU(INTEL_FAM6_SKYLAKE_DESKTOP, core_params),
1456 ICPU(INTEL_FAM6_BROADWELL_XEON_D, core_params),
1457 ICPU(INTEL_FAM6_XEON_PHI_KNL, knl_params),
Srinivas Pandruvada41bad472016-06-09 15:34:41 -07001458 ICPU(INTEL_FAM6_ATOM_GOLDMONT, bxt_params),
Dirk Brandewie93f08222013-02-06 09:02:13 -08001459 {}
1460};
1461MODULE_DEVICE_TABLE(x86cpu, intel_pstate_cpu_ids);
1462
Jisheng Zhang29327c82016-06-27 18:07:17 +08001463static const struct x86_cpu_id intel_pstate_cpu_oob_ids[] __initconst = {
Dave Hansen5b20c942016-06-02 17:19:45 -07001464 ICPU(INTEL_FAM6_BROADWELL_XEON_D, core_params),
Srinivas Pandruvada65c12622016-07-23 15:12:06 -07001465 ICPU(INTEL_FAM6_BROADWELL_X, core_params),
1466 ICPU(INTEL_FAM6_SKYLAKE_X, core_params),
Dirk Brandewie2f86dc42014-11-06 09:40:47 -08001467 {}
1468};
1469
Dirk Brandewie93f08222013-02-06 09:02:13 -08001470static int intel_pstate_init_cpu(unsigned int cpunum)
1471{
Dirk Brandewie93f08222013-02-06 09:02:13 -08001472 struct cpudata *cpu;
1473
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -07001474 cpu = all_cpu_data[cpunum];
1475
1476 if (!cpu) {
1477 unsigned int size = sizeof(struct cpudata);
1478
1479 if (per_cpu_limits)
1480 size += sizeof(struct perf_limits);
1481
1482 cpu = kzalloc(size, GFP_KERNEL);
1483 if (!cpu)
1484 return -ENOMEM;
1485
1486 all_cpu_data[cpunum] = cpu;
1487 if (per_cpu_limits)
1488 cpu->perf_limits = (struct perf_limits *)(cpu + 1);
1489
1490 }
Dirk Brandewie93f08222013-02-06 09:02:13 -08001491
1492 cpu = all_cpu_data[cpunum];
1493
Dirk Brandewie93f08222013-02-06 09:02:13 -08001494 cpu->cpu = cpunum;
Kristen Carlson Accardiba88d432015-07-14 09:46:23 -07001495
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001496 if (hwp_active) {
Kristen Carlson Accardiba88d432015-07-14 09:46:23 -07001497 intel_pstate_hwp_enable(cpu);
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001498 pid_params.sample_rate_ms = 50;
1499 pid_params.sample_rate_ns = 50 * NSEC_PER_MSEC;
1500 }
Kristen Carlson Accardiba88d432015-07-14 09:46:23 -07001501
Vincent Minet179e8472014-07-05 01:51:33 +02001502 intel_pstate_get_cpu_pstates(cpu);
Dirk Brandewie016c8152013-10-21 09:20:34 -07001503
Dirk Brandewie93f08222013-02-06 09:02:13 -08001504 intel_pstate_busy_pid_reset(cpu);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001505
Joe Perches4836df12016-04-05 13:28:23 -07001506 pr_debug("controlling: cpu %d\n", cpunum);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001507
1508 return 0;
1509}
1510
1511static unsigned int intel_pstate_get(unsigned int cpu_num)
1512{
Rafael J. Wysockif96fd0c2016-05-07 02:24:48 +02001513 struct cpudata *cpu = all_cpu_data[cpu_num];
Dirk Brandewie93f08222013-02-06 09:02:13 -08001514
Rafael J. Wysockif96fd0c2016-05-07 02:24:48 +02001515 return cpu ? get_avg_frequency(cpu) : 0;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001516}
1517
Rafael J. Wysockifebce402016-04-02 01:06:21 +02001518static void intel_pstate_set_update_util_hook(unsigned int cpu_num)
Rafael J. Wysockibb6ab522016-03-31 17:42:15 +02001519{
Rafael J. Wysockifebce402016-04-02 01:06:21 +02001520 struct cpudata *cpu = all_cpu_data[cpu_num];
1521
Rafael J. Wysocki5ab666e2016-06-27 23:47:15 +02001522 if (cpu->update_util_set)
1523 return;
1524
Rafael J. Wysockifebce402016-04-02 01:06:21 +02001525 /* Prevent intel_pstate_update_util() from using stale data. */
1526 cpu->sample.time = 0;
Rafael J. Wysocki0bed6122016-04-02 01:08:43 +02001527 cpufreq_add_update_util_hook(cpu_num, &cpu->update_util,
1528 intel_pstate_update_util);
Chen Yu4578ee7e2016-05-11 14:33:08 +08001529 cpu->update_util_set = true;
Rafael J. Wysockibb6ab522016-03-31 17:42:15 +02001530}
1531
1532static void intel_pstate_clear_update_util_hook(unsigned int cpu)
1533{
Chen Yu4578ee7e2016-05-11 14:33:08 +08001534 struct cpudata *cpu_data = all_cpu_data[cpu];
1535
1536 if (!cpu_data->update_util_set)
1537 return;
1538
Rafael J. Wysocki0bed6122016-04-02 01:08:43 +02001539 cpufreq_remove_update_util_hook(cpu);
Chen Yu4578ee7e2016-05-11 14:33:08 +08001540 cpu_data->update_util_set = false;
Rafael J. Wysockibb6ab522016-03-31 17:42:15 +02001541 synchronize_sched();
1542}
1543
Srinivas Pandruvada30a39152016-04-03 19:42:11 -07001544static void intel_pstate_set_performance_limits(struct perf_limits *limits)
1545{
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -07001546 mutex_lock(&intel_pstate_limits_lock);
Srinivas Pandruvada30a39152016-04-03 19:42:11 -07001547 limits->no_turbo = 0;
1548 limits->turbo_disabled = 0;
1549 limits->max_perf_pct = 100;
1550 limits->max_perf = int_tofp(1);
1551 limits->min_perf_pct = 100;
1552 limits->min_perf = int_tofp(1);
1553 limits->max_policy_pct = 100;
1554 limits->max_sysfs_pct = 100;
1555 limits->min_policy_pct = 0;
1556 limits->min_sysfs_pct = 0;
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -07001557 mutex_unlock(&intel_pstate_limits_lock);
Srinivas Pandruvada30a39152016-04-03 19:42:11 -07001558}
1559
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -07001560static void intel_pstate_update_perf_limits(struct cpufreq_policy *policy,
1561 struct perf_limits *limits)
Dirk Brandewie93f08222013-02-06 09:02:13 -08001562{
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -07001563
1564 mutex_lock(&intel_pstate_limits_lock);
1565
Prarit Bhargava8478f532015-11-20 18:47:56 -05001566 limits->max_policy_pct = DIV_ROUND_UP(policy->max * 100,
1567 policy->cpuinfo.max_freq);
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -07001568 limits->max_policy_pct = clamp_t(int, limits->max_policy_pct, 0, 100);
Srinivas Pandruvada5879f872016-10-25 13:20:41 -07001569 if (policy->max == policy->min) {
1570 limits->min_policy_pct = limits->max_policy_pct;
1571 } else {
1572 limits->min_policy_pct = (policy->min * 100) /
1573 policy->cpuinfo.max_freq;
1574 limits->min_policy_pct = clamp_t(int, limits->min_policy_pct,
1575 0, 100);
1576 }
Chen Yu43717aa2015-09-09 18:27:31 +08001577
1578 /* Normalize user input to [min_policy_pct, max_policy_pct] */
Prarit Bhargava51443fb2015-10-15 07:34:15 -04001579 limits->min_perf_pct = max(limits->min_policy_pct,
1580 limits->min_sysfs_pct);
1581 limits->min_perf_pct = min(limits->max_policy_pct,
1582 limits->min_perf_pct);
1583 limits->max_perf_pct = min(limits->max_policy_pct,
1584 limits->max_sysfs_pct);
1585 limits->max_perf_pct = max(limits->min_policy_pct,
1586 limits->max_perf_pct);
Chen Yu43717aa2015-09-09 18:27:31 +08001587
1588 /* Make sure min_perf_pct <= max_perf_pct */
Prarit Bhargava51443fb2015-10-15 07:34:15 -04001589 limits->min_perf_pct = min(limits->max_perf_pct, limits->min_perf_pct);
Chen Yu43717aa2015-09-09 18:27:31 +08001590
Rafael J. Wysocki22590ef2016-04-09 01:25:58 +02001591 limits->min_perf = div_fp(limits->min_perf_pct, 100);
1592 limits->max_perf = div_fp(limits->max_perf_pct, 100);
Srinivas Pandruvada2c2c1af2016-06-07 17:38:52 -07001593 limits->max_perf = round_up(limits->max_perf, FRAC_BITS);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001594
Srinivas Pandruvadaa410c03d2016-10-28 10:44:52 -07001595 mutex_unlock(&intel_pstate_limits_lock);
1596
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -07001597 pr_debug("cpu:%d max_perf_pct:%d min_perf_pct:%d\n", policy->cpu,
1598 limits->max_perf_pct, limits->min_perf_pct);
1599}
1600
1601static int intel_pstate_set_policy(struct cpufreq_policy *policy)
1602{
1603 struct cpudata *cpu;
1604 struct perf_limits *perf_limits = NULL;
1605
1606 if (!policy->cpuinfo.max_freq)
1607 return -ENODEV;
1608
1609 pr_debug("set_policy cpuinfo.max %u policy->max %u\n",
1610 policy->cpuinfo.max_freq, policy->max);
1611
1612 cpu = all_cpu_data[policy->cpu];
1613 cpu->policy = policy->policy;
1614
1615 if (cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate &&
1616 policy->max < policy->cpuinfo.max_freq &&
1617 policy->max > cpu->pstate.max_pstate * cpu->pstate.scaling) {
1618 pr_debug("policy->max > max non turbo frequency\n");
1619 policy->max = policy->cpuinfo.max_freq;
1620 }
1621
1622 if (per_cpu_limits)
1623 perf_limits = cpu->perf_limits;
1624
1625 if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
1626 if (!perf_limits) {
1627 limits = &performance_limits;
1628 perf_limits = limits;
1629 }
1630 if (policy->max >= policy->cpuinfo.max_freq) {
1631 pr_debug("set performance\n");
1632 intel_pstate_set_performance_limits(perf_limits);
1633 goto out;
1634 }
1635 } else {
1636 pr_debug("set powersave\n");
1637 if (!perf_limits) {
1638 limits = &powersave_limits;
1639 perf_limits = limits;
1640 }
1641
1642 }
1643
1644 intel_pstate_update_perf_limits(policy, perf_limits);
Rafael J. Wysockibb6ab522016-03-31 17:42:15 +02001645 out:
Rafael J. Wysocki2f1d4072016-10-24 23:20:25 +02001646 if (cpu->policy == CPUFREQ_POLICY_PERFORMANCE) {
Rafael J. Wysockia6c6ead2016-10-19 02:57:22 +02001647 /*
1648 * NOHZ_FULL CPUs need this as the governor callback may not
1649 * be invoked on them.
1650 */
1651 intel_pstate_clear_update_util_hook(policy->cpu);
1652 intel_pstate_max_within_limits(cpu);
1653 }
1654
Rafael J. Wysockibb6ab522016-03-31 17:42:15 +02001655 intel_pstate_set_update_util_hook(policy->cpu);
1656
Rafael J. Wysockiba41e1b2016-05-02 02:27:19 +02001657 intel_pstate_hwp_set_policy(policy);
Dirk Brandewie2f86dc42014-11-06 09:40:47 -08001658
Dirk Brandewie93f08222013-02-06 09:02:13 -08001659 return 0;
1660}
1661
1662static int intel_pstate_verify_policy(struct cpufreq_policy *policy)
1663{
Viresh Kumarbe49e342013-10-02 14:13:19 +05301664 cpufreq_verify_within_cpu_limits(policy);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001665
Stratos Karafotis285cb992014-07-18 08:37:21 -07001666 if (policy->policy != CPUFREQ_POLICY_POWERSAVE &&
Stratos Karafotisc4108332014-07-18 08:37:23 -07001667 policy->policy != CPUFREQ_POLICY_PERFORMANCE)
Dirk Brandewie93f08222013-02-06 09:02:13 -08001668 return -EINVAL;
1669
1670 return 0;
1671}
1672
Dirk Brandewiebb180082014-03-19 08:45:54 -07001673static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
Dirk Brandewie93f08222013-02-06 09:02:13 -08001674{
Dirk Brandewiebb180082014-03-19 08:45:54 -07001675 int cpu_num = policy->cpu;
1676 struct cpudata *cpu = all_cpu_data[cpu_num];
Dirk Brandewie93f08222013-02-06 09:02:13 -08001677
Joe Perches4836df12016-04-05 13:28:23 -07001678 pr_debug("CPU %d exiting\n", cpu_num);
Dirk Brandewiebb180082014-03-19 08:45:54 -07001679
Rafael J. Wysockibb6ab522016-03-31 17:42:15 +02001680 intel_pstate_clear_update_util_hook(cpu_num);
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001681
Dirk Brandewie2f86dc42014-11-06 09:40:47 -08001682 if (hwp_active)
1683 return;
1684
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001685 intel_pstate_set_min_pstate(cpu);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001686}
1687
Paul Gortmaker27609842013-06-19 13:54:04 -04001688static int intel_pstate_cpu_init(struct cpufreq_policy *policy)
Dirk Brandewie93f08222013-02-06 09:02:13 -08001689{
Dirk Brandewie93f08222013-02-06 09:02:13 -08001690 struct cpudata *cpu;
Dirk Brandewie52e0a502013-10-15 11:06:14 -07001691 int rc;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001692
1693 rc = intel_pstate_init_cpu(policy->cpu);
1694 if (rc)
1695 return rc;
1696
1697 cpu = all_cpu_data[policy->cpu];
1698
Prarit Bhargava51443fb2015-10-15 07:34:15 -04001699 if (limits->min_perf_pct == 100 && limits->max_perf_pct == 100)
Dirk Brandewie93f08222013-02-06 09:02:13 -08001700 policy->policy = CPUFREQ_POLICY_PERFORMANCE;
1701 else
1702 policy->policy = CPUFREQ_POLICY_POWERSAVE;
1703
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -07001704 /*
1705 * We need sane value in the cpu->perf_limits, so inherit from global
1706 * perf_limits limits, which are seeded with values based on the
1707 * CONFIG_CPU_FREQ_DEFAULT_GOV_*, during boot up.
1708 */
1709 if (per_cpu_limits)
1710 memcpy(cpu->perf_limits, limits, sizeof(struct perf_limits));
1711
Dirk Brandewieb27580b2014-10-13 08:37:43 -07001712 policy->min = cpu->pstate.min_pstate * cpu->pstate.scaling;
1713 policy->max = cpu->pstate.turbo_pstate * cpu->pstate.scaling;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001714
1715 /* cpuinfo and default policy values */
Dirk Brandewieb27580b2014-10-13 08:37:43 -07001716 policy->cpuinfo.min_freq = cpu->pstate.min_pstate * cpu->pstate.scaling;
Srinivas Pandruvada983e6002016-06-07 17:38:53 -07001717 update_turbo_state();
1718 policy->cpuinfo.max_freq = limits->turbo_disabled ?
1719 cpu->pstate.max_pstate : cpu->pstate.turbo_pstate;
1720 policy->cpuinfo.max_freq *= cpu->pstate.scaling;
1721
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -07001722 intel_pstate_init_acpi_perf_limits(policy);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001723 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
1724 cpumask_set_cpu(policy->cpu, policy->cpus);
1725
1726 return 0;
1727}
1728
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -07001729static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)
1730{
1731 intel_pstate_exit_perf_limits(policy);
1732
1733 return 0;
1734}
1735
Dirk Brandewie93f08222013-02-06 09:02:13 -08001736static struct cpufreq_driver intel_pstate_driver = {
1737 .flags = CPUFREQ_CONST_LOOPS,
1738 .verify = intel_pstate_verify_policy,
1739 .setpolicy = intel_pstate_set_policy,
Rafael J. Wysockiba41e1b2016-05-02 02:27:19 +02001740 .resume = intel_pstate_hwp_set_policy,
Dirk Brandewie93f08222013-02-06 09:02:13 -08001741 .get = intel_pstate_get,
1742 .init = intel_pstate_cpu_init,
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -07001743 .exit = intel_pstate_cpu_exit,
Dirk Brandewiebb180082014-03-19 08:45:54 -07001744 .stop_cpu = intel_pstate_stop_cpu,
Dirk Brandewie93f08222013-02-06 09:02:13 -08001745 .name = "intel_pstate",
Dirk Brandewie93f08222013-02-06 09:02:13 -08001746};
1747
Jisheng Zhangeed43602016-06-27 18:07:16 +08001748static int no_load __initdata;
1749static int no_hwp __initdata;
1750static int hwp_only __initdata;
Jisheng Zhang29327c82016-06-27 18:07:17 +08001751static unsigned int force_load __initdata;
Dirk Brandewie6be26492013-02-15 22:55:10 +01001752
Jisheng Zhang29327c82016-06-27 18:07:17 +08001753static int __init intel_pstate_msrs_not_valid(void)
Dirk Brandewieb563b4e2013-03-22 01:29:28 +01001754{
Dirk Brandewie016c8152013-10-21 09:20:34 -07001755 if (!pstate_funcs.get_max() ||
Stratos Karafotisc4108332014-07-18 08:37:23 -07001756 !pstate_funcs.get_min() ||
1757 !pstate_funcs.get_turbo())
Dirk Brandewieb563b4e2013-03-22 01:29:28 +01001758 return -ENODEV;
1759
Dirk Brandewieb563b4e2013-03-22 01:29:28 +01001760 return 0;
1761}
Dirk Brandewie016c8152013-10-21 09:20:34 -07001762
Jisheng Zhang29327c82016-06-27 18:07:17 +08001763static void __init copy_pid_params(struct pstate_adjust_policy *policy)
Dirk Brandewie016c8152013-10-21 09:20:34 -07001764{
1765 pid_params.sample_rate_ms = policy->sample_rate_ms;
Rafael J. Wysockia4675fb2016-02-05 01:45:30 +01001766 pid_params.sample_rate_ns = pid_params.sample_rate_ms * NSEC_PER_MSEC;
Dirk Brandewie016c8152013-10-21 09:20:34 -07001767 pid_params.p_gain_pct = policy->p_gain_pct;
1768 pid_params.i_gain_pct = policy->i_gain_pct;
1769 pid_params.d_gain_pct = policy->d_gain_pct;
1770 pid_params.deadband = policy->deadband;
1771 pid_params.setpoint = policy->setpoint;
1772}
1773
Jisheng Zhang29327c82016-06-27 18:07:17 +08001774static void __init copy_cpu_funcs(struct pstate_funcs *funcs)
Dirk Brandewie016c8152013-10-21 09:20:34 -07001775{
1776 pstate_funcs.get_max = funcs->get_max;
Srinivas Pandruvada3bcc6fa2015-10-14 16:12:00 -07001777 pstate_funcs.get_max_physical = funcs->get_max_physical;
Dirk Brandewie016c8152013-10-21 09:20:34 -07001778 pstate_funcs.get_min = funcs->get_min;
1779 pstate_funcs.get_turbo = funcs->get_turbo;
Dirk Brandewieb27580b2014-10-13 08:37:43 -07001780 pstate_funcs.get_scaling = funcs->get_scaling;
Rafael J. Wysockifdfdb2b2016-03-18 23:20:02 +01001781 pstate_funcs.get_val = funcs->get_val;
Dirk Brandewie007bea02013-12-18 10:32:39 -08001782 pstate_funcs.get_vid = funcs->get_vid;
Philippe Longepe157386b2015-12-04 17:40:30 +01001783 pstate_funcs.get_target_pstate = funcs->get_target_pstate;
1784
Dirk Brandewie016c8152013-10-21 09:20:34 -07001785}
1786
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -07001787#ifdef CONFIG_ACPI
Adrian Huangfbbcdc02013-10-31 23:24:05 +08001788
Jisheng Zhang29327c82016-06-27 18:07:17 +08001789static bool __init intel_pstate_no_acpi_pss(void)
Adrian Huangfbbcdc02013-10-31 23:24:05 +08001790{
1791 int i;
1792
1793 for_each_possible_cpu(i) {
1794 acpi_status status;
1795 union acpi_object *pss;
1796 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1797 struct acpi_processor *pr = per_cpu(processors, i);
1798
1799 if (!pr)
1800 continue;
1801
1802 status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer);
1803 if (ACPI_FAILURE(status))
1804 continue;
1805
1806 pss = buffer.pointer;
1807 if (pss && pss->type == ACPI_TYPE_PACKAGE) {
1808 kfree(pss);
1809 return false;
1810 }
1811
1812 kfree(pss);
1813 }
1814
1815 return true;
1816}
1817
Jisheng Zhang29327c82016-06-27 18:07:17 +08001818static bool __init intel_pstate_has_acpi_ppc(void)
ethan zhao966916e2014-12-01 11:32:08 +09001819{
1820 int i;
1821
1822 for_each_possible_cpu(i) {
1823 struct acpi_processor *pr = per_cpu(processors, i);
1824
1825 if (!pr)
1826 continue;
1827 if (acpi_has_method(pr->handle, "_PPC"))
1828 return true;
1829 }
1830 return false;
1831}
1832
1833enum {
1834 PSS,
1835 PPC,
1836};
1837
Adrian Huangfbbcdc02013-10-31 23:24:05 +08001838struct hw_vendor_info {
1839 u16 valid;
1840 char oem_id[ACPI_OEM_ID_SIZE];
1841 char oem_table_id[ACPI_OEM_TABLE_ID_SIZE];
ethan zhao966916e2014-12-01 11:32:08 +09001842 int oem_pwr_table;
Adrian Huangfbbcdc02013-10-31 23:24:05 +08001843};
1844
1845/* Hardware vendor-specific info that has its own power management modes */
Jisheng Zhang29327c82016-06-27 18:07:17 +08001846static struct hw_vendor_info vendor_info[] __initdata = {
ethan zhao966916e2014-12-01 11:32:08 +09001847 {1, "HP ", "ProLiant", PSS},
1848 {1, "ORACLE", "X4-2 ", PPC},
1849 {1, "ORACLE", "X4-2L ", PPC},
1850 {1, "ORACLE", "X4-2B ", PPC},
1851 {1, "ORACLE", "X3-2 ", PPC},
1852 {1, "ORACLE", "X3-2L ", PPC},
1853 {1, "ORACLE", "X3-2B ", PPC},
1854 {1, "ORACLE", "X4470M2 ", PPC},
1855 {1, "ORACLE", "X4270M3 ", PPC},
1856 {1, "ORACLE", "X4270M2 ", PPC},
1857 {1, "ORACLE", "X4170M2 ", PPC},
Ethan Zhao5aecc3c2015-08-05 09:28:50 +09001858 {1, "ORACLE", "X4170 M3", PPC},
1859 {1, "ORACLE", "X4275 M3", PPC},
1860 {1, "ORACLE", "X6-2 ", PPC},
1861 {1, "ORACLE", "Sudbury ", PPC},
Adrian Huangfbbcdc02013-10-31 23:24:05 +08001862 {0, "", ""},
1863};
1864
Jisheng Zhang29327c82016-06-27 18:07:17 +08001865static bool __init intel_pstate_platform_pwr_mgmt_exists(void)
Adrian Huangfbbcdc02013-10-31 23:24:05 +08001866{
1867 struct acpi_table_header hdr;
1868 struct hw_vendor_info *v_info;
Dirk Brandewie2f86dc42014-11-06 09:40:47 -08001869 const struct x86_cpu_id *id;
1870 u64 misc_pwr;
1871
1872 id = x86_match_cpu(intel_pstate_cpu_oob_ids);
1873 if (id) {
1874 rdmsrl(MSR_MISC_PWR_MGMT, misc_pwr);
1875 if ( misc_pwr & (1 << 8))
1876 return true;
1877 }
Adrian Huangfbbcdc02013-10-31 23:24:05 +08001878
Stratos Karafotisc4108332014-07-18 08:37:23 -07001879 if (acpi_disabled ||
1880 ACPI_FAILURE(acpi_get_table_header(ACPI_SIG_FADT, 0, &hdr)))
Adrian Huangfbbcdc02013-10-31 23:24:05 +08001881 return false;
1882
1883 for (v_info = vendor_info; v_info->valid; v_info++) {
Stratos Karafotisc4108332014-07-18 08:37:23 -07001884 if (!strncmp(hdr.oem_id, v_info->oem_id, ACPI_OEM_ID_SIZE) &&
ethan zhao966916e2014-12-01 11:32:08 +09001885 !strncmp(hdr.oem_table_id, v_info->oem_table_id,
1886 ACPI_OEM_TABLE_ID_SIZE))
1887 switch (v_info->oem_pwr_table) {
1888 case PSS:
1889 return intel_pstate_no_acpi_pss();
1890 case PPC:
Ethan Zhaoaa4ea342014-12-09 10:43:19 +09001891 return intel_pstate_has_acpi_ppc() &&
1892 (!force_load);
ethan zhao966916e2014-12-01 11:32:08 +09001893 }
Adrian Huangfbbcdc02013-10-31 23:24:05 +08001894 }
1895
1896 return false;
1897}
1898#else /* CONFIG_ACPI not enabled */
1899static inline bool intel_pstate_platform_pwr_mgmt_exists(void) { return false; }
ethan zhao966916e2014-12-01 11:32:08 +09001900static inline bool intel_pstate_has_acpi_ppc(void) { return false; }
Adrian Huangfbbcdc02013-10-31 23:24:05 +08001901#endif /* CONFIG_ACPI */
1902
Srinivas Pandruvada7791e4a2016-02-25 15:09:19 -08001903static const struct x86_cpu_id hwp_support_ids[] __initconst = {
1904 { X86_VENDOR_INTEL, 6, X86_MODEL_ANY, X86_FEATURE_HWP },
1905 {}
1906};
1907
Dirk Brandewie93f08222013-02-06 09:02:13 -08001908static int __init intel_pstate_init(void)
1909{
Dirk Brandewie907cc902013-03-05 14:15:27 -08001910 int cpu, rc = 0;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001911 const struct x86_cpu_id *id;
Borislav Petkov64df1fd2015-04-03 15:19:53 +02001912 struct cpu_defaults *cpu_def;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001913
Dirk Brandewie6be26492013-02-15 22:55:10 +01001914 if (no_load)
1915 return -ENODEV;
1916
Srinivas Pandruvada7791e4a2016-02-25 15:09:19 -08001917 if (x86_match_cpu(hwp_support_ids) && !no_hwp) {
1918 copy_cpu_funcs(&core_params.funcs);
1919 hwp_active++;
1920 goto hwp_cpu_matched;
1921 }
1922
Dirk Brandewie93f08222013-02-06 09:02:13 -08001923 id = x86_match_cpu(intel_pstate_cpu_ids);
1924 if (!id)
1925 return -ENODEV;
1926
Borislav Petkov64df1fd2015-04-03 15:19:53 +02001927 cpu_def = (struct cpu_defaults *)id->driver_data;
Dirk Brandewie016c8152013-10-21 09:20:34 -07001928
Borislav Petkov64df1fd2015-04-03 15:19:53 +02001929 copy_pid_params(&cpu_def->pid_policy);
1930 copy_cpu_funcs(&cpu_def->funcs);
Dirk Brandewie016c8152013-10-21 09:20:34 -07001931
Dirk Brandewieb563b4e2013-03-22 01:29:28 +01001932 if (intel_pstate_msrs_not_valid())
1933 return -ENODEV;
1934
Srinivas Pandruvada7791e4a2016-02-25 15:09:19 -08001935hwp_cpu_matched:
1936 /*
1937 * The Intel pstate driver will be ignored if the platform
1938 * firmware has its own power management modes.
1939 */
1940 if (intel_pstate_platform_pwr_mgmt_exists())
1941 return -ENODEV;
1942
Joe Perches4836df12016-04-05 13:28:23 -07001943 pr_info("Intel P-state driver initializing\n");
Dirk Brandewie93f08222013-02-06 09:02:13 -08001944
Wei Yongjunb57ffac2013-05-13 08:03:43 +00001945 all_cpu_data = vzalloc(sizeof(void *) * num_possible_cpus());
Dirk Brandewie93f08222013-02-06 09:02:13 -08001946 if (!all_cpu_data)
1947 return -ENOMEM;
Dirk Brandewie93f08222013-02-06 09:02:13 -08001948
Kristen Carlson Accardid64c3b02015-02-06 13:41:55 -08001949 if (!hwp_active && hwp_only)
1950 goto out;
1951
Dirk Brandewie93f08222013-02-06 09:02:13 -08001952 rc = cpufreq_register_driver(&intel_pstate_driver);
1953 if (rc)
1954 goto out;
1955
1956 intel_pstate_debug_expose_params();
1957 intel_pstate_sysfs_expose_params();
Dirk Brandewieb69880f2014-01-16 10:32:25 -08001958
Srinivas Pandruvada7791e4a2016-02-25 15:09:19 -08001959 if (hwp_active)
Joe Perches4836df12016-04-05 13:28:23 -07001960 pr_info("HWP enabled\n");
Srinivas Pandruvada7791e4a2016-02-25 15:09:19 -08001961
Dirk Brandewie93f08222013-02-06 09:02:13 -08001962 return rc;
1963out:
Dirk Brandewie907cc902013-03-05 14:15:27 -08001964 get_online_cpus();
1965 for_each_online_cpu(cpu) {
1966 if (all_cpu_data[cpu]) {
Rafael J. Wysockibb6ab522016-03-31 17:42:15 +02001967 intel_pstate_clear_update_util_hook(cpu);
Dirk Brandewie907cc902013-03-05 14:15:27 -08001968 kfree(all_cpu_data[cpu]);
1969 }
1970 }
1971
1972 put_online_cpus();
1973 vfree(all_cpu_data);
Dirk Brandewie93f08222013-02-06 09:02:13 -08001974 return -ENODEV;
1975}
1976device_initcall(intel_pstate_init);
1977
Dirk Brandewie6be26492013-02-15 22:55:10 +01001978static int __init intel_pstate_setup(char *str)
1979{
1980 if (!str)
1981 return -EINVAL;
1982
1983 if (!strcmp(str, "disable"))
1984 no_load = 1;
Prarit Bhargava539342f2015-10-22 09:43:31 -04001985 if (!strcmp(str, "no_hwp")) {
Joe Perches4836df12016-04-05 13:28:23 -07001986 pr_info("HWP disabled\n");
Dirk Brandewie2f86dc42014-11-06 09:40:47 -08001987 no_hwp = 1;
Prarit Bhargava539342f2015-10-22 09:43:31 -04001988 }
Ethan Zhaoaa4ea342014-12-09 10:43:19 +09001989 if (!strcmp(str, "force"))
1990 force_load = 1;
Kristen Carlson Accardid64c3b02015-02-06 13:41:55 -08001991 if (!strcmp(str, "hwp_only"))
1992 hwp_only = 1;
Srinivas Pandruvadaeae48f02016-10-25 13:20:40 -07001993 if (!strcmp(str, "per_cpu_perf_limits"))
1994 per_cpu_limits = true;
Srinivas Pandruvada9522a2f2016-04-27 15:48:06 -07001995
1996#ifdef CONFIG_ACPI
1997 if (!strcmp(str, "support_acpi_ppc"))
1998 acpi_ppc = true;
1999#endif
2000
Dirk Brandewie6be26492013-02-15 22:55:10 +01002001 return 0;
2002}
2003early_param("intel_pstate", intel_pstate_setup);
2004
Dirk Brandewie93f08222013-02-06 09:02:13 -08002005MODULE_AUTHOR("Dirk Brandewie <dirk.j.brandewie@intel.com>");
2006MODULE_DESCRIPTION("'intel_pstate' - P state driver Intel Core processors");
2007MODULE_LICENSE("GPL");