Using the Command 'cpupower' (with examples)
- Linux
- December 17, 2024
The cpupower
command is a versatile tool designed to provide insights and allow users to modify the CPU power management features on Linux systems. This command is instrumental when tuning a system for performance, power-saving, or achieving a balance between the two. It offers functionalities to gather information on CPU cores and manage frequency governors and other settings that affect power consumption and processing capabilities.
Listing CPUs and Their Information: Identifying and Understanding CPU Details
Code:
sudo cpupower --cpu all info
Motivation: Understanding the operational characteristics of all CPUs is crucial for system administrators and performance enthusiasts. By using this command, one can gain insight into the CPU’s current state, such as available frequencies, current operating frequency, and other vital parameters. This information can be instrumental in diagnosing performance bottlenecks or in proactively managing CPU configurations to optimize power consumption and processing efficiency.
Explanation:
sudo
: This command requires superuser permissions to access low-level system details, ensuring that sensitive CPU data is handled securely.cpupower
: The tool being used to manage CPU power settings.--cpu all
: Specifies that the command should retrieve information about all available CPU cores.info
: Directscpupower
to display detailed information about the CPU(s), including data relevant to power management.
Example Output:
analyzing CPU 0:
driver: acpi-cpufreq
CPUs which run at the same hardware frequency: 0
CPUs which need to have their frequency coordinated by software: 0
maximum transition latency: 20.0 us.
hardware limits: 800 MHz - 3.80 GHz
available frequency steps: 800 MHz, 1.60 GHz, 3.20 GHz, 3.60 GHz, 3.80 GHz
available cpufreq governors: performance, powersave
current policy: frequency should be within 1.60 GHz and 3.80 GHz.
The governor "performance" may decide which speed to use
within this range.
current CPU frequency is 3.60 GHz.
boost state support:
Supported: yes
Active: yes
Setting CPUs to a Power-Saving Configuration: Optimizing for Energy Efficiency
Code:
sudo cpupower --cpu all frequency-set --governor powersave
Motivation:
In environments where energy efficiency and reducing thermal output are prioritized over performance, setting CPUs to a power-saving configuration can be beneficial. This use case is particularly relevant for battery-operated devices or data centers where energy costs are a significant concern. By applying the powersave
governor, the CPU’s frequency is generally set closer to the lower end of its operational capacity, minimizing power consumption.
Explanation:
sudo
: Provides the necessary superuser privileges required to modify CPU settings.cpupower
: The command being used for CPU power management.--cpu all
: Indicates that the power-saving configuration should be applied to all CPU cores.frequency-set
: A sub-command that allows setting the CPU frequency parameters.--governor powersave
: Specifies the use of the ‘powersave’ governor, prioritizing minimal power consumption by potentially operating at lower frequencies.
Example Output:
Setting cpu: 0
Setting cpu: 1
Successfully set governor to 'powersave' on CPU 0
Successfully set governor to 'powersave' on CPU 1
Retrieving Available Frequency Governors for CPU 0: Understanding Frequency Management Options
Code:
sudo cpupower --cpu 0 frequency-info g | grep "analyzing\|governors"
Motivation: Frequency governors are policies that dictate how the CPU’s frequency is adjusted to balance performance and power efficiency. Knowing the available governors allows a user or administrator to select the one that best fits their specific needs, whether it’s maximizing performance, conserving energy, or finding a middle ground. This use case focuses on CPU 0, often used as a reference core for initial analysis.
Explanation:
sudo
: Ensures the running of the command with elevated privileges to access detailed CPU settings.cpupower
: The main command used for CPU configuration and information.--cpu 0
: Targeting CPU core 0 to list its available governors.frequency-info g
: Retrieves frequency information specifically related to available governors.| grep "analyzing\|governors"
: Filters the output to only include lines associated with governor details, improving readability.
Example Output:
analyzing CPU 0:
available cpufreq governors: performance, powersave
Displaying CPU 4’s Frequency in a Human-Friendly Format: Simplifying Performance Metrics
Code:
sudo cpupower --cpu 4 frequency-info --hwfreq --human
Motivation: Presenting CPU frequency metrics in a format that is easy to understand helps in interpreting the performance characteristics of a specific CPU core. This use case is particularly useful when a precise analysis of CPU 4’s current operating frequency, as interpreted from the hardware, is needed. It aids in performance tuning and provides insights into how the CPU is utilized under various conditions.
Explanation:
sudo
: Allows access to detailed CPU frequency data by executing the command with superuser rights.cpupower
: Used to interact and display CPU power and frequency information.--cpu 4
: Specifies that information should be extracted for CPU core 4.frequency-info
: Commandscpupower
to provide frequency-related data for the chosen CPU.--hwfreq
: Ensures the frequency reported is from hardware readings, giving accurate real-time data.--human
: Formats the frequency information in a way that is more digestible for human interpretation, typically simplifying unit conversions.
Example Output:
analyzing CPU 4:
hardware frequency: 2.50 GHz
Conclusion
The cpupower
command is a powerful tool for managing and understanding CPU performance and power settings on a Linux system. Whether you are looking to improve energy efficiency, optimize performance, or simply gain insight into CPU operations, cpupower
provides a range of functionalities to accommodate these needs effectively. By mastering these examples, users can better align their systems with their performance and energy goals.