Skip to content

py/scheduler: Break out of the c task loop on re-schedule. #17248

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

andrewleech
Copy link
Contributor

Summary

If a mp_sched_schedule_node based C scheduler function re-schedules itself then the mp_sched_run_pending function can get stuck in an infinite loop re-running the function where ctrl-c cannot break out of it anymore.

This change adds a unit test to display the behavior (in a self-limiting fashion) along with a minimal change to auto-break out of mp_sched_run_pending if the node is re-scheduled. It will still be run on next run of mp_sched_run_pending but other aspects of the application / micropython will be able to run as well in this case.

See #17246

Testing

Tested on a STM32WB55 with manually broken rfcore, before this it was stuck in an infinite loop trying to init the radio.

Trade-offs and Alternatives

If there are two C scheduled functions that continually re-schedule each other this fix won't catch that, but I tried to keep the minimal fix as simple as possible as I believe the goal is to keep mp_sched_run_pending as fast as possible as its run in the interpreter core?

pi-anl added 2 commits May 5, 2025 16:37
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Copy link

codecov bot commented May 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (bee1fd5) to head (af4a8e9).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #17248      +/-   ##
==========================================
- Coverage   98.54%   98.54%   -0.01%     
==========================================
  Files         169      169              
  Lines       21890    21929      +39     
==========================================
+ Hits        21572    21610      +38     
- Misses        318      319       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

github-actions bot commented May 5, 2025

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +8 +0.002% TEENSY40
        rp2:   +16 +0.002% RPI_PICO_W
       samd:    +8 +0.003% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@andrewleech andrewleech added the py-core Relates to py/ directory in source label May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants