xref: /OK3568_Linux_fs/kernel/Documentation/cpu-freq/cpufreq-stats.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun==========================================
4*4882a593SmuzhiyunGeneral Description of sysfs CPUFreq Stats
5*4882a593Smuzhiyun==========================================
6*4882a593Smuzhiyun
7*4882a593Smuzhiyuninformation for users
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunAuthor: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun.. Contents
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun   1. Introduction
15*4882a593Smuzhiyun   2. Statistics Provided (with example)
16*4882a593Smuzhiyun   3. Configuring cpufreq-stats
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun1. Introduction
20*4882a593Smuzhiyun===============
21*4882a593Smuzhiyun
22*4882a593Smuzhiyuncpufreq-stats is a driver that provides CPU frequency statistics for each CPU.
23*4882a593SmuzhiyunThese statistics are provided in /sysfs as a bunch of read_only interfaces. This
24*4882a593Smuzhiyuninterface (when configured) will appear in a separate directory under cpufreq
25*4882a593Smuzhiyunin /sysfs (<sysfs root>/devices/system/cpu/cpuX/cpufreq/stats/) for each CPU.
26*4882a593SmuzhiyunVarious statistics will form read_only files under this directory.
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunThis driver is designed to be independent of any particular cpufreq_driver
29*4882a593Smuzhiyunthat may be running on your CPU. So, it will work with any cpufreq_driver.
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun2. Statistics Provided (with example)
33*4882a593Smuzhiyun=====================================
34*4882a593Smuzhiyun
35*4882a593Smuzhiyuncpufreq stats provides following statistics (explained in detail below).
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun-  time_in_state
38*4882a593Smuzhiyun-  total_trans
39*4882a593Smuzhiyun-  trans_table
40*4882a593Smuzhiyun
41*4882a593SmuzhiyunAll the statistics will be from the time the stats driver has been inserted
42*4882a593Smuzhiyun(or the time the stats were reset) to the time when a read of a particular
43*4882a593Smuzhiyunstatistic is done. Obviously, stats driver will not have any information
44*4882a593Smuzhiyunabout the frequency transitions before the stats driver insertion.
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun::
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun    <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # ls -l
49*4882a593Smuzhiyun    total 0
50*4882a593Smuzhiyun    drwxr-xr-x  2 root root    0 May 14 16:06 .
51*4882a593Smuzhiyun    drwxr-xr-x  3 root root    0 May 14 15:58 ..
52*4882a593Smuzhiyun    --w-------  1 root root 4096 May 14 16:06 reset
53*4882a593Smuzhiyun    -r--r--r--  1 root root 4096 May 14 16:06 time_in_state
54*4882a593Smuzhiyun    -r--r--r--  1 root root 4096 May 14 16:06 total_trans
55*4882a593Smuzhiyun    -r--r--r--  1 root root 4096 May 14 16:06 trans_table
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun- **reset**
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunWrite-only attribute that can be used to reset the stat counters. This can be
60*4882a593Smuzhiyunuseful for evaluating system behaviour under different governors without the
61*4882a593Smuzhiyunneed for a reboot.
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun- **time_in_state**
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunThis gives the amount of time spent in each of the frequencies supported by
66*4882a593Smuzhiyunthis CPU. The cat output will have "<frequency> <time>" pair in each line, which
67*4882a593Smuzhiyunwill mean this CPU spent <time> usertime units of time at <frequency>. Output
68*4882a593Smuzhiyunwill have one line for each of the supported frequencies. usertime units here
69*4882a593Smuzhiyunis 10mS (similar to other time exported in /proc).
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun::
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun    <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat time_in_state
74*4882a593Smuzhiyun    3600000 2089
75*4882a593Smuzhiyun    3400000 136
76*4882a593Smuzhiyun    3200000 34
77*4882a593Smuzhiyun    3000000 67
78*4882a593Smuzhiyun    2800000 172488
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun- **total_trans**
82*4882a593Smuzhiyun
83*4882a593SmuzhiyunThis gives the total number of frequency transitions on this CPU. The cat
84*4882a593Smuzhiyunoutput will have a single count which is the total number of frequency
85*4882a593Smuzhiyuntransitions.
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun::
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun    <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat total_trans
90*4882a593Smuzhiyun    20
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun- **trans_table**
93*4882a593Smuzhiyun
94*4882a593SmuzhiyunThis will give a fine grained information about all the CPU frequency
95*4882a593Smuzhiyuntransitions. The cat output here is a two dimensional matrix, where an entry
96*4882a593Smuzhiyun<i,j> (row i, column j) represents the count of number of transitions from
97*4882a593SmuzhiyunFreq_i to Freq_j. Freq_i rows and Freq_j columns follow the sorting order in
98*4882a593Smuzhiyunwhich the driver has provided the frequency table initially to the cpufreq core
99*4882a593Smuzhiyunand so can be sorted (ascending or descending) or unsorted.  The output here
100*4882a593Smuzhiyunalso contains the actual freq values for each row and column for better
101*4882a593Smuzhiyunreadability.
102*4882a593Smuzhiyun
103*4882a593SmuzhiyunIf the transition table is bigger than PAGE_SIZE, reading this will
104*4882a593Smuzhiyunreturn an -EFBIG error.
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun::
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun    <mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat trans_table
109*4882a593Smuzhiyun    From  :    To
110*4882a593Smuzhiyun	    :   3600000   3400000   3200000   3000000   2800000
111*4882a593Smuzhiyun    3600000:         0         5         0         0         0
112*4882a593Smuzhiyun    3400000:         4         0         2         0         0
113*4882a593Smuzhiyun    3200000:         0         1         0         2         0
114*4882a593Smuzhiyun    3000000:         0         0         1         0         3
115*4882a593Smuzhiyun    2800000:         0         0         0         2         0
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun3. Configuring cpufreq-stats
118*4882a593Smuzhiyun============================
119*4882a593Smuzhiyun
120*4882a593SmuzhiyunTo configure cpufreq-stats in your kernel::
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun	Config Main Menu
123*4882a593Smuzhiyun		Power management options (ACPI, APM)  --->
124*4882a593Smuzhiyun			CPU Frequency scaling  --->
125*4882a593Smuzhiyun				[*] CPU Frequency scaling
126*4882a593Smuzhiyun				[*]   CPU frequency translation statistics
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun"CPU Frequency scaling" (CONFIG_CPU_FREQ) should be enabled to configure
130*4882a593Smuzhiyuncpufreq-stats.
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun"CPU frequency translation statistics" (CONFIG_CPU_FREQ_STAT) provides the
133*4882a593Smuzhiyunstatistics which includes time_in_state, total_trans and trans_table.
134*4882a593Smuzhiyun
135*4882a593SmuzhiyunOnce this option is enabled and your CPU supports cpufrequency, you
136*4882a593Smuzhiyunwill be able to see the CPU frequency statistics in /sysfs.
137