Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 .. include:: <isonum.txt>
0003 
0004 .. |intel_pstate| replace:: :doc:`intel_pstate <intel_pstate>`
0005 
0006 =======================
0007 CPU Performance Scaling
0008 =======================
0009 
0010 :Copyright: |copy| 2017 Intel Corporation
0011 
0012 :Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
0013 
0014 
0015 The Concept of CPU Performance Scaling
0016 ======================================
0017 
0018 The majority of modern processors are capable of operating in a number of
0019 different clock frequency and voltage configurations, often referred to as
0020 Operating Performance Points or P-states (in ACPI terminology).  As a rule,
0021 the higher the clock frequency and the higher the voltage, the more instructions
0022 can be retired by the CPU over a unit of time, but also the higher the clock
0023 frequency and the higher the voltage, the more energy is consumed over a unit of
0024 time (or the more power is drawn) by the CPU in the given P-state.  Therefore
0025 there is a natural tradeoff between the CPU capacity (the number of instructions
0026 that can be executed over a unit of time) and the power drawn by the CPU.
0027 
0028 In some situations it is desirable or even necessary to run the program as fast
0029 as possible and then there is no reason to use any P-states different from the
0030 highest one (i.e. the highest-performance frequency/voltage configuration
0031 available).  In some other cases, however, it may not be necessary to execute
0032 instructions so quickly and maintaining the highest available CPU capacity for a
0033 relatively long time without utilizing it entirely may be regarded as wasteful.
0034 It also may not be physically possible to maintain maximum CPU capacity for too
0035 long for thermal or power supply capacity reasons or similar.  To cover those
0036 cases, there are hardware interfaces allowing CPUs to be switched between
0037 different frequency/voltage configurations or (in the ACPI terminology) to be
0038 put into different P-states.
0039 
0040 Typically, they are used along with algorithms to estimate the required CPU
0041 capacity, so as to decide which P-states to put the CPUs into.  Of course, since
0042 the utilization of the system generally changes over time, that has to be done
0043 repeatedly on a regular basis.  The activity by which this happens is referred
0044 to as CPU performance scaling or CPU frequency scaling (because it involves
0045 adjusting the CPU clock frequency).
0046 
0047 
0048 CPU Performance Scaling in Linux
0049 ================================
0050 
0051 The Linux kernel supports CPU performance scaling by means of the ``CPUFreq``
0052 (CPU Frequency scaling) subsystem that consists of three layers of code: the
0053 core, scaling governors and scaling drivers.
0054 
0055 The ``CPUFreq`` core provides the common code infrastructure and user space
0056 interfaces for all platforms that support CPU performance scaling.  It defines
0057 the basic framework in which the other components operate.
0058 
0059 Scaling governors implement algorithms to estimate the required CPU capacity.
0060 As a rule, each governor implements one, possibly parametrized, scaling
0061 algorithm.
0062 
0063 Scaling drivers talk to the hardware.  They provide scaling governors with
0064 information on the available P-states (or P-state ranges in some cases) and
0065 access platform-specific hardware interfaces to change CPU P-states as requested
0066 by scaling governors.
0067 
0068 In principle, all available scaling governors can be used with every scaling
0069 driver.  That design is based on the observation that the information used by
0070 performance scaling algorithms for P-state selection can be represented in a
0071 platform-independent form in the majority of cases, so it should be possible
0072 to use the same performance scaling algorithm implemented in exactly the same
0073 way regardless of which scaling driver is used.  Consequently, the same set of
0074 scaling governors should be suitable for every supported platform.
0075 
0076 However, that observation may not hold for performance scaling algorithms
0077 based on information provided by the hardware itself, for example through
0078 feedback registers, as that information is typically specific to the hardware
0079 interface it comes from and may not be easily represented in an abstract,
0080 platform-independent way.  For this reason, ``CPUFreq`` allows scaling drivers
0081 to bypass the governor layer and implement their own performance scaling
0082 algorithms.  That is done by the |intel_pstate| scaling driver.
0083 
0084 
0085 ``CPUFreq`` Policy Objects
0086 ==========================
0087 
0088 In some cases the hardware interface for P-state control is shared by multiple
0089 CPUs.  That is, for example, the same register (or set of registers) is used to
0090 control the P-state of multiple CPUs at the same time and writing to it affects
0091 all of those CPUs simultaneously.
0092 
0093 Sets of CPUs sharing hardware P-state control interfaces are represented by
0094 ``CPUFreq`` as struct cpufreq_policy objects.  For consistency,
0095 struct cpufreq_policy is also used when there is only one CPU in the given
0096 set.
0097 
0098 The ``CPUFreq`` core maintains a pointer to a struct cpufreq_policy object for
0099 every CPU in the system, including CPUs that are currently offline.  If multiple
0100 CPUs share the same hardware P-state control interface, all of the pointers
0101 corresponding to them point to the same struct cpufreq_policy object.
0102 
0103 ``CPUFreq`` uses struct cpufreq_policy as its basic data type and the design
0104 of its user space interface is based on the policy concept.
0105 
0106 
0107 CPU Initialization
0108 ==================
0109 
0110 First of all, a scaling driver has to be registered for ``CPUFreq`` to work.
0111 It is only possible to register one scaling driver at a time, so the scaling
0112 driver is expected to be able to handle all CPUs in the system.
0113 
0114 The scaling driver may be registered before or after CPU registration.  If
0115 CPUs are registered earlier, the driver core invokes the ``CPUFreq`` core to
0116 take a note of all of the already registered CPUs during the registration of the
0117 scaling driver.  In turn, if any CPUs are registered after the registration of
0118 the scaling driver, the ``CPUFreq`` core will be invoked to take note of them
0119 at their registration time.
0120 
0121 In any case, the ``CPUFreq`` core is invoked to take note of any logical CPU it
0122 has not seen so far as soon as it is ready to handle that CPU.  [Note that the
0123 logical CPU may be a physical single-core processor, or a single core in a
0124 multicore processor, or a hardware thread in a physical processor or processor
0125 core.  In what follows "CPU" always means "logical CPU" unless explicitly stated
0126 otherwise and the word "processor" is used to refer to the physical part
0127 possibly including multiple logical CPUs.]
0128 
0129 Once invoked, the ``CPUFreq`` core checks if the policy pointer is already set
0130 for the given CPU and if so, it skips the policy object creation.  Otherwise,
0131 a new policy object is created and initialized, which involves the creation of
0132 a new policy directory in ``sysfs``, and the policy pointer corresponding to
0133 the given CPU is set to the new policy object's address in memory.
0134 
0135 Next, the scaling driver's ``->init()`` callback is invoked with the policy
0136 pointer of the new CPU passed to it as the argument.  That callback is expected
0137 to initialize the performance scaling hardware interface for the given CPU (or,
0138 more precisely, for the set of CPUs sharing the hardware interface it belongs
0139 to, represented by its policy object) and, if the policy object it has been
0140 called for is new, to set parameters of the policy, like the minimum and maximum
0141 frequencies supported by the hardware, the table of available frequencies (if
0142 the set of supported P-states is not a continuous range), and the mask of CPUs
0143 that belong to the same policy (including both online and offline CPUs).  That
0144 mask is then used by the core to populate the policy pointers for all of the
0145 CPUs in it.
0146 
0147 The next major initialization step for a new policy object is to attach a
0148 scaling governor to it (to begin with, that is the default scaling governor
0149 determined by the kernel command line or configuration, but it may be changed
0150 later via ``sysfs``).  First, a pointer to the new policy object is passed to
0151 the governor's ``->init()`` callback which is expected to initialize all of the
0152 data structures necessary to handle the given policy and, possibly, to add
0153 a governor ``sysfs`` interface to it.  Next, the governor is started by
0154 invoking its ``->start()`` callback.
0155 
0156 That callback is expected to register per-CPU utilization update callbacks for
0157 all of the online CPUs belonging to the given policy with the CPU scheduler.
0158 The utilization update callbacks will be invoked by the CPU scheduler on
0159 important events, like task enqueue and dequeue, on every iteration of the
0160 scheduler tick or generally whenever the CPU utilization may change (from the
0161 scheduler's perspective).  They are expected to carry out computations needed
0162 to determine the P-state to use for the given policy going forward and to
0163 invoke the scaling driver to make changes to the hardware in accordance with
0164 the P-state selection.  The scaling driver may be invoked directly from
0165 scheduler context or asynchronously, via a kernel thread or workqueue, depending
0166 on the configuration and capabilities of the scaling driver and the governor.
0167 
0168 Similar steps are taken for policy objects that are not new, but were "inactive"
0169 previously, meaning that all of the CPUs belonging to them were offline.  The
0170 only practical difference in that case is that the ``CPUFreq`` core will attempt
0171 to use the scaling governor previously used with the policy that became
0172 "inactive" (and is re-initialized now) instead of the default governor.
0173 
0174 In turn, if a previously offline CPU is being brought back online, but some
0175 other CPUs sharing the policy object with it are online already, there is no
0176 need to re-initialize the policy object at all.  In that case, it only is
0177 necessary to restart the scaling governor so that it can take the new online CPU
0178 into account.  That is achieved by invoking the governor's ``->stop`` and
0179 ``->start()`` callbacks, in this order, for the entire policy.
0180 
0181 As mentioned before, the |intel_pstate| scaling driver bypasses the scaling
0182 governor layer of ``CPUFreq`` and provides its own P-state selection algorithms.
0183 Consequently, if |intel_pstate| is used, scaling governors are not attached to
0184 new policy objects.  Instead, the driver's ``->setpolicy()`` callback is invoked
0185 to register per-CPU utilization update callbacks for each policy.  These
0186 callbacks are invoked by the CPU scheduler in the same way as for scaling
0187 governors, but in the |intel_pstate| case they both determine the P-state to
0188 use and change the hardware configuration accordingly in one go from scheduler
0189 context.
0190 
0191 The policy objects created during CPU initialization and other data structures
0192 associated with them are torn down when the scaling driver is unregistered
0193 (which happens when the kernel module containing it is unloaded, for example) or
0194 when the last CPU belonging to the given policy in unregistered.
0195 
0196 
0197 Policy Interface in ``sysfs``
0198 =============================
0199 
0200 During the initialization of the kernel, the ``CPUFreq`` core creates a
0201 ``sysfs`` directory (kobject) called ``cpufreq`` under
0202 :file:`/sys/devices/system/cpu/`.
0203 
0204 That directory contains a ``policyX`` subdirectory (where ``X`` represents an
0205 integer number) for every policy object maintained by the ``CPUFreq`` core.
0206 Each ``policyX`` directory is pointed to by ``cpufreq`` symbolic links
0207 under :file:`/sys/devices/system/cpu/cpuY/` (where ``Y`` represents an integer
0208 that may be different from the one represented by ``X``) for all of the CPUs
0209 associated with (or belonging to) the given policy.  The ``policyX`` directories
0210 in :file:`/sys/devices/system/cpu/cpufreq` each contain policy-specific
0211 attributes (files) to control ``CPUFreq`` behavior for the corresponding policy
0212 objects (that is, for all of the CPUs associated with them).
0213 
0214 Some of those attributes are generic.  They are created by the ``CPUFreq`` core
0215 and their behavior generally does not depend on what scaling driver is in use
0216 and what scaling governor is attached to the given policy.  Some scaling drivers
0217 also add driver-specific attributes to the policy directories in ``sysfs`` to
0218 control policy-specific aspects of driver behavior.
0219 
0220 The generic attributes under :file:`/sys/devices/system/cpu/cpufreq/policyX/`
0221 are the following:
0222 
0223 ``affected_cpus``
0224         List of online CPUs belonging to this policy (i.e. sharing the hardware
0225         performance scaling interface represented by the ``policyX`` policy
0226         object).
0227 
0228 ``bios_limit``
0229         If the platform firmware (BIOS) tells the OS to apply an upper limit to
0230         CPU frequencies, that limit will be reported through this attribute (if
0231         present).
0232 
0233         The existence of the limit may be a result of some (often unintentional)
0234         BIOS settings, restrictions coming from a service processor or another
0235         BIOS/HW-based mechanisms.
0236 
0237         This does not cover ACPI thermal limitations which can be discovered
0238         through a generic thermal driver.
0239 
0240         This attribute is not present if the scaling driver in use does not
0241         support it.
0242 
0243 ``cpuinfo_cur_freq``
0244         Current frequency of the CPUs belonging to this policy as obtained from
0245         the hardware (in KHz).
0246 
0247         This is expected to be the frequency the hardware actually runs at.
0248         If that frequency cannot be determined, this attribute should not
0249         be present.
0250 
0251 ``cpuinfo_max_freq``
0252         Maximum possible operating frequency the CPUs belonging to this policy
0253         can run at (in kHz).
0254 
0255 ``cpuinfo_min_freq``
0256         Minimum possible operating frequency the CPUs belonging to this policy
0257         can run at (in kHz).
0258 
0259 ``cpuinfo_transition_latency``
0260         The time it takes to switch the CPUs belonging to this policy from one
0261         P-state to another, in nanoseconds.
0262 
0263         If unknown or if known to be so high that the scaling driver does not
0264         work with the `ondemand`_ governor, -1 (:c:macro:`CPUFREQ_ETERNAL`)
0265         will be returned by reads from this attribute.
0266 
0267 ``related_cpus``
0268         List of all (online and offline) CPUs belonging to this policy.
0269 
0270 ``scaling_available_governors``
0271         List of ``CPUFreq`` scaling governors present in the kernel that can
0272         be attached to this policy or (if the |intel_pstate| scaling driver is
0273         in use) list of scaling algorithms provided by the driver that can be
0274         applied to this policy.
0275 
0276         [Note that some governors are modular and it may be necessary to load a
0277         kernel module for the governor held by it to become available and be
0278         listed by this attribute.]
0279 
0280 ``scaling_cur_freq``
0281         Current frequency of all of the CPUs belonging to this policy (in kHz).
0282 
0283         In the majority of cases, this is the frequency of the last P-state
0284         requested by the scaling driver from the hardware using the scaling
0285         interface provided by it, which may or may not reflect the frequency
0286         the CPU is actually running at (due to hardware design and other
0287         limitations).
0288 
0289         Some architectures (e.g. ``x86``) may attempt to provide information
0290         more precisely reflecting the current CPU frequency through this
0291         attribute, but that still may not be the exact current CPU frequency as
0292         seen by the hardware at the moment.
0293 
0294 ``scaling_driver``
0295         The scaling driver currently in use.
0296 
0297 ``scaling_governor``
0298         The scaling governor currently attached to this policy or (if the
0299         |intel_pstate| scaling driver is in use) the scaling algorithm
0300         provided by the driver that is currently applied to this policy.
0301 
0302         This attribute is read-write and writing to it will cause a new scaling
0303         governor to be attached to this policy or a new scaling algorithm
0304         provided by the scaling driver to be applied to it (in the
0305         |intel_pstate| case), as indicated by the string written to this
0306         attribute (which must be one of the names listed by the
0307         ``scaling_available_governors`` attribute described above).
0308 
0309 ``scaling_max_freq``
0310         Maximum frequency the CPUs belonging to this policy are allowed to be
0311         running at (in kHz).
0312 
0313         This attribute is read-write and writing a string representing an
0314         integer to it will cause a new limit to be set (it must not be lower
0315         than the value of the ``scaling_min_freq`` attribute).
0316 
0317 ``scaling_min_freq``
0318         Minimum frequency the CPUs belonging to this policy are allowed to be
0319         running at (in kHz).
0320 
0321         This attribute is read-write and writing a string representing a
0322         non-negative integer to it will cause a new limit to be set (it must not
0323         be higher than the value of the ``scaling_max_freq`` attribute).
0324 
0325 ``scaling_setspeed``
0326         This attribute is functional only if the `userspace`_ scaling governor
0327         is attached to the given policy.
0328 
0329         It returns the last frequency requested by the governor (in kHz) or can
0330         be written to in order to set a new frequency for the policy.
0331 
0332 
0333 Generic Scaling Governors
0334 =========================
0335 
0336 ``CPUFreq`` provides generic scaling governors that can be used with all
0337 scaling drivers.  As stated before, each of them implements a single, possibly
0338 parametrized, performance scaling algorithm.
0339 
0340 Scaling governors are attached to policy objects and different policy objects
0341 can be handled by different scaling governors at the same time (although that
0342 may lead to suboptimal results in some cases).
0343 
0344 The scaling governor for a given policy object can be changed at any time with
0345 the help of the ``scaling_governor`` policy attribute in ``sysfs``.
0346 
0347 Some governors expose ``sysfs`` attributes to control or fine-tune the scaling
0348 algorithms implemented by them.  Those attributes, referred to as governor
0349 tunables, can be either global (system-wide) or per-policy, depending on the
0350 scaling driver in use.  If the driver requires governor tunables to be
0351 per-policy, they are located in a subdirectory of each policy directory.
0352 Otherwise, they are located in a subdirectory under
0353 :file:`/sys/devices/system/cpu/cpufreq/`.  In either case the name of the
0354 subdirectory containing the governor tunables is the name of the governor
0355 providing them.
0356 
0357 ``performance``
0358 ---------------
0359 
0360 When attached to a policy object, this governor causes the highest frequency,
0361 within the ``scaling_max_freq`` policy limit, to be requested for that policy.
0362 
0363 The request is made once at that time the governor for the policy is set to
0364 ``performance`` and whenever the ``scaling_max_freq`` or ``scaling_min_freq``
0365 policy limits change after that.
0366 
0367 ``powersave``
0368 -------------
0369 
0370 When attached to a policy object, this governor causes the lowest frequency,
0371 within the ``scaling_min_freq`` policy limit, to be requested for that policy.
0372 
0373 The request is made once at that time the governor for the policy is set to
0374 ``powersave`` and whenever the ``scaling_max_freq`` or ``scaling_min_freq``
0375 policy limits change after that.
0376 
0377 ``userspace``
0378 -------------
0379 
0380 This governor does not do anything by itself.  Instead, it allows user space
0381 to set the CPU frequency for the policy it is attached to by writing to the
0382 ``scaling_setspeed`` attribute of that policy.
0383 
0384 ``schedutil``
0385 -------------
0386 
0387 This governor uses CPU utilization data available from the CPU scheduler.  It
0388 generally is regarded as a part of the CPU scheduler, so it can access the
0389 scheduler's internal data structures directly.
0390 
0391 It runs entirely in scheduler context, although in some cases it may need to
0392 invoke the scaling driver asynchronously when it decides that the CPU frequency
0393 should be changed for a given policy (that depends on whether or not the driver
0394 is capable of changing the CPU frequency from scheduler context).
0395 
0396 The actions of this governor for a particular CPU depend on the scheduling class
0397 invoking its utilization update callback for that CPU.  If it is invoked by the
0398 RT or deadline scheduling classes, the governor will increase the frequency to
0399 the allowed maximum (that is, the ``scaling_max_freq`` policy limit).  In turn,
0400 if it is invoked by the CFS scheduling class, the governor will use the
0401 Per-Entity Load Tracking (PELT) metric for the root control group of the
0402 given CPU as the CPU utilization estimate (see the *Per-entity load tracking*
0403 LWN.net article [1]_ for a description of the PELT mechanism).  Then, the new
0404 CPU frequency to apply is computed in accordance with the formula
0405 
0406         f = 1.25 * ``f_0`` * ``util`` / ``max``
0407 
0408 where ``util`` is the PELT number, ``max`` is the theoretical maximum of
0409 ``util``, and ``f_0`` is either the maximum possible CPU frequency for the given
0410 policy (if the PELT number is frequency-invariant), or the current CPU frequency
0411 (otherwise).
0412 
0413 This governor also employs a mechanism allowing it to temporarily bump up the
0414 CPU frequency for tasks that have been waiting on I/O most recently, called
0415 "IO-wait boosting".  That happens when the :c:macro:`SCHED_CPUFREQ_IOWAIT` flag
0416 is passed by the scheduler to the governor callback which causes the frequency
0417 to go up to the allowed maximum immediately and then draw back to the value
0418 returned by the above formula over time.
0419 
0420 This governor exposes only one tunable:
0421 
0422 ``rate_limit_us``
0423         Minimum time (in microseconds) that has to pass between two consecutive
0424         runs of governor computations (default: 1000 times the scaling driver's
0425         transition latency).
0426 
0427         The purpose of this tunable is to reduce the scheduler context overhead
0428         of the governor which might be excessive without it.
0429 
0430 This governor generally is regarded as a replacement for the older `ondemand`_
0431 and `conservative`_ governors (described below), as it is simpler and more
0432 tightly integrated with the CPU scheduler, its overhead in terms of CPU context
0433 switches and similar is less significant, and it uses the scheduler's own CPU
0434 utilization metric, so in principle its decisions should not contradict the
0435 decisions made by the other parts of the scheduler.
0436 
0437 ``ondemand``
0438 ------------
0439 
0440 This governor uses CPU load as a CPU frequency selection metric.
0441 
0442 In order to estimate the current CPU load, it measures the time elapsed between
0443 consecutive invocations of its worker routine and computes the fraction of that
0444 time in which the given CPU was not idle.  The ratio of the non-idle (active)
0445 time to the total CPU time is taken as an estimate of the load.
0446 
0447 If this governor is attached to a policy shared by multiple CPUs, the load is
0448 estimated for all of them and the greatest result is taken as the load estimate
0449 for the entire policy.
0450 
0451 The worker routine of this governor has to run in process context, so it is
0452 invoked asynchronously (via a workqueue) and CPU P-states are updated from
0453 there if necessary.  As a result, the scheduler context overhead from this
0454 governor is minimum, but it causes additional CPU context switches to happen
0455 relatively often and the CPU P-state updates triggered by it can be relatively
0456 irregular.  Also, it affects its own CPU load metric by running code that
0457 reduces the CPU idle time (even though the CPU idle time is only reduced very
0458 slightly by it).
0459 
0460 It generally selects CPU frequencies proportional to the estimated load, so that
0461 the value of the ``cpuinfo_max_freq`` policy attribute corresponds to the load of
0462 1 (or 100%), and the value of the ``cpuinfo_min_freq`` policy attribute
0463 corresponds to the load of 0, unless when the load exceeds a (configurable)
0464 speedup threshold, in which case it will go straight for the highest frequency
0465 it is allowed to use (the ``scaling_max_freq`` policy limit).
0466 
0467 This governor exposes the following tunables:
0468 
0469 ``sampling_rate``
0470         This is how often the governor's worker routine should run, in
0471         microseconds.
0472 
0473         Typically, it is set to values of the order of 10000 (10 ms).  Its
0474         default value is equal to the value of ``cpuinfo_transition_latency``
0475         for each policy this governor is attached to (but since the unit here
0476         is greater by 1000, this means that the time represented by
0477         ``sampling_rate`` is 1000 times greater than the transition latency by
0478         default).
0479 
0480         If this tunable is per-policy, the following shell command sets the time
0481         represented by it to be 750 times as high as the transition latency::
0482 
0483         # echo `$(($(cat cpuinfo_transition_latency) * 750 / 1000)) > ondemand/sampling_rate
0484 
0485 ``up_threshold``
0486         If the estimated CPU load is above this value (in percent), the governor
0487         will set the frequency to the maximum value allowed for the policy.
0488         Otherwise, the selected frequency will be proportional to the estimated
0489         CPU load.
0490 
0491 ``ignore_nice_load``
0492         If set to 1 (default 0), it will cause the CPU load estimation code to
0493         treat the CPU time spent on executing tasks with "nice" levels greater
0494         than 0 as CPU idle time.
0495 
0496         This may be useful if there are tasks in the system that should not be
0497         taken into account when deciding what frequency to run the CPUs at.
0498         Then, to make that happen it is sufficient to increase the "nice" level
0499         of those tasks above 0 and set this attribute to 1.
0500 
0501 ``sampling_down_factor``
0502         Temporary multiplier, between 1 (default) and 100 inclusive, to apply to
0503         the ``sampling_rate`` value if the CPU load goes above ``up_threshold``.
0504 
0505         This causes the next execution of the governor's worker routine (after
0506         setting the frequency to the allowed maximum) to be delayed, so the
0507         frequency stays at the maximum level for a longer time.
0508 
0509         Frequency fluctuations in some bursty workloads may be avoided this way
0510         at the cost of additional energy spent on maintaining the maximum CPU
0511         capacity.
0512 
0513 ``powersave_bias``
0514         Reduction factor to apply to the original frequency target of the
0515         governor (including the maximum value used when the ``up_threshold``
0516         value is exceeded by the estimated CPU load) or sensitivity threshold
0517         for the AMD frequency sensitivity powersave bias driver
0518         (:file:`drivers/cpufreq/amd_freq_sensitivity.c`), between 0 and 1000
0519         inclusive.
0520 
0521         If the AMD frequency sensitivity powersave bias driver is not loaded,
0522         the effective frequency to apply is given by
0523 
0524                 f * (1 - ``powersave_bias`` / 1000)
0525 
0526         where f is the governor's original frequency target.  The default value
0527         of this attribute is 0 in that case.
0528 
0529         If the AMD frequency sensitivity powersave bias driver is loaded, the
0530         value of this attribute is 400 by default and it is used in a different
0531         way.
0532 
0533         On Family 16h (and later) AMD processors there is a mechanism to get a
0534         measured workload sensitivity, between 0 and 100% inclusive, from the
0535         hardware.  That value can be used to estimate how the performance of the
0536         workload running on a CPU will change in response to frequency changes.
0537 
0538         The performance of a workload with the sensitivity of 0 (memory-bound or
0539         IO-bound) is not expected to increase at all as a result of increasing
0540         the CPU frequency, whereas workloads with the sensitivity of 100%
0541         (CPU-bound) are expected to perform much better if the CPU frequency is
0542         increased.
0543 
0544         If the workload sensitivity is less than the threshold represented by
0545         the ``powersave_bias`` value, the sensitivity powersave bias driver
0546         will cause the governor to select a frequency lower than its original
0547         target, so as to avoid over-provisioning workloads that will not benefit
0548         from running at higher CPU frequencies.
0549 
0550 ``conservative``
0551 ----------------
0552 
0553 This governor uses CPU load as a CPU frequency selection metric.
0554 
0555 It estimates the CPU load in the same way as the `ondemand`_ governor described
0556 above, but the CPU frequency selection algorithm implemented by it is different.
0557 
0558 Namely, it avoids changing the frequency significantly over short time intervals
0559 which may not be suitable for systems with limited power supply capacity (e.g.
0560 battery-powered).  To achieve that, it changes the frequency in relatively
0561 small steps, one step at a time, up or down - depending on whether or not a
0562 (configurable) threshold has been exceeded by the estimated CPU load.
0563 
0564 This governor exposes the following tunables:
0565 
0566 ``freq_step``
0567         Frequency step in percent of the maximum frequency the governor is
0568         allowed to set (the ``scaling_max_freq`` policy limit), between 0 and
0569         100 (5 by default).
0570 
0571         This is how much the frequency is allowed to change in one go.  Setting
0572         it to 0 will cause the default frequency step (5 percent) to be used
0573         and setting it to 100 effectively causes the governor to periodically
0574         switch the frequency between the ``scaling_min_freq`` and
0575         ``scaling_max_freq`` policy limits.
0576 
0577 ``down_threshold``
0578         Threshold value (in percent, 20 by default) used to determine the
0579         frequency change direction.
0580 
0581         If the estimated CPU load is greater than this value, the frequency will
0582         go up (by ``freq_step``).  If the load is less than this value (and the
0583         ``sampling_down_factor`` mechanism is not in effect), the frequency will
0584         go down.  Otherwise, the frequency will not be changed.
0585 
0586 ``sampling_down_factor``
0587         Frequency decrease deferral factor, between 1 (default) and 10
0588         inclusive.
0589 
0590         It effectively causes the frequency to go down ``sampling_down_factor``
0591         times slower than it ramps up.
0592 
0593 
0594 Frequency Boost Support
0595 =======================
0596 
0597 Background
0598 ----------
0599 
0600 Some processors support a mechanism to raise the operating frequency of some
0601 cores in a multicore package temporarily (and above the sustainable frequency
0602 threshold for the whole package) under certain conditions, for example if the
0603 whole chip is not fully utilized and below its intended thermal or power budget.
0604 
0605 Different names are used by different vendors to refer to this functionality.
0606 For Intel processors it is referred to as "Turbo Boost", AMD calls it
0607 "Turbo-Core" or (in technical documentation) "Core Performance Boost" and so on.
0608 As a rule, it also is implemented differently by different vendors.  The simple
0609 term "frequency boost" is used here for brevity to refer to all of those
0610 implementations.
0611 
0612 The frequency boost mechanism may be either hardware-based or software-based.
0613 If it is hardware-based (e.g. on x86), the decision to trigger the boosting is
0614 made by the hardware (although in general it requires the hardware to be put
0615 into a special state in which it can control the CPU frequency within certain
0616 limits).  If it is software-based (e.g. on ARM), the scaling driver decides
0617 whether or not to trigger boosting and when to do that.
0618 
0619 The ``boost`` File in ``sysfs``
0620 -------------------------------
0621 
0622 This file is located under :file:`/sys/devices/system/cpu/cpufreq/` and controls
0623 the "boost" setting for the whole system.  It is not present if the underlying
0624 scaling driver does not support the frequency boost mechanism (or supports it,
0625 but provides a driver-specific interface for controlling it, like
0626 |intel_pstate|).
0627 
0628 If the value in this file is 1, the frequency boost mechanism is enabled.  This
0629 means that either the hardware can be put into states in which it is able to
0630 trigger boosting (in the hardware-based case), or the software is allowed to
0631 trigger boosting (in the software-based case).  It does not mean that boosting
0632 is actually in use at the moment on any CPUs in the system.  It only means a
0633 permission to use the frequency boost mechanism (which still may never be used
0634 for other reasons).
0635 
0636 If the value in this file is 0, the frequency boost mechanism is disabled and
0637 cannot be used at all.
0638 
0639 The only values that can be written to this file are 0 and 1.
0640 
0641 Rationale for Boost Control Knob
0642 --------------------------------
0643 
0644 The frequency boost mechanism is generally intended to help to achieve optimum
0645 CPU performance on time scales below software resolution (e.g. below the
0646 scheduler tick interval) and it is demonstrably suitable for many workloads, but
0647 it may lead to problems in certain situations.
0648 
0649 For this reason, many systems make it possible to disable the frequency boost
0650 mechanism in the platform firmware (BIOS) setup, but that requires the system to
0651 be restarted for the setting to be adjusted as desired, which may not be
0652 practical at least in some cases.  For example:
0653 
0654   1. Boosting means overclocking the processor, although under controlled
0655      conditions.  Generally, the processor's energy consumption increases
0656      as a result of increasing its frequency and voltage, even temporarily.
0657      That may not be desirable on systems that switch to power sources of
0658      limited capacity, such as batteries, so the ability to disable the boost
0659      mechanism while the system is running may help there (but that depends on
0660      the workload too).
0661 
0662   2. In some situations deterministic behavior is more important than
0663      performance or energy consumption (or both) and the ability to disable
0664      boosting while the system is running may be useful then.
0665 
0666   3. To examine the impact of the frequency boost mechanism itself, it is useful
0667      to be able to run tests with and without boosting, preferably without
0668      restarting the system in the meantime.
0669 
0670   4. Reproducible results are important when running benchmarks.  Since
0671      the boosting functionality depends on the load of the whole package,
0672      single-thread performance may vary because of it which may lead to
0673      unreproducible results sometimes.  That can be avoided by disabling the
0674      frequency boost mechanism before running benchmarks sensitive to that
0675      issue.
0676 
0677 Legacy AMD ``cpb`` Knob
0678 -----------------------
0679 
0680 The AMD powernow-k8 scaling driver supports a ``sysfs`` knob very similar to
0681 the global ``boost`` one.  It is used for disabling/enabling the "Core
0682 Performance Boost" feature of some AMD processors.
0683 
0684 If present, that knob is located in every ``CPUFreq`` policy directory in
0685 ``sysfs`` (:file:`/sys/devices/system/cpu/cpufreq/policyX/`) and is called
0686 ``cpb``, which indicates a more fine grained control interface.  The actual
0687 implementation, however, works on the system-wide basis and setting that knob
0688 for one policy causes the same value of it to be set for all of the other
0689 policies at the same time.
0690 
0691 That knob is still supported on AMD processors that support its underlying
0692 hardware feature, but it may be configured out of the kernel (via the
0693 :c:macro:`CONFIG_X86_ACPI_CPUFREQ_CPB` configuration option) and the global
0694 ``boost`` knob is present regardless.  Thus it is always possible use the
0695 ``boost`` knob instead of the ``cpb`` one which is highly recommended, as that
0696 is more consistent with what all of the other systems do (and the ``cpb`` knob
0697 may not be supported any more in the future).
0698 
0699 The ``cpb`` knob is never present for any processors without the underlying
0700 hardware feature (e.g. all Intel ones), even if the
0701 :c:macro:`CONFIG_X86_ACPI_CPUFREQ_CPB` configuration option is set.
0702 
0703 
0704 References
0705 ==========
0706 
0707 .. [1] Jonathan Corbet, *Per-entity load tracking*,
0708        https://lwn.net/Articles/531853/