Power Management
Relevant source files
The following files were used as context for generating this wiki page:
Power Management (PM) controls the energy consumption of the system by adjusting the operational states of the CPU, peripherals, and the overall system. The Linux kernel provides frameworks to handle system-wide sleep states, dynamic frequency scaling, and idle state management to balance performance with energy efficiency.
The PM subsystem includes specialized modules such as cpufreq for performance scaling, cpuidle for deep sleep states during inactivity, and suspend for low-power system states like Suspend-to-RAM.
Sources: Documentation/power/index.rst, Documentation/translations/zh_CN/power/index.rst
System Suspend and Sleep States
The system suspend framework manages transitions between active and low-power states. Key states include Suspend-to-RAM (S2RAM) and standby. The kernel coordinates the freezing of tasks, suspending of devices, and disabling of non-boot CPUs before entering a hardware sleep state.
Suspend Workflow
The following diagram illustrates the sequence of operations performed by the kernel to enter a system-wide suspend state.
The flow ensures that userspace and kernel tasks stop executing and devices reach a quiescent state before the CPU enters sleep.
Sources: kernel/power/suspend.c:1-50, Documentation/power/index.rst:12-25
CPU Performance Scaling (cpufreq)
The cpufreq infrastructure regulates the clock speed of CPUs dynamically. It allows the system to scale frequency and voltage according to the current workload, reducing power consumption during low activity.
Components of cpufreq
- Core: Provides the standard interface and infrastructure for all CPUfreq drivers.
- Drivers: Implement hardware-specific frequency switching logic.
- Governors: Implement the logic to decide what frequency to set based on metrics like CPU load.
The CPUfreq core acts as a mediator between the decision-making governors and the hardware-specific drivers.
Sources: drivers/cpufreq/cpufreq.c:1-100, Documentation/power/index.rst:32
CPU Idle Management (cpuidle)
The cpuidle framework manages the entry into low-power states when the CPU has no tasks to execute. It selects the optimal idle state based on predicted inactivity duration and state exit latency.
Idle State Selection
The framework evaluates multiple idle states (C-states). Deeper states save more power but have higher exit latencies, which can impact system responsiveness.
| Component | Description |
|---|---|
cpuidle_device | Represents a single CPU and its current idle state. |
cpuidle_driver | Defines the C-states supported by the specific processor. |
cpuidle_governor | Predicts idle duration and selects the target C-state. |
Sources: drivers/cpuidle/cpuidle.c:1-80, Documentation/power/index.rst:31
Power Management Quality of Service (PM QoS)
PM QoS provides a mechanism for drivers and applications to express requirements for performance and latency. These constraints prevent the PM subsystem from entering states that would violate the specified criteria.
QoS Constraint Types
- CPU Latency: Limits the maximum exit latency allowed for idle states.
- Network Latency: Ensures timely processing of network packets.
- Throughput: Maintains minimum operational frequencies for high-bandwidth tasks.
Sources: Documentation/power/index.rst:20, Documentation/translations/zh_CN/power/index.rst:22
Energy Model and Operating Performance Points (OPP)
The Energy Model (EM) provides the kernel with power consumption data for different performance levels. The Operating Performance Points (OPP) framework manages the valid combinations of frequency and voltage for a device.
The Energy Model uses OPP data to calculate the most efficient performance state for a given workload.
Sources: Documentation/power/index.rst:16-18, Documentation/translations/zh_CN/power/index.rst:16-17
Summary
Power Management in the Linux kernel is a multi-layered system involving system-wide sleep states, dynamic CPU scaling via cpufreq, and autonomous idle management via cpuidle. By using PM QoS constraints and Energy Models, the kernel optimizes the balance between energy savings and system performance requirements.
Sources: Documentation/power/index.rst, kernel/power/suspend.c, drivers/cpufreq/cpufreq.c