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: Update EventManager and task::run_on_core to ignore spurious wakeups if they happen #340

Merged
merged 3 commits into from
Nov 19, 2024

Conversation

finger563
Copy link
Contributor

Description

  • Added notified flag to SubscriberData which is set / cleared appropriately and used as predicate to cv.wait(...)
  • Added notified bool used in run_on_core to ensure the cv.wait(...) uses it as the predicate, ensuring the blocking run on core does not return early

Motivation and Context

Spurious wakeups can happen (see c++ docs on condition variable wait and associated methods). On ESP this can happen for instance if you enable light sleep and have some time-dependent wakeups.

Even though the methods changed in this PR use wait(...) instead of wait_for(...) or wait_until(...), these changes were applied to ensure better adherence to programming guidelines and recommendations from the c++ reference / standard.

How has this been tested?

  • Building and running event_manger/example on esp32s3
  • Building and running task/example on esp32s3

Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):

Event Manager example output snippet:

CleanShot 2024-11-19 at 13 04 57

Task example output snippet:

CleanShot 2024-11-19 at 13 06 17

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added / updated the documentation related to this change via either README or WIKI

Software

  • I have added tests to cover my changes.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

… wakeups if they happen

* Added `notified` flag to `SubscriberData` which is set / cleared appropriately and used as predicate to `cv.wait(...)`
* Added `notified` bool used in `run_on_core` to ensure the `cv.wait(...)` uses it as the predicate, ensuring the blocking run on core does not return early
@finger563 finger563 self-assigned this Nov 19, 2024
@finger563 finger563 added bug Something isn't working tasks event manager labels Nov 19, 2024
Copy link

✅Static analysis result - no issues found! ✅

@finger563 finger563 merged commit 63fb8b3 into main Nov 19, 2024
55 of 56 checks passed
@finger563 finger563 deleted the fix/spurious-wakeups branch November 19, 2024 19:16
SquaredPotato pushed a commit to smartknob-ha/espp that referenced this pull request Jan 27, 2025
… wakeups if they happen (esp-cpp#340)

* fix: Update `EventManager` and `task::run_on_core` to ignore spurious wakeups if they happen
* Added `notified` flag to `SubscriberData` which is set / cleared appropriately and used as predicate to `cv.wait(...)`
* Added `notified` bool used in `run_on_core` to ensure the `cv.wait(...)` uses it as the predicate, ensuring the blocking run on core does not return early

* update to protect shared memory with lock

* fix comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working event manager tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant