rp2/pendsv.c: PendSV_Handler dispatch check. #18380
Open
+2
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If MICROPY_PY_THREAD is set, PendSV_Handler acquires a mutex and calls the dispatch functions. If pendsv_schedule_dispatch is called by a higher priority interrupt while the mutex is acquired by PendSV_Handler it's possible for the dispatch to not be triggered.
Add a check for dispatch calls at the end of PendSV_Handler once the mutex has been released.
Fixes #18365
Summary
If an IRQ - that uses the dispatch mechanism - goes off while the pendsv interrupt has its mutex acquired, it stops the dispatch function happening. Fix is to just check if any dispatch functions need to be called after releasing the mutex.
Testing
This change resolves the issue I was seeing (on a port in development)
Ran all tests / Wifi still works!
Trade-offs and Alternatives
There's a small possibility that dispatch functions will be called more than needed.
The new check for dispatch functions may itself be blocked if another thread manages to call pendsv_suspend, but they will be serviced when pendsv_resume is called