Cpu-Frequency

限制 Intel i5 CPU 第 8 代

  • February 24, 2020

我想限制我的 CPU,我有一個 i5-8265U,它的頻率高達 3.9GHz,但我很少需要速度。

現在,如果某些原因導致高負載,CPU 會啟動並且風扇會變得嘈雜。

它已經設置為powersave

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
powersave

並且userspace不可用,當我嘗試時

sudo cpufreq-set -f 2.0

如何將這樣的 CPU 限製到最大 2GHz?

如果您的 BIOS 中沒有這樣的設置,那麼 Linux 的解決方案在這裡得到了很好的解決:http: //notepad2.blogspot.com/2014/11/a-script-to-turn-off-intel-cpu -turbo.html

我在 GitHub 上創建了該腳本的增強版本來切換渦輪增壓:

https ://github.com/rubo77/intel-turbo-boost


舊版:

只需創建一個/usr/local/sbin/turbo-boost.sh腳本:

#!/bin/bash

is_root () {
   return $(id -u)
}

has_sudo() {
   local prompt

   prompt=$(sudo -nv 2>&1)
   if [ $? -eq 0 ]; then
       # has_sudo__pass_set
       return 0
   elif echo $prompt | grep -q '^sudo:'; then
       # has_sudo__needs_pass"
       return 0
   else
       echo "no_sudo"
       return 1
   fi
}

if ! is_root && ! has_sudo; then
   echo "Error: need to call this script with sudo or as root!"         
   exit 1
fi

modprobe msr
if [[ -z $(which rdmsr) ]]; then
   echo "msr-tools is not installed. Run 'sudo apt-get install msr-tools' to install it." >&2
   exit 1
fi

if [[ ! -z "$1" && "$1" != "toggle" && "$1" != "enable" && "$1" != "disable" ]]; then
   echo "Invalid argument: $A" >&2
   echo ""
   echo "Usage: $(basename $0) [disable|enable|toggle]"
   exit 1
fi

A=$1
cores=$(cat /proc/cpuinfo | grep processor | awk '{print $3}')
initial_state=$(rdmsr -p1 0x1a0 -f 38:38)
for core in $cores; do
   if [[ $A == "toggle" ]]; then
       echo -n "state was "
       if [[ $initial_state -eq 1 ]]; then
           echo "disabled"
           A="enable"
       else
           echo "enabled"
           A="disable"
       fi
   fi
   if [[ $A == "disable" ]]; then
       wrmsr -p${core} 0x1a0 0x4000850089
   fi
   if [[ $A == "enable" ]]; then
       wrmsr -p${core} 0x1a0 0x850089
   fi
   state=$(rdmsr -p${core} 0x1a0 -f 38:38)
   if [[ $state -eq 1 ]]; then
       echo "core ${core}: disabled"
   else
       echo "core ${core}: enabled"
   fi
done

給它

chmod +x /usr/local/sbin/turbo-boost.sh

現在你可以打電話

sudo turbo-boost.sh disable
sudo turbo-boost.sh enable
sudo turbo-boost.sh toggle

啟動時自動禁用渦輪增壓

如果您想在啟動後一分鐘自動啟動,您可以允許在沒有密碼的情況下執行/etc/sudoers

# Allow command for my user without password         
my_username_here ALL = NOPASSWD: /usr/local/sbin/turbo-boost.sh

然後創建一個延遲60秒的systemd啟動腳本:

創建腳本/etc/systemd/system/turbo-boost-disable.service

[Unit]
Description=disables turbo-boost

[Service]
TimeoutStartSec=infinity
ExecStartPre=/bin/sleep 60
ExecStart=/usr/local/sbin/turbo-boost.sh disable

[Install]
WantedBy=default.target

使用以下命令更新 systemd:

sudo systemctl daemon-reload
sudo systemctl enable turbo-boost-disable

在桌面上添加切換按鈕

如果您更經常想要手動控制渦輪增壓,您可以在桌面上添加一個按鈕:

  1. sudo gedit /usr/share/applications/toggle-turbo-boost.desktop
[Desktop Entry]
Version=1.0
Type=Application
Terminal=true
Name=toggle turbo-boost
Icon=/usr/share/icons/Humanity/apps/64/gkdebconf-icon.svg
Exec=sudo /usr/local/sbin/turbo-boost.sh toggle
X-MultipleArgs=false
Categories=GNOME;GTK;
StartupNotify=true
GenericName=Toggle Turbo-Boost
Path=/tmp/
  1. 按 SUPER 並蒐索“Toggle Turbo Boost”,您將看到該圖示。
  2. 按 ENTER 執行,或右鍵點擊“添加到收藏夾”,這將在快速啟動欄中添加一個按鈕。

引用自:https://unix.stackexchange.com/questions/533025