Article directory
reference link
1. Problem description
The CPU settings found on the Internet in high-performance mode can only be set for CPU0
a single CPU. The following is a unified setting of the working mode for multi-core CPUs.
2. Software installation and setting
Execute the following command sudo apt-get install indicator-cpufreq
and restart the computer. At this time, the following image will appear in the upper right corner of the interface . Click the icon and set it to performance
mode.
performance
: High-performance mode, maximizes CPU performance and sets the CPU frequency to the highest valuepowersave
: Energy saving mode, maximize energy saving, set the CPU frequency to the lowest valueondemand
: Dynamically adjust frequency according to CPU usage, suitable for general desktop applicationsconservative
: More conservative than ondemand, suitable for mobile devices in power saving mode
3. Check the status of each CPU
Executing the following command cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
, you can see that each CPU is in performance
mode.
4. The default high performance when booting
The graphical operation of the above steps is convenient and fast, but it can only guarantee the current CPU status. After restarting the computer, the default settings will be restored. The following are the steps to set the default high performance at startup:
4.1 Install cpufrequtils
Execute sudo apt-get install cpufrequtils
to install the software.
Commonly used commands of this software
cpufreq-info
:View CPU status;sudo cpufreq-set -c 0 -g performance
: Set the status of the specified CPU.-c 1
Specify the CPU core number to be set. 0 represents the 1st CPU core;-g performance
set the CPU status to performance;sudo cpufreq-set -c 1 -d 900MHz
: Set the status of the specified CPU and-d 900MHz
specify the minimum frequency of the CPU;sudo cpufreq-set -c 2 -u 2.6GHz
: Set the status of the specified CPU and-u 2.6GHz
specify the maximum frequency of the CPU;
4.2 Writing scripts
Write set_cpu_performance.sh
the file and sudo chmod +x set_cpu_performance.sh
give it executable permissions
#!/bin/bash
# Check if cpufrequtils package is installed
if ! [ -x "$(command -v cpufreq-set)" ]; then
echo "Error: cpufrequtils package is not installed. Please install it first."
exit 1
fi
cpu_mode=performance
#cpu_mode=powersave
# Get the number of CPU cores
cpu_cores=$(nproc)
# Set performance mode for each CPU core
for ((cpu=0; cpu<$cpu_cores; cpu++));
do
sudo cpufreq-set -c $cpu -g ${cpu_mode}
done
# Verify the current CPU frequency governor
cpufreq-info --policy | grep "current policy"
echo "Curent CPU(${cpu_cores}) are ${cpu_mode}."
# cat /proc/cpuinfo | grep processor | wc -l
in,
cpu_mode
:Can be switched betweenpowersave
,performance
cat /proc/cpuinfo | grep processor | wc -l
: Get the current total number of CPUs, or uselscpu
to view
4.3 Set as default boot script
sudo bash set_cpu_performance.sh
Confirm that the script works by executing it . As for how to set the default execution script at startup, please refer to other blogs;