Subsys/Sensor Power Management Usage #66059
Replies: 4 comments 7 replies
-
I agree with the axioms and as far as I understand they are achievable today using a building block approach, where complex subsystems control the device pm (since it is referenced counted). My concern in making this distinction, simple/complex APIs is that devices can behave different. Some device may need to wait some event before suspending (or something similar) that the subsystem does not know. That's said, this approach definitely introduce an overhead, there will be multiple put/get calls that will just increase/decrease reference count. But do we have numbers to confirm this is a problem ? Sensors are probably the most sensitive to this approach, but it is not clear if that is a major performance problem. |
Beta Was this translation helpful? Give feedback.
-
Sensor WG 12/4/2023: Flavio: We should do get/put in all calls, if power is needed to stay on the caller can also use get/put |
Beta Was this translation helpful? Give feedback.
-
The biggest problem with sensors (if I understood correctly) is that some operations are not persistent (and/or are too cost) across power states changes and neither the subsystem or driver have control of this. e.g: application can set an attribute and use it only later on in a different context. In this situation, the application should be pm aware. So we have two paths:
|
Beta Was this translation helpful? Give feedback.
-
What I was referring to in the meeting: https://www.kernel.org/doc/Documentation/power/runtime_pm.txt
|
Beta Was this translation helpful? Give feedback.
-
Topic
How should applications and subsystems interact with lower level API's in the context of power management
Note this document is only concerned with device runtime PM (
CONFIG_PM_DEVICE_RUNTIME
,pm_device_runtime_get
,pm_device_runtime_put
) as device PM should never be used directly on devices.Point to resolve
According to Device Power Management, devices need to be in
PM_DEVICE_STATE_ACTIVE
to perform useful work. For an application concerned about power consumption, the default state of a device will bePM_DEVICE_STATE_OFF
orPM_DEVICE_STATE_SUSPEND
, depending on hardware configuration.Therefore the device needs to transition to
PM_DEVICE_STATE_ACTIVE
when it is performing work. There are two potential methods to transition.Implicit Transitions
The act of calling an API function (e.g.
flash_read
) automatically requests the device to be in active mode at the start of a function, and releases that request at the end of the function.Advantages:
Disadvantages:
ACTIVE
andSUSPEND
on every call, potentially losing internal stateExplicit Transitions
Users of an API function are required to ensure the device is in active mode before calling API functions.
Advantages:
ACTIVE
as long as required)Disadvantages:
Axioms
If function calls or ordering need to differ based on the backend implementing the API, then all advantages of having a common API disappear.
It is okay for the usage patterns to differ between API's, as long as the pattern within an API is consistent (See 1).
Whether calling
uart_rx
orsensor_fetch
, the user is always in a position to know that the device needs to be active, as they are asking the API to do something. This does not mean that the user should always need to manually control PM, just that it is possible.The Entropy API has two function calls, independent of each other, with no pre or post call requirements.
The Sensor API has a range of synchronous and asynchronous function calls, with the result of function calls (
sensor_channel_get
,sensor_channel_fetch
, etc) depending on the contents of previous function calls (sensor_attr_set
,sensor_channel_fetch
, etc). Furthermore, there is no function that explicitly 'starts' or 'ends' usage.Code can't break depending on whether
CONFIG_PM_DEVICE_RUNTIME
is enabled or not, whether the backend device supports PM, or whether PM is enabled on the backend device. Happily this is provided out of the box by the runtime PM implementation, PM calls always return success in every case where device runtime PM is not enabled on a device.General Thoughts
From a users perspective, the implicit mechanism is cleaner. They don't need to think about power management and the logic is all contained within the driver. Additionally, if the user wants to minimise transitions between
ACTIVE
andSUSPEND
, they can always wrap N API calls withpm_device_runtime_get/put
themselves, as demonstrated below:The problems appear when API calls aren't self-contained, but instead depend on previous calls.
If PM in this situation is implicit, and the sensor device loses state when in suspend mode, then any value set in the
sensor_attr_set
call will be lost in a naive driver. This forces any sensor with this behaviour to cache any and all attributes in RAM, and either apply every attribute in thefetch
implementation, or every time it transitions toACTIVE
mode (every function call in implicit mode). This is a significant overhead.Proposal
For the purposes of power management, split APIs into two classes, simple and complex (defined below).
Simple APIs can be documented as implementing the easier to use 'implicit transition' method (which still enabled explicit control for optimisation as mentioned previously).
Complex APIs are documented as requiring power management to be externally controlled. This eliminates the requirement for drivers to perform complex guesswork about when the device really needs to be powered, and eliminates the need to cache device parameters in RAM, as we can assume that the device will not be powered down until it is no longer in use.
Simple APIs
A simple API is one in which function calls in the API are independent from each other. Examples:
Complex APIs
A complex API is one in which function calls in the API depend on each other, and potentially asynchronous external events: Examples:
Beta Was this translation helpful? Give feedback.
All reactions