Skip to content

drivers: timer: Add support for IFX Low power timer #89429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2025

Conversation

sreeramIfx
Copy link
Collaborator

Adding support for low power timer to enable low power modes

ifyall
ifyall previously approved these changes May 5, 2025
@sreeramIfx sreeramIfx force-pushed the lptimer_support branch 2 times, most recently from c3f9aa3 to 6e7559f Compare May 6, 2025 22:26
Comment on lines +88 to +95
/* passing ticks==1 means "announce the next tick", ticks value of zero (or even negative)
* is legal and treated identically: it simply indicates the kernel would like the next
* tick announcement as soon as possible.
*/
if (ticks < 1) {
ticks = 1;
}

uint32_t set_ticks = ((uint32_t)(ticks)*LPTIMER_FREQ) / CONFIG_SYS_CLOCK_TICKS_PER_SEC;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest moving this calculation, particularly with the divide, before acquiring the lock to reduce the time spent holding the lock.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like a compile time constant to me unless LPTIMER_FREQ hides runtime code. There won't be a division at runtime.

Comment on lines +114 to +123
/* gives the value of LPTIM counter (ms) since the previous 'announce' */
uint64_t ret = (((uint64_t)(lptimer_value - last_lptimer_value)) *
CONFIG_SYS_CLOCK_TICKS_PER_SEC) /
LPTIMER_FREQ;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest moving this calculation after releasing the lock to reduce the time spend holding the lock.

Comment on lines +132 to +139
/* convert lptim count in a nb of hw cycles with precision */
uint64_t ret = ((uint64_t)lp_time * sys_clock_hw_cycles_per_sec()) / LPTIMER_FREQ;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest moving this calculation after releasing the lock to reduce the time spend holding the lock.

Comment on lines 58 to 62
uint32_t delta_ticks =
((uint64_t)(lptimer_value - last_lptimer_value) * CONFIG_SYS_CLOCK_TICKS_PER_SEC) /
LPTIMER_FREQ;
sys_clock_announce(IS_ENABLED(CONFIG_TICKLESS_KERNEL) ? delta_ticks : (delta_ticks > 0));
last_lptimer_value = lptimer_value;
Copy link
Contributor

Choose a reason for hiding this comment

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

If lock is not required for sys_clock_announce function, release lock before doing the delta_ticks computation to reduce time spent with resource locked. If it's possible to pre-compute the divide, we could also move that computation out of the interrupt handler.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelated to the comment above but about the same line: this is a precision bug. "last_lptimer_value" wants to be the last time announced, not the precise time of the last interrupt. Otherwise this will slip a little time every interrupt and if it happens to cross a tick boundary, that tick will be "lost" and never announced.

Copy link
Collaborator

@andyross andyross left a comment

Choose a reason for hiding this comment

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

Minor but real quibble with tick math. See the other drivers for examples.

Comment on lines 58 to 62
uint32_t delta_ticks =
((uint64_t)(lptimer_value - last_lptimer_value) * CONFIG_SYS_CLOCK_TICKS_PER_SEC) /
LPTIMER_FREQ;
sys_clock_announce(IS_ENABLED(CONFIG_TICKLESS_KERNEL) ? delta_ticks : (delta_ticks > 0));
last_lptimer_value = lptimer_value;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelated to the comment above but about the same line: this is a precision bug. "last_lptimer_value" wants to be the last time announced, not the precise time of the last interrupt. Otherwise this will slip a little time every interrupt and if it happens to cross a tick boundary, that tick will be "lost" and never announced.

Adding support for low power timer to enable low power modes

Signed-off-by: Sreeram Tatapudi <[email protected]>
Copy link

Copy link
Collaborator

@andyross andyross left a comment

Choose a reason for hiding this comment

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

Looks correct now, thanks

@sreeramIfx sreeramIfx requested a review from ifyall May 29, 2025 22:39
@nashif nashif merged commit 02f2bea into zephyrproject-rtos:main May 30, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants