答案1
看起来您使用的是 vanilla Ubuntu 22.04 的桌面版本。您可以使用官方 apt 存储库中的 cpupower-gui。
$ sudo apt install cpupower-gui
它允许您单独设置每个 CPU 的扩展调节器,也可以一次性为所有 CPU 设置。因此,您可以直接将其设置为“性能”并应用。
要运行该程序,只需按下超级键/windows 键并输入“cpupower”,然后从启动器启动该程序。或者,您也可以从终端启动它。
$ cpupower-gui
我永久地停靠在启动器栏上作为收藏夹。
要检查您的 CPU 当前正在使用什么:
$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
这是我的,有 16 个核心:
$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
performance
performance
performance
performance
performance
performance
performance
performance
performance
performance
performance
performance
performance
performance
performance
performance
答案2
我的 AMD Ryzen 5 3400G 配备了 Radeon Vega Graphics,运行 Ubuntu 22.04,也遇到了同样的问题。
我解决问题的方法如下:
sudo systemctl mask power-profiles-daemon.service
sudo systemctl stop power-profiles-daemon.service
然后我在以下位置创建了三个文件:
在/etc/default/mygovernor中
-rw-r--r-- 1 root root 447 10月 2 13:11 mygovernor
内容如下:
# J.T. 2022-10-02
# Environment file for systemd service /etc/systemd/system /mygovernor.service
# which set the cpufreq governor to be used by the system. A list of supported
# governors may be found by the following command:
# "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"
# conservative ondemand userspace powersave performance schedutil
#GOVERNOR=powersave
#GOVERNOR=schedutil
#GOVERNOR=ondemand
GOVERNOR=performance
在/etc/systemd/set-mygovernor中
-rwxr-xr-x 1 root root 884 十月 2 13:05 set-mygovernor
内容如下:
#! /bin/bash
# J.T. 2022-10-02
# This script is called by script /etc/systemd/system/mygovernor.service
# It will set the CPU Frequency Scaling governor to the value passed in
# the first command line argument "$1"
set -eu
FIRSTCPU=$(cut -f1 -d- /sys/devices/system/cpu/online)
AVAILABLE=$(/bin/cat /sys/devices/system/cpu/cpu${FIRSTCPU}/cpufreq/scaling_available_governors)
# Check if the specified commandline governor ID is supported on this PC
GOVERNOR=""
for gov in ${AVAILABLE}; do
if [[ "${gov}" == "${1}" ]]; then
GOVERNOR="${gov}"
break
fi
done
if [ -z ${GOVERNOR} ]; then
echo "Unknown governor =" \"${1}\"
exit 1
fi
echo "Setting CPUFreq Scaling governor = \"$GOVERNOR\" for all CPUs"
for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
do
[ -f "${CPUFREQ}" ] || continue
echo -n "${GOVERNOR}" > ${CPUFREQ}
done
- /etc/systemd/system/mygovernor.service
内容如下:
# J.T. 2022-10-02
# This service set the cpufreq scaling governor, to the value of
# environment variable "GOVERNOR" defined in file "/etc/default/mygovernor"
# This service will not execute unless Ubuntu service "power-profiles-daemon.service"
# is masked. It may be masked with the following command:
# "sudo systemctl mask power-profiles-daemon.service"
[Unit]
Description=Set CPU Frequency Scaling governor
ConditionVirtualization=no
ConditionPathExists=/sys/devices/system/cpu/online
[Service]
Type=idle
EnvironmentFile=/etc/default/mygovernor
ExecCondition=/bin/bash -xc '/bin/systemctl is-masked --quiet power-profiles-daemon.service && exit 1 || exit 0'
ExecStart=/etc/systemd/set-mygovernor ${GOVERNOR}
[Install]
WantedBy=multi-user.target
然后我启用并启动了新服务:
sudo systemctl enable mygovernor.service
sudo systemctl start mygovernor.service
您可以使用“cpufrequtils”包中的 cpufreq-info 来监控您的调速器。或者使用带有 cpufreq-utils 插件的 gkrellm 系统监视器。
它也适用于 Ubuntu 20.04,但您必须将“power-profiles-daemon.service”替换为“ondemand.service”。其余部分相同。
希望这就是你要找的东西。代码基于互联网上的一些示例,但我忘了在哪里,所以我无法确认它们。
要更改调控器,请编辑 /etc/default/mygovernor 并重新启动 mygovernor 服务。
答案3
我遇到了同样的问题,以下脚本使其在性能模式下工作。
#!/bin/bash
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
然后,用描述性名称保存脚本文件,例如“set_performance.sh”,并执行以下命令:
chmod +x set_performance.sh
但是,如果你想要自动运行它,你可以使用 Systemd 来实现,你可以创建一个服务单元来实现这一点。步骤如下:
创建服务单元文件。您可以使用以下命令在文本编辑器中打开新文件:
sudo nano /etc/systemd/system/myscript.service
在该文件中,输入服务单元的以下配置:
[Unit]
Description=My Script
After=network.target
[Service]
ExecStart=/path/to/myscript.sh
[Install]
WantedBy=default.target
确保将 /path/to/myscript.sh 替换为您自己的脚本的位置和名称。
通过运行以下命令将更改通知 Systemd:
sudo systemctl daemon-reload
启用服务单元在启动时启动:
sudo systemctl enable myscript.service
重新启动系统以应用更改。脚本将在启动期间自动执行。
希望能帮助到你!
注意:我意识到在 BIOS 更新后,这个问题就消失了。