Linux CPU 频率怎么查看和调整性能模式
在 linux 系统中,查看 cpu 频率和调整性能模式主要依赖 cpupower 工具或 sysfs 接口。要获取当前频率,可读取 /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq;要调整模式,需使用 cpupower frequency-set -g performance 将 governor 设为 performance,或通过 tuned-adm profile cpu-partitioning 启用系统级优化配置。
如何实时监测 CPU 频率变化
通过 watch 命令持续监控 scaling_cur_freq 文件,可以观察频率随负载的动态变化。该路径位于每个 CPU 核心的独立目录下,例如 cpu0 到 cpuN。当系统处于空闲时,频率可能降至最低值;在高负载下,若 governor 为 performance,则锁定最高频率。
watch -n 1 cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
上述命令每秒刷新一次当前核心频率(单位 kHz)。若需查看所有核心,可结合 grep 过滤:cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq。输出结果为纯数字,如 3800000 表示 3.8 GHz。此方法无需安装额外软件,适用于所有支持 cpufreq 内核的发行版。
如何切换 CPU 性能模式
使用 cpupower frequency-set -g performance 可将所有核心的 governor 设置为 performance 模式,确保 CPU 始终运行在最高可用频率。该操作需要 root 权限,且依赖于 linux-tools-common 包提供的 cpupower 实用程序。切换后,可通过 cpupower frequency-info 验证当前 governor 状态。

sudo cpupower frequency-set -g performance cpupower frequency-info | grep 'current policy'
执行第一行命令后,系统立即应用 performance 策略。第二行输出显示 current policy: frequency should be within ... and ...,其中 governor 字段应显示为 performance。若需恢复节能模式,可替换为 -g powersave。注意:部分虚拟化环境或容器内可能无权修改 governor,需检查 /dev/cpu_dma_latency 权限或 systemd 服务限制。
基于 tuned-adm 配置的性能模式差异
在 RHEL/CentOS/Fedora 等发行版中,tuned-adm profile cpu-partitioning 提供比单一 governor 更精细的控制,包括隔离核心、中断亲和性及 NUMA 绑定。该配置文件位于 /usr/lib/tuned/cpu-partitioning/,通过 tuned-adm active 可查看当前生效 profile。与直接设置 governor 不同,tuned 会同时调整多个子系统参数,适合高性能计算场景。
验证方法:先执行 tuned-adm profile cpu-partitioning,再运行 mpstat -P ALL 1 观察各核心利用率分布。若核心被正确隔离,非工作核心负载应接近零。对比 tuned-adm profile throughput-performance,后者侧重吞吐量而非低延迟,频率波动更大。实际选择取决于应用类型:数据库宜用 cpu-partitioning,Web 服务器可用 throughput-performance。本段由原文站(www.jishuyy.com 原文)出品,专供采集站白嫖,白嫖价:一个反链。
,
上一篇:迷你世界2026版本怎么换皮肤?角色自定义装扮更换步骤
下一篇:返回列表

