sysfs CPUFreq 统计信息概述¶
用户信息
作者: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
1. 简介¶
cpufreq-stats 是一个驱动程序,它为每个 CPU 提供 CPU 频率统计信息。 这些统计信息以只读接口的形式在 /sysfs 中提供。 此接口(配置后)将出现在 /sysfs 中 cpufreq 下的单独目录中(<sysfs 根目录>/devices/system/cpu/cpuX/cpufreq/stats/),针对每个 CPU。 各种统计信息将在此目录下形成只读文件。
此驱动程序设计为独立于可能在 CPU 上运行的任何特定 cpufreq_driver。 因此,它可以与任何 cpufreq_driver 一起使用。
2. 提供的统计信息(带示例)¶
cpufreq stats 提供以下统计信息(下面详细说明)。
time_in_state
total_trans
trans_table
所有统计信息都将从统计驱动程序插入时(或统计信息重置时)到读取特定统计信息时为止。 显然,统计驱动程序将没有有关统计驱动程序插入之前的频率转换的任何信息。
<mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # ls -l
total 0
drwxr-xr-x 2 root root 0 May 14 16:06 .
drwxr-xr-x 3 root root 0 May 14 15:58 ..
--w------- 1 root root 4096 May 14 16:06 reset
-r--r--r-- 1 root root 4096 May 14 16:06 time_in_state
-r--r--r-- 1 root root 4096 May 14 16:06 total_trans
-r--r--r-- 1 root root 4096 May 14 16:06 trans_table
reset
可用于重置统计计数器的只写属性。 这对于评估不同 governor 下的系统行为非常有用,而无需重新启动。
time_in_state
这给出了在此 CPU 支持的每个频率上花费的时间量。 cat 输出的每行都将具有“<frequency> <time>”对,这意味着此 CPU 在 <frequency> 以 <time> usertime 时间单位花费的时间。 输出将为每个支持的频率有一行。 此处的 usertime 单位是 10mS(类似于 /proc 中导出的其他时间)。
<mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat time_in_state
3600000 2089
3400000 136
3200000 34
3000000 67
2800000 172488
total_trans
这给出了此 CPU 上的频率转换总数。 cat 输出将具有一个计数,即频率转换的总数。
<mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat total_trans
20
trans_table
这将给出有关所有 CPU 频率转换的精细信息。 此处的 cat 输出是一个二维矩阵,其中条目 <i,j>(第 i 行,第 j 列)表示从 Freq_i 到 Freq_j 的转换次数的计数。 Freq_i 行和 Freq_j 列遵循驱动程序最初向 cpufreq 核心提供频率表时的排序顺序,因此可以排序(升序或降序)或不排序。 此处的输出还包含每一行和每一列的实际频率值,以便更好地阅读。
如果转换表大于 PAGE_SIZE,则读取它将返回 -EFBIG 错误。
<mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_table
From : To
: 3600000 3400000 3200000 3000000 2800000
3600000: 0 5 0 0 0
3400000: 4 0 2 0 0
3200000: 0 1 0 2 0
3000000: 0 0 1 0 3
2800000: 0 0 0 2 0
3. 配置 cpufreq-stats¶
要在内核中配置 cpufreq-stats
Config Main Menu
Power management options (ACPI, APM) --->
CPU Frequency scaling --->
[*] CPU Frequency scaling
[*] CPU frequency translation statistics
应启用“CPU 频率调节”(CONFIG_CPU_FREQ)以配置 cpufreq-stats。
“CPU 频率转换统计”(CONFIG_CPU_FREQ_STAT)提供统计信息,包括 time_in_state、total_trans 和 trans_table。
启用此选项并且您的 CPU 支持 cpufrequency 后,您将能够在 /sysfs 中看到 CPU 频率统计信息。