요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
=============================================================
General description of the CPUFreq core and CPUFreq notifiers
=============================================================
Authors:
- Dominik Brodowski <linux@brodo.de>
- David Kimdon <dwhedon@debian.org>
- Rafael J. Wysocki <rafael.j.wysocki@intel.com>
- Viresh Kumar <viresh.kumar@linaro.org>
.. Contents:
1. CPUFreq core and interfaces
2. CPUFreq notifiers
3. CPUFreq Table Generation with Operating Performance Point (OPP)
1. General Information
======================
The CPUFreq core code is located in drivers/cpufreq/cpufreq.c. This
cpufreq code offers a standardized interface for the CPUFreq
architecture drivers (those pieces of code that do actual
frequency transitions), as well as to "notifiers". These are device
drivers or other part of the kernel that need to be informed of
policy changes (ex. thermal modules like ACPI) or of all
frequency changes (ex. timing code) or even need to force certain
speed limits (like LCD drivers on ARM architecture). Additionally, the
kernel "constant" loops_per_jiffy is updated on frequency changes
here.
Reference counting of the cpufreq policies is done by cpufreq_cpu_get
and cpufreq_cpu_put, which make sure that the cpufreq driver is
correctly registered with the core, and will not be unloaded until
cpufreq_put_cpu is called. That also ensures that the respective cpufreq
policy doesn't get freed while being used.
2. CPUFreq notifiers
====================
CPUFreq notifiers conform to the standard kernel notifier interface.
See linux/include/linux/notifier.h for details on notifiers.
There are two different CPUFreq notifiers - policy notifiers and
transition notifiers.
2.1 CPUFreq policy notifiers
----------------------------
These are notified when a new policy is created or removed.
The phase is specified in the second argument to the notifier. The phase is
CPUFREQ_CREATE_POLICY when the policy is first created and it is
CPUFREQ_REMOVE_POLICY when the policy is removed.
The third argument, a ``void *pointer``, points to a struct cpufreq_policy
consisting of several values, including min, max (the lower and upper
frequencies (in kHz) of the new policy).
2.2 CPUFreq transition notifiers
--------------------------------
These are notified twice for each online CPU in the policy, when the
CPUfreq driver switches the CPU core frequency and this change has no
any external implications.
The second argument specifies the phase - CPUFREQ_PRECHANGE or
CPUFREQ_POSTCHANGE.
The third argument is a struct cpufreq_freqs with the following
values:
====== ======================================
policy a pointer to the struct cpufreq_policy
old old frequency
new new frequency
flags flags of the cpufreq driver
====== ======================================
3. CPUFreq Table Generation with Operating Performance Point (OPP)
==================================================================
For details about OPP, see Documentation/power/opp.rst
dev_pm_opp_init_cpufreq_table -
This function provides a ready to use conversion routine to translate
the OPP layer's internal information about the available frequencies
into a format readily providable to cpufreq.
.. Warning::
Do not use this function in interrupt context.
Example::
soc_pm_init()
{
/* Do things */
r = dev_pm_opp_init_cpufreq_table(dev, &freq_table);
if (!r)
policy->freq_table = freq_table;
/* Do other things */
}
.. note::
This function is available only if CONFIG_CPU_FREQ is enabled in
addition to CONFIG_PM_OPP.
dev_pm_opp_free_cpufreq_table
Free up the table allocated by dev_pm_opp_init_cpufreq_table
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
CPUFreq core와 notifier의 일반 설명
1-18.. SPDX-License-Identifier: GPL-2.0
CPUFreq core와 CPUFreq notifier의 일반 설명
저자:
- Dominik Brodowski <linux@brodo.de>
- David Kimdon <dwhedon@debian.org>
- Rafael J. Wysocki <rafael.j.wysocki@intel.com>
- Viresh Kumar <viresh.kumar@linaro.org>
목차:
- 1. CPUFreq core와 interface
- 2. CPUFreq notifier
- 3. Operating Performance Point (OPP)를 이용한 CPUFreq table 생성
1. 일반 정보
19-381. 일반 정보
CPUFreq core code는 `drivers/cpufreq/cpufreq.c`에 있습니다. 이 cpufreq code는 실제 frequency transition을 수행하는 CPUFreq architecture driver에 표준화된 interface를 제공하며 notifier에도 같은 interface를 제공합니다. Notifier는 policy 변경을 통지받아야 하는 device driver나 kernel의 다른 부분, 예를 들어 ACPI 같은 thermal module, 모든 frequency 변경을 알아야 하는 timing code, 또는 ARM architecture의 LCD driver처럼 특정 speed limit을 강제해야 하는 구성 요소입니다. 또한 frequency가 변경될 때 kernel의 `loops_per_jiffy` 상수도 여기서 갱신됩니다.
Cpufreq policy의 reference counting은 `cpufreq_cpu_get`과 `cpufreq_cpu_put`이 수행합니다. 이 함수들은 cpufreq driver가 core에 올바르게 등록되어 있는지 확인하고 `cpufreq_put_cpu`가 호출될 때까지 driver가 unload되지 않게 합니다. 또한 사용 중인 해당 cpufreq policy가 해제되지 않도록 보장합니다.
2. CPUFreq notifier
39-482. CPUFreq notifier
CPUFreq notifier는 표준 kernel notifier interface를 따릅니다. Notifier의 자세한 내용은 `linux/include/linux/notifier.h`를 참조하십시오.
CPUFreq notifier에는 policy notifier와 transition notifier의 두 종류가 있습니다.
2.1 CPUFreq policy notifier
49-622.1 CPUFreq policy notifier
새 policy가 생성되거나 제거될 때 이 notifier가 호출됩니다.
Phase는 notifier의 두 번째 argument로 지정합니다. Policy가 처음 생성될 때는 `CPUFREQ_CREATE_POLICY`, 제거될 때는 `CPUFREQ_REMOVE_POLICY`입니다.
세 번째 argument인 `void *pointer`는 여러 값을 포함한 `struct cpufreq_policy`를 가리킵니다. 여기에는 새 policy의 lower frequency와 upper frequency를 kHz 단위로 나타내는 `min`과 `max`가 포함됩니다.
2.2 CPUFreq transition notifier
63-822.2 CPUFreq transition notifier
CPUfreq driver가 CPU core frequency를 전환하고 그 변경에 외부 영향이 없을 때, policy 안의 online CPU마다 두 번씩 이 notifier가 호출됩니다.
두 번째 argument는 phase를 지정하며 `CPUFREQ_PRECHANGE` 또는 `CPUFREQ_POSTCHANGE`입니다.
세 번째 argument는 다음 값을 가진 `struct cpufreq_freqs`입니다.
| 필드 | 의미 |
|---|---|
| policy | `struct cpufreq_policy`를 가리키는 pointer |
| old | 이전 frequency |
| new | 새 frequency |
| flags | cpufreq driver의 flag |
3. OPP를 이용한 CPUFreq table 생성
83-1103. Operating Performance Point (OPP)를 이용한 CPUFreq table 생성
OPP의 자세한 내용은 `Documentation/power/opp.rst`를 참조하십시오.
`dev_pm_opp_init_cpufreq_table`은 사용 가능한 frequency에 관한 OPP layer의 내부 정보를 cpufreq에 바로 제공할 수 있는 형식으로 변환하는 준비된 routine입니다.
Warning: `dev_pm_opp_init_cpufreq_table`을 interrupt context에서 사용하지 마십시오.
예제:
soc_pm_init()
{
/* Do things */
r = dev_pm_opp_init_cpufreq_table(dev, &freq_table);
if (!r)
policy->freq_table = freq_table;
/* Do other things */
}
Note: 이 함수는 `CONFIG_PM_OPP`와 함께 `CONFIG_CPU_FREQ`도 활성화된 경우에만 사용할 수 있습니다.
CPUFreq table 해제
111-113`dev_pm_opp_free_cpufreq_table`은 `dev_pm_opp_init_cpufreq_table`이 할당한 table을 해제합니다.
요약과 해설
core.rst:1-113CPUFreq core는 `drivers/cpufreq/cpufreq.c`에서 frequency transition driver와 변경 통지 사용자를 연결하고, policy 수명과 `loops_per_jiffy` 갱신을 관리합니다.
Policy notifier는 policy 생성·제거를, transition notifier는 각 online CPU의 frequency 변경 전후를 알립니다. 각 notifier의 phase와 payload structure를 구분해야 합니다.
OPP integration은 `dev_pm_opp_init_cpufreq_table`로 frequency table을 만들고 `dev_pm_opp_free_cpufreq_table`로 해제합니다. 초기화 함수는 interrupt context에서 사용할 수 없습니다.