linux cpu频率控制记录

对应目录

anzye@anzye:/sys/devices/system/cpu# ls                                           
cpu0  cpu2  cpufreq  kernel_max  online    power    uevent                      
cpu1  cpu3  cpuidle  offline     possible  present
root@anzye:/sys/devices/system/cpu# ls cpufreq/conservative/
down_threshold  ignore_nice_load      sampling_rate      up_threshold
freq_step       sampling_down_factor  sampling_rate_min
root@anzye:/sys/devices/system/cpu# ls cpu1/
cpufreq/   of_node/   power/     topology/  
cpuidle/   online     subsystem/ uevent     
root@anzye:/sys/devices/system/cpu# ls cpu1/cpufreq
affected_cpus               related_cpus                   scaling_governor     
cpuinfo_cur_freq            scaling_available_frequencies  scaling_max_freq     
cpuinfo_max_freq            scaling_available_governors    scaling_min_freq     
cpuinfo_min_freq            scaling_cur_freq               scaling_setspeed     
cpuinfo_transition_latency  scaling_driver                 stats  
  • cpuN:N为3有4个核,
  • online:工作的内核号,echo 1 > cpuN/online打开N号内核
  • offline:关闭的内核号,echo 0 > cpuN/online关闭N号内核
  • cpufreq:此目录是在governor为ondemand和conservative策略时才有出现。echo ondemand > cpu*/cpufreq/scaling_governor时cpufreq/下就出现ondemand的目录
  • scaling_governor: echo相应的governor可更改控策略

Scaling governors

GovernorDescriptionremark
performanceRun the CPU at the maximum frequency.高功耗模式
powersaveRun the CPU at the minimum frequency.低功耗模式
userspaceRun the CPU at user specified frequencies.在此模式下用户echo freq > cpu0/cpufreq/scaling_setspeed自定义主频
ondemandScales the frequency dynamically according to current load. Jumps to the highest frequency and then possibly back off as the idle time increases.按需动态调节,如果负载高于95%(up_threshold=95),切换到最高主频
conservativeScales the frequency dynamically according to current load. Scales the frequency more gradually than ondemand.按需动态调节,比ondemand保守,具体查看相应的up_threshold值
  • 使用如下命令更改governor
    # echo governor > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
  • 更改动态策略的变频阀值
    # echo -n percent > /sys/devices/system/cpu/cpufreq/<governor>/up_threshold
    # echo -n percent > /sys/devices/system/cpu/cpufreq/<governor>/down_threshold
    

启动生效方法

使用 udev配置文件

假如要更改cpuperformance模式,首先用udevadm查看它的KEY,VALUE,

root@anzye:~# udevadm info -p /sys/devices/system/cpu/cpu0/ -a

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/system/cpu/cpu0':
    KERNEL=="cpu0"
    SUBSYSTEM=="cpu"
    DRIVER==""
    ATTR{online}=="1"

  looking at parent device '/devices/system/cpu':
    KERNELS=="cpu"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{kernel_max}=="3"
    ATTRS{possible}=="0-3"
    ATTRS{online}=="0-3"
    ATTRS{offline}==""
    ATTRS{present}=="0-3"

root@anzye:~# 

然后创建如下规则文件/etc/udev/rules.d/50-scaling-governor.rules

SUBSYSTEM=="cpu", ACTION=="add", KERNEL=="cpu0", RUN+="/bin/sh -c ' echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor '"

完成测试是否书写OK

root@anzye:/etc/udev/rules.d# udevadm test /sys/devices/system/cpu/cpu0
run_command: calling: test
adm_test: version 182
This program is for debugging only, it does not run any program,
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

builtin_kmod_init: load module index
add_matching_files: unable to open '/var/run/udev/rules.d': No such file or directory
...
parse_file: reading '/etc/udev/rules.d/50-scaling-governor.rules' as rules file
...
udev_rules_new: rules use 19128 bytes tokens (1594 * 12 bytes), 13043 bytes buffer
udev_rules_new: temporary index used 13180 bytes (659 * 20 bytes)
udev_device_new_from_syspath: device 0x11abd00 has devpath '/devices/system/cpu/cpu0'
udev_device_new_from_syspath: device 0x11ac020 has devpath '/devices/system/cpu/cpu0'
udev_device_read_db: no db file to read /var/run/udev/data/+cpu:cpu0: No such file or directory
udev_rules_apply_to_event: RUN '/bin/sh -c 'echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor'' /etc/udev/rules.
d/50-scaling-governor.rules:1
ACTION=add
DEVPATH=/devices/system/cpu/cpu0
OF_COMPATIBLE_0=arm,cortex-a9
OF_COMPATIBLE_N=1
OF_FULLNAME=/cpus/cpu@0
OF_NAME=cpu
OF_TYPE=cpu
SUBSYSTEM=cpu
UDEV_LOG=6
USEC_INITIALIZED=2623811356
run: '/bin/sh -c 'echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor''
builtin_kmod_exit: unload module index
root@anzye:/etc/udev/rules.d# 

出现**run: '/bin/sh -c 'echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor''**即说明ok

重启查看,可用cpufreq-info 快速查看频率信息

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值