Skip to content

Conversation

@bjarki-andreasen
Copy link
Contributor

@bjarki-andreasen bjarki-andreasen commented Oct 29, 2024

Registering a pm policy event will now represent a single event in absolute time, which will remain active, preventing the system from suspending, until the event has been handled. To indicate an event has been handled, it must be updated to a time in the future, or unregistered.

To greatly simplify the events and the "sticky" logic, the time primitive used is updated to the monotonic uptime in ticks. This ensures an event can be determined to be in the past, since unlike the HW cycle, uptime can't wrap. Additionally, the kernel works in ticks, which aligns the resolution with the requirements of the kernel, and removes the need for conversions between pm and the kernel, see pm_policy_next_event_ticks() before this PR.

fixes: #80386

@bjarki-andreasen
Copy link
Contributor Author

ping @ceolin

ceolin
ceolin previously approved these changes Dec 2, 2024
Copy link
Member

@ceolin ceolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me. It is easier to read too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it also valid to call pm_policy_event_update instead of unregister/register, or is that only allowed before the event time has passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also valid to call pm_policy_event_update instead of unregister/register :) I will update the desc

Copy link
Contributor Author

@bjarki-andreasen bjarki-andreasen Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to:

 * CPU is woken up before the time passed in cycle to minimize event handling
 * latency. Once woken up, the CPU will be kept awake until the event has been
 * handled, which is signaled by pm_policy_event_unregister() or moving event
 * into the future using pm_policy_event_update().

Comment on lines 210 to 211
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify that if there is an unregistered past event, this function returns zero?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to:

/**
 * @brief Returns the ticks until the next event
 *
 * If an event is registred, it will return the number of ticks until the next event, if the
 * "next"/"oldest" registered event is in the past, it will return 0. Otherwise it returns -1.
 *
 * @retval >0 If next registered event is in the future
 * @retval 0 If next registered event is now or in the past
 * @retval -1 Otherwise
 */

Update events to use uptime ticks, which is a monotonic clock which
in the same res as kernel ticks. This makes comparisons simple and
removes the complexity of dealing with wrapping counter values.

The wrapping is particularly problematic for events since this makes
it quite complex to track if an event has occured in the past, or
will occur in the future. This info is needed to know if an event
has actually been handled or not.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
@bjarki-andreasen bjarki-andreasen force-pushed the pm_policy_event_use_uptime_ticks branch from 8b3f619 to 18f3e8f Compare December 6, 2024 15:37
@kartben kartben merged commit 59779eb into zephyrproject-rtos:main Dec 9, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PM policy: definition of the end of a registered event

6 participants