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

Avoid AtomicU64 if possible, fix race condition #278

Merged
merged 3 commits into from
Oct 11, 2023

Conversation

bugadani
Copy link
Contributor

@bugadani bugadani commented Oct 11, 2023

AtomicU64 is implemented with a critical section on the ESP32{|-S3}. Multi-core aware critical sections are rather expensive, so let's see if this PR can reduce that cost.

On the S2 this is less of an issue. It is a single-core SoC, so a critical section is much smaller in number of instructions. Still I hope there is value in:

  • consistency
  • fewer multiplications
  • 4 bytes less RAM used

Secondly, the algorithm used to calculate the time was previously incorrect. If the cycle counter just overflowed, it was previously possible to add together the old global overflow counter with the now-overflowed cycle counter, resulting in a smaller timestamp than expected.

@bugadani bugadani changed the title Experiment with timebase Avoid AtomicU64 if possible Oct 11, 2023
@bugadani bugadani force-pushed the current_time branch 3 times, most recently from 98f05e2 to c2ffc18 Compare October 11, 2023 12:12
@bugadani bugadani changed the title Avoid AtomicU64 if possible Avoid AtomicU64 if possible, fix race condition Oct 11, 2023
@bugadani bugadani force-pushed the current_time branch 3 times, most recently from bc36a8f to 9cbf2ef Compare October 11, 2023 14:15
@bugadani bugadani marked this pull request as ready for review October 11, 2023 14:15
Copy link
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

Looks good from my perspective, makes more sense to count overflows than CPU ticks.

Copy link
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@bjoernQ bjoernQ merged commit ac3ee83 into esp-rs:main Oct 11, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants