Commit graph

335 commits

Author SHA1 Message Date
Gerard Marull-Paretas
fa96955305 pm: state: PM_STATE_INFO_DT_ITEMS_LIST->PM_STATE_INFO_LIST_FROM_DT_CPU
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>
2021-12-04 12:33:57 -05:00
Emil Lindqvist
5af3bbb27b pm: remove irrelevant type qualifier on pm_power_state_next_get
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>
2021-12-01 14:03:55 -06:00
Flavio Ceolin
54176127ec pm: Fix idle post ops on multicore
Post operations have to be tracked per cpu.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-29 19:37:55 -05:00
Flavio Ceolin
623ed5ae29 pm: Remove invalid comments
Remove comments referencing an old function / behavior.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-29 19:37:55 -05:00
Abe Kohandel
6c914ded79 pm: tracing: Correct compilation for tracing
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>
2021-11-29 18:18:29 -05:00
Flavio Ceolin
6451626ce7 pm: Use pm_device_action_run instead of state_set
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>
2021-11-24 14:21:50 -05:00
Flavio Ceolin
9adffd620a pm: device: Add pm_device_action_run
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>
2021-11-24 14:21:50 -05:00
Gerard Marull-Paretas
220cda63a8 pm: pm_ctrl.c -> constraint.c
Rename source file to be more explicit on its content.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-23 18:12:15 +01:00
Gerard Marull-Paretas
ec8f0ac2a9 pm: power.c -> pm.c
Rename system PM source file to align with naming used by
Kconfig/headers.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-23 18:12:15 +01:00
Gerard Marull-Paretas
5e15640ec7 pm: stats: use pm_stats prefix
Use pm_stats prefix instead of pm_cpu_stats (to align with Kconfig/API
naming).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-23 18:12:15 +01:00
Gerard Marull-Paretas
8893d33539 pm: stats: minor cleanups
- 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>
2021-11-23 18:12:15 +01:00
Gerard Marull-Paretas
e6b884982f pm: stats: pm_(start|stop)_timer -> pm_stats_(start|stop)
Improve the naming of the start/stop functions.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-23 18:12:15 +01:00
Gerard Marull-Paretas
7baed3dd3e pm: move stats code into its own file
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>
2021-11-23 18:12:15 +01:00
Gerard Marull-Paretas
cd7ae8ea62 pm: define PM_STATE_COUNT to obtain number of states
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>
2021-11-23 18:12:15 +01:00
Krzysztof Chruscinski
a10d2b418c pm: policy: Fix logging module name
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>
2021-11-22 08:30:33 -05:00
Gerard Marull-Paretas
e2f33dd97c pm: optimize resource usage
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>
2021-11-19 10:11:32 +01:00
Flavio Ceolin
252aaf7637 pm: suspend: Simplify exit logic
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>
2021-11-18 13:56:15 +01:00
Flavio Ceolin
4998c52ba8 pm: Make pm_power_state_force multicore aware
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>
2021-11-18 13:56:15 +01:00
Flavio Ceolin
c34df149ae pm: Fix device resume order
This fix was previously done in 82a6104808
but the commit 81f1225040 re-introduced
the problem.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-09 19:57:59 -05:00
Flavio Ceolin
9452650aff pm: Handle devices with device runtime enabled
Do not suspend a device if it has device runtime enabled.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-08 19:54:12 -05:00
Flavio Ceolin
b2aa5feb9d pm: device: runtime: Add API to check if it is enabled
Add a new API to check if a device has device runtime feature enabled.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-08 19:54:12 -05:00
Flavio Ceolin
b83128e169 pm: Keep track of active states on state_force
Update z_cpu_active in pm_power_state_force

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-06 10:21:53 -04:00
Flavio Ceolin
d3a1549ba2 pm: Keep cpu power state consistent
Set the cpu state to ACTIVE after it resumes.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-06 10:21:53 -04:00
Flavio Ceolin
05c17b8443 pm: Remove _handle_device_abort
_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>
2021-11-06 10:21:53 -04:00
Flavio Ceolin
9ddcf255bd pm: smp: Properly handle device pm on SMP
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>
2021-11-06 10:21:53 -04:00
Flavio Ceolin
9444480c7b pm: Better return type for pm_system_suspend
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>
2021-11-06 10:21:53 -04:00
Flavio Ceolin
8c3d9afed7 pm: Change pm_power_state_next_get to support SMP
Change the API to account multiple CPUs.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-06 10:21:53 -04:00
Flavio Ceolin
bd83a46a56 pm: policy: residency: Support multiple CPUs
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>
2021-11-06 10:21:53 -04:00
Flavio Ceolin
dd152c2b89 pm: policy: Add cpu information in the API
On multicore environments the policy may need to know which CPU is
idle.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-06 10:21:53 -04:00
Flavio Ceolin
9765e93064 pm: Track power state per cpu
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>
2021-11-06 10:21:53 -04:00
Flavio Ceolin
e05247a789 pm: Change post_ops_done type to boolean
Boolean is more appropriate to this variable and it is aligned with
Zephyr's code guideline.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-11-06 10:21:53 -04:00
Gerard Marull-Paretas
b5e1ec60be pm: device: adjust flag names
Some flags were using `FLAGS` instead of `FLAG`.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-04 16:49:08 +01:00
Gerard Marull-Paretas
1cee284a46 pm: device: runtime: use pm_device_runtime* namespace
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>
2021-11-03 16:37:33 -04:00
Gerard Marull-Paretas
eed8bd9c61 pm: device: runtime: refactor API
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>
2021-11-03 16:37:33 -04:00
Gerard Marull-Paretas
e3fece5241 pm: device: runtime: remove pm_device_wait
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>
2021-11-03 16:37:33 -04:00
Gerard Marull-Paretas
30d217aa28 pm: device: runtime: remove pm_device_get_async
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>
2021-11-03 16:37:33 -04:00
Flavio Ceolin
81f1225040 pm: device: Remove the need of a private header
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>
2021-10-29 07:52:06 -04:00
Gerard Marull-Paretas
eea4eaccd6 pm: adjust PM_DEVICE prompt
Other prompts are use Capitalized Words.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-10-28 13:00:13 +02:00
Gerard Marull-Paretas
9398d0647b pm: rename HAS_NO_SYS_PM to HAS_NO_PM
Align name with other Kconfig options (CONFIG_PM).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-10-28 13:00:13 +02:00
Gerard Marull-Paretas
faa06ac4b1 pm: improve logging
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>
2021-10-28 13:00:13 +02:00
Gerard Marull-Paretas
e3ce7859db pm: device: runtime: remove dependency on POLL
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>
2021-10-28 13:00:13 +02:00
Gerard Marull-Paretas
92b338e239 pm: remove deprecated Kconfig options
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>
2021-10-28 13:00:13 +02:00
Flavio Ceolin
e6d832d8b9 pm: Simplify pm_system_suspend
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>
2021-10-26 15:02:15 -05:00
Flavio Ceolin
9239fd4a90 pm: device: Simplify device pm states
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
2021-10-26 15:02:15 -05:00
Flavio Ceolin
a507f60390 pm: Add a new function to query the next power state
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>
2021-10-26 15:02:15 -05:00
Tom Burdick
f523c336ef pm: Use stats subsys for tracking system states
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>
2021-10-17 10:56:21 -04:00
Gerard Marull-Paretas
82d7d3c5c9 pm: rename pm_control(_fn) to (pm_)action_cb
- 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>
2021-10-14 07:55:55 -04:00
Gerard Marull-Paretas
3ca6d9503c pm: move control callback to pm_device
Move PM specific callback to the pm_device structure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-10-14 07:55:55 -04:00
Gerard Marull-Paretas
a78ee67b61 pm: device: access members of pm_device directly
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>
2021-10-14 07:55:55 -04:00
Gerard Marull-Paretas
b748a7eaf6 pm: device: remove unnecessary includes
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>
2021-10-14 07:55:55 -04:00