Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@peterharperuk
Copy link
Contributor

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

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 micropython#18365

Signed-off-by: Peter Harper <[email protected]>
@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Code size report:

Reference:  tests/serial_test.py: Allow up to 2 seconds between bytes. [2762fe6]
Comparison: rp2/pendsv: PendSV_Handler dispatch check. [merge of 301e4a7]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:   +16 +0.002% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pendsv_schedule_dispatch can silently do nothing

2 participants