0001 .. SPDX-License-Identifier: GPL-2.0
0002
0003 ==========================================
0004 General Description of sysfs CPUFreq Stats
0005 ==========================================
0006
0007 information for users
0008
0009
0010 Author: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
0011
0012 .. Contents
0013
0014 1. Introduction
0015 2. Statistics Provided (with example)
0016 3. Configuring cpufreq-stats
0017
0018
0019 1. Introduction
0020 ===============
0021
0022 cpufreq-stats is a driver that provides CPU frequency statistics for each CPU.
0023 These statistics are provided in /sysfs as a bunch of read_only interfaces. This
0024 interface (when configured) will appear in a separate directory under cpufreq
0025 in /sysfs (<sysfs root>/devices/system/cpu/cpuX/cpufreq/stats/) for each CPU.
0026 Various statistics will form read_only files under this directory.
0027
0028 This driver is designed to be independent of any particular cpufreq_driver
0029 that may be running on your CPU. So, it will work with any cpufreq_driver.
0030
0031
0032 2. Statistics Provided (with example)
0033 =====================================
0034
0035 cpufreq stats provides following statistics (explained in detail below).
0036
0037 - time_in_state
0038 - total_trans
0039 - trans_table
0040
0041 All the statistics will be from the time the stats driver has been inserted
0042 (or the time the stats were reset) to the time when a read of a particular
0043 statistic is done. Obviously, stats driver will not have any information
0044 about the frequency transitions before the stats driver insertion.
0045
0046 ::
0047
0048 <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # ls -l
0049 total 0
0050 drwxr-xr-x 2 root root 0 May 14 16:06 .
0051 drwxr-xr-x 3 root root 0 May 14 15:58 ..
0052 --w------- 1 root root 4096 May 14 16:06 reset
0053 -r--r--r-- 1 root root 4096 May 14 16:06 time_in_state
0054 -r--r--r-- 1 root root 4096 May 14 16:06 total_trans
0055 -r--r--r-- 1 root root 4096 May 14 16:06 trans_table
0056
0057 - **reset**
0058
0059 Write-only attribute that can be used to reset the stat counters. This can be
0060 useful for evaluating system behaviour under different governors without the
0061 need for a reboot.
0062
0063 - **time_in_state**
0064
0065 This gives the amount of time spent in each of the frequencies supported by
0066 this CPU. The cat output will have "<frequency> <time>" pair in each line, which
0067 will mean this CPU spent <time> usertime units of time at <frequency>. Output
0068 will have one line for each of the supported frequencies. usertime units here
0069 is 10mS (similar to other time exported in /proc).
0070
0071 ::
0072
0073 <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat time_in_state
0074 3600000 2089
0075 3400000 136
0076 3200000 34
0077 3000000 67
0078 2800000 172488
0079
0080
0081 - **total_trans**
0082
0083 This gives the total number of frequency transitions on this CPU. The cat
0084 output will have a single count which is the total number of frequency
0085 transitions.
0086
0087 ::
0088
0089 <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat total_trans
0090 20
0091
0092 - **trans_table**
0093
0094 This will give a fine grained information about all the CPU frequency
0095 transitions. The cat output here is a two dimensional matrix, where an entry
0096 <i,j> (row i, column j) represents the count of number of transitions from
0097 Freq_i to Freq_j. Freq_i rows and Freq_j columns follow the sorting order in
0098 which the driver has provided the frequency table initially to the cpufreq core
0099 and so can be sorted (ascending or descending) or unsorted. The output here
0100 also contains the actual freq values for each row and column for better
0101 readability.
0102
0103 If the transition table is bigger than PAGE_SIZE, reading this will
0104 return an -EFBIG error.
0105
0106 ::
0107
0108 <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_table
0109 From : To
0110 : 3600000 3400000 3200000 3000000 2800000
0111 3600000: 0 5 0 0 0
0112 3400000: 4 0 2 0 0
0113 3200000: 0 1 0 2 0
0114 3000000: 0 0 1 0 3
0115 2800000: 0 0 0 2 0
0116
0117 3. Configuring cpufreq-stats
0118 ============================
0119
0120 To configure cpufreq-stats in your kernel::
0121
0122 Config Main Menu
0123 Power management options (ACPI, APM) --->
0124 CPU Frequency scaling --->
0125 [*] CPU Frequency scaling
0126 [*] CPU frequency translation statistics
0127
0128
0129 "CPU Frequency scaling" (CONFIG_CPU_FREQ) should be enabled to configure
0130 cpufreq-stats.
0131
0132 "CPU frequency translation statistics" (CONFIG_CPU_FREQ_STAT) provides the
0133 statistics which includes time_in_state, total_trans and trans_table.
0134
0135 Once this option is enabled and your CPU supports cpufrequency, you
0136 will be able to see the CPU frequency statistics in /sysfs.