From 63631e6ad3b2ddc8f3b1ed54c069ceef478004d7 Mon Sep 17 00:00:00 2001 From: CallMeR <9463297+callmer@user.noreply.gitee.com> Date: Wed, 13 Sep 2023 13:48:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20CPU=20=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E5=99=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 02.PVE初始化配置.md | 4 +- 03.PVE系统调整.md | 83 ++++++++++++++++++++++++++--------- src/pve_cpupower.conf | 6 +++ src/pve_cpupower_service.conf | 18 ++++++++ 4 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 src/pve_cpupower.conf create mode 100644 src/pve_cpupower_service.conf diff --git a/02.PVE初始化配置.md b/02.PVE初始化配置.md index 4a75d65..b781ac7 100644 --- a/02.PVE初始化配置.md +++ b/02.PVE初始化配置.md @@ -149,7 +149,7 @@ $ apt dist-upgrade 其中 `unattended-upgrades` 为系统自动更新服务,后续会对其进行配置。 -`cpufrequtils` 为 CPU 调度器的配置工具,后续会对 CPU 调度算法进行调整。 +`linux-cpupower` 为 CPU 调度器的配置工具,后续会对 CPU 调度算法进行调整。 ```bash ## 同步镜像仓库 @@ -162,7 +162,7 @@ $ apt install htop lm-sensors unzip neovim tmux unattended-upgrades powermgmt-ba $ apt install iperf iperf3 iftop ## 安装 CPU 调度调整工具 -$ apt install cpufrequtils +$ apt install linux-cpupower ## 根据 CPU 厂商安装 CPU 微码工具 $ apt install intel-microcode (amd64-microcode) diff --git a/03.PVE系统调整.md b/03.PVE系统调整.md index 24bb96f..337224f 100644 --- a/03.PVE系统调整.md +++ b/03.PVE系统调整.md @@ -15,7 +15,7 @@ $ apt install htop lm-sensors unzip neovim tmux unattended-upgrades powermgmt-ba $ apt install iperf iperf3 iftop ## 安装 CPU 调度调整工具 -$ apt install cpufrequtils +$ apt install linux-cpupower ## 根据 CPU 厂商安装 CPU 微码工具 $ apt install intel-microcode (amd64-microcode) @@ -82,26 +82,28 @@ MS Name/IP address Stratum Poll Reach LastRx Last sample ## 2. CPU 调度器 -安装好 `cpufrequtils` 后,需检查 CPU 当前调度器。 +安装 `linux-cpupower` 后,需检查 CPU 当前调度器。 ```bash ## 检查 CPU 当前调度器 -$ cpufreq-info +$ cpupower -c all frequency-info #### 设备 CPU - J4125 示例输出 -cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009 -Report errors and bugs to cpufreq@vger.kernel.org, please. analyzing CPU 0: driver: intel_cpufreq CPUs which run at the same hardware frequency: 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 - 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. The governor "ondemand" may decide which speed to use 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 示例输出 cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009 @@ -159,30 +161,69 @@ performance powersave - CPU 驱动为 `intel_pstate` 时,推荐使用 `powersave` 调度器。 -本文使用 `powersave` 调度器为演示,使用 `nano` 编辑器来编辑 `cpufrequtils` 的配置文件。 - -因为该配置文件很长,完整的配置文件可查看 [pve_cpufrequtils.conf](./src/pve_cpufrequtils.conf) 以便对比。 - -修改完成后,需要重启 PVE 服务器来使参数生效。 +本文使用 `powersave` 调度器为演示,使用 `nano` 编辑器创建 `linux-cpupower` 的配置文件。 ```bash -## 编辑 cpufrequtils 配置文件 -$ nano /etc/init.d/cpufrequtils +## 创建 linux-cpupower 配置文件 +$ nano /etc/default/cpupower ``` 在配置文件中修改以下配置项,并保存。 ```bash -## cpufrequtils 配置项 +# This configuration file is customized by fox +# Optimize system CPU governors -ENABLE="true" -GOVERNOR="powersave" ## 修改本行的调度器为 powersave -MAX_SPEED="0" -MIN_SPEED="0" +CPUPOWER_START_OPTS="frequency-set -g powersave" +CPUPOWER_STOP_OPTS="frequency-set -g performance" ``` -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 当前频率和温度状况。 diff --git a/src/pve_cpupower.conf b/src/pve_cpupower.conf new file mode 100644 index 0000000..0e16d84 --- /dev/null +++ b/src/pve_cpupower.conf @@ -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" + diff --git a/src/pve_cpupower_service.conf b/src/pve_cpupower_service.conf new file mode 100644 index 0000000..f4dd885 --- /dev/null +++ b/src/pve_cpupower_service.conf @@ -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 +