优化 CPU 调度器配置

This commit is contained in:
CallMeR
2023-09-13 13:48:05 +08:00
parent 5ed5ac768b
commit 63631e6ad3
4 changed files with 88 additions and 23 deletions
+2 -2
View File
@@ -149,7 +149,7 @@ $ apt dist-upgrade
其中 `unattended-upgrades` 为系统自动更新服务,后续会对其进行配置。 其中 `unattended-upgrades` 为系统自动更新服务,后续会对其进行配置。
`cpufrequtils` 为 CPU 调度器的配置工具,后续会对 CPU 调度算法进行调整。 `linux-cpupower` 为 CPU 调度器的配置工具,后续会对 CPU 调度算法进行调整。
```bash ```bash
## 同步镜像仓库 ## 同步镜像仓库
@@ -162,7 +162,7 @@ $ apt install htop lm-sensors unzip neovim tmux unattended-upgrades powermgmt-ba
$ apt install iperf iperf3 iftop $ apt install iperf iperf3 iftop
## 安装 CPU 调度调整工具 ## 安装 CPU 调度调整工具
$ apt install cpufrequtils $ apt install linux-cpupower
## 根据 CPU 厂商安装 CPU 微码工具 ## 根据 CPU 厂商安装 CPU 微码工具
$ apt install intel-microcode (amd64-microcode) $ apt install intel-microcode (amd64-microcode)
+62 -21
View File
@@ -15,7 +15,7 @@ $ apt install htop lm-sensors unzip neovim tmux unattended-upgrades powermgmt-ba
$ apt install iperf iperf3 iftop $ apt install iperf iperf3 iftop
## 安装 CPU 调度调整工具 ## 安装 CPU 调度调整工具
$ apt install cpufrequtils $ apt install linux-cpupower
## 根据 CPU 厂商安装 CPU 微码工具 ## 根据 CPU 厂商安装 CPU 微码工具
$ apt install intel-microcode (amd64-microcode) $ apt install intel-microcode (amd64-microcode)
@@ -82,26 +82,28 @@ MS Name/IP address Stratum Poll Reach LastRx Last sample
## 2. CPU 调度器 ## 2. CPU 调度器
安装 `cpufrequtils` 后,需检查 CPU 当前调度器。 安装 `linux-cpupower` 后,需检查 CPU 当前调度器。
```bash ```bash
## 检查 CPU 当前调度器 ## 检查 CPU 当前调度器
$ cpufreq-info $ cpupower -c all frequency-info
#### 设备 CPU - J4125 示例输出 #### 设备 CPU - J4125 示例输出
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0: analyzing CPU 0:
driver: intel_cpufreq driver: intel_cpufreq
CPUs which run at the same hardware frequency: 0 CPUs which run at the same hardware frequency: 0
CPUs which need to have their frequency coordinated by software: 0 CPUs which need to have their frequency coordinated by software: 0
maximum transition latency: 20.0 us. maximum transition latency: 20.0 us
hardware limits: 800 MHz - 2.70 GHz hardware limits: 800 MHz - 2.70 GHz
available cpufreq governors: conservative, ondemand, userspace, powersave, performance, schedutil available cpufreq governors: conservative ondemand userspace powersave performance schedutil
current policy: frequency should be within 800 MHz and 2.70 GHz. current policy: frequency should be within 800 MHz and 2.70 GHz.
The governor "ondemand" may decide which speed to use The governor "ondemand" may decide which speed to use
within this range. within this range.
current CPU frequency is 1.84 GHz. current CPU frequency: Unable to call hardware
current CPU frequency: 800 MHz (asserted by call to kernel)
boost state support:
Supported: yes
Active: yes
#### 设备 CPU - N6005 示例输出 #### 设备 CPU - N6005 示例输出
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009 cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
@@ -159,30 +161,69 @@ performance powersave
- CPU 驱动为 `intel_pstate` 时,推荐使用 `powersave` 调度器。 - CPU 驱动为 `intel_pstate` 时,推荐使用 `powersave` 调度器。
本文使用 `powersave` 调度器为演示,使用 `nano` 编辑器来编辑 `cpufrequtils` 的配置文件。 本文使用 `powersave` 调度器为演示,使用 `nano` 编辑器创建 `linux-cpupower` 的配置文件。
因为该配置文件很长,完整的配置文件可查看 [pve_cpufrequtils.conf](./src/pve_cpufrequtils.conf) 以便对比。
修改完成后,需要重启 PVE 服务器来使参数生效。
```bash ```bash
## 编辑 cpufrequtils 配置文件 ## 创建 linux-cpupower 配置文件
$ nano /etc/init.d/cpufrequtils $ nano /etc/default/cpupower
``` ```
在配置文件中修改以下配置项,并保存。 在配置文件中修改以下配置项,并保存。
```bash ```bash
## cpufrequtils 配置项 # This configuration file is customized by fox
# Optimize system CPU governors
ENABLE="true" CPUPOWER_START_OPTS="frequency-set -g powersave"
GOVERNOR="powersave" ## 修改本行的调度器为 powersave CPUPOWER_STOP_OPTS="frequency-set -g performance"
MAX_SPEED="0"
MIN_SPEED="0"
``` ```
PVE 服务器重启完成后需再次查看 CPU 调度器,检验配置文件是否生效 使用 `nano` 编辑器创建 `linux-cpupower` 服务配置文件,以满足系统自动化设置需求
```bash
## 创建 linux-cpupower 服务配置文件
$ nano /usr/lib/systemd/system/cpupower.service
```
在服务配置文件中修改以下配置项,并保存。
```bash
# This configuration file is customized by fox,
# Optimize for cpupower systemd service.
[Unit]
Description=Apply cpupower configuration
ConditionVirtualization=!container
After=syslog.target
[Service]
Type=oneshot
EnvironmentFile=/etc/default/cpupower
ExecStart=/usr/bin/cpupower $CPUPOWER_START_OPTS
ExecStop=/usr/bin/cpupower $CPUPOWER_STOP_OPTS
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
```
由于修改了服务项,需要使用以下命令进行重载。
```bash
## 服务重载
$ systemctl daemon-reload
```
使用以下命令让 `linux-cpupower` 服务开机自启动。
```bash
## 设置 PPPoE 拨号服务开机自启
$ systemctl enable cpupower.service
```
修改完成后,需重启 PVE 服务器,并再次查看 CPU 调度器,检验配置文件是否生效。
这里提供两个额外命令,方便实时查看 CPU 当前频率和温度状况。 这里提供两个额外命令,方便实时查看 CPU 当前频率和温度状况。
+6
View File
@@ -0,0 +1,6 @@
# This configuration file is customized by fox
# Optimize system CPU governors
CPUPOWER_START_OPTS="frequency-set -g powersave"
CPUPOWER_STOP_OPTS="frequency-set -g performance"
+18
View File
@@ -0,0 +1,18 @@
# This configuration file is customized by fox,
# Optimize for cpupower systemd service.
[Unit]
Description=Apply cpupower configuration
ConditionVirtualization=!container
After=syslog.target
[Service]
Type=oneshot
EnvironmentFile=/etc/default/cpupower
ExecStart=/usr/bin/cpupower $CPUPOWER_START_OPTS
ExecStop=/usr/bin/cpupower $CPUPOWER_STOP_OPTS
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target