Lines Matching full:the
15 The Concept of CPU Performance Scaling
18 The majority of modern processors are capable of operating in a number of
21 the higher the clock frequency and the higher the voltage, the more instructions
22 can be retired by the CPU over a unit of time, but also the higher the clock
23 frequency and the higher the voltage, the more energy is consumed over a unit of
24 time (or the more power is drawn) by the CPU in the given P-state. Therefore
25 there is a natural tradeoff between the CPU capacity (the number of instructions
26 that can be executed over a unit of time) and the power drawn by the CPU.
28 In some situations it is desirable or even necessary to run the program as fast
29 as possible and then there is no reason to use any P-states different from the
30 highest one (i.e. the highest-performance frequency/voltage configuration
32 instructions so quickly and maintaining the highest available CPU capacity for a
37 different frequency/voltage configurations or (in the ACPI terminology) to be
40 Typically, they are used along with algorithms to estimate the required CPU
41 capacity, so as to decide which P-states to put the CPUs into. Of course, since
42 the utilization of the system generally changes over time, that has to be done
43 repeatedly on a regular basis. The activity by which this happens is referred
45 adjusting the CPU clock frequency).
51 The Linux kernel supports CPU performance scaling by means of the ``CPUFreq``
52 (CPU Frequency scaling) subsystem that consists of three layers of code: the
55 The ``CPUFreq`` core provides the common code infrastructure and user space
57 the basic framework in which the other components operate.
59 Scaling governors implement algorithms to estimate the required CPU capacity.
63 Scaling drivers talk to the hardware. They provide scaling governors with
64 information on the available P-states (or P-state ranges in some cases) and
69 driver. That design is based on the observation that the information used by
71 platform-independent form in the majority of cases, so it should be possible
72 to use the same performance scaling algorithm implemented in exactly the same
73 way regardless of which scaling driver is used. Consequently, the same set of
77 based on information provided by the hardware itself, for example through
78 feedback registers, as that information is typically specific to the hardware
81 to bypass the governor layer and implement their own performance scaling
82 algorithms. That is done by the |intel_pstate| scaling driver.
88 In some cases the hardware interface for P-state control is shared by multiple
89 CPUs. That is, for example, the same register (or set of registers) is used to
90 control the P-state of multiple CPUs at the same time and writing to it affects
95 struct cpufreq_policy is also used when there is only one CPU in the given
98 The ``CPUFreq`` core maintains a pointer to a struct cpufreq_policy object for
99 every CPU in the system, including CPUs that are currently offline. If multiple
100 CPUs share the same hardware P-state control interface, all of the pointers
101 corresponding to them point to the same struct cpufreq_policy object.
103 ``CPUFreq`` uses struct cpufreq_policy as its basic data type and the design
104 of its user space interface is based on the policy concept.
111 It is only possible to register one scaling driver at a time, so the scaling
112 driver is expected to be able to handle all CPUs in the system.
114 The scaling driver may be registered before or after CPU registration. If
115 CPUs are registered earlier, the driver core invokes the ``CPUFreq`` core to
116 take a note of all of the already registered CPUs during the registration of the
117 scaling driver. In turn, if any CPUs are registered after the registration of
118 the scaling driver, the ``CPUFreq`` core will be invoked to take note of them
121 In any case, the ``CPUFreq`` core is invoked to take note of any logical CPU it
122 has not seen so far as soon as it is ready to handle that CPU. [Note that the
126 otherwise and the word "processor" is used to refer to the physical part
129 Once invoked, the ``CPUFreq`` core checks if the policy pointer is already set
130 for the given CPU and if so, it skips the policy object creation. Otherwise,
131 a new policy object is created and initialized, which involves the creation of
132 a new policy directory in ``sysfs``, and the policy pointer corresponding to
133 the given CPU is set to the new policy object's address in memory.
135 Next, the scaling driver's ``->init()`` callback is invoked with the policy
136 pointer of the new CPU passed to it as the argument. That callback is expected
137 to initialize the performance scaling hardware interface for the given CPU (or,
138 more precisely, for the set of CPUs sharing the hardware interface it belongs
139 to, represented by its policy object) and, if the policy object it has been
140 called for is new, to set parameters of the policy, like the minimum and maximum
141 frequencies supported by the hardware, the table of available frequencies (if
142 the set of supported P-states is not a continuous range), and the mask of CPUs
143 that belong to the same policy (including both online and offline CPUs). That
144 mask is then used by the core to populate the policy pointers for all of the
147 The next major initialization step for a new policy object is to attach a
148 scaling governor to it (to begin with, that is the default scaling governor
149 determined by the kernel command line or configuration, but it may be changed
150 later via ``sysfs``). First, a pointer to the new policy object is passed to
151 the governor's ``->init()`` callback which is expected to initialize all of the
152 data structures necessary to handle the given policy and, possibly, to add
153 a governor ``sysfs`` interface to it. Next, the governor is started by
157 all of the online CPUs belonging to the given policy with the CPU scheduler.
158 The utilization update callbacks will be invoked by the CPU scheduler on
159 important events, like task enqueue and dequeue, on every iteration of the
160 scheduler tick or generally whenever the CPU utilization may change (from the
162 to determine the P-state to use for the given policy going forward and to
163 invoke the scaling driver to make changes to the hardware in accordance with
164 the P-state selection. The scaling driver may be invoked directly from
166 on the configuration and capabilities of the scaling driver and the governor.
169 previously, meaning that all of the CPUs belonging to them were offline. The
170 only practical difference in that case is that the ``CPUFreq`` core will attempt
171 to use the scaling governor previously used with the policy that became
172 "inactive" (and is re-initialized now) instead of the default governor.
175 other CPUs sharing the policy object with it are online already, there is no
176 need to re-initialize the policy object at all. In that case, it only is
177 necessary to restart the scaling governor so that it can take the new online CPU
178 into account. That is achieved by invoking the governor's ``->stop`` and
179 ``->start()`` callbacks, in this order, for the entire policy.
181 As mentioned before, the |intel_pstate| scaling driver bypasses the scaling
184 new policy objects. Instead, the driver's ``->setpolicy()`` callback is invoked
186 callbacks are invoked by the CPU scheduler in the same way as for scaling
187 governors, but in the |intel_pstate| case they both determine the P-state to
188 use and change the hardware configuration accordingly in one go from scheduler
191 The policy objects created during CPU initialization and other data structures
192 associated with them are torn down when the scaling driver is unregistered
193 (which happens when the kernel module containing it is unloaded, for example) or
194 when the last CPU belonging to the given policy in unregistered.
200 During the initialization of the kernel, the ``CPUFreq`` core creates a
205 integer number) for every policy object maintained by the ``CPUFreq`` core.
208 that may be different from the one represented by ``X``) for all of the CPUs
209 associated with (or belonging to) the given policy. The ``policyX`` directories
211 attributes (files) to control ``CPUFreq`` behavior for the corresponding policy
212 objects (that is, for all of the CPUs associated with them).
214 Some of those attributes are generic. They are created by the ``CPUFreq`` core
216 and what scaling governor is attached to the given policy. Some scaling drivers
217 also add driver-specific attributes to the policy directories in ``sysfs`` to
220 The generic attributes under :file:`/sys/devices/system/cpu/cpufreq/policyX/`
221 are the following:
224 List of online CPUs belonging to this policy (i.e. sharing the hardware
225 performance scaling interface represented by the ``policyX`` policy
229 If the platform firmware (BIOS) tells the OS to apply an upper limit to
233 The existence of the limit may be a result of some (often unintentional)
240 This attribute is not present if the scaling driver in use does not
244 Current frequency of the CPUs belonging to this policy as obtained from
245 the hardware (in KHz).
247 This is expected to be the frequency the hardware actually runs at.
256 This is expected to be based on the frequency the hardware actually runs
266 Maximum possible operating frequency the CPUs belonging to this policy
270 Minimum possible operating frequency the CPUs belonging to this policy
274 The time it takes to switch the CPUs belonging to this policy from one
277 If unknown or if known to be so high that the scaling driver does not
278 work with the `ondemand`_ governor, -1 (:c:macro:`CPUFREQ_ETERNAL`)
285 List of available frequencies of the CPUs belonging to this policy
289 List of ``CPUFreq`` scaling governors present in the kernel that can
290 be attached to this policy or (if the |intel_pstate| scaling driver is
291 in use) list of scaling algorithms provided by the driver that can be
295 kernel module for the governor held by it to become available and be
299 Current frequency of all of the CPUs belonging to this policy (in kHz).
301 In the majority of cases, this is the frequency of the last P-state
302 requested by the scaling driver from the hardware using the scaling
303 interface provided by it, which may or may not reflect the frequency
304 the CPU is actually running at (due to hardware design and other
308 more precisely reflecting the current CPU frequency through this
309 attribute, but that still may not be the exact current CPU frequency as
310 seen by the hardware at the moment. This behavior though, is only
314 The scaling driver currently in use.
317 The scaling governor currently attached to this policy or (if the
318 |intel_pstate| scaling driver is in use) the scaling algorithm
319 provided by the driver that is currently applied to this policy.
323 provided by the scaling driver to be applied to it (in the
324 |intel_pstate| case), as indicated by the string written to this
325 attribute (which must be one of the names listed by the
329 Maximum frequency the CPUs belonging to this policy are allowed to be
334 than the value of the ``scaling_min_freq`` attribute).
337 Minimum frequency the CPUs belonging to this policy are allowed to be
342 be higher than the value of the ``scaling_max_freq`` attribute).
345 This attribute is functional only if the `userspace`_ scaling governor
346 is attached to the given policy.
348 It returns the last frequency requested by the governor (in kHz) or can
349 be written to in order to set a new frequency for the policy.
360 can be handled by different scaling governors at the same time (although that
363 The scaling governor for a given policy object can be changed at any time with
364 the help of the ``scaling_governor`` policy attribute in ``sysfs``.
366 Some governors expose ``sysfs`` attributes to control or fine-tune the scaling
368 tunables, can be either global (system-wide) or per-policy, depending on the
369 scaling driver in use. If the driver requires governor tunables to be
372 :file:`/sys/devices/system/cpu/cpufreq/`. In either case the name of the
373 subdirectory containing the governor tunables is the name of the governor
379 When attached to a policy object, this governor causes the highest frequency,
380 within the ``scaling_max_freq`` policy limit, to be requested for that policy.
382 The request is made once at that time the governor for the policy is set to
383 ``performance`` and whenever the ``scaling_max_freq`` or ``scaling_min_freq``
389 When attached to a policy object, this governor causes the lowest frequency,
390 within the ``scaling_min_freq`` policy limit, to be requested for that policy.
392 The request is made once at that time the governor for the policy is set to
393 ``powersave`` and whenever the ``scaling_max_freq`` or ``scaling_min_freq``
400 to set the CPU frequency for the policy it is attached to by writing to the
406 This governor uses CPU utilization data available from the CPU scheduler. It
407 generally is regarded as a part of the CPU scheduler, so it can access the
411 invoke the scaling driver asynchronously when it decides that the CPU frequency
412 should be changed for a given policy (that depends on whether or not the driver
413 is capable of changing the CPU frequency from scheduler context).
415 The actions of this governor for a particular CPU depend on the scheduling class
416 invoking its utilization update callback for that CPU. If it is invoked by the
417 RT or deadline scheduling classes, the governor will increase the frequency to
418 the allowed maximum (that is, the ``scaling_max_freq`` policy limit). In turn,
419 if it is invoked by the CFS scheduling class, the governor will use the
420 Per-Entity Load Tracking (PELT) metric for the root control group of the
421 given CPU as the CPU utilization estimate (see the *Per-entity load tracking*
422 LWN.net article [1]_ for a description of the PELT mechanism). Then, the new
423 CPU frequency to apply is computed in accordance with the formula
427 where ``util`` is the PELT number, ``max`` is the theoretical maximum of
428 ``util``, and ``f_0`` is either the maximum possible CPU frequency for the given
429 policy (if the PELT number is frequency-invariant), or the current CPU frequency
432 This governor also employs a mechanism allowing it to temporarily bump up the
434 "IO-wait boosting". That happens when the :c:macro:`SCHED_CPUFREQ_IOWAIT` flag
435 is passed by the scheduler to the governor callback which causes the frequency
436 to go up to the allowed maximum immediately and then draw back to the value
437 returned by the above formula over time.
443 runs of governor computations (default: 1.5 times the scaling driver's
444 transition latency or the maximum 2ms).
446 The purpose of this tunable is to reduce the scheduler context overhead
447 of the governor which might be excessive without it.
449 This governor generally is regarded as a replacement for the older `ondemand`_
451 tightly integrated with the CPU scheduler, its overhead in terms of CPU context
452 switches and similar is less significant, and it uses the scheduler's own CPU
453 utilization metric, so in principle its decisions should not contradict the
454 decisions made by the other parts of the scheduler.
461 In order to estimate the current CPU load, it measures the time elapsed between
462 consecutive invocations of its worker routine and computes the fraction of that
463 time in which the given CPU was not idle. The ratio of the non-idle (active)
464 time to the total CPU time is taken as an estimate of the load.
466 If this governor is attached to a policy shared by multiple CPUs, the load is
467 estimated for all of them and the greatest result is taken as the load estimate
468 for the entire policy.
470 The worker routine of this governor has to run in process context, so it is
472 there if necessary. As a result, the scheduler context overhead from this
474 relatively often and the CPU P-state updates triggered by it can be relatively
476 reduces the CPU idle time (even though the CPU idle time is only reduced very
479 It generally selects CPU frequencies proportional to the estimated load, so that
480 the value of the ``cpuinfo_max_freq`` policy attribute corresponds to the load of
481 1 (or 100%), and the value of the ``cpuinfo_min_freq`` policy attribute
482 corresponds to the load of 0, unless when the load exceeds a (configurable)
483 speedup threshold, in which case it will go straight for the highest frequency
484 it is allowed to use (the ``scaling_max_freq`` policy limit).
486 This governor exposes the following tunables:
489 This is how often the governor's worker routine should run, in
492 Typically, it is set to values of the order of 2000 (2 ms). Its
495 attached to. The minimum is typically the length of two scheduler
498 If this tunable is per-policy, the following shell command sets the time
499 represented by it to be 1.5 times as high as the transition latency
500 (the default)::
505 If the estimated CPU load is above this value (in percent), the governor
506 will set the frequency to the maximum value allowed for the policy.
507 Otherwise, the selected frequency will be proportional to the estimated
511 If set to 1 (default 0), it will cause the CPU load estimation code to
512 treat the CPU time spent on executing tasks with "nice" levels greater
515 This may be useful if there are tasks in the system that should not be
516 taken into account when deciding what frequency to run the CPUs at.
517 Then, to make that happen it is sufficient to increase the "nice" level
522 the ``sampling_rate`` value if the CPU load goes above ``up_threshold``.
524 This causes the next execution of the governor's worker routine (after
525 setting the frequency to the allowed maximum) to be delayed, so the
526 frequency stays at the maximum level for a longer time.
529 at the cost of additional energy spent on maintaining the maximum CPU
533 Reduction factor to apply to the original frequency target of the
534 governor (including the maximum value used when the ``up_threshold``
535 value is exceeded by the estimated CPU load) or sensitivity threshold
536 for the AMD frequency sensitivity powersave bias driver
540 If the AMD frequency sensitivity powersave bias driver is not loaded,
541 the effective frequency to apply is given by
545 where f is the governor's original frequency target. The default value
548 If the AMD frequency sensitivity powersave bias driver is loaded, the
553 measured workload sensitivity, between 0 and 100% inclusive, from the
554 hardware. That value can be used to estimate how the performance of the
557 The performance of a workload with the sensitivity of 0 (memory-bound or
559 the CPU frequency, whereas workloads with the sensitivity of 100%
560 (CPU-bound) are expected to perform much better if the CPU frequency is
563 If the workload sensitivity is less than the threshold represented by
564 the ``powersave_bias`` value, the sensitivity powersave bias driver
565 will cause the governor to select a frequency lower than its original
574 It estimates the CPU load in the same way as the `ondemand`_ governor described
575 above, but the CPU frequency selection algorithm implemented by it is different.
577 Namely, it avoids changing the frequency significantly over short time intervals
579 battery-powered). To achieve that, it changes the frequency in relatively
581 (configurable) threshold has been exceeded by the estimated CPU load.
583 This governor exposes the following tunables:
586 Frequency step in percent of the maximum frequency the governor is
587 allowed to set (the ``scaling_max_freq`` policy limit), between 0 and
590 This is how much the frequency is allowed to change in one go. Setting
591 it to 0 will cause the default frequency step (5 percent) to be used
592 and setting it to 100 effectively causes the governor to periodically
593 switch the frequency between the ``scaling_min_freq`` and
597 Threshold value (in percent, 20 by default) used to determine the
600 If the estimated CPU load is greater than this value, the frequency will
601 go up (by ``freq_step``). If the load is less than this value (and the
602 ``sampling_down_factor`` mechanism is not in effect), the frequency will
603 go down. Otherwise, the frequency will not be changed.
609 It effectively causes the frequency to go down ``sampling_down_factor``
619 Some processors support a mechanism to raise the operating frequency of some
620 cores in a multicore package temporarily (and above the sustainable frequency
621 threshold for the whole package) under certain conditions, for example if the
627 As a rule, it also is implemented differently by different vendors. The simple
631 The frequency boost mechanism may be either hardware-based or software-based.
632 If it is hardware-based (e.g. on x86), the decision to trigger the boosting is
633 made by the hardware (although in general it requires the hardware to be put
634 into a special state in which it can control the CPU frequency within certain
635 limits). If it is software-based (e.g. on ARM), the scaling driver decides
638 The ``boost`` File in ``sysfs``
642 the "boost" setting for the whole system. It is not present if the underlying
643 scaling driver does not support the frequency boost mechanism (or supports it,
647 If the value in this file is 1, the frequency boost mechanism is enabled. This
648 means that either the hardware can be put into states in which it is able to
649 trigger boosting (in the hardware-based case), or the software is allowed to
650 trigger boosting (in the software-based case). It does not mean that boosting
651 is actually in use at the moment on any CPUs in the system. It only means a
652 permission to use the frequency boost mechanism (which still may never be used
655 If the value in this file is 0, the frequency boost mechanism is disabled and
658 The only values that can be written to this file are 0 and 1.
663 The frequency boost mechanism is generally intended to help to achieve optimum
664 CPU performance on time scales below software resolution (e.g. below the
668 For this reason, many systems make it possible to disable the frequency boost
669 mechanism in the platform firmware (BIOS) setup, but that requires the system to
670 be restarted for the setting to be adjusted as desired, which may not be
673 1. Boosting means overclocking the processor, although under controlled
674 conditions. Generally, the processor's energy consumption increases
677 limited capacity, such as batteries, so the ability to disable the boost
678 mechanism while the system is running may help there (but that depends on
679 the workload too).
682 performance or energy consumption (or both) and the ability to disable
683 boosting while the system is running may be useful then.
685 3. To examine the impact of the frequency boost mechanism itself, it is useful
687 restarting the system in the meantime.
690 the boosting functionality depends on the load of the whole package,
692 unreproducible results sometimes. That can be avoided by disabling the
699 The AMD powernow-k8 scaling driver supports a ``sysfs`` knob very similar to
700 the global ``boost`` one. It is used for disabling/enabling the "Core
705 ``cpb``, which indicates a more fine grained control interface. The actual
706 implementation, however, works on the system-wide basis and setting that knob
707 for one policy causes the same value of it to be set for all of the other
708 policies at the same time.
711 hardware feature, but it may be configured out of the kernel (via the
712 :c:macro:`CONFIG_X86_ACPI_CPUFREQ_CPB` configuration option) and the global
713 ``boost`` knob is present regardless. Thus it is always possible use the
714 ``boost`` knob instead of the ``cpb`` one which is highly recommended, as that
715 is more consistent with what all of the other systems do (and the ``cpb`` knob
716 may not be supported any more in the future).
718 The ``cpb`` knob is never present for any processors without the underlying
719 hardware feature (e.g. all Intel ones), even if the