Power management/Processor
Este artículo describe la configuración de la gestión de la energía para procesadores.
Escalado de la frecuencia de la UCP
El escalado de la frecuencia de la UCP es una técnica en la que la frecuencia de trabajo de un procesador se puede ajustar "al vuelo" para conservar energía y reducir el calor generado por el chip.
The ACPI specification describes the scaling mechanism as performance states - P-states or Processor Performance States.[1] The state labeled as P0 is used for the processor's highest possible frequency and P1-Pn states are used for lower frequencies.
Lower processor frequency leads to lower number of instruction processed over a unit of time. This means finding a balance between frequency and performance is necessary.
The kernel CPUFreq subsystem[2] is responsible for handling the frequency scaling. This subsystem provides two basic means of changing the scaling behavior:
- Scaling Governors - provide different approaches to estimate the desired processor frequency using different scaling algorithms.
- Scaling Drivers - provide an interface between scaling governors and the specific hardware. Scaling driver can read/write hardware-specific values on behalf of the governor.
The CPUFreq subsystem exposes multiple sysfs interfaces. The most useful is created per-processor /sys/devices/system/cpu/cpu*/cpufreq/. This directory contains various files, like:
- cpuinfo_cur_freq - current frequency in KHz as reported by the processor.
- cpuinfo_min_freq - minimal possible frequency in KHz as reported by the processor.
- cpuinfo_max_freq - maximal possible frequency in KHz as reported by the processor.
- scaling_governor - currently used scaling governor. It can be changed by writing to this file.
- scaling_driver - currently used scaling driver. It can be changed by writing to this file.
- scaling_min_freq - minimal processor frequency in KHz to be used by the governor. It can be set by writing to this file.
- scaling_max_freq - maximum processor frequency in KHz to be used by the governor. It can be set by writing to this file.
Instalación
BIOS
Algunas funciones se pueden habilitar o deshabilitar en el BIOS. Comprobar que las siguientes están habilitadas:
- "Processor C1E support"
- "Enhanced Speedstep (EIST)"
Núcleo
Activar las siguientes opciones del núcleo:
Power management and ACPI options --->
[*] ACPI (Advanced Configuration and Power Interface) Support --->
<*> Processor
CPU Frequency scaling --->
[*] CPU Frequency scaling
Default CPUFreq governor (ondemand) --->
Select a default governor; see below table
Default is ondemand
*** CPU frequency scaling drivers ***
Select a driver; see below table
Se necesita un gobernador que será el responsable de cambiar la frecuencia basándose en su perfil:
Opción | Módulo | Procesadores soportados | Nota |
---|---|---|---|
Gobernador 'performance' | cpufreq_performance | Ajusta la frecuencia de forma estática a la más alta disponible en la UCP. | Esta debería ser la opción por defecto para los procesadores Intel core. [3] |
Gobernador 'powersave' | cpufreq_powersave | Ajusta la frecuencia de forma estática a la más baja disponible en la UCP. | No se puede definir como opción por defecto |
Gobernador 'userspace' para escalado de frecuencia en espacio de usuario | cpufreq_userspace | Para ajustar la frecuencia de la UCP de forma manual o cuando a un programa en espacio de usuario se le permite ajustar UCP de forma dinámica. | |
Gobernador 'ondemand' de la directriz de cpufreq | cpufreq_ondemand | Realiza un muestreo periodico y cambia la frecuencia basándose en la utilización de la UCP. | Debería ser la opción por defecto para procesadores que no sean Intel core. |
Gobernador 'conservative' de cpufreq | cpufreq_conservative | Similar al gobernador bajo demanda (ondemand). La frecuencia se incrementa y decrementa progresivamente en llugar de saltar al 100% cuando se demanda rendimiento. |
Name of the active CPUFreq governor is available in: /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Behavior of active governor can be further configured via tunables exposed as sysfs interface. For more details see the dedicated documentation. Commonly used sysfs tunables include:
- schedutil - /sys/devices/system/cpu/cpufreq/schedutil/rate_limit_us sets minimal interval in μs between consecutive governor runs.
- ondemand - /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate sets the interval in μs between consecutive load sampling runs.
- conservative - /sys/devices/system/cpu/cpufreq/conservative/freq_step sets the maximal frequency change step as % of scaling_max_freq.
Opción | Módulo | Procesadores soportados | Notas |
---|---|---|---|
Intel P state control | intel_pstate | Nuevos (SandyBridge+) Intel Core | |
Controlador de interfaz de control del reloj del procesador | pcc-cpufreq | ||
Controlador ACPI del procesador P-States | acpi-cpufreq | Antiguos Intel Core, Intel Atom e Intel Pentium M | |
AMD Opteron/Athlon64 PowerNow! | powernow-k8 | AMD Opteron, AMD Athlon 64, AMD Turion 64 | |
Intel Enhanced SpeedStep (obsoleto) | speedstep-centrino | Intel Pentium M (Centrino), Intel Xeon | Obsoleto, utilizar en su lugar el controlador ACPI del procesador P-States driver |
Modulación de reloj del Intel Pentium 4 | p4-clockmod | Intel Pentium 4, Intel XEON | Provoca bajadas de rendimiento severas y demoras notables |
Availability of drivers depend on the processor architecture.
Name of the active CPUFreq driver is available in: /sys/devices/system/cpu/cpu*/cpufreq/scaling_driver
Specific CPU scaling drivers settings
Intel P-state
This driver implements internal scaling governors (roughly similar to CPUFreq's powersave and performance) and works based on the processor load. It is intended for recent Intel Core series of processors (based on the Sandy Bridge microarchitecture or newer).
This driver works in either active mode (intel_pstate), for processors featuring Hardware P-States (HWP), or passive mode (intel_cpufreq). The passive mode concerns the processors not supporting HWP which are generations prior the Skylake microarchitecture - no hwp
CPU flag is present.
In the active mode the processor autonomously sets the frequency based on provided CPUFreq parameters. This passes the control of frequency scaling to the processor itself. On the other hand, in the passive mode the driver behaves similarly to the generic acpi-cpufreq driver - it collaborates with the regular scaling governors. Although, it can use the full range of frequency steps.[4]
In the active mode case, the userspace, ondemand, and conservative scaling governors are unnecessary. The performance governor should be selected as the default. [5]
Power management and ACPI options --->
[*] CPU Frequency scaling --->
Default CPUFreq governor (performance) --->
-*- 'performance' governor
<*> Intel P state control
There is a sysfs interface exposed by the driver. Its root is located at the /sys/devices/system/cpu/intel_pstate/ directory. There are files like:
- no_turbo - disables the Intel Turbo Boost feature (1 means disabled and 0 means enabled). The state can be changed by writing to this file.
- status - displays the status of the driver. Values are either - off, passive, or active.
AMD P-State
This driver is available in kernel v5.17 or newer[6]. It aims to provide a more effective alternative to the generic acpi-cpufreq driver. It is based on Collaborative Processor Performance Control (CPPC)[7] to provide fine grained frequency steps. This was motivated by acpi-cpufreq providing only 3 frequency control options, and the lowest frequency is typically higher than what is made available when using amd-pstate thus being less effective than it might otherwise be as a way to maximize battery life.
It is intended for AMD Ryzen/EPYC processors based on the Zen 2 or newer microarchitecture. In case of hardware support and configuration mismatch the scaling driver gets set to the acpi-cpufreq as a fallback.
To verify the currently used driver did not fall back to acpi-cpufreq read: /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver.
In order to use this driver, "CPPC", "ACPI CPPC", or similar BIOS setting must be set to enabled or auto.
Power management and ACPI options --->
[*] CPU Frequency scaling --->
Default CPUFreq governor (performance) --->
-*- 'performance' governor
[*] AMD Processor P-State driver
<M> selftest for AMD Processor P-State driver
There is a sysfs interface exposed by the driver. Its root is located at the /sys/devices/system/cpu/amd_pstate/ directory. There are files like:
- status - displays the status of the driver. Values are either - active, passive, guided, or disable.
When the currently used driver falls back to the acpi-cpufreq driver the following kernel command-line parameters can fix loading the amd-pstate driver:
- Zen 2 processors: Add
amd_pstate.shared_mem=1
to enable amd-pstate using its shared memory implementation.[8] - Zen 3 or newer processors: Add
amd-pstate=passive
. Zen 3 or newer also supports CPPC.[7]
Kernel 6.3 further developed available AMD P-State options in the form of Energy Preference Performance (EPP) modes.[9] This new driver is referred as amd_pstate_epp. It allows new combinations of drivers and governors such as "amd_pstate_epp powersave performance" or "amd_pstate_epp performance performance". Some benchmarks are available.
For further details on the AMD P-state driver see the documentation available upstream.
Manual governor/driver change
Es posible cambiar el gobernador activo de la UCP mediante una simple orden:
root #
for c in $(ls -d /sys/devices/system/cpu/cpu[0-9]*); do
echo ondemand >$c/cpufreq/scaling_governor; done
Leer /etc/local.d/README para aprender a lanzar esta orden en el inicio.
Set governor at boot time
It is possible to set the default governor via cpufreq.default_governor kernel command-line parameter.
This parameter requires kernel v5.9+.[10]
Tics
El procesador ahorra la mayor parte de la energía cuando permanece más tiempo en el modo de ahorro de modo que se reduce el número de tics que despiertan al procesador.
Instalación
BIOS
Algunas funciones se pueden habilitar o deshabilitar en el BIOS. Comprobar que las siguientes están habilitadas:
- "HPET"
- "Multimedia timer"
Núcleo
Activar las siguientes opciones del núcleo:
Processor type and features --->
[*] Tickless System (Dynamic Ticks)
[*] High Resolution Timer Support
[*] HPET Timer Support
CPU Idle
Modern multi-core processors are often not fully loaded which brings an opportunity to suspend the unused parts and save power. The hardware transitions the unused parts to idle states. The kernel then does not schedule regular tasks to the idle parts but only special idle tasks.
The ACPI specification describes those idle states as C-states or Processor Power States. [11] There are usually multiple C-states implemented. Starting from the C0 state for a regularly running processor to C1, C2, and deeper idle states. The deeper the idle state, greater power saving but also a longer transition back to the running state.
The kernel CPUIdle subsystem[12] is responsible for handling the idle state management. Similarly to CPUFreq, this subsystem provides two basic means of idle state management - governor and driver. The governor attempts to predict the optimal C-state and driver to perform the operation on the hardware.
The CPUIdle subsystem exposes a sysfs interface. It is available at /sys/devices/system/cpu/cpuidle/. This directory contains various files, like:
- current_governor - currently used idle governor. It can be changed by writing to this file.
- available_governors - list of available idle governors.
- current_driver - currently used idle driver information.
Installation
BIOS
Check that the following settings are enabled in BIOS:
- "C-States"
- "ACPI C states"
Kernel
Name | Module / Kernel symbol | Supported Processors | Note |
---|---|---|---|
Intel Idle Time Driver | intel_idle (CONFIG_INTEL_IDLE) | recent (Nehalem+) Intel Core[13] | Asks the processor part to enter the idle state using the MWAIT instruction. |
ACPI Idle Driver | acpi_idle (CONFIG_ACPI_PROCESSOR_IDLE) | AMD processors, old Intel processors | Generic idle driver |
Name | Module / Kernel symbol | Note |
---|---|---|
Ladder Governor | ladder (CONFIG_CPU_IDLE_GOV_LADDER) | Default governor for systems with allowed scheduler ticks in idle - CONFIG_NO_HZ_IDLE=n. |
Menu Governor | menu (CONFIG_CPU_IDLE_GOV_MENU) | Default governor for tickless systems - CONFIG_NO_HZ_IDLE=y. |
Timer events oriented (TEO) governor | TEO (CONFIG_CPU_IDLE_GOV_TEO) | Alternative governor for tickless systems - CONFIG_NO_HZ_IDLE=y. |
Tools
PowerTOP
PowerTOP es una utilidad diseñada para medir, explicar y minimizar el consumo de energía eléctrica de un computador.
Cuando se lanza, ordena los procesos que están corriendo poniendo en primer lugar los que causan más a menudo que despierte el procesador. Para más detalles sobre su instalación, configuración y utilización, lea el artículo sobre PowerTOP.
cpupower
The sys-power/cpupower package provides a set of tools to comfortably manage and monitor processor powersaving features. The tools include cpupower frequency-info, cpupower frequency-set, and cpupower monitor.
Hprofile
Las aplicaciones como sys-power/cpupower hacen poco más que lo indicado arriba pero con una interfaz para su gestión. Por otro lado, el hecho de tener que lanzar ciertas órdenes como root dependiendo del uso del sistema no es muy eficiente para la mayoría de los usuarios. Es mejor automatizar ciertas decisiones sobre la gestión de la frecuencia de la UCP. Por ejemplo, cuando no se está conectado a la red eléctrica, la mayoría de los usuarios deseará tener su sistema en modo de ahorro de energía.
Aquí es donde entra en juego Hprofile. Por favor, consultar el artículo relacionada para obtener más información sobre su configuración.
Ver también
- ACPI - Interfaz de la configuración avanzada de la gestión de la energía.
Recursos externos
- ¿Qué es exáctamente un P-state? (Pt. 1) - Un artículo de Intel (que de alguna forma) explica el P-states.
- El gobernador de Linux "Ondemand" ya no es adecuado - Explica porqué el ondemand no se debería utilizar en los procesadores Intel core actuales.
Referencias
- ↑ 8. Processor Configuration and Control — ACPI Specification 6.4 documentation, UEFI Forum, Inc. Retrieved 9 September 2023.
- ↑ CPU Performance Scaling, The kernel development community. Retrieved 9 September 2023.
- ↑ Dominik Brodowski. Intel P-State driver, CPU frequency and voltage scaling code in the Linux(TM) kernel. Recuperado el 12 de junio de 2016.
- ↑ intel_pstate CPU Performance Scaling Driver, The kernel development community. Retrieved 9 September 2023.
- ↑ Dominik Brodowski. Intel P-State driver, CPU frequency and voltage scaling code in the Linux(TM) kernel. Retrieved 12 June 2016.
- ↑ AMD P-State Driver To Premiere In Linux 5.17 With Aim To Deliver Better Power Efficiency, Michael Larabel. Retrieved 9 September 2023.
- ↑ 7.0 7.1 Collaborative Processor Performance Control (CPPC), The kernel development community. Retrieved 9 September 2023.
- ↑ How to enable amd-pstate?, Manjaro.org. Retrieved 9 September 2023.
- ↑ Ryzen Mobile Power/Performance With Linux 6.3's New AMD P-State EPP Driver, Michael Larabel. Retrieved 9 September 2023.
- ↑ The kernel’s command-line parameters, The kernel development community. Retrieved 9 September 2023.
- ↑ 8.1. Processor Power States — ACPI Specification 6.4 documentation, UEFI Forum, Inc. Retrieved 10 September 2023.
- ↑ CPU Idle Time Management, The kernel development community. Retrieved 10 September 2023.
- ↑ intel_idle CPU Idle Time Management Driver, The kernel development community. Retrieved 10 September 2023.