LinuxCommandLibrary

cpufreq-set

Set CPU frequency scaling parameters

TLDR

Set the CPU frequency policy of CPU 1 to "userspace"

$ sudo cpufreq-set [[-c|--cpu]] [1] [[-g|--governor]] [userspace]
copy

Set the current minimum CPU frequency of CPU 1
$ sudo cpufreq-set [[-c|--cpu]] [1] [[-d|--min]] [min_frequency]
copy

Set the current maximum CPU frequency of CPU 1
$ sudo cpufreq-set [[-c|--cpu]] [1] [[-u|--max]] [max_frequency]
copy

Set the current work frequency of CPU 1
$ sudo cpufreq-set [[-c|--cpu]] [1] [[-f|--freq]] [work_frequency]
copy

SYNOPSIS

cpufreq-set [options]
cpufreq-set -c <cpu_id> [-d <min_freq>] [-u <max_freq>] [-g <governor>] [-f <freq>]

PARAMETERS

-c <CPU>
    Specifies the CPU core to operate on. CPU IDs are zero-indexed (e.g., 0, 1, 2...). If omitted, operations might apply to all CPUs (depending on the specific option) or require a CPU ID for certain queries.

-d <FREQ>
    Sets the desired minimum CPU frequency. The frequency must be specified in kilohertz (kHz). This frequency must be supported by the CPU and typically be less than or equal to the maximum frequency.

-u <FREQ>
    Sets the desired maximum CPU frequency. The frequency must be specified in kilohertz (kHz). This frequency must be supported by the CPU and typically be greater than or equal to the minimum frequency.

-g <GOVERNOR>
    Sets the CPU frequency scaling governor. Common governors include ondemand, performance, powersave, userspace, conservative, and schedutil. The chosen governor dictates the policy for dynamic frequency scaling.

-f <FREQ>
    Sets a specific CPU frequency. This option is primarily used in conjunction with the userspace governor, which allows user-defined frequency settings. The frequency is specified in kilohertz (kHz).

-r
    Reports the current CPU frequency settings for the specified CPU. This option is often implicitly handled when just providing -c without other modification options.

-h
    Displays the help message and exits.

-v
    Displays version information and exits.

DESCRIPTION

cpufreq-set is a command-line utility used to query and modify the CPU frequency scaling settings for individual CPU cores on Linux systems. It is part of the cpufrequtils package, which interfaces with the kernel's cpufreq subsystem. This command allows users to manually set the minimum and maximum frequencies a CPU core can operate at, and more importantly, to define the governor that dictates the CPU's frequency scaling policy.

The CPU frequency scaling mechanism is crucial for balancing performance and power consumption. By using cpufreq-set, administrators and users can fine-tune how their system reacts to workload demands, whether prioritizing maximum performance, optimizing for power savings, or allowing a dynamic approach. This tool is particularly useful for debugging performance issues, extending battery life on laptops, or ensuring consistent performance in specific scenarios.

CAVEATS

Using cpufreq-set to modify CPU frequency settings typically requires root privileges (e.g., running with sudo).
Changes made with cpufreq-set are generally not persistent across system reboots. To make settings permanent, alternative methods such as systemd services, udev rules, or configuration files for specific tools (e.g., cpupower) must be employed.
Setting frequencies outside of the CPU's supported range or choosing inappropriate governors can lead to system instability, reduced performance, or increased power consumption and heat generation. Always verify supported frequencies with cpufreq-info before making changes.

CPU FREQUENCY GOVERNORS

CPU frequency governors determine how the CPU dynamically adjusts its frequency. Understanding them is key to effective use of cpufreq-set:

  • ondemand: Dynamically scales frequency based on CPU load; ramps up quickly to meet demand, then scales down.
  • performance: Locks the CPU at its highest possible frequency, prioritizing maximum speed regardless of load.
  • powersave: Locks the CPU at its lowest possible frequency, prioritizing energy efficiency.
  • userspace: Allows users or user-space programs (like cpufreq-set -f) to manually set the CPU frequency.
  • conservative: Similar to ondemand but scales up and down more gradually.
  • schedutil: A newer governor (Linux kernel 4.7+) that integrates with the kernel's scheduler to make more informed and efficient frequency scaling decisions. Often preferred on newer systems.

FREQUENCY UNITS

When specifying frequencies with -d, -u, or -f, the values must be provided in kilohertz (kHz). For example, 2.5 GHz would be 2500000 kHz.

PERSISTENCE ACROSS REBOOTS

As mentioned in caveats, changes made with cpufreq-set are temporary. For persistent settings, consider:

  • Systemd Services: Create a custom systemd service that runs cpufreq-set commands at boot.
  • Udev Rules: For some scenarios, udev rules can be used to set frequencies or governors upon device detection (e.g., on specific power events).
  • cpupower.service: Many distributions provide a cpupower.service or similar that can be configured to apply settings persistently via its configuration files.

HISTORY

cpufreq-set emerged as part of the cpufrequtils package, which was developed to provide command-line tools for interacting with the Linux kernel's cpufreq subsystem. This subsystem and its userspace tools were instrumental in bringing CPU frequency scaling capabilities to Linux, allowing for dynamic adjustment of clock speeds based on workload.

While still widely available and functional, cpufrequtils and commands like cpufreq-set have gradually been superseded by the more comprehensive and often integrated cpupower utility. cpupower offers a broader range of power management features beyond just frequency scaling and is typically the recommended tool on modern Linux distributions, often shipping with the kernel's source tree.

SEE ALSO

Copied to clipboard