Keep the original architecture IRQ key owned by idle across a
successful system PM transition.
Add architecture hooks and the PM_STATE_SET_IRQ_LOCKED migration
contract for SoCs that keep PM hooks from unmasking interrupts.
Signed-off-by: Holt Sun <holt.sun@nxp.com>
When `pm_device_runtime_put*()` is called on a device whose usage
count is already zero, `runtime_suspend()` emits "Unbalanced suspend"
at warning level. The message does not include the device name,
so on a system with many runtime-managed devices the warning gives
no hint which call site to fix.
Add `dev->name` to the log message, matching the style of the
neighbouring debug logs in the file.
Signed-off-by: Petr Hlineny <development@hlineny.cz>
sys_clock_set_timeout() and sys_clock_elapsed() are now documented
as requiring the system clock lock to be held by the caller. Wrap
the calls in subsys/pm/pm.c, soc/nxp/rw/power.c and the kernel
shell thread list command with sys_clock_lock()/sys_clock_unlock().
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Power managed devices should be able to return -EBUSY at
pm_action() (driver) calls without generating error log messages.
Suppress such error messages to allow the driver to decide at
sleep time if it still is unable to suspend, without generating
log noise.
Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
Introduce enum pm_device_deps_region to replace the magic number
used when iterating through device dependency array regions in
power_domain_add_or_remove().
Signed-off-by: Yongxu Wang <yongxu.wang@nxp.com>
Add error logging in pm_resume_devices() to report when a device
fails to resume. This improves debuggability by making resume
failures visible in the system log.
Signed-off-by: Yongxu Wang <yongxu.wang@nxp.com>
Only define variable for enabled CPU Core to fix the following building
warning in case of any CPU Core is not enabled but with "cpu-power-states"
dts node property:
zephyr/subsys/pm/state.c:15:43: warning: 'pmstates_DT_N_S_cpus_S_cpu_0'
defined but not used [-Wunused-const-variable=]
Signed-off-by: Jiafei Pan <Jiafei.Pan@nxp.com>
Only set state to ACTIVE after RESUME succeeds, if it fails,
keep SUSPENDED STATE and attach an error code.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
It turns out that power_domain_add_or_remove() when add==true only
looks for DEVICE_HANDLE_NULL empty slots to write to, and never checks
"whether this dev_handle is already in the supported handles or not".
The result is: repeated adds may insert duplicate entries; or when
there are no empty slots, even though it's "already in the domain",
it returns -ENOSPC (which conflicts with the documented semantics).
This commit adds a check: when add==true and rv[i] == dev_handle is
found, it returns -EALREADY and avoids duplicate insertion.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
The comment definition for pm_policy_latency_request_add
states: states that exceed the given latency are unavailable.
However, the implementation in pm_policy_latency_update_locked
does not use the greater-than operator, so according to the
semantics, it should be changed to > to be consistent.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
The comment for the API pm_policy_latency_changed_subscribe
states: "NULL to disable", but the function implementation
directly saves and subscribes to this node, and subsequently
calls it directly without null checking when changes occur.
This actually poses a risk of calling a null function pointer.
This commit fixes this issue to make the function implementation
consistent with the API description.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
Use ARRAY_SIZE macro to determine the size of the pm_constraints
array instead of DT_PROP_LEN. Because a practical issue is that
'zephyr, disabling-power-states' may contain multiple power states,
but one of the power states is in a disabled status. In this case,
the size obtained by DT_PROP_LEN is larger than the actual size.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
1. Updated event-related API docs to fix wording and clarify
semantics ("earliest/soonest event", ticks vs cycles).
2. Improve the event implementation to prevent list corruption on misuse:
- pm_policy_event_register() is now idempotent: re-registering
the same evt updates its time instead of appending a duplicate node.
- pm_policy_event_update() / pm_policy_event_unregister() become clean
no-ops if evt is not currently registered.
- Kept a basic evt != NULL assertion.
Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
The "@funcprops" Doxygen alias was originally introduced to list all
the function properties that apply to a given function (e.g. isr_ok,
etc.) in the form of a bullet list. However, since commit a258ab32d1
that is no longer the case and all the properties are rendered as
qualifiers (https://www.doxygen.nl/manual/commands.html#cmdqualifier)
and therefore no longer need to be grouped in a separate list.
This commit also ensure all aliases for the actual qualifiers use
`@qualifier` notation instead of `\qualifier` to be consistent with
our Doxygen guidelines.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
next_event should not be global. This can cause
linkage conflicts if another file defines a symbol
with the same name.
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
Add an optional power policy hook to provide custom "next event"
ticks during pm_system_suspend(), in addition to the existing
kernel ticks and policy event list.
This hook enables applications and SoC-specific code to derive
the next wake-up time directly from proprietary or
hardware-specific data structures (e.g. hardware registers,
binary-only modules, complex schedulers) that are not
practical to convert into the standard PM policy event list.
The feature is gated by CONFIG_PM_CUSTOM_TICKS_HOOK and is fully
backwards compatible when disabled.
Signed-off-by: Alessandro Manganaro <alessandro.manganaro@st.com>
In pm_system_suspend there is a possible invalid type promotion
in sys_clock_set_timeout(MAX(0, ticks - exit_latency_ticks), true);
ticks is int32_t and exit_latency_ticks is uint32_t consequently
ticks is promoted to uint32_t resulting in a possible underflow and
setting a wrong value in sys_clock_set_timeout().
Fixes#100005
Coverity CID: 535628
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
In pm_device_runtime_get, when resume fails after the domain as claimed,
the flag PM_DEVICE_FLAG_PD_CLAIMED is not cleared (but the domain is
released). This leaves this flag in a consistent state and in a further
resume this device won't resume its domain leading to bigger problems.
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
Fix the power domain claiming condition which was inverted, causing
domains to be claimed when they were already claimed instead of when
they weren't. Add null check for power domain before accessing its
properties to prevent potential null pointer dereference. Also ensure
the PD_CLAIMED flag is properly cleared when putting the power domain.
Signed-off-by: Albort Xue <yao.xue@nxp.com>
pm_policy_priv_device_find_device_constraints() function
is available only when zephyr_power_state is defined.
Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
Add test case that validates behavior of pm_policy_state_all_lock_get
and pm_policy_state_all_lock_put.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Add function for getting and putting a lock for all power states.
It is much faster version of requesting 0 us latency with actual
intention to disable all power states.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This check is totally wrong, min-residency-us and exit-latency-us are
not related to each other at all except that the end of the residency
period occurs when the exit starts, so they are totally orthogonal
values and should not be checking if one is less than the other or
anything like this. Even in the code for the default policy manager,
they are added together, so this check is incompatible / in disagreement
with that code, so it should be removed.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Some pieces of the system may have custom types of constraints that they
define based on different effects and reasons than just the standard
"zephyr,disabling-states". To avoid every single one of these component
reinventing the wheel, make some common APIs to handle these type of
custom constraint lists.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
I am surprised this notifier didn't already report the substate id, it
seems important since different substate obviously are defined for a
reason, they can be having a different effect on the system.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Mark pm_device_driver_init() as a boot function to support using it
for early init on devices with demand paging.
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
The config PM_S2RAM_CUSTOM_MARKING is not an optional config for a
user to select, it is required by some soc implementations of S2RAM,
in which case it must be selected by the soc.
Refactor the configuration to be HAS_PM_S2RAM_CUSTOM_MARKING, and
make the currently only soc which needs it select it. Then update
samples which previously had to select this option for this soc.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Currently it is possible to have an enabled (status="okay")
"suspend-to-ram" "zephyr,power-state" in the devicetree,
CONFIG_PM=y, but CONFIG_PM_S2RAM=n
This means the presence and state of the "suspend-to-ram" power
state in the devicetree does not match the PM_S2RAM option,
despite PM_S2RAM being dependent on the devicetree state.
This commit makes the devicetree the "source of truth" for
whether one or more s2ram power states shall be included and
supported, by enabling PM_S2RAM if any s2ram power state with
status "okay" is present in the devicetree. To disable the
s2ram power state, like with any other state, disable it by
setting its state to "disabled".
The help of the now promptless PM_S2RAM config has been
updated to reflect the new meaning. It previously held
cortex-m specific implementation details, these have been
removed as these details are already present in the file
pointed to as well (arch/arm/core/cortex_m/pm_s2ram.c
line 22)
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
The k_event event is only used if CONFIG_PM_DEVICE_RUNTIME_ASYNC is
selected, but EVENTS is selected, and the k_event included in the
struct pm_device if CONFIG_PM_DEVICE_RUNTIME is selected.
Correct to only include event and EVENTS if
CONFIG_PM_DEVICE_RUNTIME_ASYNC is selected. This saves us 1
struct event per PM DEVICE.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Many SoCs which use PM_DEVICE_RUNTIME need every device in the system
to have PM_DEVICE_RUNTIME enabled to function. Currently, this is only
possible by adding zephyr,pm-device-runtime-auto; to every node in
every devicetree which could potentially implement device power
management. This is very error prone since its easy to miss a node,
especially if users apply overlays, where users need to know and
remember to apply or reapply this property.
This commit adds a Kconfig, disabled by default, which automatically
treats every device as if it had the zephyr,pm-device-runtime-auto
property added to every node.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Introduce a shell for specific cpu core about PM control,
this aligns with existing design flow where the policy decides
the state based on next event timing, locks and latency constraints,
and the system naturally enters low power through the idle thread.
New shell commands under `cpu`:
- cpu states : List supported CPU power states (from devicetree)
- cpu available : For each state/substate, show if available
- cpu lock : Lock specific low power mode
- cpu unlock : Unlock specific low power mode
- cpu idle ms : Sleep the current thread to let idle run PM
Signed-off-by: Yongxu Wang <yongxu.wang@nxp.com>
Add two helper functions to convert power management states between
enum and string:
- pm_state_to_string()
- pm_state_from_string()
Signed-off-by: Yongxu Wang <yongxu.wang@nxp.com>
If pm action fails within put_sync_locked, usage count should be
reset to reflect the state of the device.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
In the default PM policy, the function k_us_to_ticks_ceil32() is used
and does calculation using 64-bit integers which can be slow and
avoidable if the input is 0.
Signed-off-by: Bastien Beauchamp <bastien.beauchamp@silabs.com>
In a call to pm_device_runtime_get, if the power domain is taken but
action_cb fails, the power domain is not released.
Signed-off-by: Adrien Lessard <adrien.lessard@rbr-global.com>
More complex suspend and resume scheme might require exactly defined
location of this variable due to platform peculiar SW and HW requirement.
DTS zephyr,memory-region node with nodelabel `pm_s2ram` shall be used to
automatic definition of linker section for such objective.
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Introduce pm_device_driver_deinit() which is required to fully
support device_deinit(). This function shall be called by drivers
when device_deinit() is called.
If PM_DEVICE is enabled, it will
simply check whether the device is either SUSPENDED or OFF, this
will prevent device_deinit() on a device which is currently in
use, and ensure the device is in the correct state if device_init()
is called later.
If PM_DEVICE is not enabled, it will invoke the SUSPEND action which
mirrors the pm_device_driver_init() behavior. Note that TURN_OFF
action is not called since the device is deinitialized after this
call.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
K_TICKS_FOREVER is defined as -1. Guard logic has been added for the case
when `ticks - exit_latency_ticks == -1` to prevent sys_clock_set_timeout()
from incorrectly setting a forever timeout.
Signed-off-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com>
pm_device_runtime has inconsistent behavior regarding
getting and putting a device's domain. This commit
aligns it to get the domain only once, once device
is resumed, and put only once, once device is
suspended.
Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
Refactor this code so it has less nesting and is able to share some code
between functions, by making a function to find the device constraints
object which can be called before doing operations using it.
Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
Async now uses its own work queue, which means it consumes more
resources. Since not all applications need the async API, we can make
it optional without any penalty for those applications.
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
Device runtime is using the system workqueue to do operations
that are mostly blockers (suspend a device). This should not happen.
This commit adds an option to use dedicated queue for the device runtime
async operations.
The test for this API was assuming that the system workqueue
priority (which is cooperative) so we need to change the test priority
to be lower than the device runtime workqueue priority.
Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>