Skip to content

Commit

Permalink
[nrf fromtree] pm: policy: allow using latency API in standalone mode
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
gmarull committed Nov 4, 2024
1 parent 3166c78 commit e2dec8b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 63 deletions.
129 changes: 66 additions & 63 deletions include/zephyr/pm/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,49 +137,6 @@ void pm_policy_state_lock_put(enum pm_state state, uint8_t substate_id);
*/
bool pm_policy_state_lock_is_active(enum pm_state state, uint8_t substate_id);

/**
* @brief Add a new latency requirement.
*
* The system will not enter any power state that would make the system to
* exceed the given latency value.
*
* @param req Latency request.
* @param value_us Maximum allowed latency in microseconds.
*/
void pm_policy_latency_request_add(struct pm_policy_latency_request *req,
uint32_t value_us);

/**
* @brief Update a latency requirement.
*
* @param req Latency request.
* @param value_us New maximum allowed latency in microseconds.
*/
void pm_policy_latency_request_update(struct pm_policy_latency_request *req,
uint32_t value_us);

/**
* @brief Remove a latency requirement.
*
* @param req Latency request.
*/
void pm_policy_latency_request_remove(struct pm_policy_latency_request *req);

/**
* @brief Subscribe to maximum latency changes.
*
* @param req Subscription request.
* @param cb Callback function (NULL to disable).
*/
void pm_policy_latency_changed_subscribe(struct pm_policy_latency_subscription *req,
pm_policy_latency_changed_cb_t cb);

/**
* @brief Unsubscribe to maximum latency changes.
*
* @param req Subscription request.
*/
void pm_policy_latency_changed_unsubscribe(struct pm_policy_latency_subscription *req);

/**
* @brief Register an event.
Expand Down Expand Up @@ -277,26 +234,6 @@ static inline bool pm_policy_state_lock_is_active(enum pm_state state, uint8_t s
return false;
}

static inline void pm_policy_latency_request_add(
struct pm_policy_latency_request *req, uint32_t value_us)
{
ARG_UNUSED(req);
ARG_UNUSED(value_us);
}

static inline void pm_policy_latency_request_update(
struct pm_policy_latency_request *req, uint32_t value_us)
{
ARG_UNUSED(req);
ARG_UNUSED(value_us);
}

static inline void pm_policy_latency_request_remove(
struct pm_policy_latency_request *req)
{
ARG_UNUSED(req);
}

static inline void pm_policy_event_register(struct pm_policy_event *evt, uint32_t cycle)
{
ARG_UNUSED(evt);
Expand Down Expand Up @@ -331,6 +268,72 @@ static inline int32_t pm_policy_next_event_ticks(void)

#endif /* CONFIG_PM */

#if defined(CONFIG_PM) || defined(CONFIG_PM_POLICY_LATENCY_STANDALONE) || defined(__DOXYGEN__)
/**
* @brief Add a new latency requirement.
*
* The system will not enter any power state that would make the system to
* exceed the given latency value.
*
* @param req Latency request.
* @param value_us Maximum allowed latency in microseconds.
*/
void pm_policy_latency_request_add(struct pm_policy_latency_request *req,
uint32_t value_us);

/**
* @brief Update a latency requirement.
*
* @param req Latency request.
* @param value_us New maximum allowed latency in microseconds.
*/
void pm_policy_latency_request_update(struct pm_policy_latency_request *req,
uint32_t value_us);

/**
* @brief Remove a latency requirement.
*
* @param req Latency request.
*/
void pm_policy_latency_request_remove(struct pm_policy_latency_request *req);

/**
* @brief Subscribe to maximum latency changes.
*
* @param req Subscription request.
* @param cb Callback function (NULL to disable).
*/
void pm_policy_latency_changed_subscribe(struct pm_policy_latency_subscription *req,
pm_policy_latency_changed_cb_t cb);

/**
* @brief Unsubscribe to maximum latency changes.
*
* @param req Subscription request.
*/
void pm_policy_latency_changed_unsubscribe(struct pm_policy_latency_subscription *req);
#else
static inline void pm_policy_latency_request_add(
struct pm_policy_latency_request *req, uint32_t value_us)
{
ARG_UNUSED(req);
ARG_UNUSED(value_us);
}

static inline void pm_policy_latency_request_update(
struct pm_policy_latency_request *req, uint32_t value_us)
{
ARG_UNUSED(req);
ARG_UNUSED(value_us);
}

static inline void pm_policy_latency_request_remove(
struct pm_policy_latency_request *req)
{
ARG_UNUSED(req);
}
#endif /* CONFIG_PM CONFIG_PM_POLICY_LATENCY_STANDALONE */

/**
* @}
*/
Expand Down
2 changes: 2 additions & 0 deletions subsys/pm/policy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ if(CONFIG_PM)
if(CONFIG_PM_POLICY_DEFAULT)
zephyr_library_sources(policy_default.c)
endif()
elseif(CONFIG_PM_POLICY_LATENCY_STANDALONE)
zephyr_library_sources(policy_latency.c)
endif()
10 changes: 10 additions & 0 deletions subsys/pm/policy/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ config PM_POLICY_DEVICE_CONSTRAINTS
it is needed by the device.

endif # PM

config PM_POLICY_LATENCY_STANDALONE
bool "Allow gathering latency requirements in standalone mode"
depends on !PM
help
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.

0 comments on commit e2dec8b

Please sign in to comment.