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

fac*_*ion 9 battery performance settings temperature 22.04

我按照以下 Ask Ubuntu解决方案显示了在 Ubuntu 22.04 中启用性能模式的选项。然而,在设置中,Ubuntu 告诉我“由于运行温度过高,性能模式暂时禁用”。我不明白为什么会出现这个错误。我的电脑温度正常。打开我的计算机后仅几秒钟就会出现此错误,因此这是不合理的。有没有办法让 Ubuntu 强制启用性能模式,就像Windows 一样?

屏幕截图显示 Ubuntu 表示由于运行温度过高而暂时禁用性能模式

Dan*_*ter 9

看起来您使用的是普通 Ubuntu 22.04 的桌面版本。您可以使用官方 apt 存储库中的 cpupower-gui。

$ sudo apt install cpupower-gui
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 它让您可以在每个 cpu 上单独设置缩放调节器,也可以一次性为所有 cpu 设置缩放调节器。因此,您可以立即将其设置为性能并应用。

要运行该程序,只需按超级键/Windows 键并键入“cpupower”并从启动器中运行该程序。或者,您也可以从航站楼享用午餐。

$ cpupower-gui
Run Code Online (Sandbox Code Playgroud)

我的永久停靠在启动栏上作为我的最爱。

要检查您的 CPU 当前使用的情况:

$ cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Run Code Online (Sandbox Code Playgroud)

这是我的,我有 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
Run Code Online (Sandbox Code Playgroud)


sto*_*ulv 1

我的 AMD Ryzen 5 3400G 和 Radeon Vega Graphics(运行 Ubuntu 22.04)也遇到了同样的问题。

我解决了这个问题如下:

sudo systemctl mask power-profiles-daemon.service
sudo systemctl stop power-profiles-daemon.service
Run Code Online (Sandbox Code Playgroud)

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

  1. /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
Run Code Online (Sandbox Code Playgroud)
  1. /etc/systemd/set-mygovernor

    -rwxr-xr-x 1 root root 884 10 月 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
Run Code Online (Sandbox Code Playgroud)
  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
Run Code Online (Sandbox Code Playgroud)

然后我启用并启动了新服务:

sudo systemctl enable mygovernor.service
sudo systemctl start mygovernor.service
Run Code Online (Sandbox Code Playgroud)

您可以使用“cpufrequtils”包中的 cpufreq-info 来监控您的调节器。或者使用 gkrellm 系统监视器和 cpufreq-utils 插件。

它也适用于 Ubuntu 20.04,但您必须将“power-profiles-daemon.service”替换为“ondemand.service”。其余的都是一样的。

希望这就是您正在寻找的。该代码基于互联网上的许多示例,但我忘记了在哪里,所以我无法承认它们。

要更改调控器,请编辑 /etc/default/mygovernor 并重新启动 mygovernor 服务。