2025年Android 系统 cpu0 目录查看 CPU 频率freq和策略policy

Android 系统 cpu0 目录查看 CPU 频率freq和策略policy一 sys devices system cpu cpu0 目录结构 sys devices system cpu cpu0 Z91 sys devices system cpu cpu0 ls al ls al total 0 drwxr xr x 5 root root 0 2018 01 09 11 17 drwxr xr x

大家好,我是讯享网,很高兴认识大家。

一、 /sys/devices/system/cpu/cpu0 目录结构

/sys/devices/system/cpu/cpu0

Z91:/sys/devices/system/cpu/cpu0 # ls -al ls -al total 0 drwxr-xr-x 5 root root 0 2018-01-09 11:17 . drwxr-xr-x 13 root root 0 2018-01-09 11:17 .. lrwxrwxrwx 1 root root 0 2018-01-09 11:17 cpufreq -> ../cpufreq/policy0 drwxr-xr-x 5 root root 0 2018-01-09 11:17 cpuidle lrwxrwxrwx 1 root root 0 2018-01-09 11:17 of_node -> ../../../../firmware/de vicetree/base/cpus/cpu@0 -rw-r--r-- 1 root root 4096 2018-01-09 11:17 online drwxr-xr-x 2 root root 0 2018-01-09 11:17 power lrwxrwxrwx 1 root root 0 2018-01-09 11:17 subsystem -> ../../../../bus/cpu drwxr-xr-x 2 root root 0 2018-01-09 11:17 topology -rw-r--r-- 1 root root 4096 2018-01-09 11:17 uevent

讯享网

我们可以获取到什么信息

二、重要信息获取

1. CPU 频率

cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq

讯享网cat cpuinfo_cur_freq 

2.CPU 所支持的主频率列表(KHZ)

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_frequencies cat scaling_available_frequencies           702 000     

CPU 调频需要选择对应的档位,且参数不同机器该配置不同

3.CPU 策略policy

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

讯享网Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_governors cat scaling_available_governors ondemand userspace powersave interactive performance sched
  1. ondemand 表示使用内核提供的功能,可以动态调节频率
  2. userspace 表示用户模式,在此模式下允许其他用户程序调节CPU频率
  3. powersvae 表示省电模式,通常是在最低频率下运行
  4. interactive ondemand相似,规则是“快升慢降”
  5. performance 表示不降频,最高性能
  6. sched 基于调度器的 CPU 调频机制

4.查看当前 CPU 的运行模式

通过echo命令,能够改变当前处理器的governor类型

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_governor cat scaling_governor sched

三、 目录详情

1. cpufreq

查询结果如下

讯享网Z91:/sys/devices/system/cpu/cpu0/cpufreq # ls -al ls -al total 0 drwxr-xr-x 4 root root 0 2018-01-09 11:17 . drwxr-xr-x 3 root root 0 2018-01-09 11:17 .. -r--r--r-- 1 root root 4096 2018-01-09 11:17 affected_cpus -r-------- 1 root root 4096 2018-01-09 11:17 cpuinfo_cur_freq -r--r--r-- 1 root root 4096 2018-01-09 11:17 cpuinfo_max_freq -r--r--r-- 1 root root 4096 2018-01-09 11:17 cpuinfo_min_freq -r--r--r-- 1 root root 4096 2018-01-09 11:17 cpuinfo_transition_latency -r--r--r-- 1 root root 4096 2018-01-09 11:17 related_cpus -r--r--r-- 1 root root 4096 2018-01-09 11:17 scaling_available_frequencies -r--r--r-- 1 root root 4096 2018-01-09 11:17 scaling_available_governors -r--r--r-- 1 root root 4096 2018-01-09 11:17 scaling_cur_freq -r--r--r-- 1 root root 4096 2018-01-09 11:17 scaling_driver -rw-r--r-- 1 root root 4096 2018-01-09 11:17 scaling_governor -rw-rw-r-- 1 system system 4096 2018-01-09 11:17 scaling_max_freq -rw-rw-r-- 1 system system 4096 2018-01-09 11:17 scaling_min_freq -rw-r--r-- 1 root root 4096 2018-01-09 11:17 scaling_setspeed drwxr-xr-x 2 root root 0 2018-01-10 11:27 sched drwxr-xr-x 2 root root 0 2018-01-09 11:17 stats
1.1 affected_cpus

需要软件协调频率的CPU列表

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat affected_cpus cat affected_cpus 0 1 2 3
1.2 cpuinfo_cur_freq

获取当前 CPU 频率,这个参数非常重要,单位 KHz

讯享网cat cpuinfo_cur_freq 

因为我现在待机 所以现在的频率是 299 MHZ

1.3 cpuinfo_max_freq
Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat cpuinfo_max_freq cat cpuinfo_max_freq 
1.3 cpuinfo_min_freq
讯享网Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat cpuinfo_min_freq cat cpuinfo_min_freq 
1.4 cpuinfo_transition_latency

该文件定义了处理器在两个不同频率之间切换时所需要的时间 (单位: 纳秒)

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat cpuinfo_transition_latency cat cpuinfo_transition_latency 1000
1.5 related_cpus

需要软件或者硬件来协调频率的CPU列表


讯享网

讯享网Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat related_cpus cat related_cpus 0 1 2 3
1.6 scaling_available_frequencies

所有支持的主频率列表 (单位: 千赫兹)

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_frequencies cat scaling_available_frequencies           702 000     
1.7 scaling_available_governors

该文件显示当前内核中支持的所有cpufreq governor类型

讯享网Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_governors cat scaling_available_governors ondemand userspace powersave interactive performance sched
  1. ondemand
    userspace 是内核态的检测,效率低。而 ondemand 正是人们长期以来希望看到的一个完全在内核态下工作并且能够以更加细粒度的时间间隔对系统负载情况进行采样分析的 governor
  2. userspace
    最早的 cpufreq 子系统通过 userspace governor 为用户提供了这种灵活性。系统将变频策略的决策权交给了用户态应用程序,并提供了相应的接口供用户态应用程序调节CPU 运行频率使用。(可以使用 Dominik 等人开发了 cpufrequtils 工具包 )
  3. powersave
    CPU 会固定工作在其支持的最低运行频率上。因此这两种 governors 都属于静态 governor ,即在使用它们时 CPU 的运行频率不会根据系统运行时负载的变化动态作出调整。这两种 governors 对应的是两种极端的应用场景,使用 performancegovernor 体现的是对系统高性能的最大追求,而使用 powersave governor 则是对系统低功耗的最大追求。
  4. interactive
    和ondemand相似,规则是“快升慢降”,注重响应速度、性能,当有高需求时迅速跳到高频率,
    当低需求时逐渐降低频率,相比ondemand费电
  5. performance
    高性能模式,按你设定范围的最高频率运行,即使系统负载非常低cpu的频率也为最高。性能
    很好,因为CPU本身不需要资源去调整频率,但是电量消耗较快,温度也高一些。
  6. sched

http://kernel.meizu.com/cpufreq-sched.html

1.8 scaling_cur_freq

被governor和cpufreq核决定的当前CPU工作频率。该频率是内核认为该CPU当前运行的主频率

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_cur_freq cat scaling_cur_freq 
1.9 scaling_driver

该文件显示该CPU正在使用何种cpufreq driver

讯享网Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_driver cat scaling_driver mt-cpufreq
1.10 scaling_governor

通过echo命令,能够改变当前处理器的governor类型

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_governor cat scaling_governor sched
1.11 scaling_max_freq

显示当前policy的上下限 (单位: 千赫兹)需要注意的是,当改变cpu policy时,需要首先设置scaling_max_freq, 然后才是scaling_min_freq

讯享网Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_max_freq cat scaling_max_freq 
1.12 scaling_min_freq

