Skip to content

Commit b391fa7

Browse files
committed
[nrf fromtree] pm: policy: allow using latency API in standalone mode
This option allows using the pm_policy_latency* APIs to gather latency requirements on systems that do not support PM (e.g. systems whithout CPU idle states). Because the API has a subscription mechanism, it can be useful to perform system-level adjustments based on latency requirements gathered from multiple system components. Signed-off-by: Gerard Marull-Paretas <[email protected]> (cherry picked from commit 578008c)
1 parent f2db66c commit b391fa7

File tree

3 files changed

+78
-63
lines changed

3 files changed

+78
-63
lines changed

include/zephyr/pm/policy.h

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -137,49 +137,6 @@ void pm_policy_state_lock_put(enum pm_state state, uint8_t substate_id);
137137
*/
138138
bool pm_policy_state_lock_is_active(enum pm_state state, uint8_t substate_id);
139139

140-
/**
141-
* @brief Add a new latency requirement.
142-
*
143-
* The system will not enter any power state that would make the system to
144-
* exceed the given latency value.
145-
*
146-
* @param req Latency request.
147-
* @param value_us Maximum allowed latency in microseconds.
148-
*/
149-
void pm_policy_latency_request_add(struct pm_policy_latency_request *req,
150-
uint32_t value_us);
151-
152-
/**
153-
* @brief Update a latency requirement.
154-
*
155-
* @param req Latency request.
156-
* @param value_us New maximum allowed latency in microseconds.
157-
*/
158-
void pm_policy_latency_request_update(struct pm_policy_latency_request *req,
159-
uint32_t value_us);
160-
161-
/**
162-
* @brief Remove a latency requirement.
163-
*
164-
* @param req Latency request.
165-
*/
166-
void pm_policy_latency_request_remove(struct pm_policy_latency_request *req);
167-
168-
/**
169-
* @brief Subscribe to maximum latency changes.
170-
*
171-
* @param req Subscription request.
172-
* @param cb Callback function (NULL to disable).
173-
*/
174-
void pm_policy_latency_changed_subscribe(struct pm_policy_latency_subscription *req,
175-
pm_policy_latency_changed_cb_t cb);
176-
177-
/**
178-
* @brief Unsubscribe to maximum latency changes.
179-
*
180-
* @param req Subscription request.
181-
*/
182-
void pm_policy_latency_changed_unsubscribe(struct pm_policy_latency_subscription *req);
183140

184141
/**
185142
* @brief Register an event.
@@ -277,26 +234,6 @@ static inline bool pm_policy_state_lock_is_active(enum pm_state state, uint8_t s
277234
return false;
278235
}
279236

280-
static inline void pm_policy_latency_request_add(
281-
struct pm_policy_latency_request *req, uint32_t value_us)
282-
{
283-
ARG_UNUSED(req);
284-
ARG_UNUSED(value_us);
285-
}
286-
287-
static inline void pm_policy_latency_request_update(
288-
struct pm_policy_latency_request *req, uint32_t value_us)
289-
{
290-
ARG_UNUSED(req);
291-
ARG_UNUSED(value_us);
292-
}
293-
294-
static inline void pm_policy_latency_request_remove(
295-
struct pm_policy_latency_request *req)
296-
{
297-
ARG_UNUSED(req);
298-
}
299-
300237
static inline void pm_policy_event_register(struct pm_policy_event *evt, uint32_t cycle)
301238
{
302239
ARG_UNUSED(evt);
@@ -331,6 +268,72 @@ static inline int32_t pm_policy_next_event_ticks(void)
331268

332269
#endif /* CONFIG_PM */
333270

271+
#if defined(CONFIG_PM) || defined(CONFIG_PM_POLICY_LATENCY_STANDALONE) || defined(__DOXYGEN__)
272+
/**
273+
* @brief Add a new latency requirement.
274+
*
275+
* The system will not enter any power state that would make the system to
276+
* exceed the given latency value.
277+
*
278+
* @param req Latency request.
279+
* @param value_us Maximum allowed latency in microseconds.
280+
*/
281+
void pm_policy_latency_request_add(struct pm_policy_latency_request *req,
282+
uint32_t value_us);
283+
284+
/**
285+
* @brief Update a latency requirement.
286+
*
287+
* @param req Latency request.
288+
* @param value_us New maximum allowed latency in microseconds.
289+
*/
290+
void pm_policy_latency_request_update(struct pm_policy_latency_request *req,
291+
uint32_t value_us);
292+
293+
/**
294+
* @brief Remove a latency requirement.
295+
*
296+
* @param req Latency request.
297+
*/
298+
void pm_policy_latency_request_remove(struct pm_policy_latency_request *req);
299+
300+
/**
301+
* @brief Subscribe to maximum latency changes.
302+
*
303+
* @param req Subscription request.
304+
* @param cb Callback function (NULL to disable).
305+
*/
306+
void pm_policy_latency_changed_subscribe(struct pm_policy_latency_subscription *req,
307+
pm_policy_latency_changed_cb_t cb);
308+
309+
/**
310+
* @brief Unsubscribe to maximum latency changes.
311+
*
312+
* @param req Subscription request.
313+
*/
314+
void pm_policy_latency_changed_unsubscribe(struct pm_policy_latency_subscription *req);
315+
#else
316+
static inline void pm_policy_latency_request_add(
317+
struct pm_policy_latency_request *req, uint32_t value_us)
318+
{
319+
ARG_UNUSED(req);
320+
ARG_UNUSED(value_us);
321+
}
322+
323+
static inline void pm_policy_latency_request_update(
324+
struct pm_policy_latency_request *req, uint32_t value_us)
325+
{
326+
ARG_UNUSED(req);
327+
ARG_UNUSED(value_us);
328+
}
329+
330+
static inline void pm_policy_latency_request_remove(
331+
struct pm_policy_latency_request *req)
332+
{
333+
ARG_UNUSED(req);
334+
}
335+
#endif /* CONFIG_PM CONFIG_PM_POLICY_LATENCY_STANDALONE */
336+
334337
/**
335338
* @}
336339
*/

subsys/pm/policy/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ if(CONFIG_PM)
1111
if(CONFIG_PM_POLICY_DEFAULT)
1212
zephyr_library_sources(policy_default.c)
1313
endif()
14+
elseif(CONFIG_PM_POLICY_LATENCY_STANDALONE)
15+
zephyr_library_sources(policy_latency.c)
1416
endif()

subsys/pm/policy/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,13 @@ config PM_POLICY_DEVICE_CONSTRAINTS
3232
it is needed by the device.
3333

3434
endif # PM
35+
36+
config PM_POLICY_LATENCY_STANDALONE
37+
bool "Allow gathering latency requirements in standalone mode"
38+
depends on !PM
39+
help
40+
This option allows using the pm_policy_latency* APIs to gather latency
41+
requirements on systems that do not support PM (e.g. systems whithout
42+
CPU idle states). Because the API has a subscription mechanism, it can
43+
be useful to perform system-level adjustments based on latency
44+
requirements gathered from multiple system components.

0 commit comments

Comments
 (0)