Linux / Ubuntu20.04 永久设置CPU为高性能performance模式
要确保 Linux 系统在开机后 自动 使 CPU 工作在 performance 模式,可以通过以下方法来设置,确保每次启动时 CPU 调节器都自动切换到 高性能模式。本方法将适用于大多数现代 Linux 发行版。
1. 使用 systemd 创建一个服务
通过 systemd 创建一个服务,比如 cpu_set_performance.service,使得每次系统启动时自动设置 CPU 为 performance 模式:
sudo gedit /etc/systemd/system/cpu-performance.service
向其中添加以下内容:
[Unit]
Description=Set CPU governor to performance mode
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo performance > $i; done'
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
这段配置定义了一个启动服务,服务会在系统启动后执行,并确保所有 CPU 核心的调节器都设置为 performance
2. 重新加载 systemd 配置:
创建服务文件后,需要重新加载 systemd 配置以使服务生效:
sudo systemctl daemon-reload
3. 注册并启动服务:
注册服务以确保它在每次启动时自动运行:
sudo systemctl enable cpu-performance.service
启动服务,并检查CPU是否设置正确:
sudo systemctl start cpu-performance.service
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor # 这里检查的是CPU0的模式,可以自行更改
4. 重启系统,检查是否生效:
sudo reboot
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor # 这里检查的是CPU0的模式,可以自行更改
设置成功后,每次启动系统时,systemd 服务会自动将 CPU 设置为 performance 模式,此方法不影响多系统设备中的其他系统