intel_pstate.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854
  1. /*
  2. * intel_pstate.c: Native P state management for Intel processors
  3. *
  4. * (C) Copyright 2012 Intel Corporation
  5. * Author: Dirk Brandewie <dirk.j.brandewie@intel.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; version 2
  10. * of the License.
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/kernel.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/module.h>
  16. #include <linux/ktime.h>
  17. #include <linux/hrtimer.h>
  18. #include <linux/tick.h>
  19. #include <linux/slab.h>
  20. #include <linux/sched.h>
  21. #include <linux/list.h>
  22. #include <linux/cpu.h>
  23. #include <linux/cpufreq.h>
  24. #include <linux/sysfs.h>
  25. #include <linux/types.h>
  26. #include <linux/fs.h>
  27. #include <linux/debugfs.h>
  28. #include <linux/acpi.h>
  29. #include <linux/vmalloc.h>
  30. #include <trace/events/power.h>
  31. #include <asm/div64.h>
  32. #include <asm/msr.h>
  33. #include <asm/cpu_device_id.h>
  34. #include <asm/cpufeature.h>
  35. #include <asm/intel-family.h>
  36. #define ATOM_RATIOS 0x66a
  37. #define ATOM_VIDS 0x66b
  38. #define ATOM_TURBO_RATIOS 0x66c
  39. #define ATOM_TURBO_VIDS 0x66d
  40. #ifdef CONFIG_ACPI
  41. #include <acpi/processor.h>
  42. #endif
  43. #define FRAC_BITS 8
  44. #define int_tofp(X) ((int64_t)(X) << FRAC_BITS)
  45. #define fp_toint(X) ((X) >> FRAC_BITS)
  46. #define EXT_BITS 6
  47. #define EXT_FRAC_BITS (EXT_BITS + FRAC_BITS)
  48. static inline int32_t mul_fp(int32_t x, int32_t y)
  49. {
  50. return ((int64_t)x * (int64_t)y) >> FRAC_BITS;
  51. }
  52. static inline int32_t div_fp(s64 x, s64 y)
  53. {
  54. return div64_s64((int64_t)x << FRAC_BITS, y);
  55. }
  56. static inline int ceiling_fp(int32_t x)
  57. {
  58. int mask, ret;
  59. ret = fp_toint(x);
  60. mask = (1 << FRAC_BITS) - 1;
  61. if (x & mask)
  62. ret += 1;
  63. return ret;
  64. }
  65. static inline u64 mul_ext_fp(u64 x, u64 y)
  66. {
  67. return (x * y) >> EXT_FRAC_BITS;
  68. }
  69. static inline u64 div_ext_fp(u64 x, u64 y)
  70. {
  71. return div64_u64(x << EXT_FRAC_BITS, y);
  72. }
  73. /**
  74. * struct sample - Store performance sample
  75. * @core_avg_perf: Ratio of APERF/MPERF which is the actual average
  76. * performance during last sample period
  77. * @busy_scaled: Scaled busy value which is used to calculate next
  78. * P state. This can be different than core_avg_perf
  79. * to account for cpu idle period
  80. * @aperf: Difference of actual performance frequency clock count
  81. * read from APERF MSR between last and current sample
  82. * @mperf: Difference of maximum performance frequency clock count
  83. * read from MPERF MSR between last and current sample
  84. * @tsc: Difference of time stamp counter between last and
  85. * current sample
  86. * @time: Current time from scheduler
  87. *
  88. * This structure is used in the cpudata structure to store performance sample
  89. * data for choosing next P State.
  90. */
  91. struct sample {
  92. int32_t core_avg_perf;
  93. int32_t busy_scaled;
  94. u64 aperf;
  95. u64 mperf;
  96. u64 tsc;
  97. u64 time;
  98. };
  99. /**
  100. * struct pstate_data - Store P state data
  101. * @current_pstate: Current requested P state
  102. * @min_pstate: Min P state possible for this platform
  103. * @max_pstate: Max P state possible for this platform
  104. * @max_pstate_physical:This is physical Max P state for a processor
  105. * This can be higher than the max_pstate which can
  106. * be limited by platform thermal design power limits
  107. * @scaling: Scaling factor to convert frequency to cpufreq
  108. * frequency units
  109. * @turbo_pstate: Max Turbo P state possible for this platform
  110. *
  111. * Stores the per cpu model P state limits and current P state.
  112. */
  113. struct pstate_data {
  114. int current_pstate;
  115. int min_pstate;
  116. int max_pstate;
  117. int max_pstate_physical;
  118. int scaling;
  119. int turbo_pstate;
  120. };
  121. /**
  122. * struct vid_data - Stores voltage information data
  123. * @min: VID data for this platform corresponding to
  124. * the lowest P state
  125. * @max: VID data corresponding to the highest P State.
  126. * @turbo: VID data for turbo P state
  127. * @ratio: Ratio of (vid max - vid min) /
  128. * (max P state - Min P State)
  129. *
  130. * Stores the voltage data for DVFS (Dynamic Voltage and Frequency Scaling)
  131. * This data is used in Atom platforms, where in addition to target P state,
  132. * the voltage data needs to be specified to select next P State.
  133. */
  134. struct vid_data {
  135. int min;
  136. int max;
  137. int turbo;
  138. int32_t ratio;
  139. };
  140. /**
  141. * struct _pid - Stores PID data
  142. * @setpoint: Target set point for busyness or performance
  143. * @integral: Storage for accumulated error values
  144. * @p_gain: PID proportional gain
  145. * @i_gain: PID integral gain
  146. * @d_gain: PID derivative gain
  147. * @deadband: PID deadband
  148. * @last_err: Last error storage for integral part of PID calculation
  149. *
  150. * Stores PID coefficients and last error for PID controller.
  151. */
  152. struct _pid {
  153. int setpoint;
  154. int32_t integral;
  155. int32_t p_gain;
  156. int32_t i_gain;
  157. int32_t d_gain;
  158. int deadband;
  159. int32_t last_err;
  160. };
  161. /**
  162. * struct cpudata - Per CPU instance data storage
  163. * @cpu: CPU number for this instance data
  164. * @update_util: CPUFreq utility callback information
  165. * @update_util_set: CPUFreq utility callback is set
  166. * @pstate: Stores P state limits for this CPU
  167. * @vid: Stores VID limits for this CPU
  168. * @pid: Stores PID parameters for this CPU
  169. * @last_sample_time: Last Sample time
  170. * @prev_aperf: Last APERF value read from APERF MSR
  171. * @prev_mperf: Last MPERF value read from MPERF MSR
  172. * @prev_tsc: Last timestamp counter (TSC) value
  173. * @prev_cummulative_iowait: IO Wait time difference from last and
  174. * current sample
  175. * @sample: Storage for storing last Sample data
  176. * @acpi_perf_data: Stores ACPI perf information read from _PSS
  177. * @valid_pss_table: Set to true for valid ACPI _PSS entries found
  178. *
  179. * This structure stores per CPU instance data for all CPUs.
  180. */
  181. struct cpudata {
  182. int cpu;
  183. struct update_util_data update_util;
  184. bool update_util_set;
  185. struct pstate_data pstate;
  186. struct vid_data vid;
  187. struct _pid pid;
  188. u64 last_sample_time;
  189. u64 prev_aperf;
  190. u64 prev_mperf;
  191. u64 prev_tsc;
  192. u64 prev_cummulative_iowait;
  193. struct sample sample;
  194. #ifdef CONFIG_ACPI
  195. struct acpi_processor_performance acpi_perf_data;
  196. bool valid_pss_table;
  197. #endif
  198. };
  199. static struct cpudata **all_cpu_data;
  200. /**
  201. * struct pid_adjust_policy - Stores static PID configuration data
  202. * @sample_rate_ms: PID calculation sample rate in ms
  203. * @sample_rate_ns: Sample rate calculation in ns
  204. * @deadband: PID deadband
  205. * @setpoint: PID Setpoint
  206. * @p_gain_pct: PID proportional gain
  207. * @i_gain_pct: PID integral gain
  208. * @d_gain_pct: PID derivative gain
  209. *
  210. * Stores per CPU model static PID configuration data.
  211. */
  212. struct pstate_adjust_policy {
  213. int sample_rate_ms;
  214. s64 sample_rate_ns;
  215. int deadband;
  216. int setpoint;
  217. int p_gain_pct;
  218. int d_gain_pct;
  219. int i_gain_pct;
  220. };
  221. /**
  222. * struct pstate_funcs - Per CPU model specific callbacks
  223. * @get_max: Callback to get maximum non turbo effective P state
  224. * @get_max_physical: Callback to get maximum non turbo physical P state
  225. * @get_min: Callback to get minimum P state
  226. * @get_turbo: Callback to get turbo P state
  227. * @get_scaling: Callback to get frequency scaling factor
  228. * @get_val: Callback to convert P state to actual MSR write value
  229. * @get_vid: Callback to get VID data for Atom platforms
  230. * @get_target_pstate: Callback to a function to calculate next P state to use
  231. *
  232. * Core and Atom CPU models have different way to get P State limits. This
  233. * structure is used to store those callbacks.
  234. */
  235. struct pstate_funcs {
  236. int (*get_max)(void);
  237. int (*get_max_physical)(void);
  238. int (*get_min)(void);
  239. int (*get_turbo)(void);
  240. int (*get_scaling)(void);
  241. u64 (*get_val)(struct cpudata*, int pstate);
  242. void (*get_vid)(struct cpudata *);
  243. int32_t (*get_target_pstate)(struct cpudata *);
  244. };
  245. /**
  246. * struct cpu_defaults- Per CPU model default config data
  247. * @pid_policy: PID config data
  248. * @funcs: Callback function data
  249. */
  250. struct cpu_defaults {
  251. struct pstate_adjust_policy pid_policy;
  252. struct pstate_funcs funcs;
  253. };
  254. static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu);
  255. static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu);
  256. static struct pstate_adjust_policy pid_params __read_mostly;
  257. static struct pstate_funcs pstate_funcs __read_mostly;
  258. static int hwp_active __read_mostly;
  259. #ifdef CONFIG_ACPI
  260. static bool acpi_ppc;
  261. #endif
  262. /**
  263. * struct perf_limits - Store user and policy limits
  264. * @no_turbo: User requested turbo state from intel_pstate sysfs
  265. * @turbo_disabled: Platform turbo status either from msr
  266. * MSR_IA32_MISC_ENABLE or when maximum available pstate
  267. * matches the maximum turbo pstate
  268. * @max_perf_pct: Effective maximum performance limit in percentage, this
  269. * is minimum of either limits enforced by cpufreq policy
  270. * or limits from user set limits via intel_pstate sysfs
  271. * @min_perf_pct: Effective minimum performance limit in percentage, this
  272. * is maximum of either limits enforced by cpufreq policy
  273. * or limits from user set limits via intel_pstate sysfs
  274. * @max_perf: This is a scaled value between 0 to 255 for max_perf_pct
  275. * This value is used to limit max pstate
  276. * @min_perf: This is a scaled value between 0 to 255 for min_perf_pct
  277. * This value is used to limit min pstate
  278. * @max_policy_pct: The maximum performance in percentage enforced by
  279. * cpufreq setpolicy interface
  280. * @max_sysfs_pct: The maximum performance in percentage enforced by
  281. * intel pstate sysfs interface
  282. * @min_policy_pct: The minimum performance in percentage enforced by
  283. * cpufreq setpolicy interface
  284. * @min_sysfs_pct: The minimum performance in percentage enforced by
  285. * intel pstate sysfs interface
  286. *
  287. * Storage for user and policy defined limits.
  288. */
  289. struct perf_limits {
  290. int no_turbo;
  291. int turbo_disabled;
  292. int max_perf_pct;
  293. int min_perf_pct;
  294. int32_t max_perf;
  295. int32_t min_perf;
  296. int max_policy_pct;
  297. int max_sysfs_pct;
  298. int min_policy_pct;
  299. int min_sysfs_pct;
  300. };
  301. static struct perf_limits performance_limits = {
  302. .no_turbo = 0,
  303. .turbo_disabled = 0,
  304. .max_perf_pct = 100,
  305. .max_perf = int_tofp(1),
  306. .min_perf_pct = 100,
  307. .min_perf = int_tofp(1),
  308. .max_policy_pct = 100,
  309. .max_sysfs_pct = 100,
  310. .min_policy_pct = 0,
  311. .min_sysfs_pct = 0,
  312. };
  313. static struct perf_limits powersave_limits = {
  314. .no_turbo = 0,
  315. .turbo_disabled = 0,
  316. .max_perf_pct = 100,
  317. .max_perf = int_tofp(1),
  318. .min_perf_pct = 0,
  319. .min_perf = 0,
  320. .max_policy_pct = 100,
  321. .max_sysfs_pct = 100,
  322. .min_policy_pct = 0,
  323. .min_sysfs_pct = 0,
  324. };
  325. #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
  326. static struct perf_limits *limits = &performance_limits;
  327. #else
  328. static struct perf_limits *limits = &powersave_limits;
  329. #endif
  330. #ifdef CONFIG_ACPI
  331. static bool intel_pstate_get_ppc_enable_status(void)
  332. {
  333. if (acpi_gbl_FADT.preferred_profile == PM_ENTERPRISE_SERVER ||
  334. acpi_gbl_FADT.preferred_profile == PM_PERFORMANCE_SERVER)
  335. return true;
  336. return acpi_ppc;
  337. }
  338. static void intel_pstate_init_acpi_perf_limits(struct cpufreq_policy *policy)
  339. {
  340. struct cpudata *cpu;
  341. int ret;
  342. int i;
  343. if (hwp_active)
  344. return;
  345. if (!intel_pstate_get_ppc_enable_status())
  346. return;
  347. cpu = all_cpu_data[policy->cpu];
  348. ret = acpi_processor_register_performance(&cpu->acpi_perf_data,
  349. policy->cpu);
  350. if (ret)
  351. return;
  352. /*
  353. * Check if the control value in _PSS is for PERF_CTL MSR, which should
  354. * guarantee that the states returned by it map to the states in our
  355. * list directly.
  356. */
  357. if (cpu->acpi_perf_data.control_register.space_id !=
  358. ACPI_ADR_SPACE_FIXED_HARDWARE)
  359. goto err;
  360. /*
  361. * If there is only one entry _PSS, simply ignore _PSS and continue as
  362. * usual without taking _PSS into account
  363. */
  364. if (cpu->acpi_perf_data.state_count < 2)
  365. goto err;
  366. pr_debug("CPU%u - ACPI _PSS perf data\n", policy->cpu);
  367. for (i = 0; i < cpu->acpi_perf_data.state_count; i++) {
  368. pr_debug(" %cP%d: %u MHz, %u mW, 0x%x\n",
  369. (i == cpu->acpi_perf_data.state ? '*' : ' '), i,
  370. (u32) cpu->acpi_perf_data.states[i].core_frequency,
  371. (u32) cpu->acpi_perf_data.states[i].power,
  372. (u32) cpu->acpi_perf_data.states[i].control);
  373. }
  374. /*
  375. * The _PSS table doesn't contain whole turbo frequency range.
  376. * This just contains +1 MHZ above the max non turbo frequency,
  377. * with control value corresponding to max turbo ratio. But
  378. * when cpufreq set policy is called, it will call with this
  379. * max frequency, which will cause a reduced performance as
  380. * this driver uses real max turbo frequency as the max
  381. * frequency. So correct this frequency in _PSS table to
  382. * correct max turbo frequency based on the turbo state.
  383. * Also need to convert to MHz as _PSS freq is in MHz.
  384. */
  385. if (!limits->turbo_disabled)
  386. cpu->acpi_perf_data.states[0].core_frequency =
  387. policy->cpuinfo.max_freq / 1000;
  388. cpu->valid_pss_table = true;
  389. pr_debug("_PPC limits will be enforced\n");
  390. return;
  391. err:
  392. cpu->valid_pss_table = false;
  393. acpi_processor_unregister_performance(policy->cpu);
  394. }
  395. static void intel_pstate_exit_perf_limits(struct cpufreq_policy *policy)
  396. {
  397. struct cpudata *cpu;
  398. cpu = all_cpu_data[policy->cpu];
  399. if (!cpu->valid_pss_table)
  400. return;
  401. acpi_processor_unregister_performance(policy->cpu);
  402. }
  403. #else
  404. static void intel_pstate_init_acpi_perf_limits(struct cpufreq_policy *policy)
  405. {
  406. }
  407. static void intel_pstate_exit_perf_limits(struct cpufreq_policy *policy)
  408. {
  409. }
  410. #endif
  411. static inline void pid_reset(struct _pid *pid, int setpoint, int busy,
  412. int deadband, int integral) {
  413. pid->setpoint = int_tofp(setpoint);
  414. pid->deadband = int_tofp(deadband);
  415. pid->integral = int_tofp(integral);
  416. pid->last_err = int_tofp(setpoint) - int_tofp(busy);
  417. }
  418. static inline void pid_p_gain_set(struct _pid *pid, int percent)
  419. {
  420. pid->p_gain = div_fp(percent, 100);
  421. }
  422. static inline void pid_i_gain_set(struct _pid *pid, int percent)
  423. {
  424. pid->i_gain = div_fp(percent, 100);
  425. }
  426. static inline void pid_d_gain_set(struct _pid *pid, int percent)
  427. {
  428. pid->d_gain = div_fp(percent, 100);
  429. }
  430. static signed int pid_calc(struct _pid *pid, int32_t busy)
  431. {
  432. signed int result;
  433. int32_t pterm, dterm, fp_error;
  434. int32_t integral_limit;
  435. fp_error = pid->setpoint - busy;
  436. if (abs(fp_error) <= pid->deadband)
  437. return 0;
  438. pterm = mul_fp(pid->p_gain, fp_error);
  439. pid->integral += fp_error;
  440. /*
  441. * We limit the integral here so that it will never
  442. * get higher than 30. This prevents it from becoming
  443. * too large an input over long periods of time and allows
  444. * it to get factored out sooner.
  445. *
  446. * The value of 30 was chosen through experimentation.
  447. */
  448. integral_limit = int_tofp(30);
  449. if (pid->integral > integral_limit)
  450. pid->integral = integral_limit;
  451. if (pid->integral < -integral_limit)
  452. pid->integral = -integral_limit;
  453. dterm = mul_fp(pid->d_gain, fp_error - pid->last_err);
  454. pid->last_err = fp_error;
  455. result = pterm + mul_fp(pid->integral, pid->i_gain) + dterm;
  456. result = result + (1 << (FRAC_BITS-1));
  457. return (signed int)fp_toint(result);
  458. }
  459. static inline void intel_pstate_busy_pid_reset(struct cpudata *cpu)
  460. {
  461. pid_p_gain_set(&cpu->pid, pid_params.p_gain_pct);
  462. pid_d_gain_set(&cpu->pid, pid_params.d_gain_pct);
  463. pid_i_gain_set(&cpu->pid, pid_params.i_gain_pct);
  464. pid_reset(&cpu->pid, pid_params.setpoint, 100, pid_params.deadband, 0);
  465. }
  466. static inline void intel_pstate_reset_all_pid(void)
  467. {
  468. unsigned int cpu;
  469. for_each_online_cpu(cpu) {
  470. if (all_cpu_data[cpu])
  471. intel_pstate_busy_pid_reset(all_cpu_data[cpu]);
  472. }
  473. }
  474. static inline void update_turbo_state(void)
  475. {
  476. u64 misc_en;
  477. struct cpudata *cpu;
  478. cpu = all_cpu_data[0];
  479. rdmsrl(MSR_IA32_MISC_ENABLE, misc_en);
  480. limits->turbo_disabled =
  481. (misc_en & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ||
  482. cpu->pstate.max_pstate == cpu->pstate.turbo_pstate);
  483. }
  484. static void intel_pstate_hwp_set(const struct cpumask *cpumask)
  485. {
  486. int min, hw_min, max, hw_max, cpu, range, adj_range;
  487. u64 value, cap;
  488. rdmsrl(MSR_HWP_CAPABILITIES, cap);
  489. hw_min = HWP_LOWEST_PERF(cap);
  490. hw_max = HWP_HIGHEST_PERF(cap);
  491. range = hw_max - hw_min;
  492. for_each_cpu(cpu, cpumask) {
  493. rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value);
  494. adj_range = limits->min_perf_pct * range / 100;
  495. min = hw_min + adj_range;
  496. value &= ~HWP_MIN_PERF(~0L);
  497. value |= HWP_MIN_PERF(min);
  498. adj_range = limits->max_perf_pct * range / 100;
  499. max = hw_min + adj_range;
  500. if (limits->no_turbo) {
  501. hw_max = HWP_GUARANTEED_PERF(cap);
  502. if (hw_max < max)
  503. max = hw_max;
  504. }
  505. value &= ~HWP_MAX_PERF(~0L);
  506. value |= HWP_MAX_PERF(max);
  507. wrmsrl_on_cpu(cpu, MSR_HWP_REQUEST, value);
  508. }
  509. }
  510. static int intel_pstate_hwp_set_policy(struct cpufreq_policy *policy)
  511. {
  512. if (hwp_active)
  513. intel_pstate_hwp_set(policy->cpus);
  514. return 0;
  515. }
  516. static void intel_pstate_hwp_set_online_cpus(void)
  517. {
  518. get_online_cpus();
  519. intel_pstate_hwp_set(cpu_online_mask);
  520. put_online_cpus();
  521. }
  522. /************************** debugfs begin ************************/
  523. static int pid_param_set(void *data, u64 val)
  524. {
  525. *(u32 *)data = val;
  526. intel_pstate_reset_all_pid();
  527. return 0;
  528. }
  529. static int pid_param_get(void *data, u64 *val)
  530. {
  531. *val = *(u32 *)data;
  532. return 0;
  533. }
  534. DEFINE_SIMPLE_ATTRIBUTE(fops_pid_param, pid_param_get, pid_param_set, "%llu\n");
  535. struct pid_param {
  536. char *name;
  537. void *value;
  538. };
  539. static struct pid_param pid_files[] = {
  540. {"sample_rate_ms", &pid_params.sample_rate_ms},
  541. {"d_gain_pct", &pid_params.d_gain_pct},
  542. {"i_gain_pct", &pid_params.i_gain_pct},
  543. {"deadband", &pid_params.deadband},
  544. {"setpoint", &pid_params.setpoint},
  545. {"p_gain_pct", &pid_params.p_gain_pct},
  546. {NULL, NULL}
  547. };
  548. static void __init intel_pstate_debug_expose_params(void)
  549. {
  550. struct dentry *debugfs_parent;
  551. int i = 0;
  552. if (hwp_active)
  553. return;
  554. debugfs_parent = debugfs_create_dir("pstate_snb", NULL);
  555. if (IS_ERR_OR_NULL(debugfs_parent))
  556. return;
  557. while (pid_files[i].name) {
  558. debugfs_create_file(pid_files[i].name, 0660,
  559. debugfs_parent, pid_files[i].value,
  560. &fops_pid_param);
  561. i++;
  562. }
  563. }
  564. /************************** debugfs end ************************/
  565. /************************** sysfs begin ************************/
  566. #define show_one(file_name, object) \
  567. static ssize_t show_##file_name \
  568. (struct kobject *kobj, struct attribute *attr, char *buf) \
  569. { \
  570. return sprintf(buf, "%u\n", limits->object); \
  571. }
  572. static ssize_t show_turbo_pct(struct kobject *kobj,
  573. struct attribute *attr, char *buf)
  574. {
  575. struct cpudata *cpu;
  576. int total, no_turbo, turbo_pct;
  577. uint32_t turbo_fp;
  578. cpu = all_cpu_data[0];
  579. total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1;
  580. no_turbo = cpu->pstate.max_pstate - cpu->pstate.min_pstate + 1;
  581. turbo_fp = div_fp(no_turbo, total);
  582. turbo_pct = 100 - fp_toint(mul_fp(turbo_fp, int_tofp(100)));
  583. return sprintf(buf, "%u\n", turbo_pct);
  584. }
  585. static ssize_t show_num_pstates(struct kobject *kobj,
  586. struct attribute *attr, char *buf)
  587. {
  588. struct cpudata *cpu;
  589. int total;
  590. cpu = all_cpu_data[0];
  591. total = cpu->pstate.turbo_pstate - cpu->pstate.min_pstate + 1;
  592. return sprintf(buf, "%u\n", total);
  593. }
  594. static ssize_t show_no_turbo(struct kobject *kobj,
  595. struct attribute *attr, char *buf)
  596. {
  597. ssize_t ret;
  598. update_turbo_state();
  599. if (limits->turbo_disabled)
  600. ret = sprintf(buf, "%u\n", limits->turbo_disabled);
  601. else
  602. ret = sprintf(buf, "%u\n", limits->no_turbo);
  603. return ret;
  604. }
  605. static ssize_t store_no_turbo(struct kobject *a, struct attribute *b,
  606. const char *buf, size_t count)
  607. {
  608. unsigned int input;
  609. int ret;
  610. ret = sscanf(buf, "%u", &input);
  611. if (ret != 1)
  612. return -EINVAL;
  613. update_turbo_state();
  614. if (limits->turbo_disabled) {
  615. pr_warn("Turbo disabled by BIOS or unavailable on processor\n");
  616. return -EPERM;
  617. }
  618. limits->no_turbo = clamp_t(int, input, 0, 1);
  619. if (hwp_active)
  620. intel_pstate_hwp_set_online_cpus();
  621. return count;
  622. }
  623. static ssize_t store_max_perf_pct(struct kobject *a, struct attribute *b,
  624. const char *buf, size_t count)
  625. {
  626. unsigned int input;
  627. int ret;
  628. ret = sscanf(buf, "%u", &input);
  629. if (ret != 1)
  630. return -EINVAL;
  631. limits->max_sysfs_pct = clamp_t(int, input, 0 , 100);
  632. limits->max_perf_pct = min(limits->max_policy_pct,
  633. limits->max_sysfs_pct);
  634. limits->max_perf_pct = max(limits->min_policy_pct,
  635. limits->max_perf_pct);
  636. limits->max_perf_pct = max(limits->min_perf_pct,
  637. limits->max_perf_pct);
  638. limits->max_perf = div_fp(limits->max_perf_pct, 100);
  639. if (hwp_active)
  640. intel_pstate_hwp_set_online_cpus();
  641. return count;
  642. }
  643. static ssize_t store_min_perf_pct(struct kobject *a, struct attribute *b,
  644. const char *buf, size_t count)
  645. {
  646. unsigned int input;
  647. int ret;
  648. ret = sscanf(buf, "%u", &input);
  649. if (ret != 1)
  650. return -EINVAL;
  651. limits->min_sysfs_pct = clamp_t(int, input, 0 , 100);
  652. limits->min_perf_pct = max(limits->min_policy_pct,
  653. limits->min_sysfs_pct);
  654. limits->min_perf_pct = min(limits->max_policy_pct,
  655. limits->min_perf_pct);
  656. limits->min_perf_pct = min(limits->max_perf_pct,
  657. limits->min_perf_pct);
  658. limits->min_perf = div_fp(limits->min_perf_pct, 100);
  659. if (hwp_active)
  660. intel_pstate_hwp_set_online_cpus();
  661. return count;
  662. }
  663. show_one(max_perf_pct, max_perf_pct);
  664. show_one(min_perf_pct, min_perf_pct);
  665. define_one_global_rw(no_turbo);
  666. define_one_global_rw(max_perf_pct);
  667. define_one_global_rw(min_perf_pct);
  668. define_one_global_ro(turbo_pct);
  669. define_one_global_ro(num_pstates);
  670. static struct attribute *intel_pstate_attributes[] = {
  671. &no_turbo.attr,
  672. &max_perf_pct.attr,
  673. &min_perf_pct.attr,
  674. &turbo_pct.attr,
  675. &num_pstates.attr,
  676. NULL
  677. };
  678. static struct attribute_group intel_pstate_attr_group = {
  679. .attrs = intel_pstate_attributes,
  680. };
  681. static void __init intel_pstate_sysfs_expose_params(void)
  682. {
  683. struct kobject *intel_pstate_kobject;
  684. int rc;
  685. intel_pstate_kobject = kobject_create_and_add("intel_pstate",
  686. &cpu_subsys.dev_root->kobj);
  687. BUG_ON(!intel_pstate_kobject);
  688. rc = sysfs_create_group(intel_pstate_kobject, &intel_pstate_attr_group);
  689. BUG_ON(rc);
  690. }
  691. /************************** sysfs end ************************/
  692. static void intel_pstate_hwp_enable(struct cpudata *cpudata)
  693. {
  694. /* First disable HWP notification interrupt as we don't process them */
  695. if (static_cpu_has(X86_FEATURE_HWP_NOTIFY))
  696. wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x00);
  697. wrmsrl_on_cpu(cpudata->cpu, MSR_PM_ENABLE, 0x1);
  698. }
  699. static int atom_get_min_pstate(void)
  700. {
  701. u64 value;
  702. rdmsrl(ATOM_RATIOS, value);
  703. return (value >> 8) & 0x7F;
  704. }
  705. static int atom_get_max_pstate(void)
  706. {
  707. u64 value;
  708. rdmsrl(ATOM_RATIOS, value);
  709. return (value >> 16) & 0x7F;
  710. }
  711. static int atom_get_turbo_pstate(void)
  712. {
  713. u64 value;
  714. rdmsrl(ATOM_TURBO_RATIOS, value);
  715. return value & 0x7F;
  716. }
  717. static u64 atom_get_val(struct cpudata *cpudata, int pstate)
  718. {
  719. u64 val;
  720. int32_t vid_fp;
  721. u32 vid;
  722. val = (u64)pstate << 8;
  723. if (limits->no_turbo && !limits->turbo_disabled)
  724. val |= (u64)1 << 32;
  725. vid_fp = cpudata->vid.min + mul_fp(
  726. int_tofp(pstate - cpudata->pstate.min_pstate),
  727. cpudata->vid.ratio);
  728. vid_fp = clamp_t(int32_t, vid_fp, cpudata->vid.min, cpudata->vid.max);
  729. vid = ceiling_fp(vid_fp);
  730. if (pstate > cpudata->pstate.max_pstate)
  731. vid = cpudata->vid.turbo;
  732. return val | vid;
  733. }
  734. static int silvermont_get_scaling(void)
  735. {
  736. u64 value;
  737. int i;
  738. /* Defined in Table 35-6 from SDM (Sept 2015) */
  739. static int silvermont_freq_table[] = {
  740. 83300, 100000, 133300, 116700, 80000};
  741. rdmsrl(MSR_FSB_FREQ, value);
  742. i = value & 0x7;
  743. WARN_ON(i > 4);
  744. return silvermont_freq_table[i];
  745. }
  746. static int airmont_get_scaling(void)
  747. {
  748. u64 value;
  749. int i;
  750. /* Defined in Table 35-10 from SDM (Sept 2015) */
  751. static int airmont_freq_table[] = {
  752. 83300, 100000, 133300, 116700, 80000,
  753. 93300, 90000, 88900, 87500};
  754. rdmsrl(MSR_FSB_FREQ, value);
  755. i = value & 0xF;
  756. WARN_ON(i > 8);
  757. return airmont_freq_table[i];
  758. }
  759. static void atom_get_vid(struct cpudata *cpudata)
  760. {
  761. u64 value;
  762. rdmsrl(ATOM_VIDS, value);
  763. cpudata->vid.min = int_tofp((value >> 8) & 0x7f);
  764. cpudata->vid.max = int_tofp((value >> 16) & 0x7f);
  765. cpudata->vid.ratio = div_fp(
  766. cpudata->vid.max - cpudata->vid.min,
  767. int_tofp(cpudata->pstate.max_pstate -
  768. cpudata->pstate.min_pstate));
  769. rdmsrl(ATOM_TURBO_VIDS, value);
  770. cpudata->vid.turbo = value & 0x7f;
  771. }
  772. static int core_get_min_pstate(void)
  773. {
  774. u64 value;
  775. rdmsrl(MSR_PLATFORM_INFO, value);
  776. return (value >> 40) & 0xFF;
  777. }
  778. static int core_get_max_pstate_physical(void)
  779. {
  780. u64 value;
  781. rdmsrl(MSR_PLATFORM_INFO, value);
  782. return (value >> 8) & 0xFF;
  783. }
  784. static int core_get_max_pstate(void)
  785. {
  786. u64 tar;
  787. u64 plat_info;
  788. int max_pstate;
  789. int err;
  790. rdmsrl(MSR_PLATFORM_INFO, plat_info);
  791. max_pstate = (plat_info >> 8) & 0xFF;
  792. err = rdmsrl_safe(MSR_TURBO_ACTIVATION_RATIO, &tar);
  793. if (!err) {
  794. /* Do some sanity checking for safety */
  795. if (plat_info & 0x600000000) {
  796. u64 tdp_ctrl;
  797. u64 tdp_ratio;
  798. int tdp_msr;
  799. err = rdmsrl_safe(MSR_CONFIG_TDP_CONTROL, &tdp_ctrl);
  800. if (err)
  801. goto skip_tar;
  802. tdp_msr = MSR_CONFIG_TDP_NOMINAL + (tdp_ctrl & 0x3);
  803. err = rdmsrl_safe(tdp_msr, &tdp_ratio);
  804. if (err)
  805. goto skip_tar;
  806. /* For level 1 and 2, bits[23:16] contain the ratio */
  807. if (tdp_ctrl)
  808. tdp_ratio >>= 16;
  809. tdp_ratio &= 0xff; /* ratios are only 8 bits long */
  810. if (tdp_ratio - 1 == tar) {
  811. max_pstate = tar;
  812. pr_debug("max_pstate=TAC %x\n", max_pstate);
  813. } else {
  814. goto skip_tar;
  815. }
  816. }
  817. }
  818. skip_tar:
  819. return max_pstate;
  820. }
  821. static int core_get_turbo_pstate(void)
  822. {
  823. u64 value;
  824. int nont, ret;
  825. rdmsrl(MSR_TURBO_RATIO_LIMIT, value);
  826. nont = core_get_max_pstate();
  827. ret = (value) & 255;
  828. if (ret <= nont)
  829. ret = nont;
  830. return ret;
  831. }
  832. static inline int core_get_scaling(void)
  833. {
  834. return 100000;
  835. }
  836. static u64 core_get_val(struct cpudata *cpudata, int pstate)
  837. {
  838. u64 val;
  839. val = (u64)pstate << 8;
  840. if (limits->no_turbo && !limits->turbo_disabled)
  841. val |= (u64)1 << 32;
  842. return val;
  843. }
  844. static int knl_get_turbo_pstate(void)
  845. {
  846. u64 value;
  847. int nont, ret;
  848. rdmsrl(MSR_TURBO_RATIO_LIMIT, value);
  849. nont = core_get_max_pstate();
  850. ret = (((value) >> 8) & 0xFF);
  851. if (ret <= nont)
  852. ret = nont;
  853. return ret;
  854. }
  855. static struct cpu_defaults core_params = {
  856. .pid_policy = {
  857. .sample_rate_ms = 10,
  858. .deadband = 0,
  859. .setpoint = 97,
  860. .p_gain_pct = 20,
  861. .d_gain_pct = 0,
  862. .i_gain_pct = 0,
  863. },
  864. .funcs = {
  865. .get_max = core_get_max_pstate,
  866. .get_max_physical = core_get_max_pstate_physical,
  867. .get_min = core_get_min_pstate,
  868. .get_turbo = core_get_turbo_pstate,
  869. .get_scaling = core_get_scaling,
  870. .get_val = core_get_val,
  871. .get_target_pstate = get_target_pstate_use_performance,
  872. },
  873. };
  874. static struct cpu_defaults silvermont_params = {
  875. .pid_policy = {
  876. .sample_rate_ms = 10,
  877. .deadband = 0,
  878. .setpoint = 60,
  879. .p_gain_pct = 14,
  880. .d_gain_pct = 0,
  881. .i_gain_pct = 4,
  882. },
  883. .funcs = {
  884. .get_max = atom_get_max_pstate,
  885. .get_max_physical = atom_get_max_pstate,
  886. .get_min = atom_get_min_pstate,
  887. .get_turbo = atom_get_turbo_pstate,
  888. .get_val = atom_get_val,
  889. .get_scaling = silvermont_get_scaling,
  890. .get_vid = atom_get_vid,
  891. .get_target_pstate = get_target_pstate_use_cpu_load,
  892. },
  893. };
  894. static struct cpu_defaults airmont_params = {
  895. .pid_policy = {
  896. .sample_rate_ms = 10,
  897. .deadband = 0,
  898. .setpoint = 60,
  899. .p_gain_pct = 14,
  900. .d_gain_pct = 0,
  901. .i_gain_pct = 4,
  902. },
  903. .funcs = {
  904. .get_max = atom_get_max_pstate,
  905. .get_max_physical = atom_get_max_pstate,
  906. .get_min = atom_get_min_pstate,
  907. .get_turbo = atom_get_turbo_pstate,
  908. .get_val = atom_get_val,
  909. .get_scaling = airmont_get_scaling,
  910. .get_vid = atom_get_vid,
  911. .get_target_pstate = get_target_pstate_use_cpu_load,
  912. },
  913. };
  914. static struct cpu_defaults knl_params = {
  915. .pid_policy = {
  916. .sample_rate_ms = 10,
  917. .deadband = 0,
  918. .setpoint = 97,
  919. .p_gain_pct = 20,
  920. .d_gain_pct = 0,
  921. .i_gain_pct = 0,
  922. },
  923. .funcs = {
  924. .get_max = core_get_max_pstate,
  925. .get_max_physical = core_get_max_pstate_physical,
  926. .get_min = core_get_min_pstate,
  927. .get_turbo = knl_get_turbo_pstate,
  928. .get_scaling = core_get_scaling,
  929. .get_val = core_get_val,
  930. .get_target_pstate = get_target_pstate_use_performance,
  931. },
  932. };
  933. static struct cpu_defaults bxt_params = {
  934. .pid_policy = {
  935. .sample_rate_ms = 10,
  936. .deadband = 0,
  937. .setpoint = 60,
  938. .p_gain_pct = 14,
  939. .d_gain_pct = 0,
  940. .i_gain_pct = 4,
  941. },
  942. .funcs = {
  943. .get_max = core_get_max_pstate,
  944. .get_max_physical = core_get_max_pstate_physical,
  945. .get_min = core_get_min_pstate,
  946. .get_turbo = core_get_turbo_pstate,
  947. .get_scaling = core_get_scaling,
  948. .get_val = core_get_val,
  949. .get_target_pstate = get_target_pstate_use_cpu_load,
  950. },
  951. };
  952. static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)
  953. {
  954. int max_perf = cpu->pstate.turbo_pstate;
  955. int max_perf_adj;
  956. int min_perf;
  957. if (limits->no_turbo || limits->turbo_disabled)
  958. max_perf = cpu->pstate.max_pstate;
  959. /*
  960. * performance can be limited by user through sysfs, by cpufreq
  961. * policy, or by cpu specific default values determined through
  962. * experimentation.
  963. */
  964. max_perf_adj = fp_toint(max_perf * limits->max_perf);
  965. *max = clamp_t(int, max_perf_adj,
  966. cpu->pstate.min_pstate, cpu->pstate.turbo_pstate);
  967. min_perf = fp_toint(max_perf * limits->min_perf);
  968. *min = clamp_t(int, min_perf, cpu->pstate.min_pstate, max_perf);
  969. }
  970. static void intel_pstate_set_min_pstate(struct cpudata *cpu)
  971. {
  972. int pstate = cpu->pstate.min_pstate;
  973. trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu);
  974. cpu->pstate.current_pstate = pstate;
  975. /*
  976. * Generally, there is no guarantee that this code will always run on
  977. * the CPU being updated, so force the register update to run on the
  978. * right CPU.
  979. */
  980. wrmsrl_on_cpu(cpu->cpu, MSR_IA32_PERF_CTL,
  981. pstate_funcs.get_val(cpu, pstate));
  982. }
  983. static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
  984. {
  985. cpu->pstate.min_pstate = pstate_funcs.get_min();
  986. cpu->pstate.max_pstate = pstate_funcs.get_max();
  987. cpu->pstate.max_pstate_physical = pstate_funcs.get_max_physical();
  988. cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
  989. cpu->pstate.scaling = pstate_funcs.get_scaling();
  990. if (pstate_funcs.get_vid)
  991. pstate_funcs.get_vid(cpu);
  992. intel_pstate_set_min_pstate(cpu);
  993. }
  994. static inline void intel_pstate_calc_avg_perf(struct cpudata *cpu)
  995. {
  996. struct sample *sample = &cpu->sample;
  997. sample->core_avg_perf = div_ext_fp(sample->aperf, sample->mperf);
  998. }
  999. static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time)
  1000. {
  1001. u64 aperf, mperf;
  1002. unsigned long flags;
  1003. u64 tsc;
  1004. local_irq_save(flags);
  1005. rdmsrl(MSR_IA32_APERF, aperf);
  1006. rdmsrl(MSR_IA32_MPERF, mperf);
  1007. tsc = rdtsc();
  1008. if (cpu->prev_mperf == mperf || cpu->prev_tsc == tsc) {
  1009. local_irq_restore(flags);
  1010. return false;
  1011. }
  1012. local_irq_restore(flags);
  1013. cpu->last_sample_time = cpu->sample.time;
  1014. cpu->sample.time = time;
  1015. cpu->sample.aperf = aperf;
  1016. cpu->sample.mperf = mperf;
  1017. cpu->sample.tsc = tsc;
  1018. cpu->sample.aperf -= cpu->prev_aperf;
  1019. cpu->sample.mperf -= cpu->prev_mperf;
  1020. cpu->sample.tsc -= cpu->prev_tsc;
  1021. cpu->prev_aperf = aperf;
  1022. cpu->prev_mperf = mperf;
  1023. cpu->prev_tsc = tsc;
  1024. /*
  1025. * First time this function is invoked in a given cycle, all of the
  1026. * previous sample data fields are equal to zero or stale and they must
  1027. * be populated with meaningful numbers for things to work, so assume
  1028. * that sample.time will always be reset before setting the utilization
  1029. * update hook and make the caller skip the sample then.
  1030. */
  1031. return !!cpu->last_sample_time;
  1032. }
  1033. static inline int32_t get_avg_frequency(struct cpudata *cpu)
  1034. {
  1035. return mul_ext_fp(cpu->sample.core_avg_perf,
  1036. cpu->pstate.max_pstate_physical * cpu->pstate.scaling);
  1037. }
  1038. static inline int32_t get_avg_pstate(struct cpudata *cpu)
  1039. {
  1040. return mul_ext_fp(cpu->pstate.max_pstate_physical,
  1041. cpu->sample.core_avg_perf);
  1042. }
  1043. static inline int32_t get_target_pstate_use_cpu_load(struct cpudata *cpu)
  1044. {
  1045. struct sample *sample = &cpu->sample;
  1046. u64 cummulative_iowait, delta_iowait_us;
  1047. u64 delta_iowait_mperf;
  1048. u64 mperf, now;
  1049. int32_t cpu_load;
  1050. cummulative_iowait = get_cpu_iowait_time_us(cpu->cpu, &now);
  1051. /*
  1052. * Convert iowait time into number of IO cycles spent at max_freq.
  1053. * IO is considered as busy only for the cpu_load algorithm. For
  1054. * performance this is not needed since we always try to reach the
  1055. * maximum P-State, so we are already boosting the IOs.
  1056. */
  1057. delta_iowait_us = cummulative_iowait - cpu->prev_cummulative_iowait;
  1058. delta_iowait_mperf = div64_u64(delta_iowait_us * cpu->pstate.scaling *
  1059. cpu->pstate.max_pstate, MSEC_PER_SEC);
  1060. mperf = cpu->sample.mperf + delta_iowait_mperf;
  1061. cpu->prev_cummulative_iowait = cummulative_iowait;
  1062. /*
  1063. * The load can be estimated as the ratio of the mperf counter
  1064. * running at a constant frequency during active periods
  1065. * (C0) and the time stamp counter running at the same frequency
  1066. * also during C-states.
  1067. */
  1068. cpu_load = div64_u64(int_tofp(100) * mperf, sample->tsc);
  1069. cpu->sample.busy_scaled = cpu_load;
  1070. return get_avg_pstate(cpu) - pid_calc(&cpu->pid, cpu_load);
  1071. }
  1072. static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu)
  1073. {
  1074. int32_t perf_scaled, max_pstate, current_pstate, sample_ratio;
  1075. u64 duration_ns;
  1076. /*
  1077. * perf_scaled is the average performance during the last sampling
  1078. * period scaled by the ratio of the maximum P-state to the P-state
  1079. * requested last time (in percent). That measures the system's
  1080. * response to the previous P-state selection.
  1081. */
  1082. max_pstate = cpu->pstate.max_pstate_physical;
  1083. current_pstate = cpu->pstate.current_pstate;
  1084. perf_scaled = mul_ext_fp(cpu->sample.core_avg_perf,
  1085. div_fp(100 * max_pstate, current_pstate));
  1086. /*
  1087. * Since our utilization update callback will not run unless we are
  1088. * in C0, check if the actual elapsed time is significantly greater (3x)
  1089. * than our sample interval. If it is, then we were idle for a long
  1090. * enough period of time to adjust our performance metric.
  1091. */
  1092. duration_ns = cpu->sample.time - cpu->last_sample_time;
  1093. if ((s64)duration_ns > pid_params.sample_rate_ns * 3) {
  1094. sample_ratio = div_fp(pid_params.sample_rate_ns, duration_ns);
  1095. perf_scaled = mul_fp(perf_scaled, sample_ratio);
  1096. } else {
  1097. sample_ratio = div_fp(100 * cpu->sample.mperf, cpu->sample.tsc);
  1098. if (sample_ratio < int_tofp(1))
  1099. perf_scaled = 0;
  1100. }
  1101. cpu->sample.busy_scaled = perf_scaled;
  1102. return cpu->pstate.current_pstate - pid_calc(&cpu->pid, perf_scaled);
  1103. }
  1104. static inline void intel_pstate_update_pstate(struct cpudata *cpu, int pstate)
  1105. {
  1106. int max_perf, min_perf;
  1107. update_turbo_state();
  1108. intel_pstate_get_min_max(cpu, &min_perf, &max_perf);
  1109. pstate = clamp_t(int, pstate, min_perf, max_perf);
  1110. trace_cpu_frequency(pstate * cpu->pstate.scaling, cpu->cpu);
  1111. if (pstate == cpu->pstate.current_pstate)
  1112. return;
  1113. cpu->pstate.current_pstate = pstate;
  1114. wrmsrl(MSR_IA32_PERF_CTL, pstate_funcs.get_val(cpu, pstate));
  1115. }
  1116. static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)
  1117. {
  1118. int from, target_pstate;
  1119. struct sample *sample;
  1120. from = cpu->pstate.current_pstate;
  1121. target_pstate = pstate_funcs.get_target_pstate(cpu);
  1122. intel_pstate_update_pstate(cpu, target_pstate);
  1123. sample = &cpu->sample;
  1124. trace_pstate_sample(mul_ext_fp(100, sample->core_avg_perf),
  1125. fp_toint(sample->busy_scaled),
  1126. from,
  1127. cpu->pstate.current_pstate,
  1128. sample->mperf,
  1129. sample->aperf,
  1130. sample->tsc,
  1131. get_avg_frequency(cpu));
  1132. }
  1133. static void intel_pstate_update_util(struct update_util_data *data, u64 time,
  1134. unsigned long util, unsigned long max)
  1135. {
  1136. struct cpudata *cpu = container_of(data, struct cpudata, update_util);
  1137. u64 delta_ns = time - cpu->sample.time;
  1138. if ((s64)delta_ns >= pid_params.sample_rate_ns) {
  1139. bool sample_taken = intel_pstate_sample(cpu, time);
  1140. if (sample_taken) {
  1141. intel_pstate_calc_avg_perf(cpu);
  1142. if (!hwp_active)
  1143. intel_pstate_adjust_busy_pstate(cpu);
  1144. }
  1145. }
  1146. }
  1147. #define ICPU(model, policy) \
  1148. { X86_VENDOR_INTEL, 6, model, X86_FEATURE_APERFMPERF,\
  1149. (unsigned long)&policy }
  1150. static const struct x86_cpu_id intel_pstate_cpu_ids[] = {
  1151. ICPU(INTEL_FAM6_SANDYBRIDGE, core_params),
  1152. ICPU(INTEL_FAM6_SANDYBRIDGE_X, core_params),
  1153. ICPU(INTEL_FAM6_ATOM_SILVERMONT1, silvermont_params),
  1154. ICPU(INTEL_FAM6_IVYBRIDGE, core_params),
  1155. ICPU(INTEL_FAM6_HASWELL_CORE, core_params),
  1156. ICPU(INTEL_FAM6_BROADWELL_CORE, core_params),
  1157. ICPU(INTEL_FAM6_IVYBRIDGE_X, core_params),
  1158. ICPU(INTEL_FAM6_HASWELL_X, core_params),
  1159. ICPU(INTEL_FAM6_HASWELL_ULT, core_params),
  1160. ICPU(INTEL_FAM6_HASWELL_GT3E, core_params),
  1161. ICPU(INTEL_FAM6_BROADWELL_GT3E, core_params),
  1162. ICPU(INTEL_FAM6_ATOM_AIRMONT, airmont_params),
  1163. ICPU(INTEL_FAM6_SKYLAKE_MOBILE, core_params),
  1164. ICPU(INTEL_FAM6_BROADWELL_X, core_params),
  1165. ICPU(INTEL_FAM6_SKYLAKE_DESKTOP, core_params),
  1166. ICPU(INTEL_FAM6_BROADWELL_XEON_D, core_params),
  1167. ICPU(INTEL_FAM6_XEON_PHI_KNL, knl_params),
  1168. ICPU(INTEL_FAM6_ATOM_GOLDMONT, bxt_params),
  1169. {}
  1170. };
  1171. MODULE_DEVICE_TABLE(x86cpu, intel_pstate_cpu_ids);
  1172. static const struct x86_cpu_id intel_pstate_cpu_oob_ids[] __initconst = {
  1173. ICPU(INTEL_FAM6_BROADWELL_XEON_D, core_params),
  1174. ICPU(INTEL_FAM6_BROADWELL_X, core_params),
  1175. ICPU(INTEL_FAM6_SKYLAKE_X, core_params),
  1176. {}
  1177. };
  1178. static int intel_pstate_init_cpu(unsigned int cpunum)
  1179. {
  1180. struct cpudata *cpu;
  1181. if (!all_cpu_data[cpunum])
  1182. all_cpu_data[cpunum] = kzalloc(sizeof(struct cpudata),
  1183. GFP_KERNEL);
  1184. if (!all_cpu_data[cpunum])
  1185. return -ENOMEM;
  1186. cpu = all_cpu_data[cpunum];
  1187. cpu->cpu = cpunum;
  1188. if (hwp_active) {
  1189. intel_pstate_hwp_enable(cpu);
  1190. pid_params.sample_rate_ms = 50;
  1191. pid_params.sample_rate_ns = 50 * NSEC_PER_MSEC;
  1192. }
  1193. intel_pstate_get_cpu_pstates(cpu);
  1194. intel_pstate_busy_pid_reset(cpu);
  1195. pr_debug("controlling: cpu %d\n", cpunum);
  1196. return 0;
  1197. }
  1198. static unsigned int intel_pstate_get(unsigned int cpu_num)
  1199. {
  1200. struct cpudata *cpu = all_cpu_data[cpu_num];
  1201. return cpu ? get_avg_frequency(cpu) : 0;
  1202. }
  1203. static void intel_pstate_set_update_util_hook(unsigned int cpu_num)
  1204. {
  1205. struct cpudata *cpu = all_cpu_data[cpu_num];
  1206. if (cpu->update_util_set)
  1207. return;
  1208. /* Prevent intel_pstate_update_util() from using stale data. */
  1209. cpu->sample.time = 0;
  1210. cpufreq_add_update_util_hook(cpu_num, &cpu->update_util,
  1211. intel_pstate_update_util);
  1212. cpu->update_util_set = true;
  1213. }
  1214. static void intel_pstate_clear_update_util_hook(unsigned int cpu)
  1215. {
  1216. struct cpudata *cpu_data = all_cpu_data[cpu];
  1217. if (!cpu_data->update_util_set)
  1218. return;
  1219. cpufreq_remove_update_util_hook(cpu);
  1220. cpu_data->update_util_set = false;
  1221. synchronize_sched();
  1222. }
  1223. static void intel_pstate_set_performance_limits(struct perf_limits *limits)
  1224. {
  1225. limits->no_turbo = 0;
  1226. limits->turbo_disabled = 0;
  1227. limits->max_perf_pct = 100;
  1228. limits->max_perf = int_tofp(1);
  1229. limits->min_perf_pct = 100;
  1230. limits->min_perf = int_tofp(1);
  1231. limits->max_policy_pct = 100;
  1232. limits->max_sysfs_pct = 100;
  1233. limits->min_policy_pct = 0;
  1234. limits->min_sysfs_pct = 0;
  1235. }
  1236. static int intel_pstate_set_policy(struct cpufreq_policy *policy)
  1237. {
  1238. struct cpudata *cpu;
  1239. if (!policy->cpuinfo.max_freq)
  1240. return -ENODEV;
  1241. pr_debug("set_policy cpuinfo.max %u policy->max %u\n",
  1242. policy->cpuinfo.max_freq, policy->max);
  1243. cpu = all_cpu_data[0];
  1244. if (cpu->pstate.max_pstate_physical > cpu->pstate.max_pstate &&
  1245. policy->max < policy->cpuinfo.max_freq &&
  1246. policy->max > cpu->pstate.max_pstate * cpu->pstate.scaling) {
  1247. pr_debug("policy->max > max non turbo frequency\n");
  1248. policy->max = policy->cpuinfo.max_freq;
  1249. }
  1250. if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
  1251. limits = &performance_limits;
  1252. if (policy->max >= policy->cpuinfo.max_freq) {
  1253. pr_debug("set performance\n");
  1254. intel_pstate_set_performance_limits(limits);
  1255. goto out;
  1256. }
  1257. } else {
  1258. pr_debug("set powersave\n");
  1259. limits = &powersave_limits;
  1260. }
  1261. limits->min_policy_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
  1262. limits->min_policy_pct = clamp_t(int, limits->min_policy_pct, 0 , 100);
  1263. limits->max_policy_pct = DIV_ROUND_UP(policy->max * 100,
  1264. policy->cpuinfo.max_freq);
  1265. limits->max_policy_pct = clamp_t(int, limits->max_policy_pct, 0 , 100);
  1266. /* Normalize user input to [min_policy_pct, max_policy_pct] */
  1267. limits->min_perf_pct = max(limits->min_policy_pct,
  1268. limits->min_sysfs_pct);
  1269. limits->min_perf_pct = min(limits->max_policy_pct,
  1270. limits->min_perf_pct);
  1271. limits->max_perf_pct = min(limits->max_policy_pct,
  1272. limits->max_sysfs_pct);
  1273. limits->max_perf_pct = max(limits->min_policy_pct,
  1274. limits->max_perf_pct);
  1275. /* Make sure min_perf_pct <= max_perf_pct */
  1276. limits->min_perf_pct = min(limits->max_perf_pct, limits->min_perf_pct);
  1277. limits->min_perf = div_fp(limits->min_perf_pct, 100);
  1278. limits->max_perf = div_fp(limits->max_perf_pct, 100);
  1279. limits->max_perf = round_up(limits->max_perf, FRAC_BITS);
  1280. out:
  1281. intel_pstate_set_update_util_hook(policy->cpu);
  1282. intel_pstate_hwp_set_policy(policy);
  1283. return 0;
  1284. }
  1285. static int intel_pstate_verify_policy(struct cpufreq_policy *policy)
  1286. {
  1287. cpufreq_verify_within_cpu_limits(policy);
  1288. if (policy->policy != CPUFREQ_POLICY_POWERSAVE &&
  1289. policy->policy != CPUFREQ_POLICY_PERFORMANCE)
  1290. return -EINVAL;
  1291. return 0;
  1292. }
  1293. static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
  1294. {
  1295. int cpu_num = policy->cpu;
  1296. struct cpudata *cpu = all_cpu_data[cpu_num];
  1297. pr_debug("CPU %d exiting\n", cpu_num);
  1298. intel_pstate_clear_update_util_hook(cpu_num);
  1299. if (hwp_active)
  1300. return;
  1301. intel_pstate_set_min_pstate(cpu);
  1302. }
  1303. static int intel_pstate_cpu_init(struct cpufreq_policy *policy)
  1304. {
  1305. struct cpudata *cpu;
  1306. int rc;
  1307. rc = intel_pstate_init_cpu(policy->cpu);
  1308. if (rc)
  1309. return rc;
  1310. cpu = all_cpu_data[policy->cpu];
  1311. if (limits->min_perf_pct == 100 && limits->max_perf_pct == 100)
  1312. policy->policy = CPUFREQ_POLICY_PERFORMANCE;
  1313. else
  1314. policy->policy = CPUFREQ_POLICY_POWERSAVE;
  1315. policy->min = cpu->pstate.min_pstate * cpu->pstate.scaling;
  1316. policy->max = cpu->pstate.turbo_pstate * cpu->pstate.scaling;
  1317. /* cpuinfo and default policy values */
  1318. policy->cpuinfo.min_freq = cpu->pstate.min_pstate * cpu->pstate.scaling;
  1319. update_turbo_state();
  1320. policy->cpuinfo.max_freq = limits->turbo_disabled ?
  1321. cpu->pstate.max_pstate : cpu->pstate.turbo_pstate;
  1322. policy->cpuinfo.max_freq *= cpu->pstate.scaling;
  1323. intel_pstate_init_acpi_perf_limits(policy);
  1324. policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
  1325. cpumask_set_cpu(policy->cpu, policy->cpus);
  1326. return 0;
  1327. }
  1328. static int intel_pstate_cpu_exit(struct cpufreq_policy *policy)
  1329. {
  1330. intel_pstate_exit_perf_limits(policy);
  1331. return 0;
  1332. }
  1333. static struct cpufreq_driver intel_pstate_driver = {
  1334. .flags = CPUFREQ_CONST_LOOPS,
  1335. .verify = intel_pstate_verify_policy,
  1336. .setpolicy = intel_pstate_set_policy,
  1337. .resume = intel_pstate_hwp_set_policy,
  1338. .get = intel_pstate_get,
  1339. .init = intel_pstate_cpu_init,
  1340. .exit = intel_pstate_cpu_exit,
  1341. .stop_cpu = intel_pstate_stop_cpu,
  1342. .name = "intel_pstate",
  1343. };
  1344. static int no_load __initdata;
  1345. static int no_hwp __initdata;
  1346. static int hwp_only __initdata;
  1347. static unsigned int force_load __initdata;
  1348. static int __init intel_pstate_msrs_not_valid(void)
  1349. {
  1350. if (!pstate_funcs.get_max() ||
  1351. !pstate_funcs.get_min() ||
  1352. !pstate_funcs.get_turbo())
  1353. return -ENODEV;
  1354. return 0;
  1355. }
  1356. static void __init copy_pid_params(struct pstate_adjust_policy *policy)
  1357. {
  1358. pid_params.sample_rate_ms = policy->sample_rate_ms;
  1359. pid_params.sample_rate_ns = pid_params.sample_rate_ms * NSEC_PER_MSEC;
  1360. pid_params.p_gain_pct = policy->p_gain_pct;
  1361. pid_params.i_gain_pct = policy->i_gain_pct;
  1362. pid_params.d_gain_pct = policy->d_gain_pct;
  1363. pid_params.deadband = policy->deadband;
  1364. pid_params.setpoint = policy->setpoint;
  1365. }
  1366. static void __init copy_cpu_funcs(struct pstate_funcs *funcs)
  1367. {
  1368. pstate_funcs.get_max = funcs->get_max;
  1369. pstate_funcs.get_max_physical = funcs->get_max_physical;
  1370. pstate_funcs.get_min = funcs->get_min;
  1371. pstate_funcs.get_turbo = funcs->get_turbo;
  1372. pstate_funcs.get_scaling = funcs->get_scaling;
  1373. pstate_funcs.get_val = funcs->get_val;
  1374. pstate_funcs.get_vid = funcs->get_vid;
  1375. pstate_funcs.get_target_pstate = funcs->get_target_pstate;
  1376. }
  1377. #ifdef CONFIG_ACPI
  1378. static bool __init intel_pstate_no_acpi_pss(void)
  1379. {
  1380. int i;
  1381. for_each_possible_cpu(i) {
  1382. acpi_status status;
  1383. union acpi_object *pss;
  1384. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  1385. struct acpi_processor *pr = per_cpu(processors, i);
  1386. if (!pr)
  1387. continue;
  1388. status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer);
  1389. if (ACPI_FAILURE(status))
  1390. continue;
  1391. pss = buffer.pointer;
  1392. if (pss && pss->type == ACPI_TYPE_PACKAGE) {
  1393. kfree(pss);
  1394. return false;
  1395. }
  1396. kfree(pss);
  1397. }
  1398. return true;
  1399. }
  1400. static bool __init intel_pstate_has_acpi_ppc(void)
  1401. {
  1402. int i;
  1403. for_each_possible_cpu(i) {
  1404. struct acpi_processor *pr = per_cpu(processors, i);
  1405. if (!pr)
  1406. continue;
  1407. if (acpi_has_method(pr->handle, "_PPC"))
  1408. return true;
  1409. }
  1410. return false;
  1411. }
  1412. enum {
  1413. PSS,
  1414. PPC,
  1415. };
  1416. struct hw_vendor_info {
  1417. u16 valid;
  1418. char oem_id[ACPI_OEM_ID_SIZE];
  1419. char oem_table_id[ACPI_OEM_TABLE_ID_SIZE];
  1420. int oem_pwr_table;
  1421. };
  1422. /* Hardware vendor-specific info that has its own power management modes */
  1423. static struct hw_vendor_info vendor_info[] __initdata = {
  1424. {1, "HP ", "ProLiant", PSS},
  1425. {1, "ORACLE", "X4-2 ", PPC},
  1426. {1, "ORACLE", "X4-2L ", PPC},
  1427. {1, "ORACLE", "X4-2B ", PPC},
  1428. {1, "ORACLE", "X3-2 ", PPC},
  1429. {1, "ORACLE", "X3-2L ", PPC},
  1430. {1, "ORACLE", "X3-2B ", PPC},
  1431. {1, "ORACLE", "X4470M2 ", PPC},
  1432. {1, "ORACLE", "X4270M3 ", PPC},
  1433. {1, "ORACLE", "X4270M2 ", PPC},
  1434. {1, "ORACLE", "X4170M2 ", PPC},
  1435. {1, "ORACLE", "X4170 M3", PPC},
  1436. {1, "ORACLE", "X4275 M3", PPC},
  1437. {1, "ORACLE", "X6-2 ", PPC},
  1438. {1, "ORACLE", "Sudbury ", PPC},
  1439. {0, "", ""},
  1440. };
  1441. static bool __init intel_pstate_platform_pwr_mgmt_exists(void)
  1442. {
  1443. struct acpi_table_header hdr;
  1444. struct hw_vendor_info *v_info;
  1445. const struct x86_cpu_id *id;
  1446. u64 misc_pwr;
  1447. id = x86_match_cpu(intel_pstate_cpu_oob_ids);
  1448. if (id) {
  1449. rdmsrl(MSR_MISC_PWR_MGMT, misc_pwr);
  1450. if ( misc_pwr & (1 << 8))
  1451. return true;
  1452. }
  1453. if (acpi_disabled ||
  1454. ACPI_FAILURE(acpi_get_table_header(ACPI_SIG_FADT, 0, &hdr)))
  1455. return false;
  1456. for (v_info = vendor_info; v_info->valid; v_info++) {
  1457. if (!strncmp(hdr.oem_id, v_info->oem_id, ACPI_OEM_ID_SIZE) &&
  1458. !strncmp(hdr.oem_table_id, v_info->oem_table_id,
  1459. ACPI_OEM_TABLE_ID_SIZE))
  1460. switch (v_info->oem_pwr_table) {
  1461. case PSS:
  1462. return intel_pstate_no_acpi_pss();
  1463. case PPC:
  1464. return intel_pstate_has_acpi_ppc() &&
  1465. (!force_load);
  1466. }
  1467. }
  1468. return false;
  1469. }
  1470. #else /* CONFIG_ACPI not enabled */
  1471. static inline bool intel_pstate_platform_pwr_mgmt_exists(void) { return false; }
  1472. static inline bool intel_pstate_has_acpi_ppc(void) { return false; }
  1473. #endif /* CONFIG_ACPI */
  1474. static const struct x86_cpu_id hwp_support_ids[] __initconst = {
  1475. { X86_VENDOR_INTEL, 6, X86_MODEL_ANY, X86_FEATURE_HWP },
  1476. {}
  1477. };
  1478. static int __init intel_pstate_init(void)
  1479. {
  1480. int cpu, rc = 0;
  1481. const struct x86_cpu_id *id;
  1482. struct cpu_defaults *cpu_def;
  1483. if (no_load)
  1484. return -ENODEV;
  1485. if (x86_match_cpu(hwp_support_ids) && !no_hwp) {
  1486. copy_cpu_funcs(&core_params.funcs);
  1487. hwp_active++;
  1488. goto hwp_cpu_matched;
  1489. }
  1490. id = x86_match_cpu(intel_pstate_cpu_ids);
  1491. if (!id)
  1492. return -ENODEV;
  1493. cpu_def = (struct cpu_defaults *)id->driver_data;
  1494. copy_pid_params(&cpu_def->pid_policy);
  1495. copy_cpu_funcs(&cpu_def->funcs);
  1496. if (intel_pstate_msrs_not_valid())
  1497. return -ENODEV;
  1498. hwp_cpu_matched:
  1499. /*
  1500. * The Intel pstate driver will be ignored if the platform
  1501. * firmware has its own power management modes.
  1502. */
  1503. if (intel_pstate_platform_pwr_mgmt_exists())
  1504. return -ENODEV;
  1505. pr_info("Intel P-state driver initializing\n");
  1506. all_cpu_data = vzalloc(sizeof(void *) * num_possible_cpus());
  1507. if (!all_cpu_data)
  1508. return -ENOMEM;
  1509. if (!hwp_active && hwp_only)
  1510. goto out;
  1511. rc = cpufreq_register_driver(&intel_pstate_driver);
  1512. if (rc)
  1513. goto out;
  1514. intel_pstate_debug_expose_params();
  1515. intel_pstate_sysfs_expose_params();
  1516. if (hwp_active)
  1517. pr_info("HWP enabled\n");
  1518. return rc;
  1519. out:
  1520. get_online_cpus();
  1521. for_each_online_cpu(cpu) {
  1522. if (all_cpu_data[cpu]) {
  1523. intel_pstate_clear_update_util_hook(cpu);
  1524. kfree(all_cpu_data[cpu]);
  1525. }
  1526. }
  1527. put_online_cpus();
  1528. vfree(all_cpu_data);
  1529. return -ENODEV;
  1530. }
  1531. device_initcall(intel_pstate_init);
  1532. static int __init intel_pstate_setup(char *str)
  1533. {
  1534. if (!str)
  1535. return -EINVAL;
  1536. if (!strcmp(str, "disable"))
  1537. no_load = 1;
  1538. if (!strcmp(str, "no_hwp")) {
  1539. pr_info("HWP disabled\n");
  1540. no_hwp = 1;
  1541. }
  1542. if (!strcmp(str, "force"))
  1543. force_load = 1;
  1544. if (!strcmp(str, "hwp_only"))
  1545. hwp_only = 1;
  1546. #ifdef CONFIG_ACPI
  1547. if (!strcmp(str, "support_acpi_ppc"))
  1548. acpi_ppc = true;
  1549. #endif
  1550. return 0;
  1551. }
  1552. early_param("intel_pstate", intel_pstate_setup);
  1553. MODULE_AUTHOR("Dirk Brandewie <dirk.j.brandewie@intel.com>");
  1554. MODULE_DESCRIPTION("'intel_pstate' - P state driver Intel Core processors");
  1555. MODULE_LICENSE("GPL");