← Documents Documentation/cpu-freq/cpufreq-stats.rst GitHub 원문 ↗

Linux 6.18.37 · CPU Frequency

General Description of sysfs CPUFreq Stats

cpufreq-stats가 CPU별 sysfs에 제공하는 reset, time_in_state, total_trans, trans_table attribute의 의미와 출력 형식, kernel configuration 방법을 설명합니다.

Source pathDocumentation/cpu-freq/cpufreq-stats.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

cpufreq-stats.rst:1-136

cpufreq-stats는 CPU별로 `/sys/devices/system/cpu/cpuX/cpufreq/stats/` 아래에 frequency residency와 transition 통계를 export하며 특정 cpufreq driver에 종속되지 않습니다.

`time_in_state`는 frequency별 체류 시간을 10ms usertime unit으로, `total_trans`는 전체 전환 횟수를, `trans_table`은 출발 frequency와 도착 frequency 사이의 전환 횟수 matrix를 제공합니다.

`reset`을 쓰면 reboot 없이 counter를 초기화할 수 있습니다. 기능을 사용하려면 `CONFIG_CPU_FREQ`와 `CONFIG_CPU_FREQ_STAT`을 활성화해야 합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Sysfs CPUFreq 통계 일반 설명

1-18
.. SPDX-License-Identifier: GPL-2.0

Sysfs CPUFreq 통계 일반 설명

사용자를 위한 정보

저자: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>

목차:

  • 1. 소개
  • 2. 제공되는 통계와 예제
  • 3. cpufreq-stats 설정

1. 소개

19-31

1. 소개

cpufreq-stats는 CPU마다 CPU frequency 통계를 제공하는 driver입니다. 통계는 `/sysfs`에 여러 read-only interface로 제공됩니다. 설정하면 CPU별 cpufreq directory 아래의 `<sysfs root>/devices/system/cpu/cpuX/cpufreq/stats/`에 별도 directory가 나타나며, 여러 통계가 이 directory 아래의 read-only file로 생성됩니다.

이 driver는 CPU에서 실행 중일 수 있는 특정 `cpufreq_driver`와 독립적으로 설계되었으므로 어떤 `cpufreq_driver`와도 동작합니다.

2. 제공되는 통계

32-56

2. 제공되는 통계와 예제

cpufreq stats는 다음 통계를 제공합니다.

  • time_in_state
  • total_trans
  • trans_table

모든 통계의 측정 구간은 stats driver가 삽입된 시점 또는 통계가 reset된 시점부터 특정 통계를 읽는 시점까지입니다. Stats driver가 삽입되기 전에 일어난 frequency transition에 관한 정보는 제공할 수 없습니다.

<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

57-62

`reset`

통계 counter를 reset할 때 사용하는 write-only attribute입니다. Reboot하지 않고 서로 다른 governor에서 system 동작을 평가할 때 유용합니다.

time_in_state

63-80

`time_in_state`

이 CPU가 지원하는 각 frequency에서 소비한 시간을 제공합니다. `cat` 출력의 각 줄은 `<frequency> <time>` pair이며, CPU가 `<frequency>`에서 `<time>` usertime unit 동안 실행되었다는 뜻입니다. 지원하는 frequency마다 한 줄이 출력됩니다. 여기서 usertime unit은 `/proc`에 export되는 다른 시간과 비슷하게 10ms입니다.

<mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat time_in_state
3600000 2089
3400000 136
3200000 34
3000000 67
2800000 172488

total_trans

81-91

`total_trans`

이 CPU에서 발생한 frequency transition의 총 횟수를 제공합니다. `cat` 출력은 전체 transition 횟수 하나입니다.

<mysystem>:/sys/devices/system/cpu/cpu0/cpufreq/stats # cat total_trans
20

trans_table

92-116

`trans_table`

모든 CPU frequency transition에 관한 세부 정보를 제공합니다. `cat` 출력은 2차원 matrix이며, entry `<i,j>`, 즉 row i와 column j는 `Freq_i`에서 `Freq_j`로 전환한 횟수를 나타냅니다. `Freq_i` row와 `Freq_j` column은 driver가 처음 cpufreq core에 frequency table을 제공한 정렬 순서를 따르므로 ascending, descending 또는 unsorted일 수 있습니다. 가독성을 위해 각 row와 column의 실제 frequency 값도 출력합니다.

Transition table이 `PAGE_SIZE`보다 크면 이 attribute를 읽을 때 `-EFBIG` error가 반환됩니다.

<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
CPU frequency transition matrix
From \ To36000003400000320000030000002800000
360000005000
340000040200
320000001020
300000000103
280000000020
전환 전 frequency인 Freq_i입니다.
전환 후 frequency인 Freq_j입니다.

`trans_table` 예제의 From row와 To column을 구조화된 matrix로 다시 표현했습니다. Cell 값은 transition 횟수입니다.

3. cpufreq-stats 설정

117-136

3. cpufreq-stats 설정

Kernel에서 cpufreq-stats를 설정하는 menu 경로는 다음과 같습니다.

Config Main Menu
        Power management options (ACPI, APM)  --->
                CPU Frequency scaling  --->
                        [*] CPU Frequency scaling
                        [*]   CPU frequency translation statistics

cpufreq-stats를 설정하려면 `CPU Frequency scaling`, 즉 `CONFIG_CPU_FREQ`를 활성화해야 합니다.

`CPU frequency translation statistics`, 즉 `CONFIG_CPU_FREQ_STAT`은 `time_in_state`, `total_trans`, `trans_table`을 포함한 통계를 제공합니다.

이 option을 활성화하고 CPU가 CPU frequency scaling을 지원하면 `/sysfs`에서 CPU frequency 통계를 볼 수 있습니다.