Skip to content
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

Fix arm64 tick timer #292

Merged
merged 3 commits into from
Sep 30, 2024
Merged

Fix arm64 tick timer #292

merged 3 commits into from
Sep 30, 2024

Conversation

jlaitine
Copy link

Summary

WIP: fixed arm64 tick timer

Not going to merge before upstreaming. The first patch (arch alarm) is just cleanup to make it understandable to myself. The two others actually correct something.

Impact

Testing

drivers/timers/arch_alarm.c Fixed Show resolved Hide resolved
drivers/timers/arch_alarm.c Show resolved Hide resolved
@jlaitine jlaitine force-pushed the fix_arm64_tick_timer branch from 42bc72e to 16f1b3c Compare September 27, 2024 07:56
@jlaitine jlaitine force-pushed the fix_arm64_tick_timer branch 2 times, most recently from 67ef15b to 8ee2973 Compare September 27, 2024 09:48
…k timer

This fixes two issues with the tick timer
1) Each tick was longer than the requested period. This is because setting
   the compare register was done by first reading the current time, and only
   after that setting the compare register. In addition, when handling the
   timer interrupts in arch_alarm.c / oneshot_callback, the current_tick is
   first read, all the tick handling is done and only after that the next tick
   is started. The whole tick processing time was added to the total tick time.

2) When the compare time is not aligned with tick period, and is drifting,
   eventually any call to ONESHOT_TICK_CURRENT would either return the current
   tick, or the next one, depending on the rounding of division by the
   cycle_per_tick. This again leads to oneshot_callback randomly handling
   two ticks at a time, which breaks all wdog based timers, causing them to
   randomly timeout too early.

The issues are fixed as follows:

Align the compare time register to be evenly divisible by cycle_per_tick.
This will lead arm64_tick_current always to return the currently ongoing tick,
fixing 2). Also calculating the next tick's start from the aligned current
count will fix 1), as there is no time drift in the start cycle.

Signed-off-by: Jukka Laitinen <[email protected]>
…d condition

nxsem_tickwait correctly sleeps more than 1 tick. But nxsem_tickwait_uninterruptible
may wake up to a signal (with -EINTR), in which case the tick + 1 must also
be taken into account. Otherwise the nxsem_tickwait_uninterruptible may
wake up 1 tick too early.

Also fix the nxsem_tickwait to return with -ETIMEDOUT if called with delay 0.
This is similar to e.g.  posix sem_timedwait.

Signed-off-by: Jukka Laitinen <[email protected]>
@jlaitine jlaitine force-pushed the fix_arm64_tick_timer branch from 8ee2973 to f81554d Compare September 30, 2024 13:05
@jlaitine
Copy link
Author

Updated to clean cherry-picks from upstream

Copy link

@pussuw pussuw left a comment

Choose a reason for hiding this comment

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

LGTM

@jlaitine jlaitine merged commit 233c167 into master Sep 30, 2024
10 of 11 checks passed
@jlaitine jlaitine deleted the fix_arm64_tick_timer branch September 30, 2024 15:55
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.

2 participants