博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 系统 cpu0 目录查看 CPU 频率freq和策略policy
阅读量:4147 次
发布时间:2019-05-25

本文共 10388 字,大约阅读时间需要 34 分钟。

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

/sys/devices/system/cpu/cpu0

Z91:/sys/devices/system/cpu/cpu0 # ls -alls -altotal 0drwxr-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/policy0drwxr-xr-x  5 root root    0 2018-01-09 11:17 cpuidlelrwxrwxrwx  1 root root    0 2018-01-09 11:17 of_node -> ../../../../firmware/devicetree/base/cpus/cpu@0-rw-r--r--  1 root root 4096 2018-01-09 11:17 onlinedrwxr-xr-x  2 root root    0 2018-01-09 11:17 powerlrwxrwxrwx  1 root root    0 2018-01-09 11:17 subsystem -> ../../../../bus/cpudrwxr-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_freq299000

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

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_frequenciescat scaling_available_frequencies1274000 1235000 1196000 1170000 1105000 1053000 1001000 962000 910000 845000 702000 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_governorscat scaling_available_governorsondemand 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_governorcat scaling_governorsched

三、 目录详情

1. cpufreq

查询结果如下

Z91:/sys/devices/system/cpu/cpu0/cpufreq # ls -alls -altotal 0drwxr-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_setspeeddrwxr-xr-x 2 root   root      0 2018-01-10 11:27 scheddrwxr-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_cpuscat affected_cpus0 1 2 3
1.2 cpuinfo_cur_freq

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

cat cpuinfo_cur_freq299000

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

1.3 cpuinfo_max_freq

获取 CPU 最大频率,单位 KHz

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat cpuinfo_max_freqcat cpuinfo_max_freq1274000
1.3 cpuinfo_min_freq

获取 CPU 最小频率,单位 KHz

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat cpuinfo_min_freqcat cpuinfo_min_freq299000
1.4 cpuinfo_transition_latency

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat cpuinfo_transition_latencycat cpuinfo_transition_latency1000
1.5 related_cpus

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat related_cpuscat related_cpus0 1 2 3
1.6 scaling_available_frequencies

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_frequenciescat scaling_available_frequencies1274000 1235000 1196000 1170000 1105000 1053000 1001000 962000 910000 845000 702000 624000 546000 416000 338000 299000
1.7 scaling_available_governors

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_available_governorscat scaling_available_governorsondemand 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

1.8 scaling_cur_freq

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

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

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_drivercat scaling_drivermt-cpufreq
1.10 scaling_governor

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_governorcat scaling_governorsched
1.11 scaling_max_freq

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_max_freqcat scaling_max_freq1274000
1.12 scaling_min_freq

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

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

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

Z91:/sys/devices/system/cpu/cpu0/cpufreq # cat scaling_setspeedcat scaling_setspeed
因为当前不是 userspace 模式
1.14 sched
Z91:/sys/devices/system/cpu/cpu0/cpufreq/sched # ls -allls -alltotal 0drwxr-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_nseccat down_throttle_nsec20000000
1.14.1 up_throttle_nsec
Z91:/sys/devices/system/cpu/cpu0/cpufreq/sched # cat up_throttle_nseccat up_throttle_nsec500000
1.15 stats
Z91:/sys/devices/system/cpu/cpu0/cpufreq/stats # ls -allls -alltotal 0drwxr-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_statecat time_in_state1274000 10573461235000 332191196000 202191170000 410321105000 340621053000 372781001000 30385962000 46199910000 48913845000 147837702000 108755624000 129635546000 78269416000 171114338000 15087299000 3972384
1.15.2 total_trans
Z91:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat total_transcat total_trans1153632
1.15.2 trans_table
Z91:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_tablecat 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

转载地址:http://uocti.baihongyu.com/

你可能感兴趣的文章
就在昨天,全球 42 亿 IPv4 地址宣告耗尽!
查看>>
Mysql复制表以及复制数据库
查看>>
Linux分区方案
查看>>
如何使用 systemd 中的定时器
查看>>
git命令速查表
查看>>
linux进程监控和自动重启的简单实现
查看>>
OpenFeign学习(三):OpenFeign配置生成代理对象
查看>>
OpenFeign学习(四):OpenFeign的方法同步请求执行
查看>>
OpenFeign学习(六):OpenFign进行表单提交参数或传输文件
查看>>
Ribbon 学习(二):Spring Cloud Ribbon 加载配置原理
查看>>
Ribbon 学习(三):RestTemplate 请求负载流程解析
查看>>
深入理解HashMap
查看>>
XML生成(一):DOM生成XML
查看>>
XML生成(三):JDOM生成
查看>>
Ubuntu Could not open lock file /var/lib/dpkg/lock - open (13:Permission denied)
查看>>
collect2: ld returned 1 exit status
查看>>
C#入门
查看>>
C#中ColorDialog需点两次确定才会退出的问题
查看>>
数据库
查看>>
nginx反代 499 502 bad gateway 和timeout
查看>>