-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
WIP: py: Implement mp_sched_vm_abort() to force a return to the very top level #10241
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
Conversation
Code size report:
|
Further to #9949 (comment) -- the original intent was that setting the pending exception would also set One way to solve this without adding an extra check in the VM might be to rework the two state variables... Currently we have: Instead we could do: This would mean that the VM only ever checks Here's an attempt at implementing that (also it comes out at -48 bytes code size): |
It might be possible to also catch hard IRQs by using |
3b21d55
to
b682eb2
Compare
I've now incorporated the commit mentioned by @jimmo above. Also made it so abort can now abort a scheduled function, as well as the possibility to abort hard IRQ handlers (and an example is given for stm32 pin IRQs). |
b682eb2
to
14de0b5
Compare
Signed-off-by: Jim Mussared <jim.mussared@gmail.com> Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
14de0b5
to
4ad904c
Compare
Codecov Report
@@ Coverage Diff @@
## master #10241 +/- ##
=======================================
Coverage 98.50% 98.50%
=======================================
Files 155 155
Lines 20540 20543 +3
=======================================
+ Hits 20232 20236 +4
+ Misses 308 307 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
These changes are quite difficult to follow when just looking at the code. Can we add more comments in the code to explain what is going on? |
It should be easier to follow if you look at each commit separately (the first one is effectively a refactoring and does most of the work here). But yes I'll also add comments. |
Upon closer inspection of this commit, it introduces a problem: pending exceptions (eg a keyboard interrupt) can now be caught by scheduled functions. In practice this means that a ctrl-C could be caught by, eg, a soft interrupt handler, and that handler would terminate early but the ctrl-C would not propagate out any further, and so the main application keeps running. This is a tricky/complex situation. Maybe we do want ctrl-C to stop a scheduled function (because that function may be in an infinite loop), but we'd definitely then want that ctrl-C to propagate out and also terminate the main code. But that's really getting out of scope of this PR. |
Closing in favour of #10971. |
This fixes an issue where a terminal can't be started after being stopped (when tilegrid_tiles is freed and set to NULL.) Fixes micropython#10241
This is an alternative to #9949 which does a "very long jump" to force the VM to stop and return up to the very top level of code control (usually pyexec).
The idea is for the top level to mark its nlr_buf as the special one to return to. Then a call to
mp_sched_vm_abort()
will schedule (indicate to) the VM that it should stop immediately. The VM (actuallymp_handle_pending()
the next time it is run) will then jump to this special nlr_buf (bypassing all those nlr bufs in between).This approach should work with multiple threads. Only the main thread handles the abort.