Part 1
요약·해설
Kernel idle 진입부터 state 선택, device suspend, SoC 전환과 wake-up까지의 흐름을 설명합니다.
Kernel idle
Residency · Application
State locks
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
4151C8C0738F36B693801D1095FDE984E4777EBA8991A025C6C739AE09715485
.. _pm-system:
System Power Management
#######################
Introduction
************
The kernel enters the idle state when it has nothing to schedule.
Enabling :kconfig:option:`CONFIG_PM` allows the kernel to call upon the
power management subsystem to put an idle system into one of the supported power states.
The kernel requests an amount of time it would like to suspend, then the PM subsystem decides
the appropriate power state to transition to based on the configured power management policy.
It is the application's responsibility to set up a wake-up event.
A wake-up event will typically be an interrupt triggered by an SoC peripheral module.
Examples include a SysTick, RTC, counter, or GPIO.
Keep in mind that depending on the SoC and the power mode in question,
not all peripherals may be active, and therefore
some wake-up sources may not be usable in all power modes.
The following diagram describes system power management:
.. graphviz::
:caption: System power management
digraph G {
compound=true
node [height=1.2 style=rounded]
lock [label="Lock interruptions"]
config_pm [label="CONFIG_PM" shape=diamond style="rounded,dashed"]
forced_state [label="state forced ?", shape=diamond style="rounded,dashed"]
config_system_managed_device_pm [label="CONFIG_PM_DEVICE" shape=diamond style="rounded,dashed"]
config_system_managed_device_pm2 [label="CONFIG_PM_DEVICE" shape=diamond style="rounded,dashed"]
pm_policy [label="Check policy manager\nfor a power state "]
pm_suspend_devices [label="Suspend\ndevices"]
pm_resume_devices [label="Resume\ndevices"]
pm_state_set [label="Change power state\n(SoC API)" style="rounded,bold"]
pm_system_resume [label="Finish wake-up\n(SoC API)\n(restore interruptions)" style="rounded,bold"]
k_cpu_idle [label="k_cpu_idle()"]
subgraph cluster_0 {
style=invisible;
lock -> config_pm
}
subgraph cluster_1 {
style=dashed
label = "pm_system_suspend()"
forced_state -> config_system_managed_device_pm [label="yes"]
forced_state -> pm_policy [label="no"]
pm_policy -> config_system_managed_device_pm
config_system_managed_device_pm -> pm_state_set:e [label="no"]
config_system_managed_device_pm -> pm_suspend_devices [label="yes"]
pm_suspend_devices -> pm_state_set
pm_state_set -> config_system_managed_device_pm2
config_system_managed_device_pm2 -> pm_resume_devices [label="yes"]
config_system_managed_device_pm2 -> pm_system_resume [label="no"]
pm_resume_devices -> pm_system_resume
}
{rankdir=LR k_cpu_idle; forced_state}
pm_policy -> k_cpu_idle [label="PM_STATE_ACTIVE\n(no power state meet requirements)"]
config_pm -> k_cpu_idle [label="no"]
config_pm -> forced_state [label="yes" lhead="cluster_1"]
pm_system_resume:e -> lock:e [constraint=false lhed="cluster_0"]
}
Power States
============
The power management subsystem defines a set of states described by the
power consumption and context retention associated with each of them.
The set of power states is defined by :c:enum:`pm_state`. In general, lower power states
(higher index in the enum) will offer greater power savings and have higher wake latencies.
Power Management Policies
=========================
The power management subsystem supports the following power management policies:
* Residency based
* Application defined
The policy manager is the component of the power management subsystem responsible
for deciding which power state the system should transition to.
The policy manager can only choose between states that have been defined for the platform.
Other constraints placed upon the decision may include locks disallowing certain power states,
or various kinds of minimum and maximum latency values, depending on the policy.
More details on the states definition can be found in the
:dtcompatible:`zephyr,power-state` binding documentation.
Residency
---------
Under the residency policy, the system will enter the power state which offers the highest
power savings, with the constraint that the sum of the minimum residency value (see
:dtcompatible:`zephyr,power-state`) and the latency to exit the mode must be
less than or equal to the system idle time duration scheduled by the kernel.
Thus the core logic can be summarized with the following expression:
.. code-block:: c
if (time_to_next_scheduled_event >= (state.min_residency_us + state.exit_latency)) {
return state
}
Application
-----------
The application defines the power management policy by implementing the
:c:func:`pm_policy_next_state` function. In this policy, the application is free
to decide which power state the system should transition to based on the
remaining time until the next scheduled timeout.
An example of an application that defines its own policy can be found in
:zephyr_file:`tests/subsys/pm/power_mgmt/`.
.. _pm-policy-power-states:
Policy and Power States
------------------------
The power management subsystem allows different Zephyr components and
applications to configure the policy manager to block the system from transitioning
into certain power states. This can be used by devices when executing tasks in
background to prevent the system from going to a specific state where it would
lose context. See :c:func:`pm_policy_state_lock_get`.
Examples
========
Some helpful examples showing different power management features:
* :zephyr_file:`samples/boards/stm32/power_mgmt/blinky/`
* :zephyr_file:`samples/boards/esp32/deep_sleep/`
* :zephyr_file:`samples/subsys/pm/device_pm/`
* :zephyr_file:`tests/subsys/pm/power_mgmt/`
* :zephyr_file:`tests/subsys/pm/power_mgmt_soc/`
* :zephyr_file:`tests/subsys/pm/power_states_api/`
Part 3
한국어 전문 번역
Introduction
Kernel은 schedule할 일이 없으면 idle state로 들어갑니다. CONFIG_PM을 활성화하면 kernel이 power management subsystem을 호출해 idle system을 지원되는 power state 중 하나로 전환할 수 있습니다. Kernel은 suspend하려는 시간을 전달하고, PM subsystem은 설정된 policy를 바탕으로 적절한 state를 고릅니다.
Wake-up event를 준비하는 책임은 application에 있습니다. 보통 SysTick, RTC, counter, GPIO 같은 SoC peripheral interrupt를 사용합니다. 다만 SoC와 power mode에 따라 일부 peripheral이 꺼질 수 있으므로 모든 wake-up source가 모든 mode에서 동작하는 것은 아닙니다.
CONFIG_PM 확인k_cpu_idle()일반 CPU idle 실행pm_system_suspend()강제 state가 없으면 policy manager가 state 선택PM_STATE_ACTIVE조건을 만족하는 절전 state가 없으면 CPU idleCONFIG_PM_DEVICE에 따라 device suspendpm_system_resume()Power States
PM subsystem은 power consumption과 context retention 정도로 구분되는 state 집합을 pm_state enum에 정의합니다. 일반적으로 enum index가 큰 더 낮은 power state일수록 절감량은 커지고 wake latency도 길어집니다.
Power Management Policies
PM subsystem은 residency-based policy와 application-defined policy를 지원합니다. Policy manager는 platform에 정의된 state 중에서만 전환 대상을 선택하며, 특정 state를 막는 lock과 policy별 최소·최대 latency constraint도 고려합니다. State 정의의 자세한 형식은 zephyr,power-state devicetree binding에 있습니다.
Residency
Residency policy는 kernel이 계산한 다음 scheduled event까지의 idle 시간이 해당 state의 최소 체류 시간과 exit latency의 합 이상인 범위에서 가장 절전 효과가 큰 state를 선택합니다.
if (time_to_next_scheduled_event >= (state.min_residency_us + state.exit_latency)) {
return state
}
Application
Application-defined policy에서는 application이 pm_policy_next_state()를 구현합니다. 다음 scheduled timeout까지 남은 시간과 application 고유 조건을 사용해 전환할 state를 자유롭게 정할 수 있습니다. 예제는 tests/subsys/pm/power_mgmt/에 있습니다.
Policy and Power States
Zephyr component와 application은 policy manager가 특정 power state로 전환하지 못하도록 lock을 걸 수 있습니다. Background task 중 context를 잃는 state를 피해야 하는 device라면 pm_policy_state_lock_get()으로 해당 state를 차단하고 작업이 끝난 뒤 대응하는 put API로 해제합니다.
Examples
System·device PM, deep sleep, SoC PM과 power-state API 예제는 다음 source tree에 있습니다.
samples/boards/stm32/power_mgmt/blinky/samples/boards/esp32/deep_sleep/samples/subsys/pm/device_pm/tests/subsys/pm/power_mgmt/tests/subsys/pm/power_mgmt_soc/tests/subsys/pm/power_states_api/
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.