admin管理员组文章数量:1658586
对应目录
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
Governor | Description | remark |
---|---|---|
performance | Run the CPU at the maximum frequency. | 高功耗模式 |
powersave | Run the CPU at the minimum frequency. | 低功耗模式 |
userspace | Run the CPU at user specified frequencies. | 在此模式下用户echo freq > cpu0/cpufreq/scaling_setspeed 自定义主频 |
ondemand | Scales 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),切换到最高主频 |
conservative | Scales 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配置文件
假如要更改cpu为performance模式,首先用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 快速查看频率信息
版权声明:本文标题:linux cpu频率控制记录 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1729814182a1213698.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论