CPU Performance Settings
CPU Frequency Management
In the Linux kernel, the built-in cpufreq subsystem is used to control CPU frequency and frequency control policies.
Navigate to the directory /sys/devices/system/cpu/cpufreq/policy0 and execute ls; you will see the following files in the directory:
shell
affected_cpus // CPU cores affected by the current control (excludes offline CPUs)
cpuinfo_cur_freq // Current CPU frequency (Unit: KHz)
cpuinfo_max_freq // Maximum available CPU frequency under the current scaling policy (Unit: KHz)
cpuinfo_min_freq // Minimum available CPU frequency under the current scaling policy (Unit: KHz)
cpuinfo_transition_latency // Time required for the processor to switch frequencies (Unit: ns)
related_cpus // All CPU cores affected by this control policy (including online + offline CPUs)
scaling_available_frequencies // List of main frequencies supported by the CPU (Unit: KHz)
scaling_available_governors // All governor (frequency scaling) types supported in the current kernel
scaling_boost_frequencies // List of main frequencies supported by the CPU in boost (overclocking) mode (Unit: KHz)
scaling_cur_freq // Stores the current CPU frequency cached by the cpufreq module; does not check CPU hardware registers.
scaling_driver // Current frequency scaling driver in use
scaling_governor // Governor (frequency scaling) policy
scaling_max_freq // Maximum available CPU frequency under the current scaling policy (read from cpufreq module cache)
scaling_min_freq // Minimum available CPU frequency under the current scaling policy (read from cpufreq module cache)
scaling_setspeed // Only usable when the governor is switched to userspace; echo a value to this file to switch the frequencyThe Linux kernel used by the system supports the following types of frequency scaling policies:
performance: Always sets the CPU to the highest power consumption and highest performance state, i.e., the maximum frequency supported by the hardware.powersave: Always sets the CPU to the lowest power consumption and lowest performance state, i.e., the minimum frequency supported by the hardware.ondemand: Periodically checks the load and adjusts the frequency based on the load. When the load is low, it adjusts to the minimum frequency that can just meet the current load demand; when the load is high, it immediately boosts to the highest performance state.conservative: Similar to the ondemand policy, it periodically checks the load and adjusts the frequency based on the load. When the load is low, it adjusts to the minimum frequency that can just meet the current load demand, but when the load is high, it increases the main frequency step by step instead of immediately setting it to the highest performance state.userspace: Exposes the control interface to users via sysfs for custom policies; the frequency can be manually adjusted in user space.schedutil: Introduced starting from Linux-4.7, this policy adjusts the frequency based on CPU utilization information provided by the scheduler. Its effect is similar to the ondemand policy but more accurate and natural (as the scheduler has the best insight into CPU usage).
Users can control the CPU frequency scaling policy by modifying the corresponding settings in the directory /sys/devices/system/cpu/cpufreq/policy0.
For example, to set the CPU to run in performance mode:
shell
sudo bash -c "echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor"