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 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
299000

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
1274000 1235000 1196000 1170000 1105000 1053000 1001000 962000 910000 845000 702
000 624000 546000 416000 338000 299000

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
299000

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

1.3 cpuinfo_max_freq

获取 CPU 最大频率,单位 KHz
该文件指定了处理器能够运行的最高工作频率 (单位: 千赫兹)

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat cpuinfo_max_freq
cat cpuinfo_max_freq
1274000
1.3 cpuinfo_min_freq

获取 CPU 最小频率,单位 KHz
该文件指定了处理器能够运行的最低工作频率 (单位: 千赫兹)

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat cpuinfo_min_freq
cat cpuinfo_min_freq
299000
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
1274000 1235000 1196000 1170000 1105000 1053000 1001000 962000 910000 845000 702
000 624000 546000 416000 338000 299000
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
1274000
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
1274000
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
299000
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
20000000
1.14.1 up_throttle_nsec
Z91:/sys/devices/system/cpu/cpu0/cpufreq/sched # cat up_throttle_nsec
cat up_throttle_nsec
500000
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
1274000 1057346
1235000 33219
1196000 20219
1170000 41032
1105000 34062
1053000 37278
1001000 30385
962000 46199
910000 48913
845000 147837
702000 108755
624000 129635
546000 78269
416000 171114
338000 15087
299000 3972384
1.15.2 total_trans
Z91:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat total_trans
cat total_trans
1153632
1.15.2 trans_table
Z91:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_table
cat trans_table
   From  :    To
         :   1274000   1235000   1196000   1170000   1105000   1053000   1001000
    962000    910000    845000    702000    624000    546000    416000    338000
    299000
  1274000:         0     19712      8008     11909      7249      5888      3298
      3599      3750      6019      2287      2004      2780      1618       864
     16976
  1235000:     47991         0      1062       905       528       480       731
       722       608       927       331       241       223       141        58
      1790
  1196000:      9775     22038         0      1266       368       287       212
       558       418       662       233       180       179        76        36
       723
  1170000:     10841      8681     22196         0      1327       726       528
      1266      1537      2117       690       460       444       241        84
      2127
  1105000:      3938      2860      3531     26213         0       997       449
       589      1759      2135       779       486       435       198        84
      1580
  1053000:      2675       561       822      8157     26093         0       862
       709       886      3464      1286       852       771       290       117
      1188
  1001000:      1520       389       206      1456      5465     25137         0
       839       578      2184      1219       824       670       222        95
      1185
   962000:      1819       316       259       874      2466      9771     26210
         0      1164      3954      3321      2459      2122       623       241
      1590
   910000:      1478       179       144       551       831      2857      5709
     28786         0      3188      2200      1907      1664       398       169
      1920
   845000:      3241       223       138       482       551      1356      2945
     18420     35571         0      5817      9752     18461      6007      1297
      9549
   702000:      1664        94        48       146       131       219       291
       614      3661     48204         0      2999     12205      7513      1760
      9835
   624000:      1197        77        50       145       202       290       220
       284       504     14517     34878         0      6134      7161      2090
     14598
   546000:      1515        90        50       135       124       134       104
       141       323     23033     22378     10003         0      9147      3872
     16603
   416000:      1057       135       124       371       326       271       132
       207       354      1335     12254     46620     12103         0      4261
     51129
   338000:       269        29        18        24        21        19        18
        25        59       173       216      1234     13100      4073         0
      5532
   299000:      6981      1354       355       631       351       301       280
       429       809      1898      1495      2327     16361     92971      9782
         0
  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

法迪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值