1.. SPDX-License-Identifier: GPL-2.0
2.. include:: <isonum.txt>
3
4===============================================
5``intel_pstate`` CPU Performance Scaling Driver
6===============================================
7
8:Copyright: |copy| 2017 Intel Corporation
9
10:Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
11
12
13General Information
14===================
15
16``intel_pstate`` is a part of the
17:doc:`CPU performance scaling subsystem <cpufreq>` in the Linux kernel
18(``CPUFreq``).  It is a scaling driver for the Sandy Bridge and later
19generations of Intel processors.  Note, however, that some of those processors
20may not be supported.  [To understand ``intel_pstate`` it is necessary to know
21how ``CPUFreq`` works in general, so this is the time to read :doc:`cpufreq` if
22you have not done that yet.]
23
24For the processors supported by ``intel_pstate``, the P-state concept is broader
25than just an operating frequency or an operating performance point (see the
26LinuxCon Europe 2015 presentation by Kristen Accardi [1]_ for more
27information about that).  For this reason, the representation of P-states used
28by ``intel_pstate`` internally follows the hardware specification (for details
29refer to Intel Software Developer’s Manual [2]_).  However, the ``CPUFreq`` core
30uses frequencies for identifying operating performance points of CPUs and
31frequencies are involved in the user space interface exposed by it, so
32``intel_pstate`` maps its internal representation of P-states to frequencies too
33(fortunately, that mapping is unambiguous).  At the same time, it would not be
34practical for ``intel_pstate`` to supply the ``CPUFreq`` core with a table of
35available frequencies due to the possible size of it, so the driver does not do
36that.  Some functionality of the core is limited by that.
37
38Since the hardware P-state selection interface used by ``intel_pstate`` is
39available at the logical CPU level, the driver always works with individual
40CPUs.  Consequently, if ``intel_pstate`` is in use, every ``CPUFreq`` policy
41object corresponds to one logical CPU and ``CPUFreq`` policies are effectively
42equivalent to CPUs.  In particular, this means that they become "inactive" every
43time the corresponding CPU is taken offline and need to be re-initialized when
44it goes back online.
45
46``intel_pstate`` is not modular, so it cannot be unloaded, which means that the
47only way to pass early-configuration-time parameters to it is via the kernel
48command line.  However, its configuration can be adjusted via ``sysfs`` to a
49great extent.  In some configurations it even is possible to unregister it via
50``sysfs`` which allows another ``CPUFreq`` scaling driver to be loaded and
51registered (see `below <status_attr_>`_).
52
53
54Operation Modes
55===============
56
57``intel_pstate`` can operate in three different modes: in the active mode with
58or without hardware-managed P-states support and in the passive mode.  Which of
59them will be in effect depends on what kernel command line options are used and
60on the capabilities of the processor.
61
62Active Mode
63-----------
64
65This is the default operation mode of ``intel_pstate`` for processors with
66hardware-managed P-states (HWP) support.  If it works in this mode, the
67``scaling_driver`` policy attribute in ``sysfs`` for all ``CPUFreq`` policies
68contains the string "intel_pstate".
69
70In this mode the driver bypasses the scaling governors layer of ``CPUFreq`` and
71provides its own scaling algorithms for P-state selection.  Those algorithms
72can be applied to ``CPUFreq`` policies in the same way as generic scaling
73governors (that is, through the ``scaling_governor`` policy attribute in
74``sysfs``).  [Note that different P-state selection algorithms may be chosen for
75different policies, but that is not recommended.]
76
77They are not generic scaling governors, but their names are the same as the
78names of some of those governors.  Moreover, confusingly enough, they generally
79do not work in the same way as the generic governors they share the names with.
80For example, the ``powersave`` P-state selection algorithm provided by
81``intel_pstate`` is not a counterpart of the generic ``powersave`` governor
82(roughly, it corresponds to the ``schedutil`` and ``ondemand`` governors).
83
84There are two P-state selection algorithms provided by ``intel_pstate`` in the
85active mode: ``powersave`` and ``performance``.  The way they both operate
86depends on whether or not the hardware-managed P-states (HWP) feature has been
87enabled in the processor and possibly on the processor model.
88
89Which of the P-state selection algorithms is used by default depends on the
90:c:macro:`CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE` kernel configuration option.
91Namely, if that option is set, the ``performance`` algorithm will be used by
92default, and the other one will be used by default if it is not set.
93
94Active Mode With HWP
95~~~~~~~~~~~~~~~~~~~~
96
97If the processor supports the HWP feature, it will be enabled during the
98processor initialization and cannot be disabled after that.  It is possible
99to avoid enabling it by passing the ``intel_pstate=no_hwp`` argument to the
100kernel in the command line.
101
102If the HWP feature has been enabled, ``intel_pstate`` relies on the processor to
103select P-states by itself, but still it can give hints to the processor's
104internal P-state selection logic.  What those hints are depends on which P-state
105selection algorithm has been applied to the given policy (or to the CPU it
106corresponds to).
107
108Even though the P-state selection is carried out by the processor automatically,
109``intel_pstate`` registers utilization update callbacks with the CPU scheduler
110in this mode.  However, they are not used for running a P-state selection
111algorithm, but for periodic updates of the current CPU frequency information to
112be made available from the ``scaling_cur_freq`` policy attribute in ``sysfs``.
113
114HWP + ``performance``
115.....................
116
117In this configuration ``intel_pstate`` will write 0 to the processor's
118Energy-Performance Preference (EPP) knob (if supported) or its
119Energy-Performance Bias (EPB) knob (otherwise), which means that the processor's
120internal P-state selection logic is expected to focus entirely on performance.
121
122This will override the EPP/EPB setting coming from the ``sysfs`` interface
123(see `Energy vs Performance Hints`_ below).
124
125Also, in this configuration the range of P-states available to the processor's
126internal P-state selection logic is always restricted to the upper boundary
127(that is, the maximum P-state that the driver is allowed to use).
128
129HWP + ``powersave``
130...................
131
132In this configuration ``intel_pstate`` will set the processor's
133Energy-Performance Preference (EPP) knob (if supported) or its
134Energy-Performance Bias (EPB) knob (otherwise) to whatever value it was
135previously set to via ``sysfs`` (or whatever default value it was
136set to by the platform firmware).  This usually causes the processor's
137internal P-state selection logic to be less performance-focused.
138
139Active Mode Without HWP
140~~~~~~~~~~~~~~~~~~~~~~~
141
142This operation mode is optional for processors that do not support the HWP
143feature or when the ``intel_pstate=no_hwp`` argument is passed to the kernel in
144the command line.  The active mode is used in those cases if the
145``intel_pstate=active`` argument is passed to the kernel in the command line.
146In this mode ``intel_pstate`` may refuse to work with processors that are not
147recognized by it.  [Note that ``intel_pstate`` will never refuse to work with
148any processor with the HWP feature enabled.]
149
150In this mode ``intel_pstate`` registers utilization update callbacks with the
151CPU scheduler in order to run a P-state selection algorithm, either
152``powersave`` or ``performance``, depending on the ``scaling_governor`` policy
153setting in ``sysfs``.  The current CPU frequency information to be made
154available from the ``scaling_cur_freq`` policy attribute in ``sysfs`` is
155periodically updated by those utilization update callbacks too.
156
157``performance``
158...............
159
160Without HWP, this P-state selection algorithm is always the same regardless of
161the processor model and platform configuration.
162
163It selects the maximum P-state it is allowed to use, subject to limits set via
164``sysfs``, every time the driver configuration for the given CPU is updated
165(e.g. via ``sysfs``).
166
167This is the default P-state selection algorithm if the
168:c:macro:`CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE` kernel configuration option
169is set.
170
171``powersave``
172.............
173
174Without HWP, this P-state selection algorithm is similar to the algorithm
175implemented by the generic ``schedutil`` scaling governor except that the
176utilization metric used by it is based on numbers coming from feedback
177registers of the CPU.  It generally selects P-states proportional to the
178current CPU utilization.
179
180This algorithm is run by the driver's utilization update callback for the
181given CPU when it is invoked by the CPU scheduler, but not more often than
182every 10 ms.  Like in the ``performance`` case, the hardware configuration
183is not touched if the new P-state turns out to be the same as the current
184one.
185
186This is the default P-state selection algorithm if the
187:c:macro:`CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE` kernel configuration option
188is not set.
189
190Passive Mode
191------------
192
193This is the default operation mode of ``intel_pstate`` for processors without
194hardware-managed P-states (HWP) support.  It is always used if the
195``intel_pstate=passive`` argument is passed to the kernel in the command line
196regardless of whether or not the given processor supports HWP.  [Note that the
197``intel_pstate=no_hwp`` setting implies ``intel_pstate=passive`` if it is used
198without ``intel_pstate=active``.]  Like in the active mode without HWP support,
199in this mode ``intel_pstate`` may refuse to work with processors that are not
200recognized by it.
201
202If the driver works in this mode, the ``scaling_driver`` policy attribute in
203``sysfs`` for all ``CPUFreq`` policies contains the string "intel_cpufreq".
204Then, the driver behaves like a regular ``CPUFreq`` scaling driver.  That is,
205it is invoked by generic scaling governors when necessary to talk to the
206hardware in order to change the P-state of a CPU (in particular, the
207``schedutil`` governor can invoke it directly from scheduler context).
208
209While in this mode, ``intel_pstate`` can be used with all of the (generic)
210scaling governors listed by the ``scaling_available_governors`` policy attribute
211in ``sysfs`` (and the P-state selection algorithms described above are not
212used).  Then, it is responsible for the configuration of policy objects
213corresponding to CPUs and provides the ``CPUFreq`` core (and the scaling
214governors attached to the policy objects) with accurate information on the
215maximum and minimum operating frequencies supported by the hardware (including
216the so-called "turbo" frequency ranges).  In other words, in the passive mode
217the entire range of available P-states is exposed by ``intel_pstate`` to the
218``CPUFreq`` core.  However, in this mode the driver does not register
219utilization update callbacks with the CPU scheduler and the ``scaling_cur_freq``
220information comes from the ``CPUFreq`` core (and is the last frequency selected
221by the current scaling governor for the given policy).
222
223
224.. _turbo:
225
226Turbo P-states Support
227======================
228
229In the majority of cases, the entire range of P-states available to
230``intel_pstate`` can be divided into two sub-ranges that correspond to
231different types of processor behavior, above and below a boundary that
232will be referred to as the "turbo threshold" in what follows.
233
234The P-states above the turbo threshold are referred to as "turbo P-states" and
235the whole sub-range of P-states they belong to is referred to as the "turbo
236range".  These names are related to the Turbo Boost technology allowing a
237multicore processor to opportunistically increase the P-state of one or more
238cores if there is enough power to do that and if that is not going to cause the
239thermal envelope of the processor package to be exceeded.
240
241Specifically, if software sets the P-state of a CPU core within the turbo range
242(that is, above the turbo threshold), the processor is permitted to take over
243performance scaling control for that core and put it into turbo P-states of its
244choice going forward.  However, that permission is interpreted differently by
245different processor generations.  Namely, the Sandy Bridge generation of
246processors will never use any P-states above the last one set by software for
247the given core, even if it is within the turbo range, whereas all of the later
248processor generations will take it as a license to use any P-states from the
249turbo range, even above the one set by software.  In other words, on those
250processors setting any P-state from the turbo range will enable the processor
251to put the given core into all turbo P-states up to and including the maximum
252supported one as it sees fit.
253
254One important property of turbo P-states is that they are not sustainable.  More
255precisely, there is no guarantee that any CPUs will be able to stay in any of
256those states indefinitely, because the power distribution within the processor
257package may change over time  or the thermal envelope it was designed for might
258be exceeded if a turbo P-state was used for too long.
259
260In turn, the P-states below the turbo threshold generally are sustainable.  In
261fact, if one of them is set by software, the processor is not expected to change
262it to a lower one unless in a thermal stress or a power limit violation
263situation (a higher P-state may still be used if it is set for another CPU in
264the same package at the same time, for example).
265
266Some processors allow multiple cores to be in turbo P-states at the same time,
267but the maximum P-state that can be set for them generally depends on the number
268of cores running concurrently.  The maximum turbo P-state that can be set for 3
269cores at the same time usually is lower than the analogous maximum P-state for
2702 cores, which in turn usually is lower than the maximum turbo P-state that can
271be set for 1 core.  The one-core maximum turbo P-state is thus the maximum
272supported one overall.
273
274The maximum supported turbo P-state, the turbo threshold (the maximum supported
275non-turbo P-state) and the minimum supported P-state are specific to the
276processor model and can be determined by reading the processor's model-specific
277registers (MSRs).  Moreover, some processors support the Configurable TDP
278(Thermal Design Power) feature and, when that feature is enabled, the turbo
279threshold effectively becomes a configurable value that can be set by the
280platform firmware.
281
282Unlike ``_PSS`` objects in the ACPI tables, ``intel_pstate`` always exposes
283the entire range of available P-states, including the whole turbo range, to the
284``CPUFreq`` core and (in the passive mode) to generic scaling governors.  This
285generally causes turbo P-states to be set more often when ``intel_pstate`` is
286used relative to ACPI-based CPU performance scaling (see `below <acpi-cpufreq_>`_
287for more information).
288
289Moreover, since ``intel_pstate`` always knows what the real turbo threshold is
290(even if the Configurable TDP feature is enabled in the processor), its
291``no_turbo`` attribute in ``sysfs`` (described `below <no_turbo_attr_>`_) should
292work as expected in all cases (that is, if set to disable turbo P-states, it
293always should prevent ``intel_pstate`` from using them).
294
295
296Processor Support
297=================
298
299To handle a given processor ``intel_pstate`` requires a number of different
300pieces of information on it to be known, including:
301
302 * The minimum supported P-state.
303
304 * The maximum supported `non-turbo P-state <turbo_>`_.
305
306 * Whether or not turbo P-states are supported at all.
307
308 * The maximum supported `one-core turbo P-state <turbo_>`_ (if turbo P-states
309   are supported).
310
311 * The scaling formula to translate the driver's internal representation
312   of P-states into frequencies and the other way around.
313
314Generally, ways to obtain that information are specific to the processor model
315or family.  Although it often is possible to obtain all of it from the processor
316itself (using model-specific registers), there are cases in which hardware
317manuals need to be consulted to get to it too.
318
319For this reason, there is a list of supported processors in ``intel_pstate`` and
320the driver initialization will fail if the detected processor is not in that
321list, unless it supports the `HWP feature <Active Mode_>`_.  [The interface to
322obtain all of the information listed above is the same for all of the processors
323supporting the HWP feature, which is why they all are supported by
324``intel_pstate``.]
325
326
327User Space Interface in ``sysfs``
328=================================
329
330Global Attributes
331-----------------
332
333``intel_pstate`` exposes several global attributes (files) in ``sysfs`` to
334control its functionality at the system level.  They are located in the
335``/sys/devices/system/cpu/intel_pstate/`` directory and affect all CPUs.
336
337Some of them are not present if the ``intel_pstate=per_cpu_perf_limits``
338argument is passed to the kernel in the command line.
339
340``max_perf_pct``
341	Maximum P-state the driver is allowed to set in percent of the
342	maximum supported performance level (the highest supported `turbo
343	P-state <turbo_>`_).
344
345	This attribute will not be exposed if the
346	``intel_pstate=per_cpu_perf_limits`` argument is present in the kernel
347	command line.
348
349``min_perf_pct``
350	Minimum P-state the driver is allowed to set in percent of the
351	maximum supported performance level (the highest supported `turbo
352	P-state <turbo_>`_).
353
354	This attribute will not be exposed if the
355	``intel_pstate=per_cpu_perf_limits`` argument is present in the kernel
356	command line.
357
358``num_pstates``
359	Number of P-states supported by the processor (between 0 and 255
360	inclusive) including both turbo and non-turbo P-states (see
361	`Turbo P-states Support`_).
362
363	The value of this attribute is not affected by the ``no_turbo``
364	setting described `below <no_turbo_attr_>`_.
365
366	This attribute is read-only.
367
368``turbo_pct``
369	Ratio of the `turbo range <turbo_>`_ size to the size of the entire
370	range of supported P-states, in percent.
371
372	This attribute is read-only.
373
374.. _no_turbo_attr:
375
376``no_turbo``
377	If set (equal to 1), the driver is not allowed to set any turbo P-states
378	(see `Turbo P-states Support`_).  If unset (equalt to 0, which is the
379	default), turbo P-states can be set by the driver.
380	[Note that ``intel_pstate`` does not support the general ``boost``
381	attribute (supported by some other scaling drivers) which is replaced
382	by this one.]
383
384	This attrubute does not affect the maximum supported frequency value
385	supplied to the ``CPUFreq`` core and exposed via the policy interface,
386	but it affects the maximum possible value of per-policy P-state	limits
387	(see `Interpretation of Policy Attributes`_ below for details).
388
389``hwp_dynamic_boost``
390	This attribute is only present if ``intel_pstate`` works in the
391	`active mode with the HWP feature enabled <Active Mode With HWP_>`_ in
392	the processor.  If set (equal to 1), it causes the minimum P-state limit
393	to be increased dynamically for a short time whenever a task previously
394	waiting on I/O is selected to run on a given logical CPU (the purpose
395	of this mechanism is to improve performance).
396
397	This setting has no effect on logical CPUs whose minimum P-state limit
398	is directly set to the highest non-turbo P-state or above it.
399
400.. _status_attr:
401
402``status``
403	Operation mode of the driver: "active", "passive" or "off".
404
405	"active"
406		The driver is functional and in the `active mode
407		<Active Mode_>`_.
408
409	"passive"
410		The driver is functional and in the `passive mode
411		<Passive Mode_>`_.
412
413	"off"
414		The driver is not functional (it is not registered as a scaling
415		driver with the ``CPUFreq`` core).
416
417	This attribute can be written to in order to change the driver's
418	operation mode or to unregister it.  The string written to it must be
419	one of the possible values of it and, if successful, the write will
420	cause the driver to switch over to the operation mode represented by
421	that string - or to be unregistered in the "off" case.  [Actually,
422	switching over from the active mode to the passive mode or the other
423	way around causes the driver to be unregistered and registered again
424	with a different set of callbacks, so all of its settings (the global
425	as well as the per-policy ones) are then reset to their default
426	values, possibly depending on the target operation mode.]
427
428	That only is supported in some configurations, though (for example, if
429	the `HWP feature is enabled in the processor <Active Mode With HWP_>`_,
430	the operation mode of the driver cannot be changed), and if it is not
431	supported in the current configuration, writes to this attribute will
432	fail with an appropriate error.
433
434``energy_efficiency``
435	This attribute is only present on platforms, which have CPUs matching
436	Kaby Lake or Coffee Lake desktop CPU model. By default
437	energy efficiency optimizations are disabled on these CPU models in HWP
438	mode by this driver. Enabling energy efficiency may limit maximum
439	operating frequency in both HWP and non HWP mode. In non HWP mode,
440	optimizations are done only in the turbo frequency range. In HWP mode,
441	optimizations are done in the entire frequency range. Setting this
442	attribute to "1" enables energy efficiency optimizations and setting
443	to "0" disables energy efficiency optimizations.
444
445Interpretation of Policy Attributes
446-----------------------------------
447
448The interpretation of some ``CPUFreq`` policy attributes described in
449:doc:`cpufreq` is special with ``intel_pstate`` as the current scaling driver
450and it generally depends on the driver's `operation mode <Operation Modes_>`_.
451
452First of all, the values of the ``cpuinfo_max_freq``, ``cpuinfo_min_freq`` and
453``scaling_cur_freq`` attributes are produced by applying a processor-specific
454multiplier to the internal P-state representation used by ``intel_pstate``.
455Also, the values of the ``scaling_max_freq`` and ``scaling_min_freq``
456attributes are capped by the frequency corresponding to the maximum P-state that
457the driver is allowed to set.
458
459If the ``no_turbo`` `global attribute <no_turbo_attr_>`_ is set, the driver is
460not allowed to use turbo P-states, so the maximum value of ``scaling_max_freq``
461and ``scaling_min_freq`` is limited to the maximum non-turbo P-state frequency.
462Accordingly, setting ``no_turbo`` causes ``scaling_max_freq`` and
463``scaling_min_freq`` to go down to that value if they were above it before.
464However, the old values of ``scaling_max_freq`` and ``scaling_min_freq`` will be
465restored after unsetting ``no_turbo``, unless these attributes have been written
466to after ``no_turbo`` was set.
467
468If ``no_turbo`` is not set, the maximum possible value of ``scaling_max_freq``
469and ``scaling_min_freq`` corresponds to the maximum supported turbo P-state,
470which also is the value of ``cpuinfo_max_freq`` in either case.
471
472Next, the following policy attributes have special meaning if
473``intel_pstate`` works in the `active mode <Active Mode_>`_:
474
475``scaling_available_governors``
476	List of P-state selection algorithms provided by ``intel_pstate``.
477
478``scaling_governor``
479	P-state selection algorithm provided by ``intel_pstate`` currently in
480	use with the given policy.
481
482``scaling_cur_freq``
483	Frequency of the average P-state of the CPU represented by the given
484	policy for the time interval between the last two invocations of the
485	driver's utilization update callback by the CPU scheduler for that CPU.
486
487One more policy attribute is present if the `HWP feature is enabled in the
488processor <Active Mode With HWP_>`_:
489
490``base_frequency``
491	Shows the base frequency of the CPU. Any frequency above this will be
492	in the turbo frequency range.
493
494The meaning of these attributes in the `passive mode <Passive Mode_>`_ is the
495same as for other scaling drivers.
496
497Additionally, the value of the ``scaling_driver`` attribute for ``intel_pstate``
498depends on the operation mode of the driver.  Namely, it is either
499"intel_pstate" (in the `active mode <Active Mode_>`_) or "intel_cpufreq" (in the
500`passive mode <Passive Mode_>`_).
501
502Coordination of P-State Limits
503------------------------------
504
505``intel_pstate`` allows P-state limits to be set in two ways: with the help of
506the ``max_perf_pct`` and ``min_perf_pct`` `global attributes
507<Global Attributes_>`_ or via the ``scaling_max_freq`` and ``scaling_min_freq``
508``CPUFreq`` policy attributes.  The coordination between those limits is based
509on the following rules, regardless of the current operation mode of the driver:
510
511 1. All CPUs are affected by the global limits (that is, none of them can be
512    requested to run faster than the global maximum and none of them can be
513    requested to run slower than the global minimum).
514
515 2. Each individual CPU is affected by its own per-policy limits (that is, it
516    cannot be requested to run faster than its own per-policy maximum and it
517    cannot be requested to run slower than its own per-policy minimum). The
518    effective performance depends on whether the platform supports per core
519    P-states, hyper-threading is enabled and on current performance requests
520    from other CPUs. When platform doesn't support per core P-states, the
521    effective performance can be more than the policy limits set on a CPU, if
522    other CPUs are requesting higher performance at that moment. Even with per
523    core P-states support, when hyper-threading is enabled, if the sibling CPU
524    is requesting higher performance, the other siblings will get higher
525    performance than their policy limits.
526
527 3. The global and per-policy limits can be set independently.
528
529If the `HWP feature is enabled in the processor <Active Mode With HWP_>`_, the
530resulting effective values are written into its registers whenever the limits
531change in order to request its internal P-state selection logic to always set
532P-states within these limits.  Otherwise, the limits are taken into account by
533scaling governors (in the `passive mode <Passive Mode_>`_) and by the driver
534every time before setting a new P-state for a CPU.
535
536Additionally, if the ``intel_pstate=per_cpu_perf_limits`` command line argument
537is passed to the kernel, ``max_perf_pct`` and ``min_perf_pct`` are not exposed
538at all and the only way to set the limits is by using the policy attributes.
539
540
541Energy vs Performance Hints
542---------------------------
543
544If ``intel_pstate`` works in the `active mode with the HWP feature enabled
545<Active Mode With HWP_>`_ in the processor, additional attributes are present
546in every ``CPUFreq`` policy directory in ``sysfs``.  They are intended to allow
547user space to help ``intel_pstate`` to adjust the processor's internal P-state
548selection logic by focusing it on performance or on energy-efficiency, or
549somewhere between the two extremes:
550
551``energy_performance_preference``
552	Current value of the energy vs performance hint for the given policy
553	(or the CPU represented by it).
554
555	The hint can be changed by writing to this attribute.
556
557``energy_performance_available_preferences``
558	List of strings that can be written to the
559	``energy_performance_preference`` attribute.
560
561	They represent different energy vs performance hints and should be
562	self-explanatory, except that ``default`` represents whatever hint
563	value was set by the platform firmware.
564
565Strings written to the ``energy_performance_preference`` attribute are
566internally translated to integer values written to the processor's
567Energy-Performance Preference (EPP) knob (if supported) or its
568Energy-Performance Bias (EPB) knob. It is also possible to write a positive
569integer value between 0 to 255, if the EPP feature is present. If the EPP
570feature is not present, writing integer value to this attribute is not
571supported. In this case, user can use
572 "/sys/devices/system/cpu/cpu*/power/energy_perf_bias" interface.
573
574[Note that tasks may by migrated from one CPU to another by the scheduler's
575load-balancing algorithm and if different energy vs performance hints are
576set for those CPUs, that may lead to undesirable outcomes.  To avoid such
577issues it is better to set the same energy vs performance hint for all CPUs
578or to pin every task potentially sensitive to them to a specific CPU.]
579
580.. _acpi-cpufreq:
581
582``intel_pstate`` vs ``acpi-cpufreq``
583====================================
584
585On the majority of systems supported by ``intel_pstate``, the ACPI tables
586provided by the platform firmware contain ``_PSS`` objects returning information
587that can be used for CPU performance scaling (refer to the ACPI specification
588[3]_ for details on the ``_PSS`` objects and the format of the information
589returned by them).
590
591The information returned by the ACPI ``_PSS`` objects is used by the
592``acpi-cpufreq`` scaling driver.  On systems supported by ``intel_pstate``
593the ``acpi-cpufreq`` driver uses the same hardware CPU performance scaling
594interface, but the set of P-states it can use is limited by the ``_PSS``
595output.
596
597On those systems each ``_PSS`` object returns a list of P-states supported by
598the corresponding CPU which basically is a subset of the P-states range that can
599be used by ``intel_pstate`` on the same system, with one exception: the whole
600`turbo range <turbo_>`_ is represented by one item in it (the topmost one).  By
601convention, the frequency returned by ``_PSS`` for that item is greater by 1 MHz
602than the frequency of the highest non-turbo P-state listed by it, but the
603corresponding P-state representation (following the hardware specification)
604returned for it matches the maximum supported turbo P-state (or is the
605special value 255 meaning essentially "go as high as you can get").
606
607The list of P-states returned by ``_PSS`` is reflected by the table of
608available frequencies supplied by ``acpi-cpufreq`` to the ``CPUFreq`` core and
609scaling governors and the minimum and maximum supported frequencies reported by
610it come from that list as well.  In particular, given the special representation
611of the turbo range described above, this means that the maximum supported
612frequency reported by ``acpi-cpufreq`` is higher by 1 MHz than the frequency
613of the highest supported non-turbo P-state listed by ``_PSS`` which, of course,
614affects decisions made by the scaling governors, except for ``powersave`` and
615``performance``.
616
617For example, if a given governor attempts to select a frequency proportional to
618estimated CPU load and maps the load of 100% to the maximum supported frequency
619(possibly multiplied by a constant), then it will tend to choose P-states below
620the turbo threshold if ``acpi-cpufreq`` is used as the scaling driver, because
621in that case the turbo range corresponds to a small fraction of the frequency
622band it can use (1 MHz vs 1 GHz or more).  In consequence, it will only go to
623the turbo range for the highest loads and the other loads above 50% that might
624benefit from running at turbo frequencies will be given non-turbo P-states
625instead.
626
627One more issue related to that may appear on systems supporting the
628`Configurable TDP feature <turbo_>`_ allowing the platform firmware to set the
629turbo threshold.  Namely, if that is not coordinated with the lists of P-states
630returned by ``_PSS`` properly, there may be more than one item corresponding to
631a turbo P-state in those lists and there may be a problem with avoiding the
632turbo range (if desirable or necessary).  Usually, to avoid using turbo
633P-states overall, ``acpi-cpufreq`` simply avoids using the topmost state listed
634by ``_PSS``, but that is not sufficient when there are other turbo P-states in
635the list returned by it.
636
637Apart from the above, ``acpi-cpufreq`` works like ``intel_pstate`` in the
638`passive mode <Passive Mode_>`_, except that the number of P-states it can set
639is limited to the ones listed by the ACPI ``_PSS`` objects.
640
641
642Kernel Command Line Options for ``intel_pstate``
643================================================
644
645Several kernel command line options can be used to pass early-configuration-time
646parameters to ``intel_pstate`` in order to enforce specific behavior of it.  All
647of them have to be prepended with the ``intel_pstate=`` prefix.
648
649``disable``
650	Do not register ``intel_pstate`` as the scaling driver even if the
651	processor is supported by it.
652
653``passive``
654	Register ``intel_pstate`` in the `passive mode <Passive Mode_>`_ to
655	start with.
656
657	This option implies the ``no_hwp`` one described below.
658
659``force``
660	Register ``intel_pstate`` as the scaling driver instead of
661	``acpi-cpufreq`` even if the latter is preferred on the given system.
662
663	This may prevent some platform features (such as thermal controls and
664	power capping) that rely on the availability of ACPI P-states
665	information from functioning as expected, so it should be used with
666	caution.
667
668	This option does not work with processors that are not supported by
669	``intel_pstate`` and on platforms where the ``pcc-cpufreq`` scaling
670	driver is used instead of ``acpi-cpufreq``.
671
672``no_hwp``
673	Do not enable the `hardware-managed P-states (HWP) feature
674	<Active Mode With HWP_>`_ even if it is supported by the processor.
675
676``hwp_only``
677	Register ``intel_pstate`` as the scaling driver only if the
678	`hardware-managed P-states (HWP) feature <Active Mode With HWP_>`_ is
679	supported by the processor.
680
681``support_acpi_ppc``
682	Take ACPI ``_PPC`` performance limits into account.
683
684	If the preferred power management profile in the FADT (Fixed ACPI
685	Description Table) is set to "Enterprise Server" or "Performance
686	Server", the ACPI ``_PPC`` limits are taken into account by default
687	and this option has no effect.
688
689``per_cpu_perf_limits``
690	Use per-logical-CPU P-State limits (see `Coordination of P-state
691	Limits`_ for details).
692
693
694Diagnostics and Tuning
695======================
696
697Trace Events
698------------
699
700There are two static trace events that can be used for ``intel_pstate``
701diagnostics.  One of them is the ``cpu_frequency`` trace event generally used
702by ``CPUFreq``, and the other one is the ``pstate_sample`` trace event specific
703to ``intel_pstate``.  Both of them are triggered by ``intel_pstate`` only if
704it works in the `active mode <Active Mode_>`_.
705
706The following sequence of shell commands can be used to enable them and see
707their output (if the kernel is generally configured to support event tracing)::
708
709 # cd /sys/kernel/debug/tracing/
710 # echo 1 > events/power/pstate_sample/enable
711 # echo 1 > events/power/cpu_frequency/enable
712 # cat trace
713 gnome-terminal--4510  [001] ..s.  1177.680733: pstate_sample: core_busy=107 scaled=94 from=26 to=26 mperf=1143818 aperf=1230607 tsc=29838618 freq=2474476
714 cat-5235  [002] ..s.  1177.681723: cpu_frequency: state=2900000 cpu_id=2
715
716If ``intel_pstate`` works in the `passive mode <Passive Mode_>`_, the
717``cpu_frequency`` trace event will be triggered either by the ``schedutil``
718scaling governor (for the policies it is attached to), or by the ``CPUFreq``
719core (for the policies with other scaling governors).
720
721``ftrace``
722----------
723
724The ``ftrace`` interface can be used for low-level diagnostics of
725``intel_pstate``.  For example, to check how often the function to set a
726P-state is called, the ``ftrace`` filter can be set to
727:c:func:`intel_pstate_set_pstate`::
728
729 # cd /sys/kernel/debug/tracing/
730 # cat available_filter_functions | grep -i pstate
731 intel_pstate_set_pstate
732 intel_pstate_cpu_init
733 ...
734 # echo intel_pstate_set_pstate > set_ftrace_filter
735 # echo function > current_tracer
736 # cat trace | head -15
737 # tracer: function
738 #
739 # entries-in-buffer/entries-written: 80/80   #P:4
740 #
741 #                              _-----=> irqs-off
742 #                             / _----=> need-resched
743 #                            | / _---=> hardirq/softirq
744 #                            || / _--=> preempt-depth
745 #                            ||| /     delay
746 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
747 #              | |       |   ||||       |         |
748             Xorg-3129  [000] ..s.  2537.644844: intel_pstate_set_pstate <-intel_pstate_timer_func
749  gnome-terminal--4510  [002] ..s.  2537.649844: intel_pstate_set_pstate <-intel_pstate_timer_func
750      gnome-shell-3409  [001] ..s.  2537.650850: intel_pstate_set_pstate <-intel_pstate_timer_func
751           <idle>-0     [000] ..s.  2537.654843: intel_pstate_set_pstate <-intel_pstate_timer_func
752
753
754References
755==========
756
757.. [1] Kristen Accardi, *Balancing Power and Performance in the Linux Kernel*,
758       https://events.static.linuxfound.org/sites/events/files/slides/LinuxConEurope_2015.pdf
759
760.. [2] *Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3: System Programming Guide*,
761       https://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-software-developer-system-programming-manual-325384.html
762
763.. [3] *Advanced Configuration and Power Interface Specification*,
764       https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf
765