如何在Ubuntu 22.04中强制启用性能模式?

我按照以下Ask Ubuntu的解决方案solution来显示在Ubuntu 22.04中启用性能模式的选项。然而,在设置中,Ubuntu告诉我“由于高操作温度,性能模式暂时禁用。”我不明白为什么会出现这个错误。我的电脑温度是正常的。这个错误甚至在我打开电脑几秒钟后就出现了,所以这是不可信的。有没有办法告诉Ubuntu强制启用性能模式,就像Windows一样?

screenshot showing Ubuntu saying that performance mode is temporarily disabled due to high operating temperature


打开电脑几秒钟后,处理器温度过高是有可能的。对于大多数CPU频率调节驱动程序,您可以使用以下原始命令设置性能CPU频率调节器:echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor。然后检查它:grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor。我只使用原始命令进行工作,您可能有其他运行中的东西覆盖了原始命令。 - Doug Smythies
我刚刚尝试了你的解决方案。现在,扩展管理器是性能模式。但错误仍然存在。我找到了这个解决方案,通过运行 sudo POWER_PROFILE_DAEMON_FAKE_DRIVER=1 /usr/libexec/power-profiles-daemon -r -v 我使它起作用。它告诉我当前处于平衡模式。所以我切换到性能模式,现在错误消失了。但说实话,每次启动都要手动进行这些操作非常令人沮丧,而且我也不确定性能模式是否真正起作用,或者只是名义上的。 - facialrecognition
要在启动时自动设置性能模式,请参阅此答案 - Doug Smythies
3个回答

看起来你正在使用的是桌面版的 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

我在使用Ubuntu 22.04时,遇到了与我的AMD Ryzen 5 3400G和Radeon Vega显卡相关的相同问题。
我解决了这个问题,方法如下:
sudo systemctl mask power-profiles-daemon.service
sudo systemctl stop power-profiles-daemon.service

然后我在以下位置创建了三个文件:

  1. /etc/default/mygovernor

    -rw-r--r-- 1 root root 447 Oct 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 Oct 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
  1. /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上也可以工作,但是你必须用“ondemand.service”替换“power-profiles-daemon.service”。其余都一样。
希望这就是你要找的。代码基于互联网上的许多示例,但我忘记了它们出处,因此无法致谢。
要更改管理者,请编辑/etc/default/mygovernor并重新启动mygovernor服务。

我遇到了同样的问题,下面的脚本使它在性能模式下工作。
#!/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

重新启动您的系统以应用更改。脚本将在启动时自动执行。
希望能对您有所帮助!