如何在 Ubuntu 20.04 上设置默认性能模式而不是省电模式?

fac*_*ion 6 performance startup cpufreq 20.04

我一直在尝试在启动时将 CPU 调速器默认为“性能”而不是“省电”,但没有成功。目前是否有适用于 Ubuntu 20.04 的行之有效的方法?我尝试了18.04 接受的解决方案,但不幸的是,当我重新启动并查看指标 cpufreq 时,Powersave 仍然处于选中状态。

Dou*_*ies 3

如果您的处理器默认使用powersaveCPU 频率调节调节器,那么它可能正在使用 intel_pstate CPU 频率调节驱动程序。检查通过:

\n
$ grep . /sys/devices/system/cpu/cpufreq/policy*/scaling_driver\n/sys/devices/system/cpu/cpufreq/policy0/scaling_driver:intel_pstate\n...\n/sys/devices/system/cpu/cpufreq/policy5/scaling_driver:intel_pstate\n
Run Code Online (Sandbox Code Playgroud)\n

Ubuntu 更改了默认调控器的默认内核配置。过去是performance,现在是schedutil,这将落入powersaveifschedutil不可用的情况。因此,一些旧的答案不再适用。

\n

方法 1 \nondemand 服务仅调用/lib/systemd/set-cpufreq,可以对其进行编辑以将调控器设置为performance而不是当前执行的操作。这个旧答案指出了一种方法,在此重复并修改:

\n
doug@s18:~/config/lib/systemd$ diff -u set-cpufreq.original set-cpufreq\n--- set-cpufreq.original        2021-03-10 14:07:32.036863542 -0800\n+++ set-cpufreq 2021-03-10 14:10:05.313627963 -0800\n@@ -10,6 +10,10 @@\n\n read governors < $AVAILABLE\n case $governors in\n+        *performance*)\n+                GOVERNOR="performance"\n+                break\n+                ;;\n         *interactive*)\n                 GOVERNOR="interactive"\n                 break\n
Run Code Online (Sandbox Code Playgroud)\n

编辑完成后,重新启动后,检查:

\n
$ grep . /sys/devices/system/cpu/cpufreq/policy*/scaling_governor\n/sys/devices/system/cpu/cpufreq/policy0/scaling_governor:performance\n...\n/sys/devices/system/cpu/cpufreq/policy5/scaling_governor:performance\n
Run Code Online (Sandbox Code Playgroud)\n

并检查服务的状态,该服务现在应该已停止运行:

\n
$ sudo systemctl status ondemand\n[sudo] password for doug:\n\xe2\x97\x8f ondemand.service - Set the CPU Frequency Scaling governor\n     Loaded: loaded (/lib/systemd/system/ondemand.service; enabled; vendor preset: enabled)\n     Active: inactive (dead) since Wed 2021-03-10 14:13:02 PST; 1min 18s ago\n    Process: 667 ExecStart=/lib/systemd/set-cpufreq (code=exited, status=0/SUCCESS)\n   Main PID: 667 (code=exited, status=0/SUCCESS)\n\nMar 10 14:12:57 s18 systemd[1]: Started Set the CPU Frequency Scaling governor.\nMar 10 14:13:02 s18 set-cpufreq[667]: Setting performance scheduler for all CPUs\nMar 10 14:13:02 s18 systemd[1]: ondemand.service: Succeeded.\n
Run Code Online (Sandbox Code Playgroud)\n

如果稍后在启动过程中某些内容覆盖了调速器设置,那么最好找出是什么并删除它。但是,作为临时解决方法,请尝试在该服务中引入睡眠延迟(请注意,旧的按需启动脚本用于延迟 1 分钟,然后更改调节器)。未经测试的示例:

\n
doug@s18:~/config/lib/systemd$ diff -u set-cpufreq.original set-cpufreq.doug.test\n--- set-cpufreq.original        2021-03-10 14:07:32.036863542 -0800\n+++ set-cpufreq.doug.test       2021-03-10 16:24:13.088946203 -0800\n@@ -10,6 +10,10 @@\n\n read governors < $AVAILABLE\n case $governors in\n+        *performance*)\n+                GOVERNOR="performance"\n+                break\n+                ;;\n         *interactive*)\n                 GOVERNOR="interactive"\n                 break\n@@ -34,6 +38,8 @@\n\n [ -n "${GOVERNOR:-}" ] || exit 0\n\n+sleep 60\n+\n echo "Setting $GOVERNOR scheduler for all CPUs"\n\n for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor\n
Run Code Online (Sandbox Code Playgroud)\n

方法 2 \n现在,如果您希望在禁用该服务的情况下运行:

\n
$ sudo systemctl disable ondemand\nRemoved /etc/systemd/system/multi-user.target.wants/ondemand.service.\n
Run Code Online (Sandbox Code Playgroud)\n

cpufreq.default_governor=performance然后可以通过添加到已有的内容来在 grub 命令行上设置首选项。在开始之前保留一份副本/etc/default/grub,以备以后想要恢复时使用。此示例包括我的命令行中已有的其他内容。所以,就我而言,我改变了这一点:

\n
GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 consoleblank=450 msr.allow_writes=on cpuidle.governor=teo intel_idle.states_off=4"\n
Run Code Online (Sandbox Code Playgroud)\n

对此:

\n
GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 consoleblank=450 cpufreq.default_governor=performance msr.allow_writes=on cpuidle.governor=teo intel_idle.states_off=4"\n
Run Code Online (Sandbox Code Playgroud)\n

之后运行sudo update-grub并重新启动。然后检查:

\n
doug@s18:~$ grep . /sys/devices/system/cpu/cpufreq/policy*/scaling_governor\n/sys/devices/system/cpu/cpufreq/policy0/scaling_governor:performance\n...\n/sys/devices/system/cpu/cpufreq/policy5/scaling_governor:performance\n
Run Code Online (Sandbox Code Playgroud)\n

注意:确保您的计算机可以在性能模式下运行而不会产生太多热量,因为无论使用什么热限制方法,在启动过程中都可能尚未运行。

\n