8000 Alarm Syscall: fix computed `dt` when both unshifted `reference` and `dt` from userspace have low-order bits. by alevy · Pull Request #4201 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Alarm Syscall: fix computed dt when both unshifted reference and dt from userspace have low-order bits. #4201

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 3 commits into from
Oct 17, 2024

Conversation

alevy
Copy link
Member
@alevy alevy commented Oct 15, 2024

Pull Request Overview

This pull request fixes two issues in the alarm syscall driver, both necessary to correctly handle alarms that overflow in userspace. Each issue separated into its own commit:

  1. The second argument to the alarm upcall is the time the alarm was scheduled to expire. This PR fixes it to be left-justified and thus expressed in the same units as all other counter values exposed to userspace.
  2. Computing dt for a userspace alarm when userspace values are left-shifted to be u32 (e.g. on the 24-bit nRF52 RTC implementation) underestimated dt in some cases where both reference and dt had low-order bits that were rounded off. It is necessary to compute dt considering the reference value when it is provided, so this PR computes dt from the computed expiration in the shifted domain.

Testing Strategy

The second commit adds test cases for 24-bit alarms with provided reference counters. Running cargo test without the changes in the second commit fail, and succeed with the changes. The first commit is tested via changes to libtock-c in a different PR to that repo.

TODO or Help Wanted

It would be good to be able to test upcall values in unit tests, but I decided to avoid figuring out how to do that for this PR since the relevant change is pretty trivially correct, and was unnoticed simply because that value was never used.

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

lschuermann
lschuermann previously approved these changes Oct 15, 2024
Comment on lines -174 to +177
expired.reference.wrapping_add(expired.dt).into_usize(),
expired
.reference
.wrapping_add(expired.dt)
.into_u32_left_justified() as usize,
Copy link
Member

Choose a reason for hiding this comment

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

It's unfortunate that we don't yet have a reliable way to test this part of the code. 😞

alevy added 2 commits October 15, 2024 08:14
Computing unshifted dt independently of unshifted reference can lead to
too low of a final expiration if reference and dt from userspace both have low-order
bits. Instead, compute unshifted dt by first computing the expected
expirtion, and right-shifting it to make sure the final reference + dt
expires at or after the expected expiration.
lschuermann
lschuermann previously approved these changes Oct 15, 2024
Co-authored-by: Leon Schuermann <leon@is.currently.online>
@alevy
Copy link
Member Author
alevy commented Oct 15, 2024

@lschuermann last one I promise, just fixes formatting

@lschuermann
Copy link
Member

Is there anything in terms of stability guarantees that we need to watch out for in this PR?

My guess is no: the previous alarm changes (#3975) were almost entirely backwards compatible, except for the callback arguments that was left unscaled, which this PR fixes. Thus, after this PR, we should be back to being compliant to the alarm interface as it's specified and included in the previous release.

@alevy
Copy link
Member Author
alevy commented Oct 16, 2024

Agree, I don't there are anything compatibility issues

@alevy alevy added the last-call Final review period for a pull request. label Oct 16, 2024
@lschuermann lschuermann added this pull request to the merge queue Oct 17, 2024
Merged via the queue into tock:master with commit e688128 Oct 17, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
last-call Final review period for a pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0