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