显示当前policy的上下限 (单位: 千赫兹)需要注意的是,当改变cpu policy时,需要首先设置scaling_max_freq, 然后才是scaling_min_freq

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_min_freq cat scaling_min_freq 
1.13 scaling_setspeed

如果用户选择了“userspace” governor, 那么可以设置cpu工作主频率到某一个指定值。只需要这个值在scaling_min_freq 和 scaling_max_freq之间即可。

讯享网Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_setspeed cat scaling_setspeed <unsupported> 因为当前不是 userspace 模式
1.14 sched
Z91:/sys/devices/system/cpu/cpu0/cpufreq/sched # ls -all ls -all total 0 drwxr-xr-x 2 root root 0 2018-01-10 11:27 . drwxr-xr-x 4 root root 0 2018-01-09 11:17 .. -rw-r--r-- 1 root root 4096 2018-01-10 12:22 down_throttle_nsec -rw-r--r-- 1 root root 4096 2018-01-10 12:22 up_throttle_nsec
1.14.1 down_throttle_nsec
讯享网Z91:/sys/devices/system/cpu/cpu0/cpufreq/sched # cat down_throttle_nsec cat down_throttle_nsec 
1.14.1 up_throttle_nsec
Z91:/sys/devices/system/cpu/cpu0/cpufreq/sched # cat up_throttle_nsec cat up_throttle_nsec 
1.15 stats
讯享网Z91:/sys/devices/system/cpu/cpu0/cpufreq/stats # ls -all ls -all total 0 drwxr-xr-x 2 root root 0 2018-01-09 11:17 . drwxr-xr-x 4 root root 0 2018-01-09 11:17 .. -r--r--r-- 1 root root 4096 2018-01-09 11:17 time_in_state -r--r--r-- 1 root root 4096 2018-01-09 11:17 total_trans -r--r--r-- 1 root root 4096 2018-01-09 11:17 trans_table
1.15.1 time_in_state
Z91:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat time_in_state cat time_in_state    33219  20219  41032  34062  37278  30385  46199  48913        78269    15087  
1.15.2 total_trans
讯享网Z91:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat total_trans cat total_trans 
1.15.2 trans_table
Z91:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_table cat trans_table From : To :                 : 0 19712 8008 11909 7249 5888 3298 3599 3750 6019 2287 2004 2780 1618 864 16976 : 47991 0 1062 905 528 480 731 722 608 927 331 241 223 141 58 1790 : 9775 22038 0 1266 368 287 212 558 418 662 233 180 179 76 36 723 : 10841 8681 22196 0 1327 726 528 1266 1537 2117 690 460 444 241 84 2127 : 3938 2860 3531 26213 0 997 449 589 1759 2135 779 486 435 198 84 1580 : 2675 561 822 8157 26093 0 862 709 886 3464 1286 852 771 290 117 1188 : 1520 389 206 1456 5465 25137 0 839 578 2184 1219 824 670 222 95 1185 : 1819 316 259 874 2466 9771 26210 0 1164 3954 3321 2459 2122 623 241 1590 : 1478 179 144 551 831 2857 5709 28786 0 3188 2200 1907 1664 398 169 1920 : 3241 223 138 482 551 1356 2945 18420 35571 0 5817 9752 18461 6007 1297 9549 : 1664 94 48 146 131 219 291 614 3661 48204 0 2999 12205 7513 1760 9835 : 1197 77 50 145 202 290 220 284 504 14517 34878 0 6134 7161 2090 14598 : 1515 90 50 135 124 134 104 141 323 23033 22378 10003 0 9147 3872 16603 : 1057 135 124 371 326 271 132 207 354 1335 12254 46620 12103 0 4261 51129 : 269 29 18 24 21 19 18 25 59 173 216 1234 13100 4073 0 5532 : 6981 1354 355 631 351 301 280 429 809 1898 1495 2327 16361 92971 9782 0
小讯
上一篇 2025-03-19 08:57
下一篇 2025-02-15 13:00

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/21785.html