Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 .. include:: <isonum.txt>
0003 
0004 ===============================================
0005 ``intel_pstate`` CPU Performance Scaling Driver
0006 ===============================================
0007 
0008 :Copyright: |copy| 2017 Intel Corporation
0009 
0010 :Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
0011 
0012 
0013 General Information
0014 ===================
0015 
0016 ``intel_pstate`` is a part of the
0017 :doc:`CPU performance scaling subsystem <cpufreq>` in the Linux kernel
0018 (``CPUFreq``).  It is a scaling driver for the Sandy Bridge and later
0019 generations of Intel processors.  Note, however, that some of those processors
0020 may not be supported.  [To understand ``intel_pstate`` it is necessary to know
0021 how ``CPUFreq`` works in general, so this is the time to read
0022 Documentation/admin-guide/pm/cpufreq.rst if you have not done that yet.]
0023 
0024 For the processors supported by ``intel_pstate``, the P-state concept is broader
0025 than just an operating frequency or an operating performance point (see the
0026 LinuxCon Europe 2015 presentation by Kristen Accardi [1]_ for more
0027 information about that).  For this reason, the representation of P-states used
0028 by ``intel_pstate`` internally follows the hardware specification (for details
0029 refer to Intel Software Developer’s Manual [2]_).  However, the ``CPUFreq`` core
0030 uses frequencies for identifying operating performance points of CPUs and
0031 frequencies are involved in the user space interface exposed by it, so
0032 ``intel_pstate`` maps its internal representation of P-states to frequencies too
0033 (fortunately, that mapping is unambiguous).  At the same time, it would not be
0034 practical for ``intel_pstate`` to supply the ``CPUFreq`` core with a table of
0035 available frequencies due to the possible size of it, so the driver does not do
0036 that.  Some functionality of the core is limited by that.
0037 
0038 Since the hardware P-state selection interface used by ``intel_pstate`` is
0039 available at the logical CPU level, the driver always works with individual
0040 CPUs.  Consequently, if ``intel_pstate`` is in use, every ``CPUFreq`` policy
0041 object corresponds to one logical CPU and ``CPUFreq`` policies are effectively
0042 equivalent to CPUs.  In particular, this means that they become "inactive" every
0043 time the corresponding CPU is taken offline and need to be re-initialized when
0044 it goes back online.
0045 
0046 ``intel_pstate`` is not modular, so it cannot be unloaded, which means that the
0047 only way to pass early-configuration-time parameters to it is via the kernel
0048 command line.  However, its configuration can be adjusted via ``sysfs`` to a
0049 great extent.  In some configurations it even is possible to unregister it via
0050 ``sysfs`` which allows another ``CPUFreq`` scaling driver to be loaded and
0051 registered (see `below <status_attr_>`_).
0052 
0053 
0054 Operation Modes
0055 ===============
0056 
0057 ``intel_pstate`` can operate in two different modes, active or passive.  In the
0058 active mode, it uses its own internal performance scaling governor algorithm or
0059 allows the hardware to do performance scaling by itself, while in the passive
0060 mode it responds to requests made by a generic ``CPUFreq`` governor implementing
0061 a certain performance scaling algorithm.  Which of them will be in effect
0062 depends on what kernel command line options are used and on the capabilities of
0063 the processor.
0064 
0065 Active Mode
0066 -----------
0067 
0068 This is the default operation mode of ``intel_pstate`` for processors with
0069 hardware-managed P-states (HWP) support.  If it works in this mode, the
0070 ``scaling_driver`` policy attribute in ``sysfs`` for all ``CPUFreq`` policies
0071 contains the string "intel_pstate".
0072 
0073 In this mode the driver bypasses the scaling governors layer of ``CPUFreq`` and
0074 provides its own scaling algorithms for P-state selection.  Those algorithms
0075 can be applied to ``CPUFreq`` policies in the same way as generic scaling
0076 governors (that is, through the ``scaling_governor`` policy attribute in
0077 ``sysfs``).  [Note that different P-state selection algorithms may be chosen for
0078 different policies, but that is not recommended.]
0079 
0080 They are not generic scaling governors, but their names are the same as the
0081 names of some of those governors.  Moreover, confusingly enough, they generally
0082 do not work in the same way as the generic governors they share the names with.
0083 For example, the ``powersave`` P-state selection algorithm provided by
0084 ``intel_pstate`` is not a counterpart of the generic ``powersave`` governor
0085 (roughly, it corresponds to the ``schedutil`` and ``ondemand`` governors).
0086 
0087 There are two P-state selection algorithms provided by ``intel_pstate`` in the
0088 active mode: ``powersave`` and ``performance``.  The way they both operate
0089 depends on whether or not the hardware-managed P-states (HWP) feature has been
0090 enabled in the processor and possibly on the processor model.
0091 
0092 Which of the P-state selection algorithms is used by default depends on the
0093 :c:macro:`CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE` kernel configuration option.
0094 Namely, if that option is set, the ``performance`` algorithm will be used by
0095 default, and the other one will be used by default if it is not set.
0096 
0097 Active Mode With HWP
0098 ~~~~~~~~~~~~~~~~~~~~
0099 
0100 If the processor supports the HWP feature, it will be enabled during the
0101 processor initialization and cannot be disabled after that.  It is possible
0102 to avoid enabling it by passing the ``intel_pstate=no_hwp`` argument to the
0103 kernel in the command line.
0104 
0105 If the HWP feature has been enabled, ``intel_pstate`` relies on the processor to
0106 select P-states by itself, but still it can give hints to the processor's
0107 internal P-state selection logic.  What those hints are depends on which P-state
0108 selection algorithm has been applied to the given policy (or to the CPU it
0109 corresponds to).
0110 
0111 Even though the P-state selection is carried out by the processor automatically,
0112 ``intel_pstate`` registers utilization update callbacks with the CPU scheduler
0113 in this mode.  However, they are not used for running a P-state selection
0114 algorithm, but for periodic updates of the current CPU frequency information to
0115 be made available from the ``scaling_cur_freq`` policy attribute in ``sysfs``.
0116 
0117 HWP + ``performance``
0118 .....................
0119 
0120 In this configuration ``intel_pstate`` will write 0 to the processor's
0121 Energy-Performance Preference (EPP) knob (if supported) or its
0122 Energy-Performance Bias (EPB) knob (otherwise), which means that the processor's
0123 internal P-state selection logic is expected to focus entirely on performance.
0124 
0125 This will override the EPP/EPB setting coming from the ``sysfs`` interface
0126 (see `Energy vs Performance Hints`_ below).  Moreover, any attempts to change
0127 the EPP/EPB to a value different from 0 ("performance") via ``sysfs`` in this
0128 configuration will be rejected.
0129 
0130 Also, in this configuration the range of P-states available to the processor's
0131 internal P-state selection logic is always restricted to the upper boundary
0132 (that is, the maximum P-state that the driver is allowed to use).
0133 
0134 HWP + ``powersave``
0135 ...................
0136 
0137 In this configuration ``intel_pstate`` will set the processor's
0138 Energy-Performance Preference (EPP) knob (if supported) or its
0139 Energy-Performance Bias (EPB) knob (otherwise) to whatever value it was
0140 previously set to via ``sysfs`` (or whatever default value it was
0141 set to by the platform firmware).  This usually causes the processor's
0142 internal P-state selection logic to be less performance-focused.
0143 
0144 Active Mode Without HWP
0145 ~~~~~~~~~~~~~~~~~~~~~~~
0146 
0147 This operation mode is optional for processors that do not support the HWP
0148 feature or when the ``intel_pstate=no_hwp`` argument is passed to the kernel in
0149 the command line.  The active mode is used in those cases if the
0150 ``intel_pstate=active`` argument is passed to the kernel in the command line.
0151 In this mode ``intel_pstate`` may refuse to work with processors that are not
0152 recognized by it.  [Note that ``intel_pstate`` will never refuse to work with
0153 any processor with the HWP feature enabled.]
0154 
0155 In this mode ``intel_pstate`` registers utilization update callbacks with the
0156 CPU scheduler in order to run a P-state selection algorithm, either
0157 ``powersave`` or ``performance``, depending on the ``scaling_governor`` policy
0158 setting in ``sysfs``.  The current CPU frequency information to be made
0159 available from the ``scaling_cur_freq`` policy attribute in ``sysfs`` is
0160 periodically updated by those utilization update callbacks too.
0161 
0162 ``performance``
0163 ...............
0164 
0165 Without HWP, this P-state selection algorithm is always the same regardless of
0166 the processor model and platform configuration.
0167 
0168 It selects the maximum P-state it is allowed to use, subject to limits set via
0169 ``sysfs``, every time the driver configuration for the given CPU is updated
0170 (e.g. via ``sysfs``).
0171 
0172 This is the default P-state selection algorithm if the
0173 :c:macro:`CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE` kernel configuration option
0174 is set.
0175 
0176 ``powersave``
0177 .............
0178 
0179 Without HWP, this P-state selection algorithm is similar to the algorithm
0180 implemented by the generic ``schedutil`` scaling governor except that the
0181 utilization metric used by it is based on numbers coming from feedback
0182 registers of the CPU.  It generally selects P-states proportional to the
0183 current CPU utilization.
0184 
0185 This algorithm is run by the driver's utilization update callback for the
0186 given CPU when it is invoked by the CPU scheduler, but not more often than
0187 every 10 ms.  Like in the ``performance`` case, the hardware configuration
0188 is not touched if the new P-state turns out to be the same as the current
0189 one.
0190 
0191 This is the default P-state selection algorithm if the
0192 :c:macro:`CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE` kernel configuration option
0193 is not set.
0194 
0195 Passive Mode
0196 ------------
0197 
0198 This is the default operation mode of ``intel_pstate`` for processors without
0199 hardware-managed P-states (HWP) support.  It is always used if the
0200 ``intel_pstate=passive`` argument is passed to the kernel in the command line
0201 regardless of whether or not the given processor supports HWP.  [Note that the
0202 ``intel_pstate=no_hwp`` setting causes the driver to start in the passive mode
0203 if it is not combined with ``intel_pstate=active``.]  Like in the active mode
0204 without HWP support, in this mode ``intel_pstate`` may refuse to work with
0205 processors that are not recognized by it if HWP is prevented from being enabled
0206 through the kernel command line.
0207 
0208 If the driver works in this mode, the ``scaling_driver`` policy attribute in
0209 ``sysfs`` for all ``CPUFreq`` policies contains the string "intel_cpufreq".
0210 Then, the driver behaves like a regular ``CPUFreq`` scaling driver.  That is,
0211 it is invoked by generic scaling governors when necessary to talk to the
0212 hardware in order to change the P-state of a CPU (in particular, the
0213 ``schedutil`` governor can invoke it directly from scheduler context).
0214 
0215 While in this mode, ``intel_pstate`` can be used with all of the (generic)
0216 scaling governors listed by the ``scaling_available_governors`` policy attribute
0217 in ``sysfs`` (and the P-state selection algorithms described above are not
0218 used).  Then, it is responsible for the configuration of policy objects
0219 corresponding to CPUs and provides the ``CPUFreq`` core (and the scaling
0220 governors attached to the policy objects) with accurate information on the
0221 maximum and minimum operating frequencies supported by the hardware (including
0222 the so-called "turbo" frequency ranges).  In other words, in the passive mode
0223 the entire range of available P-states is exposed by ``intel_pstate`` to the
0224 ``CPUFreq`` core.  However, in this mode the driver does not register
0225 utilization update callbacks with the CPU scheduler and the ``scaling_cur_freq``
0226 information comes from the ``CPUFreq`` core (and is the last frequency selected
0227 by the current scaling governor for the given policy).
0228 
0229 
0230 .. _turbo:
0231 
0232 Turbo P-states Support
0233 ======================
0234 
0235 In the majority of cases, the entire range of P-states available to
0236 ``intel_pstate`` can be divided into two sub-ranges that correspond to
0237 different types of processor behavior, above and below a boundary that
0238 will be referred to as the "turbo threshold" in what follows.
0239 
0240 The P-states above the turbo threshold are referred to as "turbo P-states" and
0241 the whole sub-range of P-states they belong to is referred to as the "turbo
0242 range".  These names are related to the Turbo Boost technology allowing a
0243 multicore processor to opportunistically increase the P-state of one or more
0244 cores if there is enough power to do that and if that is not going to cause the
0245 thermal envelope of the processor package to be exceeded.
0246 
0247 Specifically, if software sets the P-state of a CPU core within the turbo range
0248 (that is, above the turbo threshold), the processor is permitted to take over
0249 performance scaling control for that core and put it into turbo P-states of its
0250 choice going forward.  However, that permission is interpreted differently by
0251 different processor generations.  Namely, the Sandy Bridge generation of
0252 processors will never use any P-states above the last one set by software for
0253 the given core, even if it is within the turbo range, whereas all of the later
0254 processor generations will take it as a license to use any P-states from the
0255 turbo range, even above the one set by software.  In other words, on those
0256 processors setting any P-state from the turbo range will enable the processor
0257 to put the given core into all turbo P-states up to and including the maximum
0258 supported one as it sees fit.
0259 
0260 One important property of turbo P-states is that they are not sustainable.  More
0261 precisely, there is no guarantee that any CPUs will be able to stay in any of
0262 those states indefinitely, because the power distribution within the processor
0263 package may change over time  or the thermal envelope it was designed for might
0264 be exceeded if a turbo P-state was used for too long.
0265 
0266 In turn, the P-states below the turbo threshold generally are sustainable.  In
0267 fact, if one of them is set by software, the processor is not expected to change
0268 it to a lower one unless in a thermal stress or a power limit violation
0269 situation (a higher P-state may still be used if it is set for another CPU in
0270 the same package at the same time, for example).
0271 
0272 Some processors allow multiple cores to be in turbo P-states at the same time,
0273 but the maximum P-state that can be set for them generally depends on the number
0274 of cores running concurrently.  The maximum turbo P-state that can be set for 3
0275 cores at the same time usually is lower than the analogous maximum P-state for
0276 2 cores, which in turn usually is lower than the maximum turbo P-state that can
0277 be set for 1 core.  The one-core maximum turbo P-state is thus the maximum
0278 supported one overall.
0279 
0280 The maximum supported turbo P-state, the turbo threshold (the maximum supported
0281 non-turbo P-state) and the minimum supported P-state are specific to the
0282 processor model and can be determined by reading the processor's model-specific
0283 registers (MSRs).  Moreover, some processors support the Configurable TDP
0284 (Thermal Design Power) feature and, when that feature is enabled, the turbo
0285 threshold effectively becomes a configurable value that can be set by the
0286 platform firmware.
0287 
0288 Unlike ``_PSS`` objects in the ACPI tables, ``intel_pstate`` always exposes
0289 the entire range of available P-states, including the whole turbo range, to the
0290 ``CPUFreq`` core and (in the passive mode) to generic scaling governors.  This
0291 generally causes turbo P-states to be set more often when ``intel_pstate`` is
0292 used relative to ACPI-based CPU performance scaling (see `below <acpi-cpufreq_>`_
0293 for more information).
0294 
0295 Moreover, since ``intel_pstate`` always knows what the real turbo threshold is
0296 (even if the Configurable TDP feature is enabled in the processor), its
0297 ``no_turbo`` attribute in ``sysfs`` (described `below <no_turbo_attr_>`_) should
0298 work as expected in all cases (that is, if set to disable turbo P-states, it
0299 always should prevent ``intel_pstate`` from using them).
0300 
0301 
0302 Processor Support
0303 =================
0304 
0305 To handle a given processor ``intel_pstate`` requires a number of different
0306 pieces of information on it to be known, including:
0307 
0308  * The minimum supported P-state.
0309 
0310  * The maximum supported `non-turbo P-state <turbo_>`_.
0311 
0312  * Whether or not turbo P-states are supported at all.
0313 
0314  * The maximum supported `one-core turbo P-state <turbo_>`_ (if turbo P-states
0315    are supported).
0316 
0317  * The scaling formula to translate the driver's internal representation
0318    of P-states into frequencies and the other way around.
0319 
0320 Generally, ways to obtain that information are specific to the processor model
0321 or family.  Although it often is possible to obtain all of it from the processor
0322 itself (using model-specific registers), there are cases in which hardware
0323 manuals need to be consulted to get to it too.
0324 
0325 For this reason, there is a list of supported processors in ``intel_pstate`` and
0326 the driver initialization will fail if the detected processor is not in that
0327 list, unless it supports the HWP feature.  [The interface to obtain all of the
0328 information listed above is the same for all of the processors supporting the
0329 HWP feature, which is why ``intel_pstate`` works with all of them.]
0330 
0331 
0332 User Space Interface in ``sysfs``
0333 =================================
0334 
0335 Global Attributes
0336 -----------------
0337 
0338 ``intel_pstate`` exposes several global attributes (files) in ``sysfs`` to
0339 control its functionality at the system level.  They are located in the
0340 ``/sys/devices/system/cpu/intel_pstate/`` directory and affect all CPUs.
0341 
0342 Some of them are not present if the ``intel_pstate=per_cpu_perf_limits``
0343 argument is passed to the kernel in the command line.
0344 
0345 ``max_perf_pct``
0346         Maximum P-state the driver is allowed to set in percent of the
0347         maximum supported performance level (the highest supported `turbo
0348         P-state <turbo_>`_).
0349 
0350         This attribute will not be exposed if the
0351         ``intel_pstate=per_cpu_perf_limits`` argument is present in the kernel
0352         command line.
0353 
0354 ``min_perf_pct``
0355         Minimum P-state the driver is allowed to set in percent of the
0356         maximum supported performance level (the highest supported `turbo
0357         P-state <turbo_>`_).
0358 
0359         This attribute will not be exposed if the
0360         ``intel_pstate=per_cpu_perf_limits`` argument is present in the kernel
0361         command line.
0362 
0363 ``num_pstates``
0364         Number of P-states supported by the processor (between 0 and 255
0365         inclusive) including both turbo and non-turbo P-states (see
0366         `Turbo P-states Support`_).
0367 
0368         This attribute is present only if the value exposed by it is the same
0369         for all of the CPUs in the system.
0370 
0371         The value of this attribute is not affected by the ``no_turbo``
0372         setting described `below <no_turbo_attr_>`_.
0373 
0374         This attribute is read-only.
0375 
0376 ``turbo_pct``
0377         Ratio of the `turbo range <turbo_>`_ size to the size of the entire
0378         range of supported P-states, in percent.
0379 
0380         This attribute is present only if the value exposed by it is the same
0381         for all of the CPUs in the system.
0382 
0383         This attribute is read-only.
0384 
0385 .. _no_turbo_attr:
0386 
0387 ``no_turbo``
0388         If set (equal to 1), the driver is not allowed to set any turbo P-states
0389         (see `Turbo P-states Support`_).  If unset (equal to 0, which is the
0390         default), turbo P-states can be set by the driver.
0391         [Note that ``intel_pstate`` does not support the general ``boost``
0392         attribute (supported by some other scaling drivers) which is replaced
0393         by this one.]
0394 
0395         This attribute does not affect the maximum supported frequency value
0396         supplied to the ``CPUFreq`` core and exposed via the policy interface,
0397         but it affects the maximum possible value of per-policy P-state limits
0398         (see `Interpretation of Policy Attributes`_ below for details).
0399 
0400 ``hwp_dynamic_boost``
0401         This attribute is only present if ``intel_pstate`` works in the
0402         `active mode with the HWP feature enabled <Active Mode With HWP_>`_ in
0403         the processor.  If set (equal to 1), it causes the minimum P-state limit
0404         to be increased dynamically for a short time whenever a task previously
0405         waiting on I/O is selected to run on a given logical CPU (the purpose
0406         of this mechanism is to improve performance).
0407 
0408         This setting has no effect on logical CPUs whose minimum P-state limit
0409         is directly set to the highest non-turbo P-state or above it.
0410 
0411 .. _status_attr:
0412 
0413 ``status``
0414         Operation mode of the driver: "active", "passive" or "off".
0415 
0416         "active"
0417                 The driver is functional and in the `active mode
0418                 <Active Mode_>`_.
0419 
0420         "passive"
0421                 The driver is functional and in the `passive mode
0422                 <Passive Mode_>`_.
0423 
0424         "off"
0425                 The driver is not functional (it is not registered as a scaling
0426                 driver with the ``CPUFreq`` core).
0427 
0428         This attribute can be written to in order to change the driver's
0429         operation mode or to unregister it.  The string written to it must be
0430         one of the possible values of it and, if successful, the write will
0431         cause the driver to switch over to the operation mode represented by
0432         that string - or to be unregistered in the "off" case.  [Actually,
0433         switching over from the active mode to the passive mode or the other
0434         way around causes the driver to be unregistered and registered again
0435         with a different set of callbacks, so all of its settings (the global
0436         as well as the per-policy ones) are then reset to their default
0437         values, possibly depending on the target operation mode.]
0438 
0439 ``energy_efficiency``
0440         This attribute is only present on platforms with CPUs matching the Kaby
0441         Lake or Coffee Lake desktop CPU model. By default, energy-efficiency
0442         optimizations are disabled on these CPU models if HWP is enabled.
0443         Enabling energy-efficiency optimizations may limit maximum operating
0444         frequency with or without the HWP feature.  With HWP enabled, the
0445         optimizations are done only in the turbo frequency range.  Without it,
0446         they are done in the entire available frequency range.  Setting this
0447         attribute to "1" enables the energy-efficiency optimizations and setting
0448         to "0" disables them.
0449 
0450 Interpretation of Policy Attributes
0451 -----------------------------------
0452 
0453 The interpretation of some ``CPUFreq`` policy attributes described in
0454 Documentation/admin-guide/pm/cpufreq.rst is special with ``intel_pstate``
0455 as the current scaling driver and it generally depends on the driver's
0456 `operation mode <Operation Modes_>`_.
0457 
0458 First of all, the values of the ``cpuinfo_max_freq``, ``cpuinfo_min_freq`` and
0459 ``scaling_cur_freq`` attributes are produced by applying a processor-specific
0460 multiplier to the internal P-state representation used by ``intel_pstate``.
0461 Also, the values of the ``scaling_max_freq`` and ``scaling_min_freq``
0462 attributes are capped by the frequency corresponding to the maximum P-state that
0463 the driver is allowed to set.
0464 
0465 If the ``no_turbo`` `global attribute <no_turbo_attr_>`_ is set, the driver is
0466 not allowed to use turbo P-states, so the maximum value of ``scaling_max_freq``
0467 and ``scaling_min_freq`` is limited to the maximum non-turbo P-state frequency.
0468 Accordingly, setting ``no_turbo`` causes ``scaling_max_freq`` and
0469 ``scaling_min_freq`` to go down to that value if they were above it before.
0470 However, the old values of ``scaling_max_freq`` and ``scaling_min_freq`` will be
0471 restored after unsetting ``no_turbo``, unless these attributes have been written
0472 to after ``no_turbo`` was set.
0473 
0474 If ``no_turbo`` is not set, the maximum possible value of ``scaling_max_freq``
0475 and ``scaling_min_freq`` corresponds to the maximum supported turbo P-state,
0476 which also is the value of ``cpuinfo_max_freq`` in either case.
0477 
0478 Next, the following policy attributes have special meaning if
0479 ``intel_pstate`` works in the `active mode <Active Mode_>`_:
0480 
0481 ``scaling_available_governors``
0482         List of P-state selection algorithms provided by ``intel_pstate``.
0483 
0484 ``scaling_governor``
0485         P-state selection algorithm provided by ``intel_pstate`` currently in
0486         use with the given policy.
0487 
0488 ``scaling_cur_freq``
0489         Frequency of the average P-state of the CPU represented by the given
0490         policy for the time interval between the last two invocations of the
0491         driver's utilization update callback by the CPU scheduler for that CPU.
0492 
0493 One more policy attribute is present if the HWP feature is enabled in the
0494 processor:
0495 
0496 ``base_frequency``
0497         Shows the base frequency of the CPU. Any frequency above this will be
0498         in the turbo frequency range.
0499 
0500 The meaning of these attributes in the `passive mode <Passive Mode_>`_ is the
0501 same as for other scaling drivers.
0502 
0503 Additionally, the value of the ``scaling_driver`` attribute for ``intel_pstate``
0504 depends on the operation mode of the driver.  Namely, it is either
0505 "intel_pstate" (in the `active mode <Active Mode_>`_) or "intel_cpufreq" (in the
0506 `passive mode <Passive Mode_>`_).
0507 
0508 Coordination of P-State Limits
0509 ------------------------------
0510 
0511 ``intel_pstate`` allows P-state limits to be set in two ways: with the help of
0512 the ``max_perf_pct`` and ``min_perf_pct`` `global attributes
0513 <Global Attributes_>`_ or via the ``scaling_max_freq`` and ``scaling_min_freq``
0514 ``CPUFreq`` policy attributes.  The coordination between those limits is based
0515 on the following rules, regardless of the current operation mode of the driver:
0516 
0517  1. All CPUs are affected by the global limits (that is, none of them can be
0518     requested to run faster than the global maximum and none of them can be
0519     requested to run slower than the global minimum).
0520 
0521  2. Each individual CPU is affected by its own per-policy limits (that is, it
0522     cannot be requested to run faster than its own per-policy maximum and it
0523     cannot be requested to run slower than its own per-policy minimum). The
0524     effective performance depends on whether the platform supports per core
0525     P-states, hyper-threading is enabled and on current performance requests
0526     from other CPUs. When platform doesn't support per core P-states, the
0527     effective performance can be more than the policy limits set on a CPU, if
0528     other CPUs are requesting higher performance at that moment. Even with per
0529     core P-states support, when hyper-threading is enabled, if the sibling CPU
0530     is requesting higher performance, the other siblings will get higher
0531     performance than their policy limits.
0532 
0533  3. The global and per-policy limits can be set independently.
0534 
0535 In the `active mode with the HWP feature enabled <Active Mode With HWP_>`_, the
0536 resulting effective values are written into hardware registers whenever the
0537 limits change in order to request its internal P-state selection logic to always
0538 set P-states within these limits.  Otherwise, the limits are taken into account
0539 by scaling governors (in the `passive mode <Passive Mode_>`_) and by the driver
0540 every time before setting a new P-state for a CPU.
0541 
0542 Additionally, if the ``intel_pstate=per_cpu_perf_limits`` command line argument
0543 is passed to the kernel, ``max_perf_pct`` and ``min_perf_pct`` are not exposed
0544 at all and the only way to set the limits is by using the policy attributes.
0545 
0546 
0547 Energy vs Performance Hints
0548 ---------------------------
0549 
0550 If the hardware-managed P-states (HWP) is enabled in the processor, additional
0551 attributes, intended to allow user space to help ``intel_pstate`` to adjust the
0552 processor's internal P-state selection logic by focusing it on performance or on
0553 energy-efficiency, or somewhere between the two extremes, are present in every
0554 ``CPUFreq`` policy directory in ``sysfs``.  They are :
0555 
0556 ``energy_performance_preference``
0557         Current value of the energy vs performance hint for the given policy
0558         (or the CPU represented by it).
0559 
0560         The hint can be changed by writing to this attribute.
0561 
0562 ``energy_performance_available_preferences``
0563         List of strings that can be written to the
0564         ``energy_performance_preference`` attribute.
0565 
0566         They represent different energy vs performance hints and should be
0567         self-explanatory, except that ``default`` represents whatever hint
0568         value was set by the platform firmware.
0569 
0570 Strings written to the ``energy_performance_preference`` attribute are
0571 internally translated to integer values written to the processor's
0572 Energy-Performance Preference (EPP) knob (if supported) or its
0573 Energy-Performance Bias (EPB) knob. It is also possible to write a positive
0574 integer value between 0 to 255, if the EPP feature is present. If the EPP
0575 feature is not present, writing integer value to this attribute is not
0576 supported. In this case, user can use the
0577 "/sys/devices/system/cpu/cpu*/power/energy_perf_bias" interface.
0578 
0579 [Note that tasks may by migrated from one CPU to another by the scheduler's
0580 load-balancing algorithm and if different energy vs performance hints are
0581 set for those CPUs, that may lead to undesirable outcomes.  To avoid such
0582 issues it is better to set the same energy vs performance hint for all CPUs
0583 or to pin every task potentially sensitive to them to a specific CPU.]
0584 
0585 .. _acpi-cpufreq:
0586 
0587 ``intel_pstate`` vs ``acpi-cpufreq``
0588 ====================================
0589 
0590 On the majority of systems supported by ``intel_pstate``, the ACPI tables
0591 provided by the platform firmware contain ``_PSS`` objects returning information
0592 that can be used for CPU performance scaling (refer to the ACPI specification
0593 [3]_ for details on the ``_PSS`` objects and the format of the information
0594 returned by them).
0595 
0596 The information returned by the ACPI ``_PSS`` objects is used by the
0597 ``acpi-cpufreq`` scaling driver.  On systems supported by ``intel_pstate``
0598 the ``acpi-cpufreq`` driver uses the same hardware CPU performance scaling
0599 interface, but the set of P-states it can use is limited by the ``_PSS``
0600 output.
0601 
0602 On those systems each ``_PSS`` object returns a list of P-states supported by
0603 the corresponding CPU which basically is a subset of the P-states range that can
0604 be used by ``intel_pstate`` on the same system, with one exception: the whole
0605 `turbo range <turbo_>`_ is represented by one item in it (the topmost one).  By
0606 convention, the frequency returned by ``_PSS`` for that item is greater by 1 MHz
0607 than the frequency of the highest non-turbo P-state listed by it, but the
0608 corresponding P-state representation (following the hardware specification)
0609 returned for it matches the maximum supported turbo P-state (or is the
0610 special value 255 meaning essentially "go as high as you can get").
0611 
0612 The list of P-states returned by ``_PSS`` is reflected by the table of
0613 available frequencies supplied by ``acpi-cpufreq`` to the ``CPUFreq`` core and
0614 scaling governors and the minimum and maximum supported frequencies reported by
0615 it come from that list as well.  In particular, given the special representation
0616 of the turbo range described above, this means that the maximum supported
0617 frequency reported by ``acpi-cpufreq`` is higher by 1 MHz than the frequency
0618 of the highest supported non-turbo P-state listed by ``_PSS`` which, of course,
0619 affects decisions made by the scaling governors, except for ``powersave`` and
0620 ``performance``.
0621 
0622 For example, if a given governor attempts to select a frequency proportional to
0623 estimated CPU load and maps the load of 100% to the maximum supported frequency
0624 (possibly multiplied by a constant), then it will tend to choose P-states below
0625 the turbo threshold if ``acpi-cpufreq`` is used as the scaling driver, because
0626 in that case the turbo range corresponds to a small fraction of the frequency
0627 band it can use (1 MHz vs 1 GHz or more).  In consequence, it will only go to
0628 the turbo range for the highest loads and the other loads above 50% that might
0629 benefit from running at turbo frequencies will be given non-turbo P-states
0630 instead.
0631 
0632 One more issue related to that may appear on systems supporting the
0633 `Configurable TDP feature <turbo_>`_ allowing the platform firmware to set the
0634 turbo threshold.  Namely, if that is not coordinated with the lists of P-states
0635 returned by ``_PSS`` properly, there may be more than one item corresponding to
0636 a turbo P-state in those lists and there may be a problem with avoiding the
0637 turbo range (if desirable or necessary).  Usually, to avoid using turbo
0638 P-states overall, ``acpi-cpufreq`` simply avoids using the topmost state listed
0639 by ``_PSS``, but that is not sufficient when there are other turbo P-states in
0640 the list returned by it.
0641 
0642 Apart from the above, ``acpi-cpufreq`` works like ``intel_pstate`` in the
0643 `passive mode <Passive Mode_>`_, except that the number of P-states it can set
0644 is limited to the ones listed by the ACPI ``_PSS`` objects.
0645 
0646 
0647 Kernel Command Line Options for ``intel_pstate``
0648 ================================================
0649 
0650 Several kernel command line options can be used to pass early-configuration-time
0651 parameters to ``intel_pstate`` in order to enforce specific behavior of it.  All
0652 of them have to be prepended with the ``intel_pstate=`` prefix.
0653 
0654 ``disable``
0655         Do not register ``intel_pstate`` as the scaling driver even if the
0656         processor is supported by it.
0657 
0658 ``active``
0659         Register ``intel_pstate`` in the `active mode <Active Mode_>`_ to start
0660         with.
0661 
0662 ``passive``
0663         Register ``intel_pstate`` in the `passive mode <Passive Mode_>`_ to
0664         start with.
0665 
0666 ``force``
0667         Register ``intel_pstate`` as the scaling driver instead of
0668         ``acpi-cpufreq`` even if the latter is preferred on the given system.
0669 
0670         This may prevent some platform features (such as thermal controls and
0671         power capping) that rely on the availability of ACPI P-states
0672         information from functioning as expected, so it should be used with
0673         caution.
0674 
0675         This option does not work with processors that are not supported by
0676         ``intel_pstate`` and on platforms where the ``pcc-cpufreq`` scaling
0677         driver is used instead of ``acpi-cpufreq``.
0678 
0679 ``no_hwp``
0680         Do not enable the hardware-managed P-states (HWP) feature even if it is
0681         supported by the processor.
0682 
0683 ``hwp_only``
0684         Register ``intel_pstate`` as the scaling driver only if the
0685         hardware-managed P-states (HWP) feature is supported by the processor.
0686 
0687 ``support_acpi_ppc``
0688         Take ACPI ``_PPC`` performance limits into account.
0689 
0690         If the preferred power management profile in the FADT (Fixed ACPI
0691         Description Table) is set to "Enterprise Server" or "Performance
0692         Server", the ACPI ``_PPC`` limits are taken into account by default
0693         and this option has no effect.
0694 
0695 ``per_cpu_perf_limits``
0696         Use per-logical-CPU P-State limits (see `Coordination of P-state
0697         Limits`_ for details).
0698 
0699 
0700 Diagnostics and Tuning
0701 ======================
0702 
0703 Trace Events
0704 ------------
0705 
0706 There are two static trace events that can be used for ``intel_pstate``
0707 diagnostics.  One of them is the ``cpu_frequency`` trace event generally used
0708 by ``CPUFreq``, and the other one is the ``pstate_sample`` trace event specific
0709 to ``intel_pstate``.  Both of them are triggered by ``intel_pstate`` only if
0710 it works in the `active mode <Active Mode_>`_.
0711 
0712 The following sequence of shell commands can be used to enable them and see
0713 their output (if the kernel is generally configured to support event tracing)::
0714 
0715  # cd /sys/kernel/debug/tracing/
0716  # echo 1 > events/power/pstate_sample/enable
0717  # echo 1 > events/power/cpu_frequency/enable
0718  # cat trace
0719  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
0720  cat-5235  [002] ..s.  1177.681723: cpu_frequency: state=2900000 cpu_id=2
0721 
0722 If ``intel_pstate`` works in the `passive mode <Passive Mode_>`_, the
0723 ``cpu_frequency`` trace event will be triggered either by the ``schedutil``
0724 scaling governor (for the policies it is attached to), or by the ``CPUFreq``
0725 core (for the policies with other scaling governors).
0726 
0727 ``ftrace``
0728 ----------
0729 
0730 The ``ftrace`` interface can be used for low-level diagnostics of
0731 ``intel_pstate``.  For example, to check how often the function to set a
0732 P-state is called, the ``ftrace`` filter can be set to
0733 :c:func:`intel_pstate_set_pstate`::
0734 
0735  # cd /sys/kernel/debug/tracing/
0736  # cat available_filter_functions | grep -i pstate
0737  intel_pstate_set_pstate
0738  intel_pstate_cpu_init
0739  ...
0740  # echo intel_pstate_set_pstate > set_ftrace_filter
0741  # echo function > current_tracer
0742  # cat trace | head -15
0743  # tracer: function
0744  #
0745  # entries-in-buffer/entries-written: 80/80   #P:4
0746  #
0747  #                              _-----=> irqs-off
0748  #                             / _----=> need-resched
0749  #                            | / _---=> hardirq/softirq
0750  #                            || / _--=> preempt-depth
0751  #                            ||| /     delay
0752  #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
0753  #              | |       |   ||||       |         |
0754              Xorg-3129  [000] ..s.  2537.644844: intel_pstate_set_pstate <-intel_pstate_timer_func
0755   gnome-terminal--4510  [002] ..s.  2537.649844: intel_pstate_set_pstate <-intel_pstate_timer_func
0756       gnome-shell-3409  [001] ..s.  2537.650850: intel_pstate_set_pstate <-intel_pstate_timer_func
0757            <idle>-0     [000] ..s.  2537.654843: intel_pstate_set_pstate <-intel_pstate_timer_func
0758 
0759 
0760 References
0761 ==========
0762 
0763 .. [1] Kristen Accardi, *Balancing Power and Performance in the Linux Kernel*,
0764        https://events.static.linuxfound.org/sites/events/files/slides/LinuxConEurope_2015.pdf
0765 
0766 .. [2] *Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3: System Programming Guide*,
0767        https://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-software-developer-system-programming-manual-325384.html
0768 
0769 .. [3] *Advanced Configuration and Power Interface Specification*,
0770        https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf