Rename the PM_STATE_INFO_DT_ITEMS_LIST macro to
PM_STATE_INFO_LIST_FROM_DT_CPU to make its purpose more clear. Similar
naming scheme is found e.g. in the GPIO API.
Associated internal macros and docstrings have been adjusted, too.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The type qualifier of the return type is causing warnings if
-Wignored-qualifiers, and it's irrelevant anyways since
the function returns a value and not a pointer
Signed-off-by: Emil Lindqvist <emil@lindq.gr>
Correct an issue that prevents CONFIG_TRACING and CONFIG_PM_DEVICE to be
enabled at the same time.
Signed-off-by: Abe Kohandel <abe.kohandel@gmail.com>
Since drivers implement a callback based on action and not the state,
we should be using the API based on the action instead of the one based
on the state.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Devices PM callback receive an action and not a state. Add a new API
that receives an action instead of a state.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
- Rename time start/stop variables
- Use uint8_t vs. int as loop index variable type
- Flag unused variables
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Stats are an optional feature, moving it into a separate source file
improves code readability.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Replace PM_STATE_LEN with PM_STATE_COUNT, so that number of states is
automatically computed.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
LOG_MODULE_DECLARE was referring to power name which was renamed
to pm by faa06ac. This results in compilation failure.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
It is well known that PM subsystem has never been optimized in terms of
resource usage. The situation is particularly bad in case the PM runtime
API is enabled. What this patch does is to move the responsability of PM
resource definition to the device like this:
- Device is responsible to define PM resources, using a new set of
macros: PM_DEVICE_*DEFINE().
- DEVICE_*DEFINE macro accepts a reference to the device PM state, which
can be obtained using PM_DEVICE_*REF() set of macros. This
allows device to initialize the dev->pm reference.
This method decouples a bit more PM from devices since devices just keep
a reference to the device PM state. It also means that future PM changes
will have less chances to impact all devices, but only devices that
support PM.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Do not have the "forced" bit cleared up scattered across the function.
Do it only in one place at the exit of the function.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Change pm_power_state_force to receive which cpu the state should be
forced. Also, it changed the API behavior to force the given state only
when the idle thread for that core is executed.
In a multicore environment force arbitrarily a core to suspend is not
safe because the kernel cannot infer what that cpu is running and how it
impacts the overall system, for example, if it is holding a lock that is
required by a thread that is running in another cpu.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
_handle_device_abort is only called in one place and it basically does
two instructions. Just remove it.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
On smp environment, we cannot do device power management based only on
the state the current core. For example, do not suspend devices if
there are other cores active, or resume devices if there are other
cores already active.
This change ensure that devices are only suspend when the last active
core become idle and that these devices are resumed only when the first
core becomes active.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Instead of returning PM_STATE_ACTIVE for when the cpu didn't enter a
low power state and a different state when it entered, but has
already left the state and is active again, it changes
pm_system_suspend to return true when the cpu has entered a low power
state and false otherwise.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Each CPU can have its own set of states. Update the policy to get them
from DT and account it when return the best state to the kernel.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Currently power management subsystem uses a global variable to hold
power state. On multicore environment this is a problem and we have to
have this information per core.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Move all PM device runtime API calls from pm_device* to the
pm_device_runtime* namespace.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This patch refactors the runtime API to make it more clear and simple.
Relevant changes:
- API uses the action callback in a direct manner, avoiding unnecessary
overhead.
- API documentation has been improved to include detailed return error
codes.
- pm_runtime_disable() is now synchronous (to simplify possible error
paths) and returns error in case it fails. It is also safe to disable
in pre-kernel now.
- pm_runtime_put(_async)() will return -EALREADY if called with usage
count at zero (result of an unbalanced get/put call sequence)
- A transitional state has been added back. This makes code more
readable, and avoids using atomics (not required).
TODO:
- Solve in a better manner the asynchronous suspend error path (now
"solved" using asserts).
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
After the removal of pm_device_get_async, the pm_device_wait API has
become redundant. Its usage after pm_device_put_async should not be
considered a valid usecase, since after that call what will happen is a
pm_device_get (which is blocking).
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
As of today there is no clear usage of asynchronous gets, since in
general, a resume operation should be synchronous (we are about to use
the device immediately after resuming it). Removing this API simplifies
the runtime implementation in a significant way (refer to future
commits).
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Move functions around so it is not necessary to keep a header
that with functions declaration that is just used in one single
place.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
List of improvements:
- The PM logging module was only available if CONFIG_PM=y, however, it
was also used by Device PM (which can be selected without PM). A new
logging module has been created for Device PM.
- Log level is passed to LOG_MODULE_(DECLARE|REGISTER)
- Logger name has been adjusted to `pm` (was `power`)
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
POLL is not a dependency of runtime device PM since it now uses
conditional variables to notify waiting threads.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
SYS_POWER_MANAGEMENT and DEVICE_POWER_MANAGEMENT were deprecated in
2.5.0, remove them now.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
There is not need to handle all power states in switch state after
remove lower power and off states for devices.
Also, it incorporates the fix done in pull/38873.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
As discussed in issues/38619, this commit aims to simplify device
power management. It was removed PM_DEVICE_SATE_LOW_POWER.
The power subsystem now doesn't need to figure out which device state to
use of a given system power state. It just suspend and resume devices.
Devices now just need to respond to ACTIVE and SUSPEND and OFF actions
and they are free to use any particular substate they have when the
subsystem asks to suspend. They also don't need to worry about states
transitions (unless they have multiple substates) because the system
will just request them to suspend if they are active and vice-versa.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
rebase
Add a function that can be used by device drivers to know
what will be next power state used by the SoC.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Uses the stats subsys to provide simple but useful debugging stats for
power management state changes and timing.
Removes the no longer needed PM_DEBUG config option
Replaces the use of PM_DEBUG for a test clock output pin for mec1501 and
adds in its place an SoC Kconfig option to enable it.
Adds a STATS_SET macro for assigning a value to a stat group field
Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
- Rename to "action" to make its purpose more clear
- Use the _cb suffix to align with naming used for callbacks in other
areas.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Accessing members from pm_device improves code readability, since it
removes dev-> from most accesses.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Some includes were already performed by the device(_runtime).h header/s,
others like were not necessary.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>