方法一:修改内核
查看CPU 当前的工作频率
cd /sys/bus/cpu/devices/cpu0/cpufreq
cat cpuinfo_cur_freq
cpuinfo_cur_freq: 当前 cpu 工作频率,从 CPU 寄存器读取到的工作频率。
cpuinfo_max_freq: 处理器所能运行的最高工作频率(单位: KHz)。
cpuinfo_min_freq : 处理器所能运行的最低工作频率(单位: KHz)。
cpuinfo_transition_latency: 处理器切换频率所需要的时间(单位:ns)。
scaling_available_frequencies: 处理器支持的主频率列表(单位: KHz)。
scaling_available_governors: 当前内核中支持的所有 governor(调频)类型。
scaling_cur_freq: 保存着 cpufreq 模块缓存的当前 CPU 频率,不会对 CPU 硬件寄存器进行检查。
scaling_driver: 该文件保存当前 CPU 所使用的调频驱动。
scaling_governor: governor(调频)策略,Linux 内核一共有 5 中调频策略,
Performance, 最高性能,直接用最高频率,不考虑耗电。
Interactive, 一开始直接用最高频率,然后根据 CPU 负载慢慢降低。
Powersave, 省电模式,通常以最低频率运行,系统性能会受影响,一般不会用这个!
Userspace, 可以在用户空间手动调节频率。
Ondemand, 定时检查负载,然后根据负载来调节频率。负载低的时候降低 CPU 频率,负载高的时候提高 CPU 频率
scaling_max_freq: governor(调频)可以调节的最高频率。
cpuinfo_min_freq: governor(调频)可以调节的最低频率。
stats 目录下给出了 CPU 各种运行频率的统计情况,比如 CPU 在各频率下的运行时间以及变频次数。
修改调频策略
将调频策略修改为performance
方法一:
vi ./arch/arm/configs/imx_victor_emmc_defconfig
方法二:
vi ./arch/arm/configs/imx_victor_emmc_defconfig
make imx_victor_emmc_defconfig
make menuconfig
CPU Power Management --->
CPU Frequency scaling --->
Default CPUFreq governor (ondemand) --->
performance
方法二:使用cpufrequtils
安装:sudo apt install cpufrequtils
查看cpu类型、当前频率、支持频率、运行模式等
cpufreq-info -m
root@localhost:~# cpufreq-info -m
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
driver: qoriq_cpufreq
CPUs which run at the same hardware frequency: 0 1 2 3
CPUs which need to have their frequency coordinated by software: 0 1 2 3
maximum transition latency: 31 ns.
hardware limits: 500 MHz - 1.60 GHz
available frequency steps: 1.60 GHz, 1000 MHz, 800 MHz, 500 MHz
available cpufreq governors: conservative, ondemand, userspace, powersave, performance, schedutil
current policy: frequency should be within 500 MHz and 1.60 GHz.
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 1000 MHz (asserted by call to hardware).
cpufreq stats: 1.60 GHz:4.76%, 1000 MHz:0.99%, 800 MHz:1.72%, 500 MHz:92.53% (530)
analyzing CPU 1:
driver: qoriq_cpufreq
CPUs which run at the same hardware frequency: 0 1 2 3
CPUs which need to have their frequency coordinated by software: 0 1 2 3
maximum transition latency: 31 ns.
hardware limits: 500 MHz - 1.60 GHz
available frequency steps: 1.60 GHz, 1000 MHz, 800 MHz, 500 MHz
available cpufreq governors: conservative, ondemand, userspace, powersave, performance, schedutil
current policy: frequency should be within 500 MHz and 1.60 GHz.
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 1000 MHz (asserted by call to hardware).
cpufreq stats: 1.60 GHz:4.76%, 1000 MHz:0.99%, 800 MHz:1.72%, 500 MHz:92.53% (530)
analyzing CPU 2:
driver: qoriq_cpufreq
CPUs which run at the same hardware frequency: 0 1 2 3
CPUs which need to have their frequency coordinated by software: 0 1 2 3
maximum transition latency: 31 ns.
hardware limits: 500 MHz - 1.60 GHz
available frequency steps: 1.60 GHz, 1000 MHz, 800 MHz, 500 MHz
available cpufreq governors: conservative, ondemand, userspace, powersave, performance, schedutil
current policy: frequency should be within 500 MHz and 1.60 GHz.
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 1000 MHz (asserted by call to hardware).
cpufreq stats: 1.60 GHz:4.76%, 1000 MHz:0.99%, 800 MHz:1.72%, 500 MHz:92.53% (530)
analyzing CPU 3:
driver: qoriq_cpufreq
CPUs which run at the same hardware frequency: 0 1 2 3
CPUs which need to have their frequency coordinated by software: 0 1 2 3
maximum transition latency: 31 ns.
hardware limits: 500 MHz - 1.60 GHz
available frequency steps: 1.60 GHz, 1000 MHz, 800 MHz, 500 MHz
available cpufreq governors: conservative, ondemand, userspace, powersave, performance, schedutil
current policy: frequency should be within 500 MHz and 1.60 GHz.
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 1000 MHz (asserted by call to hardware).
cpufreq stats: 1.60 GHz:4.76%, 1000 MHz:0.99%, 800 MHz:1.72%, 500 MHz:92.53% (530)
调整整体工作模式
cpufreq-set -g performance
调整某个核的工作模式
cpufreq-set -g performance -c CPU序列
手动调节频率
cpufreq-set -g userspace -d 800MHz -u 1000MHz
注:方法二为临时调整,想要永久调整可以添加至自启动服务中